Skip to content

Commit

Permalink
Fix getAllowedBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 1, 2024
1 parent a9aad32 commit d355bc9
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2190,31 +2190,43 @@ export const hasInserterItems = createRegistrySelector(
*
* @return {Array?} The list of allowed block types.
*/
export const getAllowedBlocks = createSelector(
( state, rootClientId = null ) => {
if ( ! rootClientId ) {
return;
}
export const getAllowedBlocks = createRegistrySelector( ( select ) =>
createSelector(
( state, rootClientId = null ) => {
if ( ! rootClientId ) {
return;
}

const blockTypes = getBlockTypes().filter( ( blockType ) =>
canIncludeBlockTypeInInserter( state, blockType, rootClientId )
);
const blockTypes = getBlockTypes().filter( ( blockType ) =>
canIncludeBlockTypeInInserter( state, blockType, rootClientId )
);

if (
canInsertBlockTypeUnmemoized( state, 'core/block', rootClientId )
) {
blockTypes.push( 'core/block' );
}
const hasReusableBlock =
canInsertBlockTypeUnmemoized(
state,
'core/block',
rootClientId
) &&
unlock( select( STORE_NAME ) ).getReusableBlocks().length > 0;

return blockTypes;
},
( state, rootClientId ) => [
state.blockListSettings[ rootClientId ],
state.blocks.byClientId.get( rootClientId ),
state.settings.allowedBlockTypes,
state.settings.templateLock,
getBlockTypes(),
]
if ( hasReusableBlock ) {
blockTypes.push( 'core/block' );
}

return blockTypes;
},
( state, rootClientId ) =>
rootClientId
? [
state.blockListSettings[ rootClientId ],
state.blocks.byClientId.get( rootClientId ),
state.settings.allowedBlockTypes,
state.settings.templateLock,
unlock( select( STORE_NAME ) ).getReusableBlocks(),
getBlockTypes(),
]
: []
)
);

export const __experimentalGetAllowedBlocks = createSelector(
Expand Down

0 comments on commit d355bc9

Please sign in to comment.