From 31cdc4528131fff74f43c33787c4b81af9ad34d0 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 20 Dec 2024 15:30:04 +1100 Subject: [PATCH] By nesting the new key in supports we can dispense with the Reflect.ownKeys checks --- packages/block-library/src/query/index.js | 5 ++++- packages/blocks/src/api/registration.js | 8 +++----- packages/blocks/src/api/utils.js | 2 +- packages/blocks/src/store/reducer.js | 15 ++++++--------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/block-library/src/query/index.js b/packages/block-library/src/query/index.js index 0a60e6c81e2558..0a70eadd005af9 100644 --- a/packages/block-library/src/query/index.js +++ b/packages/block-library/src/query/index.js @@ -77,7 +77,10 @@ export default function addDisplayKeyToBlockMetadata( } return { ...blockSettings, - [ blockMetadataDisplayKey ]: { role: 'content' }, + supports: { + ...blockSettings.supports, + [ blockMetadataDisplayKey ]: { role: 'content' }, + }, }; } diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index 4fc9ee1bb0981e..507aaaec8f758a 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -177,11 +177,9 @@ function getBlockSettingsFromMetadata( { textdomain, ...metadata } ) { ]; const settings = Object.fromEntries( - Reflect.ownKeys( metadata ) - .map( ( key ) => [ key, metadata[ key ] ] ) - .filter( ( [ key ] ) => - allowedFields.some( ( field ) => field === key ) - ) + Object.entries( metadata ).filter( ( [ key ] ) => + allowedFields.includes( key ) + ) ); if ( textdomain ) { diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index e4e443032a3440..4d3fcebaab92d8 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -374,7 +374,7 @@ export const __experimentalGetBlockAttributesNamesByRole = ( ...args ) => { export function isContentBlock( name ) { const blockType = getBlockType( name ); - if ( blockType?.[ blockMetadataDisplayKey ]?.role === 'content' ) { + if ( blockType.supports?.[ blockMetadataDisplayKey ]?.role === 'content' ) { return true; } diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index d1714e3f2bce56..ac652b91890319 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -95,17 +95,14 @@ function bootstrappedBlockTypes( state = {}, action ) { } } else { newDefinition = Object.fromEntries( - Reflect.ownKeys( blockType ) + Object.entries( blockType ) .filter( - ( key ) => - blockType[ key ] !== null && - blockType[ key ] !== undefined + ( [ , value ] ) => + value !== null && value !== undefined ) - .map( ( key ) => [ - typeof key === 'symbol' - ? key - : camelCase( key.toString() ), - blockType[ key ], + .map( ( [ key, value ] ) => [ + camelCase( key ), + value, ] ) ); newDefinition.name = name;