@portabletext/editor 1.48.12 → 1.48.14
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/editor-provider.cjs +633 -637
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +634 -638
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +4 -2564
- package/lib/behaviors/index.d.ts +4 -2564
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.d.cts +5 -2564
- package/lib/index.d.ts +5 -2564
- package/lib/plugins/index.cjs +1 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +4 -2569
- package/lib/plugins/index.d.ts +4 -2569
- package/lib/plugins/index.js +2 -8
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +3 -2563
- package/lib/selectors/index.d.ts +3 -2563
- package/lib/utils/index.d.cts +5 -2564
- package/lib/utils/index.d.ts +5 -2564
- package/package.json +6 -6
- package/src/behaviors/behavior.abstract.keyboard.ts +16 -0
- package/src/behaviors/{behavior.default.ts → behavior.abstract.ts} +3 -3
- package/src/behaviors/behavior.core.ts +0 -3
- package/src/behaviors/behavior.perform-event.ts +64 -78
- package/src/behaviors/behavior.types.action.ts +1 -10
- package/src/editor/PortableTextEditor.tsx +1 -1
- package/src/editor/editor-machine.ts +33 -22
- package/src/editor/mutation-machine.ts +6 -6
- package/src/editor/plugins/create-with-event-listeners.ts +25 -25
- package/src/editor/plugins/createWithEditableAPI.ts +3 -3
- package/src/editor/plugins/createWithPatches.ts +13 -5
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +5 -5
- package/src/editor/plugins/createWithUndoRedo.ts +8 -8
- package/src/editor/with-applying-behavior-operations.ts +18 -0
- package/src/editor/{with-applying-behavior-actions.ts → with-undo-step.ts} +1 -19
- package/src/index.ts +1 -1
- package/src/{behavior-actions/behavior.action.annotation.add.ts → operations/behavior.operation.annotation.add.ts} +7 -7
- package/src/{behavior-actions/behavior.action.annotation.remove.ts → operations/behavior.operation.annotation.remove.ts} +6 -6
- package/src/{behavior-actions/behavior.action.block.set.ts → operations/behavior.operation.block.set.ts} +14 -14
- package/src/{behavior-actions/behavior.action.block.unset.ts → operations/behavior.operation.block.unset.ts} +19 -17
- package/src/{behavior-actions/behavior.action.decorator.add.ts → operations/behavior.operation.decorator.add.ts} +10 -10
- package/src/operations/behavior.operation.delete.backward.ts +8 -0
- package/src/operations/behavior.operation.delete.block.ts +24 -0
- package/src/operations/behavior.operation.delete.forward.ts +8 -0
- package/src/{behavior-actions/behavior.action.delete.ts → operations/behavior.operation.delete.ts} +8 -8
- package/src/{behavior-actions/behavior.action.insert-inline-object.ts → operations/behavior.operation.insert-inline-object.ts} +11 -11
- package/src/{behavior-actions/behavior.action.insert-span.ts → operations/behavior.operation.insert-span.ts} +15 -15
- package/src/{behavior-actions/behavior.action.insert.block.ts → operations/behavior.operation.insert.block.ts} +8 -8
- package/src/operations/behavior.operation.insert.text.ts +17 -0
- package/src/operations/behavior.operation.move.backward.ts +12 -0
- package/src/operations/behavior.operation.move.block.ts +16 -0
- package/src/operations/behavior.operation.move.forward.ts +11 -0
- package/src/operations/behavior.operation.select.ts +15 -0
- package/src/operations/behavior.operations.ts +239 -0
- package/src/plugins/index.ts +0 -1
- package/src/behavior-actions/behavior.action.delete.backward.ts +0 -7
- package/src/behavior-actions/behavior.action.delete.block.ts +0 -24
- package/src/behavior-actions/behavior.action.delete.forward.ts +0 -7
- package/src/behavior-actions/behavior.action.effect.ts +0 -7
- package/src/behavior-actions/behavior.action.insert.text.ts +0 -17
- package/src/behavior-actions/behavior.action.move.backward.ts +0 -12
- package/src/behavior-actions/behavior.action.move.block.ts +0 -16
- package/src/behavior-actions/behavior.action.move.forward.ts +0 -11
- package/src/behavior-actions/behavior.action.select.ts +0 -15
- package/src/behavior-actions/behavior.actions.ts +0 -228
- package/src/behaviors/behavior.default.raise-soft-break.ts +0 -14
- package/src/plugins/plugin.core.tsx +0 -9
|
@@ -149,18 +149,18 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
149
149
|
}) => {
|
|
150
150
|
if (xstate.assertEvent(event, "patch"), context.pendingMutations.length === 0)
|
|
151
151
|
return [{
|
|
152
|
-
|
|
152
|
+
operationId: event.operationId,
|
|
153
153
|
value: event.value,
|
|
154
154
|
patches: [event.patch]
|
|
155
155
|
}];
|
|
156
156
|
const lastBulk = context.pendingMutations.at(-1);
|
|
157
|
-
return lastBulk && lastBulk.
|
|
157
|
+
return lastBulk && lastBulk.operationId === event.operationId ? context.pendingMutations.slice(0, -1).concat({
|
|
158
158
|
value: event.value,
|
|
159
|
-
|
|
159
|
+
operationId: lastBulk.operationId,
|
|
160
160
|
patches: [...lastBulk.patches, event.patch]
|
|
161
161
|
}) : context.pendingMutations.concat({
|
|
162
162
|
value: event.value,
|
|
163
|
-
|
|
163
|
+
operationId: event.operationId,
|
|
164
164
|
patches: [event.patch]
|
|
165
165
|
});
|
|
166
166
|
}
|
|
@@ -1301,16 +1301,6 @@ function randomKey(length) {
|
|
|
1301
1301
|
const table = getByteHexTable();
|
|
1302
1302
|
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
1303
1303
|
}
|
|
1304
|
-
const CURRENT_ACTION_ID = /* @__PURE__ */ new WeakMap();
|
|
1305
|
-
function withApplyingBehaviorActions(editor, fn) {
|
|
1306
|
-
CURRENT_ACTION_ID.set(editor, defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_ACTION_ID.set(editor, void 0);
|
|
1307
|
-
}
|
|
1308
|
-
function getCurrentActionId(editor) {
|
|
1309
|
-
return CURRENT_ACTION_ID.get(editor);
|
|
1310
|
-
}
|
|
1311
|
-
function isApplyingBehaviorActions(editor) {
|
|
1312
|
-
return getCurrentActionId(editor) !== void 0;
|
|
1313
|
-
}
|
|
1314
1304
|
const CURRENT_UNDO_STEP = /* @__PURE__ */ new WeakMap();
|
|
1315
1305
|
function withUndoStep(editor, fn) {
|
|
1316
1306
|
const current = CURRENT_UNDO_STEP.get(editor);
|
|
@@ -1412,10 +1402,10 @@ function createWithUndoRedo(options) {
|
|
|
1412
1402
|
}, editor;
|
|
1413
1403
|
};
|
|
1414
1404
|
}
|
|
1415
|
-
const
|
|
1416
|
-
|
|
1405
|
+
const historyUndoOperationImplementation = ({
|
|
1406
|
+
operation
|
|
1417
1407
|
}) => {
|
|
1418
|
-
const editor =
|
|
1408
|
+
const editor = operation.editor, {
|
|
1419
1409
|
undos
|
|
1420
1410
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1421
1411
|
if (undos.length > 0) {
|
|
@@ -1447,10 +1437,10 @@ const historyUndoActionImplementation = ({
|
|
|
1447
1437
|
editor.history.redos.push(step), editor.history.undos.pop();
|
|
1448
1438
|
}
|
|
1449
1439
|
}
|
|
1450
|
-
},
|
|
1451
|
-
|
|
1440
|
+
}, historyRedoOperationImplementation = ({
|
|
1441
|
+
operation
|
|
1452
1442
|
}) => {
|
|
1453
|
-
const editor =
|
|
1443
|
+
const editor = operation.editor, {
|
|
1454
1444
|
redos
|
|
1455
1445
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1456
1446
|
if (redos.length > 0) {
|
|
@@ -2626,13 +2616,214 @@ function createOperationToPatches(editorActor) {
|
|
|
2626
2616
|
splitNodePatch
|
|
2627
2617
|
};
|
|
2628
2618
|
}
|
|
2629
|
-
|
|
2630
|
-
|
|
2619
|
+
function getFocusBlock({
|
|
2620
|
+
editor
|
|
2621
|
+
}) {
|
|
2622
|
+
if (!editor.selection)
|
|
2623
|
+
return [void 0, void 0];
|
|
2624
|
+
try {
|
|
2625
|
+
return slate.Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0];
|
|
2626
|
+
} catch {
|
|
2627
|
+
return [void 0, void 0];
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
function getSelectionStartBlock({
|
|
2631
|
+
editor
|
|
2632
|
+
}) {
|
|
2633
|
+
if (!editor.selection)
|
|
2634
|
+
return [void 0, void 0];
|
|
2635
|
+
const selectionStartPoint = slate.Range.start(editor.selection);
|
|
2636
|
+
return getPointBlock({
|
|
2637
|
+
editor,
|
|
2638
|
+
point: selectionStartPoint
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
function getSelectionEndBlock({
|
|
2642
|
+
editor
|
|
2643
|
+
}) {
|
|
2644
|
+
if (!editor.selection)
|
|
2645
|
+
return [void 0, void 0];
|
|
2646
|
+
const selectionEndPoint = slate.Range.end(editor.selection);
|
|
2647
|
+
return getPointBlock({
|
|
2648
|
+
editor,
|
|
2649
|
+
point: selectionEndPoint
|
|
2650
|
+
});
|
|
2651
|
+
}
|
|
2652
|
+
function getPointBlock({
|
|
2653
|
+
editor,
|
|
2654
|
+
point
|
|
2655
|
+
}) {
|
|
2656
|
+
try {
|
|
2657
|
+
const [block] = slate.Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
|
|
2658
|
+
return block ? [block, point.path.slice(0, 1)] : [void 0, void 0];
|
|
2659
|
+
} catch {
|
|
2660
|
+
return [void 0, void 0];
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
function getFocusChild({
|
|
2664
|
+
editor
|
|
2665
|
+
}) {
|
|
2666
|
+
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
2667
|
+
editor
|
|
2668
|
+
}), childIndex = editor.selection?.focus.path.at(1);
|
|
2669
|
+
if (!focusBlock || !focusBlockPath || childIndex === void 0)
|
|
2670
|
+
return [void 0, void 0];
|
|
2671
|
+
try {
|
|
2672
|
+
const focusChild = slate.Node.child(focusBlock, childIndex);
|
|
2673
|
+
return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
|
|
2674
|
+
} catch {
|
|
2675
|
+
return [void 0, void 0];
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
function getPointChild({
|
|
2679
|
+
editor,
|
|
2680
|
+
point
|
|
2681
|
+
}) {
|
|
2682
|
+
const [block, blockPath] = getPointBlock({
|
|
2683
|
+
editor,
|
|
2684
|
+
point
|
|
2685
|
+
}), childIndex = point.path.at(1);
|
|
2686
|
+
if (!block || !blockPath || childIndex === void 0)
|
|
2687
|
+
return [void 0, void 0];
|
|
2688
|
+
try {
|
|
2689
|
+
const pointChild = slate.Node.child(block, childIndex);
|
|
2690
|
+
return pointChild ? [pointChild, [...blockPath, childIndex]] : [void 0, void 0];
|
|
2691
|
+
} catch {
|
|
2692
|
+
return [void 0, void 0];
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
function getFirstBlock({
|
|
2696
|
+
editor
|
|
2697
|
+
}) {
|
|
2698
|
+
const firstBlockPath = slate.Editor.start(editor, []).path.at(0);
|
|
2699
|
+
try {
|
|
2700
|
+
return firstBlockPath !== void 0 ? slate.Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
2701
|
+
} catch {
|
|
2702
|
+
return [void 0, void 0];
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
function getLastBlock({
|
|
2706
|
+
editor
|
|
2707
|
+
}) {
|
|
2708
|
+
const lastBlockPath = slate.Editor.end(editor, []).path.at(0);
|
|
2709
|
+
try {
|
|
2710
|
+
return lastBlockPath !== void 0 ? slate.Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
2711
|
+
} catch {
|
|
2712
|
+
return [void 0, void 0];
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
function getNodeBlock({
|
|
2716
|
+
editor,
|
|
2717
|
+
schema: schema2,
|
|
2718
|
+
node
|
|
2719
|
+
}) {
|
|
2720
|
+
if (slate.Editor.isEditor(node))
|
|
2721
|
+
return;
|
|
2722
|
+
if (isBlockElement({
|
|
2723
|
+
editor,
|
|
2724
|
+
schema: schema2
|
|
2725
|
+
}, node))
|
|
2726
|
+
return elementToBlock({
|
|
2727
|
+
schema: schema2,
|
|
2728
|
+
element: node
|
|
2729
|
+
});
|
|
2730
|
+
const parent = Array.from(slate.Editor.nodes(editor, {
|
|
2731
|
+
mode: "highest",
|
|
2732
|
+
at: [],
|
|
2733
|
+
match: (n) => isBlockElement({
|
|
2734
|
+
editor,
|
|
2735
|
+
schema: schema2
|
|
2736
|
+
}, n) && n.children.some((child) => child._key === node._key)
|
|
2737
|
+
})).at(0)?.at(0);
|
|
2738
|
+
return slate.Element.isElement(parent) ? elementToBlock({
|
|
2739
|
+
schema: schema2,
|
|
2740
|
+
element: parent
|
|
2741
|
+
}) : void 0;
|
|
2742
|
+
}
|
|
2743
|
+
function elementToBlock({
|
|
2744
|
+
schema: schema2,
|
|
2745
|
+
element
|
|
2746
|
+
}) {
|
|
2747
|
+
return fromSlateValue([element], schema2.block.name)?.at(0);
|
|
2748
|
+
}
|
|
2749
|
+
function isBlockElement({
|
|
2750
|
+
editor,
|
|
2751
|
+
schema: schema2
|
|
2752
|
+
}, node) {
|
|
2753
|
+
return slate.Element.isElement(node) && !editor.isInline(node) && (schema2.block.name === node._type || schema2.blockObjects.some((blockObject) => blockObject.name === node._type));
|
|
2754
|
+
}
|
|
2755
|
+
function isListItemActive({
|
|
2756
|
+
editor,
|
|
2757
|
+
listItem
|
|
2758
|
+
}) {
|
|
2759
|
+
if (!editor.selection)
|
|
2760
|
+
return !1;
|
|
2761
|
+
const selectedBlocks = [...slate.Editor.nodes(editor, {
|
|
2762
|
+
at: editor.selection,
|
|
2763
|
+
match: (node) => editor.isTextBlock(node)
|
|
2764
|
+
})];
|
|
2765
|
+
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
2766
|
+
}
|
|
2767
|
+
function isStyleActive({
|
|
2768
|
+
editor,
|
|
2769
|
+
style
|
|
2770
|
+
}) {
|
|
2771
|
+
if (!editor.selection)
|
|
2772
|
+
return !1;
|
|
2773
|
+
const selectedBlocks = [...slate.Editor.nodes(editor, {
|
|
2774
|
+
at: editor.selection,
|
|
2775
|
+
match: (node) => editor.isTextBlock(node)
|
|
2776
|
+
})];
|
|
2777
|
+
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
2778
|
+
}
|
|
2779
|
+
function slateRangeToSelection({
|
|
2780
|
+
schema: schema2,
|
|
2781
|
+
editor,
|
|
2782
|
+
range
|
|
2783
|
+
}) {
|
|
2784
|
+
const [anchorBlock] = getPointBlock({
|
|
2785
|
+
editor,
|
|
2786
|
+
point: range.anchor
|
|
2787
|
+
}), [focusBlock] = getPointBlock({
|
|
2788
|
+
editor,
|
|
2789
|
+
point: range.focus
|
|
2790
|
+
});
|
|
2791
|
+
if (!anchorBlock || !focusBlock)
|
|
2792
|
+
return null;
|
|
2793
|
+
const [anchorChild] = anchorBlock._type === schema2.block.name ? getPointChild({
|
|
2794
|
+
editor,
|
|
2795
|
+
point: range.anchor
|
|
2796
|
+
}) : [void 0, void 0], [focusChild] = focusBlock._type === schema2.block.name ? getPointChild({
|
|
2797
|
+
editor,
|
|
2798
|
+
point: range.focus
|
|
2799
|
+
}) : [void 0, void 0], selection = {
|
|
2800
|
+
anchor: {
|
|
2801
|
+
path: [{
|
|
2802
|
+
_key: anchorBlock._key
|
|
2803
|
+
}],
|
|
2804
|
+
offset: range.anchor.offset
|
|
2805
|
+
},
|
|
2806
|
+
focus: {
|
|
2807
|
+
path: [{
|
|
2808
|
+
_key: focusBlock._key
|
|
2809
|
+
}],
|
|
2810
|
+
offset: range.focus.offset
|
|
2811
|
+
},
|
|
2812
|
+
backward: slate.Range.isBackward(range)
|
|
2813
|
+
};
|
|
2814
|
+
return anchorChild && (selection.anchor.path.push("children"), selection.anchor.path.push({
|
|
2815
|
+
_key: anchorChild._key
|
|
2816
|
+
})), focusChild && (selection.focus.path.push("children"), selection.focus.path.push({
|
|
2817
|
+
_key: focusChild._key
|
|
2818
|
+
})), selection;
|
|
2819
|
+
}
|
|
2820
|
+
const insertTextOperationImplementation = ({
|
|
2821
|
+
operation
|
|
2631
2822
|
}) => {
|
|
2632
|
-
|
|
2633
|
-
text:
|
|
2634
|
-
...
|
|
2635
|
-
}) : slate.Transforms.insertText(
|
|
2823
|
+
operation.editor.marks ? slate.Transforms.insertNodes(operation.editor, {
|
|
2824
|
+
text: operation.text,
|
|
2825
|
+
...operation.editor.marks
|
|
2826
|
+
}) : slate.Transforms.insertText(operation.editor, operation.text), operation.editor.marks = null;
|
|
2636
2827
|
};
|
|
2637
2828
|
function isPortableTextSpan(node) {
|
|
2638
2829
|
return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
|
|
@@ -3032,10 +3223,10 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3032
3223
|
}, editor;
|
|
3033
3224
|
};
|
|
3034
3225
|
}
|
|
3035
|
-
const
|
|
3036
|
-
|
|
3226
|
+
const removeDecoratorOperationImplementation = ({
|
|
3227
|
+
operation
|
|
3037
3228
|
}) => {
|
|
3038
|
-
const editor =
|
|
3229
|
+
const editor = operation.editor, mark = operation.decorator, {
|
|
3039
3230
|
selection
|
|
3040
3231
|
} = editor;
|
|
3041
3232
|
if (selection) {
|
|
@@ -3106,14 +3297,14 @@ function isDecoratorActive({
|
|
|
3106
3297
|
...slate.Editor.marks(editor) || {}
|
|
3107
3298
|
}.marks || []).includes(decorator);
|
|
3108
3299
|
}
|
|
3109
|
-
const
|
|
3300
|
+
const addAnnotationOperationImplementation = ({
|
|
3110
3301
|
context,
|
|
3111
|
-
|
|
3302
|
+
operation
|
|
3112
3303
|
}) => {
|
|
3113
3304
|
const parsedAnnotation = util_sliceBlocks.parseAnnotation({
|
|
3114
3305
|
annotation: {
|
|
3115
|
-
_type:
|
|
3116
|
-
...
|
|
3306
|
+
_type: operation.annotation.name,
|
|
3307
|
+
...operation.annotation.value
|
|
3117
3308
|
},
|
|
3118
3309
|
context,
|
|
3119
3310
|
options: {
|
|
@@ -3121,8 +3312,8 @@ const addAnnotationActionImplementation = ({
|
|
|
3121
3312
|
}
|
|
3122
3313
|
});
|
|
3123
3314
|
if (!parsedAnnotation)
|
|
3124
|
-
throw new Error(`Failed to parse annotation ${JSON.stringify(
|
|
3125
|
-
const editor =
|
|
3315
|
+
throw new Error(`Failed to parse annotation ${JSON.stringify(operation.annotation)}`);
|
|
3316
|
+
const editor = operation.editor;
|
|
3126
3317
|
if (!editor.selection || slate.Range.isCollapsed(editor.selection))
|
|
3127
3318
|
return;
|
|
3128
3319
|
let paths, spanPath, markDefPath;
|
|
@@ -3173,10 +3364,10 @@ const addAnnotationActionImplementation = ({
|
|
|
3173
3364
|
markDefPaths,
|
|
3174
3365
|
spanPath
|
|
3175
3366
|
}), paths;
|
|
3176
|
-
},
|
|
3177
|
-
|
|
3367
|
+
}, removeAnnotationOperationImplementation = ({
|
|
3368
|
+
operation
|
|
3178
3369
|
}) => {
|
|
3179
|
-
const editor =
|
|
3370
|
+
const editor = operation.editor;
|
|
3180
3371
|
if (editor.selection)
|
|
3181
3372
|
if (slate.Range.isCollapsed(editor.selection)) {
|
|
3182
3373
|
const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
|
|
@@ -3184,7 +3375,7 @@ const addAnnotationActionImplementation = ({
|
|
|
3184
3375
|
});
|
|
3185
3376
|
if (!editor.isTextBlock(block))
|
|
3186
3377
|
return;
|
|
3187
|
-
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type ===
|
|
3378
|
+
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), [selectedChild, selectedChildPath] = slate.Editor.node(editor, editor.selection, {
|
|
3188
3379
|
depth: 2
|
|
3189
3380
|
});
|
|
3190
3381
|
if (!editor.isTextSpan(selectedChild))
|
|
@@ -3229,7 +3420,7 @@ const addAnnotationActionImplementation = ({
|
|
|
3229
3420
|
for (const [child, childPath] of children) {
|
|
3230
3421
|
if (!editor.isTextSpan(child) || !slate.Range.includes(editor.selection, childPath))
|
|
3231
3422
|
continue;
|
|
3232
|
-
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !==
|
|
3423
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
|
|
3233
3424
|
marksWithoutAnnotation.length !== marks.length && slate.Transforms.setNodes(editor, {
|
|
3234
3425
|
marks: marksWithoutAnnotation
|
|
3235
3426
|
}, {
|
|
@@ -3281,34 +3472,34 @@ function moveRangeByOperation(range, operation) {
|
|
|
3281
3472
|
focus
|
|
3282
3473
|
};
|
|
3283
3474
|
}
|
|
3284
|
-
const
|
|
3475
|
+
const blockSetOperationImplementation = ({
|
|
3285
3476
|
context,
|
|
3286
|
-
|
|
3477
|
+
operation
|
|
3287
3478
|
}) => {
|
|
3288
3479
|
const location = toSlateRange({
|
|
3289
3480
|
anchor: {
|
|
3290
|
-
path:
|
|
3481
|
+
path: operation.at,
|
|
3291
3482
|
offset: 0
|
|
3292
3483
|
},
|
|
3293
3484
|
focus: {
|
|
3294
|
-
path:
|
|
3485
|
+
path: operation.at,
|
|
3295
3486
|
offset: 0
|
|
3296
3487
|
}
|
|
3297
|
-
},
|
|
3488
|
+
}, operation.editor);
|
|
3298
3489
|
if (!location)
|
|
3299
|
-
throw new Error(`Unable to convert ${JSON.stringify(
|
|
3300
|
-
const block = slate.Editor.node(
|
|
3490
|
+
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3491
|
+
const block = slate.Editor.node(operation.editor, location, {
|
|
3301
3492
|
depth: 1
|
|
3302
3493
|
})?.[0];
|
|
3303
3494
|
if (!block)
|
|
3304
|
-
throw new Error(`Unable to find block at ${JSON.stringify(
|
|
3305
|
-
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(
|
|
3495
|
+
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
3496
|
+
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
3306
3497
|
if (!parsedBlock)
|
|
3307
|
-
throw new Error(`Unable to parse block at ${JSON.stringify(
|
|
3498
|
+
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
3308
3499
|
const {
|
|
3309
3500
|
_type,
|
|
3310
3501
|
...filteredProps
|
|
3311
|
-
} =
|
|
3502
|
+
} = operation.props, updatedBlock = util_sliceBlocks.parseBlock({
|
|
3312
3503
|
context,
|
|
3313
3504
|
block: {
|
|
3314
3505
|
...parsedBlock,
|
|
@@ -3319,41 +3510,41 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3319
3510
|
}
|
|
3320
3511
|
});
|
|
3321
3512
|
if (!updatedBlock)
|
|
3322
|
-
throw new Error(`Unable to update block at ${JSON.stringify(
|
|
3513
|
+
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
3323
3514
|
const slateBlock = toSlateValue([updatedBlock], {
|
|
3324
3515
|
schemaTypes: context.schema
|
|
3325
3516
|
})?.at(0);
|
|
3326
3517
|
if (!slateBlock)
|
|
3327
3518
|
throw new Error("Unable to convert block to Slate value");
|
|
3328
|
-
slate.Transforms.setNodes(
|
|
3519
|
+
slate.Transforms.setNodes(operation.editor, slateBlock, {
|
|
3329
3520
|
at: location
|
|
3330
3521
|
});
|
|
3331
|
-
},
|
|
3522
|
+
}, blockUnsetOperationImplementation = ({
|
|
3332
3523
|
context,
|
|
3333
|
-
|
|
3524
|
+
operation
|
|
3334
3525
|
}) => {
|
|
3335
3526
|
const location = toSlateRange({
|
|
3336
3527
|
anchor: {
|
|
3337
|
-
path:
|
|
3528
|
+
path: operation.at,
|
|
3338
3529
|
offset: 0
|
|
3339
3530
|
},
|
|
3340
3531
|
focus: {
|
|
3341
|
-
path:
|
|
3532
|
+
path: operation.at,
|
|
3342
3533
|
offset: 0
|
|
3343
3534
|
}
|
|
3344
|
-
},
|
|
3535
|
+
}, operation.editor);
|
|
3345
3536
|
if (!location)
|
|
3346
|
-
throw new Error(`Unable to convert ${JSON.stringify(
|
|
3347
|
-
const block = slate.Editor.node(
|
|
3537
|
+
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3538
|
+
const block = slate.Editor.node(operation.editor, location, {
|
|
3348
3539
|
depth: 1
|
|
3349
3540
|
})?.[0];
|
|
3350
3541
|
if (!block)
|
|
3351
|
-
throw new Error(`Unable to find block at ${JSON.stringify(
|
|
3352
|
-
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(
|
|
3542
|
+
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
3543
|
+
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
3353
3544
|
if (!parsedBlock)
|
|
3354
|
-
throw new Error(`Unable to parse block at ${JSON.stringify(
|
|
3545
|
+
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
3355
3546
|
if (util_sliceBlocks.isTextBlock(context, parsedBlock)) {
|
|
3356
|
-
const propsToRemove =
|
|
3547
|
+
const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_sliceBlocks.parseBlock({
|
|
3357
3548
|
context,
|
|
3358
3549
|
block: omit__default.default(parsedBlock, propsToRemove),
|
|
3359
3550
|
options: {
|
|
@@ -3361,260 +3552,58 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3361
3552
|
}
|
|
3362
3553
|
});
|
|
3363
3554
|
if (!updatedTextBlock)
|
|
3364
|
-
throw new Error(`Unable to update block at ${JSON.stringify(
|
|
3555
|
+
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
3365
3556
|
const propsToSet = {};
|
|
3366
3557
|
for (const prop of propsToRemove)
|
|
3367
3558
|
prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
|
|
3368
|
-
slate.Transforms.setNodes(
|
|
3559
|
+
slate.Transforms.setNodes(operation.editor, propsToSet, {
|
|
3369
3560
|
at: location
|
|
3370
3561
|
});
|
|
3371
3562
|
return;
|
|
3372
3563
|
}
|
|
3373
3564
|
const updatedBlockObject = util_sliceBlocks.parseBlock({
|
|
3374
3565
|
context,
|
|
3375
|
-
block: omit__default.default(parsedBlock,
|
|
3566
|
+
block: omit__default.default(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
|
|
3376
3567
|
options: {
|
|
3377
3568
|
refreshKeys: !1
|
|
3378
3569
|
}
|
|
3379
3570
|
});
|
|
3380
3571
|
if (!updatedBlockObject)
|
|
3381
|
-
throw new Error(`Unable to update block at ${JSON.stringify(
|
|
3572
|
+
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
3382
3573
|
const {
|
|
3383
3574
|
_type,
|
|
3384
3575
|
_key,
|
|
3385
3576
|
...props
|
|
3386
3577
|
} = updatedBlockObject;
|
|
3387
|
-
slate.Transforms.setNodes(
|
|
3578
|
+
slate.Transforms.setNodes(operation.editor, {
|
|
3388
3579
|
_type,
|
|
3389
3580
|
_key,
|
|
3390
3581
|
value: props
|
|
3391
3582
|
}, {
|
|
3392
3583
|
at: location
|
|
3393
3584
|
});
|
|
3394
|
-
}
|
|
3395
|
-
function getFocusBlock({
|
|
3396
|
-
editor
|
|
3397
|
-
}) {
|
|
3398
|
-
if (!editor.selection)
|
|
3399
|
-
return [void 0, void 0];
|
|
3400
|
-
try {
|
|
3401
|
-
return slate.Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0];
|
|
3402
|
-
} catch {
|
|
3403
|
-
return [void 0, void 0];
|
|
3404
|
-
}
|
|
3405
|
-
}
|
|
3406
|
-
function getSelectionStartBlock({
|
|
3407
|
-
editor
|
|
3408
|
-
}) {
|
|
3409
|
-
if (!editor.selection)
|
|
3410
|
-
return [void 0, void 0];
|
|
3411
|
-
const selectionStartPoint = slate.Range.start(editor.selection);
|
|
3412
|
-
return getPointBlock({
|
|
3413
|
-
editor,
|
|
3414
|
-
point: selectionStartPoint
|
|
3415
|
-
});
|
|
3416
|
-
}
|
|
3417
|
-
function getSelectionEndBlock({
|
|
3418
|
-
editor
|
|
3419
|
-
}) {
|
|
3420
|
-
if (!editor.selection)
|
|
3421
|
-
return [void 0, void 0];
|
|
3422
|
-
const selectionEndPoint = slate.Range.end(editor.selection);
|
|
3423
|
-
return getPointBlock({
|
|
3424
|
-
editor,
|
|
3425
|
-
point: selectionEndPoint
|
|
3426
|
-
});
|
|
3427
|
-
}
|
|
3428
|
-
function getPointBlock({
|
|
3429
|
-
editor,
|
|
3430
|
-
point
|
|
3431
|
-
}) {
|
|
3432
|
-
try {
|
|
3433
|
-
const [block] = slate.Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
|
|
3434
|
-
return block ? [block, point.path.slice(0, 1)] : [void 0, void 0];
|
|
3435
|
-
} catch {
|
|
3436
|
-
return [void 0, void 0];
|
|
3437
|
-
}
|
|
3438
|
-
}
|
|
3439
|
-
function getFocusChild({
|
|
3440
|
-
editor
|
|
3441
|
-
}) {
|
|
3442
|
-
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
3443
|
-
editor
|
|
3444
|
-
}), childIndex = editor.selection?.focus.path.at(1);
|
|
3445
|
-
if (!focusBlock || !focusBlockPath || childIndex === void 0)
|
|
3446
|
-
return [void 0, void 0];
|
|
3447
|
-
try {
|
|
3448
|
-
const focusChild = slate.Node.child(focusBlock, childIndex);
|
|
3449
|
-
return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
|
|
3450
|
-
} catch {
|
|
3451
|
-
return [void 0, void 0];
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
function getPointChild({
|
|
3455
|
-
editor,
|
|
3456
|
-
point
|
|
3457
|
-
}) {
|
|
3458
|
-
const [block, blockPath] = getPointBlock({
|
|
3459
|
-
editor,
|
|
3460
|
-
point
|
|
3461
|
-
}), childIndex = point.path.at(1);
|
|
3462
|
-
if (!block || !blockPath || childIndex === void 0)
|
|
3463
|
-
return [void 0, void 0];
|
|
3464
|
-
try {
|
|
3465
|
-
const pointChild = slate.Node.child(block, childIndex);
|
|
3466
|
-
return pointChild ? [pointChild, [...blockPath, childIndex]] : [void 0, void 0];
|
|
3467
|
-
} catch {
|
|
3468
|
-
return [void 0, void 0];
|
|
3469
|
-
}
|
|
3470
|
-
}
|
|
3471
|
-
function getFirstBlock({
|
|
3472
|
-
editor
|
|
3473
|
-
}) {
|
|
3474
|
-
const firstBlockPath = slate.Editor.start(editor, []).path.at(0);
|
|
3475
|
-
try {
|
|
3476
|
-
return firstBlockPath !== void 0 ? slate.Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
3477
|
-
} catch {
|
|
3478
|
-
return [void 0, void 0];
|
|
3479
|
-
}
|
|
3480
|
-
}
|
|
3481
|
-
function getLastBlock({
|
|
3482
|
-
editor
|
|
3483
|
-
}) {
|
|
3484
|
-
const lastBlockPath = slate.Editor.end(editor, []).path.at(0);
|
|
3485
|
-
try {
|
|
3486
|
-
return lastBlockPath !== void 0 ? slate.Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
3487
|
-
} catch {
|
|
3488
|
-
return [void 0, void 0];
|
|
3489
|
-
}
|
|
3490
|
-
}
|
|
3491
|
-
function getNodeBlock({
|
|
3492
|
-
editor,
|
|
3493
|
-
schema: schema2,
|
|
3494
|
-
node
|
|
3495
|
-
}) {
|
|
3496
|
-
if (slate.Editor.isEditor(node))
|
|
3497
|
-
return;
|
|
3498
|
-
if (isBlockElement({
|
|
3499
|
-
editor,
|
|
3500
|
-
schema: schema2
|
|
3501
|
-
}, node))
|
|
3502
|
-
return elementToBlock({
|
|
3503
|
-
schema: schema2,
|
|
3504
|
-
element: node
|
|
3505
|
-
});
|
|
3506
|
-
const parent = Array.from(slate.Editor.nodes(editor, {
|
|
3507
|
-
mode: "highest",
|
|
3508
|
-
at: [],
|
|
3509
|
-
match: (n) => isBlockElement({
|
|
3510
|
-
editor,
|
|
3511
|
-
schema: schema2
|
|
3512
|
-
}, n) && n.children.some((child) => child._key === node._key)
|
|
3513
|
-
})).at(0)?.at(0);
|
|
3514
|
-
return slate.Element.isElement(parent) ? elementToBlock({
|
|
3515
|
-
schema: schema2,
|
|
3516
|
-
element: parent
|
|
3517
|
-
}) : void 0;
|
|
3518
|
-
}
|
|
3519
|
-
function elementToBlock({
|
|
3520
|
-
schema: schema2,
|
|
3521
|
-
element
|
|
3522
|
-
}) {
|
|
3523
|
-
return fromSlateValue([element], schema2.block.name)?.at(0);
|
|
3524
|
-
}
|
|
3525
|
-
function isBlockElement({
|
|
3526
|
-
editor,
|
|
3527
|
-
schema: schema2
|
|
3528
|
-
}, node) {
|
|
3529
|
-
return slate.Element.isElement(node) && !editor.isInline(node) && (schema2.block.name === node._type || schema2.blockObjects.some((blockObject) => blockObject.name === node._type));
|
|
3530
|
-
}
|
|
3531
|
-
function isListItemActive({
|
|
3532
|
-
editor,
|
|
3533
|
-
listItem
|
|
3534
|
-
}) {
|
|
3535
|
-
if (!editor.selection)
|
|
3536
|
-
return !1;
|
|
3537
|
-
const selectedBlocks = [...slate.Editor.nodes(editor, {
|
|
3538
|
-
at: editor.selection,
|
|
3539
|
-
match: (node) => editor.isTextBlock(node)
|
|
3540
|
-
})];
|
|
3541
|
-
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
3542
|
-
}
|
|
3543
|
-
function isStyleActive({
|
|
3544
|
-
editor,
|
|
3545
|
-
style
|
|
3546
|
-
}) {
|
|
3547
|
-
if (!editor.selection)
|
|
3548
|
-
return !1;
|
|
3549
|
-
const selectedBlocks = [...slate.Editor.nodes(editor, {
|
|
3550
|
-
at: editor.selection,
|
|
3551
|
-
match: (node) => editor.isTextBlock(node)
|
|
3552
|
-
})];
|
|
3553
|
-
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
3554
|
-
}
|
|
3555
|
-
function slateRangeToSelection({
|
|
3556
|
-
schema: schema2,
|
|
3557
|
-
editor,
|
|
3558
|
-
range
|
|
3559
|
-
}) {
|
|
3560
|
-
const [anchorBlock] = getPointBlock({
|
|
3561
|
-
editor,
|
|
3562
|
-
point: range.anchor
|
|
3563
|
-
}), [focusBlock] = getPointBlock({
|
|
3564
|
-
editor,
|
|
3565
|
-
point: range.focus
|
|
3566
|
-
});
|
|
3567
|
-
if (!anchorBlock || !focusBlock)
|
|
3568
|
-
return null;
|
|
3569
|
-
const [anchorChild] = anchorBlock._type === schema2.block.name ? getPointChild({
|
|
3570
|
-
editor,
|
|
3571
|
-
point: range.anchor
|
|
3572
|
-
}) : [void 0, void 0], [focusChild] = focusBlock._type === schema2.block.name ? getPointChild({
|
|
3573
|
-
editor,
|
|
3574
|
-
point: range.focus
|
|
3575
|
-
}) : [void 0, void 0], selection = {
|
|
3576
|
-
anchor: {
|
|
3577
|
-
path: [{
|
|
3578
|
-
_key: anchorBlock._key
|
|
3579
|
-
}],
|
|
3580
|
-
offset: range.anchor.offset
|
|
3581
|
-
},
|
|
3582
|
-
focus: {
|
|
3583
|
-
path: [{
|
|
3584
|
-
_key: focusBlock._key
|
|
3585
|
-
}],
|
|
3586
|
-
offset: range.focus.offset
|
|
3587
|
-
},
|
|
3588
|
-
backward: slate.Range.isBackward(range)
|
|
3589
|
-
};
|
|
3590
|
-
return anchorChild && (selection.anchor.path.push("children"), selection.anchor.path.push({
|
|
3591
|
-
_key: anchorChild._key
|
|
3592
|
-
})), focusChild && (selection.focus.path.push("children"), selection.focus.path.push({
|
|
3593
|
-
_key: focusChild._key
|
|
3594
|
-
})), selection;
|
|
3595
|
-
}
|
|
3596
|
-
const decoratorAddActionImplementation = ({
|
|
3585
|
+
}, decoratorAddOperationImplementation = ({
|
|
3597
3586
|
context,
|
|
3598
|
-
|
|
3587
|
+
operation
|
|
3599
3588
|
}) => {
|
|
3600
|
-
const editor =
|
|
3589
|
+
const editor = operation.editor, mark = operation.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = operation.at?.anchor ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
3601
3590
|
context: {
|
|
3602
3591
|
...context,
|
|
3603
3592
|
value
|
|
3604
3593
|
},
|
|
3605
|
-
blockOffset:
|
|
3594
|
+
blockOffset: operation.at.anchor,
|
|
3606
3595
|
direction: "backward"
|
|
3607
|
-
}) : void 0, manualFocus =
|
|
3596
|
+
}) : void 0, manualFocus = operation.at?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
3608
3597
|
context: {
|
|
3609
3598
|
...context,
|
|
3610
3599
|
value
|
|
3611
3600
|
},
|
|
3612
|
-
blockOffset:
|
|
3601
|
+
blockOffset: operation.at.focus,
|
|
3613
3602
|
direction: "forward"
|
|
3614
3603
|
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
3615
3604
|
anchor: manualAnchor,
|
|
3616
3605
|
focus: manualFocus
|
|
3617
|
-
} : void 0, selection = manualSelection ? toSlateRange(manualSelection,
|
|
3606
|
+
} : void 0, selection = manualSelection ? toSlateRange(manualSelection, operation.editor) ?? editor.selection : editor.selection;
|
|
3618
3607
|
if (!selection)
|
|
3619
3608
|
return;
|
|
3620
3609
|
const editorSelection = slateRangeToSelection({
|
|
@@ -3717,86 +3706,82 @@ const decoratorAddActionImplementation = ({
|
|
|
3717
3706
|
...selection2
|
|
3718
3707
|
};
|
|
3719
3708
|
}
|
|
3720
|
-
},
|
|
3709
|
+
}, deleteOperationImplementation = ({
|
|
3721
3710
|
context,
|
|
3722
|
-
|
|
3711
|
+
operation
|
|
3723
3712
|
}) => {
|
|
3724
|
-
const range = toSlateRange(
|
|
3713
|
+
const range = toSlateRange(operation.at, operation.editor);
|
|
3725
3714
|
if (!range)
|
|
3726
|
-
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(
|
|
3715
|
+
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
|
|
3727
3716
|
if (slate.Range.isCollapsed(range)) {
|
|
3728
3717
|
const [focusBlock] = getFocusBlock({
|
|
3729
3718
|
editor: {
|
|
3730
|
-
...
|
|
3719
|
+
...operation.editor,
|
|
3731
3720
|
selection: range
|
|
3732
3721
|
}
|
|
3733
3722
|
}), [focusChild] = getFocusChild({
|
|
3734
3723
|
editor: {
|
|
3735
|
-
...
|
|
3724
|
+
...operation.editor,
|
|
3736
3725
|
selection: range
|
|
3737
3726
|
}
|
|
3738
3727
|
});
|
|
3739
3728
|
if (focusBlock && focusBlock._type === context.schema.block.name && focusChild && focusChild._type === context.schema.span.name)
|
|
3740
3729
|
return;
|
|
3741
3730
|
}
|
|
3742
|
-
|
|
3731
|
+
operation.editor.delete({
|
|
3743
3732
|
at: range
|
|
3744
3733
|
});
|
|
3745
|
-
},
|
|
3746
|
-
|
|
3734
|
+
}, deleteBackwardOperationImplementation = ({
|
|
3735
|
+
operation
|
|
3747
3736
|
}) => {
|
|
3748
|
-
|
|
3749
|
-
},
|
|
3750
|
-
|
|
3737
|
+
slate.deleteBackward(operation.editor, operation.unit);
|
|
3738
|
+
}, deleteBlockOperationImplementation = ({
|
|
3739
|
+
operation
|
|
3751
3740
|
}) => {
|
|
3752
3741
|
const range = toSlateRange({
|
|
3753
3742
|
anchor: {
|
|
3754
|
-
path:
|
|
3743
|
+
path: operation.at,
|
|
3755
3744
|
offset: 0
|
|
3756
3745
|
},
|
|
3757
3746
|
focus: {
|
|
3758
|
-
path:
|
|
3747
|
+
path: operation.at,
|
|
3759
3748
|
offset: 0
|
|
3760
3749
|
}
|
|
3761
|
-
},
|
|
3750
|
+
}, operation.editor);
|
|
3762
3751
|
if (!range) {
|
|
3763
3752
|
console.error("Unable to find Slate range from selection points");
|
|
3764
3753
|
return;
|
|
3765
3754
|
}
|
|
3766
|
-
slate.Transforms.removeNodes(
|
|
3755
|
+
slate.Transforms.removeNodes(operation.editor, {
|
|
3767
3756
|
at: range
|
|
3768
3757
|
});
|
|
3769
|
-
},
|
|
3770
|
-
|
|
3771
|
-
}) => {
|
|
3772
|
-
action.editor.deleteForward(action.unit);
|
|
3773
|
-
}, effectActionImplementation = ({
|
|
3774
|
-
action
|
|
3758
|
+
}, deleteForwardOperationImplementation = ({
|
|
3759
|
+
operation
|
|
3775
3760
|
}) => {
|
|
3776
|
-
|
|
3777
|
-
},
|
|
3761
|
+
slate.deleteForward(operation.editor, operation.unit);
|
|
3762
|
+
}, insertInlineObjectOperationImplementation = ({
|
|
3778
3763
|
context,
|
|
3779
|
-
|
|
3764
|
+
operation
|
|
3780
3765
|
}) => {
|
|
3781
3766
|
const parsedInlineObject = util_sliceBlocks.parseInlineObject({
|
|
3782
3767
|
context,
|
|
3783
3768
|
inlineObject: {
|
|
3784
|
-
_type:
|
|
3785
|
-
...
|
|
3769
|
+
_type: operation.inlineObject.name,
|
|
3770
|
+
...operation.inlineObject.value ?? {}
|
|
3786
3771
|
},
|
|
3787
3772
|
options: {
|
|
3788
3773
|
refreshKeys: !1
|
|
3789
3774
|
}
|
|
3790
3775
|
});
|
|
3791
3776
|
if (!parsedInlineObject)
|
|
3792
|
-
throw new Error(`Failed to parse inline object ${JSON.stringify(
|
|
3793
|
-
if (!
|
|
3777
|
+
throw new Error(`Failed to parse inline object ${JSON.stringify(operation.inlineObject)}`);
|
|
3778
|
+
if (!operation.editor.selection) {
|
|
3794
3779
|
console.error("Unable to insert inline object without selection");
|
|
3795
3780
|
return;
|
|
3796
3781
|
}
|
|
3797
|
-
const [focusTextBlock] = Array.from(slate.Editor.nodes(
|
|
3798
|
-
at:
|
|
3799
|
-
match: (node) =>
|
|
3782
|
+
const [focusTextBlock] = Array.from(slate.Editor.nodes(operation.editor, {
|
|
3783
|
+
at: operation.editor.selection.focus.path,
|
|
3784
|
+
match: (node) => operation.editor.isTextBlock(node)
|
|
3800
3785
|
})).at(0) ?? [void 0, void 0];
|
|
3801
3786
|
if (!focusTextBlock) {
|
|
3802
3787
|
console.error("Unable to perform action without focus text block");
|
|
@@ -3813,49 +3798,49 @@ const decoratorAddActionImplementation = ({
|
|
|
3813
3798
|
console.error("Unable to insert inline object");
|
|
3814
3799
|
return;
|
|
3815
3800
|
}
|
|
3816
|
-
slate.Transforms.insertNodes(
|
|
3817
|
-
},
|
|
3801
|
+
slate.Transforms.insertNodes(operation.editor, child);
|
|
3802
|
+
}, insertSpanOperationImplementation = ({
|
|
3818
3803
|
context,
|
|
3819
|
-
|
|
3804
|
+
operation
|
|
3820
3805
|
}) => {
|
|
3821
|
-
if (!
|
|
3822
|
-
console.error("Unable to perform action without selection",
|
|
3806
|
+
if (!operation.editor.selection) {
|
|
3807
|
+
console.error("Unable to perform action without selection", operation);
|
|
3823
3808
|
return;
|
|
3824
3809
|
}
|
|
3825
|
-
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(
|
|
3826
|
-
at:
|
|
3827
|
-
match: (node) =>
|
|
3810
|
+
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(operation.editor, {
|
|
3811
|
+
at: operation.editor.selection.focus.path,
|
|
3812
|
+
match: (node) => operation.editor.isTextBlock(node)
|
|
3828
3813
|
}))[0] ?? [void 0, void 0];
|
|
3829
3814
|
if (!focusBlock || !focusBlockPath) {
|
|
3830
|
-
console.error("Unable to perform action without focus block",
|
|
3815
|
+
console.error("Unable to perform action without focus block", operation);
|
|
3831
3816
|
return;
|
|
3832
3817
|
}
|
|
3833
|
-
const markDefs = focusBlock.markDefs ?? [], annotations =
|
|
3818
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = operation.annotations ? operation.annotations.map((annotation) => ({
|
|
3834
3819
|
_type: annotation.name,
|
|
3835
3820
|
_key: context.keyGenerator(),
|
|
3836
3821
|
...annotation.value
|
|
3837
3822
|
})) : void 0;
|
|
3838
|
-
annotations && annotations.length > 0 && slate.Transforms.setNodes(
|
|
3823
|
+
annotations && annotations.length > 0 && slate.Transforms.setNodes(operation.editor, {
|
|
3839
3824
|
markDefs: [...markDefs, ...annotations]
|
|
3840
|
-
}), slate.Transforms.insertNodes(
|
|
3825
|
+
}), slate.Transforms.insertNodes(operation.editor, {
|
|
3841
3826
|
_type: "span",
|
|
3842
3827
|
_key: context.keyGenerator(),
|
|
3843
|
-
text:
|
|
3844
|
-
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...
|
|
3828
|
+
text: operation.text,
|
|
3829
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...operation.decorators ?? []]
|
|
3845
3830
|
});
|
|
3846
|
-
},
|
|
3831
|
+
}, insertBlockOperationImplementation = ({
|
|
3847
3832
|
context,
|
|
3848
|
-
|
|
3833
|
+
operation
|
|
3849
3834
|
}) => {
|
|
3850
3835
|
const parsedBlock = util_sliceBlocks.parseBlock({
|
|
3851
|
-
block:
|
|
3836
|
+
block: operation.block,
|
|
3852
3837
|
context,
|
|
3853
3838
|
options: {
|
|
3854
3839
|
refreshKeys: !1
|
|
3855
3840
|
}
|
|
3856
3841
|
});
|
|
3857
3842
|
if (!parsedBlock)
|
|
3858
|
-
throw new Error(`Failed to parse block ${JSON.stringify(
|
|
3843
|
+
throw new Error(`Failed to parse block ${JSON.stringify(operation.block)}`);
|
|
3859
3844
|
const fragment = toSlateValue([parsedBlock], {
|
|
3860
3845
|
schemaTypes: context.schema
|
|
3861
3846
|
})[0];
|
|
@@ -3863,9 +3848,9 @@ const decoratorAddActionImplementation = ({
|
|
|
3863
3848
|
throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
|
|
3864
3849
|
insertBlock({
|
|
3865
3850
|
block: fragment,
|
|
3866
|
-
placement:
|
|
3867
|
-
select:
|
|
3868
|
-
editor:
|
|
3851
|
+
placement: operation.placement,
|
|
3852
|
+
select: operation.select ?? "start",
|
|
3853
|
+
editor: operation.editor,
|
|
3869
3854
|
schema: context.schema
|
|
3870
3855
|
});
|
|
3871
3856
|
};
|
|
@@ -4017,226 +4002,229 @@ function insertBlock({
|
|
|
4017
4002
|
}
|
|
4018
4003
|
}
|
|
4019
4004
|
}
|
|
4020
|
-
const
|
|
4021
|
-
|
|
4005
|
+
const moveBackwardOperationImplementation = ({
|
|
4006
|
+
operation
|
|
4022
4007
|
}) => {
|
|
4023
|
-
slate.Transforms.move(
|
|
4008
|
+
slate.Transforms.move(operation.editor, {
|
|
4024
4009
|
unit: "character",
|
|
4025
|
-
distance:
|
|
4010
|
+
distance: operation.distance,
|
|
4026
4011
|
reverse: !0
|
|
4027
4012
|
});
|
|
4028
|
-
},
|
|
4029
|
-
|
|
4013
|
+
}, moveBlockOperationImplementation = ({
|
|
4014
|
+
operation
|
|
4030
4015
|
}) => {
|
|
4031
|
-
const at = [toSlatePath(
|
|
4032
|
-
slate.Transforms.moveNodes(
|
|
4016
|
+
const at = [toSlatePath(operation.at, operation.editor)[0]], to = [toSlatePath(operation.to, operation.editor)[0]];
|
|
4017
|
+
slate.Transforms.moveNodes(operation.editor, {
|
|
4033
4018
|
at,
|
|
4034
4019
|
to,
|
|
4035
4020
|
mode: "highest"
|
|
4036
4021
|
});
|
|
4037
|
-
},
|
|
4038
|
-
|
|
4022
|
+
}, moveForwardOperationImplementation = ({
|
|
4023
|
+
operation
|
|
4039
4024
|
}) => {
|
|
4040
|
-
slate.Transforms.move(
|
|
4025
|
+
slate.Transforms.move(operation.editor, {
|
|
4041
4026
|
unit: "character",
|
|
4042
|
-
distance:
|
|
4027
|
+
distance: operation.distance
|
|
4043
4028
|
});
|
|
4044
|
-
},
|
|
4045
|
-
|
|
4029
|
+
}, selectOperationImplementation = ({
|
|
4030
|
+
operation
|
|
4046
4031
|
}) => {
|
|
4047
|
-
const newSelection = toSlateRange(
|
|
4048
|
-
newSelection ? slate.Transforms.select(
|
|
4049
|
-
},
|
|
4050
|
-
"annotation.add":
|
|
4051
|
-
"annotation.remove":
|
|
4052
|
-
"block.set":
|
|
4053
|
-
"block.unset":
|
|
4054
|
-
"decorator.add":
|
|
4055
|
-
"decorator.remove":
|
|
4056
|
-
delete:
|
|
4057
|
-
"delete.backward":
|
|
4058
|
-
"delete.forward":
|
|
4059
|
-
"delete.block":
|
|
4060
|
-
"history.redo":
|
|
4061
|
-
"history.undo":
|
|
4062
|
-
"insert.block":
|
|
4063
|
-
"insert.inline object":
|
|
4064
|
-
"insert.span":
|
|
4065
|
-
"insert.text":
|
|
4066
|
-
|
|
4067
|
-
"move.
|
|
4068
|
-
"move.
|
|
4069
|
-
|
|
4070
|
-
select: selectActionImplementation
|
|
4032
|
+
const newSelection = toSlateRange(operation.at, operation.editor);
|
|
4033
|
+
newSelection ? slate.Transforms.select(operation.editor, newSelection) : slate.Transforms.deselect(operation.editor);
|
|
4034
|
+
}, behaviorOperationImplementations = {
|
|
4035
|
+
"annotation.add": addAnnotationOperationImplementation,
|
|
4036
|
+
"annotation.remove": removeAnnotationOperationImplementation,
|
|
4037
|
+
"block.set": blockSetOperationImplementation,
|
|
4038
|
+
"block.unset": blockUnsetOperationImplementation,
|
|
4039
|
+
"decorator.add": decoratorAddOperationImplementation,
|
|
4040
|
+
"decorator.remove": removeDecoratorOperationImplementation,
|
|
4041
|
+
delete: deleteOperationImplementation,
|
|
4042
|
+
"delete.backward": deleteBackwardOperationImplementation,
|
|
4043
|
+
"delete.forward": deleteForwardOperationImplementation,
|
|
4044
|
+
"delete.block": deleteBlockOperationImplementation,
|
|
4045
|
+
"history.redo": historyRedoOperationImplementation,
|
|
4046
|
+
"history.undo": historyUndoOperationImplementation,
|
|
4047
|
+
"insert.block": insertBlockOperationImplementation,
|
|
4048
|
+
"insert.inline object": insertInlineObjectOperationImplementation,
|
|
4049
|
+
"insert.span": insertSpanOperationImplementation,
|
|
4050
|
+
"insert.text": insertTextOperationImplementation,
|
|
4051
|
+
"move.backward": moveBackwardOperationImplementation,
|
|
4052
|
+
"move.block": moveBlockOperationImplementation,
|
|
4053
|
+
"move.forward": moveForwardOperationImplementation,
|
|
4054
|
+
select: selectOperationImplementation
|
|
4071
4055
|
};
|
|
4072
|
-
function
|
|
4056
|
+
function performOperation({
|
|
4073
4057
|
context,
|
|
4074
|
-
|
|
4058
|
+
operation
|
|
4075
4059
|
}) {
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
behaviorActionImplementations.select({
|
|
4219
|
-
context,
|
|
4220
|
-
action
|
|
4221
|
-
});
|
|
4222
|
-
break;
|
|
4060
|
+
try {
|
|
4061
|
+
switch (operation.type) {
|
|
4062
|
+
case "annotation.add": {
|
|
4063
|
+
behaviorOperationImplementations["annotation.add"]({
|
|
4064
|
+
context,
|
|
4065
|
+
operation
|
|
4066
|
+
});
|
|
4067
|
+
break;
|
|
4068
|
+
}
|
|
4069
|
+
case "annotation.remove": {
|
|
4070
|
+
behaviorOperationImplementations["annotation.remove"]({
|
|
4071
|
+
context,
|
|
4072
|
+
operation
|
|
4073
|
+
});
|
|
4074
|
+
break;
|
|
4075
|
+
}
|
|
4076
|
+
case "block.set": {
|
|
4077
|
+
behaviorOperationImplementations["block.set"]({
|
|
4078
|
+
context,
|
|
4079
|
+
operation
|
|
4080
|
+
});
|
|
4081
|
+
break;
|
|
4082
|
+
}
|
|
4083
|
+
case "block.unset": {
|
|
4084
|
+
behaviorOperationImplementations["block.unset"]({
|
|
4085
|
+
context,
|
|
4086
|
+
operation
|
|
4087
|
+
});
|
|
4088
|
+
break;
|
|
4089
|
+
}
|
|
4090
|
+
case "decorator.add": {
|
|
4091
|
+
behaviorOperationImplementations["decorator.add"]({
|
|
4092
|
+
context,
|
|
4093
|
+
operation
|
|
4094
|
+
});
|
|
4095
|
+
break;
|
|
4096
|
+
}
|
|
4097
|
+
case "decorator.remove": {
|
|
4098
|
+
behaviorOperationImplementations["decorator.remove"]({
|
|
4099
|
+
context,
|
|
4100
|
+
operation
|
|
4101
|
+
});
|
|
4102
|
+
break;
|
|
4103
|
+
}
|
|
4104
|
+
case "delete": {
|
|
4105
|
+
behaviorOperationImplementations.delete({
|
|
4106
|
+
context,
|
|
4107
|
+
operation
|
|
4108
|
+
});
|
|
4109
|
+
break;
|
|
4110
|
+
}
|
|
4111
|
+
case "delete.backward": {
|
|
4112
|
+
behaviorOperationImplementations["delete.backward"]({
|
|
4113
|
+
context,
|
|
4114
|
+
operation
|
|
4115
|
+
});
|
|
4116
|
+
break;
|
|
4117
|
+
}
|
|
4118
|
+
case "delete.block": {
|
|
4119
|
+
behaviorOperationImplementations["delete.block"]({
|
|
4120
|
+
context,
|
|
4121
|
+
operation
|
|
4122
|
+
});
|
|
4123
|
+
break;
|
|
4124
|
+
}
|
|
4125
|
+
case "delete.forward": {
|
|
4126
|
+
behaviorOperationImplementations["delete.forward"]({
|
|
4127
|
+
context,
|
|
4128
|
+
operation
|
|
4129
|
+
});
|
|
4130
|
+
break;
|
|
4131
|
+
}
|
|
4132
|
+
case "history.redo": {
|
|
4133
|
+
behaviorOperationImplementations["history.redo"]({
|
|
4134
|
+
context,
|
|
4135
|
+
operation
|
|
4136
|
+
});
|
|
4137
|
+
break;
|
|
4138
|
+
}
|
|
4139
|
+
case "history.undo": {
|
|
4140
|
+
behaviorOperationImplementations["history.undo"]({
|
|
4141
|
+
context,
|
|
4142
|
+
operation
|
|
4143
|
+
});
|
|
4144
|
+
break;
|
|
4145
|
+
}
|
|
4146
|
+
case "insert.block": {
|
|
4147
|
+
behaviorOperationImplementations["insert.block"]({
|
|
4148
|
+
context,
|
|
4149
|
+
operation
|
|
4150
|
+
});
|
|
4151
|
+
break;
|
|
4152
|
+
}
|
|
4153
|
+
case "insert.inline object": {
|
|
4154
|
+
behaviorOperationImplementations["insert.inline object"]({
|
|
4155
|
+
context,
|
|
4156
|
+
operation
|
|
4157
|
+
});
|
|
4158
|
+
break;
|
|
4159
|
+
}
|
|
4160
|
+
case "insert.span": {
|
|
4161
|
+
behaviorOperationImplementations["insert.span"]({
|
|
4162
|
+
context,
|
|
4163
|
+
operation
|
|
4164
|
+
});
|
|
4165
|
+
break;
|
|
4166
|
+
}
|
|
4167
|
+
case "insert.text": {
|
|
4168
|
+
behaviorOperationImplementations["insert.text"]({
|
|
4169
|
+
context,
|
|
4170
|
+
operation
|
|
4171
|
+
});
|
|
4172
|
+
break;
|
|
4173
|
+
}
|
|
4174
|
+
case "move.backward": {
|
|
4175
|
+
behaviorOperationImplementations["move.backward"]({
|
|
4176
|
+
context,
|
|
4177
|
+
operation
|
|
4178
|
+
});
|
|
4179
|
+
break;
|
|
4180
|
+
}
|
|
4181
|
+
case "move.block": {
|
|
4182
|
+
behaviorOperationImplementations["move.block"]({
|
|
4183
|
+
context,
|
|
4184
|
+
operation
|
|
4185
|
+
});
|
|
4186
|
+
break;
|
|
4187
|
+
}
|
|
4188
|
+
case "move.forward": {
|
|
4189
|
+
behaviorOperationImplementations["move.forward"]({
|
|
4190
|
+
context,
|
|
4191
|
+
operation
|
|
4192
|
+
});
|
|
4193
|
+
break;
|
|
4194
|
+
}
|
|
4195
|
+
default: {
|
|
4196
|
+
behaviorOperationImplementations.select({
|
|
4197
|
+
context,
|
|
4198
|
+
operation
|
|
4199
|
+
});
|
|
4200
|
+
break;
|
|
4201
|
+
}
|
|
4223
4202
|
}
|
|
4203
|
+
} catch (error) {
|
|
4204
|
+
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4224
4205
|
}
|
|
4225
4206
|
}
|
|
4207
|
+
const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
|
|
4208
|
+
function withApplyingBehaviorOperations(editor, fn) {
|
|
4209
|
+
CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
|
|
4210
|
+
}
|
|
4211
|
+
function getCurrentOperationId(editor) {
|
|
4212
|
+
return CURRENT_OPERATION_ID.get(editor);
|
|
4213
|
+
}
|
|
4214
|
+
function isApplyingBehaviorOperations(editor) {
|
|
4215
|
+
return getCurrentOperationId(editor) !== void 0;
|
|
4216
|
+
}
|
|
4226
4217
|
function createWithEventListeners(editorActor) {
|
|
4227
4218
|
return function(editor) {
|
|
4228
4219
|
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
4229
4220
|
return editor;
|
|
4230
4221
|
const {
|
|
4231
|
-
deleteBackward,
|
|
4232
|
-
deleteForward,
|
|
4233
|
-
insertBreak,
|
|
4234
4222
|
insertText,
|
|
4235
4223
|
select
|
|
4236
4224
|
} = editor;
|
|
4237
4225
|
return editor.deleteBackward = (unit) => {
|
|
4238
|
-
if (
|
|
4239
|
-
deleteBackward(
|
|
4226
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4227
|
+
console.error("Unexpected call to .deleteBackward(...)");
|
|
4240
4228
|
return;
|
|
4241
4229
|
}
|
|
4242
4230
|
editorActor.send({
|
|
@@ -4248,8 +4236,8 @@ function createWithEventListeners(editorActor) {
|
|
|
4248
4236
|
editor
|
|
4249
4237
|
});
|
|
4250
4238
|
}, editor.deleteForward = (unit) => {
|
|
4251
|
-
if (
|
|
4252
|
-
deleteForward(
|
|
4239
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4240
|
+
console.error("Unexpected call to .deleteForward(...)");
|
|
4253
4241
|
return;
|
|
4254
4242
|
}
|
|
4255
4243
|
editorActor.send({
|
|
@@ -4261,8 +4249,8 @@ function createWithEventListeners(editorActor) {
|
|
|
4261
4249
|
editor
|
|
4262
4250
|
});
|
|
4263
4251
|
}, editor.insertBreak = () => {
|
|
4264
|
-
if (
|
|
4265
|
-
insertBreak();
|
|
4252
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4253
|
+
console.error("Unexpected call to .insertBreak(...)");
|
|
4266
4254
|
return;
|
|
4267
4255
|
}
|
|
4268
4256
|
editorActor.send({
|
|
@@ -4273,8 +4261,10 @@ function createWithEventListeners(editorActor) {
|
|
|
4273
4261
|
editor
|
|
4274
4262
|
});
|
|
4275
4263
|
}, editor.insertData = (dataTransfer) => {
|
|
4276
|
-
if (
|
|
4277
|
-
|
|
4264
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4265
|
+
console.error("Unexpected call to .insertData(...)");
|
|
4266
|
+
return;
|
|
4267
|
+
}
|
|
4278
4268
|
editorActor.send({
|
|
4279
4269
|
type: "behavior event",
|
|
4280
4270
|
behaviorEvent: {
|
|
@@ -4286,13 +4276,13 @@ function createWithEventListeners(editorActor) {
|
|
|
4286
4276
|
editor
|
|
4287
4277
|
});
|
|
4288
4278
|
}, editor.insertSoftBreak = () => {
|
|
4289
|
-
if (
|
|
4290
|
-
|
|
4279
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4280
|
+
insertTextOperationImplementation({
|
|
4291
4281
|
context: {
|
|
4292
4282
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4293
4283
|
schema: editorActor.getSnapshot().context.schema
|
|
4294
4284
|
},
|
|
4295
|
-
|
|
4285
|
+
operation: {
|
|
4296
4286
|
text: `
|
|
4297
4287
|
`,
|
|
4298
4288
|
editor
|
|
@@ -4308,7 +4298,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4308
4298
|
editor
|
|
4309
4299
|
});
|
|
4310
4300
|
}, editor.insertText = (text, options) => {
|
|
4311
|
-
if (
|
|
4301
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4312
4302
|
insertText(text, options);
|
|
4313
4303
|
return;
|
|
4314
4304
|
}
|
|
@@ -4321,13 +4311,13 @@ function createWithEventListeners(editorActor) {
|
|
|
4321
4311
|
editor
|
|
4322
4312
|
});
|
|
4323
4313
|
}, editor.redo = () => {
|
|
4324
|
-
if (
|
|
4325
|
-
|
|
4314
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4315
|
+
performOperation({
|
|
4326
4316
|
context: {
|
|
4327
4317
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4328
4318
|
schema: editorActor.getSnapshot().context.schema
|
|
4329
4319
|
},
|
|
4330
|
-
|
|
4320
|
+
operation: {
|
|
4331
4321
|
type: "history.redo",
|
|
4332
4322
|
editor
|
|
4333
4323
|
}
|
|
@@ -4342,7 +4332,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4342
4332
|
editor
|
|
4343
4333
|
});
|
|
4344
4334
|
}, editor.select = (location) => {
|
|
4345
|
-
if (
|
|
4335
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4346
4336
|
select(location);
|
|
4347
4337
|
return;
|
|
4348
4338
|
}
|
|
@@ -4360,15 +4350,15 @@ function createWithEventListeners(editorActor) {
|
|
|
4360
4350
|
editor
|
|
4361
4351
|
});
|
|
4362
4352
|
}, editor.setFragmentData = () => {
|
|
4363
|
-
console.
|
|
4353
|
+
console.error("Unexpected call to .setFragmentData(...)");
|
|
4364
4354
|
}, editor.undo = () => {
|
|
4365
|
-
if (
|
|
4366
|
-
|
|
4355
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4356
|
+
performOperation({
|
|
4367
4357
|
context: {
|
|
4368
4358
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4369
4359
|
schema: editorActor.getSnapshot().context.schema
|
|
4370
4360
|
},
|
|
4371
|
-
|
|
4361
|
+
operation: {
|
|
4372
4362
|
type: "history.undo",
|
|
4373
4363
|
editor
|
|
4374
4364
|
}
|
|
@@ -4772,9 +4762,14 @@ function createWithPatches({
|
|
|
4772
4762
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
4773
4763
|
withoutPatching(editor, () => {
|
|
4774
4764
|
withoutSaving(editor, () => {
|
|
4775
|
-
|
|
4776
|
-
debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`)
|
|
4777
|
-
|
|
4765
|
+
for (const patch of patches2) {
|
|
4766
|
+
debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
4767
|
+
try {
|
|
4768
|
+
changed = applyPatch(editor, patch);
|
|
4769
|
+
} catch (error) {
|
|
4770
|
+
console.error(`Applying patch ${JSON.stringify(patch)} failed due to: ${error.message}`);
|
|
4771
|
+
}
|
|
4772
|
+
}
|
|
4778
4773
|
});
|
|
4779
4774
|
});
|
|
4780
4775
|
}), changed && (editor.normalize(), editor.onChange());
|
|
@@ -4836,7 +4831,7 @@ function createWithPatches({
|
|
|
4836
4831
|
...patch,
|
|
4837
4832
|
origin: "local"
|
|
4838
4833
|
},
|
|
4839
|
-
|
|
4834
|
+
operationId: getCurrentOperationId(editor),
|
|
4840
4835
|
value: fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4841
4836
|
});
|
|
4842
4837
|
return editor;
|
|
@@ -5578,12 +5573,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5578
5573
|
addAnnotation: (type, value) => {
|
|
5579
5574
|
let paths;
|
|
5580
5575
|
return slate.Editor.withoutNormalizing(editor, () => {
|
|
5581
|
-
paths =
|
|
5576
|
+
paths = addAnnotationOperationImplementation({
|
|
5582
5577
|
context: {
|
|
5583
5578
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5584
5579
|
schema: types2
|
|
5585
5580
|
},
|
|
5586
|
-
|
|
5581
|
+
operation: {
|
|
5587
5582
|
annotation: {
|
|
5588
5583
|
name: type.name,
|
|
5589
5584
|
value: value ?? {}
|
|
@@ -6667,7 +6662,24 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6667
6662
|
text: `
|
|
6668
6663
|
`
|
|
6669
6664
|
})]]
|
|
6670
|
-
})],
|
|
6665
|
+
})], keyIs = {
|
|
6666
|
+
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
6667
|
+
}, abstractKeyboardBehaviors = [
|
|
6668
|
+
/**
|
|
6669
|
+
* On WebKit, Shift+Enter results in an `insertParagraph` input event rather
|
|
6670
|
+
* than an `insertLineBreak` input event. This Behavior makes sure we catch
|
|
6671
|
+
* that `keyboard.keydown` event beforehand and raise an `insert.soft break` manually.
|
|
6672
|
+
*/
|
|
6673
|
+
behaviors_index.defineBehavior({
|
|
6674
|
+
on: "keyboard.keydown",
|
|
6675
|
+
guard: ({
|
|
6676
|
+
event
|
|
6677
|
+
}) => keyIs.lineBreak(event.originEvent),
|
|
6678
|
+
actions: [() => [behaviors_index.raise({
|
|
6679
|
+
type: "insert.soft break"
|
|
6680
|
+
})]]
|
|
6681
|
+
})
|
|
6682
|
+
], abstractListItemBehaviors = [behaviors_index.defineBehavior({
|
|
6671
6683
|
on: "list item.add",
|
|
6672
6684
|
guard: ({
|
|
6673
6685
|
snapshot
|
|
@@ -6993,17 +7005,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6993
7005
|
type: "style.add",
|
|
6994
7006
|
style: event.style
|
|
6995
7007
|
})]]
|
|
6996
|
-
})],
|
|
6997
|
-
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
6998
|
-
}, raiseInsertSoftBreak = behaviors_index.defineBehavior({
|
|
6999
|
-
on: "keyboard.keydown",
|
|
7000
|
-
guard: ({
|
|
7001
|
-
event
|
|
7002
|
-
}) => keyIs.lineBreak(event.originEvent),
|
|
7003
|
-
actions: [() => [behaviors_index.raise({
|
|
7004
|
-
type: "insert.soft break"
|
|
7005
|
-
})]]
|
|
7006
|
-
}), raiseDeserializationSuccessOrFailure = behaviors_index.defineBehavior({
|
|
7008
|
+
})], raiseDeserializationSuccessOrFailure = behaviors_index.defineBehavior({
|
|
7007
7009
|
on: "deserialize",
|
|
7008
7010
|
guard: ({
|
|
7009
7011
|
snapshot,
|
|
@@ -7063,7 +7065,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
7063
7065
|
...serializeEvent,
|
|
7064
7066
|
originEvent: event.originEvent
|
|
7065
7067
|
}))]
|
|
7066
|
-
}),
|
|
7068
|
+
}), abstractBehaviors = [
|
|
7067
7069
|
behaviors_index.defineBehavior({
|
|
7068
7070
|
on: "clipboard.copy",
|
|
7069
7071
|
guard: ({
|
|
@@ -7338,14 +7340,14 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
7338
7340
|
...abstractDecoratorBehaviors,
|
|
7339
7341
|
...abstractDeleteBehaviors,
|
|
7340
7342
|
...abstractInsertBehaviors,
|
|
7343
|
+
...abstractKeyboardBehaviors,
|
|
7341
7344
|
...abstractListItemBehaviors,
|
|
7342
7345
|
...abstractMoveBehaviors,
|
|
7343
7346
|
...abstractStyleBehaviors,
|
|
7344
7347
|
...abstractSelectBehaviors,
|
|
7345
7348
|
...abstractSplitBehaviors,
|
|
7346
7349
|
raiseDeserializationSuccessOrFailure,
|
|
7347
|
-
raiseSerializationSuccessOrFailure
|
|
7348
|
-
raiseInsertSoftBreak
|
|
7350
|
+
raiseSerializationSuccessOrFailure
|
|
7349
7351
|
];
|
|
7350
7352
|
function isSyntheticBehaviorEvent(event) {
|
|
7351
7353
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
@@ -7377,28 +7379,24 @@ function performEvent({
|
|
|
7377
7379
|
nativeEvent
|
|
7378
7380
|
}) {
|
|
7379
7381
|
debug$2(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
7380
|
-
const eventBehaviors = [...remainingEventBehaviors, ...
|
|
7382
|
+
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
7381
7383
|
if (behavior.on === "*")
|
|
7382
7384
|
return !0;
|
|
7383
7385
|
const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
|
|
7384
7386
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
7385
7387
|
});
|
|
7386
7388
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
7387
|
-
nativeEvent?.preventDefault(),
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
});
|
|
7399
|
-
} catch (error) {
|
|
7400
|
-
console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
|
|
7401
|
-
}
|
|
7389
|
+
nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
7390
|
+
debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
7391
|
+
context: {
|
|
7392
|
+
keyGenerator,
|
|
7393
|
+
schema: schema2
|
|
7394
|
+
},
|
|
7395
|
+
operation: {
|
|
7396
|
+
...event,
|
|
7397
|
+
editor
|
|
7398
|
+
}
|
|
7399
|
+
});
|
|
7402
7400
|
}), editor.onChange();
|
|
7403
7401
|
return;
|
|
7404
7402
|
}
|
|
@@ -7418,25 +7416,27 @@ function performEvent({
|
|
|
7418
7416
|
if (shouldRun) {
|
|
7419
7417
|
defaultBehaviorOverwritten = !0;
|
|
7420
7418
|
for (const actionSet of eventBehavior.actions) {
|
|
7421
|
-
const actionsSnapshot = getSnapshot()
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7419
|
+
const actionsSnapshot = getSnapshot();
|
|
7420
|
+
let actions = [];
|
|
7421
|
+
try {
|
|
7422
|
+
actions = actionSet({
|
|
7423
|
+
snapshot: actionsSnapshot,
|
|
7424
|
+
event
|
|
7425
|
+
}, shouldRun);
|
|
7426
|
+
} catch (error) {
|
|
7427
|
+
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
7428
|
+
}
|
|
7425
7429
|
if (actions.length !== 0) {
|
|
7426
7430
|
if (actions.some((action) => action.type === "execute")) {
|
|
7427
7431
|
withUndoStep(editor, () => {
|
|
7428
7432
|
for (const action of actions) {
|
|
7429
7433
|
if (action.type === "effect") {
|
|
7430
|
-
nativeEventPrevented = !0
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
}
|
|
7435
|
-
|
|
7436
|
-
...action,
|
|
7437
|
-
editor
|
|
7438
|
-
}
|
|
7439
|
-
});
|
|
7434
|
+
nativeEventPrevented = !0;
|
|
7435
|
+
try {
|
|
7436
|
+
action.effect();
|
|
7437
|
+
} catch (error) {
|
|
7438
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
7439
|
+
}
|
|
7440
7440
|
continue;
|
|
7441
7441
|
}
|
|
7442
7442
|
if (action.type === "forward") {
|
|
@@ -7485,16 +7485,12 @@ function performEvent({
|
|
|
7485
7485
|
}
|
|
7486
7486
|
for (const action of actions) {
|
|
7487
7487
|
if (action.type === "effect") {
|
|
7488
|
-
nativeEventPrevented = !0
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
}
|
|
7493
|
-
|
|
7494
|
-
...action,
|
|
7495
|
-
editor
|
|
7496
|
-
}
|
|
7497
|
-
});
|
|
7488
|
+
nativeEventPrevented = !0;
|
|
7489
|
+
try {
|
|
7490
|
+
action.effect();
|
|
7491
|
+
} catch (error) {
|
|
7492
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
7493
|
+
}
|
|
7498
7494
|
continue;
|
|
7499
7495
|
}
|
|
7500
7496
|
if (action.type === "forward") {
|
|
@@ -7533,21 +7529,17 @@ function performEvent({
|
|
|
7533
7529
|
break;
|
|
7534
7530
|
}
|
|
7535
7531
|
}
|
|
7536
|
-
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(),
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
});
|
|
7548
|
-
} catch (error) {
|
|
7549
|
-
console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
|
|
7550
|
-
}
|
|
7532
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
7533
|
+
debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
7534
|
+
context: {
|
|
7535
|
+
keyGenerator,
|
|
7536
|
+
schema: schema2
|
|
7537
|
+
},
|
|
7538
|
+
operation: {
|
|
7539
|
+
...event,
|
|
7540
|
+
editor
|
|
7541
|
+
}
|
|
7542
|
+
});
|
|
7551
7543
|
}), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
|
|
7552
7544
|
}
|
|
7553
7545
|
function createEditorSnapshot({
|
|
@@ -7694,27 +7686,32 @@ const editorMachine = xstate.setup({
|
|
|
7694
7686
|
event,
|
|
7695
7687
|
self: self2
|
|
7696
7688
|
}) => {
|
|
7697
|
-
xstate.assertEvent(event, ["behavior event"])
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
schema: context.schema,
|
|
7705
|
-
getSnapshot: () => createEditorSnapshot({
|
|
7706
|
-
converters: [...context.converters],
|
|
7689
|
+
xstate.assertEvent(event, ["behavior event"]);
|
|
7690
|
+
try {
|
|
7691
|
+
performEvent({
|
|
7692
|
+
mode: "raise",
|
|
7693
|
+
behaviors: [...context.behaviors.values(), ...coreBehaviors],
|
|
7694
|
+
remainingEventBehaviors: [...context.behaviors.values(), ...coreBehaviors],
|
|
7695
|
+
event: event.behaviorEvent,
|
|
7707
7696
|
editor: event.editor,
|
|
7708
7697
|
keyGenerator: context.keyGenerator,
|
|
7709
|
-
readOnly: self2.getSnapshot().matches({
|
|
7710
|
-
"edit mode": "read only"
|
|
7711
|
-
}),
|
|
7712
7698
|
schema: context.schema,
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7699
|
+
getSnapshot: () => createEditorSnapshot({
|
|
7700
|
+
converters: [...context.converters],
|
|
7701
|
+
editor: event.editor,
|
|
7702
|
+
keyGenerator: context.keyGenerator,
|
|
7703
|
+
readOnly: self2.getSnapshot().matches({
|
|
7704
|
+
"edit mode": "read only"
|
|
7705
|
+
}),
|
|
7706
|
+
schema: context.schema,
|
|
7707
|
+
hasTag: (tag) => self2.getSnapshot().hasTag(tag),
|
|
7708
|
+
internalDrag: context.internalDrag
|
|
7709
|
+
}),
|
|
7710
|
+
nativeEvent: event.nativeEvent
|
|
7711
|
+
});
|
|
7712
|
+
} catch (error) {
|
|
7713
|
+
console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
7714
|
+
}
|
|
7718
7715
|
}
|
|
7719
7716
|
},
|
|
7720
7717
|
guards: {
|
|
@@ -7727,7 +7724,7 @@ const editorMachine = xstate.setup({
|
|
|
7727
7724
|
context: ({
|
|
7728
7725
|
input
|
|
7729
7726
|
}) => ({
|
|
7730
|
-
behaviors: /* @__PURE__ */ new Set([
|
|
7727
|
+
behaviors: /* @__PURE__ */ new Set([]),
|
|
7731
7728
|
converters: new Set(input.converters ?? []),
|
|
7732
7729
|
getLegacySchema: input.getLegacySchema,
|
|
7733
7730
|
keyGenerator: input.keyGenerator,
|
|
@@ -8645,7 +8642,6 @@ exports.EditorActorContext = EditorActorContext;
|
|
|
8645
8642
|
exports.EditorProvider = EditorProvider;
|
|
8646
8643
|
exports.KEY_TO_VALUE_ELEMENT = KEY_TO_VALUE_ELEMENT;
|
|
8647
8644
|
exports.PortableTextEditor = PortableTextEditor;
|
|
8648
|
-
exports.coreBehaviors = coreBehaviors;
|
|
8649
8645
|
exports.debugWithName = debugWithName;
|
|
8650
8646
|
exports.defaultKeyGenerator = defaultKeyGenerator;
|
|
8651
8647
|
exports.defineSchema = defineSchema;
|