Skip to content
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

Blocks: Document changes to style and editorStyle in block.json #36218

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions docs/reference-guides/block-api/block-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ See the [the example documentation](/docs/reference-guides/block-api/block-regis

### Editor Script

- Type: `string` ([WPDefinedAsset](#WPDefinedAsset))
- Type: `WPDefinedAsset` ([learn more](#WPDefinedAsset))
- Optional
- Localized: No
- Property: `editorScript`
Expand All @@ -420,7 +420,7 @@ Block type editor script definition. It will only be enqueued in the context of

### Script

- Type: `string` ([WPDefinedAsset](#WPDefinedAsset))
- Type: `WPDefinedAsset` ([learn more](#WPDefinedAsset))
- Optional
- Localized: No
- Property: `script`
Expand All @@ -433,7 +433,7 @@ Block type frontend and editor script definition. It will be enqueued both in th

### View Script

- Type: `string` ([WPDefinedAsset](#WPDefinedAsset))
- Type: `WPDefinedAsset` ([learn more](#WPDefinedAsset))
- Optional
- Localized: No
- Property: `viewScript`
Expand All @@ -447,7 +447,7 @@ Block type frontend script definition. It will be enqueued only when viewing the

### Editor Style

- Type: `string` ([WPDefinedAsset](#WPDefinedAsset))
- Type: `WPDefinedAsset`|`WPDefinedAsset[]` ([learn more](#WPDefinedAsset))
- Optional
- Localized: No
- Property: `editorStyle`
Expand All @@ -458,9 +458,11 @@ Block type frontend script definition. It will be enqueued only when viewing the

Block type editor style definition. It will only be enqueued in the context of the editor.

_Note: An option to pass also an array of editor styles exists since WordPress `5.9.0`._

### Style

- Type: `string` ([WPDefinedAsset](#WPDefinedAsset))
- Type: `WPDefinedAsset`|`WPDefinedAsset[]` ([learn more](#WPDefinedAsset))
- Optional
- Localized: No
- Property: `style`
Expand All @@ -469,24 +471,29 @@ Block type editor style definition. It will only be enqueued in the context of t
{ "style": "file:./build/style.css" }
```

Block type frontend style definition. It will be enqueued both in the editor and when viewing the content on the front of the site.
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.

_Note: An option to pass also an array of styles exists since WordPress `5.9.0`._

## Assets

### `WPDefinedAsset`

The `WPDefinedAsset` type is a subtype of string, where the value represents a path to a JavaScript or CSS file relative to where `block.json` file is located. The path provided must be prefixed with `file:`. This approach is based on how npm handles [local paths](https://docs.npmjs.com/files/package.json#local-paths) for packages.

An alternative would be a script or style handle name referencing a registered asset using WordPress helpers.
An alternative would be a script or style handle name referencing an already registered asset using WordPress helpers.

**Example:**

In `block.json`:

```json
{
"editorScript": "file:./build/index.js",
"editorStyle": "my-editor-style-handle"
"editorScript": "file:./index.js",
"script": "my-script-handle",
"viewScript": "file:./view.js",
"editorStyle": "my-editor-style-handle",
"style": [ "file:./style.css", "my-style-handle" ]
}
```

Expand All @@ -505,6 +512,7 @@ The definition is stored inside separate PHP file which ends with `.asset.php` a
**Example:**

```
block.json
build/
├─ index.js
└─ index.asset.php
Expand Down
28 changes: 24 additions & 4 deletions schemas/json/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,32 @@
"description": "Block type frontend script definition. It will be enqueued only when viewing the content on the front of the site."
},
"editorStyle": {
"type": "string",
"description": "Block type editor style definition. It will only be enqueued in the context of the editor."
"description": "Block type editor style definition. It will only be enqueued in the context of the editor.",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"style": {
"type": "string",
"description": "Block type frontend style definition. It will be enqueued both in the editor and when viewing the content on the front of the site."
"description": "Block type frontend style 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"
}
}
]
}
},
"required": [ "name", "title" ],
Expand Down