From c5594d14a9777f1ba73212efb897cf85f35e09bc Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 14 Sep 2022 14:46:45 +0200 Subject: [PATCH] Docs: Inlude information about multiple scripts support added in WordPress 6.1 --- .../block-api/block-metadata.md | 24 +++++++++------- schemas/json/block.json | 28 ++++++++++++++++--- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/docs/reference-guides/block-api/block-metadata.md b/docs/reference-guides/block-api/block-metadata.md index bf59213e2696b8..e835db50c5e286 100644 --- a/docs/reference-guides/block-api/block-metadata.md +++ b/docs/reference-guides/block-api/block-metadata.md @@ -51,9 +51,9 @@ Starting in WordPress 5.8 release, we encourage using the `block.json` metadata ], "editorScript": "file:./index.js", "script": "file:./script.js", - "viewScript": "file:./view.js", + "viewScript": [ "file:./view.js", "example-shared-view-script" ], "editorStyle": "file:./index.css", - "style": "file:./style.css", + "style": [ "file:./style.css", "example-shared-style" ], "render": "file:./render.php" } ``` @@ -464,7 +464,7 @@ See the [the variations documentation](/docs/reference-guides/block-api/block-va ### Editor Script -- Type: `WPDefinedAsset` ([learn more](#wpdefinedasset)) +- Type: `WPDefinedAsset`|`WPDefinedAsset[]` ([learn more](#wpdefinedasset)) - Optional - Localized: No - Property: `editorScript` @@ -475,9 +475,11 @@ See the [the variations documentation](/docs/reference-guides/block-api/block-va Block type editor script definition. It will only be enqueued in the context of the editor. +_Note: An option to pass also an array of editor scripts exists since WordPress `6.1.0`._ + ### Script -- Type: `WPDefinedAsset` ([learn more](#wpdefinedasset)) +- Type: `WPDefinedAsset`|`WPDefinedAsset[]` ([learn more](#wpdefinedasset)) - Optional - Localized: No - Property: `script` @@ -488,6 +490,8 @@ Block type editor script definition. It will only be enqueued in the context of Block type frontend and editor script definition. It will be enqueued both in the editor and when viewing the content on the front of the site. +_Note: An option to pass also an array of scripts exists since WordPress `6.1.0`._ + ### View Script - Type: `WPDefinedAsset`|`WPDefinedAsset[]` ([learn more](#wpdefinedasset)) @@ -497,7 +501,7 @@ Block type frontend and editor script definition. It will be enqueued both in th - Since: `WordPress 5.9.0` ```json -{ "viewScript": "file:./view.js" } +{ "viewScript": [ "file:./view.js", "example-shared-view-script" ] } ``` Block type frontend script definition. It will be enqueued only when viewing the content on the front of the site. @@ -527,7 +531,7 @@ _Note: An option to pass also an array of editor styles exists since WordPress ` - Property: `style` ```json -{ "style": "file:./style.css" } +{ "style": [ "file:./style.css", "example-shared-style" ] } ``` Block type frontend and editor style definition. It will be enqueued both in the editor and when viewing the content on the front of the site. @@ -579,10 +583,10 @@ In `block.json`: ```json { "editorScript": "file:./index.js", - "script": "my-script-handle", - "viewScript": "file:./view.js", - "editorStyle": "my-editor-style-handle", - "style": [ "file:./style.css", "my-style-handle" ] + "script": "file:./script.js", + "viewScript": [ "file:./view.js", "example-shared-view-script" ], + "editorStyle": "file:./index.css", + "style": [ "file:./style.css", "example-shared-style" ] } ``` diff --git a/schemas/json/block.json b/schemas/json/block.json index 7553a564fe90ed..41a051182ec6d7 100644 --- a/schemas/json/block.json +++ b/schemas/json/block.json @@ -439,12 +439,32 @@ } }, "editorScript": { - "type": "string", - "description": "Block type editor script definition. It will only be enqueued in the context of the editor." + "description": "Block type editor script definition. It will only be enqueued in the context of the editor.", + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] }, "script": { - "type": "string", - "description": "Block type frontend and editor script definition. It will be enqueued both in the editor and when viewing the content on the front of the site." + "description": "Block type frontend and editor script definition. It will be enqueued both in the editor and when viewing the content on the front of the site.", + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] }, "viewScript": { "description": "Block type frontend script definition. It will be enqueued only when viewing the content on the front of the site.",