@portabletext/editor 1.49.3 → 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 +323 -247
- 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 +324 -248
- 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 +202 -182
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$i = require("debug"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), startCase = require("lodash.startcase");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$
|
|
7
|
+
var noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$i), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase);
|
|
8
8
|
function EditorEventListener(props) {
|
|
9
9
|
const $ = reactCompilerRuntime.c(5), editor = useEditor.useEditor(), on = useEffectEvent.useEffectEvent(props.on);
|
|
10
10
|
let t0;
|
|
@@ -2505,7 +2505,7 @@ function withUndoStep(editor, fn) {
|
|
|
2505
2505
|
function getCurrentUndoStepId(editor) {
|
|
2506
2506
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
2507
2507
|
}
|
|
2508
|
-
const debug$
|
|
2508
|
+
const debug$h = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2509
2509
|
const state = SAVING.get(editor);
|
|
2510
2510
|
return state === void 0 ? !0 : state;
|
|
2511
2511
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -2518,7 +2518,7 @@ function createWithUndoRedo(options) {
|
|
|
2518
2518
|
const remotePatches = getRemotePatches(editor);
|
|
2519
2519
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
2520
2520
|
options.subscriptions.push(() => {
|
|
2521
|
-
debug$
|
|
2521
|
+
debug$h("Subscribing to patches");
|
|
2522
2522
|
const sub = editorActor.on("patches", ({
|
|
2523
2523
|
patches: patches2,
|
|
2524
2524
|
snapshot
|
|
@@ -2527,7 +2527,7 @@ function createWithUndoRedo(options) {
|
|
|
2527
2527
|
patches2.forEach((patch) => {
|
|
2528
2528
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2529
2529
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2530
|
-
debug$
|
|
2530
|
+
debug$h("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2531
2531
|
undos: [],
|
|
2532
2532
|
redos: []
|
|
2533
2533
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -2543,7 +2543,7 @@ function createWithUndoRedo(options) {
|
|
|
2543
2543
|
}), previousSnapshot = snapshot;
|
|
2544
2544
|
});
|
|
2545
2545
|
return () => {
|
|
2546
|
-
debug$
|
|
2546
|
+
debug$h("Unsubscribing to patches"), sub.unsubscribe();
|
|
2547
2547
|
};
|
|
2548
2548
|
}), editor.history = {
|
|
2549
2549
|
undos: [],
|
|
@@ -2582,7 +2582,7 @@ function createWithUndoRedo(options) {
|
|
|
2582
2582
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
2583
2583
|
timestamp: /* @__PURE__ */ new Date()
|
|
2584
2584
|
};
|
|
2585
|
-
undos.push(newStep), debug$
|
|
2585
|
+
undos.push(newStep), debug$h("Created new undo step", step);
|
|
2586
2586
|
}
|
|
2587
2587
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
2588
2588
|
undos.shift();
|
|
@@ -2600,7 +2600,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2600
2600
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2601
2601
|
if (undos.length > 0) {
|
|
2602
2602
|
const step = undos[undos.length - 1];
|
|
2603
|
-
if (debug$
|
|
2603
|
+
if (debug$h("Undoing", step), step.operations.length > 0) {
|
|
2604
2604
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2605
2605
|
let transformedOperations = step.operations;
|
|
2606
2606
|
otherPatches.forEach((item) => {
|
|
@@ -2618,7 +2618,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2618
2618
|
});
|
|
2619
2619
|
});
|
|
2620
2620
|
} catch (err) {
|
|
2621
|
-
debug$
|
|
2621
|
+
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
2622
2622
|
undos: [],
|
|
2623
2623
|
redos: []
|
|
2624
2624
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2635,7 +2635,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2635
2635
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2636
2636
|
if (redos.length > 0) {
|
|
2637
2637
|
const step = redos[redos.length - 1];
|
|
2638
|
-
if (debug$
|
|
2638
|
+
if (debug$h("Redoing", step), step.operations.length > 0) {
|
|
2639
2639
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2640
2640
|
let transformedOperations = step.operations;
|
|
2641
2641
|
otherPatches.forEach((item) => {
|
|
@@ -2652,7 +2652,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2652
2652
|
});
|
|
2653
2653
|
});
|
|
2654
2654
|
} catch (err) {
|
|
2655
|
-
debug$
|
|
2655
|
+
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
|
|
2656
2656
|
undos: [],
|
|
2657
2657
|
redos: []
|
|
2658
2658
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2670,16 +2670,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2670
2670
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2671
2671
|
_key: blk._key
|
|
2672
2672
|
}, patch.path[0]));
|
|
2673
|
-
return debug$
|
|
2673
|
+
return debug$h(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2674
2674
|
}
|
|
2675
2675
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2676
2676
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2677
2677
|
_key: blk._key
|
|
2678
2678
|
}, patch.path[0]));
|
|
2679
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2679
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$h("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2680
2680
|
}
|
|
2681
2681
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2682
|
-
return debug$
|
|
2682
|
+
return debug$h(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2683
2683
|
if (patch.type === "diffMatchPatch") {
|
|
2684
2684
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2685
2685
|
return !operationTargetBlock || !isEqual__default.default({
|
|
@@ -2766,7 +2766,7 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
2766
2766
|
let block;
|
|
2767
2767
|
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;
|
|
2768
2768
|
}
|
|
2769
|
-
const debug$
|
|
2769
|
+
const debug$g = debugWithName("sync machine"), syncValueCallback = ({
|
|
2770
2770
|
sendBack,
|
|
2771
2771
|
input
|
|
2772
2772
|
}) => {
|
|
@@ -2821,13 +2821,17 @@ const debug$f = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2821
2821
|
context
|
|
2822
2822
|
}) => {
|
|
2823
2823
|
const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
|
|
2824
|
-
return debug$
|
|
2824
|
+
return debug$g("isBusy", {
|
|
2825
2825
|
isBusy,
|
|
2826
2826
|
editable,
|
|
2827
2827
|
isProcessingLocalChanges,
|
|
2828
2828
|
isChanging
|
|
2829
2829
|
}), isBusy;
|
|
2830
2830
|
},
|
|
2831
|
+
"is new value": ({
|
|
2832
|
+
context,
|
|
2833
|
+
event
|
|
2834
|
+
}) => event.type === "update value" && context.previousValue !== event.value,
|
|
2831
2835
|
"value changed while syncing": ({
|
|
2832
2836
|
context,
|
|
2833
2837
|
event
|
|
@@ -2868,139 +2872,115 @@ const debug$f = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
2868
2872
|
actions: ["assign readOnly"]
|
|
2869
2873
|
}
|
|
2870
2874
|
},
|
|
2871
|
-
|
|
2875
|
+
initial: "idle",
|
|
2872
2876
|
states: {
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2877
|
+
idle: {
|
|
2878
|
+
entry: [() => {
|
|
2879
|
+
debug$g("entry: syncing->idle");
|
|
2880
|
+
}],
|
|
2881
|
+
exit: [() => {
|
|
2882
|
+
debug$g("exit: syncing->idle");
|
|
2883
|
+
}],
|
|
2884
|
+
on: {
|
|
2885
|
+
"update value": [{
|
|
2886
|
+
guard: xstate.and(["is busy", "is new value"]),
|
|
2887
|
+
target: "busy",
|
|
2888
|
+
actions: ["assign pending value"]
|
|
2889
|
+
}, {
|
|
2890
|
+
guard: "is new value",
|
|
2891
|
+
target: "syncing",
|
|
2892
|
+
actions: ["assign pending value"]
|
|
2893
|
+
}, {
|
|
2894
|
+
guard: xstate.not("initial value synced"),
|
|
2895
|
+
actions: [() => {
|
|
2896
|
+
debug$g("no new value \u2013 setting initial value as synced");
|
|
2897
|
+
}, "assign initial value synced", "emit done syncing value"]
|
|
2898
|
+
}, {
|
|
2899
|
+
actions: [() => {
|
|
2900
|
+
debug$g("no new value and initial value already synced");
|
|
2901
|
+
}]
|
|
2902
|
+
}]
|
|
2903
|
+
}
|
|
2904
|
+
},
|
|
2905
|
+
busy: {
|
|
2906
|
+
entry: [() => {
|
|
2907
|
+
debug$g("entry: syncing->busy");
|
|
2908
|
+
}],
|
|
2909
|
+
exit: [() => {
|
|
2910
|
+
debug$g("exit: syncing->busy");
|
|
2911
|
+
}],
|
|
2912
|
+
after: {
|
|
2913
|
+
1e3: [{
|
|
2914
|
+
guard: "is busy",
|
|
2915
|
+
target: ".",
|
|
2916
|
+
reenter: !0,
|
|
2917
|
+
actions: [() => {
|
|
2918
|
+
debug$g("reenter: syncing->busy");
|
|
2919
|
+
}]
|
|
2920
|
+
}, {
|
|
2921
|
+
target: "syncing"
|
|
2922
|
+
}]
|
|
2923
|
+
},
|
|
2924
|
+
on: {
|
|
2925
|
+
"update value": [{
|
|
2926
|
+
guard: "is new value",
|
|
2927
|
+
actions: ["assign pending value"]
|
|
2928
|
+
}]
|
|
2897
2929
|
}
|
|
2898
2930
|
},
|
|
2899
2931
|
syncing: {
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
}]
|
|
2918
|
-
}
|
|
2919
|
-
},
|
|
2920
|
-
busy: {
|
|
2921
|
-
entry: [() => {
|
|
2922
|
-
debug$f("entry: syncing->busy");
|
|
2923
|
-
}],
|
|
2924
|
-
exit: [() => {
|
|
2925
|
-
debug$f("exit: syncing->busy");
|
|
2926
|
-
}],
|
|
2927
|
-
after: {
|
|
2928
|
-
1e3: [{
|
|
2929
|
-
guard: "is busy",
|
|
2930
|
-
target: ".",
|
|
2931
|
-
reenter: !0,
|
|
2932
|
-
actions: [() => {
|
|
2933
|
-
debug$f("reenter: syncing->busy");
|
|
2934
|
-
}]
|
|
2935
|
-
}, {
|
|
2936
|
-
target: "syncing"
|
|
2937
|
-
}]
|
|
2932
|
+
entry: [() => {
|
|
2933
|
+
debug$g("entry: syncing->syncing");
|
|
2934
|
+
}, "emit syncing value"],
|
|
2935
|
+
exit: [() => {
|
|
2936
|
+
debug$g("exit: syncing->syncing");
|
|
2937
|
+
}, "emit done syncing value"],
|
|
2938
|
+
invoke: {
|
|
2939
|
+
src: "sync value",
|
|
2940
|
+
id: "sync value",
|
|
2941
|
+
input: ({
|
|
2942
|
+
context
|
|
2943
|
+
}) => ({
|
|
2944
|
+
context: {
|
|
2945
|
+
keyGenerator: context.keyGenerator,
|
|
2946
|
+
previousValue: context.previousValue,
|
|
2947
|
+
readOnly: context.readOnly,
|
|
2948
|
+
schema: context.schema
|
|
2938
2949
|
},
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2950
|
+
slateEditor: context.slateEditor,
|
|
2951
|
+
streamBlocks: !context.initialValueSynced,
|
|
2952
|
+
value: context.pendingValue
|
|
2953
|
+
})
|
|
2954
|
+
},
|
|
2955
|
+
on: {
|
|
2956
|
+
"update value": {
|
|
2957
|
+
guard: "is new value",
|
|
2958
|
+
actions: ["assign pending value"]
|
|
2944
2959
|
},
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
}
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
slateEditor: context.slateEditor,
|
|
2970
|
-
streamBlocks: !context.initialValueSynced,
|
|
2971
|
-
value: context.pendingValue
|
|
2972
|
-
})
|
|
2973
|
-
},
|
|
2974
|
-
on: {
|
|
2975
|
-
"update value": {
|
|
2976
|
-
actions: ["assign pending value"]
|
|
2977
|
-
},
|
|
2978
|
-
patch: {
|
|
2979
|
-
actions: [xstate.emit(({
|
|
2980
|
-
event
|
|
2981
|
-
}) => event)]
|
|
2982
|
-
},
|
|
2983
|
-
"invalid value": {
|
|
2984
|
-
actions: [xstate.emit(({
|
|
2985
|
-
event
|
|
2986
|
-
}) => event)]
|
|
2987
|
-
},
|
|
2988
|
-
"value changed": {
|
|
2989
|
-
actions: [xstate.emit(({
|
|
2990
|
-
event
|
|
2991
|
-
}) => event)]
|
|
2992
|
-
},
|
|
2993
|
-
"done syncing": [{
|
|
2994
|
-
guard: "value changed while syncing",
|
|
2995
|
-
actions: ["assign previous value", "assign initial value synced"],
|
|
2996
|
-
target: "syncing",
|
|
2997
|
-
reenter: !0
|
|
2998
|
-
}, {
|
|
2999
|
-
target: "idle",
|
|
3000
|
-
actions: ["clear pending value", "assign previous value", "assign initial value synced"]
|
|
3001
|
-
}]
|
|
3002
|
-
}
|
|
3003
|
-
}
|
|
2960
|
+
patch: {
|
|
2961
|
+
actions: [xstate.emit(({
|
|
2962
|
+
event
|
|
2963
|
+
}) => event)]
|
|
2964
|
+
},
|
|
2965
|
+
"invalid value": {
|
|
2966
|
+
actions: [xstate.emit(({
|
|
2967
|
+
event
|
|
2968
|
+
}) => event)]
|
|
2969
|
+
},
|
|
2970
|
+
"value changed": {
|
|
2971
|
+
actions: [xstate.emit(({
|
|
2972
|
+
event
|
|
2973
|
+
}) => event)]
|
|
2974
|
+
},
|
|
2975
|
+
"done syncing": [{
|
|
2976
|
+
guard: "value changed while syncing",
|
|
2977
|
+
actions: ["assign previous value", "assign initial value synced"],
|
|
2978
|
+
target: "syncing",
|
|
2979
|
+
reenter: !0
|
|
2980
|
+
}, {
|
|
2981
|
+
target: "idle",
|
|
2982
|
+
actions: ["clear pending value", "assign previous value", "assign initial value synced"]
|
|
2983
|
+
}]
|
|
3004
2984
|
}
|
|
3005
2985
|
}
|
|
3006
2986
|
}
|
|
@@ -3014,7 +2994,7 @@ async function updateValue({
|
|
|
3014
2994
|
}) {
|
|
3015
2995
|
let isChanged = !1, isValid = !0;
|
|
3016
2996
|
const hadSelection = !!slateEditor.selection;
|
|
3017
|
-
if ((!value || value.length === 0) && (debug$
|
|
2997
|
+
if ((!value || value.length === 0) && (debug$g("Value is empty"), slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
3018
2998
|
withoutSaving(slateEditor, () => {
|
|
3019
2999
|
withoutPatching(slateEditor, () => {
|
|
3020
3000
|
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
@@ -3034,21 +3014,16 @@ async function updateValue({
|
|
|
3034
3014
|
const slateValueFromProps = toSlateValue(value, {
|
|
3035
3015
|
schemaTypes: context.schema
|
|
3036
3016
|
});
|
|
3037
|
-
await new Promise((resolve) => {
|
|
3017
|
+
streamBlocks ? await new Promise((resolve) => {
|
|
3038
3018
|
slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
3039
3019
|
withRemoteChanges(slateEditor, () => {
|
|
3040
3020
|
withoutPatching(slateEditor, async () => {
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
isChanged = !0;
|
|
3048
|
-
}
|
|
3049
|
-
for await (const [currentBlock, currentBlockIndex] of getBlocks({
|
|
3050
|
-
slateValue: slateValueFromProps,
|
|
3051
|
-
streamBlocks
|
|
3021
|
+
isChanged = removeExtraBlocks({
|
|
3022
|
+
slateEditor,
|
|
3023
|
+
slateValueFromProps
|
|
3024
|
+
});
|
|
3025
|
+
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
3026
|
+
slateValue: slateValueFromProps
|
|
3052
3027
|
})) {
|
|
3053
3028
|
const {
|
|
3054
3029
|
blockChanged,
|
|
@@ -3067,17 +3042,41 @@ async function updateValue({
|
|
|
3067
3042
|
});
|
|
3068
3043
|
});
|
|
3069
3044
|
});
|
|
3045
|
+
}) : slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
3046
|
+
withRemoteChanges(slateEditor, () => {
|
|
3047
|
+
withoutPatching(slateEditor, () => {
|
|
3048
|
+
isChanged = removeExtraBlocks({
|
|
3049
|
+
slateEditor,
|
|
3050
|
+
slateValueFromProps
|
|
3051
|
+
});
|
|
3052
|
+
let index = 0;
|
|
3053
|
+
for (const currentBlock of slateValueFromProps) {
|
|
3054
|
+
const {
|
|
3055
|
+
blockChanged,
|
|
3056
|
+
blockValid
|
|
3057
|
+
} = syncBlock({
|
|
3058
|
+
context,
|
|
3059
|
+
sendBack,
|
|
3060
|
+
block: currentBlock,
|
|
3061
|
+
index,
|
|
3062
|
+
slateEditor,
|
|
3063
|
+
value
|
|
3064
|
+
});
|
|
3065
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid, index++;
|
|
3066
|
+
}
|
|
3067
|
+
});
|
|
3068
|
+
});
|
|
3070
3069
|
});
|
|
3071
3070
|
}
|
|
3072
3071
|
if (!isValid) {
|
|
3073
|
-
debug$
|
|
3072
|
+
debug$g("Invalid value, returning"), sendBack({
|
|
3074
3073
|
type: "done syncing",
|
|
3075
3074
|
value
|
|
3076
3075
|
});
|
|
3077
3076
|
return;
|
|
3078
3077
|
}
|
|
3079
3078
|
if (isChanged) {
|
|
3080
|
-
debug$
|
|
3079
|
+
debug$g("Server value changed, syncing editor");
|
|
3081
3080
|
try {
|
|
3082
3081
|
slateEditor.onChange();
|
|
3083
3082
|
} catch (err) {
|
|
@@ -3105,19 +3104,33 @@ async function updateValue({
|
|
|
3105
3104
|
value
|
|
3106
3105
|
});
|
|
3107
3106
|
} else
|
|
3108
|
-
debug$
|
|
3107
|
+
debug$g("Server value and editor value is equal, no need to sync.");
|
|
3109
3108
|
sendBack({
|
|
3110
3109
|
type: "done syncing",
|
|
3111
3110
|
value
|
|
3112
3111
|
});
|
|
3113
3112
|
}
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3113
|
+
function removeExtraBlocks({
|
|
3114
|
+
slateEditor,
|
|
3115
|
+
slateValueFromProps
|
|
3116
|
+
}) {
|
|
3117
|
+
let isChanged = !1;
|
|
3118
|
+
const childrenLength = slateEditor.children.length;
|
|
3119
|
+
if (slateValueFromProps.length < childrenLength) {
|
|
3120
|
+
for (let i = childrenLength - 1; i > slateValueFromProps.length - 1; i--)
|
|
3121
|
+
slate.Transforms.removeNodes(slateEditor, {
|
|
3122
|
+
at: [i]
|
|
3123
|
+
});
|
|
3124
|
+
isChanged = !0;
|
|
3125
|
+
}
|
|
3126
|
+
return isChanged;
|
|
3127
|
+
}
|
|
3128
|
+
async function* getStreamedBlocks({
|
|
3129
|
+
slateValue
|
|
3117
3130
|
}) {
|
|
3118
3131
|
let index = 0;
|
|
3119
3132
|
for await (const block of slateValue)
|
|
3120
|
-
|
|
3133
|
+
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
3121
3134
|
}
|
|
3122
3135
|
function syncBlock({
|
|
3123
3136
|
context,
|
|
@@ -3139,7 +3152,7 @@ function syncBlock({
|
|
|
3139
3152
|
type: "patch",
|
|
3140
3153
|
patch
|
|
3141
3154
|
});
|
|
3142
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
3155
|
+
})), 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({
|
|
3143
3156
|
type: "invalid value",
|
|
3144
3157
|
resolution: validation.resolution,
|
|
3145
3158
|
value
|
|
@@ -3147,9 +3160,9 @@ function syncBlock({
|
|
|
3147
3160
|
}
|
|
3148
3161
|
if (!oldBlock && blockValid) {
|
|
3149
3162
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
3150
|
-
debug$
|
|
3163
|
+
debug$g.enabled && debug$g("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
3151
3164
|
at: [currentBlockIndex]
|
|
3152
|
-
}) : (debug$
|
|
3165
|
+
}) : (debug$g("Invalid", validation), sendBack({
|
|
3153
3166
|
type: "invalid value",
|
|
3154
3167
|
resolution: validation.resolution,
|
|
3155
3168
|
value
|
|
@@ -3177,14 +3190,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3177
3190
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
3178
3191
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
3179
3192
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
3180
|
-
childIndex > 0 && (debug$
|
|
3193
|
+
childIndex > 0 && (debug$g("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
3181
3194
|
at: [currentBlockIndex, childIndex]
|
|
3182
3195
|
}));
|
|
3183
3196
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
3184
3197
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
3185
3198
|
if (isChildChanged)
|
|
3186
3199
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
3187
|
-
debug$
|
|
3200
|
+
debug$g("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
3188
3201
|
at: path
|
|
3189
3202
|
});
|
|
3190
3203
|
const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -3201,23 +3214,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3201
3214
|
}
|
|
3202
3215
|
}), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
3203
3216
|
at: path
|
|
3204
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
3217
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$g("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
|
|
3205
3218
|
_key: VOID_CHILD_KEY
|
|
3206
3219
|
}, {
|
|
3207
3220
|
at: [...path, 0],
|
|
3208
3221
|
voids: !0
|
|
3209
3222
|
}));
|
|
3210
|
-
} else oldBlockChild ? (debug$
|
|
3223
|
+
} else oldBlockChild ? (debug$g("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
3211
3224
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3212
3225
|
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3213
3226
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3214
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
3227
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$g("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3215
3228
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3216
3229
|
}), slateEditor.onChange());
|
|
3217
3230
|
});
|
|
3218
3231
|
}
|
|
3219
3232
|
}
|
|
3220
|
-
const debug$
|
|
3233
|
+
const debug$f = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
3221
3234
|
function Synchronizer(props) {
|
|
3222
3235
|
const $ = reactCompilerRuntime.c(41), {
|
|
3223
3236
|
editorActor,
|
|
@@ -3313,14 +3326,14 @@ function Synchronizer(props) {
|
|
|
3313
3326
|
}, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), React.useEffect(t11, t12);
|
|
3314
3327
|
let t13, t14;
|
|
3315
3328
|
$[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
|
|
3316
|
-
debug$
|
|
3329
|
+
debug$f("Value from props changed, syncing new value"), syncActorRef.send({
|
|
3317
3330
|
type: "update value",
|
|
3318
3331
|
value: incomingValue
|
|
3319
3332
|
});
|
|
3320
3333
|
}, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
|
|
3321
3334
|
let t15;
|
|
3322
3335
|
$[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
|
|
3323
|
-
debug$
|
|
3336
|
+
debug$f("Subscribing to patch events");
|
|
3324
3337
|
const sub = editorActor.on("internal.patch", (event_1) => {
|
|
3325
3338
|
mutationActorRef.send({
|
|
3326
3339
|
...event_1,
|
|
@@ -3328,7 +3341,7 @@ function Synchronizer(props) {
|
|
|
3328
3341
|
});
|
|
3329
3342
|
});
|
|
3330
3343
|
return () => {
|
|
3331
|
-
debug$
|
|
3344
|
+
debug$f("Unsubscribing to patch events"), sub.unsubscribe();
|
|
3332
3345
|
};
|
|
3333
3346
|
}, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
|
|
3334
3347
|
let t16;
|
|
@@ -3343,11 +3356,11 @@ function _temp$1(s) {
|
|
|
3343
3356
|
return s.context.incomingValue;
|
|
3344
3357
|
}
|
|
3345
3358
|
Synchronizer.displayName = "Synchronizer";
|
|
3346
|
-
const debug$
|
|
3359
|
+
const debug$e = debugWithName("operationToPatches");
|
|
3347
3360
|
function createOperationToPatches(editorActor) {
|
|
3348
3361
|
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
3349
3362
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
3350
|
-
debug$
|
|
3363
|
+
debug$e.enabled && debug$e("Operation", JSON.stringify(operation, null, 2));
|
|
3351
3364
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
3352
3365
|
if (!block)
|
|
3353
3366
|
throw new Error("Could not find block");
|
|
@@ -3440,7 +3453,7 @@ function createOperationToPatches(editorActor) {
|
|
|
3440
3453
|
_key: block.children[operation.path[1] - 1]._key
|
|
3441
3454
|
}])];
|
|
3442
3455
|
}
|
|
3443
|
-
return debug$
|
|
3456
|
+
return debug$e("Something was inserted into a void block. Not producing editor patches."), [];
|
|
3444
3457
|
}
|
|
3445
3458
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
3446
3459
|
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -3498,9 +3511,9 @@ function createOperationToPatches(editorActor) {
|
|
|
3498
3511
|
_key: block._key
|
|
3499
3512
|
}, "children", {
|
|
3500
3513
|
_key: spanToRemove._key
|
|
3501
|
-
}])] : (debug$
|
|
3514
|
+
}])] : (debug$e("Span not found in editor trying to remove node"), []);
|
|
3502
3515
|
} else
|
|
3503
|
-
return debug$
|
|
3516
|
+
return debug$e("Not creating patch inside object block"), [];
|
|
3504
3517
|
}
|
|
3505
3518
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
3506
3519
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -3526,7 +3539,7 @@ function createOperationToPatches(editorActor) {
|
|
|
3526
3539
|
_key: removedSpan._key
|
|
3527
3540
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
3528
3541
|
} else
|
|
3529
|
-
debug$
|
|
3542
|
+
debug$e("Void nodes can't be merged, not creating any patches");
|
|
3530
3543
|
return patches$1;
|
|
3531
3544
|
}
|
|
3532
3545
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -3616,7 +3629,7 @@ function getNextSpan({
|
|
|
3616
3629
|
}
|
|
3617
3630
|
return nextSpan;
|
|
3618
3631
|
}
|
|
3619
|
-
const debug$
|
|
3632
|
+
const debug$d = debugWithName("plugin:withPortableTextMarkModel");
|
|
3620
3633
|
function createWithPortableTextMarkModel(editorActor) {
|
|
3621
3634
|
return function(editor) {
|
|
3622
3635
|
const {
|
|
@@ -3630,7 +3643,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3630
3643
|
for (const [child, childPath] of children) {
|
|
3631
3644
|
const nextNode = node.children[childPath[1] + 1];
|
|
3632
3645
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3633
|
-
debug$
|
|
3646
|
+
debug$d("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3634
3647
|
type: "normalizing"
|
|
3635
3648
|
}), slate.Transforms.mergeNodes(editor, {
|
|
3636
3649
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3643,7 +3656,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3643
3656
|
}
|
|
3644
3657
|
}
|
|
3645
3658
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3646
|
-
debug$
|
|
3659
|
+
debug$d("Adding .markDefs to block node"), editorActor.send({
|
|
3647
3660
|
type: "normalizing"
|
|
3648
3661
|
}), slate.Transforms.setNodes(editor, {
|
|
3649
3662
|
markDefs: []
|
|
@@ -3655,7 +3668,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3655
3668
|
return;
|
|
3656
3669
|
}
|
|
3657
3670
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3658
|
-
debug$
|
|
3671
|
+
debug$d("Adding .marks to span node"), editorActor.send({
|
|
3659
3672
|
type: "normalizing"
|
|
3660
3673
|
}), slate.Transforms.setNodes(editor, {
|
|
3661
3674
|
marks: []
|
|
@@ -3669,7 +3682,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3669
3682
|
if (editor.isTextSpan(node)) {
|
|
3670
3683
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3671
3684
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3672
|
-
debug$
|
|
3685
|
+
debug$d("Removing annotations from empty span node"), editorActor.send({
|
|
3673
3686
|
type: "normalizing"
|
|
3674
3687
|
}), slate.Transforms.setNodes(editor, {
|
|
3675
3688
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3687,7 +3700,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3687
3700
|
if (editor.isTextSpan(child)) {
|
|
3688
3701
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3689
3702
|
if (orphanedAnnotations.length > 0) {
|
|
3690
|
-
debug$
|
|
3703
|
+
debug$d("Removing orphaned annotations from span node"), editorActor.send({
|
|
3691
3704
|
type: "normalizing"
|
|
3692
3705
|
}), slate.Transforms.setNodes(editor, {
|
|
3693
3706
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3705,7 +3718,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3705
3718
|
if (editor.isTextBlock(block)) {
|
|
3706
3719
|
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));
|
|
3707
3720
|
if (orphanedAnnotations.length > 0) {
|
|
3708
|
-
debug$
|
|
3721
|
+
debug$d("Removing orphaned annotations from span node"), editorActor.send({
|
|
3709
3722
|
type: "normalizing"
|
|
3710
3723
|
}), slate.Transforms.setNodes(editor, {
|
|
3711
3724
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3723,7 +3736,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3723
3736
|
for (const markDef of markDefs)
|
|
3724
3737
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3725
3738
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3726
|
-
debug$
|
|
3739
|
+
debug$d("Removing duplicate markDefs"), editorActor.send({
|
|
3727
3740
|
type: "normalizing"
|
|
3728
3741
|
}), slate.Transforms.setNodes(editor, {
|
|
3729
3742
|
markDefs: newMarkDefs
|
|
@@ -3738,7 +3751,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3738
3751
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3739
3752
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3740
3753
|
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
3741
|
-
debug$
|
|
3754
|
+
debug$d("Removing markDef not in use"), editorActor.send({
|
|
3742
3755
|
type: "normalizing"
|
|
3743
3756
|
}), slate.Transforms.setNodes(editor, {
|
|
3744
3757
|
markDefs: newMarkDefs
|
|
@@ -3958,7 +3971,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3958
3971
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
3959
3972
|
if (editor.isTextBlock(targetBlock)) {
|
|
3960
3973
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
3961
|
-
debug$
|
|
3974
|
+
debug$d("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
|
|
3962
3975
|
markDefs: newMarkDefs
|
|
3963
3976
|
}, {
|
|
3964
3977
|
at: targetPath,
|
|
@@ -5182,13 +5195,13 @@ function createWithObjectKeys(editorActor) {
|
|
|
5182
5195
|
}, editor;
|
|
5183
5196
|
};
|
|
5184
5197
|
}
|
|
5185
|
-
const debug$
|
|
5198
|
+
const debug$c = debugWithName("applyPatches"), debugVerbose = debug$c.enabled && !0;
|
|
5186
5199
|
function createApplyPatch(schema2) {
|
|
5187
5200
|
return (editor, patch) => {
|
|
5188
5201
|
let changed = !1;
|
|
5189
|
-
debugVerbose && (debug$
|
|
5202
|
+
debugVerbose && (debug$c(`
|
|
5190
5203
|
|
|
5191
|
-
NEW PATCH =============================================================`), debug$
|
|
5204
|
+
NEW PATCH =============================================================`), debug$c(JSON.stringify(patch, null, 2)));
|
|
5192
5205
|
try {
|
|
5193
5206
|
switch (patch.type) {
|
|
5194
5207
|
case "insert":
|
|
@@ -5204,7 +5217,7 @@ NEW PATCH =============================================================`), debug
|
|
|
5204
5217
|
changed = diffMatchPatch(editor, patch);
|
|
5205
5218
|
break;
|
|
5206
5219
|
default:
|
|
5207
|
-
debug$
|
|
5220
|
+
debug$c("Unhandled patch", patch.type);
|
|
5208
5221
|
}
|
|
5209
5222
|
} catch (err) {
|
|
5210
5223
|
console.error(err);
|
|
@@ -5219,9 +5232,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
5219
5232
|
childPath
|
|
5220
5233
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5221
5234
|
if (!block)
|
|
5222
|
-
return debug$
|
|
5235
|
+
return debug$c("Block not found"), !1;
|
|
5223
5236
|
if (!child || !childPath)
|
|
5224
|
-
return debug$
|
|
5237
|
+
return debug$c("Child not found"), !1;
|
|
5225
5238
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
5226
5239
|
return !1;
|
|
5227
5240
|
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
|
|
@@ -5251,9 +5264,9 @@ function insertPatch(editor, patch, schema2) {
|
|
|
5251
5264
|
childPath: targetChildPath
|
|
5252
5265
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5253
5266
|
if (!targetBlock || !targetBlockPath)
|
|
5254
|
-
return debug$
|
|
5267
|
+
return debug$c("Block not found"), !1;
|
|
5255
5268
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
5256
|
-
return debug$
|
|
5269
|
+
return debug$c("Ignoring patch targeting void value"), !1;
|
|
5257
5270
|
if (patch.path.length === 1) {
|
|
5258
5271
|
const {
|
|
5259
5272
|
items: items2,
|
|
@@ -5261,7 +5274,7 @@ function insertPatch(editor, patch, schema2) {
|
|
|
5261
5274
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
5262
5275
|
schemaTypes: schema2
|
|
5263
5276
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
5264
|
-
return debug$
|
|
5277
|
+
return debug$c(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
|
|
5265
5278
|
at: [normalizedIdx2]
|
|
5266
5279
|
}), debugState(editor, "after"), !0;
|
|
5267
5280
|
}
|
|
@@ -5270,14 +5283,14 @@ function insertPatch(editor, patch, schema2) {
|
|
|
5270
5283
|
position
|
|
5271
5284
|
} = patch;
|
|
5272
5285
|
if (!targetChild || !targetChildPath)
|
|
5273
|
-
return debug$
|
|
5286
|
+
return debug$c("Child not found"), !1;
|
|
5274
5287
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
5275
5288
|
...targetBlock,
|
|
5276
5289
|
children: items
|
|
5277
5290
|
}], {
|
|
5278
5291
|
schemaTypes: schema2
|
|
5279
5292
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
5280
|
-
return debug$
|
|
5293
|
+
return debug$c(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
5281
5294
|
at: childInsertPath
|
|
5282
5295
|
}), debugState(editor, "after"), !0;
|
|
5283
5296
|
}
|
|
@@ -5291,14 +5304,14 @@ function setPatch(editor, patch) {
|
|
|
5291
5304
|
childPath
|
|
5292
5305
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5293
5306
|
if (!block)
|
|
5294
|
-
return debug$
|
|
5307
|
+
return debug$c("Block not found"), !1;
|
|
5295
5308
|
const isTextBlock = editor.isTextBlock(block);
|
|
5296
5309
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
5297
|
-
return debug$
|
|
5310
|
+
return debug$c("Ignoring setting void value"), !1;
|
|
5298
5311
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
5299
5312
|
if (slate.Text.isText(value) && slate.Text.isText(child)) {
|
|
5300
5313
|
const newText = child.text;
|
|
5301
|
-
value.text !== newText && (debug$
|
|
5314
|
+
value.text !== newText && (debug$c("Setting text property"), editor.apply({
|
|
5302
5315
|
type: "remove_text",
|
|
5303
5316
|
path: childPath,
|
|
5304
5317
|
offset: 0,
|
|
@@ -5310,7 +5323,7 @@ function setPatch(editor, patch) {
|
|
|
5310
5323
|
text: value.text
|
|
5311
5324
|
}), editor.onChange());
|
|
5312
5325
|
} else
|
|
5313
|
-
debug$
|
|
5326
|
+
debug$c("Setting non-text property"), editor.apply({
|
|
5314
5327
|
type: "set_node",
|
|
5315
5328
|
path: childPath,
|
|
5316
5329
|
properties: {},
|
|
@@ -5318,7 +5331,7 @@ function setPatch(editor, patch) {
|
|
|
5318
5331
|
});
|
|
5319
5332
|
return !0;
|
|
5320
5333
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
5321
|
-
debug$
|
|
5334
|
+
debug$c("Setting block property");
|
|
5322
5335
|
const {
|
|
5323
5336
|
children,
|
|
5324
5337
|
...nextRest
|
|
@@ -5335,7 +5348,7 @@ function setPatch(editor, patch) {
|
|
|
5335
5348
|
...prevRest
|
|
5336
5349
|
},
|
|
5337
5350
|
newProperties: nextRest
|
|
5338
|
-
}), debug$
|
|
5351
|
+
}), debug$c("Setting children"), block.children.forEach((c, cIndex) => {
|
|
5339
5352
|
editor.apply({
|
|
5340
5353
|
type: "remove_node",
|
|
5341
5354
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -5366,7 +5379,7 @@ function setPatch(editor, patch) {
|
|
|
5366
5379
|
}
|
|
5367
5380
|
function unsetPatch(editor, patch) {
|
|
5368
5381
|
if (patch.path.length === 0) {
|
|
5369
|
-
debug$
|
|
5382
|
+
debug$c("Removing everything"), debugState(editor, "before");
|
|
5370
5383
|
const previousSelection = editor.selection;
|
|
5371
5384
|
return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
5372
5385
|
slate.Transforms.removeNodes(editor, {
|
|
@@ -5393,13 +5406,13 @@ function unsetPatch(editor, patch) {
|
|
|
5393
5406
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5394
5407
|
if (patch.path.length === 1) {
|
|
5395
5408
|
if (!block || !blockPath)
|
|
5396
|
-
return debug$
|
|
5409
|
+
return debug$c("Block not found"), !1;
|
|
5397
5410
|
const blockIndex = blockPath[0];
|
|
5398
|
-
return debug$
|
|
5411
|
+
return debug$c(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
|
|
5399
5412
|
at: [blockIndex]
|
|
5400
5413
|
}), debugState(editor, "after"), !0;
|
|
5401
5414
|
}
|
|
5402
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
5415
|
+
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)}`), slate.Transforms.removeNodes(editor, {
|
|
5403
5416
|
at: childPath
|
|
5404
5417
|
}), debugState(editor, "after"), !0) : !1;
|
|
5405
5418
|
}
|
|
@@ -5407,7 +5420,7 @@ function isKeyedSegment(segment) {
|
|
|
5407
5420
|
return typeof segment == "object" && "_key" in segment;
|
|
5408
5421
|
}
|
|
5409
5422
|
function debugState(editor, stateName) {
|
|
5410
|
-
debugVerbose && (debug$
|
|
5423
|
+
debugVerbose && (debug$c(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$c(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
5411
5424
|
}
|
|
5412
5425
|
function findBlockFromPath(editor, path) {
|
|
5413
5426
|
let blockIndex = -1;
|
|
@@ -5449,7 +5462,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
5449
5462
|
childPath: void 0
|
|
5450
5463
|
};
|
|
5451
5464
|
}
|
|
5452
|
-
const debug$
|
|
5465
|
+
const debug$b = debugWithName("plugin:withPatches");
|
|
5453
5466
|
function createWithPatches({
|
|
5454
5467
|
editorActor,
|
|
5455
5468
|
patchFunctions,
|
|
@@ -5474,7 +5487,7 @@ function createWithPatches({
|
|
|
5474
5487
|
withoutPatching(editor, () => {
|
|
5475
5488
|
withoutSaving(editor, () => {
|
|
5476
5489
|
for (const patch of patches2) {
|
|
5477
|
-
debug$
|
|
5490
|
+
debug$b.enabled && debug$b(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
5478
5491
|
try {
|
|
5479
5492
|
changed = applyPatch(editor, patch);
|
|
5480
5493
|
} catch (error) {
|
|
@@ -5492,10 +5505,10 @@ function createWithPatches({
|
|
|
5492
5505
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
5493
5506
|
};
|
|
5494
5507
|
return subscriptions.push(() => {
|
|
5495
|
-
debug$
|
|
5508
|
+
debug$b("Subscribing to remote patches");
|
|
5496
5509
|
const sub = editorActor.on("patches", handlePatches);
|
|
5497
5510
|
return () => {
|
|
5498
|
-
debug$
|
|
5511
|
+
debug$b("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
5499
5512
|
};
|
|
5500
5513
|
}), editor.apply = (operation) => {
|
|
5501
5514
|
let patches$1 = [];
|
|
@@ -5549,7 +5562,7 @@ function createWithPatches({
|
|
|
5549
5562
|
}, editor;
|
|
5550
5563
|
};
|
|
5551
5564
|
}
|
|
5552
|
-
const debug$
|
|
5565
|
+
const debug$a = debugWithName("plugin:withPlaceholderBlock");
|
|
5553
5566
|
function createWithPlaceholderBlock(editorActor) {
|
|
5554
5567
|
return function(editor) {
|
|
5555
5568
|
const {
|
|
@@ -5574,7 +5587,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
5574
5587
|
const node = op.node;
|
|
5575
5588
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
5576
5589
|
const nextPath = slate.Path.next(op.path);
|
|
5577
|
-
editor.children[nextPath[0]] || (debug$
|
|
5590
|
+
editor.children[nextPath[0]] || (debug$a("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
5578
5591
|
decorators: []
|
|
5579
5592
|
})));
|
|
5580
5593
|
}
|
|
@@ -5583,7 +5596,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
5583
5596
|
}, editor;
|
|
5584
5597
|
};
|
|
5585
5598
|
}
|
|
5586
|
-
const debug$
|
|
5599
|
+
const debug$9 = debugWithName("plugin:withPortableTextBlockStyle");
|
|
5587
5600
|
function createWithPortableTextBlockStyle(editorActor) {
|
|
5588
5601
|
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
5589
5602
|
return function(editor) {
|
|
@@ -5596,7 +5609,7 @@ function createWithPortableTextBlockStyle(editorActor) {
|
|
|
5596
5609
|
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !slate.Path.equals(path, op.path)) {
|
|
5597
5610
|
const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
5598
5611
|
if (slate.Text.isText(child) && child.text === "") {
|
|
5599
|
-
debug$
|
|
5612
|
+
debug$9(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
5600
5613
|
type: "normalizing"
|
|
5601
5614
|
}), slate.Transforms.setNodes(editor, {
|
|
5602
5615
|
style: defaultStyle
|
|
@@ -5647,7 +5660,7 @@ function createWithPortableTextSelections(editorActor) {
|
|
|
5647
5660
|
}, editor;
|
|
5648
5661
|
};
|
|
5649
5662
|
}
|
|
5650
|
-
const debug$
|
|
5663
|
+
const debug$8 = debugWithName("plugin:withSchemaTypes");
|
|
5651
5664
|
function createWithSchemaTypes({
|
|
5652
5665
|
editorActor
|
|
5653
5666
|
}) {
|
|
@@ -5659,7 +5672,7 @@ function createWithSchemaTypes({
|
|
|
5659
5672
|
return editor.normalizeNode = (entry) => {
|
|
5660
5673
|
const [node, path] = entry;
|
|
5661
5674
|
if (node._type === void 0 && path.length === 2) {
|
|
5662
|
-
debug$
|
|
5675
|
+
debug$8("Setting span type on text node without a type");
|
|
5663
5676
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
5664
5677
|
editorActor.send({
|
|
5665
5678
|
type: "normalizing"
|
|
@@ -5675,7 +5688,7 @@ function createWithSchemaTypes({
|
|
|
5675
5688
|
return;
|
|
5676
5689
|
}
|
|
5677
5690
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
5678
|
-
debug$
|
|
5691
|
+
debug$8("Setting missing key on child node without a key");
|
|
5679
5692
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
5680
5693
|
editorActor.send({
|
|
5681
5694
|
type: "normalizing"
|
|
@@ -5736,12 +5749,12 @@ const withPlugins = (editor, options) => {
|
|
|
5736
5749
|
editorActor
|
|
5737
5750
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5738
5751
|
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5739
|
-
}, debug$
|
|
5752
|
+
}, debug$7 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
5740
5753
|
function createSlateEditor(config) {
|
|
5741
5754
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
5742
5755
|
if (existingSlateEditor)
|
|
5743
|
-
return debug$
|
|
5744
|
-
debug$
|
|
5756
|
+
return debug$7("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
5757
|
+
debug$7("Creating new Slate editor instance", config.editorActor.id);
|
|
5745
5758
|
const unsubscriptions = [], subscriptions = [], instance = withPlugins(slateReact.withReact(slate.createEditor()), {
|
|
5746
5759
|
editorActor: config.editorActor,
|
|
5747
5760
|
subscriptions
|
|
@@ -6028,7 +6041,7 @@ function getEditorSnapshot({
|
|
|
6028
6041
|
}
|
|
6029
6042
|
};
|
|
6030
6043
|
}
|
|
6031
|
-
const debug$
|
|
6044
|
+
const debug$6 = debugWithName("API:editable");
|
|
6032
6045
|
function createEditableAPI(editor, editorActor) {
|
|
6033
6046
|
const types2 = editorActor.getSnapshot().context.schema;
|
|
6034
6047
|
return {
|
|
@@ -6161,7 +6174,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
6161
6174
|
}], {
|
|
6162
6175
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
6163
6176
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
6164
|
-
return isSpanNode && focusNode._type !== types2.span.name && (debug$
|
|
6177
|
+
return isSpanNode && focusNode._type !== types2.span.name && (debug$6("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
6165
6178
|
distance: 1,
|
|
6166
6179
|
unit: "character"
|
|
6167
6180
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
@@ -6306,18 +6319,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
6306
6319
|
throw new Error("Invalid range");
|
|
6307
6320
|
if (range) {
|
|
6308
6321
|
if (!options?.mode || options?.mode === "selected") {
|
|
6309
|
-
debug$
|
|
6322
|
+
debug$6("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
6310
6323
|
at: range,
|
|
6311
6324
|
hanging: !0,
|
|
6312
6325
|
voids: !0
|
|
6313
6326
|
}), editor.onChange();
|
|
6314
6327
|
return;
|
|
6315
6328
|
}
|
|
6316
|
-
options?.mode === "blocks" && (debug$
|
|
6329
|
+
options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
6317
6330
|
at: range,
|
|
6318
6331
|
voids: !0,
|
|
6319
6332
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
6320
|
-
})), options?.mode === "children" && (debug$
|
|
6333
|
+
})), options?.mode === "children" && (debug$6("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
6321
6334
|
at: range,
|
|
6322
6335
|
voids: !0,
|
|
6323
6336
|
match: (node) => node._type === types2.span.name || // Text children
|
|
@@ -8076,7 +8089,7 @@ function isNativeBehaviorEvent(event) {
|
|
|
8076
8089
|
function isCustomBehaviorEvent(event) {
|
|
8077
8090
|
return event.type.startsWith("custom.");
|
|
8078
8091
|
}
|
|
8079
|
-
const debug$
|
|
8092
|
+
const debug$5 = debugWithName("behaviors:event");
|
|
8080
8093
|
function eventCategory(event) {
|
|
8081
8094
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
8082
8095
|
}
|
|
@@ -8091,7 +8104,7 @@ function performEvent({
|
|
|
8091
8104
|
getSnapshot,
|
|
8092
8105
|
nativeEvent
|
|
8093
8106
|
}) {
|
|
8094
|
-
debug$
|
|
8107
|
+
debug$5(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
8095
8108
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
8096
8109
|
if (behavior.on === "*")
|
|
8097
8110
|
return !0;
|
|
@@ -8100,7 +8113,7 @@ function performEvent({
|
|
|
8100
8113
|
});
|
|
8101
8114
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
8102
8115
|
nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
8103
|
-
debug$
|
|
8116
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
8104
8117
|
context: {
|
|
8105
8118
|
keyGenerator,
|
|
8106
8119
|
schema: schema2
|
|
@@ -8243,7 +8256,7 @@ function performEvent({
|
|
|
8243
8256
|
}
|
|
8244
8257
|
}
|
|
8245
8258
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
8246
|
-
debug$
|
|
8259
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
8247
8260
|
context: {
|
|
8248
8261
|
keyGenerator,
|
|
8249
8262
|
schema: schema2
|
|
@@ -8331,7 +8344,7 @@ function createEditorSnapshot({
|
|
|
8331
8344
|
}
|
|
8332
8345
|
};
|
|
8333
8346
|
}
|
|
8334
|
-
const editorMachine = xstate.setup({
|
|
8347
|
+
const debug$4 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
8335
8348
|
types: {
|
|
8336
8349
|
context: {},
|
|
8337
8350
|
events: {},
|
|
@@ -8612,6 +8625,12 @@ const editorMachine = xstate.setup({
|
|
|
8612
8625
|
},
|
|
8613
8626
|
states: {
|
|
8614
8627
|
"determine initial edit mode": {
|
|
8628
|
+
entry: [() => {
|
|
8629
|
+
debug$4("entry: edit mode->read only->determine initial edit mode");
|
|
8630
|
+
}],
|
|
8631
|
+
exit: [() => {
|
|
8632
|
+
debug$4("exit: edit mode->read only->determine initial edit mode");
|
|
8633
|
+
}],
|
|
8615
8634
|
on: {
|
|
8616
8635
|
"done syncing value": [{
|
|
8617
8636
|
target: "#editor.edit mode.read only.read only",
|
|
@@ -8624,6 +8643,12 @@ const editorMachine = xstate.setup({
|
|
|
8624
8643
|
}
|
|
8625
8644
|
},
|
|
8626
8645
|
"read only": {
|
|
8646
|
+
entry: [() => {
|
|
8647
|
+
debug$4("entry: edit mode->read only->read only");
|
|
8648
|
+
}],
|
|
8649
|
+
exit: [() => {
|
|
8650
|
+
debug$4("exit: edit mode->read only->read only");
|
|
8651
|
+
}],
|
|
8627
8652
|
on: {
|
|
8628
8653
|
"update readOnly": {
|
|
8629
8654
|
guard: ({
|
|
@@ -8663,6 +8688,12 @@ const editorMachine = xstate.setup({
|
|
|
8663
8688
|
initial: "idle",
|
|
8664
8689
|
states: {
|
|
8665
8690
|
idle: {
|
|
8691
|
+
entry: [() => {
|
|
8692
|
+
debug$4("entry: edit mode->editable->idle");
|
|
8693
|
+
}],
|
|
8694
|
+
exit: [() => {
|
|
8695
|
+
debug$4("exit: edit mode->editable-idle");
|
|
8696
|
+
}],
|
|
8666
8697
|
on: {
|
|
8667
8698
|
dragstart: {
|
|
8668
8699
|
actions: [xstate.assign({
|
|
@@ -8681,6 +8712,12 @@ const editorMachine = xstate.setup({
|
|
|
8681
8712
|
initial: "checking if busy",
|
|
8682
8713
|
states: {
|
|
8683
8714
|
"checking if busy": {
|
|
8715
|
+
entry: [() => {
|
|
8716
|
+
debug$4("entry: edit mode->editable->focusing->checking if busy");
|
|
8717
|
+
}],
|
|
8718
|
+
exit: [() => {
|
|
8719
|
+
debug$4("exit: edit mode->editable->focusing->checking if busy");
|
|
8720
|
+
}],
|
|
8684
8721
|
always: [{
|
|
8685
8722
|
guard: "slate is busy",
|
|
8686
8723
|
target: "busy"
|
|
@@ -8690,6 +8727,12 @@ const editorMachine = xstate.setup({
|
|
|
8690
8727
|
}]
|
|
8691
8728
|
},
|
|
8692
8729
|
busy: {
|
|
8730
|
+
entry: [() => {
|
|
8731
|
+
debug$4("entry: edit mode->editable->focusing-busy");
|
|
8732
|
+
}],
|
|
8733
|
+
exit: [() => {
|
|
8734
|
+
debug$4("exit: edit mode->editable->focusing->busy");
|
|
8735
|
+
}],
|
|
8693
8736
|
after: {
|
|
8694
8737
|
10: {
|
|
8695
8738
|
target: "checking if busy"
|
|
@@ -8699,7 +8742,12 @@ const editorMachine = xstate.setup({
|
|
|
8699
8742
|
}
|
|
8700
8743
|
},
|
|
8701
8744
|
"dragging internally": {
|
|
8702
|
-
|
|
8745
|
+
entry: [() => {
|
|
8746
|
+
debug$4("entry: edit mode->editable->dragging internally");
|
|
8747
|
+
}],
|
|
8748
|
+
exit: [() => {
|
|
8749
|
+
debug$4("exit: edit mode->editable->dragging internally");
|
|
8750
|
+
}, ({
|
|
8703
8751
|
context
|
|
8704
8752
|
}) => {
|
|
8705
8753
|
if (context.internalDrag?.ghost)
|
|
@@ -8729,7 +8777,12 @@ const editorMachine = xstate.setup({
|
|
|
8729
8777
|
initial: "setting up",
|
|
8730
8778
|
states: {
|
|
8731
8779
|
"setting up": {
|
|
8732
|
-
|
|
8780
|
+
entry: [() => {
|
|
8781
|
+
debug$4("entry: setup->setting up");
|
|
8782
|
+
}],
|
|
8783
|
+
exit: [() => {
|
|
8784
|
+
debug$4("exit: setup->setting up");
|
|
8785
|
+
}, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
8733
8786
|
on: {
|
|
8734
8787
|
"internal.patch": {
|
|
8735
8788
|
actions: "defer event"
|
|
@@ -8752,6 +8805,12 @@ const editorMachine = xstate.setup({
|
|
|
8752
8805
|
initial: "idle",
|
|
8753
8806
|
states: {
|
|
8754
8807
|
idle: {
|
|
8808
|
+
entry: [() => {
|
|
8809
|
+
debug$4("entry: setup->set up->value sync->idle");
|
|
8810
|
+
}],
|
|
8811
|
+
exit: [() => {
|
|
8812
|
+
debug$4("exit: setup->set up->value sync->idle");
|
|
8813
|
+
}],
|
|
8755
8814
|
on: {
|
|
8756
8815
|
patches: {
|
|
8757
8816
|
actions: [xstate.emit(({
|
|
@@ -8764,7 +8823,12 @@ const editorMachine = xstate.setup({
|
|
|
8764
8823
|
}
|
|
8765
8824
|
},
|
|
8766
8825
|
"syncing value": {
|
|
8767
|
-
|
|
8826
|
+
entry: [() => {
|
|
8827
|
+
debug$4("entry: setup->set up->value sync->syncing value");
|
|
8828
|
+
}],
|
|
8829
|
+
exit: [() => {
|
|
8830
|
+
debug$4("exit: setup->set up->value sync->syncing value");
|
|
8831
|
+
}, "emit pending incoming patches", "clear pending incoming patches"],
|
|
8768
8832
|
on: {
|
|
8769
8833
|
patches: {
|
|
8770
8834
|
actions: ["defer incoming patches"]
|
|
@@ -8783,6 +8847,12 @@ const editorMachine = xstate.setup({
|
|
|
8783
8847
|
initial: "idle",
|
|
8784
8848
|
states: {
|
|
8785
8849
|
idle: {
|
|
8850
|
+
entry: [() => {
|
|
8851
|
+
debug$4("entry: setup->set up->writing->pristine->idle");
|
|
8852
|
+
}],
|
|
8853
|
+
exit: [() => {
|
|
8854
|
+
debug$4("exit: setup->set up->writing->pristine->idle");
|
|
8855
|
+
}],
|
|
8786
8856
|
on: {
|
|
8787
8857
|
normalizing: {
|
|
8788
8858
|
target: "normalizing"
|
|
@@ -8798,6 +8868,12 @@ const editorMachine = xstate.setup({
|
|
|
8798
8868
|
}
|
|
8799
8869
|
},
|
|
8800
8870
|
normalizing: {
|
|
8871
|
+
entry: [() => {
|
|
8872
|
+
debug$4("entry: setup->set up->writing->pristine->normalizing");
|
|
8873
|
+
}],
|
|
8874
|
+
exit: [() => {
|
|
8875
|
+
debug$4("exit: setup->set up->writing->pristine->normalizing");
|
|
8876
|
+
}],
|
|
8801
8877
|
on: {
|
|
8802
8878
|
"done normalizing": {
|
|
8803
8879
|
target: "idle"
|
|
@@ -8813,7 +8889,12 @@ const editorMachine = xstate.setup({
|
|
|
8813
8889
|
}
|
|
8814
8890
|
},
|
|
8815
8891
|
dirty: {
|
|
8816
|
-
entry: [
|
|
8892
|
+
entry: [() => {
|
|
8893
|
+
debug$4("entry: setup->set up->writing->dirty");
|
|
8894
|
+
}, "emit pending events", "clear pending events"],
|
|
8895
|
+
exit: [() => {
|
|
8896
|
+
debug$4("exit: setup->set up->writing->dirty");
|
|
8897
|
+
}],
|
|
8817
8898
|
on: {
|
|
8818
8899
|
"internal.patch": {
|
|
8819
8900
|
actions: "emit patch event"
|
|
@@ -9878,12 +9959,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
9878
9959
|
type: "range decorations updated",
|
|
9879
9960
|
rangeDecorations: rangeDecorations ?? []
|
|
9880
9961
|
});
|
|
9881
|
-
}, [rangeDecorationsActor, rangeDecorations]), React.useMemo(() =>
|
|
9882
|
-
if (readOnly)
|
|
9883
|
-
return debug("Editable is in read only mode"), slateEditor;
|
|
9884
|
-
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
9885
|
-
return debug("Editable is in edit mode"), withHotKeys(slateEditor);
|
|
9886
|
-
}, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
9962
|
+
}, [rangeDecorationsActor, rangeDecorations]), React.useMemo(() => readOnly ? slateEditor : createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor), [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
9887
9963
|
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(RenderElement, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, spellCheck }), [spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = React.useCallback((leafProps) => /* @__PURE__ */ jsxRuntime.jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), [readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder]), renderText = React.useCallback((props_0) => /* @__PURE__ */ jsxRuntime.jsx(RenderText, { ...props_0 }), []), restoreSelectionFromProps = React.useCallback(() => {
|
|
9888
9964
|
if (propsSelection) {
|
|
9889
9965
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|