From 33d3bf19aeb3868ee7c17e3c24f693cebf58fa7e Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 15 Dec 2022 11:33:58 +0800 Subject: [PATCH 1/2] Fix Off Canvas Editor add submenu item option --- .../src/components/off-canvas-editor/block.js | 55 ++++++++++++------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block.js b/packages/block-editor/src/components/off-canvas-editor/block.js index 49ce5788dfafe0..40635a032674bd 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block.js +++ b/packages/block-editor/src/components/off-canvas-editor/block.js @@ -42,7 +42,7 @@ import useBlockDisplayInformation from '../use-block-display-information'; import { useBlockLock } from '../block-lock'; function ListViewBlock( { - block, + block: { clientId }, isDragged, isSelected, isBranchSelected, @@ -60,7 +60,6 @@ function ListViewBlock( { } ) { const cellRef = useRef( null ); const [ isHovered, setIsHovered ] = useState( false ); - const { clientId, attributes } = block; const { isLocked, isContentLocked } = useBlockLock( clientId ); const forceSelectionContentLock = useSelect( @@ -87,12 +86,12 @@ function ListViewBlock( { ( isSelected && selectedClientIds[ selectedClientIds.length - 1 ] === clientId ); - const { replaceBlock, toggleBlockHighlight } = + const { insertBlock, replaceBlock, toggleBlockHighlight } = useDispatch( blockEditorStore ); const blockInformation = useBlockDisplayInformation( clientId ); - const blockName = useSelect( - ( select ) => select( blockEditorStore ).getBlockName( clientId ), + const block = useSelect( + ( select ) => select( blockEditorStore ).getBlock( clientId ), [ clientId ] ); @@ -100,7 +99,7 @@ function ListViewBlock( { // since that menu is part of the toolbar in the editor canvas. // List View respects this by also hiding the block settings menu. const showBlockActions = hasBlockSupport( - blockName, + block.name, '__experimentalToolbar', true ); @@ -145,7 +144,7 @@ function ListViewBlock( { const { isTreeGridMounted, expand, collapse } = useListViewContext(); - const isEditable = blockName !== 'core/page-list-item'; + const isEditable = block.name !== 'core/page-list-item'; const hasSiblings = siblingBlockCount > 0; const hasRenderedMovers = showBlockMovers && hasSiblings; const moverCellClassName = classnames( @@ -369,20 +368,34 @@ function ListViewBlock( { const newLink = createBlock( 'core/navigation-link' ); - const newSubmenu = createBlock( - 'core/navigation-submenu', - attributes, - block.innerBlocks - ? [ - ...block.innerBlocks, - newLink, - ] - : [ newLink ] - ); - replaceBlock( - clientId, - newSubmenu - ); + // Convert to a submenu if the block currently isn't one. + if ( + block.name === + 'core/navigation-submenu' + ) { + const updateSelectionOnInsert = false; + insertBlock( + newLink, + block.innerBlocks.length, + clientId, + updateSelectionOnInsert + ); + } else { + const newSubmenu = createBlock( + 'core/navigation-submenu', + block.attributes, + block.innerBlocks + ? [ + ...block.innerBlocks, + newLink, + ] + : [ newLink ] + ); + replaceBlock( + clientId, + newSubmenu + ); + } onClose(); } } > From 68a7defbb1dc062765b17b15e917f939e1c45281 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 15 Dec 2022 11:39:30 +0800 Subject: [PATCH 2/2] Fix comment --- packages/block-editor/src/components/off-canvas-editor/block.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block.js b/packages/block-editor/src/components/off-canvas-editor/block.js index 40635a032674bd..6e588e1e166c5a 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block.js +++ b/packages/block-editor/src/components/off-canvas-editor/block.js @@ -368,7 +368,6 @@ function ListViewBlock( { const newLink = createBlock( 'core/navigation-link' ); - // Convert to a submenu if the block currently isn't one. if ( block.name === 'core/navigation-submenu' @@ -381,6 +380,7 @@ function ListViewBlock( { updateSelectionOnInsert ); } else { + // Convert to a submenu if the block currently isn't one. const newSubmenu = createBlock( 'core/navigation-submenu', block.attributes,