@portabletext/editor 1.55.13 → 1.55.15
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-cjs/{selector.is-selection-expanded.cjs → selector.get-focus-span.cjs} +27 -27
- package/lib/_chunks-cjs/selector.get-focus-span.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -3
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +291 -168
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.is-equal-selection-points.cjs → util.is-selection-collapsed.cjs} +7 -3
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.slice-text-block.cjs +2 -6
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
- package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-focus-span.js} +27 -27
- package/lib/_chunks-es/selector.get-focus-span.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +266 -143
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
- package/lib/_chunks-es/{util.is-equal-selection-points.js → util.is-selection-collapsed.js} +7 -3
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +2 -2
- package/lib/_chunks-es/util.slice-text-block.js +1 -5
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/behaviors/index.d.cts +3 -6
- package/lib/behaviors/index.d.ts +3 -6
- package/lib/index.cjs +357 -322
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +11 -20
- package/lib/index.d.ts +11 -20
- package/lib/index.js +296 -261
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -16
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +3 -6
- package/lib/plugins/index.d.ts +3 -6
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +14 -14
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +3 -6
- package/lib/selectors/index.d.ts +3 -6
- package/lib/selectors/index.js +2 -2
- package/lib/utils/index.cjs +9 -9
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3 -6
- package/lib/utils/index.d.ts +3 -6
- package/lib/utils/index.js +5 -5
- package/package.json +3 -3
- package/src/behaviors/behavior.abstract.ts +2 -1
- package/src/behaviors/behavior.core.dnd.ts +4 -4
- package/src/editor/Editable.tsx +8 -1
- package/src/editor/create-slate-editor.tsx +0 -1
- package/src/editor/editor-dom.ts +3 -3
- package/src/editor/editor-selector.ts +1 -13
- package/src/editor/editor-snapshot.ts +4 -19
- package/src/editor/plugins/createWithEditableAPI.ts +52 -13
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +13 -4
- package/src/editor/plugins/with-plugins.ts +4 -8
- package/src/editor/range-decorations-machine.ts +24 -12
- package/src/internal-utils/create-test-snapshot.ts +2 -5
- package/src/internal-utils/paths.ts +65 -17
- package/src/internal-utils/ranges.test.ts +179 -0
- package/src/internal-utils/ranges.ts +39 -22
- package/src/internal-utils/test-editor.tsx +16 -1
- package/src/operations/behavior.operation.block.set.ts +10 -6
- package/src/operations/behavior.operation.block.unset.ts +10 -6
- package/src/operations/behavior.operation.child.set.ts +10 -6
- package/src/operations/behavior.operation.child.unset.ts +10 -6
- package/src/operations/behavior.operation.decorator.add.ts +17 -6
- package/src/operations/behavior.operation.delete.ts +8 -1
- package/src/operations/behavior.operation.insert.text.ts +34 -20
- package/src/operations/behavior.operation.move.block.ts +25 -3
- package/src/operations/behavior.operation.select.ts +9 -2
- package/src/selectors/selector.get-active-annotation-marks.ts +12 -0
- package/src/selectors/selector.get-active-annotations.ts +8 -20
- package/src/{editor/get-active-decorators.ts → selectors/selector.get-active-decorators.ts} +6 -11
- package/src/{internal-utils/mark-state.ts → selectors/selector.get-mark-state.ts} +41 -67
- package/src/selectors/selector.get-next-span.ts +56 -0
- package/src/selectors/selector.get-previous-span.ts +53 -0
- package/src/selectors/selector.is-active-annotation.ts +3 -1
- package/src/selectors/selector.is-active-decorator.ts +4 -1
- package/src/types/editor.ts +0 -2
- package/src/utils/util.is-selection-expanded.ts +13 -0
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +0 -1
- package/src/editor/get-active-annotations.ts +0 -15
- package/src/editor/plugins/slate-plugin.update-mark-state.ts +0 -21
package/lib/index.js
CHANGED
|
@@ -9,12 +9,11 @@ import { Element as Element$1, Text, Range, Editor, Node, Point, Transforms, Pat
|
|
|
9
9
|
import { useSelected, useSlateSelector, useSlateStatic, withReact, ReactEditor, Slate, useSlate, Editable } from "slate-react";
|
|
10
10
|
import debug$f from "debug";
|
|
11
11
|
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
12
|
-
import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint,
|
|
13
|
-
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-
|
|
14
|
-
import { isSelectionCollapsed, selectionPointToBlockOffset, sliceTextBlock } from "./_chunks-es/util.slice-text-block.js";
|
|
12
|
+
import { getBlockStartPoint, getBlockKeyFromSelectionPoint, isTextBlock, getChildKeyFromSelectionPoint, isSpan, parseBlock, parseAnnotation, blockOffsetToSpanSelectionPoint, parseInlineObject, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
|
|
13
|
+
import { getBlockEndPoint, isSelectionCollapsed, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-selection-collapsed.js";
|
|
15
14
|
import isEqual from "lodash/isEqual.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
15
|
+
import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getActiveAnnotationsMarks, getTrimmedSelection, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
16
|
+
import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.get-focus-span.js";
|
|
18
17
|
import getRandomValues from "get-random-values-esm";
|
|
19
18
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
20
19
|
import uniq from "lodash/uniq.js";
|
|
@@ -27,6 +26,7 @@ import flatten from "lodash/flatten.js";
|
|
|
27
26
|
import omit from "lodash/omit.js";
|
|
28
27
|
import { applyAll, unset, insert, set, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
29
28
|
import { blockOffsetsToSelection } from "./_chunks-es/util.child-selection-point-to-block-offset.js";
|
|
29
|
+
import { selectionPointToBlockOffset, sliceTextBlock } from "./_chunks-es/util.slice-text-block.js";
|
|
30
30
|
import get from "lodash/get.js";
|
|
31
31
|
import isUndefined from "lodash/isUndefined.js";
|
|
32
32
|
import omitBy from "lodash/omitBy.js";
|
|
@@ -548,47 +548,78 @@ function getSlateRangeFromEvent(editor, event) {
|
|
|
548
548
|
}
|
|
549
549
|
return range;
|
|
550
550
|
}
|
|
551
|
-
function toSlatePath(
|
|
551
|
+
function toSlatePath(snapshot, path) {
|
|
552
552
|
const blockKey = getBlockKeyFromSelectionPoint({
|
|
553
553
|
path
|
|
554
554
|
});
|
|
555
555
|
if (!blockKey)
|
|
556
|
-
return
|
|
557
|
-
|
|
556
|
+
return {
|
|
557
|
+
block: void 0,
|
|
558
|
+
child: void 0,
|
|
559
|
+
path: []
|
|
560
|
+
};
|
|
561
|
+
const blockIndex = snapshot.blockIndexMap.get(blockKey);
|
|
558
562
|
if (blockIndex === void 0)
|
|
559
|
-
return
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
563
|
+
return {
|
|
564
|
+
block: void 0,
|
|
565
|
+
child: void 0,
|
|
566
|
+
path: []
|
|
567
|
+
};
|
|
568
|
+
const block = snapshot.context.value.at(blockIndex);
|
|
569
|
+
if (!block)
|
|
570
|
+
return {
|
|
571
|
+
block: void 0,
|
|
572
|
+
child: void 0,
|
|
573
|
+
path: []
|
|
574
|
+
};
|
|
575
|
+
if (!isTextBlock(snapshot.context, block))
|
|
576
|
+
return {
|
|
577
|
+
block,
|
|
578
|
+
child: void 0,
|
|
579
|
+
path: [blockIndex, 0]
|
|
580
|
+
};
|
|
565
581
|
const childKey = getChildKeyFromSelectionPoint({
|
|
566
582
|
path
|
|
567
583
|
});
|
|
568
584
|
if (!childKey)
|
|
569
|
-
return
|
|
570
|
-
|
|
585
|
+
return {
|
|
586
|
+
block,
|
|
587
|
+
child: void 0,
|
|
588
|
+
path: [blockIndex, 0]
|
|
589
|
+
};
|
|
590
|
+
let childPath = [], childIndex = -1, pathChild;
|
|
571
591
|
for (const child of block.children)
|
|
572
592
|
if (childIndex++, child._key === childKey) {
|
|
573
|
-
|
|
593
|
+
pathChild = child, isSpan(snapshot.context, child) ? childPath = [childIndex] : childPath = [childIndex, 0];
|
|
574
594
|
break;
|
|
575
595
|
}
|
|
576
|
-
return
|
|
596
|
+
return childPath.length === 0 ? {
|
|
597
|
+
block,
|
|
598
|
+
child: void 0,
|
|
599
|
+
path: [blockIndex, 0]
|
|
600
|
+
} : {
|
|
601
|
+
block,
|
|
602
|
+
child: pathChild,
|
|
603
|
+
path: [blockIndex].concat(childPath)
|
|
604
|
+
};
|
|
577
605
|
}
|
|
578
|
-
function toSlateRange(
|
|
579
|
-
if (!selection
|
|
606
|
+
function toSlateRange(snapshot) {
|
|
607
|
+
if (!snapshot.context.selection)
|
|
608
|
+
return null;
|
|
609
|
+
const anchorPath = toSlatePath(snapshot, snapshot.context.selection.anchor.path), focusPath = toSlatePath(snapshot, snapshot.context.selection.focus.path);
|
|
610
|
+
if (anchorPath.path.length === 0 || focusPath.path.length === 0)
|
|
580
611
|
return null;
|
|
581
|
-
const anchor =
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
612
|
+
const anchorOffset = anchorPath.child && isSpan(snapshot.context, anchorPath.child) ? Math.min(anchorPath.child.text.length, snapshot.context.selection.anchor.offset) : 0, focusOffset = focusPath.child && isSpan(snapshot.context, focusPath.child) ? Math.min(focusPath.child.text.length, snapshot.context.selection.focus.offset) : 0;
|
|
613
|
+
return {
|
|
614
|
+
anchor: {
|
|
615
|
+
path: anchorPath.path,
|
|
616
|
+
offset: anchorOffset
|
|
617
|
+
},
|
|
618
|
+
focus: {
|
|
619
|
+
path: focusPath.path,
|
|
620
|
+
offset: focusOffset
|
|
621
|
+
}
|
|
587
622
|
};
|
|
588
|
-
return focus.path.length === 0 || anchor.path.length === 0 ? null : anchor && focus ? {
|
|
589
|
-
anchor,
|
|
590
|
-
focus
|
|
591
|
-
} : null;
|
|
592
623
|
}
|
|
593
624
|
function moveRangeByOperation(range, operation) {
|
|
594
625
|
const anchor = Point.transform(range.anchor, operation), focus = Point.transform(range.focus, operation);
|
|
@@ -1372,43 +1403,34 @@ function createPlaceholderBlock(context) {
|
|
|
1372
1403
|
}]
|
|
1373
1404
|
};
|
|
1374
1405
|
}
|
|
1375
|
-
function getActiveAnnotations({
|
|
1376
|
-
markState,
|
|
1377
|
-
schema
|
|
1378
|
-
}) {
|
|
1379
|
-
return (markState?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
1380
|
-
}
|
|
1381
|
-
function getActiveDecorators({
|
|
1382
|
-
decoratorState,
|
|
1383
|
-
markState,
|
|
1384
|
-
schema
|
|
1385
|
-
}) {
|
|
1386
|
-
const decorators = schema.decorators.map((decorator) => decorator.name);
|
|
1387
|
-
let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
1388
|
-
for (const decorator in decoratorState)
|
|
1389
|
-
decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
|
|
1390
|
-
return activeDecorators;
|
|
1391
|
-
}
|
|
1392
1406
|
const insertTextOperationImplementation = ({
|
|
1393
1407
|
context,
|
|
1394
1408
|
operation
|
|
1395
1409
|
}) => {
|
|
1396
|
-
const
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1410
|
+
const snapshot = {
|
|
1411
|
+
blockIndexMap: operation.editor.blockIndexMap,
|
|
1412
|
+
context: {
|
|
1413
|
+
value: operation.editor.value,
|
|
1414
|
+
selection: operation.editor.selection ? slateRangeToSelection({
|
|
1415
|
+
schema: context.schema,
|
|
1416
|
+
editor: operation.editor,
|
|
1417
|
+
range: operation.editor.selection
|
|
1418
|
+
}) : null,
|
|
1419
|
+
schema: context.schema,
|
|
1420
|
+
keyGenerator: context.keyGenerator,
|
|
1421
|
+
converters: [],
|
|
1422
|
+
readOnly: !1
|
|
1423
|
+
},
|
|
1424
|
+
decoratorState: operation.editor.decoratorState
|
|
1425
|
+
}, markState = getMarkState(snapshot), activeDecorators = getActiveDecorators(snapshot), activeAnnotations = getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
|
|
1404
1426
|
editor: operation.editor
|
|
1405
1427
|
});
|
|
1406
1428
|
if (!focusSpan) {
|
|
1407
1429
|
Transforms.insertText(operation.editor, operation.text);
|
|
1408
1430
|
return;
|
|
1409
1431
|
}
|
|
1410
|
-
if (
|
|
1411
|
-
const markStateDecorators = (
|
|
1432
|
+
if (markState && markState.state === "unchanged") {
|
|
1433
|
+
const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
1412
1434
|
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
1413
1435
|
Transforms.insertText(operation.editor, operation.text);
|
|
1414
1436
|
return;
|
|
@@ -1522,17 +1544,7 @@ function getEditorSnapshot({
|
|
|
1522
1544
|
selection: editorActorSnapshot.context.selection,
|
|
1523
1545
|
value: slateEditorInstance.value
|
|
1524
1546
|
},
|
|
1525
|
-
|
|
1526
|
-
activeAnnotations: getActiveAnnotations({
|
|
1527
|
-
markState: slateEditorInstance.markState,
|
|
1528
|
-
schema: editorActorSnapshot.context.schema
|
|
1529
|
-
}),
|
|
1530
|
-
activeDecorators: getActiveDecorators({
|
|
1531
|
-
decoratorState: slateEditorInstance.decoratorState,
|
|
1532
|
-
markState: slateEditorInstance.markState,
|
|
1533
|
-
schema: editorActorSnapshot.context.schema
|
|
1534
|
-
})
|
|
1535
|
-
}
|
|
1547
|
+
decoratorState: slateEditorInstance.decoratorState
|
|
1536
1548
|
};
|
|
1537
1549
|
}
|
|
1538
1550
|
const debug$e = debugWithName("plugin:withPortableTextMarkModel");
|
|
@@ -1747,11 +1759,15 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1747
1759
|
}
|
|
1748
1760
|
}
|
|
1749
1761
|
if (op.type === "insert_text") {
|
|
1750
|
-
|
|
1762
|
+
const snapshot = getEditorSnapshot({
|
|
1763
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1764
|
+
slateEditorInstance: editor
|
|
1765
|
+
}), markState = getMarkState(snapshot);
|
|
1766
|
+
if (!markState) {
|
|
1751
1767
|
apply2(op);
|
|
1752
1768
|
return;
|
|
1753
1769
|
}
|
|
1754
|
-
if (
|
|
1770
|
+
if (markState.state === "unchanged") {
|
|
1755
1771
|
apply2(op);
|
|
1756
1772
|
return;
|
|
1757
1773
|
}
|
|
@@ -1759,7 +1775,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1759
1775
|
_type: "span",
|
|
1760
1776
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1761
1777
|
text: op.text,
|
|
1762
|
-
marks:
|
|
1778
|
+
marks: markState.marks
|
|
1763
1779
|
});
|
|
1764
1780
|
return;
|
|
1765
1781
|
}
|
|
@@ -1796,7 +1812,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1796
1812
|
});
|
|
1797
1813
|
Editor.withoutNormalizing(editor, () => {
|
|
1798
1814
|
apply2(op), Transforms.setNodes(editor, {
|
|
1799
|
-
marks: snapshot
|
|
1815
|
+
marks: getActiveDecorators(snapshot)
|
|
1800
1816
|
}, {
|
|
1801
1817
|
at: op.path
|
|
1802
1818
|
});
|
|
@@ -2919,15 +2935,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
2919
2935
|
operation
|
|
2920
2936
|
}) => {
|
|
2921
2937
|
const location = toSlateRange({
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2938
|
+
context: {
|
|
2939
|
+
schema: context.schema,
|
|
2940
|
+
value: operation.editor.value,
|
|
2941
|
+
selection: {
|
|
2942
|
+
anchor: {
|
|
2943
|
+
path: operation.at,
|
|
2944
|
+
offset: 0
|
|
2945
|
+
},
|
|
2946
|
+
focus: {
|
|
2947
|
+
path: operation.at,
|
|
2948
|
+
offset: 0
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2925
2951
|
},
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
offset: 0
|
|
2929
|
-
}
|
|
2930
|
-
}, operation.editor);
|
|
2952
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
2953
|
+
});
|
|
2931
2954
|
if (!location)
|
|
2932
2955
|
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
2933
2956
|
const block = Editor.node(operation.editor, location, {
|
|
@@ -2967,15 +2990,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
2967
2990
|
operation
|
|
2968
2991
|
}) => {
|
|
2969
2992
|
const location = toSlateRange({
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2993
|
+
context: {
|
|
2994
|
+
schema: context.schema,
|
|
2995
|
+
value: operation.editor.value,
|
|
2996
|
+
selection: {
|
|
2997
|
+
anchor: {
|
|
2998
|
+
path: operation.at,
|
|
2999
|
+
offset: 0
|
|
3000
|
+
},
|
|
3001
|
+
focus: {
|
|
3002
|
+
path: operation.at,
|
|
3003
|
+
offset: 0
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
2973
3006
|
},
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
offset: 0
|
|
2977
|
-
}
|
|
2978
|
-
}, operation.editor);
|
|
3007
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3008
|
+
});
|
|
2979
3009
|
if (!location)
|
|
2980
3010
|
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
2981
3011
|
const block = Editor.node(operation.editor, location, {
|
|
@@ -3032,15 +3062,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
3032
3062
|
operation
|
|
3033
3063
|
}) => {
|
|
3034
3064
|
const location = toSlateRange({
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3065
|
+
context: {
|
|
3066
|
+
schema: context.schema,
|
|
3067
|
+
value: operation.editor.value,
|
|
3068
|
+
selection: {
|
|
3069
|
+
anchor: {
|
|
3070
|
+
path: operation.at,
|
|
3071
|
+
offset: 0
|
|
3072
|
+
},
|
|
3073
|
+
focus: {
|
|
3074
|
+
path: operation.at,
|
|
3075
|
+
offset: 0
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3038
3078
|
},
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
offset: 0
|
|
3042
|
-
}
|
|
3043
|
-
}, operation.editor);
|
|
3079
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3080
|
+
});
|
|
3044
3081
|
if (!location)
|
|
3045
3082
|
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3046
3083
|
const childEntry = Editor.node(operation.editor, location, {
|
|
@@ -3101,15 +3138,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
3101
3138
|
operation
|
|
3102
3139
|
}) => {
|
|
3103
3140
|
const location = toSlateRange({
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3141
|
+
context: {
|
|
3142
|
+
schema: context.schema,
|
|
3143
|
+
value: operation.editor.value,
|
|
3144
|
+
selection: {
|
|
3145
|
+
anchor: {
|
|
3146
|
+
path: operation.at,
|
|
3147
|
+
offset: 0
|
|
3148
|
+
},
|
|
3149
|
+
focus: {
|
|
3150
|
+
path: operation.at,
|
|
3151
|
+
offset: 0
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3107
3154
|
},
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
offset: 0
|
|
3111
|
-
}
|
|
3112
|
-
}, operation.editor);
|
|
3155
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3156
|
+
});
|
|
3113
3157
|
if (!location)
|
|
3114
3158
|
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3115
3159
|
const childEntry = Editor.node(operation.editor, location, {
|
|
@@ -3174,7 +3218,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
3174
3218
|
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
3175
3219
|
anchor: manualAnchor,
|
|
3176
3220
|
focus: manualFocus
|
|
3177
|
-
} : void 0, selection = manualSelection ? toSlateRange(
|
|
3221
|
+
} : void 0, selection = manualSelection ? toSlateRange({
|
|
3222
|
+
context: {
|
|
3223
|
+
schema: context.schema,
|
|
3224
|
+
value: operation.editor.value,
|
|
3225
|
+
selection: manualSelection
|
|
3226
|
+
},
|
|
3227
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3228
|
+
}) ?? editor.selection : editor.selection;
|
|
3178
3229
|
if (!selection)
|
|
3179
3230
|
return;
|
|
3180
3231
|
const editorSelection = slateRangeToSelection({
|
|
@@ -3215,10 +3266,6 @@ const addAnnotationOperationImplementation = ({
|
|
|
3215
3266
|
backward: editorSelection?.backward
|
|
3216
3267
|
}), trimmedSelection = getTrimmedSelection({
|
|
3217
3268
|
blockIndexMap: editor.blockIndexMap,
|
|
3218
|
-
beta: {
|
|
3219
|
-
activeAnnotations: [],
|
|
3220
|
-
activeDecorators: []
|
|
3221
|
-
},
|
|
3222
3269
|
context: {
|
|
3223
3270
|
converters: [],
|
|
3224
3271
|
keyGenerator: context.keyGenerator,
|
|
@@ -3226,11 +3273,19 @@ const addAnnotationOperationImplementation = ({
|
|
|
3226
3273
|
schema: context.schema,
|
|
3227
3274
|
selection: newSelection,
|
|
3228
3275
|
value: newValue
|
|
3229
|
-
}
|
|
3276
|
+
},
|
|
3277
|
+
decoratorState: editor.decoratorState
|
|
3230
3278
|
});
|
|
3231
3279
|
if (!trimmedSelection)
|
|
3232
3280
|
throw new Error("Unable to find trimmed selection");
|
|
3233
|
-
const newRange = toSlateRange(
|
|
3281
|
+
const newRange = toSlateRange({
|
|
3282
|
+
context: {
|
|
3283
|
+
schema: context.schema,
|
|
3284
|
+
value: operation.editor.value,
|
|
3285
|
+
selection: trimmedSelection
|
|
3286
|
+
},
|
|
3287
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3288
|
+
});
|
|
3234
3289
|
if (!newRange)
|
|
3235
3290
|
throw new Error("Unable to find new selection");
|
|
3236
3291
|
const splitTextNodes = Range.isRange(newRange) ? [...Editor.nodes(editor, {
|
|
@@ -3291,7 +3346,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
3291
3346
|
}), operation.editor.children.length === 0 && Transforms.insertNodes(operation.editor, createPlaceholderBlock(context));
|
|
3292
3347
|
return;
|
|
3293
3348
|
}
|
|
3294
|
-
const range = toSlateRange(
|
|
3349
|
+
const range = toSlateRange({
|
|
3350
|
+
context: {
|
|
3351
|
+
schema: context.schema,
|
|
3352
|
+
value: operation.editor.value,
|
|
3353
|
+
selection: operation.at
|
|
3354
|
+
},
|
|
3355
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3356
|
+
});
|
|
3295
3357
|
if (!range)
|
|
3296
3358
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
|
|
3297
3359
|
operation.editor.delete({
|
|
@@ -3564,9 +3626,22 @@ const moveBackwardOperationImplementation = ({
|
|
|
3564
3626
|
reverse: !0
|
|
3565
3627
|
});
|
|
3566
3628
|
}, moveBlockOperationImplementation = ({
|
|
3629
|
+
context,
|
|
3567
3630
|
operation
|
|
3568
3631
|
}) => {
|
|
3569
|
-
const at = [toSlatePath(
|
|
3632
|
+
const at = [toSlatePath({
|
|
3633
|
+
context: {
|
|
3634
|
+
schema: context.schema,
|
|
3635
|
+
value: operation.editor.value
|
|
3636
|
+
},
|
|
3637
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3638
|
+
}, operation.at).path[0]], to = [toSlatePath({
|
|
3639
|
+
context: {
|
|
3640
|
+
schema: context.schema,
|
|
3641
|
+
value: operation.editor.value
|
|
3642
|
+
},
|
|
3643
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3644
|
+
}, operation.to).path[0]];
|
|
3570
3645
|
Transforms.moveNodes(operation.editor, {
|
|
3571
3646
|
at,
|
|
3572
3647
|
to,
|
|
@@ -3580,9 +3655,17 @@ const moveBackwardOperationImplementation = ({
|
|
|
3580
3655
|
distance: operation.distance
|
|
3581
3656
|
});
|
|
3582
3657
|
}, selectOperationImplementation = ({
|
|
3658
|
+
context,
|
|
3583
3659
|
operation
|
|
3584
3660
|
}) => {
|
|
3585
|
-
const newSelection = toSlateRange(
|
|
3661
|
+
const newSelection = toSlateRange({
|
|
3662
|
+
context: {
|
|
3663
|
+
schema: context.schema,
|
|
3664
|
+
value: operation.editor.value,
|
|
3665
|
+
selection: operation.at
|
|
3666
|
+
},
|
|
3667
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3668
|
+
});
|
|
3586
3669
|
newSelection ? Transforms.select(operation.editor, newSelection) : Transforms.deselect(operation.editor);
|
|
3587
3670
|
}, behaviorOperationImplementations = {
|
|
3588
3671
|
"annotation.add": addAnnotationOperationImplementation,
|
|
@@ -4829,110 +4912,6 @@ function createWithUtils({
|
|
|
4829
4912
|
})[0], editor;
|
|
4830
4913
|
};
|
|
4831
4914
|
}
|
|
4832
|
-
function getMarkState({
|
|
4833
|
-
schema,
|
|
4834
|
-
editor
|
|
4835
|
-
}) {
|
|
4836
|
-
if (!editor.selection)
|
|
4837
|
-
return;
|
|
4838
|
-
const [block, blockPath] = getFocusBlock({
|
|
4839
|
-
editor
|
|
4840
|
-
}), [span, spanPath] = getFocusSpan({
|
|
4841
|
-
editor
|
|
4842
|
-
});
|
|
4843
|
-
if (!block || !editor.isTextBlock(block) || !span)
|
|
4844
|
-
return;
|
|
4845
|
-
if (Range.isExpanded(editor.selection)) {
|
|
4846
|
-
const selection = editor.selection ? slateRangeToSelection({
|
|
4847
|
-
schema,
|
|
4848
|
-
editor,
|
|
4849
|
-
range: editor.selection
|
|
4850
|
-
}) : null, selectedSpans = getSelectedSpans({
|
|
4851
|
-
blockIndexMap: editor.blockIndexMap,
|
|
4852
|
-
context: {
|
|
4853
|
-
value: editor.value,
|
|
4854
|
-
selection,
|
|
4855
|
-
schema,
|
|
4856
|
-
converters: [],
|
|
4857
|
-
keyGenerator: () => "",
|
|
4858
|
-
readOnly: !1
|
|
4859
|
-
}
|
|
4860
|
-
});
|
|
4861
|
-
let index = 0, marks2 = [];
|
|
4862
|
-
for (const span2 of selectedSpans)
|
|
4863
|
-
index === 0 ? marks2 = span2.node.marks ?? [] : (span2.node.marks?.length === 0 || (span2.node.marks ?? [])?.some((mark) => !marks2.includes(mark))) && (marks2 = []), index++;
|
|
4864
|
-
return {
|
|
4865
|
-
state: "unchanged",
|
|
4866
|
-
marks: marks2
|
|
4867
|
-
};
|
|
4868
|
-
}
|
|
4869
|
-
const decorators = schema.decorators.map((decorator) => decorator.name), marks = span.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = editor.selection.anchor.offset === 0, atTheEndOfSpan = editor.selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
|
|
4870
|
-
editor,
|
|
4871
|
-
blockPath,
|
|
4872
|
-
spanPath
|
|
4873
|
-
}), nextSpan = getNextSpan({
|
|
4874
|
-
editor,
|
|
4875
|
-
blockPath,
|
|
4876
|
-
spanPath
|
|
4877
|
-
}), nextSpanAnnotations = nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
|
|
4878
|
-
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4879
|
-
if (atTheBeginningOfSpan) {
|
|
4880
|
-
if (previousSpanHasSameMarks)
|
|
4881
|
-
return {
|
|
4882
|
-
state: "changed",
|
|
4883
|
-
marks: previousSpan?.marks ?? []
|
|
4884
|
-
};
|
|
4885
|
-
if (previousSpanHasSameAnnotations)
|
|
4886
|
-
return {
|
|
4887
|
-
state: "changed",
|
|
4888
|
-
marks: previousSpan?.marks ?? []
|
|
4889
|
-
};
|
|
4890
|
-
if (previousSpanHasSameAnnotation)
|
|
4891
|
-
return {
|
|
4892
|
-
state: "unchanged",
|
|
4893
|
-
marks: span.marks ?? []
|
|
4894
|
-
};
|
|
4895
|
-
if (!previousSpan)
|
|
4896
|
-
return {
|
|
4897
|
-
state: "changed",
|
|
4898
|
-
marks: []
|
|
4899
|
-
};
|
|
4900
|
-
}
|
|
4901
|
-
if (atTheEndOfSpan) {
|
|
4902
|
-
if (nextSpan && nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations)
|
|
4903
|
-
return {
|
|
4904
|
-
state: "changed",
|
|
4905
|
-
marks: nextSpan?.marks ?? []
|
|
4906
|
-
};
|
|
4907
|
-
if (!nextSpan)
|
|
4908
|
-
return {
|
|
4909
|
-
state: "changed",
|
|
4910
|
-
marks: []
|
|
4911
|
-
};
|
|
4912
|
-
}
|
|
4913
|
-
}
|
|
4914
|
-
return atTheBeginningOfSpan && !spanIsEmpty && previousSpan ? previousSpanHasAnnotations ? {
|
|
4915
|
-
state: "changed",
|
|
4916
|
-
marks: []
|
|
4917
|
-
} : {
|
|
4918
|
-
state: "changed",
|
|
4919
|
-
marks: (previousSpan?.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
4920
|
-
} : {
|
|
4921
|
-
state: "unchanged",
|
|
4922
|
-
marks: span.marks ?? []
|
|
4923
|
-
};
|
|
4924
|
-
}
|
|
4925
|
-
function pluginUpdateMarkState(context, editor) {
|
|
4926
|
-
const {
|
|
4927
|
-
apply: apply2
|
|
4928
|
-
} = editor;
|
|
4929
|
-
return editor.apply = (operation) => {
|
|
4930
|
-
apply2(operation), editor.markState = getMarkState({
|
|
4931
|
-
editor,
|
|
4932
|
-
schema: context.schema
|
|
4933
|
-
});
|
|
4934
|
-
}, editor;
|
|
4935
|
-
}
|
|
4936
4915
|
function pluginUpdateSelection({
|
|
4937
4916
|
editor,
|
|
4938
4917
|
editorActor
|
|
@@ -5276,10 +5255,10 @@ const withPlugins = (editor, options) => {
|
|
|
5276
5255
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5277
5256
|
editorActor
|
|
5278
5257
|
});
|
|
5279
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateValue(editorActor.getSnapshot().context,
|
|
5258
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateSelection({
|
|
5280
5259
|
editorActor,
|
|
5281
5260
|
editor: e
|
|
5282
|
-
})))))))))))
|
|
5261
|
+
})))))))))));
|
|
5283
5262
|
}, debug$9 = debugWithName("setup");
|
|
5284
5263
|
function createSlateEditor(config) {
|
|
5285
5264
|
debug$9("Creating new Slate editor instance");
|
|
@@ -5288,7 +5267,7 @@ function createSlateEditor(config) {
|
|
|
5288
5267
|
relayActor: config.relayActor,
|
|
5289
5268
|
subscriptions: config.subscriptions
|
|
5290
5269
|
});
|
|
5291
|
-
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.decoratedRanges = [], instance.decoratorState = {}
|
|
5270
|
+
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.decoratedRanges = [], instance.decoratorState = {};
|
|
5292
5271
|
const placeholderBlock = createPlaceholderBlock(config.editorActor.getSnapshot().context);
|
|
5293
5272
|
instance.value = [placeholderBlock], instance.blockIndexMap = /* @__PURE__ */ new Map(), instance.listIndexMap = /* @__PURE__ */ new Map(), buildIndexMaps({
|
|
5294
5273
|
schema: config.editorActor.getSnapshot().context.schema,
|
|
@@ -5322,7 +5301,7 @@ function createEditorDom(sendBack, slateEditor) {
|
|
|
5322
5301
|
function getBlockNodes(slateEditor, snapshot) {
|
|
5323
5302
|
if (!snapshot.context.selection)
|
|
5324
5303
|
return [];
|
|
5325
|
-
const range = toSlateRange(snapshot
|
|
5304
|
+
const range = toSlateRange(snapshot);
|
|
5326
5305
|
if (!range)
|
|
5327
5306
|
return [];
|
|
5328
5307
|
try {
|
|
@@ -5338,7 +5317,7 @@ function getBlockNodes(slateEditor, snapshot) {
|
|
|
5338
5317
|
function getChildNodes(slateEditor, snapshot) {
|
|
5339
5318
|
if (!snapshot.context.selection)
|
|
5340
5319
|
return [];
|
|
5341
|
-
const range = toSlateRange(snapshot
|
|
5320
|
+
const range = toSlateRange(snapshot);
|
|
5342
5321
|
if (!range)
|
|
5343
5322
|
return [];
|
|
5344
5323
|
try {
|
|
@@ -6082,16 +6061,16 @@ const coreDndBehaviors = [
|
|
|
6082
6061
|
dragOrigin,
|
|
6083
6062
|
dropPosition,
|
|
6084
6063
|
originEvent
|
|
6085
|
-
}) => [
|
|
6064
|
+
}) => [raise({
|
|
6065
|
+
type: "select",
|
|
6066
|
+
at: dropPosition
|
|
6067
|
+
}), ...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
6086
6068
|
type: "delete.block",
|
|
6087
6069
|
at: block.path
|
|
6088
6070
|
})) : [raise({
|
|
6089
6071
|
type: "delete",
|
|
6090
6072
|
at: dragOrigin.selection
|
|
6091
6073
|
})], raise({
|
|
6092
|
-
type: "select",
|
|
6093
|
-
at: dropPosition
|
|
6094
|
-
}), raise({
|
|
6095
6074
|
type: "insert.blocks",
|
|
6096
6075
|
blocks: event.data,
|
|
6097
6076
|
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
@@ -7278,9 +7257,9 @@ const coreDndBehaviors = [
|
|
|
7278
7257
|
event
|
|
7279
7258
|
}) => {
|
|
7280
7259
|
if (getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
|
|
7281
|
-
const activeDecorators = snapshot
|
|
7260
|
+
const activeDecorators = getActiveDecorators(snapshot);
|
|
7282
7261
|
return {
|
|
7283
|
-
activeAnnotations: getActiveAnnotations
|
|
7262
|
+
activeAnnotations: getActiveAnnotations(snapshot),
|
|
7284
7263
|
activeDecorators,
|
|
7285
7264
|
textRuns: event.data.flatMap((block) => isTextBlock(snapshot.context, block) ? [getTextBlockText(block)] : [])
|
|
7286
7265
|
};
|
|
@@ -7654,17 +7633,7 @@ function createEditorSnapshot({
|
|
|
7654
7633
|
return {
|
|
7655
7634
|
blockIndexMap: editor.blockIndexMap,
|
|
7656
7635
|
context,
|
|
7657
|
-
|
|
7658
|
-
activeAnnotations: getActiveAnnotations({
|
|
7659
|
-
markState: editor.markState,
|
|
7660
|
-
schema
|
|
7661
|
-
}),
|
|
7662
|
-
activeDecorators: getActiveDecorators({
|
|
7663
|
-
decoratorState: editor.decoratorState,
|
|
7664
|
-
markState: editor.markState,
|
|
7665
|
-
schema
|
|
7666
|
-
})
|
|
7667
|
-
}
|
|
7636
|
+
decoratorState: editor.decoratorState
|
|
7668
7637
|
};
|
|
7669
7638
|
}
|
|
7670
7639
|
const debug$7 = debugWithName("editor machine"), editorMachine = setup({
|
|
@@ -8630,16 +8599,19 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8630
8599
|
editor
|
|
8631
8600
|
});
|
|
8632
8601
|
},
|
|
8633
|
-
isMarkActive: (mark) =>
|
|
8634
|
-
editorActorSnapshot: editorActor.getSnapshot(),
|
|
8635
|
-
slateEditorInstance: editor
|
|
8636
|
-
}).beta.activeDecorators.includes(mark),
|
|
8637
|
-
marks: () => {
|
|
8602
|
+
isMarkActive: (mark) => {
|
|
8638
8603
|
const snapshot = getEditorSnapshot({
|
|
8639
8604
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
8640
8605
|
slateEditorInstance: editor
|
|
8641
8606
|
});
|
|
8642
|
-
return
|
|
8607
|
+
return getActiveDecorators(snapshot).includes(mark);
|
|
8608
|
+
},
|
|
8609
|
+
marks: () => {
|
|
8610
|
+
const snapshot = getEditorSnapshot({
|
|
8611
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
8612
|
+
slateEditorInstance: editor
|
|
8613
|
+
}), activeAnnotations = getActiveAnnotationsMarks(snapshot), activeDecorators = getActiveDecorators(snapshot);
|
|
8614
|
+
return [...activeAnnotations, ...activeDecorators];
|
|
8643
8615
|
},
|
|
8644
8616
|
undo: () => {
|
|
8645
8617
|
editorActor.send({
|
|
@@ -8660,7 +8632,14 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8660
8632
|
});
|
|
8661
8633
|
},
|
|
8662
8634
|
select: (selection) => {
|
|
8663
|
-
const slateSelection = toSlateRange(
|
|
8635
|
+
const slateSelection = toSlateRange({
|
|
8636
|
+
context: {
|
|
8637
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8638
|
+
value: editor.value,
|
|
8639
|
+
selection
|
|
8640
|
+
},
|
|
8641
|
+
blockIndexMap: editor.blockIndexMap
|
|
8642
|
+
});
|
|
8664
8643
|
slateSelection ? Transforms.select(editor, slateSelection) : Transforms.deselect(editor), editor.onChange();
|
|
8665
8644
|
},
|
|
8666
8645
|
focusBlock: () => {
|
|
@@ -8766,15 +8745,22 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8766
8745
|
isVoid: (element) => ![types.block.name, types.span.name].includes(element._type),
|
|
8767
8746
|
findByPath: (path) => {
|
|
8768
8747
|
const slatePath = toSlateRange({
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8748
|
+
context: {
|
|
8749
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8750
|
+
value: editor.value,
|
|
8751
|
+
selection: {
|
|
8752
|
+
focus: {
|
|
8753
|
+
path,
|
|
8754
|
+
offset: 0
|
|
8755
|
+
},
|
|
8756
|
+
anchor: {
|
|
8757
|
+
path,
|
|
8758
|
+
offset: 0
|
|
8759
|
+
}
|
|
8760
|
+
}
|
|
8772
8761
|
},
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
offset: 0
|
|
8776
|
-
}
|
|
8777
|
-
}, editor);
|
|
8762
|
+
blockIndexMap: editor.blockIndexMap
|
|
8763
|
+
});
|
|
8778
8764
|
if (slatePath) {
|
|
8779
8765
|
const [block, blockPath] = Editor.node(editor, slatePath.focus.path.slice(0, 1));
|
|
8780
8766
|
if (block && blockPath && typeof block._key == "string") {
|
|
@@ -8856,7 +8842,14 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8856
8842
|
},
|
|
8857
8843
|
delete: (selection, options) => {
|
|
8858
8844
|
if (selection) {
|
|
8859
|
-
const range = toSlateRange(
|
|
8845
|
+
const range = toSlateRange({
|
|
8846
|
+
context: {
|
|
8847
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8848
|
+
value: editor.value,
|
|
8849
|
+
selection
|
|
8850
|
+
},
|
|
8851
|
+
blockIndexMap: editor.blockIndexMap
|
|
8852
|
+
});
|
|
8860
8853
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
8861
8854
|
throw new Error("Invalid range");
|
|
8862
8855
|
if (range) {
|
|
@@ -8917,7 +8910,21 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8917
8910
|
},
|
|
8918
8911
|
getFragment: () => fromSlateValue(editor.getFragment(), types.block.name),
|
|
8919
8912
|
isSelectionsOverlapping: (selectionA, selectionB) => {
|
|
8920
|
-
const rangeA = toSlateRange(
|
|
8913
|
+
const rangeA = toSlateRange({
|
|
8914
|
+
context: {
|
|
8915
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8916
|
+
value: editor.value,
|
|
8917
|
+
selection: selectionA
|
|
8918
|
+
},
|
|
8919
|
+
blockIndexMap: editor.blockIndexMap
|
|
8920
|
+
}), rangeB = toSlateRange({
|
|
8921
|
+
context: {
|
|
8922
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8923
|
+
value: editor.value,
|
|
8924
|
+
selection: selectionB
|
|
8925
|
+
},
|
|
8926
|
+
blockIndexMap: editor.blockIndexMap
|
|
8927
|
+
});
|
|
8921
8928
|
return Range.isRange(rangeA) && Range.isRange(rangeB) && Range.includes(rangeA, rangeB);
|
|
8922
8929
|
}
|
|
8923
8930
|
};
|
|
@@ -10885,7 +10892,14 @@ const slateOperationCallback = ({
|
|
|
10885
10892
|
}) => {
|
|
10886
10893
|
const rangeDecorationState = [];
|
|
10887
10894
|
for (const rangeDecoration of context.pendingRangeDecorations) {
|
|
10888
|
-
const slateRange = toSlateRange(
|
|
10895
|
+
const slateRange = toSlateRange({
|
|
10896
|
+
context: {
|
|
10897
|
+
schema: context.schema,
|
|
10898
|
+
value: context.slateEditor.value,
|
|
10899
|
+
selection: rangeDecoration.selection
|
|
10900
|
+
},
|
|
10901
|
+
blockIndexMap: context.slateEditor.blockIndexMap
|
|
10902
|
+
});
|
|
10889
10903
|
if (!Range.isRange(slateRange)) {
|
|
10890
10904
|
rangeDecoration.onMoved?.({
|
|
10891
10905
|
newSelection: null,
|
|
@@ -10909,7 +10923,14 @@ const slateOperationCallback = ({
|
|
|
10909
10923
|
return;
|
|
10910
10924
|
const rangeDecorationState = [];
|
|
10911
10925
|
for (const rangeDecoration of event.rangeDecorations) {
|
|
10912
|
-
const slateRange = toSlateRange(
|
|
10926
|
+
const slateRange = toSlateRange({
|
|
10927
|
+
context: {
|
|
10928
|
+
schema: context.schema,
|
|
10929
|
+
value: context.slateEditor.value,
|
|
10930
|
+
selection: rangeDecoration.selection
|
|
10931
|
+
},
|
|
10932
|
+
blockIndexMap: context.slateEditor.blockIndexMap
|
|
10933
|
+
});
|
|
10913
10934
|
if (!Range.isRange(slateRange)) {
|
|
10914
10935
|
rangeDecoration.onMoved?.({
|
|
10915
10936
|
newSelection: null,
|
|
@@ -10933,7 +10954,14 @@ const slateOperationCallback = ({
|
|
|
10933
10954
|
return;
|
|
10934
10955
|
const rangeDecorationState = [];
|
|
10935
10956
|
for (const decoratedRange of context.slateEditor.decoratedRanges) {
|
|
10936
|
-
const slateRange = toSlateRange(
|
|
10957
|
+
const slateRange = toSlateRange({
|
|
10958
|
+
context: {
|
|
10959
|
+
schema: context.schema,
|
|
10960
|
+
value: context.slateEditor.value,
|
|
10961
|
+
selection: decoratedRange.rangeDecoration.selection
|
|
10962
|
+
},
|
|
10963
|
+
blockIndexMap: context.slateEditor.blockIndexMap
|
|
10964
|
+
});
|
|
10937
10965
|
if (!Range.isRange(slateRange)) {
|
|
10938
10966
|
decoratedRange.rangeDecoration.onMoved?.({
|
|
10939
10967
|
newSelection: null,
|
|
@@ -11187,7 +11215,14 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
11187
11215
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
11188
11216
|
if (normalizedSelection !== null) {
|
|
11189
11217
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
11190
|
-
const slateRange = toSlateRange(
|
|
11218
|
+
const slateRange = toSlateRange({
|
|
11219
|
+
context: {
|
|
11220
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
11221
|
+
value: slateEditor.value,
|
|
11222
|
+
selection: normalizedSelection
|
|
11223
|
+
},
|
|
11224
|
+
blockIndexMap: slateEditor.blockIndexMap
|
|
11225
|
+
});
|
|
11191
11226
|
slateRange && (Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || editorActor.send({
|
|
11192
11227
|
type: "update selection",
|
|
11193
11228
|
selection: normalizedSelection
|