From 31189e4d937bc09111f5047065e4f99c3d74b9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 5 Oct 2021 14:11:49 +0200 Subject: [PATCH 1/7] Replace BlockEdit filter with block context --- .../block-library/src/navigation/block.json | 1 + packages/block-library/src/navigation/edit.js | 25 ++- .../src/components/layout/index.js | 157 ++++++++++-------- ...disable-inserting-non-navigation-blocks.js | 28 ---- packages/edit-navigation/src/filters/index.js | 10 +- .../remove-edit-unsupported-features.js | 30 ---- packages/edit-navigation/src/index.js | 8 +- 7 files changed, 111 insertions(+), 148 deletions(-) delete mode 100644 packages/edit-navigation/src/filters/disable-inserting-non-navigation-blocks.js delete mode 100644 packages/edit-navigation/src/filters/remove-edit-unsupported-features.js diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index 273ac75dd65f3e..c40b0b3d7a9432 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -91,6 +91,7 @@ "__experimentalTextDecoration": true } }, + "usesContext": [ "navigation" ], "viewScript": "file:./view.min.js", "editorStyle": "wp-block-navigation-editor", "style": "wp-block-navigation" diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index d5ef92a4c894f2..80edeebeffc24b 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -96,6 +96,7 @@ function Navigation( { selectedBlockHasDescendants, attributes, setAttributes, + context: { navigation }, clientId, hasExistingNavItems, isImmediateParentOfSelectedBlock, @@ -111,11 +112,6 @@ function Navigation( { overlayTextColor, setOverlayTextColor, - // These props are used by the navigation editor to override specific - // navigation block settings. - hasSubmenuIndicatorSetting = true, - hasItemJustificationControls = true, - hasColorSettings = true, customPlaceholder: CustomPlaceholder = null, customAppender: CustomAppender = null, } ) { @@ -126,6 +122,17 @@ function Navigation( { false ); + // The context is used by the navigation editor to override specific + // navigation block settings. + const contextSettings = { + allowedBlocks: navigation?.allowedBlocks || ALLOWED_BLOCKS, + hasSubmenuIndicatorSetting: + navigation?.hasSubmenuIndicatorSetting ?? true, + hasItemJustificationControls: + navigation?.hasItemJustificationControls ?? true, + hasColorSettings: navigation?.hasColorSettings ?? true, + }; + const { selectBlock } = useDispatch( blockEditorStore ); const navRef = useRef(); @@ -173,7 +180,7 @@ function Navigation( { className: 'wp-block-navigation__container', }, { - allowedBlocks: ALLOWED_BLOCKS, + allowedBlocks: contextSettings.allowedBlocks, __experimentalDefaultBlock: DEFAULT_BLOCK, __experimentalDirectInsert: DIRECT_INSERT, orientation: attributes.orientation, @@ -253,7 +260,7 @@ function Navigation( { return ( <> - { hasItemJustificationControls && ( + { contextSettings.hasItemJustificationControls && ( { navigatorModal } - { hasSubmenuIndicatorSetting && ( + { contextSettings.hasSubmenuIndicatorSetting && ( ) } - { hasColorSettings && ( + { contextSettings.hasColorSettings && ( { + const context = { + hasSubmenuIndicatorSetting: false, + hasItemJustificationControls: false, + hasColorSettings: false, + }; + if ( ! blockEditorSettings.blockNavMenus ) { + context.allowedBlocks = [ + 'core/navigation', + 'core/navigation-link', + 'core/navigation-submenu', + ]; + } + return { navigation: context }; + }, [ blockEditorSettings.blockNavMenus ] ); + useEffect( () => { if ( ! selectedMenuId && menus?.length ) { selectMenu( menus[ 0 ].id ); @@ -127,77 +144,83 @@ export default function Layout( { blockEditorSettings } ) { } } useSubRegistry={ false } > - [ - isMenuNameControlFocused, - setIsMenuNameControlFocused, - ], - [ isMenuNameControlFocused ] - ) } - > - - } - content={ - <> - - { ! hasFinishedInitialLoad && ( - - ) } - - { ! isMenuSelected && - hasFinishedInitialLoad && ( - + + [ + isMenuNameControlFocused, + setIsMenuNameControlFocused, + ], + [ isMenuNameControlFocused ] + ) } + > + + } + content={ + <> + + { ! hasFinishedInitialLoad && ( + ) } - { isBlockEditorReady && ( -
- - - -
- ) } - - } - sidebar={ - hasSidebarEnabled && ( - - ) - } - secondarySidebar={ - isInserterOpened && - } - /> - { isMenuSelected && ( - + + + + + ) } + + } + sidebar={ + hasSidebarEnabled && ( + + ) + } + secondarySidebar={ + isInserterOpened && + } /> - ) } -
- + { isMenuSelected && ( + + ) } +
+ + diff --git a/packages/edit-navigation/src/filters/disable-inserting-non-navigation-blocks.js b/packages/edit-navigation/src/filters/disable-inserting-non-navigation-blocks.js deleted file mode 100644 index f8426c7dd9137d..00000000000000 --- a/packages/edit-navigation/src/filters/disable-inserting-non-navigation-blocks.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * WordPress dependencies - */ -import { addFilter } from '@wordpress/hooks'; -/** - * External dependencies - */ -import { set } from 'lodash'; - -function disableInsertingNonNavigationBlocks( settings, name ) { - if ( - ! [ - 'core/navigation', - 'core/navigation-link', - 'core/navigation-submenu', - ].includes( name ) - ) { - set( settings, [ 'supports', 'inserter' ], false ); - } - return settings; -} - -export default () => - addFilter( - 'blocks.registerBlockType', - 'core/edit-navigation/disable-inserting-non-navigation-blocks', - disableInsertingNonNavigationBlocks - ); diff --git a/packages/edit-navigation/src/filters/index.js b/packages/edit-navigation/src/filters/index.js index 17074eb87c6603..e00c28a97cffc9 100644 --- a/packages/edit-navigation/src/filters/index.js +++ b/packages/edit-navigation/src/filters/index.js @@ -4,19 +4,11 @@ import addNavigationEditorCustomAppender from './add-navigation-editor-custom-appender'; import addNavigationEditorPlaceholder from './add-navigation-editor-placeholder'; import addMenuNameEditor from './add-menu-name-editor'; -import disableInsertingNonNavigationBlocks from './disable-inserting-non-navigation-blocks'; -import removeEditUnsupportedFeatures from './remove-edit-unsupported-features'; import removeSettingsUnsupportedFeatures from './remove-settings-unsupported-features'; -export const addFilters = ( - shouldAddDisableInsertingNonNavigationBlocksFilter -) => { +export const addFilters = () => { addNavigationEditorCustomAppender(); addNavigationEditorPlaceholder(); addMenuNameEditor(); - if ( shouldAddDisableInsertingNonNavigationBlocksFilter ) { - disableInsertingNonNavigationBlocks(); - } - removeEditUnsupportedFeatures(); removeSettingsUnsupportedFeatures(); }; diff --git a/packages/edit-navigation/src/filters/remove-edit-unsupported-features.js b/packages/edit-navigation/src/filters/remove-edit-unsupported-features.js deleted file mode 100644 index 2c58b995158d4d..00000000000000 --- a/packages/edit-navigation/src/filters/remove-edit-unsupported-features.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * WordPress dependencies - */ -import { addFilter } from '@wordpress/hooks'; -import { createHigherOrderComponent } from '@wordpress/compose'; - -const removeNavigationBlockEditUnsupportedFeatures = createHigherOrderComponent( - ( BlockEdit ) => ( props ) => { - if ( props.name !== 'core/navigation' ) { - return ; - } - - return ( - - ); - }, - 'removeNavigationBlockEditUnsupportedFeatures' -); - -export default () => - addFilter( - 'editor.BlockEdit', - 'core/edit-navigation/remove-navigation-block-edit-unsupported-features', - removeNavigationBlockEditUnsupportedFeatures - ); diff --git a/packages/edit-navigation/src/index.js b/packages/edit-navigation/src/index.js index fe3629e2829494..ff3f2f66050139 100644 --- a/packages/edit-navigation/src/index.js +++ b/packages/edit-navigation/src/index.js @@ -53,11 +53,9 @@ function NavEditor( { settings } ) { /** * Setup and registration of editor. - * - * @param {Object} settings blockEditor settings. */ -function setUpEditor( settings ) { - addFilters( ! settings.blockNavMenus ); +function setUpEditor( ) { + addFilters(); registerCoreBlocks(); // Set up the navigation post entity. @@ -83,7 +81,7 @@ function setUpEditor( settings ) { * @param {Object} settings blockEditor settings. */ export function initialize( id, settings ) { - setUpEditor( settings ); + setUpEditor(); render( , From a836a4de536532a8c6bb381f563ee03cdcc4aee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 5 Oct 2021 14:20:24 +0200 Subject: [PATCH 2/7] Pass customPlaceholder via nav context --- packages/block-library/src/navigation/edit.js | 37 ++++++++++--------- .../src/components/layout/index.js | 2 + .../add-navigation-editor-placeholder.js | 29 --------------- packages/edit-navigation/src/filters/index.js | 2 - packages/edit-navigation/src/index.js | 2 +- 5 files changed, 23 insertions(+), 49 deletions(-) delete mode 100644 packages/edit-navigation/src/filters/add-navigation-editor-placeholder.js diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index 80edeebeffc24b..029c1643f9fac9 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -2,6 +2,7 @@ * External dependencies */ import classnames from 'classnames'; +import { defaults } from 'lodash'; /** * WordPress dependencies @@ -50,6 +51,14 @@ const ALLOWED_BLOCKS = [ 'core/navigation-submenu', ]; +const CONTEXT_DEFAULTS = { + allowedBlocks: ALLOWED_BLOCKS, + hasSubmenuIndicatorSetting: true, + hasItemJustificationControls: true, + hasColorSettings: true, + customPlaceholder: NavigationPlaceholder, +}; + const DEFAULT_BLOCK = [ 'core/navigation-link' ]; const DIRECT_INSERT = ( block ) => { @@ -112,7 +121,6 @@ function Navigation( { overlayTextColor, setOverlayTextColor, - customPlaceholder: CustomPlaceholder = null, customAppender: CustomAppender = null, } ) { const [ isPlaceholderShown, setIsPlaceholderShown ] = useState( @@ -124,14 +132,7 @@ function Navigation( { // The context is used by the navigation editor to override specific // navigation block settings. - const contextSettings = { - allowedBlocks: navigation?.allowedBlocks || ALLOWED_BLOCKS, - hasSubmenuIndicatorSetting: - navigation?.hasSubmenuIndicatorSetting ?? true, - hasItemJustificationControls: - navigation?.hasItemJustificationControls ?? true, - hasColorSettings: navigation?.hasColorSettings ?? true, - }; + const navContext = defaults( CONTEXT_DEFAULTS, navigation ); const { selectBlock } = useDispatch( blockEditorStore ); @@ -180,7 +181,7 @@ function Navigation( { className: 'wp-block-navigation__container', }, { - allowedBlocks: contextSettings.allowedBlocks, + allowedBlocks: navContext.allowedBlocks, __experimentalDefaultBlock: DEFAULT_BLOCK, __experimentalDirectInsert: DIRECT_INSERT, orientation: attributes.orientation, @@ -196,7 +197,11 @@ function Navigation( { // inherit templateLock={ 'all' }. templateLock: false, __experimentalLayout: LAYOUT, - placeholder: ! CustomPlaceholder ? placeholder : undefined, + placeholder: + navContext.customPlaceholder === + CONTEXT_DEFAULTS.customPlaceholder + ? placeholder + : undefined, } ); @@ -233,9 +238,7 @@ function Navigation( { } ); if ( isPlaceholderShown ) { - const PlaceholderComponent = CustomPlaceholder - ? CustomPlaceholder - : NavigationPlaceholder; + const PlaceholderComponent = navContext.customPlaceholder; return (
@@ -260,7 +263,7 @@ function Navigation( { return ( <> - { contextSettings.hasItemJustificationControls && ( + { navContext.hasItemJustificationControls && ( { navigatorModal } - { contextSettings.hasSubmenuIndicatorSetting && ( + { navContext.hasSubmenuIndicatorSetting && ( ) } - { contextSettings.hasColorSettings && ( + { navContext.hasColorSettings && ( ( props ) => { - if ( props.name !== 'core/navigation' ) { - return ; - } - return ( - - ); - }, - 'withNavigationEditorPlaceholder' -); - -export default () => - addFilter( - 'editor.BlockEdit', - 'core/edit-navigation/with-navigation-editor-placeholder', - addNavigationEditorPlaceholder - ); diff --git a/packages/edit-navigation/src/filters/index.js b/packages/edit-navigation/src/filters/index.js index e00c28a97cffc9..724e850f1369b2 100644 --- a/packages/edit-navigation/src/filters/index.js +++ b/packages/edit-navigation/src/filters/index.js @@ -2,13 +2,11 @@ * Internal dependencies */ import addNavigationEditorCustomAppender from './add-navigation-editor-custom-appender'; -import addNavigationEditorPlaceholder from './add-navigation-editor-placeholder'; import addMenuNameEditor from './add-menu-name-editor'; import removeSettingsUnsupportedFeatures from './remove-settings-unsupported-features'; export const addFilters = () => { addNavigationEditorCustomAppender(); - addNavigationEditorPlaceholder(); addMenuNameEditor(); removeSettingsUnsupportedFeatures(); }; diff --git a/packages/edit-navigation/src/index.js b/packages/edit-navigation/src/index.js index ff3f2f66050139..9d8ba610019718 100644 --- a/packages/edit-navigation/src/index.js +++ b/packages/edit-navigation/src/index.js @@ -54,7 +54,7 @@ function NavEditor( { settings } ) { /** * Setup and registration of editor. */ -function setUpEditor( ) { +function setUpEditor() { addFilters(); registerCoreBlocks(); From d19fc486cafeb463f55b6a1960c2e5945ee30e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 5 Oct 2021 14:39:28 +0200 Subject: [PATCH 3/7] Add custom appender to the nav context --- packages/block-library/src/navigation/edit.js | 15 ++-- .../src/components/layout/index.js | 17 ++++- .../add-navigation-editor-custom-appender.js | 76 ------------------- packages/edit-navigation/src/filters/index.js | 2 - 4 files changed, 23 insertions(+), 87 deletions(-) delete mode 100644 packages/edit-navigation/src/filters/add-navigation-editor-custom-appender.js diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index 029c1643f9fac9..dd9c389bdf0913 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -57,6 +57,9 @@ const CONTEXT_DEFAULTS = { hasItemJustificationControls: true, hasColorSettings: true, customPlaceholder: NavigationPlaceholder, + + createAppender: ( wouldNavBlockShowAppender ) => + wouldNavBlockShowAppender ? undefined : false, }; const DEFAULT_BLOCK = [ 'core/navigation-link' ]; @@ -120,8 +123,6 @@ function Navigation( { setOverlayBackgroundColor, overlayTextColor, setOverlayTextColor, - - customAppender: CustomAppender = null, } ) { const [ isPlaceholderShown, setIsPlaceholderShown ] = useState( ! hasExistingNavItems @@ -170,11 +171,9 @@ function Navigation( { // When the block is selected itself or has a top level item selected that // doesn't itself have children, show the standard appender. Else show no // appender. - const appender = + const wouldNavBlockShowAppender = isSelected || - ( isImmediateParentOfSelectedBlock && ! selectedBlockHasDescendants ) - ? undefined - : false; + ( isImmediateParentOfSelectedBlock && ! selectedBlockHasDescendants ); const innerBlocksProps = useInnerBlocksProps( { @@ -185,7 +184,9 @@ function Navigation( { __experimentalDefaultBlock: DEFAULT_BLOCK, __experimentalDirectInsert: DIRECT_INSERT, orientation: attributes.orientation, - renderAppender: CustomAppender || appender, + renderAppender: navContext.createAppender( + wouldNavBlockShowAppender + ), // Ensure block toolbar is not too far removed from item // being edited when in vertical mode. diff --git a/packages/edit-navigation/src/components/layout/index.js b/packages/edit-navigation/src/components/layout/index.js index 88512a6a38ca93..44c4c7da83d5f1 100644 --- a/packages/edit-navigation/src/components/layout/index.js +++ b/packages/edit-navigation/src/components/layout/index.js @@ -6,7 +6,9 @@ import { BlockEditorKeyboardShortcuts, BlockEditorProvider, BlockTools, + InnerBlocks, __unstableUseBlockSelectionClearer as useBlockSelectionClearer, + store as blockEditorStore, } from '@wordpress/block-editor'; import { useEntityBlockEditor } from '@wordpress/core-data'; import { Popover, SlotFillProvider, Spinner } from '@wordpress/components'; @@ -54,6 +56,10 @@ const interfaceLabels = { secondarySidebar: __( 'Block library' ), }; +function CustomAppender() { + return ; +} + export default function Layout( { blockEditorSettings } ) { const contentAreaRef = useBlockSelectionClearer(); const [ isMenuNameControlFocused, setIsMenuNameControlFocused ] = useState( @@ -82,12 +88,15 @@ export default function Layout( { blockEditorSettings } ) { } ); - const { hasSidebarEnabled, isInserterOpened } = useSelect( + const { hasSidebarEnabled, isInserterOpened, noBlockSelected } = useSelect( ( select ) => ( { hasSidebarEnabled: !! select( interfaceStore ).getActiveComplementaryArea( 'core/edit-navigation' ), isInserterOpened: select( editNavigationStore ).isInserterOpened(), + noBlockSelected: ! select( + blockEditorStore + ).getSelectedBlockClientId(), } ), [] ); @@ -98,6 +107,10 @@ export default function Layout( { blockEditorSettings } ) { hasItemJustificationControls: false, hasColorSettings: false, customPlaceholder: BlockPlaceholder, + createAppender: ( wouldNavBlockShowAppender ) => + wouldNavBlockShowAppender || noBlockSelected + ? CustomAppender + : false, }; if ( ! blockEditorSettings.blockNavMenus ) { context.allowedBlocks = [ @@ -107,7 +120,7 @@ export default function Layout( { blockEditorSettings } ) { ]; } return { navigation: context }; - }, [ blockEditorSettings.blockNavMenus ] ); + }, [ blockEditorSettings.blockNavMenus, noBlockSelected ] ); useEffect( () => { if ( ! selectedMenuId && menus?.length ) { diff --git a/packages/edit-navigation/src/filters/add-navigation-editor-custom-appender.js b/packages/edit-navigation/src/filters/add-navigation-editor-custom-appender.js deleted file mode 100644 index 6a3b5f64e94dce..00000000000000 --- a/packages/edit-navigation/src/filters/add-navigation-editor-custom-appender.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * WordPress dependencies - */ -import { useSelect } from '@wordpress/data'; -import { addFilter } from '@wordpress/hooks'; -import { createHigherOrderComponent } from '@wordpress/compose'; -import { - InnerBlocks, - store as blockEditorStore, -} from '@wordpress/block-editor'; - -function CustomAppender() { - return ; -} - -function EnhancedNavigationBlock( { blockEdit: BlockEdit, ...props } ) { - const clientId = props.clientId; - const { - noBlockSelected, - isSelected, - isImmediateParentOfSelectedBlock, - selectedBlockHasDescendants, - } = useSelect( - ( select ) => { - const { - getClientIdsOfDescendants, - hasSelectedInnerBlock, - getSelectedBlockClientId, - } = select( blockEditorStore ); - const _isImmediateParentOfSelectedBlock = hasSelectedInnerBlock( - clientId, - false - ); - const selectedBlockId = getSelectedBlockClientId(); - const _selectedBlockHasDescendants = !! getClientIdsOfDescendants( [ - selectedBlockId, - ] )?.length; - - return { - isSelected: selectedBlockId === clientId, - noBlockSelected: ! selectedBlockId, - isImmediateParentOfSelectedBlock: _isImmediateParentOfSelectedBlock, - selectedBlockHasDescendants: _selectedBlockHasDescendants, - }; - }, - [ clientId ] - ); - - const customAppender = - noBlockSelected || - isSelected || - ( isImmediateParentOfSelectedBlock && ! selectedBlockHasDescendants ) - ? CustomAppender - : false; - - return ; -} - -const addNavigationEditorCustomAppender = createHigherOrderComponent( - ( BlockEdit ) => ( props ) => { - if ( props.name !== 'core/navigation' ) { - return ; - } - - // Use a separate component so that `useSelect` only run on the navigation block. - return ; - }, - 'withNavigationEditorCustomAppender' -); - -export default () => - addFilter( - 'editor.BlockEdit', - 'core/edit-navigation/with-navigation-editor-custom-appender', - addNavigationEditorCustomAppender - ); diff --git a/packages/edit-navigation/src/filters/index.js b/packages/edit-navigation/src/filters/index.js index 724e850f1369b2..806d07dfa70f60 100644 --- a/packages/edit-navigation/src/filters/index.js +++ b/packages/edit-navigation/src/filters/index.js @@ -1,12 +1,10 @@ /** * Internal dependencies */ -import addNavigationEditorCustomAppender from './add-navigation-editor-custom-appender'; import addMenuNameEditor from './add-menu-name-editor'; import removeSettingsUnsupportedFeatures from './remove-settings-unsupported-features'; export const addFilters = () => { - addNavigationEditorCustomAppender(); addMenuNameEditor(); removeSettingsUnsupportedFeatures(); }; From c51e06b4a8fb9f7e4672cf635b460cd9789e65ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 5 Oct 2021 14:47:20 +0200 Subject: [PATCH 4/7] Reverse the defaults arguments order --- packages/block-library/src/navigation/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index dd9c389bdf0913..d000bcddf6af06 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -133,7 +133,7 @@ function Navigation( { // The context is used by the navigation editor to override specific // navigation block settings. - const navContext = defaults( CONTEXT_DEFAULTS, navigation ); + const navContext = defaults( navigation, CONTEXT_DEFAULTS ); const { selectBlock } = useDispatch( blockEditorStore ); From 7edab217712fb290e500eac38997451b31f6872c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 5 Oct 2021 15:08:47 +0200 Subject: [PATCH 5/7] Lint --- packages/block-library/src/navigation/edit.js | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index d000bcddf6af06..173d3de6a40965 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -39,25 +39,22 @@ 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', - 'core/site-title', - 'core/site-logo', - 'core/navigation-submenu', -]; - const CONTEXT_DEFAULTS = { - allowedBlocks: ALLOWED_BLOCKS, + allowedBlocks: [ + 'core/navigation-link', + 'core/search', + 'core/social-links', + 'core/page-list', + 'core/spacer', + 'core/home-link', + 'core/site-title', + 'core/site-logo', + 'core/navigation-submenu', + ], hasSubmenuIndicatorSetting: true, hasItemJustificationControls: true, hasColorSettings: true, customPlaceholder: NavigationPlaceholder, - createAppender: ( wouldNavBlockShowAppender ) => wouldNavBlockShowAppender ? undefined : false, }; From cfdb4635679e8ab227c69414d6bbbe18bbf10a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 5 Oct 2021 15:09:36 +0200 Subject: [PATCH 6/7] Rename customPlaceholder to just placeholder --- packages/block-library/src/navigation/edit.js | 8 ++++---- packages/edit-navigation/src/components/layout/index.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index 173d3de6a40965..bb3dfefc6c49bc 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -54,7 +54,7 @@ const CONTEXT_DEFAULTS = { hasSubmenuIndicatorSetting: true, hasItemJustificationControls: true, hasColorSettings: true, - customPlaceholder: NavigationPlaceholder, + placeholder: NavigationPlaceholder, createAppender: ( wouldNavBlockShowAppender ) => wouldNavBlockShowAppender ? undefined : false, }; @@ -196,8 +196,8 @@ function Navigation( { templateLock: false, __experimentalLayout: LAYOUT, placeholder: - navContext.customPlaceholder === - CONTEXT_DEFAULTS.customPlaceholder + navContext.placeholder === + CONTEXT_DEFAULTS.placeholder ? placeholder : undefined, } @@ -236,7 +236,7 @@ function Navigation( { } ); if ( isPlaceholderShown ) { - const PlaceholderComponent = navContext.customPlaceholder; + const PlaceholderComponent = navContext.placeholder; return (
diff --git a/packages/edit-navigation/src/components/layout/index.js b/packages/edit-navigation/src/components/layout/index.js index 44c4c7da83d5f1..04c0ad39319c53 100644 --- a/packages/edit-navigation/src/components/layout/index.js +++ b/packages/edit-navigation/src/components/layout/index.js @@ -106,7 +106,7 @@ export default function Layout( { blockEditorSettings } ) { hasSubmenuIndicatorSetting: false, hasItemJustificationControls: false, hasColorSettings: false, - customPlaceholder: BlockPlaceholder, + placeholder: BlockPlaceholder, createAppender: ( wouldNavBlockShowAppender ) => wouldNavBlockShowAppender || noBlockSelected ? CustomAppender From eac4e5bf094fe2dd47ac0eb84aa1aff70bffd94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 5 Oct 2021 15:52:07 +0200 Subject: [PATCH 7/7] Lint --- packages/block-library/src/navigation/edit.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index bb3dfefc6c49bc..6caf58881a2c80 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -196,8 +196,7 @@ function Navigation( { templateLock: false, __experimentalLayout: LAYOUT, placeholder: - navContext.placeholder === - CONTEXT_DEFAULTS.placeholder + navContext.placeholder === CONTEXT_DEFAULTS.placeholder ? placeholder : undefined, }