UNPKG

@wordpress/editor

Version:
79 lines (77 loc) 2.37 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/editor/src/utils/terms.js var terms_exports = {}; __export(terms_exports, { buildTermsTree: () => buildTermsTree, unescapeString: () => unescapeString, unescapeTerm: () => unescapeTerm, unescapeTerms: () => unescapeTerms }); module.exports = __toCommonJS(terms_exports); var import_html_entities = require("@wordpress/html-entities"); function buildTermsTree(flatTerms) { const flatTermsWithParentAndChildren = flatTerms.map((term) => { return { children: [], parent: void 0, ...term }; }); if (flatTermsWithParentAndChildren.some( ({ parent }) => parent === void 0 )) { return flatTermsWithParentAndChildren; } const termsById = /* @__PURE__ */ Object.create(null); for (const term of flatTermsWithParentAndChildren) { term.children = []; termsById[term.id] = term; } const tree = []; for (const term of flatTermsWithParentAndChildren) { const parent = termsById[term.parent]; if (parent) { parent.children.push(term); } else if (`${term.parent}` === "0") { tree.push(term); } } return tree; } var unescapeString = (arg) => { return (0, import_html_entities.decodeEntities)(arg); }; var unescapeTerm = (term) => { return { ...term, name: unescapeString(term.name) }; }; var unescapeTerms = (terms) => { return (terms ?? []).map(unescapeTerm); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { buildTermsTree, unescapeString, unescapeTerm, unescapeTerms }); //# sourceMappingURL=terms.cjs.map