Skip to content

Commit

Permalink
Updated offsite editor. (+1 squashed commit)
Browse files Browse the repository at this point in the history
Squashed commits:
[b429410eea] Fix: Inserter on navigation menu sidebar.
  • Loading branch information
jorgefilipecosta committed Feb 22, 2023
1 parent 278be06 commit d96da60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
29 changes: 13 additions & 16 deletions packages/block-editor/src/components/off-canvas-editor/appender.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -220,6 +220,7 @@ function ListViewBranch( props ) {
<TreeGridCell>
{ ( treeGridCellProps ) => (
<Appender
clientId={ parentId }
nestingLevel={ level }
blockCount={ blockCount }
{ ...treeGridCellProps }
Expand Down
10 changes: 8 additions & 2 deletions packages/block-editor/src/components/off-canvas-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ function OffCanvasEditor(
const { clientIdsTree, draggedClientIds, selectedClientIds } =
useListViewClientIds( blocks );

const { visibleBlockCount, shouldShowInnerBlocks } = useSelect(
const { visibleBlockCount, shouldShowInnerBlocks, parentId } = useSelect(
( select ) => {
const {
getBlockRootClientId,
getGlobalBlockCount,
getClientIdsOfDescendants,
__unstableGetEditorMode,
Expand All @@ -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();
Expand Down Expand Up @@ -227,6 +232,7 @@ function OffCanvasEditor(
>
<ListViewContext.Provider value={ contextValue }>
<ListViewBranch
parentId={ parentId }
blocks={ clientIdsTree }
selectBlock={ selectEditorBlock }
showBlockMovers={ showBlockMovers }
Expand Down

0 comments on commit d96da60

Please sign in to comment.