@portabletext/editor 6.1.1 → 6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js
CHANGED
|
@@ -36,9 +36,6 @@ const debug$1 = {
|
|
|
36
36
|
syncValue: createDebugger("sync:value"),
|
|
37
37
|
syncPatch: createDebugger("sync:patch")
|
|
38
38
|
}, Operation = {
|
|
39
|
-
isNodeOperation(value) {
|
|
40
|
-
return Operation.isOperation(value) && value.type.endsWith("_node");
|
|
41
|
-
},
|
|
42
39
|
isOperation(value) {
|
|
43
40
|
if (!isObject(value))
|
|
44
41
|
return !1;
|
|
@@ -68,12 +65,6 @@ const debug$1 = {
|
|
|
68
65
|
isOperationList(value) {
|
|
69
66
|
return Array.isArray(value) && value.every((val) => Operation.isOperation(val));
|
|
70
67
|
},
|
|
71
|
-
isSelectionOperation(value) {
|
|
72
|
-
return Operation.isOperation(value) && value.type.endsWith("_selection");
|
|
73
|
-
},
|
|
74
|
-
isTextOperation(value) {
|
|
75
|
-
return Operation.isOperation(value) && value.type.endsWith("_text");
|
|
76
|
-
},
|
|
77
68
|
inverse(op) {
|
|
78
69
|
switch (op.type) {
|
|
79
70
|
case "insert_node":
|
|
@@ -177,10 +168,6 @@ const debug$1 = {
|
|
|
177
168
|
equals(range2, another) {
|
|
178
169
|
return Point.equals(range2.anchor, another.anchor) && Point.equals(range2.focus, another.focus);
|
|
179
170
|
},
|
|
180
|
-
surrounds(range2, target) {
|
|
181
|
-
const intersectionRange = Range.intersection(range2, target);
|
|
182
|
-
return intersectionRange ? Range.equals(intersectionRange, target) : !1;
|
|
183
|
-
},
|
|
184
171
|
includes(range2, target) {
|
|
185
172
|
if (Range.isRange(target)) {
|
|
186
173
|
if (Range.includes(range2, target.anchor) || Range.includes(range2, target.focus))
|
|
@@ -280,18 +267,6 @@ const debug$1 = {
|
|
|
280
267
|
},
|
|
281
268
|
isElement(value, schema) {
|
|
282
269
|
return isObject(value) && value._type === schema.block.name;
|
|
283
|
-
},
|
|
284
|
-
isElementList(value, schema) {
|
|
285
|
-
return Array.isArray(value) && value.every((val) => Element$2.isElement(val, schema));
|
|
286
|
-
},
|
|
287
|
-
isElementProps(props) {
|
|
288
|
-
return props.children !== void 0;
|
|
289
|
-
},
|
|
290
|
-
matches(element, props) {
|
|
291
|
-
for (const key in props)
|
|
292
|
-
if (key !== "children" && element[key] !== props[key])
|
|
293
|
-
return !1;
|
|
294
|
-
return !0;
|
|
295
270
|
}
|
|
296
271
|
}, Span = {
|
|
297
272
|
isSpan(value) {
|
|
@@ -331,10 +306,6 @@ const debug$1 = {
|
|
|
331
306
|
throw new Error(`Cannot get the ancestor node at path [${path2}] because it refers to a leaf node instead: ${Scrubber.stringify(node2)}`);
|
|
332
307
|
return node2;
|
|
333
308
|
},
|
|
334
|
-
*ancestors(root, path2, schema, options = {}) {
|
|
335
|
-
for (const p of Path.ancestors(path2, options))
|
|
336
|
-
yield [Node$1.ancestor(root, p, schema), p];
|
|
337
|
-
},
|
|
338
309
|
child(root, index, schema) {
|
|
339
310
|
if (Text$1.isText(root, schema) || Node$1.isObjectNode(root, schema))
|
|
340
311
|
throw new Error(`Cannot get the child of a leaf node: ${Scrubber.stringify(root)}`);
|
|
@@ -355,24 +326,6 @@ const debug$1 = {
|
|
|
355
326
|
yield [child, childPath], index = reverse ? index - 1 : index + 1;
|
|
356
327
|
}
|
|
357
328
|
},
|
|
358
|
-
common(root, path2, another, schema) {
|
|
359
|
-
const p = Path.common(path2, another);
|
|
360
|
-
return [Node$1.get(root, p, schema), p];
|
|
361
|
-
},
|
|
362
|
-
descendant(root, path2, schema) {
|
|
363
|
-
const node2 = Node$1.get(root, path2, schema);
|
|
364
|
-
if (Editor.isEditor(node2))
|
|
365
|
-
throw new Error(`Cannot get the descendant node at path [${path2}] because it refers to the root editor node instead: ${Scrubber.stringify(node2)}`);
|
|
366
|
-
return node2;
|
|
367
|
-
},
|
|
368
|
-
*descendants(root, schema, options = {}) {
|
|
369
|
-
for (const [node2, path2] of Node$1.nodes(root, schema, options))
|
|
370
|
-
path2.length !== 0 && (yield [node2, path2]);
|
|
371
|
-
},
|
|
372
|
-
*elements(root, schema, options = {}) {
|
|
373
|
-
for (const [node2, path2] of Node$1.nodes(root, schema, options))
|
|
374
|
-
Element$2.isElement(node2, schema) && (yield [node2, path2]);
|
|
375
|
-
},
|
|
376
329
|
extractProps(node2, schema) {
|
|
377
330
|
if (Element$2.isAncestor(node2, schema)) {
|
|
378
331
|
const {
|
|
@@ -503,9 +456,6 @@ const debug$1 = {
|
|
|
503
456
|
for (const p of Path.levels(path2, options))
|
|
504
457
|
yield [Node$1.get(root, p, schema), p];
|
|
505
458
|
},
|
|
506
|
-
matches(node2, props, schema) {
|
|
507
|
-
return Element$2.isElement(node2, schema) && Element$2.isElementProps(props) && Element$2.matches(node2, props) || Text$1.isText(node2, schema) && Text$1.isTextProps(props) && Text$1.matches(node2, props);
|
|
508
|
-
},
|
|
509
459
|
*nodes(root, schema, options = {}) {
|
|
510
460
|
const {
|
|
511
461
|
pass,
|
|
@@ -593,14 +543,6 @@ const debug$1 = {
|
|
|
593
543
|
}
|
|
594
544
|
return 0;
|
|
595
545
|
},
|
|
596
|
-
endsAfter(path2, another) {
|
|
597
|
-
const i = path2.length - 1, as = path2.slice(0, i), bs = another.slice(0, i), av = path2[i], bv = another[i];
|
|
598
|
-
return Path.equals(as, bs) && av > bv;
|
|
599
|
-
},
|
|
600
|
-
endsAt(path2, another) {
|
|
601
|
-
const i = path2.length, as = path2.slice(0, i), bs = another.slice(0, i);
|
|
602
|
-
return Path.equals(as, bs);
|
|
603
|
-
},
|
|
604
546
|
endsBefore(path2, another) {
|
|
605
547
|
const i = path2.length - 1, as = path2.slice(0, i), bs = another.slice(0, i), av = path2[i], bv = another[i];
|
|
606
548
|
return Path.equals(as, bs) && av < bv;
|
|
@@ -620,18 +562,12 @@ const debug$1 = {
|
|
|
620
562
|
isBefore(path2, another) {
|
|
621
563
|
return Path.compare(path2, another) === -1;
|
|
622
564
|
},
|
|
623
|
-
isChild(path2, another) {
|
|
624
|
-
return path2.length === another.length + 1 && Path.compare(path2, another) === 0;
|
|
625
|
-
},
|
|
626
565
|
isCommon(path2, another) {
|
|
627
566
|
return path2.length <= another.length && Path.compare(path2, another) === 0;
|
|
628
567
|
},
|
|
629
568
|
isDescendant(path2, another) {
|
|
630
569
|
return path2.length > another.length && Path.compare(path2, another) === 0;
|
|
631
570
|
},
|
|
632
|
-
isParent(path2, another) {
|
|
633
|
-
return path2.length + 1 === another.length && Path.compare(path2, another) === 0;
|
|
634
|
-
},
|
|
635
571
|
isPath(value) {
|
|
636
572
|
return Array.isArray(value) && (value.length === 0 || typeof value[0] == "number");
|
|
637
573
|
},
|
|
@@ -680,11 +616,6 @@ const debug$1 = {
|
|
|
680
616
|
throw new Error(`Cannot get the previous path of a first child path [${path2}] because it would result in a negative index.`);
|
|
681
617
|
return path2.slice(0, -1).concat(last - 1);
|
|
682
618
|
},
|
|
683
|
-
relative(path2, ancestor) {
|
|
684
|
-
if (!Path.isAncestor(ancestor, path2) && !Path.equals(path2, ancestor))
|
|
685
|
-
throw new Error(`Cannot get the relative path of [${path2}] inside ancestor [${ancestor}], because it is not above or equal to the path.`);
|
|
686
|
-
return path2.slice(ancestor.length);
|
|
687
|
-
},
|
|
688
619
|
transform(path2, operation, options = {}) {
|
|
689
620
|
if (!path2)
|
|
690
621
|
return null;
|
|
@@ -844,14 +775,9 @@ const debug$1 = {
|
|
|
844
775
|
});
|
|
845
776
|
ref.current = path2, path2 == null && ref.unref();
|
|
846
777
|
}
|
|
847
|
-
}
|
|
848
|
-
let _scrubber;
|
|
849
|
-
const Scrubber = {
|
|
850
|
-
setScrubber(scrubber) {
|
|
851
|
-
_scrubber = scrubber;
|
|
852
|
-
},
|
|
778
|
+
}, Scrubber = {
|
|
853
779
|
stringify(value) {
|
|
854
|
-
return JSON.stringify(value
|
|
780
|
+
return JSON.stringify(value);
|
|
855
781
|
}
|
|
856
782
|
}, Text$1 = {
|
|
857
783
|
equals(text, another, options = {}) {
|
|
@@ -870,18 +796,6 @@ const Scrubber = {
|
|
|
870
796
|
isText(value, schema) {
|
|
871
797
|
return isObject(value) && value._type === schema.span.name;
|
|
872
798
|
},
|
|
873
|
-
isTextList(value, schema) {
|
|
874
|
-
return Array.isArray(value) && value.every((val) => Text$1.isText(val, schema));
|
|
875
|
-
},
|
|
876
|
-
isTextProps(props) {
|
|
877
|
-
return props.text !== void 0;
|
|
878
|
-
},
|
|
879
|
-
matches(text, props) {
|
|
880
|
-
for (const key in props)
|
|
881
|
-
if (key !== "text" && (!text.hasOwnProperty(key) || text[key] !== props[key]))
|
|
882
|
-
return !1;
|
|
883
|
-
return !0;
|
|
884
|
-
},
|
|
885
799
|
decorations(node2, decorations) {
|
|
886
800
|
let leaves = [{
|
|
887
801
|
leaf: {
|
|
@@ -1431,9 +1345,6 @@ const endingEmojiZWJ = new RegExp("\\p{ExtPict}[\\p{Gr_Ext}\\p{EMod}]*\\u200D$",
|
|
|
1431
1345
|
levels(editor, options) {
|
|
1432
1346
|
return editor.levels(options);
|
|
1433
1347
|
},
|
|
1434
|
-
marks(editor) {
|
|
1435
|
-
return editor.getMarks();
|
|
1436
|
-
},
|
|
1437
1348
|
next(editor, options) {
|
|
1438
1349
|
return editor.next(options);
|
|
1439
1350
|
},
|
|
@@ -1775,13 +1686,13 @@ const apply$1 = (editor, op) => {
|
|
|
1775
1686
|
}, hasInlines = (editor, element) => element.children.some((n2) => Text$1.isText(n2, editor.schema) || Editor.isInline(editor, n2)), hasPath = (editor, path2) => Node$1.has(editor, path2, editor.schema), insertText = (editor, text, options = {}) => {
|
|
1776
1687
|
const {
|
|
1777
1688
|
selection,
|
|
1778
|
-
marks
|
|
1689
|
+
marks
|
|
1779
1690
|
} = editor;
|
|
1780
1691
|
if (selection) {
|
|
1781
|
-
if (
|
|
1692
|
+
if (marks) {
|
|
1782
1693
|
const node2 = {
|
|
1783
1694
|
text,
|
|
1784
|
-
...
|
|
1695
|
+
...marks
|
|
1785
1696
|
};
|
|
1786
1697
|
Transforms.insertNodes(editor, node2, {
|
|
1787
1698
|
at: options.at,
|
|
@@ -1818,64 +1729,7 @@ function* levels(editor, options = {}) {
|
|
|
1818
1729
|
match2(n2, p) && levels2.push([n2, p]);
|
|
1819
1730
|
reverse && levels2.reverse(), yield* levels2;
|
|
1820
1731
|
}
|
|
1821
|
-
const
|
|
1822
|
-
const {
|
|
1823
|
-
marks: marks2,
|
|
1824
|
-
selection
|
|
1825
|
-
} = editor;
|
|
1826
|
-
if (!selection)
|
|
1827
|
-
return null;
|
|
1828
|
-
let {
|
|
1829
|
-
anchor,
|
|
1830
|
-
focus
|
|
1831
|
-
} = selection;
|
|
1832
|
-
if (marks2)
|
|
1833
|
-
return marks2;
|
|
1834
|
-
if (Range.isExpanded(selection)) {
|
|
1835
|
-
if (Range.isBackward(selection) && ([focus, anchor] = [anchor, focus]), Editor.isEnd(editor, anchor, anchor.path)) {
|
|
1836
|
-
const after2 = Editor.after(editor, anchor);
|
|
1837
|
-
after2 && (anchor = after2);
|
|
1838
|
-
}
|
|
1839
|
-
const [match2] = Editor.nodes(editor, {
|
|
1840
|
-
match: (n2) => Text$1.isText(n2, editor.schema),
|
|
1841
|
-
at: {
|
|
1842
|
-
anchor,
|
|
1843
|
-
focus
|
|
1844
|
-
}
|
|
1845
|
-
});
|
|
1846
|
-
if (match2) {
|
|
1847
|
-
const [node22] = match2, {
|
|
1848
|
-
text: _text,
|
|
1849
|
-
...rest2
|
|
1850
|
-
} = node22;
|
|
1851
|
-
return rest2;
|
|
1852
|
-
} else
|
|
1853
|
-
return {};
|
|
1854
|
-
}
|
|
1855
|
-
const {
|
|
1856
|
-
path: path2
|
|
1857
|
-
} = anchor;
|
|
1858
|
-
let [node2] = Editor.leaf(editor, path2);
|
|
1859
|
-
if (!Text$1.isText(node2, editor.schema))
|
|
1860
|
-
return {};
|
|
1861
|
-
if (anchor.offset === 0) {
|
|
1862
|
-
const prev = Editor.previous(editor, {
|
|
1863
|
-
at: path2,
|
|
1864
|
-
match: (n2) => Text$1.isText(n2, editor.schema)
|
|
1865
|
-
}), block = Editor.above(editor, {
|
|
1866
|
-
match: (n2) => Element$2.isElement(n2, editor.schema) && Editor.isBlock(editor, n2)
|
|
1867
|
-
});
|
|
1868
|
-
if (prev && block) {
|
|
1869
|
-
const [prevNode, prevPath] = prev, [, blockPath] = block;
|
|
1870
|
-
Path.isAncestor(blockPath, prevPath) && (node2 = prevNode);
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
const {
|
|
1874
|
-
text: _text2,
|
|
1875
|
-
...rest
|
|
1876
|
-
} = node2;
|
|
1877
|
-
return rest;
|
|
1878
|
-
}, next = (editor, options = {}) => {
|
|
1732
|
+
const next = (editor, options = {}) => {
|
|
1879
1733
|
const {
|
|
1880
1734
|
mode = "lowest",
|
|
1881
1735
|
voids = !1
|
|
@@ -2889,7 +2743,6 @@ const previous = (editor, options = {}) => {
|
|
|
2889
2743
|
deselect: (...args) => deselect(e, ...args),
|
|
2890
2744
|
elementReadOnly: (...args) => elementReadOnly(e, ...args),
|
|
2891
2745
|
end: (...args) => end(e, ...args),
|
|
2892
|
-
getMarks: (...args) => marks(e, ...args),
|
|
2893
2746
|
hasInlines: (...args) => hasInlines(e, ...args),
|
|
2894
2747
|
hasPath: (...args) => hasPath(e, ...args),
|
|
2895
2748
|
insertNodes: (...args) => insertNodes(e, ...args),
|
|
@@ -3048,10 +2901,7 @@ const previous = (editor, options = {}) => {
|
|
|
3048
2901
|
}
|
|
3049
2902
|
return !1;
|
|
3050
2903
|
}, IS_IOS = typeof navigator < "u" && typeof window < "u" && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, IS_ANDROID = typeof navigator < "u" && /Android/.test(navigator.userAgent), IS_FIREFOX = typeof navigator < "u" && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent), IS_WEBKIT = typeof navigator < "u" && /AppleWebKit(?!.*Chrome)/i.test(navigator.userAgent), IS_EDGE_LEGACY = typeof navigator < "u" && /Edge?\/(?:[0-6][0-9]|[0-7][0-8])(?:\.)/i.test(navigator.userAgent), IS_CHROME = typeof navigator < "u" && /Chrome/i.test(navigator.userAgent), IS_CHROME_LEGACY = typeof navigator < "u" && /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])(?:\.)/i.test(navigator.userAgent), IS_ANDROID_CHROME_LEGACY = IS_ANDROID && typeof navigator < "u" && /Chrome?\/(?:[0-5]?\d)(?:\.)/i.test(navigator.userAgent), IS_FIREFOX_LEGACY = typeof navigator < "u" && /^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])(?:\.)).*/i.test(navigator.userAgent), IS_UC_MOBILE = typeof navigator < "u" && /.*UCBrowser/.test(navigator.userAgent), IS_WECHATBROWSER = typeof navigator < "u" && /.*Wechat/.test(navigator.userAgent) && !/.*MacWechat/.test(navigator.userAgent) && // avoid lookbehind (buggy in safari < 16.4)
|
|
3051
|
-
(!IS_CHROME || IS_CHROME_LEGACY), CAN_USE_DOM = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u"
|
|
3052
|
-
typeof navigator < "u" && /Safari/.test(navigator.userAgent) && /Version\/(\\d+)/.test(navigator.userAgent) && (navigator.userAgent.match(/Version\/(\\d+)/)?.[1] && // biome-ignore lint/suspicious/noNonNullAssertedOptionalChain: Slate upstream — regex match guaranteed by outer test
|
|
3053
|
-
parseInt(navigator.userAgent.match(/Version\/(\\d+)/)?.[1], 10) < 17);
|
|
3054
|
-
const HAS_BEFORE_INPUT_SUPPORT = (!IS_CHROME_LEGACY || !IS_ANDROID_CHROME_LEGACY) && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
|
|
2904
|
+
(!IS_CHROME || IS_CHROME_LEGACY), CAN_USE_DOM = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", HAS_BEFORE_INPUT_SUPPORT = (!IS_CHROME_LEGACY || !IS_ANDROID_CHROME_LEGACY) && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
|
|
3055
2905
|
typeof globalThis < "u" && globalThis.InputEvent && typeof globalThis.InputEvent.prototype.getTargetRanges == "function";
|
|
3056
2906
|
let n = 0;
|
|
3057
2907
|
class Key {
|
|
@@ -3060,20 +2910,10 @@ class Key {
|
|
|
3060
2910
|
}
|
|
3061
2911
|
}
|
|
3062
2912
|
const DOMEditor = {
|
|
3063
|
-
androidPendingDiffs: (editor) => editor.pendingDiffs,
|
|
3064
|
-
androidScheduleFlush: (editor) => {
|
|
3065
|
-
editor.scheduleFlush?.();
|
|
3066
|
-
},
|
|
3067
2913
|
blur: (editor) => {
|
|
3068
2914
|
const el = DOMEditor.toDOMNode(editor, editor), root = DOMEditor.findDocumentOrShadowRoot(editor);
|
|
3069
2915
|
editor.focused = !1, root.activeElement === el && el.blur();
|
|
3070
2916
|
},
|
|
3071
|
-
deselect: (editor) => {
|
|
3072
|
-
const {
|
|
3073
|
-
selection
|
|
3074
|
-
} = editor, root = DOMEditor.findDocumentOrShadowRoot(editor), domSelection = getSelection(root);
|
|
3075
|
-
domSelection && domSelection.rangeCount > 0 && domSelection.removeAllRanges(), selection && Transforms.deselect(editor);
|
|
3076
|
-
},
|
|
3077
2917
|
findDocumentOrShadowRoot: (editor) => {
|
|
3078
2918
|
const el = DOMEditor.toDOMNode(editor, editor), root = el.getRootNode();
|
|
3079
2919
|
return root instanceof Document || root instanceof ShadowRoot ? root : el.ownerDocument;
|
|
@@ -3194,7 +3034,6 @@ const DOMEditor = {
|
|
|
3194
3034
|
hasTarget: (editor, target) => isDOMNode(target) && DOMEditor.hasDOMNode(editor, target),
|
|
3195
3035
|
isComposing: (editor) => !!editor.composing,
|
|
3196
3036
|
isFocused: (editor) => !!editor.focused,
|
|
3197
|
-
isReadOnly: (editor) => !!editor.readOnly,
|
|
3198
3037
|
isTargetInsideNonReadonlyVoid: (editor, target) => {
|
|
3199
3038
|
if (editor.readOnly)
|
|
3200
3039
|
return !1;
|
|
@@ -3734,14 +3573,12 @@ function transformTextDiff(textDiff, op) {
|
|
|
3734
3573
|
id
|
|
3735
3574
|
} : null;
|
|
3736
3575
|
}
|
|
3737
|
-
const withDOM = (editor
|
|
3576
|
+
const withDOM = (editor) => {
|
|
3738
3577
|
const e = editor, {
|
|
3739
3578
|
apply: apply2,
|
|
3740
3579
|
onChange
|
|
3741
3580
|
} = e;
|
|
3742
|
-
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.nodeToElement = /* @__PURE__ */ new WeakMap(), e.nodeToKey = /* @__PURE__ */ new WeakMap(), e.
|
|
3743
|
-
current: 0
|
|
3744
|
-
}, 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) => {
|
|
3581
|
+
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.nodeToElement = /* @__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) => {
|
|
3745
3582
|
const matches = [], pathRefMatches = [], pendingDiffs = e.pendingDiffs;
|
|
3746
3583
|
if (pendingDiffs?.length) {
|
|
3747
3584
|
const transformed = pendingDiffs.map((textDiff) => transformTextDiff(textDiff, op)).filter(Boolean);
|
|
@@ -3841,7 +3678,7 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
3841
3678
|
span.style.whiteSpace = "pre", span.appendChild(attach), contents.appendChild(span), attach = span;
|
|
3842
3679
|
}
|
|
3843
3680
|
const fragment = e.getFragment(), string2 = JSON.stringify(fragment), encoded = window.btoa(encodeURIComponent(string2));
|
|
3844
|
-
attach.setAttribute("data-slate-fragment", encoded), data.setData(
|
|
3681
|
+
attach.setAttribute("data-slate-fragment", encoded), data.setData("application/x-slate-fragment", encoded);
|
|
3845
3682
|
const div = contents.ownerDocument.createElement("div");
|
|
3846
3683
|
return div.appendChild(contents), div.setAttribute("hidden", "true"), contents.ownerDocument.body.appendChild(div), data.setData("text/html", div.innerHTML), data.setData("text/plain", getPlainText(div)), contents.ownerDocument.body.removeChild(div), data;
|
|
3847
3684
|
}, e.insertData = (data) => {
|
|
@@ -4018,22 +3855,6 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
4018
3855
|
meta: !1,
|
|
4019
3856
|
alt: !1
|
|
4020
3857
|
}]
|
|
4021
|
-
}), extendBackward = createKeyboardShortcut({
|
|
4022
|
-
default: [{
|
|
4023
|
-
key: "ArrowLeft",
|
|
4024
|
-
shift: !0,
|
|
4025
|
-
ctrl: !1,
|
|
4026
|
-
meta: !1,
|
|
4027
|
-
alt: !1
|
|
4028
|
-
}]
|
|
4029
|
-
}), extendForward = createKeyboardShortcut({
|
|
4030
|
-
default: [{
|
|
4031
|
-
key: "ArrowRight",
|
|
4032
|
-
shift: !0,
|
|
4033
|
-
ctrl: !1,
|
|
4034
|
-
meta: !1,
|
|
4035
|
-
alt: !1
|
|
4036
|
-
}]
|
|
4037
3858
|
}), italic = createKeyboardShortcut({
|
|
4038
3859
|
default: [{
|
|
4039
3860
|
key: "I",
|
|
@@ -4241,8 +4062,6 @@ var Hotkeys = {
|
|
|
4241
4062
|
isDeleteLineForward: deleteLineForward.guard,
|
|
4242
4063
|
isDeleteWordBackward: deleteWordBackward.guard,
|
|
4243
4064
|
isDeleteWordForward: deleteWordForward.guard,
|
|
4244
|
-
isExtendBackward: extendBackward.guard,
|
|
4245
|
-
isExtendForward: extendForward.guard,
|
|
4246
4065
|
isExtendLineBackward: extendLineBackward.guard,
|
|
4247
4066
|
isExtendLineForward: extendLineForward.guard,
|
|
4248
4067
|
isItalic: italic.guard,
|
|
@@ -6788,9 +6607,9 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6788
6607
|
});
|
|
6789
6608
|
}
|
|
6790
6609
|
const {
|
|
6791
|
-
marks
|
|
6610
|
+
marks
|
|
6792
6611
|
} = editor;
|
|
6793
|
-
if (state.hasMarkPlaceholder = !1, editor.selection && Range.isCollapsed(editor.selection) &&
|
|
6612
|
+
if (state.hasMarkPlaceholder = !1, editor.selection && Range.isCollapsed(editor.selection) && marks) {
|
|
6794
6613
|
const {
|
|
6795
6614
|
anchor
|
|
6796
6615
|
} = editor.selection, leaf2 = Node$1.leaf(editor, anchor.path, editor.schema);
|
|
@@ -6799,7 +6618,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6799
6618
|
text: _text,
|
|
6800
6619
|
...rest
|
|
6801
6620
|
} = leaf2;
|
|
6802
|
-
if (!Text$1.equals(leaf2,
|
|
6621
|
+
if (!Text$1.equals(leaf2, marks, {
|
|
6803
6622
|
loose: !0
|
|
6804
6623
|
})) {
|
|
6805
6624
|
state.hasMarkPlaceholder = !0;
|
|
@@ -6807,7 +6626,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6807
6626
|
decorations.push({
|
|
6808
6627
|
[MARK_PLACEHOLDER_SYMBOL]: !0,
|
|
6809
6628
|
...unset2,
|
|
6810
|
-
...
|
|
6629
|
+
...marks,
|
|
6811
6630
|
anchor,
|
|
6812
6631
|
focus: anchor
|
|
6813
6632
|
});
|
|
@@ -6825,10 +6644,10 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
|
|
|
6825
6644
|
} = selection, text = Node$1.leaf(editor, anchor.path, editor.schema);
|
|
6826
6645
|
if (!Text$1.isText(text, editor.schema))
|
|
6827
6646
|
return;
|
|
6828
|
-
if (
|
|
6647
|
+
if (marks && !Text$1.equals(text, marks, {
|
|
6829
6648
|
loose: !0
|
|
6830
6649
|
})) {
|
|
6831
|
-
editor.pendingInsertionMarks =
|
|
6650
|
+
editor.pendingInsertionMarks = marks;
|
|
6832
6651
|
return;
|
|
6833
6652
|
}
|
|
6834
6653
|
}
|
|
@@ -7706,9 +7525,9 @@ function requireReactDom() {
|
|
|
7706
7525
|
return process.env.NODE_ENV === "production" ? (checkDCE(), reactDom.exports = requireReactDom_production()) : reactDom.exports = requireReactDom_development(), reactDom.exports;
|
|
7707
7526
|
}
|
|
7708
7527
|
var reactDomExports = requireReactDom(), ReactDOM = /* @__PURE__ */ getDefaultExportFromCjs(reactDomExports);
|
|
7709
|
-
const withReact = (editor
|
|
7528
|
+
const withReact = (editor) => {
|
|
7710
7529
|
let e = editor;
|
|
7711
|
-
e = withDOM(e
|
|
7530
|
+
e = withDOM(e);
|
|
7712
7531
|
const {
|
|
7713
7532
|
onChange,
|
|
7714
7533
|
apply: apply2,
|
|
@@ -10985,11 +10804,11 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10985
10804
|
const decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name);
|
|
10986
10805
|
for (const [child, childPath] of Node$1.children(editor, path2, editor.schema))
|
|
10987
10806
|
if (editor.isTextSpan(child)) {
|
|
10988
|
-
const
|
|
10807
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !node2.markDefs?.find((def) => def._key === mark));
|
|
10989
10808
|
if (orphanedAnnotations.length > 0) {
|
|
10990
10809
|
debug$1.normalization("removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
10991
10810
|
applySetNode(editor, {
|
|
10992
|
-
marks:
|
|
10811
|
+
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
10993
10812
|
}, childPath);
|
|
10994
10813
|
});
|
|
10995
10814
|
return;
|
|
@@ -10999,11 +10818,11 @@ function createNormalizationPlugin(editorActor) {
|
|
|
10999
10818
|
if (editor.isTextSpan(node2)) {
|
|
11000
10819
|
const blockPath = Path.parent(path2), [block] = Editor.node(editor, blockPath);
|
|
11001
10820
|
if (editor.isTextBlock(block)) {
|
|
11002
|
-
const decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name),
|
|
10821
|
+
const decorators = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node2.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
11003
10822
|
if (orphanedAnnotations.length > 0) {
|
|
11004
10823
|
debug$1.normalization("removing orphaned annotations from span node"), withNormalizeNode(editor, () => {
|
|
11005
10824
|
applySetNode(editor, {
|
|
11006
|
-
marks:
|
|
10825
|
+
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
11007
10826
|
}, path2);
|
|
11008
10827
|
});
|
|
11009
10828
|
return;
|
|
@@ -12661,9 +12480,9 @@ function createUniqueKeysPlugin(editorActor) {
|
|
|
12661
12480
|
let childIndex = 0;
|
|
12662
12481
|
for (const child of block.children) {
|
|
12663
12482
|
if (isSpan(editorActor.getSnapshot().context, child)) {
|
|
12664
|
-
const
|
|
12665
|
-
isEqualMarks(child.marks,
|
|
12666
|
-
marks
|
|
12483
|
+
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
12484
|
+
isEqualMarks(child.marks, marks) || applySetNode(editor, {
|
|
12485
|
+
marks
|
|
12667
12486
|
}, [index, childIndex]);
|
|
12668
12487
|
}
|
|
12669
12488
|
previousBlockChildKeys.includes(child._key) && applySetNode(editor, {
|
|
@@ -13069,10 +12888,10 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
13069
12888
|
const startChild = getSelectionStartChild(effectiveSnapshot), startPoint = getSelectionStartPoint(effectiveSnapshot), endChild = getSelectionEndChild(effectiveSnapshot), endPoint = getSelectionEndPoint(effectiveSnapshot);
|
|
13070
12889
|
if (!startChild || !endChild || !startPoint || !endPoint || startChild.path[2]._key !== endChild.path[2]._key || !isSpan(snapshot.context, startChild.node) || !(startPoint.offset === 0 && endPoint.offset === startChild.node.text.length))
|
|
13071
12890
|
return !1;
|
|
13072
|
-
const decorators = snapshot.context.schema.decorators.map((decorator) => decorator.name),
|
|
13073
|
-
if (!
|
|
12891
|
+
const decorators = snapshot.context.schema.decorators.map((decorator) => decorator.name), marks = startChild.node.marks ?? [];
|
|
12892
|
+
if (!marks.some((mark) => !decorators.includes(mark)))
|
|
13074
12893
|
return !1;
|
|
13075
|
-
const previousSpan = getPreviousSpan(effectiveSnapshot), nextSpan = getNextSpan(effectiveSnapshot), previousSpanHasSameAnnotation = previousSpan ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark) &&
|
|
12894
|
+
const previousSpan = getPreviousSpan(effectiveSnapshot), nextSpan = getNextSpan(effectiveSnapshot), previousSpanHasSameAnnotation = previousSpan ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? nextSpan.node.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
|
|
13076
12895
|
if (previousSpanHasSameAnnotation || nextSpanHasSameAnnotation)
|
|
13077
12896
|
return !1;
|
|
13078
12897
|
const activeDecorators = getActiveDecorators(effectiveSnapshot);
|
|
@@ -14418,9 +14237,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
14418
14237
|
for (const [span, path2] of children) {
|
|
14419
14238
|
if (!editor.isTextSpan(span) || !selectionRange || !Range.includes(selectionRange, path2))
|
|
14420
14239
|
continue;
|
|
14421
|
-
const
|
|
14240
|
+
const marks = span.marks ?? [];
|
|
14422
14241
|
applySetNode(editor, {
|
|
14423
|
-
marks: [...
|
|
14242
|
+
marks: [...marks, annotationKey]
|
|
14424
14243
|
}, path2);
|
|
14425
14244
|
}
|
|
14426
14245
|
blockIndex++;
|
|
@@ -14514,8 +14333,8 @@ const addAnnotationOperationImplementation = ({
|
|
|
14514
14333
|
for (const [child, childPath] of children) {
|
|
14515
14334
|
if (!editor.isTextSpan(child) || !selectionRange || !Range.includes(selectionRange, childPath))
|
|
14516
14335
|
continue;
|
|
14517
|
-
const markDefs = block.markDefs ?? [],
|
|
14518
|
-
marksWithoutAnnotation.length !==
|
|
14336
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
|
|
14337
|
+
marksWithoutAnnotation.length !== marks.length && applySetNode(editor, {
|
|
14519
14338
|
marks: marksWithoutAnnotation
|
|
14520
14339
|
}, childPath);
|
|
14521
14340
|
}
|
|
@@ -14762,9 +14581,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
14762
14581
|
match: (n2) => Text$1.isText(n2, editor.schema)
|
|
14763
14582
|
});
|
|
14764
14583
|
for (const [node2, path2] of splitTextNodes) {
|
|
14765
|
-
const
|
|
14584
|
+
const marks = [...(Array.isArray(node2.marks) ? node2.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
14766
14585
|
applySetNode(editor, {
|
|
14767
|
-
marks
|
|
14586
|
+
marks
|
|
14768
14587
|
}, path2);
|
|
14769
14588
|
}
|
|
14770
14589
|
} else {
|
|
@@ -15544,12 +15363,12 @@ function insertBlock(options) {
|
|
|
15544
15363
|
return markDef;
|
|
15545
15364
|
}), adjustedChildren = block.children.map((child) => {
|
|
15546
15365
|
if (isSpan(context, child)) {
|
|
15547
|
-
const
|
|
15548
|
-
if (!isEqualMarks(child.marks,
|
|
15366
|
+
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
15367
|
+
if (!isEqualMarks(child.marks, marks))
|
|
15549
15368
|
return {
|
|
15550
15369
|
...child,
|
|
15551
15370
|
_key: endBlockChildKeys.includes(child._key) ? context.keyGenerator() : child._key,
|
|
15552
|
-
marks
|
|
15371
|
+
marks
|
|
15553
15372
|
};
|
|
15554
15373
|
}
|
|
15555
15374
|
return endBlockChildKeys.includes(child._key) ? {
|