@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
51 lines (50 loc) • 1.57 kB
JavaScript
/**
* WordPress dependencies
*/
import { layout } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { getTemplatePartIcon } from './get-template-part-icon';
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
*/
export 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: getTemplatePartIcon(item.icon)
}));
const templateIcon = templateAreasWithIcon?.find(item => area === item.area)?.icon || layout;
return {
title: templateTitle && templateTitle !== slug ? templateTitle : defaultTitle || slug,
description: templateDescription || defaultDescription,
icon: templateIcon
};
};
//# sourceMappingURL=get-template-info.js.map