#60233 closed enhancement (fixed)
Editor: Support module metadata in block.json
Reported by: | jonsurrell | Owned by: | gziolo |
---|---|---|---|
Milestone: | 6.5 | Priority: | normal |
Severity: | normal | Version: | 6.5 |
Component: | Editor | Keywords: | has-patch has-unit-tests has-dev-note |
Focuses: | Cc: |
Description
Problem:
Scripts and styles can be registered for blocks via block.json metadata. There is now a Modules API, but no way to register or associate module assets with blocks via block.json metadata or the register_block_type_from_metadata
function.
Proposed solution:
Introduce module fields analogous to the script fields currently supported in block.json.
The end goal would be to support editorModule
, module
, and viewModule
. An initial version could support only viewModule
given that most functionality provided by WordPress for working with the editor is only available as scripts and not accessible to modules at this time.
Background:
See https://github.com/WordPress/gutenberg/issues/57492 for prior discussion in Gutenberg.
- Add support for viewModule in block.json when registering a block from metadata. https://github.com/WordPress/gutenberg/pull/57437
- Add experimental support to @wordpress/scripts for module compilation and support
viewModule
: https://github.com/WordPress/gutenberg/pull/57461 - Add support to @wordpress/dependency-extraction-webpack-plugin for module compilation and extraction of assets files.
Change History (25)
This ticket was mentioned in PR #5860 on WordPress/wordpress-develop by @jonsurrell.
11 months ago
#2
- Keywords has-patch added
Add handling for viewModule
block.json metadata when registering blocks.
Trac ticket: https://core.trac.wordpress.org/ticket/60233
@jonsurrell commented on PR #5860:
11 months ago
#3
We'll want to wait until naming questions are settled:
@youknowriad commented on PR #5860:
11 months ago
#4
Is the naming settled, what's blocking here?
11 months ago
#5
Is the naming settled, what's blocking here?
It needs a rebase after https://github.com/WordPress/wordpress-develop/pull/5869 lands. The name of the helper functions for modules follows the following pattern: wp_register_script_module
, so that probably should get reflected in block.json
and other places, viewScriptModule
? It's a bit unfortunate that we can't extend viewScript
in a backward-compatible way to support both ES Modules and legacy scripts.
@jonsurrell commented on PR #5860:
11 months ago
#6
https://github.com/WordPress/wordpress-develop/pull/5869 landed recently so I'll finish this and get it ready for review.
@jonsurrell commented on PR #5860:
11 months ago
#7
The Modules API ended up with names like "script_module." To better align, this has been updated to use viewScriptModule
instead of viewModule
.
@jonsurrell commented on PR #5860:
11 months ago
#8
@luisherranz @gziolo @youknowriad This is ready for review.
@jonsurrell commented on PR #5860:
11 months ago
#9
There was 1 test failure on a single PHP version that seems to be a flakey test.
@jonsurrell commented on PR #5860:
11 months ago
#10
Adding support to the @wordpress/scripts
for building blocks with viewScriptModule
: https://github.com/WordPress/gutenberg/pull/58203
@jonsurrell commented on PR #5860:
10 months ago
#11
Tests were failing because the number of REST fields returned in the response has changed again. They should be fixed now.
@jonsurrell commented on PR #5860:
10 months ago
#12
The asset file can be optional: https://github.com/WordPress/wordpress-develop/pull/5799
@jonsurrell commented on PR #5860:
10 months ago
#13
👋 pinging @luisherranz in case you have input on these comments:
@jonsurrell commented on PR #5860:
10 months ago
#14
I've pushed changes so the asset file is not longer required to align with hhttps://github.com/WordPress/wordpress-develop/pull/5799.
10 months ago
#15
I spotted an issue in the updated documentation: https://github.com/WordPress/gutenberg/pull/58731/files#r1482664885.
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#view-script
@jonsurrell commented on PR #5860:
10 months ago
#16
I spotted an issue in the updated documentation
Thanks, I'll create a PR for that 👍
@jonsurrell commented on PR #5860:
10 months ago
#18
I've finished rebasing (it was a bit tricky) and tweaking some documentation, I this this is ready now.
#19
@
10 months ago
- Owner set to gziolo
- Resolution set to fixed
- Status changed from new to closed
In 57565:
#20
@
10 months ago
- Component changed from General to Editor
- Keywords has-unit-tests needs-dev-note added
- Milestone changed from Awaiting Review to 6.5
- Version set to trunk
10 months ago
#21
Committed with https://core.trac.wordpress.org/changeset/57565.
#22
@
10 months ago
- Summary changed from Support module metadata in block.json to Editor: Support module metadata in block.json
https://core.trac.wordpress.org/changeset/57269 added the Modules API.