@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 1.77 kB
Source Map (JSON)
{"version":3,"file":"use-enable-link-status-validation.cjs","names":["useSelect","blockEditorStore"],"sources":["../../../src/navigation-link/shared/use-enable-link-status-validation.js"],"sourcesContent":["import { 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":";;;;;;;;;;;;;;;;;;AAaA,SAAgB,8BAA+B,UAAW;CACzD,QAAA,GAAOA,gBAAAA,UAAAA,EACJ,WAAY;EACb,MAAM,EACL,0BACA,uBACA,+BACG,OAAQC,wBAAAA,KAAiB;EAE7B,MAAM,kBAAkB,yBAAyB;EACjD,MAAM,mBAAmB,2BACxB,UACA,iBACD,CAAC,CAAE;EAGH,OACC,oBAAoB,oBACpB,sBAAuB,kBAAkB,IAAK;CAEhD,GACA,CAAE,QAAS,CACZ;AACD"}