@wordpress/block-library
Version:
Block library for the WordPress editor.
33 lines (32 loc) • 1.98 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_core_data = require("@wordpress/core-data");
let _wordpress_data = require("@wordpress/data");
let ___template_part_edit_utils_create_template_part_id_js = require("../template-part/edit/utils/create-template-part-id.cjs");
let ___template_part_edit_utils_get_template_part_icon_js = require("../template-part/edit/utils/get-template-part-icon.cjs");
// packages/block-library/src/navigation/use-template-part-area-label.js
function useTemplatePartAreaLabel(clientId) {
return (0, _wordpress_data.useSelect)((select) => {
if (!clientId) return;
const { getBlock, getBlockParentsByBlockName } = select(_wordpress_block_editor.store);
const parentTemplatePartClientIds = getBlockParentsByBlockName(clientId, "core/template-part", true);
if (!parentTemplatePartClientIds?.length) return;
const { getCurrentTheme, getEditedEntityRecord } = select(_wordpress_core_data.store);
const currentTheme = getCurrentTheme();
const definedAreas = (currentTheme?.default_template_part_areas || []).map((item) => ({
...item,
icon: (0, ___template_part_edit_utils_get_template_part_icon_js.getTemplatePartIcon)(item.icon)
}));
for (const templatePartClientId of parentTemplatePartClientIds) {
const { theme = currentTheme?.stylesheet, slug } = getBlock(templatePartClientId).attributes;
const templatePartEntity = getEditedEntityRecord("postType", "wp_template_part", (0, ___template_part_edit_utils_create_template_part_id_js.createTemplatePartId)(theme, slug));
if (templatePartEntity?.area) return definedAreas.find((definedArea) => definedArea.area !== "uncategorized" && definedArea.area === templatePartEntity.area)?.label;
}
}, [clientId]);
}
exports.default = useTemplatePartAreaLabel;
//# sourceMappingURL=use-template-part-area-label.cjs.map