magic-editor-x 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +493 -168
  3. package/dist/admin/{ConfigurationPage-3Dir3dAf.mjs → ConfigurationPage-BxLHIQdo.mjs} +450 -21
  4. package/dist/admin/{ConfigurationPage-YvnPnna6.js → ConfigurationPage-C-UktL1x.js} +479 -50
  5. package/dist/admin/ConfirmAction-DuQwvRYi.mjs +125 -0
  6. package/dist/admin/ConfirmAction-zLuIFj8t.js +124 -0
  7. package/dist/admin/{CustomBlocksPage-BiiL2ORG.js → CustomBlocksPage-CxcTfdOT.js} +135 -84
  8. package/dist/admin/{CustomBlocksPage-CR2BaP9O.mjs → CustomBlocksPage-D8aMbVXc.mjs} +92 -41
  9. package/dist/admin/DraftSync-BIA8cZgA.js +11 -0
  10. package/dist/admin/DraftSync-CUxOMG-E.mjs +12 -0
  11. package/dist/admin/TemplatesPage-Hn6gyu2l.js +993 -0
  12. package/dist/admin/TemplatesPage-jhYi6Zdf.mjs +993 -0
  13. package/dist/admin/{de-BmmLBJli.mjs → de-1cFMs-4c.mjs} +2 -0
  14. package/dist/admin/{de-BteRx2iA.js → de-2Ie5jy7j.js} +79 -1
  15. package/dist/admin/{de-62Vxb2iw.js → de-B1X46JJZ.js} +205 -2
  16. package/dist/admin/{de-CFX5atOk.mjs → de-BMY2LBaa.mjs} +79 -1
  17. package/dist/admin/{de-Bt6pYIWi.mjs → de-BUS1hUw0.mjs} +145 -0
  18. package/dist/admin/{de-CVbi685U.js → de-C3AsGauQ.js} +145 -0
  19. package/dist/admin/{de-BVvwSYYO.mjs → de-DOiGaTNX.mjs} +205 -2
  20. package/dist/admin/{de-DaJwN6nk.js → de-Dn8athM8.js} +2 -0
  21. package/dist/admin/{en-CyjAcccB.js → en-Ah-Cw0Wd.js} +79 -1
  22. package/dist/admin/{en-BX362fTp.js → en-BkEjpC3i.js} +145 -0
  23. package/dist/admin/{en-VlkaIzrM.js → en-CDg_18Bt.js} +205 -2
  24. package/dist/admin/{en-Cn78RZs-.js → en-CIZ5Ggod.js} +2 -0
  25. package/dist/admin/{en-Cg2Ak5Cr.mjs → en-CU6UzV4g.mjs} +205 -2
  26. package/dist/admin/{en-ea0tfA5i.mjs → en-CvFiqti2.mjs} +79 -1
  27. package/dist/admin/{en-D7mZWLGp.mjs → en-Dc9y-6n9.mjs} +2 -0
  28. package/dist/admin/{en-B_HltUxZ.mjs → en-GCzgS9Aw.mjs} +145 -0
  29. package/dist/admin/{es-BT9oAcHf.js → es-BCpJmUEM.js} +205 -2
  30. package/dist/admin/{es-C9-cXdb6.mjs → es-BmfffNM2.mjs} +205 -2
  31. package/dist/admin/{es-BmGtLkJD.js → es-C4IRHV5d.js} +2 -0
  32. package/dist/admin/{es-CHHEZi44.js → es-C4pEnDRv.js} +145 -0
  33. package/dist/admin/{es-C8GZFGjv.js → es-Cr8JH85N.js} +79 -1
  34. package/dist/admin/{es-joykG5I9.mjs → es-D2Kw6E4N.mjs} +2 -0
  35. package/dist/admin/{es-CrhwOq-5.mjs → es-DHBBZKl2.mjs} +145 -0
  36. package/dist/admin/{es-CEi_ycX8.mjs → es-DbKHZz5l.mjs} +79 -1
  37. package/dist/admin/{fr-CrzxGe5e.mjs → fr-BOvvfEH7.mjs} +2 -0
  38. package/dist/admin/{fr-B3SL0TBV.js → fr-C2aLSwEu.js} +145 -0
  39. package/dist/admin/{fr-BAMSvQbR.mjs → fr-DQJ_7aq5.mjs} +79 -1
  40. package/dist/admin/{fr-DpU_qiXR.mjs → fr-DZd2XJP6.mjs} +205 -2
  41. package/dist/admin/{fr-5djKfQ3s.mjs → fr-Dvq4xk2e.mjs} +145 -0
  42. package/dist/admin/{fr-oRCJNdeJ.js → fr-OJ4VW1kh.js} +79 -1
  43. package/dist/admin/{fr-D6KJqPWi.js → fr-ZcN0yM_2.js} +205 -2
  44. package/dist/admin/{fr-Ct_uPqxV.js → fr-Zkb8vfjN.js} +2 -0
  45. package/dist/admin/index-BHBRr562.js +1940 -0
  46. package/dist/admin/index-CQk1XeNb.mjs +1939 -0
  47. package/dist/admin/{EditorField-Diq1j8kc.js → index-Cm-fFUhE.js} +13704 -6766
  48. package/dist/admin/{EditorField-B8pyAxPE.mjs → index-XgfwqLfV.mjs} +10203 -3265
  49. package/dist/admin/index.js +1 -1
  50. package/dist/admin/index.mjs +2 -2
  51. package/dist/admin/{pt-chN2jrXl.js → pt-1IUyx6ae.js} +2 -0
  52. package/dist/admin/{pt-CQrfqsCN.mjs → pt-BSLzA17U.mjs} +79 -1
  53. package/dist/admin/{pt-jUqOR7Xh.mjs → pt-C3UdeIpd.mjs} +205 -2
  54. package/dist/admin/{pt-BOrl6x-r.js → pt-CImqDnLB.js} +205 -2
  55. package/dist/admin/{pt-BdnY2Cth.mjs → pt-CilDggGF.mjs} +145 -0
  56. package/dist/admin/{pt-tUeJ2Ywd.js → pt-D0I0_JYs.js} +79 -1
  57. package/dist/admin/{pt-EVwCuBUK.js → pt-DX0OAIoL.js} +145 -0
  58. package/dist/admin/{pt-Ga-4Hsv0.mjs → pt-etwsg3G4.mjs} +2 -0
  59. package/dist/admin/useBreakpoint-D30eNTkF.js +37 -0
  60. package/dist/admin/useBreakpoint-DCfn6pDG.mjs +38 -0
  61. package/dist/admin/useT-CmaeZbCr.mjs +65 -0
  62. package/dist/admin/{useT-BWZ_-Hel.js → useT-D3sM9Zf7.js} +4 -70
  63. package/dist/blocks/index.d.mts +167 -0
  64. package/dist/blocks/index.d.ts +167 -0
  65. package/dist/blocks/index.js +631 -0
  66. package/dist/blocks/index.mjs +609 -0
  67. package/dist/react/index.d.mts +39 -0
  68. package/dist/react/index.d.ts +39 -0
  69. package/dist/react/index.js +2687 -0
  70. package/dist/react/index.mjs +2657 -0
  71. package/dist/render/index.d.mts +131 -5
  72. package/dist/render/index.d.ts +131 -5
  73. package/dist/render/index.js +1679 -181
  74. package/dist/render/index.mjs +1679 -181
  75. package/dist/server/index.js +10645 -3716
  76. package/dist/server/index.mjs +10645 -3716
  77. package/dist/vue/index.d.mts +41 -0
  78. package/dist/vue/index.d.ts +41 -0
  79. package/dist/vue/index.js +2630 -0
  80. package/dist/vue/index.mjs +2610 -0
  81. package/package.json +30 -6
  82. package/schema/magic-editor-x.schema.json +540 -1
  83. package/types/blocks.d.ts +167 -0
  84. package/types/index.d.ts +127 -0
  85. package/types/react.d.ts +39 -0
  86. package/types/render.d.ts +131 -5
  87. package/types/vue.d.ts +41 -0
  88. package/dist/admin/api-Dsq53giv.js +0 -37
  89. package/dist/admin/api-RZ0Fz0BD.mjs +0 -38
  90. package/dist/admin/index-C-lyON1B.mjs +0 -303
  91. package/dist/admin/index-iA0lued_.js +0 -302
  92. package/dist/admin/sanitize-Cb4jvBhj.js +0 -628
  93. package/dist/admin/sanitize-ClkX823p.mjs +0 -627
  94. package/dist/admin/useT-pvHmgBFj.mjs +0 -131
@@ -1,628 +0,0 @@
1
- "use strict";
2
- const createDOMPurify = require("dompurify");
3
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
4
- const createDOMPurify__default = /* @__PURE__ */ _interopDefault(createDOMPurify);
5
- const EDITOR_DATA_LIMITS = Object.freeze({
6
- maxBlocks: 5e3,
7
- maxBytes: 5 * 1024 * 1024,
8
- maxDepth: 24,
9
- maxBlockIdLength: 64,
10
- maxTypeLength: 64
11
- });
12
- const FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
13
- const BLOCK_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
14
- const BLOCK_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
15
- const isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
16
- class EditorDataError extends Error {
17
- /**
18
- * @param {string} message - Fixed, non-sensitive message.
19
- * @param {string} code - Machine-readable reason.
20
- */
21
- constructor(message, code) {
22
- super(message);
23
- this.name = "EditorDataError";
24
- this.code = code;
25
- }
26
- }
27
- const cloneJsonSafe = (value, depth = 0) => {
28
- if (depth > EDITOR_DATA_LIMITS.maxDepth) {
29
- throw new EditorDataError("Editor content is nested too deeply", "TOO_DEEP");
30
- }
31
- if (value === null) return null;
32
- if (Array.isArray(value)) {
33
- const out = [];
34
- for (const item of value) {
35
- const cloned = cloneJsonSafe(item, depth + 1);
36
- out.push(cloned === void 0 ? null : cloned);
37
- }
38
- return out;
39
- }
40
- switch (typeof value) {
41
- case "string":
42
- case "boolean":
43
- return value;
44
- case "number":
45
- return Number.isFinite(value) ? value : null;
46
- case "object": {
47
- const out = {};
48
- for (const key of Object.keys(value)) {
49
- if (FORBIDDEN_KEYS.has(key)) continue;
50
- const cloned = cloneJsonSafe(value[key], depth + 1);
51
- if (cloned !== void 0) out[key] = cloned;
52
- }
53
- return out;
54
- }
55
- default:
56
- return void 0;
57
- }
58
- };
59
- const tryParseJson = (text) => {
60
- try {
61
- return { ok: true, value: JSON.parse(text) };
62
- } catch {
63
- return { ok: false };
64
- }
65
- };
66
- const escapeHtml = (text) => String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
67
- const hashString = (text) => {
68
- let hash = 2166136261;
69
- for (let i = 0; i < text.length; i += 1) {
70
- hash ^= text.charCodeAt(i);
71
- hash = Math.imul(hash, 16777619) >>> 0;
72
- }
73
- return hash.toString(16).padStart(8, "0");
74
- };
75
- const legacyBlockId = (index, type, data) => `mx${hashString(`${index}:${type}:${JSON.stringify(data)}`)}${index}`;
76
- const textToBlocks = (text) => {
77
- const trimmed = text.trim();
78
- if (!trimmed) return [];
79
- const looksLikeHtml = /<\/?[a-z][^>]{0,200}>/i.test(trimmed.slice(0, 2e3));
80
- if (looksLikeHtml) {
81
- return [{ type: "paragraph", data: { text: trimmed } }];
82
- }
83
- return trimmed.split(/\r?\n\s*\r?\n/).map((part) => part.trim()).filter(Boolean).map((part) => ({ type: "paragraph", data: { text: escapeHtml(part).replace(/\r?\n/g, "<br>") } }));
84
- };
85
- const unwrapValue = (value) => {
86
- let current = value;
87
- let legacy = false;
88
- for (let i = 0; i < 3 && typeof current === "string"; i += 1) {
89
- const text = current.trim();
90
- if (!text) return { candidate: null, legacy: true };
91
- if (text.startsWith("{") || text.startsWith("[") || text.startsWith('"')) {
92
- const parsed = tryParseJson(text);
93
- if (parsed.ok) {
94
- current = parsed.value;
95
- legacy = true;
96
- continue;
97
- }
98
- }
99
- return { candidate: { blocks: textToBlocks(text) }, legacy: true };
100
- }
101
- if (Array.isArray(current)) {
102
- return { candidate: { blocks: current }, legacy: true };
103
- }
104
- return { candidate: current, legacy };
105
- };
106
- const normalizeEditorData = (value) => {
107
- if (value === null || value === void 0) return null;
108
- if (typeof value === "string" && value.length > EDITOR_DATA_LIMITS.maxBytes) {
109
- throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
110
- }
111
- const { candidate } = unwrapValue(value);
112
- if (candidate === null || candidate === void 0) return null;
113
- if (!isPlainObject(candidate)) {
114
- throw new EditorDataError("Editor content must be an Editor.js object", "INVALID_SHAPE");
115
- }
116
- const clean = cloneJsonSafe(candidate);
117
- const rawBlocks = Array.isArray(clean.blocks) ? clean.blocks : [];
118
- if (rawBlocks.length > EDITOR_DATA_LIMITS.maxBlocks) {
119
- throw new EditorDataError("Editor content has too many blocks", "TOO_MANY_BLOCKS");
120
- }
121
- const seen = /* @__PURE__ */ new Set();
122
- const blocks = [];
123
- rawBlocks.forEach((block, index) => {
124
- if (!isPlainObject(block)) return;
125
- const type = typeof block.type === "string" ? block.type.trim() : "";
126
- if (!BLOCK_TYPE_PATTERN.test(type)) return;
127
- const data = isPlainObject(block.data) ? block.data : {};
128
- let id = typeof block.id === "string" && BLOCK_ID_PATTERN.test(block.id) ? block.id : "";
129
- if (!id || seen.has(id)) id = legacyBlockId(index, type, data);
130
- while (seen.has(id)) id = `${id}x`;
131
- seen.add(id);
132
- const normalized = { id, type, data };
133
- if (isPlainObject(block.tunes) && Object.keys(block.tunes).length > 0) normalized.tunes = block.tunes;
134
- blocks.push(normalized);
135
- });
136
- const time = Number.isFinite(clean.time) && clean.time > 0 ? Math.floor(clean.time) : 0;
137
- const version = typeof clean.version === "string" && clean.version.length <= 32 ? clean.version : "2.31.7";
138
- const result = { time, blocks, version };
139
- const size = byteLength(JSON.stringify(result));
140
- if (size > EDITOR_DATA_LIMITS.maxBytes) {
141
- throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
142
- }
143
- return result;
144
- };
145
- const normalizeEditorDataSafe = (value) => {
146
- try {
147
- return normalizeEditorData(value);
148
- } catch {
149
- return null;
150
- }
151
- };
152
- const byteLength = (text) => {
153
- let bytes = 0;
154
- for (let i = 0; i < text.length; i += 1) {
155
- const code = text.charCodeAt(i);
156
- if (code < 128) bytes += 1;
157
- else if (code < 2048) bytes += 2;
158
- else if (code >= 55296 && code <= 56319) {
159
- bytes += 4;
160
- i += 1;
161
- } else bytes += 3;
162
- }
163
- return bytes;
164
- };
165
- const computeStats = (data) => {
166
- if (!data || !Array.isArray(data.blocks)) return { blocks: 0, words: 0, characters: 0 };
167
- let text = "";
168
- const collect = (value, depth = 0) => {
169
- if (depth > 8 || value === null || value === void 0) return;
170
- if (typeof value === "string") {
171
- text += ` ${value.replace(/<[^>]{0,500}>/g, " ").replace(/&nbsp;/g, " ")}`;
172
- } else if (Array.isArray(value)) value.forEach((item) => collect(item, depth + 1));
173
- else if (typeof value === "object") {
174
- for (const [key, item] of Object.entries(value)) {
175
- if (["url", "link", "href", "src", "id", "documentId", "style", "type", "service"].includes(key))
176
- continue;
177
- collect(item, depth + 1);
178
- }
179
- }
180
- };
181
- data.blocks.forEach((block) => collect(block.data));
182
- const normalized = text.replace(/\s+/g, " ").trim();
183
- return {
184
- blocks: data.blocks.length,
185
- words: normalized ? normalized.split(" ").length : 0,
186
- characters: normalized.length
187
- };
188
- };
189
- const INLINE_TAGS = Object.freeze([
190
- "b",
191
- "strong",
192
- "i",
193
- "em",
194
- "u",
195
- "s",
196
- "mark",
197
- "code",
198
- "a",
199
- "br",
200
- "span",
201
- "sub",
202
- "sup"
203
- ]);
204
- const INTERNAL_LINK_ATTRIBUTES = Object.freeze([
205
- "data-mex-uid",
206
- "data-mex-document-id",
207
- "data-mex-locale"
208
- ]);
209
- const INTERNAL_LINK_RULES = Object.freeze({
210
- "data-mex-uid": /^api::[a-z0-9-]{1,60}\.[a-z0-9-]{1,60}$/,
211
- "data-mex-document-id": /^[a-z0-9]{1,64}$/,
212
- "data-mex-locale": /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8}){0,3}$/
213
- });
214
- const cleanInternalLinkAttributes = (attribs) => {
215
- const out = {};
216
- if (!attribs || typeof attribs !== "object") return out;
217
- for (const name of INTERNAL_LINK_ATTRIBUTES) {
218
- const value = attribs[name];
219
- if (typeof value === "string" && INTERNAL_LINK_RULES[name].test(value)) out[name] = value;
220
- }
221
- if (!out["data-mex-uid"] || !out["data-mex-document-id"]) return {};
222
- return out;
223
- };
224
- const INLINE_ATTRIBUTES = Object.freeze({
225
- a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
226
- span: ["class", "data-tooltip"],
227
- mark: ["class"],
228
- u: ["class"],
229
- s: ["class"],
230
- code: ["class"]
231
- });
232
- const INLINE_CLASSES = Object.freeze({
233
- span: ["cdx-tooltip"],
234
- mark: ["cdx-marker"],
235
- u: ["cdx-underline"],
236
- s: ["cdx-strikethrough", "cdx-strikethroughs"],
237
- code: ["inline-code"]
238
- });
239
- const LINK_SCHEMES = Object.freeze(["http", "https", "mailto", "tel"]);
240
- const MAX_URL_LENGTH = 2048;
241
- const TARGETS = /* @__PURE__ */ new Set(["_blank", "_self", "_parent", "_top"]);
242
- const sanitizeUrl = (value, options = {}) => {
243
- const schemes = options.schemes || LINK_SCHEMES;
244
- const allowRelative = options.allowRelative !== false;
245
- if (typeof value !== "string") return "";
246
- const url = value.trim();
247
- if (!url || url.length > MAX_URL_LENGTH) return "";
248
- if (/[\u0000-\u001f\u007f\s]/.test(url) && !/^(mailto|tel):/i.test(url)) return "";
249
- if (url.startsWith("//") || url.startsWith("\\")) return "";
250
- const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]{0,20}):/.exec(url);
251
- if (!scheme) {
252
- return allowRelative && /^[/#?.]/.test(url) ? url : "";
253
- }
254
- if (!schemes.includes(scheme[1].toLowerCase())) return "";
255
- if (scheme[1].toLowerCase().startsWith("http")) {
256
- try {
257
- const parsed = new URL(url);
258
- if (parsed.username || parsed.password) return "";
259
- } catch {
260
- return "";
261
- }
262
- }
263
- return url;
264
- };
265
- const plain = (value, max = 1e5) => typeof value === "string" ? value.slice(0, max) : "";
266
- const oneOf = (value, allowed, fallback) => typeof value === "string" && allowed.includes(value) ? value : fallback;
267
- const int = (value, min, max, fallback) => {
268
- const number = typeof value === "string" ? Number(value) : value;
269
- return Number.isInteger(number) && number >= min && number <= max ? number : fallback;
270
- };
271
- const bool = (value) => value === true;
272
- const generic = (value, inline, depth = 0, key = "") => {
273
- if (depth > 20) return null;
274
- if (typeof value === "string") {
275
- if (/^(url|href|link|src|photo|source|embed)$/i.test(key)) return sanitizeUrl(value);
276
- return inline(value);
277
- }
278
- if (Array.isArray(value)) return value.map((item) => generic(item, inline, depth + 1, key));
279
- if (isPlainObject(value)) {
280
- const out = {};
281
- for (const [childKey, child] of Object.entries(value))
282
- out[childKey] = generic(child, inline, depth + 1, childKey);
283
- return out;
284
- }
285
- return value;
286
- };
287
- const listItems = (items, inline, depth = 0) => {
288
- if (!Array.isArray(items) || depth > 12) return [];
289
- return items.map((item) => {
290
- if (typeof item === "string") return inline(item);
291
- if (!isPlainObject(item)) return { content: "", items: [] };
292
- const out = { content: inline(typeof item.content === "string" ? item.content : plain(item.text)) };
293
- if (isPlainObject(item.meta)) {
294
- const meta = {};
295
- if (typeof item.meta.checked === "boolean") meta.checked = item.meta.checked;
296
- const start = int(item.meta.start, 0, 1e5, void 0);
297
- if (start !== void 0) meta.start = start;
298
- if (typeof item.meta.counterType === "string") {
299
- meta.counterType = oneOf(
300
- item.meta.counterType,
301
- ["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
302
- "numeric"
303
- );
304
- }
305
- out.meta = meta;
306
- }
307
- out.items = listItems(item.items, inline, depth + 1);
308
- return out;
309
- });
310
- };
311
- const BLOCK_POLICIES = {
312
- paragraph: (d, inline) => ({ text: inline(d.text) }),
313
- header: (d, inline) => ({ text: inline(d.text), level: int(d.level, 1, 6, 2) }),
314
- quote: (d, inline) => ({
315
- text: inline(d.text),
316
- caption: inline(d.caption),
317
- alignment: oneOf(d.alignment, ["left", "center"], "left")
318
- }),
319
- list: (d, inline) => {
320
- const out = {
321
- style: oneOf(d.style, ["ordered", "unordered", "checklist"], "unordered"),
322
- items: listItems(d.items, inline)
323
- };
324
- if (isPlainObject(d.meta)) {
325
- const meta = {};
326
- const start = int(d.meta.start, 0, 1e5, void 0);
327
- if (start !== void 0) meta.start = start;
328
- if (typeof d.meta.counterType === "string") {
329
- meta.counterType = oneOf(
330
- d.meta.counterType,
331
- ["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
332
- "numeric"
333
- );
334
- }
335
- out.meta = meta;
336
- }
337
- return out;
338
- },
339
- checklist: (d, inline) => ({
340
- items: Array.isArray(d.items) ? d.items.filter(isPlainObject).map((item) => ({ text: inline(item.text), checked: bool(item.checked) })) : []
341
- }),
342
- warning: (d, inline) => ({ title: inline(d.title), message: inline(d.message) }),
343
- alert: (d, inline) => ({
344
- type: oneOf(
345
- d.type,
346
- ["primary", "secondary", "info", "success", "warning", "danger", "light", "dark"],
347
- "info"
348
- ),
349
- align: oneOf(d.align, ["left", "center", "right"], "left"),
350
- message: inline(d.message)
351
- }),
352
- toggle: (d, inline) => ({
353
- text: inline(d.text),
354
- status: oneOf(d.status, ["open", "closed"], "open"),
355
- fk: typeof d.fk === "string" ? d.fk.slice(0, 64) : void 0,
356
- items: int(d.items, 0, 5e3, 0)
357
- }),
358
- code: (d) => ({ code: plain(d.code, 5e5) }),
359
- codeFlask: (d) => {
360
- const out = {
361
- code: plain(d.code, 5e5),
362
- language: typeof d.language === "string" && /^[a-z0-9+#-]{1,32}$/i.test(d.language) ? d.language : "plaintext"
363
- };
364
- if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
365
- return out;
366
- },
367
- raw: (d, _inline, ctx) => {
368
- const html = plain(d.html, 5e5);
369
- if (ctx.rawHtml === "allow") return { html };
370
- if (ctx.rawHtml === "disable") return { html: "" };
371
- return { html: ctx.rawSanitizer(html) };
372
- },
373
- table: (d, inline) => ({
374
- withHeadings: bool(d.withHeadings),
375
- stretched: bool(d.stretched),
376
- content: Array.isArray(d.content) ? d.content.slice(0, 500).map((row) => Array.isArray(row) ? row.slice(0, 100).map((cell) => inline(cell)) : []) : []
377
- }),
378
- image: (d, inline) => {
379
- const file = isPlainObject(d.file) ? d.file : {};
380
- const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
381
- for (const key of ["mime", "alt", "name", "hash", "ext"])
382
- if (typeof file[key] === "string") cleanFile[key] = plain(file[key], 500);
383
- for (const key of ["width", "height", "size"]) if (Number.isFinite(file[key])) cleanFile[key] = file[key];
384
- if (isPlainObject(file.formats))
385
- cleanFile.formats = generic(file.formats, (s) => plain(s, 2048), 0, "formats");
386
- if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
387
- cleanFile.id = file.id;
388
- if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
389
- const out = {
390
- file: cleanFile,
391
- caption: inline(d.caption),
392
- withBorder: bool(d.withBorder),
393
- withBackground: bool(d.withBackground),
394
- stretched: bool(d.stretched)
395
- };
396
- if (d.decorative === true) out.decorative = true;
397
- return out;
398
- },
399
- simpleImage: (d, inline) => {
400
- const out = {
401
- url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
402
- caption: inline(d.caption),
403
- withBorder: bool(d.withBorder),
404
- withBackground: bool(d.withBackground),
405
- stretched: bool(d.stretched)
406
- };
407
- if (typeof d.alt === "string") out.alt = plain(d.alt, 500);
408
- if (d.decorative === true) out.decorative = true;
409
- return out;
410
- },
411
- linkTool: (d) => {
412
- const meta = isPlainObject(d.meta) ? d.meta : {};
413
- const image = isPlainObject(meta.image) ? { url: sanitizeUrl(meta.image.url, { schemes: ["http", "https"] }) } : void 0;
414
- const cleanMeta = { title: plain(meta.title, 500), description: plain(meta.description, 2e3) };
415
- if (typeof meta.site_name === "string") cleanMeta.site_name = plain(meta.site_name, 200);
416
- if (image && image.url) cleanMeta.image = image;
417
- return { link: sanitizeUrl(d.link, { schemes: ["http", "https"] }), meta: cleanMeta };
418
- },
419
- attaches: (d) => {
420
- const file = isPlainObject(d.file) ? d.file : {};
421
- const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
422
- if (typeof file.name === "string") cleanFile.name = plain(file.name, 255);
423
- if (typeof file.extension === "string") cleanFile.extension = plain(file.extension, 16);
424
- if (Number.isFinite(file.size)) cleanFile.size = file.size;
425
- if (typeof file.title === "string") cleanFile.title = plain(file.title, 255);
426
- return { file: cleanFile, title: plain(d.title, 255) };
427
- },
428
- embed: (d, inline) => ({
429
- service: typeof d.service === "string" && /^[a-z0-9_-]{1,40}$/i.test(d.service) ? d.service : "",
430
- source: sanitizeUrl(d.source, { schemes: ["https", "http"], allowRelative: false }),
431
- embed: sanitizeUrl(d.embed, { schemes: ["https"], allowRelative: false }),
432
- width: int(d.width, 1, 1e4, void 0),
433
- height: int(d.height, 1, 1e4, void 0),
434
- caption: inline(d.caption)
435
- }),
436
- personality: (d) => ({
437
- name: plain(d.name, 500),
438
- description: plain(d.description, 2e3),
439
- link: sanitizeUrl(d.link, { schemes: ["http", "https", "mailto"] }),
440
- photo: sanitizeUrl(d.photo, { schemes: ["http", "https"] })
441
- }),
442
- button: (d) => ({
443
- text: plain(d.text, 200),
444
- link: sanitizeUrl(d.link),
445
- style: oneOf(d.style, ["primary", "secondary", "outline", "ghost", "danger", "success"], "primary"),
446
- openInNewTab: bool(d.openInNewTab)
447
- }),
448
- delimiter: () => ({})
449
- };
450
- const sanitizeTunes = (tunes) => {
451
- if (!isPlainObject(tunes)) return void 0;
452
- const out = {};
453
- if (isPlainObject(tunes.alignmentTune)) {
454
- out.alignmentTune = {
455
- alignment: oneOf(tunes.alignmentTune.alignment, ["left", "center", "right", "justify"], "left")
456
- };
457
- }
458
- if (typeof tunes.textVariant === "string") {
459
- out.textVariant = oneOf(tunes.textVariant, ["", "call-out", "citation", "details"], "");
460
- }
461
- if (isPlainObject(tunes.indentTune)) {
462
- out.indentTune = { indentLevel: int(tunes.indentTune.indentLevel, 0, 10, 0) };
463
- }
464
- return Object.keys(out).length ? out : void 0;
465
- };
466
- const sanitizeEditorData = (data, options) => {
467
- if (!data) return data;
468
- const inline = (value) => typeof value === "string" ? options.sanitizeInlineHtml(value) : "";
469
- const ctx = { rawHtml: options.rawHtml || "sanitize", rawSanitizer: options.sanitizeRawHtml };
470
- const blocks = data.blocks.map((block) => {
471
- const policy = Object.prototype.hasOwnProperty.call(BLOCK_POLICIES, block.type) ? BLOCK_POLICIES[block.type] : null;
472
- const cleanData = policy ? policy(block.data || {}, inline, ctx) : generic(block.data || {}, inline, 0);
473
- for (const key of Object.keys(cleanData)) if (cleanData[key] === void 0) delete cleanData[key];
474
- const out = { id: block.id, type: block.type, data: cleanData };
475
- const tunes = sanitizeTunes(block.tunes);
476
- if (tunes) out.tunes = tunes;
477
- return out;
478
- });
479
- return { time: data.time, blocks, version: data.version };
480
- };
481
- const sanitizeTarget = (value) => typeof value === "string" && TARGETS.has(value) ? value : null;
482
- let purify = null;
483
- const instance = () => {
484
- if (purify) return purify;
485
- purify = createDOMPurify__default.default(window);
486
- purify.addHook("uponSanitizeAttribute", (node, data) => {
487
- const tag = node.nodeName.toLowerCase();
488
- if (data.attrName === "class") {
489
- const allowed = INLINE_CLASSES[tag] || [];
490
- const kept = String(data.attrValue).split(/\s+/).filter((name) => allowed.includes(name));
491
- if (kept.length === 0) data.keepAttr = false;
492
- else data.attrValue = kept.join(" ");
493
- }
494
- if (data.attrName === "href") {
495
- const safe = sanitizeUrl(data.attrValue);
496
- if (!safe) data.keepAttr = false;
497
- else data.attrValue = safe;
498
- }
499
- if (data.attrName === "target" && !["_blank", "_self", "_parent", "_top"].includes(data.attrValue))
500
- data.keepAttr = false;
501
- });
502
- purify.addHook("afterSanitizeAttributes", (node) => {
503
- if (node.nodeName === "A" && node.getAttribute("target") === "_blank")
504
- node.setAttribute("rel", "noopener noreferrer");
505
- if (typeof node.hasAttribute !== "function") return;
506
- if (!INTERNAL_LINK_ATTRIBUTES.some((name) => node.hasAttribute(name))) return;
507
- const kept = node.nodeName === "A" ? cleanInternalLinkAttributes(
508
- Object.fromEntries(INTERNAL_LINK_ATTRIBUTES.map((name) => [name, node.getAttribute(name)]))
509
- ) : {};
510
- for (const name of INTERNAL_LINK_ATTRIBUTES) {
511
- if (kept[name]) node.setAttribute(name, kept[name]);
512
- else node.removeAttribute(name);
513
- }
514
- });
515
- return purify;
516
- };
517
- const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat()));
518
- const sanitizeInline = (html) => instance().sanitize(String(html || ""), {
519
- ALLOWED_TAGS: [...INLINE_TAGS],
520
- ALLOWED_ATTR,
521
- ALLOW_DATA_ATTR: false,
522
- // DOMPurify checks attribute values like URIs; `api::article.article` looks
523
- // like an unknown scheme and was dropped, which removed the entry reference
524
- // of internal links whenever content was shown again. The values are
525
- // validated by cleanInternalLinkAttributes in the hook above.
526
- ADD_URI_SAFE_ATTR: [...INTERNAL_LINK_ATTRIBUTES]
527
- });
528
- const sanitizeTemplate = (html) => instance().sanitize(String(html || ""), {
529
- ALLOWED_TAGS: [
530
- "div",
531
- "span",
532
- "p",
533
- "h2",
534
- "h3",
535
- "h4",
536
- "strong",
537
- "b",
538
- "em",
539
- "i",
540
- "u",
541
- "s",
542
- "small",
543
- "br",
544
- "hr",
545
- "ul",
546
- "ol",
547
- "li",
548
- "blockquote",
549
- "figure",
550
- "figcaption",
551
- "img",
552
- "a",
553
- "section",
554
- "header",
555
- "footer",
556
- "code",
557
- "pre",
558
- "mark"
559
- ],
560
- ALLOWED_ATTR: [
561
- "class",
562
- "data-field",
563
- "title",
564
- "href",
565
- "target",
566
- "rel",
567
- "src",
568
- "alt",
569
- "width",
570
- "height",
571
- "loading"
572
- ],
573
- ALLOW_DATA_ATTR: false
574
- });
575
- const sanitizeSvg = (svg) => instance().sanitize(String(svg || ""), {
576
- USE_PROFILES: { svg: true, svgFilters: false },
577
- FORBID_TAGS: ["style", "use", "image", "foreignObject", "a", "script"],
578
- FORBID_ATTR: ["style", "href", "xlink:href"]
579
- });
580
- const prepareEditorValue = (value, rawHtml = "allow") => {
581
- try {
582
- const data = normalizeEditorData(value);
583
- if (!data) return { data: null, error: null };
584
- return {
585
- data: sanitizeEditorData(data, {
586
- sanitizeInlineHtml: sanitizeInline,
587
- sanitizeRawHtml: (html) => html,
588
- rawHtml
589
- }),
590
- error: null
591
- };
592
- } catch (error) {
593
- return { data: null, error: error && error.code || "INVALID" };
594
- }
595
- };
596
- const prepareRemoteData = (data, cache) => {
597
- const blocks = [];
598
- for (const block of data && data.blocks || []) {
599
- let clean = cache.get(block);
600
- if (clean === void 0) {
601
- const prepared = prepareEditorValue({ time: data.time, version: data.version, blocks: [block] }).data;
602
- clean = prepared && prepared.blocks.length === 1 ? prepared.blocks[0] : null;
603
- cache.set(block, clean);
604
- }
605
- if (clean) blocks.push(clean);
606
- }
607
- return { time: data && data.time || Date.now(), version: data && data.version || "2.31.7", blocks };
608
- };
609
- exports.BLOCK_POLICIES = BLOCK_POLICIES;
610
- exports.EDITOR_DATA_LIMITS = EDITOR_DATA_LIMITS;
611
- exports.INLINE_ATTRIBUTES = INLINE_ATTRIBUTES;
612
- exports.INLINE_CLASSES = INLINE_CLASSES;
613
- exports.INLINE_TAGS = INLINE_TAGS;
614
- exports.cleanInternalLinkAttributes = cleanInternalLinkAttributes;
615
- exports.cloneJsonSafe = cloneJsonSafe;
616
- exports.computeStats = computeStats;
617
- exports.escapeHtml = escapeHtml;
618
- exports.hashString = hashString;
619
- exports.isPlainObject = isPlainObject;
620
- exports.normalizeEditorDataSafe = normalizeEditorDataSafe;
621
- exports.prepareEditorValue = prepareEditorValue;
622
- exports.prepareRemoteData = prepareRemoteData;
623
- exports.sanitizeInline = sanitizeInline;
624
- exports.sanitizeSvg = sanitizeSvg;
625
- exports.sanitizeTarget = sanitizeTarget;
626
- exports.sanitizeTemplate = sanitizeTemplate;
627
- exports.sanitizeTunes = sanitizeTunes;
628
- exports.sanitizeUrl = sanitizeUrl;