magic-editor-x 1.6.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +268 -0
- package/LICENSE +1 -7
- package/README.md +324 -981
- package/dist/admin/ConfigurationPage-B1uCIE3J.js +767 -0
- package/dist/admin/ConfigurationPage-DvAifELO.mjs +767 -0
- package/dist/admin/CustomBlocksPage-6-OQwpXQ.mjs +1741 -0
- package/dist/admin/CustomBlocksPage-6eWCOreU.js +1743 -0
- package/dist/admin/EditorField-DocyD2Q3.js +5506 -0
- package/dist/admin/EditorField-ThSoOCPm.mjs +5471 -0
- package/dist/admin/api-B-RsxJCs.js +34 -0
- package/dist/admin/api-C4XsDZxd.mjs +35 -0
- package/dist/admin/de-B8XFFhHh.js +95 -0
- package/dist/admin/de-BMxADn2Z.mjs +231 -0
- package/dist/admin/de-DBR893G4.js +13 -0
- package/dist/admin/de-DcDPRzV4.js +155 -0
- package/dist/admin/de-Dx7vUW0Z.js +231 -0
- package/dist/admin/de-RAxzvrwm.mjs +95 -0
- package/dist/admin/de-fBFh09Wl.mjs +13 -0
- package/dist/admin/de-n5V6c5RT.mjs +155 -0
- package/dist/admin/en-BQ5Pxe2o.mjs +231 -0
- package/dist/admin/en-BqNm3nMQ.mjs +155 -0
- package/dist/admin/en-BzfyifEU.mjs +95 -0
- package/dist/admin/en-D-DGftl0.js +155 -0
- package/dist/admin/en-D9Nfccux.mjs +13 -0
- package/dist/admin/en-DcWUTE2J.js +95 -0
- package/dist/admin/en-gueRT44P.js +13 -0
- package/dist/admin/en-sNn4z9lA.js +231 -0
- package/dist/admin/es-B0Zy8DVg.mjs +13 -0
- package/dist/admin/es-B6NYq0VH.mjs +231 -0
- package/dist/admin/es-BOtVc9qv.js +95 -0
- package/dist/admin/es-C2OJVYkV.mjs +95 -0
- package/dist/admin/es-DRGs7meF.js +13 -0
- package/dist/admin/es-DVsXnS0N.js +231 -0
- package/dist/admin/es-Di0pyQCh.js +155 -0
- package/dist/admin/es-SzeTV4q8.mjs +155 -0
- package/dist/admin/fr-B8rdLAIL.js +13 -0
- package/dist/admin/fr-Bpo5Uq1f.mjs +95 -0
- package/dist/admin/fr-D6F--jIB.js +155 -0
- package/dist/admin/fr-DfxKaOc_.js +95 -0
- package/dist/admin/fr-DhgPYHIH.mjs +155 -0
- package/dist/admin/fr-DmG3_Cn-.mjs +231 -0
- package/dist/admin/fr-Fwxcj4SM.js +231 -0
- package/dist/admin/fr-oiUb2bb_.mjs +13 -0
- package/dist/admin/index-CwfaB5-e.js +155 -0
- package/dist/admin/index-D1Q5Rlt6.mjs +156 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/pt-B3Jce6uT.mjs +13 -0
- package/dist/admin/pt-BPo0ex21.js +155 -0
- package/dist/admin/pt-BbdwHlWF.mjs +231 -0
- package/dist/admin/pt-BiWuSBcH.js +13 -0
- package/dist/admin/pt-BvSl1btT.mjs +155 -0
- package/dist/admin/pt-C6nr71Yw.js +231 -0
- package/dist/admin/pt-DqCXuI4S.mjs +95 -0
- package/dist/admin/pt-LCvjwk0y.js +95 -0
- package/dist/admin/sanitize-9UVcXFfc.js +552 -0
- package/dist/admin/sanitize-D4kfZ_ly.mjs +551 -0
- package/dist/admin/useT-B5M49wGH.js +130 -0
- package/dist/admin/useT-CjX6fL2m.mjs +131 -0
- package/dist/server/index.js +4150 -64739
- package/dist/server/index.mjs +4150 -64748
- package/package.json +90 -66
- package/strapi-admin.js +3 -0
- package/strapi-server.js +3 -0
- package/COPYRIGHT_NOTICE.txt +0 -20
- package/dist/admin/App-BwMEZnS-.mjs +0 -2144
- package/dist/admin/App-HNr2tizR.js +0 -2147
- package/dist/admin/CustomBlocksPage-BjcA7MGz.js +0 -1519
- package/dist/admin/CustomBlocksPage-COPOZ2-_.mjs +0 -1517
- package/dist/admin/LicensePage-D0DMTF41.mjs +0 -392
- package/dist/admin/LicensePage-D0_9yPkw.js +0 -394
- package/dist/admin/LiveCollaborationPanel-CZAbgAVr.js +0 -223
- package/dist/admin/LiveCollaborationPanel-D8z72afw.mjs +0 -221
- package/dist/admin/Settings-DRenvRcG.js +0 -441
- package/dist/admin/Settings-DjyNURlS.mjs +0 -439
- package/dist/admin/de-C_0Mj-Zo.mjs +0 -296
- package/dist/admin/de-DVNVpAt9.js +0 -296
- package/dist/admin/en-B7AAf1ie.mjs +0 -296
- package/dist/admin/en-C2hv5GsA.js +0 -296
- package/dist/admin/es-BzJqcIST.js +0 -274
- package/dist/admin/es-zdP8sd-f.mjs +0 -274
- package/dist/admin/fr-CtAgOgH1.mjs +0 -274
- package/dist/admin/fr-D3GwqAAJ.js +0 -274
- package/dist/admin/getTranslation-2OiEgVGt.mjs +0 -49459
- package/dist/admin/getTranslation-DQ_WJ-7M.js +0 -49475
- package/dist/admin/index-Bn2tfJrC.js +0 -2186
- package/dist/admin/index-DAtClhqy.js +0 -6956
- package/dist/admin/index-FVEbTfqO.mjs +0 -2187
- package/dist/admin/index-gjWl-6E2.mjs +0 -6934
- package/dist/admin/magic-editor-x.css +0 -1103
- package/dist/admin/pt-BmUw6YMP.mjs +0 -274
- package/dist/admin/pt-CFo0nTbj.js +0 -274
- package/dist/admin/tools-CzHTZaY_.mjs +0 -2268
- package/dist/admin/tools-DALFhvPO.js +0 -2299
- package/pics/collab-magiceditorX.png +0 -0
- package/pics/editorX.png +0 -0
- package/pics/liveCollabwidget1.png +0 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import createDOMPurify from "dompurify";
|
|
2
|
+
const EDITOR_DATA_LIMITS = Object.freeze({
|
|
3
|
+
maxBlocks: 5e3,
|
|
4
|
+
maxBytes: 5 * 1024 * 1024,
|
|
5
|
+
maxDepth: 24,
|
|
6
|
+
maxBlockIdLength: 64,
|
|
7
|
+
maxTypeLength: 64
|
|
8
|
+
});
|
|
9
|
+
const FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
10
|
+
const BLOCK_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
11
|
+
const BLOCK_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
12
|
+
const isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
13
|
+
class EditorDataError extends Error {
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} message - Fixed, non-sensitive message.
|
|
16
|
+
* @param {string} code - Machine-readable reason.
|
|
17
|
+
*/
|
|
18
|
+
constructor(message, code) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "EditorDataError";
|
|
21
|
+
this.code = code;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const cloneJsonSafe = (value, depth = 0) => {
|
|
25
|
+
if (depth > EDITOR_DATA_LIMITS.maxDepth) {
|
|
26
|
+
throw new EditorDataError("Editor content is nested too deeply", "TOO_DEEP");
|
|
27
|
+
}
|
|
28
|
+
if (value === null) return null;
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const item of value) {
|
|
32
|
+
const cloned = cloneJsonSafe(item, depth + 1);
|
|
33
|
+
out.push(cloned === void 0 ? null : cloned);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
switch (typeof value) {
|
|
38
|
+
case "string":
|
|
39
|
+
case "boolean":
|
|
40
|
+
return value;
|
|
41
|
+
case "number":
|
|
42
|
+
return Number.isFinite(value) ? value : null;
|
|
43
|
+
case "object": {
|
|
44
|
+
const out = {};
|
|
45
|
+
for (const key of Object.keys(value)) {
|
|
46
|
+
if (FORBIDDEN_KEYS.has(key)) continue;
|
|
47
|
+
const cloned = cloneJsonSafe(value[key], depth + 1);
|
|
48
|
+
if (cloned !== void 0) out[key] = cloned;
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
default:
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const tryParseJson = (text) => {
|
|
57
|
+
try {
|
|
58
|
+
return { ok: true, value: JSON.parse(text) };
|
|
59
|
+
} catch {
|
|
60
|
+
return { ok: false };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const escapeHtml = (text) => String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
64
|
+
const hashString = (text) => {
|
|
65
|
+
let hash = 2166136261;
|
|
66
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
67
|
+
hash ^= text.charCodeAt(i);
|
|
68
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
69
|
+
}
|
|
70
|
+
return hash.toString(16).padStart(8, "0");
|
|
71
|
+
};
|
|
72
|
+
const legacyBlockId = (index, type, data) => `mx${hashString(`${index}:${type}:${JSON.stringify(data)}`)}${index}`;
|
|
73
|
+
const textToBlocks = (text) => {
|
|
74
|
+
const trimmed = text.trim();
|
|
75
|
+
if (!trimmed) return [];
|
|
76
|
+
const looksLikeHtml = /<\/?[a-z][^>]{0,200}>/i.test(trimmed.slice(0, 2e3));
|
|
77
|
+
if (looksLikeHtml) {
|
|
78
|
+
return [{ type: "paragraph", data: { text: trimmed } }];
|
|
79
|
+
}
|
|
80
|
+
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>") } }));
|
|
81
|
+
};
|
|
82
|
+
const unwrapValue = (value) => {
|
|
83
|
+
let current = value;
|
|
84
|
+
let legacy = false;
|
|
85
|
+
for (let i = 0; i < 3 && typeof current === "string"; i += 1) {
|
|
86
|
+
const text = current.trim();
|
|
87
|
+
if (!text) return { candidate: null, legacy: true };
|
|
88
|
+
if (text.startsWith("{") || text.startsWith("[") || text.startsWith('"')) {
|
|
89
|
+
const parsed = tryParseJson(text);
|
|
90
|
+
if (parsed.ok) {
|
|
91
|
+
current = parsed.value;
|
|
92
|
+
legacy = true;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { candidate: { blocks: textToBlocks(text) }, legacy: true };
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(current)) {
|
|
99
|
+
return { candidate: { blocks: current }, legacy: true };
|
|
100
|
+
}
|
|
101
|
+
return { candidate: current, legacy };
|
|
102
|
+
};
|
|
103
|
+
const normalizeEditorData = (value) => {
|
|
104
|
+
if (value === null || value === void 0) return null;
|
|
105
|
+
if (typeof value === "string" && value.length > EDITOR_DATA_LIMITS.maxBytes) {
|
|
106
|
+
throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
|
|
107
|
+
}
|
|
108
|
+
const { candidate } = unwrapValue(value);
|
|
109
|
+
if (candidate === null || candidate === void 0) return null;
|
|
110
|
+
if (!isPlainObject(candidate)) {
|
|
111
|
+
throw new EditorDataError("Editor content must be an Editor.js object", "INVALID_SHAPE");
|
|
112
|
+
}
|
|
113
|
+
const clean = cloneJsonSafe(candidate);
|
|
114
|
+
const rawBlocks = Array.isArray(clean.blocks) ? clean.blocks : [];
|
|
115
|
+
if (rawBlocks.length > EDITOR_DATA_LIMITS.maxBlocks) {
|
|
116
|
+
throw new EditorDataError("Editor content has too many blocks", "TOO_MANY_BLOCKS");
|
|
117
|
+
}
|
|
118
|
+
const seen = /* @__PURE__ */ new Set();
|
|
119
|
+
const blocks = [];
|
|
120
|
+
rawBlocks.forEach((block, index) => {
|
|
121
|
+
if (!isPlainObject(block)) return;
|
|
122
|
+
const type = typeof block.type === "string" ? block.type.trim() : "";
|
|
123
|
+
if (!BLOCK_TYPE_PATTERN.test(type)) return;
|
|
124
|
+
const data = isPlainObject(block.data) ? block.data : {};
|
|
125
|
+
let id = typeof block.id === "string" && BLOCK_ID_PATTERN.test(block.id) ? block.id : "";
|
|
126
|
+
if (!id || seen.has(id)) id = legacyBlockId(index, type, data);
|
|
127
|
+
while (seen.has(id)) id = `${id}x`;
|
|
128
|
+
seen.add(id);
|
|
129
|
+
const normalized = { id, type, data };
|
|
130
|
+
if (isPlainObject(block.tunes) && Object.keys(block.tunes).length > 0) normalized.tunes = block.tunes;
|
|
131
|
+
blocks.push(normalized);
|
|
132
|
+
});
|
|
133
|
+
const time = Number.isFinite(clean.time) && clean.time > 0 ? Math.floor(clean.time) : 0;
|
|
134
|
+
const version = typeof clean.version === "string" && clean.version.length <= 32 ? clean.version : "2.31.7";
|
|
135
|
+
const result = { time, blocks, version };
|
|
136
|
+
const size = byteLength(JSON.stringify(result));
|
|
137
|
+
if (size > EDITOR_DATA_LIMITS.maxBytes) {
|
|
138
|
+
throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
};
|
|
142
|
+
const byteLength = (text) => {
|
|
143
|
+
let bytes = 0;
|
|
144
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
145
|
+
const code = text.charCodeAt(i);
|
|
146
|
+
if (code < 128) bytes += 1;
|
|
147
|
+
else if (code < 2048) bytes += 2;
|
|
148
|
+
else if (code >= 55296 && code <= 56319) {
|
|
149
|
+
bytes += 4;
|
|
150
|
+
i += 1;
|
|
151
|
+
} else bytes += 3;
|
|
152
|
+
}
|
|
153
|
+
return bytes;
|
|
154
|
+
};
|
|
155
|
+
const computeStats = (data) => {
|
|
156
|
+
if (!data || !Array.isArray(data.blocks)) return { blocks: 0, words: 0, characters: 0 };
|
|
157
|
+
let text = "";
|
|
158
|
+
const collect = (value, depth = 0) => {
|
|
159
|
+
if (depth > 8 || value === null || value === void 0) return;
|
|
160
|
+
if (typeof value === "string") {
|
|
161
|
+
text += ` ${value.replace(/<[^>]{0,500}>/g, " ").replace(/ /g, " ")}`;
|
|
162
|
+
} else if (Array.isArray(value)) value.forEach((item) => collect(item, depth + 1));
|
|
163
|
+
else if (typeof value === "object") {
|
|
164
|
+
for (const [key, item] of Object.entries(value)) {
|
|
165
|
+
if (["url", "link", "href", "src", "id", "documentId", "style", "type", "service"].includes(key))
|
|
166
|
+
continue;
|
|
167
|
+
collect(item, depth + 1);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
data.blocks.forEach((block) => collect(block.data));
|
|
172
|
+
const normalized = text.replace(/\s+/g, " ").trim();
|
|
173
|
+
return {
|
|
174
|
+
blocks: data.blocks.length,
|
|
175
|
+
words: normalized ? normalized.split(" ").length : 0,
|
|
176
|
+
characters: normalized.length
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
const INLINE_TAGS = Object.freeze([
|
|
180
|
+
"b",
|
|
181
|
+
"strong",
|
|
182
|
+
"i",
|
|
183
|
+
"em",
|
|
184
|
+
"u",
|
|
185
|
+
"s",
|
|
186
|
+
"mark",
|
|
187
|
+
"code",
|
|
188
|
+
"a",
|
|
189
|
+
"br",
|
|
190
|
+
"span",
|
|
191
|
+
"sub",
|
|
192
|
+
"sup"
|
|
193
|
+
]);
|
|
194
|
+
const INLINE_ATTRIBUTES = Object.freeze({
|
|
195
|
+
a: ["href", "target", "rel", "title"],
|
|
196
|
+
span: ["class", "data-tooltip"],
|
|
197
|
+
mark: ["class"],
|
|
198
|
+
u: ["class"],
|
|
199
|
+
s: ["class"],
|
|
200
|
+
code: ["class"]
|
|
201
|
+
});
|
|
202
|
+
const INLINE_CLASSES = Object.freeze({
|
|
203
|
+
span: ["cdx-tooltip"],
|
|
204
|
+
mark: ["cdx-marker"],
|
|
205
|
+
u: ["cdx-underline"],
|
|
206
|
+
s: ["cdx-strikethrough", "cdx-strikethroughs"],
|
|
207
|
+
code: ["inline-code"]
|
|
208
|
+
});
|
|
209
|
+
const LINK_SCHEMES = Object.freeze(["http", "https", "mailto", "tel"]);
|
|
210
|
+
const MAX_URL_LENGTH = 2048;
|
|
211
|
+
const sanitizeUrl = (value, options = {}) => {
|
|
212
|
+
const schemes = options.schemes || LINK_SCHEMES;
|
|
213
|
+
const allowRelative = options.allowRelative !== false;
|
|
214
|
+
if (typeof value !== "string") return "";
|
|
215
|
+
const url = value.trim();
|
|
216
|
+
if (!url || url.length > MAX_URL_LENGTH) return "";
|
|
217
|
+
if (/[\u0000-\u001f\u007f\s]/.test(url) && !/^(mailto|tel):/i.test(url)) return "";
|
|
218
|
+
if (url.startsWith("//") || url.startsWith("\\")) return "";
|
|
219
|
+
const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]{0,20}):/.exec(url);
|
|
220
|
+
if (!scheme) {
|
|
221
|
+
return allowRelative && /^[/#?.]/.test(url) ? url : "";
|
|
222
|
+
}
|
|
223
|
+
if (!schemes.includes(scheme[1].toLowerCase())) return "";
|
|
224
|
+
if (scheme[1].toLowerCase().startsWith("http")) {
|
|
225
|
+
try {
|
|
226
|
+
const parsed = new URL(url);
|
|
227
|
+
if (parsed.username || parsed.password) return "";
|
|
228
|
+
} catch {
|
|
229
|
+
return "";
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return url;
|
|
233
|
+
};
|
|
234
|
+
const plain = (value, max = 1e5) => typeof value === "string" ? value.slice(0, max) : "";
|
|
235
|
+
const oneOf = (value, allowed, fallback) => typeof value === "string" && allowed.includes(value) ? value : fallback;
|
|
236
|
+
const int = (value, min, max, fallback) => {
|
|
237
|
+
const number = typeof value === "string" ? Number(value) : value;
|
|
238
|
+
return Number.isInteger(number) && number >= min && number <= max ? number : fallback;
|
|
239
|
+
};
|
|
240
|
+
const bool = (value) => value === true;
|
|
241
|
+
const generic = (value, inline, depth = 0, key = "") => {
|
|
242
|
+
if (depth > 20) return null;
|
|
243
|
+
if (typeof value === "string") {
|
|
244
|
+
if (/^(url|href|link|src|photo|source|embed)$/i.test(key)) return sanitizeUrl(value);
|
|
245
|
+
return inline(value);
|
|
246
|
+
}
|
|
247
|
+
if (Array.isArray(value)) return value.map((item) => generic(item, inline, depth + 1, key));
|
|
248
|
+
if (isPlainObject(value)) {
|
|
249
|
+
const out = {};
|
|
250
|
+
for (const [childKey, child] of Object.entries(value))
|
|
251
|
+
out[childKey] = generic(child, inline, depth + 1, childKey);
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
return value;
|
|
255
|
+
};
|
|
256
|
+
const listItems = (items, inline, depth = 0) => {
|
|
257
|
+
if (!Array.isArray(items) || depth > 12) return [];
|
|
258
|
+
return items.map((item) => {
|
|
259
|
+
if (typeof item === "string") return inline(item);
|
|
260
|
+
if (!isPlainObject(item)) return { content: "", items: [] };
|
|
261
|
+
const out = { content: inline(typeof item.content === "string" ? item.content : plain(item.text)) };
|
|
262
|
+
if (isPlainObject(item.meta)) {
|
|
263
|
+
const meta = {};
|
|
264
|
+
if (typeof item.meta.checked === "boolean") meta.checked = item.meta.checked;
|
|
265
|
+
const start = int(item.meta.start, 0, 1e5, void 0);
|
|
266
|
+
if (start !== void 0) meta.start = start;
|
|
267
|
+
if (typeof item.meta.counterType === "string") {
|
|
268
|
+
meta.counterType = oneOf(
|
|
269
|
+
item.meta.counterType,
|
|
270
|
+
["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
|
|
271
|
+
"numeric"
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
out.meta = meta;
|
|
275
|
+
}
|
|
276
|
+
out.items = listItems(item.items, inline, depth + 1);
|
|
277
|
+
return out;
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
const BLOCK_POLICIES = {
|
|
281
|
+
paragraph: (d, inline) => ({ text: inline(d.text) }),
|
|
282
|
+
header: (d, inline) => ({ text: inline(d.text), level: int(d.level, 1, 6, 2) }),
|
|
283
|
+
quote: (d, inline) => ({
|
|
284
|
+
text: inline(d.text),
|
|
285
|
+
caption: inline(d.caption),
|
|
286
|
+
alignment: oneOf(d.alignment, ["left", "center"], "left")
|
|
287
|
+
}),
|
|
288
|
+
list: (d, inline) => {
|
|
289
|
+
const out = {
|
|
290
|
+
style: oneOf(d.style, ["ordered", "unordered", "checklist"], "unordered"),
|
|
291
|
+
items: listItems(d.items, inline)
|
|
292
|
+
};
|
|
293
|
+
if (isPlainObject(d.meta)) {
|
|
294
|
+
const meta = {};
|
|
295
|
+
const start = int(d.meta.start, 0, 1e5, void 0);
|
|
296
|
+
if (start !== void 0) meta.start = start;
|
|
297
|
+
if (typeof d.meta.counterType === "string") {
|
|
298
|
+
meta.counterType = oneOf(
|
|
299
|
+
d.meta.counterType,
|
|
300
|
+
["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
|
|
301
|
+
"numeric"
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
out.meta = meta;
|
|
305
|
+
}
|
|
306
|
+
return out;
|
|
307
|
+
},
|
|
308
|
+
checklist: (d, inline) => ({
|
|
309
|
+
items: Array.isArray(d.items) ? d.items.filter(isPlainObject).map((item) => ({ text: inline(item.text), checked: bool(item.checked) })) : []
|
|
310
|
+
}),
|
|
311
|
+
warning: (d, inline) => ({ title: inline(d.title), message: inline(d.message) }),
|
|
312
|
+
alert: (d, inline) => ({
|
|
313
|
+
type: oneOf(
|
|
314
|
+
d.type,
|
|
315
|
+
["primary", "secondary", "info", "success", "warning", "danger", "light", "dark"],
|
|
316
|
+
"info"
|
|
317
|
+
),
|
|
318
|
+
align: oneOf(d.align, ["left", "center", "right"], "left"),
|
|
319
|
+
message: inline(d.message)
|
|
320
|
+
}),
|
|
321
|
+
toggle: (d, inline) => ({
|
|
322
|
+
text: inline(d.text),
|
|
323
|
+
status: oneOf(d.status, ["open", "closed"], "open"),
|
|
324
|
+
fk: typeof d.fk === "string" ? d.fk.slice(0, 64) : void 0,
|
|
325
|
+
items: int(d.items, 0, 5e3, 0)
|
|
326
|
+
}),
|
|
327
|
+
code: (d) => ({ code: plain(d.code, 5e5) }),
|
|
328
|
+
codeFlask: (d) => {
|
|
329
|
+
const out = {
|
|
330
|
+
code: plain(d.code, 5e5),
|
|
331
|
+
language: /^[a-z0-9+#-]{1,32}$/i.test(d.language || "") ? d.language : "plaintext"
|
|
332
|
+
};
|
|
333
|
+
if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
|
|
334
|
+
return out;
|
|
335
|
+
},
|
|
336
|
+
raw: (d, _inline, ctx) => {
|
|
337
|
+
const html = plain(d.html, 5e5);
|
|
338
|
+
if (ctx.rawHtml === "allow") return { html };
|
|
339
|
+
if (ctx.rawHtml === "disable") return { html: "" };
|
|
340
|
+
return { html: ctx.rawSanitizer(html) };
|
|
341
|
+
},
|
|
342
|
+
table: (d, inline) => ({
|
|
343
|
+
withHeadings: bool(d.withHeadings),
|
|
344
|
+
stretched: bool(d.stretched),
|
|
345
|
+
content: Array.isArray(d.content) ? d.content.slice(0, 500).map((row) => Array.isArray(row) ? row.slice(0, 100).map((cell) => inline(cell)) : []) : []
|
|
346
|
+
}),
|
|
347
|
+
image: (d, inline) => {
|
|
348
|
+
const file = isPlainObject(d.file) ? d.file : {};
|
|
349
|
+
const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
|
|
350
|
+
for (const key of ["mime", "alt", "name", "hash", "ext"])
|
|
351
|
+
if (typeof file[key] === "string") cleanFile[key] = plain(file[key], 500);
|
|
352
|
+
for (const key of ["width", "height", "size"]) if (Number.isFinite(file[key])) cleanFile[key] = file[key];
|
|
353
|
+
if (isPlainObject(file.formats))
|
|
354
|
+
cleanFile.formats = generic(file.formats, (s) => plain(s, 2048), 0, "formats");
|
|
355
|
+
if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
|
|
356
|
+
cleanFile.id = file.id;
|
|
357
|
+
if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
|
|
358
|
+
return {
|
|
359
|
+
file: cleanFile,
|
|
360
|
+
caption: inline(d.caption),
|
|
361
|
+
withBorder: bool(d.withBorder),
|
|
362
|
+
withBackground: bool(d.withBackground),
|
|
363
|
+
stretched: bool(d.stretched)
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
simpleImage: (d, inline) => ({
|
|
367
|
+
url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
|
|
368
|
+
caption: inline(d.caption),
|
|
369
|
+
withBorder: bool(d.withBorder),
|
|
370
|
+
withBackground: bool(d.withBackground),
|
|
371
|
+
stretched: bool(d.stretched)
|
|
372
|
+
}),
|
|
373
|
+
linkTool: (d) => {
|
|
374
|
+
const meta = isPlainObject(d.meta) ? d.meta : {};
|
|
375
|
+
const image = isPlainObject(meta.image) ? { url: sanitizeUrl(meta.image.url, { schemes: ["http", "https"] }) } : void 0;
|
|
376
|
+
const cleanMeta = { title: plain(meta.title, 500), description: plain(meta.description, 2e3) };
|
|
377
|
+
if (typeof meta.site_name === "string") cleanMeta.site_name = plain(meta.site_name, 200);
|
|
378
|
+
if (image && image.url) cleanMeta.image = image;
|
|
379
|
+
return { link: sanitizeUrl(d.link, { schemes: ["http", "https"] }), meta: cleanMeta };
|
|
380
|
+
},
|
|
381
|
+
attaches: (d) => {
|
|
382
|
+
const file = isPlainObject(d.file) ? d.file : {};
|
|
383
|
+
const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
|
|
384
|
+
if (typeof file.name === "string") cleanFile.name = plain(file.name, 255);
|
|
385
|
+
if (typeof file.extension === "string") cleanFile.extension = plain(file.extension, 16);
|
|
386
|
+
if (Number.isFinite(file.size)) cleanFile.size = file.size;
|
|
387
|
+
if (typeof file.title === "string") cleanFile.title = plain(file.title, 255);
|
|
388
|
+
return { file: cleanFile, title: plain(d.title, 255) };
|
|
389
|
+
},
|
|
390
|
+
embed: (d, inline) => ({
|
|
391
|
+
service: /^[a-z0-9_-]{1,40}$/i.test(d.service || "") ? d.service : "",
|
|
392
|
+
source: sanitizeUrl(d.source, { schemes: ["https", "http"], allowRelative: false }),
|
|
393
|
+
embed: sanitizeUrl(d.embed, { schemes: ["https"], allowRelative: false }),
|
|
394
|
+
width: int(d.width, 1, 1e4, void 0),
|
|
395
|
+
height: int(d.height, 1, 1e4, void 0),
|
|
396
|
+
caption: inline(d.caption)
|
|
397
|
+
}),
|
|
398
|
+
personality: (d) => ({
|
|
399
|
+
name: plain(d.name, 500),
|
|
400
|
+
description: plain(d.description, 2e3),
|
|
401
|
+
link: sanitizeUrl(d.link, { schemes: ["http", "https", "mailto"] }),
|
|
402
|
+
photo: sanitizeUrl(d.photo, { schemes: ["http", "https"] })
|
|
403
|
+
}),
|
|
404
|
+
button: (d) => ({
|
|
405
|
+
text: plain(d.text, 200),
|
|
406
|
+
link: sanitizeUrl(d.link),
|
|
407
|
+
style: oneOf(d.style, ["primary", "secondary", "outline", "ghost", "danger", "success"], "primary"),
|
|
408
|
+
openInNewTab: bool(d.openInNewTab)
|
|
409
|
+
}),
|
|
410
|
+
delimiter: () => ({})
|
|
411
|
+
};
|
|
412
|
+
const sanitizeTunes = (tunes) => {
|
|
413
|
+
if (!isPlainObject(tunes)) return void 0;
|
|
414
|
+
const out = {};
|
|
415
|
+
if (isPlainObject(tunes.alignmentTune)) {
|
|
416
|
+
out.alignmentTune = {
|
|
417
|
+
alignment: oneOf(tunes.alignmentTune.alignment, ["left", "center", "right", "justify"], "left")
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
if (typeof tunes.textVariant === "string") {
|
|
421
|
+
out.textVariant = oneOf(tunes.textVariant, ["", "call-out", "citation", "details"], "");
|
|
422
|
+
}
|
|
423
|
+
if (isPlainObject(tunes.indentTune)) {
|
|
424
|
+
out.indentTune = { indentLevel: int(tunes.indentTune.indentLevel, 0, 10, 0) };
|
|
425
|
+
}
|
|
426
|
+
return Object.keys(out).length ? out : void 0;
|
|
427
|
+
};
|
|
428
|
+
const sanitizeEditorData = (data, options) => {
|
|
429
|
+
if (!data) return data;
|
|
430
|
+
const inline = (value) => typeof value === "string" ? options.sanitizeInlineHtml(value) : "";
|
|
431
|
+
const ctx = { rawHtml: options.rawHtml || "sanitize", rawSanitizer: options.sanitizeRawHtml };
|
|
432
|
+
const blocks = data.blocks.map((block) => {
|
|
433
|
+
const policy = Object.prototype.hasOwnProperty.call(BLOCK_POLICIES, block.type) ? BLOCK_POLICIES[block.type] : null;
|
|
434
|
+
const cleanData = policy ? policy(block.data || {}, inline, ctx) : generic(block.data || {}, inline, 0);
|
|
435
|
+
for (const key of Object.keys(cleanData)) if (cleanData[key] === void 0) delete cleanData[key];
|
|
436
|
+
const out = { id: block.id, type: block.type, data: cleanData };
|
|
437
|
+
const tunes = sanitizeTunes(block.tunes);
|
|
438
|
+
if (tunes) out.tunes = tunes;
|
|
439
|
+
return out;
|
|
440
|
+
});
|
|
441
|
+
return { time: data.time, blocks, version: data.version };
|
|
442
|
+
};
|
|
443
|
+
let purify = null;
|
|
444
|
+
const instance = () => {
|
|
445
|
+
if (purify) return purify;
|
|
446
|
+
purify = createDOMPurify(window);
|
|
447
|
+
purify.addHook("uponSanitizeAttribute", (node, data) => {
|
|
448
|
+
const tag = node.nodeName.toLowerCase();
|
|
449
|
+
if (data.attrName === "class") {
|
|
450
|
+
const allowed = INLINE_CLASSES[tag] || [];
|
|
451
|
+
const kept = String(data.attrValue).split(/\s+/).filter((name) => allowed.includes(name));
|
|
452
|
+
if (kept.length === 0) data.keepAttr = false;
|
|
453
|
+
else data.attrValue = kept.join(" ");
|
|
454
|
+
}
|
|
455
|
+
if (data.attrName === "href") {
|
|
456
|
+
const safe = sanitizeUrl(data.attrValue);
|
|
457
|
+
if (!safe) data.keepAttr = false;
|
|
458
|
+
else data.attrValue = safe;
|
|
459
|
+
}
|
|
460
|
+
if (data.attrName === "target" && !["_blank", "_self", "_parent", "_top"].includes(data.attrValue))
|
|
461
|
+
data.keepAttr = false;
|
|
462
|
+
});
|
|
463
|
+
purify.addHook("afterSanitizeAttributes", (node) => {
|
|
464
|
+
if (node.nodeName === "A" && node.getAttribute("target") === "_blank")
|
|
465
|
+
node.setAttribute("rel", "noopener noreferrer");
|
|
466
|
+
});
|
|
467
|
+
return purify;
|
|
468
|
+
};
|
|
469
|
+
const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat()));
|
|
470
|
+
const sanitizeInline = (html) => instance().sanitize(String(html || ""), {
|
|
471
|
+
ALLOWED_TAGS: [...INLINE_TAGS],
|
|
472
|
+
ALLOWED_ATTR,
|
|
473
|
+
ALLOW_DATA_ATTR: false
|
|
474
|
+
});
|
|
475
|
+
const sanitizeTemplate = (html) => instance().sanitize(String(html || ""), {
|
|
476
|
+
ALLOWED_TAGS: [
|
|
477
|
+
"div",
|
|
478
|
+
"span",
|
|
479
|
+
"p",
|
|
480
|
+
"h2",
|
|
481
|
+
"h3",
|
|
482
|
+
"h4",
|
|
483
|
+
"strong",
|
|
484
|
+
"b",
|
|
485
|
+
"em",
|
|
486
|
+
"i",
|
|
487
|
+
"u",
|
|
488
|
+
"s",
|
|
489
|
+
"small",
|
|
490
|
+
"br",
|
|
491
|
+
"hr",
|
|
492
|
+
"ul",
|
|
493
|
+
"ol",
|
|
494
|
+
"li",
|
|
495
|
+
"blockquote",
|
|
496
|
+
"figure",
|
|
497
|
+
"figcaption",
|
|
498
|
+
"img",
|
|
499
|
+
"a",
|
|
500
|
+
"section",
|
|
501
|
+
"header",
|
|
502
|
+
"footer",
|
|
503
|
+
"code",
|
|
504
|
+
"pre",
|
|
505
|
+
"mark"
|
|
506
|
+
],
|
|
507
|
+
ALLOWED_ATTR: [
|
|
508
|
+
"class",
|
|
509
|
+
"data-field",
|
|
510
|
+
"title",
|
|
511
|
+
"href",
|
|
512
|
+
"target",
|
|
513
|
+
"rel",
|
|
514
|
+
"src",
|
|
515
|
+
"alt",
|
|
516
|
+
"width",
|
|
517
|
+
"height",
|
|
518
|
+
"loading"
|
|
519
|
+
],
|
|
520
|
+
ALLOW_DATA_ATTR: false
|
|
521
|
+
});
|
|
522
|
+
const sanitizeSvg = (svg) => instance().sanitize(String(svg || ""), {
|
|
523
|
+
USE_PROFILES: { svg: true, svgFilters: false },
|
|
524
|
+
FORBID_TAGS: ["style", "use", "image", "foreignObject", "a", "script"],
|
|
525
|
+
FORBID_ATTR: ["style", "href", "xlink:href"]
|
|
526
|
+
});
|
|
527
|
+
const prepareEditorValue = (value, rawHtml = "allow") => {
|
|
528
|
+
try {
|
|
529
|
+
const data = normalizeEditorData(value);
|
|
530
|
+
if (!data) return { data: null, error: null };
|
|
531
|
+
return {
|
|
532
|
+
data: sanitizeEditorData(data, {
|
|
533
|
+
sanitizeInlineHtml: sanitizeInline,
|
|
534
|
+
sanitizeRawHtml: (html) => html,
|
|
535
|
+
rawHtml
|
|
536
|
+
}),
|
|
537
|
+
error: null
|
|
538
|
+
};
|
|
539
|
+
} catch (error) {
|
|
540
|
+
return { data: null, error: error && error.code || "INVALID" };
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
export {
|
|
544
|
+
sanitizeInline as a,
|
|
545
|
+
sanitizeSvg as b,
|
|
546
|
+
sanitizeTemplate as c,
|
|
547
|
+
computeStats as d,
|
|
548
|
+
isPlainObject as i,
|
|
549
|
+
prepareEditorValue as p,
|
|
550
|
+
sanitizeUrl as s
|
|
551
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const designSystem = require("@strapi/design-system");
|
|
5
|
+
const admin = require("@strapi/strapi/admin");
|
|
6
|
+
const reactIntl = require("react-intl");
|
|
7
|
+
const index = require("./index-CwfaB5-e.js");
|
|
8
|
+
const PageShell = ({
|
|
9
|
+
title,
|
|
10
|
+
subtitle,
|
|
11
|
+
primaryAction,
|
|
12
|
+
secondaryAction,
|
|
13
|
+
startActions,
|
|
14
|
+
endActions,
|
|
15
|
+
children
|
|
16
|
+
}) => {
|
|
17
|
+
const id = `mex-page-title-${react.useId().replace(/:/g, "")}`;
|
|
18
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { "aria-labelledby": id, children: [
|
|
19
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: title }),
|
|
20
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
21
|
+
admin.Layouts.Header,
|
|
22
|
+
{
|
|
23
|
+
id,
|
|
24
|
+
title,
|
|
25
|
+
subtitle,
|
|
26
|
+
primaryAction,
|
|
27
|
+
secondaryAction
|
|
28
|
+
}
|
|
29
|
+
),
|
|
30
|
+
startActions || endActions ? /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Action, { startActions, endActions }) : null,
|
|
31
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, paddingBottom: 8, minWidth: 0, children }) })
|
|
32
|
+
] });
|
|
33
|
+
};
|
|
34
|
+
const SectionCard = ({ title, subtitle, action, headingTag = "h2", children }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
35
|
+
designSystem.Box,
|
|
36
|
+
{
|
|
37
|
+
tag: "section",
|
|
38
|
+
background: "neutral0",
|
|
39
|
+
hasRadius: true,
|
|
40
|
+
shadow: "tableShadow",
|
|
41
|
+
padding: { initial: 4, medium: 6 },
|
|
42
|
+
minWidth: 0,
|
|
43
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
44
|
+
title || action ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "flex-start", gap: 4, wrap: "wrap", children: [
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, flex: "1 1 24rem", children: [
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: headingTag, textColor: "neutral800", children: title }),
|
|
47
|
+
subtitle ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: subtitle }) : null
|
|
48
|
+
] }),
|
|
49
|
+
action ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 2, wrap: "wrap", children: action }) : null
|
|
50
|
+
] }) : null,
|
|
51
|
+
children
|
|
52
|
+
] })
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
const canTakeFocus = (el) => Boolean(
|
|
56
|
+
el && el.isConnected && typeof el.focus === "function" && !el.disabled && (typeof el.getAttribute !== "function" || el.getAttribute("aria-disabled") !== "true")
|
|
57
|
+
);
|
|
58
|
+
const pickFocusTarget = (opener, fallback) => {
|
|
59
|
+
if (canTakeFocus(opener)) return opener;
|
|
60
|
+
if (canTakeFocus(fallback)) return fallback;
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
const refocusIfLost = (opener, fallback, doc = globalThis.document) => {
|
|
64
|
+
if (!doc) return;
|
|
65
|
+
const active = doc.activeElement;
|
|
66
|
+
if (active && active !== doc.body) return;
|
|
67
|
+
const target = pickFocusTarget(opener, fallback);
|
|
68
|
+
if (target) target.focus();
|
|
69
|
+
};
|
|
70
|
+
const ConfirmAction = ({
|
|
71
|
+
trigger,
|
|
72
|
+
title,
|
|
73
|
+
body,
|
|
74
|
+
confirmLabel,
|
|
75
|
+
onConfirm,
|
|
76
|
+
variant = "danger",
|
|
77
|
+
disabled = false,
|
|
78
|
+
fallbackFocusRef
|
|
79
|
+
}) => {
|
|
80
|
+
const [open, setOpen] = react.useState(false);
|
|
81
|
+
const [busy, setBusy] = react.useState(false);
|
|
82
|
+
const triggerRef = react.useRef(null);
|
|
83
|
+
const restoreFocus = () => requestAnimationFrame(() => {
|
|
84
|
+
const active = document.activeElement;
|
|
85
|
+
if (active && active !== document.body) return;
|
|
86
|
+
const target = pickFocusTarget(triggerRef.current, fallbackFocusRef && fallbackFocusRef.current);
|
|
87
|
+
if (target) target.focus();
|
|
88
|
+
});
|
|
89
|
+
const onOpenChange = (next) => {
|
|
90
|
+
if (busy) return;
|
|
91
|
+
setOpen(next);
|
|
92
|
+
if (!next) restoreFocus();
|
|
93
|
+
};
|
|
94
|
+
const confirm = async (event) => {
|
|
95
|
+
if (event && typeof event.preventDefault === "function") event.preventDefault();
|
|
96
|
+
setBusy(true);
|
|
97
|
+
try {
|
|
98
|
+
await onConfirm();
|
|
99
|
+
setOpen(false);
|
|
100
|
+
restoreFocus();
|
|
101
|
+
} catch {
|
|
102
|
+
} finally {
|
|
103
|
+
setBusy(false);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Root, { open, onOpenChange, children: [
|
|
107
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Trigger, { ref: triggerRef, disabled, children: trigger }),
|
|
108
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
109
|
+
admin.ConfirmDialog,
|
|
110
|
+
{
|
|
111
|
+
title,
|
|
112
|
+
variant,
|
|
113
|
+
endAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { fullWidth: true, variant, onClick: confirm, loading: busy, disabled: busy, children: confirmLabel }),
|
|
114
|
+
children: body
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
] });
|
|
118
|
+
};
|
|
119
|
+
const useT = () => {
|
|
120
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
121
|
+
return react.useCallback(
|
|
122
|
+
(id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values),
|
|
123
|
+
[formatMessage]
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
exports.ConfirmAction = ConfirmAction;
|
|
127
|
+
exports.PageShell = PageShell;
|
|
128
|
+
exports.SectionCard = SectionCard;
|
|
129
|
+
exports.refocusIfLost = refocusIfLost;
|
|
130
|
+
exports.useT = useT;
|