From 575cbaa3812afd0bccdc75ea7df64bee8289ab6c Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Tue, 14 Jan 2025 09:49:44 +0530 Subject: [PATCH] Fix: Add isNavigationBlock utility to identify navigation blocks --- .../use-block-display-information/index.js | 5 ++++- packages/blocks/README.md | 12 ++++++++++++ packages/blocks/src/api/index.js | 1 + packages/blocks/src/api/registration.js | 12 ++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index 0da99d415f53f..f9605046e0b37 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -6,6 +6,7 @@ import { store as blocksStore, isReusableBlock, isTemplatePart, + isNavigationBlock, __experimentalGetBlockLabel as getBlockLabel, } from '@wordpress/blocks'; import { __ } from '@wordpress/i18n'; @@ -83,7 +84,9 @@ export default function useBlockDisplayInformation( clientId ) { const attributes = getBlockAttributes( clientId ); const match = getActiveBlockVariation( blockName, attributes ); const isSynced = - isReusableBlock( blockType ) || isTemplatePart( blockType ); + isReusableBlock( blockType ) || + isTemplatePart( blockType ) || + isNavigationBlock( blockType ); const syncedTitle = isSynced ? getBlockLabel( blockType, attributes ) : undefined; diff --git a/packages/blocks/README.md b/packages/blocks/README.md index f4805e1c60b38..2d55764f4b9f3 100644 --- a/packages/blocks/README.md +++ b/packages/blocks/README.md @@ -365,6 +365,18 @@ _Returns_ - `boolean`: True if a block contains at least one child blocks with inserter support and false otherwise. +### isNavigationBlock + +Determines whether or not the given block is a navigation block. This is a special block type that is used to represent a navigation menu. + +_Parameters_ + +- _blockOrType_ `Object`: Block or Block Type to test. + +_Returns_ + +- `boolean`: Whether the given block is a navigation block. + ### isReusableBlock Determines whether or not the given block is a reusable block. This is a special block type that is used to point to a global block stored via the API. diff --git a/packages/blocks/src/api/index.js b/packages/blocks/src/api/index.js index fbfe16384fa7e..c740715a63158 100644 --- a/packages/blocks/src/api/index.js +++ b/packages/blocks/src/api/index.js @@ -133,6 +133,7 @@ export { getBlockVariations, isReusableBlock, isTemplatePart, + isNavigationBlock, getChildBlockNames, hasChildBlocks, hasChildBlocksWithInserterSupport, diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index 2886632e2ab0e..936abf32390e4 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -579,6 +579,18 @@ export function isTemplatePart( blockOrType ) { return blockOrType?.name === 'core/template-part'; } +/** + * Determines whether or not the given block is a navigation block. This is a + * special block type that is used to represent a navigation menu. + * + * @param {Object} blockOrType Block or Block Type to test. + * + * @return {boolean} Whether the given block is a navigation block. + */ +export function isNavigationBlock( blockOrType ) { + return blockOrType?.name === 'core/navigation'; +} + /** * Returns an array with the child blocks of a given block. *