-
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
Define Nav block allowed inner blocks via block supports mechanism #32426
Changes from all commits
c20edf1
8da9940
20e0a7b
a2973ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ import { | |||||||||||
useBlockProps, | ||||||||||||
store as blockEditorStore, | ||||||||||||
} from '@wordpress/block-editor'; | ||||||||||||
import { getBlockSupport } from '@wordpress/blocks'; | ||||||||||||
import { useDispatch, withSelect, withDispatch } from '@wordpress/data'; | ||||||||||||
import { PanelBody, ToggleControl, ToolbarGroup } from '@wordpress/components'; | ||||||||||||
import { compose } from '@wordpress/compose'; | ||||||||||||
|
@@ -29,15 +30,6 @@ import NavigationPlaceholder from './placeholder'; | |||||||||||
import PlaceholderPreview from './placeholder-preview'; | ||||||||||||
import ResponsiveWrapper from './responsive-wrapper'; | ||||||||||||
|
||||||||||||
const ALLOWED_BLOCKS = [ | ||||||||||||
'core/navigation-link', | ||||||||||||
'core/search', | ||||||||||||
'core/social-links', | ||||||||||||
'core/page-list', | ||||||||||||
'core/spacer', | ||||||||||||
'core/home-link', | ||||||||||||
]; | ||||||||||||
|
||||||||||||
const LAYOUT = { | ||||||||||||
type: 'default', | ||||||||||||
alignments: [], | ||||||||||||
|
@@ -55,6 +47,7 @@ function Navigation( { | |||||||||||
className, | ||||||||||||
hasSubmenuIndicatorSetting = true, | ||||||||||||
hasItemJustificationControls = true, | ||||||||||||
allowedBlocks, | ||||||||||||
} ) { | ||||||||||||
const [ isPlaceholderShown, setIsPlaceholderShown ] = useState( | ||||||||||||
! hasExistingNavItems | ||||||||||||
|
@@ -84,7 +77,7 @@ function Navigation( { | |||||||||||
className: 'wp-block-navigation__container', | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
allowedBlocks: ALLOWED_BLOCKS, | ||||||||||||
allowedBlocks, | ||||||||||||
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. If it's specified in the block.json, my feeling is a block developer shouldn't have to add some logic to the block edit function. Is there a way to make it work without it having to pass it through as a prop? 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. Yeh I mean this implementation is pretty naive and rough. More a POC really. That said, if we wanted to pursue this API we could intercept the gutenberg/packages/block-editor/src/components/inner-blocks/index.js Lines 37 to 41 in f3ad70f
I'm unsure how we'd determine priority between
I guess always honour 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 imagine block.json could override the prop, with the prop deprecated. |
||||||||||||
orientation: attributes.orientation || 'horizontal', | ||||||||||||
renderAppender: | ||||||||||||
( isImmediateParentOfSelectedBlock && | ||||||||||||
|
@@ -183,6 +176,11 @@ function Navigation( { | |||||||||||
|
||||||||||||
export default compose( [ | ||||||||||||
withSelect( ( select, { clientId } ) => { | ||||||||||||
const allowedBlocks = getBlockSupport( | ||||||||||||
getdave marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
'core/navigation', | ||||||||||||
'__experimentalAllowedBlocks' | ||||||||||||
); | ||||||||||||
|
||||||||||||
const innerBlocks = select( blockEditorStore ).getBlocks( clientId ); | ||||||||||||
const { | ||||||||||||
getClientIdsOfDescendants, | ||||||||||||
|
@@ -202,7 +200,7 @@ export default compose( [ | |||||||||||
isImmediateParentOfSelectedBlock, | ||||||||||||
selectedBlockHasDescendants, | ||||||||||||
hasExistingNavItems: !! innerBlocks.length, | ||||||||||||
|
||||||||||||
allowedBlocks, | ||||||||||||
// This prop is already available but computing it here ensures it's | ||||||||||||
// fresh compared to isImmediateParentOfSelectedBlock | ||||||||||||
isSelected: selectedBlockId === clientId, | ||||||||||||
|
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.
I wonder if it should be part of
supports
or just a normal block property. 🤔