Skip to content

Commit

Permalink
By nesting the new key in supports we can dispense with the Reflect.o…
Browse files Browse the repository at this point in the history
…wnKeys checks
  • Loading branch information
ramonjd committed Dec 20, 2024
1 parent e414b83 commit 31cdc45
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
5 changes: 4 additions & 1 deletion packages/block-library/src/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export default function addDisplayKeyToBlockMetadata(
}
return {
...blockSettings,
[ blockMetadataDisplayKey ]: { role: 'content' },
supports: {
...blockSettings.supports,
[ blockMetadataDisplayKey ]: { role: 'content' },
},
};
}

Expand Down
8 changes: 3 additions & 5 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
15 changes: 6 additions & 9 deletions packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 31cdc45

Please sign in to comment.