@wordpress/block-library
Version:
Block library for the WordPress editor.
34 lines (33 loc) • 1.64 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_data = require("@wordpress/data");
let _wordpress_core_data = require("@wordpress/core-data");
let ___navigation_constants_js = require("../navigation/constants.cjs");
// 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 = (0, _wordpress_data.select)("core/editor");
if (!editorStore) return false;
const { getCurrentPostType, getCurrentPostId } = editorStore;
const { getEditedEntityRecord } = (0, _wordpress_data.select)(_wordpress_core_data.store);
const postType = getCurrentPostType?.();
const postId = getCurrentPostId?.();
if (postType === "wp_template_part" && postId) return getEditedEntityRecord("postType", "wp_template_part", postId)?.area === ___navigation_constants_js.NAVIGATION_OVERLAY_TEMPLATE_PART_AREA;
return false;
}
exports.isWithinNavigationOverlay = isWithinNavigationOverlay;
//# sourceMappingURL=is-within-overlay.cjs.map