Skip to content

Commit

Permalink
Try allowing list item insertion in content only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Oct 2, 2024
1 parent 79e6643 commit 62af365
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function UncontrolledInnerBlocks( props ) {
blockType,
parentLock,
defaultLayout,
contentOnlyInsertion,
} = props;

useNestedSettingsUpdate(
Expand All @@ -89,7 +90,8 @@ function UncontrolledInnerBlocks( props ) {
templateLock,
captureToolbars,
orientation,
layout
layout,
contentOnlyInsertion
);

useInnerBlockTemplateSync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 ) {
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default function Edit( { attributes, setAttributes, clientId, style } ) {
renderAppender: false,
} ),
__experimentalCaptureToolbars: true,
contentOnlyInsertion: true,
} );
useMigrateOnLoad( attributes, clientId );

Expand Down

0 comments on commit 62af365

Please sign in to comment.