@notectl/core 0.0.2 → 0.0.5
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 +1195 -607
- package/dist/notectl-core.js.map +1 -1
- package/dist/notectl-core.umd.cjs +7 -3
- package/dist/notectl-core.umd.cjs.map +1 -1
- package/dist/types/index.d.ts +380 -1
- package/package.json +2 -2
package/dist/notectl-core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class Ze {
|
|
2
2
|
constructor(t) {
|
|
3
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
4
|
}
|
|
@@ -20,21 +20,21 @@ class Xe {
|
|
|
20
20
|
validateNode(t) {
|
|
21
21
|
const e = [];
|
|
22
22
|
if ("text" in t) {
|
|
23
|
-
const
|
|
24
|
-
if (typeof
|
|
25
|
-
for (const o of
|
|
23
|
+
const n = t;
|
|
24
|
+
if (typeof n.text != "string" && e.push("Text node must have a string text property"), n.marks)
|
|
25
|
+
for (const o of n.marks)
|
|
26
26
|
this.marks.has(o.type) || e.push(`Unknown mark type: ${o.type}`);
|
|
27
27
|
} else {
|
|
28
|
-
const
|
|
28
|
+
const n = t, o = this.nodes.get(n.type);
|
|
29
29
|
if (!o)
|
|
30
|
-
return e.push(`Unknown node type: ${
|
|
30
|
+
return e.push(`Unknown node type: ${n.type}`), { valid: !1, errors: e };
|
|
31
31
|
if (o.attrs)
|
|
32
|
-
for (const [
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
for (const
|
|
36
|
-
const
|
|
37
|
-
e.push(...
|
|
32
|
+
for (const [s, l] of Object.entries(o.attrs))
|
|
33
|
+
l.required && (!n.attrs || !(s in n.attrs)) && e.push(`Required attribute missing: ${s}`), n.attrs?.[s] && l.validate && (l.validate(n.attrs[s]) || e.push(`Invalid attribute value: ${s}`));
|
|
34
|
+
if (n.children)
|
|
35
|
+
for (const s of n.children) {
|
|
36
|
+
const l = this.validateNode(s);
|
|
37
|
+
e.push(...l.errors);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
return {
|
|
@@ -46,19 +46,19 @@ class Xe {
|
|
|
46
46
|
* Check if a mark is allowed on a node
|
|
47
47
|
*/
|
|
48
48
|
markAllowedOn(t, e) {
|
|
49
|
-
const
|
|
50
|
-
return !
|
|
49
|
+
const n = this.nodes.get(e);
|
|
50
|
+
return !n || !n.marks ? !1 : n.marks === "_" ? !0 : n.marks.split(" ").includes(t);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Check if two marks can coexist
|
|
54
54
|
*/
|
|
55
55
|
marksCompatible(t, e) {
|
|
56
|
-
const
|
|
57
|
-
return !(
|
|
56
|
+
const n = this.marks.get(t), o = this.marks.get(e);
|
|
57
|
+
return !(n?.excludes && n.excludes.split(" ").includes(e) || o?.excludes && o.excludes.split(" ").includes(t));
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
function be() {
|
|
61
|
-
return new
|
|
61
|
+
return new Ze({
|
|
62
62
|
nodes: [
|
|
63
63
|
{
|
|
64
64
|
type: "paragraph",
|
|
@@ -141,13 +141,13 @@ function be() {
|
|
|
141
141
|
topNode: "paragraph"
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function w() {
|
|
145
145
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (r) => {
|
|
146
146
|
const t = Math.random() * 16 | 0;
|
|
147
147
|
return (r === "x" ? t : t & 3 | 8).toString(16);
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
|
-
class
|
|
150
|
+
class Je {
|
|
151
151
|
constructor(t) {
|
|
152
152
|
this.schema = t;
|
|
153
153
|
}
|
|
@@ -166,7 +166,7 @@ class qe {
|
|
|
166
166
|
*/
|
|
167
167
|
paragraph(t, e) {
|
|
168
168
|
return {
|
|
169
|
-
id:
|
|
169
|
+
id: w(),
|
|
170
170
|
type: "paragraph",
|
|
171
171
|
attrs: e,
|
|
172
172
|
children: t || []
|
|
@@ -175,11 +175,11 @@ class qe {
|
|
|
175
175
|
/**
|
|
176
176
|
* Create a heading node
|
|
177
177
|
*/
|
|
178
|
-
heading(t, e,
|
|
178
|
+
heading(t, e, n) {
|
|
179
179
|
return {
|
|
180
|
-
id:
|
|
180
|
+
id: w(),
|
|
181
181
|
type: "heading",
|
|
182
|
-
attrs: { ...
|
|
182
|
+
attrs: { ...n, level: t },
|
|
183
183
|
children: e || []
|
|
184
184
|
};
|
|
185
185
|
}
|
|
@@ -188,7 +188,7 @@ class qe {
|
|
|
188
188
|
*/
|
|
189
189
|
list(t, e) {
|
|
190
190
|
return {
|
|
191
|
-
id:
|
|
191
|
+
id: w(),
|
|
192
192
|
type: "list",
|
|
193
193
|
attrs: e,
|
|
194
194
|
children: t
|
|
@@ -199,7 +199,7 @@ class qe {
|
|
|
199
199
|
*/
|
|
200
200
|
listItem(t, e) {
|
|
201
201
|
return {
|
|
202
|
-
id:
|
|
202
|
+
id: w(),
|
|
203
203
|
type: "list_item",
|
|
204
204
|
attrs: e,
|
|
205
205
|
children: t
|
|
@@ -210,7 +210,7 @@ class qe {
|
|
|
210
210
|
*/
|
|
211
211
|
table(t, e) {
|
|
212
212
|
return {
|
|
213
|
-
id:
|
|
213
|
+
id: w(),
|
|
214
214
|
type: "table",
|
|
215
215
|
attrs: e,
|
|
216
216
|
children: t
|
|
@@ -221,7 +221,7 @@ class qe {
|
|
|
221
221
|
*/
|
|
222
222
|
tableRow(t, e) {
|
|
223
223
|
return {
|
|
224
|
-
id:
|
|
224
|
+
id: w(),
|
|
225
225
|
type: "table_row",
|
|
226
226
|
attrs: e,
|
|
227
227
|
children: t
|
|
@@ -232,7 +232,7 @@ class qe {
|
|
|
232
232
|
*/
|
|
233
233
|
tableCell(t, e) {
|
|
234
234
|
return {
|
|
235
|
-
id:
|
|
235
|
+
id: w(),
|
|
236
236
|
type: "table_cell",
|
|
237
237
|
attrs: e,
|
|
238
238
|
children: t
|
|
@@ -241,11 +241,11 @@ class qe {
|
|
|
241
241
|
/**
|
|
242
242
|
* Create an image node
|
|
243
243
|
*/
|
|
244
|
-
image(t, e,
|
|
244
|
+
image(t, e, n) {
|
|
245
245
|
return {
|
|
246
|
-
id:
|
|
246
|
+
id: w(),
|
|
247
247
|
type: "image",
|
|
248
|
-
attrs: { src: t, alt: e || "", decorative: !e, ...
|
|
248
|
+
attrs: { src: t, alt: e || "", decorative: !e, ...n },
|
|
249
249
|
children: []
|
|
250
250
|
};
|
|
251
251
|
}
|
|
@@ -254,7 +254,7 @@ class qe {
|
|
|
254
254
|
*/
|
|
255
255
|
codeBlock(t, e) {
|
|
256
256
|
return {
|
|
257
|
-
id:
|
|
257
|
+
id: w(),
|
|
258
258
|
type: "code_block",
|
|
259
259
|
attrs: e,
|
|
260
260
|
children: [this.text(t)]
|
|
@@ -263,14 +263,14 @@ class qe {
|
|
|
263
263
|
/**
|
|
264
264
|
* Create a generic block node
|
|
265
265
|
*/
|
|
266
|
-
block(t, e,
|
|
266
|
+
block(t, e, n) {
|
|
267
267
|
if (!this.schema.node(t))
|
|
268
268
|
throw new Error(`Unknown node type: ${t}`);
|
|
269
269
|
return {
|
|
270
|
-
id:
|
|
270
|
+
id: w(),
|
|
271
271
|
type: t,
|
|
272
272
|
attrs: e,
|
|
273
|
-
children:
|
|
273
|
+
children: n
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
276
|
/**
|
|
@@ -290,18 +290,18 @@ class qe {
|
|
|
290
290
|
cloneNode(t, e) {
|
|
291
291
|
return {
|
|
292
292
|
...t,
|
|
293
|
-
id:
|
|
293
|
+
id: w(),
|
|
294
294
|
// Generate new ID for cloned node
|
|
295
295
|
children: e !== void 0 ? e : t.children
|
|
296
296
|
};
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
|
-
function
|
|
300
|
-
return new
|
|
299
|
+
function Qe(r) {
|
|
300
|
+
return new Je(r);
|
|
301
301
|
}
|
|
302
|
-
class
|
|
303
|
-
constructor(t, e,
|
|
304
|
-
this.selection = null, this.history = [], this.historyIndex = -1, this.schema = e || be(), this.nodeFactory =
|
|
302
|
+
class ot {
|
|
303
|
+
constructor(t, e, n) {
|
|
304
|
+
this.selection = null, this.history = [], this.historyIndex = -1, this.schema = e || be(), this.nodeFactory = Qe(this.schema), this.maxHistoryDepth = n?.maxHistoryDepth || 100, this.document = t || {
|
|
305
305
|
version: 0,
|
|
306
306
|
schemaVersion: "1.0.0",
|
|
307
307
|
children: [this.nodeFactory.paragraph()]
|
|
@@ -339,9 +339,9 @@ class it {
|
|
|
339
339
|
throw new Error(
|
|
340
340
|
`Delta version mismatch: expected ${this.document.version}, got ${t.baseVersion}`
|
|
341
341
|
);
|
|
342
|
-
t.ops.some((
|
|
343
|
-
for (const
|
|
344
|
-
this.applyOperation(
|
|
342
|
+
t.ops.some((n) => n.op !== "update_selection") && this.addToHistory(t);
|
|
343
|
+
for (const n of t.ops)
|
|
344
|
+
this.applyOperation(n);
|
|
345
345
|
this.document.version++;
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
@@ -387,10 +387,10 @@ class it {
|
|
|
387
387
|
applyInsertText(t) {
|
|
388
388
|
const e = this.findBlock(t.target.blockId);
|
|
389
389
|
if (!e || !e.children) return;
|
|
390
|
-
const
|
|
391
|
-
if (
|
|
392
|
-
const o =
|
|
393
|
-
|
|
390
|
+
const n = e.children.find((o) => "text" in o);
|
|
391
|
+
if (n) {
|
|
392
|
+
const o = n.text.slice(0, t.target.offset), s = n.text.slice(t.target.offset);
|
|
393
|
+
n.text = o + t.text + s, t.marks && t.marks.length > 0 && (n.marks = t.marks);
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
/**
|
|
@@ -399,10 +399,10 @@ class it {
|
|
|
399
399
|
applyDeleteRange(t) {
|
|
400
400
|
const e = this.findBlock(t.range.start.blockId);
|
|
401
401
|
if (!e || !e.children) return;
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
404
|
-
const o =
|
|
405
|
-
|
|
402
|
+
const n = e.children.find((o) => "text" in o);
|
|
403
|
+
if (n) {
|
|
404
|
+
const o = n.text.slice(0, t.range.start.offset), s = n.text.slice(t.range.end.offset);
|
|
405
|
+
n.text = o + s;
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
/**
|
|
@@ -411,28 +411,28 @@ class it {
|
|
|
411
411
|
applyMark(t) {
|
|
412
412
|
const e = this.findBlock(t.range.start.blockId);
|
|
413
413
|
if (!e || !e.children) return;
|
|
414
|
-
const
|
|
415
|
-
|
|
414
|
+
const n = e.children.find((o) => "text" in o);
|
|
415
|
+
n && (t.add ? (n.marks = n.marks || [], n.marks.some((o) => o.type === t.mark.type) || n.marks.push(t.mark)) : n.marks = n.marks?.filter((o) => o.type !== t.mark.type));
|
|
416
416
|
}
|
|
417
417
|
/**
|
|
418
418
|
* Apply insert block after operation
|
|
419
419
|
*/
|
|
420
420
|
applyInsertBlockAfter(t) {
|
|
421
|
-
const e = this.document.children.findIndex((
|
|
421
|
+
const e = this.document.children.findIndex((n) => n.id === t.after);
|
|
422
422
|
e !== -1 && this.document.children.splice(e + 1, 0, t.block);
|
|
423
423
|
}
|
|
424
424
|
/**
|
|
425
425
|
* Apply insert block before operation
|
|
426
426
|
*/
|
|
427
427
|
applyInsertBlockBefore(t) {
|
|
428
|
-
const e = this.document.children.findIndex((
|
|
428
|
+
const e = this.document.children.findIndex((n) => n.id === t.before);
|
|
429
429
|
e !== -1 && this.document.children.splice(e, 0, t.block);
|
|
430
430
|
}
|
|
431
431
|
/**
|
|
432
432
|
* Apply delete block operation
|
|
433
433
|
*/
|
|
434
434
|
applyDeleteBlock(t) {
|
|
435
|
-
const e = this.document.children.findIndex((
|
|
435
|
+
const e = this.document.children.findIndex((n) => n.id === t.target.blockId);
|
|
436
436
|
e !== -1 && this.document.children.splice(e, 1);
|
|
437
437
|
}
|
|
438
438
|
/**
|
|
@@ -446,13 +446,13 @@ class it {
|
|
|
446
446
|
* Find a block by ID
|
|
447
447
|
*/
|
|
448
448
|
findBlock(t) {
|
|
449
|
-
const e = (
|
|
450
|
-
for (const o of
|
|
449
|
+
const e = (n) => {
|
|
450
|
+
for (const o of n) {
|
|
451
451
|
if (o.id === t)
|
|
452
452
|
return o;
|
|
453
453
|
if (o.children) {
|
|
454
|
-
const
|
|
455
|
-
if (
|
|
454
|
+
const s = o.children.filter((h) => "id" in h), l = e(s);
|
|
455
|
+
if (l) return l;
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
458
|
};
|
|
@@ -506,37 +506,205 @@ class it {
|
|
|
506
506
|
* Create state from JSON
|
|
507
507
|
*/
|
|
508
508
|
static fromJSON(t, e) {
|
|
509
|
-
return new
|
|
509
|
+
return new ot(t, e);
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
|
-
|
|
512
|
+
const Un = 100, Fn = 100, Hn = 100, Gn = 200, R = {
|
|
513
|
+
// Plugin-related errors
|
|
514
|
+
PLUGIN_ALREADY_REGISTERED: "PLUGIN_ALREADY_REGISTERED",
|
|
515
|
+
PLUGIN_NOT_FOUND: "PLUGIN_NOT_FOUND",
|
|
516
|
+
PLUGIN_MISSING_DEPENDENCY: "PLUGIN_MISSING_DEPENDENCY",
|
|
517
|
+
PLUGIN_INVALID_CONFIG: "PLUGIN_INVALID_CONFIG",
|
|
518
|
+
PLUGIN_INIT_FAILED: "PLUGIN_INIT_FAILED",
|
|
519
|
+
PLUGIN_DESTROY_FAILED: "PLUGIN_DESTROY_FAILED",
|
|
520
|
+
PLUGIN_DEPENDENCY_CONFLICT: "PLUGIN_DEPENDENCY_CONFLICT",
|
|
521
|
+
// Editor state errors
|
|
522
|
+
EDITOR_NOT_MOUNTED: "EDITOR_NOT_MOUNTED",
|
|
523
|
+
EDITOR_NOT_INITIALIZED: "EDITOR_NOT_INITIALIZED",
|
|
524
|
+
EDITOR_DESTROYED: "EDITOR_DESTROYED",
|
|
525
|
+
// Command errors
|
|
526
|
+
COMMAND_NOT_FOUND: "COMMAND_NOT_FOUND",
|
|
527
|
+
COMMAND_ALREADY_REGISTERED: "COMMAND_ALREADY_REGISTERED",
|
|
528
|
+
COMMAND_EXECUTION_FAILED: "COMMAND_EXECUTION_FAILED",
|
|
529
|
+
COMMAND_INVALID_ARGS: "COMMAND_INVALID_ARGS",
|
|
530
|
+
// Content errors
|
|
531
|
+
INVALID_CONTENT: "INVALID_CONTENT",
|
|
532
|
+
INVALID_DELTA: "INVALID_DELTA",
|
|
533
|
+
INVALID_DOCUMENT: "INVALID_DOCUMENT",
|
|
534
|
+
SANITIZATION_FAILED: "SANITIZATION_FAILED",
|
|
535
|
+
// Security errors
|
|
536
|
+
XSS_DETECTED: "XSS_DETECTED",
|
|
537
|
+
UNSAFE_OPERATION: "UNSAFE_OPERATION",
|
|
538
|
+
// General errors
|
|
539
|
+
INVALID_OPERATION: "INVALID_OPERATION",
|
|
540
|
+
INTERNAL_ERROR: "INTERNAL_ERROR"
|
|
541
|
+
};
|
|
542
|
+
class O extends Error {
|
|
543
|
+
constructor(t, e, n) {
|
|
544
|
+
super(e), this.code = t, this.details = n, this.name = "NotectlError", Error.captureStackTrace && Error.captureStackTrace(this, O);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Convert to JSON-serializable format
|
|
548
|
+
*/
|
|
549
|
+
toJSON() {
|
|
550
|
+
return {
|
|
551
|
+
error: {
|
|
552
|
+
code: this.code,
|
|
553
|
+
message: this.message,
|
|
554
|
+
details: this.details
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
const Bn = {
|
|
560
|
+
NO_DANGLING_REFS: "noDanglingRefs",
|
|
561
|
+
TABLE_GRID_CONSISTENT: "tableGridConsistent",
|
|
562
|
+
ALT_OR_DECORATIVE: "altOrDecorative",
|
|
563
|
+
RTL_INTEGRITY: "rtlIntegrity"
|
|
564
|
+
};
|
|
565
|
+
class tn {
|
|
513
566
|
constructor() {
|
|
514
567
|
this.plugins = /* @__PURE__ */ new Map(), this.initializationOrder = [];
|
|
515
568
|
}
|
|
516
569
|
/**
|
|
517
570
|
* Register a plugin
|
|
571
|
+
*
|
|
572
|
+
* @param plugin - The plugin to register
|
|
573
|
+
* @param context - Plugin context with editor APIs
|
|
574
|
+
* @throws {NotectlError} If plugin validation fails or initialization errors occur
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```typescript
|
|
578
|
+
* const toolbarPlugin = new ToolbarPlugin();
|
|
579
|
+
* await pluginManager.register(toolbarPlugin, context);
|
|
580
|
+
* ```
|
|
518
581
|
*/
|
|
519
582
|
async register(t, e) {
|
|
520
|
-
if (
|
|
521
|
-
throw new
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
583
|
+
if (!t)
|
|
584
|
+
throw new O(
|
|
585
|
+
R.PLUGIN_INVALID_CONFIG,
|
|
586
|
+
"Cannot register null or undefined plugin"
|
|
587
|
+
);
|
|
588
|
+
if (!t.id || typeof t.id != "string")
|
|
589
|
+
throw new O(
|
|
590
|
+
R.PLUGIN_INVALID_CONFIG,
|
|
591
|
+
'Plugin must have a valid string "id" property',
|
|
592
|
+
{ plugin: t }
|
|
593
|
+
);
|
|
594
|
+
if (!t.name || typeof t.name != "string")
|
|
595
|
+
throw new O(
|
|
596
|
+
R.PLUGIN_INVALID_CONFIG,
|
|
597
|
+
`Plugin "${t.id}" must have a valid string "name" property`,
|
|
598
|
+
{ pluginId: t.id }
|
|
599
|
+
);
|
|
600
|
+
if (!t.version || typeof t.version != "string")
|
|
601
|
+
throw new O(
|
|
602
|
+
R.PLUGIN_INVALID_CONFIG,
|
|
603
|
+
`Plugin "${t.id}" must have a valid string "version" property`,
|
|
604
|
+
{ pluginId: t.id, pluginName: t.name }
|
|
605
|
+
);
|
|
606
|
+
if (typeof t.init != "function")
|
|
607
|
+
throw new O(
|
|
608
|
+
R.PLUGIN_INVALID_CONFIG,
|
|
609
|
+
`Plugin "${t.id}" must have an "init" method`,
|
|
610
|
+
{ pluginId: t.id, pluginName: t.name }
|
|
611
|
+
);
|
|
612
|
+
if (this.plugins.has(t.id)) {
|
|
613
|
+
const n = this.plugins.get(t.id);
|
|
614
|
+
throw new O(
|
|
615
|
+
R.PLUGIN_ALREADY_REGISTERED,
|
|
616
|
+
`Plugin "${t.id}" is already registered (version: ${n.version})`,
|
|
617
|
+
{ pluginId: t.id, existingVersion: n.version, newVersion: t.version }
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
if (t.dependencies && t.dependencies.length > 0) {
|
|
621
|
+
const n = [];
|
|
622
|
+
for (const o of t.dependencies)
|
|
623
|
+
this.plugins.has(o) || n.push(o);
|
|
624
|
+
if (n.length > 0)
|
|
625
|
+
throw new O(
|
|
626
|
+
R.PLUGIN_MISSING_DEPENDENCY,
|
|
627
|
+
`Plugin "${t.id}" (${t.name}) cannot be registered because the following dependencies are missing: ${n.join(", ")}. Please register these plugins first.`,
|
|
628
|
+
{
|
|
629
|
+
pluginId: t.id,
|
|
630
|
+
pluginName: t.name,
|
|
631
|
+
missingDependencies: n,
|
|
632
|
+
registeredPlugins: Array.from(this.plugins.keys())
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
await t.init(e);
|
|
638
|
+
} catch (n) {
|
|
639
|
+
throw new O(
|
|
640
|
+
R.PLUGIN_INIT_FAILED,
|
|
641
|
+
`Failed to initialize plugin "${t.id}" (${t.name}): ${n instanceof Error ? n.message : String(n)}`,
|
|
642
|
+
{
|
|
643
|
+
pluginId: t.id,
|
|
644
|
+
pluginName: t.name,
|
|
645
|
+
originalError: n
|
|
646
|
+
}
|
|
647
|
+
);
|
|
526
648
|
}
|
|
527
|
-
|
|
649
|
+
this.plugins.set(t.id, t), this.initializationOrder.push(t.id), e.emit("plugin-registered", { pluginId: t.id, plugin: t });
|
|
528
650
|
}
|
|
529
651
|
/**
|
|
530
652
|
* Unregister a plugin
|
|
653
|
+
*
|
|
654
|
+
* @param pluginId - ID of the plugin to unregister
|
|
655
|
+
* @param context - Plugin context for event emission
|
|
656
|
+
* @throws {NotectlError} If plugin is not found or has dependents
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```typescript
|
|
660
|
+
* await pluginManager.unregister('toolbar-plugin', context);
|
|
661
|
+
* ```
|
|
531
662
|
*/
|
|
532
663
|
async unregister(t, e) {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
664
|
+
if (!t || typeof t != "string")
|
|
665
|
+
throw new O(
|
|
666
|
+
R.PLUGIN_NOT_FOUND,
|
|
667
|
+
"Plugin ID must be a non-empty string",
|
|
668
|
+
{ pluginId: t }
|
|
669
|
+
);
|
|
670
|
+
const n = this.plugins.get(t);
|
|
671
|
+
if (!n)
|
|
672
|
+
throw new O(
|
|
673
|
+
R.PLUGIN_NOT_FOUND,
|
|
674
|
+
`Plugin "${t}" is not registered and cannot be unregistered`,
|
|
675
|
+
{
|
|
676
|
+
pluginId: t,
|
|
677
|
+
registeredPlugins: Array.from(this.plugins.keys())
|
|
678
|
+
}
|
|
679
|
+
);
|
|
680
|
+
const o = [];
|
|
681
|
+
for (const [s, l] of this.plugins.entries())
|
|
682
|
+
l.dependencies?.includes(t) && o.push(`${s} (${l.name})`);
|
|
683
|
+
if (o.length > 0)
|
|
684
|
+
throw new O(
|
|
685
|
+
R.PLUGIN_DEPENDENCY_CONFLICT,
|
|
686
|
+
`Cannot unregister plugin "${t}" (${n.name}) because the following plugins depend on it: ${o.join(", ")}. Please unregister dependent plugins first.`,
|
|
687
|
+
{
|
|
688
|
+
pluginId: t,
|
|
689
|
+
pluginName: n.name,
|
|
690
|
+
dependentPlugins: o
|
|
691
|
+
}
|
|
692
|
+
);
|
|
693
|
+
if (n.destroy)
|
|
694
|
+
try {
|
|
695
|
+
await n.destroy();
|
|
696
|
+
} catch (s) {
|
|
697
|
+
throw new O(
|
|
698
|
+
R.PLUGIN_DESTROY_FAILED,
|
|
699
|
+
`Failed to destroy plugin "${t}" (${n.name}): ${s instanceof Error ? s.message : String(s)}`,
|
|
700
|
+
{
|
|
701
|
+
pluginId: t,
|
|
702
|
+
pluginName: n.name,
|
|
703
|
+
originalError: s
|
|
704
|
+
}
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
this.plugins.delete(t), this.initializationOrder = this.initializationOrder.filter((s) => s !== t), e.emit("plugin-unregistered", { pluginId: t });
|
|
540
708
|
}
|
|
541
709
|
/**
|
|
542
710
|
* Get a plugin by ID
|
|
@@ -560,13 +728,13 @@ class Je {
|
|
|
560
728
|
* Notify plugins of state update
|
|
561
729
|
*/
|
|
562
730
|
notifyStateUpdate(t, e) {
|
|
563
|
-
for (const
|
|
564
|
-
const o = this.plugins.get(
|
|
731
|
+
for (const n of this.initializationOrder) {
|
|
732
|
+
const o = this.plugins.get(n);
|
|
565
733
|
if (o?.onStateUpdate)
|
|
566
734
|
try {
|
|
567
735
|
o.onStateUpdate(t, e);
|
|
568
|
-
} catch (
|
|
569
|
-
console.error(`Error in plugin ${
|
|
736
|
+
} catch (s) {
|
|
737
|
+
console.error(`Error in plugin ${n} onStateUpdate:`, s);
|
|
570
738
|
}
|
|
571
739
|
}
|
|
572
740
|
}
|
|
@@ -575,10 +743,10 @@ class Je {
|
|
|
575
743
|
*/
|
|
576
744
|
notifyDeltaApplied(t) {
|
|
577
745
|
for (const e of this.initializationOrder) {
|
|
578
|
-
const
|
|
579
|
-
if (
|
|
746
|
+
const n = this.plugins.get(e);
|
|
747
|
+
if (n?.onDeltaApplied)
|
|
580
748
|
try {
|
|
581
|
-
|
|
749
|
+
n.onDeltaApplied(t);
|
|
582
750
|
} catch (o) {
|
|
583
751
|
console.error(`Error in plugin ${e} onDeltaApplied:`, o);
|
|
584
752
|
}
|
|
@@ -590,10 +758,10 @@ class Je {
|
|
|
590
758
|
async destroyAll() {
|
|
591
759
|
const t = [...this.initializationOrder].reverse();
|
|
592
760
|
for (const e of t) {
|
|
593
|
-
const
|
|
594
|
-
if (
|
|
761
|
+
const n = this.plugins.get(e);
|
|
762
|
+
if (n?.destroy)
|
|
595
763
|
try {
|
|
596
|
-
await
|
|
764
|
+
await n.destroy();
|
|
597
765
|
} catch (o) {
|
|
598
766
|
console.error(`Error destroying plugin ${e}:`, o);
|
|
599
767
|
}
|
|
@@ -603,142 +771,142 @@ class Je {
|
|
|
603
771
|
}
|
|
604
772
|
/*! @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
773
|
const {
|
|
606
|
-
entries:
|
|
607
|
-
setPrototypeOf:
|
|
608
|
-
isFrozen:
|
|
609
|
-
getPrototypeOf:
|
|
610
|
-
getOwnPropertyDescriptor:
|
|
774
|
+
entries: Ae,
|
|
775
|
+
setPrototypeOf: pe,
|
|
776
|
+
isFrozen: en,
|
|
777
|
+
getPrototypeOf: nn,
|
|
778
|
+
getOwnPropertyDescriptor: rn
|
|
611
779
|
} = Object;
|
|
612
780
|
let {
|
|
613
|
-
freeze:
|
|
614
|
-
seal:
|
|
615
|
-
create:
|
|
781
|
+
freeze: D,
|
|
782
|
+
seal: C,
|
|
783
|
+
create: Ne
|
|
616
784
|
} = Object, {
|
|
617
|
-
apply:
|
|
618
|
-
construct:
|
|
785
|
+
apply: Bt,
|
|
786
|
+
construct: $t
|
|
619
787
|
} = typeof Reflect < "u" && Reflect;
|
|
620
|
-
|
|
788
|
+
D || (D = function(t) {
|
|
621
789
|
return t;
|
|
622
790
|
});
|
|
623
|
-
|
|
791
|
+
C || (C = function(t) {
|
|
624
792
|
return t;
|
|
625
793
|
});
|
|
626
|
-
|
|
627
|
-
for (var
|
|
628
|
-
o[
|
|
794
|
+
Bt || (Bt = function(t, e) {
|
|
795
|
+
for (var n = arguments.length, o = new Array(n > 2 ? n - 2 : 0), s = 2; s < n; s++)
|
|
796
|
+
o[s - 2] = arguments[s];
|
|
629
797
|
return t.apply(e, o);
|
|
630
798
|
});
|
|
631
|
-
|
|
632
|
-
for (var e = arguments.length,
|
|
633
|
-
|
|
634
|
-
return new t(...
|
|
799
|
+
$t || ($t = function(t) {
|
|
800
|
+
for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
|
|
801
|
+
n[o - 1] = arguments[o];
|
|
802
|
+
return new t(...n);
|
|
635
803
|
});
|
|
636
|
-
const
|
|
637
|
-
function
|
|
804
|
+
const Et = x(Array.prototype.forEach), on = x(Array.prototype.lastIndexOf), me = x(Array.prototype.pop), tt = x(Array.prototype.push), sn = x(Array.prototype.splice), Tt = x(String.prototype.toLowerCase), vt = x(String.prototype.toString), Pt = x(String.prototype.match), et = x(String.prototype.replace), an = x(String.prototype.indexOf), ln = x(String.prototype.trim), M = x(Object.prototype.hasOwnProperty), S = x(RegExp.prototype.test), nt = cn(TypeError);
|
|
805
|
+
function x(r) {
|
|
638
806
|
return function(t) {
|
|
639
807
|
t instanceof RegExp && (t.lastIndex = 0);
|
|
640
|
-
for (var e = arguments.length,
|
|
641
|
-
|
|
642
|
-
return
|
|
808
|
+
for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
|
|
809
|
+
n[o - 1] = arguments[o];
|
|
810
|
+
return Bt(r, t, n);
|
|
643
811
|
};
|
|
644
812
|
}
|
|
645
|
-
function
|
|
813
|
+
function cn(r) {
|
|
646
814
|
return function() {
|
|
647
|
-
for (var t = arguments.length, e = new Array(t),
|
|
648
|
-
e[
|
|
649
|
-
return
|
|
815
|
+
for (var t = arguments.length, e = new Array(t), n = 0; n < t; n++)
|
|
816
|
+
e[n] = arguments[n];
|
|
817
|
+
return $t(r, e);
|
|
650
818
|
};
|
|
651
819
|
}
|
|
652
|
-
function
|
|
653
|
-
let e = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] :
|
|
654
|
-
|
|
655
|
-
let
|
|
656
|
-
for (;
|
|
657
|
-
let o = t[
|
|
820
|
+
function u(r, t) {
|
|
821
|
+
let e = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : Tt;
|
|
822
|
+
pe && pe(r, null);
|
|
823
|
+
let n = t.length;
|
|
824
|
+
for (; n--; ) {
|
|
825
|
+
let o = t[n];
|
|
658
826
|
if (typeof o == "string") {
|
|
659
|
-
const
|
|
660
|
-
|
|
827
|
+
const s = e(o);
|
|
828
|
+
s !== o && (en(t) || (t[n] = s), o = s);
|
|
661
829
|
}
|
|
662
830
|
r[o] = !0;
|
|
663
831
|
}
|
|
664
832
|
return r;
|
|
665
833
|
}
|
|
666
|
-
function
|
|
834
|
+
function dn(r) {
|
|
667
835
|
for (let t = 0; t < r.length; t++)
|
|
668
|
-
|
|
836
|
+
M(r, t) || (r[t] = null);
|
|
669
837
|
return r;
|
|
670
838
|
}
|
|
671
|
-
function
|
|
672
|
-
const t =
|
|
673
|
-
for (const [e,
|
|
674
|
-
|
|
839
|
+
function H(r) {
|
|
840
|
+
const t = Ne(null);
|
|
841
|
+
for (const [e, n] of Ae(r))
|
|
842
|
+
M(r, e) && (Array.isArray(n) ? t[e] = dn(n) : n && typeof n == "object" && n.constructor === Object ? t[e] = H(n) : t[e] = n);
|
|
675
843
|
return t;
|
|
676
844
|
}
|
|
677
|
-
function
|
|
845
|
+
function it(r, t) {
|
|
678
846
|
for (; r !== null; ) {
|
|
679
|
-
const
|
|
680
|
-
if (
|
|
681
|
-
if (
|
|
682
|
-
return
|
|
683
|
-
if (typeof
|
|
684
|
-
return
|
|
847
|
+
const n = rn(r, t);
|
|
848
|
+
if (n) {
|
|
849
|
+
if (n.get)
|
|
850
|
+
return x(n.get);
|
|
851
|
+
if (typeof n.value == "function")
|
|
852
|
+
return x(n.value);
|
|
685
853
|
}
|
|
686
|
-
r =
|
|
854
|
+
r = nn(r);
|
|
687
855
|
}
|
|
688
856
|
function e() {
|
|
689
857
|
return null;
|
|
690
858
|
}
|
|
691
859
|
return e;
|
|
692
860
|
}
|
|
693
|
-
const
|
|
861
|
+
const ge = D(["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"]), Ut = D(["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"]), Ft = D(["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"]), hn = D(["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"]), Ht = D(["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"]), un = D(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]), Ee = D(["#text"]), ye = D(["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"]), Gt = D(["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"]), Te = D(["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"]), yt = D(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]), fn = C(/\{\{[\w\W]*|[\w\W]*\}\}/gm), pn = C(/<%[\w\W]*|[\w\W]*%>/gm), mn = C(/\$\{[\w\W]*/gm), gn = C(/^data-[\-\w.\u00B7-\uFFFF]+$/), En = C(/^aria-[\-\w]+$/), Se = C(
|
|
694
862
|
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
|
695
863
|
// eslint-disable-line no-useless-escape
|
|
696
|
-
),
|
|
864
|
+
), yn = C(/^(?:\w+script|data):/i), Tn = C(
|
|
697
865
|
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
|
698
866
|
// eslint-disable-line no-control-regex
|
|
699
|
-
),
|
|
700
|
-
var
|
|
867
|
+
), De = C(/^html$/i), _n = C(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
868
|
+
var _e = /* @__PURE__ */ Object.freeze({
|
|
701
869
|
__proto__: null,
|
|
702
|
-
ARIA_ATTR:
|
|
703
|
-
ATTR_WHITESPACE:
|
|
704
|
-
CUSTOM_ELEMENT:
|
|
705
|
-
DATA_ATTR:
|
|
706
|
-
DOCTYPE_NAME:
|
|
707
|
-
ERB_EXPR:
|
|
870
|
+
ARIA_ATTR: En,
|
|
871
|
+
ATTR_WHITESPACE: Tn,
|
|
872
|
+
CUSTOM_ELEMENT: _n,
|
|
873
|
+
DATA_ATTR: gn,
|
|
874
|
+
DOCTYPE_NAME: De,
|
|
875
|
+
ERB_EXPR: pn,
|
|
708
876
|
IS_ALLOWED_URI: Se,
|
|
709
|
-
IS_SCRIPT_OR_DATA:
|
|
710
|
-
MUSTACHE_EXPR:
|
|
711
|
-
TMPLIT_EXPR:
|
|
877
|
+
IS_SCRIPT_OR_DATA: yn,
|
|
878
|
+
MUSTACHE_EXPR: fn,
|
|
879
|
+
TMPLIT_EXPR: mn
|
|
712
880
|
});
|
|
713
|
-
const
|
|
881
|
+
const rt = {
|
|
714
882
|
element: 1,
|
|
715
883
|
text: 3,
|
|
716
884
|
// Deprecated
|
|
717
885
|
progressingInstruction: 7,
|
|
718
886
|
comment: 8,
|
|
719
887
|
document: 9
|
|
720
|
-
},
|
|
888
|
+
}, In = function() {
|
|
721
889
|
return typeof window > "u" ? null : window;
|
|
722
890
|
}, bn = function(t, e) {
|
|
723
891
|
if (typeof t != "object" || typeof t.createPolicy != "function")
|
|
724
892
|
return null;
|
|
725
|
-
let
|
|
893
|
+
let n = null;
|
|
726
894
|
const o = "data-tt-policy-suffix";
|
|
727
|
-
e && e.hasAttribute(o) && (
|
|
728
|
-
const
|
|
895
|
+
e && e.hasAttribute(o) && (n = e.getAttribute(o));
|
|
896
|
+
const s = "dompurify" + (n ? "#" + n : "");
|
|
729
897
|
try {
|
|
730
|
-
return t.createPolicy(
|
|
731
|
-
createHTML(
|
|
732
|
-
return
|
|
898
|
+
return t.createPolicy(s, {
|
|
899
|
+
createHTML(l) {
|
|
900
|
+
return l;
|
|
733
901
|
},
|
|
734
|
-
createScriptURL(
|
|
735
|
-
return
|
|
902
|
+
createScriptURL(l) {
|
|
903
|
+
return l;
|
|
736
904
|
}
|
|
737
905
|
});
|
|
738
906
|
} catch {
|
|
739
|
-
return console.warn("TrustedTypes policy " +
|
|
907
|
+
return console.warn("TrustedTypes policy " + s + " could not be created."), null;
|
|
740
908
|
}
|
|
741
|
-
},
|
|
909
|
+
}, Ie = function() {
|
|
742
910
|
return {
|
|
743
911
|
afterSanitizeAttributes: [],
|
|
744
912
|
afterSanitizeElements: [],
|
|
@@ -751,57 +919,57 @@ const nt = {
|
|
|
751
919
|
uponSanitizeShadowNode: []
|
|
752
920
|
};
|
|
753
921
|
};
|
|
754
|
-
function
|
|
755
|
-
let r = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] :
|
|
756
|
-
const t = (
|
|
757
|
-
if (t.version = "3.2.7", t.removed = [], !r || !r.document || r.document.nodeType !==
|
|
922
|
+
function xe() {
|
|
923
|
+
let r = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : In();
|
|
924
|
+
const t = (d) => xe(d);
|
|
925
|
+
if (t.version = "3.2.7", t.removed = [], !r || !r.document || r.document.nodeType !== rt.document || !r.Element)
|
|
758
926
|
return t.isSupported = !1, t;
|
|
759
927
|
let {
|
|
760
928
|
document: e
|
|
761
929
|
} = r;
|
|
762
|
-
const
|
|
763
|
-
DocumentFragment:
|
|
764
|
-
HTMLTemplateElement:
|
|
930
|
+
const n = e, o = n.currentScript, {
|
|
931
|
+
DocumentFragment: s,
|
|
932
|
+
HTMLTemplateElement: l,
|
|
765
933
|
Node: h,
|
|
766
|
-
Element:
|
|
767
|
-
NodeFilter:
|
|
768
|
-
NamedNodeMap:
|
|
769
|
-
HTMLFormElement:
|
|
770
|
-
DOMParser:
|
|
771
|
-
trustedTypes:
|
|
772
|
-
} = r,
|
|
773
|
-
if (typeof
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
}
|
|
777
|
-
let
|
|
934
|
+
Element: f,
|
|
935
|
+
NodeFilter: E,
|
|
936
|
+
NamedNodeMap: L = r.NamedNodeMap || r.MozNamedAttrMap,
|
|
937
|
+
HTMLFormElement: at,
|
|
938
|
+
DOMParser: Oe,
|
|
939
|
+
trustedTypes: lt
|
|
940
|
+
} = r, X = f.prototype, Re = it(X, "cloneNode"), Ce = it(X, "remove"), we = it(X, "nextSibling"), Me = it(X, "childNodes"), ct = it(X, "parentNode");
|
|
941
|
+
if (typeof l == "function") {
|
|
942
|
+
const d = e.createElement("template");
|
|
943
|
+
d.content && d.content.ownerDocument && (e = d.content.ownerDocument);
|
|
944
|
+
}
|
|
945
|
+
let A, q = "";
|
|
778
946
|
const {
|
|
779
|
-
implementation:
|
|
947
|
+
implementation: _t,
|
|
780
948
|
createNodeIterator: ve,
|
|
781
|
-
createDocumentFragment:
|
|
782
|
-
getElementsByTagName:
|
|
949
|
+
createDocumentFragment: Pe,
|
|
950
|
+
getElementsByTagName: Ue
|
|
783
951
|
} = e, {
|
|
784
|
-
importNode:
|
|
785
|
-
} =
|
|
786
|
-
let
|
|
787
|
-
t.isSupported = typeof
|
|
952
|
+
importNode: Fe
|
|
953
|
+
} = n;
|
|
954
|
+
let N = Ie();
|
|
955
|
+
t.isSupported = typeof Ae == "function" && typeof ct == "function" && _t && _t.createHTMLDocument !== void 0;
|
|
788
956
|
const {
|
|
789
|
-
MUSTACHE_EXPR:
|
|
957
|
+
MUSTACHE_EXPR: It,
|
|
790
958
|
ERB_EXPR: bt,
|
|
791
|
-
TMPLIT_EXPR:
|
|
792
|
-
DATA_ATTR:
|
|
793
|
-
ARIA_ATTR:
|
|
794
|
-
IS_SCRIPT_OR_DATA:
|
|
795
|
-
ATTR_WHITESPACE:
|
|
796
|
-
CUSTOM_ELEMENT:
|
|
797
|
-
} =
|
|
959
|
+
TMPLIT_EXPR: At,
|
|
960
|
+
DATA_ATTR: He,
|
|
961
|
+
ARIA_ATTR: Ge,
|
|
962
|
+
IS_SCRIPT_OR_DATA: Be,
|
|
963
|
+
ATTR_WHITESPACE: zt,
|
|
964
|
+
CUSTOM_ELEMENT: $e
|
|
965
|
+
} = _e;
|
|
798
966
|
let {
|
|
799
|
-
IS_ALLOWED_URI:
|
|
800
|
-
} =
|
|
801
|
-
const Wt =
|
|
802
|
-
let
|
|
803
|
-
const
|
|
804
|
-
let m = Object.seal(
|
|
967
|
+
IS_ALLOWED_URI: Vt
|
|
968
|
+
} = _e, y = null;
|
|
969
|
+
const Wt = u({}, [...ge, ...Ut, ...Ft, ...Ht, ...Ee]);
|
|
970
|
+
let _ = null;
|
|
971
|
+
const Yt = u({}, [...ye, ...Gt, ...Te, ...yt]);
|
|
972
|
+
let m = Object.seal(Ne(null, {
|
|
805
973
|
tagNameCheck: {
|
|
806
974
|
writable: !0,
|
|
807
975
|
configurable: !1,
|
|
@@ -820,168 +988,168 @@ function ke() {
|
|
|
820
988
|
enumerable: !0,
|
|
821
989
|
value: !1
|
|
822
990
|
}
|
|
823
|
-
})),
|
|
824
|
-
const
|
|
825
|
-
let Lt = !0,
|
|
826
|
-
const
|
|
827
|
-
let
|
|
828
|
-
const
|
|
829
|
-
let
|
|
830
|
-
const
|
|
831
|
-
let
|
|
832
|
-
const
|
|
833
|
-
let
|
|
834
|
-
const We =
|
|
835
|
-
let
|
|
836
|
-
const
|
|
837
|
-
let
|
|
838
|
-
const
|
|
839
|
-
return
|
|
840
|
-
},
|
|
841
|
-
let
|
|
842
|
-
if (!(K && K ===
|
|
843
|
-
if ((!
|
|
844
|
-
|
|
845
|
-
if (typeof
|
|
846
|
-
throw
|
|
847
|
-
if (typeof
|
|
848
|
-
throw
|
|
849
|
-
|
|
991
|
+
})), Z = null, Nt = null, Kt = !0, St = !0, jt = !1, Xt = !0, $ = !1, dt = !0, G = !1, Dt = !1, xt = !1, z = !1, ht = !1, ut = !1, qt = !0, Zt = !1;
|
|
992
|
+
const ze = "user-content-";
|
|
993
|
+
let Lt = !0, J = !1, V = {}, W = null;
|
|
994
|
+
const Jt = u({}, ["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"]);
|
|
995
|
+
let Qt = null;
|
|
996
|
+
const te = u({}, ["audio", "video", "img", "source", "image", "track"]);
|
|
997
|
+
let kt = null;
|
|
998
|
+
const ee = u({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]), ft = "http://www.w3.org/1998/Math/MathML", pt = "http://www.w3.org/2000/svg", P = "http://www.w3.org/1999/xhtml";
|
|
999
|
+
let Y = P, Ot = !1, Rt = null;
|
|
1000
|
+
const Ve = u({}, [ft, pt, P], vt);
|
|
1001
|
+
let mt = u({}, ["mi", "mo", "mn", "ms", "mtext"]), gt = u({}, ["annotation-xml"]);
|
|
1002
|
+
const We = u({}, ["title", "style", "font", "a", "script"]);
|
|
1003
|
+
let Q = null;
|
|
1004
|
+
const Ye = ["application/xhtml+xml", "text/html"], Ke = "text/html";
|
|
1005
|
+
let T = null, K = null;
|
|
1006
|
+
const je = e.createElement("form"), ne = function(i) {
|
|
1007
|
+
return i instanceof RegExp || i instanceof Function;
|
|
1008
|
+
}, Ct = function() {
|
|
1009
|
+
let i = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1010
|
+
if (!(K && K === i)) {
|
|
1011
|
+
if ((!i || typeof i != "object") && (i = {}), i = H(i), Q = // eslint-disable-next-line unicorn/prefer-includes
|
|
1012
|
+
Ye.indexOf(i.PARSER_MEDIA_TYPE) === -1 ? Ke : i.PARSER_MEDIA_TYPE, T = Q === "application/xhtml+xml" ? vt : Tt, y = M(i, "ALLOWED_TAGS") ? u({}, i.ALLOWED_TAGS, T) : Wt, _ = M(i, "ALLOWED_ATTR") ? u({}, i.ALLOWED_ATTR, T) : Yt, Rt = M(i, "ALLOWED_NAMESPACES") ? u({}, i.ALLOWED_NAMESPACES, vt) : Ve, kt = M(i, "ADD_URI_SAFE_ATTR") ? u(H(ee), i.ADD_URI_SAFE_ATTR, T) : ee, Qt = M(i, "ADD_DATA_URI_TAGS") ? u(H(te), i.ADD_DATA_URI_TAGS, T) : te, W = M(i, "FORBID_CONTENTS") ? u({}, i.FORBID_CONTENTS, T) : Jt, Z = M(i, "FORBID_TAGS") ? u({}, i.FORBID_TAGS, T) : H({}), Nt = M(i, "FORBID_ATTR") ? u({}, i.FORBID_ATTR, T) : H({}), V = M(i, "USE_PROFILES") ? i.USE_PROFILES : !1, Kt = i.ALLOW_ARIA_ATTR !== !1, St = i.ALLOW_DATA_ATTR !== !1, jt = i.ALLOW_UNKNOWN_PROTOCOLS || !1, Xt = i.ALLOW_SELF_CLOSE_IN_ATTR !== !1, $ = i.SAFE_FOR_TEMPLATES || !1, dt = i.SAFE_FOR_XML !== !1, G = i.WHOLE_DOCUMENT || !1, z = i.RETURN_DOM || !1, ht = i.RETURN_DOM_FRAGMENT || !1, ut = i.RETURN_TRUSTED_TYPE || !1, xt = i.FORCE_BODY || !1, qt = i.SANITIZE_DOM !== !1, Zt = i.SANITIZE_NAMED_PROPS || !1, Lt = i.KEEP_CONTENT !== !1, J = i.IN_PLACE || !1, Vt = i.ALLOWED_URI_REGEXP || Se, Y = i.NAMESPACE || P, mt = i.MATHML_TEXT_INTEGRATION_POINTS || mt, gt = i.HTML_INTEGRATION_POINTS || gt, m = i.CUSTOM_ELEMENT_HANDLING || {}, i.CUSTOM_ELEMENT_HANDLING && ne(i.CUSTOM_ELEMENT_HANDLING.tagNameCheck) && (m.tagNameCheck = i.CUSTOM_ELEMENT_HANDLING.tagNameCheck), i.CUSTOM_ELEMENT_HANDLING && ne(i.CUSTOM_ELEMENT_HANDLING.attributeNameCheck) && (m.attributeNameCheck = i.CUSTOM_ELEMENT_HANDLING.attributeNameCheck), i.CUSTOM_ELEMENT_HANDLING && typeof i.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements == "boolean" && (m.allowCustomizedBuiltInElements = i.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements), $ && (St = !1), ht && (z = !0), V && (y = u({}, Ee), _ = [], V.html === !0 && (u(y, ge), u(_, ye)), V.svg === !0 && (u(y, Ut), u(_, Gt), u(_, yt)), V.svgFilters === !0 && (u(y, Ft), u(_, Gt), u(_, yt)), V.mathMl === !0 && (u(y, Ht), u(_, Te), u(_, yt))), i.ADD_TAGS && (y === Wt && (y = H(y)), u(y, i.ADD_TAGS, T)), i.ADD_ATTR && (_ === Yt && (_ = H(_)), u(_, i.ADD_ATTR, T)), i.ADD_URI_SAFE_ATTR && u(kt, i.ADD_URI_SAFE_ATTR, T), i.FORBID_CONTENTS && (W === Jt && (W = H(W)), u(W, i.FORBID_CONTENTS, T)), Lt && (y["#text"] = !0), G && u(y, ["html", "head", "body"]), y.table && (u(y, ["tbody"]), delete Z.tbody), i.TRUSTED_TYPES_POLICY) {
|
|
1013
|
+
if (typeof i.TRUSTED_TYPES_POLICY.createHTML != "function")
|
|
1014
|
+
throw nt('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
1015
|
+
if (typeof i.TRUSTED_TYPES_POLICY.createScriptURL != "function")
|
|
1016
|
+
throw nt('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
1017
|
+
A = i.TRUSTED_TYPES_POLICY, q = A.createHTML("");
|
|
850
1018
|
} else
|
|
851
|
-
|
|
852
|
-
|
|
1019
|
+
A === void 0 && (A = bn(lt, o)), A !== null && typeof q == "string" && (q = A.createHTML(""));
|
|
1020
|
+
D && D(i), K = i;
|
|
853
1021
|
}
|
|
854
|
-
},
|
|
855
|
-
let
|
|
856
|
-
(!
|
|
857
|
-
namespaceURI:
|
|
1022
|
+
}, ie = u({}, [...Ut, ...Ft, ...hn]), re = u({}, [...Ht, ...un]), Xe = function(i) {
|
|
1023
|
+
let a = ct(i);
|
|
1024
|
+
(!a || !a.tagName) && (a = {
|
|
1025
|
+
namespaceURI: Y,
|
|
858
1026
|
tagName: "template"
|
|
859
1027
|
});
|
|
860
|
-
const
|
|
861
|
-
return
|
|
862
|
-
}, v = function(
|
|
863
|
-
|
|
864
|
-
element:
|
|
1028
|
+
const c = Tt(i.tagName), p = Tt(a.tagName);
|
|
1029
|
+
return Rt[i.namespaceURI] ? i.namespaceURI === pt ? a.namespaceURI === P ? c === "svg" : a.namespaceURI === ft ? c === "svg" && (p === "annotation-xml" || mt[p]) : !!ie[c] : i.namespaceURI === ft ? a.namespaceURI === P ? c === "math" : a.namespaceURI === pt ? c === "math" && gt[p] : !!re[c] : i.namespaceURI === P ? a.namespaceURI === pt && !gt[p] || a.namespaceURI === ft && !mt[p] ? !1 : !re[c] && (We[c] || !ie[c]) : !!(Q === "application/xhtml+xml" && Rt[i.namespaceURI]) : !1;
|
|
1030
|
+
}, v = function(i) {
|
|
1031
|
+
tt(t.removed, {
|
|
1032
|
+
element: i
|
|
865
1033
|
});
|
|
866
1034
|
try {
|
|
867
|
-
|
|
1035
|
+
ct(i).removeChild(i);
|
|
868
1036
|
} catch {
|
|
869
|
-
|
|
1037
|
+
Ce(i);
|
|
870
1038
|
}
|
|
871
|
-
},
|
|
1039
|
+
}, B = function(i, a) {
|
|
872
1040
|
try {
|
|
873
|
-
|
|
874
|
-
attribute:
|
|
875
|
-
from:
|
|
1041
|
+
tt(t.removed, {
|
|
1042
|
+
attribute: a.getAttributeNode(i),
|
|
1043
|
+
from: a
|
|
876
1044
|
});
|
|
877
1045
|
} catch {
|
|
878
|
-
|
|
1046
|
+
tt(t.removed, {
|
|
879
1047
|
attribute: null,
|
|
880
|
-
from:
|
|
1048
|
+
from: a
|
|
881
1049
|
});
|
|
882
1050
|
}
|
|
883
|
-
if (
|
|
884
|
-
if (
|
|
1051
|
+
if (a.removeAttribute(i), i === "is")
|
|
1052
|
+
if (z || ht)
|
|
885
1053
|
try {
|
|
886
|
-
v(
|
|
1054
|
+
v(a);
|
|
887
1055
|
} catch {
|
|
888
1056
|
}
|
|
889
1057
|
else
|
|
890
1058
|
try {
|
|
891
|
-
|
|
1059
|
+
a.setAttribute(i, "");
|
|
892
1060
|
} catch {
|
|
893
1061
|
}
|
|
894
|
-
},
|
|
895
|
-
let
|
|
896
|
-
if (
|
|
897
|
-
|
|
1062
|
+
}, oe = function(i) {
|
|
1063
|
+
let a = null, c = null;
|
|
1064
|
+
if (xt)
|
|
1065
|
+
i = "<remove></remove>" + i;
|
|
898
1066
|
else {
|
|
899
|
-
const g =
|
|
900
|
-
|
|
1067
|
+
const g = Pt(i, /^[\r\n\t ]+/);
|
|
1068
|
+
c = g && g[0];
|
|
901
1069
|
}
|
|
902
|
-
|
|
903
|
-
const
|
|
904
|
-
if (
|
|
1070
|
+
Q === "application/xhtml+xml" && Y === P && (i = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + i + "</body></html>");
|
|
1071
|
+
const p = A ? A.createHTML(i) : i;
|
|
1072
|
+
if (Y === P)
|
|
905
1073
|
try {
|
|
906
|
-
|
|
1074
|
+
a = new Oe().parseFromString(p, Q);
|
|
907
1075
|
} catch {
|
|
908
1076
|
}
|
|
909
|
-
if (!
|
|
910
|
-
|
|
1077
|
+
if (!a || !a.documentElement) {
|
|
1078
|
+
a = _t.createDocument(Y, "template", null);
|
|
911
1079
|
try {
|
|
912
|
-
|
|
1080
|
+
a.documentElement.innerHTML = Ot ? q : p;
|
|
913
1081
|
} catch {
|
|
914
1082
|
}
|
|
915
1083
|
}
|
|
916
|
-
const
|
|
917
|
-
return
|
|
918
|
-
},
|
|
1084
|
+
const b = a.body || a.documentElement;
|
|
1085
|
+
return i && c && b.insertBefore(e.createTextNode(c), b.childNodes[0] || null), Y === P ? Ue.call(a, G ? "html" : "body")[0] : G ? a.documentElement : b;
|
|
1086
|
+
}, se = function(i) {
|
|
919
1087
|
return ve.call(
|
|
920
|
-
|
|
921
|
-
|
|
1088
|
+
i.ownerDocument || i,
|
|
1089
|
+
i,
|
|
922
1090
|
// eslint-disable-next-line no-bitwise
|
|
923
|
-
|
|
1091
|
+
E.SHOW_ELEMENT | E.SHOW_COMMENT | E.SHOW_TEXT | E.SHOW_PROCESSING_INSTRUCTION | E.SHOW_CDATA_SECTION,
|
|
924
1092
|
null
|
|
925
1093
|
);
|
|
926
|
-
},
|
|
927
|
-
return
|
|
928
|
-
},
|
|
929
|
-
return typeof h == "function" &&
|
|
1094
|
+
}, wt = function(i) {
|
|
1095
|
+
return i instanceof at && (typeof i.nodeName != "string" || typeof i.textContent != "string" || typeof i.removeChild != "function" || !(i.attributes instanceof L) || typeof i.removeAttribute != "function" || typeof i.setAttribute != "function" || typeof i.namespaceURI != "string" || typeof i.insertBefore != "function" || typeof i.hasChildNodes != "function");
|
|
1096
|
+
}, ae = function(i) {
|
|
1097
|
+
return typeof h == "function" && i instanceof h;
|
|
930
1098
|
};
|
|
931
|
-
function
|
|
932
|
-
|
|
933
|
-
|
|
1099
|
+
function U(d, i, a) {
|
|
1100
|
+
Et(d, (c) => {
|
|
1101
|
+
c.call(t, i, a, K);
|
|
934
1102
|
});
|
|
935
1103
|
}
|
|
936
|
-
const
|
|
937
|
-
let
|
|
938
|
-
if (
|
|
939
|
-
return v(
|
|
940
|
-
const
|
|
941
|
-
if (
|
|
942
|
-
tagName:
|
|
1104
|
+
const le = function(i) {
|
|
1105
|
+
let a = null;
|
|
1106
|
+
if (U(N.beforeSanitizeElements, i, null), wt(i))
|
|
1107
|
+
return v(i), !0;
|
|
1108
|
+
const c = T(i.nodeName);
|
|
1109
|
+
if (U(N.uponSanitizeElement, i, {
|
|
1110
|
+
tagName: c,
|
|
943
1111
|
allowedTags: y
|
|
944
|
-
}),
|
|
945
|
-
return v(
|
|
946
|
-
if (!y[
|
|
947
|
-
if (!
|
|
1112
|
+
}), dt && i.hasChildNodes() && !ae(i.firstElementChild) && S(/<[/\w!]/g, i.innerHTML) && S(/<[/\w!]/g, i.textContent) || i.nodeType === rt.progressingInstruction || dt && i.nodeType === rt.comment && S(/<[/\w]/g, i.data))
|
|
1113
|
+
return v(i), !0;
|
|
1114
|
+
if (!y[c] || Z[c]) {
|
|
1115
|
+
if (!Z[c] && de(c) && (m.tagNameCheck instanceof RegExp && S(m.tagNameCheck, c) || m.tagNameCheck instanceof Function && m.tagNameCheck(c)))
|
|
948
1116
|
return !1;
|
|
949
|
-
if (Lt && !W[
|
|
950
|
-
const
|
|
951
|
-
if (
|
|
952
|
-
const g =
|
|
953
|
-
for (let
|
|
954
|
-
const
|
|
955
|
-
|
|
1117
|
+
if (Lt && !W[c]) {
|
|
1118
|
+
const p = ct(i) || i.parentNode, b = Me(i) || i.childNodes;
|
|
1119
|
+
if (b && p) {
|
|
1120
|
+
const g = b.length;
|
|
1121
|
+
for (let k = g - 1; k >= 0; --k) {
|
|
1122
|
+
const F = Re(b[k], !0);
|
|
1123
|
+
F.__removalCount = (i.__removalCount || 0) + 1, p.insertBefore(F, we(i));
|
|
956
1124
|
}
|
|
957
1125
|
}
|
|
958
1126
|
}
|
|
959
|
-
return v(
|
|
1127
|
+
return v(i), !0;
|
|
960
1128
|
}
|
|
961
|
-
return
|
|
962
|
-
|
|
963
|
-
}),
|
|
964
|
-
element:
|
|
965
|
-
}),
|
|
966
|
-
},
|
|
967
|
-
if (
|
|
1129
|
+
return i instanceof f && !Xe(i) || (c === "noscript" || c === "noembed" || c === "noframes") && S(/<\/no(script|embed|frames)/i, i.innerHTML) ? (v(i), !0) : ($ && i.nodeType === rt.text && (a = i.textContent, Et([It, bt, At], (p) => {
|
|
1130
|
+
a = et(a, p, " ");
|
|
1131
|
+
}), i.textContent !== a && (tt(t.removed, {
|
|
1132
|
+
element: i.cloneNode()
|
|
1133
|
+
}), i.textContent = a)), U(N.afterSanitizeElements, i, null), !1);
|
|
1134
|
+
}, ce = function(i, a, c) {
|
|
1135
|
+
if (qt && (a === "id" || a === "name") && (c in e || c in je))
|
|
968
1136
|
return !1;
|
|
969
|
-
if (!(St && !
|
|
970
|
-
if (!(Kt &&
|
|
971
|
-
if (!
|
|
1137
|
+
if (!(St && !Nt[a] && S(He, a))) {
|
|
1138
|
+
if (!(Kt && S(Ge, a))) {
|
|
1139
|
+
if (!_[a] || Nt[a]) {
|
|
972
1140
|
if (
|
|
973
1141
|
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
974
1142
|
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
975
1143
|
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
976
|
-
!(
|
|
1144
|
+
!(de(i) && (m.tagNameCheck instanceof RegExp && S(m.tagNameCheck, i) || m.tagNameCheck instanceof Function && m.tagNameCheck(i)) && (m.attributeNameCheck instanceof RegExp && S(m.attributeNameCheck, a) || m.attributeNameCheck instanceof Function && m.attributeNameCheck(a, i)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
|
977
1145
|
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
978
|
-
|
|
1146
|
+
a === "is" && m.allowCustomizedBuiltInElements && (m.tagNameCheck instanceof RegExp && S(m.tagNameCheck, c) || m.tagNameCheck instanceof Function && m.tagNameCheck(c)))
|
|
979
1147
|
) return !1;
|
|
980
|
-
} else if (!
|
|
981
|
-
if (!
|
|
982
|
-
if (!((
|
|
983
|
-
if (!(
|
|
984
|
-
if (
|
|
1148
|
+
} else if (!kt[a]) {
|
|
1149
|
+
if (!S(Vt, et(c, zt, ""))) {
|
|
1150
|
+
if (!((a === "src" || a === "xlink:href" || a === "href") && i !== "script" && an(c, "data:") === 0 && Qt[i])) {
|
|
1151
|
+
if (!(jt && !S(Be, et(c, zt, "")))) {
|
|
1152
|
+
if (c)
|
|
985
1153
|
return !1;
|
|
986
1154
|
}
|
|
987
1155
|
}
|
|
@@ -990,151 +1158,151 @@ function ke() {
|
|
|
990
1158
|
}
|
|
991
1159
|
}
|
|
992
1160
|
return !0;
|
|
993
|
-
},
|
|
994
|
-
return
|
|
995
|
-
},
|
|
996
|
-
|
|
1161
|
+
}, de = function(i) {
|
|
1162
|
+
return i !== "annotation-xml" && Pt(i, $e);
|
|
1163
|
+
}, he = function(i) {
|
|
1164
|
+
U(N.beforeSanitizeAttributes, i, null);
|
|
997
1165
|
const {
|
|
998
|
-
attributes:
|
|
999
|
-
} =
|
|
1000
|
-
if (!
|
|
1166
|
+
attributes: a
|
|
1167
|
+
} = i;
|
|
1168
|
+
if (!a || wt(i))
|
|
1001
1169
|
return;
|
|
1002
|
-
const
|
|
1170
|
+
const c = {
|
|
1003
1171
|
attrName: "",
|
|
1004
1172
|
attrValue: "",
|
|
1005
1173
|
keepAttr: !0,
|
|
1006
|
-
allowedAttributes:
|
|
1174
|
+
allowedAttributes: _,
|
|
1007
1175
|
forceKeepAttr: void 0
|
|
1008
1176
|
};
|
|
1009
|
-
let
|
|
1010
|
-
for (;
|
|
1011
|
-
const
|
|
1177
|
+
let p = a.length;
|
|
1178
|
+
for (; p--; ) {
|
|
1179
|
+
const b = a[p], {
|
|
1012
1180
|
name: g,
|
|
1013
|
-
namespaceURI:
|
|
1014
|
-
value:
|
|
1015
|
-
} =
|
|
1016
|
-
let
|
|
1017
|
-
if (
|
|
1018
|
-
|
|
1181
|
+
namespaceURI: k,
|
|
1182
|
+
value: F
|
|
1183
|
+
} = b, j = T(g), Mt = F;
|
|
1184
|
+
let I = g === "value" ? Mt : ln(Mt);
|
|
1185
|
+
if (c.attrName = j, c.attrValue = I, c.keepAttr = !0, c.forceKeepAttr = void 0, U(N.uponSanitizeAttribute, i, c), I = c.attrValue, Zt && (j === "id" || j === "name") && (B(g, i), I = ze + I), dt && S(/((--!?|])>)|<\/(style|title|textarea)/i, I)) {
|
|
1186
|
+
B(g, i);
|
|
1019
1187
|
continue;
|
|
1020
1188
|
}
|
|
1021
|
-
if (
|
|
1022
|
-
|
|
1189
|
+
if (j === "attributename" && Pt(I, "href")) {
|
|
1190
|
+
B(g, i);
|
|
1023
1191
|
continue;
|
|
1024
1192
|
}
|
|
1025
|
-
if (
|
|
1193
|
+
if (c.forceKeepAttr)
|
|
1026
1194
|
continue;
|
|
1027
|
-
if (!
|
|
1028
|
-
|
|
1195
|
+
if (!c.keepAttr) {
|
|
1196
|
+
B(g, i);
|
|
1029
1197
|
continue;
|
|
1030
1198
|
}
|
|
1031
|
-
if (!
|
|
1032
|
-
|
|
1199
|
+
if (!Xt && S(/\/>/i, I)) {
|
|
1200
|
+
B(g, i);
|
|
1033
1201
|
continue;
|
|
1034
1202
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1203
|
+
$ && Et([It, bt, At], (fe) => {
|
|
1204
|
+
I = et(I, fe, " ");
|
|
1037
1205
|
});
|
|
1038
|
-
const
|
|
1039
|
-
if (!
|
|
1040
|
-
|
|
1206
|
+
const ue = T(i.nodeName);
|
|
1207
|
+
if (!ce(ue, j, I)) {
|
|
1208
|
+
B(g, i);
|
|
1041
1209
|
continue;
|
|
1042
1210
|
}
|
|
1043
|
-
if (
|
|
1044
|
-
switch (
|
|
1211
|
+
if (A && typeof lt == "object" && typeof lt.getAttributeType == "function" && !k)
|
|
1212
|
+
switch (lt.getAttributeType(ue, j)) {
|
|
1045
1213
|
case "TrustedHTML": {
|
|
1046
|
-
|
|
1214
|
+
I = A.createHTML(I);
|
|
1047
1215
|
break;
|
|
1048
1216
|
}
|
|
1049
1217
|
case "TrustedScriptURL": {
|
|
1050
|
-
|
|
1218
|
+
I = A.createScriptURL(I);
|
|
1051
1219
|
break;
|
|
1052
1220
|
}
|
|
1053
1221
|
}
|
|
1054
|
-
if (
|
|
1222
|
+
if (I !== Mt)
|
|
1055
1223
|
try {
|
|
1056
|
-
|
|
1224
|
+
k ? i.setAttributeNS(k, g, I) : i.setAttribute(g, I), wt(i) ? v(i) : me(t.removed);
|
|
1057
1225
|
} catch {
|
|
1058
|
-
|
|
1226
|
+
B(g, i);
|
|
1059
1227
|
}
|
|
1060
1228
|
}
|
|
1061
|
-
|
|
1062
|
-
},
|
|
1063
|
-
let
|
|
1064
|
-
const
|
|
1065
|
-
for (
|
|
1066
|
-
|
|
1067
|
-
|
|
1229
|
+
U(N.afterSanitizeAttributes, i, null);
|
|
1230
|
+
}, qe = function d(i) {
|
|
1231
|
+
let a = null;
|
|
1232
|
+
const c = se(i);
|
|
1233
|
+
for (U(N.beforeSanitizeShadowDOM, i, null); a = c.nextNode(); )
|
|
1234
|
+
U(N.uponSanitizeShadowNode, a, null), le(a), he(a), a.content instanceof s && d(a.content);
|
|
1235
|
+
U(N.afterSanitizeShadowDOM, i, null);
|
|
1068
1236
|
};
|
|
1069
|
-
return t.sanitize = function(
|
|
1070
|
-
let
|
|
1071
|
-
if (
|
|
1072
|
-
if (typeof
|
|
1073
|
-
if (
|
|
1074
|
-
throw
|
|
1237
|
+
return t.sanitize = function(d) {
|
|
1238
|
+
let i = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, a = null, c = null, p = null, b = null;
|
|
1239
|
+
if (Ot = !d, Ot && (d = "<!-->"), typeof d != "string" && !ae(d))
|
|
1240
|
+
if (typeof d.toString == "function") {
|
|
1241
|
+
if (d = d.toString(), typeof d != "string")
|
|
1242
|
+
throw nt("dirty is not a string, aborting");
|
|
1075
1243
|
} else
|
|
1076
|
-
throw
|
|
1244
|
+
throw nt("toString is not a function");
|
|
1077
1245
|
if (!t.isSupported)
|
|
1078
|
-
return
|
|
1079
|
-
if (
|
|
1080
|
-
if (
|
|
1081
|
-
const
|
|
1082
|
-
if (!y[
|
|
1083
|
-
throw
|
|
1246
|
+
return d;
|
|
1247
|
+
if (Dt || Ct(i), t.removed = [], typeof d == "string" && (J = !1), J) {
|
|
1248
|
+
if (d.nodeName) {
|
|
1249
|
+
const F = T(d.nodeName);
|
|
1250
|
+
if (!y[F] || Z[F])
|
|
1251
|
+
throw nt("root node is forbidden and cannot be sanitized in-place");
|
|
1084
1252
|
}
|
|
1085
|
-
} else if (
|
|
1086
|
-
|
|
1253
|
+
} else if (d instanceof h)
|
|
1254
|
+
a = oe("<!---->"), c = a.ownerDocument.importNode(d, !0), c.nodeType === rt.element && c.nodeName === "BODY" || c.nodeName === "HTML" ? a = c : a.appendChild(c);
|
|
1087
1255
|
else {
|
|
1088
|
-
if (
|
|
1089
|
-
|
|
1090
|
-
return
|
|
1091
|
-
if (
|
|
1092
|
-
return
|
|
1256
|
+
if (!z && !$ && !G && // eslint-disable-next-line unicorn/prefer-includes
|
|
1257
|
+
d.indexOf("<") === -1)
|
|
1258
|
+
return A && ut ? A.createHTML(d) : d;
|
|
1259
|
+
if (a = oe(d), !a)
|
|
1260
|
+
return z ? null : ut ? q : "";
|
|
1093
1261
|
}
|
|
1094
|
-
|
|
1095
|
-
const g =
|
|
1096
|
-
for (;
|
|
1097
|
-
|
|
1098
|
-
if (
|
|
1099
|
-
return
|
|
1100
|
-
if (
|
|
1101
|
-
if (
|
|
1102
|
-
for (
|
|
1103
|
-
|
|
1262
|
+
a && xt && v(a.firstChild);
|
|
1263
|
+
const g = se(J ? d : a);
|
|
1264
|
+
for (; p = g.nextNode(); )
|
|
1265
|
+
le(p), he(p), p.content instanceof s && qe(p.content);
|
|
1266
|
+
if (J)
|
|
1267
|
+
return d;
|
|
1268
|
+
if (z) {
|
|
1269
|
+
if (ht)
|
|
1270
|
+
for (b = Pe.call(a.ownerDocument); a.firstChild; )
|
|
1271
|
+
b.appendChild(a.firstChild);
|
|
1104
1272
|
else
|
|
1105
|
-
|
|
1106
|
-
return (
|
|
1273
|
+
b = a;
|
|
1274
|
+
return (_.shadowroot || _.shadowrootmode) && (b = Fe.call(n, b, !0)), b;
|
|
1107
1275
|
}
|
|
1108
|
-
let
|
|
1109
|
-
return
|
|
1110
|
-
` +
|
|
1111
|
-
|
|
1112
|
-
}),
|
|
1276
|
+
let k = G ? a.outerHTML : a.innerHTML;
|
|
1277
|
+
return G && y["!doctype"] && a.ownerDocument && a.ownerDocument.doctype && a.ownerDocument.doctype.name && S(De, a.ownerDocument.doctype.name) && (k = "<!DOCTYPE " + a.ownerDocument.doctype.name + `>
|
|
1278
|
+
` + k), $ && Et([It, bt, At], (F) => {
|
|
1279
|
+
k = et(k, F, " ");
|
|
1280
|
+
}), A && ut ? A.createHTML(k) : k;
|
|
1113
1281
|
}, t.setConfig = function() {
|
|
1114
|
-
let
|
|
1115
|
-
|
|
1282
|
+
let d = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1283
|
+
Ct(d), Dt = !0;
|
|
1116
1284
|
}, t.clearConfig = function() {
|
|
1117
|
-
K = null,
|
|
1118
|
-
}, t.isValidAttribute = function(
|
|
1119
|
-
K ||
|
|
1120
|
-
const
|
|
1121
|
-
return
|
|
1122
|
-
}, t.addHook = function(
|
|
1123
|
-
typeof
|
|
1124
|
-
}, t.removeHook = function(
|
|
1125
|
-
if (
|
|
1126
|
-
const
|
|
1127
|
-
return
|
|
1285
|
+
K = null, Dt = !1;
|
|
1286
|
+
}, t.isValidAttribute = function(d, i, a) {
|
|
1287
|
+
K || Ct({});
|
|
1288
|
+
const c = T(d), p = T(i);
|
|
1289
|
+
return ce(c, p, a);
|
|
1290
|
+
}, t.addHook = function(d, i) {
|
|
1291
|
+
typeof i == "function" && tt(N[d], i);
|
|
1292
|
+
}, t.removeHook = function(d, i) {
|
|
1293
|
+
if (i !== void 0) {
|
|
1294
|
+
const a = on(N[d], i);
|
|
1295
|
+
return a === -1 ? void 0 : sn(N[d], a, 1)[0];
|
|
1128
1296
|
}
|
|
1129
|
-
return
|
|
1130
|
-
}, t.removeHooks = function(
|
|
1131
|
-
|
|
1297
|
+
return me(N[d]);
|
|
1298
|
+
}, t.removeHooks = function(d) {
|
|
1299
|
+
N[d] = [];
|
|
1132
1300
|
}, t.removeAllHooks = function() {
|
|
1133
|
-
|
|
1301
|
+
N = Ie();
|
|
1134
1302
|
}, t;
|
|
1135
1303
|
}
|
|
1136
|
-
var
|
|
1137
|
-
const
|
|
1304
|
+
var An = xe();
|
|
1305
|
+
const Nn = {
|
|
1138
1306
|
ALLOWED_TAGS: [
|
|
1139
1307
|
"p",
|
|
1140
1308
|
"br",
|
|
@@ -1188,14 +1356,14 @@ const xn = {
|
|
|
1188
1356
|
SANITIZE_DOM: !0,
|
|
1189
1357
|
SAFE_FOR_TEMPLATES: !0
|
|
1190
1358
|
};
|
|
1191
|
-
function
|
|
1192
|
-
const e = t ? Sn :
|
|
1193
|
-
return
|
|
1359
|
+
function st(r, t = !1) {
|
|
1360
|
+
const e = t ? Sn : Nn;
|
|
1361
|
+
return An.sanitize(r, e);
|
|
1194
1362
|
}
|
|
1195
|
-
function
|
|
1196
|
-
return t ?
|
|
1363
|
+
function Dn(r, t = !0) {
|
|
1364
|
+
return t ? st(r) : xn(r);
|
|
1197
1365
|
}
|
|
1198
|
-
function
|
|
1366
|
+
function xn(r) {
|
|
1199
1367
|
const t = document.createElement("div");
|
|
1200
1368
|
return t.textContent = r, t.innerHTML;
|
|
1201
1369
|
}
|
|
@@ -1206,18 +1374,18 @@ function Ln(r) {
|
|
|
1206
1374
|
for (const t of r.ops) {
|
|
1207
1375
|
if ("insert" in t) {
|
|
1208
1376
|
const e = t.insert;
|
|
1209
|
-
if (typeof e == "string" &&
|
|
1377
|
+
if (typeof e == "string" && st(e) !== e && e.includes("<script"))
|
|
1210
1378
|
return !1;
|
|
1211
1379
|
if (typeof e == "object" && e !== null) {
|
|
1212
|
-
const
|
|
1213
|
-
if ("script" in
|
|
1380
|
+
const n = e;
|
|
1381
|
+
if ("script" in n || "onerror" in n || "onclick" in n)
|
|
1214
1382
|
return !1;
|
|
1215
1383
|
}
|
|
1216
1384
|
}
|
|
1217
1385
|
if ("attributes" in t && t.attributes) {
|
|
1218
1386
|
const e = t.attributes;
|
|
1219
|
-
for (const
|
|
1220
|
-
if (
|
|
1387
|
+
for (const n in e)
|
|
1388
|
+
if (n.startsWith("on") || n.toLowerCase().includes("script"))
|
|
1221
1389
|
return !1;
|
|
1222
1390
|
}
|
|
1223
1391
|
}
|
|
@@ -1232,12 +1400,12 @@ function Le(r, t = "polite") {
|
|
|
1232
1400
|
e.textContent = r;
|
|
1233
1401
|
}, 100);
|
|
1234
1402
|
}
|
|
1235
|
-
function
|
|
1236
|
-
const e = (
|
|
1403
|
+
function kn(r, t) {
|
|
1404
|
+
const e = (n) => {
|
|
1237
1405
|
for (const o of r) {
|
|
1238
|
-
const
|
|
1239
|
-
if (
|
|
1240
|
-
|
|
1406
|
+
const s = o.ctrlKey ? n.ctrlKey : !0, l = o.metaKey ? n.metaKey : !0, h = o.shiftKey ? n.shiftKey : !n.shiftKey, f = o.altKey ? n.altKey : !n.altKey;
|
|
1407
|
+
if (n.key.toLowerCase() === o.key.toLowerCase() && s && l && h && f) {
|
|
1408
|
+
n.preventDefault(), o.action(), Le(o.description);
|
|
1241
1409
|
break;
|
|
1242
1410
|
}
|
|
1243
1411
|
}
|
|
@@ -1246,15 +1414,25 @@ function Rn(r, t) {
|
|
|
1246
1414
|
t.removeEventListener("keydown", e);
|
|
1247
1415
|
};
|
|
1248
1416
|
}
|
|
1249
|
-
function
|
|
1250
|
-
for (const [e,
|
|
1417
|
+
function On(r, t) {
|
|
1418
|
+
for (const [e, n] of Object.entries(t)) {
|
|
1251
1419
|
const o = e.startsWith("aria-") ? e : `aria-${e}`;
|
|
1252
|
-
r.setAttribute(o, String(
|
|
1420
|
+
r.setAttribute(o, String(n));
|
|
1253
1421
|
}
|
|
1254
1422
|
}
|
|
1255
|
-
class
|
|
1423
|
+
class ke extends HTMLElement {
|
|
1256
1424
|
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.
|
|
1425
|
+
super(), this.eventListeners = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.contentElement = null, this.pluginContainerTop = null, this.pluginContainerBottom = null, this.ariaLiveRegion = null, this.pendingPlugins = [], this.isReady = !1, this.handleInput = (e) => {
|
|
1426
|
+
this.updatePlaceholder(), e.target?.closest('[data-node-type="table"]') || this.syncContentToState(), this.emit("change", { state: this.state });
|
|
1427
|
+
}, this.handleKeydown = (e) => {
|
|
1428
|
+
this.emit("keydown", e), !e.defaultPrevented && ((e.ctrlKey || e.metaKey) && e.key === "z" && (e.preventDefault(), e.shiftKey ? (this.redo(), this.announceToScreenReader("Action redone")) : (this.undo(), this.announceToScreenReader("Action undone"))), ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(e.key) && (e.ctrlKey || e.metaKey) && this.announceToScreenReader(`Navigating ${e.key.replace("Arrow", "").toLowerCase()}`));
|
|
1429
|
+
}, this.handleFocus = () => {
|
|
1430
|
+
this.emit("focus", { state: this.state });
|
|
1431
|
+
}, this.handleBlur = () => {
|
|
1432
|
+
this.emit("blur", { state: this.state });
|
|
1433
|
+
}, this.handleContextMenu = (e) => {
|
|
1434
|
+
this.emit("contextmenu", e);
|
|
1435
|
+
}, this.config = {
|
|
1258
1436
|
placeholder: "Start typing...",
|
|
1259
1437
|
readonly: !1,
|
|
1260
1438
|
autofocus: !1,
|
|
@@ -1262,9 +1440,11 @@ class Re extends HTMLElement {
|
|
|
1262
1440
|
maxHistoryDepth: 100
|
|
1263
1441
|
};
|
|
1264
1442
|
const t = be();
|
|
1265
|
-
this.state = new
|
|
1443
|
+
this.state = new ot(void 0, t, {
|
|
1266
1444
|
maxHistoryDepth: this.config.maxHistoryDepth
|
|
1267
|
-
}), this.pluginManager = new
|
|
1445
|
+
}), this.pluginManager = new tn(), this.readyPromise = new Promise((e) => {
|
|
1446
|
+
this.readyResolve = e;
|
|
1447
|
+
}), this.attachShadow({ mode: "open" });
|
|
1268
1448
|
}
|
|
1269
1449
|
/**
|
|
1270
1450
|
* Observed attributes for the web component
|
|
@@ -1275,29 +1455,41 @@ class Re extends HTMLElement {
|
|
|
1275
1455
|
/**
|
|
1276
1456
|
* Called when element is connected to DOM
|
|
1277
1457
|
*/
|
|
1278
|
-
connectedCallback() {
|
|
1279
|
-
this.render(), this.attachEventListeners(), this.setupAccessibility(), this.setupKeyboardShortcuts(), this.
|
|
1458
|
+
async connectedCallback() {
|
|
1459
|
+
if (this.render(), this.attachEventListeners(), this.setupAccessibility(), this.setupKeyboardShortcuts(), this.isReady = !0, this.pendingPlugins.length > 0) {
|
|
1460
|
+
const t = [...this.pendingPlugins];
|
|
1461
|
+
this.pendingPlugins = [];
|
|
1462
|
+
for (const e of t)
|
|
1463
|
+
try {
|
|
1464
|
+
await this.pluginManager.register(e, this.createPluginContext());
|
|
1465
|
+
} catch (n) {
|
|
1466
|
+
console.error(`Failed to register pending plugin ${e.id}:`, n);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
this.readyResolve && this.readyResolve(), this.emit("ready", { editor: this }), this.config.autofocus && this.focus();
|
|
1280
1470
|
}
|
|
1281
1471
|
/**
|
|
1282
1472
|
* Called when element is disconnected from DOM
|
|
1283
1473
|
*/
|
|
1284
1474
|
disconnectedCallback() {
|
|
1285
|
-
this.detachEventListeners(), this.pluginManager.destroyAll(), this.keyboardShortcutCleanup && this.keyboardShortcutCleanup(), this.ariaLiveRegion && this.ariaLiveRegion.parentNode && this.ariaLiveRegion.parentNode.removeChild(this.ariaLiveRegion)
|
|
1475
|
+
this.detachEventListeners(), this.pluginManager.destroyAll(), this.keyboardShortcutCleanup && this.keyboardShortcutCleanup(), this.ariaLiveRegion && this.ariaLiveRegion.parentNode && this.ariaLiveRegion.parentNode.removeChild(this.ariaLiveRegion), this.isReady = !1, this.readyPromise = new Promise((t) => {
|
|
1476
|
+
this.readyResolve = t;
|
|
1477
|
+
});
|
|
1286
1478
|
}
|
|
1287
1479
|
/**
|
|
1288
1480
|
* Called when attributes change
|
|
1289
1481
|
*/
|
|
1290
|
-
attributeChangedCallback(t, e,
|
|
1291
|
-
if (e !==
|
|
1482
|
+
attributeChangedCallback(t, e, n) {
|
|
1483
|
+
if (e !== n)
|
|
1292
1484
|
switch (t) {
|
|
1293
1485
|
case "placeholder":
|
|
1294
|
-
this.config.placeholder =
|
|
1486
|
+
this.config.placeholder = n || "", this.updatePlaceholder();
|
|
1295
1487
|
break;
|
|
1296
1488
|
case "readonly":
|
|
1297
|
-
this.config.readonly =
|
|
1489
|
+
this.config.readonly = n !== null, this.updateReadonly();
|
|
1298
1490
|
break;
|
|
1299
1491
|
case "autofocus":
|
|
1300
|
-
this.config.autofocus =
|
|
1492
|
+
this.config.autofocus = n !== null;
|
|
1301
1493
|
break;
|
|
1302
1494
|
}
|
|
1303
1495
|
}
|
|
@@ -1423,7 +1615,7 @@ class Re extends HTMLElement {
|
|
|
1423
1615
|
renderContent() {
|
|
1424
1616
|
if (!this.contentElement) return;
|
|
1425
1617
|
const t = this.state.getDocument(), e = this.documentToHTML(t);
|
|
1426
|
-
this.contentElement.innerHTML = this.config.sanitizeHTML ?
|
|
1618
|
+
this.contentElement.innerHTML = this.config.sanitizeHTML ? st(e) : e;
|
|
1427
1619
|
}
|
|
1428
1620
|
/**
|
|
1429
1621
|
* Convert document to HTML
|
|
@@ -1441,6 +1633,8 @@ class Re extends HTMLElement {
|
|
|
1441
1633
|
case "heading":
|
|
1442
1634
|
const e = t.attrs?.level || 1;
|
|
1443
1635
|
return `<h${e}>${this.childrenToHTML(t.children || [])}</h${e}>`;
|
|
1636
|
+
case "table":
|
|
1637
|
+
return this.tableToHTML(t);
|
|
1444
1638
|
default:
|
|
1445
1639
|
return `<div>${this.childrenToHTML(t.children || [])}</div>`;
|
|
1446
1640
|
}
|
|
@@ -1451,11 +1645,11 @@ class Re extends HTMLElement {
|
|
|
1451
1645
|
childrenToHTML(t) {
|
|
1452
1646
|
return t.map((e) => {
|
|
1453
1647
|
if (e.type === "text") {
|
|
1454
|
-
let
|
|
1648
|
+
let n = this.escapeHTML(e.text);
|
|
1455
1649
|
if (e.marks)
|
|
1456
1650
|
for (const o of e.marks)
|
|
1457
|
-
|
|
1458
|
-
return
|
|
1651
|
+
n = this.applyMarkHTML(n, o);
|
|
1652
|
+
return n;
|
|
1459
1653
|
}
|
|
1460
1654
|
return this.blockToHTML(e);
|
|
1461
1655
|
}).join("");
|
|
@@ -1487,11 +1681,63 @@ class Re extends HTMLElement {
|
|
|
1487
1681
|
const e = document.createElement("div");
|
|
1488
1682
|
return e.textContent = t, e.innerHTML;
|
|
1489
1683
|
}
|
|
1684
|
+
tableToHTML(t) {
|
|
1685
|
+
const e = t.attrs?.table, o = [
|
|
1686
|
+
'data-node-type="table"',
|
|
1687
|
+
`data-block-id="${t.id || crypto.randomUUID()}"`
|
|
1688
|
+
];
|
|
1689
|
+
if (t.attrs?.style) {
|
|
1690
|
+
const h = this.styleObjectToString(t.attrs.style);
|
|
1691
|
+
h && o.push(`style="${h}"`);
|
|
1692
|
+
}
|
|
1693
|
+
let s = "";
|
|
1694
|
+
const l = Array.isArray(e?.rows) ? e.rows : [];
|
|
1695
|
+
if (l.length === 0) {
|
|
1696
|
+
const h = crypto.randomUUID();
|
|
1697
|
+
s = `
|
|
1698
|
+
<tr data-node-type="table_row" data-row="0" data-block-id="${crypto.randomUUID()}">
|
|
1699
|
+
<td data-node-type="table_cell" data-row="0" data-col="0" data-block-id="${h}"><br></td>
|
|
1700
|
+
</tr>
|
|
1701
|
+
`;
|
|
1702
|
+
} else
|
|
1703
|
+
s = l.map((h, f) => this.tableRowToHTML(h, f)).join("");
|
|
1704
|
+
return `<table ${o.join(" ")}><tbody>${s}</tbody></table>`;
|
|
1705
|
+
}
|
|
1706
|
+
tableRowToHTML(t, e) {
|
|
1707
|
+
const n = t.id || crypto.randomUUID(), o = [
|
|
1708
|
+
'data-node-type="table_row"',
|
|
1709
|
+
`data-row="${e}"`,
|
|
1710
|
+
`data-block-id="${n}"`
|
|
1711
|
+
];
|
|
1712
|
+
if (t.attrs?.style) {
|
|
1713
|
+
const h = this.styleObjectToString(t.attrs.style);
|
|
1714
|
+
h && o.push(`style="${h}"`);
|
|
1715
|
+
}
|
|
1716
|
+
const l = (Array.isArray(t.cells) ? t.cells : []).map((h, f) => this.tableCellToHTML(h, e, f)).join("");
|
|
1717
|
+
return `<tr ${o.join(" ")}>${l}</tr>`;
|
|
1718
|
+
}
|
|
1719
|
+
tableCellToHTML(t, e, n) {
|
|
1720
|
+
const o = t.id || crypto.randomUUID(), s = [
|
|
1721
|
+
'data-node-type="table_cell"',
|
|
1722
|
+
`data-row="${e}"`,
|
|
1723
|
+
`data-col="${n}"`,
|
|
1724
|
+
`data-block-id="${o}"`
|
|
1725
|
+
], l = Number(t.rowSpan) || 1, h = Number(t.colSpan) || 1;
|
|
1726
|
+
if (l > 1 && s.push(`rowspan="${l}"`), h > 1 && s.push(`colspan="${h}"`), t.attrs?.style) {
|
|
1727
|
+
const L = this.styleObjectToString(t.attrs.style);
|
|
1728
|
+
L && s.push(`style="${L}"`);
|
|
1729
|
+
}
|
|
1730
|
+
const E = (typeof t.content == "string" ? this.escapeHTML(t.content) : "") || "<br>";
|
|
1731
|
+
return `<td ${s.join(" ")}>${E}</td>`;
|
|
1732
|
+
}
|
|
1733
|
+
styleObjectToString(t) {
|
|
1734
|
+
return Object.entries(t).map(([e, n]) => n == null || n === "" ? null : `${e.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`)}: ${String(n)}`).filter(Boolean).join("; ");
|
|
1735
|
+
}
|
|
1490
1736
|
/**
|
|
1491
1737
|
* Setup accessibility features
|
|
1492
1738
|
*/
|
|
1493
1739
|
setupAccessibility() {
|
|
1494
|
-
this.contentElement && (
|
|
1740
|
+
this.contentElement && (On(this.contentElement, {
|
|
1495
1741
|
role: "textbox",
|
|
1496
1742
|
"aria-multiline": !0,
|
|
1497
1743
|
"aria-label": "Rich text editor",
|
|
@@ -1537,7 +1783,7 @@ class Re extends HTMLElement {
|
|
|
1537
1783
|
action: () => this.redo()
|
|
1538
1784
|
}
|
|
1539
1785
|
];
|
|
1540
|
-
this.keyboardShortcutCleanup =
|
|
1786
|
+
this.keyboardShortcutCleanup = kn(t, this.contentElement);
|
|
1541
1787
|
}
|
|
1542
1788
|
/**
|
|
1543
1789
|
* Toggle formatting
|
|
@@ -1560,16 +1806,16 @@ class Re extends HTMLElement {
|
|
|
1560
1806
|
document.execCommand("strikeThrough", !1);
|
|
1561
1807
|
break;
|
|
1562
1808
|
case "code":
|
|
1563
|
-
const
|
|
1809
|
+
const n = document.createElement("code");
|
|
1564
1810
|
if (e.rangeCount > 0) {
|
|
1565
1811
|
const o = e.getRangeAt(0);
|
|
1566
|
-
|
|
1812
|
+
n.appendChild(o.extractContents()), o.insertNode(n);
|
|
1567
1813
|
}
|
|
1568
1814
|
break;
|
|
1569
1815
|
}
|
|
1570
1816
|
this.announceToScreenReader(`${t} formatting applied`), this.emit("change", { state: this.state });
|
|
1571
|
-
} catch (
|
|
1572
|
-
console.error(`Failed to apply ${t} formatting:`,
|
|
1817
|
+
} catch (n) {
|
|
1818
|
+
console.error(`Failed to apply ${t} formatting:`, n), this.announceToScreenReader(`Failed to apply ${t} formatting`);
|
|
1573
1819
|
}
|
|
1574
1820
|
}
|
|
1575
1821
|
/**
|
|
@@ -1579,48 +1825,48 @@ class Re extends HTMLElement {
|
|
|
1579
1825
|
if (this.contentElement)
|
|
1580
1826
|
try {
|
|
1581
1827
|
this.contentElement.focus();
|
|
1582
|
-
const
|
|
1583
|
-
|
|
1828
|
+
const n = document.createElement("table");
|
|
1829
|
+
n.setAttribute("data-notectl-table", "true");
|
|
1584
1830
|
const o = document.createElement("tbody");
|
|
1585
|
-
for (let
|
|
1586
|
-
const
|
|
1587
|
-
for (let
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1831
|
+
for (let f = 0; f < t; f++) {
|
|
1832
|
+
const E = document.createElement("tr");
|
|
1833
|
+
for (let L = 0; L < e; L++) {
|
|
1834
|
+
const at = document.createElement("td");
|
|
1835
|
+
at.textContent = "", E.appendChild(at);
|
|
1590
1836
|
}
|
|
1591
|
-
o.appendChild(
|
|
1837
|
+
o.appendChild(E);
|
|
1592
1838
|
}
|
|
1593
|
-
|
|
1594
|
-
const
|
|
1595
|
-
let
|
|
1596
|
-
if (
|
|
1597
|
-
const
|
|
1598
|
-
if (this.contentElement.contains(
|
|
1599
|
-
let
|
|
1600
|
-
if (
|
|
1601
|
-
|
|
1839
|
+
n.appendChild(o);
|
|
1840
|
+
const s = window.getSelection();
|
|
1841
|
+
let l = this.contentElement.childNodes.length;
|
|
1842
|
+
if (s && s.rangeCount > 0) {
|
|
1843
|
+
const f = s.getRangeAt(0);
|
|
1844
|
+
if (this.contentElement.contains(f.commonAncestorContainer)) {
|
|
1845
|
+
let E = f.startContainer;
|
|
1846
|
+
if (E.nodeType === Node.TEXT_NODE && (E = E.parentNode), E === this.contentElement)
|
|
1847
|
+
l = f.startOffset;
|
|
1602
1848
|
else {
|
|
1603
|
-
let
|
|
1604
|
-
for (;
|
|
1605
|
-
|
|
1606
|
-
|
|
1849
|
+
let L = E;
|
|
1850
|
+
for (; L.parentNode && L.parentNode !== this.contentElement; )
|
|
1851
|
+
L = L.parentNode;
|
|
1852
|
+
L.parentNode === this.contentElement && (l = Array.from(this.contentElement.childNodes).indexOf(L) + 1);
|
|
1607
1853
|
}
|
|
1608
1854
|
}
|
|
1609
1855
|
}
|
|
1610
1856
|
const h = document.createElement("p");
|
|
1611
|
-
if (h.innerHTML = "<br>",
|
|
1612
|
-
this.contentElement.appendChild(
|
|
1857
|
+
if (h.innerHTML = "<br>", l >= this.contentElement.childNodes.length)
|
|
1858
|
+
this.contentElement.appendChild(n), this.contentElement.appendChild(h);
|
|
1613
1859
|
else {
|
|
1614
|
-
const
|
|
1615
|
-
this.contentElement.insertBefore(
|
|
1860
|
+
const f = this.contentElement.childNodes[l];
|
|
1861
|
+
this.contentElement.insertBefore(n, f), this.contentElement.insertBefore(h, f);
|
|
1616
1862
|
}
|
|
1617
|
-
if (
|
|
1618
|
-
const
|
|
1619
|
-
|
|
1863
|
+
if (s) {
|
|
1864
|
+
const f = document.createRange();
|
|
1865
|
+
f.setStart(h, 0), f.setEnd(h, 0), s.removeAllRanges(), s.addRange(f);
|
|
1620
1866
|
}
|
|
1621
1867
|
this.updatePlaceholder(), this.syncContentToState(), this.announceToScreenReader(`Table with ${t} rows and ${e} columns inserted`), this.emit("change", { state: this.state });
|
|
1622
|
-
} catch (
|
|
1623
|
-
console.error("Failed to insert table:",
|
|
1868
|
+
} catch (n) {
|
|
1869
|
+
console.error("Failed to insert table:", n), this.announceToScreenReader("Failed to insert table");
|
|
1624
1870
|
}
|
|
1625
1871
|
}
|
|
1626
1872
|
/**
|
|
@@ -1635,37 +1881,13 @@ class Re extends HTMLElement {
|
|
|
1635
1881
|
* Attach event listeners
|
|
1636
1882
|
*/
|
|
1637
1883
|
attachEventListeners() {
|
|
1638
|
-
this.contentElement && (this.contentElement.addEventListener("input", this.handleInput
|
|
1884
|
+
this.contentElement && (this.contentElement.addEventListener("input", this.handleInput), this.contentElement.addEventListener("keydown", this.handleKeydown), this.contentElement.addEventListener("focus", this.handleFocus), this.contentElement.addEventListener("blur", this.handleBlur), this.contentElement.addEventListener("contextmenu", this.handleContextMenu));
|
|
1639
1885
|
}
|
|
1640
1886
|
/**
|
|
1641
1887
|
* Detach event listeners
|
|
1642
1888
|
*/
|
|
1643
1889
|
detachEventListeners() {
|
|
1644
|
-
this.contentElement && (this.contentElement.removeEventListener("input", this.handleInput
|
|
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 });
|
|
1890
|
+
this.contentElement && (this.contentElement.removeEventListener("input", this.handleInput), this.contentElement.removeEventListener("keydown", this.handleKeydown), this.contentElement.removeEventListener("focus", this.handleFocus), this.contentElement.removeEventListener("blur", this.handleBlur), this.contentElement.removeEventListener("contextmenu", this.handleContextMenu));
|
|
1669
1891
|
}
|
|
1670
1892
|
/**
|
|
1671
1893
|
* Update placeholder visibility
|
|
@@ -1682,7 +1904,7 @@ class Re extends HTMLElement {
|
|
|
1682
1904
|
if (this.contentElement)
|
|
1683
1905
|
try {
|
|
1684
1906
|
const t = this.htmlToDocument(this.contentElement.innerHTML);
|
|
1685
|
-
this.state =
|
|
1907
|
+
this.state = ot.fromJSON(t, this.state.schema);
|
|
1686
1908
|
} catch (t) {
|
|
1687
1909
|
console.error("Failed to sync content to state:", t);
|
|
1688
1910
|
}
|
|
@@ -1691,18 +1913,18 @@ class Re extends HTMLElement {
|
|
|
1691
1913
|
* Convert HTML to document structure
|
|
1692
1914
|
*/
|
|
1693
1915
|
htmlToDocument(t) {
|
|
1694
|
-
const o = new DOMParser().parseFromString(t, "text/html").body,
|
|
1695
|
-
return Array.from(o.childNodes).forEach((
|
|
1696
|
-
const h = this.nodeToBlock(
|
|
1697
|
-
h &&
|
|
1698
|
-
}),
|
|
1916
|
+
const o = new DOMParser().parseFromString(t, "text/html").body, s = [];
|
|
1917
|
+
return Array.from(o.childNodes).forEach((l) => {
|
|
1918
|
+
const h = this.nodeToBlock(l);
|
|
1919
|
+
h && s.push(h);
|
|
1920
|
+
}), s.length === 0 && s.push({
|
|
1699
1921
|
id: crypto.randomUUID(),
|
|
1700
1922
|
type: "paragraph",
|
|
1701
1923
|
children: []
|
|
1702
1924
|
}), {
|
|
1703
1925
|
version: this.state.getDocument().version + 1,
|
|
1704
1926
|
schemaVersion: "1.0.0",
|
|
1705
|
-
children:
|
|
1927
|
+
children: s
|
|
1706
1928
|
};
|
|
1707
1929
|
}
|
|
1708
1930
|
/**
|
|
@@ -1718,15 +1940,15 @@ class Re extends HTMLElement {
|
|
|
1718
1940
|
} : null;
|
|
1719
1941
|
}
|
|
1720
1942
|
if (t.nodeType === Node.ELEMENT_NODE) {
|
|
1721
|
-
const e = t,
|
|
1722
|
-
if (
|
|
1943
|
+
const e = t, n = e.tagName.toLowerCase();
|
|
1944
|
+
if (n === "p")
|
|
1723
1945
|
return {
|
|
1724
1946
|
id: crypto.randomUUID(),
|
|
1725
1947
|
type: "paragraph",
|
|
1726
1948
|
children: this.parseChildren(e)
|
|
1727
1949
|
};
|
|
1728
|
-
if (["h1", "h2", "h3", "h4", "h5", "h6"].includes(
|
|
1729
|
-
const o = parseInt(
|
|
1950
|
+
if (["h1", "h2", "h3", "h4", "h5", "h6"].includes(n)) {
|
|
1951
|
+
const o = parseInt(n.charAt(1), 10);
|
|
1730
1952
|
return {
|
|
1731
1953
|
id: crypto.randomUUID(),
|
|
1732
1954
|
type: "heading",
|
|
@@ -1743,17 +1965,17 @@ class Re extends HTMLElement {
|
|
|
1743
1965
|
*/
|
|
1744
1966
|
parseChildren(t) {
|
|
1745
1967
|
const e = [];
|
|
1746
|
-
return Array.from(t.childNodes).forEach((
|
|
1747
|
-
if (
|
|
1748
|
-
const o =
|
|
1968
|
+
return Array.from(t.childNodes).forEach((n) => {
|
|
1969
|
+
if (n.nodeType === Node.TEXT_NODE) {
|
|
1970
|
+
const o = n.textContent || "";
|
|
1749
1971
|
o && e.push({
|
|
1750
1972
|
type: "text",
|
|
1751
1973
|
text: o,
|
|
1752
1974
|
marks: []
|
|
1753
1975
|
});
|
|
1754
|
-
} else if (
|
|
1755
|
-
const o =
|
|
1756
|
-
|
|
1976
|
+
} else if (n.nodeType === Node.ELEMENT_NODE) {
|
|
1977
|
+
const o = n, s = this.parseInlineElement(o);
|
|
1978
|
+
s && (Array.isArray(s) ? e.push(...s) : e.push(s));
|
|
1757
1979
|
}
|
|
1758
1980
|
}), e;
|
|
1759
1981
|
}
|
|
@@ -1761,21 +1983,21 @@ class Re extends HTMLElement {
|
|
|
1761
1983
|
* Parse inline element with marks
|
|
1762
1984
|
*/
|
|
1763
1985
|
parseInlineElement(t) {
|
|
1764
|
-
const e = t.tagName.toLowerCase(),
|
|
1765
|
-
e === "strong" || e === "b" ?
|
|
1986
|
+
const e = t.tagName.toLowerCase(), n = [];
|
|
1987
|
+
e === "strong" || e === "b" ? n.push({ type: "bold" }) : e === "em" || e === "i" ? n.push({ type: "italic" }) : e === "u" ? n.push({ type: "underline" }) : e === "s" || e === "strike" ? n.push({ type: "strikethrough" }) : e === "code" && n.push({ type: "code" });
|
|
1766
1988
|
const o = [];
|
|
1767
|
-
return Array.from(t.childNodes).forEach((
|
|
1768
|
-
if (
|
|
1769
|
-
const
|
|
1770
|
-
|
|
1989
|
+
return Array.from(t.childNodes).forEach((s) => {
|
|
1990
|
+
if (s.nodeType === Node.TEXT_NODE) {
|
|
1991
|
+
const l = s.textContent || "";
|
|
1992
|
+
l && o.push({
|
|
1771
1993
|
type: "text",
|
|
1772
|
-
text:
|
|
1773
|
-
marks:
|
|
1994
|
+
text: l,
|
|
1995
|
+
marks: n
|
|
1774
1996
|
});
|
|
1775
|
-
} else if (
|
|
1776
|
-
const
|
|
1777
|
-
h && (h.type === "text" ? (h.marks = [...
|
|
1778
|
-
|
|
1997
|
+
} else if (s.nodeType === Node.ELEMENT_NODE) {
|
|
1998
|
+
const l = s, h = this.parseInlineElement(l);
|
|
1999
|
+
h && (h.type === "text" ? (h.marks = [...n, ...h.marks || []], o.push(h)) : Array.isArray(h) && h.forEach((f) => {
|
|
2000
|
+
f.type === "text" && (f.marks = [...n, ...f.marks || []]), o.push(f);
|
|
1779
2001
|
}));
|
|
1780
2002
|
}
|
|
1781
2003
|
}), o.length === 1 ? o[0] : o;
|
|
@@ -1788,8 +2010,19 @@ class Re extends HTMLElement {
|
|
|
1788
2010
|
}
|
|
1789
2011
|
/**
|
|
1790
2012
|
* Register a plugin
|
|
2013
|
+
*
|
|
2014
|
+
* Plugins can be registered before or after the editor is mounted.
|
|
2015
|
+
* If registered before mounting, they will be queued and initialized
|
|
2016
|
+
* automatically when the editor connects to the DOM.
|
|
2017
|
+
*
|
|
2018
|
+
* @param plugin - The plugin to register
|
|
2019
|
+
* @returns Promise that resolves when the plugin is registered
|
|
1791
2020
|
*/
|
|
1792
2021
|
async registerPlugin(t) {
|
|
2022
|
+
if (!this.isReady) {
|
|
2023
|
+
this.pendingPlugins.push(t);
|
|
2024
|
+
return;
|
|
2025
|
+
}
|
|
1793
2026
|
const e = this.createPluginContext();
|
|
1794
2027
|
await this.pluginManager.register(t, e);
|
|
1795
2028
|
}
|
|
@@ -1800,18 +2033,301 @@ class Re extends HTMLElement {
|
|
|
1800
2033
|
const e = this.createPluginContext();
|
|
1801
2034
|
await this.pluginManager.unregister(t, e);
|
|
1802
2035
|
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Wait for the editor to be ready
|
|
2038
|
+
*
|
|
2039
|
+
* Returns a Promise that resolves when the editor has been mounted
|
|
2040
|
+
* and all pending plugins have been initialized. This is useful when
|
|
2041
|
+
* you need to ensure the editor is fully initialized before performing
|
|
2042
|
+
* operations that depend on the editor being mounted.
|
|
2043
|
+
*
|
|
2044
|
+
* @returns Promise that resolves when the editor is ready
|
|
2045
|
+
* @example
|
|
2046
|
+
* ```typescript
|
|
2047
|
+
* const editor = document.createElement('notectl-editor');
|
|
2048
|
+
* container.appendChild(editor);
|
|
2049
|
+
* await editor.whenReady();
|
|
2050
|
+
* // Editor is now fully initialized
|
|
2051
|
+
* ```
|
|
2052
|
+
*/
|
|
2053
|
+
async whenReady() {
|
|
2054
|
+
return this.readyPromise;
|
|
2055
|
+
}
|
|
2056
|
+
// ===== Plugin Context Helper Methods =====
|
|
2057
|
+
/**
|
|
2058
|
+
* Get the block containing the current selection
|
|
2059
|
+
*/
|
|
2060
|
+
getSelectedBlock() {
|
|
2061
|
+
const t = this.state.getSelection();
|
|
2062
|
+
return t && this.state.findBlock(t.anchor.blockId) || null;
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
* Find all blocks of a specific type
|
|
2066
|
+
*/
|
|
2067
|
+
findBlocksByType(t) {
|
|
2068
|
+
const e = [], n = this.state.getDocument(), o = (s) => {
|
|
2069
|
+
for (const l of s)
|
|
2070
|
+
if (l.type === t && e.push(l), l.children) {
|
|
2071
|
+
const h = l.children.filter(
|
|
2072
|
+
(f) => "id" in f
|
|
2073
|
+
);
|
|
2074
|
+
o(h);
|
|
2075
|
+
}
|
|
2076
|
+
};
|
|
2077
|
+
return o(n.children), e;
|
|
2078
|
+
}
|
|
2079
|
+
/**
|
|
2080
|
+
* Find parent block of a given block
|
|
2081
|
+
*/
|
|
2082
|
+
findParentBlock(t) {
|
|
2083
|
+
const e = this.state.getDocument(), n = (o, s = null) => {
|
|
2084
|
+
for (const l of o) {
|
|
2085
|
+
if (l.id === t.id)
|
|
2086
|
+
return s;
|
|
2087
|
+
if (l.children) {
|
|
2088
|
+
const h = l.children.filter(
|
|
2089
|
+
(E) => "id" in E
|
|
2090
|
+
), f = n(h, l);
|
|
2091
|
+
if (f) return f;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
return null;
|
|
2095
|
+
};
|
|
2096
|
+
return n(e.children);
|
|
2097
|
+
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Get block at current cursor position
|
|
2100
|
+
*/
|
|
2101
|
+
getBlockAtCursor() {
|
|
2102
|
+
return this.getSelectedBlock();
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Insert a block after another block (Delta-based)
|
|
2106
|
+
*/
|
|
2107
|
+
insertBlockAfter(t, e) {
|
|
2108
|
+
const n = this.state.getDocument(), o = e || n.children[n.children.length - 1]?.id;
|
|
2109
|
+
if (!o) {
|
|
2110
|
+
const l = {
|
|
2111
|
+
txnId: crypto.randomUUID(),
|
|
2112
|
+
clientId: "editor",
|
|
2113
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2114
|
+
baseVersion: this.state.getVersion(),
|
|
2115
|
+
ltime: Date.now(),
|
|
2116
|
+
intent: "edit",
|
|
2117
|
+
ops: [
|
|
2118
|
+
{
|
|
2119
|
+
op: "insert_block_after",
|
|
2120
|
+
after: "",
|
|
2121
|
+
block: t
|
|
2122
|
+
}
|
|
2123
|
+
]
|
|
2124
|
+
};
|
|
2125
|
+
this.applyDelta(l);
|
|
2126
|
+
return;
|
|
2127
|
+
}
|
|
2128
|
+
const s = {
|
|
2129
|
+
txnId: crypto.randomUUID(),
|
|
2130
|
+
clientId: "editor",
|
|
2131
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2132
|
+
baseVersion: this.state.getVersion(),
|
|
2133
|
+
ltime: Date.now(),
|
|
2134
|
+
intent: "edit",
|
|
2135
|
+
ops: [
|
|
2136
|
+
{
|
|
2137
|
+
op: "insert_block_after",
|
|
2138
|
+
after: o,
|
|
2139
|
+
block: t
|
|
2140
|
+
}
|
|
2141
|
+
]
|
|
2142
|
+
};
|
|
2143
|
+
this.applyDelta(s);
|
|
2144
|
+
}
|
|
2145
|
+
/**
|
|
2146
|
+
* Insert a block before another block (Delta-based)
|
|
2147
|
+
*/
|
|
2148
|
+
insertBlockBefore(t, e) {
|
|
2149
|
+
const n = this.state.getDocument(), o = e || n.children[0]?.id;
|
|
2150
|
+
if (!o) {
|
|
2151
|
+
this.insertBlockAfter(t);
|
|
2152
|
+
return;
|
|
2153
|
+
}
|
|
2154
|
+
const s = {
|
|
2155
|
+
txnId: crypto.randomUUID(),
|
|
2156
|
+
clientId: "editor",
|
|
2157
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2158
|
+
baseVersion: this.state.getVersion(),
|
|
2159
|
+
ltime: Date.now(),
|
|
2160
|
+
intent: "edit",
|
|
2161
|
+
ops: [
|
|
2162
|
+
{
|
|
2163
|
+
op: "insert_block_before",
|
|
2164
|
+
before: o,
|
|
2165
|
+
block: t
|
|
2166
|
+
}
|
|
2167
|
+
]
|
|
2168
|
+
};
|
|
2169
|
+
this.applyDelta(s);
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Update block attributes (Delta-based)
|
|
2173
|
+
*/
|
|
2174
|
+
updateBlockAttrs(t, e) {
|
|
2175
|
+
const n = {
|
|
2176
|
+
txnId: crypto.randomUUID(),
|
|
2177
|
+
clientId: "editor",
|
|
2178
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2179
|
+
baseVersion: this.state.getVersion(),
|
|
2180
|
+
ltime: Date.now(),
|
|
2181
|
+
intent: "edit",
|
|
2182
|
+
ops: [
|
|
2183
|
+
{
|
|
2184
|
+
op: "set_attrs",
|
|
2185
|
+
target: { blockId: t },
|
|
2186
|
+
attrs: e
|
|
2187
|
+
}
|
|
2188
|
+
]
|
|
2189
|
+
};
|
|
2190
|
+
this.applyDelta(n);
|
|
2191
|
+
}
|
|
2192
|
+
/**
|
|
2193
|
+
* Delete a block (Delta-based)
|
|
2194
|
+
*/
|
|
2195
|
+
deleteBlockById(t) {
|
|
2196
|
+
const e = {
|
|
2197
|
+
txnId: crypto.randomUUID(),
|
|
2198
|
+
clientId: "editor",
|
|
2199
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2200
|
+
baseVersion: this.state.getVersion(),
|
|
2201
|
+
ltime: Date.now(),
|
|
2202
|
+
intent: "edit",
|
|
2203
|
+
ops: [
|
|
2204
|
+
{
|
|
2205
|
+
op: "delete_block",
|
|
2206
|
+
target: { blockId: t }
|
|
2207
|
+
}
|
|
2208
|
+
]
|
|
2209
|
+
};
|
|
2210
|
+
this.applyDelta(e);
|
|
2211
|
+
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Add mark to current selection (Delta-based)
|
|
2214
|
+
*/
|
|
2215
|
+
addMarkToSelection(t) {
|
|
2216
|
+
const e = this.state.getSelection();
|
|
2217
|
+
if (!e) return;
|
|
2218
|
+
const n = {
|
|
2219
|
+
txnId: crypto.randomUUID(),
|
|
2220
|
+
clientId: "editor",
|
|
2221
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2222
|
+
baseVersion: this.state.getVersion(),
|
|
2223
|
+
ltime: Date.now(),
|
|
2224
|
+
intent: "format",
|
|
2225
|
+
ops: [
|
|
2226
|
+
{
|
|
2227
|
+
op: "apply_mark",
|
|
2228
|
+
range: {
|
|
2229
|
+
start: e.anchor,
|
|
2230
|
+
end: e.head
|
|
2231
|
+
},
|
|
2232
|
+
mark: t,
|
|
2233
|
+
add: !0
|
|
2234
|
+
}
|
|
2235
|
+
]
|
|
2236
|
+
};
|
|
2237
|
+
this.applyDelta(n);
|
|
2238
|
+
}
|
|
2239
|
+
/**
|
|
2240
|
+
* Remove mark from current selection (Delta-based)
|
|
2241
|
+
*/
|
|
2242
|
+
removeMarkFromSelection(t) {
|
|
2243
|
+
const e = this.state.getSelection();
|
|
2244
|
+
if (!e) return;
|
|
2245
|
+
const n = {
|
|
2246
|
+
txnId: crypto.randomUUID(),
|
|
2247
|
+
clientId: "editor",
|
|
2248
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2249
|
+
baseVersion: this.state.getVersion(),
|
|
2250
|
+
ltime: Date.now(),
|
|
2251
|
+
intent: "format",
|
|
2252
|
+
ops: [
|
|
2253
|
+
{
|
|
2254
|
+
op: "apply_mark",
|
|
2255
|
+
range: {
|
|
2256
|
+
start: e.anchor,
|
|
2257
|
+
end: e.head
|
|
2258
|
+
},
|
|
2259
|
+
mark: { type: t },
|
|
2260
|
+
add: !1
|
|
2261
|
+
}
|
|
2262
|
+
]
|
|
2263
|
+
};
|
|
2264
|
+
this.applyDelta(n);
|
|
2265
|
+
}
|
|
2266
|
+
/**
|
|
2267
|
+
* Toggle mark on current selection (Delta-based)
|
|
2268
|
+
*/
|
|
2269
|
+
toggleMarkOnSelection(t) {
|
|
2270
|
+
const e = this.state.getSelection();
|
|
2271
|
+
if (!e) return;
|
|
2272
|
+
const n = this.state.findBlock(e.anchor.blockId);
|
|
2273
|
+
if (!n || !n.children) return;
|
|
2274
|
+
const s = n.children.find((h) => "text" in h)?.marks?.some((h) => h.type === t) || !1, l = {
|
|
2275
|
+
txnId: crypto.randomUUID(),
|
|
2276
|
+
clientId: "editor",
|
|
2277
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2278
|
+
baseVersion: this.state.getVersion(),
|
|
2279
|
+
ltime: Date.now(),
|
|
2280
|
+
intent: "format",
|
|
2281
|
+
ops: [
|
|
2282
|
+
{
|
|
2283
|
+
op: "apply_mark",
|
|
2284
|
+
range: {
|
|
2285
|
+
start: e.anchor,
|
|
2286
|
+
end: e.head
|
|
2287
|
+
},
|
|
2288
|
+
mark: { type: t },
|
|
2289
|
+
add: !s
|
|
2290
|
+
}
|
|
2291
|
+
]
|
|
2292
|
+
};
|
|
2293
|
+
this.applyDelta(l);
|
|
2294
|
+
}
|
|
1803
2295
|
/**
|
|
1804
2296
|
* Create plugin context
|
|
1805
2297
|
*/
|
|
1806
2298
|
createPluginContext() {
|
|
1807
2299
|
return {
|
|
2300
|
+
// Core state and delta operations
|
|
1808
2301
|
getState: () => this.state,
|
|
1809
2302
|
applyDelta: (t) => this.applyDelta(t),
|
|
2303
|
+
// Selection helpers
|
|
2304
|
+
getSelection: () => this.state.getSelection(),
|
|
2305
|
+
setSelection: (t) => {
|
|
2306
|
+
this.state.setSelection(t), this.emit("selection-change", { selection: t });
|
|
2307
|
+
},
|
|
2308
|
+
getSelectedBlock: () => this.getSelectedBlock(),
|
|
2309
|
+
// Node queries
|
|
2310
|
+
findBlocksByType: (t) => this.findBlocksByType(t),
|
|
2311
|
+
findBlockById: (t) => this.state.findBlock(t),
|
|
2312
|
+
findParentBlock: (t) => this.findParentBlock(t),
|
|
2313
|
+
getBlockAtCursor: () => this.getBlockAtCursor(),
|
|
2314
|
+
// Block mutations
|
|
2315
|
+
insertBlockAfter: (t, e) => this.insertBlockAfter(t, e),
|
|
2316
|
+
insertBlockBefore: (t, e) => this.insertBlockBefore(t, e),
|
|
2317
|
+
updateBlockAttrs: (t, e) => this.updateBlockAttrs(t, e),
|
|
2318
|
+
deleteBlock: (t) => this.deleteBlockById(t),
|
|
2319
|
+
// Mark utilities
|
|
2320
|
+
addMark: (t) => this.addMarkToSelection(t),
|
|
2321
|
+
removeMark: (t) => this.removeMarkFromSelection(t),
|
|
2322
|
+
toggleMark: (t) => this.toggleMarkOnSelection(t),
|
|
2323
|
+
// Events
|
|
1810
2324
|
on: (t, e) => this.on(t, e),
|
|
1811
2325
|
off: (t, e) => this.off(t, e),
|
|
1812
2326
|
emit: (t, e) => this.emit(t, e),
|
|
2327
|
+
// Commands
|
|
1813
2328
|
registerCommand: (t, e) => this.registerCommand(t, e),
|
|
1814
2329
|
executeCommand: (t, ...e) => this.executeCommand(t, ...e),
|
|
2330
|
+
// DOM access (deprecated)
|
|
1815
2331
|
getContainer: () => this.contentElement,
|
|
1816
2332
|
getPluginContainer: (t) => t === "top" ? this.pluginContainerTop : this.pluginContainerBottom
|
|
1817
2333
|
};
|
|
@@ -1842,9 +2358,9 @@ class Re extends HTMLElement {
|
|
|
1842
2358
|
* Emit event
|
|
1843
2359
|
*/
|
|
1844
2360
|
emit(t, e) {
|
|
1845
|
-
this.eventListeners.get(t)?.forEach((
|
|
2361
|
+
this.eventListeners.get(t)?.forEach((n) => {
|
|
1846
2362
|
try {
|
|
1847
|
-
|
|
2363
|
+
n(e);
|
|
1848
2364
|
} catch (o) {
|
|
1849
2365
|
console.error(`Error in event listener for ${t}:`, o);
|
|
1850
2366
|
}
|
|
@@ -1860,10 +2376,10 @@ class Re extends HTMLElement {
|
|
|
1860
2376
|
* Execute command
|
|
1861
2377
|
*/
|
|
1862
2378
|
executeCommand(t, ...e) {
|
|
1863
|
-
const
|
|
1864
|
-
if (!
|
|
2379
|
+
const n = this.commands.get(t);
|
|
2380
|
+
if (!n)
|
|
1865
2381
|
throw new Error(`Command not found: ${t}`);
|
|
1866
|
-
return
|
|
2382
|
+
return n(...e);
|
|
1867
2383
|
}
|
|
1868
2384
|
/**
|
|
1869
2385
|
* Undo last change
|
|
@@ -1919,21 +2435,21 @@ class Re extends HTMLElement {
|
|
|
1919
2435
|
* Set document from JSON
|
|
1920
2436
|
*/
|
|
1921
2437
|
setJSON(t) {
|
|
1922
|
-
this.state =
|
|
2438
|
+
this.state = ot.fromJSON(t, this.state.schema), this.renderContent();
|
|
1923
2439
|
}
|
|
1924
2440
|
/**
|
|
1925
2441
|
* Get HTML content (sanitized)
|
|
1926
2442
|
*/
|
|
1927
2443
|
getHTML() {
|
|
1928
2444
|
const t = this.documentToHTML(this.state.getDocument());
|
|
1929
|
-
return this.config.sanitizeHTML ?
|
|
2445
|
+
return this.config.sanitizeHTML ? st(t) : t;
|
|
1930
2446
|
}
|
|
1931
2447
|
/**
|
|
1932
2448
|
* Set HTML content (with sanitization)
|
|
1933
2449
|
* @param html - HTML content to set
|
|
1934
2450
|
*/
|
|
1935
2451
|
setHTML(t) {
|
|
1936
|
-
const e = this.config.sanitizeHTML ?
|
|
2452
|
+
const e = this.config.sanitizeHTML ? st(t) : t;
|
|
1937
2453
|
this.contentElement && (this.contentElement.innerHTML = e, this.announceToScreenReader("Content updated"));
|
|
1938
2454
|
}
|
|
1939
2455
|
/**
|
|
@@ -1942,8 +2458,8 @@ class Re extends HTMLElement {
|
|
|
1942
2458
|
* @param allowHTML - Allow HTML tags
|
|
1943
2459
|
*/
|
|
1944
2460
|
setContent(t, e = !0) {
|
|
1945
|
-
const
|
|
1946
|
-
this.contentElement && (this.contentElement.innerHTML =
|
|
2461
|
+
const n = this.config.sanitizeHTML ? Dn(t, e) : t;
|
|
2462
|
+
this.contentElement && (this.contentElement.innerHTML = n, this.announceToScreenReader("Content updated"));
|
|
1947
2463
|
}
|
|
1948
2464
|
/**
|
|
1949
2465
|
* Export HTML content (sanitized)
|
|
@@ -1965,8 +2481,8 @@ class Re extends HTMLElement {
|
|
|
1965
2481
|
this.contentElement?.blur();
|
|
1966
2482
|
}
|
|
1967
2483
|
}
|
|
1968
|
-
customElements.get("notectl-editor") || customElements.define("notectl-editor",
|
|
1969
|
-
class
|
|
2484
|
+
customElements.get("notectl-editor") || customElements.define("notectl-editor", ke);
|
|
2485
|
+
class $n {
|
|
1970
2486
|
async init(t) {
|
|
1971
2487
|
this.context = t;
|
|
1972
2488
|
}
|
|
@@ -1979,7 +2495,7 @@ class Mn {
|
|
|
1979
2495
|
return this.context;
|
|
1980
2496
|
}
|
|
1981
2497
|
}
|
|
1982
|
-
class
|
|
2498
|
+
class Rn {
|
|
1983
2499
|
constructor(t, e) {
|
|
1984
2500
|
this.operations = [], this.delta = {
|
|
1985
2501
|
txnId: this.generateTxnId(),
|
|
@@ -2047,35 +2563,35 @@ class wn {
|
|
|
2047
2563
|
});
|
|
2048
2564
|
}
|
|
2049
2565
|
}
|
|
2050
|
-
function
|
|
2051
|
-
return new
|
|
2566
|
+
function zn(r, t) {
|
|
2567
|
+
return new Rn(r, t);
|
|
2052
2568
|
}
|
|
2053
|
-
function
|
|
2569
|
+
function Vn(r) {
|
|
2054
2570
|
return r.inverseOps || [];
|
|
2055
2571
|
}
|
|
2056
|
-
function
|
|
2572
|
+
function Wn(r) {
|
|
2057
2573
|
const t = [];
|
|
2058
2574
|
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
2575
|
valid: t.length === 0,
|
|
2060
2576
|
errors: t
|
|
2061
2577
|
};
|
|
2062
2578
|
}
|
|
2063
|
-
function
|
|
2579
|
+
function Yn(r) {
|
|
2064
2580
|
return r.op === "insert_text" || r.op === "delete_range" || r.op === "apply_mark";
|
|
2065
2581
|
}
|
|
2066
|
-
function
|
|
2582
|
+
function Kn(r) {
|
|
2067
2583
|
return r.op === "insert_block_before" || r.op === "insert_block_after" || r.op === "delete_block" || r.op === "set_attrs";
|
|
2068
2584
|
}
|
|
2069
|
-
function
|
|
2585
|
+
function jn(r) {
|
|
2070
2586
|
return r.op.startsWith("table_");
|
|
2071
2587
|
}
|
|
2072
|
-
function
|
|
2588
|
+
function Xn(r) {
|
|
2073
2589
|
return r.op === "update_selection";
|
|
2074
2590
|
}
|
|
2075
|
-
function
|
|
2076
|
-
return r.op === "insert_text" && t.op === "insert_text" ?
|
|
2591
|
+
function Cn(r, t, e) {
|
|
2592
|
+
return r.op === "insert_text" && t.op === "insert_text" ? wn(r, t, e) : r.op === "insert_text" && t.op === "delete_range" ? Mn(r, t) : r.op === "delete_range" && t.op === "insert_text" ? vn(r, t) : r.op === "delete_range" && t.op === "delete_range" ? Pn(r, t) : r;
|
|
2077
2593
|
}
|
|
2078
|
-
function
|
|
2594
|
+
function wn(r, t, e) {
|
|
2079
2595
|
if (r.target.blockId === t.target.blockId) {
|
|
2080
2596
|
if (t.target.offset <= r.target.offset)
|
|
2081
2597
|
return {
|
|
@@ -2096,7 +2612,7 @@ function On(r, t, e) {
|
|
|
2096
2612
|
}
|
|
2097
2613
|
return r;
|
|
2098
2614
|
}
|
|
2099
|
-
function
|
|
2615
|
+
function Mn(r, t) {
|
|
2100
2616
|
if (r.target.blockId === t.range.start.blockId && r.target.offset >= t.range.start.offset) {
|
|
2101
2617
|
const e = t.range.end.offset - t.range.start.offset;
|
|
2102
2618
|
return {
|
|
@@ -2124,82 +2640,154 @@ function vn(r, t) {
|
|
|
2124
2640
|
}
|
|
2125
2641
|
} : r;
|
|
2126
2642
|
}
|
|
2127
|
-
function
|
|
2643
|
+
function Pn(r, t, e) {
|
|
2128
2644
|
if (r.range.start.blockId === t.range.start.blockId) {
|
|
2129
|
-
const
|
|
2130
|
-
if (
|
|
2131
|
-
const h =
|
|
2645
|
+
const n = r.range.start.offset, o = r.range.end.offset, s = t.range.start.offset, l = t.range.end.offset;
|
|
2646
|
+
if (l <= n) {
|
|
2647
|
+
const h = l - s;
|
|
2132
2648
|
return {
|
|
2133
2649
|
...r,
|
|
2134
2650
|
range: {
|
|
2135
|
-
start: { ...r.range.start, offset:
|
|
2651
|
+
start: { ...r.range.start, offset: n - h },
|
|
2136
2652
|
end: { ...r.range.end, offset: o - h }
|
|
2137
2653
|
}
|
|
2138
2654
|
};
|
|
2139
2655
|
}
|
|
2140
|
-
if (
|
|
2656
|
+
if (s <= n && l >= o)
|
|
2141
2657
|
return {
|
|
2142
2658
|
...r,
|
|
2143
2659
|
range: {
|
|
2144
|
-
start: { ...r.range.start, offset:
|
|
2145
|
-
end: { ...r.range.end, offset:
|
|
2660
|
+
start: { ...r.range.start, offset: s },
|
|
2661
|
+
end: { ...r.range.end, offset: s }
|
|
2146
2662
|
}
|
|
2147
2663
|
};
|
|
2148
2664
|
}
|
|
2149
2665
|
return r;
|
|
2150
2666
|
}
|
|
2151
|
-
function
|
|
2152
|
-
const
|
|
2153
|
-
let
|
|
2154
|
-
for (const
|
|
2155
|
-
|
|
2156
|
-
return
|
|
2667
|
+
function qn(r, t, e = "left") {
|
|
2668
|
+
const n = r.ops.map((o) => {
|
|
2669
|
+
let s = o;
|
|
2670
|
+
for (const l of t.ops)
|
|
2671
|
+
s = Cn(s, l, e);
|
|
2672
|
+
return s;
|
|
2157
2673
|
});
|
|
2158
2674
|
return {
|
|
2159
2675
|
...r,
|
|
2160
|
-
ops:
|
|
2676
|
+
ops: n,
|
|
2161
2677
|
baseVersion: t.baseVersion + 1
|
|
2162
2678
|
// Update to new base
|
|
2163
2679
|
};
|
|
2164
2680
|
}
|
|
2165
|
-
function
|
|
2681
|
+
function Zn(r, t) {
|
|
2166
2682
|
return {
|
|
2167
2683
|
...t,
|
|
2168
2684
|
ops: [...r.ops, ...t.ops],
|
|
2169
2685
|
baseVersion: r.baseVersion
|
|
2170
2686
|
};
|
|
2171
2687
|
}
|
|
2172
|
-
function
|
|
2688
|
+
function Jn(r, t) {
|
|
2173
2689
|
return t.baseVersion === r.baseVersion || t.clientId === r.clientId;
|
|
2174
2690
|
}
|
|
2175
|
-
|
|
2176
|
-
|
|
2691
|
+
const Qn = {
|
|
2692
|
+
/**
|
|
2693
|
+
* Check if selection is collapsed (cursor)
|
|
2694
|
+
*/
|
|
2695
|
+
isCollapsed(r) {
|
|
2696
|
+
return r.anchor.blockId === r.head.blockId && r.anchor.offset === r.head.offset;
|
|
2697
|
+
},
|
|
2698
|
+
/**
|
|
2699
|
+
* Check if selection spans multiple blocks
|
|
2700
|
+
*/
|
|
2701
|
+
isMultiBlock(r) {
|
|
2702
|
+
return r.anchor.blockId !== r.head.blockId;
|
|
2703
|
+
},
|
|
2704
|
+
/**
|
|
2705
|
+
* Get the direction of selection (forward/backward)
|
|
2706
|
+
*/
|
|
2707
|
+
getDirection(r) {
|
|
2708
|
+
return this.isCollapsed(r) ? "none" : r.anchor.blockId === r.head.blockId ? r.anchor.offset < r.head.offset ? "forward" : "backward" : "forward";
|
|
2709
|
+
},
|
|
2710
|
+
/**
|
|
2711
|
+
* Create a collapsed selection at a position
|
|
2712
|
+
*/
|
|
2713
|
+
createCollapsed(r) {
|
|
2714
|
+
return {
|
|
2715
|
+
anchor: r,
|
|
2716
|
+
head: r
|
|
2717
|
+
};
|
|
2718
|
+
},
|
|
2719
|
+
/**
|
|
2720
|
+
* Create a selection range
|
|
2721
|
+
*/
|
|
2722
|
+
createRange(r, t) {
|
|
2723
|
+
return {
|
|
2724
|
+
anchor: r,
|
|
2725
|
+
head: t
|
|
2726
|
+
};
|
|
2727
|
+
}
|
|
2728
|
+
}, ti = {
|
|
2729
|
+
/**
|
|
2730
|
+
* Check if a node is a text node
|
|
2731
|
+
*/
|
|
2732
|
+
isTextNode(r) {
|
|
2733
|
+
return "text" in r && r.type === "text";
|
|
2734
|
+
},
|
|
2735
|
+
/**
|
|
2736
|
+
* Check if a node is a block node
|
|
2737
|
+
*/
|
|
2738
|
+
isBlockNode(r) {
|
|
2739
|
+
return "id" in r && "type" in r;
|
|
2740
|
+
},
|
|
2741
|
+
/**
|
|
2742
|
+
* Get all text content from a block
|
|
2743
|
+
*/
|
|
2744
|
+
getTextContent(r) {
|
|
2745
|
+
return r.children ? r.children.map((t) => this.isTextNode(t) ? t.text : this.isBlockNode(t) ? this.getTextContent(t) : "").join("") : "";
|
|
2746
|
+
},
|
|
2747
|
+
/**
|
|
2748
|
+
* Check if block is empty
|
|
2749
|
+
*/
|
|
2750
|
+
isEmpty(r) {
|
|
2751
|
+
return !r.children || r.children.length === 0 ? !0 : this.getTextContent(r).trim() === "";
|
|
2752
|
+
}
|
|
2753
|
+
};
|
|
2754
|
+
function ei(r, t) {
|
|
2755
|
+
const e = new ke();
|
|
2177
2756
|
return r.appendChild(e), e;
|
|
2178
2757
|
}
|
|
2179
|
-
const
|
|
2758
|
+
const ni = "0.0.1";
|
|
2180
2759
|
export {
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2760
|
+
Fn as ARIA_ANNOUNCEMENT_DELAY,
|
|
2761
|
+
$n as BasePlugin,
|
|
2762
|
+
Hn as DEFAULT_MAX_HISTORY_DEPTH,
|
|
2763
|
+
Gn as DEFAULT_MIN_HEIGHT,
|
|
2764
|
+
Rn as DeltaBuilder,
|
|
2765
|
+
Un as EDITOR_READY_TIMEOUT,
|
|
2766
|
+
ot as EditorState,
|
|
2767
|
+
R as ErrorCodes,
|
|
2768
|
+
Je as NodeFactory,
|
|
2769
|
+
ke as NotectlEditor,
|
|
2770
|
+
O as NotectlError,
|
|
2771
|
+
tn as PluginManager,
|
|
2772
|
+
Ze as Schema,
|
|
2773
|
+
ni as VERSION,
|
|
2774
|
+
Bn as ValidationConstraints,
|
|
2775
|
+
ti as blockHelpers,
|
|
2776
|
+
Jn as canCompose,
|
|
2777
|
+
Zn as composeDelta,
|
|
2778
|
+
Vn as computeInverse,
|
|
2192
2779
|
be as createDefaultSchema,
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2780
|
+
zn as createDelta,
|
|
2781
|
+
ei as createEditor,
|
|
2782
|
+
Qe as createNodeFactory,
|
|
2783
|
+
w as generateBlockId,
|
|
2784
|
+
Kn as isBlockOperation,
|
|
2785
|
+
Xn as isSelectionOperation,
|
|
2786
|
+
jn as isTableOperation,
|
|
2787
|
+
Yn as isTextOperation,
|
|
2788
|
+
Qn as selectionHelpers,
|
|
2789
|
+
qn as transformDelta,
|
|
2790
|
+
Cn as transformOperation,
|
|
2791
|
+
Wn as validateDelta
|
|
2204
2792
|
};
|
|
2205
2793
|
//# sourceMappingURL=notectl-core.js.map
|