UNPKG

@wordpress/editor

Version:
60 lines (56 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTemplateInfo = void 0; var _icons = require("@wordpress/icons"); var _getTemplatePartIcon = require("./get-template-part-icon"); /** * WordPress dependencies */ /** * Internal dependencies */ const EMPTY_OBJECT = {}; /** * Helper function to retrieve the corresponding template info for a given template. * @param {Object} params * @param {Array} params.templateTypes * @param {Array} [params.templateAreas] * @param {Object} params.template */ const getTemplateInfo = params => { var _Object$values$find; if (!params) { return EMPTY_OBJECT; } const { templateTypes, templateAreas, template } = params; const { description, slug, title, area } = template; const { title: defaultTitle, description: defaultDescription } = (_Object$values$find = Object.values(templateTypes).find(type => type.slug === slug)) !== null && _Object$values$find !== void 0 ? _Object$values$find : EMPTY_OBJECT; const templateTitle = typeof title === 'string' ? title : title?.rendered; const templateDescription = typeof description === 'string' ? description : description?.raw; const templateAreasWithIcon = templateAreas?.map(item => ({ ...item, icon: (0, _getTemplatePartIcon.getTemplatePartIcon)(item.icon) })); const templateIcon = templateAreasWithIcon?.find(item => area === item.area)?.icon || _icons.layout; return { title: templateTitle && templateTitle !== slug ? templateTitle : defaultTitle || slug, description: templateDescription || defaultDescription, icon: templateIcon }; }; exports.getTemplateInfo = getTemplateInfo; //# sourceMappingURL=get-template-info.js.map