@portabletext/editor 1.49.4 → 1.49.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/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);
@@ -3065,28 +3045,29 @@ async function updateValue({
3065
3045
  streamBlocks ? await new Promise((resolve) => {
3066
3046
  Editor.withoutNormalizing(slateEditor, () => {
3067
3047
  withRemoteChanges(slateEditor, () => {
3068
- withoutPatching(slateEditor, async () => {
3048
+ withoutPatching(slateEditor, () => {
3069
3049
  isChanged = removeExtraBlocks({
3070
3050
  slateEditor,
3071
3051
  slateValueFromProps
3072
- });
3073
- for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
3074
- slateValue: slateValueFromProps
3075
- })) {
3076
- const {
3077
- blockChanged,
3078
- blockValid
3079
- } = syncBlock({
3080
- context,
3081
- sendBack,
3082
- block: currentBlock,
3083
- index: currentBlockIndex,
3084
- slateEditor,
3085
- value
3086
- });
3087
- isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
3088
- }
3089
- resolve();
3052
+ }), (async () => {
3053
+ for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
3054
+ slateValue: slateValueFromProps
3055
+ })) {
3056
+ const {
3057
+ blockChanged,
3058
+ blockValid
3059
+ } = syncBlock({
3060
+ context,
3061
+ sendBack,
3062
+ block: currentBlock,
3063
+ index: currentBlockIndex,
3064
+ slateEditor,
3065
+ value
3066
+ });
3067
+ isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
3068
+ }
3069
+ resolve();
3070
+ })();
3090
3071
  });
3091
3072
  });
3092
3073
  });
@@ -3117,14 +3098,14 @@ async function updateValue({
3117
3098
  });
3118
3099
  }
3119
3100
  if (!isValid) {
3120
- debug$f("Invalid value, returning"), sendBack({
3101
+ debug$g("Invalid value, returning"), sendBack({
3121
3102
  type: "done syncing",
3122
3103
  value
3123
3104
  });
3124
3105
  return;
3125
3106
  }
3126
3107
  if (isChanged) {
3127
- debug$f("Server value changed, syncing editor");
3108
+ debug$g("Server value changed, syncing editor");
3128
3109
  try {
3129
3110
  slateEditor.onChange();
3130
3111
  } catch (err) {
@@ -3152,7 +3133,7 @@ async function updateValue({
3152
3133
  value
3153
3134
  });
3154
3135
  } else
3155
- debug$f("Server value and editor value is equal, no need to sync.");
3136
+ debug$g("Server value and editor value is equal, no need to sync.");
3156
3137
  sendBack({
3157
3138
  type: "done syncing",
3158
3139
  value
@@ -3200,7 +3181,7 @@ function syncBlock({
3200
3181
  type: "patch",
3201
3182
  patch
3202
3183
  });
3203
- })), 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({
3184
+ })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$g.enabled && debug$g("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$g.enabled && debug$g("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
3204
3185
  type: "invalid value",
3205
3186
  resolution: validation.resolution,
3206
3187
  value
@@ -3208,9 +3189,9 @@ function syncBlock({
3208
3189
  }
3209
3190
  if (!oldBlock && blockValid) {
3210
3191
  const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
3211
- 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, {
3192
+ debug$g.enabled && debug$g("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
3212
3193
  at: [currentBlockIndex]
3213
- }) : (debug$f("Invalid", validation), sendBack({
3194
+ }) : (debug$g("Invalid", validation), sendBack({
3214
3195
  type: "invalid value",
3215
3196
  resolution: validation.resolution,
3216
3197
  value
@@ -3238,14 +3219,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
3238
3219
  const oldBlockChildrenLength = oldBlock.children.length;
3239
3220
  currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
3240
3221
  const childIndex = oldBlockChildrenLength - 1 - index;
3241
- childIndex > 0 && (debug$f("Removing child"), Transforms.removeNodes(slateEditor, {
3222
+ childIndex > 0 && (debug$g("Removing child"), Transforms.removeNodes(slateEditor, {
3242
3223
  at: [currentBlockIndex, childIndex]
3243
3224
  }));
3244
3225
  }), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
3245
3226
  const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
3246
3227
  if (isChildChanged)
3247
3228
  if (currentBlockChild._key === oldBlockChild?._key) {
3248
- debug$f("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
3229
+ debug$g("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
3249
3230
  at: path
3250
3231
  });
3251
3232
  const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
@@ -3262,23 +3243,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
3262
3243
  }
3263
3244
  }), Transforms.insertText(slateEditor, currentBlockChild.text, {
3264
3245
  at: path
3265
- }), slateEditor.onChange()) : isSpanNode || (debug$f("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
3246
+ }), slateEditor.onChange()) : isSpanNode || (debug$g("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
3266
3247
  _key: VOID_CHILD_KEY
3267
3248
  }, {
3268
3249
  at: [...path, 0],
3269
3250
  voids: !0
3270
3251
  }));
3271
- } else oldBlockChild ? (debug$f("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
3252
+ } else oldBlockChild ? (debug$g("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
3272
3253
  at: [currentBlockIndex, currentBlockChildIndex]
3273
3254
  }), Transforms.insertNodes(slateEditor, currentBlockChild, {
3274
3255
  at: [currentBlockIndex, currentBlockChildIndex]
3275
- }), slateEditor.onChange()) : oldBlockChild || (debug$f("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
3256
+ }), slateEditor.onChange()) : oldBlockChild || (debug$g("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
3276
3257
  at: [currentBlockIndex, currentBlockChildIndex]
3277
3258
  }), slateEditor.onChange());
3278
3259
  });
3279
3260
  }
3280
3261
  }
3281
- const debug$e = debugWithName("component:PortableTextEditor:Synchronizer");
3262
+ const debug$f = debugWithName("component:PortableTextEditor:Synchronizer");
3282
3263
  function Synchronizer(props) {
3283
3264
  const $ = c(41), {
3284
3265
  editorActor,
@@ -3374,14 +3355,14 @@ function Synchronizer(props) {
3374
3355
  }, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), useEffect(t11, t12);
3375
3356
  let t13, t14;
3376
3357
  $[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
3377
- debug$e("Value from props changed, syncing new value"), syncActorRef.send({
3358
+ debug$f("Value from props changed, syncing new value"), syncActorRef.send({
3378
3359
  type: "update value",
3379
3360
  value: incomingValue
3380
3361
  });
3381
3362
  }, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), useEffect(t13, t14);
3382
3363
  let t15;
3383
3364
  $[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
3384
- debug$e("Subscribing to patch events");
3365
+ debug$f("Subscribing to patch events");
3385
3366
  const sub = editorActor.on("internal.patch", (event_1) => {
3386
3367
  mutationActorRef.send({
3387
3368
  ...event_1,
@@ -3389,7 +3370,7 @@ function Synchronizer(props) {
3389
3370
  });
3390
3371
  });
3391
3372
  return () => {
3392
- debug$e("Unsubscribing to patch events"), sub.unsubscribe();
3373
+ debug$f("Unsubscribing to patch events"), sub.unsubscribe();
3393
3374
  };
3394
3375
  }, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
3395
3376
  let t16;
@@ -3404,11 +3385,11 @@ function _temp$1(s) {
3404
3385
  return s.context.incomingValue;
3405
3386
  }
3406
3387
  Synchronizer.displayName = "Synchronizer";
3407
- const debug$d = debugWithName("operationToPatches");
3388
+ const debug$e = debugWithName("operationToPatches");
3408
3389
  function createOperationToPatches(editorActor) {
3409
3390
  const textBlockName = editorActor.getSnapshot().context.schema.block.name;
3410
3391
  function insertTextPatch(editor, operation, beforeValue) {
3411
- debug$d.enabled && debug$d("Operation", JSON.stringify(operation, null, 2));
3392
+ debug$e.enabled && debug$e("Operation", JSON.stringify(operation, null, 2));
3412
3393
  const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
3413
3394
  if (!block)
3414
3395
  throw new Error("Could not find block");
@@ -3501,7 +3482,7 @@ function createOperationToPatches(editorActor) {
3501
3482
  _key: block.children[operation.path[1] - 1]._key
3502
3483
  }])];
3503
3484
  }
3504
- return debug$d("Something was inserted into a void block. Not producing editor patches."), [];
3485
+ return debug$e("Something was inserted into a void block. Not producing editor patches."), [];
3505
3486
  }
3506
3487
  function splitNodePatch(editor, operation, beforeValue) {
3507
3488
  const patches = [], splitBlock = editor.children[operation.path[0]];
@@ -3559,9 +3540,9 @@ function createOperationToPatches(editorActor) {
3559
3540
  _key: block._key
3560
3541
  }, "children", {
3561
3542
  _key: spanToRemove._key
3562
- }])] : (debug$d("Span not found in editor trying to remove node"), []);
3543
+ }])] : (debug$e("Span not found in editor trying to remove node"), []);
3563
3544
  } else
3564
- return debug$d("Not creating patch inside object block"), [];
3545
+ return debug$e("Not creating patch inside object block"), [];
3565
3546
  }
3566
3547
  function mergeNodePatch(editor, operation, beforeValue) {
3567
3548
  const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
@@ -3587,7 +3568,7 @@ function createOperationToPatches(editorActor) {
3587
3568
  _key: removedSpan._key
3588
3569
  }])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
3589
3570
  } else
3590
- debug$d("Void nodes can't be merged, not creating any patches");
3571
+ debug$e("Void nodes can't be merged, not creating any patches");
3591
3572
  return patches;
3592
3573
  }
3593
3574
  function moveNodePatch(editor, operation, beforeValue) {
@@ -3677,7 +3658,7 @@ function getNextSpan({
3677
3658
  }
3678
3659
  return nextSpan;
3679
3660
  }
3680
- const debug$c = debugWithName("plugin:withPortableTextMarkModel");
3661
+ const debug$d = debugWithName("plugin:withPortableTextMarkModel");
3681
3662
  function createWithPortableTextMarkModel(editorActor) {
3682
3663
  return function(editor) {
3683
3664
  const {
@@ -3691,7 +3672,7 @@ function createWithPortableTextMarkModel(editorActor) {
3691
3672
  for (const [child, childPath] of children) {
3692
3673
  const nextNode = node.children[childPath[1] + 1];
3693
3674
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
3694
- debug$c("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3675
+ debug$d("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
3695
3676
  type: "normalizing"
3696
3677
  }), Transforms.mergeNodes(editor, {
3697
3678
  at: [childPath[0], childPath[1] + 1],
@@ -3704,7 +3685,7 @@ function createWithPortableTextMarkModel(editorActor) {
3704
3685
  }
3705
3686
  }
3706
3687
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
3707
- debug$c("Adding .markDefs to block node"), editorActor.send({
3688
+ debug$d("Adding .markDefs to block node"), editorActor.send({
3708
3689
  type: "normalizing"
3709
3690
  }), Transforms.setNodes(editor, {
3710
3691
  markDefs: []
@@ -3716,7 +3697,7 @@ function createWithPortableTextMarkModel(editorActor) {
3716
3697
  return;
3717
3698
  }
3718
3699
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
3719
- debug$c("Adding .marks to span node"), editorActor.send({
3700
+ debug$d("Adding .marks to span node"), editorActor.send({
3720
3701
  type: "normalizing"
3721
3702
  }), Transforms.setNodes(editor, {
3722
3703
  marks: []
@@ -3730,7 +3711,7 @@ function createWithPortableTextMarkModel(editorActor) {
3730
3711
  if (editor.isTextSpan(node)) {
3731
3712
  const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
3732
3713
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
3733
- debug$c("Removing annotations from empty span node"), editorActor.send({
3714
+ debug$d("Removing annotations from empty span node"), editorActor.send({
3734
3715
  type: "normalizing"
3735
3716
  }), Transforms.setNodes(editor, {
3736
3717
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -3748,7 +3729,7 @@ function createWithPortableTextMarkModel(editorActor) {
3748
3729
  if (editor.isTextSpan(child)) {
3749
3730
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
3750
3731
  if (orphanedAnnotations.length > 0) {
3751
- debug$c("Removing orphaned annotations from span node"), editorActor.send({
3732
+ debug$d("Removing orphaned annotations from span node"), editorActor.send({
3752
3733
  type: "normalizing"
3753
3734
  }), Transforms.setNodes(editor, {
3754
3735
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3766,7 +3747,7 @@ function createWithPortableTextMarkModel(editorActor) {
3766
3747
  if (editor.isTextBlock(block)) {
3767
3748
  const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
3768
3749
  if (orphanedAnnotations.length > 0) {
3769
- debug$c("Removing orphaned annotations from span node"), editorActor.send({
3750
+ debug$d("Removing orphaned annotations from span node"), editorActor.send({
3770
3751
  type: "normalizing"
3771
3752
  }), Transforms.setNodes(editor, {
3772
3753
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -3784,7 +3765,7 @@ function createWithPortableTextMarkModel(editorActor) {
3784
3765
  for (const markDef of markDefs)
3785
3766
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
3786
3767
  if (markDefs.length !== newMarkDefs.length) {
3787
- debug$c("Removing duplicate markDefs"), editorActor.send({
3768
+ debug$d("Removing duplicate markDefs"), editorActor.send({
3788
3769
  type: "normalizing"
3789
3770
  }), Transforms.setNodes(editor, {
3790
3771
  markDefs: newMarkDefs
@@ -3799,7 +3780,7 @@ function createWithPortableTextMarkModel(editorActor) {
3799
3780
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
3800
3781
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
3801
3782
  if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
3802
- debug$c("Removing markDef not in use"), editorActor.send({
3783
+ debug$d("Removing markDef not in use"), editorActor.send({
3803
3784
  type: "normalizing"
3804
3785
  }), Transforms.setNodes(editor, {
3805
3786
  markDefs: newMarkDefs
@@ -4019,7 +4000,7 @@ function createWithPortableTextMarkModel(editorActor) {
4019
4000
  const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
4020
4001
  if (editor.isTextBlock(targetBlock)) {
4021
4002
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
4022
- debug$c("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
4003
+ debug$d("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
4023
4004
  markDefs: newMarkDefs
4024
4005
  }, {
4025
4006
  at: targetPath,
@@ -5243,13 +5224,13 @@ function createWithObjectKeys(editorActor) {
5243
5224
  }, editor;
5244
5225
  };
5245
5226
  }
5246
- const debug$b = debugWithName("applyPatches"), debugVerbose = debug$b.enabled && !0;
5227
+ const debug$c = debugWithName("applyPatches"), debugVerbose = debug$c.enabled && !0;
5247
5228
  function createApplyPatch(schema) {
5248
5229
  return (editor, patch) => {
5249
5230
  let changed = !1;
5250
- debugVerbose && (debug$b(`
5231
+ debugVerbose && (debug$c(`
5251
5232
 
5252
- NEW PATCH =============================================================`), debug$b(JSON.stringify(patch, null, 2)));
5233
+ NEW PATCH =============================================================`), debug$c(JSON.stringify(patch, null, 2)));
5253
5234
  try {
5254
5235
  switch (patch.type) {
5255
5236
  case "insert":
@@ -5265,7 +5246,7 @@ NEW PATCH =============================================================`), debug
5265
5246
  changed = diffMatchPatch(editor, patch);
5266
5247
  break;
5267
5248
  default:
5268
- debug$b("Unhandled patch", patch.type);
5249
+ debug$c("Unhandled patch", patch.type);
5269
5250
  }
5270
5251
  } catch (err) {
5271
5252
  console.error(err);
@@ -5280,9 +5261,9 @@ function diffMatchPatch(editor, patch) {
5280
5261
  childPath
5281
5262
  } = findBlockAndChildFromPath(editor, patch.path);
5282
5263
  if (!block)
5283
- return debug$b("Block not found"), !1;
5264
+ return debug$c("Block not found"), !1;
5284
5265
  if (!child || !childPath)
5285
- return debug$b("Child not found"), !1;
5266
+ return debug$c("Child not found"), !1;
5286
5267
  if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
5287
5268
  return !1;
5288
5269
  const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
@@ -5312,9 +5293,9 @@ function insertPatch(editor, patch, schema) {
5312
5293
  childPath: targetChildPath
5313
5294
  } = findBlockAndChildFromPath(editor, patch.path);
5314
5295
  if (!targetBlock || !targetBlockPath)
5315
- return debug$b("Block not found"), !1;
5296
+ return debug$c("Block not found"), !1;
5316
5297
  if (patch.path.length > 1 && patch.path[1] !== "children")
5317
- return debug$b("Ignoring patch targeting void value"), !1;
5298
+ return debug$c("Ignoring patch targeting void value"), !1;
5318
5299
  if (patch.path.length === 1) {
5319
5300
  const {
5320
5301
  items: items2,
@@ -5322,7 +5303,7 @@ function insertPatch(editor, patch, schema) {
5322
5303
  } = patch, blocksToInsert = toSlateValue(items2, {
5323
5304
  schemaTypes: schema
5324
5305
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
5325
- return debug$b(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
5306
+ return debug$c(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
5326
5307
  at: [normalizedIdx2]
5327
5308
  }), debugState(editor, "after"), !0;
5328
5309
  }
@@ -5331,14 +5312,14 @@ function insertPatch(editor, patch, schema) {
5331
5312
  position
5332
5313
  } = patch;
5333
5314
  if (!targetChild || !targetChildPath)
5334
- return debug$b("Child not found"), !1;
5315
+ return debug$c("Child not found"), !1;
5335
5316
  const childrenToInsert = targetBlock && toSlateValue([{
5336
5317
  ...targetBlock,
5337
5318
  children: items
5338
5319
  }], {
5339
5320
  schemaTypes: schema
5340
5321
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
5341
- return debug$b(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
5322
+ return debug$c(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
5342
5323
  at: childInsertPath
5343
5324
  }), debugState(editor, "after"), !0;
5344
5325
  }
@@ -5352,14 +5333,14 @@ function setPatch(editor, patch) {
5352
5333
  childPath
5353
5334
  } = findBlockAndChildFromPath(editor, patch.path);
5354
5335
  if (!block)
5355
- return debug$b("Block not found"), !1;
5336
+ return debug$c("Block not found"), !1;
5356
5337
  const isTextBlock2 = editor.isTextBlock(block);
5357
5338
  if (isTextBlock2 && patch.path.length > 1 && patch.path[1] !== "children")
5358
- return debug$b("Ignoring setting void value"), !1;
5339
+ return debug$c("Ignoring setting void value"), !1;
5359
5340
  if (debugState(editor, "before"), isTextBlock2 && child && childPath) {
5360
5341
  if (Text.isText(value) && Text.isText(child)) {
5361
5342
  const newText = child.text;
5362
- value.text !== newText && (debug$b("Setting text property"), editor.apply({
5343
+ value.text !== newText && (debug$c("Setting text property"), editor.apply({
5363
5344
  type: "remove_text",
5364
5345
  path: childPath,
5365
5346
  offset: 0,
@@ -5371,7 +5352,7 @@ function setPatch(editor, patch) {
5371
5352
  text: value.text
5372
5353
  }), editor.onChange());
5373
5354
  } else
5374
- debug$b("Setting non-text property"), editor.apply({
5355
+ debug$c("Setting non-text property"), editor.apply({
5375
5356
  type: "set_node",
5376
5357
  path: childPath,
5377
5358
  properties: {},
@@ -5379,7 +5360,7 @@ function setPatch(editor, patch) {
5379
5360
  });
5380
5361
  return !0;
5381
5362
  } else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
5382
- debug$b("Setting block property");
5363
+ debug$c("Setting block property");
5383
5364
  const {
5384
5365
  children,
5385
5366
  ...nextRest
@@ -5396,7 +5377,7 @@ function setPatch(editor, patch) {
5396
5377
  ...prevRest
5397
5378
  },
5398
5379
  newProperties: nextRest
5399
- }), debug$b("Setting children"), block.children.forEach((c2, cIndex) => {
5380
+ }), debug$c("Setting children"), block.children.forEach((c2, cIndex) => {
5400
5381
  editor.apply({
5401
5382
  type: "remove_node",
5402
5383
  path: blockPath.concat(block.children.length - 1 - cIndex),
@@ -5427,7 +5408,7 @@ function setPatch(editor, patch) {
5427
5408
  }
5428
5409
  function unsetPatch(editor, patch) {
5429
5410
  if (patch.path.length === 0) {
5430
- debug$b("Removing everything"), debugState(editor, "before");
5411
+ debug$c("Removing everything"), debugState(editor, "before");
5431
5412
  const previousSelection = editor.selection;
5432
5413
  return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
5433
5414
  Transforms.removeNodes(editor, {
@@ -5454,13 +5435,13 @@ function unsetPatch(editor, patch) {
5454
5435
  } = findBlockAndChildFromPath(editor, patch.path);
5455
5436
  if (patch.path.length === 1) {
5456
5437
  if (!block || !blockPath)
5457
- return debug$b("Block not found"), !1;
5438
+ return debug$c("Block not found"), !1;
5458
5439
  const blockIndex = blockPath[0];
5459
- return debug$b(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
5440
+ return debug$c(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
5460
5441
  at: [blockIndex]
5461
5442
  }), debugState(editor, "after"), !0;
5462
5443
  }
5463
- 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, {
5444
+ return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$c("Child not found"), !1) : (debug$c(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$c(`Removing child at path ${JSON.stringify(childPath)}`), Transforms.removeNodes(editor, {
5464
5445
  at: childPath
5465
5446
  }), debugState(editor, "after"), !0) : !1;
5466
5447
  }
@@ -5468,7 +5449,7 @@ function isKeyedSegment(segment) {
5468
5449
  return typeof segment == "object" && "_key" in segment;
5469
5450
  }
5470
5451
  function debugState(editor, stateName) {
5471
- debugVerbose && (debug$b(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$b(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
5452
+ debugVerbose && (debug$c(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$c(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
5472
5453
  }
5473
5454
  function findBlockFromPath(editor, path) {
5474
5455
  let blockIndex = -1;
@@ -5510,7 +5491,7 @@ function findBlockAndChildFromPath(editor, path) {
5510
5491
  childPath: void 0
5511
5492
  };
5512
5493
  }
5513
- const debug$a = debugWithName("plugin:withPatches");
5494
+ const debug$b = debugWithName("plugin:withPatches");
5514
5495
  function createWithPatches({
5515
5496
  editorActor,
5516
5497
  patchFunctions,
@@ -5535,7 +5516,7 @@ function createWithPatches({
5535
5516
  withoutPatching(editor, () => {
5536
5517
  withoutSaving(editor, () => {
5537
5518
  for (const patch of patches) {
5538
- debug$a.enabled && debug$a(`Handling remote patch ${JSON.stringify(patch)}`);
5519
+ debug$b.enabled && debug$b(`Handling remote patch ${JSON.stringify(patch)}`);
5539
5520
  try {
5540
5521
  changed = applyPatch(editor, patch);
5541
5522
  } catch (error) {
@@ -5553,10 +5534,10 @@ function createWithPatches({
5553
5534
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
5554
5535
  };
5555
5536
  return subscriptions.push(() => {
5556
- debug$a("Subscribing to remote patches");
5537
+ debug$b("Subscribing to remote patches");
5557
5538
  const sub = editorActor.on("patches", handlePatches);
5558
5539
  return () => {
5559
- debug$a("Unsubscribing to remote patches"), sub.unsubscribe();
5540
+ debug$b("Unsubscribing to remote patches"), sub.unsubscribe();
5560
5541
  };
5561
5542
  }), editor.apply = (operation) => {
5562
5543
  let patches = [];
@@ -5610,7 +5591,7 @@ function createWithPatches({
5610
5591
  }, editor;
5611
5592
  };
5612
5593
  }
5613
- const debug$9 = debugWithName("plugin:withPlaceholderBlock");
5594
+ const debug$a = debugWithName("plugin:withPlaceholderBlock");
5614
5595
  function createWithPlaceholderBlock(editorActor) {
5615
5596
  return function(editor) {
5616
5597
  const {
@@ -5635,7 +5616,7 @@ function createWithPlaceholderBlock(editorActor) {
5635
5616
  const node = op.node;
5636
5617
  if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
5637
5618
  const nextPath = Path.next(op.path);
5638
- editor.children[nextPath[0]] || (debug$9("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
5619
+ editor.children[nextPath[0]] || (debug$a("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
5639
5620
  decorators: []
5640
5621
  })));
5641
5622
  }
@@ -5644,7 +5625,7 @@ function createWithPlaceholderBlock(editorActor) {
5644
5625
  }, editor;
5645
5626
  };
5646
5627
  }
5647
- const debug$8 = debugWithName("plugin:withPortableTextBlockStyle");
5628
+ const debug$9 = debugWithName("plugin:withPortableTextBlockStyle");
5648
5629
  function createWithPortableTextBlockStyle(editorActor) {
5649
5630
  const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
5650
5631
  return function(editor) {
@@ -5657,7 +5638,7 @@ function createWithPortableTextBlockStyle(editorActor) {
5657
5638
  if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !Path.equals(path, op.path)) {
5658
5639
  const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
5659
5640
  if (Text.isText(child) && child.text === "") {
5660
- debug$8(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
5641
+ debug$9(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
5661
5642
  type: "normalizing"
5662
5643
  }), Transforms.setNodes(editor, {
5663
5644
  style: defaultStyle
@@ -5708,7 +5689,7 @@ function createWithPortableTextSelections(editorActor) {
5708
5689
  }, editor;
5709
5690
  };
5710
5691
  }
5711
- const debug$7 = debugWithName("plugin:withSchemaTypes");
5692
+ const debug$8 = debugWithName("plugin:withSchemaTypes");
5712
5693
  function createWithSchemaTypes({
5713
5694
  editorActor
5714
5695
  }) {
@@ -5720,7 +5701,7 @@ function createWithSchemaTypes({
5720
5701
  return editor.normalizeNode = (entry) => {
5721
5702
  const [node, path] = entry;
5722
5703
  if (node._type === void 0 && path.length === 2) {
5723
- debug$7("Setting span type on text node without a type");
5704
+ debug$8("Setting span type on text node without a type");
5724
5705
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
5725
5706
  editorActor.send({
5726
5707
  type: "normalizing"
@@ -5736,7 +5717,7 @@ function createWithSchemaTypes({
5736
5717
  return;
5737
5718
  }
5738
5719
  if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
5739
- debug$7("Setting missing key on child node without a key");
5720
+ debug$8("Setting missing key on child node without a key");
5740
5721
  const key = editorActor.getSnapshot().context.keyGenerator();
5741
5722
  editorActor.send({
5742
5723
  type: "normalizing"
@@ -5797,12 +5778,12 @@ const withPlugins = (editor, options) => {
5797
5778
  editorActor
5798
5779
  }), withPortableTextSelections = createWithPortableTextSelections(editorActor);
5799
5780
  return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
5800
- }, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
5781
+ }, debug$7 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
5801
5782
  function createSlateEditor(config) {
5802
5783
  const existingSlateEditor = slateEditors.get(config.editorActor);
5803
5784
  if (existingSlateEditor)
5804
- return debug$6("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
5805
- debug$6("Creating new Slate editor instance", config.editorActor.id);
5785
+ return debug$7("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
5786
+ debug$7("Creating new Slate editor instance", config.editorActor.id);
5806
5787
  const unsubscriptions = [], subscriptions = [], instance = withPlugins(withReact(createEditor()), {
5807
5788
  editorActor: config.editorActor,
5808
5789
  subscriptions
@@ -6089,7 +6070,7 @@ function getEditorSnapshot({
6089
6070
  }
6090
6071
  };
6091
6072
  }
6092
- const debug$5 = debugWithName("API:editable");
6073
+ const debug$6 = debugWithName("API:editable");
6093
6074
  function createEditableAPI(editor, editorActor) {
6094
6075
  const types = editorActor.getSnapshot().context.schema;
6095
6076
  return {
@@ -6222,7 +6203,7 @@ function createEditableAPI(editor, editorActor) {
6222
6203
  }], {
6223
6204
  schemaTypes: editorActor.getSnapshot().context.schema
6224
6205
  })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
6225
- return isSpanNode && focusNode._type !== types.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
6206
+ return isSpanNode && focusNode._type !== types.span.name && (debug$6("Inserting span child next to inline object child, moving selection + 1"), editor.move({
6226
6207
  distance: 1,
6227
6208
  unit: "character"
6228
6209
  })), Transforms.insertNodes(editor, child, {
@@ -6367,18 +6348,18 @@ function createEditableAPI(editor, editorActor) {
6367
6348
  throw new Error("Invalid range");
6368
6349
  if (range) {
6369
6350
  if (!options?.mode || options?.mode === "selected") {
6370
- debug$5("Deleting content in selection"), Transforms.delete(editor, {
6351
+ debug$6("Deleting content in selection"), Transforms.delete(editor, {
6371
6352
  at: range,
6372
6353
  hanging: !0,
6373
6354
  voids: !0
6374
6355
  }), editor.onChange();
6375
6356
  return;
6376
6357
  }
6377
- options?.mode === "blocks" && (debug$5("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
6358
+ options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
6378
6359
  at: range,
6379
6360
  voids: !0,
6380
6361
  match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
6381
- })), options?.mode === "children" && (debug$5("Deleting children touched by selection"), Transforms.removeNodes(editor, {
6362
+ })), options?.mode === "children" && (debug$6("Deleting children touched by selection"), Transforms.removeNodes(editor, {
6382
6363
  at: range,
6383
6364
  voids: !0,
6384
6365
  match: (node) => node._type === types.span.name || // Text children
@@ -8137,7 +8118,7 @@ function isNativeBehaviorEvent(event) {
8137
8118
  function isCustomBehaviorEvent(event) {
8138
8119
  return event.type.startsWith("custom.");
8139
8120
  }
8140
- const debug$4 = debugWithName("behaviors:event");
8121
+ const debug$5 = debugWithName("behaviors:event");
8141
8122
  function eventCategory(event) {
8142
8123
  return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "synthetic" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
8143
8124
  }
@@ -8152,7 +8133,7 @@ function performEvent({
8152
8133
  getSnapshot,
8153
8134
  nativeEvent
8154
8135
  }) {
8155
- debug$4(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
8136
+ debug$5(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
8156
8137
  const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
8157
8138
  if (behavior.on === "*")
8158
8139
  return !0;
@@ -8161,7 +8142,7 @@ function performEvent({
8161
8142
  });
8162
8143
  if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
8163
8144
  nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
8164
- debug$4(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
8145
+ debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
8165
8146
  context: {
8166
8147
  keyGenerator,
8167
8148
  schema
@@ -8304,7 +8285,7 @@ function performEvent({
8304
8285
  }
8305
8286
  }
8306
8287
  !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
8307
- debug$4(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
8288
+ debug$5(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
8308
8289
  context: {
8309
8290
  keyGenerator,
8310
8291
  schema
@@ -8392,7 +8373,7 @@ function createEditorSnapshot({
8392
8373
  }
8393
8374
  };
8394
8375
  }
8395
- const editorMachine = setup({
8376
+ const debug$4 = debugWithName("editor machine"), editorMachine = setup({
8396
8377
  types: {
8397
8378
  context: {},
8398
8379
  events: {},
@@ -8673,6 +8654,12 @@ const editorMachine = setup({
8673
8654
  },
8674
8655
  states: {
8675
8656
  "determine initial edit mode": {
8657
+ entry: [() => {
8658
+ debug$4("entry: edit mode->read only->determine initial edit mode");
8659
+ }],
8660
+ exit: [() => {
8661
+ debug$4("exit: edit mode->read only->determine initial edit mode");
8662
+ }],
8676
8663
  on: {
8677
8664
  "done syncing value": [{
8678
8665
  target: "#editor.edit mode.read only.read only",
@@ -8685,6 +8672,12 @@ const editorMachine = setup({
8685
8672
  }
8686
8673
  },
8687
8674
  "read only": {
8675
+ entry: [() => {
8676
+ debug$4("entry: edit mode->read only->read only");
8677
+ }],
8678
+ exit: [() => {
8679
+ debug$4("exit: edit mode->read only->read only");
8680
+ }],
8688
8681
  on: {
8689
8682
  "update readOnly": {
8690
8683
  guard: ({
@@ -8724,6 +8717,12 @@ const editorMachine = setup({
8724
8717
  initial: "idle",
8725
8718
  states: {
8726
8719
  idle: {
8720
+ entry: [() => {
8721
+ debug$4("entry: edit mode->editable->idle");
8722
+ }],
8723
+ exit: [() => {
8724
+ debug$4("exit: edit mode->editable-idle");
8725
+ }],
8727
8726
  on: {
8728
8727
  dragstart: {
8729
8728
  actions: [assign({
@@ -8742,6 +8741,12 @@ const editorMachine = setup({
8742
8741
  initial: "checking if busy",
8743
8742
  states: {
8744
8743
  "checking if busy": {
8744
+ entry: [() => {
8745
+ debug$4("entry: edit mode->editable->focusing->checking if busy");
8746
+ }],
8747
+ exit: [() => {
8748
+ debug$4("exit: edit mode->editable->focusing->checking if busy");
8749
+ }],
8745
8750
  always: [{
8746
8751
  guard: "slate is busy",
8747
8752
  target: "busy"
@@ -8751,6 +8756,12 @@ const editorMachine = setup({
8751
8756
  }]
8752
8757
  },
8753
8758
  busy: {
8759
+ entry: [() => {
8760
+ debug$4("entry: edit mode->editable->focusing-busy");
8761
+ }],
8762
+ exit: [() => {
8763
+ debug$4("exit: edit mode->editable->focusing->busy");
8764
+ }],
8754
8765
  after: {
8755
8766
  10: {
8756
8767
  target: "checking if busy"
@@ -8760,7 +8771,12 @@ const editorMachine = setup({
8760
8771
  }
8761
8772
  },
8762
8773
  "dragging internally": {
8763
- exit: [({
8774
+ entry: [() => {
8775
+ debug$4("entry: edit mode->editable->dragging internally");
8776
+ }],
8777
+ exit: [() => {
8778
+ debug$4("exit: edit mode->editable->dragging internally");
8779
+ }, ({
8764
8780
  context
8765
8781
  }) => {
8766
8782
  if (context.internalDrag?.ghost)
@@ -8790,7 +8806,12 @@ const editorMachine = setup({
8790
8806
  initial: "setting up",
8791
8807
  states: {
8792
8808
  "setting up": {
8793
- exit: ["emit ready", "emit pending incoming patches", "clear pending incoming patches"],
8809
+ entry: [() => {
8810
+ debug$4("entry: setup->setting up");
8811
+ }],
8812
+ exit: [() => {
8813
+ debug$4("exit: setup->setting up");
8814
+ }, "emit ready", "emit pending incoming patches", "clear pending incoming patches"],
8794
8815
  on: {
8795
8816
  "internal.patch": {
8796
8817
  actions: "defer event"
@@ -8813,6 +8834,12 @@ const editorMachine = setup({
8813
8834
  initial: "idle",
8814
8835
  states: {
8815
8836
  idle: {
8837
+ entry: [() => {
8838
+ debug$4("entry: setup->set up->value sync->idle");
8839
+ }],
8840
+ exit: [() => {
8841
+ debug$4("exit: setup->set up->value sync->idle");
8842
+ }],
8816
8843
  on: {
8817
8844
  patches: {
8818
8845
  actions: [emit(({
@@ -8825,7 +8852,12 @@ const editorMachine = setup({
8825
8852
  }
8826
8853
  },
8827
8854
  "syncing value": {
8828
- exit: ["emit pending incoming patches", "clear pending incoming patches"],
8855
+ entry: [() => {
8856
+ debug$4("entry: setup->set up->value sync->syncing value");
8857
+ }],
8858
+ exit: [() => {
8859
+ debug$4("exit: setup->set up->value sync->syncing value");
8860
+ }, "emit pending incoming patches", "clear pending incoming patches"],
8829
8861
  on: {
8830
8862
  patches: {
8831
8863
  actions: ["defer incoming patches"]
@@ -8844,6 +8876,12 @@ const editorMachine = setup({
8844
8876
  initial: "idle",
8845
8877
  states: {
8846
8878
  idle: {
8879
+ entry: [() => {
8880
+ debug$4("entry: setup->set up->writing->pristine->idle");
8881
+ }],
8882
+ exit: [() => {
8883
+ debug$4("exit: setup->set up->writing->pristine->idle");
8884
+ }],
8847
8885
  on: {
8848
8886
  normalizing: {
8849
8887
  target: "normalizing"
@@ -8859,6 +8897,12 @@ const editorMachine = setup({
8859
8897
  }
8860
8898
  },
8861
8899
  normalizing: {
8900
+ entry: [() => {
8901
+ debug$4("entry: setup->set up->writing->pristine->normalizing");
8902
+ }],
8903
+ exit: [() => {
8904
+ debug$4("exit: setup->set up->writing->pristine->normalizing");
8905
+ }],
8862
8906
  on: {
8863
8907
  "done normalizing": {
8864
8908
  target: "idle"
@@ -8874,7 +8918,12 @@ const editorMachine = setup({
8874
8918
  }
8875
8919
  },
8876
8920
  dirty: {
8877
- entry: ["emit pending events", "clear pending events"],
8921
+ entry: [() => {
8922
+ debug$4("entry: setup->set up->writing->dirty");
8923
+ }, "emit pending events", "clear pending events"],
8924
+ exit: [() => {
8925
+ debug$4("exit: setup->set up->writing->dirty");
8926
+ }],
8878
8927
  on: {
8879
8928
  "internal.patch": {
8880
8929
  actions: "emit patch event"
@@ -9939,12 +9988,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
9939
9988
  type: "range decorations updated",
9940
9989
  rangeDecorations: rangeDecorations ?? []
9941
9990
  });
9942
- }, [rangeDecorationsActor, rangeDecorations]), useMemo(() => {
9943
- if (readOnly)
9944
- return debug("Editable is in read only mode"), slateEditor;
9945
- const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
9946
- return debug("Editable is in edit mode"), withHotKeys(slateEditor);
9947
- }, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
9991
+ }, [rangeDecorationsActor, rangeDecorations]), useMemo(() => readOnly ? slateEditor : createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor), [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
9948
9992
  const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, spellCheck }), [spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((leafProps) => /* @__PURE__ */ jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), [readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder]), renderText = useCallback((props_0) => /* @__PURE__ */ jsx(RenderText, { ...props_0 }), []), restoreSelectionFromProps = useCallback(() => {
9949
9993
  if (propsSelection) {
9950
9994
  debug(`Selection from props ${JSON.stringify(propsSelection)}`);