Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment: Expanded contentOnly / write mode List block editing #65836

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 20 additions & 7 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1623,22 +1623,28 @@ 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;
}

const _isSectionBlock = !! isSectionBlock( state, rootClientId );
if ( _isSectionBlock ) {
const allowSectionInsertion =
!! parentBlockListSettings?.contentOnlyInsertion;
if ( _isSectionBlock && ! allowSectionInsertion ) {
return false;
}

if ( getBlockEditingMode( state, rootClientId ?? '' ) === 'disabled' ) {
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 Expand Up @@ -1780,12 +1786,19 @@ export function canRemoveBlock( state, clientId ) {
}

const rootClientId = getBlockRootClientId( state, clientId );
if ( getTemplateLock( state, rootClientId ) ) {
const templateLock = getTemplateLock( state, rootClientId );
const parentBlockListSettings = getBlockListSettings( state, rootClientId );
const allowsContentOnlyInsertion =
templateLock === 'contentOnly' &&
!! parentBlockListSettings?.contentOnlyInsertion;
if ( templateLock && ! allowsContentOnlyInsertion ) {
return false;
}

const isBlockWithinSection = !! getParentSectionBlock( state, clientId );
if ( isBlockWithinSection ) {
const allowSectionInsertion =
!! parentBlockListSettings?.contentOnlyInsertion;
if ( isBlockWithinSection && ! allowSectionInsertion ) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/list-item/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default function ListItemEdit( {
const innerBlocksProps = useInnerBlocksProps( blockProps, {
renderAppender: false,
__unstableDisableDropZone: true,
contentOnlyInsertion: true,
} );
const useEnterRef = useEnter( { content, clientId } );
const useSpaceRef = useSpace( clientId );
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
Loading