From ce466cc9bf111c922d27b202f4f522058d3ea687 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu <andrei.draganescu@automattic.com> Date: Mon, 11 Nov 2024 18:43:40 +0200 Subject: [PATCH] only show the off canvas list view for children of content only locked parents --- .../src/components/block-inspector/index.js | 45 ++++++++++++++----- packages/block-editor/src/store/selectors.js | 10 +++-- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index e4eb91e1fc5a7d..c59b0f4e822e4f 100644 --- a/packages/block-editor/src/components/block-inspector/index.js +++ b/packages/block-editor/src/components/block-inspector/index.js @@ -249,19 +249,38 @@ const BlockInspectorSingleBlock = ( { [ isSectionBlock, clientId ] ); - const { selectedContentClientId, isSelectedContentClientIdControlling } = - useSelect( ( select ) => { - const { getSelectedBlockClientId, areInnerBlocksControlled } = - select( blockEditorStore ); + const { + selectedContentClientId, + isSelectedContentClientIdControlling, + isSelectedBlockInContentOnlyContainer, + } = useSelect( ( select ) => { + const { + getSelectedBlockClientId, + areInnerBlocksControlled, + getBlockRootClientId, + getTemplateLock, + } = select( blockEditorStore ); + + const _selectedBlockClientId = getSelectedBlockClientId(); + const _isSelectedContentClientIdControlling = areInnerBlocksControlled( + _selectedBlockClientId + ); + + const rootClientId = getBlockRootClientId( _selectedBlockClientId ); + const templateLock = getTemplateLock( rootClientId ); + + const _isSelectedBlockInContentOnlyContainer = + templateLock === 'contentOnly'; - const _selectedBlockClientId = getSelectedBlockClientId(); - return { - selectedContentClientId: _selectedBlockClientId, - isSelectedContentClientIdControlling: areInnerBlocksControlled( - _selectedBlockClientId - ), - }; - } ); + return { + selectedContentClientId: _selectedBlockClientId, + isSelectedContentClientIdControlling: + _isSelectedContentClientIdControlling, + isSelectedBlockInContentOnlyContainer: + _isSelectedBlockInContentOnlyContainer, + hasContentLockedParent: false, + }; + } ); const { __unstableGetEditorMode } = useSelect( blockEditorStore ); const editorMode = __unstableGetEditorMode(); @@ -298,6 +317,7 @@ const BlockInspectorSingleBlock = ( { ) } { isSelectedContentClientIdControlling && + isSelectedBlockInContentOnlyContainer && contentClientIds && contentClientIds?.length > 0 && ( <PanelBody title={ __( 'Content' ) }> @@ -314,6 +334,7 @@ const BlockInspectorSingleBlock = ( { { ! isSectionBlock && ( <> { editorMode === 'navigation' && + isSelectedBlockInContentOnlyContainer && isSelectedContentClientIdControlling && ( <PanelBody title={ __( 'Content' ) }> <PrivateListView diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index bfaf572f71ed99..879667884bb86c 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -3046,6 +3046,12 @@ export const getBlockEditingMode = createRegistrySelector( clientId = ''; } + // All controlling blocks are treated as content only + // by default. + if ( areInnerBlocksControlled( state, clientId ) ) { + return 'contentOnly'; + } + // In zoom-out mode, override the behavior set by // __unstableSetBlockEditingMode to only allow editing the top-level // sections. @@ -3075,10 +3081,6 @@ export const getBlockEditingMode = createRegistrySelector( if ( editorMode === 'navigation' ) { const sectionRootClientId = getSectionRootClientId( state ); - if ( areInnerBlocksControlled( state, clientId ) ) { - return 'contentOnly'; - } - // The root section is "default mode" if ( clientId === sectionRootClientId ) { return 'default';