@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
53 lines (51 loc) • 1.83 kB
JavaScript
;
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/core-data/src/utils/crdt-text.ts
var crdt_text_exports = {};
__export(crdt_text_exports, {
createRichTextDataCache: () => createRichTextDataCache,
getCachedRichTextData: () => getCachedRichTextData
});
module.exports = __toCommonJS(crdt_text_exports);
var import_rich_text = require("@wordpress/rich-text");
var RICH_TEXT_CACHE_MAX_SIZE = 500;
function createRichTextDataCache(maxSize) {
const cache = /* @__PURE__ */ new Map();
return function(value) {
const cached = cache.get(value);
if (cached) {
return cached;
}
const result = import_rich_text.RichTextData.fromHTMLString(value);
if (cache.size >= maxSize) {
cache.delete(cache.keys().next().value);
}
cache.set(value, result);
return result;
};
}
var getCachedRichTextData = createRichTextDataCache(
RICH_TEXT_CACHE_MAX_SIZE
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createRichTextDataCache,
getCachedRichTextData
});
//# sourceMappingURL=crdt-text.cjs.map