UNPKG

@wordpress/editor

Version:
58 lines (54 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getItemTitle = getItemTitle; exports.isTemplate = isTemplate; exports.isTemplateOrTemplatePart = isTemplateOrTemplatePart; exports.isTemplatePart = isTemplatePart; exports.isTemplateRemovable = isTemplateRemovable; var _htmlEntities = require("@wordpress/html-entities"); var _constants = require("../../store/constants"); /** * WordPress dependencies */ /** * Internal dependencies */ function isTemplate(post) { return post.type === _constants.TEMPLATE_POST_TYPE; } function isTemplatePart(post) { return post.type === _constants.TEMPLATE_PART_POST_TYPE; } function isTemplateOrTemplatePart(p) { return p.type === _constants.TEMPLATE_POST_TYPE || p.type === _constants.TEMPLATE_PART_POST_TYPE; } function getItemTitle(item) { if (typeof item.title === 'string') { return (0, _htmlEntities.decodeEntities)(item.title); } if ('rendered' in item.title) { return (0, _htmlEntities.decodeEntities)(item.title.rendered); } if ('raw' in item.title) { return (0, _htmlEntities.decodeEntities)(item.title.raw); } return ''; } /** * Check if a template is removable. * * @param template The template entity to check. * @return Whether the template is removable. */ function isTemplateRemovable(template) { if (!template) { return false; } // In patterns list page we map the templates parts to a different object // than the one returned from the endpoint. This is why we need to check for // two props whether is custom or has a theme file. return [template.source, template.source].includes(_constants.TEMPLATE_ORIGINS.custom) && !Boolean(template.type === 'wp_template' && template?.plugin) && !template.has_theme_file; } //# sourceMappingURL=utils.js.map