@portabletext/editor 1.48.13 → 1.48.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/editor-provider.cjs +682 -609
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +683 -610
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +226 -2772
- package/lib/behaviors/index.d.ts +226 -2772
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +22 -6
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +227 -2780
- package/lib/index.d.ts +227 -2780
- package/lib/index.js +23 -7
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +1 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +226 -2785
- package/lib/plugins/index.d.ts +226 -2785
- package/lib/plugins/index.js +2 -8
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +225 -2771
- package/lib/selectors/index.d.ts +225 -2771
- package/lib/utils/index.d.cts +227 -2772
- package/lib/utils/index.d.ts +227 -2772
- package/package.json +1 -1
- package/src/behaviors/behavior.abstract.keyboard.ts +16 -0
- package/src/behaviors/{behavior.default.ts → behavior.abstract.ts} +3 -3
- package/src/behaviors/behavior.config.ts +7 -0
- package/src/behaviors/behavior.core.ts +6 -5
- package/src/behaviors/behavior.perform-event.ts +27 -51
- package/src/behaviors/behavior.types.action.ts +1 -11
- package/src/editor/PortableTextEditor.tsx +1 -1
- package/src/editor/components/Element.tsx +30 -4
- package/src/editor/create-editor.ts +17 -5
- package/src/editor/editor-machine.ts +23 -17
- 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/priority/priority.core.ts +3 -0
- package/src/priority/priority.sort.test.ts +319 -0
- package/src/priority/priority.sort.ts +121 -0
- package/src/priority/priority.types.ts +24 -0
- 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.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 -219
- package/src/behaviors/behavior.default.raise-soft-break.ts +0 -14
- package/src/plugins/plugin.core.tsx +0 -9
|
@@ -5,7 +5,7 @@ import { withReact, ReactEditor, Slate } from "slate-react";
|
|
|
5
5
|
import { c } from "react-compiler-runtime";
|
|
6
6
|
import debug$f from "debug";
|
|
7
7
|
import isEqual from "lodash/isEqual.js";
|
|
8
|
-
import { Element, Text, Editor, Path, Operation, Transforms,
|
|
8
|
+
import { Element, Text, Editor, Path, Operation, Transforms, Range, Node, Point, deleteBackward, deleteForward, createEditor } from "slate";
|
|
9
9
|
import { setup, stateIn, fromCallback, assign, enqueueActions, emit, assertEvent, and, not, createActor } from "xstate";
|
|
10
10
|
import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
|
|
11
11
|
import flatten from "lodash/flatten.js";
|
|
@@ -173,18 +173,18 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
173
173
|
}) => {
|
|
174
174
|
if (assertEvent(event, "patch"), context.pendingMutations.length === 0)
|
|
175
175
|
return [{
|
|
176
|
-
|
|
176
|
+
operationId: event.operationId,
|
|
177
177
|
value: event.value,
|
|
178
178
|
patches: [event.patch]
|
|
179
179
|
}];
|
|
180
180
|
const lastBulk = context.pendingMutations.at(-1);
|
|
181
|
-
return lastBulk && lastBulk.
|
|
181
|
+
return lastBulk && lastBulk.operationId === event.operationId ? context.pendingMutations.slice(0, -1).concat({
|
|
182
182
|
value: event.value,
|
|
183
|
-
|
|
183
|
+
operationId: lastBulk.operationId,
|
|
184
184
|
patches: [...lastBulk.patches, event.patch]
|
|
185
185
|
}) : context.pendingMutations.concat({
|
|
186
186
|
value: event.value,
|
|
187
|
-
|
|
187
|
+
operationId: event.operationId,
|
|
188
188
|
patches: [event.patch]
|
|
189
189
|
});
|
|
190
190
|
}
|
|
@@ -1325,16 +1325,6 @@ function randomKey(length) {
|
|
|
1325
1325
|
const table = getByteHexTable();
|
|
1326
1326
|
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
1327
1327
|
}
|
|
1328
|
-
const CURRENT_ACTION_ID = /* @__PURE__ */ new WeakMap();
|
|
1329
|
-
function withApplyingBehaviorActions(editor, fn) {
|
|
1330
|
-
CURRENT_ACTION_ID.set(editor, defaultKeyGenerator()), Editor.withoutNormalizing(editor, fn), CURRENT_ACTION_ID.set(editor, void 0);
|
|
1331
|
-
}
|
|
1332
|
-
function getCurrentActionId(editor) {
|
|
1333
|
-
return CURRENT_ACTION_ID.get(editor);
|
|
1334
|
-
}
|
|
1335
|
-
function isApplyingBehaviorActions(editor) {
|
|
1336
|
-
return getCurrentActionId(editor) !== void 0;
|
|
1337
|
-
}
|
|
1338
1328
|
const CURRENT_UNDO_STEP = /* @__PURE__ */ new WeakMap();
|
|
1339
1329
|
function withUndoStep(editor, fn) {
|
|
1340
1330
|
const current = CURRENT_UNDO_STEP.get(editor);
|
|
@@ -1436,10 +1426,10 @@ function createWithUndoRedo(options) {
|
|
|
1436
1426
|
}, editor;
|
|
1437
1427
|
};
|
|
1438
1428
|
}
|
|
1439
|
-
const
|
|
1440
|
-
|
|
1429
|
+
const historyUndoOperationImplementation = ({
|
|
1430
|
+
operation
|
|
1441
1431
|
}) => {
|
|
1442
|
-
const editor =
|
|
1432
|
+
const editor = operation.editor, {
|
|
1443
1433
|
undos
|
|
1444
1434
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1445
1435
|
if (undos.length > 0) {
|
|
@@ -1471,10 +1461,10 @@ const historyUndoActionImplementation = ({
|
|
|
1471
1461
|
editor.history.redos.push(step), editor.history.undos.pop();
|
|
1472
1462
|
}
|
|
1473
1463
|
}
|
|
1474
|
-
},
|
|
1475
|
-
|
|
1464
|
+
}, historyRedoOperationImplementation = ({
|
|
1465
|
+
operation
|
|
1476
1466
|
}) => {
|
|
1477
|
-
const editor =
|
|
1467
|
+
const editor = operation.editor, {
|
|
1478
1468
|
redos
|
|
1479
1469
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
1480
1470
|
if (redos.length > 0) {
|
|
@@ -2428,7 +2418,16 @@ function compileType(rawType) {
|
|
|
2428
2418
|
types: [rawType]
|
|
2429
2419
|
}).get(rawType.name);
|
|
2430
2420
|
}
|
|
2431
|
-
|
|
2421
|
+
function createEditorPriority(config) {
|
|
2422
|
+
return {
|
|
2423
|
+
id: defaultKeyGenerator(),
|
|
2424
|
+
name: config?.name,
|
|
2425
|
+
reference: config?.reference
|
|
2426
|
+
};
|
|
2427
|
+
}
|
|
2428
|
+
const corePriority = createEditorPriority({
|
|
2429
|
+
name: "core"
|
|
2430
|
+
}), debug$b = debugWithName("operationToPatches");
|
|
2432
2431
|
function createOperationToPatches(editorActor) {
|
|
2433
2432
|
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
2434
2433
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
@@ -2650,13 +2649,214 @@ function createOperationToPatches(editorActor) {
|
|
|
2650
2649
|
splitNodePatch
|
|
2651
2650
|
};
|
|
2652
2651
|
}
|
|
2653
|
-
|
|
2654
|
-
|
|
2652
|
+
function getFocusBlock({
|
|
2653
|
+
editor
|
|
2654
|
+
}) {
|
|
2655
|
+
if (!editor.selection)
|
|
2656
|
+
return [void 0, void 0];
|
|
2657
|
+
try {
|
|
2658
|
+
return Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0];
|
|
2659
|
+
} catch {
|
|
2660
|
+
return [void 0, void 0];
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
function getSelectionStartBlock({
|
|
2664
|
+
editor
|
|
2665
|
+
}) {
|
|
2666
|
+
if (!editor.selection)
|
|
2667
|
+
return [void 0, void 0];
|
|
2668
|
+
const selectionStartPoint = Range.start(editor.selection);
|
|
2669
|
+
return getPointBlock({
|
|
2670
|
+
editor,
|
|
2671
|
+
point: selectionStartPoint
|
|
2672
|
+
});
|
|
2673
|
+
}
|
|
2674
|
+
function getSelectionEndBlock({
|
|
2675
|
+
editor
|
|
2676
|
+
}) {
|
|
2677
|
+
if (!editor.selection)
|
|
2678
|
+
return [void 0, void 0];
|
|
2679
|
+
const selectionEndPoint = Range.end(editor.selection);
|
|
2680
|
+
return getPointBlock({
|
|
2681
|
+
editor,
|
|
2682
|
+
point: selectionEndPoint
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
function getPointBlock({
|
|
2686
|
+
editor,
|
|
2687
|
+
point
|
|
2688
|
+
}) {
|
|
2689
|
+
try {
|
|
2690
|
+
const [block] = Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
|
|
2691
|
+
return block ? [block, point.path.slice(0, 1)] : [void 0, void 0];
|
|
2692
|
+
} catch {
|
|
2693
|
+
return [void 0, void 0];
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
function getFocusChild({
|
|
2697
|
+
editor
|
|
2698
|
+
}) {
|
|
2699
|
+
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
2700
|
+
editor
|
|
2701
|
+
}), childIndex = editor.selection?.focus.path.at(1);
|
|
2702
|
+
if (!focusBlock || !focusBlockPath || childIndex === void 0)
|
|
2703
|
+
return [void 0, void 0];
|
|
2704
|
+
try {
|
|
2705
|
+
const focusChild = Node.child(focusBlock, childIndex);
|
|
2706
|
+
return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
|
|
2707
|
+
} catch {
|
|
2708
|
+
return [void 0, void 0];
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
function getPointChild({
|
|
2712
|
+
editor,
|
|
2713
|
+
point
|
|
2714
|
+
}) {
|
|
2715
|
+
const [block, blockPath] = getPointBlock({
|
|
2716
|
+
editor,
|
|
2717
|
+
point
|
|
2718
|
+
}), childIndex = point.path.at(1);
|
|
2719
|
+
if (!block || !blockPath || childIndex === void 0)
|
|
2720
|
+
return [void 0, void 0];
|
|
2721
|
+
try {
|
|
2722
|
+
const pointChild = Node.child(block, childIndex);
|
|
2723
|
+
return pointChild ? [pointChild, [...blockPath, childIndex]] : [void 0, void 0];
|
|
2724
|
+
} catch {
|
|
2725
|
+
return [void 0, void 0];
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
function getFirstBlock({
|
|
2729
|
+
editor
|
|
2730
|
+
}) {
|
|
2731
|
+
const firstBlockPath = Editor.start(editor, []).path.at(0);
|
|
2732
|
+
try {
|
|
2733
|
+
return firstBlockPath !== void 0 ? Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
2734
|
+
} catch {
|
|
2735
|
+
return [void 0, void 0];
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
function getLastBlock({
|
|
2739
|
+
editor
|
|
2740
|
+
}) {
|
|
2741
|
+
const lastBlockPath = Editor.end(editor, []).path.at(0);
|
|
2742
|
+
try {
|
|
2743
|
+
return lastBlockPath !== void 0 ? Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
2744
|
+
} catch {
|
|
2745
|
+
return [void 0, void 0];
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
function getNodeBlock({
|
|
2749
|
+
editor,
|
|
2750
|
+
schema,
|
|
2751
|
+
node
|
|
2752
|
+
}) {
|
|
2753
|
+
if (Editor.isEditor(node))
|
|
2754
|
+
return;
|
|
2755
|
+
if (isBlockElement({
|
|
2756
|
+
editor,
|
|
2757
|
+
schema
|
|
2758
|
+
}, node))
|
|
2759
|
+
return elementToBlock({
|
|
2760
|
+
schema,
|
|
2761
|
+
element: node
|
|
2762
|
+
});
|
|
2763
|
+
const parent = Array.from(Editor.nodes(editor, {
|
|
2764
|
+
mode: "highest",
|
|
2765
|
+
at: [],
|
|
2766
|
+
match: (n) => isBlockElement({
|
|
2767
|
+
editor,
|
|
2768
|
+
schema
|
|
2769
|
+
}, n) && n.children.some((child) => child._key === node._key)
|
|
2770
|
+
})).at(0)?.at(0);
|
|
2771
|
+
return Element.isElement(parent) ? elementToBlock({
|
|
2772
|
+
schema,
|
|
2773
|
+
element: parent
|
|
2774
|
+
}) : void 0;
|
|
2775
|
+
}
|
|
2776
|
+
function elementToBlock({
|
|
2777
|
+
schema,
|
|
2778
|
+
element
|
|
2779
|
+
}) {
|
|
2780
|
+
return fromSlateValue([element], schema.block.name)?.at(0);
|
|
2781
|
+
}
|
|
2782
|
+
function isBlockElement({
|
|
2783
|
+
editor,
|
|
2784
|
+
schema
|
|
2785
|
+
}, node) {
|
|
2786
|
+
return Element.isElement(node) && !editor.isInline(node) && (schema.block.name === node._type || schema.blockObjects.some((blockObject) => blockObject.name === node._type));
|
|
2787
|
+
}
|
|
2788
|
+
function isListItemActive({
|
|
2789
|
+
editor,
|
|
2790
|
+
listItem
|
|
2791
|
+
}) {
|
|
2792
|
+
if (!editor.selection)
|
|
2793
|
+
return !1;
|
|
2794
|
+
const selectedBlocks = [...Editor.nodes(editor, {
|
|
2795
|
+
at: editor.selection,
|
|
2796
|
+
match: (node) => editor.isTextBlock(node)
|
|
2797
|
+
})];
|
|
2798
|
+
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
2799
|
+
}
|
|
2800
|
+
function isStyleActive({
|
|
2801
|
+
editor,
|
|
2802
|
+
style
|
|
2803
|
+
}) {
|
|
2804
|
+
if (!editor.selection)
|
|
2805
|
+
return !1;
|
|
2806
|
+
const selectedBlocks = [...Editor.nodes(editor, {
|
|
2807
|
+
at: editor.selection,
|
|
2808
|
+
match: (node) => editor.isTextBlock(node)
|
|
2809
|
+
})];
|
|
2810
|
+
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
2811
|
+
}
|
|
2812
|
+
function slateRangeToSelection({
|
|
2813
|
+
schema,
|
|
2814
|
+
editor,
|
|
2815
|
+
range
|
|
2816
|
+
}) {
|
|
2817
|
+
const [anchorBlock] = getPointBlock({
|
|
2818
|
+
editor,
|
|
2819
|
+
point: range.anchor
|
|
2820
|
+
}), [focusBlock] = getPointBlock({
|
|
2821
|
+
editor,
|
|
2822
|
+
point: range.focus
|
|
2823
|
+
});
|
|
2824
|
+
if (!anchorBlock || !focusBlock)
|
|
2825
|
+
return null;
|
|
2826
|
+
const [anchorChild] = anchorBlock._type === schema.block.name ? getPointChild({
|
|
2827
|
+
editor,
|
|
2828
|
+
point: range.anchor
|
|
2829
|
+
}) : [void 0, void 0], [focusChild] = focusBlock._type === schema.block.name ? getPointChild({
|
|
2830
|
+
editor,
|
|
2831
|
+
point: range.focus
|
|
2832
|
+
}) : [void 0, void 0], selection = {
|
|
2833
|
+
anchor: {
|
|
2834
|
+
path: [{
|
|
2835
|
+
_key: anchorBlock._key
|
|
2836
|
+
}],
|
|
2837
|
+
offset: range.anchor.offset
|
|
2838
|
+
},
|
|
2839
|
+
focus: {
|
|
2840
|
+
path: [{
|
|
2841
|
+
_key: focusBlock._key
|
|
2842
|
+
}],
|
|
2843
|
+
offset: range.focus.offset
|
|
2844
|
+
},
|
|
2845
|
+
backward: Range.isBackward(range)
|
|
2846
|
+
};
|
|
2847
|
+
return anchorChild && (selection.anchor.path.push("children"), selection.anchor.path.push({
|
|
2848
|
+
_key: anchorChild._key
|
|
2849
|
+
})), focusChild && (selection.focus.path.push("children"), selection.focus.path.push({
|
|
2850
|
+
_key: focusChild._key
|
|
2851
|
+
})), selection;
|
|
2852
|
+
}
|
|
2853
|
+
const insertTextOperationImplementation = ({
|
|
2854
|
+
operation
|
|
2655
2855
|
}) => {
|
|
2656
|
-
|
|
2657
|
-
text:
|
|
2658
|
-
...
|
|
2659
|
-
}) : Transforms.insertText(
|
|
2856
|
+
operation.editor.marks ? Transforms.insertNodes(operation.editor, {
|
|
2857
|
+
text: operation.text,
|
|
2858
|
+
...operation.editor.marks
|
|
2859
|
+
}) : Transforms.insertText(operation.editor, operation.text), operation.editor.marks = null;
|
|
2660
2860
|
};
|
|
2661
2861
|
function isPortableTextSpan(node) {
|
|
2662
2862
|
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"));
|
|
@@ -3056,10 +3256,10 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3056
3256
|
}, editor;
|
|
3057
3257
|
};
|
|
3058
3258
|
}
|
|
3059
|
-
const
|
|
3060
|
-
|
|
3259
|
+
const removeDecoratorOperationImplementation = ({
|
|
3260
|
+
operation
|
|
3061
3261
|
}) => {
|
|
3062
|
-
const editor =
|
|
3262
|
+
const editor = operation.editor, mark = operation.decorator, {
|
|
3063
3263
|
selection
|
|
3064
3264
|
} = editor;
|
|
3065
3265
|
if (selection) {
|
|
@@ -3130,14 +3330,14 @@ function isDecoratorActive({
|
|
|
3130
3330
|
...Editor.marks(editor) || {}
|
|
3131
3331
|
}.marks || []).includes(decorator);
|
|
3132
3332
|
}
|
|
3133
|
-
const
|
|
3333
|
+
const addAnnotationOperationImplementation = ({
|
|
3134
3334
|
context,
|
|
3135
|
-
|
|
3335
|
+
operation
|
|
3136
3336
|
}) => {
|
|
3137
3337
|
const parsedAnnotation = parseAnnotation({
|
|
3138
3338
|
annotation: {
|
|
3139
|
-
_type:
|
|
3140
|
-
...
|
|
3339
|
+
_type: operation.annotation.name,
|
|
3340
|
+
...operation.annotation.value
|
|
3141
3341
|
},
|
|
3142
3342
|
context,
|
|
3143
3343
|
options: {
|
|
@@ -3145,8 +3345,8 @@ const addAnnotationActionImplementation = ({
|
|
|
3145
3345
|
}
|
|
3146
3346
|
});
|
|
3147
3347
|
if (!parsedAnnotation)
|
|
3148
|
-
throw new Error(`Failed to parse annotation ${JSON.stringify(
|
|
3149
|
-
const editor =
|
|
3348
|
+
throw new Error(`Failed to parse annotation ${JSON.stringify(operation.annotation)}`);
|
|
3349
|
+
const editor = operation.editor;
|
|
3150
3350
|
if (!editor.selection || Range.isCollapsed(editor.selection))
|
|
3151
3351
|
return;
|
|
3152
3352
|
let paths, spanPath, markDefPath;
|
|
@@ -3197,10 +3397,10 @@ const addAnnotationActionImplementation = ({
|
|
|
3197
3397
|
markDefPaths,
|
|
3198
3398
|
spanPath
|
|
3199
3399
|
}), paths;
|
|
3200
|
-
},
|
|
3201
|
-
|
|
3400
|
+
}, removeAnnotationOperationImplementation = ({
|
|
3401
|
+
operation
|
|
3202
3402
|
}) => {
|
|
3203
|
-
const editor =
|
|
3403
|
+
const editor = operation.editor;
|
|
3204
3404
|
if (editor.selection)
|
|
3205
3405
|
if (Range.isCollapsed(editor.selection)) {
|
|
3206
3406
|
const [block, blockPath] = Editor.node(editor, editor.selection, {
|
|
@@ -3208,7 +3408,7 @@ const addAnnotationActionImplementation = ({
|
|
|
3208
3408
|
});
|
|
3209
3409
|
if (!editor.isTextBlock(block))
|
|
3210
3410
|
return;
|
|
3211
|
-
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type ===
|
|
3411
|
+
const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), [selectedChild, selectedChildPath] = Editor.node(editor, editor.selection, {
|
|
3212
3412
|
depth: 2
|
|
3213
3413
|
});
|
|
3214
3414
|
if (!editor.isTextSpan(selectedChild))
|
|
@@ -3253,7 +3453,7 @@ const addAnnotationActionImplementation = ({
|
|
|
3253
3453
|
for (const [child, childPath] of children) {
|
|
3254
3454
|
if (!editor.isTextSpan(child) || !Range.includes(editor.selection, childPath))
|
|
3255
3455
|
continue;
|
|
3256
|
-
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !==
|
|
3456
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
|
|
3257
3457
|
marksWithoutAnnotation.length !== marks.length && Transforms.setNodes(editor, {
|
|
3258
3458
|
marks: marksWithoutAnnotation
|
|
3259
3459
|
}, {
|
|
@@ -3305,34 +3505,34 @@ function moveRangeByOperation(range, operation) {
|
|
|
3305
3505
|
focus
|
|
3306
3506
|
};
|
|
3307
3507
|
}
|
|
3308
|
-
const
|
|
3508
|
+
const blockSetOperationImplementation = ({
|
|
3309
3509
|
context,
|
|
3310
|
-
|
|
3510
|
+
operation
|
|
3311
3511
|
}) => {
|
|
3312
3512
|
const location = toSlateRange({
|
|
3313
3513
|
anchor: {
|
|
3314
|
-
path:
|
|
3514
|
+
path: operation.at,
|
|
3315
3515
|
offset: 0
|
|
3316
3516
|
},
|
|
3317
3517
|
focus: {
|
|
3318
|
-
path:
|
|
3518
|
+
path: operation.at,
|
|
3319
3519
|
offset: 0
|
|
3320
3520
|
}
|
|
3321
|
-
},
|
|
3521
|
+
}, operation.editor);
|
|
3322
3522
|
if (!location)
|
|
3323
|
-
throw new Error(`Unable to convert ${JSON.stringify(
|
|
3324
|
-
const block = Editor.node(
|
|
3523
|
+
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3524
|
+
const block = Editor.node(operation.editor, location, {
|
|
3325
3525
|
depth: 1
|
|
3326
3526
|
})?.[0];
|
|
3327
3527
|
if (!block)
|
|
3328
|
-
throw new Error(`Unable to find block at ${JSON.stringify(
|
|
3329
|
-
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(
|
|
3528
|
+
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
3529
|
+
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
3330
3530
|
if (!parsedBlock)
|
|
3331
|
-
throw new Error(`Unable to parse block at ${JSON.stringify(
|
|
3531
|
+
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
3332
3532
|
const {
|
|
3333
3533
|
_type,
|
|
3334
3534
|
...filteredProps
|
|
3335
|
-
} =
|
|
3535
|
+
} = operation.props, updatedBlock = parseBlock({
|
|
3336
3536
|
context,
|
|
3337
3537
|
block: {
|
|
3338
3538
|
...parsedBlock,
|
|
@@ -3343,41 +3543,41 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3343
3543
|
}
|
|
3344
3544
|
});
|
|
3345
3545
|
if (!updatedBlock)
|
|
3346
|
-
throw new Error(`Unable to update block at ${JSON.stringify(
|
|
3546
|
+
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
3347
3547
|
const slateBlock = toSlateValue([updatedBlock], {
|
|
3348
3548
|
schemaTypes: context.schema
|
|
3349
3549
|
})?.at(0);
|
|
3350
3550
|
if (!slateBlock)
|
|
3351
3551
|
throw new Error("Unable to convert block to Slate value");
|
|
3352
|
-
Transforms.setNodes(
|
|
3552
|
+
Transforms.setNodes(operation.editor, slateBlock, {
|
|
3353
3553
|
at: location
|
|
3354
3554
|
});
|
|
3355
|
-
},
|
|
3555
|
+
}, blockUnsetOperationImplementation = ({
|
|
3356
3556
|
context,
|
|
3357
|
-
|
|
3557
|
+
operation
|
|
3358
3558
|
}) => {
|
|
3359
3559
|
const location = toSlateRange({
|
|
3360
3560
|
anchor: {
|
|
3361
|
-
path:
|
|
3561
|
+
path: operation.at,
|
|
3362
3562
|
offset: 0
|
|
3363
3563
|
},
|
|
3364
3564
|
focus: {
|
|
3365
|
-
path:
|
|
3565
|
+
path: operation.at,
|
|
3366
3566
|
offset: 0
|
|
3367
3567
|
}
|
|
3368
|
-
},
|
|
3568
|
+
}, operation.editor);
|
|
3369
3569
|
if (!location)
|
|
3370
|
-
throw new Error(`Unable to convert ${JSON.stringify(
|
|
3371
|
-
const block = Editor.node(
|
|
3570
|
+
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3571
|
+
const block = Editor.node(operation.editor, location, {
|
|
3372
3572
|
depth: 1
|
|
3373
3573
|
})?.[0];
|
|
3374
3574
|
if (!block)
|
|
3375
|
-
throw new Error(`Unable to find block at ${JSON.stringify(
|
|
3376
|
-
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(
|
|
3575
|
+
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
3576
|
+
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
3377
3577
|
if (!parsedBlock)
|
|
3378
|
-
throw new Error(`Unable to parse block at ${JSON.stringify(
|
|
3578
|
+
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
3379
3579
|
if (isTextBlock(context, parsedBlock)) {
|
|
3380
|
-
const propsToRemove =
|
|
3580
|
+
const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = parseBlock({
|
|
3381
3581
|
context,
|
|
3382
3582
|
block: omit(parsedBlock, propsToRemove),
|
|
3383
3583
|
options: {
|
|
@@ -3385,260 +3585,58 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3385
3585
|
}
|
|
3386
3586
|
});
|
|
3387
3587
|
if (!updatedTextBlock)
|
|
3388
|
-
throw new Error(`Unable to update block at ${JSON.stringify(
|
|
3588
|
+
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
3389
3589
|
const propsToSet = {};
|
|
3390
3590
|
for (const prop of propsToRemove)
|
|
3391
3591
|
prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
|
|
3392
|
-
Transforms.setNodes(
|
|
3592
|
+
Transforms.setNodes(operation.editor, propsToSet, {
|
|
3393
3593
|
at: location
|
|
3394
3594
|
});
|
|
3395
3595
|
return;
|
|
3396
3596
|
}
|
|
3397
3597
|
const updatedBlockObject = parseBlock({
|
|
3398
3598
|
context,
|
|
3399
|
-
block: omit(parsedBlock,
|
|
3599
|
+
block: omit(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
|
|
3400
3600
|
options: {
|
|
3401
3601
|
refreshKeys: !1
|
|
3402
3602
|
}
|
|
3403
3603
|
});
|
|
3404
3604
|
if (!updatedBlockObject)
|
|
3405
|
-
throw new Error(`Unable to update block at ${JSON.stringify(
|
|
3605
|
+
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
3406
3606
|
const {
|
|
3407
|
-
_type,
|
|
3408
|
-
_key,
|
|
3409
|
-
...props
|
|
3410
|
-
} = updatedBlockObject;
|
|
3411
|
-
Transforms.setNodes(
|
|
3412
|
-
_type,
|
|
3413
|
-
_key,
|
|
3414
|
-
value: props
|
|
3415
|
-
}, {
|
|
3416
|
-
at: location
|
|
3417
|
-
});
|
|
3418
|
-
};
|
|
3419
|
-
function getFocusBlock({
|
|
3420
|
-
editor
|
|
3421
|
-
}) {
|
|
3422
|
-
if (!editor.selection)
|
|
3423
|
-
return [void 0, void 0];
|
|
3424
|
-
try {
|
|
3425
|
-
return Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0];
|
|
3426
|
-
} catch {
|
|
3427
|
-
return [void 0, void 0];
|
|
3428
|
-
}
|
|
3429
|
-
}
|
|
3430
|
-
function getSelectionStartBlock({
|
|
3431
|
-
editor
|
|
3432
|
-
}) {
|
|
3433
|
-
if (!editor.selection)
|
|
3434
|
-
return [void 0, void 0];
|
|
3435
|
-
const selectionStartPoint = Range.start(editor.selection);
|
|
3436
|
-
return getPointBlock({
|
|
3437
|
-
editor,
|
|
3438
|
-
point: selectionStartPoint
|
|
3439
|
-
});
|
|
3440
|
-
}
|
|
3441
|
-
function getSelectionEndBlock({
|
|
3442
|
-
editor
|
|
3443
|
-
}) {
|
|
3444
|
-
if (!editor.selection)
|
|
3445
|
-
return [void 0, void 0];
|
|
3446
|
-
const selectionEndPoint = Range.end(editor.selection);
|
|
3447
|
-
return getPointBlock({
|
|
3448
|
-
editor,
|
|
3449
|
-
point: selectionEndPoint
|
|
3450
|
-
});
|
|
3451
|
-
}
|
|
3452
|
-
function getPointBlock({
|
|
3453
|
-
editor,
|
|
3454
|
-
point
|
|
3455
|
-
}) {
|
|
3456
|
-
try {
|
|
3457
|
-
const [block] = Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
|
|
3458
|
-
return block ? [block, point.path.slice(0, 1)] : [void 0, void 0];
|
|
3459
|
-
} catch {
|
|
3460
|
-
return [void 0, void 0];
|
|
3461
|
-
}
|
|
3462
|
-
}
|
|
3463
|
-
function getFocusChild({
|
|
3464
|
-
editor
|
|
3465
|
-
}) {
|
|
3466
|
-
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
3467
|
-
editor
|
|
3468
|
-
}), childIndex = editor.selection?.focus.path.at(1);
|
|
3469
|
-
if (!focusBlock || !focusBlockPath || childIndex === void 0)
|
|
3470
|
-
return [void 0, void 0];
|
|
3471
|
-
try {
|
|
3472
|
-
const focusChild = Node.child(focusBlock, childIndex);
|
|
3473
|
-
return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
|
|
3474
|
-
} catch {
|
|
3475
|
-
return [void 0, void 0];
|
|
3476
|
-
}
|
|
3477
|
-
}
|
|
3478
|
-
function getPointChild({
|
|
3479
|
-
editor,
|
|
3480
|
-
point
|
|
3481
|
-
}) {
|
|
3482
|
-
const [block, blockPath] = getPointBlock({
|
|
3483
|
-
editor,
|
|
3484
|
-
point
|
|
3485
|
-
}), childIndex = point.path.at(1);
|
|
3486
|
-
if (!block || !blockPath || childIndex === void 0)
|
|
3487
|
-
return [void 0, void 0];
|
|
3488
|
-
try {
|
|
3489
|
-
const pointChild = Node.child(block, childIndex);
|
|
3490
|
-
return pointChild ? [pointChild, [...blockPath, childIndex]] : [void 0, void 0];
|
|
3491
|
-
} catch {
|
|
3492
|
-
return [void 0, void 0];
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
|
-
function getFirstBlock({
|
|
3496
|
-
editor
|
|
3497
|
-
}) {
|
|
3498
|
-
const firstBlockPath = Editor.start(editor, []).path.at(0);
|
|
3499
|
-
try {
|
|
3500
|
-
return firstBlockPath !== void 0 ? Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
3501
|
-
} catch {
|
|
3502
|
-
return [void 0, void 0];
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
function getLastBlock({
|
|
3506
|
-
editor
|
|
3507
|
-
}) {
|
|
3508
|
-
const lastBlockPath = Editor.end(editor, []).path.at(0);
|
|
3509
|
-
try {
|
|
3510
|
-
return lastBlockPath !== void 0 ? Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
3511
|
-
} catch {
|
|
3512
|
-
return [void 0, void 0];
|
|
3513
|
-
}
|
|
3514
|
-
}
|
|
3515
|
-
function getNodeBlock({
|
|
3516
|
-
editor,
|
|
3517
|
-
schema,
|
|
3518
|
-
node
|
|
3519
|
-
}) {
|
|
3520
|
-
if (Editor.isEditor(node))
|
|
3521
|
-
return;
|
|
3522
|
-
if (isBlockElement({
|
|
3523
|
-
editor,
|
|
3524
|
-
schema
|
|
3525
|
-
}, node))
|
|
3526
|
-
return elementToBlock({
|
|
3527
|
-
schema,
|
|
3528
|
-
element: node
|
|
3529
|
-
});
|
|
3530
|
-
const parent = Array.from(Editor.nodes(editor, {
|
|
3531
|
-
mode: "highest",
|
|
3532
|
-
at: [],
|
|
3533
|
-
match: (n) => isBlockElement({
|
|
3534
|
-
editor,
|
|
3535
|
-
schema
|
|
3536
|
-
}, n) && n.children.some((child) => child._key === node._key)
|
|
3537
|
-
})).at(0)?.at(0);
|
|
3538
|
-
return Element.isElement(parent) ? elementToBlock({
|
|
3539
|
-
schema,
|
|
3540
|
-
element: parent
|
|
3541
|
-
}) : void 0;
|
|
3542
|
-
}
|
|
3543
|
-
function elementToBlock({
|
|
3544
|
-
schema,
|
|
3545
|
-
element
|
|
3546
|
-
}) {
|
|
3547
|
-
return fromSlateValue([element], schema.block.name)?.at(0);
|
|
3548
|
-
}
|
|
3549
|
-
function isBlockElement({
|
|
3550
|
-
editor,
|
|
3551
|
-
schema
|
|
3552
|
-
}, node) {
|
|
3553
|
-
return Element.isElement(node) && !editor.isInline(node) && (schema.block.name === node._type || schema.blockObjects.some((blockObject) => blockObject.name === node._type));
|
|
3554
|
-
}
|
|
3555
|
-
function isListItemActive({
|
|
3556
|
-
editor,
|
|
3557
|
-
listItem
|
|
3558
|
-
}) {
|
|
3559
|
-
if (!editor.selection)
|
|
3560
|
-
return !1;
|
|
3561
|
-
const selectedBlocks = [...Editor.nodes(editor, {
|
|
3562
|
-
at: editor.selection,
|
|
3563
|
-
match: (node) => editor.isTextBlock(node)
|
|
3564
|
-
})];
|
|
3565
|
-
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
3566
|
-
}
|
|
3567
|
-
function isStyleActive({
|
|
3568
|
-
editor,
|
|
3569
|
-
style
|
|
3570
|
-
}) {
|
|
3571
|
-
if (!editor.selection)
|
|
3572
|
-
return !1;
|
|
3573
|
-
const selectedBlocks = [...Editor.nodes(editor, {
|
|
3574
|
-
at: editor.selection,
|
|
3575
|
-
match: (node) => editor.isTextBlock(node)
|
|
3576
|
-
})];
|
|
3577
|
-
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
3578
|
-
}
|
|
3579
|
-
function slateRangeToSelection({
|
|
3580
|
-
schema,
|
|
3581
|
-
editor,
|
|
3582
|
-
range
|
|
3583
|
-
}) {
|
|
3584
|
-
const [anchorBlock] = getPointBlock({
|
|
3585
|
-
editor,
|
|
3586
|
-
point: range.anchor
|
|
3587
|
-
}), [focusBlock] = getPointBlock({
|
|
3588
|
-
editor,
|
|
3589
|
-
point: range.focus
|
|
3607
|
+
_type,
|
|
3608
|
+
_key,
|
|
3609
|
+
...props
|
|
3610
|
+
} = updatedBlockObject;
|
|
3611
|
+
Transforms.setNodes(operation.editor, {
|
|
3612
|
+
_type,
|
|
3613
|
+
_key,
|
|
3614
|
+
value: props
|
|
3615
|
+
}, {
|
|
3616
|
+
at: location
|
|
3590
3617
|
});
|
|
3591
|
-
|
|
3592
|
-
return null;
|
|
3593
|
-
const [anchorChild] = anchorBlock._type === schema.block.name ? getPointChild({
|
|
3594
|
-
editor,
|
|
3595
|
-
point: range.anchor
|
|
3596
|
-
}) : [void 0, void 0], [focusChild] = focusBlock._type === schema.block.name ? getPointChild({
|
|
3597
|
-
editor,
|
|
3598
|
-
point: range.focus
|
|
3599
|
-
}) : [void 0, void 0], selection = {
|
|
3600
|
-
anchor: {
|
|
3601
|
-
path: [{
|
|
3602
|
-
_key: anchorBlock._key
|
|
3603
|
-
}],
|
|
3604
|
-
offset: range.anchor.offset
|
|
3605
|
-
},
|
|
3606
|
-
focus: {
|
|
3607
|
-
path: [{
|
|
3608
|
-
_key: focusBlock._key
|
|
3609
|
-
}],
|
|
3610
|
-
offset: range.focus.offset
|
|
3611
|
-
},
|
|
3612
|
-
backward: Range.isBackward(range)
|
|
3613
|
-
};
|
|
3614
|
-
return anchorChild && (selection.anchor.path.push("children"), selection.anchor.path.push({
|
|
3615
|
-
_key: anchorChild._key
|
|
3616
|
-
})), focusChild && (selection.focus.path.push("children"), selection.focus.path.push({
|
|
3617
|
-
_key: focusChild._key
|
|
3618
|
-
})), selection;
|
|
3619
|
-
}
|
|
3620
|
-
const decoratorAddActionImplementation = ({
|
|
3618
|
+
}, decoratorAddOperationImplementation = ({
|
|
3621
3619
|
context,
|
|
3622
|
-
|
|
3620
|
+
operation
|
|
3623
3621
|
}) => {
|
|
3624
|
-
const editor =
|
|
3622
|
+
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 ? blockOffsetToSpanSelectionPoint({
|
|
3625
3623
|
context: {
|
|
3626
3624
|
...context,
|
|
3627
3625
|
value
|
|
3628
3626
|
},
|
|
3629
|
-
blockOffset:
|
|
3627
|
+
blockOffset: operation.at.anchor,
|
|
3630
3628
|
direction: "backward"
|
|
3631
|
-
}) : void 0, manualFocus =
|
|
3629
|
+
}) : void 0, manualFocus = operation.at?.focus ? blockOffsetToSpanSelectionPoint({
|
|
3632
3630
|
context: {
|
|
3633
3631
|
...context,
|
|
3634
3632
|
value
|
|
3635
3633
|
},
|
|
3636
|
-
blockOffset:
|
|
3634
|
+
blockOffset: operation.at.focus,
|
|
3637
3635
|
direction: "forward"
|
|
3638
3636
|
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
3639
3637
|
anchor: manualAnchor,
|
|
3640
3638
|
focus: manualFocus
|
|
3641
|
-
} : void 0, selection = manualSelection ? toSlateRange(manualSelection,
|
|
3639
|
+
} : void 0, selection = manualSelection ? toSlateRange(manualSelection, operation.editor) ?? editor.selection : editor.selection;
|
|
3642
3640
|
if (!selection)
|
|
3643
3641
|
return;
|
|
3644
3642
|
const editorSelection = slateRangeToSelection({
|
|
@@ -3741,82 +3739,82 @@ const decoratorAddActionImplementation = ({
|
|
|
3741
3739
|
...selection2
|
|
3742
3740
|
};
|
|
3743
3741
|
}
|
|
3744
|
-
},
|
|
3742
|
+
}, deleteOperationImplementation = ({
|
|
3745
3743
|
context,
|
|
3746
|
-
|
|
3744
|
+
operation
|
|
3747
3745
|
}) => {
|
|
3748
|
-
const range = toSlateRange(
|
|
3746
|
+
const range = toSlateRange(operation.at, operation.editor);
|
|
3749
3747
|
if (!range)
|
|
3750
|
-
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(
|
|
3748
|
+
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
|
|
3751
3749
|
if (Range.isCollapsed(range)) {
|
|
3752
3750
|
const [focusBlock] = getFocusBlock({
|
|
3753
3751
|
editor: {
|
|
3754
|
-
...
|
|
3752
|
+
...operation.editor,
|
|
3755
3753
|
selection: range
|
|
3756
3754
|
}
|
|
3757
3755
|
}), [focusChild] = getFocusChild({
|
|
3758
3756
|
editor: {
|
|
3759
|
-
...
|
|
3757
|
+
...operation.editor,
|
|
3760
3758
|
selection: range
|
|
3761
3759
|
}
|
|
3762
3760
|
});
|
|
3763
3761
|
if (focusBlock && focusBlock._type === context.schema.block.name && focusChild && focusChild._type === context.schema.span.name)
|
|
3764
3762
|
return;
|
|
3765
3763
|
}
|
|
3766
|
-
|
|
3764
|
+
operation.editor.delete({
|
|
3767
3765
|
at: range
|
|
3768
3766
|
});
|
|
3769
|
-
},
|
|
3770
|
-
|
|
3767
|
+
}, deleteBackwardOperationImplementation = ({
|
|
3768
|
+
operation
|
|
3771
3769
|
}) => {
|
|
3772
|
-
|
|
3773
|
-
},
|
|
3774
|
-
|
|
3770
|
+
deleteBackward(operation.editor, operation.unit);
|
|
3771
|
+
}, deleteBlockOperationImplementation = ({
|
|
3772
|
+
operation
|
|
3775
3773
|
}) => {
|
|
3776
3774
|
const range = toSlateRange({
|
|
3777
3775
|
anchor: {
|
|
3778
|
-
path:
|
|
3776
|
+
path: operation.at,
|
|
3779
3777
|
offset: 0
|
|
3780
3778
|
},
|
|
3781
3779
|
focus: {
|
|
3782
|
-
path:
|
|
3780
|
+
path: operation.at,
|
|
3783
3781
|
offset: 0
|
|
3784
3782
|
}
|
|
3785
|
-
},
|
|
3783
|
+
}, operation.editor);
|
|
3786
3784
|
if (!range) {
|
|
3787
3785
|
console.error("Unable to find Slate range from selection points");
|
|
3788
3786
|
return;
|
|
3789
3787
|
}
|
|
3790
|
-
Transforms.removeNodes(
|
|
3788
|
+
Transforms.removeNodes(operation.editor, {
|
|
3791
3789
|
at: range
|
|
3792
3790
|
});
|
|
3793
|
-
},
|
|
3794
|
-
|
|
3791
|
+
}, deleteForwardOperationImplementation = ({
|
|
3792
|
+
operation
|
|
3795
3793
|
}) => {
|
|
3796
|
-
|
|
3797
|
-
},
|
|
3794
|
+
deleteForward(operation.editor, operation.unit);
|
|
3795
|
+
}, insertInlineObjectOperationImplementation = ({
|
|
3798
3796
|
context,
|
|
3799
|
-
|
|
3797
|
+
operation
|
|
3800
3798
|
}) => {
|
|
3801
3799
|
const parsedInlineObject = parseInlineObject({
|
|
3802
3800
|
context,
|
|
3803
3801
|
inlineObject: {
|
|
3804
|
-
_type:
|
|
3805
|
-
...
|
|
3802
|
+
_type: operation.inlineObject.name,
|
|
3803
|
+
...operation.inlineObject.value ?? {}
|
|
3806
3804
|
},
|
|
3807
3805
|
options: {
|
|
3808
3806
|
refreshKeys: !1
|
|
3809
3807
|
}
|
|
3810
3808
|
});
|
|
3811
3809
|
if (!parsedInlineObject)
|
|
3812
|
-
throw new Error(`Failed to parse inline object ${JSON.stringify(
|
|
3813
|
-
if (!
|
|
3810
|
+
throw new Error(`Failed to parse inline object ${JSON.stringify(operation.inlineObject)}`);
|
|
3811
|
+
if (!operation.editor.selection) {
|
|
3814
3812
|
console.error("Unable to insert inline object without selection");
|
|
3815
3813
|
return;
|
|
3816
3814
|
}
|
|
3817
|
-
const [focusTextBlock] = Array.from(Editor.nodes(
|
|
3818
|
-
at:
|
|
3819
|
-
match: (node) =>
|
|
3815
|
+
const [focusTextBlock] = Array.from(Editor.nodes(operation.editor, {
|
|
3816
|
+
at: operation.editor.selection.focus.path,
|
|
3817
|
+
match: (node) => operation.editor.isTextBlock(node)
|
|
3820
3818
|
})).at(0) ?? [void 0, void 0];
|
|
3821
3819
|
if (!focusTextBlock) {
|
|
3822
3820
|
console.error("Unable to perform action without focus text block");
|
|
@@ -3833,49 +3831,49 @@ const decoratorAddActionImplementation = ({
|
|
|
3833
3831
|
console.error("Unable to insert inline object");
|
|
3834
3832
|
return;
|
|
3835
3833
|
}
|
|
3836
|
-
Transforms.insertNodes(
|
|
3837
|
-
},
|
|
3834
|
+
Transforms.insertNodes(operation.editor, child);
|
|
3835
|
+
}, insertSpanOperationImplementation = ({
|
|
3838
3836
|
context,
|
|
3839
|
-
|
|
3837
|
+
operation
|
|
3840
3838
|
}) => {
|
|
3841
|
-
if (!
|
|
3842
|
-
console.error("Unable to perform action without selection",
|
|
3839
|
+
if (!operation.editor.selection) {
|
|
3840
|
+
console.error("Unable to perform action without selection", operation);
|
|
3843
3841
|
return;
|
|
3844
3842
|
}
|
|
3845
|
-
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(
|
|
3846
|
-
at:
|
|
3847
|
-
match: (node) =>
|
|
3843
|
+
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(operation.editor, {
|
|
3844
|
+
at: operation.editor.selection.focus.path,
|
|
3845
|
+
match: (node) => operation.editor.isTextBlock(node)
|
|
3848
3846
|
}))[0] ?? [void 0, void 0];
|
|
3849
3847
|
if (!focusBlock || !focusBlockPath) {
|
|
3850
|
-
console.error("Unable to perform action without focus block",
|
|
3848
|
+
console.error("Unable to perform action without focus block", operation);
|
|
3851
3849
|
return;
|
|
3852
3850
|
}
|
|
3853
|
-
const markDefs = focusBlock.markDefs ?? [], annotations =
|
|
3851
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = operation.annotations ? operation.annotations.map((annotation) => ({
|
|
3854
3852
|
_type: annotation.name,
|
|
3855
3853
|
_key: context.keyGenerator(),
|
|
3856
3854
|
...annotation.value
|
|
3857
3855
|
})) : void 0;
|
|
3858
|
-
annotations && annotations.length > 0 && Transforms.setNodes(
|
|
3856
|
+
annotations && annotations.length > 0 && Transforms.setNodes(operation.editor, {
|
|
3859
3857
|
markDefs: [...markDefs, ...annotations]
|
|
3860
|
-
}), Transforms.insertNodes(
|
|
3858
|
+
}), Transforms.insertNodes(operation.editor, {
|
|
3861
3859
|
_type: "span",
|
|
3862
3860
|
_key: context.keyGenerator(),
|
|
3863
|
-
text:
|
|
3864
|
-
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...
|
|
3861
|
+
text: operation.text,
|
|
3862
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...operation.decorators ?? []]
|
|
3865
3863
|
});
|
|
3866
|
-
},
|
|
3864
|
+
}, insertBlockOperationImplementation = ({
|
|
3867
3865
|
context,
|
|
3868
|
-
|
|
3866
|
+
operation
|
|
3869
3867
|
}) => {
|
|
3870
3868
|
const parsedBlock = parseBlock({
|
|
3871
|
-
block:
|
|
3869
|
+
block: operation.block,
|
|
3872
3870
|
context,
|
|
3873
3871
|
options: {
|
|
3874
3872
|
refreshKeys: !1
|
|
3875
3873
|
}
|
|
3876
3874
|
});
|
|
3877
3875
|
if (!parsedBlock)
|
|
3878
|
-
throw new Error(`Failed to parse block ${JSON.stringify(
|
|
3876
|
+
throw new Error(`Failed to parse block ${JSON.stringify(operation.block)}`);
|
|
3879
3877
|
const fragment = toSlateValue([parsedBlock], {
|
|
3880
3878
|
schemaTypes: context.schema
|
|
3881
3879
|
})[0];
|
|
@@ -3883,9 +3881,9 @@ const decoratorAddActionImplementation = ({
|
|
|
3883
3881
|
throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
|
|
3884
3882
|
insertBlock({
|
|
3885
3883
|
block: fragment,
|
|
3886
|
-
placement:
|
|
3887
|
-
select:
|
|
3888
|
-
editor:
|
|
3884
|
+
placement: operation.placement,
|
|
3885
|
+
select: operation.select ?? "start",
|
|
3886
|
+
editor: operation.editor,
|
|
3889
3887
|
schema: context.schema
|
|
3890
3888
|
});
|
|
3891
3889
|
};
|
|
@@ -4037,218 +4035,229 @@ function insertBlock({
|
|
|
4037
4035
|
}
|
|
4038
4036
|
}
|
|
4039
4037
|
}
|
|
4040
|
-
const
|
|
4041
|
-
|
|
4038
|
+
const moveBackwardOperationImplementation = ({
|
|
4039
|
+
operation
|
|
4042
4040
|
}) => {
|
|
4043
|
-
Transforms.move(
|
|
4041
|
+
Transforms.move(operation.editor, {
|
|
4044
4042
|
unit: "character",
|
|
4045
|
-
distance:
|
|
4043
|
+
distance: operation.distance,
|
|
4046
4044
|
reverse: !0
|
|
4047
4045
|
});
|
|
4048
|
-
},
|
|
4049
|
-
|
|
4046
|
+
}, moveBlockOperationImplementation = ({
|
|
4047
|
+
operation
|
|
4050
4048
|
}) => {
|
|
4051
|
-
const at = [toSlatePath(
|
|
4052
|
-
Transforms.moveNodes(
|
|
4049
|
+
const at = [toSlatePath(operation.at, operation.editor)[0]], to = [toSlatePath(operation.to, operation.editor)[0]];
|
|
4050
|
+
Transforms.moveNodes(operation.editor, {
|
|
4053
4051
|
at,
|
|
4054
4052
|
to,
|
|
4055
4053
|
mode: "highest"
|
|
4056
4054
|
});
|
|
4057
|
-
},
|
|
4058
|
-
|
|
4055
|
+
}, moveForwardOperationImplementation = ({
|
|
4056
|
+
operation
|
|
4059
4057
|
}) => {
|
|
4060
|
-
Transforms.move(
|
|
4058
|
+
Transforms.move(operation.editor, {
|
|
4061
4059
|
unit: "character",
|
|
4062
|
-
distance:
|
|
4060
|
+
distance: operation.distance
|
|
4063
4061
|
});
|
|
4064
|
-
},
|
|
4065
|
-
|
|
4062
|
+
}, selectOperationImplementation = ({
|
|
4063
|
+
operation
|
|
4066
4064
|
}) => {
|
|
4067
|
-
const newSelection = toSlateRange(
|
|
4068
|
-
newSelection ? Transforms.select(
|
|
4069
|
-
},
|
|
4070
|
-
"annotation.add":
|
|
4071
|
-
"annotation.remove":
|
|
4072
|
-
"block.set":
|
|
4073
|
-
"block.unset":
|
|
4074
|
-
"decorator.add":
|
|
4075
|
-
"decorator.remove":
|
|
4076
|
-
delete:
|
|
4077
|
-
"delete.backward":
|
|
4078
|
-
"delete.forward":
|
|
4079
|
-
"delete.block":
|
|
4080
|
-
"history.redo":
|
|
4081
|
-
"history.undo":
|
|
4082
|
-
"insert.block":
|
|
4083
|
-
"insert.inline object":
|
|
4084
|
-
"insert.span":
|
|
4085
|
-
"insert.text":
|
|
4086
|
-
"move.backward":
|
|
4087
|
-
"move.block":
|
|
4088
|
-
"move.forward":
|
|
4089
|
-
select:
|
|
4065
|
+
const newSelection = toSlateRange(operation.at, operation.editor);
|
|
4066
|
+
newSelection ? Transforms.select(operation.editor, newSelection) : Transforms.deselect(operation.editor);
|
|
4067
|
+
}, behaviorOperationImplementations = {
|
|
4068
|
+
"annotation.add": addAnnotationOperationImplementation,
|
|
4069
|
+
"annotation.remove": removeAnnotationOperationImplementation,
|
|
4070
|
+
"block.set": blockSetOperationImplementation,
|
|
4071
|
+
"block.unset": blockUnsetOperationImplementation,
|
|
4072
|
+
"decorator.add": decoratorAddOperationImplementation,
|
|
4073
|
+
"decorator.remove": removeDecoratorOperationImplementation,
|
|
4074
|
+
delete: deleteOperationImplementation,
|
|
4075
|
+
"delete.backward": deleteBackwardOperationImplementation,
|
|
4076
|
+
"delete.forward": deleteForwardOperationImplementation,
|
|
4077
|
+
"delete.block": deleteBlockOperationImplementation,
|
|
4078
|
+
"history.redo": historyRedoOperationImplementation,
|
|
4079
|
+
"history.undo": historyUndoOperationImplementation,
|
|
4080
|
+
"insert.block": insertBlockOperationImplementation,
|
|
4081
|
+
"insert.inline object": insertInlineObjectOperationImplementation,
|
|
4082
|
+
"insert.span": insertSpanOperationImplementation,
|
|
4083
|
+
"insert.text": insertTextOperationImplementation,
|
|
4084
|
+
"move.backward": moveBackwardOperationImplementation,
|
|
4085
|
+
"move.block": moveBlockOperationImplementation,
|
|
4086
|
+
"move.forward": moveForwardOperationImplementation,
|
|
4087
|
+
select: selectOperationImplementation
|
|
4090
4088
|
};
|
|
4091
|
-
function
|
|
4089
|
+
function performOperation({
|
|
4092
4090
|
context,
|
|
4093
|
-
|
|
4091
|
+
operation
|
|
4094
4092
|
}) {
|
|
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
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4093
|
+
try {
|
|
4094
|
+
switch (operation.type) {
|
|
4095
|
+
case "annotation.add": {
|
|
4096
|
+
behaviorOperationImplementations["annotation.add"]({
|
|
4097
|
+
context,
|
|
4098
|
+
operation
|
|
4099
|
+
});
|
|
4100
|
+
break;
|
|
4101
|
+
}
|
|
4102
|
+
case "annotation.remove": {
|
|
4103
|
+
behaviorOperationImplementations["annotation.remove"]({
|
|
4104
|
+
context,
|
|
4105
|
+
operation
|
|
4106
|
+
});
|
|
4107
|
+
break;
|
|
4108
|
+
}
|
|
4109
|
+
case "block.set": {
|
|
4110
|
+
behaviorOperationImplementations["block.set"]({
|
|
4111
|
+
context,
|
|
4112
|
+
operation
|
|
4113
|
+
});
|
|
4114
|
+
break;
|
|
4115
|
+
}
|
|
4116
|
+
case "block.unset": {
|
|
4117
|
+
behaviorOperationImplementations["block.unset"]({
|
|
4118
|
+
context,
|
|
4119
|
+
operation
|
|
4120
|
+
});
|
|
4121
|
+
break;
|
|
4122
|
+
}
|
|
4123
|
+
case "decorator.add": {
|
|
4124
|
+
behaviorOperationImplementations["decorator.add"]({
|
|
4125
|
+
context,
|
|
4126
|
+
operation
|
|
4127
|
+
});
|
|
4128
|
+
break;
|
|
4129
|
+
}
|
|
4130
|
+
case "decorator.remove": {
|
|
4131
|
+
behaviorOperationImplementations["decorator.remove"]({
|
|
4132
|
+
context,
|
|
4133
|
+
operation
|
|
4134
|
+
});
|
|
4135
|
+
break;
|
|
4136
|
+
}
|
|
4137
|
+
case "delete": {
|
|
4138
|
+
behaviorOperationImplementations.delete({
|
|
4139
|
+
context,
|
|
4140
|
+
operation
|
|
4141
|
+
});
|
|
4142
|
+
break;
|
|
4143
|
+
}
|
|
4144
|
+
case "delete.backward": {
|
|
4145
|
+
behaviorOperationImplementations["delete.backward"]({
|
|
4146
|
+
context,
|
|
4147
|
+
operation
|
|
4148
|
+
});
|
|
4149
|
+
break;
|
|
4150
|
+
}
|
|
4151
|
+
case "delete.block": {
|
|
4152
|
+
behaviorOperationImplementations["delete.block"]({
|
|
4153
|
+
context,
|
|
4154
|
+
operation
|
|
4155
|
+
});
|
|
4156
|
+
break;
|
|
4157
|
+
}
|
|
4158
|
+
case "delete.forward": {
|
|
4159
|
+
behaviorOperationImplementations["delete.forward"]({
|
|
4160
|
+
context,
|
|
4161
|
+
operation
|
|
4162
|
+
});
|
|
4163
|
+
break;
|
|
4164
|
+
}
|
|
4165
|
+
case "history.redo": {
|
|
4166
|
+
behaviorOperationImplementations["history.redo"]({
|
|
4167
|
+
context,
|
|
4168
|
+
operation
|
|
4169
|
+
});
|
|
4170
|
+
break;
|
|
4171
|
+
}
|
|
4172
|
+
case "history.undo": {
|
|
4173
|
+
behaviorOperationImplementations["history.undo"]({
|
|
4174
|
+
context,
|
|
4175
|
+
operation
|
|
4176
|
+
});
|
|
4177
|
+
break;
|
|
4178
|
+
}
|
|
4179
|
+
case "insert.block": {
|
|
4180
|
+
behaviorOperationImplementations["insert.block"]({
|
|
4181
|
+
context,
|
|
4182
|
+
operation
|
|
4183
|
+
});
|
|
4184
|
+
break;
|
|
4185
|
+
}
|
|
4186
|
+
case "insert.inline object": {
|
|
4187
|
+
behaviorOperationImplementations["insert.inline object"]({
|
|
4188
|
+
context,
|
|
4189
|
+
operation
|
|
4190
|
+
});
|
|
4191
|
+
break;
|
|
4192
|
+
}
|
|
4193
|
+
case "insert.span": {
|
|
4194
|
+
behaviorOperationImplementations["insert.span"]({
|
|
4195
|
+
context,
|
|
4196
|
+
operation
|
|
4197
|
+
});
|
|
4198
|
+
break;
|
|
4199
|
+
}
|
|
4200
|
+
case "insert.text": {
|
|
4201
|
+
behaviorOperationImplementations["insert.text"]({
|
|
4202
|
+
context,
|
|
4203
|
+
operation
|
|
4204
|
+
});
|
|
4205
|
+
break;
|
|
4206
|
+
}
|
|
4207
|
+
case "move.backward": {
|
|
4208
|
+
behaviorOperationImplementations["move.backward"]({
|
|
4209
|
+
context,
|
|
4210
|
+
operation
|
|
4211
|
+
});
|
|
4212
|
+
break;
|
|
4213
|
+
}
|
|
4214
|
+
case "move.block": {
|
|
4215
|
+
behaviorOperationImplementations["move.block"]({
|
|
4216
|
+
context,
|
|
4217
|
+
operation
|
|
4218
|
+
});
|
|
4219
|
+
break;
|
|
4220
|
+
}
|
|
4221
|
+
case "move.forward": {
|
|
4222
|
+
behaviorOperationImplementations["move.forward"]({
|
|
4223
|
+
context,
|
|
4224
|
+
operation
|
|
4225
|
+
});
|
|
4226
|
+
break;
|
|
4227
|
+
}
|
|
4228
|
+
default: {
|
|
4229
|
+
behaviorOperationImplementations.select({
|
|
4230
|
+
context,
|
|
4231
|
+
operation
|
|
4232
|
+
});
|
|
4233
|
+
break;
|
|
4234
|
+
}
|
|
4235
4235
|
}
|
|
4236
|
+
} catch (error) {
|
|
4237
|
+
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4236
4238
|
}
|
|
4237
4239
|
}
|
|
4240
|
+
const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
|
|
4241
|
+
function withApplyingBehaviorOperations(editor, fn) {
|
|
4242
|
+
CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator()), Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
|
|
4243
|
+
}
|
|
4244
|
+
function getCurrentOperationId(editor) {
|
|
4245
|
+
return CURRENT_OPERATION_ID.get(editor);
|
|
4246
|
+
}
|
|
4247
|
+
function isApplyingBehaviorOperations(editor) {
|
|
4248
|
+
return getCurrentOperationId(editor) !== void 0;
|
|
4249
|
+
}
|
|
4238
4250
|
function createWithEventListeners(editorActor) {
|
|
4239
4251
|
return function(editor) {
|
|
4240
4252
|
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
4241
4253
|
return editor;
|
|
4242
4254
|
const {
|
|
4243
|
-
deleteBackward,
|
|
4244
|
-
deleteForward,
|
|
4245
|
-
insertBreak,
|
|
4246
4255
|
insertText,
|
|
4247
4256
|
select
|
|
4248
4257
|
} = editor;
|
|
4249
4258
|
return editor.deleteBackward = (unit) => {
|
|
4250
|
-
if (
|
|
4251
|
-
deleteBackward(
|
|
4259
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4260
|
+
console.error("Unexpected call to .deleteBackward(...)");
|
|
4252
4261
|
return;
|
|
4253
4262
|
}
|
|
4254
4263
|
editorActor.send({
|
|
@@ -4260,8 +4269,8 @@ function createWithEventListeners(editorActor) {
|
|
|
4260
4269
|
editor
|
|
4261
4270
|
});
|
|
4262
4271
|
}, editor.deleteForward = (unit) => {
|
|
4263
|
-
if (
|
|
4264
|
-
deleteForward(
|
|
4272
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4273
|
+
console.error("Unexpected call to .deleteForward(...)");
|
|
4265
4274
|
return;
|
|
4266
4275
|
}
|
|
4267
4276
|
editorActor.send({
|
|
@@ -4273,8 +4282,8 @@ function createWithEventListeners(editorActor) {
|
|
|
4273
4282
|
editor
|
|
4274
4283
|
});
|
|
4275
4284
|
}, editor.insertBreak = () => {
|
|
4276
|
-
if (
|
|
4277
|
-
insertBreak();
|
|
4285
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4286
|
+
console.error("Unexpected call to .insertBreak(...)");
|
|
4278
4287
|
return;
|
|
4279
4288
|
}
|
|
4280
4289
|
editorActor.send({
|
|
@@ -4285,8 +4294,10 @@ function createWithEventListeners(editorActor) {
|
|
|
4285
4294
|
editor
|
|
4286
4295
|
});
|
|
4287
4296
|
}, editor.insertData = (dataTransfer) => {
|
|
4288
|
-
if (
|
|
4289
|
-
|
|
4297
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4298
|
+
console.error("Unexpected call to .insertData(...)");
|
|
4299
|
+
return;
|
|
4300
|
+
}
|
|
4290
4301
|
editorActor.send({
|
|
4291
4302
|
type: "behavior event",
|
|
4292
4303
|
behaviorEvent: {
|
|
@@ -4298,13 +4309,13 @@ function createWithEventListeners(editorActor) {
|
|
|
4298
4309
|
editor
|
|
4299
4310
|
});
|
|
4300
4311
|
}, editor.insertSoftBreak = () => {
|
|
4301
|
-
if (
|
|
4302
|
-
|
|
4312
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4313
|
+
insertTextOperationImplementation({
|
|
4303
4314
|
context: {
|
|
4304
4315
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4305
4316
|
schema: editorActor.getSnapshot().context.schema
|
|
4306
4317
|
},
|
|
4307
|
-
|
|
4318
|
+
operation: {
|
|
4308
4319
|
text: `
|
|
4309
4320
|
`,
|
|
4310
4321
|
editor
|
|
@@ -4320,7 +4331,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4320
4331
|
editor
|
|
4321
4332
|
});
|
|
4322
4333
|
}, editor.insertText = (text, options) => {
|
|
4323
|
-
if (
|
|
4334
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4324
4335
|
insertText(text, options);
|
|
4325
4336
|
return;
|
|
4326
4337
|
}
|
|
@@ -4333,13 +4344,13 @@ function createWithEventListeners(editorActor) {
|
|
|
4333
4344
|
editor
|
|
4334
4345
|
});
|
|
4335
4346
|
}, editor.redo = () => {
|
|
4336
|
-
if (
|
|
4337
|
-
|
|
4347
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4348
|
+
performOperation({
|
|
4338
4349
|
context: {
|
|
4339
4350
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4340
4351
|
schema: editorActor.getSnapshot().context.schema
|
|
4341
4352
|
},
|
|
4342
|
-
|
|
4353
|
+
operation: {
|
|
4343
4354
|
type: "history.redo",
|
|
4344
4355
|
editor
|
|
4345
4356
|
}
|
|
@@ -4354,7 +4365,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4354
4365
|
editor
|
|
4355
4366
|
});
|
|
4356
4367
|
}, editor.select = (location) => {
|
|
4357
|
-
if (
|
|
4368
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4358
4369
|
select(location);
|
|
4359
4370
|
return;
|
|
4360
4371
|
}
|
|
@@ -4372,15 +4383,15 @@ function createWithEventListeners(editorActor) {
|
|
|
4372
4383
|
editor
|
|
4373
4384
|
});
|
|
4374
4385
|
}, editor.setFragmentData = () => {
|
|
4375
|
-
console.
|
|
4386
|
+
console.error("Unexpected call to .setFragmentData(...)");
|
|
4376
4387
|
}, editor.undo = () => {
|
|
4377
|
-
if (
|
|
4378
|
-
|
|
4388
|
+
if (isApplyingBehaviorOperations(editor)) {
|
|
4389
|
+
performOperation({
|
|
4379
4390
|
context: {
|
|
4380
4391
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4381
4392
|
schema: editorActor.getSnapshot().context.schema
|
|
4382
4393
|
},
|
|
4383
|
-
|
|
4394
|
+
operation: {
|
|
4384
4395
|
type: "history.undo",
|
|
4385
4396
|
editor
|
|
4386
4397
|
}
|
|
@@ -4784,9 +4795,14 @@ function createWithPatches({
|
|
|
4784
4795
|
Editor.withoutNormalizing(editor, () => {
|
|
4785
4796
|
withoutPatching(editor, () => {
|
|
4786
4797
|
withoutSaving(editor, () => {
|
|
4787
|
-
|
|
4788
|
-
debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`)
|
|
4789
|
-
|
|
4798
|
+
for (const patch of patches) {
|
|
4799
|
+
debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
4800
|
+
try {
|
|
4801
|
+
changed = applyPatch(editor, patch);
|
|
4802
|
+
} catch (error) {
|
|
4803
|
+
console.error(`Applying patch ${JSON.stringify(patch)} failed due to: ${error.message}`);
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4790
4806
|
});
|
|
4791
4807
|
});
|
|
4792
4808
|
}), changed && (editor.normalize(), editor.onChange());
|
|
@@ -4848,7 +4864,7 @@ function createWithPatches({
|
|
|
4848
4864
|
...patch,
|
|
4849
4865
|
origin: "local"
|
|
4850
4866
|
},
|
|
4851
|
-
|
|
4867
|
+
operationId: getCurrentOperationId(editor),
|
|
4852
4868
|
value: fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
|
|
4853
4869
|
});
|
|
4854
4870
|
return editor;
|
|
@@ -5590,12 +5606,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5590
5606
|
addAnnotation: (type, value) => {
|
|
5591
5607
|
let paths;
|
|
5592
5608
|
return Editor.withoutNormalizing(editor, () => {
|
|
5593
|
-
paths =
|
|
5609
|
+
paths = addAnnotationOperationImplementation({
|
|
5594
5610
|
context: {
|
|
5595
5611
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5596
5612
|
schema: types
|
|
5597
5613
|
},
|
|
5598
|
-
|
|
5614
|
+
operation: {
|
|
5599
5615
|
annotation: {
|
|
5600
5616
|
name: type.name,
|
|
5601
5617
|
value: value ?? {}
|
|
@@ -5727,19 +5743,29 @@ function createInternalEditor(editorActor) {
|
|
|
5727
5743
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
5728
5744
|
slateEditorInstance: slateEditor.instance
|
|
5729
5745
|
}),
|
|
5730
|
-
registerBehavior: (
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
})
|
|
5738
|
-
|
|
5746
|
+
registerBehavior: (behaviorConfig) => {
|
|
5747
|
+
const priority = createEditorPriority({
|
|
5748
|
+
name: "custom",
|
|
5749
|
+
reference: {
|
|
5750
|
+
priority: corePriority,
|
|
5751
|
+
importance: "higher"
|
|
5752
|
+
}
|
|
5753
|
+
}), behaviorConfigWithPriority = {
|
|
5754
|
+
...behaviorConfig,
|
|
5755
|
+
priority
|
|
5756
|
+
};
|
|
5757
|
+
return editorActor.send({
|
|
5758
|
+
type: "add behavior",
|
|
5759
|
+
behaviorConfig: behaviorConfigWithPriority
|
|
5760
|
+
}), () => {
|
|
5761
|
+
editorActor.send({
|
|
5762
|
+
type: "remove behavior",
|
|
5763
|
+
behaviorConfig: behaviorConfigWithPriority
|
|
5764
|
+
});
|
|
5765
|
+
};
|
|
5766
|
+
},
|
|
5739
5767
|
send: (event) => {
|
|
5740
5768
|
switch (event.type) {
|
|
5741
|
-
case "add behavior":
|
|
5742
|
-
case "remove behavior":
|
|
5743
5769
|
case "update key generator":
|
|
5744
5770
|
case "update readOnly":
|
|
5745
5771
|
case "patches":
|
|
@@ -6483,7 +6509,10 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6483
6509
|
clearListOnEnter,
|
|
6484
6510
|
indentListOnTab,
|
|
6485
6511
|
unindentListOnShiftTab
|
|
6486
|
-
},
|
|
6512
|
+
}, coreBehaviorsConfig = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks].map((behavior) => ({
|
|
6513
|
+
behavior,
|
|
6514
|
+
priority: corePriority
|
|
6515
|
+
})), abstractAnnotationBehaviors = [defineBehavior({
|
|
6487
6516
|
on: "annotation.toggle",
|
|
6488
6517
|
guard: ({
|
|
6489
6518
|
snapshot,
|
|
@@ -6679,7 +6708,24 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6679
6708
|
text: `
|
|
6680
6709
|
`
|
|
6681
6710
|
})]]
|
|
6682
|
-
})],
|
|
6711
|
+
})], keyIs = {
|
|
6712
|
+
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
6713
|
+
}, abstractKeyboardBehaviors = [
|
|
6714
|
+
/**
|
|
6715
|
+
* On WebKit, Shift+Enter results in an `insertParagraph` input event rather
|
|
6716
|
+
* than an `insertLineBreak` input event. This Behavior makes sure we catch
|
|
6717
|
+
* that `keyboard.keydown` event beforehand and raise an `insert.soft break` manually.
|
|
6718
|
+
*/
|
|
6719
|
+
defineBehavior({
|
|
6720
|
+
on: "keyboard.keydown",
|
|
6721
|
+
guard: ({
|
|
6722
|
+
event
|
|
6723
|
+
}) => keyIs.lineBreak(event.originEvent),
|
|
6724
|
+
actions: [() => [raise({
|
|
6725
|
+
type: "insert.soft break"
|
|
6726
|
+
})]]
|
|
6727
|
+
})
|
|
6728
|
+
], abstractListItemBehaviors = [defineBehavior({
|
|
6683
6729
|
on: "list item.add",
|
|
6684
6730
|
guard: ({
|
|
6685
6731
|
snapshot
|
|
@@ -7005,17 +7051,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
7005
7051
|
type: "style.add",
|
|
7006
7052
|
style: event.style
|
|
7007
7053
|
})]]
|
|
7008
|
-
})],
|
|
7009
|
-
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
7010
|
-
}, raiseInsertSoftBreak = defineBehavior({
|
|
7011
|
-
on: "keyboard.keydown",
|
|
7012
|
-
guard: ({
|
|
7013
|
-
event
|
|
7014
|
-
}) => keyIs.lineBreak(event.originEvent),
|
|
7015
|
-
actions: [() => [raise({
|
|
7016
|
-
type: "insert.soft break"
|
|
7017
|
-
})]]
|
|
7018
|
-
}), raiseDeserializationSuccessOrFailure = defineBehavior({
|
|
7054
|
+
})], raiseDeserializationSuccessOrFailure = defineBehavior({
|
|
7019
7055
|
on: "deserialize",
|
|
7020
7056
|
guard: ({
|
|
7021
7057
|
snapshot,
|
|
@@ -7075,7 +7111,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
7075
7111
|
...serializeEvent,
|
|
7076
7112
|
originEvent: event.originEvent
|
|
7077
7113
|
}))]
|
|
7078
|
-
}),
|
|
7114
|
+
}), abstractBehaviors = [
|
|
7079
7115
|
defineBehavior({
|
|
7080
7116
|
on: "clipboard.copy",
|
|
7081
7117
|
guard: ({
|
|
@@ -7350,14 +7386,14 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
7350
7386
|
...abstractDecoratorBehaviors,
|
|
7351
7387
|
...abstractDeleteBehaviors,
|
|
7352
7388
|
...abstractInsertBehaviors,
|
|
7389
|
+
...abstractKeyboardBehaviors,
|
|
7353
7390
|
...abstractListItemBehaviors,
|
|
7354
7391
|
...abstractMoveBehaviors,
|
|
7355
7392
|
...abstractStyleBehaviors,
|
|
7356
7393
|
...abstractSelectBehaviors,
|
|
7357
7394
|
...abstractSplitBehaviors,
|
|
7358
7395
|
raiseDeserializationSuccessOrFailure,
|
|
7359
|
-
raiseSerializationSuccessOrFailure
|
|
7360
|
-
raiseInsertSoftBreak
|
|
7396
|
+
raiseSerializationSuccessOrFailure
|
|
7361
7397
|
];
|
|
7362
7398
|
function isSyntheticBehaviorEvent(event) {
|
|
7363
7399
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
@@ -7389,28 +7425,24 @@ function performEvent({
|
|
|
7389
7425
|
nativeEvent
|
|
7390
7426
|
}) {
|
|
7391
7427
|
debug$2(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
7392
|
-
const eventBehaviors = [...remainingEventBehaviors, ...
|
|
7428
|
+
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
7393
7429
|
if (behavior.on === "*")
|
|
7394
7430
|
return !0;
|
|
7395
7431
|
const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
|
|
7396
7432
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
7397
7433
|
});
|
|
7398
7434
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
7399
|
-
nativeEvent?.preventDefault(),
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
});
|
|
7411
|
-
} catch (error) {
|
|
7412
|
-
console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
|
|
7413
|
-
}
|
|
7435
|
+
nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
7436
|
+
debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
7437
|
+
context: {
|
|
7438
|
+
keyGenerator,
|
|
7439
|
+
schema
|
|
7440
|
+
},
|
|
7441
|
+
operation: {
|
|
7442
|
+
...event,
|
|
7443
|
+
editor
|
|
7444
|
+
}
|
|
7445
|
+
});
|
|
7414
7446
|
}), editor.onChange();
|
|
7415
7447
|
return;
|
|
7416
7448
|
}
|
|
@@ -7543,23 +7575,62 @@ function performEvent({
|
|
|
7543
7575
|
break;
|
|
7544
7576
|
}
|
|
7545
7577
|
}
|
|
7546
|
-
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(),
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
});
|
|
7558
|
-
} catch (error) {
|
|
7559
|
-
console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
|
|
7560
|
-
}
|
|
7578
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
7579
|
+
debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
7580
|
+
context: {
|
|
7581
|
+
keyGenerator,
|
|
7582
|
+
schema
|
|
7583
|
+
},
|
|
7584
|
+
operation: {
|
|
7585
|
+
...event,
|
|
7586
|
+
editor
|
|
7587
|
+
}
|
|
7588
|
+
});
|
|
7561
7589
|
}), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
|
|
7562
7590
|
}
|
|
7591
|
+
function sortByPriority(items) {
|
|
7592
|
+
if (items.length === 0)
|
|
7593
|
+
return [];
|
|
7594
|
+
const itemsWithPriority = items.filter((item) => item.priority !== void 0), itemsWithoutPriority = items.filter((item) => item.priority === void 0);
|
|
7595
|
+
if (itemsWithPriority.length === 0)
|
|
7596
|
+
return items;
|
|
7597
|
+
const itemsByPriorityId = new Map(itemsWithPriority.map((item) => [item.priority.id, item])), graph = /* @__PURE__ */ new Map(), inDegree = /* @__PURE__ */ new Map();
|
|
7598
|
+
function ensureNode(id) {
|
|
7599
|
+
graph.has(id) || (graph.set(id, /* @__PURE__ */ new Set()), inDegree.set(id, 0));
|
|
7600
|
+
}
|
|
7601
|
+
for (const item of itemsWithPriority) {
|
|
7602
|
+
const id = item.priority.id;
|
|
7603
|
+
ensureNode(id);
|
|
7604
|
+
}
|
|
7605
|
+
function addEdge(fromId, toId) {
|
|
7606
|
+
!graph.has(fromId) || !graph.has(toId) || (graph.get(fromId)?.add(toId), inDegree.set(toId, (inDegree.get(toId) ?? 0) + 1));
|
|
7607
|
+
}
|
|
7608
|
+
for (const item of itemsWithPriority) {
|
|
7609
|
+
const id = item.priority.id, visited = /* @__PURE__ */ new Set();
|
|
7610
|
+
let ref = item.priority.reference;
|
|
7611
|
+
for (; ref; ) {
|
|
7612
|
+
const refId = ref.priority.id;
|
|
7613
|
+
if (ensureNode(refId), visited.has(refId))
|
|
7614
|
+
throw new Error("Circular dependency detected in priorities");
|
|
7615
|
+
visited.add(refId), ref.importance === "higher" ? addEdge(id, refId) : addEdge(refId, id), ref = ref.priority.reference;
|
|
7616
|
+
}
|
|
7617
|
+
}
|
|
7618
|
+
const queue = [];
|
|
7619
|
+
for (const [id, degree] of inDegree)
|
|
7620
|
+
degree === 0 && queue.push(id);
|
|
7621
|
+
const result = [];
|
|
7622
|
+
for (; queue.length > 0; ) {
|
|
7623
|
+
const currentId = queue.shift(), currentItem = itemsByPriorityId.get(currentId);
|
|
7624
|
+
currentItem && result.push(currentItem);
|
|
7625
|
+
for (const neighborId of graph.get(currentId) ?? []) {
|
|
7626
|
+
const newDegree = (inDegree.get(neighborId) ?? 0) - 1;
|
|
7627
|
+
inDegree.set(neighborId, newDegree), newDegree === 0 && queue.push(neighborId);
|
|
7628
|
+
}
|
|
7629
|
+
}
|
|
7630
|
+
for (const item of itemsWithPriority)
|
|
7631
|
+
result.includes(item) || result.push(item);
|
|
7632
|
+
return [...result, ...itemsWithoutPriority];
|
|
7633
|
+
}
|
|
7563
7634
|
function createEditorSnapshot({
|
|
7564
7635
|
converters,
|
|
7565
7636
|
editor,
|
|
@@ -7606,13 +7677,13 @@ const editorMachine = setup({
|
|
|
7606
7677
|
behaviors: ({
|
|
7607
7678
|
context,
|
|
7608
7679
|
event
|
|
7609
|
-
}) => (assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.
|
|
7680
|
+
}) => (assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.behaviorConfig]))
|
|
7610
7681
|
}),
|
|
7611
7682
|
"remove behavior from context": assign({
|
|
7612
7683
|
behaviors: ({
|
|
7613
7684
|
context,
|
|
7614
7685
|
event
|
|
7615
|
-
}) => (assertEvent(event, "remove behavior"), context.behaviors.delete(event.
|
|
7686
|
+
}) => (assertEvent(event, "remove behavior"), context.behaviors.delete(event.behaviorConfig), /* @__PURE__ */ new Set([...context.behaviors]))
|
|
7616
7687
|
}),
|
|
7617
7688
|
"assign schema": assign({
|
|
7618
7689
|
schema: ({
|
|
@@ -7706,10 +7777,11 @@ const editorMachine = setup({
|
|
|
7706
7777
|
}) => {
|
|
7707
7778
|
assertEvent(event, ["behavior event"]);
|
|
7708
7779
|
try {
|
|
7780
|
+
const behaviors = sortByPriority([...context.behaviors.values(), ...coreBehaviorsConfig]).map((config) => config.behavior);
|
|
7709
7781
|
performEvent({
|
|
7710
7782
|
mode: "raise",
|
|
7711
|
-
behaviors
|
|
7712
|
-
remainingEventBehaviors:
|
|
7783
|
+
behaviors,
|
|
7784
|
+
remainingEventBehaviors: behaviors,
|
|
7713
7785
|
event: event.behaviorEvent,
|
|
7714
7786
|
editor: event.editor,
|
|
7715
7787
|
keyGenerator: context.keyGenerator,
|
|
@@ -7742,7 +7814,7 @@ const editorMachine = setup({
|
|
|
7742
7814
|
context: ({
|
|
7743
7815
|
input
|
|
7744
7816
|
}) => ({
|
|
7745
|
-
behaviors: /* @__PURE__ */ new Set([
|
|
7817
|
+
behaviors: /* @__PURE__ */ new Set([]),
|
|
7746
7818
|
converters: new Set(input.converters ?? []),
|
|
7747
7819
|
getLegacySchema: input.getLegacySchema,
|
|
7748
7820
|
keyGenerator: input.keyGenerator,
|
|
@@ -8661,7 +8733,8 @@ export {
|
|
|
8661
8733
|
EditorProvider,
|
|
8662
8734
|
KEY_TO_VALUE_ELEMENT,
|
|
8663
8735
|
PortableTextEditor,
|
|
8664
|
-
|
|
8736
|
+
corePriority,
|
|
8737
|
+
createEditorPriority,
|
|
8665
8738
|
debugWithName,
|
|
8666
8739
|
defaultKeyGenerator,
|
|
8667
8740
|
defineSchema,
|