@portabletext/editor 1.49.4 → 1.49.5
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/behaviors/index.d.cts +24 -0
- package/lib/behaviors/index.d.ts +24 -0
- package/lib/index.cjs +274 -231
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +24 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +275 -232
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +24 -0
- package/lib/plugins/index.d.ts +24 -0
- package/lib/selectors/index.d.cts +24 -0
- package/lib/selectors/index.d.ts +24 -0
- package/lib/utils/index.d.cts +24 -0
- package/lib/utils/index.d.ts +24 -0
- package/package.json +1 -1
- package/src/editor/Editable.tsx +0 -2
- package/src/editor/editor-machine.ts +131 -1
- package/src/editor/sync-machine.ts +132 -153
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { useSelector, useActorRef } from "@xstate/react";
|
|
|
7
7
|
import noop from "lodash/noop.js";
|
|
8
8
|
import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Operation, Transforms, deleteBackward, deleteForward, createEditor } from "slate";
|
|
9
9
|
import { useSlateStatic, useSelected, withReact, ReactEditor, Slate, useSlate, Editable } from "slate-react";
|
|
10
|
-
import debug$
|
|
10
|
+
import debug$i from "debug";
|
|
11
11
|
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-equal-selection-points.js";
|
|
12
12
|
import { getBlockStartPoint, isKeyedSegment as isKeyedSegment$1, parseInlineObject, parseTextBlock, parseBlockObject, parseBlock, sliceBlocks, isTextBlock, parseAnnotation, blockOffsetToSpanSelectionPoint, isSpan$1 as isSpan, isListBlock, getTextBlockText, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
|
|
13
13
|
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, getFocusBlock as getFocusBlock$1, getFocusBlockObject, getPreviousBlock, getNextBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock } from "./_chunks-es/selector.is-selection-expanded.js";
|
|
@@ -59,10 +59,10 @@ function getCompoundClientRect(nodes) {
|
|
|
59
59
|
return new DOMRect(left, top, right - left, bottom - top);
|
|
60
60
|
}
|
|
61
61
|
const rootName = "sanity-pte:";
|
|
62
|
-
debug$
|
|
62
|
+
debug$i(rootName);
|
|
63
63
|
function debugWithName(name) {
|
|
64
64
|
const namespace = `${rootName}${name}`;
|
|
65
|
-
return debug$
|
|
65
|
+
return debug$i && debug$i.enabled(namespace) ? debug$i(namespace) : debug$i(rootName);
|
|
66
66
|
}
|
|
67
67
|
function getDragSelection({
|
|
68
68
|
eventSelection,
|
|
@@ -2533,7 +2533,7 @@ function withUndoStep(editor, fn) {
|
|
|
2533
2533
|
function getCurrentUndoStepId(editor) {
|
|
2534
2534
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
2535
2535
|
}
|
|
2536
|
-
const debug$
|
|
2536
|
+
const debug$h = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2537
2537
|
const state = SAVING.get(editor);
|
|
2538
2538
|
return state === void 0 ? !0 : state;
|
|
2539
2539
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -2546,7 +2546,7 @@ function createWithUndoRedo(options) {
|
|
|
2546
2546
|
const remotePatches = getRemotePatches(editor);
|
|
2547
2547
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
2548
2548
|
options.subscriptions.push(() => {
|
|
2549
|
-
debug$
|
|
2549
|
+
debug$h("Subscribing to patches");
|
|
2550
2550
|
const sub = editorActor.on("patches", ({
|
|
2551
2551
|
patches,
|
|
2552
2552
|
snapshot
|
|
@@ -2555,7 +2555,7 @@ function createWithUndoRedo(options) {
|
|
|
2555
2555
|
patches.forEach((patch) => {
|
|
2556
2556
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2557
2557
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2558
|
-
debug$
|
|
2558
|
+
debug$h("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2559
2559
|
undos: [],
|
|
2560
2560
|
redos: []
|
|
2561
2561
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -2571,7 +2571,7 @@ function createWithUndoRedo(options) {
|
|
|
2571
2571
|
}), previousSnapshot = snapshot;
|
|
2572
2572
|
});
|
|
2573
2573
|
return () => {
|
|
2574
|
-
debug$
|
|
2574
|
+
debug$h("Unsubscribing to patches"), sub.unsubscribe();
|
|
2575
2575
|
};
|
|
2576
2576
|
}), editor.history = {
|
|
2577
2577
|
undos: [],
|
|
@@ -2610,7 +2610,7 @@ function createWithUndoRedo(options) {
|
|
|
2610
2610
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
2611
2611
|
timestamp: /* @__PURE__ */ new Date()
|
|
2612
2612
|
};
|
|
2613
|
-
undos.push(newStep), debug$
|
|
2613
|
+
undos.push(newStep), debug$h("Created new undo step", step);
|
|
2614
2614
|
}
|
|
2615
2615
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
2616
2616
|
undos.shift();
|
|
@@ -2628,7 +2628,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2628
2628
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2629
2629
|
if (undos.length > 0) {
|
|
2630
2630
|
const step = undos[undos.length - 1];
|
|
2631
|
-
if (debug$
|
|
2631
|
+
if (debug$h("Undoing", step), step.operations.length > 0) {
|
|
2632
2632
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2633
2633
|
let transformedOperations = step.operations;
|
|
2634
2634
|
otherPatches.forEach((item) => {
|
|
@@ -2646,7 +2646,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2646
2646
|
});
|
|
2647
2647
|
});
|
|
2648
2648
|
} catch (err) {
|
|
2649
|
-
debug$
|
|
2649
|
+
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2650
2650
|
undos: [],
|
|
2651
2651
|
redos: []
|
|
2652
2652
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2663,7 +2663,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2663
2663
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2664
2664
|
if (redos.length > 0) {
|
|
2665
2665
|
const step = redos[redos.length - 1];
|
|
2666
|
-
if (debug$
|
|
2666
|
+
if (debug$h("Redoing", step), step.operations.length > 0) {
|
|
2667
2667
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2668
2668
|
let transformedOperations = step.operations;
|
|
2669
2669
|
otherPatches.forEach((item) => {
|
|
@@ -2680,7 +2680,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2680
2680
|
});
|
|
2681
2681
|
});
|
|
2682
2682
|
} catch (err) {
|
|
2683
|
-
debug$
|
|
2683
|
+
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2684
2684
|
undos: [],
|
|
2685
2685
|
redos: []
|
|
2686
2686
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2698,16 +2698,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2698
2698
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
2699
2699
|
_key: blk._key
|
|
2700
2700
|
}, patch.path[0]));
|
|
2701
|
-
return debug$
|
|
2701
|
+
return debug$h(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2702
2702
|
}
|
|
2703
2703
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2704
2704
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
2705
2705
|
_key: blk._key
|
|
2706
2706
|
}, patch.path[0]));
|
|
2707
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2707
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$h("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2708
2708
|
}
|
|
2709
2709
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2710
|
-
return debug$
|
|
2710
|
+
return debug$h(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2711
2711
|
if (patch.type === "diffMatchPatch") {
|
|
2712
2712
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2713
2713
|
return !operationTargetBlock || !isEqual({
|
|
@@ -2794,7 +2794,7 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
2794
2794
|
let block;
|
|
2795
2795
|
return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
|
|
2796
2796
|
}
|
|
2797
|
-
const debug$
|
|
2797
|
+
const debug$g = debugWithName("sync machine"), syncValueCallback = ({
|
|
2798
2798
|
sendBack,
|
|
2799
2799
|
input
|
|
2800
2800
|
}) => {
|
|
@@ -2849,13 +2849,17 @@ const debug$f = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2849
2849
|
context
|
|
2850
2850
|
}) => {
|
|
2851
2851
|
const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
|
|
2852
|
-
return debug$
|
|
2852
|
+
return debug$g("isBusy", {
|
|
2853
2853
|
isBusy,
|
|
2854
2854
|
editable,
|
|
2855
2855
|
isProcessingLocalChanges,
|
|
2856
2856
|
isChanging
|
|
2857
2857
|
}), isBusy;
|
|
2858
2858
|
},
|
|
2859
|
+
"is new value": ({
|
|
2860
|
+
context,
|
|
2861
|
+
event
|
|
2862
|
+
}) => event.type === "update value" && context.previousValue !== event.value,
|
|
2859
2863
|
"value changed while syncing": ({
|
|
2860
2864
|
context,
|
|
2861
2865
|
event
|
|
@@ -2896,139 +2900,115 @@ const debug$f = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2896
2900
|
actions: ["assign readOnly"]
|
|
2897
2901
|
}
|
|
2898
2902
|
},
|
|
2899
|
-
|
|
2903
|
+
initial: "idle",
|
|
2900
2904
|
states: {
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2905
|
+
idle: {
|
|
2906
|
+
entry: [() => {
|
|
2907
|
+
debug$g("entry: syncing->idle");
|
|
2908
|
+
}],
|
|
2909
|
+
exit: [() => {
|
|
2910
|
+
debug$g("exit: syncing->idle");
|
|
2911
|
+
}],
|
|
2912
|
+
on: {
|
|
2913
|
+
"update value": [{
|
|
2914
|
+
guard: and(["is busy", "is new value"]),
|
|
2915
|
+
target: "busy",
|
|
2916
|
+
actions: ["assign pending value"]
|
|
2917
|
+
}, {
|
|
2918
|
+
guard: "is new value",
|
|
2919
|
+
target: "syncing",
|
|
2920
|
+
actions: ["assign pending value"]
|
|
2921
|
+
}, {
|
|
2922
|
+
guard: not("initial value synced"),
|
|
2923
|
+
actions: [() => {
|
|
2924
|
+
debug$g("no new value \u2013 setting initial value as synced");
|
|
2925
|
+
}, "assign initial value synced", "emit done syncing value"]
|
|
2926
|
+
}, {
|
|
2927
|
+
actions: [() => {
|
|
2928
|
+
debug$g("no new value and initial value already synced");
|
|
2929
|
+
}]
|
|
2930
|
+
}]
|
|
2931
|
+
}
|
|
2932
|
+
},
|
|
2933
|
+
busy: {
|
|
2934
|
+
entry: [() => {
|
|
2935
|
+
debug$g("entry: syncing->busy");
|
|
2936
|
+
}],
|
|
2937
|
+
exit: [() => {
|
|
2938
|
+
debug$g("exit: syncing->busy");
|
|
2939
|
+
}],
|
|
2940
|
+
after: {
|
|
2941
|
+
1e3: [{
|
|
2942
|
+
guard: "is busy",
|
|
2943
|
+
target: ".",
|
|
2944
|
+
reenter: !0,
|
|
2945
|
+
actions: [() => {
|
|
2946
|
+
debug$g("reenter: syncing->busy");
|
|
2947
|
+
}]
|
|
2948
|
+
}, {
|
|
2949
|
+
target: "syncing"
|
|
2950
|
+
}]
|
|
2951
|
+
},
|
|
2952
|
+
on: {
|
|
2953
|
+
"update value": [{
|
|
2954
|
+
guard: "is new value",
|
|
2955
|
+
actions: ["assign pending value"]
|
|
2956
|
+
}]
|
|
2925
2957
|
}
|
|
2926
2958
|
},
|
|
2927
2959
|
syncing: {
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
}]
|
|
2946
|
-
}
|
|
2947
|
-
},
|
|
2948
|
-
busy: {
|
|
2949
|
-
entry: [() => {
|
|
2950
|
-
debug$f("entry: syncing->busy");
|
|
2951
|
-
}],
|
|
2952
|
-
exit: [() => {
|
|
2953
|
-
debug$f("exit: syncing->busy");
|
|
2954
|
-
}],
|
|
2955
|
-
after: {
|
|
2956
|
-
1e3: [{
|
|
2957
|
-
guard: "is busy",
|
|
2958
|
-
target: ".",
|
|
2959
|
-
reenter: !0,
|
|
2960
|
-
actions: [() => {
|
|
2961
|
-
debug$f("reenter: syncing->busy");
|
|
2962
|
-
}]
|
|
2963
|
-
}, {
|
|
2964
|
-
target: "syncing"
|
|
2965
|
-
}]
|
|
2960
|
+
entry: [() => {
|
|
2961
|
+
debug$g("entry: syncing->syncing");
|
|
2962
|
+
}, "emit syncing value"],
|
|
2963
|
+
exit: [() => {
|
|
2964
|
+
debug$g("exit: syncing->syncing");
|
|
2965
|
+
}, "emit done syncing value"],
|
|
2966
|
+
invoke: {
|
|
2967
|
+
src: "sync value",
|
|
2968
|
+
id: "sync value",
|
|
2969
|
+
input: ({
|
|
2970
|
+
context
|
|
2971
|
+
}) => ({
|
|
2972
|
+
context: {
|
|
2973
|
+
keyGenerator: context.keyGenerator,
|
|
2974
|
+
previousValue: context.previousValue,
|
|
2975
|
+
readOnly: context.readOnly,
|
|
2976
|
+
schema: context.schema
|
|
2966
2977
|
},
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2978
|
+
slateEditor: context.slateEditor,
|
|
2979
|
+
streamBlocks: !context.initialValueSynced,
|
|
2980
|
+
value: context.pendingValue
|
|
2981
|
+
})
|
|
2982
|
+
},
|
|
2983
|
+
on: {
|
|
2984
|
+
"update value": {
|
|
2985
|
+
guard: "is new value",
|
|
2986
|
+
actions: ["assign pending value"]
|
|
2972
2987
|
},
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
}
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
slateEditor: context.slateEditor,
|
|
2998
|
-
streamBlocks: !context.initialValueSynced,
|
|
2999
|
-
value: context.pendingValue
|
|
3000
|
-
})
|
|
3001
|
-
},
|
|
3002
|
-
on: {
|
|
3003
|
-
"update value": {
|
|
3004
|
-
actions: ["assign pending value"]
|
|
3005
|
-
},
|
|
3006
|
-
patch: {
|
|
3007
|
-
actions: [emit(({
|
|
3008
|
-
event
|
|
3009
|
-
}) => event)]
|
|
3010
|
-
},
|
|
3011
|
-
"invalid value": {
|
|
3012
|
-
actions: [emit(({
|
|
3013
|
-
event
|
|
3014
|
-
}) => event)]
|
|
3015
|
-
},
|
|
3016
|
-
"value changed": {
|
|
3017
|
-
actions: [emit(({
|
|
3018
|
-
event
|
|
3019
|
-
}) => event)]
|
|
3020
|
-
},
|
|
3021
|
-
"done syncing": [{
|
|
3022
|
-
guard: "value changed while syncing",
|
|
3023
|
-
actions: ["assign previous value", "assign initial value synced"],
|
|
3024
|
-
target: "syncing",
|
|
3025
|
-
reenter: !0
|
|
3026
|
-
}, {
|
|
3027
|
-
target: "idle",
|
|
3028
|
-
actions: ["clear pending value", "assign previous value", "assign initial value synced"]
|
|
3029
|
-
}]
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
2988
|
+
patch: {
|
|
2989
|
+
actions: [emit(({
|
|
2990
|
+
event
|
|
2991
|
+
}) => event)]
|
|
2992
|
+
},
|
|
2993
|
+
"invalid value": {
|
|
2994
|
+
actions: [emit(({
|
|
2995
|
+
event
|
|
2996
|
+
}) => event)]
|
|
2997
|
+
},
|
|
2998
|
+
"value changed": {
|
|
2999
|
+
actions: [emit(({
|
|
3000
|
+
event
|
|
3001
|
+
}) => event)]
|
|
3002
|
+
},
|
|
3003
|
+
"done syncing": [{
|
|
3004
|
+
guard: "value changed while syncing",
|
|
3005
|
+
actions: ["assign previous value", "assign initial value synced"],
|
|
3006
|
+
target: "syncing",
|
|
3007
|
+
reenter: !0
|
|
3008
|
+
}, {
|
|
3009
|
+
target: "idle",
|
|
3010
|
+
actions: ["clear pending value", "assign previous value", "assign initial value synced"]
|
|
3011
|
+
}]
|
|
3032
3012
|
}
|
|
3033
3013
|
}
|
|
3034
3014
|
}
|
|
@@ -3042,7 +3022,7 @@ async function updateValue({
|
|
|
3042
3022
|
}) {
|
|
3043
3023
|
let isChanged = !1, isValid = !0;
|
|
3044
3024
|
const hadSelection = !!slateEditor.selection;
|
|
3045
|
-
if ((!value || value.length === 0) && (debug$
|
|
3025
|
+
if ((!value || value.length === 0) && (debug$g("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
|
|
3046
3026
|
withoutSaving(slateEditor, () => {
|
|
3047
3027
|
withoutPatching(slateEditor, () => {
|
|
3048
3028
|
hadSelection && Transforms.deselect(slateEditor);
|
|
@@ -3117,14 +3097,14 @@ async function updateValue({
|
|
|
3117
3097
|
});
|
|
3118
3098
|
}
|
|
3119
3099
|
if (!isValid) {
|
|
3120
|
-
debug$
|
|
3100
|
+
debug$g("Invalid value, returning"), sendBack({
|
|
3121
3101
|
type: "done syncing",
|
|
3122
3102
|
value
|
|
3123
3103
|
});
|
|
3124
3104
|
return;
|
|
3125
3105
|
}
|
|
3126
3106
|
if (isChanged) {
|
|
3127
|
-
debug$
|
|
3107
|
+
debug$g("Server value changed, syncing editor");
|
|
3128
3108
|
try {
|
|
3129
3109
|
slateEditor.onChange();
|
|
3130
3110
|
} catch (err) {
|
|
@@ -3152,7 +3132,7 @@ async function updateValue({
|
|
|
3152
3132
|
value
|
|
3153
3133
|
});
|
|
3154
3134
|
} else
|
|
3155
|
-
debug$
|
|
3135
|
+
debug$g("Server value and editor value is equal, no need to sync.");
|
|
3156
3136
|
sendBack({
|
|
3157
3137
|
type: "done syncing",
|
|
3158
3138
|
value
|
|
@@ -3200,7 +3180,7 @@ function syncBlock({
|
|
|
3200
3180
|
type: "patch",
|
|
3201
3181
|
patch
|
|
3202
3182
|
});
|
|
3203
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
3183
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$g.enabled && debug$g("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$g.enabled && debug$g("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
3204
3184
|
type: "invalid value",
|
|
3205
3185
|
resolution: validation.resolution,
|
|
3206
3186
|
value
|
|
@@ -3208,9 +3188,9 @@ function syncBlock({
|
|
|
3208
3188
|
}
|
|
3209
3189
|
if (!oldBlock && blockValid) {
|
|
3210
3190
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
3211
|
-
debug$
|
|
3191
|
+
debug$g.enabled && debug$g("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
3212
3192
|
at: [currentBlockIndex]
|
|
3213
|
-
}) : (debug$
|
|
3193
|
+
}) : (debug$g("Invalid", validation), sendBack({
|
|
3214
3194
|
type: "invalid value",
|
|
3215
3195
|
resolution: validation.resolution,
|
|
3216
3196
|
value
|
|
@@ -3238,14 +3218,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3238
3218
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
3239
3219
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
3240
3220
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
3241
|
-
childIndex > 0 && (debug$
|
|
3221
|
+
childIndex > 0 && (debug$g("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
3242
3222
|
at: [currentBlockIndex, childIndex]
|
|
3243
3223
|
}));
|
|
3244
3224
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
3245
3225
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
3246
3226
|
if (isChildChanged)
|
|
3247
3227
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
3248
|
-
debug$
|
|
3228
|
+
debug$g("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
3249
3229
|
at: path
|
|
3250
3230
|
});
|
|
3251
3231
|
const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -3262,23 +3242,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3262
3242
|
}
|
|
3263
3243
|
}), Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
3264
3244
|
at: path
|
|
3265
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
3245
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$g("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
|
|
3266
3246
|
_key: VOID_CHILD_KEY
|
|
3267
3247
|
}, {
|
|
3268
3248
|
at: [...path, 0],
|
|
3269
3249
|
voids: !0
|
|
3270
3250
|
}));
|
|
3271
|
-
} else oldBlockChild ? (debug$
|
|
3251
|
+
} else oldBlockChild ? (debug$g("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
3272
3252
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3273
3253
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3274
3254
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3275
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
3255
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$g("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3276
3256
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3277
3257
|
}), slateEditor.onChange());
|
|
3278
3258
|
});
|
|
3279
3259
|
}
|
|
3280
3260
|
}
|
|
3281
|
-
const debug$
|
|
3261
|
+
const debug$f = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
3282
3262
|
function Synchronizer(props) {
|
|
3283
3263
|
const $ = c(41), {
|
|
3284
3264
|
editorActor,
|
|
@@ -3374,14 +3354,14 @@ function Synchronizer(props) {
|
|
|
3374
3354
|
}, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), useEffect(t11, t12);
|
|
3375
3355
|
let t13, t14;
|
|
3376
3356
|
$[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
|
|
3377
|
-
debug$
|
|
3357
|
+
debug$f("Value from props changed, syncing new value"), syncActorRef.send({
|
|
3378
3358
|
type: "update value",
|
|
3379
3359
|
value: incomingValue
|
|
3380
3360
|
});
|
|
3381
3361
|
}, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), useEffect(t13, t14);
|
|
3382
3362
|
let t15;
|
|
3383
3363
|
$[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
|
|
3384
|
-
debug$
|
|
3364
|
+
debug$f("Subscribing to patch events");
|
|
3385
3365
|
const sub = editorActor.on("internal.patch", (event_1) => {
|
|
3386
3366
|
mutationActorRef.send({
|
|
3387
3367
|
...event_1,
|
|
@@ -3389,7 +3369,7 @@ function Synchronizer(props) {
|
|
|
3389
3369
|
});
|
|
3390
3370
|
});
|
|
3391
3371
|
return () => {
|
|
3392
|
-
debug$
|
|
3372
|
+
debug$f("Unsubscribing to patch events"), sub.unsubscribe();
|
|
3393
3373
|
};
|
|
3394
3374
|
}, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
|
|
3395
3375
|
let t16;
|
|
@@ -3404,11 +3384,11 @@ function _temp$1(s) {
|
|
|
3404
3384
|
return s.context.incomingValue;
|
|
3405
3385
|
}
|
|
3406
3386
|
Synchronizer.displayName = "Synchronizer";
|
|
3407
|
-
const debug$
|
|
3387
|
+
const debug$e = debugWithName("operationToPatches");
|
|
3408
3388
|
function createOperationToPatches(editorActor) {
|
|
3409
3389
|
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
3410
3390
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
3411
|
-
debug$
|
|
3391
|
+
debug$e.enabled && debug$e("Operation", JSON.stringify(operation, null, 2));
|
|
3412
3392
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
3413
3393
|
if (!block)
|
|
3414
3394
|
throw new Error("Could not find block");
|
|
@@ -3501,7 +3481,7 @@ function createOperationToPatches(editorActor) {
|
|
|
3501
3481
|
_key: block.children[operation.path[1] - 1]._key
|
|
3502
3482
|
}])];
|
|
3503
3483
|
}
|
|
3504
|
-
return debug$
|
|
3484
|
+
return debug$e("Something was inserted into a void block. Not producing editor patches."), [];
|
|
3505
3485
|
}
|
|
3506
3486
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
3507
3487
|
const patches = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -3559,9 +3539,9 @@ function createOperationToPatches(editorActor) {
|
|
|
3559
3539
|
_key: block._key
|
|
3560
3540
|
}, "children", {
|
|
3561
3541
|
_key: spanToRemove._key
|
|
3562
|
-
}])] : (debug$
|
|
3542
|
+
}])] : (debug$e("Span not found in editor trying to remove node"), []);
|
|
3563
3543
|
} else
|
|
3564
|
-
return debug$
|
|
3544
|
+
return debug$e("Not creating patch inside object block"), [];
|
|
3565
3545
|
}
|
|
3566
3546
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
3567
3547
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -3587,7 +3567,7 @@ function createOperationToPatches(editorActor) {
|
|
|
3587
3567
|
_key: removedSpan._key
|
|
3588
3568
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
3589
3569
|
} else
|
|
3590
|
-
debug$
|
|
3570
|
+
debug$e("Void nodes can't be merged, not creating any patches");
|
|
3591
3571
|
return patches;
|
|
3592
3572
|
}
|
|
3593
3573
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -3677,7 +3657,7 @@ function getNextSpan({
|
|
|
3677
3657
|
}
|
|
3678
3658
|
return nextSpan;
|
|
3679
3659
|
}
|
|
3680
|
-
const debug$
|
|
3660
|
+
const debug$d = debugWithName("plugin:withPortableTextMarkModel");
|
|
3681
3661
|
function createWithPortableTextMarkModel(editorActor) {
|
|
3682
3662
|
return function(editor) {
|
|
3683
3663
|
const {
|
|
@@ -3691,7 +3671,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3691
3671
|
for (const [child, childPath] of children) {
|
|
3692
3672
|
const nextNode = node.children[childPath[1] + 1];
|
|
3693
3673
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3694
|
-
debug$
|
|
3674
|
+
debug$d("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3695
3675
|
type: "normalizing"
|
|
3696
3676
|
}), Transforms.mergeNodes(editor, {
|
|
3697
3677
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3704,7 +3684,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3704
3684
|
}
|
|
3705
3685
|
}
|
|
3706
3686
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3707
|
-
debug$
|
|
3687
|
+
debug$d("Adding .markDefs to block node"), editorActor.send({
|
|
3708
3688
|
type: "normalizing"
|
|
3709
3689
|
}), Transforms.setNodes(editor, {
|
|
3710
3690
|
markDefs: []
|
|
@@ -3716,7 +3696,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3716
3696
|
return;
|
|
3717
3697
|
}
|
|
3718
3698
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3719
|
-
debug$
|
|
3699
|
+
debug$d("Adding .marks to span node"), editorActor.send({
|
|
3720
3700
|
type: "normalizing"
|
|
3721
3701
|
}), Transforms.setNodes(editor, {
|
|
3722
3702
|
marks: []
|
|
@@ -3730,7 +3710,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3730
3710
|
if (editor.isTextSpan(node)) {
|
|
3731
3711
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3732
3712
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3733
|
-
debug$
|
|
3713
|
+
debug$d("Removing annotations from empty span node"), editorActor.send({
|
|
3734
3714
|
type: "normalizing"
|
|
3735
3715
|
}), Transforms.setNodes(editor, {
|
|
3736
3716
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3748,7 +3728,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3748
3728
|
if (editor.isTextSpan(child)) {
|
|
3749
3729
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3750
3730
|
if (orphanedAnnotations.length > 0) {
|
|
3751
|
-
debug$
|
|
3731
|
+
debug$d("Removing orphaned annotations from span node"), editorActor.send({
|
|
3752
3732
|
type: "normalizing"
|
|
3753
3733
|
}), Transforms.setNodes(editor, {
|
|
3754
3734
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3766,7 +3746,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3766
3746
|
if (editor.isTextBlock(block)) {
|
|
3767
3747
|
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3768
3748
|
if (orphanedAnnotations.length > 0) {
|
|
3769
|
-
debug$
|
|
3749
|
+
debug$d("Removing orphaned annotations from span node"), editorActor.send({
|
|
3770
3750
|
type: "normalizing"
|
|
3771
3751
|
}), Transforms.setNodes(editor, {
|
|
3772
3752
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3784,7 +3764,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3784
3764
|
for (const markDef of markDefs)
|
|
3785
3765
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3786
3766
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3787
|
-
debug$
|
|
3767
|
+
debug$d("Removing duplicate markDefs"), editorActor.send({
|
|
3788
3768
|
type: "normalizing"
|
|
3789
3769
|
}), Transforms.setNodes(editor, {
|
|
3790
3770
|
markDefs: newMarkDefs
|
|
@@ -3799,7 +3779,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3799
3779
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3800
3780
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3801
3781
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
3802
|
-
debug$
|
|
3782
|
+
debug$d("Removing markDef not in use"), editorActor.send({
|
|
3803
3783
|
type: "normalizing"
|
|
3804
3784
|
}), Transforms.setNodes(editor, {
|
|
3805
3785
|
markDefs: newMarkDefs
|
|
@@ -4019,7 +3999,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
4019
3999
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
4020
4000
|
if (editor.isTextBlock(targetBlock)) {
|
|
4021
4001
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
4022
|
-
debug$
|
|
4002
|
+
debug$d("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
4023
4003
|
markDefs: newMarkDefs
|
|
4024
4004
|
}, {
|
|
4025
4005
|
at: targetPath,
|
|
@@ -5243,13 +5223,13 @@ function createWithObjectKeys(editorActor) {
|
|
|
5243
5223
|
}, editor;
|
|
5244
5224
|
};
|
|
5245
5225
|
}
|
|
5246
|
-
const debug$
|
|
5226
|
+
const debug$c = debugWithName("applyPatches"), debugVerbose = debug$c.enabled && !0;
|
|
5247
5227
|
function createApplyPatch(schema) {
|
|
5248
5228
|
return (editor, patch) => {
|
|
5249
5229
|
let changed = !1;
|
|
5250
|
-
debugVerbose && (debug$
|
|
5230
|
+
debugVerbose && (debug$c(`
|
|
5251
5231
|
|
|
5252
|
-
NEW PATCH =============================================================`), debug$
|
|
5232
|
+
NEW PATCH =============================================================`), debug$c(JSON.stringify(patch, null, 2)));
|
|
5253
5233
|
try {
|
|
5254
5234
|
switch (patch.type) {
|
|
5255
5235
|
case "insert":
|
|
@@ -5265,7 +5245,7 @@ NEW PATCH =============================================================`), debug
|
|
|
5265
5245
|
changed = diffMatchPatch(editor, patch);
|
|
5266
5246
|
break;
|
|
5267
5247
|
default:
|
|
5268
|
-
debug$
|
|
5248
|
+
debug$c("Unhandled patch", patch.type);
|
|
5269
5249
|
}
|
|
5270
5250
|
} catch (err) {
|
|
5271
5251
|
console.error(err);
|
|
@@ -5280,9 +5260,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
5280
5260
|
childPath
|
|
5281
5261
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5282
5262
|
if (!block)
|
|
5283
|
-
return debug$
|
|
5263
|
+
return debug$c("Block not found"), !1;
|
|
5284
5264
|
if (!child || !childPath)
|
|
5285
|
-
return debug$
|
|
5265
|
+
return debug$c("Child not found"), !1;
|
|
5286
5266
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
|
|
5287
5267
|
return !1;
|
|
5288
5268
|
const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
|
|
@@ -5312,9 +5292,9 @@ function insertPatch(editor, patch, schema) {
|
|
|
5312
5292
|
childPath: targetChildPath
|
|
5313
5293
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5314
5294
|
if (!targetBlock || !targetBlockPath)
|
|
5315
|
-
return debug$
|
|
5295
|
+
return debug$c("Block not found"), !1;
|
|
5316
5296
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
5317
|
-
return debug$
|
|
5297
|
+
return debug$c("Ignoring patch targeting void value"), !1;
|
|
5318
5298
|
if (patch.path.length === 1) {
|
|
5319
5299
|
const {
|
|
5320
5300
|
items: items2,
|
|
@@ -5322,7 +5302,7 @@ function insertPatch(editor, patch, schema) {
|
|
|
5322
5302
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
5323
5303
|
schemaTypes: schema
|
|
5324
5304
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
5325
|
-
return debug$
|
|
5305
|
+
return debug$c(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
|
|
5326
5306
|
at: [normalizedIdx2]
|
|
5327
5307
|
}), debugState(editor, "after"), !0;
|
|
5328
5308
|
}
|
|
@@ -5331,14 +5311,14 @@ function insertPatch(editor, patch, schema) {
|
|
|
5331
5311
|
position
|
|
5332
5312
|
} = patch;
|
|
5333
5313
|
if (!targetChild || !targetChildPath)
|
|
5334
|
-
return debug$
|
|
5314
|
+
return debug$c("Child not found"), !1;
|
|
5335
5315
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
5336
5316
|
...targetBlock,
|
|
5337
5317
|
children: items
|
|
5338
5318
|
}], {
|
|
5339
5319
|
schemaTypes: schema
|
|
5340
5320
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
5341
|
-
return debug$
|
|
5321
|
+
return debug$c(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
5342
5322
|
at: childInsertPath
|
|
5343
5323
|
}), debugState(editor, "after"), !0;
|
|
5344
5324
|
}
|
|
@@ -5352,14 +5332,14 @@ function setPatch(editor, patch) {
|
|
|
5352
5332
|
childPath
|
|
5353
5333
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5354
5334
|
if (!block)
|
|
5355
|
-
return debug$
|
|
5335
|
+
return debug$c("Block not found"), !1;
|
|
5356
5336
|
const isTextBlock2 = editor.isTextBlock(block);
|
|
5357
5337
|
if (isTextBlock2 && patch.path.length > 1 && patch.path[1] !== "children")
|
|
5358
|
-
return debug$
|
|
5338
|
+
return debug$c("Ignoring setting void value"), !1;
|
|
5359
5339
|
if (debugState(editor, "before"), isTextBlock2 && child && childPath) {
|
|
5360
5340
|
if (Text.isText(value) && Text.isText(child)) {
|
|
5361
5341
|
const newText = child.text;
|
|
5362
|
-
value.text !== newText && (debug$
|
|
5342
|
+
value.text !== newText && (debug$c("Setting text property"), editor.apply({
|
|
5363
5343
|
type: "remove_text",
|
|
5364
5344
|
path: childPath,
|
|
5365
5345
|
offset: 0,
|
|
@@ -5371,7 +5351,7 @@ function setPatch(editor, patch) {
|
|
|
5371
5351
|
text: value.text
|
|
5372
5352
|
}), editor.onChange());
|
|
5373
5353
|
} else
|
|
5374
|
-
debug$
|
|
5354
|
+
debug$c("Setting non-text property"), editor.apply({
|
|
5375
5355
|
type: "set_node",
|
|
5376
5356
|
path: childPath,
|
|
5377
5357
|
properties: {},
|
|
@@ -5379,7 +5359,7 @@ function setPatch(editor, patch) {
|
|
|
5379
5359
|
});
|
|
5380
5360
|
return !0;
|
|
5381
5361
|
} else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
5382
|
-
debug$
|
|
5362
|
+
debug$c("Setting block property");
|
|
5383
5363
|
const {
|
|
5384
5364
|
children,
|
|
5385
5365
|
...nextRest
|
|
@@ -5396,7 +5376,7 @@ function setPatch(editor, patch) {
|
|
|
5396
5376
|
...prevRest
|
|
5397
5377
|
},
|
|
5398
5378
|
newProperties: nextRest
|
|
5399
|
-
}), debug$
|
|
5379
|
+
}), debug$c("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
5400
5380
|
editor.apply({
|
|
5401
5381
|
type: "remove_node",
|
|
5402
5382
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -5427,7 +5407,7 @@ function setPatch(editor, patch) {
|
|
|
5427
5407
|
}
|
|
5428
5408
|
function unsetPatch(editor, patch) {
|
|
5429
5409
|
if (patch.path.length === 0) {
|
|
5430
|
-
debug$
|
|
5410
|
+
debug$c("Removing everything"), debugState(editor, "before");
|
|
5431
5411
|
const previousSelection = editor.selection;
|
|
5432
5412
|
return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
5433
5413
|
Transforms.removeNodes(editor, {
|
|
@@ -5454,13 +5434,13 @@ function unsetPatch(editor, patch) {
|
|
|
5454
5434
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5455
5435
|
if (patch.path.length === 1) {
|
|
5456
5436
|
if (!block || !blockPath)
|
|
5457
|
-
return debug$
|
|
5437
|
+
return debug$c("Block not found"), !1;
|
|
5458
5438
|
const blockIndex = blockPath[0];
|
|
5459
|
-
return debug$
|
|
5439
|
+
return debug$c(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
|
|
5460
5440
|
at: [blockIndex]
|
|
5461
5441
|
}), debugState(editor, "after"), !0;
|
|
5462
5442
|
}
|
|
5463
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
5443
|
+
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$c("Child not found"), !1) : (debug$c(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$c(`Removing child at path ${JSON.stringify(childPath)}`), Transforms.removeNodes(editor, {
|
|
5464
5444
|
at: childPath
|
|
5465
5445
|
}), debugState(editor, "after"), !0) : !1;
|
|
5466
5446
|
}
|
|
@@ -5468,7 +5448,7 @@ function isKeyedSegment(segment) {
|
|
|
5468
5448
|
return typeof segment == "object" && "_key" in segment;
|
|
5469
5449
|
}
|
|
5470
5450
|
function debugState(editor, stateName) {
|
|
5471
|
-
debugVerbose && (debug$
|
|
5451
|
+
debugVerbose && (debug$c(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$c(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
5472
5452
|
}
|
|
5473
5453
|
function findBlockFromPath(editor, path) {
|
|
5474
5454
|
let blockIndex = -1;
|
|
@@ -5510,7 +5490,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
5510
5490
|
childPath: void 0
|
|
5511
5491
|
};
|
|
5512
5492
|
}
|
|
5513
|
-
const debug$
|
|
5493
|
+
const debug$b = debugWithName("plugin:withPatches");
|
|
5514
5494
|
function createWithPatches({
|
|
5515
5495
|
editorActor,
|
|
5516
5496
|
patchFunctions,
|
|
@@ -5535,7 +5515,7 @@ function createWithPatches({
|
|
|
5535
5515
|
withoutPatching(editor, () => {
|
|
5536
5516
|
withoutSaving(editor, () => {
|
|
5537
5517
|
for (const patch of patches) {
|
|
5538
|
-
debug$
|
|
5518
|
+
debug$b.enabled && debug$b(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
5539
5519
|
try {
|
|
5540
5520
|
changed = applyPatch(editor, patch);
|
|
5541
5521
|
} catch (error) {
|
|
@@ -5553,10 +5533,10 @@ function createWithPatches({
|
|
|
5553
5533
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
5554
5534
|
};
|
|
5555
5535
|
return subscriptions.push(() => {
|
|
5556
|
-
debug$
|
|
5536
|
+
debug$b("Subscribing to remote patches");
|
|
5557
5537
|
const sub = editorActor.on("patches", handlePatches);
|
|
5558
5538
|
return () => {
|
|
5559
|
-
debug$
|
|
5539
|
+
debug$b("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
5560
5540
|
};
|
|
5561
5541
|
}), editor.apply = (operation) => {
|
|
5562
5542
|
let patches = [];
|
|
@@ -5610,7 +5590,7 @@ function createWithPatches({
|
|
|
5610
5590
|
}, editor;
|
|
5611
5591
|
};
|
|
5612
5592
|
}
|
|
5613
|
-
const debug$
|
|
5593
|
+
const debug$a = debugWithName("plugin:withPlaceholderBlock");
|
|
5614
5594
|
function createWithPlaceholderBlock(editorActor) {
|
|
5615
5595
|
return function(editor) {
|
|
5616
5596
|
const {
|
|
@@ -5635,7 +5615,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
5635
5615
|
const node = op.node;
|
|
5636
5616
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
5637
5617
|
const nextPath = Path.next(op.path);
|
|
5638
|
-
editor.children[nextPath[0]] || (debug$
|
|
5618
|
+
editor.children[nextPath[0]] || (debug$a("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
5639
5619
|
decorators: []
|
|
5640
5620
|
})));
|
|
5641
5621
|
}
|
|
@@ -5644,7 +5624,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
5644
5624
|
}, editor;
|
|
5645
5625
|
};
|
|
5646
5626
|
}
|
|
5647
|
-
const debug$
|
|
5627
|
+
const debug$9 = debugWithName("plugin:withPortableTextBlockStyle");
|
|
5648
5628
|
function createWithPortableTextBlockStyle(editorActor) {
|
|
5649
5629
|
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
5650
5630
|
return function(editor) {
|
|
@@ -5657,7 +5637,7 @@ function createWithPortableTextBlockStyle(editorActor) {
|
|
|
5657
5637
|
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !Path.equals(path, op.path)) {
|
|
5658
5638
|
const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
|
|
5659
5639
|
if (Text.isText(child) && child.text === "") {
|
|
5660
|
-
debug$
|
|
5640
|
+
debug$9(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
5661
5641
|
type: "normalizing"
|
|
5662
5642
|
}), Transforms.setNodes(editor, {
|
|
5663
5643
|
style: defaultStyle
|
|
@@ -5708,7 +5688,7 @@ function createWithPortableTextSelections(editorActor) {
|
|
|
5708
5688
|
}, editor;
|
|
5709
5689
|
};
|
|
5710
5690
|
}
|
|
5711
|
-
const debug$
|
|
5691
|
+
const debug$8 = debugWithName("plugin:withSchemaTypes");
|
|
5712
5692
|
function createWithSchemaTypes({
|
|
5713
5693
|
editorActor
|
|
5714
5694
|
}) {
|
|
@@ -5720,7 +5700,7 @@ function createWithSchemaTypes({
|
|
|
5720
5700
|
return editor.normalizeNode = (entry) => {
|
|
5721
5701
|
const [node, path] = entry;
|
|
5722
5702
|
if (node._type === void 0 && path.length === 2) {
|
|
5723
|
-
debug$
|
|
5703
|
+
debug$8("Setting span type on text node without a type");
|
|
5724
5704
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
5725
5705
|
editorActor.send({
|
|
5726
5706
|
type: "normalizing"
|
|
@@ -5736,7 +5716,7 @@ function createWithSchemaTypes({
|
|
|
5736
5716
|
return;
|
|
5737
5717
|
}
|
|
5738
5718
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
5739
|
-
debug$
|
|
5719
|
+
debug$8("Setting missing key on child node without a key");
|
|
5740
5720
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
5741
5721
|
editorActor.send({
|
|
5742
5722
|
type: "normalizing"
|
|
@@ -5797,12 +5777,12 @@ const withPlugins = (editor, options) => {
|
|
|
5797
5777
|
editorActor
|
|
5798
5778
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5799
5779
|
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5800
|
-
}, debug$
|
|
5780
|
+
}, debug$7 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
5801
5781
|
function createSlateEditor(config) {
|
|
5802
5782
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
5803
5783
|
if (existingSlateEditor)
|
|
5804
|
-
return debug$
|
|
5805
|
-
debug$
|
|
5784
|
+
return debug$7("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
5785
|
+
debug$7("Creating new Slate editor instance", config.editorActor.id);
|
|
5806
5786
|
const unsubscriptions = [], subscriptions = [], instance = withPlugins(withReact(createEditor()), {
|
|
5807
5787
|
editorActor: config.editorActor,
|
|
5808
5788
|
subscriptions
|
|
@@ -6089,7 +6069,7 @@ function getEditorSnapshot({
|
|
|
6089
6069
|
}
|
|
6090
6070
|
};
|
|
6091
6071
|
}
|
|
6092
|
-
const debug$
|
|
6072
|
+
const debug$6 = debugWithName("API:editable");
|
|
6093
6073
|
function createEditableAPI(editor, editorActor) {
|
|
6094
6074
|
const types = editorActor.getSnapshot().context.schema;
|
|
6095
6075
|
return {
|
|
@@ -6222,7 +6202,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
6222
6202
|
}], {
|
|
6223
6203
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
6224
6204
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
|
|
6225
|
-
return isSpanNode && focusNode._type !== types.span.name && (debug$
|
|
6205
|
+
return isSpanNode && focusNode._type !== types.span.name && (debug$6("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
6226
6206
|
distance: 1,
|
|
6227
6207
|
unit: "character"
|
|
6228
6208
|
})), Transforms.insertNodes(editor, child, {
|
|
@@ -6367,18 +6347,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
6367
6347
|
throw new Error("Invalid range");
|
|
6368
6348
|
if (range) {
|
|
6369
6349
|
if (!options?.mode || options?.mode === "selected") {
|
|
6370
|
-
debug$
|
|
6350
|
+
debug$6("Deleting content in selection"), Transforms.delete(editor, {
|
|
6371
6351
|
at: range,
|
|
6372
6352
|
hanging: !0,
|
|
6373
6353
|
voids: !0
|
|
6374
6354
|
}), editor.onChange();
|
|
6375
6355
|
return;
|
|
6376
6356
|
}
|
|
6377
|
-
options?.mode === "blocks" && (debug$
|
|
6357
|
+
options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
6378
6358
|
at: range,
|
|
6379
6359
|
voids: !0,
|
|
6380
6360
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
6381
|
-
})), options?.mode === "children" && (debug$
|
|
6361
|
+
})), options?.mode === "children" && (debug$6("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
6382
6362
|
at: range,
|
|
6383
6363
|
voids: !0,
|
|
6384
6364
|
match: (node) => node._type === types.span.name || // Text children
|
|
@@ -8137,7 +8117,7 @@ function isNativeBehaviorEvent(event) {
|
|
|
8137
8117
|
function isCustomBehaviorEvent(event) {
|
|
8138
8118
|
return event.type.startsWith("custom.");
|
|
8139
8119
|
}
|
|
8140
|
-
const debug$
|
|
8120
|
+
const debug$5 = debugWithName("behaviors:event");
|
|
8141
8121
|
function eventCategory(event) {
|
|
8142
8122
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
8143
8123
|
}
|
|
@@ -8152,7 +8132,7 @@ function performEvent({
|
|
|
8152
8132
|
getSnapshot,
|
|
8153
8133
|
nativeEvent
|
|
8154
8134
|
}) {
|
|
8155
|
-
debug$
|
|
8135
|
+
debug$5(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
8156
8136
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
8157
8137
|
if (behavior.on === "*")
|
|
8158
8138
|
return !0;
|
|
@@ -8161,7 +8141,7 @@ function performEvent({
|
|
|
8161
8141
|
});
|
|
8162
8142
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
8163
8143
|
nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
8164
|
-
debug$
|
|
8144
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
8165
8145
|
context: {
|
|
8166
8146
|
keyGenerator,
|
|
8167
8147
|
schema
|
|
@@ -8304,7 +8284,7 @@ function performEvent({
|
|
|
8304
8284
|
}
|
|
8305
8285
|
}
|
|
8306
8286
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
8307
|
-
debug$
|
|
8287
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
8308
8288
|
context: {
|
|
8309
8289
|
keyGenerator,
|
|
8310
8290
|
schema
|
|
@@ -8392,7 +8372,7 @@ function createEditorSnapshot({
|
|
|
8392
8372
|
}
|
|
8393
8373
|
};
|
|
8394
8374
|
}
|
|
8395
|
-
const editorMachine = setup({
|
|
8375
|
+
const debug$4 = debugWithName("editor machine"), editorMachine = setup({
|
|
8396
8376
|
types: {
|
|
8397
8377
|
context: {},
|
|
8398
8378
|
events: {},
|
|
@@ -8673,6 +8653,12 @@ const editorMachine = setup({
|
|
|
8673
8653
|
},
|
|
8674
8654
|
states: {
|
|
8675
8655
|
"determine initial edit mode": {
|
|
8656
|
+
entry: [() => {
|
|
8657
|
+
debug$4("entry: edit mode->read only->determine initial edit mode");
|
|
8658
|
+
}],
|
|
8659
|
+
exit: [() => {
|
|
8660
|
+
debug$4("exit: edit mode->read only->determine initial edit mode");
|
|
8661
|
+
}],
|
|
8676
8662
|
on: {
|
|
8677
8663
|
"done syncing value": [{
|
|
8678
8664
|
target: "#editor.edit mode.read only.read only",
|
|
@@ -8685,6 +8671,12 @@ const editorMachine = setup({
|
|
|
8685
8671
|
}
|
|
8686
8672
|
},
|
|
8687
8673
|
"read only": {
|
|
8674
|
+
entry: [() => {
|
|
8675
|
+
debug$4("entry: edit mode->read only->read only");
|
|
8676
|
+
}],
|
|
8677
|
+
exit: [() => {
|
|
8678
|
+
debug$4("exit: edit mode->read only->read only");
|
|
8679
|
+
}],
|
|
8688
8680
|
on: {
|
|
8689
8681
|
"update readOnly": {
|
|
8690
8682
|
guard: ({
|
|
@@ -8724,6 +8716,12 @@ const editorMachine = setup({
|
|
|
8724
8716
|
initial: "idle",
|
|
8725
8717
|
states: {
|
|
8726
8718
|
idle: {
|
|
8719
|
+
entry: [() => {
|
|
8720
|
+
debug$4("entry: edit mode->editable->idle");
|
|
8721
|
+
}],
|
|
8722
|
+
exit: [() => {
|
|
8723
|
+
debug$4("exit: edit mode->editable-idle");
|
|
8724
|
+
}],
|
|
8727
8725
|
on: {
|
|
8728
8726
|
dragstart: {
|
|
8729
8727
|
actions: [assign({
|
|
@@ -8742,6 +8740,12 @@ const editorMachine = setup({
|
|
|
8742
8740
|
initial: "checking if busy",
|
|
8743
8741
|
states: {
|
|
8744
8742
|
"checking if busy": {
|
|
8743
|
+
entry: [() => {
|
|
8744
|
+
debug$4("entry: edit mode->editable->focusing->checking if busy");
|
|
8745
|
+
}],
|
|
8746
|
+
exit: [() => {
|
|
8747
|
+
debug$4("exit: edit mode->editable->focusing->checking if busy");
|
|
8748
|
+
}],
|
|
8745
8749
|
always: [{
|
|
8746
8750
|
guard: "slate is busy",
|
|
8747
8751
|
target: "busy"
|
|
@@ -8751,6 +8755,12 @@ const editorMachine = setup({
|
|
|
8751
8755
|
}]
|
|
8752
8756
|
},
|
|
8753
8757
|
busy: {
|
|
8758
|
+
entry: [() => {
|
|
8759
|
+
debug$4("entry: edit mode->editable->focusing-busy");
|
|
8760
|
+
}],
|
|
8761
|
+
exit: [() => {
|
|
8762
|
+
debug$4("exit: edit mode->editable->focusing->busy");
|
|
8763
|
+
}],
|
|
8754
8764
|
after: {
|
|
8755
8765
|
10: {
|
|
8756
8766
|
target: "checking if busy"
|
|
@@ -8760,7 +8770,12 @@ const editorMachine = setup({
|
|
|
8760
8770
|
}
|
|
8761
8771
|
},
|
|
8762
8772
|
"dragging internally": {
|
|
8763
|
-
|
|
8773
|
+
entry: [() => {
|
|
8774
|
+
debug$4("entry: edit mode->editable->dragging internally");
|
|
8775
|
+
}],
|
|
8776
|
+
exit: [() => {
|
|
8777
|
+
debug$4("exit: edit mode->editable->dragging internally");
|
|
8778
|
+
}, ({
|
|
8764
8779
|
context
|
|
8765
8780
|
}) => {
|
|
8766
8781
|
if (context.internalDrag?.ghost)
|
|
@@ -8790,7 +8805,12 @@ const editorMachine = setup({
|
|
|
8790
8805
|
initial: "setting up",
|
|
8791
8806
|
states: {
|
|
8792
8807
|
"setting up": {
|
|
8793
|
-
|
|
8808
|
+
entry: [() => {
|
|
8809
|
+
debug$4("entry: setup->setting up");
|
|
8810
|
+
}],
|
|
8811
|
+
exit: [() => {
|
|
8812
|
+
debug$4("exit: setup->setting up");
|
|
8813
|
+
}, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
8794
8814
|
on: {
|
|
8795
8815
|
"internal.patch": {
|
|
8796
8816
|
actions: "defer event"
|
|
@@ -8813,6 +8833,12 @@ const editorMachine = setup({
|
|
|
8813
8833
|
initial: "idle",
|
|
8814
8834
|
states: {
|
|
8815
8835
|
idle: {
|
|
8836
|
+
entry: [() => {
|
|
8837
|
+
debug$4("entry: setup->set up->value sync->idle");
|
|
8838
|
+
}],
|
|
8839
|
+
exit: [() => {
|
|
8840
|
+
debug$4("exit: setup->set up->value sync->idle");
|
|
8841
|
+
}],
|
|
8816
8842
|
on: {
|
|
8817
8843
|
patches: {
|
|
8818
8844
|
actions: [emit(({
|
|
@@ -8825,7 +8851,12 @@ const editorMachine = setup({
|
|
|
8825
8851
|
}
|
|
8826
8852
|
},
|
|
8827
8853
|
"syncing value": {
|
|
8828
|
-
|
|
8854
|
+
entry: [() => {
|
|
8855
|
+
debug$4("entry: setup->set up->value sync->syncing value");
|
|
8856
|
+
}],
|
|
8857
|
+
exit: [() => {
|
|
8858
|
+
debug$4("exit: setup->set up->value sync->syncing value");
|
|
8859
|
+
}, "emit pending incoming patches", "clear pending incoming patches"],
|
|
8829
8860
|
on: {
|
|
8830
8861
|
patches: {
|
|
8831
8862
|
actions: ["defer incoming patches"]
|
|
@@ -8844,6 +8875,12 @@ const editorMachine = setup({
|
|
|
8844
8875
|
initial: "idle",
|
|
8845
8876
|
states: {
|
|
8846
8877
|
idle: {
|
|
8878
|
+
entry: [() => {
|
|
8879
|
+
debug$4("entry: setup->set up->writing->pristine->idle");
|
|
8880
|
+
}],
|
|
8881
|
+
exit: [() => {
|
|
8882
|
+
debug$4("exit: setup->set up->writing->pristine->idle");
|
|
8883
|
+
}],
|
|
8847
8884
|
on: {
|
|
8848
8885
|
normalizing: {
|
|
8849
8886
|
target: "normalizing"
|
|
@@ -8859,6 +8896,12 @@ const editorMachine = setup({
|
|
|
8859
8896
|
}
|
|
8860
8897
|
},
|
|
8861
8898
|
normalizing: {
|
|
8899
|
+
entry: [() => {
|
|
8900
|
+
debug$4("entry: setup->set up->writing->pristine->normalizing");
|
|
8901
|
+
}],
|
|
8902
|
+
exit: [() => {
|
|
8903
|
+
debug$4("exit: setup->set up->writing->pristine->normalizing");
|
|
8904
|
+
}],
|
|
8862
8905
|
on: {
|
|
8863
8906
|
"done normalizing": {
|
|
8864
8907
|
target: "idle"
|
|
@@ -8874,7 +8917,12 @@ const editorMachine = setup({
|
|
|
8874
8917
|
}
|
|
8875
8918
|
},
|
|
8876
8919
|
dirty: {
|
|
8877
|
-
entry: [
|
|
8920
|
+
entry: [() => {
|
|
8921
|
+
debug$4("entry: setup->set up->writing->dirty");
|
|
8922
|
+
}, "emit pending events", "clear pending events"],
|
|
8923
|
+
exit: [() => {
|
|
8924
|
+
debug$4("exit: setup->set up->writing->dirty");
|
|
8925
|
+
}],
|
|
8878
8926
|
on: {
|
|
8879
8927
|
"internal.patch": {
|
|
8880
8928
|
actions: "emit patch event"
|
|
@@ -9939,12 +9987,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
9939
9987
|
type: "range decorations updated",
|
|
9940
9988
|
rangeDecorations: rangeDecorations ?? []
|
|
9941
9989
|
});
|
|
9942
|
-
}, [rangeDecorationsActor, rangeDecorations]), useMemo(() =>
|
|
9943
|
-
if (readOnly)
|
|
9944
|
-
return debug("Editable is in read only mode"), slateEditor;
|
|
9945
|
-
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
9946
|
-
return debug("Editable is in edit mode"), withHotKeys(slateEditor);
|
|
9947
|
-
}, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
9990
|
+
}, [rangeDecorationsActor, rangeDecorations]), useMemo(() => readOnly ? slateEditor : createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor), [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
9948
9991
|
const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, spellCheck }), [spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((leafProps) => /* @__PURE__ */ jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), [readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder]), renderText = useCallback((props_0) => /* @__PURE__ */ jsx(RenderText, { ...props_0 }), []), restoreSelectionFromProps = useCallback(() => {
|
|
9949
9992
|
if (propsSelection) {
|
|
9950
9993
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|