@portabletext/editor 1.49.4 → 1.49.6
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 +294 -250
- 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 +295 -251
- 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 +154 -171
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);
|
|
@@ -3037,28 +3017,29 @@ async function updateValue({
|
|
|
3037
3017
|
streamBlocks ? await new Promise((resolve) => {
|
|
3038
3018
|
slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
3039
3019
|
withRemoteChanges(slateEditor, () => {
|
|
3040
|
-
withoutPatching(slateEditor,
|
|
3020
|
+
withoutPatching(slateEditor, () => {
|
|
3041
3021
|
isChanged = removeExtraBlocks({
|
|
3042
3022
|
slateEditor,
|
|
3043
3023
|
slateValueFromProps
|
|
3044
|
-
})
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3024
|
+
}), (async () => {
|
|
3025
|
+
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
3026
|
+
slateValue: slateValueFromProps
|
|
3027
|
+
})) {
|
|
3028
|
+
const {
|
|
3029
|
+
blockChanged,
|
|
3030
|
+
blockValid
|
|
3031
|
+
} = syncBlock({
|
|
3032
|
+
context,
|
|
3033
|
+
sendBack,
|
|
3034
|
+
block: currentBlock,
|
|
3035
|
+
index: currentBlockIndex,
|
|
3036
|
+
slateEditor,
|
|
3037
|
+
value
|
|
3038
|
+
});
|
|
3039
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
3040
|
+
}
|
|
3041
|
+
resolve();
|
|
3042
|
+
})();
|
|
3062
3043
|
});
|
|
3063
3044
|
});
|
|
3064
3045
|
});
|
|
@@ -3089,14 +3070,14 @@ async function updateValue({
|
|
|
3089
3070
|
});
|
|
3090
3071
|
}
|
|
3091
3072
|
if (!isValid) {
|
|
3092
|
-
debug$
|
|
3073
|
+
debug$g("Invalid value, returning"), sendBack({
|
|
3093
3074
|
type: "done syncing",
|
|
3094
3075
|
value
|
|
3095
3076
|
});
|
|
3096
3077
|
return;
|
|
3097
3078
|
}
|
|
3098
3079
|
if (isChanged) {
|
|
3099
|
-
debug$
|
|
3080
|
+
debug$g("Server value changed, syncing editor");
|
|
3100
3081
|
try {
|
|
3101
3082
|
slateEditor.onChange();
|
|
3102
3083
|
} catch (err) {
|
|
@@ -3124,7 +3105,7 @@ async function updateValue({
|
|
|
3124
3105
|
value
|
|
3125
3106
|
});
|
|
3126
3107
|
} else
|
|
3127
|
-
debug$
|
|
3108
|
+
debug$g("Server value and editor value is equal, no need to sync.");
|
|
3128
3109
|
sendBack({
|
|
3129
3110
|
type: "done syncing",
|
|
3130
3111
|
value
|
|
@@ -3172,7 +3153,7 @@ function syncBlock({
|
|
|
3172
3153
|
type: "patch",
|
|
3173
3154
|
patch
|
|
3174
3155
|
});
|
|
3175
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
3156
|
+
})), 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({
|
|
3176
3157
|
type: "invalid value",
|
|
3177
3158
|
resolution: validation.resolution,
|
|
3178
3159
|
value
|
|
@@ -3180,9 +3161,9 @@ function syncBlock({
|
|
|
3180
3161
|
}
|
|
3181
3162
|
if (!oldBlock && blockValid) {
|
|
3182
3163
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
3183
|
-
debug$
|
|
3164
|
+
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, {
|
|
3184
3165
|
at: [currentBlockIndex]
|
|
3185
|
-
}) : (debug$
|
|
3166
|
+
}) : (debug$g("Invalid", validation), sendBack({
|
|
3186
3167
|
type: "invalid value",
|
|
3187
3168
|
resolution: validation.resolution,
|
|
3188
3169
|
value
|
|
@@ -3210,14 +3191,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3210
3191
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
3211
3192
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
3212
3193
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
3213
|
-
childIndex > 0 && (debug$
|
|
3194
|
+
childIndex > 0 && (debug$g("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
3214
3195
|
at: [currentBlockIndex, childIndex]
|
|
3215
3196
|
}));
|
|
3216
3197
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
3217
3198
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
3218
3199
|
if (isChildChanged)
|
|
3219
3200
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
3220
|
-
debug$
|
|
3201
|
+
debug$g("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
3221
3202
|
at: path
|
|
3222
3203
|
});
|
|
3223
3204
|
const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -3234,23 +3215,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3234
3215
|
}
|
|
3235
3216
|
}), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
3236
3217
|
at: path
|
|
3237
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
3218
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$g("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(slateEditor, {
|
|
3238
3219
|
_key: VOID_CHILD_KEY
|
|
3239
3220
|
}, {
|
|
3240
3221
|
at: [...path, 0],
|
|
3241
3222
|
voids: !0
|
|
3242
3223
|
}));
|
|
3243
|
-
} else oldBlockChild ? (debug$
|
|
3224
|
+
} else oldBlockChild ? (debug$g("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
3244
3225
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3245
3226
|
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3246
3227
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3247
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
3228
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$g("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3248
3229
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3249
3230
|
}), slateEditor.onChange());
|
|
3250
3231
|
});
|
|
3251
3232
|
}
|
|
3252
3233
|
}
|
|
3253
|
-
const debug$
|
|
3234
|
+
const debug$f = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
3254
3235
|
function Synchronizer(props) {
|
|
3255
3236
|
const $ = reactCompilerRuntime.c(41), {
|
|
3256
3237
|
editorActor,
|
|
@@ -3346,14 +3327,14 @@ function Synchronizer(props) {
|
|
|
3346
3327
|
}, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), React.useEffect(t11, t12);
|
|
3347
3328
|
let t13, t14;
|
|
3348
3329
|
$[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
|
|
3349
|
-
debug$
|
|
3330
|
+
debug$f("Value from props changed, syncing new value"), syncActorRef.send({
|
|
3350
3331
|
type: "update value",
|
|
3351
3332
|
value: incomingValue
|
|
3352
3333
|
});
|
|
3353
3334
|
}, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
|
|
3354
3335
|
let t15;
|
|
3355
3336
|
$[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
|
|
3356
|
-
debug$
|
|
3337
|
+
debug$f("Subscribing to patch events");
|
|
3357
3338
|
const sub = editorActor.on("internal.patch", (event_1) => {
|
|
3358
3339
|
mutationActorRef.send({
|
|
3359
3340
|
...event_1,
|
|
@@ -3361,7 +3342,7 @@ function Synchronizer(props) {
|
|
|
3361
3342
|
});
|
|
3362
3343
|
});
|
|
3363
3344
|
return () => {
|
|
3364
|
-
debug$
|
|
3345
|
+
debug$f("Unsubscribing to patch events"), sub.unsubscribe();
|
|
3365
3346
|
};
|
|
3366
3347
|
}, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
|
|
3367
3348
|
let t16;
|
|
@@ -3376,11 +3357,11 @@ function _temp$1(s) {
|
|
|
3376
3357
|
return s.context.incomingValue;
|
|
3377
3358
|
}
|
|
3378
3359
|
Synchronizer.displayName = "Synchronizer";
|
|
3379
|
-
const debug$
|
|
3360
|
+
const debug$e = debugWithName("operationToPatches");
|
|
3380
3361
|
function createOperationToPatches(editorActor) {
|
|
3381
3362
|
const textBlockName = editorActor.getSnapshot().context.schema.block.name;
|
|
3382
3363
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
3383
|
-
debug$
|
|
3364
|
+
debug$e.enabled && debug$e("Operation", JSON.stringify(operation, null, 2));
|
|
3384
3365
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
3385
3366
|
if (!block)
|
|
3386
3367
|
throw new Error("Could not find block");
|
|
@@ -3473,7 +3454,7 @@ function createOperationToPatches(editorActor) {
|
|
|
3473
3454
|
_key: block.children[operation.path[1] - 1]._key
|
|
3474
3455
|
}])];
|
|
3475
3456
|
}
|
|
3476
|
-
return debug$
|
|
3457
|
+
return debug$e("Something was inserted into a void block. Not producing editor patches."), [];
|
|
3477
3458
|
}
|
|
3478
3459
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
3479
3460
|
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -3531,9 +3512,9 @@ function createOperationToPatches(editorActor) {
|
|
|
3531
3512
|
_key: block._key
|
|
3532
3513
|
}, "children", {
|
|
3533
3514
|
_key: spanToRemove._key
|
|
3534
|
-
}])] : (debug$
|
|
3515
|
+
}])] : (debug$e("Span not found in editor trying to remove node"), []);
|
|
3535
3516
|
} else
|
|
3536
|
-
return debug$
|
|
3517
|
+
return debug$e("Not creating patch inside object block"), [];
|
|
3537
3518
|
}
|
|
3538
3519
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
3539
3520
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -3559,7 +3540,7 @@ function createOperationToPatches(editorActor) {
|
|
|
3559
3540
|
_key: removedSpan._key
|
|
3560
3541
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
3561
3542
|
} else
|
|
3562
|
-
debug$
|
|
3543
|
+
debug$e("Void nodes can't be merged, not creating any patches");
|
|
3563
3544
|
return patches$1;
|
|
3564
3545
|
}
|
|
3565
3546
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -3649,7 +3630,7 @@ function getNextSpan({
|
|
|
3649
3630
|
}
|
|
3650
3631
|
return nextSpan;
|
|
3651
3632
|
}
|
|
3652
|
-
const debug$
|
|
3633
|
+
const debug$d = debugWithName("plugin:withPortableTextMarkModel");
|
|
3653
3634
|
function createWithPortableTextMarkModel(editorActor) {
|
|
3654
3635
|
return function(editor) {
|
|
3655
3636
|
const {
|
|
@@ -3663,7 +3644,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3663
3644
|
for (const [child, childPath] of children) {
|
|
3664
3645
|
const nextNode = node.children[childPath[1] + 1];
|
|
3665
3646
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3666
|
-
debug$
|
|
3647
|
+
debug$d("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3667
3648
|
type: "normalizing"
|
|
3668
3649
|
}), slate.Transforms.mergeNodes(editor, {
|
|
3669
3650
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3676,7 +3657,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3676
3657
|
}
|
|
3677
3658
|
}
|
|
3678
3659
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3679
|
-
debug$
|
|
3660
|
+
debug$d("Adding .markDefs to block node"), editorActor.send({
|
|
3680
3661
|
type: "normalizing"
|
|
3681
3662
|
}), slate.Transforms.setNodes(editor, {
|
|
3682
3663
|
markDefs: []
|
|
@@ -3688,7 +3669,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3688
3669
|
return;
|
|
3689
3670
|
}
|
|
3690
3671
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3691
|
-
debug$
|
|
3672
|
+
debug$d("Adding .marks to span node"), editorActor.send({
|
|
3692
3673
|
type: "normalizing"
|
|
3693
3674
|
}), slate.Transforms.setNodes(editor, {
|
|
3694
3675
|
marks: []
|
|
@@ -3702,7 +3683,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3702
3683
|
if (editor.isTextSpan(node)) {
|
|
3703
3684
|
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));
|
|
3704
3685
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3705
|
-
debug$
|
|
3686
|
+
debug$d("Removing annotations from empty span node"), editorActor.send({
|
|
3706
3687
|
type: "normalizing"
|
|
3707
3688
|
}), slate.Transforms.setNodes(editor, {
|
|
3708
3689
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3720,7 +3701,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3720
3701
|
if (editor.isTextSpan(child)) {
|
|
3721
3702
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3722
3703
|
if (orphanedAnnotations.length > 0) {
|
|
3723
|
-
debug$
|
|
3704
|
+
debug$d("Removing orphaned annotations from span node"), editorActor.send({
|
|
3724
3705
|
type: "normalizing"
|
|
3725
3706
|
}), slate.Transforms.setNodes(editor, {
|
|
3726
3707
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3738,7 +3719,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3738
3719
|
if (editor.isTextBlock(block)) {
|
|
3739
3720
|
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));
|
|
3740
3721
|
if (orphanedAnnotations.length > 0) {
|
|
3741
|
-
debug$
|
|
3722
|
+
debug$d("Removing orphaned annotations from span node"), editorActor.send({
|
|
3742
3723
|
type: "normalizing"
|
|
3743
3724
|
}), slate.Transforms.setNodes(editor, {
|
|
3744
3725
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3756,7 +3737,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3756
3737
|
for (const markDef of markDefs)
|
|
3757
3738
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3758
3739
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3759
|
-
debug$
|
|
3740
|
+
debug$d("Removing duplicate markDefs"), editorActor.send({
|
|
3760
3741
|
type: "normalizing"
|
|
3761
3742
|
}), slate.Transforms.setNodes(editor, {
|
|
3762
3743
|
markDefs: newMarkDefs
|
|
@@ -3771,7 +3752,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3771
3752
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3772
3753
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3773
3754
|
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
3774
|
-
debug$
|
|
3755
|
+
debug$d("Removing markDef not in use"), editorActor.send({
|
|
3775
3756
|
type: "normalizing"
|
|
3776
3757
|
}), slate.Transforms.setNodes(editor, {
|
|
3777
3758
|
markDefs: newMarkDefs
|
|
@@ -3991,7 +3972,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
3991
3972
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
3992
3973
|
if (editor.isTextBlock(targetBlock)) {
|
|
3993
3974
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
3994
|
-
debug$
|
|
3975
|
+
debug$d("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
|
|
3995
3976
|
markDefs: newMarkDefs
|
|
3996
3977
|
}, {
|
|
3997
3978
|
at: targetPath,
|
|
@@ -5215,13 +5196,13 @@ function createWithObjectKeys(editorActor) {
|
|
|
5215
5196
|
}, editor;
|
|
5216
5197
|
};
|
|
5217
5198
|
}
|
|
5218
|
-
const debug$
|
|
5199
|
+
const debug$c = debugWithName("applyPatches"), debugVerbose = debug$c.enabled && !0;
|
|
5219
5200
|
function createApplyPatch(schema2) {
|
|
5220
5201
|
return (editor, patch) => {
|
|
5221
5202
|
let changed = !1;
|
|
5222
|
-
debugVerbose && (debug$
|
|
5203
|
+
debugVerbose && (debug$c(`
|
|
5223
5204
|
|
|
5224
|
-
NEW PATCH =============================================================`), debug$
|
|
5205
|
+
NEW PATCH =============================================================`), debug$c(JSON.stringify(patch, null, 2)));
|
|
5225
5206
|
try {
|
|
5226
5207
|
switch (patch.type) {
|
|
5227
5208
|
case "insert":
|
|
@@ -5237,7 +5218,7 @@ NEW PATCH =============================================================`), debug
|
|
|
5237
5218
|
changed = diffMatchPatch(editor, patch);
|
|
5238
5219
|
break;
|
|
5239
5220
|
default:
|
|
5240
|
-
debug$
|
|
5221
|
+
debug$c("Unhandled patch", patch.type);
|
|
5241
5222
|
}
|
|
5242
5223
|
} catch (err) {
|
|
5243
5224
|
console.error(err);
|
|
@@ -5252,9 +5233,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
5252
5233
|
childPath
|
|
5253
5234
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5254
5235
|
if (!block)
|
|
5255
|
-
return debug$
|
|
5236
|
+
return debug$c("Block not found"), !1;
|
|
5256
5237
|
if (!child || !childPath)
|
|
5257
|
-
return debug$
|
|
5238
|
+
return debug$c("Child not found"), !1;
|
|
5258
5239
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
5259
5240
|
return !1;
|
|
5260
5241
|
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
|
|
@@ -5284,9 +5265,9 @@ function insertPatch(editor, patch, schema2) {
|
|
|
5284
5265
|
childPath: targetChildPath
|
|
5285
5266
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5286
5267
|
if (!targetBlock || !targetBlockPath)
|
|
5287
|
-
return debug$
|
|
5268
|
+
return debug$c("Block not found"), !1;
|
|
5288
5269
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
5289
|
-
return debug$
|
|
5270
|
+
return debug$c("Ignoring patch targeting void value"), !1;
|
|
5290
5271
|
if (patch.path.length === 1) {
|
|
5291
5272
|
const {
|
|
5292
5273
|
items: items2,
|
|
@@ -5294,7 +5275,7 @@ function insertPatch(editor, patch, schema2) {
|
|
|
5294
5275
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
5295
5276
|
schemaTypes: schema2
|
|
5296
5277
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
5297
|
-
return debug$
|
|
5278
|
+
return debug$c(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
|
|
5298
5279
|
at: [normalizedIdx2]
|
|
5299
5280
|
}), debugState(editor, "after"), !0;
|
|
5300
5281
|
}
|
|
@@ -5303,14 +5284,14 @@ function insertPatch(editor, patch, schema2) {
|
|
|
5303
5284
|
position
|
|
5304
5285
|
} = patch;
|
|
5305
5286
|
if (!targetChild || !targetChildPath)
|
|
5306
|
-
return debug$
|
|
5287
|
+
return debug$c("Child not found"), !1;
|
|
5307
5288
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
5308
5289
|
...targetBlock,
|
|
5309
5290
|
children: items
|
|
5310
5291
|
}], {
|
|
5311
5292
|
schemaTypes: schema2
|
|
5312
5293
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
5313
|
-
return debug$
|
|
5294
|
+
return debug$c(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
5314
5295
|
at: childInsertPath
|
|
5315
5296
|
}), debugState(editor, "after"), !0;
|
|
5316
5297
|
}
|
|
@@ -5324,14 +5305,14 @@ function setPatch(editor, patch) {
|
|
|
5324
5305
|
childPath
|
|
5325
5306
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5326
5307
|
if (!block)
|
|
5327
|
-
return debug$
|
|
5308
|
+
return debug$c("Block not found"), !1;
|
|
5328
5309
|
const isTextBlock = editor.isTextBlock(block);
|
|
5329
5310
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
5330
|
-
return debug$
|
|
5311
|
+
return debug$c("Ignoring setting void value"), !1;
|
|
5331
5312
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
5332
5313
|
if (slate.Text.isText(value) && slate.Text.isText(child)) {
|
|
5333
5314
|
const newText = child.text;
|
|
5334
|
-
value.text !== newText && (debug$
|
|
5315
|
+
value.text !== newText && (debug$c("Setting text property"), editor.apply({
|
|
5335
5316
|
type: "remove_text",
|
|
5336
5317
|
path: childPath,
|
|
5337
5318
|
offset: 0,
|
|
@@ -5343,7 +5324,7 @@ function setPatch(editor, patch) {
|
|
|
5343
5324
|
text: value.text
|
|
5344
5325
|
}), editor.onChange());
|
|
5345
5326
|
} else
|
|
5346
|
-
debug$
|
|
5327
|
+
debug$c("Setting non-text property"), editor.apply({
|
|
5347
5328
|
type: "set_node",
|
|
5348
5329
|
path: childPath,
|
|
5349
5330
|
properties: {},
|
|
@@ -5351,7 +5332,7 @@ function setPatch(editor, patch) {
|
|
|
5351
5332
|
});
|
|
5352
5333
|
return !0;
|
|
5353
5334
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
5354
|
-
debug$
|
|
5335
|
+
debug$c("Setting block property");
|
|
5355
5336
|
const {
|
|
5356
5337
|
children,
|
|
5357
5338
|
...nextRest
|
|
@@ -5368,7 +5349,7 @@ function setPatch(editor, patch) {
|
|
|
5368
5349
|
...prevRest
|
|
5369
5350
|
},
|
|
5370
5351
|
newProperties: nextRest
|
|
5371
|
-
}), debug$
|
|
5352
|
+
}), debug$c("Setting children"), block.children.forEach((c, cIndex) => {
|
|
5372
5353
|
editor.apply({
|
|
5373
5354
|
type: "remove_node",
|
|
5374
5355
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -5399,7 +5380,7 @@ function setPatch(editor, patch) {
|
|
|
5399
5380
|
}
|
|
5400
5381
|
function unsetPatch(editor, patch) {
|
|
5401
5382
|
if (patch.path.length === 0) {
|
|
5402
|
-
debug$
|
|
5383
|
+
debug$c("Removing everything"), debugState(editor, "before");
|
|
5403
5384
|
const previousSelection = editor.selection;
|
|
5404
5385
|
return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
5405
5386
|
slate.Transforms.removeNodes(editor, {
|
|
@@ -5426,13 +5407,13 @@ function unsetPatch(editor, patch) {
|
|
|
5426
5407
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
5427
5408
|
if (patch.path.length === 1) {
|
|
5428
5409
|
if (!block || !blockPath)
|
|
5429
|
-
return debug$
|
|
5410
|
+
return debug$c("Block not found"), !1;
|
|
5430
5411
|
const blockIndex = blockPath[0];
|
|
5431
|
-
return debug$
|
|
5412
|
+
return debug$c(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
|
|
5432
5413
|
at: [blockIndex]
|
|
5433
5414
|
}), debugState(editor, "after"), !0;
|
|
5434
5415
|
}
|
|
5435
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
5416
|
+
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, {
|
|
5436
5417
|
at: childPath
|
|
5437
5418
|
}), debugState(editor, "after"), !0) : !1;
|
|
5438
5419
|
}
|
|
@@ -5440,7 +5421,7 @@ function isKeyedSegment(segment) {
|
|
|
5440
5421
|
return typeof segment == "object" && "_key" in segment;
|
|
5441
5422
|
}
|
|
5442
5423
|
function debugState(editor, stateName) {
|
|
5443
|
-
debugVerbose && (debug$
|
|
5424
|
+
debugVerbose && (debug$c(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$c(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
5444
5425
|
}
|
|
5445
5426
|
function findBlockFromPath(editor, path) {
|
|
5446
5427
|
let blockIndex = -1;
|
|
@@ -5482,7 +5463,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
5482
5463
|
childPath: void 0
|
|
5483
5464
|
};
|
|
5484
5465
|
}
|
|
5485
|
-
const debug$
|
|
5466
|
+
const debug$b = debugWithName("plugin:withPatches");
|
|
5486
5467
|
function createWithPatches({
|
|
5487
5468
|
editorActor,
|
|
5488
5469
|
patchFunctions,
|
|
@@ -5507,7 +5488,7 @@ function createWithPatches({
|
|
|
5507
5488
|
withoutPatching(editor, () => {
|
|
5508
5489
|
withoutSaving(editor, () => {
|
|
5509
5490
|
for (const patch of patches2) {
|
|
5510
|
-
debug$
|
|
5491
|
+
debug$b.enabled && debug$b(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
5511
5492
|
try {
|
|
5512
5493
|
changed = applyPatch(editor, patch);
|
|
5513
5494
|
} catch (error) {
|
|
@@ -5525,10 +5506,10 @@ function createWithPatches({
|
|
|
5525
5506
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
5526
5507
|
};
|
|
5527
5508
|
return subscriptions.push(() => {
|
|
5528
|
-
debug$
|
|
5509
|
+
debug$b("Subscribing to remote patches");
|
|
5529
5510
|
const sub = editorActor.on("patches", handlePatches);
|
|
5530
5511
|
return () => {
|
|
5531
|
-
debug$
|
|
5512
|
+
debug$b("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
5532
5513
|
};
|
|
5533
5514
|
}), editor.apply = (operation) => {
|
|
5534
5515
|
let patches$1 = [];
|
|
@@ -5582,7 +5563,7 @@ function createWithPatches({
|
|
|
5582
5563
|
}, editor;
|
|
5583
5564
|
};
|
|
5584
5565
|
}
|
|
5585
|
-
const debug$
|
|
5566
|
+
const debug$a = debugWithName("plugin:withPlaceholderBlock");
|
|
5586
5567
|
function createWithPlaceholderBlock(editorActor) {
|
|
5587
5568
|
return function(editor) {
|
|
5588
5569
|
const {
|
|
@@ -5607,7 +5588,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
5607
5588
|
const node = op.node;
|
|
5608
5589
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
5609
5590
|
const nextPath = slate.Path.next(op.path);
|
|
5610
|
-
editor.children[nextPath[0]] || (debug$
|
|
5591
|
+
editor.children[nextPath[0]] || (debug$a("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
5611
5592
|
decorators: []
|
|
5612
5593
|
})));
|
|
5613
5594
|
}
|
|
@@ -5616,7 +5597,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
5616
5597
|
}, editor;
|
|
5617
5598
|
};
|
|
5618
5599
|
}
|
|
5619
|
-
const debug$
|
|
5600
|
+
const debug$9 = debugWithName("plugin:withPortableTextBlockStyle");
|
|
5620
5601
|
function createWithPortableTextBlockStyle(editorActor) {
|
|
5621
5602
|
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
5622
5603
|
return function(editor) {
|
|
@@ -5629,7 +5610,7 @@ function createWithPortableTextBlockStyle(editorActor) {
|
|
|
5629
5610
|
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)) {
|
|
5630
5611
|
const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
5631
5612
|
if (slate.Text.isText(child) && child.text === "") {
|
|
5632
|
-
debug$
|
|
5613
|
+
debug$9(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
5633
5614
|
type: "normalizing"
|
|
5634
5615
|
}), slate.Transforms.setNodes(editor, {
|
|
5635
5616
|
style: defaultStyle
|
|
@@ -5680,7 +5661,7 @@ function createWithPortableTextSelections(editorActor) {
|
|
|
5680
5661
|
}, editor;
|
|
5681
5662
|
};
|
|
5682
5663
|
}
|
|
5683
|
-
const debug$
|
|
5664
|
+
const debug$8 = debugWithName("plugin:withSchemaTypes");
|
|
5684
5665
|
function createWithSchemaTypes({
|
|
5685
5666
|
editorActor
|
|
5686
5667
|
}) {
|
|
@@ -5692,7 +5673,7 @@ function createWithSchemaTypes({
|
|
|
5692
5673
|
return editor.normalizeNode = (entry) => {
|
|
5693
5674
|
const [node, path] = entry;
|
|
5694
5675
|
if (node._type === void 0 && path.length === 2) {
|
|
5695
|
-
debug$
|
|
5676
|
+
debug$8("Setting span type on text node without a type");
|
|
5696
5677
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
5697
5678
|
editorActor.send({
|
|
5698
5679
|
type: "normalizing"
|
|
@@ -5708,7 +5689,7 @@ function createWithSchemaTypes({
|
|
|
5708
5689
|
return;
|
|
5709
5690
|
}
|
|
5710
5691
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
5711
|
-
debug$
|
|
5692
|
+
debug$8("Setting missing key on child node without a key");
|
|
5712
5693
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
5713
5694
|
editorActor.send({
|
|
5714
5695
|
type: "normalizing"
|
|
@@ -5769,12 +5750,12 @@ const withPlugins = (editor, options) => {
|
|
|
5769
5750
|
editorActor
|
|
5770
5751
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5771
5752
|
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5772
|
-
}, debug$
|
|
5753
|
+
}, debug$7 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
5773
5754
|
function createSlateEditor(config) {
|
|
5774
5755
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
5775
5756
|
if (existingSlateEditor)
|
|
5776
|
-
return debug$
|
|
5777
|
-
debug$
|
|
5757
|
+
return debug$7("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
5758
|
+
debug$7("Creating new Slate editor instance", config.editorActor.id);
|
|
5778
5759
|
const unsubscriptions = [], subscriptions = [], instance = withPlugins(slateReact.withReact(slate.createEditor()), {
|
|
5779
5760
|
editorActor: config.editorActor,
|
|
5780
5761
|
subscriptions
|
|
@@ -6061,7 +6042,7 @@ function getEditorSnapshot({
|
|
|
6061
6042
|
}
|
|
6062
6043
|
};
|
|
6063
6044
|
}
|
|
6064
|
-
const debug$
|
|
6045
|
+
const debug$6 = debugWithName("API:editable");
|
|
6065
6046
|
function createEditableAPI(editor, editorActor) {
|
|
6066
6047
|
const types2 = editorActor.getSnapshot().context.schema;
|
|
6067
6048
|
return {
|
|
@@ -6194,7 +6175,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
6194
6175
|
}], {
|
|
6195
6176
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
6196
6177
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
6197
|
-
return isSpanNode && focusNode._type !== types2.span.name && (debug$
|
|
6178
|
+
return isSpanNode && focusNode._type !== types2.span.name && (debug$6("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
6198
6179
|
distance: 1,
|
|
6199
6180
|
unit: "character"
|
|
6200
6181
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
@@ -6339,18 +6320,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
6339
6320
|
throw new Error("Invalid range");
|
|
6340
6321
|
if (range) {
|
|
6341
6322
|
if (!options?.mode || options?.mode === "selected") {
|
|
6342
|
-
debug$
|
|
6323
|
+
debug$6("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
6343
6324
|
at: range,
|
|
6344
6325
|
hanging: !0,
|
|
6345
6326
|
voids: !0
|
|
6346
6327
|
}), editor.onChange();
|
|
6347
6328
|
return;
|
|
6348
6329
|
}
|
|
6349
|
-
options?.mode === "blocks" && (debug$
|
|
6330
|
+
options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
6350
6331
|
at: range,
|
|
6351
6332
|
voids: !0,
|
|
6352
6333
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
6353
|
-
})), options?.mode === "children" && (debug$
|
|
6334
|
+
})), options?.mode === "children" && (debug$6("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
6354
6335
|
at: range,
|
|
6355
6336
|
voids: !0,
|
|
6356
6337
|
match: (node) => node._type === types2.span.name || // Text children
|
|
@@ -8109,7 +8090,7 @@ function isNativeBehaviorEvent(event) {
|
|
|
8109
8090
|
function isCustomBehaviorEvent(event) {
|
|
8110
8091
|
return event.type.startsWith("custom.");
|
|
8111
8092
|
}
|
|
8112
|
-
const debug$
|
|
8093
|
+
const debug$5 = debugWithName("behaviors:event");
|
|
8113
8094
|
function eventCategory(event) {
|
|
8114
8095
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
8115
8096
|
}
|
|
@@ -8124,7 +8105,7 @@ function performEvent({
|
|
|
8124
8105
|
getSnapshot,
|
|
8125
8106
|
nativeEvent
|
|
8126
8107
|
}) {
|
|
8127
|
-
debug$
|
|
8108
|
+
debug$5(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
8128
8109
|
const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
|
|
8129
8110
|
if (behavior.on === "*")
|
|
8130
8111
|
return !0;
|
|
@@ -8133,7 +8114,7 @@ function performEvent({
|
|
|
8133
8114
|
});
|
|
8134
8115
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
8135
8116
|
nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
8136
|
-
debug$
|
|
8117
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
8137
8118
|
context: {
|
|
8138
8119
|
keyGenerator,
|
|
8139
8120
|
schema: schema2
|
|
@@ -8276,7 +8257,7 @@ function performEvent({
|
|
|
8276
8257
|
}
|
|
8277
8258
|
}
|
|
8278
8259
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
|
|
8279
|
-
debug$
|
|
8260
|
+
debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
8280
8261
|
context: {
|
|
8281
8262
|
keyGenerator,
|
|
8282
8263
|
schema: schema2
|
|
@@ -8364,7 +8345,7 @@ function createEditorSnapshot({
|
|
|
8364
8345
|
}
|
|
8365
8346
|
};
|
|
8366
8347
|
}
|
|
8367
|
-
const editorMachine = xstate.setup({
|
|
8348
|
+
const debug$4 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
8368
8349
|
types: {
|
|
8369
8350
|
context: {},
|
|
8370
8351
|
events: {},
|
|
@@ -8645,6 +8626,12 @@ const editorMachine = xstate.setup({
|
|
|
8645
8626
|
},
|
|
8646
8627
|
states: {
|
|
8647
8628
|
"determine initial edit mode": {
|
|
8629
|
+
entry: [() => {
|
|
8630
|
+
debug$4("entry: edit mode->read only->determine initial edit mode");
|
|
8631
|
+
}],
|
|
8632
|
+
exit: [() => {
|
|
8633
|
+
debug$4("exit: edit mode->read only->determine initial edit mode");
|
|
8634
|
+
}],
|
|
8648
8635
|
on: {
|
|
8649
8636
|
"done syncing value": [{
|
|
8650
8637
|
target: "#editor.edit mode.read only.read only",
|
|
@@ -8657,6 +8644,12 @@ const editorMachine = xstate.setup({
|
|
|
8657
8644
|
}
|
|
8658
8645
|
},
|
|
8659
8646
|
"read only": {
|
|
8647
|
+
entry: [() => {
|
|
8648
|
+
debug$4("entry: edit mode->read only->read only");
|
|
8649
|
+
}],
|
|
8650
|
+
exit: [() => {
|
|
8651
|
+
debug$4("exit: edit mode->read only->read only");
|
|
8652
|
+
}],
|
|
8660
8653
|
on: {
|
|
8661
8654
|
"update readOnly": {
|
|
8662
8655
|
guard: ({
|
|
@@ -8696,6 +8689,12 @@ const editorMachine = xstate.setup({
|
|
|
8696
8689
|
initial: "idle",
|
|
8697
8690
|
states: {
|
|
8698
8691
|
idle: {
|
|
8692
|
+
entry: [() => {
|
|
8693
|
+
debug$4("entry: edit mode->editable->idle");
|
|
8694
|
+
}],
|
|
8695
|
+
exit: [() => {
|
|
8696
|
+
debug$4("exit: edit mode->editable-idle");
|
|
8697
|
+
}],
|
|
8699
8698
|
on: {
|
|
8700
8699
|
dragstart: {
|
|
8701
8700
|
actions: [xstate.assign({
|
|
@@ -8714,6 +8713,12 @@ const editorMachine = xstate.setup({
|
|
|
8714
8713
|
initial: "checking if busy",
|
|
8715
8714
|
states: {
|
|
8716
8715
|
"checking if busy": {
|
|
8716
|
+
entry: [() => {
|
|
8717
|
+
debug$4("entry: edit mode->editable->focusing->checking if busy");
|
|
8718
|
+
}],
|
|
8719
|
+
exit: [() => {
|
|
8720
|
+
debug$4("exit: edit mode->editable->focusing->checking if busy");
|
|
8721
|
+
}],
|
|
8717
8722
|
always: [{
|
|
8718
8723
|
guard: "slate is busy",
|
|
8719
8724
|
target: "busy"
|
|
@@ -8723,6 +8728,12 @@ const editorMachine = xstate.setup({
|
|
|
8723
8728
|
}]
|
|
8724
8729
|
},
|
|
8725
8730
|
busy: {
|
|
8731
|
+
entry: [() => {
|
|
8732
|
+
debug$4("entry: edit mode->editable->focusing-busy");
|
|
8733
|
+
}],
|
|
8734
|
+
exit: [() => {
|
|
8735
|
+
debug$4("exit: edit mode->editable->focusing->busy");
|
|
8736
|
+
}],
|
|
8726
8737
|
after: {
|
|
8727
8738
|
10: {
|
|
8728
8739
|
target: "checking if busy"
|
|
@@ -8732,7 +8743,12 @@ const editorMachine = xstate.setup({
|
|
|
8732
8743
|
}
|
|
8733
8744
|
},
|
|
8734
8745
|
"dragging internally": {
|
|
8735
|
-
|
|
8746
|
+
entry: [() => {
|
|
8747
|
+
debug$4("entry: edit mode->editable->dragging internally");
|
|
8748
|
+
}],
|
|
8749
|
+
exit: [() => {
|
|
8750
|
+
debug$4("exit: edit mode->editable->dragging internally");
|
|
8751
|
+
}, ({
|
|
8736
8752
|
context
|
|
8737
8753
|
}) => {
|
|
8738
8754
|
if (context.internalDrag?.ghost)
|
|
@@ -8762,7 +8778,12 @@ const editorMachine = xstate.setup({
|
|
|
8762
8778
|
initial: "setting up",
|
|
8763
8779
|
states: {
|
|
8764
8780
|
"setting up": {
|
|
8765
|
-
|
|
8781
|
+
entry: [() => {
|
|
8782
|
+
debug$4("entry: setup->setting up");
|
|
8783
|
+
}],
|
|
8784
|
+
exit: [() => {
|
|
8785
|
+
debug$4("exit: setup->setting up");
|
|
8786
|
+
}, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
8766
8787
|
on: {
|
|
8767
8788
|
"internal.patch": {
|
|
8768
8789
|
actions: "defer event"
|
|
@@ -8785,6 +8806,12 @@ const editorMachine = xstate.setup({
|
|
|
8785
8806
|
initial: "idle",
|
|
8786
8807
|
states: {
|
|
8787
8808
|
idle: {
|
|
8809
|
+
entry: [() => {
|
|
8810
|
+
debug$4("entry: setup->set up->value sync->idle");
|
|
8811
|
+
}],
|
|
8812
|
+
exit: [() => {
|
|
8813
|
+
debug$4("exit: setup->set up->value sync->idle");
|
|
8814
|
+
}],
|
|
8788
8815
|
on: {
|
|
8789
8816
|
patches: {
|
|
8790
8817
|
actions: [xstate.emit(({
|
|
@@ -8797,7 +8824,12 @@ const editorMachine = xstate.setup({
|
|
|
8797
8824
|
}
|
|
8798
8825
|
},
|
|
8799
8826
|
"syncing value": {
|
|
8800
|
-
|
|
8827
|
+
entry: [() => {
|
|
8828
|
+
debug$4("entry: setup->set up->value sync->syncing value");
|
|
8829
|
+
}],
|
|
8830
|
+
exit: [() => {
|
|
8831
|
+
debug$4("exit: setup->set up->value sync->syncing value");
|
|
8832
|
+
}, "emit pending incoming patches", "clear pending incoming patches"],
|
|
8801
8833
|
on: {
|
|
8802
8834
|
patches: {
|
|
8803
8835
|
actions: ["defer incoming patches"]
|
|
@@ -8816,6 +8848,12 @@ const editorMachine = xstate.setup({
|
|
|
8816
8848
|
initial: "idle",
|
|
8817
8849
|
states: {
|
|
8818
8850
|
idle: {
|
|
8851
|
+
entry: [() => {
|
|
8852
|
+
debug$4("entry: setup->set up->writing->pristine->idle");
|
|
8853
|
+
}],
|
|
8854
|
+
exit: [() => {
|
|
8855
|
+
debug$4("exit: setup->set up->writing->pristine->idle");
|
|
8856
|
+
}],
|
|
8819
8857
|
on: {
|
|
8820
8858
|
normalizing: {
|
|
8821
8859
|
target: "normalizing"
|
|
@@ -8831,6 +8869,12 @@ const editorMachine = xstate.setup({
|
|
|
8831
8869
|
}
|
|
8832
8870
|
},
|
|
8833
8871
|
normalizing: {
|
|
8872
|
+
entry: [() => {
|
|
8873
|
+
debug$4("entry: setup->set up->writing->pristine->normalizing");
|
|
8874
|
+
}],
|
|
8875
|
+
exit: [() => {
|
|
8876
|
+
debug$4("exit: setup->set up->writing->pristine->normalizing");
|
|
8877
|
+
}],
|
|
8834
8878
|
on: {
|
|
8835
8879
|
"done normalizing": {
|
|
8836
8880
|
target: "idle"
|
|
@@ -8846,7 +8890,12 @@ const editorMachine = xstate.setup({
|
|
|
8846
8890
|
}
|
|
8847
8891
|
},
|
|
8848
8892
|
dirty: {
|
|
8849
|
-
entry: [
|
|
8893
|
+
entry: [() => {
|
|
8894
|
+
debug$4("entry: setup->set up->writing->dirty");
|
|
8895
|
+
}, "emit pending events", "clear pending events"],
|
|
8896
|
+
exit: [() => {
|
|
8897
|
+
debug$4("exit: setup->set up->writing->dirty");
|
|
8898
|
+
}],
|
|
8850
8899
|
on: {
|
|
8851
8900
|
"internal.patch": {
|
|
8852
8901
|
actions: "emit patch event"
|
|
@@ -9911,12 +9960,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
9911
9960
|
type: "range decorations updated",
|
|
9912
9961
|
rangeDecorations: rangeDecorations ?? []
|
|
9913
9962
|
});
|
|
9914
|
-
}, [rangeDecorationsActor, rangeDecorations]), React.useMemo(() =>
|
|
9915
|
-
if (readOnly)
|
|
9916
|
-
return debug("Editable is in read only mode"), slateEditor;
|
|
9917
|
-
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
9918
|
-
return debug("Editable is in edit mode"), withHotKeys(slateEditor);
|
|
9919
|
-
}, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
9963
|
+
}, [rangeDecorationsActor, rangeDecorations]), React.useMemo(() => readOnly ? slateEditor : createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor), [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
9920
9964
|
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(() => {
|
|
9921
9965
|
if (propsSelection) {
|
|
9922
9966
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|