UNPKG

@wordpress/block-library

Version:
28 lines (27 loc) • 1.58 kB
import { store } from "@wordpress/block-editor"; import { store as store$1 } from "@wordpress/core-data"; import { useSelect } from "@wordpress/data"; import { createTemplatePartId } from "../template-part/edit/utils/create-template-part-id.mjs"; import { getTemplatePartIcon } from "../template-part/edit/utils/get-template-part-icon.mjs"; // packages/block-library/src/navigation/use-template-part-area-label.js function useTemplatePartAreaLabel(clientId) { return useSelect((select) => { if (!clientId) return; const { getBlock, getBlockParentsByBlockName } = select(store); const parentTemplatePartClientIds = getBlockParentsByBlockName(clientId, "core/template-part", true); if (!parentTemplatePartClientIds?.length) return; const { getCurrentTheme, getEditedEntityRecord } = select(store$1); const currentTheme = getCurrentTheme(); const definedAreas = (currentTheme?.default_template_part_areas || []).map((item) => ({ ...item, icon: getTemplatePartIcon(item.icon) })); for (const templatePartClientId of parentTemplatePartClientIds) { const { theme = currentTheme?.stylesheet, slug } = getBlock(templatePartClientId).attributes; const templatePartEntity = getEditedEntityRecord("postType", "wp_template_part", createTemplatePartId(theme, slug)); if (templatePartEntity?.area) return definedAreas.find((definedArea) => definedArea.area !== "uncategorized" && definedArea.area === templatePartEntity.area)?.label; } }, [clientId]); } export { useTemplatePartAreaLabel as default }; //# sourceMappingURL=use-template-part-area-label.mjs.map