-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Block Support Example #1565
Merged
Merged
✨ Block Support Example #1565
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
464b4c3
Add new block-support example project
josephfusco 1be9609
Auto analyze new project
josephfusco 377942f
Update dependencies
josephfusco dfea166
Remove hardcoded theme.json
josephfusco d1e2db5
Ignore globalStylesheet.css
josephfusco e7c9075
Reduce example to just block things
josephfusco 929f37a
Add newline to EOF
josephfusco 1bc1645
Reduce example
josephfusco b8627b6
Merge branch 'canary' into nojira-block-support-example
josephfusco 29d10da
Update lockfile after merge
josephfusco 4257d0e
Constrain layout using existing core class
josephfusco da3c5bf
Not being used
josephfusco b9a235c
Irrelevant comment
josephfusco 34334ba
Merge branch 'canary' into nojira-block-support-example
josephfusco 5f4c85a
Merge branch 'canary' into nojira-block-support-example
josephfusco 7d8db16
Merge branch 'canary' into nojira-block-support-example
josephfusco c9dd1f8
Resolve merge conflicts
josephfusco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
possibleTypes.json | ||
globalStylesheet.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import frontPage from './front-page'; | ||
|
||
export default { | ||
'front-page': frontPage, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using npm's "pre" scripts https://docs.npmjs.com/cli/v9/using-npm/scripts