diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index 475d4f6a4b8c2e..5648cc2c6370f9 100644 --- a/packages/block-editor/src/components/block-inspector/index.js +++ b/packages/block-editor/src/components/block-inspector/index.js @@ -29,8 +29,10 @@ import useBlockInspectorAnimationSettings from './useBlockInspectorAnimationSett import BlockInfo from '../block-info-slot-fill'; import BlockQuickNavigation from '../block-quick-navigation'; import { useBorderPanelLabel } from '../../hooks/border'; +import { privateApis as blockEditorPrivateApis } from '../../private-apis'; import { unlock } from '../../lock-unlock'; +const { PrivateListView } = unlock( blockEditorPrivateApis ); function BlockStylesPanel( { clientId } ) { return ( @@ -213,6 +215,7 @@ const BlockInspectorSingleBlock = ( { isSectionBlock, } ) => { const availableTabs = useInspectorControlsTabs( blockName ); + const showTabs = ! isSectionBlock && availableTabs?.length > 1; const hasBlockStyles = useSelect( @@ -223,6 +226,7 @@ const BlockInspectorSingleBlock = ( { }, [ blockName ] ); + const blockInformation = useBlockDisplayInformation( clientId ); const borderPanelLabel = useBorderPanelLabel( { blockName } ); const contentClientIds = useSelect( @@ -246,6 +250,41 @@ const BlockInspectorSingleBlock = ( { [ isSectionBlock, clientId ] ); + 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'; + + return { + selectedContentClientId: _selectedBlockClientId, + isSelectedContentClientIdControlling: + _isSelectedContentClientIdControlling, + isSelectedBlockInContentOnlyContainer: + _isSelectedBlockInContentOnlyContainer, + hasContentLockedParent: false, + }; + } ); + const { __unstableGetEditorMode } = useSelect( blockEditorStore ); + const editorMode = __unstableGetEditorMode(); + return (
) } - { contentClientIds && contentClientIds?.length > 0 && ( - - - - ) } + { ! isSelectedContentClientIdControlling && + contentClientIds && + contentClientIds?.length > 0 && ( + + + + ) } + + { isSelectedContentClientIdControlling && + isSelectedBlockInContentOnlyContainer && + contentClientIds && + contentClientIds?.length > 0 && ( + + + + ) } { ! isSectionBlock && ( <> + { editorMode === 'navigation' && + isSelectedBlockInContentOnlyContainer && + isSelectedContentClientIdControlling && ( + + + + ) } { const { getDraggedBlockClientIds, getSelectedBlockClientIds, getEnabledClientIdsTree, + __unstableGetClientIdsTree: getClientIdsTree, } = unlock( select( blockEditorStore ) ); return { selectedClientIds: getSelectedBlockClientIds(), draggedClientIds: getDraggedBlockClientIds(), clientIdsTree: - blocks ?? getEnabledClientIdsTree( rootClientId ), + blocks ?? ignoreRenderingMode + ? getClientIdsTree( rootClientId ) + : getEnabledClientIdsTree( rootClientId ), }; }, - [ blocks, rootClientId ] + [ blocks, rootClientId, ignoreRenderingMode ] ); } diff --git a/packages/block-editor/src/store/private-selectors.js b/packages/block-editor/src/store/private-selectors.js index f1b5abd7789a11..d8fbb87e6c12f6 100644 --- a/packages/block-editor/src/store/private-selectors.js +++ b/packages/block-editor/src/store/private-selectors.js @@ -90,6 +90,7 @@ function getEnabledClientIdsTreeUnmemoized( state, rootClientId ) { state, clientId ); + if ( getBlockEditingMode( state, clientId ) !== 'disabled' ) { result.push( { clientId, innerBlocks } ); } else { diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 598b6b4ea480de..fb59a55e9b114c 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -3068,6 +3068,12 @@ export const getBlockEditingMode = createRegistrySelector( return 'contentOnly'; } + // All controlling blocks are treated as content only + // by default. + if ( areInnerBlocksControlled( state, clientId ) ) { + return 'contentOnly'; + } + return 'disabled'; } @@ -3107,6 +3113,15 @@ export const getBlockEditingMode = createRegistrySelector( ); const isContent = hasContentRoleAttribute( name ); + // All controlling blocks are treated as content only + // by default. + if ( + ! isContent && + areInnerBlocksControlled( state, clientId ) + ) { + return 'contentOnly'; + } + return isContent ? 'contentOnly' : 'disabled'; } @@ -3130,6 +3145,16 @@ export const getBlockEditingMode = createRegistrySelector( select( blocksStore ) ); const isContent = hasContentRoleAttribute( name ); + + // All controlling blocks are treated as content only + // by default. + if ( + ! isContent && + areInnerBlocksControlled( state, clientId ) + ) { + return 'contentOnly'; + } + return isContent ? 'contentOnly' : 'disabled'; } // Otherwise, check if there's an ancestor that is contentOnly diff --git a/packages/block-library/src/navigation/edit/inner-blocks.js b/packages/block-library/src/navigation/edit/inner-blocks.js index 6fe3dd8347a33e..e2534a20ed1bb5 100644 --- a/packages/block-library/src/navigation/edit/inner-blocks.js +++ b/packages/block-library/src/navigation/edit/inner-blocks.js @@ -73,6 +73,11 @@ export default function NavigationInnerBlocks( { const showPlaceholder = ! hasCustomPlaceholder && ! hasMenuItems && ! isSelected; + const defaultRenderingMode = useSelect( ( select ) => { + const { getBlockEditingMode } = select( blockEditorStore ); + return getBlockEditingMode( clientId ) === 'default'; + } ); + const innerBlocksProps = useInnerBlocksProps( { className: 'wp-block-navigation__container', @@ -93,13 +98,14 @@ export default function NavigationInnerBlocks( { // the sibling inserter. // See https://github.com/WordPress/gutenberg/issues/37572. renderAppender: - isSelected || + defaultRenderingMode && + ( isSelected || ( isImmediateParentOfSelectedBlock && ! selectedBlockHasChildren ) || // Show the appender while dragging to allow inserting element between item and the appender. parentOrChildHasSelection ? InnerBlocks.ButtonBlockAppender - : false, + : false ), placeholder: showPlaceholder ? placeholder : undefined, __experimentalCaptureToolbars: true, __unstableDisableLayoutClassNames: true,