magic-editor-x 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +493 -168
  3. package/dist/admin/{ConfigurationPage-YvnPnna6.js → ConfigurationPage-CFP3lp9p.js} +479 -50
  4. package/dist/admin/{ConfigurationPage-3Dir3dAf.mjs → ConfigurationPage-CYGDLjM7.mjs} +450 -21
  5. package/dist/admin/ConfirmAction-DuQwvRYi.mjs +125 -0
  6. package/dist/admin/ConfirmAction-zLuIFj8t.js +124 -0
  7. package/dist/admin/{CustomBlocksPage-CR2BaP9O.mjs → CustomBlocksPage-B5Q33N-s.mjs} +92 -41
  8. package/dist/admin/{CustomBlocksPage-BiiL2ORG.js → CustomBlocksPage-DzPOSpfn.js} +135 -84
  9. package/dist/admin/DraftSync-BIA8cZgA.js +11 -0
  10. package/dist/admin/DraftSync-CUxOMG-E.mjs +12 -0
  11. package/dist/admin/TemplatesPage-4A8JNO_Z.mjs +993 -0
  12. package/dist/admin/TemplatesPage-BVkgafCK.js +993 -0
  13. package/dist/admin/{de-BmmLBJli.mjs → de-1cFMs-4c.mjs} +2 -0
  14. package/dist/admin/{de-BteRx2iA.js → de-2Ie5jy7j.js} +79 -1
  15. package/dist/admin/{de-62Vxb2iw.js → de-B1X46JJZ.js} +205 -2
  16. package/dist/admin/{de-CFX5atOk.mjs → de-BMY2LBaa.mjs} +79 -1
  17. package/dist/admin/{de-Bt6pYIWi.mjs → de-BUS1hUw0.mjs} +145 -0
  18. package/dist/admin/{de-CVbi685U.js → de-C3AsGauQ.js} +145 -0
  19. package/dist/admin/{de-BVvwSYYO.mjs → de-DOiGaTNX.mjs} +205 -2
  20. package/dist/admin/{de-DaJwN6nk.js → de-Dn8athM8.js} +2 -0
  21. package/dist/admin/{en-CyjAcccB.js → en-Ah-Cw0Wd.js} +79 -1
  22. package/dist/admin/{en-BX362fTp.js → en-BkEjpC3i.js} +145 -0
  23. package/dist/admin/{en-VlkaIzrM.js → en-CDg_18Bt.js} +205 -2
  24. package/dist/admin/{en-Cn78RZs-.js → en-CIZ5Ggod.js} +2 -0
  25. package/dist/admin/{en-Cg2Ak5Cr.mjs → en-CU6UzV4g.mjs} +205 -2
  26. package/dist/admin/{en-ea0tfA5i.mjs → en-CvFiqti2.mjs} +79 -1
  27. package/dist/admin/{en-D7mZWLGp.mjs → en-Dc9y-6n9.mjs} +2 -0
  28. package/dist/admin/{en-B_HltUxZ.mjs → en-GCzgS9Aw.mjs} +145 -0
  29. package/dist/admin/{es-BT9oAcHf.js → es-BCpJmUEM.js} +205 -2
  30. package/dist/admin/{es-C9-cXdb6.mjs → es-BmfffNM2.mjs} +205 -2
  31. package/dist/admin/{es-BmGtLkJD.js → es-C4IRHV5d.js} +2 -0
  32. package/dist/admin/{es-CHHEZi44.js → es-C4pEnDRv.js} +145 -0
  33. package/dist/admin/{es-C8GZFGjv.js → es-Cr8JH85N.js} +79 -1
  34. package/dist/admin/{es-joykG5I9.mjs → es-D2Kw6E4N.mjs} +2 -0
  35. package/dist/admin/{es-CrhwOq-5.mjs → es-DHBBZKl2.mjs} +145 -0
  36. package/dist/admin/{es-CEi_ycX8.mjs → es-DbKHZz5l.mjs} +79 -1
  37. package/dist/admin/{fr-CrzxGe5e.mjs → fr-BOvvfEH7.mjs} +2 -0
  38. package/dist/admin/{fr-B3SL0TBV.js → fr-C2aLSwEu.js} +145 -0
  39. package/dist/admin/{fr-BAMSvQbR.mjs → fr-DQJ_7aq5.mjs} +79 -1
  40. package/dist/admin/{fr-DpU_qiXR.mjs → fr-DZd2XJP6.mjs} +205 -2
  41. package/dist/admin/{fr-5djKfQ3s.mjs → fr-Dvq4xk2e.mjs} +145 -0
  42. package/dist/admin/{fr-oRCJNdeJ.js → fr-OJ4VW1kh.js} +79 -1
  43. package/dist/admin/{fr-D6KJqPWi.js → fr-ZcN0yM_2.js} +205 -2
  44. package/dist/admin/{fr-Ct_uPqxV.js → fr-Zkb8vfjN.js} +2 -0
  45. package/dist/admin/{EditorField-Diq1j8kc.js → index-DQVE0ymw.js} +13712 -6767
  46. package/dist/admin/index-DR8sHkTk.js +1940 -0
  47. package/dist/admin/index-My6FjjHB.mjs +1939 -0
  48. package/dist/admin/{EditorField-B8pyAxPE.mjs → index-k8_a5o1A.mjs} +10223 -3278
  49. package/dist/admin/index.js +1 -1
  50. package/dist/admin/index.mjs +2 -2
  51. package/dist/admin/{pt-chN2jrXl.js → pt-1IUyx6ae.js} +2 -0
  52. package/dist/admin/{pt-CQrfqsCN.mjs → pt-BSLzA17U.mjs} +79 -1
  53. package/dist/admin/{pt-jUqOR7Xh.mjs → pt-C3UdeIpd.mjs} +205 -2
  54. package/dist/admin/{pt-BOrl6x-r.js → pt-CImqDnLB.js} +205 -2
  55. package/dist/admin/{pt-BdnY2Cth.mjs → pt-CilDggGF.mjs} +145 -0
  56. package/dist/admin/{pt-tUeJ2Ywd.js → pt-D0I0_JYs.js} +79 -1
  57. package/dist/admin/{pt-EVwCuBUK.js → pt-DX0OAIoL.js} +145 -0
  58. package/dist/admin/{pt-Ga-4Hsv0.mjs → pt-etwsg3G4.mjs} +2 -0
  59. package/dist/admin/useBreakpoint-D30eNTkF.js +37 -0
  60. package/dist/admin/useBreakpoint-DCfn6pDG.mjs +38 -0
  61. package/dist/admin/useT-Cmg1jwwG.mjs +65 -0
  62. package/dist/admin/{useT-BWZ_-Hel.js → useT-DNphiBQR.js} +4 -70
  63. package/dist/blocks/index.d.mts +167 -0
  64. package/dist/blocks/index.d.ts +167 -0
  65. package/dist/blocks/index.js +631 -0
  66. package/dist/blocks/index.mjs +609 -0
  67. package/dist/react/index.d.mts +39 -0
  68. package/dist/react/index.d.ts +39 -0
  69. package/dist/react/index.js +2687 -0
  70. package/dist/react/index.mjs +2657 -0
  71. package/dist/render/index.d.mts +131 -5
  72. package/dist/render/index.d.ts +131 -5
  73. package/dist/render/index.js +1679 -181
  74. package/dist/render/index.mjs +1679 -181
  75. package/dist/server/index.js +10645 -3716
  76. package/dist/server/index.mjs +10645 -3716
  77. package/dist/vue/index.d.mts +41 -0
  78. package/dist/vue/index.d.ts +41 -0
  79. package/dist/vue/index.js +2630 -0
  80. package/dist/vue/index.mjs +2610 -0
  81. package/package.json +30 -6
  82. package/schema/magic-editor-x.schema.json +540 -1
  83. package/types/blocks.d.ts +167 -0
  84. package/types/index.d.ts +127 -0
  85. package/types/react.d.ts +39 -0
  86. package/types/render.d.ts +131 -5
  87. package/types/vue.d.ts +41 -0
  88. package/dist/admin/api-Dsq53giv.js +0 -37
  89. package/dist/admin/api-RZ0Fz0BD.mjs +0 -38
  90. package/dist/admin/index-C-lyON1B.mjs +0 -303
  91. package/dist/admin/index-iA0lued_.js +0 -302
  92. package/dist/admin/sanitize-Cb4jvBhj.js +0 -628
  93. package/dist/admin/sanitize-ClkX823p.mjs +0 -627
  94. package/dist/admin/useT-pvHmgBFj.mjs +0 -131
@@ -0,0 +1,1940 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const icons = require("@strapi/icons");
4
+ const createDOMPurify = require("dompurify");
5
+ const ReactNamespace = require("react");
6
+ const client = require("react-dom/client");
7
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
8
+ const createDOMPurify__default = /* @__PURE__ */ _interopDefault(createDOMPurify);
9
+ const PLUGIN_ID = "magic-editor-x";
10
+ const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.Feather, { "aria-hidden": true });
11
+ const action = (uid) => [{ action: `plugin::magic-editor-x.${uid}`, subject: null }];
12
+ const PERMISSIONS = {
13
+ customBlocksManage: action("custom-blocks.manage"),
14
+ settingsRead: action("settings.read"),
15
+ settingsUpdate: action("settings.update"),
16
+ templatesManage: action("templates.manage")
17
+ };
18
+ const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
19
+ const registry = /* @__PURE__ */ new Map();
20
+ const activeBlock = (type) => typeof type === "string" && registry.has(type) ? registry.get(type) : null;
21
+ const activeBlocks = () => [...registry.values()];
22
+ const activeBlockIgnoringCase = (name) => {
23
+ const lower = String(name).toLowerCase();
24
+ for (const definition of registry.values()) if (definition.name.toLowerCase() === lower) return definition;
25
+ return null;
26
+ };
27
+ const setActiveBlock = (compiled2) => {
28
+ registry.set(compiled2.name, compiled2);
29
+ };
30
+ const isPlainObject$1 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
31
+ const BUILT_IN_MARKER = "_mex";
32
+ const BUILT_IN_MARKER_VERSION = 1;
33
+ const MARKED_BLOCKS = Object.freeze({
34
+ toc: Object.freeze({ keys: Object.freeze(["title", "minLevel", "maxLevel", "style"]), anchor: null }),
35
+ gallery: Object.freeze({
36
+ keys: Object.freeze(["images", "layout", "columns", "caption"]),
37
+ anchor: Object.freeze(["images", "array"])
38
+ }),
39
+ video: Object.freeze({
40
+ keys: Object.freeze(["file", "poster", "title", "caption", "loop", "muted", "tracks"]),
41
+ anchor: Object.freeze(["file", "object"])
42
+ }),
43
+ audio: Object.freeze({
44
+ keys: Object.freeze(["file", "title", "caption", "loop", "tracks"]),
45
+ anchor: Object.freeze(["file", "object"])
46
+ }),
47
+ synced: Object.freeze({ keys: Object.freeze(["ref"]), anchor: Object.freeze(["ref", "string"]) })
48
+ });
49
+ const isBuiltInMarker = (value) => Number.isInteger(value) && /** @type {number} */
50
+ value >= 1;
51
+ const hasBuiltInShape = (shape, data) => {
52
+ if (!Object.keys(data).every((key2) => shape.keys.includes(key2))) return false;
53
+ if (!shape.anchor) return true;
54
+ const [key, kind] = shape.anchor;
55
+ const value = data[key];
56
+ if (kind === "array") return Array.isArray(value);
57
+ if (kind === "object") return isPlainObject$1(value);
58
+ return typeof value === kind;
59
+ };
60
+ const isMarkedBuiltIn = (type, data) => {
61
+ if (!Object.prototype.hasOwnProperty.call(MARKED_BLOCKS, type) || !isPlainObject$1(data)) return false;
62
+ if (isBuiltInMarker(data[BUILT_IN_MARKER])) return true;
63
+ return hasBuiltInShape(MARKED_BLOCKS[type], data);
64
+ };
65
+ const EDITOR_DATA_LIMITS = Object.freeze({
66
+ maxBlocks: 5e3,
67
+ maxBytes: 5 * 1024 * 1024,
68
+ maxDepth: 24,
69
+ maxBlockIdLength: 64,
70
+ maxTypeLength: 64
71
+ });
72
+ const FORBIDDEN_KEYS$1 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
73
+ const BLOCK_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
74
+ const BLOCK_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
75
+ const isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
76
+ class EditorDataError extends Error {
77
+ /**
78
+ * @param {string} message - Fixed, non-sensitive message.
79
+ * @param {string} code - Machine-readable reason.
80
+ */
81
+ constructor(message, code) {
82
+ super(message);
83
+ this.name = "EditorDataError";
84
+ this.code = code;
85
+ }
86
+ }
87
+ const cloneJsonSafe = (value, depth = 0) => {
88
+ if (depth > EDITOR_DATA_LIMITS.maxDepth) {
89
+ throw new EditorDataError("Editor content is nested too deeply", "TOO_DEEP");
90
+ }
91
+ if (value === null) return null;
92
+ if (Array.isArray(value)) {
93
+ const out = [];
94
+ for (const item of value) {
95
+ const cloned = cloneJsonSafe(item, depth + 1);
96
+ out.push(cloned === void 0 ? null : cloned);
97
+ }
98
+ return out;
99
+ }
100
+ switch (typeof value) {
101
+ case "string":
102
+ case "boolean":
103
+ return value;
104
+ case "number":
105
+ return Number.isFinite(value) ? value : null;
106
+ case "object": {
107
+ const out = {};
108
+ for (const key of Object.keys(value)) {
109
+ if (FORBIDDEN_KEYS$1.has(key)) continue;
110
+ const cloned = cloneJsonSafe(value[key], depth + 1);
111
+ if (cloned !== void 0) out[key] = cloned;
112
+ }
113
+ return out;
114
+ }
115
+ default:
116
+ return void 0;
117
+ }
118
+ };
119
+ const tryParseJson = (text) => {
120
+ try {
121
+ return { ok: true, value: JSON.parse(text) };
122
+ } catch {
123
+ return { ok: false };
124
+ }
125
+ };
126
+ const escapeHtml = (text) => String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
127
+ const hashString = (text) => {
128
+ let hash = 2166136261;
129
+ for (let i = 0; i < text.length; i += 1) {
130
+ hash ^= text.charCodeAt(i);
131
+ hash = Math.imul(hash, 16777619) >>> 0;
132
+ }
133
+ return hash.toString(16).padStart(8, "0");
134
+ };
135
+ const legacyBlockId = (index2, type, data) => `mx${hashString(`${index2}:${type}:${JSON.stringify(data)}`)}${index2}`;
136
+ const textToBlocks = (text) => {
137
+ const trimmed = text.trim();
138
+ if (!trimmed) return [];
139
+ const looksLikeHtml = /<\/?[a-z][^>]{0,200}>/i.test(trimmed.slice(0, 2e3));
140
+ if (looksLikeHtml) {
141
+ return [{ type: "paragraph", data: { text: trimmed } }];
142
+ }
143
+ 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>") } }));
144
+ };
145
+ const unwrapValue = (value) => {
146
+ let current = value;
147
+ let legacy = false;
148
+ for (let i = 0; i < 3 && typeof current === "string"; i += 1) {
149
+ const text = current.trim();
150
+ if (!text) return { candidate: null, legacy: true };
151
+ if (text.startsWith("{") || text.startsWith("[") || text.startsWith('"')) {
152
+ const parsed = tryParseJson(text);
153
+ if (parsed.ok) {
154
+ current = parsed.value;
155
+ legacy = true;
156
+ continue;
157
+ }
158
+ }
159
+ return { candidate: { blocks: textToBlocks(text) }, legacy: true };
160
+ }
161
+ if (Array.isArray(current)) {
162
+ return { candidate: { blocks: current }, legacy: true };
163
+ }
164
+ return { candidate: current, legacy };
165
+ };
166
+ const normalizeEditorData = (value) => {
167
+ if (value === null || value === void 0) return null;
168
+ if (typeof value === "string" && value.length > EDITOR_DATA_LIMITS.maxBytes) {
169
+ throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
170
+ }
171
+ const { candidate } = unwrapValue(value);
172
+ if (candidate === null || candidate === void 0) return null;
173
+ if (!isPlainObject(candidate)) {
174
+ throw new EditorDataError("Editor content must be an Editor.js object", "INVALID_SHAPE");
175
+ }
176
+ const clean = cloneJsonSafe(candidate);
177
+ const rawBlocks = Array.isArray(clean.blocks) ? clean.blocks : [];
178
+ if (rawBlocks.length > EDITOR_DATA_LIMITS.maxBlocks) {
179
+ throw new EditorDataError("Editor content has too many blocks", "TOO_MANY_BLOCKS");
180
+ }
181
+ const seen = /* @__PURE__ */ new Set();
182
+ const blocks = [];
183
+ rawBlocks.forEach((block, index2) => {
184
+ if (!isPlainObject(block)) return;
185
+ const type = typeof block.type === "string" ? block.type.trim() : "";
186
+ if (!BLOCK_TYPE_PATTERN.test(type)) return;
187
+ const data = isPlainObject(block.data) ? block.data : {};
188
+ let id = typeof block.id === "string" && BLOCK_ID_PATTERN.test(block.id) ? block.id : "";
189
+ if (!id || seen.has(id)) id = legacyBlockId(index2, type, data);
190
+ while (seen.has(id)) id = `${id}x`;
191
+ seen.add(id);
192
+ const normalized = { id, type, data };
193
+ if (isPlainObject(block.tunes) && Object.keys(block.tunes).length > 0) normalized.tunes = block.tunes;
194
+ blocks.push(normalized);
195
+ });
196
+ const time = Number.isFinite(clean.time) && clean.time > 0 ? Math.floor(clean.time) : 0;
197
+ const version = typeof clean.version === "string" && clean.version.length <= 32 ? clean.version : "2.31.7";
198
+ const result = { time, blocks, version };
199
+ const size = byteLength(JSON.stringify(result));
200
+ if (size > EDITOR_DATA_LIMITS.maxBytes) {
201
+ throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
202
+ }
203
+ return result;
204
+ };
205
+ const normalizeEditorDataSafe = (value) => {
206
+ try {
207
+ return normalizeEditorData(value);
208
+ } catch {
209
+ return null;
210
+ }
211
+ };
212
+ const byteLength = (text) => {
213
+ let bytes = 0;
214
+ for (let i = 0; i < text.length; i += 1) {
215
+ const code = text.charCodeAt(i);
216
+ if (code < 128) bytes += 1;
217
+ else if (code < 2048) bytes += 2;
218
+ else if (code >= 55296 && code <= 56319) {
219
+ bytes += 4;
220
+ i += 1;
221
+ } else bytes += 3;
222
+ }
223
+ return bytes;
224
+ };
225
+ const computeStats = (data) => {
226
+ if (!data || !Array.isArray(data.blocks)) return { blocks: 0, words: 0, characters: 0 };
227
+ let text = "";
228
+ const collect = (value, depth = 0) => {
229
+ if (depth > 8 || value === null || value === void 0) return;
230
+ if (typeof value === "string") {
231
+ text += ` ${value.replace(/<[^>]{0,500}>/g, " ").replace(/&nbsp;/g, " ")}`;
232
+ } else if (Array.isArray(value)) value.forEach((item) => collect(item, depth + 1));
233
+ else if (typeof value === "object") {
234
+ for (const [key, item] of Object.entries(value)) {
235
+ if (["url", "link", "href", "src", "id", "documentId", "style", "type", "service"].includes(key))
236
+ continue;
237
+ collect(item, depth + 1);
238
+ }
239
+ }
240
+ };
241
+ data.blocks.forEach((block) => {
242
+ if (block && block.type === "synced" && isMarkedBuiltIn("synced", block.data)) return;
243
+ const definition = block && activeBlock(block.type);
244
+ if (definition) definition.fields(block.data).forEach((field2) => collect(field2.value));
245
+ else collect(block.data);
246
+ });
247
+ const normalized = text.replace(/\s+/g, " ").trim();
248
+ return {
249
+ blocks: data.blocks.length,
250
+ words: normalized ? normalized.split(" ").length : 0,
251
+ characters: normalized.length
252
+ };
253
+ };
254
+ const INLINE_TAGS = Object.freeze([
255
+ "b",
256
+ "strong",
257
+ "i",
258
+ "em",
259
+ "u",
260
+ "s",
261
+ "mark",
262
+ "code",
263
+ "a",
264
+ "br",
265
+ "span",
266
+ "sub",
267
+ "sup"
268
+ ]);
269
+ const INTERNAL_LINK_ATTRIBUTES = Object.freeze([
270
+ "data-mex-uid",
271
+ "data-mex-document-id",
272
+ "data-mex-locale",
273
+ "data-mex-mention"
274
+ ]);
275
+ const INTERNAL_LINK_RULES = Object.freeze({
276
+ "data-mex-uid": /^api::[a-z0-9-]{1,60}\.[a-z0-9-]{1,60}$/,
277
+ "data-mex-document-id": /^[a-z0-9]{1,64}$/,
278
+ "data-mex-locale": /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8}){0,3}$/,
279
+ // Boolean flag: written as "true"; an empty value (`<a data-mex-mention>`) is accepted and normalised.
280
+ "data-mex-mention": /^(?:|true)$/
281
+ });
282
+ const cleanInternalLinkAttributes = (attribs) => {
283
+ const out = {};
284
+ if (!attribs || typeof attribs !== "object") return out;
285
+ for (const name of INTERNAL_LINK_ATTRIBUTES) {
286
+ const value = attribs[name];
287
+ if (typeof value === "string" && INTERNAL_LINK_RULES[name].test(value)) out[name] = value;
288
+ }
289
+ if (!out["data-mex-uid"] || !out["data-mex-document-id"]) return {};
290
+ if (out["data-mex-mention"] !== void 0) out["data-mex-mention"] = "true";
291
+ return out;
292
+ };
293
+ const isMentionLink = (attrs) => Boolean(
294
+ attrs && attrs["data-mex-mention"] === "true" && attrs["data-mex-uid"] && attrs["data-mex-document-id"]
295
+ );
296
+ const INLINE_ATTRIBUTES = Object.freeze({
297
+ a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
298
+ span: ["class", "data-tooltip"],
299
+ mark: ["class"],
300
+ u: ["class"],
301
+ s: ["class"],
302
+ code: ["class"]
303
+ });
304
+ const INLINE_CLASSES = Object.freeze({
305
+ span: ["cdx-tooltip"],
306
+ mark: ["cdx-marker"],
307
+ u: ["cdx-underline"],
308
+ s: ["cdx-strikethrough", "cdx-strikethroughs"],
309
+ code: ["inline-code"]
310
+ });
311
+ const LINK_SCHEMES = Object.freeze(["http", "https", "mailto", "tel"]);
312
+ const MAX_URL_LENGTH = 2048;
313
+ const TARGETS = /* @__PURE__ */ new Set(["_blank", "_self", "_parent", "_top"]);
314
+ const sanitizeUrl = (value, options = {}) => {
315
+ const schemes = options.schemes || LINK_SCHEMES;
316
+ const allowRelative = options.allowRelative !== false;
317
+ if (typeof value !== "string") return "";
318
+ const url = value.trim();
319
+ if (!url || url.length > MAX_URL_LENGTH) return "";
320
+ if (/[\u0000-\u001f\u007f\s]/.test(url) && !/^(mailto|tel):/i.test(url)) return "";
321
+ if (url.startsWith("//") || url.startsWith("\\")) return "";
322
+ const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]{0,20}):/.exec(url);
323
+ if (!scheme) {
324
+ return allowRelative && /^[/#?.]/.test(url) ? url : "";
325
+ }
326
+ if (!schemes.includes(scheme[1].toLowerCase())) return "";
327
+ if (scheme[1].toLowerCase().startsWith("http")) {
328
+ try {
329
+ const parsed = new URL(url);
330
+ if (parsed.username || parsed.password) return "";
331
+ } catch {
332
+ return "";
333
+ }
334
+ }
335
+ return url;
336
+ };
337
+ const plain = (value, max = 1e5) => typeof value === "string" ? value.slice(0, max) : "";
338
+ const oneOf = (value, allowed, fallback) => typeof value === "string" && allowed.includes(value) ? value : fallback;
339
+ const int = (value, min, max, fallback) => {
340
+ const number = typeof value === "string" ? Number(value) : value;
341
+ return Number.isInteger(number) && number >= min && number <= max ? number : fallback;
342
+ };
343
+ const bool = (value) => value === true;
344
+ const MAX_GALLERY_IMAGES = 50;
345
+ const MAX_MEDIA_TRACKS = 8;
346
+ const TRACK_KINDS = Object.freeze(["captions", "subtitles", "descriptions", "chapters"]);
347
+ const SRCLANG = /^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{1,8}){0,3}$/;
348
+ const cleanFocalPoint = (value) => {
349
+ if (!isPlainObject(value)) return void 0;
350
+ const { x, y } = value;
351
+ if (![x, y].every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0 && n <= 1)) return void 0;
352
+ return { x: Math.round(x * 100) / 100, y: Math.round(y * 100) / 100 };
353
+ };
354
+ const cleanMediaFile = (value, kind = {}) => {
355
+ const file = isPlainObject(value) ? value : {};
356
+ const out = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
357
+ for (const key of ["mime", ...kind.image ? ["alt"] : [], "name", "hash", "ext"])
358
+ if (typeof file[key] === "string") out[key] = plain(file[key], 500);
359
+ for (const key of ["width", "height", "size"]) if (Number.isFinite(file[key])) out[key] = file[key];
360
+ if (kind.image && isPlainObject(file.formats))
361
+ out.formats = generic(file.formats, (s) => plain(s, 2048), 0, "formats");
362
+ if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string")) out.id = file.id;
363
+ if (typeof file.documentId === "string") out.documentId = plain(file.documentId, 64);
364
+ const mime = typeof out.mime === "string" ? out.mime.toLowerCase() : "";
365
+ if (kind.mimePrefix && mime && !mime.startsWith(kind.mimePrefix)) out.url = "";
366
+ if (kind.vtt && out.url) {
367
+ const path = out.url.split(/[?#]/)[0].toLowerCase();
368
+ const ext = typeof out.ext === "string" ? out.ext.toLowerCase() : "";
369
+ if (mime !== "text/vtt" && ext !== ".vtt" && !path.endsWith(".vtt")) out.url = "";
370
+ }
371
+ return out;
372
+ };
373
+ const mediaTracks = (tracks) => {
374
+ if (!Array.isArray(tracks)) return [];
375
+ const out = [];
376
+ let hasDefault = false;
377
+ for (const track of tracks.slice(0, MAX_MEDIA_TRACKS)) {
378
+ if (!isPlainObject(track)) continue;
379
+ const file = cleanMediaFile(track.file, { vtt: true });
380
+ if (!file.url) continue;
381
+ const clean = {
382
+ file,
383
+ kind: oneOf(track.kind, TRACK_KINDS, "captions"),
384
+ srclang: typeof track.srclang === "string" && SRCLANG.test(track.srclang) ? track.srclang : "",
385
+ label: plain(track.label, 100)
386
+ };
387
+ if (track.default === true && !hasDefault) {
388
+ clean.default = true;
389
+ hasDefault = true;
390
+ }
391
+ out.push(clean);
392
+ }
393
+ return out;
394
+ };
395
+ const generic = (value, inline, depth = 0, key = "") => {
396
+ if (depth > 20) return null;
397
+ if (typeof value === "string") {
398
+ if (/^(url|href|link|src|photo|source|embed)$/i.test(key)) return sanitizeUrl(value);
399
+ return inline(value);
400
+ }
401
+ if (Array.isArray(value)) return value.map((item) => generic(item, inline, depth + 1, key));
402
+ if (isPlainObject(value)) {
403
+ const out = {};
404
+ for (const [childKey, child] of Object.entries(value))
405
+ out[childKey] = generic(child, inline, depth + 1, childKey);
406
+ return out;
407
+ }
408
+ return value;
409
+ };
410
+ const listItems = (items, inline, depth = 0) => {
411
+ if (!Array.isArray(items) || depth > 12) return [];
412
+ return items.map((item) => {
413
+ if (typeof item === "string") return inline(item);
414
+ if (!isPlainObject(item)) return { content: "", items: [] };
415
+ const out = { content: inline(typeof item.content === "string" ? item.content : plain(item.text)) };
416
+ if (isPlainObject(item.meta)) {
417
+ const meta = {};
418
+ if (typeof item.meta.checked === "boolean") meta.checked = item.meta.checked;
419
+ const start = int(item.meta.start, 0, 1e5, void 0);
420
+ if (start !== void 0) meta.start = start;
421
+ if (typeof item.meta.counterType === "string") {
422
+ meta.counterType = oneOf(
423
+ item.meta.counterType,
424
+ ["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
425
+ "numeric"
426
+ );
427
+ }
428
+ out.meta = meta;
429
+ }
430
+ out.items = listItems(item.items, inline, depth + 1);
431
+ return out;
432
+ });
433
+ };
434
+ const BLOCK_POLICIES = {
435
+ paragraph: (d, inline) => ({ text: inline(d.text) }),
436
+ header: (d, inline) => ({ text: inline(d.text), level: int(d.level, 1, 6, 2) }),
437
+ quote: (d, inline) => ({
438
+ text: inline(d.text),
439
+ caption: inline(d.caption),
440
+ alignment: oneOf(d.alignment, ["left", "center"], "left")
441
+ }),
442
+ list: (d, inline) => {
443
+ const out = {
444
+ style: oneOf(d.style, ["ordered", "unordered", "checklist"], "unordered"),
445
+ items: listItems(d.items, inline)
446
+ };
447
+ if (isPlainObject(d.meta)) {
448
+ const meta = {};
449
+ const start = int(d.meta.start, 0, 1e5, void 0);
450
+ if (start !== void 0) meta.start = start;
451
+ if (typeof d.meta.counterType === "string") {
452
+ meta.counterType = oneOf(
453
+ d.meta.counterType,
454
+ ["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
455
+ "numeric"
456
+ );
457
+ }
458
+ out.meta = meta;
459
+ }
460
+ return out;
461
+ },
462
+ checklist: (d, inline) => ({
463
+ items: Array.isArray(d.items) ? d.items.filter(isPlainObject).map((item) => ({ text: inline(item.text), checked: bool(item.checked) })) : []
464
+ }),
465
+ warning: (d, inline) => ({ title: inline(d.title), message: inline(d.message) }),
466
+ alert: (d, inline) => ({
467
+ type: oneOf(
468
+ d.type,
469
+ ["primary", "secondary", "info", "success", "warning", "danger", "light", "dark"],
470
+ "info"
471
+ ),
472
+ align: oneOf(d.align, ["left", "center", "right"], "left"),
473
+ message: inline(d.message)
474
+ }),
475
+ toggle: (d, inline) => ({
476
+ text: inline(d.text),
477
+ status: oneOf(d.status, ["open", "closed"], "open"),
478
+ fk: typeof d.fk === "string" ? d.fk.slice(0, 64) : void 0,
479
+ items: int(d.items, 0, 5e3, 0)
480
+ }),
481
+ code: (d) => ({ code: plain(d.code, 5e5) }),
482
+ codeFlask: (d) => {
483
+ const out = {
484
+ code: plain(d.code, 5e5),
485
+ language: typeof d.language === "string" && /^[a-z0-9+#-]{1,32}$/i.test(d.language) ? d.language : "plaintext"
486
+ };
487
+ if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
488
+ return out;
489
+ },
490
+ raw: (d, _inline, ctx) => {
491
+ const html = plain(d.html, 5e5);
492
+ if (ctx.rawHtml === "allow") return { html };
493
+ if (ctx.rawHtml === "disable") return { html: "" };
494
+ return { html: ctx.rawSanitizer(html) };
495
+ },
496
+ table: (d, inline) => ({
497
+ withHeadings: bool(d.withHeadings),
498
+ stretched: bool(d.stretched),
499
+ content: Array.isArray(d.content) ? d.content.slice(0, 500).map((row) => Array.isArray(row) ? row.slice(0, 100).map((cell) => inline(cell)) : []) : []
500
+ }),
501
+ image: (d, inline) => {
502
+ const file = isPlainObject(d.file) ? d.file : {};
503
+ const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
504
+ for (const key of ["mime", "alt", "name", "hash", "ext"])
505
+ if (typeof file[key] === "string") cleanFile[key] = plain(file[key], 500);
506
+ for (const key of ["width", "height", "size"]) if (Number.isFinite(file[key])) cleanFile[key] = file[key];
507
+ if (isPlainObject(file.formats))
508
+ cleanFile.formats = generic(file.formats, (s) => plain(s, 2048), 0, "formats");
509
+ if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
510
+ cleanFile.id = file.id;
511
+ if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
512
+ const out = {
513
+ file: cleanFile,
514
+ caption: inline(d.caption),
515
+ withBorder: bool(d.withBorder),
516
+ withBackground: bool(d.withBackground),
517
+ stretched: bool(d.stretched)
518
+ };
519
+ if (d.decorative === true) out.decorative = true;
520
+ const focalPoint = cleanFocalPoint(d.focalPoint);
521
+ if (focalPoint) out.focalPoint = focalPoint;
522
+ return out;
523
+ },
524
+ simpleImage: (d, inline) => {
525
+ const out = {
526
+ url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
527
+ caption: inline(d.caption),
528
+ withBorder: bool(d.withBorder),
529
+ withBackground: bool(d.withBackground),
530
+ stretched: bool(d.stretched)
531
+ };
532
+ if (typeof d.alt === "string") out.alt = plain(d.alt, 500);
533
+ if (d.decorative === true) out.decorative = true;
534
+ return out;
535
+ },
536
+ gallery: (d, inline) => {
537
+ const images = [];
538
+ for (const item of Array.isArray(d.images) ? d.images : []) {
539
+ if (images.length >= MAX_GALLERY_IMAGES) break;
540
+ if (!isPlainObject(item)) continue;
541
+ const file = cleanMediaFile(item.file, { image: true, mimePrefix: "image/" });
542
+ if (!file.url) continue;
543
+ const image = { file, caption: inline(item.caption) };
544
+ if (item.decorative === true) image.decorative = true;
545
+ const focalPoint = cleanFocalPoint(item.focalPoint);
546
+ if (focalPoint) image.focalPoint = focalPoint;
547
+ images.push(image);
548
+ }
549
+ return {
550
+ images,
551
+ layout: oneOf(d.layout, ["grid", "carousel"], "grid"),
552
+ columns: int(d.columns, 1, 6, 3),
553
+ caption: inline(d.caption),
554
+ _mex: BUILT_IN_MARKER_VERSION
555
+ };
556
+ },
557
+ video: (d, inline) => {
558
+ const out = {
559
+ file: cleanMediaFile(d.file, { mimePrefix: "video/" }),
560
+ title: plain(d.title, 200),
561
+ caption: inline(d.caption),
562
+ loop: bool(d.loop),
563
+ muted: bool(d.muted),
564
+ tracks: mediaTracks(d.tracks)
565
+ };
566
+ if (isPlainObject(d.poster)) {
567
+ const poster = cleanMediaFile(d.poster, { image: true, mimePrefix: "image/" });
568
+ if (poster.url) out.poster = poster;
569
+ }
570
+ out._mex = BUILT_IN_MARKER_VERSION;
571
+ return out;
572
+ },
573
+ audio: (d, inline) => ({
574
+ file: cleanMediaFile(d.file, { mimePrefix: "audio/" }),
575
+ title: plain(d.title, 200),
576
+ caption: inline(d.caption),
577
+ loop: bool(d.loop),
578
+ tracks: mediaTracks(d.tracks),
579
+ _mex: BUILT_IN_MARKER_VERSION
580
+ }),
581
+ linkTool: (d) => {
582
+ const meta = isPlainObject(d.meta) ? d.meta : {};
583
+ const image = isPlainObject(meta.image) ? { url: sanitizeUrl(meta.image.url, { schemes: ["http", "https"] }) } : void 0;
584
+ const cleanMeta = { title: plain(meta.title, 500), description: plain(meta.description, 2e3) };
585
+ if (typeof meta.site_name === "string") cleanMeta.site_name = plain(meta.site_name, 200);
586
+ if (image && image.url) cleanMeta.image = image;
587
+ return { link: sanitizeUrl(d.link, { schemes: ["http", "https"] }), meta: cleanMeta };
588
+ },
589
+ attaches: (d) => {
590
+ const file = isPlainObject(d.file) ? d.file : {};
591
+ const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
592
+ if (typeof file.name === "string") cleanFile.name = plain(file.name, 255);
593
+ if (typeof file.extension === "string") cleanFile.extension = plain(file.extension, 16);
594
+ if (Number.isFinite(file.size)) cleanFile.size = file.size;
595
+ if (typeof file.title === "string") cleanFile.title = plain(file.title, 255);
596
+ return { file: cleanFile, title: plain(d.title, 255) };
597
+ },
598
+ embed: (d, inline) => ({
599
+ service: typeof d.service === "string" && /^[a-z0-9_-]{1,40}$/i.test(d.service) ? d.service : "",
600
+ source: sanitizeUrl(d.source, { schemes: ["https", "http"], allowRelative: false }),
601
+ embed: sanitizeUrl(d.embed, { schemes: ["https"], allowRelative: false }),
602
+ width: int(d.width, 1, 1e4, void 0),
603
+ height: int(d.height, 1, 1e4, void 0),
604
+ caption: inline(d.caption)
605
+ }),
606
+ personality: (d) => ({
607
+ name: plain(d.name, 500),
608
+ description: plain(d.description, 2e3),
609
+ link: sanitizeUrl(d.link, { schemes: ["http", "https", "mailto"] }),
610
+ photo: sanitizeUrl(d.photo, { schemes: ["http", "https"] })
611
+ }),
612
+ button: (d) => ({
613
+ text: plain(d.text, 200),
614
+ link: sanitizeUrl(d.link),
615
+ style: oneOf(d.style, ["primary", "secondary", "outline", "ghost", "danger", "success"], "primary"),
616
+ openInNewTab: bool(d.openInNewTab)
617
+ }),
618
+ delimiter: () => ({}),
619
+ // Synced block (2.3): only the reference to its source is stored; an invalid reference becomes ''.
620
+ synced: (d) => ({
621
+ ref: typeof d.ref === "string" && /^[a-z0-9]{1,64}$/.test(d.ref) ? d.ref : "",
622
+ _mex: BUILT_IN_MARKER_VERSION
623
+ }),
624
+ toc: (d) => {
625
+ const minLevel = int(d.minLevel, 1, 6, 2);
626
+ const maxLevel = int(d.maxLevel, 1, 6, 4);
627
+ return {
628
+ title: plain(d.title, 200),
629
+ minLevel: Math.min(minLevel, maxLevel),
630
+ maxLevel: Math.max(minLevel, maxLevel),
631
+ style: oneOf(d.style, ["ordered", "unordered"], "unordered"),
632
+ _mex: BUILT_IN_MARKER_VERSION
633
+ };
634
+ }
635
+ };
636
+ const isBuiltInBlock = (block) => {
637
+ if (!block || typeof block.type !== "string") return false;
638
+ if (!Object.prototype.hasOwnProperty.call(BLOCK_POLICIES, block.type)) return false;
639
+ if (!Object.prototype.hasOwnProperty.call(MARKED_BLOCKS, block.type)) return true;
640
+ return isMarkedBuiltIn(block.type, block.data);
641
+ };
642
+ const sanitizeTunes = (tunes) => {
643
+ if (!isPlainObject(tunes)) return void 0;
644
+ const out = {};
645
+ if (isPlainObject(tunes.alignmentTune)) {
646
+ out.alignmentTune = {
647
+ alignment: oneOf(tunes.alignmentTune.alignment, ["left", "center", "right", "justify"], "left")
648
+ };
649
+ }
650
+ if (typeof tunes.textVariant === "string") {
651
+ out.textVariant = oneOf(tunes.textVariant, ["", "call-out", "citation", "details"], "");
652
+ }
653
+ if (isPlainObject(tunes.indentTune)) {
654
+ out.indentTune = { indentLevel: int(tunes.indentTune.indentLevel, 0, 10, 0) };
655
+ }
656
+ return Object.keys(out).length ? out : void 0;
657
+ };
658
+ const registeredBlockOf = (block, explicit) => {
659
+ if (!block || typeof block.type !== "string" || isBuiltInBlock(block)) return null;
660
+ if (explicit instanceof Map) return explicit.get(block.type) || null;
661
+ return activeBlock(block.type);
662
+ };
663
+ const sanitizeEditorData = (data, options) => {
664
+ if (!data) return data;
665
+ const inline = (value) => typeof value === "string" ? options.sanitizeInlineHtml(value) : "";
666
+ const ctx = { rawHtml: options.rawHtml || "sanitize", rawSanitizer: options.sanitizeRawHtml };
667
+ const blocks = data.blocks.map((block) => {
668
+ const policy = isBuiltInBlock(block) ? BLOCK_POLICIES[block.type] : null;
669
+ const registered = policy ? null : registeredBlockOf(block, options.blocks);
670
+ const cleanData = policy ? policy(block.data || {}, inline, ctx) : registered ? registered.clean(block.data || {}, inline) : generic(block.data || {}, inline, 0);
671
+ for (const key of Object.keys(cleanData)) if (cleanData[key] === void 0) delete cleanData[key];
672
+ const out = { id: block.id, type: block.type, data: cleanData };
673
+ const tunes = sanitizeTunes(block.tunes);
674
+ if (tunes) out.tunes = tunes;
675
+ return out;
676
+ });
677
+ return { time: data.time, blocks, version: data.version };
678
+ };
679
+ const sanitizeTarget = (value) => typeof value === "string" && TARGETS.has(value) ? value : null;
680
+ const BLOCK_FIELD_TYPES = Object.freeze([
681
+ "text",
682
+ "inline",
683
+ "url",
684
+ "enum",
685
+ "number",
686
+ "boolean",
687
+ "array",
688
+ "object"
689
+ ]);
690
+ const BLOCK_LIMITS = Object.freeze({
691
+ /** Fields per object (also the schema root). */
692
+ maxFields: 50,
693
+ /** Nesting of arrays and objects below the root. */
694
+ maxDepth: 4,
695
+ /** Largest `max` of a text or inline field. */
696
+ maxText: 1e5,
697
+ /** Default `max` of a text field. */
698
+ defaultText: 1e3,
699
+ /** Default `max` of an inline HTML field. */
700
+ defaultInline: 1e4,
701
+ /** Largest `max` of an array field. */
702
+ maxItems: 500,
703
+ /** Default `max` of an array field. */
704
+ defaultItems: 50,
705
+ /** Values of an enum field. */
706
+ maxEnumValues: 100,
707
+ /** Values cleaned per block; later array items are dropped. */
708
+ maxValues: 2e4,
709
+ /** Length of a URL value. */
710
+ maxUrl: 2048
711
+ });
712
+ const BLOCK_PRESETS = Object.freeze(["article", "basic", "minimal"]);
713
+ const RESERVED_BLOCK_NAMES = Object.freeze([
714
+ "paragraph",
715
+ "header",
716
+ "list",
717
+ "checklist",
718
+ "quote",
719
+ "warning",
720
+ "alert",
721
+ "toggle",
722
+ "code",
723
+ "codeFlask",
724
+ "delimiter",
725
+ "toc",
726
+ "synced",
727
+ "table",
728
+ "embed",
729
+ "raw",
730
+ "image",
731
+ "simpleImage",
732
+ "gallery",
733
+ "video",
734
+ "audio",
735
+ "linkTool",
736
+ "attaches",
737
+ "personality",
738
+ "button",
739
+ "mediaLib",
740
+ "embeddedEntry",
741
+ "bold",
742
+ "italic",
743
+ "hyperlink",
744
+ "mention",
745
+ "marker",
746
+ "underline",
747
+ "strikethrough",
748
+ "inlineCode",
749
+ "tooltip",
750
+ "aiAssistant",
751
+ "alignmentTune",
752
+ "textVariant",
753
+ "indentTune"
754
+ ]);
755
+ const RESERVED = new Set(RESERVED_BLOCK_NAMES.map((name) => name.toLowerCase()));
756
+ const BLOCK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{1,49}$/;
757
+ const KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
758
+ const FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
759
+ const DEFINITION_KEYS = /* @__PURE__ */ new Set([
760
+ "name",
761
+ "version",
762
+ "title",
763
+ "description",
764
+ "schema",
765
+ "sanitize",
766
+ "text",
767
+ "markdown",
768
+ "render",
769
+ "presets"
770
+ ]);
771
+ const FIELD_KEYS = {
772
+ text: ["max", "multiline", "default"],
773
+ inline: ["max", "default"],
774
+ url: ["schemes", "relative"],
775
+ enum: ["values", "default"],
776
+ number: ["min", "max", "integer", "default"],
777
+ boolean: ["default"],
778
+ array: ["items", "max"],
779
+ object: ["fields"]
780
+ };
781
+ class BlockDefinitionError extends Error {
782
+ /**
783
+ * @param {string} message - Message naming the definition and the problem.
784
+ * @param {string} [code] - `INVALID_DEFINITION` | `RESERVED_NAME` | `NAME_TAKEN` | `REGISTRY_SEALED`.
785
+ */
786
+ constructor(message, code = "INVALID_DEFINITION") {
787
+ super(message);
788
+ this.name = "BlockDefinitionError";
789
+ this.code = code;
790
+ }
791
+ }
792
+ const isObject$1 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
793
+ const fail = (where, message) => {
794
+ throw new BlockDefinitionError(`Magic Editor X block ${where}: ${message}`);
795
+ };
796
+ const boundedInt = (value, min, max, fallback, where, key) => {
797
+ if (value === void 0) return fallback;
798
+ if (!Number.isInteger(value) || value < min || value > max)
799
+ fail(where, `"${key}" must be an integer from ${min} to ${max}`);
800
+ return value;
801
+ };
802
+ const normalizeField = (input2, where, depth) => {
803
+ if (!isObject$1(input2)) fail(where, 'a field must be an object with a "type"');
804
+ const type = input2.type;
805
+ if (!BLOCK_FIELD_TYPES.includes(type)) fail(where, `unknown field type ${JSON.stringify(type)}`);
806
+ for (const key of Object.keys(input2))
807
+ if (key !== "type" && key !== "label" && !FIELD_KEYS[type].includes(key))
808
+ fail(where, `unknown option "${key}" for a ${type} field`);
809
+ const out = { type };
810
+ if (input2.label !== void 0) {
811
+ if (typeof input2.label !== "string" || input2.label.length > 100)
812
+ fail(where, '"label" must be a string of at most 100 characters');
813
+ out.label = input2.label;
814
+ }
815
+ switch (type) {
816
+ case "text":
817
+ case "inline": {
818
+ out.max = boundedInt(
819
+ input2.max,
820
+ 1,
821
+ BLOCK_LIMITS.maxText,
822
+ type === "text" ? BLOCK_LIMITS.defaultText : BLOCK_LIMITS.defaultInline,
823
+ where,
824
+ "max"
825
+ );
826
+ if (input2.default !== void 0 && typeof input2.default !== "string")
827
+ fail(where, '"default" must be a string');
828
+ out.default = (input2.default || "").slice(0, out.max);
829
+ if (type === "text") {
830
+ if (input2.multiline !== void 0 && typeof input2.multiline !== "boolean")
831
+ fail(where, '"multiline" must be a boolean');
832
+ out.multiline = input2.multiline === true;
833
+ }
834
+ break;
835
+ }
836
+ case "url": {
837
+ const schemes = input2.schemes === void 0 ? ["http", "https"] : input2.schemes;
838
+ if (!Array.isArray(schemes) || !schemes.length || schemes.some((scheme) => !LINK_SCHEMES.includes(scheme)))
839
+ fail(where, `"schemes" must be a non-empty list of ${LINK_SCHEMES.join(", ")}`);
840
+ if (input2.relative !== void 0 && typeof input2.relative !== "boolean")
841
+ fail(where, '"relative" must be a boolean');
842
+ out.schemes = Object.freeze([...new Set(schemes)]);
843
+ out.relative = input2.relative !== false;
844
+ break;
845
+ }
846
+ case "enum": {
847
+ const values = input2.values;
848
+ 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)
849
+ fail(
850
+ where,
851
+ `"values" must be 1 to ${BLOCK_LIMITS.maxEnumValues} distinct strings (1-100 characters)`
852
+ );
853
+ out.values = Object.freeze([...values]);
854
+ if (input2.default !== void 0 && !values.includes(input2.default))
855
+ fail(where, '"default" must be one of "values"');
856
+ out.default = input2.default === void 0 ? values[0] : input2.default;
857
+ break;
858
+ }
859
+ case "number": {
860
+ for (const key of ["min", "max", "default"])
861
+ if (input2[key] !== void 0 && (typeof input2[key] !== "number" || !Number.isFinite(input2[key])))
862
+ fail(where, `"${key}" must be a finite number`);
863
+ if (input2.integer !== void 0 && typeof input2.integer !== "boolean")
864
+ fail(where, '"integer" must be a boolean');
865
+ out.integer = input2.integer === true;
866
+ out.min = input2.min === void 0 ? -Number.MAX_SAFE_INTEGER : input2.min;
867
+ out.max = input2.max === void 0 ? Number.MAX_SAFE_INTEGER : input2.max;
868
+ if (out.min > out.max) fail(where, '"min" must not be greater than "max"');
869
+ if (input2.default !== void 0) {
870
+ if (input2.default < out.min || input2.default > out.max || out.integer && !Number.isInteger(input2.default))
871
+ fail(where, '"default" must be a valid value of the field');
872
+ out.default = input2.default;
873
+ }
874
+ break;
875
+ }
876
+ case "boolean":
877
+ if (input2.default !== void 0 && typeof input2.default !== "boolean")
878
+ fail(where, '"default" must be a boolean');
879
+ out.default = input2.default === true;
880
+ break;
881
+ case "array":
882
+ if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
883
+ out.max = boundedInt(input2.max, 1, BLOCK_LIMITS.maxItems, BLOCK_LIMITS.defaultItems, where, "max");
884
+ out.items = normalizeField(input2.items, `${where}[]`, depth + 1);
885
+ break;
886
+ case "object":
887
+ if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
888
+ out.fields = normalizeFields(input2.fields, where, depth + 1);
889
+ break;
890
+ }
891
+ return Object.freeze(out);
892
+ };
893
+ const normalizeFields = (input2, where, depth) => {
894
+ if (!isObject$1(input2)) fail(where, '"fields" must be an object of field descriptors');
895
+ const keys = Object.keys(input2);
896
+ if (keys.length < 1 || keys.length > BLOCK_LIMITS.maxFields)
897
+ fail(where, `an object needs 1 to ${BLOCK_LIMITS.maxFields} fields`);
898
+ const out = /* @__PURE__ */ Object.create(null);
899
+ for (const key of keys) {
900
+ if (!KEY_PATTERN.test(key) || FORBIDDEN_KEYS.has(key))
901
+ fail(where, `field name ${JSON.stringify(key)} must match ${KEY_PATTERN}`);
902
+ out[key] = normalizeField(input2[key], `${where}.${key}`, depth);
903
+ }
904
+ return Object.freeze(out);
905
+ };
906
+ const blockNameProblem = (name) => {
907
+ if (typeof name !== "string" || !BLOCK_NAME_PATTERN.test(name))
908
+ return `the name must match ${BLOCK_NAME_PATTERN}`;
909
+ if (RESERVED.has(name.toLowerCase())) return `"${name}" is a built-in tool name`;
910
+ return null;
911
+ };
912
+ const defineBlock = (definition) => {
913
+ if (!isObject$1(definition))
914
+ throw new BlockDefinitionError("Magic Editor X block: the definition must be an object");
915
+ const label = typeof definition.name === "string" ? `"${definition.name.slice(0, 50)}"` : "(no name)";
916
+ for (const key of Object.keys(definition))
917
+ if (!DEFINITION_KEYS.has(key)) fail(label, `unknown key "${key}"`);
918
+ const problem = blockNameProblem(definition.name);
919
+ if (problem)
920
+ throw new BlockDefinitionError(
921
+ `Magic Editor X block ${label}: ${problem}`,
922
+ problem.includes("built-in") ? "RESERVED_NAME" : "INVALID_DEFINITION"
923
+ );
924
+ const out = {
925
+ name: definition.name,
926
+ version: boundedInt(definition.version, 1, 1e6, 1, label, "version")
927
+ };
928
+ for (const [key, max] of [
929
+ ["title", 100],
930
+ ["description", 500]
931
+ ]) {
932
+ if (definition[key] === void 0) continue;
933
+ if (typeof definition[key] !== "string" || definition[key].length > max)
934
+ fail(label, `"${key}" must be a string of at most ${max} characters`);
935
+ out[key] = definition[key];
936
+ }
937
+ out.schema = normalizeFields(definition.schema, `${label} schema`, 0);
938
+ for (const key of ["sanitize", "text", "markdown", "render"]) {
939
+ if (definition[key] === void 0) continue;
940
+ if (typeof definition[key] !== "function") fail(label, `"${key}" must be a function`);
941
+ out[key] = definition[key];
942
+ }
943
+ const presets = definition.presets === void 0 ? [] : definition.presets;
944
+ if (!Array.isArray(presets) || presets.some((preset) => !BLOCK_PRESETS.includes(preset)))
945
+ fail(label, `"presets" must list some of ${BLOCK_PRESETS.join(", ")}`);
946
+ out.presets = Object.freeze([...new Set(presets)]);
947
+ return Object.freeze(out);
948
+ };
949
+ const cleanValue = (field2, value, inline, budget) => {
950
+ budget.left -= 1;
951
+ switch (field2.type) {
952
+ case "text":
953
+ return typeof value === "string" ? value.slice(0, field2.max) : field2.default;
954
+ case "inline":
955
+ return inline(typeof value === "string" ? value.slice(0, field2.max) : field2.default);
956
+ case "url":
957
+ return typeof value === "string" ? sanitizeUrl(value.slice(0, BLOCK_LIMITS.maxUrl), {
958
+ schemes: field2.schemes,
959
+ allowRelative: field2.relative
960
+ }) : "";
961
+ case "enum":
962
+ return typeof value === "string" && field2.values.includes(value) ? value : field2.default;
963
+ case "number":
964
+ return typeof value === "number" && Number.isFinite(value) && value >= field2.min && value <= field2.max && (!field2.integer || Number.isInteger(value)) ? value : field2.default;
965
+ case "boolean":
966
+ return typeof value === "boolean" ? value : field2.default;
967
+ case "array": {
968
+ const out = [];
969
+ if (!Array.isArray(value)) return out;
970
+ for (const item of value) {
971
+ if (out.length >= field2.max || budget.left <= 0) break;
972
+ if (!matchesType(field2.items, item)) continue;
973
+ const clean = cleanValue(field2.items, item, inline, budget);
974
+ if (clean !== void 0) out.push(clean);
975
+ }
976
+ return out;
977
+ }
978
+ case "object":
979
+ return cleanObject(field2.fields, isObject$1(value) ? value : {}, inline, budget);
980
+ default:
981
+ return void 0;
982
+ }
983
+ };
984
+ const matchesType = (field2, item) => {
985
+ switch (field2.type) {
986
+ case "text":
987
+ case "inline":
988
+ case "url":
989
+ case "enum":
990
+ return typeof item === "string";
991
+ case "number":
992
+ return typeof item === "number";
993
+ case "boolean":
994
+ return typeof item === "boolean";
995
+ case "array":
996
+ return Array.isArray(item);
997
+ default:
998
+ return isObject$1(item);
999
+ }
1000
+ };
1001
+ const cleanObject = (fields, value, inline, budget) => {
1002
+ const out = {};
1003
+ for (const key of Object.keys(fields)) {
1004
+ const own = Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
1005
+ const clean = cleanValue(fields[key], own, inline, budget);
1006
+ if (clean !== void 0) out[key] = clean;
1007
+ }
1008
+ return out;
1009
+ };
1010
+ const eachLeaf = (fields, data, visit) => {
1011
+ const walk = (field2, value, path, depth) => {
1012
+ if (depth > BLOCK_LIMITS.maxDepth + 1) return;
1013
+ if (field2.type === "array") {
1014
+ if (!Array.isArray(value)) return;
1015
+ value.slice(0, field2.max).forEach((item, index2) => walk(field2.items, item, [...path, index2], depth + 1));
1016
+ } else if (field2.type === "object") {
1017
+ if (!isObject$1(value)) return;
1018
+ for (const key of Object.keys(field2.fields))
1019
+ if (Object.prototype.hasOwnProperty.call(value, key))
1020
+ walk(field2.fields[key], value[key], [...path, key], depth + 1);
1021
+ } else visit(field2, value, path);
1022
+ };
1023
+ if (!isObject$1(data)) return;
1024
+ for (const key of Object.keys(fields))
1025
+ if (Object.prototype.hasOwnProperty.call(data, key)) walk(fields[key], data[key], [key], 0);
1026
+ };
1027
+ const fieldAt = (fields, path) => {
1028
+ let current = { type: "object", fields };
1029
+ for (const part of String(path).split(".")) {
1030
+ if (!part) continue;
1031
+ if (current.type === "array") {
1032
+ if (/^\d+$/.test(part)) {
1033
+ current = current.items;
1034
+ continue;
1035
+ }
1036
+ return null;
1037
+ }
1038
+ if (current.type !== "object" || !Object.prototype.hasOwnProperty.call(current.fields, part)) return null;
1039
+ current = current.fields[part];
1040
+ }
1041
+ return current;
1042
+ };
1043
+ const compiled = /* @__PURE__ */ new WeakMap();
1044
+ const compileBlock = (definition) => {
1045
+ if (definition && typeof definition === "object" && compiled.has(definition))
1046
+ return compiled.get(definition);
1047
+ const def = defineBlock(definition && typeof definition === "object" ? { ...definition } : definition);
1048
+ const schema = def.schema;
1049
+ const run = (data, inline) => cleanObject(schema, isObject$1(data) ? data : {}, inline, { left: BLOCK_LIMITS.maxValues });
1050
+ const result = Object.freeze({
1051
+ ...def,
1052
+ /**
1053
+ * Cleans untrusted block data (unknown keys dropped, values bounded).
1054
+ * The optional `sanitize` hook runs on the clean data; its result is
1055
+ * cleaned again, so it cannot add keys or unsafe values. A hook that
1056
+ * throws is ignored (the clean data is used).
1057
+ * @param {unknown} data - Block data.
1058
+ * @param {(html: string) => string} inline - Inline HTML sanitiser of the caller.
1059
+ * @returns {object} Clean data.
1060
+ */
1061
+ clean: (data, inline) => {
1062
+ const first = run(data, inline);
1063
+ if (!def.sanitize) return first;
1064
+ let next;
1065
+ try {
1066
+ next = def.sanitize(copyData(first), { sanitizeUrl });
1067
+ } catch {
1068
+ return first;
1069
+ }
1070
+ return isObject$1(next) ? run(next, inline) : first;
1071
+ },
1072
+ /**
1073
+ * Text fields of the data in schema order: `{ path, kind, value }`
1074
+ * (`html` for inline fields, `plain` for text fields).
1075
+ * @param {unknown} data - Block data.
1076
+ * @returns {Array<{ path: Array<string|number>, kind: 'html'|'plain', value: string }>} Fields.
1077
+ */
1078
+ fields: (data) => {
1079
+ const out = [];
1080
+ eachLeaf(schema, data, (field2, value, path) => {
1081
+ if (typeof value !== "string") return;
1082
+ if (field2.type === "inline") out.push({ path, kind: "html", value });
1083
+ else if (field2.type === "text") out.push({ path, kind: "plain", value });
1084
+ });
1085
+ return out;
1086
+ },
1087
+ /**
1088
+ * Non-empty URL values: `{ path, value }`.
1089
+ * @param {unknown} data - Block data.
1090
+ * @returns {Array<{ path: Array<string|number>, value: string }>} URLs.
1091
+ */
1092
+ urls: (data) => {
1093
+ const out = [];
1094
+ eachLeaf(schema, data, (field2, value, path) => {
1095
+ if (field2.type === "url" && typeof value === "string" && value) out.push({ path, value });
1096
+ });
1097
+ return out;
1098
+ },
1099
+ /**
1100
+ * Kind of the value at a dotted path, for the version diff.
1101
+ * @param {string} path - Dotted path.
1102
+ * @returns {'inline'|'plain'|'value'} Kind.
1103
+ */
1104
+ kindOf: (path) => {
1105
+ const field2 = fieldAt(schema, path);
1106
+ if (!field2) return "value";
1107
+ if (field2.type === "inline") return "inline";
1108
+ if (field2.type === "text") return "plain";
1109
+ return "value";
1110
+ }
1111
+ });
1112
+ compiled.set(result, result);
1113
+ if (definition && typeof definition === "object") compiled.set(definition, result);
1114
+ return result;
1115
+ };
1116
+ const copyData = (value) => {
1117
+ if (Array.isArray(value)) return value.map(copyData);
1118
+ if (isObject$1(value)) {
1119
+ const out = {};
1120
+ for (const [key, child] of Object.entries(value)) out[key] = copyData(child);
1121
+ return out;
1122
+ }
1123
+ return value;
1124
+ };
1125
+ const listCache = /* @__PURE__ */ new WeakMap();
1126
+ const compileBlockList = (list) => {
1127
+ if (!Array.isArray(list)) return /* @__PURE__ */ new Map();
1128
+ if (listCache.has(list)) return listCache.get(list);
1129
+ const map = /* @__PURE__ */ new Map();
1130
+ for (const definition of list) {
1131
+ const def = compileBlock(definition);
1132
+ map.set(def.name, def);
1133
+ }
1134
+ listCache.set(list, map);
1135
+ return map;
1136
+ };
1137
+ const registerBlockDefinition = (definition) => {
1138
+ const compiled2 = compileBlock(definition);
1139
+ const existing = activeBlockIgnoringCase(compiled2.name);
1140
+ if (existing) {
1141
+ if (existing === compiled2) return compiled2;
1142
+ throw new BlockDefinitionError(
1143
+ `Magic Editor X block "${compiled2.name}": a block named "${existing.name}" is already registered`,
1144
+ "NAME_TAKEN"
1145
+ );
1146
+ }
1147
+ setActiveBlock(compiled2);
1148
+ return activeBlock(compiled2.name);
1149
+ };
1150
+ const LINK_SANITIZE = Object.freeze({
1151
+ href: true,
1152
+ target: true,
1153
+ rel: true,
1154
+ ...Object.fromEntries(INTERNAL_LINK_ATTRIBUTES.map((name) => [name, true]))
1155
+ });
1156
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
1157
+ const localized = (value, locale) => {
1158
+ if (typeof value === "string") return value;
1159
+ if (!isObject(value)) return "";
1160
+ const lang = String(locale || "en");
1161
+ const pick = value[lang] ?? value[lang.split("-")[0]] ?? value.en ?? Object.values(value)[0];
1162
+ return typeof pick === "string" ? pick : "";
1163
+ };
1164
+ const sanitizeRulesFor = (fields) => {
1165
+ const rule = (field2) => {
1166
+ if (field2.type === "inline")
1167
+ return {
1168
+ b: true,
1169
+ strong: true,
1170
+ i: true,
1171
+ em: true,
1172
+ u: { class: true },
1173
+ s: { class: true },
1174
+ mark: { class: true },
1175
+ code: { class: true },
1176
+ span: { class: true, "data-tooltip": true },
1177
+ sub: true,
1178
+ sup: true,
1179
+ br: true,
1180
+ a: LINK_SANITIZE
1181
+ };
1182
+ if (field2.type === "object") return sanitizeRulesFor(field2.fields);
1183
+ if (field2.type === "array") return rule(field2.items);
1184
+ return true;
1185
+ };
1186
+ const out = {};
1187
+ for (const [key, field2] of Object.entries(fields)) out[key] = rule(field2);
1188
+ return out;
1189
+ };
1190
+ const mergeCodeBlocks = (server, admin, locale) => {
1191
+ const rows = /* @__PURE__ */ new Map();
1192
+ for (const block of Array.isArray(server) ? server : []) {
1193
+ rows.set(block.name, {
1194
+ name: block.name,
1195
+ title: block.title || block.name,
1196
+ version: block.version,
1197
+ fields: Array.isArray(block.fields) ? block.fields : [],
1198
+ presets: Array.isArray(block.presets) ? block.presets : [],
1199
+ onServer: true,
1200
+ inAdmin: false
1201
+ });
1202
+ }
1203
+ for (const entry of admin) {
1204
+ const { definition } = entry;
1205
+ const current = rows.get(definition.name);
1206
+ const title = localized(entry.title, locale) || definition.title || definition.name;
1207
+ if (current) rows.set(definition.name, { ...current, title, inAdmin: true });
1208
+ else
1209
+ rows.set(definition.name, {
1210
+ name: definition.name,
1211
+ title,
1212
+ version: definition.version,
1213
+ fields: Object.entries(definition.schema).map(([key, field2]) => ({ key, type: field2.type })),
1214
+ presets: [...definition.presets],
1215
+ onServer: false,
1216
+ inAdmin: true
1217
+ });
1218
+ }
1219
+ return [...rows.values()].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
1220
+ };
1221
+ let purify = null;
1222
+ const instance = () => {
1223
+ if (purify) return purify;
1224
+ purify = createDOMPurify__default.default(window);
1225
+ purify.addHook("uponSanitizeAttribute", (node, data) => {
1226
+ const tag = node.nodeName.toLowerCase();
1227
+ if (data.attrName === "class") {
1228
+ const allowed = INLINE_CLASSES[tag] || [];
1229
+ const kept = String(data.attrValue).split(/\s+/).filter((name) => allowed.includes(name));
1230
+ if (kept.length === 0) data.keepAttr = false;
1231
+ else data.attrValue = kept.join(" ");
1232
+ }
1233
+ if (data.attrName === "href") {
1234
+ const safe = sanitizeUrl(data.attrValue);
1235
+ if (!safe) data.keepAttr = false;
1236
+ else data.attrValue = safe;
1237
+ }
1238
+ if (data.attrName === "target" && !["_blank", "_self", "_parent", "_top"].includes(data.attrValue))
1239
+ data.keepAttr = false;
1240
+ });
1241
+ purify.addHook("afterSanitizeAttributes", (node) => {
1242
+ if (node.nodeName === "A" && node.getAttribute("target") === "_blank")
1243
+ node.setAttribute("rel", "noopener noreferrer");
1244
+ if (typeof node.hasAttribute !== "function") return;
1245
+ if (!INTERNAL_LINK_ATTRIBUTES.some((name) => node.hasAttribute(name))) return;
1246
+ const kept = node.nodeName === "A" ? cleanInternalLinkAttributes(
1247
+ Object.fromEntries(INTERNAL_LINK_ATTRIBUTES.map((name) => [name, node.getAttribute(name)]))
1248
+ ) : {};
1249
+ for (const name of INTERNAL_LINK_ATTRIBUTES) {
1250
+ if (kept[name]) node.setAttribute(name, kept[name]);
1251
+ else node.removeAttribute(name);
1252
+ }
1253
+ });
1254
+ return purify;
1255
+ };
1256
+ const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat()));
1257
+ const sanitizeInline = (html) => instance().sanitize(String(html || ""), {
1258
+ ALLOWED_TAGS: [...INLINE_TAGS],
1259
+ ALLOWED_ATTR,
1260
+ ALLOW_DATA_ATTR: false,
1261
+ // DOMPurify checks attribute values like URIs; `api::article.article` looks
1262
+ // like an unknown scheme and was dropped, which removed the entry reference
1263
+ // of internal links whenever content was shown again. The values are
1264
+ // validated by cleanInternalLinkAttributes in the hook above.
1265
+ ADD_URI_SAFE_ATTR: [...INTERNAL_LINK_ATTRIBUTES]
1266
+ });
1267
+ const sanitizeTemplate = (html) => instance().sanitize(String(html || ""), {
1268
+ ALLOWED_TAGS: [
1269
+ "div",
1270
+ "span",
1271
+ "p",
1272
+ "h2",
1273
+ "h3",
1274
+ "h4",
1275
+ "strong",
1276
+ "b",
1277
+ "em",
1278
+ "i",
1279
+ "u",
1280
+ "s",
1281
+ "small",
1282
+ "br",
1283
+ "hr",
1284
+ "ul",
1285
+ "ol",
1286
+ "li",
1287
+ "blockquote",
1288
+ "figure",
1289
+ "figcaption",
1290
+ "img",
1291
+ "a",
1292
+ "section",
1293
+ "header",
1294
+ "footer",
1295
+ "code",
1296
+ "pre",
1297
+ "mark"
1298
+ ],
1299
+ ALLOWED_ATTR: [
1300
+ "class",
1301
+ "data-field",
1302
+ "title",
1303
+ "href",
1304
+ "target",
1305
+ "rel",
1306
+ "src",
1307
+ "alt",
1308
+ "width",
1309
+ "height",
1310
+ "loading"
1311
+ ],
1312
+ ALLOW_DATA_ATTR: false
1313
+ });
1314
+ const sanitizeSvg = (svg) => instance().sanitize(String(svg || ""), {
1315
+ USE_PROFILES: { svg: true, svgFilters: false },
1316
+ FORBID_TAGS: ["style", "use", "image", "foreignObject", "a", "script"],
1317
+ FORBID_ATTR: ["style", "href", "xlink:href"]
1318
+ });
1319
+ const prepareEditorValue = (value, rawHtml = "allow") => {
1320
+ try {
1321
+ const data = normalizeEditorData(value);
1322
+ if (!data) return { data: null, error: null };
1323
+ return {
1324
+ data: sanitizeEditorData(data, {
1325
+ sanitizeInlineHtml: sanitizeInline,
1326
+ sanitizeRawHtml: (html) => html,
1327
+ rawHtml
1328
+ }),
1329
+ error: null
1330
+ };
1331
+ } catch (error) {
1332
+ return { data: null, error: error && error.code || "INVALID" };
1333
+ }
1334
+ };
1335
+ const prepareRemoteData = (data, cache) => {
1336
+ const blocks = [];
1337
+ for (const block of data && data.blocks || []) {
1338
+ let clean = cache.get(block);
1339
+ if (clean === void 0) {
1340
+ const prepared = prepareEditorValue({ time: data.time, version: data.version, blocks: [block] }).data;
1341
+ clean = prepared && prepared.blocks.length === 1 ? prepared.blocks[0] : null;
1342
+ cache.set(block, clean);
1343
+ }
1344
+ if (clean) blocks.push(clean);
1345
+ }
1346
+ return { time: data && data.time || Date.now(), version: data && data.version || "2.31.7", blocks };
1347
+ };
1348
+ const el = (tag, options = {}) => {
1349
+ const node = document.createElement(tag);
1350
+ const classes = Array.isArray(options.className) ? options.className : [options.className];
1351
+ classes.filter(Boolean).forEach((name) => node.classList.add(name));
1352
+ if (options.text !== void 0) node.textContent = options.text;
1353
+ for (const [name, value] of Object.entries(options.attrs || {})) {
1354
+ if (value === false || value === null || value === void 0) continue;
1355
+ node.setAttribute(name, value === true ? "" : String(value));
1356
+ }
1357
+ (options.children || []).forEach((child) => child && node.appendChild(child));
1358
+ return node;
1359
+ };
1360
+ const field = (label, control) => {
1361
+ const id = `mex-${Math.random().toString(36).slice(2, 10)}`;
1362
+ control.id = id;
1363
+ const labelEl = el("label", { className: "mex-tool__label", text: label, attrs: { for: id } });
1364
+ return el("div", { className: "mex-tool__field", children: [labelEl, control] });
1365
+ };
1366
+ const input = ({ value = "", placeholder = "", type = "text", readOnly = false } = {}) => {
1367
+ const node = el("input", {
1368
+ className: "mex-tool__input",
1369
+ attrs: { type, placeholder, readonly: readOnly }
1370
+ });
1371
+ node.value = value;
1372
+ return node;
1373
+ };
1374
+ const select = (options, value) => {
1375
+ const node = el("select", { className: "mex-tool__select" });
1376
+ node.addEventListener("keydown", (event) => {
1377
+ if (event.key === "Enter") event.preventDefault();
1378
+ });
1379
+ for (const option of options) {
1380
+ const opt = el("option", { text: option.label, attrs: { value: option.value } });
1381
+ if (option.value === value) opt.selected = true;
1382
+ node.appendChild(opt);
1383
+ }
1384
+ return node;
1385
+ };
1386
+ const button = (label, options = {}) => {
1387
+ const node = el("button", {
1388
+ className: ["mex-tool__button", `mex-tool__button--${options.variant || "secondary"}`],
1389
+ attrs: { type: "button", "aria-label": options.ariaLabel }
1390
+ });
1391
+ if (options.icon) {
1392
+ const icon = el("span", { className: "mex-tool__button-icon", attrs: { "aria-hidden": "true" } });
1393
+ icon.innerHTML = options.icon;
1394
+ node.appendChild(icon);
1395
+ }
1396
+ if (label) node.appendChild(el("span", { text: label }));
1397
+ return node;
1398
+ };
1399
+ const editable = ({
1400
+ html = "",
1401
+ placeholder = "",
1402
+ readOnly = false,
1403
+ className = "",
1404
+ label = ""
1405
+ } = {}) => {
1406
+ const node = el("div", {
1407
+ className: ["mex-tool__editable", className],
1408
+ attrs: {
1409
+ contenteditable: readOnly ? "false" : "true",
1410
+ "data-placeholder": placeholder,
1411
+ role: readOnly ? null : "textbox",
1412
+ "aria-label": label || placeholder || null
1413
+ }
1414
+ });
1415
+ node.innerHTML = html;
1416
+ return node;
1417
+ };
1418
+ const ICONS = {
1419
+ alert: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 8v5m0 3h.01M10.3 3.9 2.8 17a2 2 0 0 0 1.7 3h15a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1420
+ toggle: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m9 6 6 6-6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1421
+ code: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m8 7-5 5 5 5m8-10 5 5-5 5m-3-12-2 14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1422
+ person: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="8" r="4" stroke="currentColor" stroke-width="2"/><path d="M4 21a8 8 0 0 1 16 0" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1423
+ image: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="4" width="18" height="16" rx="2" stroke="currentColor" stroke-width="2"/><circle cx="9" cy="10" r="2" stroke="currentColor" stroke-width="2"/><path d="m4 18 5-5 4 4 3-3 4 4" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
1424
+ gallery: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="3" width="8" height="8" rx="1.5" stroke="currentColor" stroke-width="2"/><rect x="13" y="3" width="8" height="8" rx="1.5" stroke="currentColor" stroke-width="2"/><rect x="3" y="13" width="8" height="8" rx="1.5" stroke="currentColor" stroke-width="2"/><rect x="13" y="13" width="8" height="8" rx="1.5" stroke="currentColor" stroke-width="2"/></svg>',
1425
+ video: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="5" width="14" height="14" rx="2" stroke="currentColor" stroke-width="2"/><path d="m16 10 6-3v10l-6-3" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
1426
+ audio: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M9 18V6l11-2v12" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><circle cx="6" cy="18" r="3" stroke="currentColor" stroke-width="2"/><circle cx="17" cy="16" r="3" stroke="currentColor" stroke-width="2"/></svg>',
1427
+ arrowLeft: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 12H5m6-6-6 6 6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1428
+ arrowRight: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5 12h14m-6-6 6 6-6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1429
+ delimiter: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 12h16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-dasharray="2 4"/></svg>',
1430
+ link: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10 14a4 4 0 0 0 6 0l3-3a4 4 0 0 0-6-6l-1 1m2 4a4 4 0 0 0-6 0l-3 3a4 4 0 0 0 6 6l1-1" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1431
+ button: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="7" width="18" height="10" rx="3" stroke="currentColor" stroke-width="2"/><path d="M8 12h8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1432
+ entry: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="3" width="18" height="18" rx="2" stroke="currentColor" stroke-width="2"/><path d="M7 8h10M7 12h10M7 16h6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1433
+ block: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="3" width="18" height="18" rx="2" stroke="currentColor" stroke-width="2"/><path d="M7 8h10M7 12h6M7 16h8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1434
+ media: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="6" width="16" height="14" rx="2" stroke="currentColor" stroke-width="2"/><path d="M6 6V4h16v13h-4" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="m3 18 4-4 3 3 3-3 4 4" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
1435
+ checklist: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m4 7 2 2 4-4M4 17l2 2 4-4M13 7h7M13 17h7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1436
+ marker: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m15 5 4 4L9 19H5v-4L15 5Z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
1437
+ underline: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7 4v7a5 5 0 0 0 10 0V4M5 20h14" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1438
+ strike: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 12h16M16 6.5C15.3 5 13.8 4 12 4 9.8 4 8 5.3 8 7.3c0 1.3.8 2.2 2 2.7m4 4c1.2.5 2 1.4 2 2.7 0 2-1.8 3.3-4 3.3-1.8 0-3.3-1-4-2.5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1439
+ tooltip: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 5h16v11H9l-5 4V5Z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
1440
+ sparkle: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 3v4m0 10v4M3 12h4m10 0h4M6 6l2 2m8 8 2 2M6 18l2-2m8-8 2-2" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1441
+ alignLeft: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h16M4 10h10M4 14h16M4 18h10" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1442
+ alignCenter: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h16M7 10h10M4 14h16M7 18h10" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1443
+ alignRight: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h16M10 10h10M4 14h16M10 18h10" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1444
+ alignJustify: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h16M4 10h16M4 14h16M4 18h16" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1445
+ variant: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5 5h14v14H5z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M9 9h6M9 13h4" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1446
+ check: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m5 12 5 5 9-10" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1447
+ plus: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 5v14M5 12h14" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1448
+ minus: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5 12h14" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
1449
+ upload: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 16V4m0 0-4 4m4-4 4 4M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1450
+ trash: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 7h16M9 7V4h6v3m-8 0 1 13h8l1-13" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
1451
+ border: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="4" y="4" width="16" height="16" rx="1" stroke="currentColor" stroke-width="2"/></svg>',
1452
+ background: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="4" y="4" width="16" height="16" rx="1" fill="currentColor" opacity=".3"/><rect x="8" y="8" width="8" height="8" stroke="currentColor" stroke-width="2"/></svg>',
1453
+ 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>',
1454
+ 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>',
1455
+ 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>',
1456
+ 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>'
1457
+ };
1458
+ const tools = /* @__PURE__ */ new Map();
1459
+ const registerBlock = (options) => {
1460
+ if (!isObject(options))
1461
+ throw new BlockDefinitionError("Magic Editor X registerBlock: pass { definition, tool }");
1462
+ const { definition, tool, title, icon, i18n, inlineToolbar, shortcut } = options;
1463
+ if (typeof tool !== "function")
1464
+ throw new BlockDefinitionError(
1465
+ 'Magic Editor X registerBlock: "tool" must be an Editor.js block tool class'
1466
+ );
1467
+ if (shortcut !== void 0 && (typeof shortcut !== "string" || !/^[A-Z0-9+]{1,40}$/.test(shortcut)))
1468
+ throw new BlockDefinitionError('Magic Editor X registerBlock: "shortcut" must look like CMD+SHIFT+K');
1469
+ const existing = tools.get(definition && definition.name);
1470
+ if (existing && existing.tool === tool && existing.source === definition) return existing.definition;
1471
+ const compiled2 = registerBlockDefinition(definition);
1472
+ tools.set(compiled2.name, {
1473
+ source: definition,
1474
+ definition: compiled2,
1475
+ tool,
1476
+ title: title === void 0 ? compiled2.title || compiled2.name : title,
1477
+ icon: typeof icon === "string" ? sanitizeSvg(icon) : "",
1478
+ i18n: isObject(i18n) ? i18n : {},
1479
+ inlineToolbar: inlineToolbar === true,
1480
+ shortcut
1481
+ });
1482
+ return compiled2;
1483
+ };
1484
+ const codeBlocks = () => [...tools.values()];
1485
+ const buildCodeBlockTools = (ctx) => {
1486
+ const out = {};
1487
+ for (const entry of tools.values()) {
1488
+ const { definition, tool: Tool } = entry;
1489
+ 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 : {};
1490
+ const rules = sanitizeRulesFor(definition.schema);
1491
+ const toolbox = {
1492
+ title: localized(entry.title, ctx.locale) || definition.name,
1493
+ icon: entry.icon || ICONS.block
1494
+ };
1495
+ const ownSanitize = Tool.sanitize && typeof Tool.sanitize === "object";
1496
+ const ownToolbox = Boolean(Tool.toolbox);
1497
+ const ToolClass = ownSanitize && ownToolbox ? Tool : class CodeBlockTool extends Tool {
1498
+ static get sanitize() {
1499
+ return ownSanitize ? Tool.sanitize : rules;
1500
+ }
1501
+ static get toolbox() {
1502
+ return ownToolbox ? Tool.toolbox : toolbox;
1503
+ }
1504
+ };
1505
+ out[definition.name] = {
1506
+ class: ToolClass,
1507
+ ...entry.inlineToolbar ? { inlineToolbar: ctx.inline } : {},
1508
+ ...entry.shortcut ? { shortcut: entry.shortcut } : {},
1509
+ toolbox,
1510
+ config: {
1511
+ ...ctx.shared,
1512
+ t: ctx.t,
1513
+ locale: ctx.locale || "en",
1514
+ definition,
1515
+ /** Message of the registration's `i18n` for the admin locale. */
1516
+ translate: (key, fallback) => typeof messages[key] === "string" ? messages[key] : fallback,
1517
+ /** Cleans data with the definition (inline HTML through the admin sanitiser). */
1518
+ clean: (data) => definition.clean(data, sanitizeInline)
1519
+ }
1520
+ };
1521
+ }
1522
+ return out;
1523
+ };
1524
+ const createReactTool = (Component, options = {}) => {
1525
+ if (typeof Component !== "function" && !(Component && typeof Component === "object"))
1526
+ throw new TypeError("Magic Editor X createReactTool: pass a React component");
1527
+ const className = typeof options.className === "string" ? options.className : "mex-code-block-tool";
1528
+ return class ReactBlockTool {
1529
+ static get isReadOnlySupported() {
1530
+ return true;
1531
+ }
1532
+ /**
1533
+ * @param {{ data: object, config: object, readOnly: boolean, block: object }} params - Editor.js tool parameters.
1534
+ */
1535
+ constructor({ data, config, readOnly, block }) {
1536
+ this.config = config || {};
1537
+ this.readOnly = Boolean(readOnly);
1538
+ this.blockApi = block;
1539
+ this.clean = typeof this.config.clean === "function" ? this.config.clean : (value) => value || {};
1540
+ this.data = this.clean(data);
1541
+ this.root = null;
1542
+ this.element = null;
1543
+ }
1544
+ /** @returns {HTMLElement} Block element with the mounted component. */
1545
+ render() {
1546
+ this.element = document.createElement("div");
1547
+ this.element.className = className;
1548
+ this.root = client.createRoot(this.element);
1549
+ this.paint();
1550
+ return this.element;
1551
+ }
1552
+ /** Renders the component with the current data. */
1553
+ paint() {
1554
+ if (!this.root) return;
1555
+ this.root.render(
1556
+ ReactNamespace.createElement(Component, {
1557
+ data: this.data,
1558
+ readOnly: this.readOnly,
1559
+ definition: this.config.definition,
1560
+ translate: this.config.translate || ((_key, fallback) => fallback),
1561
+ onChange: (next) => {
1562
+ if (this.readOnly) return;
1563
+ this.data = this.clean(next);
1564
+ this.paint();
1565
+ if (this.blockApi && typeof this.blockApi.dispatchChange === "function")
1566
+ this.blockApi.dispatchChange();
1567
+ }
1568
+ })
1569
+ );
1570
+ }
1571
+ /** @returns {object} Current data (cleaned again by the editor and the server). */
1572
+ save() {
1573
+ return this.data;
1574
+ }
1575
+ /** Unmounts the React root (deferred: Editor.js may call this while React renders). */
1576
+ destroy() {
1577
+ const root = this.root;
1578
+ this.root = null;
1579
+ if (root) setTimeout(() => root.unmount(), 0);
1580
+ }
1581
+ removed() {
1582
+ this.destroy();
1583
+ }
1584
+ };
1585
+ };
1586
+ const LOADERS = {
1587
+ en: () => [
1588
+ Promise.resolve().then(() => require("./en-CIZ5Ggod.js")),
1589
+ Promise.resolve().then(() => require("./en-CDg_18Bt.js")),
1590
+ Promise.resolve().then(() => require("./en-Ah-Cw0Wd.js")),
1591
+ Promise.resolve().then(() => require("./en-BkEjpC3i.js"))
1592
+ ],
1593
+ de: () => [
1594
+ Promise.resolve().then(() => require("./de-Dn8athM8.js")),
1595
+ Promise.resolve().then(() => require("./de-B1X46JJZ.js")),
1596
+ Promise.resolve().then(() => require("./de-2Ie5jy7j.js")),
1597
+ Promise.resolve().then(() => require("./de-C3AsGauQ.js"))
1598
+ ],
1599
+ fr: () => [
1600
+ Promise.resolve().then(() => require("./fr-Zkb8vfjN.js")),
1601
+ Promise.resolve().then(() => require("./fr-ZcN0yM_2.js")),
1602
+ Promise.resolve().then(() => require("./fr-OJ4VW1kh.js")),
1603
+ Promise.resolve().then(() => require("./fr-C2aLSwEu.js"))
1604
+ ],
1605
+ es: () => [
1606
+ Promise.resolve().then(() => require("./es-C4IRHV5d.js")),
1607
+ Promise.resolve().then(() => require("./es-BCpJmUEM.js")),
1608
+ Promise.resolve().then(() => require("./es-Cr8JH85N.js")),
1609
+ Promise.resolve().then(() => require("./es-C4pEnDRv.js"))
1610
+ ],
1611
+ pt: () => [
1612
+ Promise.resolve().then(() => require("./pt-1IUyx6ae.js")),
1613
+ Promise.resolve().then(() => require("./pt-CImqDnLB.js")),
1614
+ Promise.resolve().then(() => require("./pt-D0I0_JYs.js")),
1615
+ Promise.resolve().then(() => require("./pt-DX0OAIoL.js"))
1616
+ ]
1617
+ };
1618
+ const PRESET_OPTIONS = [
1619
+ { value: "full", label: ["field.options.preset.full", "Full: every block and formatting"] },
1620
+ { value: "article", label: ["field.options.preset.article", "Article: long-form text without raw HTML"] },
1621
+ { value: "basic", label: ["field.options.preset.basic", "Basic: headings 2-3, lists, quotes, images"] },
1622
+ {
1623
+ value: "minimal",
1624
+ label: ["field.options.preset.minimal", "Minimal: paragraphs, lists, bold, italic, links"]
1625
+ }
1626
+ ];
1627
+ const LINK_OPTIONS = [
1628
+ { value: "all", label: ["field.options.linkTargets.all", "Entries and web addresses"] },
1629
+ { value: "internal", label: ["field.options.linkTargets.internal", "Only entries of this site"] },
1630
+ { value: "external", label: ["field.options.linkTargets.external", "Only web addresses"] },
1631
+ { value: "none", label: ["field.options.linkTargets.none", "No links"] }
1632
+ ];
1633
+ const loadMessages = async (locale) => {
1634
+ const loader = LOADERS[locale] || LOADERS[locale.split("-")[0]] || LOADERS.en;
1635
+ const modules = await Promise.all(loader());
1636
+ const merged = Object.assign({}, ...modules.map((module2) => module2.default || module2));
1637
+ return Object.fromEntries(Object.entries(merged).map(([key, value]) => [getTranslation(key), value]));
1638
+ };
1639
+ const index = {
1640
+ /**
1641
+ * Registers the plugin, the custom field and the settings links.
1642
+ * @param {object} app - Strapi admin app.
1643
+ */
1644
+ register(app) {
1645
+ app.registerPlugin({ id: PLUGIN_ID, name: PLUGIN_ID, apis: { registerBlock, createReactTool } });
1646
+ app.customFields.register({
1647
+ name: "richtext",
1648
+ pluginId: PLUGIN_ID,
1649
+ type: "json",
1650
+ intlLabel: { id: getTranslation("field.label"), defaultMessage: "Magic Editor X" },
1651
+ intlDescription: {
1652
+ id: getTranslation("field.description"),
1653
+ defaultMessage: "Block editor with media, embeds, custom blocks, history and live collaboration"
1654
+ },
1655
+ icon: PluginIcon,
1656
+ components: {
1657
+ Input: () => Promise.resolve().then(() => require("./index-DQVE0ymw.js")).then((n) => n.index)
1658
+ },
1659
+ options: {
1660
+ base: [
1661
+ {
1662
+ sectionTitle: { id: getTranslation("field.options.section"), defaultMessage: "Editor" },
1663
+ items: [
1664
+ {
1665
+ intlLabel: {
1666
+ id: getTranslation("field.options.placeholder.label"),
1667
+ defaultMessage: "Placeholder"
1668
+ },
1669
+ description: {
1670
+ id: getTranslation("field.options.placeholder.description"),
1671
+ defaultMessage: "Text shown while the editor is empty"
1672
+ },
1673
+ name: "options.placeholder",
1674
+ type: "text"
1675
+ },
1676
+ {
1677
+ intlLabel: { id: getTranslation("field.options.preset.label"), defaultMessage: "Preset" },
1678
+ description: {
1679
+ id: getTranslation("field.options.preset.description"),
1680
+ defaultMessage: "Which blocks and formatting editors can use in this field. Enforced when saving."
1681
+ },
1682
+ name: "options.preset",
1683
+ type: "select",
1684
+ options: PRESET_OPTIONS.map(({ value, label: [id, defaultMessage] }) => ({
1685
+ key: value,
1686
+ value,
1687
+ metadatas: { intlLabel: { id: getTranslation(id), defaultMessage } }
1688
+ }))
1689
+ },
1690
+ {
1691
+ intlLabel: {
1692
+ id: getTranslation("field.options.linkTargets.label"),
1693
+ defaultMessage: "Allowed links"
1694
+ },
1695
+ description: {
1696
+ id: getTranslation("field.options.linkTargets.description"),
1697
+ defaultMessage: "Links to entries of this site, to web addresses, both or none"
1698
+ },
1699
+ name: "options.linkTargets",
1700
+ type: "select",
1701
+ options: LINK_OPTIONS.map(({ value, label: [id, defaultMessage] }) => ({
1702
+ key: value,
1703
+ value,
1704
+ metadatas: { intlLabel: { id: getTranslation(id), defaultMessage } }
1705
+ }))
1706
+ },
1707
+ {
1708
+ intlLabel: {
1709
+ id: getTranslation("field.options.requireAlt.label"),
1710
+ defaultMessage: "Require alternative text for images"
1711
+ },
1712
+ description: {
1713
+ id: getTranslation("field.options.requireAlt.description"),
1714
+ defaultMessage: "Images need a text description or must be marked as decorative"
1715
+ },
1716
+ name: "options.requireAlt",
1717
+ type: "checkbox"
1718
+ }
1719
+ ]
1720
+ }
1721
+ ],
1722
+ advanced: [
1723
+ {
1724
+ sectionTitle: {
1725
+ id: getTranslation("field.options.content"),
1726
+ defaultMessage: "Allowed content and limits"
1727
+ },
1728
+ items: [
1729
+ {
1730
+ intlLabel: {
1731
+ id: getTranslation("field.options.allowedBlocks.label"),
1732
+ defaultMessage: "Allowed blocks"
1733
+ },
1734
+ description: {
1735
+ id: getTranslation("field.options.allowedBlocks.description"),
1736
+ defaultMessage: "Comma-separated block names that replace the preset list, for example: paragraph, header, list, image, myCustomBlock"
1737
+ },
1738
+ name: "options.allowedBlocks",
1739
+ type: "text"
1740
+ },
1741
+ {
1742
+ intlLabel: {
1743
+ id: getTranslation("field.options.headingLevels.label"),
1744
+ defaultMessage: "Heading levels"
1745
+ },
1746
+ description: {
1747
+ id: getTranslation("field.options.headingLevels.description"),
1748
+ defaultMessage: "For example 2-4 or 2,3. Empty uses the preset."
1749
+ },
1750
+ name: "options.headingLevels",
1751
+ type: "text"
1752
+ },
1753
+ {
1754
+ intlLabel: {
1755
+ id: getTranslation("field.options.maxBlocks.label"),
1756
+ defaultMessage: "Maximum number of blocks"
1757
+ },
1758
+ description: {
1759
+ id: getTranslation("field.options.maxBlocks.description"),
1760
+ defaultMessage: "Empty or 0 means no limit"
1761
+ },
1762
+ name: "options.maxBlocks",
1763
+ type: "number"
1764
+ },
1765
+ {
1766
+ intlLabel: {
1767
+ id: getTranslation("field.options.maxCharacters.label"),
1768
+ defaultMessage: "Maximum number of characters"
1769
+ },
1770
+ description: {
1771
+ id: getTranslation("field.options.maxCharacters.description"),
1772
+ defaultMessage: "Visible text, counted like the editor toolbar. Empty or 0 means no limit."
1773
+ },
1774
+ name: "options.maxCharacters",
1775
+ type: "number"
1776
+ }
1777
+ ]
1778
+ },
1779
+ {
1780
+ sectionTitle: { id: getTranslation("field.options.features"), defaultMessage: "Features" },
1781
+ items: [
1782
+ {
1783
+ intlLabel: {
1784
+ id: getTranslation("field.options.disableAi.label"),
1785
+ defaultMessage: "Turn off the AI assistant for this field"
1786
+ },
1787
+ name: "options.disableAi",
1788
+ type: "checkbox"
1789
+ },
1790
+ {
1791
+ intlLabel: {
1792
+ id: getTranslation("field.options.disableGrammar.label"),
1793
+ defaultMessage: "Turn off the grammar check for this field"
1794
+ },
1795
+ description: {
1796
+ id: getTranslation("field.options.disableGrammar.description"),
1797
+ defaultMessage: "No text from this field is sent to LanguageTool"
1798
+ },
1799
+ name: "options.disableGrammar",
1800
+ type: "checkbox"
1801
+ },
1802
+ {
1803
+ intlLabel: {
1804
+ id: getTranslation("field.options.disableCollaboration.label"),
1805
+ defaultMessage: "Turn off live collaboration for this field"
1806
+ },
1807
+ name: "options.disableCollaboration",
1808
+ type: "checkbox"
1809
+ },
1810
+ {
1811
+ intlLabel: {
1812
+ id: getTranslation("field.options.publishGuard.label"),
1813
+ defaultMessage: "Block publishing while quality checks report errors"
1814
+ },
1815
+ description: {
1816
+ id: getTranslation("field.options.publishGuard.description"),
1817
+ defaultMessage: "Errors are missing alternative texts (when required) and empty links"
1818
+ },
1819
+ name: "options.publishGuard",
1820
+ type: "checkbox"
1821
+ }
1822
+ ]
1823
+ },
1824
+ {
1825
+ sectionTitle: { id: getTranslation("field.options.advanced"), defaultMessage: "Layout" },
1826
+ items: [
1827
+ {
1828
+ intlLabel: {
1829
+ id: getTranslation("field.options.minHeight.label"),
1830
+ defaultMessage: "Minimum height (px)"
1831
+ },
1832
+ description: {
1833
+ id: getTranslation("field.options.minHeight.description"),
1834
+ defaultMessage: "Height of the empty editor, between 120 and 2000 pixels"
1835
+ },
1836
+ name: "options.minHeight",
1837
+ type: "number"
1838
+ }
1839
+ ]
1840
+ }
1841
+ ]
1842
+ }
1843
+ });
1844
+ app.addSettingsLink(
1845
+ {
1846
+ id: PLUGIN_ID,
1847
+ intlLabel: { id: getTranslation("settings.section"), defaultMessage: "Magic Editor X" }
1848
+ },
1849
+ [
1850
+ {
1851
+ id: `${PLUGIN_ID}-configuration`,
1852
+ intlLabel: { id: getTranslation("settings.link.configuration"), defaultMessage: "Configuration" },
1853
+ to: `${PLUGIN_ID}/configuration`,
1854
+ permissions: PERMISSIONS.settingsRead,
1855
+ Component: () => Promise.resolve().then(() => require("./ConfigurationPage-CFP3lp9p.js"))
1856
+ },
1857
+ {
1858
+ id: `${PLUGIN_ID}-custom-blocks`,
1859
+ intlLabel: { id: getTranslation("settings.link.customBlocks"), defaultMessage: "Custom blocks" },
1860
+ to: `${PLUGIN_ID}/custom-blocks`,
1861
+ permissions: PERMISSIONS.customBlocksManage,
1862
+ Component: () => Promise.resolve().then(() => require("./CustomBlocksPage-DzPOSpfn.js"))
1863
+ },
1864
+ {
1865
+ id: `${PLUGIN_ID}-templates`,
1866
+ intlLabel: { id: getTranslation("settings.link.templates"), defaultMessage: "Templates" },
1867
+ to: `${PLUGIN_ID}/templates`,
1868
+ permissions: PERMISSIONS.templatesManage,
1869
+ Component: () => Promise.resolve().then(() => require("./TemplatesPage-BVkgafCK.js"))
1870
+ }
1871
+ ]
1872
+ );
1873
+ },
1874
+ bootstrap() {
1875
+ },
1876
+ /**
1877
+ * @param {{ locales: string[] }} options - Admin locales.
1878
+ * @returns {Promise<Array<{ data: object, locale: string }>>} Translations.
1879
+ */
1880
+ async registerTrads({ locales }) {
1881
+ return Promise.all(
1882
+ locales.map(async (locale) => {
1883
+ try {
1884
+ return { data: await loadMessages(locale), locale };
1885
+ } catch {
1886
+ return { data: {}, locale };
1887
+ }
1888
+ })
1889
+ );
1890
+ }
1891
+ };
1892
+ exports.BLOCK_POLICIES = BLOCK_POLICIES;
1893
+ exports.BUILT_IN_MARKER = BUILT_IN_MARKER;
1894
+ exports.BUILT_IN_MARKER_VERSION = BUILT_IN_MARKER_VERSION;
1895
+ exports.EDITOR_DATA_LIMITS = EDITOR_DATA_LIMITS;
1896
+ exports.ICONS = ICONS;
1897
+ exports.INLINE_ATTRIBUTES = INLINE_ATTRIBUTES;
1898
+ exports.INLINE_CLASSES = INLINE_CLASSES;
1899
+ exports.INLINE_TAGS = INLINE_TAGS;
1900
+ exports.INTERNAL_LINK_ATTRIBUTES = INTERNAL_LINK_ATTRIBUTES;
1901
+ exports.LINK_SCHEMES = LINK_SCHEMES;
1902
+ exports.MARKED_BLOCKS = MARKED_BLOCKS;
1903
+ exports.MAX_GALLERY_IMAGES = MAX_GALLERY_IMAGES;
1904
+ exports.MAX_MEDIA_TRACKS = MAX_MEDIA_TRACKS;
1905
+ exports.PERMISSIONS = PERMISSIONS;
1906
+ exports.TRACK_KINDS = TRACK_KINDS;
1907
+ exports.activeBlocks = activeBlocks;
1908
+ exports.buildCodeBlockTools = buildCodeBlockTools;
1909
+ exports.button = button;
1910
+ exports.byteLength = byteLength;
1911
+ exports.cleanFocalPoint = cleanFocalPoint;
1912
+ exports.cleanInternalLinkAttributes = cleanInternalLinkAttributes;
1913
+ exports.cleanMediaFile = cleanMediaFile;
1914
+ exports.cloneJsonSafe = cloneJsonSafe;
1915
+ exports.codeBlocks = codeBlocks;
1916
+ exports.compileBlockList = compileBlockList;
1917
+ exports.computeStats = computeStats;
1918
+ exports.editable = editable;
1919
+ exports.el = el;
1920
+ exports.escapeHtml = escapeHtml;
1921
+ exports.field = field;
1922
+ exports.getTranslation = getTranslation;
1923
+ exports.hashString = hashString;
1924
+ exports.index = index;
1925
+ exports.input = input;
1926
+ exports.isBuiltInBlock = isBuiltInBlock;
1927
+ exports.isMentionLink = isMentionLink;
1928
+ exports.isPlainObject = isPlainObject;
1929
+ exports.mergeCodeBlocks = mergeCodeBlocks;
1930
+ exports.normalizeEditorDataSafe = normalizeEditorDataSafe;
1931
+ exports.prepareEditorValue = prepareEditorValue;
1932
+ exports.prepareRemoteData = prepareRemoteData;
1933
+ exports.registeredBlockOf = registeredBlockOf;
1934
+ exports.sanitizeInline = sanitizeInline;
1935
+ exports.sanitizeSvg = sanitizeSvg;
1936
+ exports.sanitizeTarget = sanitizeTarget;
1937
+ exports.sanitizeTemplate = sanitizeTemplate;
1938
+ exports.sanitizeTunes = sanitizeTunes;
1939
+ exports.sanitizeUrl = sanitizeUrl;
1940
+ exports.select = select;