magic-editor-x 2.4.0 → 2.5.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 +51 -0
- package/README.md +129 -6
- package/bin/magic-editor-x.mjs +55 -8
- package/dist/admin/{AuditPage-guB0SiGS.mjs → AuditPage-Be78C7EC.mjs} +4 -3
- package/dist/admin/{AuditPage-C2u6z4aN.js → AuditPage-iQzpjH8H.js} +7 -6
- package/dist/admin/{ConfigurationPage-DiEpF1Rr.mjs → ConfigurationPage-C9CPBfWy.mjs} +186 -6
- package/dist/admin/{ConfigurationPage-D6uya-J1.js → ConfigurationPage-DefuBeYO.js} +191 -11
- package/dist/admin/Content-BttG50Mc.mjs +360 -0
- package/dist/admin/Content-V5MRBsI3.js +362 -0
- package/dist/admin/{CustomBlocksPage-Byt10-6c.mjs → CustomBlocksPage-DB5nnCsn.mjs} +5 -4
- package/dist/admin/{CustomBlocksPage-DP3h_wNd.js → CustomBlocksPage-Dg2rM3F4.js} +8 -7
- package/dist/admin/EntryWidgets-B8YA0Zxy.mjs +199 -0
- package/dist/admin/EntryWidgets-BcXAAx3F.js +201 -0
- package/dist/admin/{MentionsWidget-sMkM9mHX.mjs → MentionsWidget-CJPZDk9Z.mjs} +2 -2
- package/dist/admin/{MentionsWidget-C2OCAmqq.js → MentionsWidget-DUz6YVIG.js} +2 -2
- package/dist/admin/{useT-CLPhBmBC.mjs → SectionCard-8ZNHkvn9.mjs} +2 -12
- package/dist/admin/{useT-BXJLIPN4.js → SectionCard-Bs-xiiH1.js} +0 -10
- package/dist/admin/{TemplatesPage-Yp4OqFE2.mjs → TemplatesPage-VsZ_Mc0R.mjs} +6 -5
- package/dist/admin/{TemplatesPage-DrSJdteI.js → TemplatesPage-dx4_yd_t.js} +13 -12
- package/dist/admin/{api-bix9RLLI.js → api-4AYzwS4-.js} +9 -1
- package/dist/admin/{api-2ZRpHM3d.mjs → api-CcTYyckq.mjs} +9 -1
- package/dist/admin/{de-zcV8D7nt.js → de-B6rdcOqQ.js} +103 -1
- package/dist/admin/{de-1cFMs-4c.mjs → de-BWfR2jTg.mjs} +8 -1
- package/dist/admin/{de-DiCZrmH8.mjs → de-Bip0sBRT.mjs} +19 -1
- package/dist/admin/{de-Dn8athM8.js → de-BrPR4sUB.js} +8 -1
- package/dist/admin/{de-CKz6CG3V.mjs → de-CQA8hOpl.mjs} +103 -1
- package/dist/admin/{de-CbBDnXeT.js → de-CnnxKXj7.js} +19 -1
- package/dist/admin/{de-BhhGss1l.js → de-Dss5POqk.js} +12 -1
- package/dist/admin/{de-BNPIGqhs.mjs → de-zgHCYTLH.mjs} +12 -1
- package/dist/admin/{en-CIZ5Ggod.js → en--JjAHbpP.js} +8 -1
- package/dist/admin/{en-cYzqbASF.mjs → en-BCKaVgBM.mjs} +103 -1
- package/dist/admin/{en-B9ApE1y1.js → en-CJ17Sp_e.js} +12 -1
- package/dist/admin/{en-BMWhILnj.js → en-CbGkcq0Q.js} +103 -1
- package/dist/admin/{en-DCPMqFIa.mjs → en-Cd6Jk-J0.mjs} +19 -1
- package/dist/admin/{en-CpehF0Kv.js → en-D69Fe9ZO.js} +19 -1
- package/dist/admin/{en-Dc9y-6n9.mjs → en-Dr58wBAo.mjs} +8 -1
- package/dist/admin/{en-gFLeK9Ng.mjs → en-Uhm7OouM.mjs} +12 -1
- package/dist/admin/entry-panel-events-0msyPrAD.js +18 -0
- package/dist/admin/entry-panel-events-XRuUoLZ9.mjs +19 -0
- package/dist/admin/{es-D2Kw6E4N.mjs → es-B2Hkkbw9.mjs} +8 -1
- package/dist/admin/{es-BmwBgEgz.mjs → es-BMkmfH88.mjs} +12 -1
- package/dist/admin/{es-Chs37IBR.mjs → es-Bz8d72Fa.mjs} +19 -1
- package/dist/admin/{es-CQPh8PXw.js → es-C8UotT8O.js} +103 -1
- package/dist/admin/{es-CawpzwyC.js → es-CcEDZpVQ.js} +19 -1
- package/dist/admin/{es-C0W31rl8.js → es-DJm3HFJt.js} +12 -1
- package/dist/admin/{es-C4IRHV5d.js → es-YvaTAtqY.js} +8 -1
- package/dist/admin/{es-DCamt1ek.mjs → es-pvPfNAld.mjs} +103 -1
- package/dist/admin/{fr-BOvvfEH7.mjs → fr-BvPjRiwr.mjs} +8 -1
- package/dist/admin/{fr-Dp5-XP29.mjs → fr-CKHZ0xxU.mjs} +19 -1
- package/dist/admin/{fr-iGeIfEcU.js → fr-CRM9VuAq.js} +12 -1
- package/dist/admin/{fr-CMWBNE5D.mjs → fr-CrIHmKYX.mjs} +12 -1
- package/dist/admin/{fr-COOsqexl.js → fr-Cx29jQ_g.js} +19 -1
- package/dist/admin/{fr-oW0t8bT5.mjs → fr-D4tL6Ag2.mjs} +103 -1
- package/dist/admin/{fr-Zkb8vfjN.js → fr-Di-U-rAH.js} +8 -1
- package/dist/admin/{fr-DpC44Ol8.js → fr-DrUYv2jh.js} +103 -1
- package/dist/admin/{index-BVjf1gVC.mjs → index-C4ksUkEm.mjs} +9183 -6353
- package/dist/admin/{index-64wc26Bl.js → index-C5D3VqLq.js} +9170 -6340
- package/dist/admin/{index-D_Fv8Non.mjs → index-CMYCZWOh.mjs} +1053 -190
- package/dist/admin/{index-D6Z7i8ba.js → index-DRyctF9s.js} +961 -98
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/{math-vsK_06ZR.js → math-D6jmskGS.js} +1 -1
- package/dist/admin/{math-CIQ4Z_mY.mjs → math-DntdSWKX.mjs} +1 -1
- package/dist/admin/{pt-DALDvfBn.mjs → pt-B8x7v-Xw.mjs} +19 -1
- package/dist/admin/{pt-DXy7G1x7.js → pt-BYn2xx78.js} +19 -1
- package/dist/admin/{pt-Bo0Pm_Pt.js → pt-CojQcz-p.js} +103 -1
- package/dist/admin/{pt-uGpfRQLC.mjs → pt-CuoIihKx.mjs} +103 -1
- package/dist/admin/{pt-1IUyx6ae.js → pt-CzrN_3ui.js} +8 -1
- package/dist/admin/{pt-DFNgZ5_k.mjs → pt-DDlPJYtB.mjs} +12 -1
- package/dist/admin/{pt-BHmXk2d9.js → pt-DPVAycXJ.js} +12 -1
- package/dist/admin/{pt-etwsg3G4.mjs → pt-DdGagO99.mjs} +8 -1
- package/dist/admin/useT-Bpw__IXT.js +12 -0
- package/dist/admin/useT-Cb-R3kyA.mjs +13 -0
- package/dist/blocks/index.d.mts +124 -0
- package/dist/blocks/index.d.ts +124 -0
- package/dist/blocks/index.js +172 -3
- package/dist/blocks/index.mjs +172 -3
- package/dist/math/index.js +6 -2
- package/dist/math/index.mjs +6 -2
- package/dist/react/index.js +1376 -1067
- package/dist/react/index.mjs +1376 -1067
- package/dist/render/index.d.mts +22 -0
- package/dist/render/index.d.ts +22 -0
- package/dist/render/index.js +1376 -1067
- package/dist/render/index.mjs +1376 -1067
- package/dist/server/index.js +28894 -24197
- package/dist/server/index.mjs +28893 -24196
- package/dist/server/mcp-worker.js +11319 -0
- package/dist/vue/index.js +1376 -1067
- package/dist/vue/index.mjs +1376 -1067
- package/package.json +7 -7
- package/schema/magic-editor-x.schema.json +9 -1
- package/types/blocks.d.ts +124 -0
- package/types/index.d.ts +10 -1
- package/types/render.d.ts +22 -0
|
@@ -1,29 +1,102 @@
|
|
|
1
|
-
import { Feather, Bell } from "@strapi/icons";
|
|
1
|
+
import { Feather, Bell, Discuss, Link } from "@strapi/icons";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { lazy, Suspense, createElement } from "react";
|
|
4
|
+
import { useIntl } from "react-intl";
|
|
5
|
+
import { Typography } from "@strapi/design-system";
|
|
6
|
+
import { unstable_useContentManagerContext, useQueryParams, useRBAC } from "@strapi/strapi/admin";
|
|
3
7
|
import createDOMPurify from "dompurify";
|
|
4
|
-
import { createElement } from "react";
|
|
5
8
|
import { createRoot } from "react-dom/client";
|
|
6
|
-
const PLUGIN_ID = "magic-editor-x";
|
|
7
|
-
const PluginIcon = () => /* @__PURE__ */ jsx(Feather, { "aria-hidden": true });
|
|
8
9
|
const action = (uid) => [{ action: `plugin::magic-editor-x.${uid}`, subject: null }];
|
|
9
10
|
const PERMISSIONS = {
|
|
11
|
+
access: action("access"),
|
|
10
12
|
customBlocksManage: action("custom-blocks.manage"),
|
|
11
13
|
settingsRead: action("settings.read"),
|
|
12
14
|
settingsUpdate: action("settings.update"),
|
|
13
15
|
templatesManage: action("templates.manage"),
|
|
14
16
|
auditRead: action("audit.read")
|
|
15
17
|
};
|
|
18
|
+
const PLUGIN_ID = "magic-editor-x";
|
|
16
19
|
const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
+
const CUSTOM_FIELD_UID = "plugin::magic-editor-x.richtext";
|
|
21
|
+
const HEARTBEAT_MS = 15e3;
|
|
22
|
+
const MAX_BACKOFF_MS = 12e4;
|
|
23
|
+
const IDLE_AFTER_MS = 6e4;
|
|
24
|
+
const MAX_DEPTH$1 = 8;
|
|
25
|
+
const hasEditorFields = (schema, components = {}, depth = 0) => {
|
|
26
|
+
if (!schema || !schema.attributes || depth > MAX_DEPTH$1) return false;
|
|
27
|
+
return Object.values(schema.attributes).some((attribute) => {
|
|
28
|
+
if (!attribute || typeof attribute !== "object") return false;
|
|
29
|
+
if (attribute.customField === CUSTOM_FIELD_UID) return true;
|
|
30
|
+
if (attribute.type === "component")
|
|
31
|
+
return hasEditorFields(components[attribute.component], components, depth + 1);
|
|
32
|
+
if (attribute.type === "dynamiczone" && Array.isArray(attribute.components))
|
|
33
|
+
return attribute.components.some((uid) => hasEditorFields(components[uid], components, depth + 1));
|
|
34
|
+
return false;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const nextDelay = (failures, status = null) => {
|
|
38
|
+
if (!failures) return HEARTBEAT_MS;
|
|
39
|
+
const delay = Math.min(MAX_BACKOFF_MS, HEARTBEAT_MS * 2 ** Math.min(failures, 4));
|
|
40
|
+
return status === 429 ? Math.max(6e4, delay) : delay;
|
|
41
|
+
};
|
|
42
|
+
const createTabId = (source = globalThis.crypto) => {
|
|
43
|
+
const bytes = source.getRandomValues(new Uint8Array(16));
|
|
44
|
+
let binary = "";
|
|
45
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
46
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
47
|
+
};
|
|
48
|
+
const entryPath = (target, extra = {}) => {
|
|
49
|
+
const value = target || {};
|
|
50
|
+
const uid = encodeURIComponent(String(value.uid || ""));
|
|
51
|
+
const path = value.kind === "singleType" ? `/content-manager/single-types/${uid}` : `/content-manager/collection-types/${uid}/${encodeURIComponent(String(value.documentId || ""))}`;
|
|
52
|
+
const params = new URLSearchParams();
|
|
53
|
+
if (value.locale) params.set("plugins[i18n][locale]", value.locale);
|
|
54
|
+
for (const [key, item] of Object.entries(extra)) params.set(key, item);
|
|
55
|
+
const query = params.toString();
|
|
56
|
+
return query ? `${path}?${query}` : path;
|
|
57
|
+
};
|
|
58
|
+
const fieldsWith = (fields, count) => Array.isArray(fields) ? fields.filter((field2) => count(field2) > 0) : [];
|
|
59
|
+
const fieldProblems = (field2) => (field2 && field2.issues ? field2.issues.errors + field2.issues.warnings : 0) + (field2 && field2.brokenLinks && field2.brokenLinks.draft ? field2.brokenLinks.draft : 0);
|
|
60
|
+
const Content = lazy(() => import("./Content-BttG50Mc.mjs"));
|
|
61
|
+
const EntryPanel = ({ model, documentId, document: document2 }) => {
|
|
62
|
+
const { formatMessage } = useIntl();
|
|
63
|
+
const context = unstable_useContentManagerContext();
|
|
64
|
+
const [{ query }] = useQueryParams();
|
|
65
|
+
const { isLoading, allowedActions } = useRBAC(PERMISSIONS.access);
|
|
66
|
+
const locale = query && query.plugins && query.plugins.i18n && typeof query.plugins.i18n.locale === "string" ? query.plugins.i18n.locale : null;
|
|
67
|
+
const editorType = hasEditorFields(context && context.contentType, context && context.components || {});
|
|
68
|
+
if (!documentId || !model || !editorType || isLoading || !allowedActions.canAccess) return null;
|
|
69
|
+
const loading = formatMessage({ id: getTranslation("entryPanel.loading"), defaultMessage: "Loading" });
|
|
70
|
+
return {
|
|
71
|
+
title: formatMessage({ id: getTranslation("entryPanel.title"), defaultMessage: "Magic Editor X" }),
|
|
72
|
+
content: /* @__PURE__ */ jsx(
|
|
73
|
+
Suspense,
|
|
74
|
+
{
|
|
75
|
+
fallback: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: loading }),
|
|
76
|
+
children: /* @__PURE__ */ jsx(
|
|
77
|
+
Content,
|
|
78
|
+
{
|
|
79
|
+
uid: model,
|
|
80
|
+
documentId,
|
|
81
|
+
locale,
|
|
82
|
+
version: String(document2 && document2.updatedAt || "")
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const PluginIcon = () => /* @__PURE__ */ jsx(Feather, { "aria-hidden": true });
|
|
90
|
+
const registry$1 = /* @__PURE__ */ new Map();
|
|
91
|
+
const activeBlock = (type) => typeof type === "string" && registry$1.has(type) ? registry$1.get(type) : null;
|
|
92
|
+
const activeBlocks = () => [...registry$1.values()];
|
|
20
93
|
const activeBlockIgnoringCase = (name) => {
|
|
21
94
|
const lower = String(name).toLowerCase();
|
|
22
|
-
for (const definition of registry.values()) if (definition.name.toLowerCase() === lower) return definition;
|
|
95
|
+
for (const definition of registry$1.values()) if (definition.name.toLowerCase() === lower) return definition;
|
|
23
96
|
return null;
|
|
24
97
|
};
|
|
25
98
|
const setActiveBlock = (compiled2) => {
|
|
26
|
-
registry.set(compiled2.name, compiled2);
|
|
99
|
+
registry$1.set(compiled2.name, compiled2);
|
|
27
100
|
};
|
|
28
101
|
const isPlainObject$1 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
29
102
|
const BUILT_IN_MARKER = "_mex";
|
|
@@ -77,6 +150,10 @@ const createFieldKey = (fill) => {
|
|
|
77
150
|
};
|
|
78
151
|
const isPositionalFieldPath = (path) => typeof path === "string" && path.split(".").some((part) => /^\d+$/.test(part));
|
|
79
152
|
const basePathOf = (path) => String(path).split(".").filter((part) => !/^\d+$/.test(part)).join(".");
|
|
153
|
+
const fieldIdentity = (path, fieldKey, positional = isPositionalFieldPath(path)) => {
|
|
154
|
+
if (!positional) return String(path);
|
|
155
|
+
return isValidFieldKey(fieldKey) ? `${basePathOf(path)}#${fieldKey}` : null;
|
|
156
|
+
};
|
|
80
157
|
const EDITOR_DATA_LIMITS = Object.freeze({
|
|
81
158
|
maxBlocks: 5e3,
|
|
82
159
|
maxBytes: 5 * 1024 * 1024,
|
|
@@ -269,7 +346,7 @@ const computeStats = (data) => {
|
|
|
269
346
|
};
|
|
270
347
|
const TABLE_LIMITS = Object.freeze({ rows: 500, cols: 100, merges: 1e3, caption: 4e3 });
|
|
271
348
|
const TABLE_ALIGNS = Object.freeze(["left", "center", "right"]);
|
|
272
|
-
const isObject$
|
|
349
|
+
const isObject$3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
273
350
|
const tableWidth = (content) => Array.isArray(content) ? content.reduce((width, row) => Math.max(width, Array.isArray(row) ? row.length : 0), 0) : 0;
|
|
274
351
|
const cleanTableAlign = (value, cols) => {
|
|
275
352
|
if (!Array.isArray(value) || cols <= 0) return null;
|
|
@@ -282,7 +359,7 @@ const normalizeMerges = (merges, rows, cols, options = {}) => {
|
|
|
282
359
|
if (!Array.isArray(merges) || rows <= 0 || cols <= 0) return [];
|
|
283
360
|
const out = [];
|
|
284
361
|
for (const merge of merges.slice(0, TABLE_LIMITS.merges)) {
|
|
285
|
-
if (!isObject$
|
|
362
|
+
if (!isObject$3(merge)) continue;
|
|
286
363
|
const { row, col, rowspan, colspan } = merge;
|
|
287
364
|
if (![row, col, rowspan, colspan].every(Number.isInteger)) continue;
|
|
288
365
|
if (row < 0 || col < 0 || rowspan < 1 || colspan < 1 || rowspan * colspan < 2) continue;
|
|
@@ -355,7 +432,7 @@ const cleanTableExtras = (out, d, inline) => {
|
|
|
355
432
|
return out;
|
|
356
433
|
};
|
|
357
434
|
const toTableModel = (data, defaults = {}) => {
|
|
358
|
-
const d = isObject$
|
|
435
|
+
const d = isObject$3(data) ? data : {};
|
|
359
436
|
let content = Array.isArray(d.content) ? d.content.slice(0, TABLE_LIMITS.rows).map(
|
|
360
437
|
(row) => Array.isArray(row) ? row.slice(0, TABLE_LIMITS.cols).map((cell) => typeof cell === "string" ? cell : "") : []
|
|
361
438
|
) : [];
|
|
@@ -637,11 +714,15 @@ const FOOTNOTE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
|
637
714
|
const MAX_MATH_TEX = 1e4;
|
|
638
715
|
const MAX_INLINE_TEX = 2e3;
|
|
639
716
|
const MAX_FOOTNOTE_NOTE = 4e3;
|
|
717
|
+
const INLINE_FORMAT_ATTRIBUTES = Object.freeze({
|
|
718
|
+
span: ["data-mex-color", "data-mex-annotation", "data-mex-a-*"],
|
|
719
|
+
mark: ["data-mex-highlight"]
|
|
720
|
+
});
|
|
640
721
|
const INLINE_ATTRIBUTES = Object.freeze({
|
|
641
722
|
a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
|
|
642
|
-
span: ["class", "data-tooltip", MATH_ATTRIBUTE],
|
|
723
|
+
span: ["class", "data-tooltip", MATH_ATTRIBUTE, ...INLINE_FORMAT_ATTRIBUTES.span],
|
|
643
724
|
sup: [...FOOTNOTE_ATTRIBUTES],
|
|
644
|
-
mark: ["class"],
|
|
725
|
+
mark: ["class", ...INLINE_FORMAT_ATTRIBUTES.mark],
|
|
645
726
|
u: ["class"],
|
|
646
727
|
s: ["class"],
|
|
647
728
|
code: ["class"]
|
|
@@ -958,6 +1039,9 @@ const BLOCK_POLICIES = {
|
|
|
958
1039
|
if (typeof file.extension === "string") cleanFile.extension = plain(file.extension, 16);
|
|
959
1040
|
if (Number.isFinite(file.size)) cleanFile.size = file.size;
|
|
960
1041
|
if (typeof file.title === "string") cleanFile.title = plain(file.title, 255);
|
|
1042
|
+
if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
|
|
1043
|
+
cleanFile.id = file.id;
|
|
1044
|
+
if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
|
|
961
1045
|
return { file: cleanFile, title: plain(d.title, 255) };
|
|
962
1046
|
},
|
|
963
1047
|
embed: (d, inline) => ({
|
|
@@ -1162,27 +1246,27 @@ class BlockDefinitionError extends Error {
|
|
|
1162
1246
|
this.code = code;
|
|
1163
1247
|
}
|
|
1164
1248
|
}
|
|
1165
|
-
const isObject$
|
|
1166
|
-
const fail = (where, message) => {
|
|
1249
|
+
const isObject$2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
1250
|
+
const fail$1 = (where, message) => {
|
|
1167
1251
|
throw new BlockDefinitionError(`Magic Editor X block ${where}: ${message}`);
|
|
1168
1252
|
};
|
|
1169
1253
|
const boundedInt = (value, min, max, fallback, where, key) => {
|
|
1170
1254
|
if (value === void 0) return fallback;
|
|
1171
1255
|
if (!Number.isInteger(value) || value < min || value > max)
|
|
1172
|
-
fail(where, `"${key}" must be an integer from ${min} to ${max}`);
|
|
1256
|
+
fail$1(where, `"${key}" must be an integer from ${min} to ${max}`);
|
|
1173
1257
|
return value;
|
|
1174
1258
|
};
|
|
1175
1259
|
const normalizeField = (input2, where, depth) => {
|
|
1176
|
-
if (!isObject$
|
|
1260
|
+
if (!isObject$2(input2)) fail$1(where, 'a field must be an object with a "type"');
|
|
1177
1261
|
const type = input2.type;
|
|
1178
|
-
if (!BLOCK_FIELD_TYPES.includes(type)) fail(where, `unknown field type ${JSON.stringify(type)}`);
|
|
1262
|
+
if (!BLOCK_FIELD_TYPES.includes(type)) fail$1(where, `unknown field type ${JSON.stringify(type)}`);
|
|
1179
1263
|
for (const key of Object.keys(input2))
|
|
1180
1264
|
if (key !== "type" && key !== "label" && !FIELD_KEYS[type].includes(key))
|
|
1181
|
-
fail(where, `unknown option "${key}" for a ${type} field`);
|
|
1265
|
+
fail$1(where, `unknown option "${key}" for a ${type} field`);
|
|
1182
1266
|
const out = { type };
|
|
1183
1267
|
if (input2.label !== void 0) {
|
|
1184
1268
|
if (typeof input2.label !== "string" || input2.label.length > 100)
|
|
1185
|
-
fail(where, '"label" must be a string of at most 100 characters');
|
|
1269
|
+
fail$1(where, '"label" must be a string of at most 100 characters');
|
|
1186
1270
|
out.label = input2.label;
|
|
1187
1271
|
}
|
|
1188
1272
|
switch (type) {
|
|
@@ -1197,11 +1281,11 @@ const normalizeField = (input2, where, depth) => {
|
|
|
1197
1281
|
"max"
|
|
1198
1282
|
);
|
|
1199
1283
|
if (input2.default !== void 0 && typeof input2.default !== "string")
|
|
1200
|
-
fail(where, '"default" must be a string');
|
|
1284
|
+
fail$1(where, '"default" must be a string');
|
|
1201
1285
|
out.default = (input2.default || "").slice(0, out.max);
|
|
1202
1286
|
if (type === "text") {
|
|
1203
1287
|
if (input2.multiline !== void 0 && typeof input2.multiline !== "boolean")
|
|
1204
|
-
fail(where, '"multiline" must be a boolean');
|
|
1288
|
+
fail$1(where, '"multiline" must be a boolean');
|
|
1205
1289
|
out.multiline = input2.multiline === true;
|
|
1206
1290
|
}
|
|
1207
1291
|
break;
|
|
@@ -1209,9 +1293,9 @@ const normalizeField = (input2, where, depth) => {
|
|
|
1209
1293
|
case "url": {
|
|
1210
1294
|
const schemes = input2.schemes === void 0 ? ["http", "https"] : input2.schemes;
|
|
1211
1295
|
if (!Array.isArray(schemes) || !schemes.length || schemes.some((scheme) => !LINK_SCHEMES.includes(scheme)))
|
|
1212
|
-
fail(where, `"schemes" must be a non-empty list of ${LINK_SCHEMES.join(", ")}`);
|
|
1296
|
+
fail$1(where, `"schemes" must be a non-empty list of ${LINK_SCHEMES.join(", ")}`);
|
|
1213
1297
|
if (input2.relative !== void 0 && typeof input2.relative !== "boolean")
|
|
1214
|
-
fail(where, '"relative" must be a boolean');
|
|
1298
|
+
fail$1(where, '"relative" must be a boolean');
|
|
1215
1299
|
out.schemes = Object.freeze([...new Set(schemes)]);
|
|
1216
1300
|
out.relative = input2.relative !== false;
|
|
1217
1301
|
break;
|
|
@@ -1219,59 +1303,59 @@ const normalizeField = (input2, where, depth) => {
|
|
|
1219
1303
|
case "enum": {
|
|
1220
1304
|
const values = input2.values;
|
|
1221
1305
|
if (!Array.isArray(values) || values.length < 1 || values.length > BLOCK_LIMITS.maxEnumValues || values.some((value) => typeof value !== "string" || value.length < 1 || value.length > 100) || new Set(values).size !== values.length)
|
|
1222
|
-
fail(
|
|
1306
|
+
fail$1(
|
|
1223
1307
|
where,
|
|
1224
1308
|
`"values" must be 1 to ${BLOCK_LIMITS.maxEnumValues} distinct strings (1-100 characters)`
|
|
1225
1309
|
);
|
|
1226
1310
|
out.values = Object.freeze([...values]);
|
|
1227
1311
|
if (input2.default !== void 0 && !values.includes(input2.default))
|
|
1228
|
-
fail(where, '"default" must be one of "values"');
|
|
1312
|
+
fail$1(where, '"default" must be one of "values"');
|
|
1229
1313
|
out.default = input2.default === void 0 ? values[0] : input2.default;
|
|
1230
1314
|
break;
|
|
1231
1315
|
}
|
|
1232
1316
|
case "number": {
|
|
1233
1317
|
for (const key of ["min", "max", "default"])
|
|
1234
1318
|
if (input2[key] !== void 0 && (typeof input2[key] !== "number" || !Number.isFinite(input2[key])))
|
|
1235
|
-
fail(where, `"${key}" must be a finite number`);
|
|
1319
|
+
fail$1(where, `"${key}" must be a finite number`);
|
|
1236
1320
|
if (input2.integer !== void 0 && typeof input2.integer !== "boolean")
|
|
1237
|
-
fail(where, '"integer" must be a boolean');
|
|
1321
|
+
fail$1(where, '"integer" must be a boolean');
|
|
1238
1322
|
out.integer = input2.integer === true;
|
|
1239
1323
|
out.min = input2.min === void 0 ? -Number.MAX_SAFE_INTEGER : input2.min;
|
|
1240
1324
|
out.max = input2.max === void 0 ? Number.MAX_SAFE_INTEGER : input2.max;
|
|
1241
|
-
if (out.min > out.max) fail(where, '"min" must not be greater than "max"');
|
|
1325
|
+
if (out.min > out.max) fail$1(where, '"min" must not be greater than "max"');
|
|
1242
1326
|
if (input2.default !== void 0) {
|
|
1243
1327
|
if (input2.default < out.min || input2.default > out.max || out.integer && !Number.isInteger(input2.default))
|
|
1244
|
-
fail(where, '"default" must be a valid value of the field');
|
|
1328
|
+
fail$1(where, '"default" must be a valid value of the field');
|
|
1245
1329
|
out.default = input2.default;
|
|
1246
1330
|
}
|
|
1247
1331
|
break;
|
|
1248
1332
|
}
|
|
1249
1333
|
case "boolean":
|
|
1250
1334
|
if (input2.default !== void 0 && typeof input2.default !== "boolean")
|
|
1251
|
-
fail(where, '"default" must be a boolean');
|
|
1335
|
+
fail$1(where, '"default" must be a boolean');
|
|
1252
1336
|
out.default = input2.default === true;
|
|
1253
1337
|
break;
|
|
1254
1338
|
case "array":
|
|
1255
|
-
if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1339
|
+
if (depth >= BLOCK_LIMITS.maxDepth) fail$1(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1256
1340
|
out.max = boundedInt(input2.max, 1, BLOCK_LIMITS.maxItems, BLOCK_LIMITS.defaultItems, where, "max");
|
|
1257
1341
|
out.items = normalizeField(input2.items, `${where}[]`, depth + 1);
|
|
1258
1342
|
break;
|
|
1259
1343
|
case "object":
|
|
1260
|
-
if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1344
|
+
if (depth >= BLOCK_LIMITS.maxDepth) fail$1(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1261
1345
|
out.fields = normalizeFields(input2.fields, where, depth + 1);
|
|
1262
1346
|
break;
|
|
1263
1347
|
}
|
|
1264
1348
|
return Object.freeze(out);
|
|
1265
1349
|
};
|
|
1266
1350
|
const normalizeFields = (input2, where, depth) => {
|
|
1267
|
-
if (!isObject$
|
|
1351
|
+
if (!isObject$2(input2)) fail$1(where, '"fields" must be an object of field descriptors');
|
|
1268
1352
|
const keys = Object.keys(input2);
|
|
1269
1353
|
if (keys.length < 1 || keys.length > BLOCK_LIMITS.maxFields)
|
|
1270
|
-
fail(where, `an object needs 1 to ${BLOCK_LIMITS.maxFields} fields`);
|
|
1354
|
+
fail$1(where, `an object needs 1 to ${BLOCK_LIMITS.maxFields} fields`);
|
|
1271
1355
|
const out = /* @__PURE__ */ Object.create(null);
|
|
1272
1356
|
for (const key of keys) {
|
|
1273
1357
|
if (!KEY_PATTERN.test(key) || FORBIDDEN_KEYS.has(key))
|
|
1274
|
-
fail(where, `field name ${JSON.stringify(key)} must match ${KEY_PATTERN}`);
|
|
1358
|
+
fail$1(where, `field name ${JSON.stringify(key)} must match ${KEY_PATTERN}`);
|
|
1275
1359
|
out[key] = normalizeField(input2[key], `${where}.${key}`, depth);
|
|
1276
1360
|
}
|
|
1277
1361
|
return Object.freeze(out);
|
|
@@ -1283,11 +1367,11 @@ const blockNameProblem = (name) => {
|
|
|
1283
1367
|
return null;
|
|
1284
1368
|
};
|
|
1285
1369
|
const defineBlock = (definition) => {
|
|
1286
|
-
if (!isObject$
|
|
1370
|
+
if (!isObject$2(definition))
|
|
1287
1371
|
throw new BlockDefinitionError("Magic Editor X block: the definition must be an object");
|
|
1288
1372
|
const label = typeof definition.name === "string" ? `"${definition.name.slice(0, 50)}"` : "(no name)";
|
|
1289
1373
|
for (const key of Object.keys(definition))
|
|
1290
|
-
if (!DEFINITION_KEYS.has(key)) fail(label, `unknown key "${key}"`);
|
|
1374
|
+
if (!DEFINITION_KEYS.has(key)) fail$1(label, `unknown key "${key}"`);
|
|
1291
1375
|
const problem = blockNameProblem(definition.name);
|
|
1292
1376
|
if (problem)
|
|
1293
1377
|
throw new BlockDefinitionError(
|
|
@@ -1304,18 +1388,18 @@ const defineBlock = (definition) => {
|
|
|
1304
1388
|
]) {
|
|
1305
1389
|
if (definition[key] === void 0) continue;
|
|
1306
1390
|
if (typeof definition[key] !== "string" || definition[key].length > max)
|
|
1307
|
-
fail(label, `"${key}" must be a string of at most ${max} characters`);
|
|
1391
|
+
fail$1(label, `"${key}" must be a string of at most ${max} characters`);
|
|
1308
1392
|
out[key] = definition[key];
|
|
1309
1393
|
}
|
|
1310
1394
|
out.schema = normalizeFields(definition.schema, `${label} schema`, 0);
|
|
1311
1395
|
for (const key of ["sanitize", "text", "markdown", "render"]) {
|
|
1312
1396
|
if (definition[key] === void 0) continue;
|
|
1313
|
-
if (typeof definition[key] !== "function") fail(label, `"${key}" must be a function`);
|
|
1397
|
+
if (typeof definition[key] !== "function") fail$1(label, `"${key}" must be a function`);
|
|
1314
1398
|
out[key] = definition[key];
|
|
1315
1399
|
}
|
|
1316
1400
|
const presets = definition.presets === void 0 ? [] : definition.presets;
|
|
1317
1401
|
if (!Array.isArray(presets) || presets.some((preset) => !BLOCK_PRESETS.includes(preset)))
|
|
1318
|
-
fail(label, `"presets" must list some of ${BLOCK_PRESETS.join(", ")}`);
|
|
1402
|
+
fail$1(label, `"presets" must list some of ${BLOCK_PRESETS.join(", ")}`);
|
|
1319
1403
|
out.presets = Object.freeze([...new Set(presets)]);
|
|
1320
1404
|
return Object.freeze(out);
|
|
1321
1405
|
};
|
|
@@ -1349,7 +1433,7 @@ const cleanValue = (field2, value, inline, budget) => {
|
|
|
1349
1433
|
return out;
|
|
1350
1434
|
}
|
|
1351
1435
|
case "object":
|
|
1352
|
-
return cleanObject(field2.fields, isObject$
|
|
1436
|
+
return cleanObject(field2.fields, isObject$2(value) ? value : {}, inline, budget);
|
|
1353
1437
|
default:
|
|
1354
1438
|
return void 0;
|
|
1355
1439
|
}
|
|
@@ -1368,7 +1452,7 @@ const matchesType = (field2, item) => {
|
|
|
1368
1452
|
case "array":
|
|
1369
1453
|
return Array.isArray(item);
|
|
1370
1454
|
default:
|
|
1371
|
-
return isObject$
|
|
1455
|
+
return isObject$2(item);
|
|
1372
1456
|
}
|
|
1373
1457
|
};
|
|
1374
1458
|
const cleanObject = (fields, value, inline, budget) => {
|
|
@@ -1387,13 +1471,13 @@ const eachLeaf = (fields, data, visit) => {
|
|
|
1387
1471
|
if (!Array.isArray(value)) return;
|
|
1388
1472
|
value.slice(0, field2.max).forEach((item, index2) => walk(field2.items, item, [...path, index2], depth + 1));
|
|
1389
1473
|
} else if (field2.type === "object") {
|
|
1390
|
-
if (!isObject$
|
|
1474
|
+
if (!isObject$2(value)) return;
|
|
1391
1475
|
for (const key of Object.keys(field2.fields))
|
|
1392
1476
|
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
1393
1477
|
walk(field2.fields[key], value[key], [...path, key], depth + 1);
|
|
1394
1478
|
} else visit(field2, value, path);
|
|
1395
1479
|
};
|
|
1396
|
-
if (!isObject$
|
|
1480
|
+
if (!isObject$2(data)) return;
|
|
1397
1481
|
for (const key of Object.keys(fields))
|
|
1398
1482
|
if (Object.prototype.hasOwnProperty.call(data, key)) walk(fields[key], data[key], [key], 0);
|
|
1399
1483
|
};
|
|
@@ -1419,7 +1503,7 @@ const compileBlock = (definition) => {
|
|
|
1419
1503
|
return compiled.get(definition);
|
|
1420
1504
|
const def = defineBlock(definition && typeof definition === "object" ? { ...definition } : definition);
|
|
1421
1505
|
const schema = def.schema;
|
|
1422
|
-
const run = (data, inline) => cleanObject(schema, isObject$
|
|
1506
|
+
const run = (data, inline) => cleanObject(schema, isObject$2(data) ? data : {}, inline, { left: BLOCK_LIMITS.maxValues });
|
|
1423
1507
|
const result = Object.freeze({
|
|
1424
1508
|
...def,
|
|
1425
1509
|
/**
|
|
@@ -1440,7 +1524,7 @@ const compileBlock = (definition) => {
|
|
|
1440
1524
|
} catch {
|
|
1441
1525
|
return first;
|
|
1442
1526
|
}
|
|
1443
|
-
return isObject$
|
|
1527
|
+
return isObject$2(next) ? run(next, inline) : first;
|
|
1444
1528
|
},
|
|
1445
1529
|
/**
|
|
1446
1530
|
* Text fields of the data in schema order: `{ path, kind, value }`
|
|
@@ -1488,7 +1572,7 @@ const compileBlock = (definition) => {
|
|
|
1488
1572
|
};
|
|
1489
1573
|
const copyData = (value) => {
|
|
1490
1574
|
if (Array.isArray(value)) return value.map(copyData);
|
|
1491
|
-
if (isObject$
|
|
1575
|
+
if (isObject$2(value)) {
|
|
1492
1576
|
const out = {};
|
|
1493
1577
|
for (const [key, child] of Object.entries(value)) out[key] = copyData(child);
|
|
1494
1578
|
return out;
|
|
@@ -1526,10 +1610,10 @@ const LINK_SANITIZE = Object.freeze({
|
|
|
1526
1610
|
rel: true,
|
|
1527
1611
|
...Object.fromEntries(INTERNAL_LINK_ATTRIBUTES.map((name) => [name, true]))
|
|
1528
1612
|
});
|
|
1529
|
-
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1613
|
+
const isObject$1 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1530
1614
|
const localized = (value, locale) => {
|
|
1531
1615
|
if (typeof value === "string") return value;
|
|
1532
|
-
if (!isObject(value)) return "";
|
|
1616
|
+
if (!isObject$1(value)) return "";
|
|
1533
1617
|
const lang = String(locale || "en");
|
|
1534
1618
|
const pick = value[lang] ?? value[lang.split("-")[0]] ?? value.en ?? Object.values(value)[0];
|
|
1535
1619
|
return typeof pick === "string" ? pick : "";
|
|
@@ -1671,6 +1755,290 @@ const nodesTextContent = (nodes) => {
|
|
|
1671
1755
|
}
|
|
1672
1756
|
return out;
|
|
1673
1757
|
};
|
|
1758
|
+
const TOKEN_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
1759
|
+
const COLOR_ATTRIBUTE = "data-mex-color";
|
|
1760
|
+
const HIGHLIGHT_ATTRIBUTE = "data-mex-highlight";
|
|
1761
|
+
const PALETTE_LIMITS = Object.freeze({ tokens: 24, label: 60, locales: 20 });
|
|
1762
|
+
const HEX = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
1763
|
+
const LOCALE = /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8}){0,3}$/;
|
|
1764
|
+
const DEFAULT_SURFACE = Object.freeze({
|
|
1765
|
+
background: Object.freeze({ light: "#ffffff", dark: "#121212" }),
|
|
1766
|
+
text: Object.freeze({ light: "#1f1f1f", dark: "#f2f2f2" })
|
|
1767
|
+
});
|
|
1768
|
+
const isHexColor = (value) => typeof value === "string" && HEX.test(value);
|
|
1769
|
+
const longHex = (value) => {
|
|
1770
|
+
const hex = value.slice(1).toLowerCase();
|
|
1771
|
+
return `#${hex.length === 3 ? [...hex].map((c) => c + c).join("") : hex}`;
|
|
1772
|
+
};
|
|
1773
|
+
const isToken = (value) => typeof value === "string" && TOKEN_PATTERN.test(value);
|
|
1774
|
+
const cleanLabel = (value) => {
|
|
1775
|
+
if (typeof value === "string") return value.trim().slice(0, PALETTE_LIMITS.label) || null;
|
|
1776
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
1777
|
+
const out = {};
|
|
1778
|
+
for (const [locale, text] of Object.entries(value).slice(0, PALETTE_LIMITS.locales))
|
|
1779
|
+
if (LOCALE.test(locale) && typeof text === "string" && text.trim())
|
|
1780
|
+
out[locale] = text.trim().slice(0, PALETTE_LIMITS.label);
|
|
1781
|
+
return Object.keys(out).length ? out : null;
|
|
1782
|
+
};
|
|
1783
|
+
const cleanTokens = (list) => {
|
|
1784
|
+
const out = [];
|
|
1785
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1786
|
+
for (const item of Array.isArray(list) ? list : []) {
|
|
1787
|
+
if (out.length >= PALETTE_LIMITS.tokens) break;
|
|
1788
|
+
if (!item || typeof item !== "object" || !isToken(item.name) || seen.has(item.name)) continue;
|
|
1789
|
+
if (!isHexColor(item.light)) continue;
|
|
1790
|
+
seen.add(item.name);
|
|
1791
|
+
out.push({
|
|
1792
|
+
name: item.name,
|
|
1793
|
+
label: cleanLabel(item.label),
|
|
1794
|
+
light: longHex(item.light),
|
|
1795
|
+
dark: longHex(isHexColor(item.dark) ? item.dark : item.light)
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
return out;
|
|
1799
|
+
};
|
|
1800
|
+
const cleanPair = (value, fallback) => {
|
|
1801
|
+
const source = value && typeof value === "object" ? value : {};
|
|
1802
|
+
return {
|
|
1803
|
+
light: isHexColor(source.light) ? longHex(source.light) : fallback.light,
|
|
1804
|
+
dark: isHexColor(source.dark) ? longHex(source.dark) : fallback.dark
|
|
1805
|
+
};
|
|
1806
|
+
};
|
|
1807
|
+
const normalizePalette = (input2) => {
|
|
1808
|
+
const source = input2 && typeof input2 === "object" ? input2 : {};
|
|
1809
|
+
return {
|
|
1810
|
+
background: cleanPair(source.background, DEFAULT_SURFACE.background),
|
|
1811
|
+
text: cleanPair(source.text, DEFAULT_SURFACE.text),
|
|
1812
|
+
colors: cleanTokens(source.colors),
|
|
1813
|
+
highlights: cleanTokens(source.highlights)
|
|
1814
|
+
};
|
|
1815
|
+
};
|
|
1816
|
+
const hasPalette = (palette) => Boolean(
|
|
1817
|
+
palette && (palette.colors && palette.colors.length || palette.highlights && palette.highlights.length)
|
|
1818
|
+
);
|
|
1819
|
+
const tokenLabel = (token, locale) => {
|
|
1820
|
+
const { label } = token;
|
|
1821
|
+
if (typeof label === "string") return label;
|
|
1822
|
+
if (label && typeof label === "object") {
|
|
1823
|
+
const language = typeof locale === "string" ? locale.split("-")[0] : "";
|
|
1824
|
+
return label[locale] || label[language] || label.en || Object.values(label)[0] || token.name;
|
|
1825
|
+
}
|
|
1826
|
+
return token.name;
|
|
1827
|
+
};
|
|
1828
|
+
const colorClass = (token) => `mex-color-${token}`;
|
|
1829
|
+
const highlightClass = (token) => `mex-highlight-${token}`;
|
|
1830
|
+
const paletteCss = (palette, options = {}) => {
|
|
1831
|
+
const selector = typeof options.selector === "function" ? options.selector : (kind, token) => `.${kind === "color" ? colorClass(token) : highlightClass(token)}`;
|
|
1832
|
+
const mode = options.dark || "media";
|
|
1833
|
+
const rules = (variant) => [
|
|
1834
|
+
...palette.colors.map((token) => `${selector("color", token.name)} { color: ${token[variant]}; }`),
|
|
1835
|
+
...palette.highlights.map(
|
|
1836
|
+
(token) => `${selector("highlight", token.name)} { background-color: ${token[variant]}; color: inherit; }`
|
|
1837
|
+
)
|
|
1838
|
+
];
|
|
1839
|
+
if (mode === "only") return rules("dark").join("\n");
|
|
1840
|
+
const light = rules("light").join("\n");
|
|
1841
|
+
if (mode === "none" || !light) return light;
|
|
1842
|
+
return `${light}
|
|
1843
|
+
@media (prefers-color-scheme: dark) {
|
|
1844
|
+
${rules("dark").map((rule) => ` ${rule}`).join("\n")}
|
|
1845
|
+
}`;
|
|
1846
|
+
};
|
|
1847
|
+
const ANNOTATION_ATTRIBUTE = "data-mex-annotation";
|
|
1848
|
+
const ANNOTATION_VALUE_PREFIX = "data-mex-a-";
|
|
1849
|
+
const ANNOTATION_NAME = /^[a-z][a-z0-9-]{1,39}$/;
|
|
1850
|
+
const ANNOTATION_KEY = /^[a-z][a-z0-9]{0,23}$/;
|
|
1851
|
+
const ANNOTATION_FIELD_TYPES = Object.freeze(["text", "enum", "url"]);
|
|
1852
|
+
const ANNOTATION_LIMITS = Object.freeze({
|
|
1853
|
+
attributes: 8,
|
|
1854
|
+
text: 1e3,
|
|
1855
|
+
textDefault: 200,
|
|
1856
|
+
values: 50,
|
|
1857
|
+
registered: 50,
|
|
1858
|
+
label: 100,
|
|
1859
|
+
resolveItems: 200
|
|
1860
|
+
});
|
|
1861
|
+
const ANNOTATION_PRESETS = Object.freeze(["full", "article", "basic", "minimal"]);
|
|
1862
|
+
const ANNOTATION_RENDER_TAGS = Object.freeze([
|
|
1863
|
+
"abbr",
|
|
1864
|
+
"dfn",
|
|
1865
|
+
"span",
|
|
1866
|
+
"a",
|
|
1867
|
+
"mark",
|
|
1868
|
+
"cite",
|
|
1869
|
+
"q",
|
|
1870
|
+
"small",
|
|
1871
|
+
"em",
|
|
1872
|
+
"strong",
|
|
1873
|
+
"b",
|
|
1874
|
+
"i",
|
|
1875
|
+
"u",
|
|
1876
|
+
"s",
|
|
1877
|
+
"time",
|
|
1878
|
+
"data",
|
|
1879
|
+
"bdi",
|
|
1880
|
+
"kbd",
|
|
1881
|
+
"var",
|
|
1882
|
+
"ins",
|
|
1883
|
+
"del"
|
|
1884
|
+
]);
|
|
1885
|
+
const ANNOTATION_SHORTCUTS = Object.freeze(["CMD+SHIFT+0", "CMD+SHIFT+1", "CMD+SHIFT+8"]);
|
|
1886
|
+
const ABBREVIATION = "abbreviation";
|
|
1887
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
1888
|
+
const fail = (name, message, code = "INVALID_DEFINITION") => {
|
|
1889
|
+
throw new BlockDefinitionError(`Magic Editor X inline annotation ${name}: ${message}`, code);
|
|
1890
|
+
};
|
|
1891
|
+
const defined = /* @__PURE__ */ new WeakSet();
|
|
1892
|
+
const cleanText = (value, max) => typeof value === "string" ? value.trim().slice(0, max).trim() : "";
|
|
1893
|
+
const normalizeAttribute = (where, input2) => {
|
|
1894
|
+
if (!isObject(input2)) fail(where, 'an attribute must be an object with a "type"');
|
|
1895
|
+
const { type } = input2;
|
|
1896
|
+
if (!ANNOTATION_FIELD_TYPES.includes(type)) fail(where, `unknown attribute type ${JSON.stringify(type)}`);
|
|
1897
|
+
const allowed = { text: ["max"], enum: ["values"], url: ["schemes", "relative"] }[type];
|
|
1898
|
+
for (const key of Object.keys(input2))
|
|
1899
|
+
if (!["type", "label", "required", ...allowed].includes(key))
|
|
1900
|
+
fail(where, `unknown option "${key}" for a ${type} attribute`);
|
|
1901
|
+
const out = { type, required: input2.required === true };
|
|
1902
|
+
if (input2.label !== void 0) {
|
|
1903
|
+
if (typeof input2.label !== "string" || input2.label.length > ANNOTATION_LIMITS.label)
|
|
1904
|
+
fail(where, `"label" must be a string of at most ${ANNOTATION_LIMITS.label} characters`);
|
|
1905
|
+
out.label = input2.label;
|
|
1906
|
+
}
|
|
1907
|
+
if (input2.required !== void 0 && typeof input2.required !== "boolean")
|
|
1908
|
+
fail(where, '"required" must be a boolean');
|
|
1909
|
+
if (type === "text") {
|
|
1910
|
+
const max = input2.max === void 0 ? ANNOTATION_LIMITS.textDefault : input2.max;
|
|
1911
|
+
if (!Number.isInteger(max) || max < 1 || max > ANNOTATION_LIMITS.text)
|
|
1912
|
+
fail(where, `"max" must be an integer from 1 to ${ANNOTATION_LIMITS.text}`);
|
|
1913
|
+
out.max = max;
|
|
1914
|
+
} else if (type === "enum") {
|
|
1915
|
+
const { values } = input2;
|
|
1916
|
+
if (!Array.isArray(values) || !values.length || values.length > ANNOTATION_LIMITS.values || !values.every((value) => typeof value === "string" && value.length >= 1 && value.length <= 100) || new Set(values).size !== values.length)
|
|
1917
|
+
fail(where, `"values" must be 1 to ${ANNOTATION_LIMITS.values} distinct strings`);
|
|
1918
|
+
out.values = Object.freeze([...values]);
|
|
1919
|
+
} else {
|
|
1920
|
+
const schemes = input2.schemes === void 0 ? ["http", "https"] : input2.schemes;
|
|
1921
|
+
if (!Array.isArray(schemes) || !schemes.length || !schemes.every((scheme) => LINK_SCHEMES.includes(scheme)))
|
|
1922
|
+
fail(where, `"schemes" must be a non-empty subset of ${LINK_SCHEMES.join(", ")}`);
|
|
1923
|
+
if (input2.relative !== void 0 && typeof input2.relative !== "boolean")
|
|
1924
|
+
fail(where, '"relative" must be a boolean');
|
|
1925
|
+
out.schemes = Object.freeze([...new Set(schemes)]);
|
|
1926
|
+
out.relative = input2.relative !== false;
|
|
1927
|
+
}
|
|
1928
|
+
return Object.freeze(out);
|
|
1929
|
+
};
|
|
1930
|
+
const defineInlineAnnotation = (definition) => {
|
|
1931
|
+
if (!isObject(definition)) fail("(unnamed)", "the definition must be an object");
|
|
1932
|
+
const { name } = definition;
|
|
1933
|
+
if (typeof name !== "string" || !ANNOTATION_NAME.test(name))
|
|
1934
|
+
fail(JSON.stringify(name), "the name must match /^[a-z][a-z0-9-]{1,39}$/");
|
|
1935
|
+
for (const key of Object.keys(definition))
|
|
1936
|
+
if (!["name", "label", "description", "attributes", "presets", "resolve", "render", "shortcut"].includes(
|
|
1937
|
+
key
|
|
1938
|
+
))
|
|
1939
|
+
fail(name, `unknown key "${key}"`);
|
|
1940
|
+
for (const key of ["label", "description"])
|
|
1941
|
+
if (definition[key] !== void 0 && (typeof definition[key] !== "string" || definition[key].length > (key === "label" ? 100 : 500)))
|
|
1942
|
+
fail(name, `"${key}" must be a short string`);
|
|
1943
|
+
if (!isObject(definition.attributes)) fail(name, '"attributes" must be an object');
|
|
1944
|
+
const keys = Object.keys(definition.attributes);
|
|
1945
|
+
if (keys.length > ANNOTATION_LIMITS.attributes)
|
|
1946
|
+
fail(name, `at most ${ANNOTATION_LIMITS.attributes} attributes`);
|
|
1947
|
+
const attributes = {};
|
|
1948
|
+
for (const key of keys) {
|
|
1949
|
+
if (!ANNOTATION_KEY.test(key)) fail(name, `attribute key "${key}" must match /^[a-z][a-z0-9]{0,23}$/`);
|
|
1950
|
+
attributes[key] = normalizeAttribute(`${name}.${key}`, definition.attributes[key]);
|
|
1951
|
+
}
|
|
1952
|
+
const presets = definition.presets === void 0 ? [] : definition.presets;
|
|
1953
|
+
if (!Array.isArray(presets) || !presets.every((preset) => ANNOTATION_PRESETS.includes(preset)))
|
|
1954
|
+
fail(name, `"presets" must list only ${ANNOTATION_PRESETS.join(", ")}`);
|
|
1955
|
+
if (definition.shortcut !== void 0 && !ANNOTATION_SHORTCUTS.includes(definition.shortcut))
|
|
1956
|
+
fail(name, `"shortcut" must be one of ${ANNOTATION_SHORTCUTS.join(", ")}`);
|
|
1957
|
+
for (const key of ["resolve", "render"])
|
|
1958
|
+
if (definition[key] !== void 0 && typeof definition[key] !== "function")
|
|
1959
|
+
fail(name, `"${key}" must be a function`);
|
|
1960
|
+
const out = Object.freeze({
|
|
1961
|
+
name,
|
|
1962
|
+
label: definition.label || name,
|
|
1963
|
+
...definition.description ? { description: definition.description } : {},
|
|
1964
|
+
attributes: Object.freeze(attributes),
|
|
1965
|
+
presets: Object.freeze([...new Set(presets)]),
|
|
1966
|
+
...definition.shortcut ? { shortcut: definition.shortcut } : {},
|
|
1967
|
+
...definition.resolve ? { resolve: definition.resolve } : {},
|
|
1968
|
+
...definition.render ? { render: definition.render } : {}
|
|
1969
|
+
});
|
|
1970
|
+
defined.add(out);
|
|
1971
|
+
return out;
|
|
1972
|
+
};
|
|
1973
|
+
const cleanAnnotationAttributes = (definition, raw) => {
|
|
1974
|
+
const source = raw && typeof raw === "object" ? raw : {};
|
|
1975
|
+
const out = {};
|
|
1976
|
+
for (const [key, field2] of Object.entries(definition.attributes)) {
|
|
1977
|
+
const value = Object.prototype.hasOwnProperty.call(source, key) ? source[key] : void 0;
|
|
1978
|
+
let clean;
|
|
1979
|
+
if (field2.type === "text") clean = cleanText(value, field2.max);
|
|
1980
|
+
else if (field2.type === "enum")
|
|
1981
|
+
clean = typeof value === "string" && field2.values.includes(value) ? value : "";
|
|
1982
|
+
else clean = sanitizeUrl(value, { schemes: field2.schemes, allowRelative: field2.relative });
|
|
1983
|
+
if (clean) out[key] = clean;
|
|
1984
|
+
else if (field2.required) return null;
|
|
1985
|
+
}
|
|
1986
|
+
return out;
|
|
1987
|
+
};
|
|
1988
|
+
const abbreviationAnnotation = defineInlineAnnotation({
|
|
1989
|
+
name: ABBREVIATION,
|
|
1990
|
+
label: "Abbreviation",
|
|
1991
|
+
description: "Short form with its full form (shown as a tooltip and read by screen readers).",
|
|
1992
|
+
attributes: { title: { type: "text", max: 200, required: true, label: "Full form" } },
|
|
1993
|
+
render: (annotation) => ({ tag: "abbr", attrs: { title: annotation.attrs.title } })
|
|
1994
|
+
});
|
|
1995
|
+
const registry = /* @__PURE__ */ new Map();
|
|
1996
|
+
const activeAnnotation = (name) => {
|
|
1997
|
+
if (name === ABBREVIATION) return abbreviationAnnotation;
|
|
1998
|
+
return typeof name === "string" && registry.has(name) ? registry.get(name) : null;
|
|
1999
|
+
};
|
|
2000
|
+
const activeAnnotations = () => [abbreviationAnnotation, ...registry.values()];
|
|
2001
|
+
const annotationsFromSummaries = (summaries) => {
|
|
2002
|
+
const out = [];
|
|
2003
|
+
for (const summary of Array.isArray(summaries) ? summaries.slice(0, ANNOTATION_LIMITS.registered) : []) {
|
|
2004
|
+
if (!isObject(summary) || summary.name === ABBREVIATION) continue;
|
|
2005
|
+
try {
|
|
2006
|
+
out.push(
|
|
2007
|
+
defineInlineAnnotation({
|
|
2008
|
+
name: summary.name,
|
|
2009
|
+
label: typeof summary.label === "string" ? summary.label.slice(0, 100) : void 0,
|
|
2010
|
+
attributes: summary.attributes,
|
|
2011
|
+
presets: Array.isArray(summary.presets) ? summary.presets : [],
|
|
2012
|
+
...typeof summary.shortcut === "string" ? { shortcut: summary.shortcut } : {}
|
|
2013
|
+
})
|
|
2014
|
+
);
|
|
2015
|
+
} catch {
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
return out;
|
|
2019
|
+
};
|
|
2020
|
+
const CLASS_TOKEN = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
2021
|
+
const RENDER_ATTRIBUTES = /* @__PURE__ */ new Set(["title", "class", "lang", "dir", "href", "datetime", "value", "cite"]);
|
|
2022
|
+
const cleanAnnotationWrapper = (out) => {
|
|
2023
|
+
if (!isObject(out) || !ANNOTATION_RENDER_TAGS.includes(out.tag)) return null;
|
|
2024
|
+
const attrs = {};
|
|
2025
|
+
for (const [name, raw] of Object.entries(isObject(out.attrs) ? out.attrs : {})) {
|
|
2026
|
+
if (raw === void 0 || raw === null || raw === false) continue;
|
|
2027
|
+
if (!["string", "number"].includes(typeof raw)) continue;
|
|
2028
|
+
const allowed = RENDER_ATTRIBUTES.has(name) || name === "aria-label" || name.startsWith("data-") && !name.startsWith("data-mex-");
|
|
2029
|
+
if (!allowed || !isSafeAttributeName(name)) continue;
|
|
2030
|
+
const text = String(raw).slice(0, 2e3);
|
|
2031
|
+
if (name === "href" || name === "cite") {
|
|
2032
|
+
if (out.tag !== "a" && name === "href") continue;
|
|
2033
|
+
const url = sanitizeUrl(text);
|
|
2034
|
+
if (url) attrs[name] = url;
|
|
2035
|
+
} else if (name === "class") {
|
|
2036
|
+
const classes = text.split(/\s+/).filter((token) => CLASS_TOKEN.test(token));
|
|
2037
|
+
if (classes.length) attrs.class = classes.join(" ");
|
|
2038
|
+
} else if (text) attrs[name] = text;
|
|
2039
|
+
}
|
|
2040
|
+
return { tag: out.tag, attrs };
|
|
2041
|
+
};
|
|
1674
2042
|
const DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
1675
2043
|
"script",
|
|
1676
2044
|
"style",
|
|
@@ -1791,6 +2159,20 @@ const cleanAttributes = (tag, attribs, options = {}) => {
|
|
|
1791
2159
|
const MAX_MARKER_TEXT = 16;
|
|
1792
2160
|
const isMathNode = (node) => node.type === "element" && node.tag === "span" && node.attrs[MATH_ATTRIBUTE] === "true";
|
|
1793
2161
|
const isFootnoteNode = (node) => node.type === "element" && node.tag === "sup" && typeof node.attrs["data-mex-footnote"] === "string";
|
|
2162
|
+
const isColorNode = (node) => node.type === "element" && node.tag === "span" && typeof node.attrs[COLOR_ATTRIBUTE] === "string";
|
|
2163
|
+
const isHighlightNode = (node) => node.type === "element" && node.tag === "mark" && typeof node.attrs[HIGHLIGHT_ATTRIBUTE] === "string";
|
|
2164
|
+
const isAnnotationNode = (node) => node.type === "element" && node.tag === "span" && typeof node.attrs[ANNOTATION_ATTRIBUTE] === "string";
|
|
2165
|
+
const annotationOf = (node) => {
|
|
2166
|
+
const attrs = {};
|
|
2167
|
+
for (const [name, value] of Object.entries(node.attrs))
|
|
2168
|
+
if (name.startsWith(ANNOTATION_VALUE_PREFIX)) attrs[name.slice(ANNOTATION_VALUE_PREFIX.length)] = value;
|
|
2169
|
+
return { name: node.attrs[ANNOTATION_ATTRIBUTE], attrs };
|
|
2170
|
+
};
|
|
2171
|
+
const annotationAttributes = (name, values) => {
|
|
2172
|
+
const out = { [ANNOTATION_ATTRIBUTE]: name };
|
|
2173
|
+
for (const key of Object.keys(values).sort()) out[`${ANNOTATION_VALUE_PREFIX}${key}`] = values[key];
|
|
2174
|
+
return out;
|
|
2175
|
+
};
|
|
1794
2176
|
const finalizeSpecial = (nodes, depth = 0) => {
|
|
1795
2177
|
for (const node of nodes) {
|
|
1796
2178
|
if (node.type !== "element") continue;
|
|
@@ -1809,6 +2191,25 @@ const specialElement = (tag, attribs, options) => {
|
|
|
1809
2191
|
if (!/^(?:|true)$/.test(attribs[MATH_ATTRIBUTE])) return null;
|
|
1810
2192
|
return { attrs: { [MATH_ATTRIBUTE]: "true" } };
|
|
1811
2193
|
}
|
|
2194
|
+
if (tag === "span" && Object.prototype.hasOwnProperty.call(attribs, ANNOTATION_ATTRIBUTE)) {
|
|
2195
|
+
const name = attribs[ANNOTATION_ATTRIBUTE];
|
|
2196
|
+
if (!ANNOTATION_NAME.test(name)) return null;
|
|
2197
|
+
const values = {};
|
|
2198
|
+
for (const [attribute, value] of Object.entries(attribs)) {
|
|
2199
|
+
if (!attribute.startsWith(ANNOTATION_VALUE_PREFIX)) continue;
|
|
2200
|
+
const key = attribute.slice(ANNOTATION_VALUE_PREFIX.length);
|
|
2201
|
+
if (!ANNOTATION_KEY.test(key) || Object.keys(values).length >= ANNOTATION_LIMITS.attributes) continue;
|
|
2202
|
+
const text = String(value).slice(0, ANNOTATION_LIMITS.text);
|
|
2203
|
+
if (text) values[key] = text;
|
|
2204
|
+
}
|
|
2205
|
+
return { attrs: annotationAttributes(name, values) };
|
|
2206
|
+
}
|
|
2207
|
+
if (tag === "span" && Object.prototype.hasOwnProperty.call(attribs, COLOR_ATTRIBUTE)) {
|
|
2208
|
+
return TOKEN_PATTERN.test(attribs[COLOR_ATTRIBUTE]) ? { attrs: { [COLOR_ATTRIBUTE]: attribs[COLOR_ATTRIBUTE] } } : null;
|
|
2209
|
+
}
|
|
2210
|
+
if (tag === "mark" && Object.prototype.hasOwnProperty.call(attribs, HIGHLIGHT_ATTRIBUTE)) {
|
|
2211
|
+
return TOKEN_PATTERN.test(attribs[HIGHLIGHT_ATTRIBUTE]) ? { attrs: { [HIGHLIGHT_ATTRIBUTE]: attribs[HIGHLIGHT_ATTRIBUTE] } } : null;
|
|
2212
|
+
}
|
|
1812
2213
|
if (tag === "sup" && !options.inNote) {
|
|
1813
2214
|
const id = attribs["data-mex-footnote"];
|
|
1814
2215
|
if (typeof id !== "string" || !FOOTNOTE_ID.test(id)) return null;
|
|
@@ -1992,6 +2393,24 @@ const inlineNodesToRender = (nodes, options = {}) => {
|
|
|
1992
2393
|
out.push({ type: "element", tag: "sup", attrs: attrs2, children: inlineNodesToRender(node.children, options) });
|
|
1993
2394
|
continue;
|
|
1994
2395
|
}
|
|
2396
|
+
if (isColorNode(node) || isHighlightNode(node)) {
|
|
2397
|
+
const color = node.tag === "span";
|
|
2398
|
+
const name = color ? COLOR_ATTRIBUTE : HIGHLIGHT_ATTRIBUTE;
|
|
2399
|
+
const token = node.attrs[name];
|
|
2400
|
+
out.push({
|
|
2401
|
+
type: "element",
|
|
2402
|
+
tag: node.tag,
|
|
2403
|
+
attrs: options.storage ? { [name]: token } : { class: color ? colorClass(token) : highlightClass(token), [name]: token },
|
|
2404
|
+
children: inlineNodesToRender(node.children, options)
|
|
2405
|
+
});
|
|
2406
|
+
continue;
|
|
2407
|
+
}
|
|
2408
|
+
if (isAnnotationNode(node)) {
|
|
2409
|
+
const children = inlineNodesToRender(node.children, options);
|
|
2410
|
+
if (options.storage) out.push({ type: "element", tag: "span", attrs: { ...node.attrs }, children });
|
|
2411
|
+
else out.push(...renderAnnotation(node, children, options));
|
|
2412
|
+
continue;
|
|
2413
|
+
}
|
|
1995
2414
|
let attrs = node.attrs;
|
|
1996
2415
|
if (node.tag === "a") {
|
|
1997
2416
|
attrs = resolveLinkAttributes(attrs, options.links);
|
|
@@ -2022,6 +2441,68 @@ const inlineNodesToRender = (nodes, options = {}) => {
|
|
|
2022
2441
|
}
|
|
2023
2442
|
return out;
|
|
2024
2443
|
};
|
|
2444
|
+
const annotationLists = /* @__PURE__ */ new WeakMap();
|
|
2445
|
+
const annotationDefinition = (name, options) => {
|
|
2446
|
+
const list = options.annotations;
|
|
2447
|
+
if (Array.isArray(list)) {
|
|
2448
|
+
if (!annotationLists.has(list)) {
|
|
2449
|
+
const map = /* @__PURE__ */ new Map();
|
|
2450
|
+
for (const item of list.slice(0, ANNOTATION_LIMITS.registered))
|
|
2451
|
+
if (item && typeof item === "object" && typeof item.name === "string" && item.attributes)
|
|
2452
|
+
map.set(item.name, item);
|
|
2453
|
+
annotationLists.set(list, map);
|
|
2454
|
+
}
|
|
2455
|
+
const found = annotationLists.get(list).get(name);
|
|
2456
|
+
if (found) return found;
|
|
2457
|
+
}
|
|
2458
|
+
return activeAnnotation(name);
|
|
2459
|
+
};
|
|
2460
|
+
const resolvedValue = (options, annotation) => {
|
|
2461
|
+
if (typeof options.resolveAnnotation !== "function") return void 0;
|
|
2462
|
+
let value;
|
|
2463
|
+
try {
|
|
2464
|
+
value = options.resolveAnnotation(annotation);
|
|
2465
|
+
} catch {
|
|
2466
|
+
return void 0;
|
|
2467
|
+
}
|
|
2468
|
+
if (typeof value === "string") return value.slice(0, 2e3);
|
|
2469
|
+
if (value && typeof value === "object" && !Array.isArray(value)) return value;
|
|
2470
|
+
return void 0;
|
|
2471
|
+
};
|
|
2472
|
+
const renderAnnotation = (node, children, options) => {
|
|
2473
|
+
const { name, attrs } = annotationOf(node);
|
|
2474
|
+
const definition = annotationDefinition(name, options);
|
|
2475
|
+
const values = definition ? cleanAnnotationAttributes(definition, attrs) : attrs;
|
|
2476
|
+
if (!values) return children;
|
|
2477
|
+
if (definition && typeof definition.render === "function") {
|
|
2478
|
+
const text = nodesToText(node.children);
|
|
2479
|
+
let out;
|
|
2480
|
+
try {
|
|
2481
|
+
out = definition.render({
|
|
2482
|
+
name,
|
|
2483
|
+
attrs: { ...values },
|
|
2484
|
+
text,
|
|
2485
|
+
resolved: resolvedValue(options, { name, attrs: { ...values }, text })
|
|
2486
|
+
});
|
|
2487
|
+
} catch {
|
|
2488
|
+
out = void 0;
|
|
2489
|
+
}
|
|
2490
|
+
if (out === false) return children;
|
|
2491
|
+
const wrapper = cleanAnnotationWrapper(out);
|
|
2492
|
+
if (wrapper) return [{ type: "element", tag: wrapper.tag, attrs: wrapper.attrs, children }];
|
|
2493
|
+
}
|
|
2494
|
+
return [
|
|
2495
|
+
{
|
|
2496
|
+
type: "element",
|
|
2497
|
+
tag: "span",
|
|
2498
|
+
attrs: {
|
|
2499
|
+
class: `mex-annotation mex-annotation-${name}`,
|
|
2500
|
+
...annotationAttributes(name, definition ? values : {})
|
|
2501
|
+
},
|
|
2502
|
+
children
|
|
2503
|
+
}
|
|
2504
|
+
];
|
|
2505
|
+
};
|
|
2025
2506
|
const inlineToNodes = (html, options) => inlineNodesToRender(parseInline(html), options);
|
|
2026
2507
|
const nodesToHtml = (nodes, options = {}) => serializeNodes(inlineNodesToRender(nodes, options));
|
|
2027
2508
|
const nodesToText = (nodes, options = {}) => nodes.map((node) => {
|
|
@@ -2054,22 +2535,53 @@ const mapFootnoteNotes = (html, fn) => {
|
|
|
2054
2535
|
visit(nodes);
|
|
2055
2536
|
return changed ? nodesToHtml(nodes, { storage: true }) : html;
|
|
2056
2537
|
};
|
|
2538
|
+
const SPECIAL_MARKERS = [
|
|
2539
|
+
MATH_ATTRIBUTE,
|
|
2540
|
+
"data-mex-footnote",
|
|
2541
|
+
COLOR_ATTRIBUTE,
|
|
2542
|
+
HIGHLIGHT_ATTRIBUTE,
|
|
2543
|
+
ANNOTATION_ATTRIBUTE
|
|
2544
|
+
];
|
|
2545
|
+
const isSpecialNode = (node) => isMathNode(node) || isFootnoteNode(node) || isColorNode(node) || isHighlightNode(node) || isAnnotationNode(node);
|
|
2057
2546
|
const canonicalInlineExtras = (html, options = {}) => {
|
|
2058
2547
|
if (typeof html !== "string") return "";
|
|
2059
|
-
const
|
|
2060
|
-
const
|
|
2061
|
-
|
|
2548
|
+
const plain2 = Array.isArray(options.plainTags) ? options.plainTags : [];
|
|
2549
|
+
const special = SPECIAL_MARKERS.some((marker) => html.includes(marker));
|
|
2550
|
+
const restricted = plain2.some((tag) => html.includes(`<${tag}`));
|
|
2551
|
+
if (!special && !restricted) return html;
|
|
2552
|
+
const colors = Array.isArray(options.colors) ? new Set(options.colors) : null;
|
|
2553
|
+
const highlights = Array.isArray(options.highlights) ? new Set(options.highlights) : null;
|
|
2554
|
+
let annotations = null;
|
|
2555
|
+
if (options.annotations instanceof Map) annotations = options.annotations;
|
|
2556
|
+
else if (Array.isArray(options.annotations))
|
|
2557
|
+
annotations = new Map(options.annotations.filter(Boolean).map((item) => [item.name, item]));
|
|
2062
2558
|
const nodes = parseInline(html);
|
|
2063
|
-
|
|
2064
|
-
const
|
|
2065
|
-
|
|
2066
|
-
if (
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2559
|
+
const filter = (list, depth = 0) => {
|
|
2560
|
+
const out = [];
|
|
2561
|
+
for (const node of list) {
|
|
2562
|
+
if (node.type !== "element") {
|
|
2563
|
+
out.push(node);
|
|
2564
|
+
continue;
|
|
2565
|
+
}
|
|
2566
|
+
if (options.footnotes === false && isFootnoteNode(node)) continue;
|
|
2567
|
+
if (depth < MAX_DEPTH) node.children = filter(node.children, depth + 1);
|
|
2568
|
+
if (node.note) node.note = filter(node.note, depth + 1);
|
|
2569
|
+
let keep = true;
|
|
2570
|
+
if (isColorNode(node)) keep = !colors || colors.has(node.attrs[COLOR_ATTRIBUTE]);
|
|
2571
|
+
else if (isHighlightNode(node)) keep = !highlights || highlights.has(node.attrs[HIGHLIGHT_ATTRIBUTE]);
|
|
2572
|
+
else if (isAnnotationNode(node) && annotations) {
|
|
2573
|
+
const { name, attrs } = annotationOf(node);
|
|
2574
|
+
const definition = annotations.get(name);
|
|
2575
|
+
const values = definition ? cleanAnnotationAttributes(definition, attrs) : null;
|
|
2576
|
+
if (values) node.attrs = annotationAttributes(name, values);
|
|
2577
|
+
else keep = false;
|
|
2578
|
+
} else if (!isSpecialNode(node) && plain2.includes(node.tag)) keep = false;
|
|
2579
|
+
if (keep) out.push(node);
|
|
2580
|
+
else out.push(...node.children);
|
|
2581
|
+
}
|
|
2582
|
+
return out;
|
|
2583
|
+
};
|
|
2584
|
+
return nodesToHtml(filter(nodes), { storage: true });
|
|
2073
2585
|
};
|
|
2074
2586
|
const walkInlineElements = (nodes, fn, inNote = false, depth = 0) => {
|
|
2075
2587
|
if (depth > MAX_DEPTH) return;
|
|
@@ -2086,6 +2598,10 @@ const instance = () => {
|
|
|
2086
2598
|
purify = createDOMPurify(window);
|
|
2087
2599
|
purify.addHook("uponSanitizeAttribute", (node, data) => {
|
|
2088
2600
|
const tag = node.nodeName.toLowerCase();
|
|
2601
|
+
if (tag === "span" && ANNOTATION_VALUE_ATTRIBUTE.test(data.attrName) && typeof node.hasAttribute === "function" && node.hasAttribute(ANNOTATION_ATTRIBUTE)) {
|
|
2602
|
+
data.forceKeepAttr = true;
|
|
2603
|
+
return;
|
|
2604
|
+
}
|
|
2089
2605
|
if (data.attrName === "class") {
|
|
2090
2606
|
const allowed = INLINE_CLASSES[tag] || [];
|
|
2091
2607
|
const kept = String(data.attrValue).split(/\s+/).filter((name) => allowed.includes(name));
|
|
@@ -2115,7 +2631,10 @@ const instance = () => {
|
|
|
2115
2631
|
});
|
|
2116
2632
|
return purify;
|
|
2117
2633
|
};
|
|
2118
|
-
const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat()))
|
|
2634
|
+
const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat())).filter(
|
|
2635
|
+
(name) => !name.endsWith("*")
|
|
2636
|
+
);
|
|
2637
|
+
const ANNOTATION_VALUE_ATTRIBUTE = /^data-mex-a-[a-z][a-z0-9]{0,23}$/;
|
|
2119
2638
|
const sanitizeInline = (html) => canonicalInlineExtras(
|
|
2120
2639
|
instance().sanitize(String(html || ""), {
|
|
2121
2640
|
ALLOWED_TAGS: [...INLINE_TAGS],
|
|
@@ -2127,7 +2646,15 @@ const sanitizeInline = (html) => canonicalInlineExtras(
|
|
|
2127
2646
|
// validated by cleanInternalLinkAttributes in the hook above, and math and
|
|
2128
2647
|
// footnote attributes (2.4: a note is inline HTML, "See: …" looks like a
|
|
2129
2648
|
// scheme too) by `canonicalInlineExtras` below.
|
|
2130
|
-
ADD_URI_SAFE_ATTR: [
|
|
2649
|
+
ADD_URI_SAFE_ATTR: [
|
|
2650
|
+
...INTERNAL_LINK_ATTRIBUTES,
|
|
2651
|
+
MATH_ATTRIBUTE,
|
|
2652
|
+
...FOOTNOTE_ATTRIBUTES,
|
|
2653
|
+
// 2.5: tokens and the annotation name (validated by `canonicalInlineExtras`).
|
|
2654
|
+
COLOR_ATTRIBUTE,
|
|
2655
|
+
HIGHLIGHT_ATTRIBUTE,
|
|
2656
|
+
ANNOTATION_ATTRIBUTE
|
|
2657
|
+
]
|
|
2131
2658
|
})
|
|
2132
2659
|
);
|
|
2133
2660
|
const sanitizeTemplate = (html) => instance().sanitize(String(html || ""), {
|
|
@@ -2322,11 +2849,13 @@ const ICONS = {
|
|
|
2322
2849
|
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
2850
|
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
2851
|
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>'
|
|
2852
|
+
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>',
|
|
2853
|
+
// 2.5: "Copy block" in the block menu.
|
|
2854
|
+
copy: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="8" y="8" width="12" height="12" rx="2" stroke="currentColor" stroke-width="2"/><path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>'
|
|
2326
2855
|
};
|
|
2327
2856
|
const tools = /* @__PURE__ */ new Map();
|
|
2328
2857
|
const registerBlock = (options) => {
|
|
2329
|
-
if (!isObject(options))
|
|
2858
|
+
if (!isObject$1(options))
|
|
2330
2859
|
throw new BlockDefinitionError("Magic Editor X registerBlock: pass { definition, tool }");
|
|
2331
2860
|
const { definition, tool, title, icon, i18n, inlineToolbar, shortcut } = options;
|
|
2332
2861
|
if (typeof tool !== "function")
|
|
@@ -2344,7 +2873,7 @@ const registerBlock = (options) => {
|
|
|
2344
2873
|
tool,
|
|
2345
2874
|
title: title === void 0 ? compiled2.title || compiled2.name : title,
|
|
2346
2875
|
icon: typeof icon === "string" ? sanitizeSvg(icon) : "",
|
|
2347
|
-
i18n: isObject(i18n) ? i18n : {},
|
|
2876
|
+
i18n: isObject$1(i18n) ? i18n : {},
|
|
2348
2877
|
inlineToolbar: inlineToolbar === true,
|
|
2349
2878
|
shortcut
|
|
2350
2879
|
});
|
|
@@ -2355,7 +2884,7 @@ const buildCodeBlockTools = (ctx) => {
|
|
|
2355
2884
|
const out = {};
|
|
2356
2885
|
for (const entry of tools.values()) {
|
|
2357
2886
|
const { definition, tool: Tool } = entry;
|
|
2358
|
-
const messages = isObject(entry.i18n[ctx.locale]) ? entry.i18n[ctx.locale] : isObject(entry.i18n[String(ctx.locale || "").split("-")[0]]) ? entry.i18n[String(ctx.locale).split("-")[0]] : isObject(entry.i18n.en) ? entry.i18n.en : {};
|
|
2887
|
+
const messages = isObject$1(entry.i18n[ctx.locale]) ? entry.i18n[ctx.locale] : isObject$1(entry.i18n[String(ctx.locale || "").split("-")[0]]) ? entry.i18n[String(ctx.locale).split("-")[0]] : isObject$1(entry.i18n.en) ? entry.i18n.en : {};
|
|
2359
2888
|
const rules = sanitizeRulesFor(definition.schema);
|
|
2360
2889
|
const toolbox = {
|
|
2361
2890
|
title: localized(entry.title, ctx.locale) || definition.name,
|
|
@@ -2452,36 +2981,244 @@ const createReactTool = (Component, options = {}) => {
|
|
|
2452
2981
|
}
|
|
2453
2982
|
};
|
|
2454
2983
|
};
|
|
2984
|
+
const DRAFT_RECORD_VERSION = 1;
|
|
2985
|
+
const DEFAULT_DRAFT_TTL_HOURS = 72;
|
|
2986
|
+
const DRAFT_WRITE_DELAY_MS = 800;
|
|
2987
|
+
const MAX_DRAFT_CHARS = 6 * 1024 * 1024;
|
|
2988
|
+
const VOLUNTARY_LOGOUT_WINDOW_MS = 60 * 1e3;
|
|
2989
|
+
const MAX_PART = 512;
|
|
2990
|
+
const draftIdentity = (target) => {
|
|
2991
|
+
if (!target || target.owner === void 0 || target.owner === null || target.owner === "") return null;
|
|
2992
|
+
const { uid, field: field2 } = target;
|
|
2993
|
+
if (typeof uid !== "string" || !uid || typeof field2 !== "string" || !field2) return null;
|
|
2994
|
+
const identity = isPositionalFieldPath(field2) && isValidFieldKey(target.fieldKey) ? `${basePathOf(field2)}#${target.fieldKey}` : field2;
|
|
2995
|
+
const parts = [
|
|
2996
|
+
String(target.owner),
|
|
2997
|
+
uid,
|
|
2998
|
+
typeof target.documentId === "string" && target.documentId ? target.documentId : "new",
|
|
2999
|
+
typeof target.locale === "string" && target.locale ? target.locale : "-",
|
|
3000
|
+
identity
|
|
3001
|
+
];
|
|
3002
|
+
if (parts.some((part) => part.length > MAX_PART)) return null;
|
|
3003
|
+
return parts.join("|");
|
|
3004
|
+
};
|
|
3005
|
+
const hashText = (text) => {
|
|
3006
|
+
let h1 = 2166136261;
|
|
3007
|
+
let h2 = 16777619;
|
|
3008
|
+
const value = String(text);
|
|
3009
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
3010
|
+
const code = value.charCodeAt(i);
|
|
3011
|
+
h1 = Math.imul(h1 ^ code, 16777619) >>> 0;
|
|
3012
|
+
h2 = Math.imul(h2 ^ code, 2246822519) >>> 0;
|
|
3013
|
+
}
|
|
3014
|
+
return `${h2.toString(16).padStart(8, "0")}${h1.toString(16).padStart(8, "0")}`;
|
|
3015
|
+
};
|
|
3016
|
+
const isValidDraftRecord = (record) => Boolean(
|
|
3017
|
+
record && typeof record === "object" && record.v === DRAFT_RECORD_VERSION && typeof record.id === "string" && typeof record.baseHash === "string" && Number.isFinite(record.savedAt) && Number.isFinite(record.expiresAt) && record.data && typeof record.data === "object" && Array.isArray(record.data.blocks)
|
|
3018
|
+
);
|
|
3019
|
+
const isExpired = (record, now) => !record || !(record.expiresAt > now);
|
|
3020
|
+
const ttlMsOf = (hours) => {
|
|
3021
|
+
const number = Number(hours);
|
|
3022
|
+
const safe = Number.isFinite(number) && number >= 1 && number <= 720 ? number : DEFAULT_DRAFT_TTL_HOURS;
|
|
3023
|
+
return Math.round(safe * 3600 * 1e3);
|
|
3024
|
+
};
|
|
3025
|
+
const buildDraftRecord = ({ id, data, baseKey, now, ttlMs }) => {
|
|
3026
|
+
if (!id || !data || !Array.isArray(data.blocks)) return null;
|
|
3027
|
+
const copy2 = { ...data };
|
|
3028
|
+
delete copy2.fieldKey;
|
|
3029
|
+
let json;
|
|
3030
|
+
try {
|
|
3031
|
+
json = JSON.stringify(copy2);
|
|
3032
|
+
} catch {
|
|
3033
|
+
return null;
|
|
3034
|
+
}
|
|
3035
|
+
if (json.length > MAX_DRAFT_CHARS) return null;
|
|
3036
|
+
return {
|
|
3037
|
+
v: DRAFT_RECORD_VERSION,
|
|
3038
|
+
id,
|
|
3039
|
+
baseHash: hashText(baseKey),
|
|
3040
|
+
savedAt: now,
|
|
3041
|
+
expiresAt: now + ttlMs,
|
|
3042
|
+
data: JSON.parse(json)
|
|
3043
|
+
};
|
|
3044
|
+
};
|
|
3045
|
+
const restoreDecision = ({ record, now, readOnly = false, recordKey, shownKey, savedKey }) => {
|
|
3046
|
+
if (!record) return { action: "none" };
|
|
3047
|
+
if (!isValidDraftRecord(record) || isExpired(record, now)) return { action: "delete" };
|
|
3048
|
+
if (readOnly) return { action: "none" };
|
|
3049
|
+
if (recordKey === shownKey || recordKey === savedKey) return { action: "delete" };
|
|
3050
|
+
return { action: "offer", conflict: record.baseHash !== hashText(savedKey) };
|
|
3051
|
+
};
|
|
3052
|
+
const bufferAction = ({ dirty, collaboration }) => {
|
|
3053
|
+
const synced = collaboration && collaboration.active && collaboration.status === "live" && !collaboration.pending;
|
|
3054
|
+
return dirty && !synced ? "write" : "delete";
|
|
3055
|
+
};
|
|
3056
|
+
const relativeTimeOf = (then, now) => {
|
|
3057
|
+
const seconds = Math.max(0, Math.round((now - then) / 1e3));
|
|
3058
|
+
if (seconds < 60) return { value: -seconds, unit: "second" };
|
|
3059
|
+
const minutes = Math.round(seconds / 60);
|
|
3060
|
+
if (minutes < 60) return { value: -minutes, unit: "minute" };
|
|
3061
|
+
const hours = Math.round(minutes / 60);
|
|
3062
|
+
if (hours < 24) return { value: -hours, unit: "hour" };
|
|
3063
|
+
return { value: -Math.round(hours / 24), unit: "day" };
|
|
3064
|
+
};
|
|
3065
|
+
const createLogoutMiddleware = ({ onLogout, now = () => Date.now() }) => {
|
|
3066
|
+
let voluntaryAt = -Infinity;
|
|
3067
|
+
return () => () => (next) => (action2) => {
|
|
3068
|
+
if (action2 && typeof action2 === "object") {
|
|
3069
|
+
if (isLogoutMutationStart(action2)) voluntaryAt = now();
|
|
3070
|
+
else if (action2.type === "admin/logout" && now() - voluntaryAt <= VOLUNTARY_LOGOUT_WINDOW_MS) {
|
|
3071
|
+
voluntaryAt = -Infinity;
|
|
3072
|
+
try {
|
|
3073
|
+
onLogout();
|
|
3074
|
+
} catch {
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
return next(action2);
|
|
3079
|
+
};
|
|
3080
|
+
};
|
|
3081
|
+
const isLogoutMutationStart = (action2) => Boolean(
|
|
3082
|
+
action2 && action2.type === "adminApi/executeMutation/pending" && action2.meta && action2.meta.arg && action2.meta.arg.endpointName === "logout"
|
|
3083
|
+
);
|
|
3084
|
+
const valueAtPath = (values, path) => {
|
|
3085
|
+
let current = values;
|
|
3086
|
+
for (const part of String(path || "").split(".").filter(Boolean).slice(0, 24)) {
|
|
3087
|
+
if (!current || typeof current !== "object") return void 0;
|
|
3088
|
+
current = current[part];
|
|
3089
|
+
}
|
|
3090
|
+
return current;
|
|
3091
|
+
};
|
|
3092
|
+
const savedValueOf = (initialValues, path, fieldKey = null) => {
|
|
3093
|
+
if (isPositionalFieldPath(path) && isValidFieldKey(fieldKey)) {
|
|
3094
|
+
const parts = basePathOf(path).split(".").filter(Boolean);
|
|
3095
|
+
let found = null;
|
|
3096
|
+
const walk = (data, index2, depth) => {
|
|
3097
|
+
if (found || !data || typeof data !== "object" || depth > 16) return;
|
|
3098
|
+
if (Array.isArray(data)) {
|
|
3099
|
+
data.forEach((item) => walk(item, index2, depth + 1));
|
|
3100
|
+
return;
|
|
3101
|
+
}
|
|
3102
|
+
if (index2 === parts.length) {
|
|
3103
|
+
if (data.fieldKey === fieldKey) found = data;
|
|
3104
|
+
return;
|
|
3105
|
+
}
|
|
3106
|
+
walk(data[parts[index2]], index2 + 1, depth + 1);
|
|
3107
|
+
};
|
|
3108
|
+
walk(initialValues, 0, 0);
|
|
3109
|
+
if (found) return found;
|
|
3110
|
+
}
|
|
3111
|
+
const value = valueAtPath(initialValues, path);
|
|
3112
|
+
return value === void 0 ? null : value;
|
|
3113
|
+
};
|
|
3114
|
+
let loggedOut = false;
|
|
3115
|
+
const isLoggedOut = () => loggedOut;
|
|
3116
|
+
const trackSessionAction = (action2) => {
|
|
3117
|
+
if (!action2 || typeof action2 !== "object") return;
|
|
3118
|
+
if (action2.type === "admin/logout") loggedOut = true;
|
|
3119
|
+
else if (action2.type === "admin/login" || action2.type === "admin/setToken") loggedOut = false;
|
|
3120
|
+
};
|
|
3121
|
+
const createSessionMiddleware = () => () => (next) => (action2) => {
|
|
3122
|
+
trackSessionAction(action2);
|
|
3123
|
+
return next(action2);
|
|
3124
|
+
};
|
|
3125
|
+
const DB_NAME = "magic-editor-x";
|
|
3126
|
+
const STORE = "drafts";
|
|
3127
|
+
let dbPromise = null;
|
|
3128
|
+
const openDb = () => {
|
|
3129
|
+
if (dbPromise) return dbPromise;
|
|
3130
|
+
dbPromise = new Promise((resolve) => {
|
|
3131
|
+
let request;
|
|
3132
|
+
try {
|
|
3133
|
+
if (typeof indexedDB === "undefined") {
|
|
3134
|
+
resolve(null);
|
|
3135
|
+
return;
|
|
3136
|
+
}
|
|
3137
|
+
request = indexedDB.open(DB_NAME, 1);
|
|
3138
|
+
} catch {
|
|
3139
|
+
resolve(null);
|
|
3140
|
+
return;
|
|
3141
|
+
}
|
|
3142
|
+
request.onupgradeneeded = () => {
|
|
3143
|
+
const db = request.result;
|
|
3144
|
+
if (!db.objectStoreNames.contains(STORE)) db.createObjectStore(STORE, { keyPath: "id" });
|
|
3145
|
+
};
|
|
3146
|
+
request.onsuccess = () => {
|
|
3147
|
+
const db = request.result;
|
|
3148
|
+
db.onversionchange = () => {
|
|
3149
|
+
db.close();
|
|
3150
|
+
dbPromise = null;
|
|
3151
|
+
};
|
|
3152
|
+
resolve(db);
|
|
3153
|
+
};
|
|
3154
|
+
request.onerror = () => resolve(null);
|
|
3155
|
+
request.onblocked = () => resolve(null);
|
|
3156
|
+
});
|
|
3157
|
+
return dbPromise;
|
|
3158
|
+
};
|
|
3159
|
+
const withStore = async (mode, run) => {
|
|
3160
|
+
const db = await openDb();
|
|
3161
|
+
if (!db) return null;
|
|
3162
|
+
return new Promise((resolve) => {
|
|
3163
|
+
try {
|
|
3164
|
+
const transaction = db.transaction(STORE, mode);
|
|
3165
|
+
const request = run(transaction.objectStore(STORE));
|
|
3166
|
+
transaction.oncomplete = () => resolve(request ? request.result : true);
|
|
3167
|
+
transaction.onerror = () => resolve(null);
|
|
3168
|
+
transaction.onabort = () => resolve(null);
|
|
3169
|
+
} catch {
|
|
3170
|
+
resolve(null);
|
|
3171
|
+
}
|
|
3172
|
+
});
|
|
3173
|
+
};
|
|
3174
|
+
const getDraft = async (id) => id ? await withStore("readonly", (s) => s.get(id)) || null : null;
|
|
3175
|
+
const putDraft = async (record) => Boolean(record && record.id && await withStore("readwrite", (s) => s.put(record)) !== null);
|
|
3176
|
+
const deleteDraft = async (id) => Boolean(id && await withStore("readwrite", (s) => s.delete(id)) !== null);
|
|
3177
|
+
const clearDrafts = async () => await withStore("readwrite", (s) => s.clear()) !== null;
|
|
3178
|
+
let pruned = false;
|
|
3179
|
+
const pruneDrafts = async (now) => {
|
|
3180
|
+
if (pruned) return;
|
|
3181
|
+
pruned = true;
|
|
3182
|
+
await withStore("readwrite", (store) => {
|
|
3183
|
+
const cursorRequest = store.openCursor();
|
|
3184
|
+
cursorRequest.onsuccess = () => {
|
|
3185
|
+
const cursor = cursorRequest.result;
|
|
3186
|
+
if (!cursor) return;
|
|
3187
|
+
if (isExpired(cursor.value, now)) cursor.delete();
|
|
3188
|
+
cursor.continue();
|
|
3189
|
+
};
|
|
3190
|
+
});
|
|
3191
|
+
};
|
|
2455
3192
|
const LOADERS = {
|
|
2456
3193
|
en: () => [
|
|
2457
|
-
import("./en-
|
|
2458
|
-
import("./en-
|
|
2459
|
-
import("./en-
|
|
2460
|
-
import("./en-
|
|
3194
|
+
import("./en-Dr58wBAo.mjs"),
|
|
3195
|
+
import("./en-BCKaVgBM.mjs"),
|
|
3196
|
+
import("./en-Uhm7OouM.mjs"),
|
|
3197
|
+
import("./en-Cd6Jk-J0.mjs")
|
|
2461
3198
|
],
|
|
2462
3199
|
de: () => [
|
|
2463
|
-
import("./de-
|
|
2464
|
-
import("./de-
|
|
2465
|
-
import("./de-
|
|
2466
|
-
import("./de-
|
|
3200
|
+
import("./de-BWfR2jTg.mjs"),
|
|
3201
|
+
import("./de-CQA8hOpl.mjs"),
|
|
3202
|
+
import("./de-zgHCYTLH.mjs"),
|
|
3203
|
+
import("./de-Bip0sBRT.mjs")
|
|
2467
3204
|
],
|
|
2468
3205
|
fr: () => [
|
|
2469
|
-
import("./fr-
|
|
2470
|
-
import("./fr-
|
|
2471
|
-
import("./fr-
|
|
2472
|
-
import("./fr-
|
|
3206
|
+
import("./fr-BvPjRiwr.mjs"),
|
|
3207
|
+
import("./fr-D4tL6Ag2.mjs"),
|
|
3208
|
+
import("./fr-CrIHmKYX.mjs"),
|
|
3209
|
+
import("./fr-CKHZ0xxU.mjs")
|
|
2473
3210
|
],
|
|
2474
3211
|
es: () => [
|
|
2475
|
-
import("./es-
|
|
2476
|
-
import("./es-
|
|
2477
|
-
import("./es-
|
|
2478
|
-
import("./es-
|
|
3212
|
+
import("./es-B2Hkkbw9.mjs"),
|
|
3213
|
+
import("./es-pvPfNAld.mjs"),
|
|
3214
|
+
import("./es-BMkmfH88.mjs"),
|
|
3215
|
+
import("./es-Bz8d72Fa.mjs")
|
|
2479
3216
|
],
|
|
2480
3217
|
pt: () => [
|
|
2481
|
-
import("./pt-
|
|
2482
|
-
import("./pt-
|
|
2483
|
-
import("./pt-
|
|
2484
|
-
import("./pt-
|
|
3218
|
+
import("./pt-DdGagO99.mjs"),
|
|
3219
|
+
import("./pt-CuoIihKx.mjs"),
|
|
3220
|
+
import("./pt-DDlPJYtB.mjs"),
|
|
3221
|
+
import("./pt-B8x7v-Xw.mjs")
|
|
2485
3222
|
]
|
|
2486
3223
|
};
|
|
2487
3224
|
const PRESET_OPTIONS = [
|
|
@@ -2519,7 +3256,7 @@ const index = {
|
|
|
2519
3256
|
icon: Bell,
|
|
2520
3257
|
title: { id: getTranslation("widget.mentions.title"), defaultMessage: "Mentions and replies" },
|
|
2521
3258
|
component: async () => {
|
|
2522
|
-
const { MentionsWidget } = await import("./MentionsWidget-
|
|
3259
|
+
const { MentionsWidget } = await import("./MentionsWidget-CJPZDk9Z.mjs");
|
|
2523
3260
|
return MentionsWidget;
|
|
2524
3261
|
},
|
|
2525
3262
|
permissions: [
|
|
@@ -2528,6 +3265,35 @@ const index = {
|
|
|
2528
3265
|
]
|
|
2529
3266
|
});
|
|
2530
3267
|
}
|
|
3268
|
+
if (app.widgets && typeof app.widgets.register === "function") {
|
|
3269
|
+
app.widgets.register([
|
|
3270
|
+
{
|
|
3271
|
+
id: "open-threads",
|
|
3272
|
+
pluginId: PLUGIN_ID,
|
|
3273
|
+
icon: Discuss,
|
|
3274
|
+
title: { id: getTranslation("widget.openThreads.title"), defaultMessage: "My open threads" },
|
|
3275
|
+
component: async () => {
|
|
3276
|
+
const { OpenThreadsWidget } = await import("./EntryWidgets-B8YA0Zxy.mjs");
|
|
3277
|
+
return OpenThreadsWidget;
|
|
3278
|
+
},
|
|
3279
|
+
permissions: [
|
|
3280
|
+
{ action: "plugin::magic-editor-x.access" },
|
|
3281
|
+
{ action: "plugin::magic-editor-x.comments.read" }
|
|
3282
|
+
]
|
|
3283
|
+
},
|
|
3284
|
+
{
|
|
3285
|
+
id: "broken-links",
|
|
3286
|
+
pluginId: PLUGIN_ID,
|
|
3287
|
+
icon: Link,
|
|
3288
|
+
title: { id: getTranslation("widget.brokenLinks.title"), defaultMessage: "Broken links" },
|
|
3289
|
+
component: async () => {
|
|
3290
|
+
const { BrokenLinksWidget } = await import("./EntryWidgets-B8YA0Zxy.mjs");
|
|
3291
|
+
return BrokenLinksWidget;
|
|
3292
|
+
},
|
|
3293
|
+
permissions: [{ action: "plugin::magic-editor-x.access" }]
|
|
3294
|
+
}
|
|
3295
|
+
]);
|
|
3296
|
+
}
|
|
2531
3297
|
app.customFields.register({
|
|
2532
3298
|
name: "richtext",
|
|
2533
3299
|
pluginId: PLUGIN_ID,
|
|
@@ -2539,7 +3305,7 @@ const index = {
|
|
|
2539
3305
|
},
|
|
2540
3306
|
icon: PluginIcon,
|
|
2541
3307
|
components: {
|
|
2542
|
-
Input: () => import("./index-
|
|
3308
|
+
Input: () => import("./index-C4ksUkEm.mjs").then((n) => n.a)
|
|
2543
3309
|
},
|
|
2544
3310
|
options: {
|
|
2545
3311
|
base: [
|
|
@@ -2661,6 +3427,51 @@ const index = {
|
|
|
2661
3427
|
}
|
|
2662
3428
|
]
|
|
2663
3429
|
},
|
|
3430
|
+
// 2.5: extra inline formatting, off unless turned on here.
|
|
3431
|
+
{
|
|
3432
|
+
sectionTitle: {
|
|
3433
|
+
id: getTranslation("field.options.formatting"),
|
|
3434
|
+
defaultMessage: "Extra formatting"
|
|
3435
|
+
},
|
|
3436
|
+
items: [
|
|
3437
|
+
{
|
|
3438
|
+
intlLabel: {
|
|
3439
|
+
id: getTranslation("field.options.inlineColors.label"),
|
|
3440
|
+
defaultMessage: "Text colour and highlight"
|
|
3441
|
+
},
|
|
3442
|
+
description: {
|
|
3443
|
+
id: getTranslation("field.options.inlineColors.description"),
|
|
3444
|
+
defaultMessage: "Editors pick from the colours your developer set in the plugin configuration (palette). Without a palette nothing is shown."
|
|
3445
|
+
},
|
|
3446
|
+
name: "options.inlineColors",
|
|
3447
|
+
type: "checkbox"
|
|
3448
|
+
},
|
|
3449
|
+
{
|
|
3450
|
+
intlLabel: {
|
|
3451
|
+
id: getTranslation("field.options.inlineScript.label"),
|
|
3452
|
+
defaultMessage: "Superscript and subscript"
|
|
3453
|
+
},
|
|
3454
|
+
description: {
|
|
3455
|
+
id: getTranslation("field.options.inlineScript.description"),
|
|
3456
|
+
defaultMessage: "For formulas and units such as m² or H₂O"
|
|
3457
|
+
},
|
|
3458
|
+
name: "options.inlineScript",
|
|
3459
|
+
type: "checkbox"
|
|
3460
|
+
},
|
|
3461
|
+
{
|
|
3462
|
+
intlLabel: {
|
|
3463
|
+
id: getTranslation("field.options.inlineAnnotations.label"),
|
|
3464
|
+
defaultMessage: "Annotations"
|
|
3465
|
+
},
|
|
3466
|
+
description: {
|
|
3467
|
+
id: getTranslation("field.options.inlineAnnotations.description"),
|
|
3468
|
+
defaultMessage: "Comma-separated annotation names, for example: abbreviation. Your developer can add more, such as glossary."
|
|
3469
|
+
},
|
|
3470
|
+
name: "options.inlineAnnotations",
|
|
3471
|
+
type: "text"
|
|
3472
|
+
}
|
|
3473
|
+
]
|
|
3474
|
+
},
|
|
2664
3475
|
{
|
|
2665
3476
|
sectionTitle: { id: getTranslation("field.options.features"), defaultMessage: "Features" },
|
|
2666
3477
|
items: [
|
|
@@ -2737,33 +3548,46 @@ const index = {
|
|
|
2737
3548
|
intlLabel: { id: getTranslation("settings.link.configuration"), defaultMessage: "Configuration" },
|
|
2738
3549
|
to: `${PLUGIN_ID}/configuration`,
|
|
2739
3550
|
permissions: PERMISSIONS.settingsRead,
|
|
2740
|
-
Component: () => import("./ConfigurationPage-
|
|
3551
|
+
Component: () => import("./ConfigurationPage-C9CPBfWy.mjs")
|
|
2741
3552
|
},
|
|
2742
3553
|
{
|
|
2743
3554
|
id: `${PLUGIN_ID}-custom-blocks`,
|
|
2744
3555
|
intlLabel: { id: getTranslation("settings.link.customBlocks"), defaultMessage: "Custom blocks" },
|
|
2745
3556
|
to: `${PLUGIN_ID}/custom-blocks`,
|
|
2746
3557
|
permissions: PERMISSIONS.customBlocksManage,
|
|
2747
|
-
Component: () => import("./CustomBlocksPage-
|
|
3558
|
+
Component: () => import("./CustomBlocksPage-DB5nnCsn.mjs")
|
|
2748
3559
|
},
|
|
2749
3560
|
{
|
|
2750
3561
|
id: `${PLUGIN_ID}-templates`,
|
|
2751
3562
|
intlLabel: { id: getTranslation("settings.link.templates"), defaultMessage: "Templates" },
|
|
2752
3563
|
to: `${PLUGIN_ID}/templates`,
|
|
2753
3564
|
permissions: PERMISSIONS.templatesManage,
|
|
2754
|
-
Component: () => import("./TemplatesPage-
|
|
3565
|
+
Component: () => import("./TemplatesPage-VsZ_Mc0R.mjs")
|
|
2755
3566
|
},
|
|
2756
3567
|
{
|
|
2757
3568
|
id: `${PLUGIN_ID}-audit`,
|
|
2758
3569
|
intlLabel: { id: getTranslation("settings.link.audit"), defaultMessage: "Audit trail" },
|
|
2759
3570
|
to: `${PLUGIN_ID}/audit`,
|
|
2760
3571
|
permissions: PERMISSIONS.auditRead,
|
|
2761
|
-
Component: () => import("./AuditPage-
|
|
3572
|
+
Component: () => import("./AuditPage-Be78C7EC.mjs")
|
|
2762
3573
|
}
|
|
2763
3574
|
]
|
|
2764
3575
|
);
|
|
3576
|
+
if (typeof app.addMiddlewares === "function")
|
|
3577
|
+
app.addMiddlewares([
|
|
3578
|
+
createLogoutMiddleware({ onLogout: () => clearDrafts() }),
|
|
3579
|
+
createSessionMiddleware
|
|
3580
|
+
]);
|
|
2765
3581
|
},
|
|
2766
|
-
|
|
3582
|
+
/**
|
|
3583
|
+
* 2.5: the one Magic Editor X side panel of the Content Manager edit view (presence, comments,
|
|
3584
|
+
* quality). Other features add a section to `components/EntryPanel/sections.jsx`, never a panel.
|
|
3585
|
+
* @param {object} app - Strapi admin app.
|
|
3586
|
+
*/
|
|
3587
|
+
bootstrap(app) {
|
|
3588
|
+
const contentManager = app.getPlugin && app.getPlugin("content-manager");
|
|
3589
|
+
const apis = contentManager && contentManager.apis;
|
|
3590
|
+
if (apis && typeof apis.addEditViewSidePanel === "function") apis.addEditViewSidePanel([EntryPanel]);
|
|
2767
3591
|
},
|
|
2768
3592
|
/**
|
|
2769
3593
|
* @param {{ locales: string[] }} options - Admin locales.
|
|
@@ -2782,108 +3606,147 @@ const index = {
|
|
|
2782
3606
|
}
|
|
2783
3607
|
};
|
|
2784
3608
|
export {
|
|
2785
|
-
|
|
2786
|
-
|
|
3609
|
+
mergeRect as $,
|
|
3610
|
+
ANNOTATION_KEY as A,
|
|
2787
3611
|
BLOCK_POLICIES as B,
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
3612
|
+
COLOR_ATTRIBUTE as C,
|
|
3613
|
+
FOOTNOTE_ID as D,
|
|
3614
|
+
canonicalInlineExtras as E,
|
|
2791
3615
|
FOOTNOTE_ATTRIBUTES as F,
|
|
2792
|
-
|
|
2793
|
-
|
|
3616
|
+
TABLE_LIMITS as G,
|
|
3617
|
+
HIGHLIGHT_ATTRIBUTE as H,
|
|
2794
3618
|
INTERNAL_LINK_ATTRIBUTES as I,
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
3619
|
+
cleanTableAlign as J,
|
|
3620
|
+
normalizeMerges as K,
|
|
3621
|
+
TABLE_ALIGNS as L,
|
|
2798
3622
|
MATH_ATTRIBUTE as M,
|
|
2799
|
-
|
|
2800
|
-
|
|
3623
|
+
toTableModel as N,
|
|
3624
|
+
isBlankInlineHtml as O,
|
|
2801
3625
|
PERMISSIONS as P,
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
3626
|
+
mergeMap as Q,
|
|
3627
|
+
headerKind as R,
|
|
3628
|
+
spanAt as S,
|
|
2805
3629
|
TRACK_KINDS as T,
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
3630
|
+
neighbourRect as U,
|
|
3631
|
+
canMergeRect as V,
|
|
3632
|
+
deleteColumn as W,
|
|
3633
|
+
insertColumn as X,
|
|
3634
|
+
deleteRow as Y,
|
|
3635
|
+
insertRow as Z,
|
|
3636
|
+
splitCell as _,
|
|
2813
3637
|
sanitizeTemplate as a,
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
3638
|
+
VOID_TAGS as a$,
|
|
3639
|
+
expandRect as a0,
|
|
3640
|
+
setColumnAlign as a1,
|
|
3641
|
+
setHeaderRow as a2,
|
|
3642
|
+
parseTabularText as a3,
|
|
3643
|
+
pasteGrid as a4,
|
|
3644
|
+
prepareEditorValue as a5,
|
|
3645
|
+
fromTableModel as a6,
|
|
3646
|
+
decodeEntities as a7,
|
|
3647
|
+
MAX_MATH_TEX as a8,
|
|
3648
|
+
MAX_INLINE_TEX as a9,
|
|
3649
|
+
inlineToHtml as aA,
|
|
3650
|
+
cleanMediaFile as aB,
|
|
3651
|
+
textNode as aC,
|
|
3652
|
+
escapeHtml as aD,
|
|
3653
|
+
inlineNodesToRender as aE,
|
|
3654
|
+
inlineToNodes as aF,
|
|
3655
|
+
serializeNodes as aG,
|
|
3656
|
+
toNodes as aH,
|
|
3657
|
+
tableLayout as aI,
|
|
3658
|
+
TAG_NAME as aJ,
|
|
3659
|
+
isSafeAttributeName as aK,
|
|
3660
|
+
LINK_SCHEMES as aL,
|
|
3661
|
+
RENDER_STATE as aM,
|
|
3662
|
+
isMathNode as aN,
|
|
3663
|
+
isFootnoteNode as aO,
|
|
3664
|
+
resolveLinkAttributes as aP,
|
|
3665
|
+
normalizePalette as aQ,
|
|
3666
|
+
isColorNode as aR,
|
|
3667
|
+
isHighlightNode as aS,
|
|
3668
|
+
paletteCss as aT,
|
|
3669
|
+
colorClass as aU,
|
|
3670
|
+
highlightClass as aV,
|
|
3671
|
+
cloneJsonSafe as aW,
|
|
3672
|
+
isPositionalFieldPath as aX,
|
|
3673
|
+
isValidFieldKey as aY,
|
|
3674
|
+
basePathOf as aZ,
|
|
3675
|
+
nodesTextContent as a_,
|
|
3676
|
+
MAX_FOOTNOTE_NOTE as aa,
|
|
3677
|
+
parseInline as ab,
|
|
3678
|
+
nodesToText as ac,
|
|
3679
|
+
nodesToHtml as ad,
|
|
3680
|
+
cleanAnnotationAttributes as ae,
|
|
3681
|
+
BUILT_IN_MARKER_VERSION as af,
|
|
3682
|
+
isBuiltInBlock as ag,
|
|
3683
|
+
BUILT_IN_MARKER as ah,
|
|
3684
|
+
activeBlocks as ai,
|
|
3685
|
+
activeAnnotations as aj,
|
|
3686
|
+
computeStats as ak,
|
|
3687
|
+
isPlainObject as al,
|
|
3688
|
+
ANNOTATION_NAME as am,
|
|
3689
|
+
mapFootnoteNotes as an,
|
|
3690
|
+
walkInlineElements as ao,
|
|
3691
|
+
registeredBlockOf as ap,
|
|
3692
|
+
hasPalette as aq,
|
|
3693
|
+
buildCodeBlockTools as ar,
|
|
3694
|
+
MARKED_BLOCKS as as,
|
|
3695
|
+
el$1 as at,
|
|
3696
|
+
normalizeEditorDataSafe as au,
|
|
3697
|
+
EDITOR_DATA_LIMITS as av,
|
|
3698
|
+
byteLength as aw,
|
|
3699
|
+
inlineToText as ax,
|
|
3700
|
+
compileBlockList as ay,
|
|
3701
|
+
sanitizeTunes as az,
|
|
3702
|
+
el as b,
|
|
3703
|
+
safeStyle as b0,
|
|
3704
|
+
draftIdentity as b1,
|
|
3705
|
+
pruneDrafts as b2,
|
|
3706
|
+
getDraft as b3,
|
|
3707
|
+
restoreDecision as b4,
|
|
3708
|
+
deleteDraft as b5,
|
|
3709
|
+
DRAFT_WRITE_DELAY_MS as b6,
|
|
3710
|
+
ttlMsOf as b7,
|
|
3711
|
+
bufferAction as b8,
|
|
3712
|
+
buildDraftRecord as b9,
|
|
3713
|
+
putDraft as ba,
|
|
3714
|
+
relativeTimeOf as bb,
|
|
3715
|
+
abbreviationAnnotation as bc,
|
|
3716
|
+
annotationsFromSummaries as bd,
|
|
3717
|
+
createFieldKey as be,
|
|
3718
|
+
savedValueOf as bf,
|
|
3719
|
+
prepareRemoteData as bg,
|
|
3720
|
+
createTabId as bh,
|
|
3721
|
+
isLoggedOut as bi,
|
|
3722
|
+
nextDelay as bj,
|
|
3723
|
+
IDLE_AFTER_MS as bk,
|
|
3724
|
+
fieldsWith as bl,
|
|
3725
|
+
fieldProblems as bm,
|
|
3726
|
+
fieldIdentity as bn,
|
|
3727
|
+
index as bo,
|
|
2865
3728
|
codeBlocks as c,
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
3729
|
+
select as d,
|
|
3730
|
+
entryPath as e,
|
|
3731
|
+
input as f,
|
|
2869
3732
|
getTranslation as g,
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
3733
|
+
field as h,
|
|
3734
|
+
isHexColor as i,
|
|
3735
|
+
ANNOTATION_VALUE_PREFIX as j,
|
|
3736
|
+
ANNOTATION_ATTRIBUTE as k,
|
|
3737
|
+
ICONS as l,
|
|
2875
3738
|
mergeCodeBlocks as m,
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
3739
|
+
button as n,
|
|
3740
|
+
sanitizeUrl as o,
|
|
3741
|
+
MAX_GALLERY_IMAGES as p,
|
|
3742
|
+
cleanFocalPoint as q,
|
|
3743
|
+
MAX_MEDIA_TRACKS as r,
|
|
2881
3744
|
sanitizeSvg as s,
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
3745
|
+
tokenLabel as t,
|
|
3746
|
+
editable as u,
|
|
3747
|
+
sanitizeInline as v,
|
|
3748
|
+
MAX_CODE_FILENAME as w,
|
|
3749
|
+
cleanCodeFilename as x,
|
|
3750
|
+
hashString as y,
|
|
3751
|
+
escapeHtml$1 as z
|
|
2889
3752
|
};
|