-
Notifications
You must be signed in to change notification settings - Fork 310
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
Update Inner Blocks (ESNext) to use latest API #163
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Update block.
- Loading branch information
commit 7856eb98831cb3862a5a5a49cc0366f1af3e733c
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"apiVersion": 2, | ||
"name": "gutenberg-examples/example-06-esnext", | ||
"title": "Example: Inner Blocks (ESNext)", | ||
"category": "layout", | ||
"icon": "universal-access-alt", | ||
"textDomain": "gutenberg-examples", | ||
"example": {}, | ||
"editorScript": "file:./build/index.js" | ||
} |
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,14 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
const Edit = () => { | ||
const blockProps = useBlockProps(); | ||
return ( | ||
<div { ...blockProps }> | ||
<InnerBlocks /> | ||
</div> | ||
); | ||
}; | ||
export default Edit; |
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 |
---|---|---|
@@ -1,21 +1,19 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
registerBlockType( 'gutenberg-examples/example-06-esnext', { | ||
title: 'Example: Inner Blocks (ESNext)', | ||
category: 'layout', | ||
edit: ( { className } ) => { | ||
return ( | ||
<div className={ className }> | ||
<InnerBlocks /> | ||
</div> | ||
); | ||
}, | ||
save: ( { className } ) => { | ||
return ( | ||
<div className={ className }> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
}, | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import json from '../block.json'; | ||
import edit from './edit'; | ||
import save from './save'; | ||
|
||
const { name, ...settings } = json; | ||
|
||
registerBlockType( name, { | ||
...settings, | ||
edit, | ||
save, | ||
} ); |
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,14 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
const Save = () => { | ||
const blockProps = useBlockProps.save(); | ||
return ( | ||
<div { ...blockProps }> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
}; | ||
export default Save; |
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.
One note. Technically speaking, you don't need to spread settings here. They are exposed from the server when registered with
register_block_type
.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.
Thanks for confirming that! It was a question that came up in a couple of live streams.
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.
https://github.com/WordPress/gutenberg/blob/1a3bda10d3d04233e864d89eb9db3ca2adb0e62c/packages/blocks/src/api/registration.js#L258-L271
That means that whatever the client provides overrides what the server provides (if registered also on the server).
If you register blocks only with JavaScript then you surely need to spread settings from
block.json
here.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.
Example for core blocks:
https://github.com/WordPress/gutenberg/blob/1a3bda10d3d04233e864d89eb9db3ca2adb0e62c/packages/block-library/src/paragraph/index.js#L25-L57
It's only settings specific to the client (UI).