@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 1.81 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/navigation-link/shared/use-enable-link-status-validation.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Hook to determine if link status validation should be enabled.\n *\n * Link status validation is enabled when the root Navigation block is selected\n * or any of its inner blocks are selected. This ensures validation only runs\n * when the user is actively working within the navigation structure.\n *\n * @param {string} clientId The client ID of the current block.\n * @return {boolean} Whether link status validation should be enabled.\n */\nexport function useEnableLinkStatusValidation( clientId ) {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst selectedBlockId = getSelectedBlockClientId();\n\t\t\tconst rootNavigationId = getBlockParentsByBlockName(\n\t\t\t\tclientId,\n\t\t\t\t'core/navigation'\n\t\t\t)[ 0 ];\n\n\t\t\t// Enable when the root Navigation block is selected or any of its inner blocks.\n\t\t\treturn (\n\t\t\t\tselectedBlockId === rootNavigationId ||\n\t\t\t\thasSelectedInnerBlock( rootNavigationId, true )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n}\n"],
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,wBAAwB;AAYnC,SAAS,8BAA+B,UAAW;AACzD,SAAO;AAAA,IACN,CAAE,WAAY;AACb,YAAM;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,MACD,IAAI,OAAQ,gBAAiB;AAE7B,YAAM,kBAAkB,yBAAyB;AACjD,YAAM,mBAAmB;AAAA,QACxB;AAAA,QACA;AAAA,MACD,EAAG,CAAE;AAGL,aACC,oBAAoB,oBACpB,sBAAuB,kBAAkB,IAAK;AAAA,IAEhD;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AACD;",
"names": []
}