diff --git a/packages/block-editor/src/components/off-canvas-editor/appender.js b/packages/block-editor/src/components/off-canvas-editor/appender.js index 7079500e66149..ed3fb1b4cb52b 100644 --- a/packages/block-editor/src/components/off-canvas-editor/appender.js +++ b/packages/block-editor/src/components/off-canvas-editor/appender.js @@ -15,26 +15,23 @@ import useBlockDisplayTitle from '../block-title/use-block-display-title'; import Inserter from '../inserter'; export const Appender = forwardRef( - ( { nestingLevel, blockCount, ...props }, ref ) => { + ( { nestingLevel, blockCount, clientId, ...props }, ref ) => { const [ insertedBlock, setInsertedBlock ] = useState( null ); const instanceId = useInstanceId( Appender ); - const { hideInserter, clientId } = useSelect( ( select ) => { - const { - getTemplateLock, - __unstableGetEditorMode, - getSelectedBlockClientId, - } = select( blockEditorStore ); + const { hideInserter } = useSelect( + ( select ) => { + const { getTemplateLock, __unstableGetEditorMode } = + select( blockEditorStore ); - const _clientId = getSelectedBlockClientId(); - - return { - clientId: getSelectedBlockClientId(), - hideInserter: - !! getTemplateLock( _clientId ) || - __unstableGetEditorMode() === 'zoom-out', - }; - }, [] ); + return { + hideInserter: + !! getTemplateLock( clientId ) || + __unstableGetEditorMode() === 'zoom-out', + }; + }, + [ clientId ] + ); const blockTitle = useBlockDisplayTitle( { clientId, diff --git a/packages/block-editor/src/components/off-canvas-editor/branch.js b/packages/block-editor/src/components/off-canvas-editor/branch.js index 7652b204898ad..636f67ee10fce 100644 --- a/packages/block-editor/src/components/off-canvas-editor/branch.js +++ b/packages/block-editor/src/components/off-canvas-editor/branch.js @@ -116,8 +116,8 @@ function ListViewBranch( props ) { return null; } - // Only show the appender at the first level. - const showAppender = level === 1; + // Only show the appender at the first level and if there is a parent block. + const showAppender = level === 1 && parentId; const filteredBlocks = blocks.filter( Boolean ); const blockCount = filteredBlocks.length; @@ -220,6 +220,7 @@ function ListViewBranch( props ) { { ( treeGridCellProps ) => ( { const { + getBlockRootClientId, getGlobalBlockCount, getClientIdsOfDescendants, __unstableGetEditorMode, @@ -94,9 +95,13 @@ function OffCanvasEditor( return { visibleBlockCount: getGlobalBlockCount() - draggedBlockCount, shouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out', + parentId: + blocks.length > 0 + ? getBlockRootClientId( blocks[ 0 ].clientId ) + : undefined, }; }, - [ draggedClientIds ] + [ draggedClientIds, blocks ] ); const { updateBlockSelection } = useBlockSelection(); @@ -227,6 +232,7 @@ function OffCanvasEditor( >