UNPKG

@wordpress/block-library

Version:
29 lines (28 loc) • 1.39 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_data = require("@wordpress/data"); let _wordpress_block_editor = require("@wordpress/block-editor"); // packages/block-library/src/navigation-link/shared/use-enable-link-status-validation.js /** * Hook to determine if link status validation should be enabled. * * Link status validation is enabled when the root Navigation block is selected * or any of its inner blocks are selected. This ensures validation only runs * when the user is actively working within the navigation structure. * * @param {string} clientId The client ID of the current block. * @return {boolean} Whether link status validation should be enabled. */ function useEnableLinkStatusValidation(clientId) { return (0, _wordpress_data.useSelect)((select) => { const { getSelectedBlockClientId, hasSelectedInnerBlock, getBlockParentsByBlockName } = select(_wordpress_block_editor.store); const selectedBlockId = getSelectedBlockClientId(); const rootNavigationId = getBlockParentsByBlockName(clientId, "core/navigation")[0]; return selectedBlockId === rootNavigationId || hasSelectedInnerBlock(rootNavigationId, true); }, [clientId]); } exports.useEnableLinkStatusValidation = useEnableLinkStatusValidation; //# sourceMappingURL=use-enable-link-status-validation.cjs.map