@portabletext/editor 1.49.3 → 1.49.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -7,7 +7,7 @@ import { useSelector, useActorRef } from "@xstate/react";
7
7
  import noop from "lodash/noop.js";
8
8
  import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Operation, Transforms, deleteBackward, deleteForward, createEditor } from "slate";
9
9
  import { useSlateStatic, useSelected, withReact, ReactEditor, Slate, useSlate, Editable } from "slate-react";
10
- import debug$h from "debug";
10
+ import debug$i from "debug";
11
11
  import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-equal-selection-points.js";
12
12
  import { getBlockStartPoint, isKeyedSegment as isKeyedSegment$1, parseInlineObject, parseTextBlock, parseBlockObject, parseBlock, sliceBlocks, isTextBlock, parseAnnotation, blockOffsetToSpanSelectionPoint, isSpan$1 as isSpan, isListBlock, getTextBlockText, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
13
13
  import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, getFocusBlock as getFocusBlock$1, getFocusBlockObject, getPreviousBlock, getNextBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock } from "./_chunks-es/selector.is-selection-expanded.js";
@@ -59,10 +59,10 @@ function getCompoundClientRect(nodes) {
59
59
  return new DOMRect(left, top, right - left, bottom - top);
60
60
  }
61
61
  const rootName = "sanity-pte:";
62
- debug$h(rootName);
62
+ debug$i(rootName);
63
63
  function debugWithName(name) {
64
64
  const namespace = `${rootName}${name}`;
65
- return debug$h && debug$h.enabled(namespace) ? debug$h(namespace) : debug$h(rootName);
65
+ return debug$i && debug$i.enabled(namespace) ? debug$i(namespace) : debug$i(rootName);
66
66
  }
67
67
  function getDragSelection({
68
68
  eventSelection,
@@ -2533,7 +2533,7 @@ function withUndoStep(editor, fn) {
2533
2533
  function getCurrentUndoStepId(editor) {
2534
2534
  return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
2535
2535
  }
2536
- const debug$g = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
2536
+ const debug$h = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
2537
2537
  const state = SAVING.get(editor);
2538
2538
  return state === void 0 ? !0 : state;
2539
2539
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -2546,7 +2546,7 @@ function createWithUndoRedo(options) {
2546
2546
  const remotePatches = getRemotePatches(editor);
2547
2547
  let previousUndoStepId = getCurrentUndoStepId(editor);
2548
2548
  options.subscriptions.push(() => {
2549
- debug$g("Subscribing to patches");
2549
+ debug$h("Subscribing to patches");
2550
2550
  const sub = editorActor.on("patches", ({
2551
2551
  patches,
2552
2552
  snapshot
@@ -2555,7 +2555,7 @@ function createWithUndoRedo(options) {
2555
2555
  patches.forEach((patch) => {
2556
2556
  if (!reset && patch.origin !== "local" && remotePatches) {
2557
2557
  if (patch.type === "unset" && patch.path.length === 0) {
2558
- debug$g("Someone else cleared the content, resetting undo/redo history"), editor.history = {
2558
+ debug$h("Someone else cleared the content, resetting undo/redo history"), editor.history = {
2559
2559
  undos: [],
2560
2560
  redos: []
2561
2561
  }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
@@ -2571,7 +2571,7 @@ function createWithUndoRedo(options) {
2571
2571
  }), previousSnapshot = snapshot;
2572
2572
  });
2573
2573
  return () => {
2574
- debug$g("Unsubscribing to patches"), sub.unsubscribe();
2574
+ debug$h("Unsubscribing to patches"), sub.unsubscribe();
2575
2575
  };
2576
2576
  }), editor.history = {
2577
2577
  undos: [],
@@ -2610,7 +2610,7 @@ function createWithUndoRedo(options) {
2610
2610
  operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
2611
2611
  timestamp: /* @__PURE__ */ new Date()
2612
2612
  };
2613
- undos.push(newStep), debug$g("Created new undo step", step);
2613
+ undos.push(newStep), debug$h("Created new undo step", step);
2614
2614
  }
2615
2615
  for (; undos.length > UNDO_STEP_LIMIT; )
2616
2616
  undos.shift();
@@ -2628,7 +2628,7 @@ const historyUndoOperationImplementation = ({
2628
2628
  } = editor.history, remotePatches = getRemotePatches(editor);
2629
2629
  if (undos.length > 0) {
2630
2630
  const step = undos[undos.length - 1];
2631
- if (debug$g("Undoing", step), step.operations.length > 0) {
2631
+ if (debug$h("Undoing", step), step.operations.length > 0) {
2632
2632
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
2633
2633
  let transformedOperations = step.operations;
2634
2634
  otherPatches.forEach((item) => {
@@ -2646,7 +2646,7 @@ const historyUndoOperationImplementation = ({
2646
2646
  });
2647
2647
  });
2648
2648
  } catch (err) {
2649
- debug$g("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
2649
+ debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
2650
2650
  undos: [],
2651
2651
  redos: []
2652
2652
  }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
@@ -2663,7 +2663,7 @@ const historyUndoOperationImplementation = ({
2663
2663
  } = editor.history, remotePatches = getRemotePatches(editor);
2664
2664
  if (redos.length > 0) {
2665
2665
  const step = redos[redos.length - 1];
2666
- if (debug$g("Redoing", step), step.operations.length > 0) {
2666
+ if (debug$h("Redoing", step), step.operations.length > 0) {
2667
2667
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
2668
2668
  let transformedOperations = step.operations;
2669
2669
  otherPatches.forEach((item) => {
@@ -2680,7 +2680,7 @@ const historyUndoOperationImplementation = ({
2680
2680
  });
2681
2681
  });
2682
2682
  } catch (err) {
2683
- debug$g("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
2683
+ debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
2684
2684
  undos: [],
2685
2685
  redos: []
2686
2686
  }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
@@ -2698,16 +2698,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2698
2698
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
2699
2699
  _key: blk._key
2700
2700
  }, patch.path[0]));
2701
- return debug$g(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
2701
+ return debug$h(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
2702
2702
  }
2703
2703
  if (patch.type === "unset" && patch.path.length === 1) {
2704
2704
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
2705
2705
  _key: blk._key
2706
2706
  }, patch.path[0]));
2707
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$g("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
2707
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$h("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
2708
2708
  }
2709
2709
  if (patch.type === "unset" && patch.path.length === 0)
2710
- return debug$g(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
2710
+ return debug$h(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
2711
2711
  if (patch.type === "diffMatchPatch") {
2712
2712
  const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
2713
2713
  return !operationTargetBlock || !isEqual({
@@ -2794,7 +2794,7 @@ function findOperationTargetBlock(editor, operation) {
2794
2794
  let block;
2795
2795
  return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
2796
2796
  }
2797
- const debug$f = debugWithName("sync machine"), syncValueCallback = ({
2797
+ const debug$g = debugWithName("sync machine"), syncValueCallback = ({
2798
2798
  sendBack,
2799
2799
  input
2800
2800
  }) => {
@@ -2849,13 +2849,17 @@ const debug$f = debugWithName("sync machine"), syncValueCallback = ({
2849
2849
  context
2850
2850
  }) => {
2851
2851
  const editable = !context.readOnly, isProcessingLocalChanges = context.isProcessingLocalChanges, isChanging = isChangingRemotely(context.slateEditor) ?? !1, isBusy = editable && (isProcessingLocalChanges || isChanging);
2852
- return debug$f("isBusy", {
2852
+ return debug$g("isBusy", {
2853
2853
  isBusy,
2854
2854
  editable,
2855
2855
  isProcessingLocalChanges,
2856
2856
  isChanging
2857
2857
  }), isBusy;
2858
2858
  },
2859
+ "is new value": ({
2860
+ context,
2861
+ event
2862
+ }) => event.type === "update value" && context.previousValue !== event.value,
2859
2863
  "value changed while syncing": ({
2860
2864
  context,
2861
2865
  event
@@ -2896,139 +2900,115 @@ const debug$f = debugWithName("sync machine"), syncValueCallback = ({
2896
2900
  actions: ["assign readOnly"]
2897
2901
  }
2898
2902
  },
2899
- type: "parallel",
2903
+ initial: "idle",
2900
2904
  states: {
2901
- "setting up": {
2902
- initial: "syncing initial value",
2903
- states: {
2904
- "syncing initial value": {
2905
- entry: [() => {
2906
- debug$f("entry: syncing initial value");
2907
- }],
2908
- exit: [() => {
2909
- debug$f("exit: syncing initial value");
2910
- }],
2911
- always: {
2912
- guard: "initial value synced",
2913
- target: "done syncing initial value"
2914
- }
2915
- },
2916
- "done syncing initial value": {
2917
- entry: ["emit done syncing value", () => {
2918
- debug$f("entry: done syncing initial value");
2919
- }],
2920
- exit: [() => {
2921
- debug$f("exit: done syncing initial value");
2922
- }],
2923
- type: "final"
2924
- }
2905
+ idle: {
2906
+ entry: [() => {
2907
+ debug$g("entry: syncing->idle");
2908
+ }],
2909
+ exit: [() => {
2910
+ debug$g("exit: syncing->idle");
2911
+ }],
2912
+ on: {
2913
+ "update value": [{
2914
+ guard: and(["is busy", "is new value"]),
2915
+ target: "busy",
2916
+ actions: ["assign pending value"]
2917
+ }, {
2918
+ guard: "is new value",
2919
+ target: "syncing",
2920
+ actions: ["assign pending value"]
2921
+ }, {
2922
+ guard: not("initial value synced"),
2923
+ actions: [() => {
2924
+ debug$g("no new value \u2013 setting initial value as synced");
2925
+ }, "assign initial value synced", "emit done syncing value"]
2926
+ }, {
2927
+ actions: [() => {
2928
+ debug$g("no new value and initial value already synced");
2929
+ }]
2930
+ }]
2931
+ }
2932
+ },
2933
+ busy: {
2934
+ entry: [() => {
2935
+ debug$g("entry: syncing->busy");
2936
+ }],
2937
+ exit: [() => {
2938
+ debug$g("exit: syncing->busy");
2939
+ }],
2940
+ after: {
2941
+ 1e3: [{
2942
+ guard: "is busy",
2943
+ target: ".",
2944
+ reenter: !0,
2945
+ actions: [() => {
2946
+ debug$g("reenter: syncing->busy");
2947
+ }]
2948
+ }, {
2949
+ target: "syncing"
2950
+ }]
2951
+ },
2952
+ on: {
2953
+ "update value": [{
2954
+ guard: "is new value",
2955
+ actions: ["assign pending value"]
2956
+ }]
2925
2957
  }
2926
2958
  },
2927
2959
  syncing: {
2928
- initial: "idle",
2929
- states: {
2930
- idle: {
2931
- entry: [() => {
2932
- debug$f("entry: syncing->idle");
2933
- }],
2934
- exit: [() => {
2935
- debug$f("exit: syncing->idle");
2936
- }],
2937
- on: {
2938
- "update value": [{
2939
- guard: "is busy",
2940
- target: "busy",
2941
- actions: ["assign pending value"]
2942
- }, {
2943
- target: "syncing",
2944
- actions: ["assign pending value"]
2945
- }]
2946
- }
2947
- },
2948
- busy: {
2949
- entry: [() => {
2950
- debug$f("entry: syncing->busy");
2951
- }],
2952
- exit: [() => {
2953
- debug$f("exit: syncing->busy");
2954
- }],
2955
- after: {
2956
- 1e3: [{
2957
- guard: "is busy",
2958
- target: ".",
2959
- reenter: !0,
2960
- actions: [() => {
2961
- debug$f("reenter: syncing->busy");
2962
- }]
2963
- }, {
2964
- target: "syncing"
2965
- }]
2960
+ entry: [() => {
2961
+ debug$g("entry: syncing->syncing");
2962
+ }, "emit syncing value"],
2963
+ exit: [() => {
2964
+ debug$g("exit: syncing->syncing");
2965
+ }, "emit done syncing value"],
2966
+ invoke: {
2967
+ src: "sync value",
2968
+ id: "sync value",
2969
+ input: ({
2970
+ context
2971
+ }) => ({
2972
+ context: {
2973
+ keyGenerator: context.keyGenerator,
2974
+ previousValue: context.previousValue,
2975
+ readOnly: context.readOnly,
2976
+ schema: context.schema
2966
2977
  },
2967
- on: {
2968
- "update value": [{
2969
- actions: ["assign pending value"]
2970
- }]
2971
- }
2978
+ slateEditor: context.slateEditor,
2979
+ streamBlocks: !context.initialValueSynced,
2980
+ value: context.pendingValue
2981
+ })
2982
+ },
2983
+ on: {
2984
+ "update value": {
2985
+ guard: "is new value",
2986
+ actions: ["assign pending value"]
2972
2987
  },
2973
- syncing: {
2974
- entry: [() => {
2975
- debug$f("entry: syncing->syncing");
2976
- }, "emit syncing value"],
2977
- exit: [() => {
2978
- debug$f("exit: syncing->syncing");
2979
- }, "emit done syncing value"],
2980
- always: {
2981
- guard: "pending value equals previous value",
2982
- target: "idle",
2983
- actions: ["clear pending value", "assign initial value synced"]
2984
- },
2985
- invoke: {
2986
- src: "sync value",
2987
- id: "sync value",
2988
- input: ({
2989
- context
2990
- }) => ({
2991
- context: {
2992
- keyGenerator: context.keyGenerator,
2993
- previousValue: context.previousValue,
2994
- readOnly: context.readOnly,
2995
- schema: context.schema
2996
- },
2997
- slateEditor: context.slateEditor,
2998
- streamBlocks: !context.initialValueSynced,
2999
- value: context.pendingValue
3000
- })
3001
- },
3002
- on: {
3003
- "update value": {
3004
- actions: ["assign pending value"]
3005
- },
3006
- patch: {
3007
- actions: [emit(({
3008
- event
3009
- }) => event)]
3010
- },
3011
- "invalid value": {
3012
- actions: [emit(({
3013
- event
3014
- }) => event)]
3015
- },
3016
- "value changed": {
3017
- actions: [emit(({
3018
- event
3019
- }) => event)]
3020
- },
3021
- "done syncing": [{
3022
- guard: "value changed while syncing",
3023
- actions: ["assign previous value", "assign initial value synced"],
3024
- target: "syncing",
3025
- reenter: !0
3026
- }, {
3027
- target: "idle",
3028
- actions: ["clear pending value", "assign previous value", "assign initial value synced"]
3029
- }]
3030
- }
3031
- }
2988
+ patch: {
2989
+ actions: [emit(({
2990
+ event
2991
+ }) => event)]
2992
+ },
2993
+ "invalid value": {
2994
+ actions: [emit(({
2995
+ event
2996
+ }) => event)]
2997
+ },
2998
+ "value changed": {
2999
+ actions: [emit(({
3000
+ event
3001
+ }) => event)]
3002
+ },
3003
+ "done syncing": [{
3004
+ guard: "value changed while syncing",
3005
+ actions: ["assign previous value", "assign initial value synced"],
3006
+ target: "syncing",
3007
+ reenter: !0
3008
+ }, {
3009
+ target: "idle",
3010
+ actions: ["clear pending value", "assign previous value", "assign initial value synced"]
3011
+ }]
3032
3012
  }
3033
3013
  }
3034
3014
  }
@@ -3042,7 +3022,7 @@ async function updateValue({
3042
3022
  }) {
3043
3023
  let isChanged = !1, isValid = !0;
3044
3024
  const hadSelection = !!slateEditor.selection;
3045
- if ((!value || value.length === 0) && (debug$f("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
3025
+ if ((!value || value.length === 0) && (debug$g("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
3046
3026
  withoutSaving(slateEditor, () => {
3047
3027
  withoutPatching(slateEditor, () => {
3048
3028
  hadSelection && Transforms.deselect(slateEditor);
@@ -3062,21 +3042,16 @@ async function updateValue({
3062
3042
  const slateValueFromProps = toSlateValue(value, {
3063
3043
  schemaTypes: context.schema
3064
3044
  });
3065
- await new Promise((resolve) => {
3045
+ streamBlocks ? await new Promise((resolve) => {
3066
3046
  Editor.withoutNormalizing(slateEditor, () => {
3067
3047
  withRemoteChanges(slateEditor, () => {
3068
3048
  withoutPatching(slateEditor, async () => {
3069
- const childrenLength = slateEditor.children.length;
3070
- if (slateValueFromProps.length < childrenLength) {
3071
- for (let i = childrenLength - 1; i > slateValueFromProps.length - 1; i--)
3072
- Transforms.removeNodes(slateEditor, {
3073
- at: [i]
3074
- });
3075
- isChanged = !0;
3076
- }
3077
- for await (const [currentBlock, currentBlockIndex] of getBlocks({
3078
- slateValue: slateValueFromProps,
3079
- streamBlocks
3049
+ isChanged = removeExtraBlocks({
3050
+ slateEditor,
3051
+ slateValueFromProps
3052
+ });
3053
+ for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
3054
+ slateValue: slateValueFromProps
3080
3055
  })) {
3081
3056
  const {
3082
3057
  blockChanged,
@@ -3095,17 +3070,41 @@ async function updateValue({
3095
3070
  });
3096
3071
  });
3097
3072
  });
3073
+ }) : Editor.withoutNormalizing(slateEditor, () => {
3074
+ withRemoteChanges(slateEditor, () => {
3075
+ withoutPatching(slateEditor, () => {
3076
+ isChanged = removeExtraBlocks({
3077
+ slateEditor,
3078
+ slateValueFromProps
3079
+ });
3080
+ let index = 0;
3081
+ for (const currentBlock of slateValueFromProps) {
3082
+ const {
3083
+ blockChanged,
3084
+ blockValid
3085
+ } = syncBlock({
3086
+ context,
3087
+ sendBack,
3088
+ block: currentBlock,
3089
+ index,
3090
+ slateEditor,
3091
+ value
3092
+ });
3093
+ isChanged = blockChanged || isChanged, isValid = isValid && blockValid, index++;
3094
+ }
3095
+ });
3096
+ });
3098
3097
  });
3099
3098
  }
3100
3099
  if (!isValid) {
3101
- debug$f("Invalid value, returning"), sendBack({
3100
+ debug$g("Invalid value, returning"), sendBack({
3102
3101
  type: "done syncing",
3103
3102
  value
3104
3103
  });
3105
3104
  return;
3106
3105
  }
3107
3106
  if (isChanged) {
3108
- debug$f("Server value changed, syncing editor");
3107
+ debug$g("Server value changed, syncing editor");
3109
3108
  try {
3110
3109
  slateEditor.onChange();
3111
3110
  } catch (err) {
@@ -3133,19 +3132,33 @@ async function updateValue({
3133
3132
  value
3134
3133
  });
3135
3134
  } else
3136
- debug$f("Server value and editor value is equal, no need to sync.");
3135
+ debug$g("Server value and editor value is equal, no need to sync.");
3137
3136
  sendBack({
3138
3137
  type: "done syncing",
3139
3138
  value
3140
3139
  });
3141
3140
  }
3142
- async function* getBlocks({
3143
- slateValue,
3144
- streamBlocks
3141
+ function removeExtraBlocks({
3142
+ slateEditor,
3143
+ slateValueFromProps
3144
+ }) {
3145
+ let isChanged = !1;
3146
+ const childrenLength = slateEditor.children.length;
3147
+ if (slateValueFromProps.length < childrenLength) {
3148
+ for (let i = childrenLength - 1; i > slateValueFromProps.length - 1; i--)
3149
+ Transforms.removeNodes(slateEditor, {
3150
+ at: [i]
3151
+ });
3152
+ isChanged = !0;
3153
+ }
3154
+ return isChanged;
3155
+ }
3156
+ async function* getStreamedBlocks({
3157
+ slateValue
3145
3158
  }) {
3146
3159
  let index = 0;
3147
3160
  for await (const block of slateValue)
3148
- streamBlocks && index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
3161
+ index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
3149
3162
  }
3150
3163
  function syncBlock({
3151
3164
  context,
@@ -3167,7 +3180,7 @@ function syncBlock({
3167
3180
  type: "patch",
3168
3181
  patch
3169
3182
  });
3170
- })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$f.enabled && debug$f("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$f.enabled && debug$f("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
3183
+ })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$g.enabled && debug$g("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$g.enabled && debug$g("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
3171
3184
  type: "invalid value",
3172
3185
  resolution: validation.resolution,
3173
3186
  value
@@ -3175,9 +3188,9 @@ function syncBlock({
3175
3188
  }
3176
3189
  if (!oldBlock && blockValid) {
3177
3190
  const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
3178
- debug$f.enabled && debug$f("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
3191
+ debug$g.enabled && debug$g("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
3179
3192
  at: [currentBlockIndex]
3180
- }) : (debug$f("Invalid", validation), sendBack({
3193
+ }) : (debug$g("Invalid", validation), sendBack({
3181
3194
  type: "invalid value",
3182
3195
  resolution: validation.resolution,
3183
3196
  value
@@ -3205,14 +3218,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
3205
3218
  const oldBlockChildrenLength = oldBlock.children.length;
3206
3219
  currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
3207
3220
  const childIndex = oldBlockChildrenLength - 1 - index;
3208
- childIndex > 0 && (debug$f("Removing child"), Transforms.removeNodes(slateEditor, {
3221
+ childIndex > 0 && (debug$g("Removing child"), Transforms.removeNodes(slateEditor, {
3209
3222
  at: [currentBlockIndex, childIndex]
3210
3223
  }));
3211
3224
  }), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
3212
3225
  const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
3213
3226
  if (isChildChanged)
3214
3227
  if (currentBlockChild._key === oldBlockChild?._key) {
3215
- debug$f("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
3228
+ debug$g("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
3216
3229
  at: path
3217
3230
  });
3218
3231
  const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
@@ -3229,23 +3242,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
3229
3242
  }
3230
3243
  }), Transforms.insertText(slateEditor, currentBlockChild.text, {
3231
3244
  at: path
3232
- }), slateEditor.onChange()) : isSpanNode || (debug$f("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
3245
+ }), slateEditor.onChange()) : isSpanNode || (debug$g("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
3233
3246
  _key: VOID_CHILD_KEY
3234
3247
  }, {
3235
3248
  at: [...path, 0],
3236
3249
  voids: !0
3237
3250
  }));
3238
- } else oldBlockChild ? (debug$f("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
3251
+ } else oldBlockChild ? (debug$g("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
3239
3252
  at: [currentBlockIndex, currentBlockChildIndex]
3240
3253
  }), Transforms.insertNodes(slateEditor, currentBlockChild, {
3241
3254
  at: [currentBlockIndex, currentBlockChildIndex]
3242
- }), slateEditor.onChange()) : oldBlockChild || (debug$f("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
3255
+ }), slateEditor.onChange()) : oldBlockChild || (debug$g("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
3243
3256
  at: [currentBlockIndex, currentBlockChildIndex]
3244
3257
  }), slateEditor.onChange());
3245
3258
  });
3246
3259
  }
3247
3260
  }
3248
- const debug$e = debugWithName("component:PortableTextEditor:Synchronizer");
3261
+ const debug$f = debugWithName("component:PortableTextEditor:Synchronizer");
3249
3262
  function Synchronizer(props) {
3250
3263
  const $ = c(41), {
3251
3264
  editorActor,
@@ -3341,14 +3354,14 @@ function Synchronizer(props) {
3341
3354
  }, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), useEffect(t11, t12);
3342
3355
  let t13, t14;
3343
3356
  $[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
3344
- debug$e("Value from props changed, syncing new value"), syncActorRef.send({
3357
+ debug$f("Value from props changed, syncing new value"), syncActorRef.send({
3345
3358
  type: "update value",
3346
3359
  value: incomingValue
3347
3360
  });
3348
3361
  }, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), useEffect(t13, t14);
3349
3362
  let t15;
3350
3363
  $[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
3351
- debug$e("Subscribing to patch events");
3364
+ debug$f("Subscribing to patch events");
3352
3365
  const sub = editorActor.on("internal.patch", (event_1) => {
3353
3366
  mutationActorRef.send({
3354
3367
  ...event_1,
@@ -3356,7 +3369,7 @@ function Synchronizer(props) {
3356
3369
  });
3357
3370
  });
3358
3371
  return () => {
3359
- debug$e("Unsubscribing to patch events"), sub.unsubscribe();
3372
+ debug$f("Unsubscribing to patch events"), sub.unsubscribe();
3360
3373
  };
3361
3374
  }, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
3362
3375
  let t16;
@@ -3371,11 +3384,11 @@ function _temp$1(s) {
3371
3384
  return s.context.incomingValue;
3372
3385
  }
3373
3386
  Synchronizer.displayName = "Synchronizer";
3374
- const debug$d = debugWithName("operationToPatches");
3387
+ const debug$e = debugWithName("operationToPatches");
3375
3388
  function createOperationToPatches(editorActor) {
3376
3389
  const textBlockName = editorActor.getSnapshot().context.schema.block.name;
3377
3390
  function insertTextPatch(editor, operation, beforeValue) {
3378
- debug$d.enabled && debug$d("Operation", JSON.stringify(operation, null, 2));
3391
+ debug$e.enabled && debug$e("Operation", JSON.stringify(operation, null, 2));
3379
3392
  const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
3380
3393
  if (!block)
3381
3394
  throw new Error("Could not find block");
@@ -3468,7 +3481,7 @@ function createOperationToPatches(editorActor) {
3468
3481
  _key: block.children[operation.path[1] - 1]._key
3469
3482
  }])];
3470
3483
  }
3471
- return debug$d("Something was inserted into a void block. Not producing editor patches."), [];
3484
+ return debug$e("Something was inserted into a void block. Not producing editor patches."), [];
3472
3485
  }
3473
3486
  function splitNodePatch(editor, operation, beforeValue) {
3474
3487
  const patches = [], splitBlock = editor.children[operation.path[0]];
@@ -3526,9 +3539,9 @@ function createOperationToPatches(editorActor) {
3526
3539
  _key: block._key
3527
3540
  }, "children", {
3528
3541
  _key: spanToRemove._key
3529
- }])] : (debug$d("Span not found in editor trying to remove node"), []);
3542
+ }])] : (debug$e("Span not found in editor trying to remove node"), []);
3530
3543
  } else
3531
- return debug$d("Not creating patch inside object block"), [];
3544
+ return debug$e("Not creating patch inside object block"), [];
3532
3545
  }
3533
3546
  function mergeNodePatch(editor, operation, beforeValue) {
3534
3547
  const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
@@ -3554,7 +3567,7 @@ function createOperationToPatches(editorActor) {
3554
3567
  _key: removedSpan._key
3555
3568
  }])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
3556
3569
  } else
3557
- debug$d("Void nodes can't be merged, not creating any patches");
3570
+ debug$e("Void nodes can't be merged, not creating any patches");
3558
3571
  return patches;
3559
3572
  }
3560
3573
  function moveNodePatch(editor, operation, beforeValue) {
@@ -3644,7 +3657,7 @@ function getNextSpan({
3644
3657
  }
3645
3658
  return nextSpan;
3646
3659
  }
3647
- const debug$c = debugWithName("plugin:withPortableTextMarkModel");
3660
+ const debug$d = debugWithName("plugin:withPortableTextMarkModel");
3648
3661
  function createWithPortableTextMarkModel(editorActor) {
3649
3662
  return function(editor) {
3650
3663
  const {
@@ -3658,7 +3671,7 @@ function createWithPortableTextMarkModel(editorActor) {
3658
3671
  for (const [child, childPath] of children) {
3659
3672
  const nextNode = node.children[childPath[1] + 1];
3660
3673
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
3661
- debug$c("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3674
+ debug$d("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3662
3675
  type: "normalizing"
3663
3676
  }), Transforms.mergeNodes(editor, {
3664
3677
  at: [childPath[0], childPath[1] + 1],
@@ -3671,7 +3684,7 @@ function createWithPortableTextMarkModel(editorActor) {
3671
3684
  }
3672
3685
  }
3673
3686
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
3674
- debug$c("Adding .markDefs to block node"), editorActor.send({
3687
+ debug$d("Adding .markDefs to block node"), editorActor.send({
3675
3688
  type: "normalizing"
3676
3689
  }), Transforms.setNodes(editor, {
3677
3690
  markDefs: []
@@ -3683,7 +3696,7 @@ function createWithPortableTextMarkModel(editorActor) {
3683
3696
  return;
3684
3697
  }
3685
3698
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
3686
- debug$c("Adding .marks to span node"), editorActor.send({
3699
+ debug$d("Adding .marks to span node"), editorActor.send({
3687
3700
  type: "normalizing"
3688
3701
  }), Transforms.setNodes(editor, {
3689
3702
  marks: []
@@ -3697,7 +3710,7 @@ function createWithPortableTextMarkModel(editorActor) {
3697
3710
  if (editor.isTextSpan(node)) {
3698
3711
  const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
3699
3712
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
3700
- debug$c("Removing annotations from empty span node"), editorActor.send({
3713
+ debug$d("Removing annotations from empty span node"), editorActor.send({
3701
3714
  type: "normalizing"
3702
3715
  }), Transforms.setNodes(editor, {
3703
3716
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -3715,7 +3728,7 @@ function createWithPortableTextMarkModel(editorActor) {
3715
3728
  if (editor.isTextSpan(child)) {
3716
3729
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
3717
3730
  if (orphanedAnnotations.length > 0) {
3718
- debug$c("Removing orphaned annotations from span node"), editorActor.send({
3731
+ debug$d("Removing orphaned annotations from span node"), editorActor.send({
3719
3732
  type: "normalizing"
3720
3733
  }), Transforms.setNodes(editor, {
3721
3734
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3733,7 +3746,7 @@ function createWithPortableTextMarkModel(editorActor) {
3733
3746
  if (editor.isTextBlock(block)) {
3734
3747
  const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
3735
3748
  if (orphanedAnnotations.length > 0) {
3736
- debug$c("Removing orphaned annotations from span node"), editorActor.send({
3749
+ debug$d("Removing orphaned annotations from span node"), editorActor.send({
3737
3750
  type: "normalizing"
3738
3751
  }), Transforms.setNodes(editor, {
3739
3752
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3751,7 +3764,7 @@ function createWithPortableTextMarkModel(editorActor) {
3751
3764
  for (const markDef of markDefs)
3752
3765
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
3753
3766
  if (markDefs.length !== newMarkDefs.length) {
3754
- debug$c("Removing duplicate markDefs"), editorActor.send({
3767
+ debug$d("Removing duplicate markDefs"), editorActor.send({
3755
3768
  type: "normalizing"
3756
3769
  }), Transforms.setNodes(editor, {
3757
3770
  markDefs: newMarkDefs
@@ -3766,7 +3779,7 @@ function createWithPortableTextMarkModel(editorActor) {
3766
3779
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
3767
3780
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
3768
3781
  if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
3769
- debug$c("Removing markDef not in use"), editorActor.send({
3782
+ debug$d("Removing markDef not in use"), editorActor.send({
3770
3783
  type: "normalizing"
3771
3784
  }), Transforms.setNodes(editor, {
3772
3785
  markDefs: newMarkDefs
@@ -3986,7 +3999,7 @@ function createWithPortableTextMarkModel(editorActor) {
3986
3999
  const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
3987
4000
  if (editor.isTextBlock(targetBlock)) {
3988
4001
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
3989
- debug$c("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
4002
+ debug$d("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
3990
4003
  markDefs: newMarkDefs
3991
4004
  }, {
3992
4005
  at: targetPath,
@@ -5210,13 +5223,13 @@ function createWithObjectKeys(editorActor) {
5210
5223
  }, editor;
5211
5224
  };
5212
5225
  }
5213
- const debug$b = debugWithName("applyPatches"), debugVerbose = debug$b.enabled && !0;
5226
+ const debug$c = debugWithName("applyPatches"), debugVerbose = debug$c.enabled && !0;
5214
5227
  function createApplyPatch(schema) {
5215
5228
  return (editor, patch) => {
5216
5229
  let changed = !1;
5217
- debugVerbose && (debug$b(`
5230
+ debugVerbose && (debug$c(`
5218
5231
 
5219
- NEW PATCH =============================================================`), debug$b(JSON.stringify(patch, null, 2)));
5232
+ NEW PATCH =============================================================`), debug$c(JSON.stringify(patch, null, 2)));
5220
5233
  try {
5221
5234
  switch (patch.type) {
5222
5235
  case "insert":
@@ -5232,7 +5245,7 @@ NEW PATCH =============================================================`), debug
5232
5245
  changed = diffMatchPatch(editor, patch);
5233
5246
  break;
5234
5247
  default:
5235
- debug$b("Unhandled patch", patch.type);
5248
+ debug$c("Unhandled patch", patch.type);
5236
5249
  }
5237
5250
  } catch (err) {
5238
5251
  console.error(err);
@@ -5247,9 +5260,9 @@ function diffMatchPatch(editor, patch) {
5247
5260
  childPath
5248
5261
  } = findBlockAndChildFromPath(editor, patch.path);
5249
5262
  if (!block)
5250
- return debug$b("Block not found"), !1;
5263
+ return debug$c("Block not found"), !1;
5251
5264
  if (!child || !childPath)
5252
- return debug$b("Child not found"), !1;
5265
+ return debug$c("Child not found"), !1;
5253
5266
  if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
5254
5267
  return !1;
5255
5268
  const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
@@ -5279,9 +5292,9 @@ function insertPatch(editor, patch, schema) {
5279
5292
  childPath: targetChildPath
5280
5293
  } = findBlockAndChildFromPath(editor, patch.path);
5281
5294
  if (!targetBlock || !targetBlockPath)
5282
- return debug$b("Block not found"), !1;
5295
+ return debug$c("Block not found"), !1;
5283
5296
  if (patch.path.length > 1 && patch.path[1] !== "children")
5284
- return debug$b("Ignoring patch targeting void value"), !1;
5297
+ return debug$c("Ignoring patch targeting void value"), !1;
5285
5298
  if (patch.path.length === 1) {
5286
5299
  const {
5287
5300
  items: items2,
@@ -5289,7 +5302,7 @@ function insertPatch(editor, patch, schema) {
5289
5302
  } = patch, blocksToInsert = toSlateValue(items2, {
5290
5303
  schemaTypes: schema
5291
5304
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
5292
- return debug$b(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
5305
+ return debug$c(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
5293
5306
  at: [normalizedIdx2]
5294
5307
  }), debugState(editor, "after"), !0;
5295
5308
  }
@@ -5298,14 +5311,14 @@ function insertPatch(editor, patch, schema) {
5298
5311
  position
5299
5312
  } = patch;
5300
5313
  if (!targetChild || !targetChildPath)
5301
- return debug$b("Child not found"), !1;
5314
+ return debug$c("Child not found"), !1;
5302
5315
  const childrenToInsert = targetBlock && toSlateValue([{
5303
5316
  ...targetBlock,
5304
5317
  children: items
5305
5318
  }], {
5306
5319
  schemaTypes: schema
5307
5320
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
5308
- return debug$b(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
5321
+ return debug$c(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
5309
5322
  at: childInsertPath
5310
5323
  }), debugState(editor, "after"), !0;
5311
5324
  }
@@ -5319,14 +5332,14 @@ function setPatch(editor, patch) {
5319
5332
  childPath
5320
5333
  } = findBlockAndChildFromPath(editor, patch.path);
5321
5334
  if (!block)
5322
- return debug$b("Block not found"), !1;
5335
+ return debug$c("Block not found"), !1;
5323
5336
  const isTextBlock2 = editor.isTextBlock(block);
5324
5337
  if (isTextBlock2 && patch.path.length > 1 && patch.path[1] !== "children")
5325
- return debug$b("Ignoring setting void value"), !1;
5338
+ return debug$c("Ignoring setting void value"), !1;
5326
5339
  if (debugState(editor, "before"), isTextBlock2 && child && childPath) {
5327
5340
  if (Text.isText(value) && Text.isText(child)) {
5328
5341
  const newText = child.text;
5329
- value.text !== newText && (debug$b("Setting text property"), editor.apply({
5342
+ value.text !== newText && (debug$c("Setting text property"), editor.apply({
5330
5343
  type: "remove_text",
5331
5344
  path: childPath,
5332
5345
  offset: 0,
@@ -5338,7 +5351,7 @@ function setPatch(editor, patch) {
5338
5351
  text: value.text
5339
5352
  }), editor.onChange());
5340
5353
  } else
5341
- debug$b("Setting non-text property"), editor.apply({
5354
+ debug$c("Setting non-text property"), editor.apply({
5342
5355
  type: "set_node",
5343
5356
  path: childPath,
5344
5357
  properties: {},
@@ -5346,7 +5359,7 @@ function setPatch(editor, patch) {
5346
5359
  });
5347
5360
  return !0;
5348
5361
  } else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
5349
- debug$b("Setting block property");
5362
+ debug$c("Setting block property");
5350
5363
  const {
5351
5364
  children,
5352
5365
  ...nextRest
@@ -5363,7 +5376,7 @@ function setPatch(editor, patch) {
5363
5376
  ...prevRest
5364
5377
  },
5365
5378
  newProperties: nextRest
5366
- }), debug$b("Setting children"), block.children.forEach((c2, cIndex) => {
5379
+ }), debug$c("Setting children"), block.children.forEach((c2, cIndex) => {
5367
5380
  editor.apply({
5368
5381
  type: "remove_node",
5369
5382
  path: blockPath.concat(block.children.length - 1 - cIndex),
@@ -5394,7 +5407,7 @@ function setPatch(editor, patch) {
5394
5407
  }
5395
5408
  function unsetPatch(editor, patch) {
5396
5409
  if (patch.path.length === 0) {
5397
- debug$b("Removing everything"), debugState(editor, "before");
5410
+ debug$c("Removing everything"), debugState(editor, "before");
5398
5411
  const previousSelection = editor.selection;
5399
5412
  return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
5400
5413
  Transforms.removeNodes(editor, {
@@ -5421,13 +5434,13 @@ function unsetPatch(editor, patch) {
5421
5434
  } = findBlockAndChildFromPath(editor, patch.path);
5422
5435
  if (patch.path.length === 1) {
5423
5436
  if (!block || !blockPath)
5424
- return debug$b("Block not found"), !1;
5437
+ return debug$c("Block not found"), !1;
5425
5438
  const blockIndex = blockPath[0];
5426
- return debug$b(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
5439
+ return debug$c(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
5427
5440
  at: [blockIndex]
5428
5441
  }), debugState(editor, "after"), !0;
5429
5442
  }
5430
- return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$b("Child not found"), !1) : (debug$b(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$b(`Removing child at path ${JSON.stringify(childPath)}`), Transforms.removeNodes(editor, {
5443
+ return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$c("Child not found"), !1) : (debug$c(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$c(`Removing child at path ${JSON.stringify(childPath)}`), Transforms.removeNodes(editor, {
5431
5444
  at: childPath
5432
5445
  }), debugState(editor, "after"), !0) : !1;
5433
5446
  }
@@ -5435,7 +5448,7 @@ function isKeyedSegment(segment) {
5435
5448
  return typeof segment == "object" && "_key" in segment;
5436
5449
  }
5437
5450
  function debugState(editor, stateName) {
5438
- debugVerbose && (debug$b(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$b(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
5451
+ debugVerbose && (debug$c(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$c(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
5439
5452
  }
5440
5453
  function findBlockFromPath(editor, path) {
5441
5454
  let blockIndex = -1;
@@ -5477,7 +5490,7 @@ function findBlockAndChildFromPath(editor, path) {
5477
5490
  childPath: void 0
5478
5491
  };
5479
5492
  }
5480
- const debug$a = debugWithName("plugin:withPatches");
5493
+ const debug$b = debugWithName("plugin:withPatches");
5481
5494
  function createWithPatches({
5482
5495
  editorActor,
5483
5496
  patchFunctions,
@@ -5502,7 +5515,7 @@ function createWithPatches({
5502
5515
  withoutPatching(editor, () => {
5503
5516
  withoutSaving(editor, () => {
5504
5517
  for (const patch of patches) {
5505
- debug$a.enabled && debug$a(`Handling remote patch ${JSON.stringify(patch)}`);
5518
+ debug$b.enabled && debug$b(`Handling remote patch ${JSON.stringify(patch)}`);
5506
5519
  try {
5507
5520
  changed = applyPatch(editor, patch);
5508
5521
  } catch (error) {
@@ -5520,10 +5533,10 @@ function createWithPatches({
5520
5533
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
5521
5534
  };
5522
5535
  return subscriptions.push(() => {
5523
- debug$a("Subscribing to remote patches");
5536
+ debug$b("Subscribing to remote patches");
5524
5537
  const sub = editorActor.on("patches", handlePatches);
5525
5538
  return () => {
5526
- debug$a("Unsubscribing to remote patches"), sub.unsubscribe();
5539
+ debug$b("Unsubscribing to remote patches"), sub.unsubscribe();
5527
5540
  };
5528
5541
  }), editor.apply = (operation) => {
5529
5542
  let patches = [];
@@ -5577,7 +5590,7 @@ function createWithPatches({
5577
5590
  }, editor;
5578
5591
  };
5579
5592
  }
5580
- const debug$9 = debugWithName("plugin:withPlaceholderBlock");
5593
+ const debug$a = debugWithName("plugin:withPlaceholderBlock");
5581
5594
  function createWithPlaceholderBlock(editorActor) {
5582
5595
  return function(editor) {
5583
5596
  const {
@@ -5602,7 +5615,7 @@ function createWithPlaceholderBlock(editorActor) {
5602
5615
  const node = op.node;
5603
5616
  if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
5604
5617
  const nextPath = Path.next(op.path);
5605
- editor.children[nextPath[0]] || (debug$9("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
5618
+ editor.children[nextPath[0]] || (debug$a("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
5606
5619
  decorators: []
5607
5620
  })));
5608
5621
  }
@@ -5611,7 +5624,7 @@ function createWithPlaceholderBlock(editorActor) {
5611
5624
  }, editor;
5612
5625
  };
5613
5626
  }
5614
- const debug$8 = debugWithName("plugin:withPortableTextBlockStyle");
5627
+ const debug$9 = debugWithName("plugin:withPortableTextBlockStyle");
5615
5628
  function createWithPortableTextBlockStyle(editorActor) {
5616
5629
  const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
5617
5630
  return function(editor) {
@@ -5624,7 +5637,7 @@ function createWithPortableTextBlockStyle(editorActor) {
5624
5637
  if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !Path.equals(path, op.path)) {
5625
5638
  const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
5626
5639
  if (Text.isText(child) && child.text === "") {
5627
- debug$8(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
5640
+ debug$9(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
5628
5641
  type: "normalizing"
5629
5642
  }), Transforms.setNodes(editor, {
5630
5643
  style: defaultStyle
@@ -5675,7 +5688,7 @@ function createWithPortableTextSelections(editorActor) {
5675
5688
  }, editor;
5676
5689
  };
5677
5690
  }
5678
- const debug$7 = debugWithName("plugin:withSchemaTypes");
5691
+ const debug$8 = debugWithName("plugin:withSchemaTypes");
5679
5692
  function createWithSchemaTypes({
5680
5693
  editorActor
5681
5694
  }) {
@@ -5687,7 +5700,7 @@ function createWithSchemaTypes({
5687
5700
  return editor.normalizeNode = (entry) => {
5688
5701
  const [node, path] = entry;
5689
5702
  if (node._type === void 0 && path.length === 2) {
5690
- debug$7("Setting span type on text node without a type");
5703
+ debug$8("Setting span type on text node without a type");
5691
5704
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
5692
5705
  editorActor.send({
5693
5706
  type: "normalizing"
@@ -5703,7 +5716,7 @@ function createWithSchemaTypes({
5703
5716
  return;
5704
5717
  }
5705
5718
  if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
5706
- debug$7("Setting missing key on child node without a key");
5719
+ debug$8("Setting missing key on child node without a key");
5707
5720
  const key = editorActor.getSnapshot().context.keyGenerator();
5708
5721
  editorActor.send({
5709
5722
  type: "normalizing"
@@ -5764,12 +5777,12 @@ const withPlugins = (editor, options) => {
5764
5777
  editorActor
5765
5778
  }), withPortableTextSelections = createWithPortableTextSelections(editorActor);
5766
5779
  return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
5767
- }, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
5780
+ }, debug$7 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
5768
5781
  function createSlateEditor(config) {
5769
5782
  const existingSlateEditor = slateEditors.get(config.editorActor);
5770
5783
  if (existingSlateEditor)
5771
- return debug$6("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
5772
- debug$6("Creating new Slate editor instance", config.editorActor.id);
5784
+ return debug$7("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
5785
+ debug$7("Creating new Slate editor instance", config.editorActor.id);
5773
5786
  const unsubscriptions = [], subscriptions = [], instance = withPlugins(withReact(createEditor()), {
5774
5787
  editorActor: config.editorActor,
5775
5788
  subscriptions
@@ -6056,7 +6069,7 @@ function getEditorSnapshot({
6056
6069
  }
6057
6070
  };
6058
6071
  }
6059
- const debug$5 = debugWithName("API:editable");
6072
+ const debug$6 = debugWithName("API:editable");
6060
6073
  function createEditableAPI(editor, editorActor) {
6061
6074
  const types = editorActor.getSnapshot().context.schema;
6062
6075
  return {
@@ -6189,7 +6202,7 @@ function createEditableAPI(editor, editorActor) {
6189
6202
  }], {
6190
6203
  schemaTypes: editorActor.getSnapshot().context.schema
6191
6204
  })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
6192
- return isSpanNode && focusNode._type !== types.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
6205
+ return isSpanNode && focusNode._type !== types.span.name && (debug$6("Inserting span child next to inline object child, moving selection + 1"), editor.move({
6193
6206
  distance: 1,
6194
6207
  unit: "character"
6195
6208
  })), Transforms.insertNodes(editor, child, {
@@ -6334,18 +6347,18 @@ function createEditableAPI(editor, editorActor) {
6334
6347
  throw new Error("Invalid range");
6335
6348
  if (range) {
6336
6349
  if (!options?.mode || options?.mode === "selected") {
6337
- debug$5("Deleting content in selection"), Transforms.delete(editor, {
6350
+ debug$6("Deleting content in selection"), Transforms.delete(editor, {
6338
6351
  at: range,
6339
6352
  hanging: !0,
6340
6353
  voids: !0
6341
6354
  }), editor.onChange();
6342
6355
  return;
6343
6356
  }
6344
- options?.mode === "blocks" && (debug$5("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
6357
+ options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
6345
6358
  at: range,
6346
6359
  voids: !0,
6347
6360
  match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
6348
- })), options?.mode === "children" && (debug$5("Deleting children touched by selection"), Transforms.removeNodes(editor, {
6361
+ })), options?.mode === "children" && (debug$6("Deleting children touched by selection"), Transforms.removeNodes(editor, {
6349
6362
  at: range,
6350
6363
  voids: !0,
6351
6364
  match: (node) => node._type === types.span.name || // Text children
@@ -8104,7 +8117,7 @@ function isNativeBehaviorEvent(event) {
8104
8117
  function isCustomBehaviorEvent(event) {
8105
8118
  return event.type.startsWith("custom.");
8106
8119
  }
8107
- const debug$4 = debugWithName("behaviors:event");
8120
+ const debug$5 = debugWithName("behaviors:event");
8108
8121
  function eventCategory(event) {
8109
8122
  return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
8110
8123
  }
@@ -8119,7 +8132,7 @@ function performEvent({
8119
8132
  getSnapshot,
8120
8133
  nativeEvent
8121
8134
  }) {
8122
- debug$4(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
8135
+ debug$5(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
8123
8136
  const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
8124
8137
  if (behavior.on === "*")
8125
8138
  return !0;
@@ -8128,7 +8141,7 @@ function performEvent({
8128
8141
  });
8129
8142
  if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
8130
8143
  nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
8131
- debug$4(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
8144
+ debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
8132
8145
  context: {
8133
8146
  keyGenerator,
8134
8147
  schema
@@ -8271,7 +8284,7 @@ function performEvent({
8271
8284
  }
8272
8285
  }
8273
8286
  !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
8274
- debug$4(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
8287
+ debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
8275
8288
  context: {
8276
8289
  keyGenerator,
8277
8290
  schema
@@ -8359,7 +8372,7 @@ function createEditorSnapshot({
8359
8372
  }
8360
8373
  };
8361
8374
  }
8362
- const editorMachine = setup({
8375
+ const debug$4 = debugWithName("editor machine"), editorMachine = setup({
8363
8376
  types: {
8364
8377
  context: {},
8365
8378
  events: {},
@@ -8640,6 +8653,12 @@ const editorMachine = setup({
8640
8653
  },
8641
8654
  states: {
8642
8655
  "determine initial edit mode": {
8656
+ entry: [() => {
8657
+ debug$4("entry: edit mode->read only->determine initial edit mode");
8658
+ }],
8659
+ exit: [() => {
8660
+ debug$4("exit: edit mode->read only->determine initial edit mode");
8661
+ }],
8643
8662
  on: {
8644
8663
  "done syncing value": [{
8645
8664
  target: "#editor.edit mode.read only.read only",
@@ -8652,6 +8671,12 @@ const editorMachine = setup({
8652
8671
  }
8653
8672
  },
8654
8673
  "read only": {
8674
+ entry: [() => {
8675
+ debug$4("entry: edit mode->read only->read only");
8676
+ }],
8677
+ exit: [() => {
8678
+ debug$4("exit: edit mode->read only->read only");
8679
+ }],
8655
8680
  on: {
8656
8681
  "update readOnly": {
8657
8682
  guard: ({
@@ -8691,6 +8716,12 @@ const editorMachine = setup({
8691
8716
  initial: "idle",
8692
8717
  states: {
8693
8718
  idle: {
8719
+ entry: [() => {
8720
+ debug$4("entry: edit mode->editable->idle");
8721
+ }],
8722
+ exit: [() => {
8723
+ debug$4("exit: edit mode->editable-idle");
8724
+ }],
8694
8725
  on: {
8695
8726
  dragstart: {
8696
8727
  actions: [assign({
@@ -8709,6 +8740,12 @@ const editorMachine = setup({
8709
8740
  initial: "checking if busy",
8710
8741
  states: {
8711
8742
  "checking if busy": {
8743
+ entry: [() => {
8744
+ debug$4("entry: edit mode->editable->focusing->checking if busy");
8745
+ }],
8746
+ exit: [() => {
8747
+ debug$4("exit: edit mode->editable->focusing->checking if busy");
8748
+ }],
8712
8749
  always: [{
8713
8750
  guard: "slate is busy",
8714
8751
  target: "busy"
@@ -8718,6 +8755,12 @@ const editorMachine = setup({
8718
8755
  }]
8719
8756
  },
8720
8757
  busy: {
8758
+ entry: [() => {
8759
+ debug$4("entry: edit mode->editable->focusing-busy");
8760
+ }],
8761
+ exit: [() => {
8762
+ debug$4("exit: edit mode->editable->focusing->busy");
8763
+ }],
8721
8764
  after: {
8722
8765
  10: {
8723
8766
  target: "checking if busy"
@@ -8727,7 +8770,12 @@ const editorMachine = setup({
8727
8770
  }
8728
8771
  },
8729
8772
  "dragging internally": {
8730
- exit: [({
8773
+ entry: [() => {
8774
+ debug$4("entry: edit mode->editable->dragging internally");
8775
+ }],
8776
+ exit: [() => {
8777
+ debug$4("exit: edit mode->editable->dragging internally");
8778
+ }, ({
8731
8779
  context
8732
8780
  }) => {
8733
8781
  if (context.internalDrag?.ghost)
@@ -8757,7 +8805,12 @@ const editorMachine = setup({
8757
8805
  initial: "setting up",
8758
8806
  states: {
8759
8807
  "setting up": {
8760
- exit: ["emit ready", "emit pending incoming patches", "clear pending incoming patches"],
8808
+ entry: [() => {
8809
+ debug$4("entry: setup->setting up");
8810
+ }],
8811
+ exit: [() => {
8812
+ debug$4("exit: setup->setting up");
8813
+ }, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
8761
8814
  on: {
8762
8815
  "internal.patch": {
8763
8816
  actions: "defer event"
@@ -8780,6 +8833,12 @@ const editorMachine = setup({
8780
8833
  initial: "idle",
8781
8834
  states: {
8782
8835
  idle: {
8836
+ entry: [() => {
8837
+ debug$4("entry: setup->set up->value sync->idle");
8838
+ }],
8839
+ exit: [() => {
8840
+ debug$4("exit: setup->set up->value sync->idle");
8841
+ }],
8783
8842
  on: {
8784
8843
  patches: {
8785
8844
  actions: [emit(({
@@ -8792,7 +8851,12 @@ const editorMachine = setup({
8792
8851
  }
8793
8852
  },
8794
8853
  "syncing value": {
8795
- exit: ["emit pending incoming patches", "clear pending incoming patches"],
8854
+ entry: [() => {
8855
+ debug$4("entry: setup->set up->value sync->syncing value");
8856
+ }],
8857
+ exit: [() => {
8858
+ debug$4("exit: setup->set up->value sync->syncing value");
8859
+ }, "emit pending incoming patches", "clear pending incoming patches"],
8796
8860
  on: {
8797
8861
  patches: {
8798
8862
  actions: ["defer incoming patches"]
@@ -8811,6 +8875,12 @@ const editorMachine = setup({
8811
8875
  initial: "idle",
8812
8876
  states: {
8813
8877
  idle: {
8878
+ entry: [() => {
8879
+ debug$4("entry: setup->set up->writing->pristine->idle");
8880
+ }],
8881
+ exit: [() => {
8882
+ debug$4("exit: setup->set up->writing->pristine->idle");
8883
+ }],
8814
8884
  on: {
8815
8885
  normalizing: {
8816
8886
  target: "normalizing"
@@ -8826,6 +8896,12 @@ const editorMachine = setup({
8826
8896
  }
8827
8897
  },
8828
8898
  normalizing: {
8899
+ entry: [() => {
8900
+ debug$4("entry: setup->set up->writing->pristine->normalizing");
8901
+ }],
8902
+ exit: [() => {
8903
+ debug$4("exit: setup->set up->writing->pristine->normalizing");
8904
+ }],
8829
8905
  on: {
8830
8906
  "done normalizing": {
8831
8907
  target: "idle"
@@ -8841,7 +8917,12 @@ const editorMachine = setup({
8841
8917
  }
8842
8918
  },
8843
8919
  dirty: {
8844
- entry: ["emit pending events", "clear pending events"],
8920
+ entry: [() => {
8921
+ debug$4("entry: setup->set up->writing->dirty");
8922
+ }, "emit pending events", "clear pending events"],
8923
+ exit: [() => {
8924
+ debug$4("exit: setup->set up->writing->dirty");
8925
+ }],
8845
8926
  on: {
8846
8927
  "internal.patch": {
8847
8928
  actions: "emit patch event"
@@ -9906,12 +9987,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
9906
9987
  type: "range decorations updated",
9907
9988
  rangeDecorations: rangeDecorations ?? []
9908
9989
  });
9909
- }, [rangeDecorationsActor, rangeDecorations]), useMemo(() => {
9910
- if (readOnly)
9911
- return debug("Editable is in read only mode"), slateEditor;
9912
- const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
9913
- return debug("Editable is in edit mode"), withHotKeys(slateEditor);
9914
- }, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
9990
+ }, [rangeDecorationsActor, rangeDecorations]), useMemo(() => readOnly ? slateEditor : createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor), [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
9915
9991
  const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, spellCheck }), [spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((leafProps) => /* @__PURE__ */ jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), [readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder]), renderText = useCallback((props_0) => /* @__PURE__ */ jsx(RenderText, { ...props_0 }), []), restoreSelectionFromProps = useCallback(() => {
9916
9992
  if (propsSelection) {
9917
9993
  debug(`Selection from props ${JSON.stringify(propsSelection)}`);