-
Notifications
You must be signed in to change notification settings - Fork 815
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
CLI Tools: update scaffolding, use block.json to register blocks. #33883
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0c32cbd
CLI Tools: update scaffolding, use block.json to register blocks.
jeherve 26771a7
Update default supported attributes
jeherve e1b8dd0
Merge remote-tracking branch 'origin/trunk' into update/cli-blocks-sc…
jeherve 88425e5
Switch back to an info icon as the default block icon
jeherve 6cafa88
Only keep the 3 first keywords that were provided
jeherve b22e853
Fix the display of the keywords when passed
jeherve d4c48c3
Handle double quotes, backslashes, and new lines in arguments
jeherve 662155d
Merge remote-tracking branch 'origin/trunk' into update/cli-blocks-sc…
jeherve 111a10e
Merge remote-tracking branch 'origin/trunk' into update/cli-blocks-sc…
jeherve e4b8331
Merge remote-tracking branch 'origin/trunk' into update/cli-blocks-sc…
jeherve 1f39cf3
Switch to wp_json_encode
jeherve 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
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-cli-blocks-scaffold
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 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
CLI Tools: update block scaffolding CLI tool to use block.json to register blocks. |
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
3 changes: 0 additions & 3 deletions
3
projects/plugins/jetpack/wp-cli-templates/block-attributes-js.mustache
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
projects/plugins/jetpack/wp-cli-templates/block-block-json.mustache
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,23 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 1, | ||
"name": "jetpack/{{ slug }}", | ||
"title": {{ title }}, | ||
"description": {{ description }}, | ||
"keywords": {{ keywords }}, | ||
"version": "{{ nextVersion }}", | ||
"textdomain": "jetpack", | ||
"category": "grow", | ||
"icon": "<svg viewBox='0 0 32 32' width='32' height='32' xmlns='http://www.w3.org/2000/svg'><path d='M9 15h2V9H9v6zm1-10c-.5 0-1 .5-1 1s.5 1 1 1 1-.5 1-1-.5-1-1-1zm0-4c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7z'/></svg>", | ||
"supports": { | ||
"align": false, | ||
"alignWide": true, | ||
"anchor": false, | ||
"customClassName": true, | ||
"className": true, | ||
"html": false, | ||
"multiple": true, | ||
"reusable": true | ||
}, | ||
"attributes": {} | ||
} |
5 changes: 4 additions & 1 deletion
5
projects/plugins/jetpack/wp-cli-templates/block-edit-js.mustache
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
11 changes: 8 additions & 3 deletions
11
projects/plugins/jetpack/wp-cli-templates/block-editor-js.mustache
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,4 +1,9 @@ | ||
import registerJetpackBlock from '../../shared/register-jetpack-block'; | ||
import { name, settings } from '.'; | ||
import { registerJetpackBlockFromMetadata } from '../../shared/register-jetpack-block'; | ||
import metadata from './block.json'; | ||
import edit from './edit'; | ||
import './editor.scss'; | ||
|
||
registerJetpackBlock( name, settings ); | ||
registerJetpackBlockFromMetadata( metadata, { | ||
edit, | ||
save: () => null, // TODO: Implement save. | ||
} ); |
8 changes: 0 additions & 8 deletions
8
projects/plugins/jetpack/wp-cli-templates/block-icon-js.mustache
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
projects/plugins/jetpack/wp-cli-templates/block-index-js.mustache
This file was deleted.
Oops, something went wrong.
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
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.
Should new blocks be defaulting to a later api version?
For version 2, it looks like we'll also have to have the default
edit
function useuseBlockProps
as documented at https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/. And maybe something similar for thesave
function anduseBlockProps.save
.Version 3 will probably have to wait until we're not using 'enqueue_block_editor_assets' to enqueue the monolithic editor.js though.
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.
@monsieur-z What's your take on this?
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.
It makes sense to nudge people to use the latest version when possible. In this case (using 2 or 3), we'd probably need to edit the
save
andedit
functions in the templates to includeuseBlockProps();
(as in the link Brad copied) and make it visible it's required.As for which version to use, I can't say I fully understand what using version 3 involves. The iframing might be an issue for some, but it seems it wouldn't occur unless all blocks are registered with 3 anyway.
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.
What I've managed to gather is that we have to make sure the scripts will be enqueued inside the iframe. Which it seems may involve somehow using the 'enqueue_block_assets' hook rather than 'enqueue_block_editor_assets', or else doing the enqueuing via block.json.
https://developer.wordpress.org/block-editor/how-to-guides/enqueueing-assets-in-the-editor/#editor-content-scripts-and-styles (and the following section) might be relevant.
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.
👍 Discussion can continue in #34120