Skip to content

Commit

Permalink
Add generic InnerBlocks filter for allowed blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaz committed Apr 13, 2021
1 parent bbd3333 commit 3b127a7
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useViewportMatch, useMergeRefs } from '@wordpress/compose';
import { forwardRef, useRef } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { getBlockType, withBlockContentContext } from '@wordpress/blocks';
import { applyFilters } from '@wordpress/hooks';

/**
* Internal dependencies
Expand Down Expand Up @@ -49,21 +50,6 @@ function UncontrolledInnerBlocks( props ) {
__experimentalLayout,
} = props;

useNestedSettingsUpdate(
clientId,
allowedBlocks,
templateLock,
captureToolbars,
orientation
);

useInnerBlockTemplateSync(
clientId,
template,
templateLock,
templateInsertUpdatesSelection
);

const context = useSelect(
( select ) => {
const block = select( blockEditorStore ).getBlock( clientId );
Expand All @@ -78,6 +64,30 @@ function UncontrolledInnerBlocks( props ) {
[ clientId ]
);

const FilteredAllowedBlocks = useSelect( ( select ) => {
const block = select( blockEditorStore ).getBlock( clientId );
const blockFilterName = block.name.replace( '/', '-' );
return applyFilters(
`editor.InnerBlocks.${ blockFilterName }.allowedBlocks`,
allowedBlocks
);
} );

useNestedSettingsUpdate(
clientId,
FilteredAllowedBlocks,
templateLock,
captureToolbars,
orientation
);

useInnerBlockTemplateSync(
clientId,
template,
templateLock,
templateInsertUpdatesSelection
);

// This component needs to always be synchronous as it's the one changing
// the async mode depending on the block selection.
return (
Expand Down

0 comments on commit 3b127a7

Please sign in to comment.