@portabletext/editor 6.4.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-dts/behavior.types.action.d.ts +104 -158
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +90 -89
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.js +1015 -572
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import { c } from "react/compiler-runtime";
|
|
|
3
3
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
4
4
|
import React, { useRef, useEffect, useLayoutEffect, useState, createContext, useContext, useReducer, useCallback, useMemo, memo, forwardRef, Component, startTransition } from "react";
|
|
5
5
|
import rawDebug from "debug";
|
|
6
|
-
import {
|
|
7
|
-
import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
|
|
6
|
+
import { isSpan, isTextBlock, compileSchema } from "@portabletext/schema";
|
|
8
7
|
import { defineSchema } from "@portabletext/schema";
|
|
8
|
+
import { isTypedObject, isListBlock, getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isKeyedSegment, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject, isEqualPathSegments } from "./_chunks-es/util.slice-blocks.js";
|
|
9
9
|
import scrollIntoView from "scroll-into-view-if-needed";
|
|
10
10
|
import { createKeyboardShortcut, code, underline, italic as italic$1, bold as bold$1, undo as undo$1, redo as redo$1 } from "@portabletext/keyboard-shortcuts";
|
|
11
11
|
import { ResizeObserver } from "@juggle/resize-observer";
|
|
@@ -50,20 +50,19 @@ function safeParse(text) {
|
|
|
50
50
|
return console.error(error), "JSON.parse failed";
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return isObject(value) && value._type === schema.block.name;
|
|
56
|
-
}
|
|
57
|
-
function isText(value, schema) {
|
|
58
|
-
return isObject(value) && value._type === schema.span.name;
|
|
53
|
+
function isObjectNode(context, node2) {
|
|
54
|
+
return isTypedObject(node2) && node2._type !== context.schema.block.name && node2._type !== context.schema.span.name;
|
|
59
55
|
}
|
|
60
|
-
function
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
function isLeaf(node2, schema) {
|
|
57
|
+
return isSpan({
|
|
58
|
+
schema
|
|
59
|
+
}, node2) || isObjectNode({
|
|
60
|
+
schema
|
|
61
|
+
}, node2);
|
|
65
62
|
}
|
|
66
63
|
function getNodeIf(root, path2, schema) {
|
|
64
|
+
if (path2.length === 0)
|
|
65
|
+
return;
|
|
67
66
|
let node2 = root;
|
|
68
67
|
for (let i = 0; i < path2.length; i++) {
|
|
69
68
|
const p = path2[i];
|
|
@@ -84,30 +83,44 @@ function getNode(root, path2, schema) {
|
|
|
84
83
|
}
|
|
85
84
|
function getFirst(root, path2, schema) {
|
|
86
85
|
const p = path2.slice();
|
|
87
|
-
let n2
|
|
86
|
+
let n2;
|
|
87
|
+
if (path2.length === 0) {
|
|
88
|
+
if (isLeaf(root, schema) || root.children.length === 0)
|
|
89
|
+
throw new Error("Cannot get the first descendant of a leaf or empty root");
|
|
90
|
+
n2 = root.children[0], p.push(0);
|
|
91
|
+
} else
|
|
92
|
+
n2 = getNode(root, p, schema);
|
|
88
93
|
for (; n2 && !isLeaf(n2, schema); ) {
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
94
|
+
const ancestorChildren = n2.children;
|
|
95
|
+
if (ancestorChildren.length === 0)
|
|
91
96
|
break;
|
|
92
|
-
n2 =
|
|
97
|
+
n2 = ancestorChildren[0], p.push(0);
|
|
93
98
|
}
|
|
94
99
|
return [n2, p];
|
|
95
100
|
}
|
|
96
101
|
function getLast(root, path2, schema) {
|
|
97
102
|
const p = path2.slice();
|
|
98
|
-
let n2
|
|
103
|
+
let n2;
|
|
104
|
+
if (path2.length === 0) {
|
|
105
|
+
if (isLeaf(root, schema) || root.children.length === 0)
|
|
106
|
+
throw new Error("Cannot get the last descendant of a leaf or empty root");
|
|
107
|
+
const i = root.children.length - 1;
|
|
108
|
+
n2 = root.children[i], p.push(i);
|
|
109
|
+
} else
|
|
110
|
+
n2 = getNode(root, p, schema);
|
|
99
111
|
for (; n2 && !isLeaf(n2, schema); ) {
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
112
|
+
const ancestorChildren = n2.children;
|
|
113
|
+
if (ancestorChildren.length === 0)
|
|
102
114
|
break;
|
|
103
|
-
const i =
|
|
104
|
-
n2 =
|
|
115
|
+
const i = ancestorChildren.length - 1;
|
|
116
|
+
n2 = ancestorChildren[i], p.push(i);
|
|
105
117
|
}
|
|
106
118
|
return [n2, p];
|
|
107
119
|
}
|
|
108
120
|
function isPath(value) {
|
|
109
121
|
return Array.isArray(value) && (value.length === 0 || typeof value[0] == "number");
|
|
110
122
|
}
|
|
123
|
+
const isObject = (value) => typeof value == "object" && value !== null;
|
|
111
124
|
function isPoint(value) {
|
|
112
125
|
return isObject(value) && typeof value.offset == "number" && isPath(value.path);
|
|
113
126
|
}
|
|
@@ -165,12 +178,18 @@ function point(editor, at, options = {}) {
|
|
|
165
178
|
path2 = firstPath;
|
|
166
179
|
}
|
|
167
180
|
const node2 = getNode(editor, path2, editor.schema);
|
|
168
|
-
if (!
|
|
181
|
+
if (!isSpan({
|
|
182
|
+
schema: editor.schema
|
|
183
|
+
}, node2) && !isTextBlock({
|
|
184
|
+
schema: editor.schema
|
|
185
|
+
}, node2) && !isEditor(node2))
|
|
169
186
|
return {
|
|
170
187
|
path: path2,
|
|
171
188
|
offset: 0
|
|
172
189
|
};
|
|
173
|
-
if (!
|
|
190
|
+
if (!isSpan({
|
|
191
|
+
schema: editor.schema
|
|
192
|
+
}, node2))
|
|
174
193
|
throw new Error(`Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.`);
|
|
175
194
|
return {
|
|
176
195
|
path: path2,
|
|
@@ -191,26 +210,9 @@ function end(editor, at) {
|
|
|
191
210
|
function isAncestorPath(path2, another) {
|
|
192
211
|
return path2.length < another.length && comparePaths(path2, another) === 0;
|
|
193
212
|
}
|
|
194
|
-
function nextPath(path2) {
|
|
195
|
-
if (path2.length === 0)
|
|
196
|
-
throw new Error(`Cannot get the next path of a root path [${path2}], because it has no next index.`);
|
|
197
|
-
const last = path2[path2.length - 1];
|
|
198
|
-
return path2.slice(0, -1).concat(last + 1);
|
|
199
|
-
}
|
|
200
213
|
function pathEquals(path2, another) {
|
|
201
214
|
return path2.length === another.length && path2.every((n2, i) => n2 === another[i]);
|
|
202
215
|
}
|
|
203
|
-
function pathHasPrevious(path2) {
|
|
204
|
-
return path2[path2.length - 1] > 0;
|
|
205
|
-
}
|
|
206
|
-
function previousPath(path2) {
|
|
207
|
-
if (path2.length === 0)
|
|
208
|
-
throw new Error(`Cannot get the previous path of a root path [${path2}], because it has no previous index.`);
|
|
209
|
-
const last = path2[path2.length - 1];
|
|
210
|
-
if (last <= 0)
|
|
211
|
-
throw new Error(`Cannot get the previous path of a first child path [${path2}] because it would result in a negative index.`);
|
|
212
|
-
return path2.slice(0, -1).concat(last - 1);
|
|
213
|
-
}
|
|
214
216
|
const getCharacterDistance = (str, isRTL = !1) => {
|
|
215
217
|
const isLTR = !isRTL, codepoints = isRTL ? codepointsIteratorRTL(str) : str;
|
|
216
218
|
let left = CodepointType.None, right = CodepointType.None, distance = 0, gb11 = null, gb12Or13 = null;
|
|
@@ -312,23 +314,9 @@ const endingEmojiZWJ = new RegExp("\\p{ExtPict}[\\p{Gr_Ext}\\p{EMod}]*\\u200D$",
|
|
|
312
314
|
return match2 === null ? !1 : match2[0].length / 2 % 2 === 1;
|
|
313
315
|
};
|
|
314
316
|
function hasInlines(editor, element) {
|
|
315
|
-
return element.children.some((n2) =>
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
let node2 = root;
|
|
319
|
-
for (let i = 0; i < path2.length; i++) {
|
|
320
|
-
const p = path2[i];
|
|
321
|
-
if (isLeaf(node2, schema))
|
|
322
|
-
return !1;
|
|
323
|
-
const children = node2.children;
|
|
324
|
-
if (!children[p])
|
|
325
|
-
return !1;
|
|
326
|
-
node2 = children[p];
|
|
327
|
-
}
|
|
328
|
-
return !0;
|
|
329
|
-
}
|
|
330
|
-
function hasPath(editor, path2) {
|
|
331
|
-
return hasNode(editor, path2, editor.schema);
|
|
317
|
+
return element.children.some((n2) => isSpan({
|
|
318
|
+
schema: editor.schema
|
|
319
|
+
}, n2) ? !0 : editor.isInline(n2));
|
|
332
320
|
}
|
|
333
321
|
const Span = {
|
|
334
322
|
isSpan(value) {
|
|
@@ -341,11 +329,38 @@ function isAfterPath(path2, another) {
|
|
|
341
329
|
function isBeforePath(path2, another) {
|
|
342
330
|
return comparePaths(path2, another) === -1;
|
|
343
331
|
}
|
|
332
|
+
function nextPath(path2) {
|
|
333
|
+
if (path2.length === 0)
|
|
334
|
+
throw new Error(`Cannot get the next path of a root path [${path2}], because it has no next index.`);
|
|
335
|
+
const last = path2[path2.length - 1];
|
|
336
|
+
return path2.slice(0, -1).concat(last + 1);
|
|
337
|
+
}
|
|
344
338
|
function parentPath(path2) {
|
|
345
339
|
if (path2.length === 0)
|
|
346
340
|
throw new Error(`Cannot get the parent path of the root path [${path2}].`);
|
|
347
341
|
return path2.slice(0, -1);
|
|
348
342
|
}
|
|
343
|
+
function previousPath(path2) {
|
|
344
|
+
if (path2.length === 0)
|
|
345
|
+
throw new Error(`Cannot get the previous path of a root path [${path2}], because it has no previous index.`);
|
|
346
|
+
const last = path2[path2.length - 1];
|
|
347
|
+
if (last <= 0)
|
|
348
|
+
throw new Error(`Cannot get the previous path of a first child path [${path2}] because it would result in a negative index.`);
|
|
349
|
+
return path2.slice(0, -1).concat(last - 1);
|
|
350
|
+
}
|
|
351
|
+
function hasNode(root, path2, schema) {
|
|
352
|
+
let node2 = root;
|
|
353
|
+
for (let i = 0; i < path2.length; i++) {
|
|
354
|
+
const p = path2[i];
|
|
355
|
+
if (isLeaf(node2, schema))
|
|
356
|
+
return !1;
|
|
357
|
+
const children = node2.children;
|
|
358
|
+
if (!children[p])
|
|
359
|
+
return !1;
|
|
360
|
+
node2 = children[p];
|
|
361
|
+
}
|
|
362
|
+
return !0;
|
|
363
|
+
}
|
|
349
364
|
function* getNodes(root, schema, options = {}) {
|
|
350
365
|
const {
|
|
351
366
|
pass,
|
|
@@ -376,7 +391,7 @@ function* getNodes(root, schema, options = {}) {
|
|
|
376
391
|
p = previousPath(p), n2 = getNode(root, p, schema);
|
|
377
392
|
continue;
|
|
378
393
|
}
|
|
379
|
-
p = parentPath(p), n2 = getNode(root, p, schema), visited.add(n2);
|
|
394
|
+
p = parentPath(p), n2 = p.length === 0 ? root : getNode(root, p, schema), visited.add(n2);
|
|
380
395
|
}
|
|
381
396
|
}
|
|
382
397
|
function commonPath(path2, another) {
|
|
@@ -416,11 +431,9 @@ function path(editor, at, options = {}) {
|
|
|
416
431
|
function* nodes(editor, options = {}) {
|
|
417
432
|
const {
|
|
418
433
|
at = editor.selection,
|
|
419
|
-
mode
|
|
420
|
-
universal = !1,
|
|
434
|
+
mode,
|
|
421
435
|
reverse = !1,
|
|
422
|
-
|
|
423
|
-
pass
|
|
436
|
+
includeObjectNodes = !1
|
|
424
437
|
} = options;
|
|
425
438
|
let {
|
|
426
439
|
match: match2
|
|
@@ -442,16 +455,17 @@ function* nodes(editor, options = {}) {
|
|
|
442
455
|
reverse,
|
|
443
456
|
from,
|
|
444
457
|
to,
|
|
445
|
-
pass: ([node2
|
|
446
|
-
|
|
458
|
+
pass: ([node2]) => isTextBlock({
|
|
459
|
+
schema: editor.schema
|
|
460
|
+
}, node2) ? !!(!includeObjectNodes && editor.isElementReadOnly(node2)) : !1
|
|
461
|
+
});
|
|
447
462
|
let hit;
|
|
448
463
|
for (const [node2, path2] of nodeEntries) {
|
|
449
464
|
const isLower = hit && comparePaths(path2, hit[1]) === 0;
|
|
450
|
-
if (mode === "highest" && isLower)
|
|
465
|
+
if (mode === "highest" && isLower || !match2(node2, path2))
|
|
451
466
|
continue;
|
|
452
|
-
if (!
|
|
453
|
-
|
|
454
|
-
return;
|
|
467
|
+
if (!mode) {
|
|
468
|
+
yield [node2, path2], hit = [node2, path2];
|
|
455
469
|
continue;
|
|
456
470
|
}
|
|
457
471
|
if (mode === "lowest" && isLower) {
|
|
@@ -459,9 +473,9 @@ function* nodes(editor, options = {}) {
|
|
|
459
473
|
continue;
|
|
460
474
|
}
|
|
461
475
|
const emit2 = mode === "lowest" ? hit : [node2, path2];
|
|
462
|
-
emit2 && (
|
|
476
|
+
emit2 && (yield emit2), hit = [node2, path2];
|
|
463
477
|
}
|
|
464
|
-
mode === "lowest" && hit && (
|
|
478
|
+
mode === "lowest" && hit && (yield hit);
|
|
465
479
|
}
|
|
466
480
|
function start(editor, at) {
|
|
467
481
|
return point(editor, at, {
|
|
@@ -479,13 +493,15 @@ function range(editor, at, to) {
|
|
|
479
493
|
}
|
|
480
494
|
function string(editor, at, options = {}) {
|
|
481
495
|
const {
|
|
482
|
-
|
|
496
|
+
includeObjectNodes = !1
|
|
483
497
|
} = options, editorRange = range(editor, at), [start2, end2] = rangeEdges(editorRange);
|
|
484
498
|
let text = "";
|
|
485
499
|
for (const [node2, path2] of nodes(editor, {
|
|
486
500
|
at: editorRange,
|
|
487
|
-
match: (n2) =>
|
|
488
|
-
|
|
501
|
+
match: (n2) => isSpan({
|
|
502
|
+
schema: editor.schema
|
|
503
|
+
}, n2),
|
|
504
|
+
includeObjectNodes
|
|
489
505
|
})) {
|
|
490
506
|
let t = node2.text;
|
|
491
507
|
pathEquals(path2, end2.path) && (t = t.slice(0, end2.offset)), pathEquals(path2, start2.path) && (t = t.slice(start2.offset)), text += t;
|
|
@@ -497,34 +513,22 @@ function* positions(editor, options = {}) {
|
|
|
497
513
|
at = editor.selection,
|
|
498
514
|
unit = "offset",
|
|
499
515
|
reverse = !1,
|
|
500
|
-
|
|
516
|
+
includeObjectNodes = !1
|
|
501
517
|
} = options;
|
|
502
518
|
if (!at)
|
|
503
519
|
return;
|
|
504
520
|
const editorRange = range(editor, at), [start$1, end$1] = rangeEdges(editorRange), first = reverse ? end$1 : start$1;
|
|
505
521
|
let isNewBlock = !1, blockText = "", distance = 0, leafTextRemaining = 0, leafTextOffset = 0;
|
|
506
|
-
const skippedPaths = [];
|
|
507
522
|
for (const [node2, nodePath] of nodes(editor, {
|
|
508
523
|
at,
|
|
509
524
|
reverse,
|
|
510
|
-
|
|
525
|
+
includeObjectNodes
|
|
511
526
|
})) {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
if (!editor.isSelectable(node2))
|
|
518
|
-
if (skippedPaths.push(nodePath), reverse) {
|
|
519
|
-
pathHasPrevious(nodePath) && (yield* maybeYield(end(editor, previousPath(nodePath))));
|
|
520
|
-
continue;
|
|
521
|
-
} else {
|
|
522
|
-
const next2 = nextPath(nodePath);
|
|
523
|
-
hasPath(editor, next2) && (yield* maybeYield(start(editor, next2)));
|
|
524
|
-
continue;
|
|
525
|
-
}
|
|
526
|
-
if (!voids && editor.isElementReadOnly(node2)) {
|
|
527
|
-
yield* maybeYield(start(editor, nodePath));
|
|
527
|
+
if (isTextBlock({
|
|
528
|
+
schema: editor.schema
|
|
529
|
+
}, node2)) {
|
|
530
|
+
if (!includeObjectNodes && editor.isElementReadOnly(node2)) {
|
|
531
|
+
yield start(editor, nodePath);
|
|
528
532
|
continue;
|
|
529
533
|
}
|
|
530
534
|
if (editor.isInline(node2))
|
|
@@ -535,30 +539,38 @@ function* positions(editor, options = {}) {
|
|
|
535
539
|
anchor: s,
|
|
536
540
|
focus: e
|
|
537
541
|
}, {
|
|
538
|
-
|
|
542
|
+
includeObjectNodes
|
|
539
543
|
}), isNewBlock = !0;
|
|
540
544
|
}
|
|
541
545
|
}
|
|
542
|
-
if (
|
|
543
|
-
|
|
546
|
+
if (isObjectNode({
|
|
547
|
+
schema: editor.schema
|
|
548
|
+
}, node2)) {
|
|
549
|
+
yield {
|
|
544
550
|
path: nodePath,
|
|
545
551
|
offset: 0
|
|
546
|
-
}
|
|
552
|
+
};
|
|
547
553
|
continue;
|
|
548
554
|
}
|
|
549
|
-
if (!isEditor(node2) && !
|
|
550
|
-
|
|
555
|
+
if (!isEditor(node2) && !isTextBlock({
|
|
556
|
+
schema: editor.schema
|
|
557
|
+
}, node2) && !isSpan({
|
|
558
|
+
schema: editor.schema
|
|
559
|
+
}, node2)) {
|
|
560
|
+
yield {
|
|
551
561
|
path: nodePath,
|
|
552
562
|
offset: 0
|
|
553
|
-
}
|
|
563
|
+
};
|
|
554
564
|
continue;
|
|
555
565
|
}
|
|
556
|
-
if (
|
|
566
|
+
if (isSpan({
|
|
567
|
+
schema: editor.schema
|
|
568
|
+
}, node2)) {
|
|
557
569
|
const isFirst = pathEquals(nodePath, first.path);
|
|
558
|
-
for (isFirst ? (leafTextRemaining = reverse ? first.offset : node2.text.length - first.offset, leafTextOffset = first.offset) : (leafTextRemaining = node2.text.length, leafTextOffset = reverse ? leafTextRemaining : 0), (isFirst || isNewBlock || unit === "offset") && (yield
|
|
570
|
+
for (isFirst ? (leafTextRemaining = reverse ? first.offset : node2.text.length - first.offset, leafTextOffset = first.offset) : (leafTextRemaining = node2.text.length, leafTextOffset = reverse ? leafTextRemaining : 0), (isFirst || isNewBlock || unit === "offset") && (yield {
|
|
559
571
|
path: nodePath,
|
|
560
572
|
offset: leafTextOffset
|
|
561
|
-
}
|
|
573
|
+
}, isNewBlock = !1); ; ) {
|
|
562
574
|
if (distance === 0) {
|
|
563
575
|
if (blockText === "")
|
|
564
576
|
break;
|
|
@@ -568,10 +580,10 @@ function* positions(editor, options = {}) {
|
|
|
568
580
|
distance = -leafTextRemaining;
|
|
569
581
|
break;
|
|
570
582
|
}
|
|
571
|
-
distance = 0, yield
|
|
583
|
+
distance = 0, yield {
|
|
572
584
|
path: nodePath,
|
|
573
585
|
offset: leafTextOffset
|
|
574
|
-
}
|
|
586
|
+
};
|
|
575
587
|
}
|
|
576
588
|
}
|
|
577
589
|
}
|
|
@@ -629,8 +641,13 @@ function pathLevels(path2, options = {}) {
|
|
|
629
641
|
return reverse && list.reverse(), list;
|
|
630
642
|
}
|
|
631
643
|
function* getLevels(root, path2, schema, options = {}) {
|
|
632
|
-
for (const p of pathLevels(path2, options))
|
|
644
|
+
for (const p of pathLevels(path2, options)) {
|
|
645
|
+
if (p.length === 0) {
|
|
646
|
+
yield [root, p];
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
633
649
|
yield [getNode(root, p, schema), p];
|
|
650
|
+
}
|
|
634
651
|
}
|
|
635
652
|
function* levels(editor, options = {}) {
|
|
636
653
|
const {
|
|
@@ -647,7 +664,7 @@ function* levels(editor, options = {}) {
|
|
|
647
664
|
match2(n2, p) && levels2.push([n2, p]);
|
|
648
665
|
reverse && levels2.reverse(), yield* levels2;
|
|
649
666
|
}
|
|
650
|
-
function above(editor, options
|
|
667
|
+
function above(editor, options) {
|
|
651
668
|
const {
|
|
652
669
|
mode = "lowest",
|
|
653
670
|
at = editor.selection,
|
|
@@ -668,22 +685,32 @@ function above(editor, options = {}) {
|
|
|
668
685
|
});
|
|
669
686
|
return firstMatch;
|
|
670
687
|
}
|
|
671
|
-
function
|
|
688
|
+
function getObjectNode(editor, options = {}) {
|
|
672
689
|
const {
|
|
673
690
|
at = editor.selection
|
|
674
691
|
} = options;
|
|
675
692
|
if (!at)
|
|
676
693
|
return;
|
|
677
694
|
const nodePath = path(editor, at), node2 = getNode(editor, nodePath, editor.schema);
|
|
678
|
-
return
|
|
695
|
+
return isObjectNode({
|
|
696
|
+
schema: editor.schema
|
|
697
|
+
}, node2) ? [node2, nodePath] : above(editor, {
|
|
679
698
|
...options,
|
|
680
|
-
match: (n2) =>
|
|
699
|
+
match: (n2) => isObjectNode({
|
|
700
|
+
schema: editor.schema
|
|
701
|
+
}, n2)
|
|
681
702
|
});
|
|
682
703
|
}
|
|
704
|
+
function hasPath(editor, path2) {
|
|
705
|
+
return hasNode(editor, path2, editor.schema);
|
|
706
|
+
}
|
|
683
707
|
function node(editor, at, options = {}) {
|
|
684
708
|
const nodePath = path(editor, at, options);
|
|
685
709
|
return [getNode(editor, nodePath, editor.schema), nodePath];
|
|
686
710
|
}
|
|
711
|
+
function pathHasPrevious(path2) {
|
|
712
|
+
return path2[path2.length - 1] > 0;
|
|
713
|
+
}
|
|
687
714
|
function pointEquals(point2, another) {
|
|
688
715
|
return point2.offset === another.offset && pathEquals(point2.path, another.path);
|
|
689
716
|
}
|
|
@@ -694,19 +721,18 @@ function isCollapsedRange(range2) {
|
|
|
694
721
|
} = range2;
|
|
695
722
|
return pointEquals(anchor, focus);
|
|
696
723
|
}
|
|
697
|
-
function isBlock(editor, value) {
|
|
698
|
-
return !editor.isInline(value);
|
|
699
|
-
}
|
|
700
724
|
function unhangRange(editor, range2, options = {}) {
|
|
701
725
|
const {
|
|
702
|
-
|
|
726
|
+
includeObjectNodes = !1
|
|
703
727
|
} = options;
|
|
704
728
|
let [start$1, end2] = rangeEdges(range2);
|
|
705
729
|
if (start$1.offset !== 0 || end2.offset !== 0 || isCollapsedRange(range2) || pathHasPrevious(end2.path))
|
|
706
730
|
return range2;
|
|
707
731
|
const endBlock = above(editor, {
|
|
708
732
|
at: end2,
|
|
709
|
-
match: (n2) =>
|
|
733
|
+
match: (n2) => isTextBlock({
|
|
734
|
+
schema: editor.schema
|
|
735
|
+
}, n2)
|
|
710
736
|
}), blockPath = endBlock ? endBlock[1] : [], before2 = {
|
|
711
737
|
anchor: start(editor, start$1),
|
|
712
738
|
focus: end2
|
|
@@ -714,9 +740,11 @@ function unhangRange(editor, range2, options = {}) {
|
|
|
714
740
|
let skip = !0;
|
|
715
741
|
for (const [node2, path2] of nodes(editor, {
|
|
716
742
|
at: before2,
|
|
717
|
-
match: (n2) =>
|
|
743
|
+
match: (n2) => isSpan({
|
|
744
|
+
schema: editor.schema
|
|
745
|
+
}, n2),
|
|
718
746
|
reverse: !0,
|
|
719
|
-
|
|
747
|
+
includeObjectNodes
|
|
720
748
|
})) {
|
|
721
749
|
if (skip) {
|
|
722
750
|
skip = !1;
|
|
@@ -875,7 +903,9 @@ const DOMEditor = {
|
|
|
875
903
|
if (x == null || y == null)
|
|
876
904
|
throw new Error(`Cannot resolve a Slate range from a DOM event: ${event}`);
|
|
877
905
|
const node2 = DOMEditor.toSlateNode(editor, event.target), path2 = DOMEditor.findPath(editor, node2);
|
|
878
|
-
if (
|
|
906
|
+
if (isObjectNode({
|
|
907
|
+
schema: editor.schema
|
|
908
|
+
}, node2)) {
|
|
879
909
|
const rect = target.getBoundingClientRect(), isPrev = path2.length > 1 ? x - rect.left < rect.left + rect.width - x : y - rect.top < rect.top + rect.height - y, edge = point(editor, path2, {
|
|
880
910
|
edge: isPrev ? "start" : "end"
|
|
881
911
|
}), point$1 = isPrev ? before(editor, edge) : after(editor, edge);
|
|
@@ -985,7 +1015,9 @@ const DOMEditor = {
|
|
|
985
1015
|
if (editor.readOnly)
|
|
986
1016
|
return !1;
|
|
987
1017
|
const slateNode = DOMEditor.hasTarget(editor, target) && DOMEditor.toSlateNode(editor, target);
|
|
988
|
-
return !!slateNode &&
|
|
1018
|
+
return !!slateNode && isObjectNode({
|
|
1019
|
+
schema: editor.schema
|
|
1020
|
+
}, slateNode);
|
|
989
1021
|
},
|
|
990
1022
|
toDOMNode: (editor, node2) => {
|
|
991
1023
|
const domNode = isEditor(node2) ? editor.domElement : editor.keyToElement?.get(DOMEditor.findKey(editor, node2));
|
|
@@ -996,7 +1028,9 @@ const DOMEditor = {
|
|
|
996
1028
|
toDOMPoint: (editor, point2) => {
|
|
997
1029
|
const [node$1] = node(editor, point2.path), el = DOMEditor.toDOMNode(editor, node$1);
|
|
998
1030
|
let domPoint;
|
|
999
|
-
if (
|
|
1031
|
+
if (isObjectNode({
|
|
1032
|
+
schema: editor.schema
|
|
1033
|
+
}, node$1)) {
|
|
1000
1034
|
const spacer = el.querySelector("[data-slate-zero-width]");
|
|
1001
1035
|
if (spacer) {
|
|
1002
1036
|
const domText = spacer.childNodes[0];
|
|
@@ -1011,7 +1045,7 @@ const DOMEditor = {
|
|
|
1011
1045
|
}
|
|
1012
1046
|
return [el, 0];
|
|
1013
1047
|
}
|
|
1014
|
-
|
|
1048
|
+
getObjectNode(editor, {
|
|
1015
1049
|
at: point2
|
|
1016
1050
|
}) && (point2 = {
|
|
1017
1051
|
path: point2.path,
|
|
@@ -1152,7 +1186,9 @@ const DOMEditor = {
|
|
|
1152
1186
|
const childEl = nearestNode.childNodes[nearestOffset];
|
|
1153
1187
|
if (childEl instanceof HTMLElement && DOMEditor.hasDOMNode(editor, childEl)) {
|
|
1154
1188
|
const slateNode2 = DOMEditor.toSlateNode(editor, childEl);
|
|
1155
|
-
if (
|
|
1189
|
+
if (isObjectNode({
|
|
1190
|
+
schema: editor.schema
|
|
1191
|
+
}, slateNode2))
|
|
1156
1192
|
try {
|
|
1157
1193
|
return {
|
|
1158
1194
|
path: DOMEditor.findPath(editor, slateNode2),
|
|
@@ -1165,7 +1201,9 @@ const DOMEditor = {
|
|
|
1165
1201
|
const elementNode = parentNode.closest('[data-slate-node="element"]') ?? (parentNode.hasAttribute("data-slate-node") ? parentNode : null);
|
|
1166
1202
|
if (elementNode && DOMEditor.hasDOMNode(editor, elementNode)) {
|
|
1167
1203
|
const slateNode2 = DOMEditor.toSlateNode(editor, elementNode);
|
|
1168
|
-
if (
|
|
1204
|
+
if (isObjectNode({
|
|
1205
|
+
schema: editor.schema
|
|
1206
|
+
}, slateNode2))
|
|
1169
1207
|
try {
|
|
1170
1208
|
return {
|
|
1171
1209
|
path: DOMEditor.findPath(editor, slateNode2),
|
|
@@ -1193,7 +1231,9 @@ const DOMEditor = {
|
|
|
1193
1231
|
const parentPath2 = path2.slice(0, -1);
|
|
1194
1232
|
try {
|
|
1195
1233
|
const parentSlateNode = getNode(editor, parentPath2, editor.schema);
|
|
1196
|
-
if (
|
|
1234
|
+
if (isObjectNode({
|
|
1235
|
+
schema: editor.schema
|
|
1236
|
+
}, parentSlateNode))
|
|
1197
1237
|
return {
|
|
1198
1238
|
path: parentPath2,
|
|
1199
1239
|
offset: 0
|
|
@@ -1255,21 +1295,20 @@ const DOMEditor = {
|
|
|
1255
1295
|
anchor,
|
|
1256
1296
|
focus
|
|
1257
1297
|
};
|
|
1258
|
-
return isExpandedRange(range2) && isForwardRange(range2) && isDOMElement(focusNode) &&
|
|
1298
|
+
return isExpandedRange(range2) && isForwardRange(range2) && isDOMElement(focusNode) && getObjectNode(editor, {
|
|
1259
1299
|
at: range2.focus,
|
|
1260
1300
|
mode: "highest"
|
|
1261
1301
|
}) && (range2 = unhangRange(editor, range2, {
|
|
1262
|
-
|
|
1302
|
+
includeObjectNodes: !0
|
|
1263
1303
|
})), range2;
|
|
1264
1304
|
}
|
|
1265
1305
|
};
|
|
1266
1306
|
function getChild(root, index, schema) {
|
|
1267
|
-
if (
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
return c2;
|
|
1307
|
+
if (isEditor(root) || isTextBlock({
|
|
1308
|
+
schema
|
|
1309
|
+
}, root))
|
|
1310
|
+
return root.children[index];
|
|
1311
|
+
throw new Error(`Cannot get the child of a leaf node: ${safeStringify(root)}`);
|
|
1273
1312
|
}
|
|
1274
1313
|
function getFocusBlock({
|
|
1275
1314
|
editor
|
|
@@ -1293,10 +1332,14 @@ function getFocusSpan({
|
|
|
1293
1332
|
});
|
|
1294
1333
|
if (!focusBlock)
|
|
1295
1334
|
return [void 0, void 0];
|
|
1296
|
-
if (!
|
|
1335
|
+
if (!isTextBlock({
|
|
1336
|
+
schema: editor.schema
|
|
1337
|
+
}, focusBlock))
|
|
1297
1338
|
return [void 0, void 0];
|
|
1298
1339
|
const [node$1, path2] = node(editor, editor.selection.focus.path.slice(0, 2));
|
|
1299
|
-
if (
|
|
1340
|
+
if (isSpan({
|
|
1341
|
+
schema: editor.schema
|
|
1342
|
+
}, node$1))
|
|
1300
1343
|
return [node$1, path2];
|
|
1301
1344
|
} catch {
|
|
1302
1345
|
return [void 0, void 0];
|
|
@@ -1378,7 +1421,6 @@ function getNodeBlock({
|
|
|
1378
1421
|
if (isEditor(node2))
|
|
1379
1422
|
return;
|
|
1380
1423
|
if (isBlockElement({
|
|
1381
|
-
editor,
|
|
1382
1424
|
schema
|
|
1383
1425
|
}, node2))
|
|
1384
1426
|
return elementToBlock({
|
|
@@ -1388,11 +1430,12 @@ function getNodeBlock({
|
|
|
1388
1430
|
mode: "highest",
|
|
1389
1431
|
at: [],
|
|
1390
1432
|
match: (n2) => isBlockElement({
|
|
1391
|
-
editor,
|
|
1392
1433
|
schema
|
|
1393
1434
|
}, n2) && n2.children.some((child) => child._key === node2._key)
|
|
1394
1435
|
})).at(0)?.at(0);
|
|
1395
|
-
return
|
|
1436
|
+
return isTextBlock({
|
|
1437
|
+
schema: editor.schema
|
|
1438
|
+
}, parent2) ? elementToBlock({
|
|
1396
1439
|
element: parent2
|
|
1397
1440
|
}) : void 0;
|
|
1398
1441
|
}
|
|
@@ -1402,10 +1445,11 @@ function elementToBlock({
|
|
|
1402
1445
|
return element;
|
|
1403
1446
|
}
|
|
1404
1447
|
function isBlockElement({
|
|
1405
|
-
editor,
|
|
1406
1448
|
schema
|
|
1407
1449
|
}, node2) {
|
|
1408
|
-
return
|
|
1450
|
+
return isTextBlock({
|
|
1451
|
+
schema
|
|
1452
|
+
}, node2);
|
|
1409
1453
|
}
|
|
1410
1454
|
function isListItemActive({
|
|
1411
1455
|
editor,
|
|
@@ -1415,9 +1459,13 @@ function isListItemActive({
|
|
|
1415
1459
|
return !1;
|
|
1416
1460
|
const selectedBlocks = [...nodes(editor, {
|
|
1417
1461
|
at: editor.selection,
|
|
1418
|
-
match: (node2) =>
|
|
1462
|
+
match: (node2) => isTextBlock({
|
|
1463
|
+
schema: editor.schema
|
|
1464
|
+
}, node2)
|
|
1419
1465
|
})];
|
|
1420
|
-
return selectedBlocks.length > 0 ? selectedBlocks.every(([node2]) =>
|
|
1466
|
+
return selectedBlocks.length > 0 ? selectedBlocks.every(([node2]) => isListBlock({
|
|
1467
|
+
schema: editor.schema
|
|
1468
|
+
}, node2) && node2.listItem === listItem) : !1;
|
|
1421
1469
|
}
|
|
1422
1470
|
function isStyleActive({
|
|
1423
1471
|
editor,
|
|
@@ -1427,7 +1475,9 @@ function isStyleActive({
|
|
|
1427
1475
|
return !1;
|
|
1428
1476
|
const selectedBlocks = [...nodes(editor, {
|
|
1429
1477
|
at: editor.selection,
|
|
1430
|
-
match: (node2) =>
|
|
1478
|
+
match: (node2) => isTextBlock({
|
|
1479
|
+
schema: editor.schema
|
|
1480
|
+
}, node2)
|
|
1431
1481
|
})];
|
|
1432
1482
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node2]) => node2.style === style) : !1;
|
|
1433
1483
|
}
|
|
@@ -2246,16 +2296,26 @@ function rangeRef(editor, range2, options = {}) {
|
|
|
2246
2296
|
}
|
|
2247
2297
|
function getLeaf(root, path2, schema) {
|
|
2248
2298
|
const node2 = getNode(root, path2, schema);
|
|
2249
|
-
if (
|
|
2250
|
-
|
|
2251
|
-
|
|
2299
|
+
if (isSpan({
|
|
2300
|
+
schema
|
|
2301
|
+
}, node2) || isObjectNode({
|
|
2302
|
+
schema
|
|
2303
|
+
}, node2))
|
|
2304
|
+
return node2;
|
|
2305
|
+
throw new Error(`Cannot get the leaf node at path [${path2}] because it refers to a non-leaf node: ${safeStringify(node2)}`);
|
|
2252
2306
|
}
|
|
2253
2307
|
function getString(node2, schema) {
|
|
2254
|
-
return
|
|
2308
|
+
return isEditor(node2) || isObjectNode({
|
|
2309
|
+
schema
|
|
2310
|
+
}, node2) ? "" : isSpan({
|
|
2311
|
+
schema
|
|
2312
|
+
}, node2) ? node2.text : node2.children.map((child) => getString(child, schema)).join("");
|
|
2255
2313
|
}
|
|
2256
2314
|
function* getTexts(root, schema, options = {}) {
|
|
2257
2315
|
for (const [node2, path2] of getNodes(root, schema, options))
|
|
2258
|
-
|
|
2316
|
+
isSpan({
|
|
2317
|
+
schema
|
|
2318
|
+
}, node2) && (yield [node2, path2]);
|
|
2259
2319
|
}
|
|
2260
2320
|
function rangeEquals(range2, another) {
|
|
2261
2321
|
return pointEquals(range2.anchor, another.anchor) && pointEquals(range2.focus, another.focus);
|
|
@@ -2316,23 +2376,18 @@ const EditorContext = createContext(null), useSlateStatic = () => {
|
|
|
2316
2376
|
throw new Error("The `useSlateStatic` hook must be used inside the <Slate> component's context.");
|
|
2317
2377
|
return editor;
|
|
2318
2378
|
};
|
|
2319
|
-
function
|
|
2320
|
-
const nodePath = path(editor, at, options), parentPath_ = parentPath(nodePath);
|
|
2321
|
-
return node(editor, parentPath_);
|
|
2322
|
-
}
|
|
2323
|
-
function next(editor, options = {}) {
|
|
2379
|
+
function next(editor, options) {
|
|
2324
2380
|
const {
|
|
2325
2381
|
mode = "lowest",
|
|
2326
|
-
|
|
2327
|
-
} = options
|
|
2328
|
-
let {
|
|
2382
|
+
includeObjectNodes = !1
|
|
2383
|
+
} = options, {
|
|
2329
2384
|
match: match2,
|
|
2330
2385
|
at = editor.selection
|
|
2331
2386
|
} = options;
|
|
2332
2387
|
if (!at)
|
|
2333
2388
|
return;
|
|
2334
2389
|
const pointAfterLocation = after(editor, at, {
|
|
2335
|
-
|
|
2390
|
+
includeObjectNodes
|
|
2336
2391
|
});
|
|
2337
2392
|
if (!pointAfterLocation)
|
|
2338
2393
|
return;
|
|
@@ -2341,17 +2396,11 @@ function next(editor, options = {}) {
|
|
|
2341
2396
|
})), span = [pointAfterLocation.path, to];
|
|
2342
2397
|
if (isPath(at) && at.length === 0)
|
|
2343
2398
|
throw new Error("Cannot get the next node from the root node!");
|
|
2344
|
-
if (match2 == null)
|
|
2345
|
-
if (isPath(at)) {
|
|
2346
|
-
const [parentNode] = parent(editor, at);
|
|
2347
|
-
match2 = (n2) => parentNode.children.includes(n2);
|
|
2348
|
-
} else
|
|
2349
|
-
match2 = () => !0;
|
|
2350
2399
|
const [nextEntry] = nodes(editor, {
|
|
2351
2400
|
at: span,
|
|
2352
2401
|
match: match2,
|
|
2353
2402
|
mode,
|
|
2354
|
-
|
|
2403
|
+
includeObjectNodes
|
|
2355
2404
|
});
|
|
2356
2405
|
return nextEntry;
|
|
2357
2406
|
}
|
|
@@ -2433,7 +2482,9 @@ function verifyDiffState(editor, textDiff) {
|
|
|
2433
2482
|
if (!hasPath(editor, path2))
|
|
2434
2483
|
return !1;
|
|
2435
2484
|
const node2 = getNode(editor, path2, editor.schema);
|
|
2436
|
-
if (!
|
|
2485
|
+
if (!isSpan({
|
|
2486
|
+
schema: editor.schema
|
|
2487
|
+
}, node2))
|
|
2437
2488
|
return !1;
|
|
2438
2489
|
if (diff2.start !== node2.text.length || diff2.text.length === 0)
|
|
2439
2490
|
return node2.text.slice(diff2.start, diff2.start + diff2.text.length) === diff2.text;
|
|
@@ -2441,7 +2492,9 @@ function verifyDiffState(editor, textDiff) {
|
|
|
2441
2492
|
if (!hasPath(editor, nextPath$1))
|
|
2442
2493
|
return !1;
|
|
2443
2494
|
const nextNode = getNode(editor, nextPath$1, editor.schema);
|
|
2444
|
-
return
|
|
2495
|
+
return isSpan({
|
|
2496
|
+
schema: editor.schema
|
|
2497
|
+
}, nextNode) && nextNode.text.startsWith(diff2.text);
|
|
2445
2498
|
}
|
|
2446
2499
|
function applyStringDiff(text, ...diffs) {
|
|
2447
2500
|
return diffs.reduce((text2, diff2) => text2.slice(0, diff2.start) + diff2.text + text2.slice(diff2.end), text);
|
|
@@ -2504,10 +2557,14 @@ function normalizePoint(editor, point2) {
|
|
|
2504
2557
|
if (!hasPath(editor, path2))
|
|
2505
2558
|
return null;
|
|
2506
2559
|
let leaf2 = getNode(editor, path2, editor.schema);
|
|
2507
|
-
if (!
|
|
2560
|
+
if (!isSpan({
|
|
2561
|
+
schema: editor.schema
|
|
2562
|
+
}, leaf2))
|
|
2508
2563
|
return null;
|
|
2509
2564
|
const parentBlock = above(editor, {
|
|
2510
|
-
match: (n2) =>
|
|
2565
|
+
match: (n2) => isTextBlock({
|
|
2566
|
+
schema: editor.schema
|
|
2567
|
+
}, n2),
|
|
2511
2568
|
at: path2
|
|
2512
2569
|
});
|
|
2513
2570
|
if (!parentBlock)
|
|
@@ -2515,7 +2572,9 @@ function normalizePoint(editor, point2) {
|
|
|
2515
2572
|
for (; offset > leaf2.text.length; ) {
|
|
2516
2573
|
const entry = next(editor, {
|
|
2517
2574
|
at: path2,
|
|
2518
|
-
match: (n2) =>
|
|
2575
|
+
match: (n2) => isSpan({
|
|
2576
|
+
schema: editor.schema
|
|
2577
|
+
}, n2)
|
|
2519
2578
|
});
|
|
2520
2579
|
if (!entry || !isDescendantPath(entry[1], parentBlock[1]))
|
|
2521
2580
|
return null;
|
|
@@ -2732,7 +2791,9 @@ function createAndroidInputManager({
|
|
|
2732
2791
|
}
|
|
2733
2792
|
}, storeDiff = (path2, diff2) => {
|
|
2734
2793
|
const pendingDiffs = editor.pendingDiffs, target = getLeaf(editor, path2, editor.schema);
|
|
2735
|
-
if (!
|
|
2794
|
+
if (!isSpan({
|
|
2795
|
+
schema: editor.schema
|
|
2796
|
+
}, target))
|
|
2736
2797
|
return;
|
|
2737
2798
|
const idx = pendingDiffs.findIndex((change) => pathEquals(change.path, path2));
|
|
2738
2799
|
if (idx < 0) {
|
|
@@ -2783,7 +2844,9 @@ function createAndroidInputManager({
|
|
|
2783
2844
|
if (type.startsWith("delete")) {
|
|
2784
2845
|
const direction = type.endsWith("Backward") ? "backward" : "forward";
|
|
2785
2846
|
let [start2, end2] = rangeEdges(targetRange2), [leaf$1, path2] = leaf(editor, start2.path);
|
|
2786
|
-
if (!
|
|
2847
|
+
if (!isSpan({
|
|
2848
|
+
schema: editor.schema
|
|
2849
|
+
}, leaf$1))
|
|
2787
2850
|
return scheduleAction(() => editorActor.send({
|
|
2788
2851
|
type: "behavior event",
|
|
2789
2852
|
behaviorEvent: {
|
|
@@ -2797,7 +2860,9 @@ function createAndroidInputManager({
|
|
|
2797
2860
|
if (isExpandedRange(targetRange2) && leaf$1.text.length === start2.offset && end2.offset === 0) {
|
|
2798
2861
|
const next$1 = next(editor, {
|
|
2799
2862
|
at: start2.path,
|
|
2800
|
-
match: (n2) =>
|
|
2863
|
+
match: (n2) => isSpan({
|
|
2864
|
+
schema: editor.schema
|
|
2865
|
+
}, n2)
|
|
2801
2866
|
});
|
|
2802
2867
|
next$1 && pathEquals(next$1[1], end2.path) && (direction === "backward" ? (targetRange2 = {
|
|
2803
2868
|
anchor: end2,
|
|
@@ -2857,7 +2922,9 @@ function createAndroidInputManager({
|
|
|
2857
2922
|
} = targetRange2;
|
|
2858
2923
|
if (canStoreDiff && isCollapsedRange(targetRange2)) {
|
|
2859
2924
|
const targetNode = getLeaf(editor, anchor.path, editor.schema);
|
|
2860
|
-
if (
|
|
2925
|
+
if (isSpan({
|
|
2926
|
+
schema: editor.schema
|
|
2927
|
+
}, targetNode) && anchor.offset < targetNode.text.length)
|
|
2861
2928
|
return storeDiff(anchor.path, {
|
|
2862
2929
|
text: "",
|
|
2863
2930
|
start: anchor.offset,
|
|
@@ -3191,10 +3258,12 @@ const shallowCompare = (obj1, obj2) => Object.keys(obj1).length === Object.keys(
|
|
|
3191
3258
|
}
|
|
3192
3259
|
return !0;
|
|
3193
3260
|
}, splitDecorationsByChild = (editor, node2, decorations) => {
|
|
3194
|
-
const
|
|
3261
|
+
const children = isEditor(node2) || isTextBlock({
|
|
3262
|
+
schema: editor.schema
|
|
3263
|
+
}, node2) ? node2.children : [], decorationsByChild = Array.from(children, () => []);
|
|
3195
3264
|
if (decorations.length === 0)
|
|
3196
3265
|
return decorationsByChild;
|
|
3197
|
-
const path2 = DOMEditor.findPath(editor, node2), level = path2.length, ancestorRange = range(editor, path2), cachedChildRanges = new Array(
|
|
3266
|
+
const path2 = DOMEditor.findPath(editor, node2), level = path2.length, ancestorRange = range(editor, path2), cachedChildRanges = new Array(children.length), getChildRange = (index) => {
|
|
3198
3267
|
const cachedRange = cachedChildRanges[index];
|
|
3199
3268
|
if (cachedRange)
|
|
3200
3269
|
return cachedRange;
|
|
@@ -3259,7 +3328,9 @@ const DecorateContext = createContext({}), useDecorations = (node2, parentDecora
|
|
|
3259
3328
|
} = useContext(DecorateContext), selector = () => {
|
|
3260
3329
|
const path2 = ReactEditor.findPath(editor, node2);
|
|
3261
3330
|
return decorate([node2, path2]);
|
|
3262
|
-
}, equalityFn =
|
|
3331
|
+
}, equalityFn = isSpan({
|
|
3332
|
+
schema: editor.schema
|
|
3333
|
+
}, node2) ? isTextDecorationsEqual : isElementDecorationsEqual, [decorations, update] = useGenericSelector(selector, equalityFn);
|
|
3263
3334
|
return useIsomorphicLayoutEffect(() => {
|
|
3264
3335
|
const unsubscribe = addEventListener(update);
|
|
3265
3336
|
return update(), unsubscribe;
|
|
@@ -3292,7 +3363,7 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
3292
3363
|
renderLeaf,
|
|
3293
3364
|
renderText
|
|
3294
3365
|
} = props, editor = useSlateStatic(), isInline = editor.isInline(element), decorations = useDecorations(element, parentDecorations), key = ReactEditor.findKey(editor, element), ref = useCallback((ref2) => {
|
|
3295
|
-
ref2 ? (editor.keyToElement?.set(key, ref2), editor.
|
|
3366
|
+
ref2 ? (editor.keyToElement?.set(key, ref2), editor.elementToNode.set(ref2, element)) : editor.keyToElement?.delete(key);
|
|
3296
3367
|
}, [editor, key, element]), children = useChildren({
|
|
3297
3368
|
decorations,
|
|
3298
3369
|
node: element,
|
|
@@ -3304,7 +3375,9 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
3304
3375
|
"data-slate-node": "element",
|
|
3305
3376
|
ref
|
|
3306
3377
|
};
|
|
3307
|
-
if (isInline && (attributes["data-slate-inline"] = !0), !isInline &&
|
|
3378
|
+
if (isInline && (attributes["data-slate-inline"] = !0), !isInline && isTextBlock({
|
|
3379
|
+
schema: editor.schema
|
|
3380
|
+
}, element) && hasInlines(editor, element)) {
|
|
3308
3381
|
const text = getString(element, editor.schema), dir = getDirection(text);
|
|
3309
3382
|
dir === "rtl" && (attributes.dir = dir);
|
|
3310
3383
|
}
|
|
@@ -3336,12 +3409,12 @@ const defaultRenderElement$1 = (props) => /* @__PURE__ */ jsx(DefaultElement, {
|
|
|
3336
3409
|
isInline,
|
|
3337
3410
|
renderElement = defaultRenderElement
|
|
3338
3411
|
} = props, editor = useSlateStatic(), readOnly = useReadOnly(), key = ReactEditor.findKey(editor, objectNode), ref = useCallback((ref2) => {
|
|
3339
|
-
ref2 ? (editor.keyToElement?.set(key, ref2), editor.
|
|
3412
|
+
ref2 ? (editor.keyToElement?.set(key, ref2), editor.elementToNode.set(ref2, objectNode)) : editor.keyToElement?.delete(key);
|
|
3340
3413
|
}, [editor, key, objectNode]), syntheticText = useMemo(() => ({
|
|
3341
3414
|
text: "",
|
|
3342
3415
|
marks: []
|
|
3343
3416
|
}), []), spacerTextRef = useCallback((span) => {
|
|
3344
|
-
span
|
|
3417
|
+
span && (editor.keyToElement?.set(ReactEditor.findKey(editor, syntheticText), span), editor.elementToNode.set(span, syntheticText));
|
|
3345
3418
|
}, [editor, syntheticText]);
|
|
3346
3419
|
React.useEffect(() => (editor.nodeToIndex.set(syntheticText, 0), editor.nodeToParent.set(syntheticText, objectNode), () => {
|
|
3347
3420
|
editor.nodeToIndex.delete(syntheticText), editor.nodeToParent.delete(syntheticText);
|
|
@@ -3445,7 +3518,9 @@ const SlateString = (props) => {
|
|
|
3445
3518
|
parent: parent2,
|
|
3446
3519
|
text
|
|
3447
3520
|
} = props, editor = useSlateStatic(), path2 = ReactEditor.findPath(editor, text), parentPath_ = parentPath(path2), isMarkPlaceholder = !!leaf2[MARK_PLACEHOLDER_SYMBOL];
|
|
3448
|
-
return leaf2.text === "" &&
|
|
3521
|
+
return leaf2.text === "" && isTextBlock({
|
|
3522
|
+
schema: editor.schema
|
|
3523
|
+
}, parent2) && parent2.children[parent2.children.length - 1] === text && !editor.isInline(parent2) && string(editor, parentPath_) === "" ? /* @__PURE__ */ jsx(ZeroWidthString, { isLineBreak: !0, isMarkPlaceholder }) : leaf2.text === "" ? /* @__PURE__ */ jsx(ZeroWidthString, { isMarkPlaceholder }) : isLast && leaf2.text.slice(-1) === `
|
|
3449
3524
|
` ? /* @__PURE__ */ jsx(TextString, { isTrailing: !0, text: leaf2.text }) : /* @__PURE__ */ jsx(TextString, { text: leaf2.text });
|
|
3450
3525
|
}, TextString = (props) => {
|
|
3451
3526
|
const {
|
|
@@ -3565,7 +3640,7 @@ const defaultRenderLeaf = (props) => /* @__PURE__ */ jsx(DefaultLeaf, { ...props
|
|
|
3565
3640
|
const attributes = {
|
|
3566
3641
|
"data-slate-node": "text",
|
|
3567
3642
|
ref: useCallback((span) => {
|
|
3568
|
-
span ? (editor.keyToElement?.set(key, span), editor.
|
|
3643
|
+
span ? (editor.keyToElement?.set(key, span), editor.elementToNode.set(span, text)) : (editor.keyToElement?.delete(key), ref.current && editor.elementToNode.delete(ref.current)), ref.current = span;
|
|
3569
3644
|
}, [ref, editor, key, text])
|
|
3570
3645
|
};
|
|
3571
3646
|
return renderText({
|
|
@@ -3589,21 +3664,41 @@ const defaultRenderLeaf = (props) => /* @__PURE__ */ jsx(DefaultLeaf, { ...props
|
|
|
3589
3664
|
renderLeaf
|
|
3590
3665
|
} = props, editor = useSlateStatic();
|
|
3591
3666
|
editor.isNodeMapDirty = !1;
|
|
3592
|
-
const isEditorNode = isEditor(node2), decorationsByChild = useDecorationsByChild(editor, node2, decorations)
|
|
3593
|
-
|
|
3667
|
+
const isEditorNode = isEditor(node2), decorationsByChild = useDecorationsByChild(editor, node2, decorations), children = isEditor(node2) || isTextBlock({
|
|
3668
|
+
schema: editor.schema
|
|
3669
|
+
}, node2) ? node2.children : [];
|
|
3670
|
+
children.forEach((n2, i) => {
|
|
3594
3671
|
editor.nodeToIndex.set(n2, i), editor.nodeToParent.set(n2, node2);
|
|
3595
3672
|
});
|
|
3596
3673
|
const renderElementComponent = useCallback((n2, i, cachedKey) => {
|
|
3597
3674
|
const key = cachedKey ?? ReactEditor.findKey(editor, n2);
|
|
3598
3675
|
return /* @__PURE__ */ jsx(ElementContext.Provider, { value: n2, children: /* @__PURE__ */ jsx(MemoizedElement, { decorations: decorationsByChild[i] ?? [], element: n2, renderElement, renderPlaceholder, renderLeaf, renderText }, key.id) }, `provider-${key.id}`);
|
|
3599
|
-
}, [editor, decorationsByChild, renderElement, renderPlaceholder, renderLeaf, renderText]),
|
|
3676
|
+
}, [editor, decorationsByChild, renderElement, renderPlaceholder, renderLeaf, renderText]), textBlockParent = isTextBlock({
|
|
3677
|
+
schema: editor.schema
|
|
3678
|
+
}, node2) ? node2 : void 0, renderTextComponent = (n2, i) => {
|
|
3679
|
+
if (!textBlockParent)
|
|
3680
|
+
throw new Error("Cannot render text component without a text block parent");
|
|
3600
3681
|
const key = ReactEditor.findKey(editor, n2);
|
|
3601
|
-
return /* @__PURE__ */ jsx(MemoizedText, { decorations: decorationsByChild[i] ?? [], isLast: i ===
|
|
3682
|
+
return /* @__PURE__ */ jsx(MemoizedText, { decorations: decorationsByChild[i] ?? [], isLast: i === children.length - 1, parent: textBlockParent, renderPlaceholder, renderLeaf, renderText, text: n2 }, key.id);
|
|
3602
3683
|
}, renderObjectNodeComponent = (n2, i) => {
|
|
3603
3684
|
const key = ReactEditor.findKey(editor, n2);
|
|
3604
3685
|
return /* @__PURE__ */ jsx(MemoizedObjectNode, { decorations: decorationsByChild[i] ?? [], isInline: !isEditorNode, objectNode: n2, renderElement }, key.id);
|
|
3605
3686
|
};
|
|
3606
|
-
return
|
|
3687
|
+
return children.map((n2, i) => {
|
|
3688
|
+
if (isTextBlock({
|
|
3689
|
+
schema: editor.schema
|
|
3690
|
+
}, n2))
|
|
3691
|
+
return renderElementComponent(n2, i);
|
|
3692
|
+
if (isObjectNode({
|
|
3693
|
+
schema: editor.schema
|
|
3694
|
+
}, n2))
|
|
3695
|
+
return renderObjectNodeComponent(n2, i);
|
|
3696
|
+
if (isSpan({
|
|
3697
|
+
schema: editor.schema
|
|
3698
|
+
}, n2))
|
|
3699
|
+
return renderTextComponent(n2, i);
|
|
3700
|
+
throw new Error("Unexpected node type");
|
|
3701
|
+
});
|
|
3607
3702
|
}, useDecorationsByChild = (editor, node2, decorations) => {
|
|
3608
3703
|
const decorationsByChild = splitDecorationsByChild(editor, node2, decorations), mutableDecorationsByChild = useRef(decorationsByChild).current;
|
|
3609
3704
|
mutableDecorationsByChild.length = decorationsByChild.length;
|
|
@@ -3613,9 +3708,7 @@ const defaultRenderLeaf = (props) => /* @__PURE__ */ jsx(DefaultLeaf, { ...props
|
|
|
3613
3708
|
}
|
|
3614
3709
|
return mutableDecorationsByChild;
|
|
3615
3710
|
}, ComposingContext = createContext(!1), SlateSelectorContext = createContext({}), refEquality = (a, b) => a === b;
|
|
3616
|
-
function useSlateSelector(selector, equalityFn = refEquality
|
|
3617
|
-
deferred
|
|
3618
|
-
} = {}) {
|
|
3711
|
+
function useSlateSelector(selector, equalityFn = refEquality) {
|
|
3619
3712
|
const context = useContext(SlateSelectorContext);
|
|
3620
3713
|
if (!context)
|
|
3621
3714
|
throw new Error("The `useSlateSelector` hook must be used inside the <Slate> component's context.");
|
|
@@ -3623,11 +3716,9 @@ function useSlateSelector(selector, equalityFn = refEquality, {
|
|
|
3623
3716
|
addEventListener
|
|
3624
3717
|
} = context, editor = useSlateStatic(), genericSelector = useCallback(() => selector(editor), [editor, selector]), [selectedState, update] = useGenericSelector(genericSelector, equalityFn);
|
|
3625
3718
|
return useIsomorphicLayoutEffect(() => {
|
|
3626
|
-
const unsubscribe = addEventListener(update
|
|
3627
|
-
deferred
|
|
3628
|
-
});
|
|
3719
|
+
const unsubscribe = addEventListener(update);
|
|
3629
3720
|
return update(), unsubscribe;
|
|
3630
|
-
}, [addEventListener, update
|
|
3721
|
+
}, [addEventListener, update]), selectedState;
|
|
3631
3722
|
}
|
|
3632
3723
|
function useSelectorContext() {
|
|
3633
3724
|
const eventListeners = useRef(/* @__PURE__ */ new Set()), deferredEventListeners = useRef(/* @__PURE__ */ new Set()), onChange = useCallback(() => {
|
|
@@ -3638,14 +3729,9 @@ function useSelectorContext() {
|
|
|
3638
3729
|
deferredEventListeners.current.forEach((listener) => {
|
|
3639
3730
|
listener();
|
|
3640
3731
|
}), deferredEventListeners.current.clear();
|
|
3641
|
-
}, []), addEventListener = useCallback((callbackProp, {
|
|
3642
|
-
|
|
3643
|
-
}
|
|
3644
|
-
const callback = deferred ? () => deferredEventListeners.current.add(callbackProp) : callbackProp;
|
|
3645
|
-
return eventListeners.current.add(callback), () => {
|
|
3646
|
-
eventListeners.current.delete(callback);
|
|
3647
|
-
};
|
|
3648
|
-
}, []);
|
|
3732
|
+
}, []), addEventListener = useCallback((callbackProp) => (eventListeners.current.add(callbackProp), () => {
|
|
3733
|
+
eventListeners.current.delete(callbackProp);
|
|
3734
|
+
}), []);
|
|
3649
3735
|
return {
|
|
3650
3736
|
selectorContext: useMemo(() => ({
|
|
3651
3737
|
addEventListener,
|
|
@@ -3859,7 +3945,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3859
3945
|
scheduleOnDOMSelectionChange
|
|
3860
3946
|
}), useIsomorphicLayoutEffect(() => {
|
|
3861
3947
|
let window2 = null;
|
|
3862
|
-
ref.current && (window2 = getDefaultView(ref.current))
|
|
3948
|
+
ref.current && (window2 = getDefaultView(ref.current)) && (editor.domWindow = window2, editor.domElement = ref.current, editor.elementToNode.set(ref.current, editor));
|
|
3863
3949
|
const {
|
|
3864
3950
|
selection
|
|
3865
3951
|
} = editor, root = ReactEditor.findDocumentOrShadowRoot(editor), domSelection = getSelection(root);
|
|
@@ -3971,7 +4057,9 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
3971
4057
|
if (native && node2.parentElement && window2?.getComputedStyle(node2.parentElement)?.whiteSpace === "pre") {
|
|
3972
4058
|
const block = above(editor, {
|
|
3973
4059
|
at: anchor.path,
|
|
3974
|
-
match: (n2) =>
|
|
4060
|
+
match: (n2) => isTextBlock({
|
|
4061
|
+
schema: editor.schema
|
|
4062
|
+
}, n2)
|
|
3975
4063
|
});
|
|
3976
4064
|
block && getString(block[0], editor.schema).includes(" ") && (native = !1);
|
|
3977
4065
|
}
|
|
@@ -4181,7 +4269,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4181
4269
|
editor.userSelection = null, toRestore && (!editor.selection || !rangeEquals(editor.selection, toRestore)) && editor.select(toRestore);
|
|
4182
4270
|
}
|
|
4183
4271
|
}, [editor, editorActor, onDOMSelectionChange, onUserInput, propsOnDOMBeforeInput, readOnly, scheduleOnDOMSelectionChange]), callbackRef = useCallback((node2) => {
|
|
4184
|
-
node2 == null ? (onDOMSelectionChange.cancel(), scheduleOnDOMSelectionChange.cancel(), editor.domElement = null,
|
|
4272
|
+
node2 == null ? (onDOMSelectionChange.cancel(), scheduleOnDOMSelectionChange.cancel(), editor.domElement = null, ref.current && HAS_BEFORE_INPUT_SUPPORT && ref.current.removeEventListener("beforeinput", onDOMBeforeInput)) : HAS_BEFORE_INPUT_SUPPORT && node2.addEventListener("beforeinput", onDOMBeforeInput), ref.current = node2, typeof forwardedRef == "function" ? forwardedRef(node2) : forwardedRef && (forwardedRef.current = node2);
|
|
4185
4273
|
}, [onDOMSelectionChange, scheduleOnDOMSelectionChange, editor, onDOMBeforeInput, forwardedRef]);
|
|
4186
4274
|
useIsomorphicLayoutEffect(() => {
|
|
4187
4275
|
const window2 = ReactEditor.getWindow(editor), onSelectionChange = ({
|
|
@@ -4214,7 +4302,9 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4214
4302
|
const {
|
|
4215
4303
|
anchor
|
|
4216
4304
|
} = editor.selection, leaf2 = getLeaf(editor, anchor.path, editor.schema);
|
|
4217
|
-
if (
|
|
4305
|
+
if (isSpan({
|
|
4306
|
+
schema: editor.schema
|
|
4307
|
+
}, leaf2)) {
|
|
4218
4308
|
const {
|
|
4219
4309
|
text: _text,
|
|
4220
4310
|
...rest
|
|
@@ -4243,7 +4333,9 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4243
4333
|
const {
|
|
4244
4334
|
anchor
|
|
4245
4335
|
} = selection, text = getLeaf(editor, anchor.path, editor.schema);
|
|
4246
|
-
if (!
|
|
4336
|
+
if (!isSpan({
|
|
4337
|
+
schema: editor.schema
|
|
4338
|
+
}, text))
|
|
4247
4339
|
return;
|
|
4248
4340
|
if (marks && !textEquals(text, marks, {
|
|
4249
4341
|
loose: !0
|
|
@@ -4322,7 +4414,11 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4322
4414
|
if (relatedTarget !== el && !(isDOMElement(relatedTarget) && relatedTarget.hasAttribute("data-slate-spacer"))) {
|
|
4323
4415
|
if (relatedTarget != null && isDOMNode(relatedTarget) && ReactEditor.hasDOMNode(editor, relatedTarget)) {
|
|
4324
4416
|
const node2 = ReactEditor.toSlateNode(editor, relatedTarget);
|
|
4325
|
-
if (
|
|
4417
|
+
if (isTextBlock({
|
|
4418
|
+
schema: editor.schema
|
|
4419
|
+
}, node2) || isObjectNode({
|
|
4420
|
+
schema: editor.schema
|
|
4421
|
+
}, node2))
|
|
4326
4422
|
return;
|
|
4327
4423
|
}
|
|
4328
4424
|
IS_WEBKIT && getSelection(root)?.removeAllRanges(), editor.focused = !1;
|
|
@@ -4331,12 +4427,16 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4331
4427
|
onClick: useCallback((event) => {
|
|
4332
4428
|
if (ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onClick) && isDOMNode(event.target)) {
|
|
4333
4429
|
const node2 = ReactEditor.toSlateNode(editor, event.target), path2 = ReactEditor.findPath(editor, node2);
|
|
4334
|
-
if (
|
|
4430
|
+
if (getNodeIf(editor, path2, editor.schema) !== node2)
|
|
4335
4431
|
return;
|
|
4336
4432
|
if (event.detail === TRIPLE_CLICK && path2.length >= 1) {
|
|
4337
4433
|
let blockPath = path2;
|
|
4338
|
-
|
|
4339
|
-
|
|
4434
|
+
isTextBlock({
|
|
4435
|
+
schema: editor.schema
|
|
4436
|
+
}, node2) && !editor.isInline(node2) || (blockPath = above(editor, {
|
|
4437
|
+
match: (n2) => isTextBlock({
|
|
4438
|
+
schema: editor.schema
|
|
4439
|
+
}, n2),
|
|
4340
4440
|
at: path2
|
|
4341
4441
|
})?.[1] ?? path2.slice(0, 1));
|
|
4342
4442
|
const range$1 = range(editor, blockPath);
|
|
@@ -4345,12 +4445,12 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4345
4445
|
}
|
|
4346
4446
|
if (readOnly)
|
|
4347
4447
|
return;
|
|
4348
|
-
const start$1 = start(editor, path2), end$1 = end(editor, path2),
|
|
4448
|
+
const start$1 = start(editor, path2), end$1 = end(editor, path2), startObjectNode = getObjectNode(editor, {
|
|
4349
4449
|
at: start$1
|
|
4350
|
-
}),
|
|
4450
|
+
}), endObjectNode = getObjectNode(editor, {
|
|
4351
4451
|
at: end$1
|
|
4352
4452
|
});
|
|
4353
|
-
if (
|
|
4453
|
+
if (startObjectNode && endObjectNode && pathEquals(startObjectNode[1], endObjectNode[1])) {
|
|
4354
4454
|
const range$1 = range(editor, start$1);
|
|
4355
4455
|
editor.select(range$1);
|
|
4356
4456
|
}
|
|
@@ -4493,7 +4593,9 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
4493
4593
|
if (HAS_BEFORE_INPUT_SUPPORT) {
|
|
4494
4594
|
if ((IS_CHROME || IS_WEBKIT) && selection && (Hotkeys.isDeleteBackward(nativeEvent) || Hotkeys.isDeleteForward(nativeEvent)) && isCollapsedRange(selection)) {
|
|
4495
4595
|
const currentNode = getNode(editor, selection.anchor.path, editor.schema);
|
|
4496
|
-
if (
|
|
4596
|
+
if (isObjectNode({
|
|
4597
|
+
schema: editor.schema
|
|
4598
|
+
}, currentNode)) {
|
|
4497
4599
|
event.preventDefault(), editorActor.send({
|
|
4498
4600
|
type: "behavior event",
|
|
4499
4601
|
behaviorEvent: {
|
|
@@ -5292,7 +5394,9 @@ function createDecorate(schema, slateEditor) {
|
|
|
5292
5394
|
}];
|
|
5293
5395
|
if (path2.length === 0)
|
|
5294
5396
|
return [];
|
|
5295
|
-
if (!
|
|
5397
|
+
if (!isTextBlock({
|
|
5398
|
+
schema: slateEditor.schema
|
|
5399
|
+
}, node2) || node2.children.length === 0)
|
|
5296
5400
|
return [];
|
|
5297
5401
|
const blockIndex = path2.at(0);
|
|
5298
5402
|
return blockIndex === void 0 ? [] : slateEditor.decoratedRanges.filter((decoratedRange) => isCollapsedRange(decoratedRange) ? node2.children.some((_, childIndex) => pathEquals(decoratedRange.anchor.path, [blockIndex, childIndex]) && pathEquals(decoratedRange.focus.path, [blockIndex, childIndex])) : rangeIntersection(decoratedRange, {
|
|
@@ -5361,7 +5465,7 @@ function useEditorSelector(editor, selector, t0) {
|
|
|
5361
5465
|
return $[0] !== editor || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
5362
5466
|
const snapshot = getEditorSnapshot({
|
|
5363
5467
|
editorActorSnapshot,
|
|
5364
|
-
slateEditorInstance: editor._internal.slateEditor
|
|
5468
|
+
slateEditorInstance: editor._internal.slateEditor
|
|
5365
5469
|
});
|
|
5366
5470
|
return selector(snapshot);
|
|
5367
5471
|
}, $[0] = editor, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
|
|
@@ -5752,27 +5856,21 @@ function RenderStyle({
|
|
|
5752
5856
|
});
|
|
5753
5857
|
}
|
|
5754
5858
|
function RenderElement(props) {
|
|
5755
|
-
const $ = c(
|
|
5859
|
+
const $ = c(26), editorActor = useContext(EditorActorContext), schema = useSelector(editorActor, _temp$3), slateStatic = useSlateStatic();
|
|
5860
|
+
if (isTextBlock({
|
|
5861
|
+
schema
|
|
5862
|
+
}, props.element)) {
|
|
5863
|
+
const t02 = props.dropPosition?.blockKey === props.element._key ? props.dropPosition.positionBlock : void 0;
|
|
5864
|
+
let t12;
|
|
5865
|
+
return $[0] !== props.attributes || $[1] !== props.children || $[2] !== props.element || $[3] !== props.readOnly || $[4] !== props.renderBlock || $[5] !== props.renderListItem || $[6] !== props.renderStyle || $[7] !== props.spellCheck || $[8] !== schema || $[9] !== t02 ? (t12 = /* @__PURE__ */ jsx(RenderTextBlock, { attributes: props.attributes, dropPosition: t02, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, schema, spellCheck: props.spellCheck, textBlock: props.element, children: props.children }), $[0] = props.attributes, $[1] = props.children, $[2] = props.element, $[3] = props.readOnly, $[4] = props.renderBlock, $[5] = props.renderListItem, $[6] = props.renderStyle, $[7] = props.spellCheck, $[8] = schema, $[9] = t02, $[10] = t12) : t12 = $[10], t12;
|
|
5866
|
+
}
|
|
5756
5867
|
if (slateStatic.isInline(props.element)) {
|
|
5757
5868
|
let t02;
|
|
5758
|
-
return $[
|
|
5759
|
-
}
|
|
5760
|
-
let block, t0;
|
|
5761
|
-
if ($[7] !== props.element._key || $[8] !== schema || $[9] !== slateStatic.blockIndexMap || $[10] !== slateStatic.children) {
|
|
5762
|
-
const blockIndex = slateStatic.blockIndexMap.get(props.element._key);
|
|
5763
|
-
block = blockIndex !== void 0 ? slateStatic.children.at(blockIndex) : void 0, t0 = isTextBlock({
|
|
5764
|
-
schema
|
|
5765
|
-
}, block), $[7] = props.element._key, $[8] = schema, $[9] = slateStatic.blockIndexMap, $[10] = slateStatic.children, $[11] = block, $[12] = t0;
|
|
5766
|
-
} else
|
|
5767
|
-
block = $[11], t0 = $[12];
|
|
5768
|
-
if (t0) {
|
|
5769
|
-
const t12 = props.dropPosition?.blockKey === props.element._key ? props.dropPosition.positionBlock : void 0;
|
|
5770
|
-
let t22;
|
|
5771
|
-
return $[13] !== block || $[14] !== props.attributes || $[15] !== props.children || $[16] !== props.element || $[17] !== props.readOnly || $[18] !== props.renderBlock || $[19] !== props.renderListItem || $[20] !== props.renderStyle || $[21] !== props.spellCheck || $[22] !== schema || $[23] !== t12 ? (t22 = /* @__PURE__ */ jsx(RenderTextBlock, { attributes: props.attributes, dropPosition: t12, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, schema, spellCheck: props.spellCheck, textBlock: block, children: props.children }), $[13] = block, $[14] = props.attributes, $[15] = props.children, $[16] = props.element, $[17] = props.readOnly, $[18] = props.renderBlock, $[19] = props.renderListItem, $[20] = props.renderStyle, $[21] = props.spellCheck, $[22] = schema, $[23] = t12, $[24] = t22) : t22 = $[24], t22;
|
|
5869
|
+
return $[11] !== props.attributes || $[12] !== props.children || $[13] !== props.element || $[14] !== props.readOnly || $[15] !== props.renderChild || $[16] !== schema ? (t02 = /* @__PURE__ */ jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderChild: props.renderChild, schema, children: props.children }), $[11] = props.attributes, $[12] = props.children, $[13] = props.element, $[14] = props.readOnly, $[15] = props.renderChild, $[16] = schema, $[17] = t02) : t02 = $[17], t02;
|
|
5772
5870
|
}
|
|
5773
|
-
const
|
|
5774
|
-
let
|
|
5775
|
-
return $[
|
|
5871
|
+
const t0 = props.dropPosition?.blockKey === props.element._key ? props.dropPosition.positionBlock : void 0;
|
|
5872
|
+
let t1;
|
|
5873
|
+
return $[18] !== props.attributes || $[19] !== props.children || $[20] !== props.element || $[21] !== props.readOnly || $[22] !== props.renderBlock || $[23] !== schema || $[24] !== t0 ? (t1 = /* @__PURE__ */ jsx(RenderBlockObject, { attributes: props.attributes, blockObject: props.element, dropPosition: t0, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, schema, children: props.children }), $[18] = props.attributes, $[19] = props.children, $[20] = props.element, $[21] = props.readOnly, $[22] = props.renderBlock, $[23] = schema, $[24] = t0, $[25] = t1) : t1 = $[25], t1;
|
|
5776
5874
|
}
|
|
5777
5875
|
function _temp$3(s) {
|
|
5778
5876
|
return s.context.schema;
|
|
@@ -5786,7 +5884,9 @@ function RenderSpan(props) {
|
|
|
5786
5884
|
name: schema.span.name,
|
|
5787
5885
|
fields: t0
|
|
5788
5886
|
}, $[1] = schema.span.name, $[2] = t1) : t1 = $[2];
|
|
5789
|
-
const schemaType = t1, parent2 = props.children.props.parent, block = parent2 &&
|
|
5887
|
+
const schemaType = t1, parent2 = props.children.props.parent, block = parent2 && isTextBlock({
|
|
5888
|
+
schema: slateEditor.schema
|
|
5889
|
+
}, parent2) ? parent2 : void 0;
|
|
5790
5890
|
let t2;
|
|
5791
5891
|
$[3] !== block || $[4] !== props.leaf._key ? (t2 = block ? [{
|
|
5792
5892
|
_key: block._key
|
|
@@ -6875,50 +6975,20 @@ function stopActor(actorRef) {
|
|
|
6875
6975
|
ref._processingStatus = 0, ref._snapshot = snapshot;
|
|
6876
6976
|
});
|
|
6877
6977
|
}
|
|
6878
|
-
|
|
6879
|
-
return isText(value, schema) || isElement(value, schema) || isEditor(value) || isObjectNode(value, schema);
|
|
6880
|
-
}
|
|
6881
|
-
function isNodeList(value, schema) {
|
|
6882
|
-
return Array.isArray(value) && value.every((val) => isNode(val, schema));
|
|
6883
|
-
}
|
|
6884
|
-
const FocusedContext = createContext(!1), REACT_MAJOR_VERSION = parseInt(React.version.split(".")[0], 10), Slate = (props) => {
|
|
6978
|
+
const Slate = (props) => {
|
|
6885
6979
|
const {
|
|
6886
6980
|
editor,
|
|
6887
|
-
children
|
|
6888
|
-
|
|
6889
|
-
onSelectionChange,
|
|
6890
|
-
onValueChange,
|
|
6891
|
-
initialValue,
|
|
6892
|
-
...rest
|
|
6893
|
-
} = props;
|
|
6894
|
-
React.useState(() => {
|
|
6895
|
-
if (!isNodeList(initialValue, editor.schema))
|
|
6896
|
-
throw new Error(`[Slate] initialValue is invalid! Expected a list of elements but got: ${safeStringify(initialValue)}`);
|
|
6897
|
-
if (!isEditor(editor))
|
|
6898
|
-
throw new Error(`[Slate] editor is invalid! You passed: ${safeStringify(editor)}`);
|
|
6899
|
-
editor.children = initialValue, Object.assign(editor, rest);
|
|
6900
|
-
});
|
|
6901
|
-
const {
|
|
6981
|
+
children
|
|
6982
|
+
} = props, {
|
|
6902
6983
|
selectorContext,
|
|
6903
6984
|
onChange: handleSelectorChange
|
|
6904
6985
|
} = useSelectorContext(), onContextChange = useCallback(() => {
|
|
6905
|
-
|
|
6906
|
-
}, [editor, handleSelectorChange
|
|
6907
|
-
useEffect(() => (editor.onContextChange = onContextChange, () => {
|
|
6986
|
+
handleSelectorChange();
|
|
6987
|
+
}, [editor, handleSelectorChange]);
|
|
6988
|
+
return useEffect(() => (editor.onContextChange = onContextChange, () => {
|
|
6908
6989
|
editor.onContextChange = () => {
|
|
6909
6990
|
};
|
|
6910
|
-
}), [editor, onContextChange]);
|
|
6911
|
-
const [isFocused, setIsFocused] = useState(ReactEditor.isFocused(editor));
|
|
6912
|
-
return useEffect(() => {
|
|
6913
|
-
setIsFocused(ReactEditor.isFocused(editor));
|
|
6914
|
-
}, [editor]), useIsomorphicLayoutEffect(() => {
|
|
6915
|
-
const fn = () => setIsFocused(ReactEditor.isFocused(editor));
|
|
6916
|
-
return REACT_MAJOR_VERSION >= 17 ? (document.addEventListener("focusin", fn), document.addEventListener("focusout", fn), () => {
|
|
6917
|
-
document.removeEventListener("focusin", fn), document.removeEventListener("focusout", fn);
|
|
6918
|
-
}) : (document.addEventListener("focus", fn, !0), document.addEventListener("blur", fn, !0), () => {
|
|
6919
|
-
document.removeEventListener("focus", fn, !0), document.removeEventListener("blur", fn, !0);
|
|
6920
|
-
});
|
|
6921
|
-
}, [editor]), /* @__PURE__ */ jsx(SlateSelectorContext.Provider, { value: selectorContext, children: /* @__PURE__ */ jsx(EditorContext.Provider, { value: editor, children: /* @__PURE__ */ jsx(FocusedContext.Provider, { value: isFocused, children }) }) });
|
|
6991
|
+
}), [editor, onContextChange]), /* @__PURE__ */ jsx(SlateSelectorContext.Provider, { value: selectorContext, children: /* @__PURE__ */ jsx(EditorContext.Provider, { value: editor, children }) });
|
|
6922
6992
|
};
|
|
6923
6993
|
const converterJson = {
|
|
6924
6994
|
mimeType: "application/json",
|
|
@@ -7393,14 +7463,20 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7393
7463
|
try {
|
|
7394
7464
|
const activeAnnotations = [], spans = nodes(editor, {
|
|
7395
7465
|
at: editor.selection,
|
|
7396
|
-
match: (node2) =>
|
|
7466
|
+
match: (node2) => isSpan({
|
|
7467
|
+
schema: editor.schema
|
|
7468
|
+
}, node2) && node2.marks !== void 0 && Array.isArray(node2.marks) && node2.marks.length > 0
|
|
7397
7469
|
});
|
|
7398
7470
|
for (const [span, path2] of spans) {
|
|
7399
7471
|
const [block] = node(editor, path2, {
|
|
7400
7472
|
depth: 1
|
|
7401
7473
|
});
|
|
7402
|
-
|
|
7403
|
-
|
|
7474
|
+
isTextBlock({
|
|
7475
|
+
schema: editor.schema
|
|
7476
|
+
}, block) && block.markDefs?.forEach((def) => {
|
|
7477
|
+
isSpan({
|
|
7478
|
+
schema: editor.schema
|
|
7479
|
+
}, span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
|
|
7404
7480
|
});
|
|
7405
7481
|
}
|
|
7406
7482
|
return activeAnnotations;
|
|
@@ -7827,9 +7903,11 @@ function normalize(editor, options = {}) {
|
|
|
7827
7903
|
}
|
|
7828
7904
|
getDirtyPaths2(editor).length !== 0 && withoutNormalizing(editor, () => {
|
|
7829
7905
|
for (const dirtyPath of getDirtyPaths2(editor))
|
|
7830
|
-
if (hasNode(editor, dirtyPath, editor.schema)) {
|
|
7906
|
+
if (dirtyPath.length !== 0 && hasNode(editor, dirtyPath, editor.schema)) {
|
|
7831
7907
|
const entry = node(editor, dirtyPath), [entryNode, _] = entry;
|
|
7832
|
-
|
|
7908
|
+
isTextBlock({
|
|
7909
|
+
schema: editor.schema
|
|
7910
|
+
}, entryNode) && entryNode.children.length === 0 && editor.normalizeNode(entry, {
|
|
7833
7911
|
operation
|
|
7834
7912
|
});
|
|
7835
7913
|
}
|
|
@@ -7845,7 +7923,11 @@ function normalize(editor, options = {}) {
|
|
|
7845
7923
|
}))
|
|
7846
7924
|
return;
|
|
7847
7925
|
const dirtyPath = popDirtyPath(editor);
|
|
7848
|
-
if (
|
|
7926
|
+
if (dirtyPath.length === 0)
|
|
7927
|
+
editor.normalizeNode([editor, dirtyPath], {
|
|
7928
|
+
operation
|
|
7929
|
+
});
|
|
7930
|
+
else if (hasNode(editor, dirtyPath, editor.schema)) {
|
|
7849
7931
|
const entry = node(editor, dirtyPath);
|
|
7850
7932
|
editor.normalizeNode(entry, {
|
|
7851
7933
|
operation
|
|
@@ -7869,17 +7951,18 @@ function withoutNormalizing(editor, fn) {
|
|
|
7869
7951
|
}
|
|
7870
7952
|
normalize(editor);
|
|
7871
7953
|
}
|
|
7872
|
-
function isAncestorElement(value, schema) {
|
|
7873
|
-
return isObject(value) && value._type === schema.block.name;
|
|
7874
|
-
}
|
|
7875
7954
|
function extractProps(node2, schema) {
|
|
7876
|
-
if (
|
|
7955
|
+
if (isTextBlock({
|
|
7956
|
+
schema
|
|
7957
|
+
}, node2)) {
|
|
7877
7958
|
const {
|
|
7878
7959
|
children: _children,
|
|
7879
7960
|
...properties
|
|
7880
7961
|
} = node2;
|
|
7881
7962
|
return properties;
|
|
7882
|
-
} else if (
|
|
7963
|
+
} else if (isSpan({
|
|
7964
|
+
schema
|
|
7965
|
+
}, node2)) {
|
|
7883
7966
|
const {
|
|
7884
7967
|
text: _text,
|
|
7885
7968
|
...properties
|
|
@@ -7934,7 +8017,9 @@ function applySplitNode(editor, path2, position, properties) {
|
|
|
7934
8017
|
const savedSelection = editor.selection;
|
|
7935
8018
|
try {
|
|
7936
8019
|
withoutNormalizing(editor, () => {
|
|
7937
|
-
if (
|
|
8020
|
+
if (isSpan({
|
|
8021
|
+
schema: editor.schema
|
|
8022
|
+
}, node2)) {
|
|
7938
8023
|
const afterText = node2.text.slice(position), newNode = {
|
|
7939
8024
|
...properties,
|
|
7940
8025
|
text: afterText
|
|
@@ -7949,16 +8034,18 @@ function applySplitNode(editor, path2, position, properties) {
|
|
|
7949
8034
|
path: nextPath(path2),
|
|
7950
8035
|
node: newNode
|
|
7951
8036
|
});
|
|
7952
|
-
} else if (
|
|
7953
|
-
|
|
8037
|
+
} else if (isTextBlock({
|
|
8038
|
+
schema: editor.schema
|
|
8039
|
+
}, node2)) {
|
|
8040
|
+
const children = node2.children, afterChildren = children.slice(position), newNode = {
|
|
7954
8041
|
...properties,
|
|
7955
8042
|
children: afterChildren
|
|
7956
8043
|
};
|
|
7957
|
-
for (let i =
|
|
8044
|
+
for (let i = children.length - 1; i >= position; i--)
|
|
7958
8045
|
editor.apply({
|
|
7959
8046
|
type: "remove_node",
|
|
7960
8047
|
path: [...path2, i],
|
|
7961
|
-
node:
|
|
8048
|
+
node: children[i]
|
|
7962
8049
|
});
|
|
7963
8050
|
editor.apply({
|
|
7964
8051
|
type: "insert_node",
|
|
@@ -8002,11 +8089,19 @@ function applyInsertNodeAtPath(editor, node2, path2) {
|
|
|
8002
8089
|
}
|
|
8003
8090
|
function applyInsertNodeAtPoint(editor, node2, at) {
|
|
8004
8091
|
withoutNormalizing(editor, () => {
|
|
8005
|
-
const match2 =
|
|
8092
|
+
const match2 = isSpan({
|
|
8093
|
+
schema: editor.schema
|
|
8094
|
+
}, node2) ? (n2) => isSpan({
|
|
8095
|
+
schema: editor.schema
|
|
8096
|
+
}, n2) : (n2) => isSpan({
|
|
8097
|
+
schema: editor.schema
|
|
8098
|
+
}, n2) || isObjectNode({
|
|
8099
|
+
schema: editor.schema
|
|
8100
|
+
}, n2), [entry] = nodes(editor, {
|
|
8006
8101
|
at: at.path,
|
|
8007
8102
|
match: match2,
|
|
8008
8103
|
mode: "lowest",
|
|
8009
|
-
|
|
8104
|
+
includeObjectNodes: !1
|
|
8010
8105
|
});
|
|
8011
8106
|
if (!entry)
|
|
8012
8107
|
return;
|
|
@@ -8085,7 +8180,9 @@ function applyMergeNode(editor, path2, position) {
|
|
|
8085
8180
|
editorAny.pendingDiffs = [], editorAny.pendingSelection = null, editorAny.pendingAction = null;
|
|
8086
8181
|
try {
|
|
8087
8182
|
withoutNormalizing(editor, () => {
|
|
8088
|
-
if (
|
|
8183
|
+
if (isSpan({
|
|
8184
|
+
schema: editor.schema
|
|
8185
|
+
}, node2))
|
|
8089
8186
|
node2.text.length > 0 && editor.apply({
|
|
8090
8187
|
type: "insert_text",
|
|
8091
8188
|
path: prevPath,
|
|
@@ -8096,13 +8193,14 @@ function applyMergeNode(editor, path2, position) {
|
|
|
8096
8193
|
path: path2,
|
|
8097
8194
|
node: node2
|
|
8098
8195
|
});
|
|
8099
|
-
else if (
|
|
8100
|
-
|
|
8101
|
-
|
|
8196
|
+
else if (isTextBlock({
|
|
8197
|
+
schema: editor.schema
|
|
8198
|
+
}, node2)) {
|
|
8199
|
+
for (let i = 0; i < node2.children.length; i++)
|
|
8102
8200
|
editor.apply({
|
|
8103
8201
|
type: "insert_node",
|
|
8104
8202
|
path: [...prevPath, position + i],
|
|
8105
|
-
node: children[i]
|
|
8203
|
+
node: node2.children[i]
|
|
8106
8204
|
});
|
|
8107
8205
|
editor.apply({
|
|
8108
8206
|
type: "remove_node",
|
|
@@ -8163,7 +8261,11 @@ function transformPointForMerge(point2, mergePath, position) {
|
|
|
8163
8261
|
function applySetNode(editor, props, path2) {
|
|
8164
8262
|
const node2 = getNode(editor, path2, editor.schema), propsRecord = props, properties = {}, newProperties = {};
|
|
8165
8263
|
for (const key of Object.keys(propsRecord))
|
|
8166
|
-
key !== "children" && (key === "text" && !
|
|
8264
|
+
key !== "children" && (key === "text" && !isTextBlock({
|
|
8265
|
+
schema: editor.schema
|
|
8266
|
+
}, node2) && !isObjectNode({
|
|
8267
|
+
schema: editor.schema
|
|
8268
|
+
}, node2) || propsRecord[key] !== node2[key] && (node2.hasOwnProperty(key) && (properties[key] = node2[key]), propsRecord[key] != null && (newProperties[key] = propsRecord[key])));
|
|
8167
8269
|
(Object.keys(newProperties).length > 0 || Object.keys(properties).length > 0) && editor.apply({
|
|
8168
8270
|
type: "set_node",
|
|
8169
8271
|
path: path2,
|
|
@@ -8171,18 +8273,15 @@ function applySetNode(editor, props, path2) {
|
|
|
8171
8273
|
newProperties
|
|
8172
8274
|
});
|
|
8173
8275
|
}
|
|
8174
|
-
function getAncestor(root, path2, schema) {
|
|
8175
|
-
const node2 = getNode(root, path2, schema);
|
|
8176
|
-
if (isText(node2, schema) || isObjectNode(node2, schema))
|
|
8177
|
-
throw new Error(`Cannot get the ancestor node at path [${path2}] because it refers to a leaf node instead: ${safeStringify(node2)}`);
|
|
8178
|
-
return node2;
|
|
8179
|
-
}
|
|
8180
8276
|
function* getChildren(root, path2, schema, options = {}) {
|
|
8181
8277
|
const {
|
|
8182
8278
|
reverse = !1
|
|
8183
|
-
} = options, ancestor =
|
|
8184
|
-
|
|
8185
|
-
|
|
8279
|
+
} = options, ancestor = path2.length === 0 ? root : getNode(root, path2, schema);
|
|
8280
|
+
if (!isTextBlock({
|
|
8281
|
+
schema
|
|
8282
|
+
}, ancestor))
|
|
8283
|
+
return;
|
|
8284
|
+
const children = ancestor.children;
|
|
8186
8285
|
let index = reverse ? children.length - 1 : 0;
|
|
8187
8286
|
for (; reverse ? index >= 0 : index < children.length; ) {
|
|
8188
8287
|
const child = getChild(ancestor, index, schema), childPath = path2.concat(index);
|
|
@@ -8209,11 +8308,17 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8209
8308
|
withNormalizeNode(editor, () => {
|
|
8210
8309
|
applyInsertNodeAtPath(editor, createPlaceholderBlock(editorActor.getSnapshot().context), [0]);
|
|
8211
8310
|
});
|
|
8212
|
-
}),
|
|
8311
|
+
}), isTextBlock({
|
|
8312
|
+
schema: editor.schema
|
|
8313
|
+
}, node$1)) {
|
|
8213
8314
|
const children = getChildren(editor, path2, editor.schema);
|
|
8214
8315
|
for (const [child, childPath] of children) {
|
|
8215
8316
|
const nextNode = node$1.children[childPath[1] + 1];
|
|
8216
|
-
if (
|
|
8317
|
+
if (isSpan({
|
|
8318
|
+
schema: editor.schema
|
|
8319
|
+
}, child) && isSpan({
|
|
8320
|
+
schema: editor.schema
|
|
8321
|
+
}, nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
8217
8322
|
debug$1.normalization("merging spans with same marks"), withNormalizeNode(editor, () => {
|
|
8218
8323
|
const mergePath = [childPath[0], childPath[1] + 1];
|
|
8219
8324
|
applyMergeNode(editor, mergePath, child.text.length);
|
|
@@ -8222,7 +8327,9 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8222
8327
|
}
|
|
8223
8328
|
}
|
|
8224
8329
|
}
|
|
8225
|
-
if (
|
|
8330
|
+
if (isTextBlock({
|
|
8331
|
+
schema: editor.schema
|
|
8332
|
+
}, node$1) && !Array.isArray(node$1.markDefs)) {
|
|
8226
8333
|
debug$1.normalization("adding .markDefs to block node"), withNormalizeNode(editor, () => {
|
|
8227
8334
|
applySetNode(editor, {
|
|
8228
8335
|
markDefs: []
|
|
@@ -8230,7 +8337,9 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8230
8337
|
});
|
|
8231
8338
|
return;
|
|
8232
8339
|
}
|
|
8233
|
-
if (defaultStyle &&
|
|
8340
|
+
if (defaultStyle && isTextBlock({
|
|
8341
|
+
schema: editor.schema
|
|
8342
|
+
}, node$1) && typeof node$1.style > "u") {
|
|
8234
8343
|
debug$1.normalization("adding .style to block node"), withNormalizeNode(editor, () => {
|
|
8235
8344
|
applySetNode(editor, {
|
|
8236
8345
|
style: defaultStyle
|
|
@@ -8238,7 +8347,9 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8238
8347
|
});
|
|
8239
8348
|
return;
|
|
8240
8349
|
}
|
|
8241
|
-
if (
|
|
8350
|
+
if (isSpan({
|
|
8351
|
+
schema: editor.schema
|
|
8352
|
+
}, node$1) && !Array.isArray(node$1.marks)) {
|
|
8242
8353
|
debug$1.normalization("Adding .marks to span node"), withNormalizeNode(editor, () => {
|
|
8243
8354
|
applySetNode(editor, {
|
|
8244
8355
|
marks: []
|
|
@@ -8246,9 +8357,13 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8246
8357
|
});
|
|
8247
8358
|
return;
|
|
8248
8359
|
}
|
|
8249
|
-
if (
|
|
8360
|
+
if (isSpan({
|
|
8361
|
+
schema: editor.schema
|
|
8362
|
+
}, node$1)) {
|
|
8250
8363
|
const blockPath = parentPath(path2), [block] = node(editor, blockPath), decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node$1.marks?.filter((mark) => !decorators.includes(mark));
|
|
8251
|
-
if (
|
|
8364
|
+
if (isTextBlock({
|
|
8365
|
+
schema: editor.schema
|
|
8366
|
+
}, block) && node$1.text === "" && annotations && annotations.length > 0) {
|
|
8252
8367
|
debug$1.normalization("removing annotations from empty span node"), withNormalizeNode(editor, () => {
|
|
8253
8368
|
applySetNode(editor, {
|
|
8254
8369
|
marks: node$1.marks?.filter((mark) => decorators.includes(mark))
|
|
@@ -8257,10 +8372,14 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8257
8372
|
return;
|
|
8258
8373
|
}
|
|
8259
8374
|
}
|
|
8260
|
-
if (
|
|
8375
|
+
if (isTextBlock({
|
|
8376
|
+
schema: editor.schema
|
|
8377
|
+
}, node$1)) {
|
|
8261
8378
|
const decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name);
|
|
8262
8379
|
for (const [child, childPath] of getChildren(editor, path2, editor.schema))
|
|
8263
|
-
if (
|
|
8380
|
+
if (isSpan({
|
|
8381
|
+
schema: editor.schema
|
|
8382
|
+
}, child)) {
|
|
8264
8383
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !node$1.markDefs?.find((def) => def._key === mark));
|
|
8265
8384
|
if (orphanedAnnotations.length > 0) {
|
|
8266
8385
|
debug$1.normalization("removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
@@ -8272,9 +8391,13 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8272
8391
|
}
|
|
8273
8392
|
}
|
|
8274
8393
|
}
|
|
8275
|
-
if (
|
|
8394
|
+
if (isSpan({
|
|
8395
|
+
schema: editor.schema
|
|
8396
|
+
}, node$1)) {
|
|
8276
8397
|
const blockPath = parentPath(path2), [block] = node(editor, blockPath);
|
|
8277
|
-
if (
|
|
8398
|
+
if (isTextBlock({
|
|
8399
|
+
schema: editor.schema
|
|
8400
|
+
}, block)) {
|
|
8278
8401
|
const decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node$1.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
8279
8402
|
if (orphanedAnnotations.length > 0) {
|
|
8280
8403
|
debug$1.normalization("removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
@@ -8286,7 +8409,9 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8286
8409
|
}
|
|
8287
8410
|
}
|
|
8288
8411
|
}
|
|
8289
|
-
if (
|
|
8412
|
+
if (isTextBlock({
|
|
8413
|
+
schema: editor.schema
|
|
8414
|
+
}, node$1)) {
|
|
8290
8415
|
const markDefs = node$1.markDefs ?? [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
|
|
8291
8416
|
for (const markDef of markDefs)
|
|
8292
8417
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
@@ -8299,8 +8424,12 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8299
8424
|
return;
|
|
8300
8425
|
}
|
|
8301
8426
|
}
|
|
8302
|
-
if (
|
|
8303
|
-
|
|
8427
|
+
if (isTextBlock({
|
|
8428
|
+
schema: editor.schema
|
|
8429
|
+
}, node$1)) {
|
|
8430
|
+
const newMarkDefs = (node$1.markDefs || []).filter((def) => node$1.children.find((child) => isSpan({
|
|
8431
|
+
schema: editor.schema
|
|
8432
|
+
}, child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
8304
8433
|
if (node$1.markDefs && !isEqualMarkDefs(newMarkDefs, node$1.markDefs)) {
|
|
8305
8434
|
debug$1.normalization("removing markDef not in use"), withNormalizeNode(editor, () => {
|
|
8306
8435
|
applySetNode(editor, {
|
|
@@ -8335,13 +8464,17 @@ function createNormalizationPlugin(editorActor) {
|
|
|
8335
8464
|
const focusSpan = Array.from(nodes(editor, {
|
|
8336
8465
|
mode: "lowest",
|
|
8337
8466
|
at: op.properties.focus,
|
|
8338
|
-
match: (n2) =>
|
|
8339
|
-
|
|
8467
|
+
match: (n2) => isSpan({
|
|
8468
|
+
schema: editor.schema
|
|
8469
|
+
}, n2),
|
|
8470
|
+
includeObjectNodes: !1
|
|
8340
8471
|
}))[0]?.[0], newFocusSpan = Array.from(nodes(editor, {
|
|
8341
8472
|
mode: "lowest",
|
|
8342
8473
|
at: op.newProperties.focus,
|
|
8343
|
-
match: (n2) =>
|
|
8344
|
-
|
|
8474
|
+
match: (n2) => isSpan({
|
|
8475
|
+
schema: editor.schema
|
|
8476
|
+
}, n2),
|
|
8477
|
+
includeObjectNodes: !1
|
|
8345
8478
|
}))[0]?.[0], movedToNextSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] + 1 && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] - 1 && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
|
|
8346
8479
|
!movedToNextSpan && !movedToPreviousSpan && (editor.decoratorState = {});
|
|
8347
8480
|
}
|
|
@@ -9014,7 +9147,9 @@ function toSlateBlock(block, {
|
|
|
9014
9147
|
...childProps
|
|
9015
9148
|
}) : child;
|
|
9016
9149
|
});
|
|
9017
|
-
return !hasMissingMarkDefs && !hasMissingChildren && !hasInlines2 &&
|
|
9150
|
+
return !hasMissingMarkDefs && !hasMissingChildren && !hasInlines2 && isTextBlock({
|
|
9151
|
+
schema: schemaTypes
|
|
9152
|
+
}, block) ? block : {
|
|
9018
9153
|
_type,
|
|
9019
9154
|
_key,
|
|
9020
9155
|
...rest,
|
|
@@ -9037,10 +9172,14 @@ function isEqualToEmptyEditor(initialValue, blocks, schemaTypes) {
|
|
|
9037
9172
|
const firstBlock = blocks.at(0);
|
|
9038
9173
|
if (!firstBlock)
|
|
9039
9174
|
return !0;
|
|
9040
|
-
if (!
|
|
9175
|
+
if (!isTextBlock({
|
|
9176
|
+
schema: schemaTypes
|
|
9177
|
+
}, firstBlock) || firstBlock._type !== schemaTypes.block.name || "listItem" in firstBlock || !("style" in firstBlock) || firstBlock.style !== schemaTypes.styles.at(0)?.name || !Array.isArray(firstBlock.children) || firstBlock.children.length !== 1)
|
|
9041
9178
|
return !1;
|
|
9042
9179
|
const firstChild = firstBlock.children.at(0);
|
|
9043
|
-
return !(!firstChild || !
|
|
9180
|
+
return !(!firstChild || !isSpan({
|
|
9181
|
+
schema: schemaTypes
|
|
9182
|
+
}, firstChild) || !("_type" in firstChild) || firstChild._type !== schemaTypes.span.name || firstChild.text !== "" || firstChild.marks?.join("") || "markDefs" in firstBlock && Array.isArray(firstBlock.markDefs) && firstBlock.markDefs.length > 0 || Object.keys(firstBlock).some((key) => key !== "_type" && key !== "_key" && key !== "children" && key !== "markDefs" && key !== "style") || isEqualValues({
|
|
9044
9183
|
schema: schemaTypes
|
|
9045
9184
|
}, initialValue, [firstBlock]));
|
|
9046
9185
|
}
|
|
@@ -9076,7 +9215,11 @@ function diffMatchPatch(editor, patch) {
|
|
|
9076
9215
|
if (!block)
|
|
9077
9216
|
return !1;
|
|
9078
9217
|
const child = findBlockChild(block, patch.path, editor.schema);
|
|
9079
|
-
if (!child || !(block &&
|
|
9218
|
+
if (!child || !(block && isTextBlock({
|
|
9219
|
+
schema: editor.schema
|
|
9220
|
+
}, block.node) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !isSpan({
|
|
9221
|
+
schema: editor.schema
|
|
9222
|
+
}, child.node))
|
|
9080
9223
|
return !1;
|
|
9081
9224
|
const patches = parse(patch.value), [newValue] = apply$1(patches, child.node.text, {
|
|
9082
9225
|
allowExceedingIndices: !0
|
|
@@ -9145,7 +9288,9 @@ function insertPatch(context, editor, patch) {
|
|
|
9145
9288
|
}, {
|
|
9146
9289
|
schemaTypes: context.schema
|
|
9147
9290
|
}), normalizedIdx = position === "after" ? targetChild.index + 1 : targetChild.index, childInsertPath = [block.index, normalizedIdx];
|
|
9148
|
-
return childrenToInsert &&
|
|
9291
|
+
return childrenToInsert && isTextBlock({
|
|
9292
|
+
schema: editor.schema
|
|
9293
|
+
}, childrenToInsert) && childrenToInsert.children.forEach((node2, i) => {
|
|
9149
9294
|
editor.apply({
|
|
9150
9295
|
type: "insert_node",
|
|
9151
9296
|
path: [childInsertPath[0], childInsertPath[1] + i],
|
|
@@ -9159,13 +9304,19 @@ function setPatch(editor, patch) {
|
|
|
9159
9304
|
const block = findBlock(editor.children, patch.path);
|
|
9160
9305
|
if (!block)
|
|
9161
9306
|
return !1;
|
|
9162
|
-
const
|
|
9307
|
+
const blockIsTextBlock = isTextBlock({
|
|
9308
|
+
schema: editor.schema
|
|
9309
|
+
}, block.node);
|
|
9163
9310
|
if (patch.path.length === 1) {
|
|
9164
9311
|
const updatedBlock = applyAll(block.node, [{
|
|
9165
9312
|
...patch,
|
|
9166
9313
|
path: patch.path.slice(1)
|
|
9167
9314
|
}]);
|
|
9168
|
-
if (
|
|
9315
|
+
if (isTextBlock({
|
|
9316
|
+
schema: editor.schema
|
|
9317
|
+
}, block.node) && isTextBlock({
|
|
9318
|
+
schema: editor.schema
|
|
9319
|
+
}, updatedBlock)) {
|
|
9169
9320
|
applySetNode(editor, updatedBlock, [block.index]);
|
|
9170
9321
|
const previousSelection = editor.selection, childPaths = Array.from(nodes(editor, {
|
|
9171
9322
|
at: [block.index],
|
|
@@ -9193,7 +9344,7 @@ function setPatch(editor, patch) {
|
|
|
9193
9344
|
} else
|
|
9194
9345
|
return applySetNode(editor, updatedBlock, [block.index]), !0;
|
|
9195
9346
|
}
|
|
9196
|
-
if (
|
|
9347
|
+
if (blockIsTextBlock && patch.path[1] !== "children") {
|
|
9197
9348
|
const updatedBlock = applyAll(block.node, [{
|
|
9198
9349
|
...patch,
|
|
9199
9350
|
path: patch.path.slice(1)
|
|
@@ -9201,8 +9352,10 @@ function setPatch(editor, patch) {
|
|
|
9201
9352
|
return applySetNode(editor, updatedBlock, [block.index]), !0;
|
|
9202
9353
|
}
|
|
9203
9354
|
const child = findBlockChild(block, patch.path, editor.schema);
|
|
9204
|
-
if (
|
|
9205
|
-
if (
|
|
9355
|
+
if (blockIsTextBlock && child) {
|
|
9356
|
+
if (isSpan({
|
|
9357
|
+
schema: editor.schema
|
|
9358
|
+
}, child.node))
|
|
9206
9359
|
if (value !== null && typeof value == "object" && "text" in value && typeof value.text == "string") {
|
|
9207
9360
|
if (patch.type === "setIfMissing")
|
|
9208
9361
|
return !1;
|
|
@@ -9239,7 +9392,7 @@ function setPatch(editor, patch) {
|
|
|
9239
9392
|
applySetNode(editor, newNode, [block.index, child.index]);
|
|
9240
9393
|
}
|
|
9241
9394
|
return !0;
|
|
9242
|
-
} else if (block && !
|
|
9395
|
+
} else if (block && !blockIsTextBlock)
|
|
9243
9396
|
if (patch.path.length > 1 && patch.path[1] !== "children") {
|
|
9244
9397
|
const newVal = applyAll(block.node, [{
|
|
9245
9398
|
...patch,
|
|
@@ -9276,7 +9429,9 @@ function unsetPatch(editor, patch) {
|
|
|
9276
9429
|
}), !0;
|
|
9277
9430
|
}
|
|
9278
9431
|
const child = findBlockChild(block, patch.path, editor.schema);
|
|
9279
|
-
if (
|
|
9432
|
+
if (isTextBlock({
|
|
9433
|
+
schema: editor.schema
|
|
9434
|
+
}, block.node) && child && patch.path[1] === "children" && patch.path.length === 3) {
|
|
9280
9435
|
const [childNode] = node(editor, [block.index, child.index]);
|
|
9281
9436
|
return editor.apply({
|
|
9282
9437
|
type: "remove_node",
|
|
@@ -9284,7 +9439,11 @@ function unsetPatch(editor, patch) {
|
|
|
9284
9439
|
node: childNode
|
|
9285
9440
|
}), !0;
|
|
9286
9441
|
}
|
|
9287
|
-
if (child && (
|
|
9442
|
+
if (child && (isTextBlock({
|
|
9443
|
+
schema: editor.schema
|
|
9444
|
+
}, child.node) || isObjectNode({
|
|
9445
|
+
schema: editor.schema
|
|
9446
|
+
}, child.node))) {
|
|
9288
9447
|
const propEntry = patch.path.slice(3).at(0);
|
|
9289
9448
|
if (propEntry === void 0 || typeof propEntry == "string" && ["_key", "_type", "children"].includes(propEntry))
|
|
9290
9449
|
return !1;
|
|
@@ -9301,7 +9460,9 @@ function unsetPatch(editor, patch) {
|
|
|
9301
9460
|
applySetNode(editor, newNode, [block.index, child.index]);
|
|
9302
9461
|
return !0;
|
|
9303
9462
|
}
|
|
9304
|
-
if (child &&
|
|
9463
|
+
if (child && isSpan({
|
|
9464
|
+
schema: editor.schema
|
|
9465
|
+
}, child.node)) {
|
|
9305
9466
|
const propPath = patch.path.slice(3), propEntry = propPath.at(0);
|
|
9306
9467
|
if (propEntry === void 0 || typeof propEntry == "string" && ["_key", "_type"].includes(propEntry))
|
|
9307
9468
|
return !1;
|
|
@@ -9321,7 +9482,9 @@ function unsetPatch(editor, patch) {
|
|
|
9321
9482
|
return applySetNode(editor, unsetProps, [block.index, child.index]), !0;
|
|
9322
9483
|
}
|
|
9323
9484
|
if (!child) {
|
|
9324
|
-
if (!
|
|
9485
|
+
if (!isTextBlock({
|
|
9486
|
+
schema: editor.schema
|
|
9487
|
+
}, block.node)) {
|
|
9325
9488
|
const newVal = applyAll(block.node, [{
|
|
9326
9489
|
...patch,
|
|
9327
9490
|
path: patch.path.slice(1)
|
|
@@ -9335,7 +9498,9 @@ function unsetPatch(editor, patch) {
|
|
|
9335
9498
|
applySetNode(editor, newVal, [block.index]);
|
|
9336
9499
|
return !0;
|
|
9337
9500
|
}
|
|
9338
|
-
if (
|
|
9501
|
+
if (isTextBlock({
|
|
9502
|
+
schema: editor.schema
|
|
9503
|
+
}, block.node)) {
|
|
9339
9504
|
const propPath = patch.path.slice(1), propEntry = propPath.at(0);
|
|
9340
9505
|
if (propEntry === void 0 || typeof propEntry != "string" || ["_key", "_type", "children"].includes(propEntry))
|
|
9341
9506
|
return !1;
|
|
@@ -9372,7 +9537,9 @@ function findBlock(children, path2) {
|
|
|
9372
9537
|
}
|
|
9373
9538
|
function findBlockChild(block, path2, schema) {
|
|
9374
9539
|
const blockNode = block.node;
|
|
9375
|
-
if (!
|
|
9540
|
+
if (!isTextBlock({
|
|
9541
|
+
schema
|
|
9542
|
+
}, blockNode) || path2[1] !== "children")
|
|
9376
9543
|
return;
|
|
9377
9544
|
let childIndex = -1;
|
|
9378
9545
|
const child = blockNode.children.find((node2, index) => {
|
|
@@ -9473,7 +9640,9 @@ function setNodePatch(schema, children, operation) {
|
|
|
9473
9640
|
const child = block.children[operation.path[1]];
|
|
9474
9641
|
if (child) {
|
|
9475
9642
|
const blockKey = block._key, childKey = child._key, patches = [];
|
|
9476
|
-
if (
|
|
9643
|
+
if (isTextBlock({
|
|
9644
|
+
schema
|
|
9645
|
+
}, child)) {
|
|
9477
9646
|
const _key = operation.newProperties._key;
|
|
9478
9647
|
_key !== void 0 && patches.push(set(_key, [{
|
|
9479
9648
|
_key: blockKey
|
|
@@ -9533,7 +9702,9 @@ function insertNodePatch(schema, children, operation, beforeValue) {
|
|
|
9533
9702
|
}], setIfMissingPatch = setIfMissing([], [{
|
|
9534
9703
|
_key: block._key
|
|
9535
9704
|
}, "children"]);
|
|
9536
|
-
return
|
|
9705
|
+
return isSpan({
|
|
9706
|
+
schema
|
|
9707
|
+
}, operation.node) ? [setIfMissingPatch, insert([operation.node], position, path2)] : [setIfMissingPatch, insert([operation.node], position, path2)];
|
|
9537
9708
|
}
|
|
9538
9709
|
return [];
|
|
9539
9710
|
}
|
|
@@ -9657,12 +9828,7 @@ function createSchemaPlugin({
|
|
|
9657
9828
|
editorActor
|
|
9658
9829
|
}) {
|
|
9659
9830
|
return function(editor) {
|
|
9660
|
-
editor.
|
|
9661
|
-
if (!isObject(value) || isEditor(value))
|
|
9662
|
-
return !1;
|
|
9663
|
-
const obj = value;
|
|
9664
|
-
return typeof obj._type == "string" && obj._type !== editor.schema.block.name && obj._type !== editor.schema.span.name;
|
|
9665
|
-
}, editor.isInline = (element) => {
|
|
9831
|
+
editor.schema = editorActor.getSnapshot().context.schema, editor.isInline = (element) => {
|
|
9666
9832
|
if (isEditor(element))
|
|
9667
9833
|
return !1;
|
|
9668
9834
|
const snapshot = editorActor.getSnapshot();
|
|
@@ -9680,6 +9846,10 @@ function createSchemaPlugin({
|
|
|
9680
9846
|
} = editor;
|
|
9681
9847
|
return editor.normalizeNode = (entry) => {
|
|
9682
9848
|
const [node2, path2] = entry;
|
|
9849
|
+
if (isEditor(node2)) {
|
|
9850
|
+
normalizeNode2(entry);
|
|
9851
|
+
return;
|
|
9852
|
+
}
|
|
9683
9853
|
if (node2._type === void 0 && path2.length === 2) {
|
|
9684
9854
|
debug$1.normalization("Setting span type on text node without a type");
|
|
9685
9855
|
const span = node2, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
@@ -9708,6 +9878,10 @@ function createSchemaPlugin({
|
|
|
9708
9878
|
}, editor;
|
|
9709
9879
|
};
|
|
9710
9880
|
}
|
|
9881
|
+
function parent(editor, at, options = {}) {
|
|
9882
|
+
const nodePath = path(editor, at, options), parentPath_ = parentPath(nodePath);
|
|
9883
|
+
return parentPath_.length === 0 ? [editor, parentPath_] : node(editor, parentPath_);
|
|
9884
|
+
}
|
|
9711
9885
|
function createUniqueKeysPlugin(editorActor) {
|
|
9712
9886
|
const context = editorActor.getSnapshot().context;
|
|
9713
9887
|
return function(editor) {
|
|
@@ -9744,7 +9918,11 @@ function createUniqueKeysPlugin(editorActor) {
|
|
|
9744
9918
|
apply2(operation);
|
|
9745
9919
|
}, editor.normalizeNode = (entry) => {
|
|
9746
9920
|
const [node2, path2] = entry;
|
|
9747
|
-
if (
|
|
9921
|
+
if (isTextBlock({
|
|
9922
|
+
schema: editor.schema
|
|
9923
|
+
}, node2) || isObjectNode({
|
|
9924
|
+
schema: editor.schema
|
|
9925
|
+
}, node2)) {
|
|
9748
9926
|
const [parentNode] = parent(editor, path2);
|
|
9749
9927
|
if (parentNode && isEditor(parentNode)) {
|
|
9750
9928
|
const blockKeys = /* @__PURE__ */ new Set();
|
|
@@ -9771,7 +9949,9 @@ function createUniqueKeysPlugin(editorActor) {
|
|
|
9771
9949
|
}
|
|
9772
9950
|
}
|
|
9773
9951
|
}
|
|
9774
|
-
if (
|
|
9952
|
+
if (isTextBlock({
|
|
9953
|
+
schema: editor.schema
|
|
9954
|
+
}, node2)) {
|
|
9775
9955
|
if (!node2._key) {
|
|
9776
9956
|
withNormalizeNode(editor, () => {
|
|
9777
9957
|
applySetNode(editor, {
|
|
@@ -9978,22 +10158,36 @@ const insertChildren = (xs, index, ...newValues) => [...xs.slice(0, index), ...n
|
|
|
9978
10158
|
const index2 = slicedPath.pop(), ancestorNode = getNode(root, slicedPath, schema);
|
|
9979
10159
|
modifiedNode = {
|
|
9980
10160
|
...ancestorNode,
|
|
9981
|
-
children: replaceChildren(
|
|
10161
|
+
children: replaceChildren(isTextBlock({
|
|
10162
|
+
schema
|
|
10163
|
+
}, ancestorNode) ? ancestorNode.children : [], index2, 1, modifiedNode)
|
|
9982
10164
|
};
|
|
9983
10165
|
}
|
|
9984
|
-
const index = slicedPath.pop()
|
|
9985
|
-
|
|
10166
|
+
const index = slicedPath.pop(), newRootChildren = replaceChildren(isEditor(root) || isTextBlock({
|
|
10167
|
+
schema
|
|
10168
|
+
}, root) ? root.children : [], index, 1, modifiedNode);
|
|
10169
|
+
root.children = newRootChildren;
|
|
9986
10170
|
}, modifyChildren = (root, path2, schema, f) => {
|
|
9987
|
-
path2.length === 0 ? root.children = f(root
|
|
9988
|
-
|
|
10171
|
+
path2.length === 0 ? root.children = f(isEditor(root) || isTextBlock({
|
|
10172
|
+
schema
|
|
10173
|
+
}, root) ? root.children : []) : modifyDescendant(root, path2, schema, (node2) => {
|
|
10174
|
+
if (isSpan({
|
|
10175
|
+
schema
|
|
10176
|
+
}, node2) || isObjectNode({
|
|
10177
|
+
schema
|
|
10178
|
+
}, node2))
|
|
9989
10179
|
throw new Error(`Cannot get the element at path [${path2}] because it refers to a leaf node: ${safeStringify(node2)}`);
|
|
9990
10180
|
return {
|
|
9991
10181
|
...node2,
|
|
9992
|
-
children: f(
|
|
10182
|
+
children: f(isTextBlock({
|
|
10183
|
+
schema
|
|
10184
|
+
}, node2) ? node2.children : [])
|
|
9993
10185
|
};
|
|
9994
10186
|
});
|
|
9995
10187
|
}, modifyLeaf = (root, path2, schema, f) => modifyDescendant(root, path2, schema, (node2) => {
|
|
9996
|
-
if (!
|
|
10188
|
+
if (!isSpan({
|
|
10189
|
+
schema
|
|
10190
|
+
}, node2))
|
|
9997
10191
|
throw new Error(`Cannot get the leaf node at path [${path2}] because it refers to a non-leaf node: ${safeStringify(node2)}`);
|
|
9998
10192
|
return f(node2);
|
|
9999
10193
|
});
|
|
@@ -10093,11 +10287,11 @@ function applyOperation(editor, op) {
|
|
|
10093
10287
|
modifyDescendant(editor, path2, editor.schema, (node2) => {
|
|
10094
10288
|
const newNode = {
|
|
10095
10289
|
...node2
|
|
10096
|
-
},
|
|
10290
|
+
}, isElement = "children" in node2 && Array.isArray(node2.children);
|
|
10097
10291
|
for (const key in newProperties) {
|
|
10098
10292
|
if (key === "children")
|
|
10099
10293
|
throw new Error(`Cannot set the "${key}" property of nodes!`);
|
|
10100
|
-
if (key === "text" && !
|
|
10294
|
+
if (key === "text" && !isElement && Array.isArray(node2.marks))
|
|
10101
10295
|
throw new Error(`Cannot set the "${key}" property of nodes!`);
|
|
10102
10296
|
const value = newProperties[key];
|
|
10103
10297
|
value == null ? delete newNode[key] : newNode[key] = value;
|
|
@@ -10219,7 +10413,9 @@ const getDirtyPaths = (_editor, op) => {
|
|
|
10219
10413
|
const {
|
|
10220
10414
|
node: node2,
|
|
10221
10415
|
path: path2
|
|
10222
|
-
} = op, levels2 = pathLevels(path2), descendants =
|
|
10416
|
+
} = op, levels2 = pathLevels(path2), descendants = isSpan({
|
|
10417
|
+
schema: _editor.schema
|
|
10418
|
+
}, node2) ? [] : Array.from(getNodes(node2, _editor.schema), ([, p]) => path2.concat(p));
|
|
10223
10419
|
return [...levels2, ...descendants];
|
|
10224
10420
|
}
|
|
10225
10421
|
case "remove_node": {
|
|
@@ -10232,6 +10428,14 @@ const getDirtyPaths = (_editor, op) => {
|
|
|
10232
10428
|
return [];
|
|
10233
10429
|
}
|
|
10234
10430
|
};
|
|
10431
|
+
function getTextBlockNode(root, path2, schema) {
|
|
10432
|
+
const node2 = getNode(root, path2, schema);
|
|
10433
|
+
if (isTextBlock({
|
|
10434
|
+
schema
|
|
10435
|
+
}, node2))
|
|
10436
|
+
return node2;
|
|
10437
|
+
throw new Error(`Cannot get the text block at path [${path2}] because it refers to a non-text-block node: ${safeStringify(node2)}`);
|
|
10438
|
+
}
|
|
10235
10439
|
function pointRef(editor, point2, options = {}) {
|
|
10236
10440
|
const {
|
|
10237
10441
|
affinity = "forward"
|
|
@@ -10251,22 +10455,23 @@ const getDefaultInsertLocation = (editor) => editor.selection ? editor.selection
|
|
|
10251
10455
|
function elementReadOnly(editor, options = {}) {
|
|
10252
10456
|
return above(editor, {
|
|
10253
10457
|
...options,
|
|
10254
|
-
match: (n2) =>
|
|
10458
|
+
match: (n2) => isTextBlock({
|
|
10459
|
+
schema: editor.schema
|
|
10460
|
+
}, n2) && editor.isElementReadOnly(n2)
|
|
10255
10461
|
});
|
|
10256
10462
|
}
|
|
10257
|
-
function previous(editor, options
|
|
10463
|
+
function previous(editor, options) {
|
|
10258
10464
|
const {
|
|
10259
10465
|
mode = "lowest",
|
|
10260
|
-
|
|
10261
|
-
} = options
|
|
10262
|
-
let {
|
|
10466
|
+
includeObjectNodes = !1
|
|
10467
|
+
} = options, {
|
|
10263
10468
|
match: match2,
|
|
10264
10469
|
at = editor.selection
|
|
10265
10470
|
} = options;
|
|
10266
10471
|
if (!at)
|
|
10267
10472
|
return;
|
|
10268
10473
|
const pointBeforeLocation = before(editor, at, {
|
|
10269
|
-
|
|
10474
|
+
includeObjectNodes
|
|
10270
10475
|
});
|
|
10271
10476
|
if (!pointBeforeLocation)
|
|
10272
10477
|
return;
|
|
@@ -10275,23 +10480,28 @@ function previous(editor, options = {}) {
|
|
|
10275
10480
|
})), span = [pointBeforeLocation.path, to];
|
|
10276
10481
|
if (isPath(at) && at.length === 0)
|
|
10277
10482
|
throw new Error("Cannot get the previous node from the root node!");
|
|
10278
|
-
if (match2 == null)
|
|
10279
|
-
if (isPath(at)) {
|
|
10280
|
-
const [parentNode] = parent(editor, at);
|
|
10281
|
-
match2 = (n2) => parentNode.children.includes(n2);
|
|
10282
|
-
} else
|
|
10283
|
-
match2 = () => !0;
|
|
10284
10483
|
const [previousEntry] = nodes(editor, {
|
|
10285
10484
|
reverse: !0,
|
|
10286
10485
|
at: span,
|
|
10287
10486
|
match: match2,
|
|
10288
10487
|
mode,
|
|
10289
|
-
|
|
10488
|
+
includeObjectNodes
|
|
10290
10489
|
});
|
|
10291
10490
|
return previousEntry;
|
|
10292
10491
|
}
|
|
10293
10492
|
function shouldMergeNodesRemovePrevNode(_editor, [prevNode, prevPath], [_curNode, _curNodePath]) {
|
|
10294
|
-
|
|
10493
|
+
let isEmptyElement = !1;
|
|
10494
|
+
if (isTextBlock({
|
|
10495
|
+
schema: _editor.schema
|
|
10496
|
+
}, prevNode)) {
|
|
10497
|
+
const prevChildren = prevNode.children;
|
|
10498
|
+
isEmptyElement = prevChildren.length === 0 || prevChildren.length === 1 && isSpan({
|
|
10499
|
+
schema: _editor.schema
|
|
10500
|
+
}, prevChildren[0]) && prevChildren[0].text === "";
|
|
10501
|
+
}
|
|
10502
|
+
return isEmptyElement || isSpan({
|
|
10503
|
+
schema: _editor.schema
|
|
10504
|
+
}, prevNode) && prevNode.text === "" && prevPath[prevPath.length - 1] !== 0;
|
|
10295
10505
|
}
|
|
10296
10506
|
function isCommonPath(path2, another) {
|
|
10297
10507
|
return path2.length <= another.length && comparePaths(path2, another) === 0;
|
|
@@ -10299,7 +10509,7 @@ function isCommonPath(path2, another) {
|
|
|
10299
10509
|
function insertText(editor, text, options = {}) {
|
|
10300
10510
|
withoutNormalizing(editor, () => {
|
|
10301
10511
|
const {
|
|
10302
|
-
|
|
10512
|
+
includeObjectNodes = !1
|
|
10303
10513
|
} = options;
|
|
10304
10514
|
let {
|
|
10305
10515
|
at = getDefaultInsertLocation(editor)
|
|
@@ -10309,14 +10519,14 @@ function insertText(editor, text, options = {}) {
|
|
|
10309
10519
|
at = at.anchor;
|
|
10310
10520
|
else {
|
|
10311
10521
|
const end2 = rangeEnd(at);
|
|
10312
|
-
if (!
|
|
10522
|
+
if (!includeObjectNodes && getObjectNode(editor, {
|
|
10313
10523
|
at: end2
|
|
10314
10524
|
}))
|
|
10315
10525
|
return;
|
|
10316
10526
|
const start2 = rangeStart(at), startRef = pointRef(editor, start2), endRef = pointRef(editor, end2);
|
|
10317
10527
|
deleteText(editor, {
|
|
10318
10528
|
at,
|
|
10319
|
-
|
|
10529
|
+
includeObjectNodes
|
|
10320
10530
|
});
|
|
10321
10531
|
const startPoint = startRef.unref(), endPoint = endRef.unref();
|
|
10322
10532
|
at = startPoint || endPoint, editor.setSelection({
|
|
@@ -10324,7 +10534,7 @@ function insertText(editor, text, options = {}) {
|
|
|
10324
10534
|
focus: at
|
|
10325
10535
|
});
|
|
10326
10536
|
}
|
|
10327
|
-
if (!
|
|
10537
|
+
if (!includeObjectNodes && getObjectNode(editor, {
|
|
10328
10538
|
at
|
|
10329
10539
|
}) || elementReadOnly(editor, {
|
|
10330
10540
|
at
|
|
@@ -10350,7 +10560,7 @@ function removeNodes(editor, options = {}) {
|
|
|
10350
10560
|
withoutNormalizing(editor, () => {
|
|
10351
10561
|
const {
|
|
10352
10562
|
hanging = !1,
|
|
10353
|
-
|
|
10563
|
+
includeObjectNodes = !1,
|
|
10354
10564
|
mode = "lowest"
|
|
10355
10565
|
} = options;
|
|
10356
10566
|
let {
|
|
@@ -10359,14 +10569,16 @@ function removeNodes(editor, options = {}) {
|
|
|
10359
10569
|
} = options;
|
|
10360
10570
|
if (!at)
|
|
10361
10571
|
return;
|
|
10362
|
-
match2 == null && (match2 = isPath(at) ? matchPath(editor, at) : (n2) =>
|
|
10363
|
-
|
|
10572
|
+
match2 == null && (match2 = isPath(at) ? matchPath(editor, at) : (n2) => isTextBlock({
|
|
10573
|
+
schema: editor.schema
|
|
10574
|
+
}, n2)), !hanging && isRange(at) && (at = unhangRange(editor, at, {
|
|
10575
|
+
includeObjectNodes
|
|
10364
10576
|
}));
|
|
10365
10577
|
const depths = nodes(editor, {
|
|
10366
10578
|
at,
|
|
10367
10579
|
match: match2,
|
|
10368
10580
|
mode,
|
|
10369
|
-
|
|
10581
|
+
includeObjectNodes
|
|
10370
10582
|
}), pathRefs = Array.from(depths, ([, p]) => pathRef(editor, p));
|
|
10371
10583
|
for (const ref of pathRefs) {
|
|
10372
10584
|
const path2 = ref.unref();
|
|
@@ -10387,7 +10599,7 @@ function deleteText(editor, options = {}) {
|
|
|
10387
10599
|
reverse = !1,
|
|
10388
10600
|
unit = "character",
|
|
10389
10601
|
distance = 1,
|
|
10390
|
-
|
|
10602
|
+
includeObjectNodes = !1
|
|
10391
10603
|
} = options;
|
|
10392
10604
|
let {
|
|
10393
10605
|
at = editor.selection,
|
|
@@ -10397,12 +10609,12 @@ function deleteText(editor, options = {}) {
|
|
|
10397
10609
|
return;
|
|
10398
10610
|
let isCollapsed = !1;
|
|
10399
10611
|
if (isRange(at) && isCollapsedRange(at) && (isCollapsed = !0, at = at.anchor), isPoint(at)) {
|
|
10400
|
-
const
|
|
10612
|
+
const furthestObjectNode = getObjectNode(editor, {
|
|
10401
10613
|
at,
|
|
10402
10614
|
mode: "highest"
|
|
10403
10615
|
});
|
|
10404
|
-
if (!
|
|
10405
|
-
const [, voidPath] =
|
|
10616
|
+
if (!includeObjectNodes && furthestObjectNode) {
|
|
10617
|
+
const [, voidPath] = furthestObjectNode;
|
|
10406
10618
|
at = voidPath;
|
|
10407
10619
|
} else {
|
|
10408
10620
|
const opts = {
|
|
@@ -10418,7 +10630,7 @@ function deleteText(editor, options = {}) {
|
|
|
10418
10630
|
if (isPath(at)) {
|
|
10419
10631
|
removeNodes(editor, {
|
|
10420
10632
|
at,
|
|
10421
|
-
|
|
10633
|
+
includeObjectNodes
|
|
10422
10634
|
});
|
|
10423
10635
|
return;
|
|
10424
10636
|
}
|
|
@@ -10427,25 +10639,29 @@ function deleteText(editor, options = {}) {
|
|
|
10427
10639
|
if (!hanging) {
|
|
10428
10640
|
const [, end2] = rangeEdges(at), endOfDoc = end(editor, []);
|
|
10429
10641
|
pointEquals(end2, endOfDoc) || (at = unhangRange(editor, at, {
|
|
10430
|
-
|
|
10642
|
+
includeObjectNodes
|
|
10431
10643
|
}));
|
|
10432
10644
|
}
|
|
10433
10645
|
let [start$1, end$1] = rangeEdges(at);
|
|
10434
10646
|
const startBlock = above(editor, {
|
|
10435
|
-
match: (n2) =>
|
|
10647
|
+
match: (n2) => isTextBlock({
|
|
10648
|
+
schema: editor.schema
|
|
10649
|
+
}, n2),
|
|
10436
10650
|
at: start$1,
|
|
10437
|
-
|
|
10651
|
+
includeObjectNodes
|
|
10438
10652
|
}), endBlock = above(editor, {
|
|
10439
|
-
match: (n2) =>
|
|
10653
|
+
match: (n2) => isTextBlock({
|
|
10654
|
+
schema: editor.schema
|
|
10655
|
+
}, n2),
|
|
10440
10656
|
at: end$1,
|
|
10441
|
-
|
|
10442
|
-
}), isAcrossBlocks = startBlock && endBlock && !pathEquals(startBlock[1], endBlock[1]), isSingleText = pathEquals(start$1.path, end$1.path), startNonEditable =
|
|
10657
|
+
includeObjectNodes
|
|
10658
|
+
}), isAcrossBlocks = startBlock && endBlock && !pathEquals(startBlock[1], endBlock[1]), isSingleText = pathEquals(start$1.path, end$1.path), startNonEditable = includeObjectNodes ? null : getObjectNode(editor, {
|
|
10443
10659
|
at: start$1,
|
|
10444
10660
|
mode: "highest"
|
|
10445
10661
|
}) ?? elementReadOnly(editor, {
|
|
10446
10662
|
at: start$1,
|
|
10447
10663
|
mode: "highest"
|
|
10448
|
-
}), endNonEditable =
|
|
10664
|
+
}), endNonEditable = includeObjectNodes ? null : getObjectNode(editor, {
|
|
10449
10665
|
at: end$1,
|
|
10450
10666
|
mode: "highest"
|
|
10451
10667
|
}) ?? elementReadOnly(editor, {
|
|
@@ -10464,16 +10680,22 @@ function deleteText(editor, options = {}) {
|
|
|
10464
10680
|
let lastPath;
|
|
10465
10681
|
for (const entry of nodes(editor, {
|
|
10466
10682
|
at,
|
|
10467
|
-
|
|
10683
|
+
includeObjectNodes
|
|
10468
10684
|
})) {
|
|
10469
10685
|
const [node2, path2] = entry;
|
|
10470
|
-
lastPath && comparePaths(path2, lastPath) === 0 || (!
|
|
10686
|
+
lastPath && comparePaths(path2, lastPath) === 0 || (!includeObjectNodes && (isObjectNode({
|
|
10687
|
+
schema: editor.schema
|
|
10688
|
+
}, node2) || isTextBlock({
|
|
10689
|
+
schema: editor.schema
|
|
10690
|
+
}, node2) && editor.isElementReadOnly(node2)) || !isCommonPath(path2, start$1.path) && !isCommonPath(path2, end$1.path)) && (matches.push(entry), lastPath = path2);
|
|
10471
10691
|
}
|
|
10472
10692
|
const pathRefs = Array.from(matches, ([, p]) => pathRef(editor, p)), startRef = pointRef(editor, start$1), endRef = pointRef(editor, end$1);
|
|
10473
10693
|
let removedText = "";
|
|
10474
10694
|
if (!isSingleText && !startNonEditable) {
|
|
10475
10695
|
const point22 = startRef.current, node2 = getNode(editor, point22.path, editor.schema);
|
|
10476
|
-
if (
|
|
10696
|
+
if (isSpan({
|
|
10697
|
+
schema: editor.schema
|
|
10698
|
+
}, node2)) {
|
|
10477
10699
|
const {
|
|
10478
10700
|
path: path2
|
|
10479
10701
|
} = point22, {
|
|
@@ -10490,11 +10712,13 @@ function deleteText(editor, options = {}) {
|
|
|
10490
10712
|
if (pathRefs.reverse().map((r) => r.unref()).filter((r) => r !== null).forEach((p) => {
|
|
10491
10713
|
removeNodes(editor, {
|
|
10492
10714
|
at: p,
|
|
10493
|
-
|
|
10715
|
+
includeObjectNodes
|
|
10494
10716
|
});
|
|
10495
10717
|
}), !endNonEditable) {
|
|
10496
10718
|
const point22 = endRef.current, node2 = getNode(editor, point22.path, editor.schema);
|
|
10497
|
-
if (
|
|
10719
|
+
if (isSpan({
|
|
10720
|
+
schema: editor.schema
|
|
10721
|
+
}, node2)) {
|
|
10498
10722
|
const {
|
|
10499
10723
|
path: path2
|
|
10500
10724
|
} = point22, offset = isSingleText ? start$1.offset : 0, text = node2.text.slice(offset, end$1.offset);
|
|
@@ -10507,15 +10731,17 @@ function deleteText(editor, options = {}) {
|
|
|
10507
10731
|
}
|
|
10508
10732
|
}
|
|
10509
10733
|
if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
|
|
10510
|
-
const mergeAt = endRef.current, mergeMatch = (n2) =>
|
|
10734
|
+
const mergeAt = endRef.current, mergeMatch = (n2) => isTextBlock({
|
|
10735
|
+
schema: editor.schema
|
|
10736
|
+
}, n2), [current] = nodes(editor, {
|
|
10511
10737
|
at: mergeAt,
|
|
10512
10738
|
match: mergeMatch,
|
|
10513
|
-
|
|
10739
|
+
includeObjectNodes,
|
|
10514
10740
|
mode: "lowest"
|
|
10515
10741
|
}), prev = previous(editor, {
|
|
10516
10742
|
at: mergeAt,
|
|
10517
10743
|
match: mergeMatch,
|
|
10518
|
-
|
|
10744
|
+
includeObjectNodes,
|
|
10519
10745
|
mode: "lowest"
|
|
10520
10746
|
});
|
|
10521
10747
|
if (current && prev) {
|
|
@@ -10524,9 +10750,11 @@ function deleteText(editor, options = {}) {
|
|
|
10524
10750
|
const newPath = nextPath(prevPath), common = commonPath(mergePath, prevPath), isPreviousSibling = isSiblingPath(mergePath, prevPath), editorLevels = Array.from(levels(editor, {
|
|
10525
10751
|
at: mergePath
|
|
10526
10752
|
}), ([n2]) => n2).slice(common.length).slice(0, -1), hasSingleChildNest = (node2) => {
|
|
10527
|
-
if (
|
|
10528
|
-
|
|
10529
|
-
|
|
10753
|
+
if (isTextBlock({
|
|
10754
|
+
schema: editor.schema
|
|
10755
|
+
}, node2)) {
|
|
10756
|
+
const elementChildren = node2.children;
|
|
10757
|
+
return elementChildren.length === 1 ? hasSingleChildNest(elementChildren[0]) : !1;
|
|
10530
10758
|
} else return !isEditor(node2);
|
|
10531
10759
|
}, emptyAncestor = above(editor, {
|
|
10532
10760
|
at: mergePath,
|
|
@@ -10534,9 +10762,17 @@ function deleteText(editor, options = {}) {
|
|
|
10534
10762
|
match: (n2) => editorLevels.includes(n2) && hasSingleChildNest(n2)
|
|
10535
10763
|
}), emptyRef = emptyAncestor && pathRef(editor, emptyAncestor[1]);
|
|
10536
10764
|
let position;
|
|
10537
|
-
if (
|
|
10765
|
+
if (isSpan({
|
|
10766
|
+
schema: editor.schema
|
|
10767
|
+
}, mergeNode) && isSpan({
|
|
10768
|
+
schema: editor.schema
|
|
10769
|
+
}, prevNode))
|
|
10538
10770
|
position = prevNode.text.length;
|
|
10539
|
-
else if (
|
|
10771
|
+
else if (isTextBlock({
|
|
10772
|
+
schema: editor.schema
|
|
10773
|
+
}, mergeNode) && isTextBlock({
|
|
10774
|
+
schema: editor.schema
|
|
10775
|
+
}, prevNode))
|
|
10540
10776
|
position = prevNode.children.length;
|
|
10541
10777
|
else
|
|
10542
10778
|
throw new Error(`Cannot merge the node at path [${mergePath}] with the previous sibling because it is not the same kind: ${safeStringify(mergeNode)} ${safeStringify(prevNode)}`);
|
|
@@ -10554,15 +10790,19 @@ function deleteText(editor, options = {}) {
|
|
|
10554
10790
|
}
|
|
10555
10791
|
if (emptyRef && removeNodes(editor, {
|
|
10556
10792
|
at: emptyRef.current,
|
|
10557
|
-
|
|
10793
|
+
includeObjectNodes
|
|
10558
10794
|
}), shouldMergeNodesRemovePrevNode(editor, prev, current))
|
|
10559
10795
|
removeNodes(editor, {
|
|
10560
10796
|
at: prevPath,
|
|
10561
|
-
|
|
10797
|
+
includeObjectNodes
|
|
10562
10798
|
});
|
|
10563
10799
|
else {
|
|
10564
10800
|
const pteEditor = editor;
|
|
10565
|
-
if (
|
|
10801
|
+
if (isTextBlock({
|
|
10802
|
+
schema: editor.schema
|
|
10803
|
+
}, mergeNode) && isTextBlock({
|
|
10804
|
+
schema: editor.schema
|
|
10805
|
+
}, prevNode) && Array.isArray(mergeNode.markDefs) && mergeNode.markDefs.length > 0) {
|
|
10566
10806
|
const targetPath = isPreviousSibling ? prevPath : previousPath(newPath), oldDefs = Array.isArray(prevNode.markDefs) && prevNode.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...mergeNode.markDefs].map((def) => [def._key, def])).values()];
|
|
10567
10807
|
applySetNode(pteEditor, {
|
|
10568
10808
|
markDefs: newMarkDefs
|
|
@@ -10583,7 +10823,7 @@ function insertNodes(editor, nodes$1, options = {}) {
|
|
|
10583
10823
|
withoutNormalizing(editor, () => {
|
|
10584
10824
|
const {
|
|
10585
10825
|
hanging = !1,
|
|
10586
|
-
|
|
10826
|
+
includeObjectNodes = !1,
|
|
10587
10827
|
mode = "lowest",
|
|
10588
10828
|
batchDirty = !0
|
|
10589
10829
|
} = options;
|
|
@@ -10592,12 +10832,12 @@ function insertNodes(editor, nodes$1, options = {}) {
|
|
|
10592
10832
|
match: match2,
|
|
10593
10833
|
select: select2
|
|
10594
10834
|
} = options;
|
|
10595
|
-
if (
|
|
10835
|
+
if (nodes$1.length === 0)
|
|
10596
10836
|
return;
|
|
10597
10837
|
const node2 = nodes$1[0];
|
|
10598
10838
|
if (at || (at = getDefaultInsertLocation(editor), select2 !== !1 && (select2 = !0)), select2 == null && (select2 = !1), isRange(at))
|
|
10599
10839
|
if (hanging || (at = unhangRange(editor, at, {
|
|
10600
|
-
|
|
10840
|
+
includeObjectNodes
|
|
10601
10841
|
})), isCollapsedRange(at))
|
|
10602
10842
|
at = at.anchor;
|
|
10603
10843
|
else {
|
|
@@ -10607,12 +10847,20 @@ function insertNodes(editor, nodes$1, options = {}) {
|
|
|
10607
10847
|
}), at = endPointRef.unref();
|
|
10608
10848
|
}
|
|
10609
10849
|
if (isPoint(at)) {
|
|
10610
|
-
match2 == null && (
|
|
10850
|
+
match2 == null && (isSpan({
|
|
10851
|
+
schema: editor.schema
|
|
10852
|
+
}, node2) ? match2 = (n2) => isSpan({
|
|
10853
|
+
schema: editor.schema
|
|
10854
|
+
}, n2) : editor.isInline(node2) ? match2 = (n2) => isSpan({
|
|
10855
|
+
schema: editor.schema
|
|
10856
|
+
}, n2) || editor.isInline(n2) : match2 = (n2) => isTextBlock({
|
|
10857
|
+
schema: editor.schema
|
|
10858
|
+
}, n2));
|
|
10611
10859
|
const [entry] = nodes(editor, {
|
|
10612
10860
|
at: at.path,
|
|
10613
10861
|
match: match2,
|
|
10614
10862
|
mode,
|
|
10615
|
-
|
|
10863
|
+
includeObjectNodes
|
|
10616
10864
|
});
|
|
10617
10865
|
if (entry) {
|
|
10618
10866
|
const [, matchPath2] = entry, matchPathRef = pathRef(editor, matchPath2), isAtEnd = isEnd(editor, at, matchPath2);
|
|
@@ -10626,7 +10874,7 @@ function insertNodes(editor, nodes$1, options = {}) {
|
|
|
10626
10874
|
at: splitAt,
|
|
10627
10875
|
match: match2,
|
|
10628
10876
|
mode,
|
|
10629
|
-
|
|
10877
|
+
includeObjectNodes
|
|
10630
10878
|
});
|
|
10631
10879
|
if (highest) {
|
|
10632
10880
|
afterRef = pointRef(editor, splitAt);
|
|
@@ -10635,7 +10883,7 @@ function insertNodes(editor, nodes$1, options = {}) {
|
|
|
10635
10883
|
for (const [node22, nodePath] of levels(editor, {
|
|
10636
10884
|
at: lowestPath,
|
|
10637
10885
|
reverse: !0,
|
|
10638
|
-
|
|
10886
|
+
includeObjectNodes
|
|
10639
10887
|
})) {
|
|
10640
10888
|
let split = !1;
|
|
10641
10889
|
if (nodePath.length < highestPath.length || nodePath.length === 0)
|
|
@@ -10660,7 +10908,7 @@ function insertNodes(editor, nodes$1, options = {}) {
|
|
|
10660
10908
|
}
|
|
10661
10909
|
const parentPath_ = parentPath(at);
|
|
10662
10910
|
let index = at[at.length - 1];
|
|
10663
|
-
if (!(!
|
|
10911
|
+
if (!(!includeObjectNodes && getObjectNode(editor, {
|
|
10664
10912
|
at: parentPath_
|
|
10665
10913
|
}))) {
|
|
10666
10914
|
if (batchDirty) {
|
|
@@ -10674,7 +10922,9 @@ function insertNodes(editor, nodes$1, options = {}) {
|
|
|
10674
10922
|
path: path2,
|
|
10675
10923
|
node: node22
|
|
10676
10924
|
};
|
|
10677
|
-
editor.apply(op), at = nextPath(at), batchedOps.push(op),
|
|
10925
|
+
editor.apply(op), at = nextPath(at), batchedOps.push(op), isSpan({
|
|
10926
|
+
schema: editor.schema
|
|
10927
|
+
}, node22) ? newDirtyPaths.push(path2) : newDirtyPaths.push(...Array.from(getNodes(node22, editor.schema), ([, p]) => path2.concat(p)));
|
|
10678
10928
|
}
|
|
10679
10929
|
}, () => {
|
|
10680
10930
|
updateDirtyPaths(editor, newDirtyPaths, (p) => {
|
|
@@ -10703,85 +10953,111 @@ function insertNodes(editor, nodes$1, options = {}) {
|
|
|
10703
10953
|
}
|
|
10704
10954
|
const normalizeNode = (editor, entry) => {
|
|
10705
10955
|
const [node2, path2] = entry;
|
|
10706
|
-
if (
|
|
10956
|
+
if (isSpan({
|
|
10957
|
+
schema: editor.schema
|
|
10958
|
+
}, node2) || isObjectNode({
|
|
10959
|
+
schema: editor.schema
|
|
10960
|
+
}, node2))
|
|
10707
10961
|
return;
|
|
10708
|
-
|
|
10962
|
+
node2.children ??= [];
|
|
10709
10963
|
let element = node2;
|
|
10710
10964
|
if (element !== editor && element.children.length === 0) {
|
|
10711
10965
|
const child = editor.createSpan();
|
|
10712
|
-
insertNodes(editor, child, {
|
|
10966
|
+
insertNodes(editor, [child], {
|
|
10713
10967
|
at: path2.concat(0),
|
|
10714
|
-
|
|
10715
|
-
}), element =
|
|
10968
|
+
includeObjectNodes: !0
|
|
10969
|
+
}), element = getTextBlockNode(editor, path2, editor.schema);
|
|
10716
10970
|
}
|
|
10717
10971
|
const firstChild = element.children[0];
|
|
10718
|
-
if (element
|
|
10972
|
+
if (!isEditor(element) && (editor.isInline(element) || isSpan({
|
|
10973
|
+
schema: editor.schema
|
|
10974
|
+
}, firstChild) || isObjectNode({
|
|
10975
|
+
schema: editor.schema
|
|
10976
|
+
}, firstChild) || isTextBlock({
|
|
10977
|
+
schema: editor.schema
|
|
10978
|
+
}, firstChild) && editor.isInline(firstChild)))
|
|
10719
10979
|
for (let n2 = 0; n2 < element.children.length; n2++) {
|
|
10720
10980
|
const child = element.children[n2], prev = element.children[n2 - 1];
|
|
10721
|
-
if (
|
|
10722
|
-
|
|
10981
|
+
if (isSpan({
|
|
10982
|
+
schema: editor.schema
|
|
10983
|
+
}, child)) {
|
|
10984
|
+
if (prev != null && isSpan({
|
|
10985
|
+
schema: editor.schema
|
|
10986
|
+
}, prev)) {
|
|
10723
10987
|
if (child.text === "")
|
|
10724
10988
|
removeNodes(editor, {
|
|
10725
10989
|
at: path2.concat(n2),
|
|
10726
|
-
|
|
10727
|
-
}), element =
|
|
10990
|
+
includeObjectNodes: !0
|
|
10991
|
+
}), element = getTextBlockNode(editor, path2, editor.schema), n2--;
|
|
10728
10992
|
else if (prev.text === "")
|
|
10729
10993
|
removeNodes(editor, {
|
|
10730
10994
|
at: path2.concat(n2 - 1),
|
|
10731
|
-
|
|
10732
|
-
}), element =
|
|
10995
|
+
includeObjectNodes: !0
|
|
10996
|
+
}), element = getTextBlockNode(editor, path2, editor.schema), n2--;
|
|
10733
10997
|
else if (textEquals(child, prev, {
|
|
10734
10998
|
loose: !0
|
|
10735
10999
|
})) {
|
|
10736
11000
|
const mergePath = path2.concat(n2);
|
|
10737
|
-
applyMergeNode(editor, mergePath, prev.text.length), element =
|
|
11001
|
+
applyMergeNode(editor, mergePath, prev.text.length), element = getTextBlockNode(editor, path2, editor.schema), n2--;
|
|
10738
11002
|
}
|
|
10739
11003
|
}
|
|
10740
|
-
} else if (
|
|
11004
|
+
} else if (isTextBlock({
|
|
11005
|
+
schema: editor.schema
|
|
11006
|
+
}, child))
|
|
10741
11007
|
if (editor.isInline(child)) {
|
|
10742
|
-
if (prev == null || !
|
|
11008
|
+
if (prev == null || !isSpan({
|
|
11009
|
+
schema: editor.schema
|
|
11010
|
+
}, prev)) {
|
|
10743
11011
|
const newChild = editor.createSpan();
|
|
10744
|
-
insertNodes(editor, newChild, {
|
|
11012
|
+
insertNodes(editor, [newChild], {
|
|
10745
11013
|
at: path2.concat(n2),
|
|
10746
|
-
|
|
10747
|
-
}), element =
|
|
11014
|
+
includeObjectNodes: !0
|
|
11015
|
+
}), element = getTextBlockNode(editor, path2, editor.schema), n2++;
|
|
10748
11016
|
}
|
|
10749
11017
|
if (n2 === element.children.length - 1) {
|
|
10750
11018
|
const newChild = editor.createSpan();
|
|
10751
|
-
insertNodes(editor, newChild, {
|
|
11019
|
+
insertNodes(editor, [newChild], {
|
|
10752
11020
|
at: path2.concat(n2 + 1),
|
|
10753
|
-
|
|
10754
|
-
}), element =
|
|
11021
|
+
includeObjectNodes: !0
|
|
11022
|
+
}), element = getTextBlockNode(editor, path2, editor.schema), n2++;
|
|
10755
11023
|
}
|
|
10756
11024
|
} else
|
|
10757
11025
|
removeNodes(editor, {
|
|
10758
11026
|
at: path2.concat(n2),
|
|
10759
|
-
|
|
10760
|
-
}), element =
|
|
10761
|
-
else if (
|
|
10762
|
-
|
|
11027
|
+
includeObjectNodes: !0
|
|
11028
|
+
}), element = getTextBlockNode(editor, path2, editor.schema), n2--;
|
|
11029
|
+
else if (isObjectNode({
|
|
11030
|
+
schema: editor.schema
|
|
11031
|
+
}, child)) {
|
|
11032
|
+
if (prev == null || !isSpan({
|
|
11033
|
+
schema: editor.schema
|
|
11034
|
+
}, prev)) {
|
|
10763
11035
|
const newChild = editor.createSpan();
|
|
10764
|
-
insertNodes(editor, newChild, {
|
|
11036
|
+
insertNodes(editor, [newChild], {
|
|
10765
11037
|
at: path2.concat(n2),
|
|
10766
|
-
|
|
10767
|
-
}), element =
|
|
11038
|
+
includeObjectNodes: !0
|
|
11039
|
+
}), element = getTextBlockNode(editor, path2, editor.schema), n2++;
|
|
10768
11040
|
}
|
|
10769
11041
|
if (n2 === element.children.length - 1) {
|
|
10770
11042
|
const newChild = editor.createSpan();
|
|
10771
|
-
insertNodes(editor, newChild, {
|
|
11043
|
+
insertNodes(editor, [newChild], {
|
|
10772
11044
|
at: path2.concat(n2 + 1),
|
|
10773
|
-
|
|
10774
|
-
}), element =
|
|
11045
|
+
includeObjectNodes: !0
|
|
11046
|
+
}), element = getTextBlockNode(editor, path2, editor.schema), n2++;
|
|
10775
11047
|
}
|
|
10776
11048
|
}
|
|
10777
11049
|
}
|
|
10778
11050
|
else
|
|
10779
11051
|
for (let n2 = 0; n2 < element.children.length; n2++) {
|
|
10780
11052
|
const child = element.children[n2];
|
|
10781
|
-
(
|
|
11053
|
+
(isSpan({
|
|
11054
|
+
schema: editor.schema
|
|
11055
|
+
}, child) || isTextBlock({
|
|
11056
|
+
schema: editor.schema
|
|
11057
|
+
}, child) && editor.isInline(child)) && (removeNodes(editor, {
|
|
10782
11058
|
at: path2.concat(n2),
|
|
10783
|
-
|
|
10784
|
-
}), element =
|
|
11059
|
+
includeObjectNodes: !0
|
|
11060
|
+
}), element = path2.length === 0 ? editor : getTextBlockNode(editor, path2, editor.schema), n2--);
|
|
10785
11061
|
}
|
|
10786
11062
|
};
|
|
10787
11063
|
function select(editor, target) {
|
|
@@ -10845,7 +11121,6 @@ const shouldNormalize = (_editor, {
|
|
|
10845
11121
|
}),
|
|
10846
11122
|
isElementReadOnly: () => !1,
|
|
10847
11123
|
isInline: () => !1,
|
|
10848
|
-
isSelectable: () => !0,
|
|
10849
11124
|
onChange: () => {
|
|
10850
11125
|
},
|
|
10851
11126
|
// Core
|
|
@@ -11170,7 +11445,7 @@ const withDOM = (editor) => {
|
|
|
11170
11445
|
apply: apply2,
|
|
11171
11446
|
onChange
|
|
11172
11447
|
} = e;
|
|
11173
|
-
return e.isNodeMapDirty = !1, e.domWindow = null, e.domElement = null, e.domPlaceholder = "", e.domPlaceholderElement = null, e.keyToElement = /* @__PURE__ */ new WeakMap(), e.nodeToIndex = /* @__PURE__ */ new WeakMap(), e.nodeToParent = /* @__PURE__ */ new WeakMap(), e.elementToNode = /* @__PURE__ */ new WeakMap(), e.
|
|
11448
|
+
return e.isNodeMapDirty = !1, e.domWindow = null, e.domElement = null, e.domPlaceholder = "", e.domPlaceholderElement = null, e.keyToElement = /* @__PURE__ */ new WeakMap(), e.nodeToIndex = /* @__PURE__ */ new WeakMap(), e.nodeToParent = /* @__PURE__ */ new WeakMap(), e.elementToNode = /* @__PURE__ */ new WeakMap(), e.nodeToKey = /* @__PURE__ */ new WeakMap(), e.readOnly = !1, e.focused = !1, e.composing = !1, e.userSelection = null, e.onContextChange = null, e.scheduleFlush = null, e.pendingInsertionMarks = null, e.userMarks = null, e.pendingDiffs = [], e.pendingAction = null, e.pendingSelection = null, e.forceRender = null, e.apply = (op) => {
|
|
11174
11449
|
const matches = [], pendingDiffs = e.pendingDiffs;
|
|
11175
11450
|
if (pendingDiffs?.length) {
|
|
11176
11451
|
const transformed = pendingDiffs.map((textDiff) => transformTextDiff(textDiff, op)).filter(Boolean);
|
|
@@ -11212,6 +11487,8 @@ const withDOM = (editor) => {
|
|
|
11212
11487
|
e.isNodeMapDirty = !0;
|
|
11213
11488
|
}
|
|
11214
11489
|
for (const [path2, key] of matches) {
|
|
11490
|
+
if (path2.length === 0)
|
|
11491
|
+
continue;
|
|
11215
11492
|
const [node$1] = node(e, path2);
|
|
11216
11493
|
e.nodeToKey.set(node$1, key);
|
|
11217
11494
|
}
|
|
@@ -11228,7 +11505,7 @@ const withDOM = (editor) => {
|
|
|
11228
11505
|
matches.push([p, key]);
|
|
11229
11506
|
}
|
|
11230
11507
|
return matches;
|
|
11231
|
-
}, withReact = (editor) => {
|
|
11508
|
+
}, REACT_MAJOR_VERSION = parseInt(React.version.split(".")[0], 10), withReact = (editor) => {
|
|
11232
11509
|
let e = editor;
|
|
11233
11510
|
e = withDOM(e);
|
|
11234
11511
|
const {
|
|
@@ -11253,21 +11530,18 @@ function createSlateEditor(config) {
|
|
|
11253
11530
|
undos: [],
|
|
11254
11531
|
redos: []
|
|
11255
11532
|
}, editor.lastSelection = null, editor.lastSlateSelection = null, editor.listIndexMap = /* @__PURE__ */ new Map(), editor.remotePatches = [], editor.undoStepId = void 0, editor.children = [placeholderBlock], editor.isDeferringMutations = !1, editor.isNormalizingNode = !1, editor.isPatching = !0, editor.isPerformingBehaviorOperation = !1, editor.isProcessingRemoteChanges = !1, editor.isRedoing = !1, editor.isUndoing = !1, editor.withHistory = !0;
|
|
11256
|
-
const
|
|
11533
|
+
const slateEditor = plugins(withReact(editor), {
|
|
11257
11534
|
editorActor: config.editorActor,
|
|
11258
11535
|
relayActor: config.relayActor,
|
|
11259
11536
|
subscriptions: config.subscriptions
|
|
11260
11537
|
});
|
|
11261
11538
|
return buildIndexMaps({
|
|
11262
11539
|
schema: context.schema,
|
|
11263
|
-
value:
|
|
11540
|
+
value: slateEditor.children
|
|
11264
11541
|
}, {
|
|
11265
|
-
blockIndexMap:
|
|
11266
|
-
listIndexMap:
|
|
11267
|
-
}),
|
|
11268
|
-
instance,
|
|
11269
|
-
initialValue: [placeholderBlock]
|
|
11270
|
-
};
|
|
11542
|
+
blockIndexMap: slateEditor.blockIndexMap,
|
|
11543
|
+
listIndexMap: slateEditor.listIndexMap
|
|
11544
|
+
}), slateEditor;
|
|
11271
11545
|
}
|
|
11272
11546
|
function createEditorDom(sendBack, slateEditor) {
|
|
11273
11547
|
return {
|
|
@@ -12779,7 +13053,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
12779
13053
|
affinity: "inward"
|
|
12780
13054
|
}) : null, selectedBlocks = nodes(editor, {
|
|
12781
13055
|
at: effectiveSelection,
|
|
12782
|
-
match: (node2) =>
|
|
13056
|
+
match: (node2) => isTextBlock({
|
|
13057
|
+
schema: editor.schema
|
|
13058
|
+
}, node2),
|
|
12783
13059
|
reverse: isBackwardRange(effectiveSelection)
|
|
12784
13060
|
});
|
|
12785
13061
|
let blockIndex = 0;
|
|
@@ -12796,7 +13072,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
12796
13072
|
const splitRange = at ?? editor.selection;
|
|
12797
13073
|
if (splitRange && isRange(splitRange)) {
|
|
12798
13074
|
const [splitLeaf] = leaf(editor, splitRange.anchor);
|
|
12799
|
-
if (!(isCollapsedRange(splitRange) &&
|
|
13075
|
+
if (!(isCollapsedRange(splitRange) && isSpan({
|
|
13076
|
+
schema: editor.schema
|
|
13077
|
+
}, splitLeaf) && splitLeaf.text.length > 0)) {
|
|
12800
13078
|
const splitRangeRef = rangeRef(editor, splitRange, {
|
|
12801
13079
|
affinity: "inward"
|
|
12802
13080
|
}), [splitStart, splitEnd] = rangeEdges(splitRange);
|
|
@@ -12814,7 +13092,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
12814
13092
|
}
|
|
12815
13093
|
const children = getChildren(editor, blockPath, editor.schema), selectionRange = ref?.current ?? editor.selection;
|
|
12816
13094
|
for (const [span, path2] of children) {
|
|
12817
|
-
if (!
|
|
13095
|
+
if (!isSpan({
|
|
13096
|
+
schema: editor.schema
|
|
13097
|
+
}, span) || !selectionRange || !rangeIncludes(selectionRange, path2))
|
|
12818
13098
|
continue;
|
|
12819
13099
|
const marks = span.marks ?? [];
|
|
12820
13100
|
applySetNode(editor, {
|
|
@@ -12841,12 +13121,16 @@ const addAnnotationOperationImplementation = ({
|
|
|
12841
13121
|
const [block, blockPath] = node(editor, effectiveSelection, {
|
|
12842
13122
|
depth: 1
|
|
12843
13123
|
});
|
|
12844
|
-
if (!
|
|
13124
|
+
if (!isTextBlock({
|
|
13125
|
+
schema: editor.schema
|
|
13126
|
+
}, block))
|
|
12845
13127
|
return;
|
|
12846
13128
|
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), [selectedChild, selectedChildPath] = node(editor, effectiveSelection, {
|
|
12847
13129
|
depth: 2
|
|
12848
13130
|
});
|
|
12849
|
-
if (!
|
|
13131
|
+
if (!isSpan({
|
|
13132
|
+
schema: editor.schema
|
|
13133
|
+
}, selectedChild))
|
|
12850
13134
|
return;
|
|
12851
13135
|
const annotationToRemove = selectedChild.marks?.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
|
|
12852
13136
|
if (!annotationToRemove)
|
|
@@ -12855,14 +13139,18 @@ const addAnnotationOperationImplementation = ({
|
|
|
12855
13139
|
for (const [child, childPath] of getChildren(editor, blockPath, editor.schema, {
|
|
12856
13140
|
reverse: !0
|
|
12857
13141
|
}))
|
|
12858
|
-
if (
|
|
13142
|
+
if (isSpan({
|
|
13143
|
+
schema: editor.schema
|
|
13144
|
+
}, child) && isBeforePath(childPath, selectedChildPath))
|
|
12859
13145
|
if (child.marks?.includes(annotationToRemove))
|
|
12860
13146
|
previousSpansWithSameAnnotation.push([child, childPath]);
|
|
12861
13147
|
else
|
|
12862
13148
|
break;
|
|
12863
13149
|
const nextSpansWithSameAnnotation = [];
|
|
12864
13150
|
for (const [child, childPath] of getChildren(editor, blockPath, editor.schema))
|
|
12865
|
-
if (
|
|
13151
|
+
if (isSpan({
|
|
13152
|
+
schema: editor.schema
|
|
13153
|
+
}, child) && isAfterPath(childPath, selectedChildPath))
|
|
12866
13154
|
if (child.marks?.includes(annotationToRemove))
|
|
12867
13155
|
nextSpansWithSameAnnotation.push([child, childPath]);
|
|
12868
13156
|
else
|
|
@@ -12877,7 +13165,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
12877
13165
|
}) : null, splitRange = at ?? editor.selection;
|
|
12878
13166
|
if (splitRange && isRange(splitRange)) {
|
|
12879
13167
|
const [splitLeaf] = leaf(editor, splitRange.anchor);
|
|
12880
|
-
if (!(isCollapsedRange(splitRange) &&
|
|
13168
|
+
if (!(isCollapsedRange(splitRange) && isSpan({
|
|
13169
|
+
schema: editor.schema
|
|
13170
|
+
}, splitLeaf) && splitLeaf.text.length > 0)) {
|
|
12881
13171
|
const splitRangeRef = rangeRef(editor, splitRange, {
|
|
12882
13172
|
affinity: "inward"
|
|
12883
13173
|
}), [splitStart, splitEnd] = rangeEdges(splitRange);
|
|
@@ -12895,12 +13185,16 @@ const addAnnotationOperationImplementation = ({
|
|
|
12895
13185
|
}
|
|
12896
13186
|
const blocks = nodes(editor, {
|
|
12897
13187
|
at: effectiveSelection,
|
|
12898
|
-
match: (node2) =>
|
|
13188
|
+
match: (node2) => isTextBlock({
|
|
13189
|
+
schema: editor.schema
|
|
13190
|
+
}, node2)
|
|
12899
13191
|
}), selectionRange = ref?.current ?? editor.selection;
|
|
12900
13192
|
for (const [block, blockPath] of blocks) {
|
|
12901
13193
|
const children = getChildren(editor, blockPath, editor.schema);
|
|
12902
13194
|
for (const [child, childPath] of children) {
|
|
12903
|
-
if (!
|
|
13195
|
+
if (!isSpan({
|
|
13196
|
+
schema: editor.schema
|
|
13197
|
+
}, child) || !selectionRange || !rangeIncludes(selectionRange, childPath))
|
|
12904
13198
|
continue;
|
|
12905
13199
|
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
|
|
12906
13200
|
marksWithoutAnnotation.length !== marks.length && applySetNode(editor, {
|
|
@@ -13016,7 +13310,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13016
13310
|
}), child = childEntry?.[0], childPath = childEntry?.[1];
|
|
13017
13311
|
if (!child || !childPath)
|
|
13018
13312
|
throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
|
|
13019
|
-
if (
|
|
13313
|
+
if (isSpan({
|
|
13314
|
+
schema: operation.editor.schema
|
|
13315
|
+
}, child)) {
|
|
13020
13316
|
const {
|
|
13021
13317
|
_type,
|
|
13022
13318
|
text,
|
|
@@ -13038,7 +13334,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13038
13334
|
}));
|
|
13039
13335
|
return;
|
|
13040
13336
|
}
|
|
13041
|
-
if (
|
|
13337
|
+
if (isObjectNode({
|
|
13338
|
+
schema: operation.editor.schema
|
|
13339
|
+
}, child)) {
|
|
13042
13340
|
const definition = context.schema.inlineObjects.find((definition2) => definition2.name === child._type);
|
|
13043
13341
|
if (!definition)
|
|
13044
13342
|
throw new Error(`Unable to find schema definition for Inline Object type ${child._type}`);
|
|
@@ -13080,7 +13378,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13080
13378
|
}), child = childEntry?.[0], childPath = childEntry?.[1];
|
|
13081
13379
|
if (!child || !childPath)
|
|
13082
13380
|
throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
|
|
13083
|
-
if (
|
|
13381
|
+
if (isSpan({
|
|
13382
|
+
schema: operation.editor.schema
|
|
13383
|
+
}, child)) {
|
|
13084
13384
|
const newNode = {};
|
|
13085
13385
|
for (const prop of operation.props)
|
|
13086
13386
|
if (prop !== "text" && prop !== "_type") {
|
|
@@ -13098,7 +13398,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13098
13398
|
});
|
|
13099
13399
|
return;
|
|
13100
13400
|
}
|
|
13101
|
-
if (
|
|
13401
|
+
if (isObjectNode({
|
|
13402
|
+
schema: operation.editor.schema
|
|
13403
|
+
}, child)) {
|
|
13102
13404
|
const unsetProps = {};
|
|
13103
13405
|
for (const prop of operation.props)
|
|
13104
13406
|
prop !== "_type" && (prop === "_key" ? unsetProps._key = context.keyGenerator() : unsetProps[prop] = null);
|
|
@@ -13137,7 +13439,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13137
13439
|
operation.at || applySelect(editor, at);
|
|
13138
13440
|
const splitTextNodes = nodes(editor, {
|
|
13139
13441
|
at,
|
|
13140
|
-
match: (n2) =>
|
|
13442
|
+
match: (n2) => isSpan({
|
|
13443
|
+
schema: editor.schema
|
|
13444
|
+
}, n2)
|
|
13141
13445
|
});
|
|
13142
13446
|
for (const [node2, path2] of splitTextNodes) {
|
|
13143
13447
|
const marks = [...(Array.isArray(node2.marks) ? node2.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
@@ -13148,17 +13452,25 @@ const addAnnotationOperationImplementation = ({
|
|
|
13148
13452
|
} else {
|
|
13149
13453
|
if (!Array.from(nodes(editor, {
|
|
13150
13454
|
at,
|
|
13151
|
-
match: (node2) =>
|
|
13455
|
+
match: (node2) => isSpan({
|
|
13456
|
+
schema: editor.schema
|
|
13457
|
+
}, node2)
|
|
13152
13458
|
}))?.at(0))
|
|
13153
13459
|
return;
|
|
13154
13460
|
const [block, blockPath] = node(editor, at, {
|
|
13155
13461
|
depth: 1
|
|
13156
|
-
}), lonelyEmptySpan =
|
|
13462
|
+
}), lonelyEmptySpan = isTextBlock({
|
|
13463
|
+
schema: editor.schema
|
|
13464
|
+
}, block) && block.children.length === 1 && isSpan({
|
|
13465
|
+
schema: editor.schema
|
|
13466
|
+
}, block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
13157
13467
|
if (lonelyEmptySpan) {
|
|
13158
13468
|
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark), newMarks = existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator;
|
|
13159
13469
|
for (const [, spanPath] of nodes(editor, {
|
|
13160
13470
|
at: blockPath,
|
|
13161
|
-
match: (node2) =>
|
|
13471
|
+
match: (node2) => isSpan({
|
|
13472
|
+
schema: editor.schema
|
|
13473
|
+
}, node2)
|
|
13162
13474
|
}))
|
|
13163
13475
|
applySetNode(editor, {
|
|
13164
13476
|
marks: newMarks
|
|
@@ -13190,7 +13502,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13190
13502
|
const ref = rangeRef(editor, at, {
|
|
13191
13503
|
affinity: "inward"
|
|
13192
13504
|
}), [decoratorLeaf] = leaf(editor, at.anchor);
|
|
13193
|
-
if (!(isCollapsedRange(at) &&
|
|
13505
|
+
if (!(isCollapsedRange(at) && isSpan({
|
|
13506
|
+
schema: editor.schema
|
|
13507
|
+
}, decoratorLeaf) && decoratorLeaf.text.length > 0)) {
|
|
13194
13508
|
const [start2, end2] = rangeEdges(at);
|
|
13195
13509
|
if (!isEnd(editor, end2, end2.path) || !isEdge(editor, end2, end2.path)) {
|
|
13196
13510
|
const [endNode] = node(editor, end2.path);
|
|
@@ -13204,10 +13518,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
13204
13518
|
const updatedAt = ref.unref();
|
|
13205
13519
|
updatedAt && [...nodes(editor, {
|
|
13206
13520
|
at: updatedAt,
|
|
13207
|
-
match: (n2) =>
|
|
13521
|
+
match: (n2) => isSpan({
|
|
13522
|
+
schema: editor.schema
|
|
13523
|
+
}, n2)
|
|
13208
13524
|
})].forEach(([node2, path2]) => {
|
|
13209
13525
|
const block = editor.children[path2[0]];
|
|
13210
|
-
|
|
13526
|
+
isTextBlock({
|
|
13527
|
+
schema: editor.schema
|
|
13528
|
+
}, block) && block.children.includes(node2) && applySetNode(editor, {
|
|
13211
13529
|
marks: (Array.isArray(node2.marks) ? node2.marks : []).filter((eMark) => eMark !== mark),
|
|
13212
13530
|
_type: context.schema.span.name
|
|
13213
13531
|
}, path2);
|
|
@@ -13215,12 +13533,18 @@ const addAnnotationOperationImplementation = ({
|
|
|
13215
13533
|
} else {
|
|
13216
13534
|
const [block, blockPath] = node(editor, at, {
|
|
13217
13535
|
depth: 1
|
|
13218
|
-
}), lonelyEmptySpan =
|
|
13536
|
+
}), lonelyEmptySpan = isTextBlock({
|
|
13537
|
+
schema: editor.schema
|
|
13538
|
+
}, block) && block.children.length === 1 && isSpan({
|
|
13539
|
+
schema: editor.schema
|
|
13540
|
+
}, block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
13219
13541
|
if (lonelyEmptySpan) {
|
|
13220
13542
|
const existingMarksWithoutDecorator = (lonelyEmptySpan.marks ?? []).filter((existingMark) => existingMark !== mark);
|
|
13221
13543
|
for (const [, spanPath] of nodes(editor, {
|
|
13222
13544
|
at: blockPath,
|
|
13223
|
-
match: (node2) =>
|
|
13545
|
+
match: (node2) => isSpan({
|
|
13546
|
+
schema: editor.schema
|
|
13547
|
+
}, node2)
|
|
13224
13548
|
}))
|
|
13225
13549
|
applySetNode(editor, {
|
|
13226
13550
|
marks: existingMarksWithoutDecorator
|
|
@@ -13265,7 +13589,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
13265
13589
|
}
|
|
13266
13590
|
}, blockMatches = nodes(operation.editor, {
|
|
13267
13591
|
at: removeRange,
|
|
13268
|
-
match: (n2) =>
|
|
13592
|
+
match: (n2) => isTextBlock({
|
|
13593
|
+
schema: operation.editor.schema
|
|
13594
|
+
}, n2) || isObjectNode({
|
|
13595
|
+
schema: operation.editor.schema
|
|
13596
|
+
}, n2) && !operation.editor.isInline(n2),
|
|
13269
13597
|
mode: "highest"
|
|
13270
13598
|
}), blockPathRefs = Array.from(blockMatches, ([, p]) => pathRef(operation.editor, p));
|
|
13271
13599
|
for (const pathRef2 of blockPathRefs) {
|
|
@@ -13284,8 +13612,12 @@ const addAnnotationOperationImplementation = ({
|
|
|
13284
13612
|
if (operation.unit === "child") {
|
|
13285
13613
|
const childMatches = nodes(operation.editor, {
|
|
13286
13614
|
at,
|
|
13287
|
-
match: (node2, path2) => isSpan(context, node2) ||
|
|
13288
|
-
|
|
13615
|
+
match: (node2, path2) => isSpan(context, node2) || isTextBlock({
|
|
13616
|
+
schema: operation.editor.schema
|
|
13617
|
+
}, node2) && operation.editor.isInline(node2) || // TODO: Update depth check when containers land (path.length > 1 assumes flat structure)
|
|
13618
|
+
isObjectNode({
|
|
13619
|
+
schema: operation.editor.schema
|
|
13620
|
+
}, node2) && path2.length > 1
|
|
13289
13621
|
}), childPathRefs = Array.from(childMatches, ([, p]) => pathRef(operation.editor, p));
|
|
13290
13622
|
for (const pathRef2 of childPathRefs) {
|
|
13291
13623
|
const path2 = pathRef2.unref();
|
|
@@ -13302,7 +13634,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13302
13634
|
}
|
|
13303
13635
|
if (operation.direction === "backward" && operation.unit === "line") {
|
|
13304
13636
|
const parentBlockEntry = above(operation.editor, {
|
|
13305
|
-
match: (n2) =>
|
|
13637
|
+
match: (n2) => isTextBlock({
|
|
13638
|
+
schema: operation.editor.schema
|
|
13639
|
+
}, n2),
|
|
13306
13640
|
at
|
|
13307
13641
|
});
|
|
13308
13642
|
if (parentBlockEntry) {
|
|
@@ -13326,7 +13660,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13326
13660
|
if (isCollapsedRange(at) && start$1.path.length >= 2)
|
|
13327
13661
|
try {
|
|
13328
13662
|
const node2 = getNode(operation.editor, start$1.path, operation.editor.schema);
|
|
13329
|
-
if (
|
|
13663
|
+
if (isObjectNode({
|
|
13664
|
+
schema: operation.editor.schema
|
|
13665
|
+
}, node2)) {
|
|
13330
13666
|
operation.editor.apply({
|
|
13331
13667
|
type: "remove_node",
|
|
13332
13668
|
path: start$1.path,
|
|
@@ -13340,29 +13676,45 @@ const addAnnotationOperationImplementation = ({
|
|
|
13340
13676
|
const blockIndex = start$1.path.at(0);
|
|
13341
13677
|
if (blockIndex !== void 0) {
|
|
13342
13678
|
const node2 = getNode(operation.editor, [blockIndex], operation.editor.schema);
|
|
13343
|
-
if (
|
|
13679
|
+
if (isObjectNode({
|
|
13680
|
+
schema: operation.editor.schema
|
|
13681
|
+
}, node2))
|
|
13344
13682
|
return [node2, [blockIndex]];
|
|
13345
13683
|
}
|
|
13346
13684
|
})(), endNodeEntry = (() => {
|
|
13347
13685
|
const blockIndex = end$1.path.at(0);
|
|
13348
13686
|
if (blockIndex !== void 0) {
|
|
13349
13687
|
const node2 = getNode(operation.editor, [blockIndex], operation.editor.schema);
|
|
13350
|
-
if (
|
|
13688
|
+
if (isObjectNode({
|
|
13689
|
+
schema: operation.editor.schema
|
|
13690
|
+
}, node2))
|
|
13351
13691
|
return [node2, [blockIndex]];
|
|
13352
13692
|
}
|
|
13353
13693
|
})(), startBlock = startNodeEntry ?? above(operation.editor, {
|
|
13354
|
-
match: (n2) =>
|
|
13694
|
+
match: (n2) => isTextBlock({
|
|
13695
|
+
schema: operation.editor.schema
|
|
13696
|
+
}, n2) || isObjectNode({
|
|
13697
|
+
schema: operation.editor.schema
|
|
13698
|
+
}, n2) && !operation.editor.isInline(n2),
|
|
13355
13699
|
at: start$1
|
|
13356
13700
|
}), endBlock = endNodeEntry ?? above(operation.editor, {
|
|
13357
|
-
match: (n2) =>
|
|
13701
|
+
match: (n2) => isTextBlock({
|
|
13702
|
+
schema: operation.editor.schema
|
|
13703
|
+
}, n2) || isObjectNode({
|
|
13704
|
+
schema: operation.editor.schema
|
|
13705
|
+
}, n2) && !operation.editor.isInline(n2),
|
|
13358
13706
|
at: end$1
|
|
13359
|
-
}), isAcrossBlocks = startBlock && endBlock && !pathEquals(startBlock[1], endBlock[1]), startObjectNode = startBlock &&
|
|
13707
|
+
}), isAcrossBlocks = startBlock && endBlock && !pathEquals(startBlock[1], endBlock[1]), startObjectNode = startBlock && isObjectNode({
|
|
13708
|
+
schema: operation.editor.schema
|
|
13709
|
+
}, startBlock[0]) ? startBlock : void 0, endObjectNode = endBlock && isObjectNode({
|
|
13710
|
+
schema: operation.editor.schema
|
|
13711
|
+
}, endBlock[0]) ? endBlock : void 0, startNonEditable = startObjectNode ?? getObjectNode(operation.editor, {
|
|
13360
13712
|
at: start$1,
|
|
13361
13713
|
mode: "highest"
|
|
13362
13714
|
}) ?? elementReadOnly(operation.editor, {
|
|
13363
13715
|
at: start$1,
|
|
13364
13716
|
mode: "highest"
|
|
13365
|
-
}), endNonEditable = endObjectNode ??
|
|
13717
|
+
}), endNonEditable = endObjectNode ?? getObjectNode(operation.editor, {
|
|
13366
13718
|
at: end$1,
|
|
13367
13719
|
mode: "highest"
|
|
13368
13720
|
}) ?? elementReadOnly(operation.editor, {
|
|
@@ -13372,16 +13724,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
13372
13724
|
let lastPath;
|
|
13373
13725
|
for (const entry of nodes(operation.editor, {
|
|
13374
13726
|
at,
|
|
13375
|
-
|
|
13727
|
+
includeObjectNodes: !1
|
|
13376
13728
|
})) {
|
|
13377
13729
|
const [node2, path2] = entry;
|
|
13378
|
-
lastPath && comparePaths(path2, lastPath) === 0 || (
|
|
13730
|
+
lastPath && comparePaths(path2, lastPath) === 0 || (isObjectNode({
|
|
13731
|
+
schema: operation.editor.schema
|
|
13732
|
+
}, node2) || isTextBlock({
|
|
13733
|
+
schema: operation.editor.schema
|
|
13734
|
+
}, node2) && operation.editor.isElementReadOnly(node2) || !isCommonPath(path2, start$1.path) && !isCommonPath(path2, end$1.path)) && (matches.push(entry), lastPath = path2);
|
|
13379
13735
|
}
|
|
13380
13736
|
const pathRefs = Array.from(matches, ([, path2]) => pathRef(operation.editor, path2)), startRef = pointRef(operation.editor, start$1), endRef = pointRef(operation.editor, end$1);
|
|
13381
13737
|
if (startBlock && endBlock && pointEquals(start$1, start(operation.editor, startBlock[1])) && pointEquals(end$1, end(operation.editor, endBlock[1])) && isAcrossBlocks) {
|
|
13382
13738
|
if (!startNonEditable) {
|
|
13383
13739
|
const point2 = startRef.current, node2 = getNode(operation.editor, point2.path, operation.editor.schema);
|
|
13384
|
-
|
|
13740
|
+
isSpan({
|
|
13741
|
+
schema: operation.editor.schema
|
|
13742
|
+
}, node2) && node2.text.length > 0 && operation.editor.apply({
|
|
13385
13743
|
type: "remove_text",
|
|
13386
13744
|
path: point2.path,
|
|
13387
13745
|
offset: 0,
|
|
@@ -13401,7 +13759,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13401
13759
|
}
|
|
13402
13760
|
if (!endNonEditable) {
|
|
13403
13761
|
const point2 = endRef.current, node2 = getNode(operation.editor, point2.path, operation.editor.schema);
|
|
13404
|
-
if (
|
|
13762
|
+
if (isSpan({
|
|
13763
|
+
schema: operation.editor.schema
|
|
13764
|
+
}, node2)) {
|
|
13405
13765
|
const {
|
|
13406
13766
|
path: path2
|
|
13407
13767
|
} = point2, offset = 0, text = node2.text.slice(offset, end$1.offset);
|
|
@@ -13416,7 +13776,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
13416
13776
|
if (endRef.current && startRef.current) {
|
|
13417
13777
|
const endBlockMatches = nodes(operation.editor, {
|
|
13418
13778
|
at: endRef.current,
|
|
13419
|
-
match: (n2) =>
|
|
13779
|
+
match: (n2) => isTextBlock({
|
|
13780
|
+
schema: operation.editor.schema
|
|
13781
|
+
}, n2) || isObjectNode({
|
|
13782
|
+
schema: operation.editor.schema
|
|
13783
|
+
}, n2) && !operation.editor.isInline(n2)
|
|
13420
13784
|
}), endBlockPathRefs = Array.from(endBlockMatches, ([, p]) => pathRef(operation.editor, p));
|
|
13421
13785
|
for (const pathRef2 of endBlockPathRefs) {
|
|
13422
13786
|
const endPath = pathRef2.unref();
|
|
@@ -13440,7 +13804,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13440
13804
|
});
|
|
13441
13805
|
return;
|
|
13442
13806
|
}
|
|
13443
|
-
if (startNonEditable && startBlock && endBlock && pathEquals(startBlock[1], endBlock[1]) &&
|
|
13807
|
+
if (startNonEditable && startBlock && endBlock && pathEquals(startBlock[1], endBlock[1]) && isObjectNode({
|
|
13808
|
+
schema: operation.editor.schema
|
|
13809
|
+
}, startBlock[0])) {
|
|
13444
13810
|
const path2 = startBlock[1];
|
|
13445
13811
|
operation.editor.apply({
|
|
13446
13812
|
type: "remove_node",
|
|
@@ -13454,7 +13820,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
13454
13820
|
const currentPath = pathRef2.current;
|
|
13455
13821
|
if (currentPath) {
|
|
13456
13822
|
const [nodeAtPath] = node(operation.editor, currentPath);
|
|
13457
|
-
if (
|
|
13823
|
+
if (isObjectNode({
|
|
13824
|
+
schema: operation.editor.schema
|
|
13825
|
+
}, nodeAtPath)) {
|
|
13458
13826
|
const path2 = pathRef2.unref();
|
|
13459
13827
|
path2 && (endObjectNode && pathEquals(path2, endObjectNode[1]) && (removedEndObjectNode = !0), operation.editor.apply({
|
|
13460
13828
|
type: "remove_node",
|
|
@@ -13733,7 +14101,16 @@ const historyUndoOperationImplementation = ({
|
|
|
13733
14101
|
editor.history.redos.push(step), editor.history.undos.pop();
|
|
13734
14102
|
}
|
|
13735
14103
|
}
|
|
13736
|
-
}
|
|
14104
|
+
};
|
|
14105
|
+
function getSpanNode(root, path2, schema) {
|
|
14106
|
+
const node2 = getNode(root, path2, schema);
|
|
14107
|
+
if (isSpan({
|
|
14108
|
+
schema
|
|
14109
|
+
}, node2))
|
|
14110
|
+
return node2;
|
|
14111
|
+
throw new Error(`Cannot get the span at path [${path2}] because it refers to a non-span node: ${safeStringify(node2)}`);
|
|
14112
|
+
}
|
|
14113
|
+
const insertBlockOperationImplementation = ({
|
|
13737
14114
|
context,
|
|
13738
14115
|
operation
|
|
13739
14116
|
}) => {
|
|
@@ -13782,12 +14159,20 @@ function insertBlock(options) {
|
|
|
13782
14159
|
const start$1 = at ? rangeStart(at) : start(editor, []), end$1 = at ? rangeEnd(at) : end(editor, []), [startBlock, startBlockPath] = Array.from(nodes(editor, {
|
|
13783
14160
|
at: start$1,
|
|
13784
14161
|
mode: "lowest",
|
|
13785
|
-
match: (node2, path2) => (
|
|
14162
|
+
match: (node2, path2) => (isTextBlock({
|
|
14163
|
+
schema: editor.schema
|
|
14164
|
+
}, node2) || isObjectNode({
|
|
14165
|
+
schema: editor.schema
|
|
14166
|
+
}, node2)) && path2.length <= start$1.path.length
|
|
13786
14167
|
})).at(0) ?? [void 0, void 0];
|
|
13787
14168
|
let [endBlock, endBlockPath] = Array.from(nodes(editor, {
|
|
13788
14169
|
at: end$1,
|
|
13789
14170
|
mode: "lowest",
|
|
13790
|
-
match: (node2, path2) => (
|
|
14171
|
+
match: (node2, path2) => (isTextBlock({
|
|
14172
|
+
schema: editor.schema
|
|
14173
|
+
}, node2) || isObjectNode({
|
|
14174
|
+
schema: editor.schema
|
|
14175
|
+
}, node2)) && path2.length <= end$1.path.length
|
|
13791
14176
|
})).at(0) ?? [void 0, void 0];
|
|
13792
14177
|
if (!startBlock || !startBlockPath || !endBlock || !endBlockPath)
|
|
13793
14178
|
throw new Error("Unable to insert block without a start and end block");
|
|
@@ -13804,19 +14189,27 @@ function insertBlock(options) {
|
|
|
13804
14189
|
replaceEmptyTextBlock(editor, endBlockPath, block, select2);
|
|
13805
14190
|
return;
|
|
13806
14191
|
}
|
|
13807
|
-
if (
|
|
14192
|
+
if (isTextBlock({
|
|
14193
|
+
schema: editor.schema
|
|
14194
|
+
}, block) && isTextBlock({
|
|
14195
|
+
schema: editor.schema
|
|
14196
|
+
}, endBlock)) {
|
|
13808
14197
|
const selectionBefore = end(editor, endBlockPath);
|
|
13809
|
-
insertTextBlockFragment(editor, block, selectionBefore), select2 === "start" ? setSelectionToPoint(editor, selectionBefore) : select2 === "none" && clearSelection(editor);
|
|
14198
|
+
insertTextBlockFragment(context, editor, block, selectionBefore), select2 === "start" ? setSelectionToPoint(editor, selectionBefore) : select2 === "none" && clearSelection(editor);
|
|
13810
14199
|
return;
|
|
13811
14200
|
}
|
|
13812
14201
|
insertNodeAt(editor, nextPath(endBlockPath), block, select2);
|
|
13813
14202
|
return;
|
|
13814
14203
|
}
|
|
13815
|
-
if (isExpandedRange(at) && !
|
|
14204
|
+
if (isExpandedRange(at) && !isTextBlock({
|
|
14205
|
+
schema: editor.schema
|
|
14206
|
+
}, block)) {
|
|
13816
14207
|
const atBeforeDelete = rangeRef(editor, at, {
|
|
13817
14208
|
affinity: "inward"
|
|
13818
|
-
}), start2 = rangeStart(at), startBlock2 = getNode(editor, [start2.path[0]], editor.schema), startOfBlock = start(editor, [start2.path[0]]), isAtStartOfBlock =
|
|
13819
|
-
|
|
14209
|
+
}), start2 = rangeStart(at), startBlock2 = getNode(editor, [start2.path[0]], editor.schema), startOfBlock = start(editor, [start2.path[0]]), isAtStartOfBlock = isTextBlock({
|
|
14210
|
+
schema: editor.schema
|
|
14211
|
+
}, startBlock2) && pointEquals(start2, startOfBlock);
|
|
14212
|
+
deleteExpandedRange(context, editor, at);
|
|
13820
14213
|
const atAfterDelete = atBeforeDelete.unref() ?? editor.selection, atBeforeInsert = atAfterDelete ? rangeRef(editor, atAfterDelete, {
|
|
13821
14214
|
affinity: "inward"
|
|
13822
14215
|
}) : void 0;
|
|
@@ -13843,11 +14236,15 @@ function insertBlock(options) {
|
|
|
13843
14236
|
type: "set_selection",
|
|
13844
14237
|
properties: editor.selection,
|
|
13845
14238
|
newProperties: atAfterInsert
|
|
13846
|
-
}), !
|
|
14239
|
+
}), !isTextBlock({
|
|
14240
|
+
schema: editor.schema
|
|
14241
|
+
}, block) && atAfterDelete) {
|
|
13847
14242
|
const emptyBlockPath = isAtStartOfBlock ? [atAfterDelete.anchor.path[0] + 1] : [atAfterDelete.anchor.path[0]];
|
|
13848
14243
|
try {
|
|
13849
14244
|
const potentiallyEmptyBlock = getNode(editor, emptyBlockPath, editor.schema);
|
|
13850
|
-
|
|
14245
|
+
isTextBlock({
|
|
14246
|
+
schema: editor.schema
|
|
14247
|
+
}, potentiallyEmptyBlock) && isEmptyTextBlock(context, potentiallyEmptyBlock) && editor.apply({
|
|
13851
14248
|
type: "remove_node",
|
|
13852
14249
|
path: emptyBlockPath,
|
|
13853
14250
|
node: potentiallyEmptyBlock
|
|
@@ -13857,12 +14254,16 @@ function insertBlock(options) {
|
|
|
13857
14254
|
}
|
|
13858
14255
|
return;
|
|
13859
14256
|
}
|
|
13860
|
-
if (!
|
|
14257
|
+
if (!isTextBlock({
|
|
14258
|
+
schema: editor.schema
|
|
14259
|
+
}, block) && isTextBlock({
|
|
14260
|
+
schema: editor.schema
|
|
14261
|
+
}, endBlock) && !isExpandedRange(at)) {
|
|
13861
14262
|
const selectionPoint = rangeStart(at), blockPath = [selectionPoint.path[0]], blockStartPoint = start(editor, blockPath), blockEndPoint = end(editor, blockPath), isAtBlockStart = pointEquals(selectionPoint, blockStartPoint), isAtBlockEnd = pointEquals(selectionPoint, blockEndPoint);
|
|
13862
14263
|
if (!isAtBlockStart && !isAtBlockEnd) {
|
|
13863
|
-
const currentBlock =
|
|
14264
|
+
const currentBlock = getTextBlockNode(editor, blockPath, editor.schema), childIndex = selectionPoint.path[1], childOffset = selectionPoint.offset;
|
|
13864
14265
|
if (childOffset > 0) {
|
|
13865
|
-
const textNode =
|
|
14266
|
+
const textNode = getSpanNode(editor, selectionPoint.path, editor.schema);
|
|
13866
14267
|
if (childOffset < textNode.text.length) {
|
|
13867
14268
|
const {
|
|
13868
14269
|
text: _2,
|
|
@@ -13915,14 +14316,20 @@ function insertBlock(options) {
|
|
|
13915
14316
|
return;
|
|
13916
14317
|
}
|
|
13917
14318
|
}
|
|
13918
|
-
if (
|
|
14319
|
+
if (isTextBlock({
|
|
14320
|
+
schema: editor.schema
|
|
14321
|
+
}, endBlock) && isTextBlock({
|
|
14322
|
+
schema: editor.schema
|
|
14323
|
+
}, block)) {
|
|
13919
14324
|
let selectionStartPoint = rangeStart(at), wasCrossBlockDeletion = !1;
|
|
13920
14325
|
if (isExpandedRange(at)) {
|
|
13921
14326
|
const [start2, end2] = rangeEdges(at), isCrossBlock = start2.path[0] !== end2.path[0];
|
|
13922
|
-
if (deleteExpandedRange(editor, at), isCrossBlock) {
|
|
14327
|
+
if (deleteExpandedRange(context, editor, at), isCrossBlock) {
|
|
13923
14328
|
wasCrossBlockDeletion = !0;
|
|
13924
14329
|
const startBlockPath2 = [start2.path[0]], mergedBlock = getNode(editor, startBlockPath2, editor.schema);
|
|
13925
|
-
if (
|
|
14330
|
+
if (isTextBlock({
|
|
14331
|
+
schema: editor.schema
|
|
14332
|
+
}, mergedBlock)) {
|
|
13926
14333
|
const mergePoint = {
|
|
13927
14334
|
path: [...startBlockPath2, start2.path[1]],
|
|
13928
14335
|
offset: start2.offset
|
|
@@ -13933,11 +14340,21 @@ function insertBlock(options) {
|
|
|
13933
14340
|
const [newEndBlock, newEndBlockPath] = Array.from(nodes(editor, {
|
|
13934
14341
|
at: end(editor, []),
|
|
13935
14342
|
mode: "lowest",
|
|
13936
|
-
match: (node2, path2) => (
|
|
14343
|
+
match: (node2, path2) => (isTextBlock({
|
|
14344
|
+
schema: editor.schema
|
|
14345
|
+
}, node2) || isObjectNode({
|
|
14346
|
+
schema: editor.schema
|
|
14347
|
+
}, node2)) && path2.length === 1
|
|
13937
14348
|
})).at(-1) ?? [void 0, void 0];
|
|
13938
|
-
newEndBlock && newEndBlockPath && (
|
|
13939
|
-
|
|
13940
|
-
|
|
14349
|
+
newEndBlock && newEndBlockPath && (isTextBlock({
|
|
14350
|
+
schema: editor.schema
|
|
14351
|
+
}, newEndBlock) || isObjectNode({
|
|
14352
|
+
schema: editor.schema
|
|
14353
|
+
}, newEndBlock)) && (endBlock = newEndBlock, endBlockPath = newEndBlockPath);
|
|
14354
|
+
}
|
|
14355
|
+
if (!isTextBlock({
|
|
14356
|
+
schema: editor.schema
|
|
14357
|
+
}, endBlock))
|
|
13941
14358
|
return;
|
|
13942
14359
|
if (isEmptyTextBlock(context, endBlock)) {
|
|
13943
14360
|
replaceEmptyTextBlock(editor, endBlockPath, block, select2);
|
|
@@ -13967,7 +14384,9 @@ function insertBlock(options) {
|
|
|
13967
14384
|
_key: context.keyGenerator()
|
|
13968
14385
|
} : child;
|
|
13969
14386
|
}), endBlockNode = getNode(editor, endBlockPath, editor.schema);
|
|
13970
|
-
if (
|
|
14387
|
+
if (isTextBlock({
|
|
14388
|
+
schema: editor.schema
|
|
14389
|
+
}, endBlockNode)) {
|
|
13971
14390
|
const properties = {
|
|
13972
14391
|
markDefs: endBlockNode.markDefs
|
|
13973
14392
|
}, newProperties = {
|
|
@@ -13986,10 +14405,10 @@ function insertBlock(options) {
|
|
|
13986
14405
|
};
|
|
13987
14406
|
if (select2 === "end") {
|
|
13988
14407
|
const insertAt = editor.selection ? rangeEnd(editor.selection) : end(editor, endBlockPath);
|
|
13989
|
-
insertTextBlockFragment(editor, adjustedBlock, insertAt);
|
|
14408
|
+
insertTextBlockFragment(context, editor, adjustedBlock, insertAt);
|
|
13990
14409
|
return;
|
|
13991
14410
|
}
|
|
13992
|
-
if (insertTextBlockFragment(editor, adjustedBlock, selectionStartPoint), select2 === "start")
|
|
14411
|
+
if (insertTextBlockFragment(context, editor, adjustedBlock, selectionStartPoint), select2 === "start")
|
|
13993
14412
|
setSelectionToPoint(editor, selectionStartPoint);
|
|
13994
14413
|
else if (select2 === "none")
|
|
13995
14414
|
if (wasCrossBlockDeletion)
|
|
@@ -13999,7 +14418,9 @@ function insertBlock(options) {
|
|
|
13999
14418
|
pointEquals(selectionStartPoint, endBlockStartPoint) || setSelectionToPoint(editor, selectionStartPoint);
|
|
14000
14419
|
}
|
|
14001
14420
|
} else {
|
|
14002
|
-
if (!
|
|
14421
|
+
if (!isTextBlock({
|
|
14422
|
+
schema: editor.schema
|
|
14423
|
+
}, endBlock)) {
|
|
14003
14424
|
insertNodeAt(editor, [endBlockPath[0] + 1], block, select2);
|
|
14004
14425
|
return;
|
|
14005
14426
|
}
|
|
@@ -14030,7 +14451,7 @@ function insertBlock(options) {
|
|
|
14030
14451
|
return;
|
|
14031
14452
|
}
|
|
14032
14453
|
if (isExpandedRange(at) && pointEquals(selectionStartPoint, endBlockStartPoint)) {
|
|
14033
|
-
const [, end2] = rangeEdges(at), endNode =
|
|
14454
|
+
const [, end2] = rangeEdges(at), endNode = getSpanNode(editor, end2.path, editor.schema);
|
|
14034
14455
|
end2.offset > 0 && editor.apply({
|
|
14035
14456
|
type: "remove_text",
|
|
14036
14457
|
path: end2.path,
|
|
@@ -14039,43 +14460,47 @@ function insertBlock(options) {
|
|
|
14039
14460
|
});
|
|
14040
14461
|
for (let i = end2.path[1] - 1; i >= 0; i--)
|
|
14041
14462
|
removeNodeAt(editor, [...endBlockPath, i]);
|
|
14042
|
-
insertTextBlockFragment(editor, block, start(editor, endBlockPath)), select2 !== "none" && setSelection(editor, endBlockPath, select2);
|
|
14463
|
+
insertTextBlockFragment(context, editor, block, start(editor, endBlockPath)), select2 !== "none" && setSelection(editor, endBlockPath, select2);
|
|
14043
14464
|
return;
|
|
14044
14465
|
}
|
|
14045
14466
|
if (isExpandedRange(at) && pointEquals(selectionEndPoint, endBlockEndPoint)) {
|
|
14046
|
-
const [start2] = rangeEdges(at), blockNode =
|
|
14467
|
+
const [start2] = rangeEdges(at), blockNode = getTextBlockNode(editor, endBlockPath, editor.schema);
|
|
14047
14468
|
for (let i = blockNode.children.length - 1; i > start2.path[1]; i--)
|
|
14048
14469
|
removeNodeAt(editor, [...endBlockPath, i]);
|
|
14049
|
-
const startNode =
|
|
14470
|
+
const startNode = getSpanNode(editor, start2.path, editor.schema);
|
|
14050
14471
|
start2.offset < startNode.text.length && editor.apply({
|
|
14051
14472
|
type: "remove_text",
|
|
14052
14473
|
path: start2.path,
|
|
14053
14474
|
offset: start2.offset,
|
|
14054
14475
|
text: startNode.text.slice(start2.offset)
|
|
14055
|
-
}), insertTextBlockFragment(editor, block, start2), select2 !== "none" && setSelection(editor, nextPath(endBlockPath), select2);
|
|
14476
|
+
}), insertTextBlockFragment(context, editor, block, start2), select2 !== "none" && setSelection(editor, nextPath(endBlockPath), select2);
|
|
14056
14477
|
return;
|
|
14057
14478
|
}
|
|
14058
14479
|
const [focusChild] = getFocusChild({
|
|
14059
14480
|
editor
|
|
14060
14481
|
});
|
|
14061
|
-
if (focusChild &&
|
|
14482
|
+
if (focusChild && isSpan({
|
|
14483
|
+
schema: editor.schema
|
|
14484
|
+
}, focusChild)) {
|
|
14062
14485
|
const startPoint = rangeStart(at);
|
|
14063
|
-
if (
|
|
14486
|
+
if (isTextBlock({
|
|
14487
|
+
schema: editor.schema
|
|
14488
|
+
}, block)) {
|
|
14064
14489
|
const nodeToSplit = getNode(editor, startPoint.path, editor.schema);
|
|
14065
|
-
if (
|
|
14490
|
+
if (isSpan(context, nodeToSplit)) {
|
|
14066
14491
|
const {
|
|
14067
14492
|
text: _,
|
|
14068
14493
|
...properties
|
|
14069
14494
|
} = nodeToSplit;
|
|
14070
14495
|
applySplitNode(editor, startPoint.path, startPoint.offset, properties);
|
|
14071
14496
|
}
|
|
14072
|
-
insertTextBlockFragment(editor, block, startPoint), select2 === "none" ? setSelectionToRange(editor, at) : setSelection(editor, [endBlockPath[0] + 1], "start");
|
|
14497
|
+
insertTextBlockFragment(context, editor, block, startPoint), select2 === "none" ? setSelectionToRange(editor, at) : setSelection(editor, [endBlockPath[0] + 1], "start");
|
|
14073
14498
|
} else {
|
|
14074
14499
|
let currentPath = startPoint.path, currentOffset = startPoint.offset;
|
|
14075
14500
|
const cursorPositionRef = pointRef(editor, startPoint, {
|
|
14076
14501
|
affinity: "backward"
|
|
14077
14502
|
}), blockPath = [currentPath[0]], firstBlockPathRef = pathRef(editor, blockPath), textNode = getNode(editor, currentPath, editor.schema);
|
|
14078
|
-
if (
|
|
14503
|
+
if (isSpan(context, textNode) && currentOffset > 0 && currentOffset < textNode.text.length) {
|
|
14079
14504
|
const {
|
|
14080
14505
|
text: _,
|
|
14081
14506
|
...properties
|
|
@@ -14083,7 +14508,9 @@ function insertBlock(options) {
|
|
|
14083
14508
|
applySplitNode(editor, currentPath, currentOffset, properties), currentPath = nextPath(currentPath), currentOffset = 0;
|
|
14084
14509
|
}
|
|
14085
14510
|
const splitAtIndex = currentOffset > 0 ? currentPath[1] + 1 : currentPath[1], blockToSplit = getNode(editor, blockPath, editor.schema);
|
|
14086
|
-
if (
|
|
14511
|
+
if (isTextBlock({
|
|
14512
|
+
schema: editor.schema
|
|
14513
|
+
}, blockToSplit) && splitAtIndex < blockToSplit.children.length) {
|
|
14087
14514
|
const {
|
|
14088
14515
|
children: _,
|
|
14089
14516
|
...blockProperties
|
|
@@ -14195,10 +14622,10 @@ function replaceEmptyTextBlock(editor, blockPath, newBlock, select2) {
|
|
|
14195
14622
|
}
|
|
14196
14623
|
});
|
|
14197
14624
|
}
|
|
14198
|
-
function deleteSameBlockRange(editor, start2, end2) {
|
|
14625
|
+
function deleteSameBlockRange(context, editor, start2, end2) {
|
|
14199
14626
|
const blockPath = [start2.path[0]];
|
|
14200
14627
|
if (pathEquals(start2.path, end2.path)) {
|
|
14201
|
-
const textToRemove =
|
|
14628
|
+
const textToRemove = getSpanNode(editor, start2.path, editor.schema).text.slice(start2.offset, end2.offset);
|
|
14202
14629
|
editor.apply({
|
|
14203
14630
|
type: "remove_text",
|
|
14204
14631
|
path: start2.path,
|
|
@@ -14207,7 +14634,7 @@ function deleteSameBlockRange(editor, start2, end2) {
|
|
|
14207
14634
|
});
|
|
14208
14635
|
return;
|
|
14209
14636
|
}
|
|
14210
|
-
const startNode =
|
|
14637
|
+
const startNode = getSpanNode(editor, start2.path, editor.schema);
|
|
14211
14638
|
if (start2.offset < startNode.text.length) {
|
|
14212
14639
|
const textToRemove = startNode.text.slice(start2.offset);
|
|
14213
14640
|
editor.apply({
|
|
@@ -14219,7 +14646,7 @@ function deleteSameBlockRange(editor, start2, end2) {
|
|
|
14219
14646
|
}
|
|
14220
14647
|
for (let i = end2.path[1] - 1; i > start2.path[1]; i--)
|
|
14221
14648
|
removeNodeAt(editor, [...blockPath, i]);
|
|
14222
|
-
const newEndPath = [...blockPath, start2.path[1] + 1], endNode =
|
|
14649
|
+
const newEndPath = [...blockPath, start2.path[1] + 1], endNode = getSpanNode(editor, newEndPath, editor.schema);
|
|
14223
14650
|
if (end2.offset > 0) {
|
|
14224
14651
|
const textToRemove = endNode.text.slice(0, end2.offset);
|
|
14225
14652
|
editor.apply({
|
|
@@ -14230,12 +14657,12 @@ function deleteSameBlockRange(editor, start2, end2) {
|
|
|
14230
14657
|
});
|
|
14231
14658
|
}
|
|
14232
14659
|
const startNodeAfter = getNode(editor, start2.path, editor.schema), endNodeAfter = getNode(editor, newEndPath, editor.schema);
|
|
14233
|
-
|
|
14660
|
+
isSpan(context, startNodeAfter) && isSpan(context, endNodeAfter) && applyMergeNode(editor, newEndPath, startNodeAfter.text.length);
|
|
14234
14661
|
}
|
|
14235
14662
|
function deleteCrossBlockRange(editor, start2, end2) {
|
|
14236
14663
|
const startBlockPath = [start2.path[0]];
|
|
14237
14664
|
if (start2.path.length > 1) {
|
|
14238
|
-
const startNode =
|
|
14665
|
+
const startNode = getSpanNode(editor, start2.path, editor.schema);
|
|
14239
14666
|
if (start2.offset < startNode.text.length) {
|
|
14240
14667
|
const textToRemove = startNode.text.slice(start2.offset);
|
|
14241
14668
|
editor.apply({
|
|
@@ -14245,7 +14672,7 @@ function deleteCrossBlockRange(editor, start2, end2) {
|
|
|
14245
14672
|
text: textToRemove
|
|
14246
14673
|
});
|
|
14247
14674
|
}
|
|
14248
|
-
const startBlock2 =
|
|
14675
|
+
const startBlock2 = getTextBlockNode(editor, startBlockPath, editor.schema);
|
|
14249
14676
|
for (let i = startBlock2.children.length - 1; i > start2.path[1]; i--)
|
|
14250
14677
|
removeNodeAt(editor, [...startBlockPath, i]);
|
|
14251
14678
|
}
|
|
@@ -14255,7 +14682,7 @@ function deleteCrossBlockRange(editor, start2, end2) {
|
|
|
14255
14682
|
if (end2.path.length > 1) {
|
|
14256
14683
|
for (let i = 0; i < end2.path[1]; i++)
|
|
14257
14684
|
removeNodeAt(editor, [...adjustedEndBlockPath, 0]);
|
|
14258
|
-
const endNodePath = [...adjustedEndBlockPath, 0], endNode =
|
|
14685
|
+
const endNodePath = [...adjustedEndBlockPath, 0], endNode = getSpanNode(editor, endNodePath, editor.schema);
|
|
14259
14686
|
if (end2.offset > 0) {
|
|
14260
14687
|
const textToRemove = endNode.text.slice(0, end2.offset);
|
|
14261
14688
|
editor.apply({
|
|
@@ -14267,7 +14694,11 @@ function deleteCrossBlockRange(editor, start2, end2) {
|
|
|
14267
14694
|
}
|
|
14268
14695
|
}
|
|
14269
14696
|
const startBlock = getNode(editor, startBlockPath, editor.schema), endBlock = getNode(editor, adjustedEndBlockPath, editor.schema);
|
|
14270
|
-
|
|
14697
|
+
isTextBlock({
|
|
14698
|
+
schema: editor.schema
|
|
14699
|
+
}, startBlock) && isTextBlock({
|
|
14700
|
+
schema: editor.schema
|
|
14701
|
+
}, endBlock) && withoutNormalizing(editor, () => {
|
|
14271
14702
|
if (Array.isArray(endBlock.markDefs) && endBlock.markDefs.length > 0) {
|
|
14272
14703
|
const oldDefs = Array.isArray(startBlock.markDefs) && startBlock.markDefs || [], newMarkDefs = [...new Map([...oldDefs, ...endBlock.markDefs].map((def) => [def._key, def])).values()];
|
|
14273
14704
|
applySetNode(editor, {
|
|
@@ -14277,16 +14708,18 @@ function deleteCrossBlockRange(editor, start2, end2) {
|
|
|
14277
14708
|
applyMergeNode(editor, adjustedEndBlockPath, startBlock.children.length);
|
|
14278
14709
|
});
|
|
14279
14710
|
}
|
|
14280
|
-
function deleteExpandedRange(editor, range2) {
|
|
14711
|
+
function deleteExpandedRange(context, editor, range2) {
|
|
14281
14712
|
const [start2, end2] = rangeEdges(range2);
|
|
14282
|
-
start2.path[0] === end2.path[0] ? deleteSameBlockRange(editor, start2, end2) : deleteCrossBlockRange(editor, start2, end2);
|
|
14713
|
+
start2.path[0] === end2.path[0] ? deleteSameBlockRange(context, editor, start2, end2) : deleteCrossBlockRange(editor, start2, end2);
|
|
14283
14714
|
}
|
|
14284
|
-
function insertTextBlockFragment(editor, block, at) {
|
|
14285
|
-
if (!
|
|
14715
|
+
function insertTextBlockFragment(context, editor, block, at) {
|
|
14716
|
+
if (!isTextBlock({
|
|
14717
|
+
schema: editor.schema
|
|
14718
|
+
}, block))
|
|
14286
14719
|
return;
|
|
14287
14720
|
if (at.offset > 0) {
|
|
14288
14721
|
const textNode = getNode(editor, at.path, editor.schema);
|
|
14289
|
-
if (
|
|
14722
|
+
if (isSpan(context, textNode)) {
|
|
14290
14723
|
const {
|
|
14291
14724
|
text: _,
|
|
14292
14725
|
...properties
|
|
@@ -14375,11 +14808,15 @@ const insertChildOperationImplementation = ({
|
|
|
14375
14808
|
offset
|
|
14376
14809
|
} = selection.anchor;
|
|
14377
14810
|
const node2 = getNode(editor, path2, editor.schema);
|
|
14378
|
-
if (
|
|
14811
|
+
if (isObjectNode({
|
|
14812
|
+
schema: editor.schema
|
|
14813
|
+
}, node2)) {
|
|
14379
14814
|
const next2 = nextPath(path2);
|
|
14380
14815
|
if (hasPath(editor, next2)) {
|
|
14381
14816
|
const nextNode = getNode(editor, next2, editor.schema);
|
|
14382
|
-
if (
|
|
14817
|
+
if (isSpan({
|
|
14818
|
+
schema: editor.schema
|
|
14819
|
+
}, nextNode))
|
|
14383
14820
|
path2 = next2, offset = 0, applySelect(editor, {
|
|
14384
14821
|
path: path2,
|
|
14385
14822
|
offset
|
|
@@ -14388,7 +14825,7 @@ const insertChildOperationImplementation = ({
|
|
|
14388
14825
|
return;
|
|
14389
14826
|
} else
|
|
14390
14827
|
return;
|
|
14391
|
-
} else if (
|
|
14828
|
+
} else if (getObjectNode(editor, {
|
|
14392
14829
|
at: selection
|
|
14393
14830
|
}) || elementReadOnly(editor, {
|
|
14394
14831
|
at: selection
|
|
@@ -18277,7 +18714,11 @@ function updateBlock({
|
|
|
18277
18714
|
path: [index],
|
|
18278
18715
|
properties: removedProperties,
|
|
18279
18716
|
newProperties: {}
|
|
18280
|
-
}),
|
|
18717
|
+
}), isTextBlock({
|
|
18718
|
+
schema: slateEditor.schema
|
|
18719
|
+
}, slateBlock) && isTextBlock({
|
|
18720
|
+
schema: slateEditor.schema
|
|
18721
|
+
}, oldSlateBlock)) {
|
|
18281
18722
|
const oldBlockChildrenLength = oldSlateBlock.children.length;
|
|
18282
18723
|
slateBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - slateBlock.children.length)).forEach((_, i) => {
|
|
18283
18724
|
const childIndex = oldBlockChildrenLength - 1 - i;
|
|
@@ -18291,7 +18732,9 @@ function updateBlock({
|
|
|
18291
18732
|
});
|
|
18292
18733
|
}
|
|
18293
18734
|
}), slateBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
18294
|
-
const oldBlockChild = oldSlateBlock.children.at(currentBlockChildIndex), isChildChanged = !oldBlockChild || !isEqualChild(currentBlockChild, oldBlockChild, slateEditor.schema.span.name), isTextChanged = oldBlockChild &&
|
|
18735
|
+
const oldBlockChild = oldSlateBlock.children.at(currentBlockChildIndex), isChildChanged = !oldBlockChild || !isEqualChild(currentBlockChild, oldBlockChild, slateEditor.schema.span.name), isTextChanged = oldBlockChild && isSpan({
|
|
18736
|
+
schema: slateEditor.schema
|
|
18737
|
+
}, oldBlockChild) && currentBlockChild.text !== oldBlockChild.text, path2 = [index, currentBlockChildIndex];
|
|
18295
18738
|
if (isChildChanged)
|
|
18296
18739
|
if (currentBlockChild._key === oldBlockChild?._key && currentBlockChild._type === oldBlockChild?._type) {
|
|
18297
18740
|
debug$1.syncValue("Updating changed child", currentBlockChild, oldBlockChild), applySetNode(slateEditor, currentBlockChild, path2);
|
|
@@ -18345,19 +18788,19 @@ function createInternalEditor(config) {
|
|
|
18345
18788
|
editorActor,
|
|
18346
18789
|
relayActor,
|
|
18347
18790
|
subscriptions
|
|
18348
|
-
}), editable = createEditableAPI(slateEditor
|
|
18791
|
+
}), editable = createEditableAPI(slateEditor, editorActor), {
|
|
18349
18792
|
mutationActor,
|
|
18350
18793
|
syncActor
|
|
18351
18794
|
} = createActors({
|
|
18352
18795
|
editorActor,
|
|
18353
18796
|
relayActor,
|
|
18354
|
-
slateEditor
|
|
18797
|
+
slateEditor,
|
|
18355
18798
|
subscriptions
|
|
18356
18799
|
}), editor = {
|
|
18357
|
-
dom: createEditorDom((event) => editorActor.send(event), slateEditor
|
|
18800
|
+
dom: createEditorDom((event) => editorActor.send(event), slateEditor),
|
|
18358
18801
|
getSnapshot: () => getEditorSnapshot({
|
|
18359
18802
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
18360
|
-
slateEditorInstance: slateEditor
|
|
18803
|
+
slateEditorInstance: slateEditor
|
|
18361
18804
|
}),
|
|
18362
18805
|
registerBehavior: (behaviorConfig) => {
|
|
18363
18806
|
const priority = createEditorPriority({
|
|
@@ -18392,7 +18835,7 @@ function createInternalEditor(config) {
|
|
|
18392
18835
|
default:
|
|
18393
18836
|
editorActor.send(rerouteExternalBehaviorEvent({
|
|
18394
18837
|
event,
|
|
18395
|
-
slateEditor
|
|
18838
|
+
slateEditor
|
|
18396
18839
|
}));
|
|
18397
18840
|
}
|
|
18398
18841
|
},
|
|
@@ -18928,7 +19371,7 @@ class PortableTextEditor {
|
|
|
18928
19371
|
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
18929
19372
|
}
|
|
18930
19373
|
function EditorProvider(props) {
|
|
18931
|
-
const $ = c(
|
|
19374
|
+
const $ = c(26);
|
|
18932
19375
|
let t0;
|
|
18933
19376
|
$[0] !== props.initialConfig ? (t0 = () => {
|
|
18934
19377
|
const internalEditor = createInternalEditor(props.initialConfig), portableTextEditor = new PortableTextEditor({
|
|
@@ -18944,31 +19387,31 @@ function EditorProvider(props) {
|
|
|
18944
19387
|
portableTextEditor: portableTextEditor_0
|
|
18945
19388
|
} = t1;
|
|
18946
19389
|
let t2;
|
|
18947
|
-
$[2] !== internalEditor_0.actors.editorActor || $[3] !== internalEditor_0.actors.mutationActor || $[4] !== internalEditor_0.actors.relayActor || $[5] !== internalEditor_0.actors.syncActor || $[6] !== internalEditor_0.editor._internal.slateEditor
|
|
19390
|
+
$[2] !== internalEditor_0.actors.editorActor || $[3] !== internalEditor_0.actors.mutationActor || $[4] !== internalEditor_0.actors.relayActor || $[5] !== internalEditor_0.actors.syncActor || $[6] !== internalEditor_0.editor._internal.slateEditor || $[7] !== internalEditor_0.subscriptions ? (t2 = () => {
|
|
18948
19391
|
const unsubscribers = [];
|
|
18949
19392
|
for (const subscription of internalEditor_0.subscriptions)
|
|
18950
19393
|
unsubscribers.push(subscription());
|
|
18951
19394
|
return internalEditor_0.actors.editorActor.start(), internalEditor_0.actors.editorActor.send({
|
|
18952
19395
|
type: "add slate editor",
|
|
18953
|
-
editor: internalEditor_0.editor._internal.slateEditor
|
|
19396
|
+
editor: internalEditor_0.editor._internal.slateEditor
|
|
18954
19397
|
}), internalEditor_0.actors.mutationActor.start(), internalEditor_0.actors.relayActor.start(), internalEditor_0.actors.syncActor.start(), () => {
|
|
18955
19398
|
for (const unsubscribe of unsubscribers)
|
|
18956
19399
|
unsubscribe();
|
|
18957
19400
|
stopActor(internalEditor_0.actors.editorActor), stopActor(internalEditor_0.actors.mutationActor), stopActor(internalEditor_0.actors.relayActor), stopActor(internalEditor_0.actors.syncActor);
|
|
18958
19401
|
};
|
|
18959
|
-
}, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.relayActor, $[5] = internalEditor_0.actors.syncActor, $[6] = internalEditor_0.editor._internal.slateEditor
|
|
19402
|
+
}, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.relayActor, $[5] = internalEditor_0.actors.syncActor, $[6] = internalEditor_0.editor._internal.slateEditor, $[7] = internalEditor_0.subscriptions, $[8] = t2) : t2 = $[8];
|
|
18960
19403
|
let t3;
|
|
18961
19404
|
$[9] !== internalEditor_0 ? (t3 = [internalEditor_0], $[9] = internalEditor_0, $[10] = t3) : t3 = $[10], useEffect(t2, t3);
|
|
18962
19405
|
let t4;
|
|
18963
19406
|
$[11] !== portableTextEditor_0 || $[12] !== props.children ? (t4 = /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: portableTextEditor_0, children: props.children }), $[11] = portableTextEditor_0, $[12] = props.children, $[13] = t4) : t4 = $[13];
|
|
18964
19407
|
let t5;
|
|
18965
|
-
$[14] !== internalEditor_0.editor._internal.slateEditor
|
|
19408
|
+
$[14] !== internalEditor_0.editor._internal.slateEditor || $[15] !== t4 ? (t5 = /* @__PURE__ */ jsx(Slate, { editor: internalEditor_0.editor._internal.slateEditor, children: t4 }), $[14] = internalEditor_0.editor._internal.slateEditor, $[15] = t4, $[16] = t5) : t5 = $[16];
|
|
18966
19409
|
let t6;
|
|
18967
|
-
$[
|
|
19410
|
+
$[17] !== internalEditor_0.actors.relayActor || $[18] !== t5 ? (t6 = /* @__PURE__ */ jsx(RelayActorContext.Provider, { value: internalEditor_0.actors.relayActor, children: t5 }), $[17] = internalEditor_0.actors.relayActor, $[18] = t5, $[19] = t6) : t6 = $[19];
|
|
18968
19411
|
let t7;
|
|
18969
|
-
$[
|
|
19412
|
+
$[20] !== internalEditor_0.actors.editorActor || $[21] !== t6 ? (t7 = /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: internalEditor_0.actors.editorActor, children: t6 }), $[20] = internalEditor_0.actors.editorActor, $[21] = t6, $[22] = t7) : t7 = $[22];
|
|
18970
19413
|
let t8;
|
|
18971
|
-
return $[
|
|
19414
|
+
return $[23] !== internalEditor_0.editor || $[24] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorContext$1.Provider, { value: internalEditor_0.editor, children: t7 }), $[23] = internalEditor_0.editor, $[24] = t7, $[25] = t8) : t8 = $[25], t8;
|
|
18972
19415
|
}
|
|
18973
19416
|
const usePortableTextEditorSelection = () => {
|
|
18974
19417
|
const $ = c(5), editorActor = useContext(EditorActorContext);
|