@notectl/core 0.0.2
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/dist/notectl-core.js +2205 -0
- package/dist/notectl-core.js.map +1 -0
- package/dist/notectl-core.umd.cjs +113 -0
- package/dist/notectl-core.umd.cjs.map +1 -0
- package/dist/types/index.d.ts +1090 -0
- package/package.json +57 -0
|
@@ -0,0 +1,2205 @@
|
|
|
1
|
+
class Xe {
|
|
2
|
+
constructor(t) {
|
|
3
|
+
this.nodes = new Map(t.nodes.map((e) => [e.type, e])), this.marks = new Map(t.marks.map((e) => [e.type, e])), this.topNode = t.topNode || "paragraph";
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Get node specification
|
|
7
|
+
*/
|
|
8
|
+
node(t) {
|
|
9
|
+
return this.nodes.get(t);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get mark specification
|
|
13
|
+
*/
|
|
14
|
+
mark(t) {
|
|
15
|
+
return this.marks.get(t);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validate if a node conforms to the schema
|
|
19
|
+
*/
|
|
20
|
+
validateNode(t) {
|
|
21
|
+
const e = [];
|
|
22
|
+
if ("text" in t) {
|
|
23
|
+
const i = t;
|
|
24
|
+
if (typeof i.text != "string" && e.push("Text node must have a string text property"), i.marks)
|
|
25
|
+
for (const o of i.marks)
|
|
26
|
+
this.marks.has(o.type) || e.push(`Unknown mark type: ${o.type}`);
|
|
27
|
+
} else {
|
|
28
|
+
const i = t, o = this.nodes.get(i.type);
|
|
29
|
+
if (!o)
|
|
30
|
+
return e.push(`Unknown node type: ${i.type}`), { valid: !1, errors: e };
|
|
31
|
+
if (o.attrs)
|
|
32
|
+
for (const [a, u] of Object.entries(o.attrs))
|
|
33
|
+
u.required && (!i.attrs || !(a in i.attrs)) && e.push(`Required attribute missing: ${a}`), i.attrs?.[a] && u.validate && (u.validate(i.attrs[a]) || e.push(`Invalid attribute value: ${a}`));
|
|
34
|
+
if (i.children)
|
|
35
|
+
for (const a of i.children) {
|
|
36
|
+
const u = this.validateNode(a);
|
|
37
|
+
e.push(...u.errors);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
valid: e.length === 0,
|
|
42
|
+
errors: e
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a mark is allowed on a node
|
|
47
|
+
*/
|
|
48
|
+
markAllowedOn(t, e) {
|
|
49
|
+
const i = this.nodes.get(e);
|
|
50
|
+
return !i || !i.marks ? !1 : i.marks === "_" ? !0 : i.marks.split(" ").includes(t);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if two marks can coexist
|
|
54
|
+
*/
|
|
55
|
+
marksCompatible(t, e) {
|
|
56
|
+
const i = this.marks.get(t), o = this.marks.get(e);
|
|
57
|
+
return !(i?.excludes && i.excludes.split(" ").includes(e) || o?.excludes && o.excludes.split(" ").includes(t));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function be() {
|
|
61
|
+
return new Xe({
|
|
62
|
+
nodes: [
|
|
63
|
+
{
|
|
64
|
+
type: "paragraph",
|
|
65
|
+
group: "block",
|
|
66
|
+
content: "inline*",
|
|
67
|
+
marks: "_"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: "heading",
|
|
71
|
+
group: "block",
|
|
72
|
+
content: "inline*",
|
|
73
|
+
marks: "_",
|
|
74
|
+
attrs: {
|
|
75
|
+
level: {
|
|
76
|
+
default: 1,
|
|
77
|
+
validate: (r) => typeof r == "number" && r >= 1 && r <= 6
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: "list",
|
|
83
|
+
group: "block",
|
|
84
|
+
content: "list_item+"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: "list_item",
|
|
88
|
+
content: "paragraph block*",
|
|
89
|
+
defining: !0
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: "table",
|
|
93
|
+
group: "block",
|
|
94
|
+
content: "table_row+",
|
|
95
|
+
isolating: !0
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: "table_row",
|
|
99
|
+
content: "table_cell+"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: "table_cell",
|
|
103
|
+
content: "block+",
|
|
104
|
+
isolating: !0
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
type: "image",
|
|
108
|
+
group: "inline",
|
|
109
|
+
attrs: {
|
|
110
|
+
src: { required: !0 },
|
|
111
|
+
alt: { default: "" },
|
|
112
|
+
decorative: { default: !1 }
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
type: "code_block",
|
|
117
|
+
group: "block",
|
|
118
|
+
content: "text*",
|
|
119
|
+
marks: ""
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: "text",
|
|
123
|
+
group: "inline"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
marks: [
|
|
127
|
+
{ type: "bold", excludes: "" },
|
|
128
|
+
{ type: "italic", excludes: "" },
|
|
129
|
+
{ type: "underline", excludes: "" },
|
|
130
|
+
{ type: "strikethrough", excludes: "" },
|
|
131
|
+
{ type: "code", excludes: "link" },
|
|
132
|
+
{
|
|
133
|
+
type: "link",
|
|
134
|
+
attrs: {
|
|
135
|
+
href: { required: !0 },
|
|
136
|
+
title: { default: "" }
|
|
137
|
+
},
|
|
138
|
+
excludes: "code"
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
topNode: "paragraph"
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function O() {
|
|
145
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (r) => {
|
|
146
|
+
const t = Math.random() * 16 | 0;
|
|
147
|
+
return (r === "x" ? t : t & 3 | 8).toString(16);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
class qe {
|
|
151
|
+
constructor(t) {
|
|
152
|
+
this.schema = t;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create a text node
|
|
156
|
+
*/
|
|
157
|
+
text(t, e) {
|
|
158
|
+
return {
|
|
159
|
+
type: "text",
|
|
160
|
+
text: t,
|
|
161
|
+
marks: e || []
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Create a paragraph node
|
|
166
|
+
*/
|
|
167
|
+
paragraph(t, e) {
|
|
168
|
+
return {
|
|
169
|
+
id: O(),
|
|
170
|
+
type: "paragraph",
|
|
171
|
+
attrs: e,
|
|
172
|
+
children: t || []
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Create a heading node
|
|
177
|
+
*/
|
|
178
|
+
heading(t, e, i) {
|
|
179
|
+
return {
|
|
180
|
+
id: O(),
|
|
181
|
+
type: "heading",
|
|
182
|
+
attrs: { ...i, level: t },
|
|
183
|
+
children: e || []
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create a list node
|
|
188
|
+
*/
|
|
189
|
+
list(t, e) {
|
|
190
|
+
return {
|
|
191
|
+
id: O(),
|
|
192
|
+
type: "list",
|
|
193
|
+
attrs: e,
|
|
194
|
+
children: t
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Create a list item node
|
|
199
|
+
*/
|
|
200
|
+
listItem(t, e) {
|
|
201
|
+
return {
|
|
202
|
+
id: O(),
|
|
203
|
+
type: "list_item",
|
|
204
|
+
attrs: e,
|
|
205
|
+
children: t
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create a table node
|
|
210
|
+
*/
|
|
211
|
+
table(t, e) {
|
|
212
|
+
return {
|
|
213
|
+
id: O(),
|
|
214
|
+
type: "table",
|
|
215
|
+
attrs: e,
|
|
216
|
+
children: t
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Create a table row node
|
|
221
|
+
*/
|
|
222
|
+
tableRow(t, e) {
|
|
223
|
+
return {
|
|
224
|
+
id: O(),
|
|
225
|
+
type: "table_row",
|
|
226
|
+
attrs: e,
|
|
227
|
+
children: t
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Create a table cell node
|
|
232
|
+
*/
|
|
233
|
+
tableCell(t, e) {
|
|
234
|
+
return {
|
|
235
|
+
id: O(),
|
|
236
|
+
type: "table_cell",
|
|
237
|
+
attrs: e,
|
|
238
|
+
children: t
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Create an image node
|
|
243
|
+
*/
|
|
244
|
+
image(t, e, i) {
|
|
245
|
+
return {
|
|
246
|
+
id: O(),
|
|
247
|
+
type: "image",
|
|
248
|
+
attrs: { src: t, alt: e || "", decorative: !e, ...i },
|
|
249
|
+
children: []
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Create a code block node
|
|
254
|
+
*/
|
|
255
|
+
codeBlock(t, e) {
|
|
256
|
+
return {
|
|
257
|
+
id: O(),
|
|
258
|
+
type: "code_block",
|
|
259
|
+
attrs: e,
|
|
260
|
+
children: [this.text(t)]
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Create a generic block node
|
|
265
|
+
*/
|
|
266
|
+
block(t, e, i) {
|
|
267
|
+
if (!this.schema.node(t))
|
|
268
|
+
throw new Error(`Unknown node type: ${t}`);
|
|
269
|
+
return {
|
|
270
|
+
id: O(),
|
|
271
|
+
type: t,
|
|
272
|
+
attrs: e,
|
|
273
|
+
children: i
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Create a mark
|
|
278
|
+
*/
|
|
279
|
+
mark(t, e) {
|
|
280
|
+
if (!this.schema.mark(t))
|
|
281
|
+
throw new Error(`Unknown mark type: ${t}`);
|
|
282
|
+
return {
|
|
283
|
+
type: t,
|
|
284
|
+
attrs: e
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Clone a node with new children
|
|
289
|
+
*/
|
|
290
|
+
cloneNode(t, e) {
|
|
291
|
+
return {
|
|
292
|
+
...t,
|
|
293
|
+
id: O(),
|
|
294
|
+
// Generate new ID for cloned node
|
|
295
|
+
children: e !== void 0 ? e : t.children
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function Ze(r) {
|
|
300
|
+
return new qe(r);
|
|
301
|
+
}
|
|
302
|
+
class it {
|
|
303
|
+
constructor(t, e, i) {
|
|
304
|
+
this.selection = null, this.history = [], this.historyIndex = -1, this.schema = e || be(), this.nodeFactory = Ze(this.schema), this.maxHistoryDepth = i?.maxHistoryDepth || 100, this.document = t || {
|
|
305
|
+
version: 0,
|
|
306
|
+
schemaVersion: "1.0.0",
|
|
307
|
+
children: [this.nodeFactory.paragraph()]
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Get current document
|
|
312
|
+
*/
|
|
313
|
+
getDocument() {
|
|
314
|
+
return this.document;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get document version
|
|
318
|
+
*/
|
|
319
|
+
getVersion() {
|
|
320
|
+
return this.document.version;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Get current selection
|
|
324
|
+
*/
|
|
325
|
+
getSelection() {
|
|
326
|
+
return this.selection;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Set selection
|
|
330
|
+
*/
|
|
331
|
+
setSelection(t) {
|
|
332
|
+
this.selection = t;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Apply a delta to the state
|
|
336
|
+
*/
|
|
337
|
+
applyDelta(t) {
|
|
338
|
+
if (t.baseVersion !== this.document.version)
|
|
339
|
+
throw new Error(
|
|
340
|
+
`Delta version mismatch: expected ${this.document.version}, got ${t.baseVersion}`
|
|
341
|
+
);
|
|
342
|
+
t.ops.some((i) => i.op !== "update_selection") && this.addToHistory(t);
|
|
343
|
+
for (const i of t.ops)
|
|
344
|
+
this.applyOperation(i);
|
|
345
|
+
this.document.version++;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Apply a single operation
|
|
349
|
+
*/
|
|
350
|
+
applyOperation(t) {
|
|
351
|
+
switch (t.op) {
|
|
352
|
+
case "insert_text":
|
|
353
|
+
this.applyInsertText(t);
|
|
354
|
+
break;
|
|
355
|
+
case "delete_range":
|
|
356
|
+
this.applyDeleteRange(t);
|
|
357
|
+
break;
|
|
358
|
+
case "apply_mark":
|
|
359
|
+
this.applyMark(t);
|
|
360
|
+
break;
|
|
361
|
+
case "insert_block_after":
|
|
362
|
+
this.applyInsertBlockAfter(t);
|
|
363
|
+
break;
|
|
364
|
+
case "insert_block_before":
|
|
365
|
+
this.applyInsertBlockBefore(t);
|
|
366
|
+
break;
|
|
367
|
+
case "delete_block":
|
|
368
|
+
this.applyDeleteBlock(t);
|
|
369
|
+
break;
|
|
370
|
+
case "set_attrs":
|
|
371
|
+
this.applySetAttrs(t);
|
|
372
|
+
break;
|
|
373
|
+
case "update_selection":
|
|
374
|
+
this.selection = {
|
|
375
|
+
anchor: t.selection.anchor,
|
|
376
|
+
head: t.selection.head
|
|
377
|
+
};
|
|
378
|
+
break;
|
|
379
|
+
// Table operations would be implemented here
|
|
380
|
+
default:
|
|
381
|
+
console.warn("Unhandled operation type:", t.op);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Apply insert text operation
|
|
386
|
+
*/
|
|
387
|
+
applyInsertText(t) {
|
|
388
|
+
const e = this.findBlock(t.target.blockId);
|
|
389
|
+
if (!e || !e.children) return;
|
|
390
|
+
const i = e.children.find((o) => "text" in o);
|
|
391
|
+
if (i) {
|
|
392
|
+
const o = i.text.slice(0, t.target.offset), a = i.text.slice(t.target.offset);
|
|
393
|
+
i.text = o + t.text + a, t.marks && t.marks.length > 0 && (i.marks = t.marks);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Apply delete range operation
|
|
398
|
+
*/
|
|
399
|
+
applyDeleteRange(t) {
|
|
400
|
+
const e = this.findBlock(t.range.start.blockId);
|
|
401
|
+
if (!e || !e.children) return;
|
|
402
|
+
const i = e.children.find((o) => "text" in o);
|
|
403
|
+
if (i) {
|
|
404
|
+
const o = i.text.slice(0, t.range.start.offset), a = i.text.slice(t.range.end.offset);
|
|
405
|
+
i.text = o + a;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Apply mark operation
|
|
410
|
+
*/
|
|
411
|
+
applyMark(t) {
|
|
412
|
+
const e = this.findBlock(t.range.start.blockId);
|
|
413
|
+
if (!e || !e.children) return;
|
|
414
|
+
const i = e.children.find((o) => "text" in o);
|
|
415
|
+
i && (t.add ? (i.marks = i.marks || [], i.marks.some((o) => o.type === t.mark.type) || i.marks.push(t.mark)) : i.marks = i.marks?.filter((o) => o.type !== t.mark.type));
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Apply insert block after operation
|
|
419
|
+
*/
|
|
420
|
+
applyInsertBlockAfter(t) {
|
|
421
|
+
const e = this.document.children.findIndex((i) => i.id === t.after);
|
|
422
|
+
e !== -1 && this.document.children.splice(e + 1, 0, t.block);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Apply insert block before operation
|
|
426
|
+
*/
|
|
427
|
+
applyInsertBlockBefore(t) {
|
|
428
|
+
const e = this.document.children.findIndex((i) => i.id === t.before);
|
|
429
|
+
e !== -1 && this.document.children.splice(e, 0, t.block);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Apply delete block operation
|
|
433
|
+
*/
|
|
434
|
+
applyDeleteBlock(t) {
|
|
435
|
+
const e = this.document.children.findIndex((i) => i.id === t.target.blockId);
|
|
436
|
+
e !== -1 && this.document.children.splice(e, 1);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Apply set attributes operation
|
|
440
|
+
*/
|
|
441
|
+
applySetAttrs(t) {
|
|
442
|
+
const e = this.findBlock(t.target.blockId);
|
|
443
|
+
e && (e.attrs = { ...e.attrs, ...t.attrs });
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Find a block by ID
|
|
447
|
+
*/
|
|
448
|
+
findBlock(t) {
|
|
449
|
+
const e = (i) => {
|
|
450
|
+
for (const o of i) {
|
|
451
|
+
if (o.id === t)
|
|
452
|
+
return o;
|
|
453
|
+
if (o.children) {
|
|
454
|
+
const a = o.children.filter((h) => "id" in h), u = e(a);
|
|
455
|
+
if (u) return u;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
return e(this.document.children);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Add delta to history
|
|
463
|
+
*/
|
|
464
|
+
addToHistory(t) {
|
|
465
|
+
this.historyIndex < this.history.length - 1 && (this.history = this.history.slice(0, this.historyIndex + 1)), this.history.push({
|
|
466
|
+
delta: t,
|
|
467
|
+
inverseOps: t.inverseOps || [],
|
|
468
|
+
timestamp: Date.now()
|
|
469
|
+
}), this.history.length > this.maxHistoryDepth ? this.history.shift() : this.historyIndex++;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Undo last change
|
|
473
|
+
*/
|
|
474
|
+
canUndo() {
|
|
475
|
+
return this.historyIndex >= 0;
|
|
476
|
+
}
|
|
477
|
+
undo() {
|
|
478
|
+
if (!this.canUndo()) return null;
|
|
479
|
+
const t = this.history[this.historyIndex];
|
|
480
|
+
return this.historyIndex--, {
|
|
481
|
+
txnId: `undo-${t.delta.txnId}`,
|
|
482
|
+
clientId: t.delta.clientId,
|
|
483
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
484
|
+
baseVersion: this.document.version,
|
|
485
|
+
ltime: Date.now(),
|
|
486
|
+
intent: "edit",
|
|
487
|
+
ops: t.inverseOps
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Redo last undone change
|
|
492
|
+
*/
|
|
493
|
+
canRedo() {
|
|
494
|
+
return this.historyIndex < this.history.length - 1;
|
|
495
|
+
}
|
|
496
|
+
redo() {
|
|
497
|
+
return this.canRedo() ? (this.historyIndex++, this.history[this.historyIndex].delta) : null;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Export state as JSON
|
|
501
|
+
*/
|
|
502
|
+
toJSON() {
|
|
503
|
+
return this.document;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Create state from JSON
|
|
507
|
+
*/
|
|
508
|
+
static fromJSON(t, e) {
|
|
509
|
+
return new it(t, e);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
class Je {
|
|
513
|
+
constructor() {
|
|
514
|
+
this.plugins = /* @__PURE__ */ new Map(), this.initializationOrder = [];
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Register a plugin
|
|
518
|
+
*/
|
|
519
|
+
async register(t, e) {
|
|
520
|
+
if (this.plugins.has(t.id))
|
|
521
|
+
throw new Error(`Plugin ${t.id} is already registered`);
|
|
522
|
+
if (t.dependencies) {
|
|
523
|
+
for (const i of t.dependencies)
|
|
524
|
+
if (!this.plugins.has(i))
|
|
525
|
+
throw new Error(`Plugin ${t.id} depends on ${i} which is not registered`);
|
|
526
|
+
}
|
|
527
|
+
await t.init(e), this.plugins.set(t.id, t), this.initializationOrder.push(t.id), e.emit("plugin-registered", { pluginId: t.id, plugin: t });
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Unregister a plugin
|
|
531
|
+
*/
|
|
532
|
+
async unregister(t, e) {
|
|
533
|
+
const i = this.plugins.get(t);
|
|
534
|
+
if (!i)
|
|
535
|
+
throw new Error(`Plugin ${t} is not registered`);
|
|
536
|
+
for (const [o, a] of this.plugins.entries())
|
|
537
|
+
if (a.dependencies?.includes(t))
|
|
538
|
+
throw new Error(`Cannot unregister ${t}: plugin ${o} depends on it`);
|
|
539
|
+
i.destroy && await i.destroy(), this.plugins.delete(t), this.initializationOrder = this.initializationOrder.filter((o) => o !== t), e.emit("plugin-unregistered", { pluginId: t });
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Get a plugin by ID
|
|
543
|
+
*/
|
|
544
|
+
get(t) {
|
|
545
|
+
return this.plugins.get(t);
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Check if a plugin is registered
|
|
549
|
+
*/
|
|
550
|
+
has(t) {
|
|
551
|
+
return this.plugins.has(t);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Get all registered plugins
|
|
555
|
+
*/
|
|
556
|
+
getAll() {
|
|
557
|
+
return this.initializationOrder.map((t) => this.plugins.get(t));
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Notify plugins of state update
|
|
561
|
+
*/
|
|
562
|
+
notifyStateUpdate(t, e) {
|
|
563
|
+
for (const i of this.initializationOrder) {
|
|
564
|
+
const o = this.plugins.get(i);
|
|
565
|
+
if (o?.onStateUpdate)
|
|
566
|
+
try {
|
|
567
|
+
o.onStateUpdate(t, e);
|
|
568
|
+
} catch (a) {
|
|
569
|
+
console.error(`Error in plugin ${i} onStateUpdate:`, a);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Notify plugins of delta application
|
|
575
|
+
*/
|
|
576
|
+
notifyDeltaApplied(t) {
|
|
577
|
+
for (const e of this.initializationOrder) {
|
|
578
|
+
const i = this.plugins.get(e);
|
|
579
|
+
if (i?.onDeltaApplied)
|
|
580
|
+
try {
|
|
581
|
+
i.onDeltaApplied(t);
|
|
582
|
+
} catch (o) {
|
|
583
|
+
console.error(`Error in plugin ${e} onDeltaApplied:`, o);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Destroy all plugins
|
|
589
|
+
*/
|
|
590
|
+
async destroyAll() {
|
|
591
|
+
const t = [...this.initializationOrder].reverse();
|
|
592
|
+
for (const e of t) {
|
|
593
|
+
const i = this.plugins.get(e);
|
|
594
|
+
if (i?.destroy)
|
|
595
|
+
try {
|
|
596
|
+
await i.destroy();
|
|
597
|
+
} catch (o) {
|
|
598
|
+
console.error(`Error destroying plugin ${e}:`, o);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
this.plugins.clear(), this.initializationOrder = [];
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
/*! @license DOMPurify 3.2.7 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.7/LICENSE */
|
|
605
|
+
const {
|
|
606
|
+
entries: _e,
|
|
607
|
+
setPrototypeOf: he,
|
|
608
|
+
isFrozen: Qe,
|
|
609
|
+
getPrototypeOf: tn,
|
|
610
|
+
getOwnPropertyDescriptor: en
|
|
611
|
+
} = Object;
|
|
612
|
+
let {
|
|
613
|
+
freeze: k,
|
|
614
|
+
seal: w,
|
|
615
|
+
create: xe
|
|
616
|
+
} = Object, {
|
|
617
|
+
apply: Ft,
|
|
618
|
+
construct: zt
|
|
619
|
+
} = typeof Reflect < "u" && Reflect;
|
|
620
|
+
k || (k = function(t) {
|
|
621
|
+
return t;
|
|
622
|
+
});
|
|
623
|
+
w || (w = function(t) {
|
|
624
|
+
return t;
|
|
625
|
+
});
|
|
626
|
+
Ft || (Ft = function(t, e) {
|
|
627
|
+
for (var i = arguments.length, o = new Array(i > 2 ? i - 2 : 0), a = 2; a < i; a++)
|
|
628
|
+
o[a - 2] = arguments[a];
|
|
629
|
+
return t.apply(e, o);
|
|
630
|
+
});
|
|
631
|
+
zt || (zt = function(t) {
|
|
632
|
+
for (var e = arguments.length, i = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
|
|
633
|
+
i[o - 1] = arguments[o];
|
|
634
|
+
return new t(...i);
|
|
635
|
+
});
|
|
636
|
+
const mt = L(Array.prototype.forEach), nn = L(Array.prototype.lastIndexOf), fe = L(Array.prototype.pop), J = L(Array.prototype.push), rn = L(Array.prototype.splice), yt = L(String.prototype.toLowerCase), vt = L(String.prototype.toString), Dt = L(String.prototype.match), Q = L(String.prototype.replace), on = L(String.prototype.indexOf), sn = L(String.prototype.trim), N = L(Object.prototype.hasOwnProperty), A = L(RegExp.prototype.test), tt = an(TypeError);
|
|
637
|
+
function L(r) {
|
|
638
|
+
return function(t) {
|
|
639
|
+
t instanceof RegExp && (t.lastIndex = 0);
|
|
640
|
+
for (var e = arguments.length, i = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
|
|
641
|
+
i[o - 1] = arguments[o];
|
|
642
|
+
return Ft(r, t, i);
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
function an(r) {
|
|
646
|
+
return function() {
|
|
647
|
+
for (var t = arguments.length, e = new Array(t), i = 0; i < t; i++)
|
|
648
|
+
e[i] = arguments[i];
|
|
649
|
+
return zt(r, e);
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
function d(r, t) {
|
|
653
|
+
let e = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : yt;
|
|
654
|
+
he && he(r, null);
|
|
655
|
+
let i = t.length;
|
|
656
|
+
for (; i--; ) {
|
|
657
|
+
let o = t[i];
|
|
658
|
+
if (typeof o == "string") {
|
|
659
|
+
const a = e(o);
|
|
660
|
+
a !== o && (Qe(t) || (t[i] = a), o = a);
|
|
661
|
+
}
|
|
662
|
+
r[o] = !0;
|
|
663
|
+
}
|
|
664
|
+
return r;
|
|
665
|
+
}
|
|
666
|
+
function ln(r) {
|
|
667
|
+
for (let t = 0; t < r.length; t++)
|
|
668
|
+
N(r, t) || (r[t] = null);
|
|
669
|
+
return r;
|
|
670
|
+
}
|
|
671
|
+
function U(r) {
|
|
672
|
+
const t = xe(null);
|
|
673
|
+
for (const [e, i] of _e(r))
|
|
674
|
+
N(r, e) && (Array.isArray(i) ? t[e] = ln(i) : i && typeof i == "object" && i.constructor === Object ? t[e] = U(i) : t[e] = i);
|
|
675
|
+
return t;
|
|
676
|
+
}
|
|
677
|
+
function et(r, t) {
|
|
678
|
+
for (; r !== null; ) {
|
|
679
|
+
const i = en(r, t);
|
|
680
|
+
if (i) {
|
|
681
|
+
if (i.get)
|
|
682
|
+
return L(i.get);
|
|
683
|
+
if (typeof i.value == "function")
|
|
684
|
+
return L(i.value);
|
|
685
|
+
}
|
|
686
|
+
r = tn(r);
|
|
687
|
+
}
|
|
688
|
+
function e() {
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
return e;
|
|
692
|
+
}
|
|
693
|
+
const pe = k(["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]), Mt = k(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "enterkeyhint", "exportparts", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "inputmode", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "part", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "slot", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]), Pt = k(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"]), cn = k(["animate", "color-profile", "cursor", "discard", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignobject", "hatch", "hatchpath", "mesh", "meshgradient", "meshpatch", "meshrow", "missing-glyph", "script", "set", "solidcolor", "unknown", "use"]), Ut = k(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]), dn = k(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]), me = k(["#text"]), ge = k(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "exportparts", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inert", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "part", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "slot", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]), Ht = k(["accent-height", "accumulate", "additive", "alignment-baseline", "amplitude", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "exponent", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "intercept", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "slope", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "tablevalues", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]), ye = k(["accent", "accentunder", "align", "bevelled", "close", "columnsalign", "columnlines", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lspace", "lquote", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]), gt = k(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]), un = w(/\{\{[\w\W]*|[\w\W]*\}\}/gm), hn = w(/<%[\w\W]*|[\w\W]*%>/gm), fn = w(/\$\{[\w\W]*/gm), pn = w(/^data-[\-\w.\u00B7-\uFFFF]+$/), mn = w(/^aria-[\-\w]+$/), Se = w(
|
|
694
|
+
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
|
695
|
+
// eslint-disable-line no-useless-escape
|
|
696
|
+
), gn = w(/^(?:\w+script|data):/i), yn = w(
|
|
697
|
+
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
|
698
|
+
// eslint-disable-line no-control-regex
|
|
699
|
+
), Ae = w(/^html$/i), En = w(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
700
|
+
var Ee = /* @__PURE__ */ Object.freeze({
|
|
701
|
+
__proto__: null,
|
|
702
|
+
ARIA_ATTR: mn,
|
|
703
|
+
ATTR_WHITESPACE: yn,
|
|
704
|
+
CUSTOM_ELEMENT: En,
|
|
705
|
+
DATA_ATTR: pn,
|
|
706
|
+
DOCTYPE_NAME: Ae,
|
|
707
|
+
ERB_EXPR: hn,
|
|
708
|
+
IS_ALLOWED_URI: Se,
|
|
709
|
+
IS_SCRIPT_OR_DATA: gn,
|
|
710
|
+
MUSTACHE_EXPR: un,
|
|
711
|
+
TMPLIT_EXPR: fn
|
|
712
|
+
});
|
|
713
|
+
const nt = {
|
|
714
|
+
element: 1,
|
|
715
|
+
text: 3,
|
|
716
|
+
// Deprecated
|
|
717
|
+
progressingInstruction: 7,
|
|
718
|
+
comment: 8,
|
|
719
|
+
document: 9
|
|
720
|
+
}, Tn = function() {
|
|
721
|
+
return typeof window > "u" ? null : window;
|
|
722
|
+
}, bn = function(t, e) {
|
|
723
|
+
if (typeof t != "object" || typeof t.createPolicy != "function")
|
|
724
|
+
return null;
|
|
725
|
+
let i = null;
|
|
726
|
+
const o = "data-tt-policy-suffix";
|
|
727
|
+
e && e.hasAttribute(o) && (i = e.getAttribute(o));
|
|
728
|
+
const a = "dompurify" + (i ? "#" + i : "");
|
|
729
|
+
try {
|
|
730
|
+
return t.createPolicy(a, {
|
|
731
|
+
createHTML(u) {
|
|
732
|
+
return u;
|
|
733
|
+
},
|
|
734
|
+
createScriptURL(u) {
|
|
735
|
+
return u;
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
} catch {
|
|
739
|
+
return console.warn("TrustedTypes policy " + a + " could not be created."), null;
|
|
740
|
+
}
|
|
741
|
+
}, Te = function() {
|
|
742
|
+
return {
|
|
743
|
+
afterSanitizeAttributes: [],
|
|
744
|
+
afterSanitizeElements: [],
|
|
745
|
+
afterSanitizeShadowDOM: [],
|
|
746
|
+
beforeSanitizeAttributes: [],
|
|
747
|
+
beforeSanitizeElements: [],
|
|
748
|
+
beforeSanitizeShadowDOM: [],
|
|
749
|
+
uponSanitizeAttribute: [],
|
|
750
|
+
uponSanitizeElement: [],
|
|
751
|
+
uponSanitizeShadowNode: []
|
|
752
|
+
};
|
|
753
|
+
};
|
|
754
|
+
function ke() {
|
|
755
|
+
let r = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : Tn();
|
|
756
|
+
const t = (c) => ke(c);
|
|
757
|
+
if (t.version = "3.2.7", t.removed = [], !r || !r.document || r.document.nodeType !== nt.document || !r.Element)
|
|
758
|
+
return t.isSupported = !1, t;
|
|
759
|
+
let {
|
|
760
|
+
document: e
|
|
761
|
+
} = r;
|
|
762
|
+
const i = e, o = i.currentScript, {
|
|
763
|
+
DocumentFragment: a,
|
|
764
|
+
HTMLTemplateElement: u,
|
|
765
|
+
Node: h,
|
|
766
|
+
Element: p,
|
|
767
|
+
NodeFilter: R,
|
|
768
|
+
NamedNodeMap: I = r.NamedNodeMap || r.MozNamedAttrMap,
|
|
769
|
+
HTMLFormElement: ot,
|
|
770
|
+
DOMParser: Ce,
|
|
771
|
+
trustedTypes: st
|
|
772
|
+
} = r, V = p.prototype, we = et(V, "cloneNode"), Ie = et(V, "remove"), Oe = et(V, "nextSibling"), Ne = et(V, "childNodes"), at = et(V, "parentNode");
|
|
773
|
+
if (typeof u == "function") {
|
|
774
|
+
const c = e.createElement("template");
|
|
775
|
+
c.content && c.content.ownerDocument && (e = c.content.ownerDocument);
|
|
776
|
+
}
|
|
777
|
+
let x, j = "";
|
|
778
|
+
const {
|
|
779
|
+
implementation: Et,
|
|
780
|
+
createNodeIterator: ve,
|
|
781
|
+
createDocumentFragment: De,
|
|
782
|
+
getElementsByTagName: Me
|
|
783
|
+
} = e, {
|
|
784
|
+
importNode: Pe
|
|
785
|
+
} = i;
|
|
786
|
+
let S = Te();
|
|
787
|
+
t.isSupported = typeof _e == "function" && typeof at == "function" && Et && Et.createHTMLDocument !== void 0;
|
|
788
|
+
const {
|
|
789
|
+
MUSTACHE_EXPR: Tt,
|
|
790
|
+
ERB_EXPR: bt,
|
|
791
|
+
TMPLIT_EXPR: _t,
|
|
792
|
+
DATA_ATTR: Ue,
|
|
793
|
+
ARIA_ATTR: He,
|
|
794
|
+
IS_SCRIPT_OR_DATA: Fe,
|
|
795
|
+
ATTR_WHITESPACE: $t,
|
|
796
|
+
CUSTOM_ELEMENT: ze
|
|
797
|
+
} = Ee;
|
|
798
|
+
let {
|
|
799
|
+
IS_ALLOWED_URI: Gt
|
|
800
|
+
} = Ee, y = null;
|
|
801
|
+
const Wt = d({}, [...pe, ...Mt, ...Pt, ...Ut, ...me]);
|
|
802
|
+
let T = null;
|
|
803
|
+
const Bt = d({}, [...ge, ...Ht, ...ye, ...gt]);
|
|
804
|
+
let m = Object.seal(xe(null, {
|
|
805
|
+
tagNameCheck: {
|
|
806
|
+
writable: !0,
|
|
807
|
+
configurable: !1,
|
|
808
|
+
enumerable: !0,
|
|
809
|
+
value: null
|
|
810
|
+
},
|
|
811
|
+
attributeNameCheck: {
|
|
812
|
+
writable: !0,
|
|
813
|
+
configurable: !1,
|
|
814
|
+
enumerable: !0,
|
|
815
|
+
value: null
|
|
816
|
+
},
|
|
817
|
+
allowCustomizedBuiltInElements: {
|
|
818
|
+
writable: !0,
|
|
819
|
+
configurable: !1,
|
|
820
|
+
enumerable: !0,
|
|
821
|
+
value: !1
|
|
822
|
+
}
|
|
823
|
+
})), X = null, xt = null, Kt = !0, St = !0, Yt = !1, Vt = !0, z = !1, lt = !0, H = !1, At = !1, kt = !1, $ = !1, ct = !1, dt = !1, jt = !0, Xt = !1;
|
|
824
|
+
const $e = "user-content-";
|
|
825
|
+
let Lt = !0, q = !1, G = {}, W = null;
|
|
826
|
+
const qt = d({}, ["annotation-xml", "audio", "colgroup", "desc", "foreignobject", "head", "iframe", "math", "mi", "mn", "mo", "ms", "mtext", "noembed", "noframes", "noscript", "plaintext", "script", "style", "svg", "template", "thead", "title", "video", "xmp"]);
|
|
827
|
+
let Zt = null;
|
|
828
|
+
const Jt = d({}, ["audio", "video", "img", "source", "image", "track"]);
|
|
829
|
+
let Rt = null;
|
|
830
|
+
const Qt = d({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]), ut = "http://www.w3.org/1998/Math/MathML", ht = "http://www.w3.org/2000/svg", D = "http://www.w3.org/1999/xhtml";
|
|
831
|
+
let B = D, Ct = !1, wt = null;
|
|
832
|
+
const Ge = d({}, [ut, ht, D], vt);
|
|
833
|
+
let ft = d({}, ["mi", "mo", "mn", "ms", "mtext"]), pt = d({}, ["annotation-xml"]);
|
|
834
|
+
const We = d({}, ["title", "style", "font", "a", "script"]);
|
|
835
|
+
let Z = null;
|
|
836
|
+
const Be = ["application/xhtml+xml", "text/html"], Ke = "text/html";
|
|
837
|
+
let E = null, K = null;
|
|
838
|
+
const Ye = e.createElement("form"), te = function(n) {
|
|
839
|
+
return n instanceof RegExp || n instanceof Function;
|
|
840
|
+
}, It = function() {
|
|
841
|
+
let n = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
842
|
+
if (!(K && K === n)) {
|
|
843
|
+
if ((!n || typeof n != "object") && (n = {}), n = U(n), Z = // eslint-disable-next-line unicorn/prefer-includes
|
|
844
|
+
Be.indexOf(n.PARSER_MEDIA_TYPE) === -1 ? Ke : n.PARSER_MEDIA_TYPE, E = Z === "application/xhtml+xml" ? vt : yt, y = N(n, "ALLOWED_TAGS") ? d({}, n.ALLOWED_TAGS, E) : Wt, T = N(n, "ALLOWED_ATTR") ? d({}, n.ALLOWED_ATTR, E) : Bt, wt = N(n, "ALLOWED_NAMESPACES") ? d({}, n.ALLOWED_NAMESPACES, vt) : Ge, Rt = N(n, "ADD_URI_SAFE_ATTR") ? d(U(Qt), n.ADD_URI_SAFE_ATTR, E) : Qt, Zt = N(n, "ADD_DATA_URI_TAGS") ? d(U(Jt), n.ADD_DATA_URI_TAGS, E) : Jt, W = N(n, "FORBID_CONTENTS") ? d({}, n.FORBID_CONTENTS, E) : qt, X = N(n, "FORBID_TAGS") ? d({}, n.FORBID_TAGS, E) : U({}), xt = N(n, "FORBID_ATTR") ? d({}, n.FORBID_ATTR, E) : U({}), G = N(n, "USE_PROFILES") ? n.USE_PROFILES : !1, Kt = n.ALLOW_ARIA_ATTR !== !1, St = n.ALLOW_DATA_ATTR !== !1, Yt = n.ALLOW_UNKNOWN_PROTOCOLS || !1, Vt = n.ALLOW_SELF_CLOSE_IN_ATTR !== !1, z = n.SAFE_FOR_TEMPLATES || !1, lt = n.SAFE_FOR_XML !== !1, H = n.WHOLE_DOCUMENT || !1, $ = n.RETURN_DOM || !1, ct = n.RETURN_DOM_FRAGMENT || !1, dt = n.RETURN_TRUSTED_TYPE || !1, kt = n.FORCE_BODY || !1, jt = n.SANITIZE_DOM !== !1, Xt = n.SANITIZE_NAMED_PROPS || !1, Lt = n.KEEP_CONTENT !== !1, q = n.IN_PLACE || !1, Gt = n.ALLOWED_URI_REGEXP || Se, B = n.NAMESPACE || D, ft = n.MATHML_TEXT_INTEGRATION_POINTS || ft, pt = n.HTML_INTEGRATION_POINTS || pt, m = n.CUSTOM_ELEMENT_HANDLING || {}, n.CUSTOM_ELEMENT_HANDLING && te(n.CUSTOM_ELEMENT_HANDLING.tagNameCheck) && (m.tagNameCheck = n.CUSTOM_ELEMENT_HANDLING.tagNameCheck), n.CUSTOM_ELEMENT_HANDLING && te(n.CUSTOM_ELEMENT_HANDLING.attributeNameCheck) && (m.attributeNameCheck = n.CUSTOM_ELEMENT_HANDLING.attributeNameCheck), n.CUSTOM_ELEMENT_HANDLING && typeof n.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements == "boolean" && (m.allowCustomizedBuiltInElements = n.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements), z && (St = !1), ct && ($ = !0), G && (y = d({}, me), T = [], G.html === !0 && (d(y, pe), d(T, ge)), G.svg === !0 && (d(y, Mt), d(T, Ht), d(T, gt)), G.svgFilters === !0 && (d(y, Pt), d(T, Ht), d(T, gt)), G.mathMl === !0 && (d(y, Ut), d(T, ye), d(T, gt))), n.ADD_TAGS && (y === Wt && (y = U(y)), d(y, n.ADD_TAGS, E)), n.ADD_ATTR && (T === Bt && (T = U(T)), d(T, n.ADD_ATTR, E)), n.ADD_URI_SAFE_ATTR && d(Rt, n.ADD_URI_SAFE_ATTR, E), n.FORBID_CONTENTS && (W === qt && (W = U(W)), d(W, n.FORBID_CONTENTS, E)), Lt && (y["#text"] = !0), H && d(y, ["html", "head", "body"]), y.table && (d(y, ["tbody"]), delete X.tbody), n.TRUSTED_TYPES_POLICY) {
|
|
845
|
+
if (typeof n.TRUSTED_TYPES_POLICY.createHTML != "function")
|
|
846
|
+
throw tt('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
847
|
+
if (typeof n.TRUSTED_TYPES_POLICY.createScriptURL != "function")
|
|
848
|
+
throw tt('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
849
|
+
x = n.TRUSTED_TYPES_POLICY, j = x.createHTML("");
|
|
850
|
+
} else
|
|
851
|
+
x === void 0 && (x = bn(st, o)), x !== null && typeof j == "string" && (j = x.createHTML(""));
|
|
852
|
+
k && k(n), K = n;
|
|
853
|
+
}
|
|
854
|
+
}, ee = d({}, [...Mt, ...Pt, ...cn]), ne = d({}, [...Ut, ...dn]), Ve = function(n) {
|
|
855
|
+
let s = at(n);
|
|
856
|
+
(!s || !s.tagName) && (s = {
|
|
857
|
+
namespaceURI: B,
|
|
858
|
+
tagName: "template"
|
|
859
|
+
});
|
|
860
|
+
const l = yt(n.tagName), f = yt(s.tagName);
|
|
861
|
+
return wt[n.namespaceURI] ? n.namespaceURI === ht ? s.namespaceURI === D ? l === "svg" : s.namespaceURI === ut ? l === "svg" && (f === "annotation-xml" || ft[f]) : !!ee[l] : n.namespaceURI === ut ? s.namespaceURI === D ? l === "math" : s.namespaceURI === ht ? l === "math" && pt[f] : !!ne[l] : n.namespaceURI === D ? s.namespaceURI === ht && !pt[f] || s.namespaceURI === ut && !ft[f] ? !1 : !ne[l] && (We[l] || !ee[l]) : !!(Z === "application/xhtml+xml" && wt[n.namespaceURI]) : !1;
|
|
862
|
+
}, v = function(n) {
|
|
863
|
+
J(t.removed, {
|
|
864
|
+
element: n
|
|
865
|
+
});
|
|
866
|
+
try {
|
|
867
|
+
at(n).removeChild(n);
|
|
868
|
+
} catch {
|
|
869
|
+
Ie(n);
|
|
870
|
+
}
|
|
871
|
+
}, F = function(n, s) {
|
|
872
|
+
try {
|
|
873
|
+
J(t.removed, {
|
|
874
|
+
attribute: s.getAttributeNode(n),
|
|
875
|
+
from: s
|
|
876
|
+
});
|
|
877
|
+
} catch {
|
|
878
|
+
J(t.removed, {
|
|
879
|
+
attribute: null,
|
|
880
|
+
from: s
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
if (s.removeAttribute(n), n === "is")
|
|
884
|
+
if ($ || ct)
|
|
885
|
+
try {
|
|
886
|
+
v(s);
|
|
887
|
+
} catch {
|
|
888
|
+
}
|
|
889
|
+
else
|
|
890
|
+
try {
|
|
891
|
+
s.setAttribute(n, "");
|
|
892
|
+
} catch {
|
|
893
|
+
}
|
|
894
|
+
}, ie = function(n) {
|
|
895
|
+
let s = null, l = null;
|
|
896
|
+
if (kt)
|
|
897
|
+
n = "<remove></remove>" + n;
|
|
898
|
+
else {
|
|
899
|
+
const g = Dt(n, /^[\r\n\t ]+/);
|
|
900
|
+
l = g && g[0];
|
|
901
|
+
}
|
|
902
|
+
Z === "application/xhtml+xml" && B === D && (n = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + n + "</body></html>");
|
|
903
|
+
const f = x ? x.createHTML(n) : n;
|
|
904
|
+
if (B === D)
|
|
905
|
+
try {
|
|
906
|
+
s = new Ce().parseFromString(f, Z);
|
|
907
|
+
} catch {
|
|
908
|
+
}
|
|
909
|
+
if (!s || !s.documentElement) {
|
|
910
|
+
s = Et.createDocument(B, "template", null);
|
|
911
|
+
try {
|
|
912
|
+
s.documentElement.innerHTML = Ct ? j : f;
|
|
913
|
+
} catch {
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
const _ = s.body || s.documentElement;
|
|
917
|
+
return n && l && _.insertBefore(e.createTextNode(l), _.childNodes[0] || null), B === D ? Me.call(s, H ? "html" : "body")[0] : H ? s.documentElement : _;
|
|
918
|
+
}, re = function(n) {
|
|
919
|
+
return ve.call(
|
|
920
|
+
n.ownerDocument || n,
|
|
921
|
+
n,
|
|
922
|
+
// eslint-disable-next-line no-bitwise
|
|
923
|
+
R.SHOW_ELEMENT | R.SHOW_COMMENT | R.SHOW_TEXT | R.SHOW_PROCESSING_INSTRUCTION | R.SHOW_CDATA_SECTION,
|
|
924
|
+
null
|
|
925
|
+
);
|
|
926
|
+
}, Ot = function(n) {
|
|
927
|
+
return n instanceof ot && (typeof n.nodeName != "string" || typeof n.textContent != "string" || typeof n.removeChild != "function" || !(n.attributes instanceof I) || typeof n.removeAttribute != "function" || typeof n.setAttribute != "function" || typeof n.namespaceURI != "string" || typeof n.insertBefore != "function" || typeof n.hasChildNodes != "function");
|
|
928
|
+
}, oe = function(n) {
|
|
929
|
+
return typeof h == "function" && n instanceof h;
|
|
930
|
+
};
|
|
931
|
+
function M(c, n, s) {
|
|
932
|
+
mt(c, (l) => {
|
|
933
|
+
l.call(t, n, s, K);
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
const se = function(n) {
|
|
937
|
+
let s = null;
|
|
938
|
+
if (M(S.beforeSanitizeElements, n, null), Ot(n))
|
|
939
|
+
return v(n), !0;
|
|
940
|
+
const l = E(n.nodeName);
|
|
941
|
+
if (M(S.uponSanitizeElement, n, {
|
|
942
|
+
tagName: l,
|
|
943
|
+
allowedTags: y
|
|
944
|
+
}), lt && n.hasChildNodes() && !oe(n.firstElementChild) && A(/<[/\w!]/g, n.innerHTML) && A(/<[/\w!]/g, n.textContent) || n.nodeType === nt.progressingInstruction || lt && n.nodeType === nt.comment && A(/<[/\w]/g, n.data))
|
|
945
|
+
return v(n), !0;
|
|
946
|
+
if (!y[l] || X[l]) {
|
|
947
|
+
if (!X[l] && le(l) && (m.tagNameCheck instanceof RegExp && A(m.tagNameCheck, l) || m.tagNameCheck instanceof Function && m.tagNameCheck(l)))
|
|
948
|
+
return !1;
|
|
949
|
+
if (Lt && !W[l]) {
|
|
950
|
+
const f = at(n) || n.parentNode, _ = Ne(n) || n.childNodes;
|
|
951
|
+
if (_ && f) {
|
|
952
|
+
const g = _.length;
|
|
953
|
+
for (let C = g - 1; C >= 0; --C) {
|
|
954
|
+
const P = we(_[C], !0);
|
|
955
|
+
P.__removalCount = (n.__removalCount || 0) + 1, f.insertBefore(P, Oe(n));
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
return v(n), !0;
|
|
960
|
+
}
|
|
961
|
+
return n instanceof p && !Ve(n) || (l === "noscript" || l === "noembed" || l === "noframes") && A(/<\/no(script|embed|frames)/i, n.innerHTML) ? (v(n), !0) : (z && n.nodeType === nt.text && (s = n.textContent, mt([Tt, bt, _t], (f) => {
|
|
962
|
+
s = Q(s, f, " ");
|
|
963
|
+
}), n.textContent !== s && (J(t.removed, {
|
|
964
|
+
element: n.cloneNode()
|
|
965
|
+
}), n.textContent = s)), M(S.afterSanitizeElements, n, null), !1);
|
|
966
|
+
}, ae = function(n, s, l) {
|
|
967
|
+
if (jt && (s === "id" || s === "name") && (l in e || l in Ye))
|
|
968
|
+
return !1;
|
|
969
|
+
if (!(St && !xt[s] && A(Ue, s))) {
|
|
970
|
+
if (!(Kt && A(He, s))) {
|
|
971
|
+
if (!T[s] || xt[s]) {
|
|
972
|
+
if (
|
|
973
|
+
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
974
|
+
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
975
|
+
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
976
|
+
!(le(n) && (m.tagNameCheck instanceof RegExp && A(m.tagNameCheck, n) || m.tagNameCheck instanceof Function && m.tagNameCheck(n)) && (m.attributeNameCheck instanceof RegExp && A(m.attributeNameCheck, s) || m.attributeNameCheck instanceof Function && m.attributeNameCheck(s, n)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
|
977
|
+
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
978
|
+
s === "is" && m.allowCustomizedBuiltInElements && (m.tagNameCheck instanceof RegExp && A(m.tagNameCheck, l) || m.tagNameCheck instanceof Function && m.tagNameCheck(l)))
|
|
979
|
+
) return !1;
|
|
980
|
+
} else if (!Rt[s]) {
|
|
981
|
+
if (!A(Gt, Q(l, $t, ""))) {
|
|
982
|
+
if (!((s === "src" || s === "xlink:href" || s === "href") && n !== "script" && on(l, "data:") === 0 && Zt[n])) {
|
|
983
|
+
if (!(Yt && !A(Fe, Q(l, $t, "")))) {
|
|
984
|
+
if (l)
|
|
985
|
+
return !1;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return !0;
|
|
993
|
+
}, le = function(n) {
|
|
994
|
+
return n !== "annotation-xml" && Dt(n, ze);
|
|
995
|
+
}, ce = function(n) {
|
|
996
|
+
M(S.beforeSanitizeAttributes, n, null);
|
|
997
|
+
const {
|
|
998
|
+
attributes: s
|
|
999
|
+
} = n;
|
|
1000
|
+
if (!s || Ot(n))
|
|
1001
|
+
return;
|
|
1002
|
+
const l = {
|
|
1003
|
+
attrName: "",
|
|
1004
|
+
attrValue: "",
|
|
1005
|
+
keepAttr: !0,
|
|
1006
|
+
allowedAttributes: T,
|
|
1007
|
+
forceKeepAttr: void 0
|
|
1008
|
+
};
|
|
1009
|
+
let f = s.length;
|
|
1010
|
+
for (; f--; ) {
|
|
1011
|
+
const _ = s[f], {
|
|
1012
|
+
name: g,
|
|
1013
|
+
namespaceURI: C,
|
|
1014
|
+
value: P
|
|
1015
|
+
} = _, Y = E(g), Nt = P;
|
|
1016
|
+
let b = g === "value" ? Nt : sn(Nt);
|
|
1017
|
+
if (l.attrName = Y, l.attrValue = b, l.keepAttr = !0, l.forceKeepAttr = void 0, M(S.uponSanitizeAttribute, n, l), b = l.attrValue, Xt && (Y === "id" || Y === "name") && (F(g, n), b = $e + b), lt && A(/((--!?|])>)|<\/(style|title|textarea)/i, b)) {
|
|
1018
|
+
F(g, n);
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
1021
|
+
if (Y === "attributename" && Dt(b, "href")) {
|
|
1022
|
+
F(g, n);
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
if (l.forceKeepAttr)
|
|
1026
|
+
continue;
|
|
1027
|
+
if (!l.keepAttr) {
|
|
1028
|
+
F(g, n);
|
|
1029
|
+
continue;
|
|
1030
|
+
}
|
|
1031
|
+
if (!Vt && A(/\/>/i, b)) {
|
|
1032
|
+
F(g, n);
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
z && mt([Tt, bt, _t], (ue) => {
|
|
1036
|
+
b = Q(b, ue, " ");
|
|
1037
|
+
});
|
|
1038
|
+
const de = E(n.nodeName);
|
|
1039
|
+
if (!ae(de, Y, b)) {
|
|
1040
|
+
F(g, n);
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
if (x && typeof st == "object" && typeof st.getAttributeType == "function" && !C)
|
|
1044
|
+
switch (st.getAttributeType(de, Y)) {
|
|
1045
|
+
case "TrustedHTML": {
|
|
1046
|
+
b = x.createHTML(b);
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
case "TrustedScriptURL": {
|
|
1050
|
+
b = x.createScriptURL(b);
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
if (b !== Nt)
|
|
1055
|
+
try {
|
|
1056
|
+
C ? n.setAttributeNS(C, g, b) : n.setAttribute(g, b), Ot(n) ? v(n) : fe(t.removed);
|
|
1057
|
+
} catch {
|
|
1058
|
+
F(g, n);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
M(S.afterSanitizeAttributes, n, null);
|
|
1062
|
+
}, je = function c(n) {
|
|
1063
|
+
let s = null;
|
|
1064
|
+
const l = re(n);
|
|
1065
|
+
for (M(S.beforeSanitizeShadowDOM, n, null); s = l.nextNode(); )
|
|
1066
|
+
M(S.uponSanitizeShadowNode, s, null), se(s), ce(s), s.content instanceof a && c(s.content);
|
|
1067
|
+
M(S.afterSanitizeShadowDOM, n, null);
|
|
1068
|
+
};
|
|
1069
|
+
return t.sanitize = function(c) {
|
|
1070
|
+
let n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, s = null, l = null, f = null, _ = null;
|
|
1071
|
+
if (Ct = !c, Ct && (c = "<!-->"), typeof c != "string" && !oe(c))
|
|
1072
|
+
if (typeof c.toString == "function") {
|
|
1073
|
+
if (c = c.toString(), typeof c != "string")
|
|
1074
|
+
throw tt("dirty is not a string, aborting");
|
|
1075
|
+
} else
|
|
1076
|
+
throw tt("toString is not a function");
|
|
1077
|
+
if (!t.isSupported)
|
|
1078
|
+
return c;
|
|
1079
|
+
if (At || It(n), t.removed = [], typeof c == "string" && (q = !1), q) {
|
|
1080
|
+
if (c.nodeName) {
|
|
1081
|
+
const P = E(c.nodeName);
|
|
1082
|
+
if (!y[P] || X[P])
|
|
1083
|
+
throw tt("root node is forbidden and cannot be sanitized in-place");
|
|
1084
|
+
}
|
|
1085
|
+
} else if (c instanceof h)
|
|
1086
|
+
s = ie("<!---->"), l = s.ownerDocument.importNode(c, !0), l.nodeType === nt.element && l.nodeName === "BODY" || l.nodeName === "HTML" ? s = l : s.appendChild(l);
|
|
1087
|
+
else {
|
|
1088
|
+
if (!$ && !z && !H && // eslint-disable-next-line unicorn/prefer-includes
|
|
1089
|
+
c.indexOf("<") === -1)
|
|
1090
|
+
return x && dt ? x.createHTML(c) : c;
|
|
1091
|
+
if (s = ie(c), !s)
|
|
1092
|
+
return $ ? null : dt ? j : "";
|
|
1093
|
+
}
|
|
1094
|
+
s && kt && v(s.firstChild);
|
|
1095
|
+
const g = re(q ? c : s);
|
|
1096
|
+
for (; f = g.nextNode(); )
|
|
1097
|
+
se(f), ce(f), f.content instanceof a && je(f.content);
|
|
1098
|
+
if (q)
|
|
1099
|
+
return c;
|
|
1100
|
+
if ($) {
|
|
1101
|
+
if (ct)
|
|
1102
|
+
for (_ = De.call(s.ownerDocument); s.firstChild; )
|
|
1103
|
+
_.appendChild(s.firstChild);
|
|
1104
|
+
else
|
|
1105
|
+
_ = s;
|
|
1106
|
+
return (T.shadowroot || T.shadowrootmode) && (_ = Pe.call(i, _, !0)), _;
|
|
1107
|
+
}
|
|
1108
|
+
let C = H ? s.outerHTML : s.innerHTML;
|
|
1109
|
+
return H && y["!doctype"] && s.ownerDocument && s.ownerDocument.doctype && s.ownerDocument.doctype.name && A(Ae, s.ownerDocument.doctype.name) && (C = "<!DOCTYPE " + s.ownerDocument.doctype.name + `>
|
|
1110
|
+
` + C), z && mt([Tt, bt, _t], (P) => {
|
|
1111
|
+
C = Q(C, P, " ");
|
|
1112
|
+
}), x && dt ? x.createHTML(C) : C;
|
|
1113
|
+
}, t.setConfig = function() {
|
|
1114
|
+
let c = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1115
|
+
It(c), At = !0;
|
|
1116
|
+
}, t.clearConfig = function() {
|
|
1117
|
+
K = null, At = !1;
|
|
1118
|
+
}, t.isValidAttribute = function(c, n, s) {
|
|
1119
|
+
K || It({});
|
|
1120
|
+
const l = E(c), f = E(n);
|
|
1121
|
+
return ae(l, f, s);
|
|
1122
|
+
}, t.addHook = function(c, n) {
|
|
1123
|
+
typeof n == "function" && J(S[c], n);
|
|
1124
|
+
}, t.removeHook = function(c, n) {
|
|
1125
|
+
if (n !== void 0) {
|
|
1126
|
+
const s = nn(S[c], n);
|
|
1127
|
+
return s === -1 ? void 0 : rn(S[c], s, 1)[0];
|
|
1128
|
+
}
|
|
1129
|
+
return fe(S[c]);
|
|
1130
|
+
}, t.removeHooks = function(c) {
|
|
1131
|
+
S[c] = [];
|
|
1132
|
+
}, t.removeAllHooks = function() {
|
|
1133
|
+
S = Te();
|
|
1134
|
+
}, t;
|
|
1135
|
+
}
|
|
1136
|
+
var _n = ke();
|
|
1137
|
+
const xn = {
|
|
1138
|
+
ALLOWED_TAGS: [
|
|
1139
|
+
"p",
|
|
1140
|
+
"br",
|
|
1141
|
+
"strong",
|
|
1142
|
+
"em",
|
|
1143
|
+
"u",
|
|
1144
|
+
"s",
|
|
1145
|
+
"code",
|
|
1146
|
+
"pre",
|
|
1147
|
+
"h1",
|
|
1148
|
+
"h2",
|
|
1149
|
+
"h3",
|
|
1150
|
+
"h4",
|
|
1151
|
+
"h5",
|
|
1152
|
+
"h6",
|
|
1153
|
+
"ul",
|
|
1154
|
+
"ol",
|
|
1155
|
+
"li",
|
|
1156
|
+
"blockquote",
|
|
1157
|
+
"a",
|
|
1158
|
+
"img",
|
|
1159
|
+
"table",
|
|
1160
|
+
"thead",
|
|
1161
|
+
"tbody",
|
|
1162
|
+
"tr",
|
|
1163
|
+
"th",
|
|
1164
|
+
"td",
|
|
1165
|
+
"div",
|
|
1166
|
+
"span"
|
|
1167
|
+
],
|
|
1168
|
+
ALLOWED_ATTR: [
|
|
1169
|
+
"href",
|
|
1170
|
+
"src",
|
|
1171
|
+
"alt",
|
|
1172
|
+
"title",
|
|
1173
|
+
"class",
|
|
1174
|
+
"id",
|
|
1175
|
+
"style",
|
|
1176
|
+
"data-*",
|
|
1177
|
+
"role",
|
|
1178
|
+
"aria-*"
|
|
1179
|
+
],
|
|
1180
|
+
ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,
|
|
1181
|
+
KEEP_CONTENT: !0,
|
|
1182
|
+
SANITIZE_DOM: !0,
|
|
1183
|
+
SAFE_FOR_TEMPLATES: !0
|
|
1184
|
+
}, Sn = {
|
|
1185
|
+
ALLOWED_TAGS: ["p", "br", "strong", "em", "u", "code"],
|
|
1186
|
+
ALLOWED_ATTR: [],
|
|
1187
|
+
KEEP_CONTENT: !0,
|
|
1188
|
+
SANITIZE_DOM: !0,
|
|
1189
|
+
SAFE_FOR_TEMPLATES: !0
|
|
1190
|
+
};
|
|
1191
|
+
function rt(r, t = !1) {
|
|
1192
|
+
const e = t ? Sn : xn;
|
|
1193
|
+
return _n.sanitize(r, e);
|
|
1194
|
+
}
|
|
1195
|
+
function An(r, t = !0) {
|
|
1196
|
+
return t ? rt(r) : kn(r);
|
|
1197
|
+
}
|
|
1198
|
+
function kn(r) {
|
|
1199
|
+
const t = document.createElement("div");
|
|
1200
|
+
return t.textContent = r, t.innerHTML;
|
|
1201
|
+
}
|
|
1202
|
+
function Ln(r) {
|
|
1203
|
+
try {
|
|
1204
|
+
if (!r || typeof r != "object" || !Array.isArray(r.ops))
|
|
1205
|
+
return !1;
|
|
1206
|
+
for (const t of r.ops) {
|
|
1207
|
+
if ("insert" in t) {
|
|
1208
|
+
const e = t.insert;
|
|
1209
|
+
if (typeof e == "string" && rt(e) !== e && e.includes("<script"))
|
|
1210
|
+
return !1;
|
|
1211
|
+
if (typeof e == "object" && e !== null) {
|
|
1212
|
+
const i = e;
|
|
1213
|
+
if ("script" in i || "onerror" in i || "onclick" in i)
|
|
1214
|
+
return !1;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
if ("attributes" in t && t.attributes) {
|
|
1218
|
+
const e = t.attributes;
|
|
1219
|
+
for (const i in e)
|
|
1220
|
+
if (i.startsWith("on") || i.toLowerCase().includes("script"))
|
|
1221
|
+
return !1;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
return !0;
|
|
1225
|
+
} catch (t) {
|
|
1226
|
+
return console.error("Error validating delta:", t), !1;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
function Le(r, t = "polite") {
|
|
1230
|
+
let e = document.getElementById("notectl-sr-live");
|
|
1231
|
+
e ? e.setAttribute("aria-live", t) : (e = document.createElement("div"), e.id = "notectl-sr-live", e.setAttribute("role", "status"), e.setAttribute("aria-live", t), e.setAttribute("aria-atomic", "true"), e.style.position = "absolute", e.style.left = "-10000px", e.style.width = "1px", e.style.height = "1px", e.style.overflow = "hidden", document.body.appendChild(e)), e.textContent = "", setTimeout(() => {
|
|
1232
|
+
e.textContent = r;
|
|
1233
|
+
}, 100);
|
|
1234
|
+
}
|
|
1235
|
+
function Rn(r, t) {
|
|
1236
|
+
const e = (i) => {
|
|
1237
|
+
for (const o of r) {
|
|
1238
|
+
const a = o.ctrlKey ? i.ctrlKey : !0, u = o.metaKey ? i.metaKey : !0, h = o.shiftKey ? i.shiftKey : !i.shiftKey, p = o.altKey ? i.altKey : !i.altKey;
|
|
1239
|
+
if (i.key.toLowerCase() === o.key.toLowerCase() && a && u && h && p) {
|
|
1240
|
+
i.preventDefault(), o.action(), Le(o.description);
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
return t.addEventListener("keydown", e), () => {
|
|
1246
|
+
t.removeEventListener("keydown", e);
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
function Cn(r, t) {
|
|
1250
|
+
for (const [e, i] of Object.entries(t)) {
|
|
1251
|
+
const o = e.startsWith("aria-") ? e : `aria-${e}`;
|
|
1252
|
+
r.setAttribute(o, String(i));
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
class Re extends HTMLElement {
|
|
1256
|
+
constructor() {
|
|
1257
|
+
super(), this.eventListeners = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.contentElement = null, this.pluginContainerTop = null, this.pluginContainerBottom = null, this.ariaLiveRegion = null, this.config = {
|
|
1258
|
+
placeholder: "Start typing...",
|
|
1259
|
+
readonly: !1,
|
|
1260
|
+
autofocus: !1,
|
|
1261
|
+
sanitizeHTML: !0,
|
|
1262
|
+
maxHistoryDepth: 100
|
|
1263
|
+
};
|
|
1264
|
+
const t = be();
|
|
1265
|
+
this.state = new it(void 0, t, {
|
|
1266
|
+
maxHistoryDepth: this.config.maxHistoryDepth
|
|
1267
|
+
}), this.pluginManager = new Je(), this.attachShadow({ mode: "open" });
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Observed attributes for the web component
|
|
1271
|
+
*/
|
|
1272
|
+
static get observedAttributes() {
|
|
1273
|
+
return ["placeholder", "readonly", "autofocus"];
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Called when element is connected to DOM
|
|
1277
|
+
*/
|
|
1278
|
+
connectedCallback() {
|
|
1279
|
+
this.render(), this.attachEventListeners(), this.setupAccessibility(), this.setupKeyboardShortcuts(), this.config.autofocus && this.focus();
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Called when element is disconnected from DOM
|
|
1283
|
+
*/
|
|
1284
|
+
disconnectedCallback() {
|
|
1285
|
+
this.detachEventListeners(), this.pluginManager.destroyAll(), this.keyboardShortcutCleanup && this.keyboardShortcutCleanup(), this.ariaLiveRegion && this.ariaLiveRegion.parentNode && this.ariaLiveRegion.parentNode.removeChild(this.ariaLiveRegion);
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Called when attributes change
|
|
1289
|
+
*/
|
|
1290
|
+
attributeChangedCallback(t, e, i) {
|
|
1291
|
+
if (e !== i)
|
|
1292
|
+
switch (t) {
|
|
1293
|
+
case "placeholder":
|
|
1294
|
+
this.config.placeholder = i || "", this.updatePlaceholder();
|
|
1295
|
+
break;
|
|
1296
|
+
case "readonly":
|
|
1297
|
+
this.config.readonly = i !== null, this.updateReadonly();
|
|
1298
|
+
break;
|
|
1299
|
+
case "autofocus":
|
|
1300
|
+
this.config.autofocus = i !== null;
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Render the editor UI
|
|
1306
|
+
*/
|
|
1307
|
+
render() {
|
|
1308
|
+
this.shadowRoot && (this.shadowRoot.innerHTML = `
|
|
1309
|
+
<style>
|
|
1310
|
+
:host {
|
|
1311
|
+
display: block;
|
|
1312
|
+
position: relative;
|
|
1313
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
1314
|
+
font-size: 16px;
|
|
1315
|
+
line-height: 1.5;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
.notectl-container {
|
|
1319
|
+
display: flex;
|
|
1320
|
+
flex-direction: column;
|
|
1321
|
+
border: 1px solid #e0e0e0;
|
|
1322
|
+
border-radius: 4px;
|
|
1323
|
+
background: white;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
.notectl-plugin-container {
|
|
1327
|
+
display: block;
|
|
1328
|
+
background: transparent;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
.notectl-plugin-container[data-position="top"] {
|
|
1332
|
+
order: -1;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
.notectl-plugin-container[data-position="bottom"] {
|
|
1336
|
+
order: 1;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
.notectl-editor-wrapper {
|
|
1340
|
+
position: relative;
|
|
1341
|
+
flex: 1;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
.notectl-editor {
|
|
1345
|
+
min-height: 200px;
|
|
1346
|
+
padding: 1rem;
|
|
1347
|
+
outline: none;
|
|
1348
|
+
background: white;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
.notectl-container:focus-within {
|
|
1352
|
+
border-color: #2196F3;
|
|
1353
|
+
box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
.notectl-editor[data-readonly="true"] {
|
|
1357
|
+
background: #f5f5f5;
|
|
1358
|
+
cursor: not-allowed;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
.notectl-editor table {
|
|
1362
|
+
border-collapse: collapse;
|
|
1363
|
+
width: 100%;
|
|
1364
|
+
margin: 1em 0;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
.notectl-editor table td,
|
|
1368
|
+
.notectl-editor table th {
|
|
1369
|
+
border: 1px solid #ddd;
|
|
1370
|
+
padding: 8px;
|
|
1371
|
+
min-width: 100px;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
.notectl-placeholder {
|
|
1375
|
+
position: absolute;
|
|
1376
|
+
top: 1rem;
|
|
1377
|
+
left: 1rem;
|
|
1378
|
+
color: #9e9e9e;
|
|
1379
|
+
pointer-events: none;
|
|
1380
|
+
user-select: none;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
.notectl-placeholder.hidden {
|
|
1384
|
+
display: none;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
.visually-hidden {
|
|
1388
|
+
position: absolute;
|
|
1389
|
+
left: -10000px;
|
|
1390
|
+
width: 1px;
|
|
1391
|
+
height: 1px;
|
|
1392
|
+
overflow: hidden;
|
|
1393
|
+
}
|
|
1394
|
+
</style>
|
|
1395
|
+
|
|
1396
|
+
<div class="notectl-container">
|
|
1397
|
+
<div class="notectl-plugin-container" data-position="top"></div>
|
|
1398
|
+
<div class="notectl-editor-wrapper">
|
|
1399
|
+
<div class="notectl-placeholder" aria-hidden="true">${this.config.placeholder}</div>
|
|
1400
|
+
<div
|
|
1401
|
+
class="notectl-editor"
|
|
1402
|
+
contenteditable="${!this.config.readonly}"
|
|
1403
|
+
data-readonly="${this.config.readonly}"
|
|
1404
|
+
role="textbox"
|
|
1405
|
+
aria-label="Rich text editor"
|
|
1406
|
+
aria-multiline="true"
|
|
1407
|
+
aria-describedby="notectl-help-text"
|
|
1408
|
+
tabindex="0"
|
|
1409
|
+
></div>
|
|
1410
|
+
</div>
|
|
1411
|
+
<div class="notectl-plugin-container" data-position="bottom"></div>
|
|
1412
|
+
</div>
|
|
1413
|
+
<div id="notectl-help-text" class="visually-hidden">
|
|
1414
|
+
Use arrow keys to navigate. Press Ctrl+B for bold, Ctrl+I for italic, Ctrl+U for underline.
|
|
1415
|
+
Press Ctrl+Z to undo, Ctrl+Shift+Z to redo.
|
|
1416
|
+
</div>
|
|
1417
|
+
<div id="notectl-aria-live" role="status" aria-live="polite" aria-atomic="true" class="visually-hidden"></div>
|
|
1418
|
+
`, this.contentElement = this.shadowRoot.querySelector(".notectl-editor"), this.pluginContainerTop = this.shadowRoot.querySelector('.notectl-plugin-container[data-position="top"]'), this.pluginContainerBottom = this.shadowRoot.querySelector('.notectl-plugin-container[data-position="bottom"]'), this.ariaLiveRegion = this.shadowRoot.querySelector("#notectl-aria-live"), this.renderContent());
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Render document content
|
|
1422
|
+
*/
|
|
1423
|
+
renderContent() {
|
|
1424
|
+
if (!this.contentElement) return;
|
|
1425
|
+
const t = this.state.getDocument(), e = this.documentToHTML(t);
|
|
1426
|
+
this.contentElement.innerHTML = this.config.sanitizeHTML ? rt(e) : e;
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Convert document to HTML
|
|
1430
|
+
*/
|
|
1431
|
+
documentToHTML(t) {
|
|
1432
|
+
return t.children.map((e) => this.blockToHTML(e)).join("");
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Convert block to HTML (simplified)
|
|
1436
|
+
*/
|
|
1437
|
+
blockToHTML(t) {
|
|
1438
|
+
switch (t.type) {
|
|
1439
|
+
case "paragraph":
|
|
1440
|
+
return `<p>${this.childrenToHTML(t.children || [])}</p>`;
|
|
1441
|
+
case "heading":
|
|
1442
|
+
const e = t.attrs?.level || 1;
|
|
1443
|
+
return `<h${e}>${this.childrenToHTML(t.children || [])}</h${e}>`;
|
|
1444
|
+
default:
|
|
1445
|
+
return `<div>${this.childrenToHTML(t.children || [])}</div>`;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Convert children to HTML
|
|
1450
|
+
*/
|
|
1451
|
+
childrenToHTML(t) {
|
|
1452
|
+
return t.map((e) => {
|
|
1453
|
+
if (e.type === "text") {
|
|
1454
|
+
let i = this.escapeHTML(e.text);
|
|
1455
|
+
if (e.marks)
|
|
1456
|
+
for (const o of e.marks)
|
|
1457
|
+
i = this.applyMarkHTML(i, o);
|
|
1458
|
+
return i;
|
|
1459
|
+
}
|
|
1460
|
+
return this.blockToHTML(e);
|
|
1461
|
+
}).join("");
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Apply mark as HTML
|
|
1465
|
+
*/
|
|
1466
|
+
applyMarkHTML(t, e) {
|
|
1467
|
+
switch (e.type) {
|
|
1468
|
+
case "bold":
|
|
1469
|
+
return `<strong>${t}</strong>`;
|
|
1470
|
+
case "italic":
|
|
1471
|
+
return `<em>${t}</em>`;
|
|
1472
|
+
case "underline":
|
|
1473
|
+
return `<u>${t}</u>`;
|
|
1474
|
+
case "strikethrough":
|
|
1475
|
+
return `<s>${t}</s>`;
|
|
1476
|
+
case "code":
|
|
1477
|
+
return `<code>${t}</code>`;
|
|
1478
|
+
default:
|
|
1479
|
+
return t;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Escape HTML
|
|
1484
|
+
*/
|
|
1485
|
+
escapeHTML(t) {
|
|
1486
|
+
if (!this.config.sanitizeHTML) return t;
|
|
1487
|
+
const e = document.createElement("div");
|
|
1488
|
+
return e.textContent = t, e.innerHTML;
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* Setup accessibility features
|
|
1492
|
+
*/
|
|
1493
|
+
setupAccessibility() {
|
|
1494
|
+
this.contentElement && (Cn(this.contentElement, {
|
|
1495
|
+
role: "textbox",
|
|
1496
|
+
"aria-multiline": !0,
|
|
1497
|
+
"aria-label": "Rich text editor",
|
|
1498
|
+
"aria-describedby": "notectl-help-text",
|
|
1499
|
+
"aria-autocomplete": "none"
|
|
1500
|
+
}), this.config.readonly && this.contentElement.setAttribute("aria-readonly", "true"));
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* Setup keyboard shortcuts with screen reader announcements
|
|
1504
|
+
*/
|
|
1505
|
+
setupKeyboardShortcuts() {
|
|
1506
|
+
if (!this.contentElement) return;
|
|
1507
|
+
const t = [
|
|
1508
|
+
{
|
|
1509
|
+
key: "b",
|
|
1510
|
+
ctrlKey: !0,
|
|
1511
|
+
description: "Bold formatting applied",
|
|
1512
|
+
action: () => this.toggleFormat("bold")
|
|
1513
|
+
},
|
|
1514
|
+
{
|
|
1515
|
+
key: "i",
|
|
1516
|
+
ctrlKey: !0,
|
|
1517
|
+
description: "Italic formatting applied",
|
|
1518
|
+
action: () => this.toggleFormat("italic")
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
key: "u",
|
|
1522
|
+
ctrlKey: !0,
|
|
1523
|
+
description: "Underline formatting applied",
|
|
1524
|
+
action: () => this.toggleFormat("underline")
|
|
1525
|
+
},
|
|
1526
|
+
{
|
|
1527
|
+
key: "z",
|
|
1528
|
+
ctrlKey: !0,
|
|
1529
|
+
description: "Action undone",
|
|
1530
|
+
action: () => this.undo()
|
|
1531
|
+
},
|
|
1532
|
+
{
|
|
1533
|
+
key: "z",
|
|
1534
|
+
ctrlKey: !0,
|
|
1535
|
+
shiftKey: !0,
|
|
1536
|
+
description: "Action redone",
|
|
1537
|
+
action: () => this.redo()
|
|
1538
|
+
}
|
|
1539
|
+
];
|
|
1540
|
+
this.keyboardShortcutCleanup = Rn(t, this.contentElement);
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Toggle formatting
|
|
1544
|
+
*/
|
|
1545
|
+
toggleFormat(t) {
|
|
1546
|
+
const e = window.getSelection();
|
|
1547
|
+
if (!(!e || !this.contentElement))
|
|
1548
|
+
try {
|
|
1549
|
+
switch (t) {
|
|
1550
|
+
case "bold":
|
|
1551
|
+
document.execCommand("bold", !1);
|
|
1552
|
+
break;
|
|
1553
|
+
case "italic":
|
|
1554
|
+
document.execCommand("italic", !1);
|
|
1555
|
+
break;
|
|
1556
|
+
case "underline":
|
|
1557
|
+
document.execCommand("underline", !1);
|
|
1558
|
+
break;
|
|
1559
|
+
case "strikethrough":
|
|
1560
|
+
document.execCommand("strikeThrough", !1);
|
|
1561
|
+
break;
|
|
1562
|
+
case "code":
|
|
1563
|
+
const i = document.createElement("code");
|
|
1564
|
+
if (e.rangeCount > 0) {
|
|
1565
|
+
const o = e.getRangeAt(0);
|
|
1566
|
+
i.appendChild(o.extractContents()), o.insertNode(i);
|
|
1567
|
+
}
|
|
1568
|
+
break;
|
|
1569
|
+
}
|
|
1570
|
+
this.announceToScreenReader(`${t} formatting applied`), this.emit("change", { state: this.state });
|
|
1571
|
+
} catch (i) {
|
|
1572
|
+
console.error(`Failed to apply ${t} formatting:`, i), this.announceToScreenReader(`Failed to apply ${t} formatting`);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Insert table at current selection
|
|
1577
|
+
*/
|
|
1578
|
+
insertTable(t = 3, e = 3) {
|
|
1579
|
+
if (this.contentElement)
|
|
1580
|
+
try {
|
|
1581
|
+
this.contentElement.focus();
|
|
1582
|
+
const i = document.createElement("table");
|
|
1583
|
+
i.setAttribute("data-notectl-table", "true");
|
|
1584
|
+
const o = document.createElement("tbody");
|
|
1585
|
+
for (let p = 0; p < t; p++) {
|
|
1586
|
+
const R = document.createElement("tr");
|
|
1587
|
+
for (let I = 0; I < e; I++) {
|
|
1588
|
+
const ot = document.createElement("td");
|
|
1589
|
+
ot.textContent = "", R.appendChild(ot);
|
|
1590
|
+
}
|
|
1591
|
+
o.appendChild(R);
|
|
1592
|
+
}
|
|
1593
|
+
i.appendChild(o);
|
|
1594
|
+
const a = window.getSelection();
|
|
1595
|
+
let u = this.contentElement.childNodes.length;
|
|
1596
|
+
if (a && a.rangeCount > 0) {
|
|
1597
|
+
const p = a.getRangeAt(0);
|
|
1598
|
+
if (this.contentElement.contains(p.commonAncestorContainer)) {
|
|
1599
|
+
let R = p.startContainer;
|
|
1600
|
+
if (R.nodeType === Node.TEXT_NODE && (R = R.parentNode), R === this.contentElement)
|
|
1601
|
+
u = p.startOffset;
|
|
1602
|
+
else {
|
|
1603
|
+
let I = R;
|
|
1604
|
+
for (; I.parentNode && I.parentNode !== this.contentElement; )
|
|
1605
|
+
I = I.parentNode;
|
|
1606
|
+
I.parentNode === this.contentElement && (u = Array.from(this.contentElement.childNodes).indexOf(I) + 1);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
const h = document.createElement("p");
|
|
1611
|
+
if (h.innerHTML = "<br>", u >= this.contentElement.childNodes.length)
|
|
1612
|
+
this.contentElement.appendChild(i), this.contentElement.appendChild(h);
|
|
1613
|
+
else {
|
|
1614
|
+
const p = this.contentElement.childNodes[u];
|
|
1615
|
+
this.contentElement.insertBefore(i, p), this.contentElement.insertBefore(h, p);
|
|
1616
|
+
}
|
|
1617
|
+
if (a) {
|
|
1618
|
+
const p = document.createRange();
|
|
1619
|
+
p.setStart(h, 0), p.setEnd(h, 0), a.removeAllRanges(), a.addRange(p);
|
|
1620
|
+
}
|
|
1621
|
+
this.updatePlaceholder(), this.syncContentToState(), this.announceToScreenReader(`Table with ${t} rows and ${e} columns inserted`), this.emit("change", { state: this.state });
|
|
1622
|
+
} catch (i) {
|
|
1623
|
+
console.error("Failed to insert table:", i), this.announceToScreenReader("Failed to insert table");
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Announce message to screen readers
|
|
1628
|
+
*/
|
|
1629
|
+
announceToScreenReader(t) {
|
|
1630
|
+
this.ariaLiveRegion ? (this.ariaLiveRegion.textContent = "", setTimeout(() => {
|
|
1631
|
+
this.ariaLiveRegion && (this.ariaLiveRegion.textContent = t);
|
|
1632
|
+
}, 100)) : Le(t);
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* Attach event listeners
|
|
1636
|
+
*/
|
|
1637
|
+
attachEventListeners() {
|
|
1638
|
+
this.contentElement && (this.contentElement.addEventListener("input", this.handleInput.bind(this)), this.contentElement.addEventListener("keydown", this.handleKeydown.bind(this)), this.contentElement.addEventListener("focus", this.handleFocus.bind(this)), this.contentElement.addEventListener("blur", this.handleBlur.bind(this)));
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Detach event listeners
|
|
1642
|
+
*/
|
|
1643
|
+
detachEventListeners() {
|
|
1644
|
+
this.contentElement && (this.contentElement.removeEventListener("input", this.handleInput.bind(this)), this.contentElement.removeEventListener("keydown", this.handleKeydown.bind(this)), this.contentElement.removeEventListener("focus", this.handleFocus.bind(this)), this.contentElement.removeEventListener("blur", this.handleBlur.bind(this)));
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Handle input event
|
|
1648
|
+
*/
|
|
1649
|
+
handleInput(t) {
|
|
1650
|
+
this.updatePlaceholder(), this.syncContentToState(), this.emit("change", { state: this.state });
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Handle keydown event
|
|
1654
|
+
*/
|
|
1655
|
+
handleKeydown(t) {
|
|
1656
|
+
(t.ctrlKey || t.metaKey) && t.key === "z" && (t.preventDefault(), t.shiftKey ? (this.redo(), this.announceToScreenReader("Action redone")) : (this.undo(), this.announceToScreenReader("Action undone"))), ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(t.key) && (t.ctrlKey || t.metaKey) && this.announceToScreenReader(`Navigating ${t.key.replace("Arrow", "").toLowerCase()}`);
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Handle focus event
|
|
1660
|
+
*/
|
|
1661
|
+
handleFocus() {
|
|
1662
|
+
this.emit("focus", { state: this.state });
|
|
1663
|
+
}
|
|
1664
|
+
/**
|
|
1665
|
+
* Handle blur event
|
|
1666
|
+
*/
|
|
1667
|
+
handleBlur() {
|
|
1668
|
+
this.emit("blur", { state: this.state });
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Update placeholder visibility
|
|
1672
|
+
*/
|
|
1673
|
+
updatePlaceholder() {
|
|
1674
|
+
if (!this.shadowRoot) return;
|
|
1675
|
+
const t = this.shadowRoot.querySelector(".notectl-placeholder"), e = !this.contentElement?.textContent?.trim();
|
|
1676
|
+
t && t.classList.toggle("hidden", !e);
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Sync content from DOM to state
|
|
1680
|
+
*/
|
|
1681
|
+
syncContentToState() {
|
|
1682
|
+
if (this.contentElement)
|
|
1683
|
+
try {
|
|
1684
|
+
const t = this.htmlToDocument(this.contentElement.innerHTML);
|
|
1685
|
+
this.state = it.fromJSON(t, this.state.schema);
|
|
1686
|
+
} catch (t) {
|
|
1687
|
+
console.error("Failed to sync content to state:", t);
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* Convert HTML to document structure
|
|
1692
|
+
*/
|
|
1693
|
+
htmlToDocument(t) {
|
|
1694
|
+
const o = new DOMParser().parseFromString(t, "text/html").body, a = [];
|
|
1695
|
+
return Array.from(o.childNodes).forEach((u) => {
|
|
1696
|
+
const h = this.nodeToBlock(u);
|
|
1697
|
+
h && a.push(h);
|
|
1698
|
+
}), a.length === 0 && a.push({
|
|
1699
|
+
id: crypto.randomUUID(),
|
|
1700
|
+
type: "paragraph",
|
|
1701
|
+
children: []
|
|
1702
|
+
}), {
|
|
1703
|
+
version: this.state.getDocument().version + 1,
|
|
1704
|
+
schemaVersion: "1.0.0",
|
|
1705
|
+
children: a
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Convert DOM node to block
|
|
1710
|
+
*/
|
|
1711
|
+
nodeToBlock(t) {
|
|
1712
|
+
if (t.nodeType === Node.TEXT_NODE) {
|
|
1713
|
+
const e = t.textContent || "";
|
|
1714
|
+
return e.trim() ? {
|
|
1715
|
+
type: "text",
|
|
1716
|
+
text: e,
|
|
1717
|
+
marks: []
|
|
1718
|
+
} : null;
|
|
1719
|
+
}
|
|
1720
|
+
if (t.nodeType === Node.ELEMENT_NODE) {
|
|
1721
|
+
const e = t, i = e.tagName.toLowerCase();
|
|
1722
|
+
if (i === "p")
|
|
1723
|
+
return {
|
|
1724
|
+
id: crypto.randomUUID(),
|
|
1725
|
+
type: "paragraph",
|
|
1726
|
+
children: this.parseChildren(e)
|
|
1727
|
+
};
|
|
1728
|
+
if (["h1", "h2", "h3", "h4", "h5", "h6"].includes(i)) {
|
|
1729
|
+
const o = parseInt(i.charAt(1), 10);
|
|
1730
|
+
return {
|
|
1731
|
+
id: crypto.randomUUID(),
|
|
1732
|
+
type: "heading",
|
|
1733
|
+
attrs: { level: o },
|
|
1734
|
+
children: this.parseChildren(e)
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
return this.parseInlineElement(e);
|
|
1738
|
+
}
|
|
1739
|
+
return null;
|
|
1740
|
+
}
|
|
1741
|
+
/**
|
|
1742
|
+
* Parse children nodes
|
|
1743
|
+
*/
|
|
1744
|
+
parseChildren(t) {
|
|
1745
|
+
const e = [];
|
|
1746
|
+
return Array.from(t.childNodes).forEach((i) => {
|
|
1747
|
+
if (i.nodeType === Node.TEXT_NODE) {
|
|
1748
|
+
const o = i.textContent || "";
|
|
1749
|
+
o && e.push({
|
|
1750
|
+
type: "text",
|
|
1751
|
+
text: o,
|
|
1752
|
+
marks: []
|
|
1753
|
+
});
|
|
1754
|
+
} else if (i.nodeType === Node.ELEMENT_NODE) {
|
|
1755
|
+
const o = i, a = this.parseInlineElement(o);
|
|
1756
|
+
a && (Array.isArray(a) ? e.push(...a) : e.push(a));
|
|
1757
|
+
}
|
|
1758
|
+
}), e;
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Parse inline element with marks
|
|
1762
|
+
*/
|
|
1763
|
+
parseInlineElement(t) {
|
|
1764
|
+
const e = t.tagName.toLowerCase(), i = [];
|
|
1765
|
+
e === "strong" || e === "b" ? i.push({ type: "bold" }) : e === "em" || e === "i" ? i.push({ type: "italic" }) : e === "u" ? i.push({ type: "underline" }) : e === "s" || e === "strike" ? i.push({ type: "strikethrough" }) : e === "code" && i.push({ type: "code" });
|
|
1766
|
+
const o = [];
|
|
1767
|
+
return Array.from(t.childNodes).forEach((a) => {
|
|
1768
|
+
if (a.nodeType === Node.TEXT_NODE) {
|
|
1769
|
+
const u = a.textContent || "";
|
|
1770
|
+
u && o.push({
|
|
1771
|
+
type: "text",
|
|
1772
|
+
text: u,
|
|
1773
|
+
marks: i
|
|
1774
|
+
});
|
|
1775
|
+
} else if (a.nodeType === Node.ELEMENT_NODE) {
|
|
1776
|
+
const u = a, h = this.parseInlineElement(u);
|
|
1777
|
+
h && (h.type === "text" ? (h.marks = [...i, ...h.marks || []], o.push(h)) : Array.isArray(h) && h.forEach((p) => {
|
|
1778
|
+
p.type === "text" && (p.marks = [...i, ...p.marks || []]), o.push(p);
|
|
1779
|
+
}));
|
|
1780
|
+
}
|
|
1781
|
+
}), o.length === 1 ? o[0] : o;
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Update readonly state
|
|
1785
|
+
*/
|
|
1786
|
+
updateReadonly() {
|
|
1787
|
+
this.contentElement && (this.contentElement.contentEditable = String(!this.config.readonly), this.contentElement.setAttribute("data-readonly", String(this.config.readonly)));
|
|
1788
|
+
}
|
|
1789
|
+
/**
|
|
1790
|
+
* Register a plugin
|
|
1791
|
+
*/
|
|
1792
|
+
async registerPlugin(t) {
|
|
1793
|
+
const e = this.createPluginContext();
|
|
1794
|
+
await this.pluginManager.register(t, e);
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* Unregister a plugin
|
|
1798
|
+
*/
|
|
1799
|
+
async unregisterPlugin(t) {
|
|
1800
|
+
const e = this.createPluginContext();
|
|
1801
|
+
await this.pluginManager.unregister(t, e);
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Create plugin context
|
|
1805
|
+
*/
|
|
1806
|
+
createPluginContext() {
|
|
1807
|
+
return {
|
|
1808
|
+
getState: () => this.state,
|
|
1809
|
+
applyDelta: (t) => this.applyDelta(t),
|
|
1810
|
+
on: (t, e) => this.on(t, e),
|
|
1811
|
+
off: (t, e) => this.off(t, e),
|
|
1812
|
+
emit: (t, e) => this.emit(t, e),
|
|
1813
|
+
registerCommand: (t, e) => this.registerCommand(t, e),
|
|
1814
|
+
executeCommand: (t, ...e) => this.executeCommand(t, ...e),
|
|
1815
|
+
getContainer: () => this.contentElement,
|
|
1816
|
+
getPluginContainer: (t) => t === "top" ? this.pluginContainerTop : this.pluginContainerBottom
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Apply a delta
|
|
1821
|
+
*/
|
|
1822
|
+
applyDelta(t) {
|
|
1823
|
+
if (!Ln(t)) {
|
|
1824
|
+
console.error("Invalid or unsafe delta rejected"), this.announceToScreenReader("Action blocked due to security validation");
|
|
1825
|
+
return;
|
|
1826
|
+
}
|
|
1827
|
+
this.state.applyDelta(t), this.renderContent(), this.pluginManager.notifyDeltaApplied(t), this.emit("change", { delta: t, state: this.state });
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Register event listener
|
|
1831
|
+
*/
|
|
1832
|
+
on(t, e) {
|
|
1833
|
+
this.eventListeners.has(t) || this.eventListeners.set(t, /* @__PURE__ */ new Set()), this.eventListeners.get(t).add(e);
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Unregister event listener
|
|
1837
|
+
*/
|
|
1838
|
+
off(t, e) {
|
|
1839
|
+
this.eventListeners.get(t)?.delete(e);
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Emit event
|
|
1843
|
+
*/
|
|
1844
|
+
emit(t, e) {
|
|
1845
|
+
this.eventListeners.get(t)?.forEach((i) => {
|
|
1846
|
+
try {
|
|
1847
|
+
i(e);
|
|
1848
|
+
} catch (o) {
|
|
1849
|
+
console.error(`Error in event listener for ${t}:`, o);
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Register command
|
|
1855
|
+
*/
|
|
1856
|
+
registerCommand(t, e) {
|
|
1857
|
+
this.commands.set(t, e);
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Execute command
|
|
1861
|
+
*/
|
|
1862
|
+
executeCommand(t, ...e) {
|
|
1863
|
+
const i = this.commands.get(t);
|
|
1864
|
+
if (!i)
|
|
1865
|
+
throw new Error(`Command not found: ${t}`);
|
|
1866
|
+
return i(...e);
|
|
1867
|
+
}
|
|
1868
|
+
/**
|
|
1869
|
+
* Undo last change
|
|
1870
|
+
*/
|
|
1871
|
+
undo() {
|
|
1872
|
+
const t = this.state.undo();
|
|
1873
|
+
t ? (this.renderContent(), this.announceToScreenReader("Undo performed"), this.emit("change", { delta: t, state: this.state })) : this.announceToScreenReader("Nothing to undo");
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Redo last undone change
|
|
1877
|
+
*/
|
|
1878
|
+
redo() {
|
|
1879
|
+
const t = this.state.redo();
|
|
1880
|
+
t ? (this.renderContent(), this.announceToScreenReader("Redo performed"), this.emit("change", { delta: t, state: this.state })) : this.announceToScreenReader("Nothing to redo");
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* Configure editor options
|
|
1884
|
+
* @param config - Configuration options to apply
|
|
1885
|
+
*/
|
|
1886
|
+
configure(t) {
|
|
1887
|
+
if (this.config = { ...this.config, ...t }, t.readonly !== void 0 && this.updateReadonly(), t.placeholder !== void 0 && this.shadowRoot) {
|
|
1888
|
+
const e = this.shadowRoot.querySelector(".notectl-placeholder");
|
|
1889
|
+
e && (e.textContent = t.placeholder);
|
|
1890
|
+
}
|
|
1891
|
+
t.initialContent && typeof t.initialContent == "object" && this.setJSON(t.initialContent), t.content && (typeof t.content == "string" ? this.setContent(t.content) : this.setJSON(t.content));
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Destroy the editor and clean up resources
|
|
1895
|
+
*/
|
|
1896
|
+
destroy() {
|
|
1897
|
+
this.detachEventListeners(), this.pluginManager.destroyAll(), this.keyboardShortcutCleanup && this.keyboardShortcutCleanup(), this.ariaLiveRegion && this.ariaLiveRegion.parentNode && this.ariaLiveRegion.parentNode.removeChild(this.ariaLiveRegion), this.eventListeners.clear(), this.commands.clear();
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* Get current content as string or JSON
|
|
1901
|
+
* @returns Current document content
|
|
1902
|
+
*/
|
|
1903
|
+
getContent() {
|
|
1904
|
+
return this.getJSON();
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Get current state
|
|
1908
|
+
*/
|
|
1909
|
+
getState() {
|
|
1910
|
+
return this.state;
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Get document as JSON
|
|
1914
|
+
*/
|
|
1915
|
+
getJSON() {
|
|
1916
|
+
return this.state.toJSON();
|
|
1917
|
+
}
|
|
1918
|
+
/**
|
|
1919
|
+
* Set document from JSON
|
|
1920
|
+
*/
|
|
1921
|
+
setJSON(t) {
|
|
1922
|
+
this.state = it.fromJSON(t, this.state.schema), this.renderContent();
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Get HTML content (sanitized)
|
|
1926
|
+
*/
|
|
1927
|
+
getHTML() {
|
|
1928
|
+
const t = this.documentToHTML(this.state.getDocument());
|
|
1929
|
+
return this.config.sanitizeHTML ? rt(t) : t;
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Set HTML content (with sanitization)
|
|
1933
|
+
* @param html - HTML content to set
|
|
1934
|
+
*/
|
|
1935
|
+
setHTML(t) {
|
|
1936
|
+
const e = this.config.sanitizeHTML ? rt(t) : t;
|
|
1937
|
+
this.contentElement && (this.contentElement.innerHTML = e, this.announceToScreenReader("Content updated"));
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
* Set content from string (with sanitization)
|
|
1941
|
+
* @param content - Content to set
|
|
1942
|
+
* @param allowHTML - Allow HTML tags
|
|
1943
|
+
*/
|
|
1944
|
+
setContent(t, e = !0) {
|
|
1945
|
+
const i = this.config.sanitizeHTML ? An(t, e) : t;
|
|
1946
|
+
this.contentElement && (this.contentElement.innerHTML = i, this.announceToScreenReader("Content updated"));
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Export HTML content (sanitized)
|
|
1950
|
+
* @returns Sanitized HTML
|
|
1951
|
+
*/
|
|
1952
|
+
exportHTML() {
|
|
1953
|
+
return this.getHTML();
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Focus the editor
|
|
1957
|
+
*/
|
|
1958
|
+
focus() {
|
|
1959
|
+
this.contentElement?.focus();
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1962
|
+
* Blur the editor
|
|
1963
|
+
*/
|
|
1964
|
+
blur() {
|
|
1965
|
+
this.contentElement?.blur();
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
customElements.get("notectl-editor") || customElements.define("notectl-editor", Re);
|
|
1969
|
+
class Mn {
|
|
1970
|
+
async init(t) {
|
|
1971
|
+
this.context = t;
|
|
1972
|
+
}
|
|
1973
|
+
async destroy() {
|
|
1974
|
+
this.context = void 0;
|
|
1975
|
+
}
|
|
1976
|
+
getContext() {
|
|
1977
|
+
if (!this.context)
|
|
1978
|
+
throw new Error("Plugin not initialized");
|
|
1979
|
+
return this.context;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
class wn {
|
|
1983
|
+
constructor(t, e) {
|
|
1984
|
+
this.operations = [], this.delta = {
|
|
1985
|
+
txnId: this.generateTxnId(),
|
|
1986
|
+
clientId: t,
|
|
1987
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1988
|
+
baseVersion: e,
|
|
1989
|
+
ltime: Date.now(),
|
|
1990
|
+
ops: []
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
/**
|
|
1994
|
+
* Set the intent of this delta
|
|
1995
|
+
*/
|
|
1996
|
+
setIntent(t) {
|
|
1997
|
+
return this.delta.intent = t, this;
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Set the undo group for batch operations
|
|
2001
|
+
*/
|
|
2002
|
+
setUndoGroup(t) {
|
|
2003
|
+
return this.delta.undoGroup = t, this;
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Add an operation to this delta
|
|
2007
|
+
*/
|
|
2008
|
+
addOperation(t) {
|
|
2009
|
+
return this.operations.push(t), this;
|
|
2010
|
+
}
|
|
2011
|
+
/**
|
|
2012
|
+
* Add multiple operations
|
|
2013
|
+
*/
|
|
2014
|
+
addOperations(t) {
|
|
2015
|
+
return this.operations.push(...t), this;
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Set inverse operations for fast undo
|
|
2019
|
+
*/
|
|
2020
|
+
setInverseOps(t) {
|
|
2021
|
+
return this.delta.inverseOps = t, this;
|
|
2022
|
+
}
|
|
2023
|
+
/**
|
|
2024
|
+
* Set validation constraints
|
|
2025
|
+
*/
|
|
2026
|
+
setValidation(t) {
|
|
2027
|
+
return this.delta.validation = t, this;
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* Build the final delta
|
|
2031
|
+
*/
|
|
2032
|
+
build() {
|
|
2033
|
+
if (this.operations.length === 0)
|
|
2034
|
+
throw new Error("Delta must contain at least one operation");
|
|
2035
|
+
return {
|
|
2036
|
+
...this.delta,
|
|
2037
|
+
ops: this.operations
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
/**
|
|
2041
|
+
* Generate a unique transaction ID
|
|
2042
|
+
*/
|
|
2043
|
+
generateTxnId() {
|
|
2044
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
|
|
2045
|
+
const e = Math.random() * 16 | 0;
|
|
2046
|
+
return (t === "x" ? e : e & 3 | 8).toString(16);
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
function Pn(r, t) {
|
|
2051
|
+
return new wn(r, t);
|
|
2052
|
+
}
|
|
2053
|
+
function Un(r) {
|
|
2054
|
+
return r.inverseOps || [];
|
|
2055
|
+
}
|
|
2056
|
+
function Hn(r) {
|
|
2057
|
+
const t = [];
|
|
2058
|
+
return r.txnId || t.push("Delta must have a transaction ID"), r.clientId || t.push("Delta must have a client ID"), r.ops.length === 0 && t.push("Delta must contain at least one operation"), r.baseVersion < 0 && t.push("Base version must be non-negative"), {
|
|
2059
|
+
valid: t.length === 0,
|
|
2060
|
+
errors: t
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
function Fn(r) {
|
|
2064
|
+
return r.op === "insert_text" || r.op === "delete_range" || r.op === "apply_mark";
|
|
2065
|
+
}
|
|
2066
|
+
function zn(r) {
|
|
2067
|
+
return r.op === "insert_block_before" || r.op === "insert_block_after" || r.op === "delete_block" || r.op === "set_attrs";
|
|
2068
|
+
}
|
|
2069
|
+
function $n(r) {
|
|
2070
|
+
return r.op.startsWith("table_");
|
|
2071
|
+
}
|
|
2072
|
+
function Gn(r) {
|
|
2073
|
+
return r.op === "update_selection";
|
|
2074
|
+
}
|
|
2075
|
+
function In(r, t, e) {
|
|
2076
|
+
return r.op === "insert_text" && t.op === "insert_text" ? On(r, t, e) : r.op === "insert_text" && t.op === "delete_range" ? Nn(r, t) : r.op === "delete_range" && t.op === "insert_text" ? vn(r, t) : r.op === "delete_range" && t.op === "delete_range" ? Dn(r, t) : r;
|
|
2077
|
+
}
|
|
2078
|
+
function On(r, t, e) {
|
|
2079
|
+
if (r.target.blockId === t.target.blockId) {
|
|
2080
|
+
if (t.target.offset <= r.target.offset)
|
|
2081
|
+
return {
|
|
2082
|
+
...r,
|
|
2083
|
+
target: {
|
|
2084
|
+
...r.target,
|
|
2085
|
+
offset: r.target.offset + t.text.length
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
if (t.target.offset === r.target.offset && e === "right")
|
|
2089
|
+
return {
|
|
2090
|
+
...r,
|
|
2091
|
+
target: {
|
|
2092
|
+
...r.target,
|
|
2093
|
+
offset: r.target.offset + t.text.length
|
|
2094
|
+
}
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
return r;
|
|
2098
|
+
}
|
|
2099
|
+
function Nn(r, t) {
|
|
2100
|
+
if (r.target.blockId === t.range.start.blockId && r.target.offset >= t.range.start.offset) {
|
|
2101
|
+
const e = t.range.end.offset - t.range.start.offset;
|
|
2102
|
+
return {
|
|
2103
|
+
...r,
|
|
2104
|
+
target: {
|
|
2105
|
+
...r.target,
|
|
2106
|
+
offset: Math.max(t.range.start.offset, r.target.offset - e)
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
}
|
|
2110
|
+
return r;
|
|
2111
|
+
}
|
|
2112
|
+
function vn(r, t) {
|
|
2113
|
+
return r.range.start.blockId === t.target.blockId && t.target.offset <= r.range.start.offset ? {
|
|
2114
|
+
...r,
|
|
2115
|
+
range: {
|
|
2116
|
+
start: {
|
|
2117
|
+
...r.range.start,
|
|
2118
|
+
offset: r.range.start.offset + t.text.length
|
|
2119
|
+
},
|
|
2120
|
+
end: {
|
|
2121
|
+
...r.range.end,
|
|
2122
|
+
offset: r.range.end.offset + t.text.length
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
} : r;
|
|
2126
|
+
}
|
|
2127
|
+
function Dn(r, t, e) {
|
|
2128
|
+
if (r.range.start.blockId === t.range.start.blockId) {
|
|
2129
|
+
const i = r.range.start.offset, o = r.range.end.offset, a = t.range.start.offset, u = t.range.end.offset;
|
|
2130
|
+
if (u <= i) {
|
|
2131
|
+
const h = u - a;
|
|
2132
|
+
return {
|
|
2133
|
+
...r,
|
|
2134
|
+
range: {
|
|
2135
|
+
start: { ...r.range.start, offset: i - h },
|
|
2136
|
+
end: { ...r.range.end, offset: o - h }
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
if (a <= i && u >= o)
|
|
2141
|
+
return {
|
|
2142
|
+
...r,
|
|
2143
|
+
range: {
|
|
2144
|
+
start: { ...r.range.start, offset: a },
|
|
2145
|
+
end: { ...r.range.end, offset: a }
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
return r;
|
|
2150
|
+
}
|
|
2151
|
+
function Wn(r, t, e = "left") {
|
|
2152
|
+
const i = r.ops.map((o) => {
|
|
2153
|
+
let a = o;
|
|
2154
|
+
for (const u of t.ops)
|
|
2155
|
+
a = In(a, u, e);
|
|
2156
|
+
return a;
|
|
2157
|
+
});
|
|
2158
|
+
return {
|
|
2159
|
+
...r,
|
|
2160
|
+
ops: i,
|
|
2161
|
+
baseVersion: t.baseVersion + 1
|
|
2162
|
+
// Update to new base
|
|
2163
|
+
};
|
|
2164
|
+
}
|
|
2165
|
+
function Bn(r, t) {
|
|
2166
|
+
return {
|
|
2167
|
+
...t,
|
|
2168
|
+
ops: [...r.ops, ...t.ops],
|
|
2169
|
+
baseVersion: r.baseVersion
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
function Kn(r, t) {
|
|
2173
|
+
return t.baseVersion === r.baseVersion || t.clientId === r.clientId;
|
|
2174
|
+
}
|
|
2175
|
+
function Yn(r, t) {
|
|
2176
|
+
const e = new Re();
|
|
2177
|
+
return r.appendChild(e), e;
|
|
2178
|
+
}
|
|
2179
|
+
const Vn = "0.0.1";
|
|
2180
|
+
export {
|
|
2181
|
+
Mn as BasePlugin,
|
|
2182
|
+
wn as DeltaBuilder,
|
|
2183
|
+
it as EditorState,
|
|
2184
|
+
qe as NodeFactory,
|
|
2185
|
+
Re as NotectlEditor,
|
|
2186
|
+
Je as PluginManager,
|
|
2187
|
+
Xe as Schema,
|
|
2188
|
+
Vn as VERSION,
|
|
2189
|
+
Kn as canCompose,
|
|
2190
|
+
Bn as composeDelta,
|
|
2191
|
+
Un as computeInverse,
|
|
2192
|
+
be as createDefaultSchema,
|
|
2193
|
+
Pn as createDelta,
|
|
2194
|
+
Yn as createEditor,
|
|
2195
|
+
Ze as createNodeFactory,
|
|
2196
|
+
O as generateBlockId,
|
|
2197
|
+
zn as isBlockOperation,
|
|
2198
|
+
Gn as isSelectionOperation,
|
|
2199
|
+
$n as isTableOperation,
|
|
2200
|
+
Fn as isTextOperation,
|
|
2201
|
+
Wn as transformDelta,
|
|
2202
|
+
In as transformOperation,
|
|
2203
|
+
Hn as validateDelta
|
|
2204
|
+
};
|
|
2205
|
+
//# sourceMappingURL=notectl-core.js.map
|