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