From aaed95bee8605d48df9bfee7f175354c35251714 Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Mon, 9 Jun 2025 14:16:39 +0530 Subject: [PATCH 1/8] doc: Update block-attributes README.md with role attribute --- .../block-api/block-attributes.md | 76 +++++++++++++------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/docs/reference-guides/block-api/block-attributes.md b/docs/reference-guides/block-api/block-attributes.md index 544f35593106f1..4709d05cdf57b6 100644 --- a/docs/reference-guides/block-api/block-attributes.md +++ b/docs/reference-guides/block-api/block-attributes.md @@ -25,7 +25,7 @@ _Example_: Attributes object defining three attributes - `url`, `title`, and `si } ``` -When a block is parsed this definition will be used to extract data from the block content. Anything that matches will be available to your block through the `attributes` prop. +When a block is parsed this definition will be used to extract data from the block content. Anything that matches will be available to your block through the `attributes` prop. This parsing process can be summarized as: @@ -37,8 +37,11 @@ _Example_: Attributes available in the `edit` and function, using the above attr ```js function YourBlockEdit( { attributes } ) { return ( -

URL is { attributes.url }, title is { attributes.title }, and size is { attributes.size }.

- ) +

+ URL is { attributes.url }, title is { attributes.title }, and size + is { attributes.size }. +

+ ); } ``` @@ -52,9 +55,7 @@ _Example_: Example `save` function that contains the `url` attribute ```js function YourBlockSave( { attributes } ) { - return ( - - ) + return ; } ``` @@ -76,13 +77,13 @@ A `type` is required, unless an `enum` is provided. A `type` can be used with an The `type` field MUST be one of the following: -- `null` -- `boolean` -- `object` -- `array` -- `string` -- `integer` -- `number` (same as `integer`) +- `null` +- `boolean` +- `object` +- `array` +- `string` +- `integer` +- `number` (same as `integer`) Note that the validity of an `object` is determined by your `source`. For an example, see the `query` details below. @@ -95,7 +96,7 @@ _Example_: Example `enum`. ```js { size: { - enum: [ 'large', 'small', 'tiny' ] + enum: [ 'large', 'small', 'tiny' ]; } } ``` @@ -105,12 +106,13 @@ _Example_: Example `enum`. Attribute sources are used to define how the attribute values are extracted from saved post content. They provide a mechanism to map from the saved markup to a JavaScript representation of a block. The available `source` values are: -- `(no value)` - when no `source` is specified then data is stored in the block's [comment delimiter](/docs/explanations/architecture/key-concepts.md#data-attributes). -- `attribute` - data is stored in an HTML element attribute. -- `text` - data is stored in HTML text. -- `html` - data is stored in HTML. This is typically used by `RichText`. -- `query` - data is stored as an array of objects. -- `meta` - data is stored in post meta (deprecated). + +- `(no value)` - when no `source` is specified then data is stored in the block's [comment delimiter](/docs/explanations/architecture/key-concepts.md#data-attributes). +- `attribute` - data is stored in an HTML element attribute. +- `text` - data is stored in HTML text. +- `html` - data is stored in HTML. This is typically used by `RichText`. +- `query` - data is stored as an array of objects. +- `meta` - data is stored in post meta (deprecated). The `source` field is usually combined with a `selector` field. If no selector argument is specified, the source definition runs against the block's root node. If a selector argument is specified, it will run against the matching element(s) within the block. @@ -129,6 +131,7 @@ Use an `attribute` source to extract the value from an attribute in the markup. _Example_: Extract the `src` attribute from an image found in the block's markup. Saved content: + ```html
Block Content @@ -138,6 +141,7 @@ Saved content: ``` Attribute definition: + ```js { url: { @@ -150,6 +154,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "url": "https://lorempixel.com/1200/800/" } ``` @@ -159,6 +164,7 @@ Most attributes from markup will be of type `string`. Numeric attributes in HTML _Example_: Extract the `width` attribute from an image found in the block's markup. Saved content: + ```html
Block Content @@ -168,6 +174,7 @@ Saved content: ``` Attribute definition: + ```js { width: { @@ -180,6 +187,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "width": "50" } ``` @@ -189,6 +197,7 @@ The only exception is when checking for the existence of an attribute (for examp _Example_: Extract the `disabled` attribute from a button found in the block's markup. Saved content: + ```html
Block Content @@ -198,6 +207,7 @@ Saved content: ``` Attribute definition: + ```js { disabled: { @@ -210,6 +220,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "disabled": true } ``` @@ -221,6 +232,7 @@ Use `text` to extract the inner text from markup. Note that HTML is returned acc _Example_: Extract the `content` attribute from a figcaption element found in the block's markup. Saved content: + ```html
@@ -230,6 +242,7 @@ Saved content: ``` Attribute definition: + ```js { content: { @@ -241,6 +254,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "content": "The inner text of the figcaption element" } ``` @@ -250,6 +264,7 @@ Another example, using `text` as the source, and using `.my-content` class as th _Example_: Extract the `content` attribute from an element with `.my-content` class found in the block's markup. Saved content: + ```html
@@ -259,6 +274,7 @@ Saved content: ``` Attribute definition: + ```js { content: { @@ -270,6 +286,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "content": "The inner text of .my-content class" } ``` @@ -281,15 +298,19 @@ Use `html` to extract the inner HTML from markup. Note that text is returned acc _Example_: Extract the `content` attribute from a figcaption element found in the block's markup. Saved content: + ```html
-
The inner text of the figcaption element
+
+ The inner text of the figcaption element +
``` Attribute definition: + ```js { content: { @@ -301,6 +322,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "content": "The inner text of the figcaption element" } ``` @@ -314,6 +336,7 @@ The `query` field is effectively a nested block attributes definition. It is pos _Example_: Extract `src` and `alt` from each image element in the block's markup. Saved content: + ```html
large image @@ -322,6 +345,7 @@ Saved content: ``` Attribute definition: + ```js { images: { @@ -345,6 +369,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "images": [ @@ -363,6 +388,7 @@ Although attributes may be obtained from a post's meta, meta attribute sources a Attributes may be obtained from a post's meta rather than from the block's representation in saved post content. For this, an attribute is required to specify its corresponding meta key under the `meta` key. Attribute definition: + ```js { author: { @@ -385,7 +411,6 @@ edit( { attributes, setAttributes } ) { }, ``` - #### Considerations By default, a meta field will be excluded from a post object's meta. This can be circumvented by explicitly making the field visible: @@ -461,3 +486,10 @@ _Example_: Example `default` values. } } ``` + +## Role + +The `role` property designates an attribute as being of a particular conceptual type. This property can be applied to any attribute to provide semantic meaning about how the attribute should be handled. + +Use `content` to designate the attribute as user-editable content. Blocks with attributes marked as `content` may be enabled for privileged editing in special circumstances such as partially synced Patterns. +Use `local` to mark the attribute as temporary and non-persistable. Attributes marked as `local` are ignored by the Block Serializer and never saved to post content. From e0c349ecd052e401c7c20483fe619c26ed8998ce Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Mon, 9 Jun 2025 14:17:04 +0530 Subject: [PATCH 2/8] doc: Add example for role content --- .../reference-guides/block-api/block-attributes.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/reference-guides/block-api/block-attributes.md b/docs/reference-guides/block-api/block-attributes.md index 4709d05cdf57b6..3414a33cb0ccab 100644 --- a/docs/reference-guides/block-api/block-attributes.md +++ b/docs/reference-guides/block-api/block-attributes.md @@ -493,3 +493,17 @@ The `role` property designates an attribute as being of a particular conceptual Use `content` to designate the attribute as user-editable content. Blocks with attributes marked as `content` may be enabled for privileged editing in special circumstances such as partially synced Patterns. Use `local` to mark the attribute as temporary and non-persistable. Attributes marked as `local` are ignored by the Block Serializer and never saved to post content. + +_Example_: `content` role used by the paragraph block + +```js +{ + content: { + type: 'string', + source: 'html', + selector: 'p', + role: 'content', + } +} + +``` From 0dafb237f197f5179a6f2de9c876ad88a57abc0f Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Mon, 9 Jun 2025 14:17:37 +0530 Subject: [PATCH 3/8] doc: Add example of role local --- docs/reference-guides/block-api/block-attributes.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/reference-guides/block-api/block-attributes.md b/docs/reference-guides/block-api/block-attributes.md index 3414a33cb0ccab..8166e8f2835643 100644 --- a/docs/reference-guides/block-api/block-attributes.md +++ b/docs/reference-guides/block-api/block-attributes.md @@ -505,5 +505,15 @@ _Example_: `content` role used by the paragraph block role: 'content', } } +``` + +_Example_: `local` role used for temporary data. +```js +{ + blob: { + type: 'string', + role: 'local', + } +} ``` From e4549d67a3981312bf6eee89a2af39119851fd73 Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Mon, 9 Jun 2025 14:26:46 +0530 Subject: [PATCH 4/8] revert: Whitespace and new line changes --- .../block-api/block-attributes.md | 100 ++++-------------- 1 file changed, 22 insertions(+), 78 deletions(-) diff --git a/docs/reference-guides/block-api/block-attributes.md b/docs/reference-guides/block-api/block-attributes.md index 8166e8f2835643..544f35593106f1 100644 --- a/docs/reference-guides/block-api/block-attributes.md +++ b/docs/reference-guides/block-api/block-attributes.md @@ -25,7 +25,7 @@ _Example_: Attributes object defining three attributes - `url`, `title`, and `si } ``` -When a block is parsed this definition will be used to extract data from the block content. Anything that matches will be available to your block through the `attributes` prop. +When a block is parsed this definition will be used to extract data from the block content. Anything that matches will be available to your block through the `attributes` prop. This parsing process can be summarized as: @@ -37,11 +37,8 @@ _Example_: Attributes available in the `edit` and function, using the above attr ```js function YourBlockEdit( { attributes } ) { return ( -

- URL is { attributes.url }, title is { attributes.title }, and size - is { attributes.size }. -

- ); +

URL is { attributes.url }, title is { attributes.title }, and size is { attributes.size }.

+ ) } ``` @@ -55,7 +52,9 @@ _Example_: Example `save` function that contains the `url` attribute ```js function YourBlockSave( { attributes } ) { - return ; + return ( + + ) } ``` @@ -77,13 +76,13 @@ A `type` is required, unless an `enum` is provided. A `type` can be used with an The `type` field MUST be one of the following: -- `null` -- `boolean` -- `object` -- `array` -- `string` -- `integer` -- `number` (same as `integer`) +- `null` +- `boolean` +- `object` +- `array` +- `string` +- `integer` +- `number` (same as `integer`) Note that the validity of an `object` is determined by your `source`. For an example, see the `query` details below. @@ -96,7 +95,7 @@ _Example_: Example `enum`. ```js { size: { - enum: [ 'large', 'small', 'tiny' ]; + enum: [ 'large', 'small', 'tiny' ] } } ``` @@ -106,13 +105,12 @@ _Example_: Example `enum`. Attribute sources are used to define how the attribute values are extracted from saved post content. They provide a mechanism to map from the saved markup to a JavaScript representation of a block. The available `source` values are: - -- `(no value)` - when no `source` is specified then data is stored in the block's [comment delimiter](/docs/explanations/architecture/key-concepts.md#data-attributes). -- `attribute` - data is stored in an HTML element attribute. -- `text` - data is stored in HTML text. -- `html` - data is stored in HTML. This is typically used by `RichText`. -- `query` - data is stored as an array of objects. -- `meta` - data is stored in post meta (deprecated). +- `(no value)` - when no `source` is specified then data is stored in the block's [comment delimiter](/docs/explanations/architecture/key-concepts.md#data-attributes). +- `attribute` - data is stored in an HTML element attribute. +- `text` - data is stored in HTML text. +- `html` - data is stored in HTML. This is typically used by `RichText`. +- `query` - data is stored as an array of objects. +- `meta` - data is stored in post meta (deprecated). The `source` field is usually combined with a `selector` field. If no selector argument is specified, the source definition runs against the block's root node. If a selector argument is specified, it will run against the matching element(s) within the block. @@ -131,7 +129,6 @@ Use an `attribute` source to extract the value from an attribute in the markup. _Example_: Extract the `src` attribute from an image found in the block's markup. Saved content: - ```html
Block Content @@ -141,7 +138,6 @@ Saved content: ``` Attribute definition: - ```js { url: { @@ -154,7 +150,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "url": "https://lorempixel.com/1200/800/" } ``` @@ -164,7 +159,6 @@ Most attributes from markup will be of type `string`. Numeric attributes in HTML _Example_: Extract the `width` attribute from an image found in the block's markup. Saved content: - ```html
Block Content @@ -174,7 +168,6 @@ Saved content: ``` Attribute definition: - ```js { width: { @@ -187,7 +180,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "width": "50" } ``` @@ -197,7 +189,6 @@ The only exception is when checking for the existence of an attribute (for examp _Example_: Extract the `disabled` attribute from a button found in the block's markup. Saved content: - ```html
Block Content @@ -207,7 +198,6 @@ Saved content: ``` Attribute definition: - ```js { disabled: { @@ -220,7 +210,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "disabled": true } ``` @@ -232,7 +221,6 @@ Use `text` to extract the inner text from markup. Note that HTML is returned acc _Example_: Extract the `content` attribute from a figcaption element found in the block's markup. Saved content: - ```html
@@ -242,7 +230,6 @@ Saved content: ``` Attribute definition: - ```js { content: { @@ -254,7 +241,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "content": "The inner text of the figcaption element" } ``` @@ -264,7 +250,6 @@ Another example, using `text` as the source, and using `.my-content` class as th _Example_: Extract the `content` attribute from an element with `.my-content` class found in the block's markup. Saved content: - ```html
@@ -274,7 +259,6 @@ Saved content: ``` Attribute definition: - ```js { content: { @@ -286,7 +270,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "content": "The inner text of .my-content class" } ``` @@ -298,19 +281,15 @@ Use `html` to extract the inner HTML from markup. Note that text is returned acc _Example_: Extract the `content` attribute from a figcaption element found in the block's markup. Saved content: - ```html
-
- The inner text of the figcaption element -
+
The inner text of the figcaption element
``` Attribute definition: - ```js { content: { @@ -322,7 +301,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "content": "The inner text of the figcaption element" } ``` @@ -336,7 +314,6 @@ The `query` field is effectively a nested block attributes definition. It is pos _Example_: Extract `src` and `alt` from each image element in the block's markup. Saved content: - ```html
large image @@ -345,7 +322,6 @@ Saved content: ``` Attribute definition: - ```js { images: { @@ -369,7 +345,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "images": [ @@ -388,7 +363,6 @@ Although attributes may be obtained from a post's meta, meta attribute sources a Attributes may be obtained from a post's meta rather than from the block's representation in saved post content. For this, an attribute is required to specify its corresponding meta key under the `meta` key. Attribute definition: - ```js { author: { @@ -411,6 +385,7 @@ edit( { attributes, setAttributes } ) { }, ``` + #### Considerations By default, a meta field will be excluded from a post object's meta. This can be circumvented by explicitly making the field visible: @@ -486,34 +461,3 @@ _Example_: Example `default` values. } } ``` - -## Role - -The `role` property designates an attribute as being of a particular conceptual type. This property can be applied to any attribute to provide semantic meaning about how the attribute should be handled. - -Use `content` to designate the attribute as user-editable content. Blocks with attributes marked as `content` may be enabled for privileged editing in special circumstances such as partially synced Patterns. -Use `local` to mark the attribute as temporary and non-persistable. Attributes marked as `local` are ignored by the Block Serializer and never saved to post content. - -_Example_: `content` role used by the paragraph block - -```js -{ - content: { - type: 'string', - source: 'html', - selector: 'p', - role: 'content', - } -} -``` - -_Example_: `local` role used for temporary data. - -```js -{ - blob: { - type: 'string', - role: 'local', - } -} -``` From a18bbfb38fc892f11d4676bf449baa08fd7a6abf Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Mon, 9 Jun 2025 14:27:48 +0530 Subject: [PATCH 5/8] doc: Add role attribute related documentation and examples --- .../block-api/block-attributes.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/reference-guides/block-api/block-attributes.md b/docs/reference-guides/block-api/block-attributes.md index 544f35593106f1..722e1119d9e705 100644 --- a/docs/reference-guides/block-api/block-attributes.md +++ b/docs/reference-guides/block-api/block-attributes.md @@ -461,3 +461,34 @@ _Example_: Example `default` values. } } ``` + +## Role + +The `role` property designates an attribute as being of a particular conceptual type. This property can be applied to any attribute to provide semantic meaning about how the attribute should be handled. + +Use `content` to designate the attribute as user-editable content. Blocks with attributes marked as `content` may be enabled for privileged editing in special circumstances such as partially synced Patterns. +Use `local` to mark the attribute as temporary and non-persistable. Attributes marked as `local` are ignored by the Block Serializer and never saved to post content. + +_Example_: `content` role used by the paragraph block + +```js +{ + content: { + type: 'string', + source: 'html', + selector: 'p', + role: 'content', + } +} +``` + +_Example_: `local` role used for temporary data. + +```js +{ + blob: { + type: 'string', + role: 'local', + } +} +``` \ No newline at end of file From 97ea4a0a774c265e5a63b807a30748adb07ca323 Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Wed, 11 Jun 2025 10:07:50 +0530 Subject: [PATCH 6/8] chore: Edit block-attributes.md content portion --- docs/reference-guides/block-api/block-attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference-guides/block-api/block-attributes.md b/docs/reference-guides/block-api/block-attributes.md index 722e1119d9e705..29df583b647ba7 100644 --- a/docs/reference-guides/block-api/block-attributes.md +++ b/docs/reference-guides/block-api/block-attributes.md @@ -466,7 +466,7 @@ _Example_: Example `default` values. The `role` property designates an attribute as being of a particular conceptual type. This property can be applied to any attribute to provide semantic meaning about how the attribute should be handled. -Use `content` to designate the attribute as user-editable content. Blocks with attributes marked as `content` may be enabled for privileged editing in special circumstances such as partially synced Patterns. +Use `content` to designate the attribute as user-editable content. Blocks with attributes marked as `content` may be enabled for privileged editing in special circumstances such as content only locking. Use `local` to mark the attribute as temporary and non-persistable. Attributes marked as `local` are ignored by the Block Serializer and never saved to post content. _Example_: `content` role used by the paragraph block From 69bf44783759e99f651669e93e5f9bb2ddae617d Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Wed, 11 Jun 2025 10:14:32 +0530 Subject: [PATCH 7/8] chore: Add ref to dev note --- .../block-api/block-attributes.md | 73 +++++++++++++------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/docs/reference-guides/block-api/block-attributes.md b/docs/reference-guides/block-api/block-attributes.md index 29df583b647ba7..36a8af06a8ee15 100644 --- a/docs/reference-guides/block-api/block-attributes.md +++ b/docs/reference-guides/block-api/block-attributes.md @@ -25,7 +25,7 @@ _Example_: Attributes object defining three attributes - `url`, `title`, and `si } ``` -When a block is parsed this definition will be used to extract data from the block content. Anything that matches will be available to your block through the `attributes` prop. +When a block is parsed this definition will be used to extract data from the block content. Anything that matches will be available to your block through the `attributes` prop. This parsing process can be summarized as: @@ -37,8 +37,11 @@ _Example_: Attributes available in the `edit` and function, using the above attr ```js function YourBlockEdit( { attributes } ) { return ( -

URL is { attributes.url }, title is { attributes.title }, and size is { attributes.size }.

- ) +

+ URL is { attributes.url }, title is { attributes.title }, and size + is { attributes.size }. +

+ ); } ``` @@ -52,9 +55,7 @@ _Example_: Example `save` function that contains the `url` attribute ```js function YourBlockSave( { attributes } ) { - return ( - - ) + return ; } ``` @@ -76,13 +77,13 @@ A `type` is required, unless an `enum` is provided. A `type` can be used with an The `type` field MUST be one of the following: -- `null` -- `boolean` -- `object` -- `array` -- `string` -- `integer` -- `number` (same as `integer`) +- `null` +- `boolean` +- `object` +- `array` +- `string` +- `integer` +- `number` (same as `integer`) Note that the validity of an `object` is determined by your `source`. For an example, see the `query` details below. @@ -95,7 +96,7 @@ _Example_: Example `enum`. ```js { size: { - enum: [ 'large', 'small', 'tiny' ] + enum: [ 'large', 'small', 'tiny' ]; } } ``` @@ -105,12 +106,13 @@ _Example_: Example `enum`. Attribute sources are used to define how the attribute values are extracted from saved post content. They provide a mechanism to map from the saved markup to a JavaScript representation of a block. The available `source` values are: -- `(no value)` - when no `source` is specified then data is stored in the block's [comment delimiter](/docs/explanations/architecture/key-concepts.md#data-attributes). -- `attribute` - data is stored in an HTML element attribute. -- `text` - data is stored in HTML text. -- `html` - data is stored in HTML. This is typically used by `RichText`. -- `query` - data is stored as an array of objects. -- `meta` - data is stored in post meta (deprecated). + +- `(no value)` - when no `source` is specified then data is stored in the block's [comment delimiter](/docs/explanations/architecture/key-concepts.md#data-attributes). +- `attribute` - data is stored in an HTML element attribute. +- `text` - data is stored in HTML text. +- `html` - data is stored in HTML. This is typically used by `RichText`. +- `query` - data is stored as an array of objects. +- `meta` - data is stored in post meta (deprecated). The `source` field is usually combined with a `selector` field. If no selector argument is specified, the source definition runs against the block's root node. If a selector argument is specified, it will run against the matching element(s) within the block. @@ -129,6 +131,7 @@ Use an `attribute` source to extract the value from an attribute in the markup. _Example_: Extract the `src` attribute from an image found in the block's markup. Saved content: + ```html
Block Content @@ -138,6 +141,7 @@ Saved content: ``` Attribute definition: + ```js { url: { @@ -150,6 +154,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "url": "https://lorempixel.com/1200/800/" } ``` @@ -159,6 +164,7 @@ Most attributes from markup will be of type `string`. Numeric attributes in HTML _Example_: Extract the `width` attribute from an image found in the block's markup. Saved content: + ```html
Block Content @@ -168,6 +174,7 @@ Saved content: ``` Attribute definition: + ```js { width: { @@ -180,6 +187,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "width": "50" } ``` @@ -189,6 +197,7 @@ The only exception is when checking for the existence of an attribute (for examp _Example_: Extract the `disabled` attribute from a button found in the block's markup. Saved content: + ```html
Block Content @@ -198,6 +207,7 @@ Saved content: ``` Attribute definition: + ```js { disabled: { @@ -210,6 +220,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "disabled": true } ``` @@ -221,6 +232,7 @@ Use `text` to extract the inner text from markup. Note that HTML is returned acc _Example_: Extract the `content` attribute from a figcaption element found in the block's markup. Saved content: + ```html
@@ -230,6 +242,7 @@ Saved content: ``` Attribute definition: + ```js { content: { @@ -241,6 +254,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "content": "The inner text of the figcaption element" } ``` @@ -250,6 +264,7 @@ Another example, using `text` as the source, and using `.my-content` class as th _Example_: Extract the `content` attribute from an element with `.my-content` class found in the block's markup. Saved content: + ```html
@@ -259,6 +274,7 @@ Saved content: ``` Attribute definition: + ```js { content: { @@ -270,6 +286,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "content": "The inner text of .my-content class" } ``` @@ -281,15 +298,19 @@ Use `html` to extract the inner HTML from markup. Note that text is returned acc _Example_: Extract the `content` attribute from a figcaption element found in the block's markup. Saved content: + ```html
-
The inner text of the figcaption element
+
+ The inner text of the figcaption element +
``` Attribute definition: + ```js { content: { @@ -301,6 +322,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "content": "The inner text of the figcaption element" } ``` @@ -314,6 +336,7 @@ The `query` field is effectively a nested block attributes definition. It is pos _Example_: Extract `src` and `alt` from each image element in the block's markup. Saved content: + ```html
large image @@ -322,6 +345,7 @@ Saved content: ``` Attribute definition: + ```js { images: { @@ -345,6 +369,7 @@ Attribute definition: ``` Attribute available in the block: + ```js { "images": [ @@ -363,6 +388,7 @@ Although attributes may be obtained from a post's meta, meta attribute sources a Attributes may be obtained from a post's meta rather than from the block's representation in saved post content. For this, an attribute is required to specify its corresponding meta key under the `meta` key. Attribute definition: + ```js { author: { @@ -385,7 +411,6 @@ edit( { attributes, setAttributes } ) { }, ``` - #### Considerations By default, a meta field will be excluded from a post object's meta. This can be circumvented by explicitly making the field visible: @@ -491,4 +516,6 @@ _Example_: `local` role used for temporary data. role: 'local', } } -``` \ No newline at end of file +``` + +Learn more in the [WordPress 6.7 dev note](https://make.wordpress.org/core/2024/10/20/miscellaneous-block-editor-changes-in-wordpress-6-7/#stabilized-role-property-for-block-attributes). From 5a991866b28d0fbbbbcbf190f5b329686acfbf13 Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Wed, 11 Jun 2025 10:17:46 +0530 Subject: [PATCH 8/8] revert: Extra whitespace and formating changes --- .../block-api/block-attributes.md | 71 ++++++------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/docs/reference-guides/block-api/block-attributes.md b/docs/reference-guides/block-api/block-attributes.md index 36a8af06a8ee15..52f4a8709f1f05 100644 --- a/docs/reference-guides/block-api/block-attributes.md +++ b/docs/reference-guides/block-api/block-attributes.md @@ -25,7 +25,7 @@ _Example_: Attributes object defining three attributes - `url`, `title`, and `si } ``` -When a block is parsed this definition will be used to extract data from the block content. Anything that matches will be available to your block through the `attributes` prop. +When a block is parsed this definition will be used to extract data from the block content. Anything that matches will be available to your block through the `attributes` prop. This parsing process can be summarized as: @@ -37,11 +37,8 @@ _Example_: Attributes available in the `edit` and function, using the above attr ```js function YourBlockEdit( { attributes } ) { return ( -

- URL is { attributes.url }, title is { attributes.title }, and size - is { attributes.size }. -

- ); +

URL is { attributes.url }, title is { attributes.title }, and size is { attributes.size }.

+ ) } ``` @@ -55,7 +52,9 @@ _Example_: Example `save` function that contains the `url` attribute ```js function YourBlockSave( { attributes } ) { - return ; + return ( + + ) } ``` @@ -77,13 +76,13 @@ A `type` is required, unless an `enum` is provided. A `type` can be used with an The `type` field MUST be one of the following: -- `null` -- `boolean` -- `object` -- `array` -- `string` -- `integer` -- `number` (same as `integer`) +- `null` +- `boolean` +- `object` +- `array` +- `string` +- `integer` +- `number` (same as `integer`) Note that the validity of an `object` is determined by your `source`. For an example, see the `query` details below. @@ -96,7 +95,7 @@ _Example_: Example `enum`. ```js { size: { - enum: [ 'large', 'small', 'tiny' ]; + enum: [ 'large', 'small', 'tiny' ] } } ``` @@ -106,13 +105,12 @@ _Example_: Example `enum`. Attribute sources are used to define how the attribute values are extracted from saved post content. They provide a mechanism to map from the saved markup to a JavaScript representation of a block. The available `source` values are: - -- `(no value)` - when no `source` is specified then data is stored in the block's [comment delimiter](/docs/explanations/architecture/key-concepts.md#data-attributes). -- `attribute` - data is stored in an HTML element attribute. -- `text` - data is stored in HTML text. -- `html` - data is stored in HTML. This is typically used by `RichText`. -- `query` - data is stored as an array of objects. -- `meta` - data is stored in post meta (deprecated). +- `(no value)` - when no `source` is specified then data is stored in the block's [comment delimiter](/docs/explanations/architecture/key-concepts.md#data-attributes). +- `attribute` - data is stored in an HTML element attribute. +- `text` - data is stored in HTML text. +- `html` - data is stored in HTML. This is typically used by `RichText`. +- `query` - data is stored as an array of objects. +- `meta` - data is stored in post meta (deprecated). The `source` field is usually combined with a `selector` field. If no selector argument is specified, the source definition runs against the block's root node. If a selector argument is specified, it will run against the matching element(s) within the block. @@ -131,7 +129,6 @@ Use an `attribute` source to extract the value from an attribute in the markup. _Example_: Extract the `src` attribute from an image found in the block's markup. Saved content: - ```html
Block Content @@ -141,7 +138,6 @@ Saved content: ``` Attribute definition: - ```js { url: { @@ -154,7 +150,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "url": "https://lorempixel.com/1200/800/" } ``` @@ -164,7 +159,6 @@ Most attributes from markup will be of type `string`. Numeric attributes in HTML _Example_: Extract the `width` attribute from an image found in the block's markup. Saved content: - ```html
Block Content @@ -174,7 +168,6 @@ Saved content: ``` Attribute definition: - ```js { width: { @@ -187,7 +180,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "width": "50" } ``` @@ -197,7 +189,6 @@ The only exception is when checking for the existence of an attribute (for examp _Example_: Extract the `disabled` attribute from a button found in the block's markup. Saved content: - ```html
Block Content @@ -207,7 +198,6 @@ Saved content: ``` Attribute definition: - ```js { disabled: { @@ -220,7 +210,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "disabled": true } ``` @@ -232,7 +221,6 @@ Use `text` to extract the inner text from markup. Note that HTML is returned acc _Example_: Extract the `content` attribute from a figcaption element found in the block's markup. Saved content: - ```html
@@ -242,7 +230,6 @@ Saved content: ``` Attribute definition: - ```js { content: { @@ -254,7 +241,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "content": "The inner text of the figcaption element" } ``` @@ -264,7 +250,6 @@ Another example, using `text` as the source, and using `.my-content` class as th _Example_: Extract the `content` attribute from an element with `.my-content` class found in the block's markup. Saved content: - ```html
@@ -274,7 +259,6 @@ Saved content: ``` Attribute definition: - ```js { content: { @@ -286,7 +270,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "content": "The inner text of .my-content class" } ``` @@ -298,19 +281,15 @@ Use `html` to extract the inner HTML from markup. Note that text is returned acc _Example_: Extract the `content` attribute from a figcaption element found in the block's markup. Saved content: - ```html
-
- The inner text of the figcaption element -
+
The inner text of the figcaption element
``` Attribute definition: - ```js { content: { @@ -322,7 +301,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "content": "The inner text of the figcaption element" } ``` @@ -336,7 +314,6 @@ The `query` field is effectively a nested block attributes definition. It is pos _Example_: Extract `src` and `alt` from each image element in the block's markup. Saved content: - ```html
large image @@ -345,7 +322,6 @@ Saved content: ``` Attribute definition: - ```js { images: { @@ -369,7 +345,6 @@ Attribute definition: ``` Attribute available in the block: - ```js { "images": [ @@ -388,7 +363,6 @@ Although attributes may be obtained from a post's meta, meta attribute sources a Attributes may be obtained from a post's meta rather than from the block's representation in saved post content. For this, an attribute is required to specify its corresponding meta key under the `meta` key. Attribute definition: - ```js { author: { @@ -411,6 +385,7 @@ edit( { attributes, setAttributes } ) { }, ``` + #### Considerations By default, a meta field will be excluded from a post object's meta. This can be circumvented by explicitly making the field visible: @@ -518,4 +493,4 @@ _Example_: `local` role used for temporary data. } ``` -Learn more in the [WordPress 6.7 dev note](https://make.wordpress.org/core/2024/10/20/miscellaneous-block-editor-changes-in-wordpress-6-7/#stabilized-role-property-for-block-attributes). +Learn more in the [WordPress 6.7 dev note](https://make.wordpress.org/core/2024/10/20/miscellaneous-block-editor-changes-in-wordpress-6-7/#stabilized-role-property-for-block-attributes). \ No newline at end of file