diff --git a/packages/block-editor/src/components/inner-blocks/index.js b/packages/block-editor/src/components/inner-blocks/index.js index 1583031a8ea18d..bc5aa86565d42c 100644 --- a/packages/block-editor/src/components/inner-blocks/index.js +++ b/packages/block-editor/src/components/inner-blocks/index.js @@ -75,6 +75,7 @@ function UncontrolledInnerBlocks( props ) { blockType, parentLock, defaultLayout, + contentOnlyInsertion, } = props; useNestedSettingsUpdate( @@ -89,7 +90,8 @@ function UncontrolledInnerBlocks( props ) { templateLock, captureToolbars, orientation, - layout + layout, + contentOnlyInsertion ); useInnerBlockTemplateSync( diff --git a/packages/block-editor/src/components/inner-blocks/use-nested-settings-update.js b/packages/block-editor/src/components/inner-blocks/use-nested-settings-update.js index 8417dec1dd48ff..38228995503634 100644 --- a/packages/block-editor/src/components/inner-blocks/use-nested-settings-update.js +++ b/packages/block-editor/src/components/inner-blocks/use-nested-settings-update.js @@ -51,6 +51,7 @@ function useShallowMemo( value ) { * @param {string} orientation The direction in which the block * should face. * @param {Object} layout The layout object for the block container. + * @param {?boolean} contentOnlyInsertion Whether inner blocks can be inserted in content only mode. */ export default function useNestedSettingsUpdate( clientId, @@ -64,7 +65,8 @@ export default function useNestedSettingsUpdate( templateLock, captureToolbars, orientation, - layout + layout, + contentOnlyInsertion ) { // Instead of adding a useSelect mapping here, please add to the useSelect // mapping in InnerBlocks! Every subscription impacts performance. @@ -147,6 +149,10 @@ export default function useNestedSettingsUpdate( } ); } + if ( contentOnlyInsertion !== undefined ) { + newSettings.contentOnlyInsertion = contentOnlyInsertion; + } + // Batch updates to block list settings to avoid triggering cascading renders // for each container block included in a tree and optimize initial render. // To avoid triggering updateBlockListSettings for each container block diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 6cf6aae296141f..75521e2d6c4482 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1623,8 +1623,14 @@ const canInsertBlockTypeUnmemoized = ( blockType = getBlockType( blockName ); } - const isLocked = !! getTemplateLock( state, rootClientId ); - if ( isLocked ) { + const parentBlockListSettings = getBlockListSettings( state, rootClientId ); + const templateLock = getTemplateLock( state, rootClientId ); + const allowsContentOnlyInsertion = + templateLock === 'contentOnly' && + !! parentBlockListSettings?.contentOnlyInsertion; + + const isLocked = !! templateLock; + if ( isLocked && ! allowsContentOnlyInsertion ) { return false; } @@ -1637,8 +1643,6 @@ const canInsertBlockTypeUnmemoized = ( return false; } - const parentBlockListSettings = getBlockListSettings( state, rootClientId ); - // The parent block doesn't have settings indicating it doesn't support // inner blocks, return false. if ( rootClientId && parentBlockListSettings === undefined ) { diff --git a/packages/block-library/src/list/edit.js b/packages/block-library/src/list/edit.js index 73551cd9cdee80..bceb88a5edc60b 100644 --- a/packages/block-library/src/list/edit.js +++ b/packages/block-library/src/list/edit.js @@ -139,6 +139,7 @@ export default function Edit( { attributes, setAttributes, clientId, style } ) { renderAppender: false, } ), __experimentalCaptureToolbars: true, + contentOnlyInsertion: true, } ); useMigrateOnLoad( attributes, clientId );