UNPKG

@wordpress/block-library

Version:
29 lines (28 loc) • 1.39 kB
import { select } from "@wordpress/data"; import { store } from "@wordpress/core-data"; import { NAVIGATION_OVERLAY_TEMPLATE_PART_AREA } from "../navigation/constants.mjs"; // packages/block-library/src/utils/is-within-overlay.js /** * Checks if the current editing context is within a navigation overlay template part. * * This utility exists because `@wordpress/block-library` cannot depend on `@wordpress/editor` * as a package dependency. Blocks can be loaded into non-post block editors, so we must * access the 'core/editor' store by string literal rather than importing it. * * React components should wrap this in useSelect for reactivity. Non-React contexts * (like filter callbacks) can call this directly. * * @return {boolean} True if editing a navigation overlay template part, false otherwise. */ function isWithinNavigationOverlay() { const editorStore = select("core/editor"); if (!editorStore) return false; const { getCurrentPostType, getCurrentPostId } = editorStore; const { getEditedEntityRecord } = select(store); const postType = getCurrentPostType?.(); const postId = getCurrentPostId?.(); if (postType === "wp_template_part" && postId) return getEditedEntityRecord("postType", "wp_template_part", postId)?.area === NAVIGATION_OVERLAY_TEMPLATE_PART_AREA; return false; } export { isWithinNavigationOverlay }; //# sourceMappingURL=is-within-overlay.mjs.map