Skip to content

Commit

Permalink
✨ Block Support Example (#1565)
Browse files Browse the repository at this point in the history
* Add new block-support example project

Signed-off-by: Joe Fusco <[email protected]>

* Auto analyze new project

Signed-off-by: Joe Fusco <[email protected]>

* Update dependencies

Signed-off-by: Joe Fusco <[email protected]>

* Remove hardcoded theme.json

Signed-off-by: Joe Fusco <[email protected]>

* Ignore globalStylesheet.css

Signed-off-by: Joe Fusco <[email protected]>

* Reduce example to just block things

Signed-off-by: Joe Fusco <[email protected]>

* Add newline to EOF

Signed-off-by: Joe Fusco <[email protected]>

* Reduce example

Signed-off-by: Joe Fusco <[email protected]>

* Update lockfile after merge

Signed-off-by: Joe Fusco <[email protected]>

* Constrain layout using existing core class

Signed-off-by: Joe Fusco <[email protected]>

* Not being used

Signed-off-by: Joe Fusco <[email protected]>

* Irrelevant comment

Signed-off-by: Joe Fusco <[email protected]>

* Resolve merge conflicts

Signed-off-by: Joe Fusco <[email protected]>

---------

Signed-off-by: Joe Fusco <[email protected]>
  • Loading branch information
josephfusco authored Oct 4, 2023
1 parent 426463c commit 4c4e600
Show file tree
Hide file tree
Showing 18 changed files with 431 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/nextjs-bundle-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ jobs:
analyze:
strategy:
matrix:
next-dir: ['examples/next/faustwp-getting-started']
next-dir: [
'examples/next/faustwp-getting-started',
'examples/next/block-support'
]

runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 5 additions & 0 deletions examples/next/block-support/.env.local.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Your WordPress site URL
NEXT_PUBLIC_WORDPRESS_URL=https://faustexample.wpengine.com

# Plugin secret found in WordPress Settings->Faust
# FAUST_SECRET_KEY=YOUR_PLUGIN_SECRET
2 changes: 2 additions & 0 deletions examples/next/block-support/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
possibleTypes.json
globalStylesheet.css
3 changes: 3 additions & 0 deletions examples/next/block-support/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @faustwp/block-support-example

Example showcasing Faust.js block editor support.
12 changes: 12 additions & 0 deletions examples/next/block-support/faust.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { setConfig } from '@faustwp/core';
import templates from './wp-templates';
import possibleTypes from './possibleTypes.json';

/**
* @type {import('@faustwp/core').FaustConfig}
**/
export default setConfig({
templates,
experimentalPlugins: [],
possibleTypes,
});
18 changes: 18 additions & 0 deletions examples/next/block-support/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { withFaust, getWpHostname } = require('@faustwp/core');

/**
* @type {import('next').NextConfig}
**/
module.exports = withFaust({
reactStrictMode: true,
sassOptions: {
includePaths: ['node_modules'],
},
images: {
domains: [getWpHostname()],
},
i18n: {
locales: ['en'],
defaultLocale: 'en',
},
});
30 changes: 30 additions & 0 deletions examples/next/block-support/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@faustwp/block-support-example",
"private": true,
"version": "0.1.0",
"scripts": {
"predev": "faust generatePossibleTypes && faust generateGlobalStylesheet",
"prebuild": "faust generatePossibleTypes && faust generateGlobalStylesheet",
"dev": "faust dev",
"build": "faust build",
"start": "faust start"
},
"dependencies": {
"@apollo/client": "^3.6.6",
"@faustwp/blocks": "2.0.0",
"@faustwp/cli": "1.0.1",
"@faustwp/core": "1.1.0",
"@wordpress/base-styles": "^4.26.0",
"@wordpress/block-library": "^7.19.0",
"classnames": "^2.3.1",
"graphql": "^16.6.0",
"next": "^12.1.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"sass": "^1.54.9"
},
"engines": {
"node": ">=16",
"npm": ">=8"
}
}
16 changes: 16 additions & 0 deletions examples/next/block-support/pages/[...wordpressNode].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getWordPressProps, WordPressTemplate } from '@faustwp/core';

export default function Page(props) {
return <WordPressTemplate {...props} />;
}

export function getStaticProps(ctx) {
return getWordPressProps({ ctx });
}

export async function getStaticPaths() {
return {
paths: [],
fallback: 'blocking',
};
}
24 changes: 24 additions & 0 deletions examples/next/block-support/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import '../faust.config';
import React from 'react';
import { useRouter } from 'next/router';
import { WordPressBlocksProvider, fromThemeJson } from '@faustwp/blocks';
import { FaustProvider } from '@faustwp/core';
import blocks from '../wp-blocks';
// import '../styles/blocks.scss'; // <-- Import block styles from WordPress.
import '../globalStylesheet.css'; // <-- Generated by @faustwp/cli

export default function MyApp({ Component, pageProps }) {
const router = useRouter();

return (
<FaustProvider pageProps={pageProps}>
<WordPressBlocksProvider
config={{
blocks,
theme: null,
}}>
<Component {...pageProps} key={router.asPath} />
</WordPressBlocksProvider>
</FaustProvider>
);
}
4 changes: 4 additions & 0 deletions examples/next/block-support/pages/api/faust/[[...route]].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import '../../../faust.config';
import { apiRouter } from '@faustwp/core';

export default apiRouter;
9 changes: 9 additions & 0 deletions examples/next/block-support/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getWordPressProps, WordPressTemplate } from '@faustwp/core';

export default function Page(props) {
return <WordPressTemplate {...props} />;
}

export function getStaticProps(ctx) {
return getWordPressProps({ ctx });
}
5 changes: 5 additions & 0 deletions examples/next/block-support/pages/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WordPressTemplate } from '@faustwp/core';

export default function Preview(props) {
return <WordPressTemplate {...props} />;
}
13 changes: 13 additions & 0 deletions examples/next/block-support/styles/blocks.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// WordPress block styles.

@use 'sass:math';

@import '@wordpress/base-styles/mixins';
@import '@wordpress/base-styles/colors.native';
@import '@wordpress/base-styles/z-index';
@import '@wordpress/base-styles/default-custom-properties';
@import '@wordpress/base-styles/colors';
@import '@wordpress/base-styles/variables';
@import '@wordpress/base-styles/breakpoints';
@import '@wordpress/block-library/src/style';
@import '@wordpress/block-library/src/theme';
15 changes: 15 additions & 0 deletions examples/next/block-support/wp-blocks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CoreBlocks } from '@faustwp/blocks';

export default {
CoreParagraph: CoreBlocks.CoreParagraph,
CoreColumns: CoreBlocks.CoreColumns,
CoreColumn: CoreBlocks.CoreColumn,
CoreCode: CoreBlocks.CoreCode,
CoreQuote: CoreBlocks.CoreQuote,
CoreImage: CoreBlocks.CoreImage,
CoreSeparator: CoreBlocks.CoreSeparator,
CoreList: CoreBlocks.CoreList,
CoreButton: CoreBlocks.CoreButton,
CoreButtons: CoreBlocks.CoreButtons,
CoreHeading: CoreBlocks.CoreHeading,
};
69 changes: 69 additions & 0 deletions examples/next/block-support/wp-templates/front-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { gql } from '@apollo/client';
import { flatListToHierarchical } from '@faustwp/core';
import { WordPressBlocksViewer } from '@faustwp/blocks';
import blocks from '../wp-blocks';

export default function Component({ loading, data }) {
// Loading state for previews.
if (loading) {
return <>Loading...</>;
}

const { title, editorBlocks } = data?.page ?? { title: '' };
const blockList = flatListToHierarchical(editorBlocks, { childrenKey: 'innerBlocks' });

return (
<div className='is-layout-constrained'>
<h1>{title}</h1>
<WordPressBlocksViewer blocks={blockList} />
</div>
);
}

Component.query = gql`
${blocks.CoreParagraph.fragments.entry}
${blocks.CoreColumns.fragments.entry}
${blocks.CoreColumn.fragments.entry}
${blocks.CoreCode.fragments.entry}
${blocks.CoreButtons.fragments.entry}
${blocks.CoreButton.fragments.entry}
${blocks.CoreQuote.fragments.entry}
${blocks.CoreImage.fragments.entry}
${blocks.CoreSeparator.fragments.entry}
${blocks.CoreList.fragments.entry}
${blocks.CoreHeading.fragments.entry}
query GetPage(
$databaseId: ID!
$asPreview: Boolean = false
) {
page(id: $databaseId, idType: DATABASE_ID, asPreview: $asPreview) {
title
content
editorBlocks(flat: false) {
name
__typename
renderedHtml
id: clientId
parentId: parentClientId
...${blocks.CoreParagraph.fragments.key}
...${blocks.CoreColumns.fragments.key}
...${blocks.CoreColumn.fragments.key}
...${blocks.CoreCode.fragments.key}
...${blocks.CoreButtons.fragments.key}
...${blocks.CoreButton.fragments.key}
...${blocks.CoreQuote.fragments.key}
...${blocks.CoreImage.fragments.key}
...${blocks.CoreSeparator.fragments.key}
...${blocks.CoreList.fragments.key}
...${blocks.CoreHeading.fragments.key}
}
}
}
`;

Component.variables = ({ databaseId }, ctx) => {
return {
databaseId,
asPreview: ctx?.asPreview,
};
};
5 changes: 5 additions & 0 deletions examples/next/block-support/wp-templates/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import frontPage from './front-page';

export default {
'front-page': frontPage,
};
Loading

0 comments on commit 4c4e600

Please sign in to comment.