From 06f70a387b2fa50b02aec7f6cc876eb9efe433ad Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Sep 2024 11:06:45 +0100 Subject: [PATCH 01/15] Update usages --- .../reference-guides/data/data-core-blocks.md | 13 +++++++ .../test/use-transformed.patterns.js | 6 ++-- .../components/block-switcher/test/utils.js | 6 ++-- packages/block-editor/src/store/selectors.js | 8 ++--- .../src/store/test/private-selectors.js | 4 +-- .../block-editor/src/store/test/selectors.js | 12 +++---- packages/block-library/src/audio/block.json | 8 ++--- packages/block-library/src/button/block.json | 10 +++--- .../block-library/src/categories/block.json | 2 +- packages/block-library/src/embed/block.json | 12 +++---- packages/block-library/src/file/block.json | 2 +- .../block-library/src/form-input/block.json | 4 +-- .../src/form-input/deprecated.js | 8 ++--- packages/block-library/src/heading/block.json | 2 +- .../block-library/src/heading/deprecated.js | 2 +- packages/block-library/src/image/block.json | 14 ++++---- .../block-library/src/image/deprecated.js | 36 +++++++++---------- .../block-library/src/list-item/block.json | 2 +- packages/block-library/src/list/block.json | 4 +-- packages/block-library/src/list/deprecated.js | 16 ++++----- .../block-library/src/media-text/block.json | 10 +++--- .../src/media-text/deprecated.js | 10 +++--- .../block-library/src/paragraph/block.json | 2 +- .../block-library/src/preformatted/block.json | 2 +- .../block-library/src/pullquote/block.json | 4 +-- .../block-library/src/pullquote/deprecated.js | 4 +-- packages/block-library/src/quote/block.json | 4 +-- .../block-library/src/quote/deprecated.js | 8 ++--- packages/block-library/src/search/block.json | 6 ++-- packages/block-library/src/verse/block.json | 2 +- .../block-library/src/verse/deprecated.js | 2 +- packages/block-library/src/video/block.json | 10 +++--- packages/blocks/src/api/serializer.js | 2 +- packages/blocks/src/api/test/serializer.js | 2 +- packages/blocks/src/api/test/utils.js | 6 ++-- packages/blocks/src/api/utils.js | 3 +- packages/blocks/src/store/selectors.js | 13 ++++--- .../core-data/src/test/entity-provider.js | 2 +- 38 files changed, 137 insertions(+), 126 deletions(-) diff --git a/docs/reference-guides/data/data-core-blocks.md b/docs/reference-guides/data/data-core-blocks.md index 084c9c1d7a5fb..121529ca334d2 100644 --- a/docs/reference-guides/data/data-core-blocks.md +++ b/docs/reference-guides/data/data-core-blocks.md @@ -660,6 +660,19 @@ _Returns_ - `boolean`: True if a block contains at least one child blocks with inserter support and false otherwise. +### hasContentRoleAttribute + +Determines if any of the block type's attributes have the content role attribute. + +_Parameters_ + +- _state_ `Object`: Data state. +- _blockTypeName_ `string`: Block type name. + +_Returns_ + +- `boolean`: Whether block type has content role attribute. + ### isMatchingSearchTerm Returns true if the block type by the given name or object value matches a search term, or false otherwise. diff --git a/packages/block-editor/src/components/block-switcher/test/use-transformed.patterns.js b/packages/block-editor/src/components/block-switcher/test/use-transformed.patterns.js index 05ce545667d46..4d63c76317479 100644 --- a/packages/block-editor/src/components/block-switcher/test/use-transformed.patterns.js +++ b/packages/block-editor/src/components/block-switcher/test/use-transformed.patterns.js @@ -20,15 +20,15 @@ describe( 'use-transformed-patterns', () => { }, content: { type: 'boolean', - __experimentalRole: 'content', + role: 'content', }, level: { type: 'number', - __experimentalRole: 'content', + role: 'content', }, color: { type: 'string', - __experimentalRole: 'other', + role: 'other', }, }, save() {}, diff --git a/packages/block-editor/src/components/block-switcher/test/utils.js b/packages/block-editor/src/components/block-switcher/test/utils.js index 38009601e1646..eafe5e8a4d937 100644 --- a/packages/block-editor/src/components/block-switcher/test/utils.js +++ b/packages/block-editor/src/components/block-switcher/test/utils.js @@ -18,15 +18,15 @@ describe( 'BlockSwitcher - utils', () => { }, content: { type: 'boolean', - __experimentalRole: 'content', + role: 'content', }, level: { type: 'number', - __experimentalRole: 'content', + role: 'content', }, color: { type: 'string', - __experimentalRole: 'other', + role: 'other', }, }, save() {}, diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 20d6627398886..bc6911315aa55 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -2479,7 +2479,7 @@ export const __experimentalGetPatternsByBlockTypes = createRegistrySelector( * Determines the items that appear in the available pattern transforms list. * * For now we only handle blocks without InnerBlocks and take into account - * the `__experimentalRole` property of blocks' attributes for the transformation. + * the `role` property of blocks' attributes for the transformation. * * We return the first set of possible eligible block patterns, * by checking the `blockTypes` property. We still have to recurse through @@ -2501,7 +2501,7 @@ export const __experimentalGetPatternTransformItems = createRegistrySelector( } /** * For now we only handle blocks without InnerBlocks and take into account - * the `__experimentalRole` property of blocks' attributes for the transformation. + * the `role` property of blocks' attributes for the transformation. * Note that the blocks have been retrieved through `getBlock`, which doesn't * return the inner blocks of an inner block controller, so we still need * to check for this case too. @@ -3007,9 +3007,7 @@ export const getBlockEditingMode = createRegistrySelector( // This "flattens" the sections tree. const name = getBlockName( state, clientId ); const isContent = - select( blocksStore ).__experimentalHasContentRoleAttribute( - name - ); + select( blocksStore ).hasContentRoleAttribute( name ); return isContent ? 'contentOnly' : 'disabled'; } diff --git a/packages/block-editor/src/store/test/private-selectors.js b/packages/block-editor/src/store/test/private-selectors.js index 5f427e79cf699..cbb75daa4baaa 100644 --- a/packages/block-editor/src/store/test/private-selectors.js +++ b/packages/block-editor/src/store/test/private-selectors.js @@ -124,10 +124,10 @@ describe( 'private selectors', () => { blockEditingModes: new Map( [] ), }; - const __experimentalHasContentRoleAttribute = jest.fn( () => false ); + const hasContentRoleAttribute = jest.fn( () => false ); getBlockEditingMode.registry = { select: jest.fn( () => ( { - __experimentalHasContentRoleAttribute, + hasContentRoleAttribute, } ) ), }; diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index 2895f6573dc54..ec0e3be6d7801 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -4475,13 +4475,11 @@ describe( 'getBlockEditingMode', () => { }, }; - const __experimentalHasContentRoleAttribute = jest.fn( ( name ) => { - // consider paragraphs as content blocks. - return name === 'core/p'; - } ); + const hasContentRoleAttribute = jest.fn( () => false ); + getBlockEditingMode.registry = { select: jest.fn( () => ( { - __experimentalHasContentRoleAttribute, + hasContentRoleAttribute, } ) ), }; @@ -4586,7 +4584,7 @@ describe( 'getBlockEditingMode', () => { }, }, }; - __experimentalHasContentRoleAttribute.mockReturnValueOnce( false ); + hasContentRoleAttribute.mockReturnValueOnce( false ); expect( getBlockEditingMode( state, 'b3247f75-fd94-4fef-97f9-5bfd162cc416' ) ).toBe( 'disabled' ); @@ -4602,7 +4600,7 @@ describe( 'getBlockEditingMode', () => { }, }, }; - __experimentalHasContentRoleAttribute.mockReturnValueOnce( true ); + hasContentRoleAttribute.mockReturnValueOnce( true ); expect( getBlockEditingMode( state, 'b3247f75-fd94-4fef-97f9-5bfd162cc416' ) ).toBe( 'contentOnly' ); diff --git a/packages/block-library/src/audio/block.json b/packages/block-library/src/audio/block.json index bee2ff6d534a7..9b77efee23cce 100644 --- a/packages/block-library/src/audio/block.json +++ b/packages/block-library/src/audio/block.json @@ -10,24 +10,24 @@ "attributes": { "blob": { "type": "string", - "__experimentalRole": "local" + "role": "local" }, "src": { "type": "string", "source": "attribute", "selector": "audio", "attribute": "src", - "__experimentalRole": "content" + "role": "content" }, "caption": { "type": "rich-text", "source": "rich-text", "selector": "figcaption", - "__experimentalRole": "content" + "role": "content" }, "id": { "type": "number", - "__experimentalRole": "content" + "role": "content" }, "autoplay": { "type": "boolean", diff --git a/packages/block-library/src/button/block.json b/packages/block-library/src/button/block.json index d0f90b93467c9..2c1c05baa20dd 100644 --- a/packages/block-library/src/button/block.json +++ b/packages/block-library/src/button/block.json @@ -26,34 +26,34 @@ "source": "attribute", "selector": "a", "attribute": "href", - "__experimentalRole": "content" + "role": "content" }, "title": { "type": "string", "source": "attribute", "selector": "a,button", "attribute": "title", - "__experimentalRole": "content" + "role": "content" }, "text": { "type": "rich-text", "source": "rich-text", "selector": "a,button", - "__experimentalRole": "content" + "role": "content" }, "linkTarget": { "type": "string", "source": "attribute", "selector": "a", "attribute": "target", - "__experimentalRole": "content" + "role": "content" }, "rel": { "type": "string", "source": "attribute", "selector": "a", "attribute": "rel", - "__experimentalRole": "content" + "role": "content" }, "placeholder": { "type": "string" diff --git a/packages/block-library/src/categories/block.json b/packages/block-library/src/categories/block.json index bfd8461f8eda4..3609bdf9ab97c 100644 --- a/packages/block-library/src/categories/block.json +++ b/packages/block-library/src/categories/block.json @@ -34,7 +34,7 @@ }, "label": { "type": "string", - "__experimentalRole": "content" + "role": "content" }, "showLabel": { "type": "boolean", diff --git a/packages/block-library/src/embed/block.json b/packages/block-library/src/embed/block.json index a42aafbab4b0b..5bfb63b0fa9e9 100644 --- a/packages/block-library/src/embed/block.json +++ b/packages/block-library/src/embed/block.json @@ -9,21 +9,21 @@ "attributes": { "url": { "type": "string", - "__experimentalRole": "content" + "role": "content" }, "caption": { "type": "rich-text", "source": "rich-text", "selector": "figcaption", - "__experimentalRole": "content" + "role": "content" }, "type": { "type": "string", - "__experimentalRole": "content" + "role": "content" }, "providerNameSlug": { "type": "string", - "__experimentalRole": "content" + "role": "content" }, "allowResponsive": { "type": "boolean", @@ -32,12 +32,12 @@ "responsive": { "type": "boolean", "default": false, - "__experimentalRole": "content" + "role": "content" }, "previewable": { "type": "boolean", "default": true, - "__experimentalRole": "content" + "role": "content" } }, "supports": { diff --git a/packages/block-library/src/file/block.json b/packages/block-library/src/file/block.json index 0526120c4dfc1..bf0082c576dd1 100644 --- a/packages/block-library/src/file/block.json +++ b/packages/block-library/src/file/block.json @@ -13,7 +13,7 @@ }, "blob": { "type": "string", - "__experimentalRole": "local" + "role": "local" }, "href": { "type": "string" diff --git a/packages/block-library/src/form-input/block.json b/packages/block-library/src/form-input/block.json index 53aa0be6744cb..386c90ac207ad 100644 --- a/packages/block-library/src/form-input/block.json +++ b/packages/block-library/src/form-input/block.json @@ -23,7 +23,7 @@ "default": "Label", "selector": ".wp-block-form-input__label-content", "source": "rich-text", - "__experimentalRole": "content" + "role": "content" }, "inlineLabel": { "type": "boolean", @@ -41,7 +41,7 @@ "selector": ".wp-block-form-input__input", "source": "attribute", "attribute": "placeholder", - "__experimentalRole": "content" + "role": "content" }, "value": { "type": "string", diff --git a/packages/block-library/src/form-input/deprecated.js b/packages/block-library/src/form-input/deprecated.js index 451cc704a42d5..d974cca387a18 100644 --- a/packages/block-library/src/form-input/deprecated.js +++ b/packages/block-library/src/form-input/deprecated.js @@ -41,7 +41,7 @@ const v2 = { default: 'Label', selector: '.wp-block-form-input__label-content', source: 'html', - __experimentalRole: 'content', + role: 'content', }, inlineLabel: { type: 'boolean', @@ -59,7 +59,7 @@ const v2 = { selector: '.wp-block-form-input__input', source: 'attribute', attribute: 'placeholder', - __experimentalRole: 'content', + role: 'content', }, value: { type: 'string', @@ -155,7 +155,7 @@ const v1 = { default: 'Label', selector: '.wp-block-form-input__label-content', source: 'html', - __experimentalRole: 'content', + role: 'content', }, inlineLabel: { type: 'boolean', @@ -173,7 +173,7 @@ const v1 = { selector: '.wp-block-form-input__input', source: 'attribute', attribute: 'placeholder', - __experimentalRole: 'content', + role: 'content', }, value: { type: 'string', diff --git a/packages/block-library/src/heading/block.json b/packages/block-library/src/heading/block.json index 6e43a18cfba45..2276bcbbb5017 100644 --- a/packages/block-library/src/heading/block.json +++ b/packages/block-library/src/heading/block.json @@ -15,7 +15,7 @@ "type": "rich-text", "source": "rich-text", "selector": "h1,h2,h3,h4,h5,h6", - "__experimentalRole": "content" + "role": "content" }, "level": { "type": "number", diff --git a/packages/block-library/src/heading/deprecated.js b/packages/block-library/src/heading/deprecated.js index a97415712bf07..76b175ac44fc4 100644 --- a/packages/block-library/src/heading/deprecated.js +++ b/packages/block-library/src/heading/deprecated.js @@ -259,7 +259,7 @@ const v5 = { source: 'html', selector: 'h1,h2,h3,h4,h5,h6', default: '', - __experimentalRole: 'content', + role: 'content', }, level: { type: 'number', diff --git a/packages/block-library/src/image/block.json b/packages/block-library/src/image/block.json index 6417879164a22..f441a6e893290 100644 --- a/packages/block-library/src/image/block.json +++ b/packages/block-library/src/image/block.json @@ -11,14 +11,14 @@ "attributes": { "blob": { "type": "string", - "__experimentalRole": "local" + "role": "local" }, "url": { "type": "string", "source": "attribute", "selector": "img", "attribute": "src", - "__experimentalRole": "content" + "role": "content" }, "alt": { "type": "string", @@ -26,13 +26,13 @@ "selector": "img", "attribute": "alt", "default": "", - "__experimentalRole": "content" + "role": "content" }, "caption": { "type": "rich-text", "source": "rich-text", "selector": "figcaption", - "__experimentalRole": "content" + "role": "content" }, "lightbox": { "type": "object", @@ -45,14 +45,14 @@ "source": "attribute", "selector": "img", "attribute": "title", - "__experimentalRole": "content" + "role": "content" }, "href": { "type": "string", "source": "attribute", "selector": "figure > a", "attribute": "href", - "__experimentalRole": "content" + "role": "content" }, "rel": { "type": "string", @@ -68,7 +68,7 @@ }, "id": { "type": "number", - "__experimentalRole": "content" + "role": "content" }, "width": { "type": "string" diff --git a/packages/block-library/src/image/deprecated.js b/packages/block-library/src/image/deprecated.js index 135463a377131..6c1db75c5e2aa 100644 --- a/packages/block-library/src/image/deprecated.js +++ b/packages/block-library/src/image/deprecated.js @@ -559,7 +559,7 @@ const v6 = { source: 'attribute', selector: 'img', attribute: 'src', - __experimentalRole: 'content', + role: 'content', }, alt: { type: 'string', @@ -567,27 +567,27 @@ const v6 = { selector: 'img', attribute: 'alt', default: '', - __experimentalRole: 'content', + role: 'content', }, caption: { type: 'string', source: 'html', selector: 'figcaption', - __experimentalRole: 'content', + role: 'content', }, title: { type: 'string', source: 'attribute', selector: 'img', attribute: 'title', - __experimentalRole: 'content', + role: 'content', }, href: { type: 'string', source: 'attribute', selector: 'figure > a', attribute: 'href', - __experimentalRole: 'content', + role: 'content', }, rel: { type: 'string', @@ -603,7 +603,7 @@ const v6 = { }, id: { type: 'number', - __experimentalRole: 'content', + role: 'content', }, width: { type: 'number', @@ -762,7 +762,7 @@ const v7 = { source: 'attribute', selector: 'img', attribute: 'src', - __experimentalRole: 'content', + role: 'content', }, alt: { type: 'string', @@ -770,27 +770,27 @@ const v7 = { selector: 'img', attribute: 'alt', default: '', - __experimentalRole: 'content', + role: 'content', }, caption: { type: 'string', source: 'html', selector: 'figcaption', - __experimentalRole: 'content', + role: 'content', }, title: { type: 'string', source: 'attribute', selector: 'img', attribute: 'title', - __experimentalRole: 'content', + role: 'content', }, href: { type: 'string', source: 'attribute', selector: 'figure > a', attribute: 'href', - __experimentalRole: 'content', + role: 'content', }, rel: { type: 'string', @@ -806,7 +806,7 @@ const v7 = { }, id: { type: 'number', - __experimentalRole: 'content', + role: 'content', }, width: { type: 'number', @@ -962,7 +962,7 @@ const v8 = { source: 'attribute', selector: 'img', attribute: 'src', - __experimentalRole: 'content', + role: 'content', }, alt: { type: 'string', @@ -970,27 +970,27 @@ const v8 = { selector: 'img', attribute: 'alt', default: '', - __experimentalRole: 'content', + role: 'content', }, caption: { type: 'string', source: 'html', selector: 'figcaption', - __experimentalRole: 'content', + role: 'content', }, title: { type: 'string', source: 'attribute', selector: 'img', attribute: 'title', - __experimentalRole: 'content', + role: 'content', }, href: { type: 'string', source: 'attribute', selector: 'figure > a', attribute: 'href', - __experimentalRole: 'content', + role: 'content', }, rel: { type: 'string', @@ -1006,7 +1006,7 @@ const v8 = { }, id: { type: 'number', - __experimentalRole: 'content', + role: 'content', }, width: { type: 'string', diff --git a/packages/block-library/src/list-item/block.json b/packages/block-library/src/list-item/block.json index a4bf2351d9750..6eb30cfe6d0af 100644 --- a/packages/block-library/src/list-item/block.json +++ b/packages/block-library/src/list-item/block.json @@ -16,7 +16,7 @@ "type": "rich-text", "source": "rich-text", "selector": "li", - "__experimentalRole": "content" + "role": "content" } }, "supports": { diff --git a/packages/block-library/src/list/block.json b/packages/block-library/src/list/block.json index ea07a0eb542df..4a86def8d687b 100644 --- a/packages/block-library/src/list/block.json +++ b/packages/block-library/src/list/block.json @@ -12,7 +12,7 @@ "ordered": { "type": "boolean", "default": false, - "__experimentalRole": "content" + "role": "content" }, "values": { "type": "string", @@ -21,7 +21,7 @@ "multiline": "li", "__unstableMultilineWrapperTags": [ "ol", "ul" ], "default": "", - "__experimentalRole": "content" + "role": "content" }, "type": { "type": "string" diff --git a/packages/block-library/src/list/deprecated.js b/packages/block-library/src/list/deprecated.js index edb04dff27c90..13804b7040ed4 100644 --- a/packages/block-library/src/list/deprecated.js +++ b/packages/block-library/src/list/deprecated.js @@ -14,7 +14,7 @@ const v0 = { ordered: { type: 'boolean', default: false, - __experimentalRole: 'content', + role: 'content', }, values: { type: 'string', @@ -23,7 +23,7 @@ const v0 = { multiline: 'li', __unstableMultilineWrapperTags: [ 'ol', 'ul' ], default: '', - __experimentalRole: 'content', + role: 'content', }, type: { type: 'string', @@ -74,7 +74,7 @@ const v1 = { ordered: { type: 'boolean', default: false, - __experimentalRole: 'content', + role: 'content', }, values: { type: 'string', @@ -83,7 +83,7 @@ const v1 = { multiline: 'li', __unstableMultilineWrapperTags: [ 'ol', 'ul' ], default: '', - __experimentalRole: 'content', + role: 'content', }, type: { type: 'string', @@ -144,7 +144,7 @@ const v2 = { ordered: { type: 'boolean', default: false, - __experimentalRole: 'content', + role: 'content', }, values: { type: 'string', @@ -153,7 +153,7 @@ const v2 = { multiline: 'li', __unstableMultilineWrapperTags: [ 'ol', 'ul' ], default: '', - __experimentalRole: 'content', + role: 'content', }, type: { type: 'string', @@ -225,7 +225,7 @@ const v3 = { ordered: { type: 'boolean', default: false, - __experimentalRole: 'content', + role: 'content', }, values: { type: 'string', @@ -234,7 +234,7 @@ const v3 = { multiline: 'li', __unstableMultilineWrapperTags: [ 'ol', 'ul' ], default: '', - __experimentalRole: 'content', + role: 'content', }, type: { type: 'string', diff --git a/packages/block-library/src/media-text/block.json b/packages/block-library/src/media-text/block.json index 42384c0c4478e..0c2cfc4a14995 100644 --- a/packages/block-library/src/media-text/block.json +++ b/packages/block-library/src/media-text/block.json @@ -18,7 +18,7 @@ "selector": "figure img", "attribute": "alt", "default": "", - "__experimentalRole": "content" + "role": "content" }, "mediaPosition": { "type": "string", @@ -26,14 +26,14 @@ }, "mediaId": { "type": "number", - "__experimentalRole": "content" + "role": "content" }, "mediaUrl": { "type": "string", "source": "attribute", "selector": "figure video,figure img", "attribute": "src", - "__experimentalRole": "content" + "role": "content" }, "mediaLink": { "type": "string" @@ -52,7 +52,7 @@ "source": "attribute", "selector": "figure a", "attribute": "href", - "__experimentalRole": "content" + "role": "content" }, "rel": { "type": "string", @@ -68,7 +68,7 @@ }, "mediaType": { "type": "string", - "__experimentalRole": "content" + "role": "content" }, "mediaWidth": { "type": "number", diff --git a/packages/block-library/src/media-text/deprecated.js b/packages/block-library/src/media-text/deprecated.js index 54c6f863311ff..24f239a41ed29 100644 --- a/packages/block-library/src/media-text/deprecated.js +++ b/packages/block-library/src/media-text/deprecated.js @@ -172,29 +172,29 @@ const v6Attributes = { selector: 'figure img', attribute: 'alt', default: '', - __experimentalRole: 'content', + role: 'content', }, mediaId: { type: 'number', - __experimentalRole: 'content', + role: 'content', }, mediaUrl: { type: 'string', source: 'attribute', selector: 'figure video,figure img', attribute: 'src', - __experimentalRole: 'content', + role: 'content', }, href: { type: 'string', source: 'attribute', selector: 'figure a', attribute: 'href', - __experimentalRole: 'content', + role: 'content', }, mediaType: { type: 'string', - __experimentalRole: 'content', + role: 'content', }, }; diff --git a/packages/block-library/src/paragraph/block.json b/packages/block-library/src/paragraph/block.json index f16a7cf041144..7e004019cbf28 100644 --- a/packages/block-library/src/paragraph/block.json +++ b/packages/block-library/src/paragraph/block.json @@ -15,7 +15,7 @@ "type": "rich-text", "source": "rich-text", "selector": "p", - "__experimentalRole": "content" + "role": "content" }, "dropCap": { "type": "boolean", diff --git a/packages/block-library/src/preformatted/block.json b/packages/block-library/src/preformatted/block.json index a1726ee8b0d43..c25b8ce37093a 100644 --- a/packages/block-library/src/preformatted/block.json +++ b/packages/block-library/src/preformatted/block.json @@ -12,7 +12,7 @@ "source": "rich-text", "selector": "pre", "__unstablePreserveWhiteSpace": true, - "__experimentalRole": "content" + "role": "content" } }, "supports": { diff --git a/packages/block-library/src/pullquote/block.json b/packages/block-library/src/pullquote/block.json index 0935f9759668d..271bba74d0252 100644 --- a/packages/block-library/src/pullquote/block.json +++ b/packages/block-library/src/pullquote/block.json @@ -11,13 +11,13 @@ "type": "rich-text", "source": "rich-text", "selector": "p", - "__experimentalRole": "content" + "role": "content" }, "citation": { "type": "rich-text", "source": "rich-text", "selector": "cite", - "__experimentalRole": "content" + "role": "content" }, "textAlign": { "type": "string" diff --git a/packages/block-library/src/pullquote/deprecated.js b/packages/block-library/src/pullquote/deprecated.js index 6e6f49da91c6a..18e4799755078 100644 --- a/packages/block-library/src/pullquote/deprecated.js +++ b/packages/block-library/src/pullquote/deprecated.js @@ -75,14 +75,14 @@ const v5 = { source: 'html', selector: 'blockquote', multiline: 'p', - __experimentalRole: 'content', + role: 'content', }, citation: { type: 'string', source: 'html', selector: 'cite', default: '', - __experimentalRole: 'content', + role: 'content', }, textAlign: { type: 'string', diff --git a/packages/block-library/src/quote/block.json b/packages/block-library/src/quote/block.json index 0f9ec97422f64..2ae37f9f36f76 100644 --- a/packages/block-library/src/quote/block.json +++ b/packages/block-library/src/quote/block.json @@ -14,13 +14,13 @@ "selector": "blockquote", "multiline": "p", "default": "", - "__experimentalRole": "content" + "role": "content" }, "citation": { "type": "rich-text", "source": "rich-text", "selector": "cite", - "__experimentalRole": "content" + "role": "content" }, "textAlign": { "type": "string" diff --git a/packages/block-library/src/quote/deprecated.js b/packages/block-library/src/quote/deprecated.js index 77098b6e75313..4d3efd28e3a22 100644 --- a/packages/block-library/src/quote/deprecated.js +++ b/packages/block-library/src/quote/deprecated.js @@ -70,14 +70,14 @@ const v4 = { selector: 'blockquote', multiline: 'p', default: '', - __experimentalRole: 'content', + role: 'content', }, citation: { type: 'string', source: 'html', selector: 'cite', default: '', - __experimentalRole: 'content', + role: 'content', }, align: { type: 'string', @@ -138,14 +138,14 @@ const v3 = { selector: 'blockquote', multiline: 'p', default: '', - __experimentalRole: 'content', + role: 'content', }, citation: { type: 'string', source: 'html', selector: 'cite', default: '', - __experimentalRole: 'content', + role: 'content', }, align: { type: 'string', diff --git a/packages/block-library/src/search/block.json b/packages/block-library/src/search/block.json index dac4c6b488a97..c5af5a29d21be 100644 --- a/packages/block-library/src/search/block.json +++ b/packages/block-library/src/search/block.json @@ -10,7 +10,7 @@ "attributes": { "label": { "type": "string", - "__experimentalRole": "content" + "role": "content" }, "showLabel": { "type": "boolean", @@ -19,7 +19,7 @@ "placeholder": { "type": "string", "default": "", - "__experimentalRole": "content" + "role": "content" }, "width": { "type": "number" @@ -29,7 +29,7 @@ }, "buttonText": { "type": "string", - "__experimentalRole": "content" + "role": "content" }, "buttonPosition": { "type": "string", diff --git a/packages/block-library/src/verse/block.json b/packages/block-library/src/verse/block.json index 387ff3dfe1712..81cccd72965b1 100644 --- a/packages/block-library/src/verse/block.json +++ b/packages/block-library/src/verse/block.json @@ -13,7 +13,7 @@ "source": "rich-text", "selector": "pre", "__unstablePreserveWhiteSpace": true, - "__experimentalRole": "content" + "role": "content" }, "textAlign": { "type": "string" diff --git a/packages/block-library/src/verse/deprecated.js b/packages/block-library/src/verse/deprecated.js index 7e3c96bc80cd9..bd4edc46738c5 100644 --- a/packages/block-library/src/verse/deprecated.js +++ b/packages/block-library/src/verse/deprecated.js @@ -46,7 +46,7 @@ const v2 = { selector: 'pre', default: '', __unstablePreserveWhiteSpace: true, - __experimentalRole: 'content', + role: 'content', }, textAlign: { type: 'string', diff --git a/packages/block-library/src/video/block.json b/packages/block-library/src/video/block.json index 1d3dc75961e8f..d2dcd95365c3b 100644 --- a/packages/block-library/src/video/block.json +++ b/packages/block-library/src/video/block.json @@ -18,7 +18,7 @@ "type": "rich-text", "source": "rich-text", "selector": "figcaption", - "__experimentalRole": "content" + "role": "content" }, "controls": { "type": "boolean", @@ -29,7 +29,7 @@ }, "id": { "type": "number", - "__experimentalRole": "content" + "role": "content" }, "loop": { "type": "boolean", @@ -58,14 +58,14 @@ }, "blob": { "type": "string", - "__experimentalRole": "local" + "role": "local" }, "src": { "type": "string", "source": "attribute", "selector": "video", "attribute": "src", - "__experimentalRole": "content" + "role": "content" }, "playsInline": { "type": "boolean", @@ -74,7 +74,7 @@ "attribute": "playsinline" }, "tracks": { - "__experimentalRole": "content", + "role": "content", "type": "array", "items": { "type": "object" diff --git a/packages/blocks/src/api/serializer.js b/packages/blocks/src/api/serializer.js index 2e7246ce9584a..8a44e085e8aa0 100644 --- a/packages/blocks/src/api/serializer.js +++ b/packages/blocks/src/api/serializer.js @@ -238,7 +238,7 @@ export function getCommentAttributes( blockType, attributes ) { } // Ignore all local attributes - if ( attributeSchema.__experimentalRole === 'local' ) { + if ( attributeSchema.role === 'local' ) { return accumulator; } diff --git a/packages/blocks/src/api/test/serializer.js b/packages/blocks/src/api/test/serializer.js index 7fed23041daaa..3c1cbd6d1e74f 100644 --- a/packages/blocks/src/api/test/serializer.js +++ b/packages/blocks/src/api/test/serializer.js @@ -155,7 +155,7 @@ describe( 'block serializer', () => { attributes: { blob: { type: 'string', - __experimentalRole: 'local', + role: 'local', }, url: { type: 'string', diff --git a/packages/blocks/src/api/test/utils.js b/packages/blocks/src/api/test/utils.js index 9bfef69c4c142..1155404a681a5 100644 --- a/packages/blocks/src/api/test/utils.js +++ b/packages/blocks/src/api/test/utils.js @@ -318,15 +318,15 @@ describe( '__experimentalGetBlockAttributesNamesByRole', () => { }, content: { type: 'boolean', - __experimentalRole: 'content', + role: 'content', }, level: { type: 'number', - __experimentalRole: 'content', + role: 'content', }, color: { type: 'string', - __experimentalRole: 'other', + role: 'other', }, }, save: noop, diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index a68937586f927..839325e633d57 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -342,8 +342,7 @@ export function __experimentalGetBlockAttributesNamesByRole( name, role ) { return attributesNames; } return attributesNames.filter( - ( attributeName ) => - attributes[ attributeName ]?.__experimentalRole === role + ( attributeName ) => attributes[ attributeName ]?.role === role ); } diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index e97048e92b0c0..7fc0bbfaafe44 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -823,11 +823,14 @@ export const hasChildBlocksWithInserterSupport = ( state, blockName ) => { }; /** - * DO-NOT-USE in production. - * This selector is created for internal/experimental only usage and may be - * removed anytime without any warning, causing breakage on any plugin or theme invoking it. + * Determines if any of the block type's attributes have + * the content role attribute. + * + * @param {Object} state Data state. + * @param {string} blockTypeName Block type name. + * @return {boolean} Whether block type has content role attribute. */ -export const __experimentalHasContentRoleAttribute = createSelector( +export const hasContentRoleAttribute = createSelector( ( state, blockTypeName ) => { const blockType = getBlockType( state, blockTypeName ); if ( ! blockType ) { @@ -835,7 +838,7 @@ export const __experimentalHasContentRoleAttribute = createSelector( } return Object.entries( blockType.attributes ).some( - ( [ , { __experimentalRole } ] ) => __experimentalRole === 'content' + ( [ , { role } ] ) => role === 'content' ); }, ( state, blockTypeName ) => [ diff --git a/packages/core-data/src/test/entity-provider.js b/packages/core-data/src/test/entity-provider.js index 6b0b7bd5ef77a..4dc0d8a51663e 100644 --- a/packages/core-data/src/test/entity-provider.js +++ b/packages/core-data/src/test/entity-provider.js @@ -104,7 +104,7 @@ describe( 'useEntityBlockEditor', () => { source: 'html', selector: 'p', default: '', - __experimentalRole: 'content', + role: 'content', }, }, title: 'block title', From f3c53dcbf0c8f1f830dcb747041b8feabae020d2 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Sep 2024 11:08:31 +0100 Subject: [PATCH 02/15] Update related functions --- .../src/components/block-switcher/utils.js | 2 +- packages/blocks/README.md | 13 +++++++ packages/blocks/src/api/index.js | 2 +- packages/blocks/src/api/test/utils.js | 34 ++++++------------- packages/blocks/src/api/utils.js | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/packages/block-editor/src/components/block-switcher/utils.js b/packages/block-editor/src/components/block-switcher/utils.js index ebd95fc460e33..fb42db6df5a8f 100644 --- a/packages/block-editor/src/components/block-switcher/utils.js +++ b/packages/block-editor/src/components/block-switcher/utils.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { __experimentalGetBlockAttributesNamesByRole as getBlockAttributesNamesByRole } from '@wordpress/blocks'; +import { getBlockAttributesNamesByRole as getBlockAttributesNamesByRole } from '@wordpress/blocks'; /** * Try to find a matching block by a block's name in a provided diff --git a/packages/blocks/README.md b/packages/blocks/README.md index d724f986b0ca8..b607286f1e73c 100644 --- a/packages/blocks/README.md +++ b/packages/blocks/README.md @@ -102,6 +102,19 @@ _Returns_ - `Object`: All block attributes. +### getBlockAttributesNamesByRole + +Filter block attributes by `role` and return their names. + +_Parameters_ + +- _name_ `string`: Block attribute's name. +- _role_ `string`: The role of a block attribute. + +_Returns_ + +- `string[]`: The attribute names that have the provided role. + ### getBlockContent Given a block object, returns the Block's Inner HTML markup. diff --git a/packages/blocks/src/api/index.js b/packages/blocks/src/api/index.js index 803467cb2187e..0ef872b0bb00d 100644 --- a/packages/blocks/src/api/index.js +++ b/packages/blocks/src/api/index.js @@ -155,7 +155,7 @@ export { getBlockLabel as __experimentalGetBlockLabel, getAccessibleBlockLabel as __experimentalGetAccessibleBlockLabel, __experimentalSanitizeBlockAttributes, - __experimentalGetBlockAttributesNamesByRole, + getBlockAttributesNamesByRole, } from './utils'; // Templates are, in a general sense, a basic collection of block nodes with any diff --git a/packages/blocks/src/api/test/utils.js b/packages/blocks/src/api/test/utils.js index 1155404a681a5..ad76e89aafe5f 100644 --- a/packages/blocks/src/api/test/utils.js +++ b/packages/blocks/src/api/test/utils.js @@ -13,7 +13,7 @@ import { getAccessibleBlockLabel, getBlockLabel, __experimentalSanitizeBlockAttributes, - __experimentalGetBlockAttributesNamesByRole, + getBlockAttributesNamesByRole, } from '../utils'; const noop = () => {}; @@ -309,7 +309,7 @@ describe( 'sanitizeBlockAttributes', () => { } ); } ); -describe( '__experimentalGetBlockAttributesNamesByRole', () => { +describe( 'getBlockAttributesNamesByRole', () => { beforeAll( () => { registerBlockType( 'core/test-block-1', { attributes: { @@ -357,42 +357,28 @@ describe( '__experimentalGetBlockAttributesNamesByRole', () => { ].forEach( unregisterBlockType ); } ); it( 'should return empty array if block has no attributes', () => { - expect( - __experimentalGetBlockAttributesNamesByRole( 'core/test-block-3' ) - ).toEqual( [] ); + expect( getBlockAttributesNamesByRole( 'core/test-block-3' ) ).toEqual( + [] + ); } ); it( 'should return all attribute names if no role is provided', () => { - expect( - __experimentalGetBlockAttributesNamesByRole( 'core/test-block-1' ) - ).toEqual( + expect( getBlockAttributesNamesByRole( 'core/test-block-1' ) ).toEqual( expect.arrayContaining( [ 'align', 'content', 'level', 'color' ] ) ); } ); it( 'should return proper results with existing attributes and provided role', () => { expect( - __experimentalGetBlockAttributesNamesByRole( - 'core/test-block-1', - 'content' - ) + getBlockAttributesNamesByRole( 'core/test-block-1', 'content' ) ).toEqual( expect.arrayContaining( [ 'content', 'level' ] ) ); expect( - __experimentalGetBlockAttributesNamesByRole( - 'core/test-block-1', - 'other' - ) + getBlockAttributesNamesByRole( 'core/test-block-1', 'other' ) ).toEqual( [ 'color' ] ); expect( - __experimentalGetBlockAttributesNamesByRole( - 'core/test-block-1', - 'not-exists' - ) + getBlockAttributesNamesByRole( 'core/test-block-1', 'not-exists' ) ).toEqual( [] ); // A block with no `role` in any attributes. expect( - __experimentalGetBlockAttributesNamesByRole( - 'core/test-block-2', - 'content' - ) + getBlockAttributesNamesByRole( 'core/test-block-2', 'content' ) ).toEqual( [] ); } ); } ); diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index 839325e633d57..e18822c677212 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -332,7 +332,7 @@ export function __experimentalSanitizeBlockAttributes( name, attributes ) { * * @return {string[]} The attribute names that have the provided role. */ -export function __experimentalGetBlockAttributesNamesByRole( name, role ) { +export function getBlockAttributesNamesByRole( name, role ) { const attributes = getBlockType( name )?.attributes; if ( ! attributes ) { return []; From a9d3779cd320ae52742b4984da5a0975c1029edd Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Sep 2024 11:14:03 +0100 Subject: [PATCH 03/15] Remove unwanted alias --- packages/block-editor/src/components/block-switcher/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-switcher/utils.js b/packages/block-editor/src/components/block-switcher/utils.js index fb42db6df5a8f..49257a2126cbe 100644 --- a/packages/block-editor/src/components/block-switcher/utils.js +++ b/packages/block-editor/src/components/block-switcher/utils.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { getBlockAttributesNamesByRole as getBlockAttributesNamesByRole } from '@wordpress/blocks'; +import { getBlockAttributesNamesByRole } from '@wordpress/blocks'; /** * Try to find a matching block by a block's name in a provided From 9ce41a3d1b2898dcfa453ee01a2750079a4295e8 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Sep 2024 11:19:17 +0100 Subject: [PATCH 04/15] Properly deprecate the experimental method --- packages/blocks/src/store/selectors.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index 7fc0bbfaafe44..c2938f35bb0ec 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -8,6 +8,7 @@ import removeAccents from 'remove-accents'; */ import { createSelector } from '@wordpress/data'; import { RichTextData } from '@wordpress/rich-text'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -845,3 +846,12 @@ export const hasContentRoleAttribute = createSelector( state.blockTypes[ blockTypeName ]?.attributes, ] ); + +export const __experimentalHasContentRoleAttribute = ( ...args ) => { + deprecated( '__experimentalHasContentRoleAttribute', { + since: '6.7', + version: '6.8', + alternative: 'hasContentRoleAttribute', + } ); + return hasContentRoleAttribute( ...args ); +}; From 94a4734edb3a4a73d20c69bb60630f7409823570 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Sep 2024 11:24:49 +0100 Subject: [PATCH 05/15] Deprecate and ensure backwards compatibility --- packages/blocks/src/api/utils.js | 29 +++++++++++++++++++++++--- packages/blocks/src/store/selectors.js | 15 ++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index e18822c677212..ac09fa2ee31a0 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -12,6 +12,7 @@ import { Component, isValidElement } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { __unstableStripHTML as stripHTML } from '@wordpress/dom'; import { RichTextData } from '@wordpress/rich-text'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -341,11 +342,33 @@ export function getBlockAttributesNamesByRole( name, role ) { if ( ! role ) { return attributesNames; } - return attributesNames.filter( - ( attributeName ) => attributes[ attributeName ]?.role === role - ); + + return attributesNames.filter( ( attributeName ) => { + const attribute = attributes[ attributeName ]; + if ( attribute?.role === role ) { + return true; + } + if ( attribute?.__experimentalRole === role ) { + deprecated( '__experimentalRole attribute', { + since: '6.7', + version: '6.8', + alternative: 'role attribute', + } ); + return true; + } + return false; + } ); } +export const __experimentalGetBlockAttributesNamesByRole = ( ...args ) => { + deprecated( '__experimentalGetBlockAttributesNamesByRole', { + since: '6.7', + version: '6.8', + alternative: 'getBlockAttributesNamesByRole', + } ); + return getBlockAttributesNamesByRole( ...args ); +}; + /** * Return a new object with the specified keys omitted. * diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index c2938f35bb0ec..e46e7dbdf0dd1 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -839,7 +839,20 @@ export const hasContentRoleAttribute = createSelector( } return Object.entries( blockType.attributes ).some( - ( [ , { role } ] ) => role === 'content' + ( [ , { role, __experimentalRole } ] ) => { + if ( role === 'content' ) { + return true; + } + if ( __experimentalRole === 'content' ) { + deprecated( '__experimentalRole attribute', { + since: '6.7', + version: '6.8', + alternative: 'role attribute', + } ); + return true; + } + return false; + } ); }, ( state, blockTypeName ) => [ From 8b6bab08c66552d4a4c14bd5663cbab20dc167cd Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 20 Sep 2024 09:44:35 +0100 Subject: [PATCH 06/15] Make selector private --- .../reference-guides/data/data-core-blocks.md | 13 ------- packages/block-editor/src/store/selectors.js | 5 ++- .../blocks/src/store/private-selectors.js | 38 ++++++++++++++++++ packages/blocks/src/store/selectors.js | 39 +------------------ 4 files changed, 43 insertions(+), 52 deletions(-) diff --git a/docs/reference-guides/data/data-core-blocks.md b/docs/reference-guides/data/data-core-blocks.md index 121529ca334d2..084c9c1d7a5fb 100644 --- a/docs/reference-guides/data/data-core-blocks.md +++ b/docs/reference-guides/data/data-core-blocks.md @@ -660,19 +660,6 @@ _Returns_ - `boolean`: True if a block contains at least one child blocks with inserter support and false otherwise. -### hasContentRoleAttribute - -Determines if any of the block type's attributes have the content role attribute. - -_Parameters_ - -- _state_ `Object`: Data state. -- _blockTypeName_ `string`: Block type name. - -_Returns_ - -- `boolean`: Whether block type has content role attribute. - ### isMatchingSearchTerm Returns true if the block type by the given name or object value matches a search term, or false otherwise. diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index bc6911315aa55..e169ab32481c8 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -3006,8 +3006,9 @@ export const getBlockEditingMode = createRegistrySelector( // The rest of the blocks depend on whether they are content blocks or not. // This "flattens" the sections tree. const name = getBlockName( state, clientId ); - const isContent = - select( blocksStore ).hasContentRoleAttribute( name ); + const isContent = unlock( + select( blocksStore ) + ).hasContentRoleAttribute( name ); return isContent ? 'contentOnly' : 'disabled'; } diff --git a/packages/blocks/src/store/private-selectors.js b/packages/blocks/src/store/private-selectors.js index 4cded8268ae97..83b3685249ba2 100644 --- a/packages/blocks/src/store/private-selectors.js +++ b/packages/blocks/src/store/private-selectors.js @@ -2,6 +2,7 @@ * WordPress dependencies */ import { createSelector } from '@wordpress/data'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -209,3 +210,40 @@ export function getAllBlockBindingsSources( state ) { export function getBlockBindingsSource( state, sourceName ) { return state.blockBindingsSources[ sourceName ]; } + +/** + * Determines if any of the block type's attributes have + * the content role attribute. + * + * @param {Object} state Data state. + * @param {string} blockTypeName Block type name. + * @return {boolean} Whether block type has content role attribute. + */ +export const hasContentRoleAttribute = createSelector( + ( state, blockTypeName ) => { + const blockType = getBlockType( state, blockTypeName ); + if ( ! blockType ) { + return false; + } + + return Object.entries( blockType.attributes ).some( + ( [ , { role, __experimentalRole } ] ) => { + if ( role === 'content' ) { + return true; + } + if ( __experimentalRole === 'content' ) { + deprecated( '__experimentalRole attribute', { + since: '6.7', + version: '6.8', + alternative: 'role attribute', + } ); + return true; + } + return false; + } + ); + }, + ( state, blockTypeName ) => [ + state.blockTypes[ blockTypeName ]?.attributes, + ] +); diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index e46e7dbdf0dd1..b173724277c0b 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -14,6 +14,7 @@ import deprecated from '@wordpress/deprecated'; * Internal dependencies */ import { getValueFromObjectPath, matchesAttributes } from './utils'; +import { hasContentRoleAttribute } from './private-selectors'; /** @typedef {import('../api/registration').WPBlockVariation} WPBlockVariation */ /** @typedef {import('../api/registration').WPBlockVariationScope} WPBlockVariationScope */ @@ -823,48 +824,12 @@ export const hasChildBlocksWithInserterSupport = ( state, blockName ) => { } ); }; -/** - * Determines if any of the block type's attributes have - * the content role attribute. - * - * @param {Object} state Data state. - * @param {string} blockTypeName Block type name. - * @return {boolean} Whether block type has content role attribute. - */ -export const hasContentRoleAttribute = createSelector( - ( state, blockTypeName ) => { - const blockType = getBlockType( state, blockTypeName ); - if ( ! blockType ) { - return false; - } - - return Object.entries( blockType.attributes ).some( - ( [ , { role, __experimentalRole } ] ) => { - if ( role === 'content' ) { - return true; - } - if ( __experimentalRole === 'content' ) { - deprecated( '__experimentalRole attribute', { - since: '6.7', - version: '6.8', - alternative: 'role attribute', - } ); - return true; - } - return false; - } - ); - }, - ( state, blockTypeName ) => [ - state.blockTypes[ blockTypeName ]?.attributes, - ] -); - export const __experimentalHasContentRoleAttribute = ( ...args ) => { deprecated( '__experimentalHasContentRoleAttribute', { since: '6.7', version: '6.8', alternative: 'hasContentRoleAttribute', + hint: 'This is a private selector.', } ); return hasContentRoleAttribute( ...args ); }; From c99343f178f0d518027edeb5409af7ef0b0f7be9 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 20 Sep 2024 09:53:48 +0100 Subject: [PATCH 07/15] Ensure serializer works backwards compat --- packages/blocks/src/api/serializer.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/blocks/src/api/serializer.js b/packages/blocks/src/api/serializer.js index 8a44e085e8aa0..49b428977cc13 100644 --- a/packages/blocks/src/api/serializer.js +++ b/packages/blocks/src/api/serializer.js @@ -10,6 +10,7 @@ import { import { hasFilter, applyFilters } from '@wordpress/hooks'; import isShallowEqual from '@wordpress/is-shallow-equal'; import { removep } from '@wordpress/autop'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -242,6 +243,15 @@ export function getCommentAttributes( blockType, attributes ) { return accumulator; } + if ( attributeSchema.__experimentalRole === 'local' ) { + deprecated( '__experimentalRole attribute', { + since: '6.7', + version: '6.8', + alternative: 'role attribute', + } ); + return accumulator; + } + // Ignore default value. if ( 'default' in attributeSchema && From 079d4ca8ca915c83a52fcf7b84f26cef3caea8d9 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 20 Sep 2024 10:01:06 +0100 Subject: [PATCH 08/15] Ensure experiment API method still exposed on blocks package --- packages/blocks/src/api/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/blocks/src/api/index.js b/packages/blocks/src/api/index.js index 0ef872b0bb00d..e7ab69af71103 100644 --- a/packages/blocks/src/api/index.js +++ b/packages/blocks/src/api/index.js @@ -156,6 +156,7 @@ export { getAccessibleBlockLabel as __experimentalGetAccessibleBlockLabel, __experimentalSanitizeBlockAttributes, getBlockAttributesNamesByRole, + __experimentalGetBlockAttributesNamesByRole, } from './utils'; // Templates are, in a general sense, a basic collection of block nodes with any From 12c89919a1ad78800f810f9870fe54572b7386d0 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 20 Sep 2024 10:07:07 +0100 Subject: [PATCH 09/15] Add hint for updating role attribute --- packages/blocks/src/api/utils.js | 1 + packages/blocks/src/store/private-selectors.js | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index ac09fa2ee31a0..20f0f6a85ed09 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -353,6 +353,7 @@ export function getBlockAttributesNamesByRole( name, role ) { since: '6.7', version: '6.8', alternative: 'role attribute', + hint: `Check the block.json of the ${ name } block.`, } ); return true; } diff --git a/packages/blocks/src/store/private-selectors.js b/packages/blocks/src/store/private-selectors.js index 83b3685249ba2..81bdc1fca2c42 100644 --- a/packages/blocks/src/store/private-selectors.js +++ b/packages/blocks/src/store/private-selectors.js @@ -236,6 +236,7 @@ export const hasContentRoleAttribute = createSelector( since: '6.7', version: '6.8', alternative: 'role attribute', + hint: `Check the block.json of the ${ blockTypeName } block.`, } ); return true; } From 1e227a88dc58de779c38cfd731955a3776285ebe Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 20 Sep 2024 10:36:09 +0100 Subject: [PATCH 10/15] Remove unlock --- packages/block-editor/src/store/selectors.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index e169ab32481c8..bc6911315aa55 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -3006,9 +3006,8 @@ export const getBlockEditingMode = createRegistrySelector( // The rest of the blocks depend on whether they are content blocks or not. // This "flattens" the sections tree. const name = getBlockName( state, clientId ); - const isContent = unlock( - select( blocksStore ) - ).hasContentRoleAttribute( name ); + const isContent = + select( blocksStore ).hasContentRoleAttribute( name ); return isContent ? 'contentOnly' : 'disabled'; } From 9b1b4def58a6defe91a9a38165227a8fc792f9c2 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 20 Sep 2024 10:36:28 +0100 Subject: [PATCH 11/15] Improve readability of proxying --- packages/blocks/src/store/selectors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index b173724277c0b..6d38af389e312 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -14,7 +14,7 @@ import deprecated from '@wordpress/deprecated'; * Internal dependencies */ import { getValueFromObjectPath, matchesAttributes } from './utils'; -import { hasContentRoleAttribute } from './private-selectors'; +import { hasContentRoleAttribute as privateHasContentRoleAttribute } from './private-selectors'; /** @typedef {import('../api/registration').WPBlockVariation} WPBlockVariation */ /** @typedef {import('../api/registration').WPBlockVariationScope} WPBlockVariationScope */ @@ -831,5 +831,5 @@ export const __experimentalHasContentRoleAttribute = ( ...args ) => { alternative: 'hasContentRoleAttribute', hint: 'This is a private selector.', } ); - return hasContentRoleAttribute( ...args ); + return privateHasContentRoleAttribute( ...args ); }; From 8ae6ad445eb75aca54ef2d10077c153165331014 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 20 Sep 2024 10:52:45 +0100 Subject: [PATCH 12/15] Add hint to serializer --- packages/blocks/src/api/serializer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/blocks/src/api/serializer.js b/packages/blocks/src/api/serializer.js index 49b428977cc13..f1fb28e9d9a36 100644 --- a/packages/blocks/src/api/serializer.js +++ b/packages/blocks/src/api/serializer.js @@ -248,6 +248,7 @@ export function getCommentAttributes( blockType, attributes ) { since: '6.7', version: '6.8', alternative: 'role attribute', + hint: `Check the block.json of the ${ blockType?.name } block.`, } ); return accumulator; } From 710da1441c2791a709c8c25c3fc0c97b68581589 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Tue, 24 Sep 2024 06:05:18 +0300 Subject: [PATCH 13/15] use stabilised selector for the content role for edit mode --- .../block-variation-transforms/index.js | 13 ++++++------- packages/block-editor/src/store/selectors.js | 15 +++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/block-editor/src/components/block-variation-transforms/index.js b/packages/block-editor/src/components/block-variation-transforms/index.js index 8f29effb14e67..e8a6ec820bb14 100644 --- a/packages/block-editor/src/components/block-variation-transforms/index.js +++ b/packages/block-editor/src/components/block-variation-transforms/index.js @@ -21,6 +21,7 @@ import { chevronDown } from '@wordpress/icons'; */ import BlockIcon from '../block-icon'; import { store as blockEditorStore } from '../../store'; +import { unlock } from '../../lock-unlock'; function VariationsButtons( { className, @@ -142,18 +143,16 @@ function __experimentalBlockVariationTransforms( { blockClientId } ) { const { updateBlockAttributes } = useDispatch( blockEditorStore ); const { activeBlockVariation, variations, isContentOnly } = useSelect( ( select ) => { - const { - getActiveBlockVariation, - getBlockVariations, - __experimentalHasContentRoleAttribute, - } = select( blocksStore ); + const { getActiveBlockVariation, getBlockVariations } = + select( blocksStore ); + const { getBlockName, getBlockAttributes, getBlockEditingMode } = select( blockEditorStore ); const name = blockClientId && getBlockName( blockClientId ); - const isContentBlock = - __experimentalHasContentRoleAttribute( name ); + const { hasContentRoleAttribute } = unlock( select( blocksStore ) ); + const isContentBlock = hasContentRoleAttribute( name ); return { activeBlockVariation: getActiveBlockVariation( diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index bc6911315aa55..c169d7fa82f84 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -3006,8 +3006,11 @@ export const getBlockEditingMode = createRegistrySelector( // The rest of the blocks depend on whether they are content blocks or not. // This "flattens" the sections tree. const name = getBlockName( state, clientId ); - const isContent = - select( blocksStore ).hasContentRoleAttribute( name ); + const { hasContentRoleAttribute } = unlock( + select( blocksStore ) + ); + const isContent = hasContentRoleAttribute( name ); + return isContent ? 'contentOnly' : 'disabled'; } @@ -3027,10 +3030,10 @@ export const getBlockEditingMode = createRegistrySelector( // If the parent of the block is contentOnly locked, check whether it's a content block. if ( templateLock === 'contentOnly' ) { const name = getBlockName( state, clientId ); - const isContent = - select( blocksStore ).__experimentalHasContentRoleAttribute( - name - ); + const { hasContentRoleAttribute } = unlock( + select( blocksStore ) + ); + const isContent = hasContentRoleAttribute( name ); return isContent ? 'contentOnly' : 'disabled'; } // Otherwise, check if there's an ancestor that is contentOnly From 37a0014e4018c1c6c852048b3f073a095975363c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 24 Sep 2024 11:37:52 +0100 Subject: [PATCH 14/15] Attempt locking to fix unit test --- packages/block-editor/src/store/test/selectors.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index ec0e3be6d7801..9df62ce062325 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -16,6 +16,7 @@ import { select, dispatch } from '@wordpress/data'; import * as selectors from '../selectors'; import { store } from '../'; import { sectionRootClientIdKey } from '../private-keys'; +import { lock } from '../../lock-unlock'; const { getBlockName, @@ -4477,10 +4478,12 @@ describe( 'getBlockEditingMode', () => { const hasContentRoleAttribute = jest.fn( () => false ); + const fauxPrivateAPIs = {}; + + lock( fauxPrivateAPIs, { hasContentRoleAttribute } ); + getBlockEditingMode.registry = { - select: jest.fn( () => ( { - hasContentRoleAttribute, - } ) ), + select: jest.fn( () => fauxPrivateAPIs ), }; it( 'should return default by default', () => { From 3a4e5961b25b70a6579b82363c3bb1c7059a9cca Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 24 Sep 2024 11:47:43 +0100 Subject: [PATCH 15/15] Ensure mock returns correct value --- packages/block-editor/src/store/test/selectors.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index 9df62ce062325..ebf23789fec31 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -4643,12 +4643,15 @@ describe( 'getBlockEditingMode', () => { } ); it( 'in navigation mode, blocks with content attributes within sections are contentOnly', () => { + hasContentRoleAttribute.mockReturnValueOnce( true ); expect( getBlockEditingMode( navigationModeStateWithRootSection, 'b3247f75-fd94-4fef-97f9-5bfd162cc416' ) ).toBe( 'contentOnly' ); + + hasContentRoleAttribute.mockReturnValueOnce( true ); expect( getBlockEditingMode( navigationModeStateWithRootSection,