-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Off Canvas Editor add submenu item option #46562
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,20 +86,20 @@ 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 ] | ||
); | ||
|
||
// When a block hides its toolbar it also hides the block settings menu, | ||
// 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 | ||
); | ||
if ( | ||
block.name === | ||
'core/navigation-submenu' | ||
Comment on lines
+372
to
+373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this to #46166 |
||
) { | ||
const updateSelectionOnInsert = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the API this is very helpful 🙇 |
||
insertBlock( | ||
newLink, | ||
block.innerBlocks.length, | ||
clientId, | ||
updateSelectionOnInsert | ||
); | ||
} else { | ||
// Convert to a submenu if the block currently isn't one. | ||
const newSubmenu = createBlock( | ||
'core/navigation-submenu', | ||
block.attributes, | ||
block.innerBlocks | ||
? [ | ||
...block.innerBlocks, | ||
newLink, | ||
] | ||
: [ newLink ] | ||
); | ||
replaceBlock( | ||
clientId, | ||
newSubmenu | ||
); | ||
} | ||
onClose(); | ||
} } | ||
> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: I added this line to #46166