magic-editor-x 2.3.1 → 2.4.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.
- package/CHANGELOG.md +74 -0
- package/README.md +299 -142
- package/dist/admin/AuditPage-C2u6z4aN.js +381 -0
- package/dist/admin/AuditPage-guB0SiGS.mjs +381 -0
- package/dist/admin/{ConfigurationPage-CFP3lp9p.js → ConfigurationPage-D6uya-J1.js} +228 -13
- package/dist/admin/{ConfigurationPage-CYGDLjM7.mjs → ConfigurationPage-DiEpF1Rr.mjs} +222 -7
- package/dist/admin/ConfirmAction-CUhpngYU.js +71 -0
- package/dist/admin/ConfirmAction-CZjpduc3.mjs +72 -0
- package/dist/admin/{CustomBlocksPage-B5Q33N-s.mjs → CustomBlocksPage-Byt10-6c.mjs} +6 -4
- package/dist/admin/{CustomBlocksPage-DzPOSpfn.js → CustomBlocksPage-DP3h_wNd.js} +21 -19
- package/dist/admin/MentionsWidget-C2OCAmqq.js +227 -0
- package/dist/admin/MentionsWidget-sMkM9mHX.mjs +225 -0
- package/dist/admin/{TemplatesPage-BVkgafCK.js → TemplatesPage-DrSJdteI.js} +313 -17
- package/dist/admin/{TemplatesPage-4A8JNO_Z.mjs → TemplatesPage-Yp4OqFE2.mjs} +305 -9
- package/dist/admin/{ConfirmAction-DuQwvRYi.mjs → api-2ZRpHM3d.mjs} +19 -70
- package/dist/admin/{ConfirmAction-zLuIFj8t.js → api-bix9RLLI.js} +19 -70
- package/dist/admin/auditText-DIIYVR6k.mjs +110 -0
- package/dist/admin/auditText-DUhWu2Nx.js +109 -0
- package/dist/admin/comments-C7P41lan.js +86 -0
- package/dist/admin/comments-hfIbLQNO.mjs +87 -0
- package/dist/admin/{de-BMY2LBaa.mjs → de-BNPIGqhs.mjs} +41 -2
- package/dist/admin/{de-2Ie5jy7j.js → de-BhhGss1l.js} +41 -2
- package/dist/admin/{de-DOiGaTNX.mjs → de-CKz6CG3V.mjs} +191 -5
- package/dist/admin/{de-C3AsGauQ.js → de-CbBDnXeT.js} +140 -1
- package/dist/admin/{de-BUS1hUw0.mjs → de-DiCZrmH8.mjs} +140 -1
- package/dist/admin/{de-B1X46JJZ.js → de-zcV8D7nt.js} +191 -5
- package/dist/admin/{en-Ah-Cw0Wd.js → en-B9ApE1y1.js} +41 -2
- package/dist/admin/{en-CDg_18Bt.js → en-BMWhILnj.js} +191 -5
- package/dist/admin/{en-BkEjpC3i.js → en-CpehF0Kv.js} +140 -1
- package/dist/admin/{en-GCzgS9Aw.mjs → en-DCPMqFIa.mjs} +140 -1
- package/dist/admin/{en-CU6UzV4g.mjs → en-cYzqbASF.mjs} +191 -5
- package/dist/admin/{en-CvFiqti2.mjs → en-gFLeK9Ng.mjs} +41 -2
- package/dist/admin/{es-DbKHZz5l.mjs → es-BmwBgEgz.mjs} +41 -2
- package/dist/admin/{es-Cr8JH85N.js → es-C0W31rl8.js} +41 -2
- package/dist/admin/{es-BCpJmUEM.js → es-CQPh8PXw.js} +191 -5
- package/dist/admin/{es-C4pEnDRv.js → es-CawpzwyC.js} +140 -1
- package/dist/admin/{es-DHBBZKl2.mjs → es-Chs37IBR.mjs} +140 -1
- package/dist/admin/{es-BmfffNM2.mjs → es-DCamt1ek.mjs} +191 -5
- package/dist/admin/{fr-DQJ_7aq5.mjs → fr-CMWBNE5D.mjs} +41 -2
- package/dist/admin/{fr-C2aLSwEu.js → fr-COOsqexl.js} +140 -1
- package/dist/admin/{fr-Dvq4xk2e.mjs → fr-Dp5-XP29.mjs} +140 -1
- package/dist/admin/{fr-ZcN0yM_2.js → fr-DpC44Ol8.js} +191 -5
- package/dist/admin/{fr-OJ4VW1kh.js → fr-iGeIfEcU.js} +41 -2
- package/dist/admin/{fr-DZd2XJP6.mjs → fr-oW0t8bT5.mjs} +191 -5
- package/dist/admin/{index-DQVE0ymw.js → index-64wc26Bl.js} +17467 -10369
- package/dist/admin/{index-k8_a5o1A.mjs → index-BVjf1gVC.mjs} +13786 -6687
- package/dist/admin/{index-DR8sHkTk.js → index-D6Z7i8ba.js} +1003 -53
- package/dist/admin/{index-My6FjjHB.mjs → index-D_Fv8Non.mjs} +1032 -82
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.mjs +3 -2
- package/dist/admin/math-CIQ4Z_mY.mjs +47 -0
- package/dist/admin/math-vsK_06ZR.js +49 -0
- package/dist/admin/{pt-D0I0_JYs.js → pt-BHmXk2d9.js} +41 -2
- package/dist/admin/{pt-CImqDnLB.js → pt-Bo0Pm_Pt.js} +191 -5
- package/dist/admin/{pt-CilDggGF.mjs → pt-DALDvfBn.mjs} +140 -1
- package/dist/admin/{pt-BSLzA17U.mjs → pt-DFNgZ5_k.mjs} +41 -2
- package/dist/admin/{pt-DX0OAIoL.js → pt-DXy7G1x7.js} +140 -1
- package/dist/admin/{pt-C3UdeIpd.mjs → pt-uGpfRQLC.mjs} +191 -5
- package/dist/admin/{useT-DNphiBQR.js → useT-BXJLIPN4.js} +1 -1
- package/dist/admin/{useT-Cmg1jwwG.mjs → useT-CLPhBmBC.mjs} +1 -1
- package/dist/blocks/index.d.mts +2 -0
- package/dist/blocks/index.d.ts +2 -0
- package/dist/blocks/index.js +13 -2
- package/dist/blocks/index.mjs +13 -2
- package/dist/math/index.d.mts +27 -0
- package/dist/math/index.d.ts +27 -0
- package/dist/math/index.js +164 -0
- package/dist/math/index.mjs +134 -0
- package/dist/react/index.js +673 -91
- package/dist/react/index.mjs +673 -91
- package/dist/render/index.d.mts +26 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +779 -106
- package/dist/render/index.mjs +779 -106
- package/dist/server/index.js +10419 -4103
- package/dist/server/index.mjs +10419 -4103
- package/dist/vue/index.js +673 -91
- package/dist/vue/index.mjs +673 -91
- package/package.json +8 -2
- package/schema/magic-editor-x.schema.json +127 -2
- package/types/blocks.d.ts +2 -0
- package/types/index.d.ts +42 -0
- package/types/math.d.ts +27 -0
- package/types/render.d.ts +26 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Feather, Bell } from "@strapi/icons";
|
|
1
2
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Feather } from "@strapi/icons";
|
|
3
3
|
import createDOMPurify from "dompurify";
|
|
4
4
|
import { createElement } from "react";
|
|
5
5
|
import { createRoot } from "react-dom/client";
|
|
@@ -10,7 +10,8 @@ const PERMISSIONS = {
|
|
|
10
10
|
customBlocksManage: action("custom-blocks.manage"),
|
|
11
11
|
settingsRead: action("settings.read"),
|
|
12
12
|
settingsUpdate: action("settings.update"),
|
|
13
|
-
templatesManage: action("templates.manage")
|
|
13
|
+
templatesManage: action("templates.manage"),
|
|
14
|
+
auditRead: action("audit.read")
|
|
14
15
|
};
|
|
15
16
|
const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
|
|
16
17
|
const registry = /* @__PURE__ */ new Map();
|
|
@@ -41,7 +42,9 @@ const MARKED_BLOCKS = Object.freeze({
|
|
|
41
42
|
keys: Object.freeze(["file", "title", "caption", "loop", "tracks"]),
|
|
42
43
|
anchor: Object.freeze(["file", "object"])
|
|
43
44
|
}),
|
|
44
|
-
synced: Object.freeze({ keys: Object.freeze(["ref"]), anchor: Object.freeze(["ref", "string"]) })
|
|
45
|
+
synced: Object.freeze({ keys: Object.freeze(["ref"]), anchor: Object.freeze(["ref", "string"]) }),
|
|
46
|
+
// 2.4: math block. A Settings custom block named `math` could exist before 2.4.
|
|
47
|
+
math: Object.freeze({ keys: Object.freeze(["tex", "display"]), anchor: Object.freeze(["tex", "string"]) })
|
|
45
48
|
});
|
|
46
49
|
const isBuiltInMarker = (value) => Number.isInteger(value) && /** @type {number} */
|
|
47
50
|
value >= 1;
|
|
@@ -59,6 +62,21 @@ const isMarkedBuiltIn = (type, data) => {
|
|
|
59
62
|
if (isBuiltInMarker(data[BUILT_IN_MARKER])) return true;
|
|
60
63
|
return hasBuiltInShape(MARKED_BLOCKS[type], data);
|
|
61
64
|
};
|
|
65
|
+
const FIELD_KEY_PATTERN = /^[A-Za-z0-9_-]{16,32}$/;
|
|
66
|
+
const FIELD_KEY_LENGTH = 22;
|
|
67
|
+
const BASE64URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
68
|
+
const isValidFieldKey = (value) => typeof value === "string" && FIELD_KEY_PATTERN.test(value);
|
|
69
|
+
const createFieldKey = (fill) => {
|
|
70
|
+
const bytes = new Uint8Array(22);
|
|
71
|
+
const source = globalThis.crypto && typeof globalThis.crypto.getRandomValues === "function" ? (array) => globalThis.crypto.getRandomValues(array) : null;
|
|
72
|
+
if (!source) throw new Error("No cryptographic random source");
|
|
73
|
+
source(bytes);
|
|
74
|
+
let key = "";
|
|
75
|
+
for (let i = 0; i < FIELD_KEY_LENGTH; i += 1) key += BASE64URL[bytes[i] & 63];
|
|
76
|
+
return key;
|
|
77
|
+
};
|
|
78
|
+
const isPositionalFieldPath = (path) => typeof path === "string" && path.split(".").some((part) => /^\d+$/.test(part));
|
|
79
|
+
const basePathOf = (path) => String(path).split(".").filter((part) => !/^\d+$/.test(part)).join(".");
|
|
62
80
|
const EDITOR_DATA_LIMITS = Object.freeze({
|
|
63
81
|
maxBlocks: 5e3,
|
|
64
82
|
maxBytes: 5 * 1024 * 1024,
|
|
@@ -120,7 +138,7 @@ const tryParseJson = (text) => {
|
|
|
120
138
|
return { ok: false };
|
|
121
139
|
}
|
|
122
140
|
};
|
|
123
|
-
const escapeHtml = (text) => String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
141
|
+
const escapeHtml$1 = (text) => String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
124
142
|
const hashString = (text) => {
|
|
125
143
|
let hash = 2166136261;
|
|
126
144
|
for (let i = 0; i < text.length; i += 1) {
|
|
@@ -137,7 +155,7 @@ const textToBlocks = (text) => {
|
|
|
137
155
|
if (looksLikeHtml) {
|
|
138
156
|
return [{ type: "paragraph", data: { text: trimmed } }];
|
|
139
157
|
}
|
|
140
|
-
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>") } }));
|
|
158
|
+
return trimmed.split(/\r?\n\s*\r?\n/).map((part) => part.trim()).filter(Boolean).map((part) => ({ type: "paragraph", data: { text: escapeHtml$1(part).replace(/\r?\n/g, "<br>") } }));
|
|
141
159
|
};
|
|
142
160
|
const unwrapValue = (value) => {
|
|
143
161
|
let current = value;
|
|
@@ -193,6 +211,7 @@ const normalizeEditorData = (value) => {
|
|
|
193
211
|
const time = Number.isFinite(clean.time) && clean.time > 0 ? Math.floor(clean.time) : 0;
|
|
194
212
|
const version = typeof clean.version === "string" && clean.version.length <= 32 ? clean.version : "2.31.7";
|
|
195
213
|
const result = { time, blocks, version };
|
|
214
|
+
if (isValidFieldKey(clean.fieldKey)) result.fieldKey = clean.fieldKey;
|
|
196
215
|
const size = byteLength(JSON.stringify(result));
|
|
197
216
|
if (size > EDITOR_DATA_LIMITS.maxBytes) {
|
|
198
217
|
throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
|
|
@@ -248,6 +267,328 @@ const computeStats = (data) => {
|
|
|
248
267
|
characters: normalized.length
|
|
249
268
|
};
|
|
250
269
|
};
|
|
270
|
+
const TABLE_LIMITS = Object.freeze({ rows: 500, cols: 100, merges: 1e3, caption: 4e3 });
|
|
271
|
+
const TABLE_ALIGNS = Object.freeze(["left", "center", "right"]);
|
|
272
|
+
const isObject$2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
273
|
+
const tableWidth = (content) => Array.isArray(content) ? content.reduce((width, row) => Math.max(width, Array.isArray(row) ? row.length : 0), 0) : 0;
|
|
274
|
+
const cleanTableAlign = (value, cols) => {
|
|
275
|
+
if (!Array.isArray(value) || cols <= 0) return null;
|
|
276
|
+
const out = value.slice(0, Math.min(cols, TABLE_LIMITS.cols)).map((item) => typeof item === "string" && TABLE_ALIGNS.includes(item) ? item : null);
|
|
277
|
+
while (out.length && out[out.length - 1] === null) out.pop();
|
|
278
|
+
return out.length ? out : null;
|
|
279
|
+
};
|
|
280
|
+
const intersects = (a, b) => a.row < b.row + b.rowspan && b.row < a.row + a.rowspan && a.col < b.col + b.colspan && b.col < a.col + a.colspan;
|
|
281
|
+
const normalizeMerges = (merges, rows, cols, options = {}) => {
|
|
282
|
+
if (!Array.isArray(merges) || rows <= 0 || cols <= 0) return [];
|
|
283
|
+
const out = [];
|
|
284
|
+
for (const merge of merges.slice(0, TABLE_LIMITS.merges)) {
|
|
285
|
+
if (!isObject$2(merge)) continue;
|
|
286
|
+
const { row, col, rowspan, colspan } = merge;
|
|
287
|
+
if (![row, col, rowspan, colspan].every(Number.isInteger)) continue;
|
|
288
|
+
if (row < 0 || col < 0 || rowspan < 1 || colspan < 1 || rowspan * colspan < 2) continue;
|
|
289
|
+
if (row + rowspan > rows || col + colspan > cols) continue;
|
|
290
|
+
if (options.headerRow && row === 0 && rowspan > 1) continue;
|
|
291
|
+
const next = { row, col, rowspan, colspan };
|
|
292
|
+
if (out.some((other) => intersects(other, next))) continue;
|
|
293
|
+
out.push(next);
|
|
294
|
+
}
|
|
295
|
+
return out.sort((a, b) => a.row - b.row || a.col - b.col);
|
|
296
|
+
};
|
|
297
|
+
const mergeMap = (merges) => {
|
|
298
|
+
const anchors = /* @__PURE__ */ new Map();
|
|
299
|
+
const covered = /* @__PURE__ */ new Map();
|
|
300
|
+
for (const merge of merges || []) {
|
|
301
|
+
anchors.set(`${merge.row}:${merge.col}`, merge);
|
|
302
|
+
for (let r = merge.row; r < merge.row + merge.rowspan; r += 1)
|
|
303
|
+
for (let c = merge.col; c < merge.col + merge.colspan; c += 1)
|
|
304
|
+
if (r !== merge.row || c !== merge.col) covered.set(`${r}:${c}`, merge);
|
|
305
|
+
}
|
|
306
|
+
return { anchors, covered };
|
|
307
|
+
};
|
|
308
|
+
const headerKind = (data, row, col) => {
|
|
309
|
+
if (data.withHeadings === true && row === 0) return "col";
|
|
310
|
+
if (data.headerColumn === true && col === 0) return "row";
|
|
311
|
+
return null;
|
|
312
|
+
};
|
|
313
|
+
const tableLayout = (data) => {
|
|
314
|
+
const merges = Array.isArray(data.merges) ? data.merges : [];
|
|
315
|
+
const { anchors, covered } = mergeMap(merges);
|
|
316
|
+
const align = Array.isArray(data.align) ? data.align : [];
|
|
317
|
+
return (data.content || []).map(
|
|
318
|
+
(row, r) => row.map((html, c) => {
|
|
319
|
+
if (covered.has(`${r}:${c}`)) return null;
|
|
320
|
+
const merge = anchors.get(`${r}:${c}`);
|
|
321
|
+
return {
|
|
322
|
+
row: r,
|
|
323
|
+
col: c,
|
|
324
|
+
html,
|
|
325
|
+
rowspan: merge ? merge.rowspan : 1,
|
|
326
|
+
colspan: merge ? merge.colspan : 1,
|
|
327
|
+
header: headerKind(data, r, c),
|
|
328
|
+
align: typeof align[c] === "string" ? align[c] : null
|
|
329
|
+
};
|
|
330
|
+
}).filter(Boolean)
|
|
331
|
+
);
|
|
332
|
+
};
|
|
333
|
+
const isBlankInlineHtml = (html) => typeof html !== "string" || /^(?:\s| | |\u00a0|<br\s*\/?>)*$/i.test(html);
|
|
334
|
+
const cleanTableExtras = (out, d, inline) => {
|
|
335
|
+
if (d.headerColumn === true) out.headerColumn = true;
|
|
336
|
+
const rows = out.content.length;
|
|
337
|
+
const cols = tableWidth(out.content);
|
|
338
|
+
const align = cleanTableAlign(d.align, cols);
|
|
339
|
+
if (align) out.align = align;
|
|
340
|
+
const merges = normalizeMerges(d.merges, rows, cols, { headerRow: out.withHeadings === true });
|
|
341
|
+
if (merges.length) {
|
|
342
|
+
const { covered } = mergeMap(merges);
|
|
343
|
+
out.content = out.content.map(
|
|
344
|
+
(row, r) => Array.from(
|
|
345
|
+
{ length: cols },
|
|
346
|
+
(_, c) => covered.has(`${r}:${c}`) ? "" : row[c] === void 0 ? "" : row[c]
|
|
347
|
+
)
|
|
348
|
+
);
|
|
349
|
+
out.merges = merges;
|
|
350
|
+
}
|
|
351
|
+
if (typeof d.caption === "string") {
|
|
352
|
+
const caption = inline(d.caption.slice(0, TABLE_LIMITS.caption));
|
|
353
|
+
if (!isBlankInlineHtml(caption)) out.caption = caption;
|
|
354
|
+
}
|
|
355
|
+
return out;
|
|
356
|
+
};
|
|
357
|
+
const toTableModel = (data, defaults = {}) => {
|
|
358
|
+
const d = isObject$2(data) ? data : {};
|
|
359
|
+
let content = Array.isArray(d.content) ? d.content.slice(0, TABLE_LIMITS.rows).map(
|
|
360
|
+
(row) => Array.isArray(row) ? row.slice(0, TABLE_LIMITS.cols).map((cell) => typeof cell === "string" ? cell : "") : []
|
|
361
|
+
) : [];
|
|
362
|
+
let cols = tableWidth(content);
|
|
363
|
+
if (!content.length || !cols) {
|
|
364
|
+
const rows = Math.min(Math.max(Number(defaults.rows) || 2, 1), TABLE_LIMITS.rows);
|
|
365
|
+
cols = Math.min(Math.max(Number(defaults.cols) || 2, 1), TABLE_LIMITS.cols);
|
|
366
|
+
content = Array.from({ length: rows }, () => Array(cols).fill(""));
|
|
367
|
+
}
|
|
368
|
+
content = content.map((row) => row.length < cols ? [...row, ...Array(cols - row.length).fill("")] : row);
|
|
369
|
+
const withHeadings = typeof d.withHeadings === "boolean" ? d.withHeadings : Array.isArray(d.content) && d.content.length ? false : defaults.withHeadings === true;
|
|
370
|
+
const align = Array.from({ length: cols }, (_, c) => {
|
|
371
|
+
const value = Array.isArray(d.align) ? d.align[c] : null;
|
|
372
|
+
return TABLE_ALIGNS.includes(value) ? value : null;
|
|
373
|
+
});
|
|
374
|
+
return {
|
|
375
|
+
withHeadings,
|
|
376
|
+
stretched: d.stretched === true,
|
|
377
|
+
headerColumn: d.headerColumn === true,
|
|
378
|
+
content,
|
|
379
|
+
align,
|
|
380
|
+
merges: normalizeMerges(d.merges, content.length, cols, { headerRow: withHeadings }),
|
|
381
|
+
caption: typeof d.caption === "string" ? d.caption.slice(0, TABLE_LIMITS.caption) : ""
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
const fromTableModel = (model) => {
|
|
385
|
+
const { covered } = mergeMap(model.merges);
|
|
386
|
+
const out = {
|
|
387
|
+
withHeadings: model.withHeadings === true,
|
|
388
|
+
stretched: model.stretched === true,
|
|
389
|
+
content: model.content.map((row, r) => row.map((cell, c) => covered.has(`${r}:${c}`) ? "" : cell))
|
|
390
|
+
};
|
|
391
|
+
if (model.headerColumn) out.headerColumn = true;
|
|
392
|
+
const align = cleanTableAlign(model.align, tableWidth(model.content));
|
|
393
|
+
if (align) out.align = align;
|
|
394
|
+
if (model.merges.length) out.merges = model.merges.map((merge) => ({ ...merge }));
|
|
395
|
+
if (!isBlankInlineHtml(model.caption)) out.caption = model.caption;
|
|
396
|
+
return out;
|
|
397
|
+
};
|
|
398
|
+
const copy = (model) => ({
|
|
399
|
+
...model,
|
|
400
|
+
content: model.content.map((row) => [...row]),
|
|
401
|
+
align: [...model.align],
|
|
402
|
+
merges: model.merges.map((merge) => ({ ...merge }))
|
|
403
|
+
});
|
|
404
|
+
const rowsOf = (model) => model.content.length;
|
|
405
|
+
const colsOf = (model) => model.content[0] ? model.content[0].length : 0;
|
|
406
|
+
const dropSingles = (merges) => merges.filter((merge) => merge.rowspan * merge.colspan >= 2);
|
|
407
|
+
const mergeAt = (model, row, col) => model.merges.find(
|
|
408
|
+
(merge) => row >= merge.row && row < merge.row + merge.rowspan && col >= merge.col && col < merge.col + merge.colspan
|
|
409
|
+
) || null;
|
|
410
|
+
const spanAt = (model, row, col) => mergeAt(model, row, col) || { row, col, rowspan: 1, colspan: 1 };
|
|
411
|
+
const expandRect = (model, rect) => {
|
|
412
|
+
const out = {
|
|
413
|
+
top: Math.min(rect.top, rect.bottom),
|
|
414
|
+
bottom: Math.max(rect.top, rect.bottom),
|
|
415
|
+
left: Math.min(rect.left, rect.right),
|
|
416
|
+
right: Math.max(rect.left, rect.right)
|
|
417
|
+
};
|
|
418
|
+
let changed = true;
|
|
419
|
+
while (changed) {
|
|
420
|
+
changed = false;
|
|
421
|
+
for (const merge of model.merges) {
|
|
422
|
+
const box = {
|
|
423
|
+
row: out.top,
|
|
424
|
+
col: out.left,
|
|
425
|
+
rowspan: out.bottom - out.top + 1,
|
|
426
|
+
colspan: out.right - out.left + 1
|
|
427
|
+
};
|
|
428
|
+
if (!intersects(box, merge)) continue;
|
|
429
|
+
const bottom = merge.row + merge.rowspan - 1;
|
|
430
|
+
const right = merge.col + merge.colspan - 1;
|
|
431
|
+
if (merge.row < out.top || merge.col < out.left || bottom > out.bottom || right > out.right) {
|
|
432
|
+
out.top = Math.min(out.top, merge.row);
|
|
433
|
+
out.left = Math.min(out.left, merge.col);
|
|
434
|
+
out.bottom = Math.max(out.bottom, bottom);
|
|
435
|
+
out.right = Math.max(out.right, right);
|
|
436
|
+
changed = true;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return out;
|
|
441
|
+
};
|
|
442
|
+
const canMergeRect = (model, rect) => {
|
|
443
|
+
const box = expandRect(model, rect);
|
|
444
|
+
if (box.top < 0 || box.left < 0 || box.bottom >= rowsOf(model) || box.right >= colsOf(model)) return false;
|
|
445
|
+
if ((box.bottom - box.top + 1) * (box.right - box.left + 1) < 2) return false;
|
|
446
|
+
if (model.merges.some(
|
|
447
|
+
(m) => m.row === box.top && m.col === box.left && m.row + m.rowspan - 1 === box.bottom && m.col + m.colspan - 1 === box.right
|
|
448
|
+
))
|
|
449
|
+
return false;
|
|
450
|
+
return !(model.withHeadings && box.top === 0 && box.bottom > 0);
|
|
451
|
+
};
|
|
452
|
+
const mergeRect = (model, rect) => {
|
|
453
|
+
if (!canMergeRect(model, rect)) return null;
|
|
454
|
+
const box = expandRect(model, rect);
|
|
455
|
+
const next = copy(model);
|
|
456
|
+
const { covered } = mergeMap(next.merges);
|
|
457
|
+
const parts = [];
|
|
458
|
+
for (let r = box.top; r <= box.bottom; r += 1)
|
|
459
|
+
for (let c = box.left; c <= box.right; c += 1) {
|
|
460
|
+
const html = covered.has(`${r}:${c}`) ? "" : next.content[r][c];
|
|
461
|
+
if (!isBlankInlineHtml(html)) parts.push(html);
|
|
462
|
+
next.content[r][c] = "";
|
|
463
|
+
}
|
|
464
|
+
next.content[box.top][box.left] = parts.join("<br>");
|
|
465
|
+
next.merges = next.merges.filter(
|
|
466
|
+
(m) => !(m.row >= box.top && m.col >= box.left && m.row + m.rowspan - 1 <= box.bottom && m.col + m.colspan - 1 <= box.right)
|
|
467
|
+
);
|
|
468
|
+
if (next.merges.length >= TABLE_LIMITS.merges) return null;
|
|
469
|
+
next.merges.push({
|
|
470
|
+
row: box.top,
|
|
471
|
+
col: box.left,
|
|
472
|
+
rowspan: box.bottom - box.top + 1,
|
|
473
|
+
colspan: box.right - box.left + 1
|
|
474
|
+
});
|
|
475
|
+
next.merges.sort((a, b) => a.row - b.row || a.col - b.col);
|
|
476
|
+
return next;
|
|
477
|
+
};
|
|
478
|
+
const neighbourRect = (model, row, col, direction) => {
|
|
479
|
+
const span = spanAt(model, row, col);
|
|
480
|
+
const rect = {
|
|
481
|
+
top: span.row,
|
|
482
|
+
left: span.col,
|
|
483
|
+
bottom: span.row + span.rowspan - 1,
|
|
484
|
+
right: span.col + span.colspan - 1
|
|
485
|
+
};
|
|
486
|
+
if (direction === "right") {
|
|
487
|
+
if (rect.right + 1 >= colsOf(model)) return null;
|
|
488
|
+
rect.right += 1;
|
|
489
|
+
} else {
|
|
490
|
+
if (rect.bottom + 1 >= rowsOf(model)) return null;
|
|
491
|
+
rect.bottom += 1;
|
|
492
|
+
}
|
|
493
|
+
return expandRect(model, rect);
|
|
494
|
+
};
|
|
495
|
+
const splitCell = (model, row, col) => {
|
|
496
|
+
const merge = mergeAt(model, row, col);
|
|
497
|
+
if (!merge) return null;
|
|
498
|
+
const next = copy(model);
|
|
499
|
+
next.merges = next.merges.filter((m) => !(m.row === merge.row && m.col === merge.col));
|
|
500
|
+
return next;
|
|
501
|
+
};
|
|
502
|
+
const insertRow = (model, at) => {
|
|
503
|
+
if (rowsOf(model) >= TABLE_LIMITS.rows || at < 0 || at > rowsOf(model)) return null;
|
|
504
|
+
const next = copy(model);
|
|
505
|
+
next.content.splice(at, 0, Array(colsOf(model)).fill(""));
|
|
506
|
+
next.merges = next.merges.map((m) => {
|
|
507
|
+
if (m.row >= at) return { ...m, row: m.row + 1 };
|
|
508
|
+
if (at < m.row + m.rowspan) return { ...m, rowspan: m.rowspan + 1 };
|
|
509
|
+
return m;
|
|
510
|
+
});
|
|
511
|
+
return next;
|
|
512
|
+
};
|
|
513
|
+
const deleteRow = (model, at) => {
|
|
514
|
+
if (rowsOf(model) <= 1 || at < 0 || at >= rowsOf(model)) return null;
|
|
515
|
+
const next = copy(model);
|
|
516
|
+
const merges = [];
|
|
517
|
+
for (const m of next.merges) {
|
|
518
|
+
if (m.row + m.rowspan - 1 < at) merges.push(m);
|
|
519
|
+
else if (m.row > at) merges.push({ ...m, row: m.row - 1 });
|
|
520
|
+
else if (m.rowspan > 1) {
|
|
521
|
+
if (m.row === at) next.content[at + 1][m.col] = next.content[at][m.col];
|
|
522
|
+
merges.push({ ...m, rowspan: m.rowspan - 1 });
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
next.content.splice(at, 1);
|
|
526
|
+
next.merges = normalizeMerges(dropSingles(merges), rowsOf(next), colsOf(next), {
|
|
527
|
+
headerRow: next.withHeadings
|
|
528
|
+
});
|
|
529
|
+
return next;
|
|
530
|
+
};
|
|
531
|
+
const insertColumn = (model, at) => {
|
|
532
|
+
if (colsOf(model) >= TABLE_LIMITS.cols || at < 0 || at > colsOf(model)) return null;
|
|
533
|
+
const next = copy(model);
|
|
534
|
+
next.content.forEach((row) => row.splice(at, 0, ""));
|
|
535
|
+
next.align.splice(at, 0, null);
|
|
536
|
+
next.merges = next.merges.map((m) => {
|
|
537
|
+
if (m.col >= at) return { ...m, col: m.col + 1 };
|
|
538
|
+
if (at < m.col + m.colspan) return { ...m, colspan: m.colspan + 1 };
|
|
539
|
+
return m;
|
|
540
|
+
});
|
|
541
|
+
return next;
|
|
542
|
+
};
|
|
543
|
+
const deleteColumn = (model, at) => {
|
|
544
|
+
if (colsOf(model) <= 1 || at < 0 || at >= colsOf(model)) return null;
|
|
545
|
+
const next = copy(model);
|
|
546
|
+
const merges = [];
|
|
547
|
+
for (const m of next.merges) {
|
|
548
|
+
if (m.col + m.colspan - 1 < at) merges.push(m);
|
|
549
|
+
else if (m.col > at) merges.push({ ...m, col: m.col - 1 });
|
|
550
|
+
else if (m.colspan > 1) {
|
|
551
|
+
if (m.col === at) next.content[m.row][at + 1] = next.content[m.row][at];
|
|
552
|
+
merges.push({ ...m, colspan: m.colspan - 1 });
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
next.content.forEach((row) => row.splice(at, 1));
|
|
556
|
+
next.align.splice(at, 1);
|
|
557
|
+
next.merges = dropSingles(merges);
|
|
558
|
+
return next;
|
|
559
|
+
};
|
|
560
|
+
const setHeaderRow = (model, on) => {
|
|
561
|
+
const next = copy(model);
|
|
562
|
+
next.withHeadings = Boolean(on);
|
|
563
|
+
next.merges = normalizeMerges(next.merges, rowsOf(next), colsOf(next), { headerRow: next.withHeadings });
|
|
564
|
+
return next;
|
|
565
|
+
};
|
|
566
|
+
const setColumnAlign = (model, col, value) => {
|
|
567
|
+
const next = copy(model);
|
|
568
|
+
if (col >= 0 && col < next.align.length) next.align[col] = TABLE_ALIGNS.includes(value) ? value : null;
|
|
569
|
+
return next;
|
|
570
|
+
};
|
|
571
|
+
const pasteGrid = (model, row, col, grid) => {
|
|
572
|
+
let next = copy(model);
|
|
573
|
+
const height = Math.min(grid.length, TABLE_LIMITS.rows - row);
|
|
574
|
+
const width = Math.min(tableWidth(grid), TABLE_LIMITS.cols - col);
|
|
575
|
+
while (rowsOf(next) < row + height) next = insertRow(next, rowsOf(next));
|
|
576
|
+
while (colsOf(next) < col + width) next = insertColumn(next, colsOf(next));
|
|
577
|
+
const { covered } = mergeMap(next.merges);
|
|
578
|
+
for (let r = 0; r < height; r += 1)
|
|
579
|
+
for (let c = 0; c < width; c += 1) {
|
|
580
|
+
if (covered.has(`${row + r}:${col + c}`)) continue;
|
|
581
|
+
const value = grid[r][c];
|
|
582
|
+
if (typeof value === "string") next.content[row + r][col + c] = value;
|
|
583
|
+
}
|
|
584
|
+
return next;
|
|
585
|
+
};
|
|
586
|
+
const parseTabularText = (text) => {
|
|
587
|
+
if (typeof text !== "string" || !text.includes(" ") || text.length > 1024 * 1024) return null;
|
|
588
|
+
const lines = text.replace(/\r\n?/g, "\n").replace(/\n$/, "").split("\n");
|
|
589
|
+
if (lines.length > TABLE_LIMITS.rows) lines.length = TABLE_LIMITS.rows;
|
|
590
|
+
return lines.map((line) => line.split(" ").slice(0, TABLE_LIMITS.cols));
|
|
591
|
+
};
|
|
251
592
|
const INLINE_TAGS = Object.freeze([
|
|
252
593
|
"b",
|
|
253
594
|
"strong",
|
|
@@ -290,9 +631,16 @@ const cleanInternalLinkAttributes = (attribs) => {
|
|
|
290
631
|
const isMentionLink = (attrs) => Boolean(
|
|
291
632
|
attrs && attrs["data-mex-mention"] === "true" && attrs["data-mex-uid"] && attrs["data-mex-document-id"]
|
|
292
633
|
);
|
|
634
|
+
const MATH_ATTRIBUTE = "data-mex-math";
|
|
635
|
+
const FOOTNOTE_ATTRIBUTES = Object.freeze(["data-mex-footnote", "data-mex-note"]);
|
|
636
|
+
const FOOTNOTE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
637
|
+
const MAX_MATH_TEX = 1e4;
|
|
638
|
+
const MAX_INLINE_TEX = 2e3;
|
|
639
|
+
const MAX_FOOTNOTE_NOTE = 4e3;
|
|
293
640
|
const INLINE_ATTRIBUTES = Object.freeze({
|
|
294
641
|
a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
|
|
295
|
-
span: ["class", "data-tooltip"],
|
|
642
|
+
span: ["class", "data-tooltip", MATH_ATTRIBUTE],
|
|
643
|
+
sup: [...FOOTNOTE_ATTRIBUTES],
|
|
296
644
|
mark: ["class"],
|
|
297
645
|
u: ["class"],
|
|
298
646
|
s: ["class"],
|
|
@@ -428,6 +776,17 @@ const listItems = (items, inline, depth = 0) => {
|
|
|
428
776
|
return out;
|
|
429
777
|
});
|
|
430
778
|
};
|
|
779
|
+
const MAX_CODE_FILENAME = 200;
|
|
780
|
+
const FILENAME_STRIP = (
|
|
781
|
+
// eslint-disable-next-line no-control-regex -- the point is to remove control characters
|
|
782
|
+
/[\u0000-\u001f\u007f-\u009f\u061c\u200b-\u200f\u2028-\u202e\u2060\u2066-\u2069\ufeff]/g
|
|
783
|
+
);
|
|
784
|
+
const cleanCodeFilename = (value) => {
|
|
785
|
+
if (typeof value !== "string") return "";
|
|
786
|
+
return Array.from(
|
|
787
|
+
value.slice(0, 4 * MAX_CODE_FILENAME).replace(/[\t\n\r\f\v]/g, " ").replace(FILENAME_STRIP, "").replace(/\s+/g, " ").trim()
|
|
788
|
+
).slice(0, MAX_CODE_FILENAME).join("").trim();
|
|
789
|
+
};
|
|
431
790
|
const BLOCK_POLICIES = {
|
|
432
791
|
paragraph: (d, inline) => ({ text: inline(d.text) }),
|
|
433
792
|
header: (d, inline) => ({ text: inline(d.text), level: int(d.level, 1, 6, 2) }),
|
|
@@ -482,6 +841,8 @@ const BLOCK_POLICIES = {
|
|
|
482
841
|
language: typeof d.language === "string" && /^[a-z0-9+#-]{1,32}$/i.test(d.language) ? d.language : "plaintext"
|
|
483
842
|
};
|
|
484
843
|
if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
|
|
844
|
+
const filename = cleanCodeFilename(d.filename);
|
|
845
|
+
if (filename) out.filename = filename;
|
|
485
846
|
return out;
|
|
486
847
|
},
|
|
487
848
|
raw: (d, _inline, ctx) => {
|
|
@@ -490,11 +851,18 @@ const BLOCK_POLICIES = {
|
|
|
490
851
|
if (ctx.rawHtml === "disable") return { html: "" };
|
|
491
852
|
return { html: ctx.rawSanitizer(html) };
|
|
492
853
|
},
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
854
|
+
// 2.4: optional header column, column alignment, merged cells and caption (shared/table.mjs).
|
|
855
|
+
table: (d, inline) => cleanTableExtras(
|
|
856
|
+
{
|
|
857
|
+
withHeadings: bool(d.withHeadings),
|
|
858
|
+
stretched: bool(d.stretched),
|
|
859
|
+
content: Array.isArray(d.content) ? d.content.slice(0, TABLE_LIMITS.rows).map(
|
|
860
|
+
(row) => Array.isArray(row) ? row.slice(0, TABLE_LIMITS.cols).map((cell) => inline(cell)) : []
|
|
861
|
+
) : []
|
|
862
|
+
},
|
|
863
|
+
d,
|
|
864
|
+
inline
|
|
865
|
+
),
|
|
498
866
|
image: (d, inline) => {
|
|
499
867
|
const file = isPlainObject(d.file) ? d.file : {};
|
|
500
868
|
const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
|
|
@@ -618,6 +986,12 @@ const BLOCK_POLICIES = {
|
|
|
618
986
|
ref: typeof d.ref === "string" && /^[a-z0-9]{1,64}$/.test(d.ref) ? d.ref : "",
|
|
619
987
|
_mex: BUILT_IN_MARKER_VERSION
|
|
620
988
|
}),
|
|
989
|
+
// Math block (2.4): only the TeX source is stored; `display: false` renders it in text style.
|
|
990
|
+
math: (d) => ({
|
|
991
|
+
tex: plain(d.tex, MAX_MATH_TEX),
|
|
992
|
+
display: d.display !== false,
|
|
993
|
+
_mex: BUILT_IN_MARKER_VERSION
|
|
994
|
+
}),
|
|
621
995
|
toc: (d) => {
|
|
622
996
|
const minLevel = int(d.minLevel, 1, 6, 2);
|
|
623
997
|
const maxLevel = int(d.maxLevel, 1, 6, 4);
|
|
@@ -666,12 +1040,14 @@ const sanitizeEditorData = (data, options) => {
|
|
|
666
1040
|
const registered = policy ? null : registeredBlockOf(block, options.blocks);
|
|
667
1041
|
const cleanData = policy ? policy(block.data || {}, inline, ctx) : registered ? registered.clean(block.data || {}, inline) : generic(block.data || {}, inline, 0);
|
|
668
1042
|
for (const key of Object.keys(cleanData)) if (cleanData[key] === void 0) delete cleanData[key];
|
|
669
|
-
const
|
|
1043
|
+
const out2 = { id: block.id, type: block.type, data: cleanData };
|
|
670
1044
|
const tunes = sanitizeTunes(block.tunes);
|
|
671
|
-
if (tunes)
|
|
672
|
-
return
|
|
1045
|
+
if (tunes) out2.tunes = tunes;
|
|
1046
|
+
return out2;
|
|
673
1047
|
});
|
|
674
|
-
|
|
1048
|
+
const out = { time: data.time, blocks, version: data.version };
|
|
1049
|
+
if (typeof data.fieldKey === "string") out.fieldKey = data.fieldKey;
|
|
1050
|
+
return out;
|
|
675
1051
|
};
|
|
676
1052
|
const sanitizeTarget = (value) => typeof value === "string" && TARGETS.has(value) ? value : null;
|
|
677
1053
|
const BLOCK_FIELD_TYPES = Object.freeze([
|
|
@@ -1170,7 +1546,7 @@ const sanitizeRulesFor = (fields) => {
|
|
|
1170
1546
|
s: { class: true },
|
|
1171
1547
|
mark: { class: true },
|
|
1172
1548
|
code: { class: true },
|
|
1173
|
-
span: { class: true, "data-tooltip": true },
|
|
1549
|
+
span: { class: true, "data-tooltip": true, "data-mex-math": true },
|
|
1174
1550
|
sub: true,
|
|
1175
1551
|
sup: true,
|
|
1176
1552
|
br: true,
|
|
@@ -1215,6 +1591,495 @@ const mergeCodeBlocks = (server, admin, locale) => {
|
|
|
1215
1591
|
}
|
|
1216
1592
|
return [...rows.values()].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1217
1593
|
};
|
|
1594
|
+
const VOID_TAGS = /* @__PURE__ */ new Set([
|
|
1595
|
+
"area",
|
|
1596
|
+
"base",
|
|
1597
|
+
"br",
|
|
1598
|
+
"col",
|
|
1599
|
+
"embed",
|
|
1600
|
+
"hr",
|
|
1601
|
+
"img",
|
|
1602
|
+
"input",
|
|
1603
|
+
"link",
|
|
1604
|
+
"meta",
|
|
1605
|
+
"source",
|
|
1606
|
+
"track",
|
|
1607
|
+
"wbr"
|
|
1608
|
+
]);
|
|
1609
|
+
const escapeHtml = (text) => String(text ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1610
|
+
const TAG_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
1611
|
+
const ATTRIBUTE_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
1612
|
+
const isSafeAttributeName = (name) => ATTRIBUTE_NAME.test(name) && !name.startsWith("on") && name !== "style" && name !== "srcdoc";
|
|
1613
|
+
const textNode = (value) => ({ type: "text", value: String(value ?? "") });
|
|
1614
|
+
const el$1 = (tag, attrs, children) => {
|
|
1615
|
+
const clean = {};
|
|
1616
|
+
for (const [name, value] of Object.entries(attrs || {})) {
|
|
1617
|
+
if (value === void 0 || value === null || value === false) continue;
|
|
1618
|
+
if (value === "" && name !== "alt") continue;
|
|
1619
|
+
clean[name] = value === true ? true : String(value);
|
|
1620
|
+
}
|
|
1621
|
+
return { type: "element", tag, attrs: clean, children: toNodes(children) };
|
|
1622
|
+
};
|
|
1623
|
+
const toNodes = (children) => {
|
|
1624
|
+
const out = [];
|
|
1625
|
+
const visit = (child) => {
|
|
1626
|
+
if (child === void 0 || child === null || child === false || child === "") return;
|
|
1627
|
+
if (Array.isArray(child)) {
|
|
1628
|
+
for (const item of child) visit(item);
|
|
1629
|
+
} else if (typeof child === "string" || typeof child === "number") {
|
|
1630
|
+
out.push(textNode(child));
|
|
1631
|
+
} else if (typeof child === "object") {
|
|
1632
|
+
out.push(
|
|
1633
|
+
/** @type {RenderNode} */
|
|
1634
|
+
child
|
|
1635
|
+
);
|
|
1636
|
+
}
|
|
1637
|
+
};
|
|
1638
|
+
visit(children);
|
|
1639
|
+
return out;
|
|
1640
|
+
};
|
|
1641
|
+
const STYLE_PROPERTIES = Object.freeze(["object-position"]);
|
|
1642
|
+
const STYLE_VALUE = /^[0-9]{1,3}(?:\.[0-9]{1,2})?% [0-9]{1,3}(?:\.[0-9]{1,2})?%$/;
|
|
1643
|
+
const safeStyle = (style) => style && typeof style === "object" ? Object.entries(style).filter(
|
|
1644
|
+
([name, value]) => STYLE_PROPERTIES.includes(name) && typeof value === "string" && STYLE_VALUE.test(value)
|
|
1645
|
+
) : [];
|
|
1646
|
+
const serializeNodes = (nodes) => {
|
|
1647
|
+
let out = "";
|
|
1648
|
+
for (const node of nodes) {
|
|
1649
|
+
if (!node || typeof node !== "object") continue;
|
|
1650
|
+
if (node.type === "text") out += escapeHtml(node.value);
|
|
1651
|
+
else if (node.type === "raw") out += node.html;
|
|
1652
|
+
else if (node.type === "block") out += serializeNodes(node.children);
|
|
1653
|
+
else if (node.type === "element") {
|
|
1654
|
+
let attributes = "";
|
|
1655
|
+
for (const [name, value] of Object.entries(node.attrs)) {
|
|
1656
|
+
attributes += value === true ? ` ${name}` : ` ${name}="${escapeHtml(value)}"`;
|
|
1657
|
+
}
|
|
1658
|
+
const style = safeStyle(node.style);
|
|
1659
|
+
if (style.length)
|
|
1660
|
+
attributes += ` style="${escapeHtml(style.map(([name, value]) => `${name}:${value}`).join(";"))}"`;
|
|
1661
|
+
out += VOID_TAGS.has(node.tag) ? `<${node.tag}${attributes}>` : `<${node.tag}${attributes}>${serializeNodes(node.children)}</${node.tag}>`;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
return out;
|
|
1665
|
+
};
|
|
1666
|
+
const nodesTextContent = (nodes) => {
|
|
1667
|
+
let out = "";
|
|
1668
|
+
for (const node of nodes) {
|
|
1669
|
+
if (node.type === "text") out += node.value;
|
|
1670
|
+
else if (node.type === "element" || node.type === "block") out += nodesTextContent(node.children);
|
|
1671
|
+
}
|
|
1672
|
+
return out;
|
|
1673
|
+
};
|
|
1674
|
+
const DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
1675
|
+
"script",
|
|
1676
|
+
"style",
|
|
1677
|
+
"textarea",
|
|
1678
|
+
"title",
|
|
1679
|
+
"xmp",
|
|
1680
|
+
"noscript",
|
|
1681
|
+
"noembed",
|
|
1682
|
+
"noframes",
|
|
1683
|
+
"template",
|
|
1684
|
+
"iframe",
|
|
1685
|
+
"object",
|
|
1686
|
+
"embed",
|
|
1687
|
+
"svg",
|
|
1688
|
+
"math",
|
|
1689
|
+
"select",
|
|
1690
|
+
"option",
|
|
1691
|
+
"plaintext"
|
|
1692
|
+
]);
|
|
1693
|
+
const ALLOWED = new Set(INLINE_TAGS);
|
|
1694
|
+
const VOID = /* @__PURE__ */ new Set(["br"]);
|
|
1695
|
+
const MAX_INPUT = 5e5;
|
|
1696
|
+
const MAX_NODES = 5e4;
|
|
1697
|
+
const MAX_DEPTH = 64;
|
|
1698
|
+
const NAMED_ENTITIES = Object.freeze({
|
|
1699
|
+
amp: "&",
|
|
1700
|
+
lt: "<",
|
|
1701
|
+
gt: ">",
|
|
1702
|
+
quot: '"',
|
|
1703
|
+
apos: "'",
|
|
1704
|
+
nbsp: " ",
|
|
1705
|
+
shy: "",
|
|
1706
|
+
copy: "©",
|
|
1707
|
+
reg: "®",
|
|
1708
|
+
trade: "™",
|
|
1709
|
+
hellip: "…",
|
|
1710
|
+
mdash: "—",
|
|
1711
|
+
ndash: "–",
|
|
1712
|
+
lsquo: "‘",
|
|
1713
|
+
rsquo: "’",
|
|
1714
|
+
ldquo: "“",
|
|
1715
|
+
rdquo: "”",
|
|
1716
|
+
laquo: "«",
|
|
1717
|
+
raquo: "»",
|
|
1718
|
+
euro: "€",
|
|
1719
|
+
middot: "·",
|
|
1720
|
+
bull: "•",
|
|
1721
|
+
times: "×",
|
|
1722
|
+
deg: "°",
|
|
1723
|
+
tab: " ",
|
|
1724
|
+
newline: "\n",
|
|
1725
|
+
colon: ":",
|
|
1726
|
+
sol: "/",
|
|
1727
|
+
lpar: "(",
|
|
1728
|
+
rpar: ")"
|
|
1729
|
+
});
|
|
1730
|
+
const decodeEntities = (text) => String(text).replace(
|
|
1731
|
+
/&(#[xX][0-9a-fA-F]{1,8}|#[0-9]{1,10}|[A-Za-z][A-Za-z0-9]{1,31});?/g,
|
|
1732
|
+
(match, body) => {
|
|
1733
|
+
if (body[0] === "#") {
|
|
1734
|
+
const code = body[1] === "x" || body[1] === "X" ? parseInt(body.slice(2), 16) : parseInt(body.slice(1), 10);
|
|
1735
|
+
if (!Number.isFinite(code) || code <= 0 || code > 1114111 || code >= 55296 && code <= 57343)
|
|
1736
|
+
return "�";
|
|
1737
|
+
return String.fromCodePoint(code);
|
|
1738
|
+
}
|
|
1739
|
+
const named = NAMED_ENTITIES[body] ?? NAMED_ENTITIES[body.toLowerCase()];
|
|
1740
|
+
return named === void 0 ? match : named;
|
|
1741
|
+
}
|
|
1742
|
+
);
|
|
1743
|
+
const parseAttributes = (source) => {
|
|
1744
|
+
const out = {};
|
|
1745
|
+
const pattern = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
1746
|
+
let match;
|
|
1747
|
+
while (match = pattern.exec(source)) {
|
|
1748
|
+
const name = match[1].toLowerCase();
|
|
1749
|
+
if (Object.prototype.hasOwnProperty.call(out, name)) continue;
|
|
1750
|
+
const raw = match[2] ?? match[3] ?? match[4] ?? "";
|
|
1751
|
+
out[name] = decodeEntities(raw);
|
|
1752
|
+
}
|
|
1753
|
+
return out;
|
|
1754
|
+
};
|
|
1755
|
+
const findTagEnd = (html, from) => {
|
|
1756
|
+
let quote = "";
|
|
1757
|
+
for (let i = from; i < html.length; i += 1) {
|
|
1758
|
+
const char = html[i];
|
|
1759
|
+
if (quote) {
|
|
1760
|
+
if (char === quote) quote = "";
|
|
1761
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
1762
|
+
else if (char === ">") return i;
|
|
1763
|
+
}
|
|
1764
|
+
return -1;
|
|
1765
|
+
};
|
|
1766
|
+
const cleanAttributes = (tag, attribs, options = {}) => {
|
|
1767
|
+
const allowed = INLINE_ATTRIBUTES[tag] || [];
|
|
1768
|
+
const out = {};
|
|
1769
|
+
for (const name of allowed) {
|
|
1770
|
+
if (!Object.prototype.hasOwnProperty.call(attribs, name) || name.startsWith("data-mex-")) continue;
|
|
1771
|
+
const value = attribs[name];
|
|
1772
|
+
if (name === "href") {
|
|
1773
|
+
const url = sanitizeUrl(value);
|
|
1774
|
+
if (url) out.href = url;
|
|
1775
|
+
} else if (name === "target") {
|
|
1776
|
+
const target = sanitizeTarget(value);
|
|
1777
|
+
if (target) out.target = target;
|
|
1778
|
+
} else if (name === "rel") {
|
|
1779
|
+
const rel = String(value).split(/\s+/).filter((token) => /^[a-z-]{1,20}$/.test(token));
|
|
1780
|
+
if (rel.length) out.rel = rel.join(" ");
|
|
1781
|
+
} else if (name === "class") {
|
|
1782
|
+
const classes = String(value).split(/\s+/).filter((token) => (INLINE_CLASSES[tag] || []).includes(token));
|
|
1783
|
+
if (classes.length) out.class = classes.join(" ");
|
|
1784
|
+
} else {
|
|
1785
|
+
out[name] = String(value).slice(0, 2e3);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
if (tag === "a" && !options.inNote) Object.assign(out, cleanInternalLinkAttributes(attribs));
|
|
1789
|
+
return out;
|
|
1790
|
+
};
|
|
1791
|
+
const MAX_MARKER_TEXT = 16;
|
|
1792
|
+
const isMathNode = (node) => node.type === "element" && node.tag === "span" && node.attrs[MATH_ATTRIBUTE] === "true";
|
|
1793
|
+
const isFootnoteNode = (node) => node.type === "element" && node.tag === "sup" && typeof node.attrs["data-mex-footnote"] === "string";
|
|
1794
|
+
const finalizeSpecial = (nodes, depth = 0) => {
|
|
1795
|
+
for (const node of nodes) {
|
|
1796
|
+
if (node.type !== "element") continue;
|
|
1797
|
+
if (isMathNode(node)) {
|
|
1798
|
+
const tex = nodesToText(node.children, { raw: true }).replace(/\u200b/g, "").slice(0, MAX_INLINE_TEX);
|
|
1799
|
+
node.children = tex ? [{ type: "text", value: tex }] : [];
|
|
1800
|
+
} else if (isFootnoteNode(node)) {
|
|
1801
|
+
const text = nodesToText(node.children, { raw: true }).slice(0, MAX_MARKER_TEXT);
|
|
1802
|
+
node.children = text ? [{ type: "text", value: text }] : [];
|
|
1803
|
+
} else if (depth < MAX_DEPTH) finalizeSpecial(node.children, depth + 1);
|
|
1804
|
+
}
|
|
1805
|
+
return nodes;
|
|
1806
|
+
};
|
|
1807
|
+
const specialElement = (tag, attribs, options) => {
|
|
1808
|
+
if (tag === "span" && Object.prototype.hasOwnProperty.call(attribs, MATH_ATTRIBUTE)) {
|
|
1809
|
+
if (!/^(?:|true)$/.test(attribs[MATH_ATTRIBUTE])) return null;
|
|
1810
|
+
return { attrs: { [MATH_ATTRIBUTE]: "true" } };
|
|
1811
|
+
}
|
|
1812
|
+
if (tag === "sup" && !options.inNote) {
|
|
1813
|
+
const id = attribs["data-mex-footnote"];
|
|
1814
|
+
if (typeof id !== "string" || !FOOTNOTE_ID.test(id)) return null;
|
|
1815
|
+
const source = typeof attribs["data-mex-note"] === "string" ? attribs["data-mex-note"] : "";
|
|
1816
|
+
const note = parseInline(source.slice(0, MAX_FOOTNOTE_NOTE), { inNote: true });
|
|
1817
|
+
return { attrs: { "data-mex-footnote": id }, note };
|
|
1818
|
+
}
|
|
1819
|
+
return null;
|
|
1820
|
+
};
|
|
1821
|
+
const parseInline = (input2, options = {}) => {
|
|
1822
|
+
const html = typeof input2 === "string" ? input2.slice(0, MAX_INPUT) : "";
|
|
1823
|
+
const root = { type: "element", tag: "#root", attrs: {}, children: [] };
|
|
1824
|
+
const stack = [root];
|
|
1825
|
+
let nodes = 0;
|
|
1826
|
+
let text = "";
|
|
1827
|
+
const flush = () => {
|
|
1828
|
+
if (!text) return;
|
|
1829
|
+
const parent = stack[stack.length - 1];
|
|
1830
|
+
const last = parent.children[parent.children.length - 1];
|
|
1831
|
+
const value = decodeEntities(text);
|
|
1832
|
+
if (last && last.type === "text") last.value += value;
|
|
1833
|
+
else if (nodes < MAX_NODES) {
|
|
1834
|
+
parent.children.push({ type: "text", value });
|
|
1835
|
+
nodes += 1;
|
|
1836
|
+
}
|
|
1837
|
+
text = "";
|
|
1838
|
+
};
|
|
1839
|
+
let i = 0;
|
|
1840
|
+
while (i < html.length) {
|
|
1841
|
+
const lt = html.indexOf("<", i);
|
|
1842
|
+
if (lt === -1) {
|
|
1843
|
+
text += html.slice(i);
|
|
1844
|
+
break;
|
|
1845
|
+
}
|
|
1846
|
+
text += html.slice(i, lt);
|
|
1847
|
+
i = lt;
|
|
1848
|
+
if (html.startsWith("<!--", i)) {
|
|
1849
|
+
const end2 = html.indexOf("-->", i + 4);
|
|
1850
|
+
flush();
|
|
1851
|
+
i = end2 === -1 ? html.length : end2 + 3;
|
|
1852
|
+
continue;
|
|
1853
|
+
}
|
|
1854
|
+
if (html.startsWith("<![CDATA[", i)) {
|
|
1855
|
+
const end2 = html.indexOf("]]>", i + 9);
|
|
1856
|
+
flush();
|
|
1857
|
+
i = end2 === -1 ? html.length : end2 + 3;
|
|
1858
|
+
continue;
|
|
1859
|
+
}
|
|
1860
|
+
if (html[i + 1] === "!" || html[i + 1] === "?") {
|
|
1861
|
+
const end2 = html.indexOf(">", i + 2);
|
|
1862
|
+
flush();
|
|
1863
|
+
i = end2 === -1 ? html.length : end2 + 1;
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
const closing = html[i + 1] === "/";
|
|
1867
|
+
const nameMatch = /^[A-Za-z][A-Za-z0-9-]{0,40}/.exec(html.slice(i + (closing ? 2 : 1), i + 45));
|
|
1868
|
+
if (!nameMatch) {
|
|
1869
|
+
text += "<";
|
|
1870
|
+
i += 1;
|
|
1871
|
+
continue;
|
|
1872
|
+
}
|
|
1873
|
+
const end = findTagEnd(html, i + 1);
|
|
1874
|
+
if (end === -1) {
|
|
1875
|
+
text += html.slice(i);
|
|
1876
|
+
break;
|
|
1877
|
+
}
|
|
1878
|
+
flush();
|
|
1879
|
+
const tag = nameMatch[0].toLowerCase();
|
|
1880
|
+
const body = html.slice(i + (closing ? 2 : 1) + nameMatch[0].length, end);
|
|
1881
|
+
i = end + 1;
|
|
1882
|
+
if (closing) {
|
|
1883
|
+
if (!ALLOWED.has(tag)) continue;
|
|
1884
|
+
for (let s = stack.length - 1; s > 0; s -= 1) {
|
|
1885
|
+
if (stack[s].tag === tag) {
|
|
1886
|
+
stack.length = s;
|
|
1887
|
+
break;
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
continue;
|
|
1891
|
+
}
|
|
1892
|
+
if (DROP_WITH_CONTENT.has(tag)) {
|
|
1893
|
+
const selfClosing = /\/\s*$/.test(body);
|
|
1894
|
+
if (selfClosing) continue;
|
|
1895
|
+
const closeIndex = html.slice(i).search(new RegExp(`</${tag}[\\s/>]`, "i"));
|
|
1896
|
+
if (closeIndex === -1) break;
|
|
1897
|
+
const closeEnd = html.indexOf(">", i + closeIndex);
|
|
1898
|
+
i = closeEnd === -1 ? html.length : closeEnd + 1;
|
|
1899
|
+
continue;
|
|
1900
|
+
}
|
|
1901
|
+
if (!ALLOWED.has(tag) || nodes >= MAX_NODES) continue;
|
|
1902
|
+
const attribs = parseAttributes(body);
|
|
1903
|
+
const special = specialElement(tag, attribs, options);
|
|
1904
|
+
const element = {
|
|
1905
|
+
type: "element",
|
|
1906
|
+
tag,
|
|
1907
|
+
attrs: special ? special.attrs : cleanAttributes(tag, attribs, options),
|
|
1908
|
+
children: []
|
|
1909
|
+
};
|
|
1910
|
+
if (special && special.note) element.note = special.note;
|
|
1911
|
+
stack[stack.length - 1].children.push(element);
|
|
1912
|
+
nodes += 1;
|
|
1913
|
+
if (!VOID.has(tag) && stack.length < MAX_DEPTH) stack.push(element);
|
|
1914
|
+
}
|
|
1915
|
+
flush();
|
|
1916
|
+
return finalizeSpecial(root.children);
|
|
1917
|
+
};
|
|
1918
|
+
const resolveLinkAttributes = (attrs, resolver) => {
|
|
1919
|
+
if (typeof resolver !== "function" || !attrs["data-mex-uid"] || !attrs["data-mex-document-id"])
|
|
1920
|
+
return attrs;
|
|
1921
|
+
let result;
|
|
1922
|
+
try {
|
|
1923
|
+
result = resolver({
|
|
1924
|
+
uid: attrs["data-mex-uid"],
|
|
1925
|
+
documentId: attrs["data-mex-document-id"],
|
|
1926
|
+
locale: attrs["data-mex-locale"] || null,
|
|
1927
|
+
href: attrs.href || null,
|
|
1928
|
+
...isMentionLink(attrs) ? { mention: true } : {}
|
|
1929
|
+
});
|
|
1930
|
+
} catch {
|
|
1931
|
+
result = void 0;
|
|
1932
|
+
}
|
|
1933
|
+
if (result === false) return null;
|
|
1934
|
+
if (typeof result === "string") {
|
|
1935
|
+
const url = sanitizeUrl(result);
|
|
1936
|
+
if (url) return { ...attrs, href: url };
|
|
1937
|
+
}
|
|
1938
|
+
return attrs;
|
|
1939
|
+
};
|
|
1940
|
+
const ATTRIBUTE_ORDER = [
|
|
1941
|
+
"href",
|
|
1942
|
+
"target",
|
|
1943
|
+
"rel",
|
|
1944
|
+
"title",
|
|
1945
|
+
"class",
|
|
1946
|
+
"data-tooltip",
|
|
1947
|
+
"data-mex-uid",
|
|
1948
|
+
"data-mex-document-id",
|
|
1949
|
+
"data-mex-locale",
|
|
1950
|
+
"data-mex-mention",
|
|
1951
|
+
MATH_ATTRIBUTE,
|
|
1952
|
+
"data-mex-footnote",
|
|
1953
|
+
"data-mex-note"
|
|
1954
|
+
];
|
|
1955
|
+
const RENDER_STATE = Symbol.for("magic-editor-x.render-state");
|
|
1956
|
+
const storedNote = (note) => serializeNodes(inlineNodesToRender(note || [], { storage: true }));
|
|
1957
|
+
const MENTION_CLASS = "mex-mention";
|
|
1958
|
+
const inlineNodesToRender = (nodes, options = {}) => {
|
|
1959
|
+
const out = [];
|
|
1960
|
+
const state = options[RENDER_STATE];
|
|
1961
|
+
for (const node of nodes) {
|
|
1962
|
+
if (node.type === "text") {
|
|
1963
|
+
out.push({ type: "text", value: node.value });
|
|
1964
|
+
continue;
|
|
1965
|
+
}
|
|
1966
|
+
if (node.tag === "br") {
|
|
1967
|
+
out.push({ type: "element", tag: "br", attrs: {}, children: [] });
|
|
1968
|
+
continue;
|
|
1969
|
+
}
|
|
1970
|
+
if (isMathNode(node)) {
|
|
1971
|
+
const tex = nodesToText(node.children);
|
|
1972
|
+
if (state && !options.storage) {
|
|
1973
|
+
if (tex.trim()) out.push(state.math(tex, false));
|
|
1974
|
+
continue;
|
|
1975
|
+
}
|
|
1976
|
+
out.push({
|
|
1977
|
+
type: "element",
|
|
1978
|
+
tag: "span",
|
|
1979
|
+
attrs: { [MATH_ATTRIBUTE]: "true" },
|
|
1980
|
+
children: tex ? [{ type: "text", value: tex }] : []
|
|
1981
|
+
});
|
|
1982
|
+
continue;
|
|
1983
|
+
}
|
|
1984
|
+
if (isFootnoteNode(node)) {
|
|
1985
|
+
if (state && !options.storage) {
|
|
1986
|
+
out.push(state.footnote(node));
|
|
1987
|
+
continue;
|
|
1988
|
+
}
|
|
1989
|
+
const attrs2 = { "data-mex-footnote": node.attrs["data-mex-footnote"] };
|
|
1990
|
+
const note = storedNote(node.note);
|
|
1991
|
+
if (note) attrs2["data-mex-note"] = note;
|
|
1992
|
+
out.push({ type: "element", tag: "sup", attrs: attrs2, children: inlineNodesToRender(node.children, options) });
|
|
1993
|
+
continue;
|
|
1994
|
+
}
|
|
1995
|
+
let attrs = node.attrs;
|
|
1996
|
+
if (node.tag === "a") {
|
|
1997
|
+
attrs = resolveLinkAttributes(attrs, options.links);
|
|
1998
|
+
if (!attrs || !attrs.href) {
|
|
1999
|
+
out.push(...inlineNodesToRender(node.children, options));
|
|
2000
|
+
continue;
|
|
2001
|
+
}
|
|
2002
|
+
if (attrs.target === "_blank") {
|
|
2003
|
+
const rel = new Set(
|
|
2004
|
+
String(attrs.rel || "").split(/\s+/).filter(Boolean)
|
|
2005
|
+
);
|
|
2006
|
+
rel.add("noopener");
|
|
2007
|
+
rel.add("noreferrer");
|
|
2008
|
+
attrs = { ...attrs, rel: Array.from(rel).sort().join(" ") };
|
|
2009
|
+
}
|
|
2010
|
+
if (!options.storage && isMentionLink(attrs)) attrs = { ...attrs, class: MENTION_CLASS };
|
|
2011
|
+
}
|
|
2012
|
+
const ordered = {};
|
|
2013
|
+
for (const name of ATTRIBUTE_ORDER) {
|
|
2014
|
+
if (attrs[name] !== void 0 && attrs[name] !== "") ordered[name] = String(attrs[name]);
|
|
2015
|
+
}
|
|
2016
|
+
out.push({
|
|
2017
|
+
type: "element",
|
|
2018
|
+
tag: node.tag,
|
|
2019
|
+
attrs: ordered,
|
|
2020
|
+
children: inlineNodesToRender(node.children, options)
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
return out;
|
|
2024
|
+
};
|
|
2025
|
+
const inlineToNodes = (html, options) => inlineNodesToRender(parseInline(html), options);
|
|
2026
|
+
const nodesToHtml = (nodes, options = {}) => serializeNodes(inlineNodesToRender(nodes, options));
|
|
2027
|
+
const nodesToText = (nodes, options = {}) => nodes.map((node) => {
|
|
2028
|
+
if (node.type === "text") return node.value;
|
|
2029
|
+
if (node.tag === "br") return "\n";
|
|
2030
|
+
if (!options.raw && isFootnoteNode(node))
|
|
2031
|
+
return typeof options.footnote === "function" ? options.footnote(node) : "";
|
|
2032
|
+
return nodesToText(node.children, options);
|
|
2033
|
+
}).join("");
|
|
2034
|
+
const inlineToHtml = (html, options) => nodesToHtml(parseInline(html), options);
|
|
2035
|
+
const inlineToText = (html, options) => nodesToText(parseInline(html), options).replace(/\u00a0/g, " ");
|
|
2036
|
+
const mapFootnoteNotes = (html, fn) => {
|
|
2037
|
+
if (typeof html !== "string" || !html.includes("data-mex-footnote")) return html;
|
|
2038
|
+
let changed = false;
|
|
2039
|
+
const visit = (nodes2, depth = 0) => {
|
|
2040
|
+
if (depth > MAX_DEPTH) return;
|
|
2041
|
+
for (const node of nodes2) {
|
|
2042
|
+
if (node.type !== "element") continue;
|
|
2043
|
+
if (isFootnoteNode(node)) {
|
|
2044
|
+
const before = storedNote(node.note);
|
|
2045
|
+
const after = fn(before);
|
|
2046
|
+
if (after !== before) {
|
|
2047
|
+
node.note = parseInline(String(after || ""), { inNote: true });
|
|
2048
|
+
changed = true;
|
|
2049
|
+
}
|
|
2050
|
+
} else visit(node.children, depth + 1);
|
|
2051
|
+
}
|
|
2052
|
+
};
|
|
2053
|
+
const nodes = parseInline(html);
|
|
2054
|
+
visit(nodes);
|
|
2055
|
+
return changed ? nodesToHtml(nodes, { storage: true }) : html;
|
|
2056
|
+
};
|
|
2057
|
+
const canonicalInlineExtras = (html, options = {}) => {
|
|
2058
|
+
if (typeof html !== "string") return "";
|
|
2059
|
+
const math = html.includes(MATH_ATTRIBUTE);
|
|
2060
|
+
const notes = html.includes("data-mex-footnote");
|
|
2061
|
+
if (!math && !notes) return html;
|
|
2062
|
+
const nodes = parseInline(html);
|
|
2063
|
+
if (options.footnotes === false && notes) {
|
|
2064
|
+
const strip = (list, depth = 0) => list.filter((node) => {
|
|
2065
|
+
if (node.type !== "element") return true;
|
|
2066
|
+
if (isFootnoteNode(node)) return false;
|
|
2067
|
+
if (depth < MAX_DEPTH) node.children = strip(node.children, depth + 1);
|
|
2068
|
+
return true;
|
|
2069
|
+
});
|
|
2070
|
+
return nodesToHtml(strip(nodes), { storage: true });
|
|
2071
|
+
}
|
|
2072
|
+
return nodesToHtml(nodes, { storage: true });
|
|
2073
|
+
};
|
|
2074
|
+
const walkInlineElements = (nodes, fn, inNote = false, depth = 0) => {
|
|
2075
|
+
if (depth > MAX_DEPTH) return;
|
|
2076
|
+
for (const node of nodes) {
|
|
2077
|
+
if (node.type !== "element") continue;
|
|
2078
|
+
fn(node, inNote);
|
|
2079
|
+
walkInlineElements(node.children, fn, inNote, depth + 1);
|
|
2080
|
+
if (node.note) walkInlineElements(node.note, fn, true, depth + 1);
|
|
2081
|
+
}
|
|
2082
|
+
};
|
|
1218
2083
|
let purify = null;
|
|
1219
2084
|
const instance = () => {
|
|
1220
2085
|
if (purify) return purify;
|
|
@@ -1251,16 +2116,20 @@ const instance = () => {
|
|
|
1251
2116
|
return purify;
|
|
1252
2117
|
};
|
|
1253
2118
|
const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat()));
|
|
1254
|
-
const sanitizeInline = (html) =>
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
2119
|
+
const sanitizeInline = (html) => canonicalInlineExtras(
|
|
2120
|
+
instance().sanitize(String(html || ""), {
|
|
2121
|
+
ALLOWED_TAGS: [...INLINE_TAGS],
|
|
2122
|
+
ALLOWED_ATTR,
|
|
2123
|
+
ALLOW_DATA_ATTR: false,
|
|
2124
|
+
// DOMPurify checks attribute values like URIs; `api::article.article` looks
|
|
2125
|
+
// like an unknown scheme and was dropped, which removed the entry reference
|
|
2126
|
+
// of internal links whenever content was shown again. The values are
|
|
2127
|
+
// validated by cleanInternalLinkAttributes in the hook above, and math and
|
|
2128
|
+
// footnote attributes (2.4: a note is inline HTML, "See: …" looks like a
|
|
2129
|
+
// scheme too) by `canonicalInlineExtras` below.
|
|
2130
|
+
ADD_URI_SAFE_ATTR: [...INTERNAL_LINK_ATTRIBUTES, MATH_ATTRIBUTE, ...FOOTNOTE_ATTRIBUTES]
|
|
2131
|
+
})
|
|
2132
|
+
);
|
|
1264
2133
|
const sanitizeTemplate = (html) => instance().sanitize(String(html || ""), {
|
|
1265
2134
|
ALLOWED_TAGS: [
|
|
1266
2135
|
"div",
|
|
@@ -1450,7 +2319,10 @@ const ICONS = {
|
|
|
1450
2319
|
stretch: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3 12h18m-15-3-3 3 3 3m12-6 3 3-3 3" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
1451
2320
|
mention: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="4" stroke="currentColor" stroke-width="2"/><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
|
|
1452
2321
|
toc: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h2M4 12h2M4 18h2M9 6h11M12 12h8M12 18h8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
|
|
1453
|
-
lineNumbers: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h2M4 12h2M4 18h2M10 6h10M10 12h10M10 18h10" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>'
|
|
2322
|
+
lineNumbers: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h2M4 12h2M4 18h2M10 6h10M10 12h10M10 18h10" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
|
|
2323
|
+
math: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 5H6l6 7-6 7h12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
2324
|
+
inlineMath: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 18c3 0 3-12 6-12M5 11h5m4 1 6 6m0-6-6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
2325
|
+
footnote: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 18h10M4 13h10M17 4l2-1v6m-2 0h4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'
|
|
1454
2326
|
};
|
|
1455
2327
|
const tools = /* @__PURE__ */ new Map();
|
|
1456
2328
|
const registerBlock = (options) => {
|
|
@@ -1583,33 +2455,33 @@ const createReactTool = (Component, options = {}) => {
|
|
|
1583
2455
|
const LOADERS = {
|
|
1584
2456
|
en: () => [
|
|
1585
2457
|
import("./en-Dc9y-6n9.mjs"),
|
|
1586
|
-
import("./en-
|
|
1587
|
-
import("./en-
|
|
1588
|
-
import("./en-
|
|
2458
|
+
import("./en-cYzqbASF.mjs"),
|
|
2459
|
+
import("./en-gFLeK9Ng.mjs"),
|
|
2460
|
+
import("./en-DCPMqFIa.mjs")
|
|
1589
2461
|
],
|
|
1590
2462
|
de: () => [
|
|
1591
2463
|
import("./de-1cFMs-4c.mjs"),
|
|
1592
|
-
import("./de-
|
|
1593
|
-
import("./de-
|
|
1594
|
-
import("./de-
|
|
2464
|
+
import("./de-CKz6CG3V.mjs"),
|
|
2465
|
+
import("./de-BNPIGqhs.mjs"),
|
|
2466
|
+
import("./de-DiCZrmH8.mjs")
|
|
1595
2467
|
],
|
|
1596
2468
|
fr: () => [
|
|
1597
2469
|
import("./fr-BOvvfEH7.mjs"),
|
|
1598
|
-
import("./fr-
|
|
1599
|
-
import("./fr-
|
|
1600
|
-
import("./fr-
|
|
2470
|
+
import("./fr-oW0t8bT5.mjs"),
|
|
2471
|
+
import("./fr-CMWBNE5D.mjs"),
|
|
2472
|
+
import("./fr-Dp5-XP29.mjs")
|
|
1601
2473
|
],
|
|
1602
2474
|
es: () => [
|
|
1603
2475
|
import("./es-D2Kw6E4N.mjs"),
|
|
1604
|
-
import("./es-
|
|
1605
|
-
import("./es-
|
|
1606
|
-
import("./es-
|
|
2476
|
+
import("./es-DCamt1ek.mjs"),
|
|
2477
|
+
import("./es-BmwBgEgz.mjs"),
|
|
2478
|
+
import("./es-Chs37IBR.mjs")
|
|
1607
2479
|
],
|
|
1608
2480
|
pt: () => [
|
|
1609
2481
|
import("./pt-etwsg3G4.mjs"),
|
|
1610
|
-
import("./pt-
|
|
1611
|
-
import("./pt-
|
|
1612
|
-
import("./pt-
|
|
2482
|
+
import("./pt-uGpfRQLC.mjs"),
|
|
2483
|
+
import("./pt-DFNgZ5_k.mjs"),
|
|
2484
|
+
import("./pt-DALDvfBn.mjs")
|
|
1613
2485
|
]
|
|
1614
2486
|
};
|
|
1615
2487
|
const PRESET_OPTIONS = [
|
|
@@ -1640,6 +2512,22 @@ const index = {
|
|
|
1640
2512
|
*/
|
|
1641
2513
|
register(app) {
|
|
1642
2514
|
app.registerPlugin({ id: PLUGIN_ID, name: PLUGIN_ID, apis: { registerBlock, createReactTool } });
|
|
2515
|
+
if (app.widgets && typeof app.widgets.register === "function") {
|
|
2516
|
+
app.widgets.register({
|
|
2517
|
+
id: "mentions",
|
|
2518
|
+
pluginId: PLUGIN_ID,
|
|
2519
|
+
icon: Bell,
|
|
2520
|
+
title: { id: getTranslation("widget.mentions.title"), defaultMessage: "Mentions and replies" },
|
|
2521
|
+
component: async () => {
|
|
2522
|
+
const { MentionsWidget } = await import("./MentionsWidget-sMkM9mHX.mjs");
|
|
2523
|
+
return MentionsWidget;
|
|
2524
|
+
},
|
|
2525
|
+
permissions: [
|
|
2526
|
+
{ action: "plugin::magic-editor-x.access" },
|
|
2527
|
+
{ action: "plugin::magic-editor-x.comments.read" }
|
|
2528
|
+
]
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
1643
2531
|
app.customFields.register({
|
|
1644
2532
|
name: "richtext",
|
|
1645
2533
|
pluginId: PLUGIN_ID,
|
|
@@ -1651,7 +2539,7 @@ const index = {
|
|
|
1651
2539
|
},
|
|
1652
2540
|
icon: PluginIcon,
|
|
1653
2541
|
components: {
|
|
1654
|
-
Input: () => import("./index-
|
|
2542
|
+
Input: () => import("./index-BVjf1gVC.mjs").then((n) => n.a)
|
|
1655
2543
|
},
|
|
1656
2544
|
options: {
|
|
1657
2545
|
base: [
|
|
@@ -1849,21 +2737,28 @@ const index = {
|
|
|
1849
2737
|
intlLabel: { id: getTranslation("settings.link.configuration"), defaultMessage: "Configuration" },
|
|
1850
2738
|
to: `${PLUGIN_ID}/configuration`,
|
|
1851
2739
|
permissions: PERMISSIONS.settingsRead,
|
|
1852
|
-
Component: () => import("./ConfigurationPage-
|
|
2740
|
+
Component: () => import("./ConfigurationPage-DiEpF1Rr.mjs")
|
|
1853
2741
|
},
|
|
1854
2742
|
{
|
|
1855
2743
|
id: `${PLUGIN_ID}-custom-blocks`,
|
|
1856
2744
|
intlLabel: { id: getTranslation("settings.link.customBlocks"), defaultMessage: "Custom blocks" },
|
|
1857
2745
|
to: `${PLUGIN_ID}/custom-blocks`,
|
|
1858
2746
|
permissions: PERMISSIONS.customBlocksManage,
|
|
1859
|
-
Component: () => import("./CustomBlocksPage-
|
|
2747
|
+
Component: () => import("./CustomBlocksPage-Byt10-6c.mjs")
|
|
1860
2748
|
},
|
|
1861
2749
|
{
|
|
1862
2750
|
id: `${PLUGIN_ID}-templates`,
|
|
1863
2751
|
intlLabel: { id: getTranslation("settings.link.templates"), defaultMessage: "Templates" },
|
|
1864
2752
|
to: `${PLUGIN_ID}/templates`,
|
|
1865
2753
|
permissions: PERMISSIONS.templatesManage,
|
|
1866
|
-
Component: () => import("./TemplatesPage-
|
|
2754
|
+
Component: () => import("./TemplatesPage-Yp4OqFE2.mjs")
|
|
2755
|
+
},
|
|
2756
|
+
{
|
|
2757
|
+
id: `${PLUGIN_ID}-audit`,
|
|
2758
|
+
intlLabel: { id: getTranslation("settings.link.audit"), defaultMessage: "Audit trail" },
|
|
2759
|
+
to: `${PLUGIN_ID}/audit`,
|
|
2760
|
+
permissions: PERMISSIONS.auditRead,
|
|
2761
|
+
Component: () => import("./AuditPage-guB0SiGS.mjs")
|
|
1867
2762
|
}
|
|
1868
2763
|
]
|
|
1869
2764
|
);
|
|
@@ -1887,53 +2782,108 @@ const index = {
|
|
|
1887
2782
|
}
|
|
1888
2783
|
};
|
|
1889
2784
|
export {
|
|
1890
|
-
|
|
2785
|
+
decodeEntities as $,
|
|
2786
|
+
TABLE_ALIGNS as A,
|
|
1891
2787
|
BLOCK_POLICIES as B,
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
2788
|
+
toTableModel as C,
|
|
2789
|
+
isBlankInlineHtml as D,
|
|
2790
|
+
mergeMap as E,
|
|
2791
|
+
FOOTNOTE_ATTRIBUTES as F,
|
|
2792
|
+
headerKind as G,
|
|
2793
|
+
spanAt as H,
|
|
1898
2794
|
INTERNAL_LINK_ATTRIBUTES as I,
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
2795
|
+
neighbourRect as J,
|
|
2796
|
+
canMergeRect as K,
|
|
2797
|
+
deleteColumn as L,
|
|
2798
|
+
MATH_ATTRIBUTE as M,
|
|
2799
|
+
insertColumn as N,
|
|
2800
|
+
deleteRow as O,
|
|
1905
2801
|
PERMISSIONS as P,
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
2802
|
+
insertRow as Q,
|
|
2803
|
+
splitCell as R,
|
|
2804
|
+
mergeRect as S,
|
|
1909
2805
|
TRACK_KINDS as T,
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
2806
|
+
expandRect as U,
|
|
2807
|
+
setColumnAlign as V,
|
|
2808
|
+
setHeaderRow as W,
|
|
2809
|
+
parseTabularText as X,
|
|
2810
|
+
pasteGrid as Y,
|
|
2811
|
+
prepareEditorValue as Z,
|
|
2812
|
+
fromTableModel as _,
|
|
1913
2813
|
sanitizeTemplate as a,
|
|
2814
|
+
MAX_MATH_TEX as a0,
|
|
2815
|
+
MAX_INLINE_TEX as a1,
|
|
2816
|
+
MAX_FOOTNOTE_NOTE as a2,
|
|
2817
|
+
parseInline as a3,
|
|
2818
|
+
nodesToText as a4,
|
|
2819
|
+
nodesToHtml as a5,
|
|
2820
|
+
BUILT_IN_MARKER_VERSION as a6,
|
|
2821
|
+
isBuiltInBlock as a7,
|
|
2822
|
+
BUILT_IN_MARKER as a8,
|
|
2823
|
+
activeBlocks as a9,
|
|
2824
|
+
tableLayout as aA,
|
|
2825
|
+
TAG_NAME as aB,
|
|
2826
|
+
isSafeAttributeName as aC,
|
|
2827
|
+
LINK_SCHEMES as aD,
|
|
2828
|
+
RENDER_STATE as aE,
|
|
2829
|
+
isMathNode as aF,
|
|
2830
|
+
isFootnoteNode as aG,
|
|
2831
|
+
resolveLinkAttributes as aH,
|
|
2832
|
+
nodesTextContent as aI,
|
|
2833
|
+
VOID_TAGS as aJ,
|
|
2834
|
+
safeStyle as aK,
|
|
2835
|
+
createFieldKey as aL,
|
|
2836
|
+
prepareRemoteData as aM,
|
|
2837
|
+
index as aN,
|
|
2838
|
+
computeStats as aa,
|
|
2839
|
+
isPlainObject as ab,
|
|
2840
|
+
mapFootnoteNotes as ac,
|
|
2841
|
+
walkInlineElements as ad,
|
|
2842
|
+
registeredBlockOf as ae,
|
|
2843
|
+
buildCodeBlockTools as af,
|
|
2844
|
+
MARKED_BLOCKS as ag,
|
|
2845
|
+
EDITOR_DATA_LIMITS as ah,
|
|
2846
|
+
cloneJsonSafe as ai,
|
|
2847
|
+
isPositionalFieldPath as aj,
|
|
2848
|
+
isValidFieldKey as ak,
|
|
2849
|
+
basePathOf as al,
|
|
2850
|
+
normalizeEditorDataSafe as am,
|
|
2851
|
+
inlineToText as an,
|
|
2852
|
+
byteLength as ao,
|
|
2853
|
+
el$1 as ap,
|
|
2854
|
+
compileBlockList as aq,
|
|
2855
|
+
sanitizeTunes as ar,
|
|
2856
|
+
inlineToHtml as as,
|
|
2857
|
+
cleanMediaFile as at,
|
|
2858
|
+
textNode as au,
|
|
2859
|
+
escapeHtml as av,
|
|
2860
|
+
inlineNodesToRender as aw,
|
|
2861
|
+
inlineToNodes as ax,
|
|
2862
|
+
serializeNodes as ay,
|
|
2863
|
+
toNodes as az,
|
|
1914
2864
|
select as b,
|
|
1915
2865
|
codeBlocks as c,
|
|
1916
2866
|
ICONS as d,
|
|
1917
2867
|
el as e,
|
|
1918
2868
|
field as f,
|
|
1919
|
-
|
|
1920
|
-
|
|
2869
|
+
getTranslation as g,
|
|
2870
|
+
button as h,
|
|
1921
2871
|
input as i,
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
2872
|
+
sanitizeUrl as j,
|
|
2873
|
+
MAX_GALLERY_IMAGES as k,
|
|
2874
|
+
cleanFocalPoint as l,
|
|
1925
2875
|
mergeCodeBlocks as m,
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
2876
|
+
MAX_MEDIA_TRACKS as n,
|
|
2877
|
+
editable as o,
|
|
2878
|
+
sanitizeInline as p,
|
|
2879
|
+
MAX_CODE_FILENAME as q,
|
|
2880
|
+
cleanCodeFilename as r,
|
|
1931
2881
|
sanitizeSvg as s,
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
2882
|
+
hashString as t,
|
|
2883
|
+
escapeHtml$1 as u,
|
|
2884
|
+
FOOTNOTE_ID as v,
|
|
2885
|
+
canonicalInlineExtras as w,
|
|
2886
|
+
TABLE_LIMITS as x,
|
|
2887
|
+
cleanTableAlign as y,
|
|
2888
|
+
normalizeMerges as z
|
|
1939
2889
|
};
|