@portabletext/editor 6.3.0 → 6.3.1

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
@@ -678,9 +678,24 @@ const debug$1 = {
678
678
  });
679
679
  ref.current = path2, path2 == null && ref.unref();
680
680
  }
681
- }, Scrubber = {
681
+ };
682
+ function safeStringify(value, space) {
683
+ try {
684
+ return JSON.stringify(value, null, space);
685
+ } catch (error) {
686
+ return console.error(error), "JSON.stringify failed";
687
+ }
688
+ }
689
+ function safeParse(text) {
690
+ try {
691
+ return JSON.parse(text);
692
+ } catch (error) {
693
+ return console.error(error), "JSON.parse failed";
694
+ }
695
+ }
696
+ const Scrubber = {
682
697
  stringify(value) {
683
- return JSON.stringify(value);
698
+ return safeStringify(value);
684
699
  }
685
700
  }, Text$1 = {
686
701
  equals(text, another, options = {}) {
@@ -2718,7 +2733,7 @@ const deleteText = (editor, options = {}) => {
2718
2733
  }, isDOMSelection = (value) => {
2719
2734
  const window2 = value && value.anchorNode && getDefaultView(value.anchorNode);
2720
2735
  return !!window2 && value instanceof window2.Selection;
2721
- }, isDOMText = (value) => isDOMNode(value) && value.nodeType === 3, isPlainTextOnlyPaste = (event) => event.clipboardData && event.clipboardData.getData("text/plain") !== "" && event.clipboardData.types.length === 1, normalizeDOMPoint = (domPoint) => {
2736
+ }, isPlainTextOnlyPaste = (event) => event.clipboardData && event.clipboardData.getData("text/plain") !== "" && event.clipboardData.types.length === 1, normalizeDOMPoint = (domPoint) => {
2722
2737
  let [node2, offset] = domPoint;
2723
2738
  if (isDOMElement(node2) && node2.childNodes.length) {
2724
2739
  let isLast = offset === node2.childNodes.length, index = isLast ? offset - 1 : offset;
@@ -2757,18 +2772,6 @@ const deleteText = (editor, options = {}) => {
2757
2772
  }, getEditableChild = (parent2, index, direction) => {
2758
2773
  const [child] = getEditableChildAndIndex(parent2, index, direction);
2759
2774
  return child;
2760
- }, getPlainText = (domNode) => {
2761
- let text = "";
2762
- if (isDOMText(domNode) && domNode.nodeValue)
2763
- return domNode.nodeValue;
2764
- if (isDOMElement(domNode)) {
2765
- for (const childNode of Array.from(domNode.childNodes))
2766
- text += getPlainText(childNode);
2767
- const display = getComputedStyle(domNode).getPropertyValue("display");
2768
- (display === "block" || display === "list" || domNode.tagName === "BR") && (text += `
2769
- `);
2770
- }
2771
- return text;
2772
2775
  }, getSelection = (root) => "getSelection" in root && typeof root.getSelection == "function" ? root.getSelection() : document.getSelection(), isTrackedMutation = (editor, mutation, batch) => {
2773
2776
  const {
2774
2777
  target
@@ -2970,7 +2973,6 @@ const DOMEditor = {
2970
2973
  const slateNode = DOMEditor.hasTarget(editor, target) && DOMEditor.toSlateNode(editor, target);
2971
2974
  return !!slateNode && editor.isObjectNode(slateNode);
2972
2975
  },
2973
- setFragmentData: (editor, data, originEvent) => editor.setFragmentData(data, originEvent),
2974
2976
  toDOMNode: (editor, node2) => {
2975
2977
  const domNode = Editor.isEditor(node2) ? editor.domElement : editor.keyToElement?.get(DOMEditor.findKey(editor, node2));
2976
2978
  if (!domNode)
@@ -3513,39 +3515,6 @@ const withDOM = (editor) => {
3513
3515
  const [node2] = Editor.node(e, path2);
3514
3516
  e.nodeToKey.set(node2, key);
3515
3517
  }
3516
- }, e.setFragmentData = (data) => {
3517
- const {
3518
- selection
3519
- } = e;
3520
- if (!selection)
3521
- return;
3522
- const [start2, end2] = Range.edges(selection), startVoid = Editor.void(e, {
3523
- at: start2.path
3524
- }), endVoid = Editor.void(e, {
3525
- at: end2.path
3526
- });
3527
- if (Range.isCollapsed(selection) && !startVoid)
3528
- return;
3529
- const domRange = DOMEditor.toDOMRange(e, selection);
3530
- let contents = domRange.cloneContents(), attach = contents.childNodes[0];
3531
- if (contents.childNodes.forEach((node2) => {
3532
- node2.textContent && node2.textContent.trim() !== "" && (attach = node2);
3533
- }), endVoid) {
3534
- const [voidNode] = endVoid, r = domRange.cloneRange(), domNode = DOMEditor.toDOMNode(e, voidNode);
3535
- r.setEndAfter(domNode), contents = r.cloneContents();
3536
- }
3537
- if (startVoid && (attach = contents.querySelector("[data-slate-spacer]")), Array.from(contents.querySelectorAll("[data-slate-zero-width]")).forEach((zw) => {
3538
- const isNewline = zw.getAttribute("data-slate-zero-width") === "n";
3539
- zw.textContent = isNewline ? `
3540
- ` : "";
3541
- }), isDOMText(attach)) {
3542
- const span = attach.ownerDocument.createElement("span");
3543
- span.style.whiteSpace = "pre", span.appendChild(attach), contents.appendChild(span), attach = span;
3544
- }
3545
- const fragment = e.getFragment(), string2 = JSON.stringify(fragment), encoded = window.btoa(encodeURIComponent(string2));
3546
- attach.setAttribute("data-slate-fragment", encoded), data.setData("application/x-slate-fragment", encoded);
3547
- const div = contents.ownerDocument.createElement("div");
3548
- return div.appendChild(contents), div.setAttribute("hidden", "true"), contents.ownerDocument.body.appendChild(div), data.setData("text/html", div.innerHTML), data.setData("text/plain", getPlainText(div)), contents.ownerDocument.body.removeChild(div), data;
3549
3518
  }, e.insertData = (data) => {
3550
3519
  e.insertTextData(data);
3551
3520
  }, e.insertTextData = (data) => {
@@ -5615,7 +5584,6 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
5615
5584
  } = useTrackUserInput(), [, forceRender] = useReducer((s) => s + 1, 0);
5616
5585
  editor.forceRender = forceRender, editor.readOnly = readOnly;
5617
5586
  const state = useMemo(() => ({
5618
- isDraggingInternally: !1,
5619
5587
  isUpdatingSelection: !1,
5620
5588
  latestElement: null,
5621
5589
  hasMarkPlaceholder: !1
@@ -5634,7 +5602,7 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
5634
5602
  return;
5635
5603
  }
5636
5604
  const androidInputManager = androidInputManagerRef.current;
5637
- if ((IS_ANDROID || !ReactEditor.isComposing(editor)) && (!state.isUpdatingSelection || androidInputManager?.isFlushing()) && !state.isDraggingInternally) {
5605
+ if ((IS_ANDROID || !ReactEditor.isComposing(editor)) && (!state.isUpdatingSelection || androidInputManager?.isFlushing())) {
5638
5606
  const root2 = ReactEditor.findDocumentOrShadowRoot(editor), {
5639
5607
  activeElement
5640
5608
  } = root2, el2 = ReactEditor.toDOMNode(editor, editor), domSelection = getSelection(root2);
@@ -5992,14 +5960,10 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
5992
5960
  const targetTagName = (target instanceof HTMLElement ? target : null)?.tagName;
5993
5961
  targetTagName === "INPUT" || targetTagName === "TEXTAREA" || scheduleOnDOMSelectionChange();
5994
5962
  };
5995
- window2.document.addEventListener("selectionchange", onSelectionChange);
5996
- const stoppedDragging = () => {
5997
- state.isDraggingInternally = !1;
5963
+ return window2.document.addEventListener("selectionchange", onSelectionChange), () => {
5964
+ window2.document.removeEventListener("selectionchange", onSelectionChange);
5998
5965
  };
5999
- return window2.document.addEventListener("dragend", stoppedDragging), window2.document.addEventListener("drop", stoppedDragging), () => {
6000
- window2.document.removeEventListener("selectionchange", onSelectionChange), window2.document.removeEventListener("dragend", stoppedDragging), window2.document.removeEventListener("drop", stoppedDragging);
6001
- };
6002
- }, [scheduleOnDOMSelectionChange, state]);
5966
+ }, [scheduleOnDOMSelectionChange]);
6003
5967
  const decorations = decorate([editor, []]), decorateContext = useDecorateContext(decorate), showPlaceholder = placeholder && editor.children.length === 1 && Array.from(Node$1.texts(editor, editor.schema)).length === 1 && Node$1.string(editor, editor.schema) === "" && !isComposing, placeHolderResizeHandler = useCallback((placeholderEl) => {
6004
5968
  setPlaceholderHeight(placeholderEl && showPlaceholder ? placeholderEl.getBoundingClientRect()?.height : void 0);
6005
5969
  }, [showPlaceholder]);
@@ -6207,74 +6171,12 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
6207
6171
  }
6208
6172
  }
6209
6173
  }, [attributes.onCompositionStart, editor, editorActor]),
6210
- onCopy: useCallback((event) => {
6211
- ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCopy) && !isDOMEventTargetInput(event) && (event.preventDefault(), ReactEditor.setFragmentData(editor, event.clipboardData, "copy"));
6212
- }, [attributes.onCopy, editor]),
6213
- onCut: useCallback((event) => {
6214
- if (!readOnly && ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCut) && !isDOMEventTargetInput(event)) {
6215
- event.preventDefault(), ReactEditor.setFragmentData(editor, event.clipboardData, "cut");
6216
- const {
6217
- selection
6218
- } = editor;
6219
- if (selection)
6220
- if (Range.isExpanded(selection))
6221
- editorActor.send({
6222
- type: "behavior event",
6223
- behaviorEvent: {
6224
- type: "delete",
6225
- direction: "forward"
6226
- },
6227
- editor
6228
- });
6229
- else {
6230
- const node2 = Node$1.get(editor, selection.anchor.path, editor.schema);
6231
- editor.isObjectNode(node2) && Transforms.delete(editor);
6232
- }
6233
- }
6234
- }, [readOnly, editor, editorActor, attributes.onCut]),
6235
- onDragOver: useCallback((event) => {
6236
- if (ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragOver)) {
6237
- const node2 = ReactEditor.toSlateNode(editor, event.target);
6238
- editor.isObjectNode(node2) && event.preventDefault();
6239
- }
6240
- }, [attributes.onDragOver, editor]),
6241
- onDragStart: useCallback((event) => {
6242
- if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragStart)) {
6243
- const node2 = ReactEditor.toSlateNode(editor, event.target), path2 = ReactEditor.findPath(editor, node2);
6244
- if (editor.isObjectNode(node2) || Editor.void(editor, {
6245
- at: path2,
6246
- voids: !0
6247
- })) {
6248
- const range2 = Editor.range(editor, path2);
6249
- Transforms.select(editor, range2);
6250
- }
6251
- state.isDraggingInternally = !0, ReactEditor.setFragmentData(editor, event.dataTransfer, "drag");
6252
- }
6253
- }, [readOnly, editor, attributes.onDragStart, state]),
6254
- onDrop: useCallback((event) => {
6255
- if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDrop)) {
6256
- event.preventDefault();
6257
- const draggedRange = editor.selection, range2 = ReactEditor.findEventRange(editor, event), data = event.dataTransfer;
6258
- Transforms.select(editor, range2), state.isDraggingInternally && draggedRange && !Range.equals(draggedRange, range2) && !Editor.void(editor, {
6259
- at: range2,
6260
- voids: !0
6261
- }) && Transforms.delete(editor, {
6262
- at: draggedRange
6263
- }), editorActor.send({
6264
- type: "behavior event",
6265
- behaviorEvent: {
6266
- type: "input.*",
6267
- originEvent: {
6268
- dataTransfer: data
6269
- }
6270
- },
6271
- editor
6272
- }), ReactEditor.isFocused(editor) || ReactEditor.focus(editor);
6273
- }
6274
- }, [readOnly, editor, editorActor, attributes.onDrop, state]),
6275
- onDragEnd: useCallback((event) => {
6276
- !readOnly && state.isDraggingInternally && attributes.onDragEnd && ReactEditor.hasTarget(editor, event.target) && attributes.onDragEnd(event);
6277
- }, [readOnly, state, attributes, editor]),
6174
+ onCopy: attributes.onCopy,
6175
+ onCut: attributes.onCut,
6176
+ onDragOver: attributes.onDragOver,
6177
+ onDragStart: attributes.onDragStart,
6178
+ onDrop: attributes.onDrop,
6179
+ onDragEnd: attributes.onDragEnd,
6278
6180
  onFocus: useCallback((event) => {
6279
6181
  if (!readOnly && !state.isUpdatingSelection && ReactEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onFocus)) {
6280
6182
  const el = ReactEditor.toDOMNode(editor, editor), root = ReactEditor.findDocumentOrShadowRoot(editor);
@@ -6296,26 +6198,6 @@ const RestoreDOM = IS_ANDROID ? RestoreDOMComponent : ({
6296
6198
  const {
6297
6199
  selection
6298
6200
  } = editor, element = editor.children[selection !== null ? selection.focus.path[0] : 0], isRTL = getDirection(Node$1.string(element, editor.schema)) === "rtl";
6299
- if (Hotkeys.isRedo(nativeEvent)) {
6300
- event.preventDefault(), editorActor.send({
6301
- type: "behavior event",
6302
- behaviorEvent: {
6303
- type: "history.redo"
6304
- },
6305
- editor
6306
- });
6307
- return;
6308
- }
6309
- if (Hotkeys.isUndo(nativeEvent)) {
6310
- event.preventDefault(), editorActor.send({
6311
- type: "behavior event",
6312
- behaviorEvent: {
6313
- type: "history.undo"
6314
- },
6315
- editor
6316
- });
6317
- return;
6318
- }
6319
6201
  if (Hotkeys.isMoveLineBackward(nativeEvent)) {
6320
6202
  event.preventDefault(), Transforms.move(editor, {
6321
6203
  unit: "line",
@@ -8496,7 +8378,7 @@ function validateSelection(slateEditor, editorElement) {
8496
8378
  }
8497
8379
  }
8498
8380
  const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8499
- const $ = c(180);
8381
+ const $ = c(181);
8500
8382
  let hotkeys, onBeforeInput, onBlur, onClick, onCopy, onCut, onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop, onFocus, onPaste, propsSelection, rangeDecorations, renderAnnotation, renderBlock, renderChild, renderDecorator, renderListItem, renderPlaceholder, renderStyle, restProps, scrollSelectionIntoView, spellCheck;
8501
8383
  $[0] !== props ? ({
8502
8384
  hotkeys,
@@ -8579,10 +8461,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8579
8461
  let t13;
8580
8462
  $[64] !== editorActor || $[65] !== propsSelection || $[66] !== slateEditor ? (t13 = () => {
8581
8463
  if (propsSelection) {
8582
- debug$1.selection(`Selection from props ${JSON.stringify(propsSelection)}`);
8464
+ debug$1.selection(`Selection from props ${safeStringify(propsSelection)}`);
8583
8465
  const normalizedSelection = normalizeSelection(propsSelection, slateEditor.children);
8584
8466
  if (normalizedSelection !== null) {
8585
- debug$1.selection(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
8467
+ debug$1.selection(`Normalized selection from props ${safeStringify(normalizedSelection)}`);
8586
8468
  const slateRange = toSlateRange({
8587
8469
  context: {
8588
8470
  schema: editorActor.getSnapshot().context.schema,
@@ -8620,61 +8502,65 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8620
8502
  }, t17 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[73] = hasInvalidValue, $[74] = propsSelection, $[75] = restoreSelectionFromProps, $[76] = t16, $[77] = t17) : (t16 = $[76], t17 = $[77]), useEffect(t16, t17);
8621
8503
  let t18;
8622
8504
  $[78] !== editorActor || $[79] !== onCopy || $[80] !== slateEditor ? (t18 = (event) => {
8623
- if (onCopy)
8624
- onCopy(event) !== void 0 && event.preventDefault();
8625
- else if (event.nativeEvent.clipboardData) {
8626
- event.stopPropagation(), event.preventDefault();
8627
- const selection = slateEditor.selection ? slateRangeToSelection({
8628
- schema: editorActor.getSnapshot().context.schema,
8629
- editor: slateEditor,
8630
- range: slateEditor.selection
8631
- }) : void 0, position = selection ? {
8632
- selection
8633
- } : void 0;
8634
- if (!position) {
8635
- console.warn("Could not find position for copy event");
8636
- return;
8637
- }
8638
- editorActor.send({
8639
- type: "behavior event",
8640
- behaviorEvent: {
8641
- type: "clipboard.copy",
8642
- originEvent: {
8643
- dataTransfer: event.nativeEvent.clipboardData
8505
+ if (ReactEditor.hasSelectableTarget(slateEditor, event.target)) {
8506
+ if (onCopy)
8507
+ onCopy(event) !== void 0 && event.preventDefault();
8508
+ else if (event.nativeEvent.clipboardData) {
8509
+ event.stopPropagation(), event.preventDefault();
8510
+ const selection = slateEditor.selection ? slateRangeToSelection({
8511
+ schema: editorActor.getSnapshot().context.schema,
8512
+ editor: slateEditor,
8513
+ range: slateEditor.selection
8514
+ }) : void 0, position = selection ? {
8515
+ selection
8516
+ } : void 0;
8517
+ if (!position) {
8518
+ console.warn("Could not find position for copy event");
8519
+ return;
8520
+ }
8521
+ editorActor.send({
8522
+ type: "behavior event",
8523
+ behaviorEvent: {
8524
+ type: "clipboard.copy",
8525
+ originEvent: {
8526
+ dataTransfer: event.nativeEvent.clipboardData
8527
+ },
8528
+ position
8644
8529
  },
8645
- position
8646
- },
8647
- editor: slateEditor,
8648
- nativeEvent: event
8649
- });
8530
+ editor: slateEditor,
8531
+ nativeEvent: event
8532
+ });
8533
+ }
8650
8534
  }
8651
8535
  }, $[78] = editorActor, $[79] = onCopy, $[80] = slateEditor, $[81] = t18) : t18 = $[81];
8652
8536
  const handleCopy = t18;
8653
8537
  let t19;
8654
8538
  $[82] !== editorActor || $[83] !== onCut || $[84] !== slateEditor ? (t19 = (event_0) => {
8655
- if (onCut)
8656
- onCut(event_0) !== void 0 && event_0.preventDefault();
8657
- else if (event_0.nativeEvent.clipboardData) {
8658
- event_0.stopPropagation(), event_0.preventDefault();
8659
- const selection_0 = editorActor.getSnapshot().context.selection, position_0 = selection_0 ? {
8660
- selection: selection_0
8661
- } : void 0;
8662
- if (!position_0) {
8663
- console.warn("Could not find position for cut event");
8664
- return;
8665
- }
8666
- editorActor.send({
8667
- type: "behavior event",
8668
- behaviorEvent: {
8669
- type: "clipboard.cut",
8670
- originEvent: {
8671
- dataTransfer: event_0.nativeEvent.clipboardData
8539
+ if (ReactEditor.hasSelectableTarget(slateEditor, event_0.target)) {
8540
+ if (onCut)
8541
+ onCut(event_0) !== void 0 && event_0.preventDefault();
8542
+ else if (event_0.nativeEvent.clipboardData) {
8543
+ event_0.stopPropagation(), event_0.preventDefault();
8544
+ const selection_0 = editorActor.getSnapshot().context.selection, position_0 = selection_0 ? {
8545
+ selection: selection_0
8546
+ } : void 0;
8547
+ if (!position_0) {
8548
+ console.warn("Could not find position for cut event");
8549
+ return;
8550
+ }
8551
+ editorActor.send({
8552
+ type: "behavior event",
8553
+ behaviorEvent: {
8554
+ type: "clipboard.cut",
8555
+ originEvent: {
8556
+ dataTransfer: event_0.nativeEvent.clipboardData
8557
+ },
8558
+ position: position_0
8672
8559
  },
8673
- position: position_0
8674
- },
8675
- editor: slateEditor,
8676
- nativeEvent: event_0
8677
- });
8560
+ editor: slateEditor,
8561
+ nativeEvent: event_0
8562
+ });
8563
+ }
8678
8564
  }
8679
8565
  }, $[82] = editorActor, $[83] = onCut, $[84] = slateEditor, $[85] = t19) : t19 = $[85];
8680
8566
  const handleCut = t19;
@@ -8885,8 +8771,8 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8885
8771
  };
8886
8772
  }, t29 = [slateEditor, editorActor], $[119] = editorActor, $[120] = slateEditor, $[121] = t28, $[122] = t29) : (t28 = $[121], t29 = $[122]), useEffect(t28, t29);
8887
8773
  let t30;
8888
- $[123] !== editorActor || $[124] !== onDragStart || $[125] !== slateEditor ? (t30 = (event_8) => {
8889
- if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
8774
+ $[123] !== editorActor || $[124] !== onDragStart || $[125] !== readOnly || $[126] !== slateEditor ? (t30 = (event_8) => {
8775
+ if (readOnly || !ReactEditor.hasTarget(slateEditor, event_8.target) || (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped()))
8890
8776
  return;
8891
8777
  const position_4 = getEventPosition({
8892
8778
  editorActor,
@@ -8913,10 +8799,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8913
8799
  },
8914
8800
  editor: slateEditor
8915
8801
  }), !0;
8916
- }, $[123] = editorActor, $[124] = onDragStart, $[125] = slateEditor, $[126] = t30) : t30 = $[126];
8802
+ }, $[123] = editorActor, $[124] = onDragStart, $[125] = readOnly, $[126] = slateEditor, $[127] = t30) : t30 = $[127];
8917
8803
  const handleDragStart = t30;
8918
8804
  let t31;
8919
- $[127] !== editorActor || $[128] !== onDrag || $[129] !== slateEditor ? (t31 = (event_9) => {
8805
+ $[128] !== editorActor || $[129] !== onDrag || $[130] !== slateEditor ? (t31 = (event_9) => {
8920
8806
  if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
8921
8807
  editorActor,
8922
8808
  slateEditor,
@@ -8932,10 +8818,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8932
8818
  },
8933
8819
  editor: slateEditor
8934
8820
  }), !0;
8935
- }, $[127] = editorActor, $[128] = onDrag, $[129] = slateEditor, $[130] = t31) : t31 = $[130];
8821
+ }, $[128] = editorActor, $[129] = onDrag, $[130] = slateEditor, $[131] = t31) : t31 = $[131];
8936
8822
  const handleDrag = t31;
8937
8823
  let t32;
8938
- $[131] !== editorActor || $[132] !== onDragEnd || $[133] !== slateEditor ? (t32 = (event_10) => {
8824
+ $[132] !== editorActor || $[133] !== onDragEnd || $[134] !== slateEditor ? (t32 = (event_10) => {
8939
8825
  if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
8940
8826
  return editorActor.send({
8941
8827
  type: "behavior event",
@@ -8947,10 +8833,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8947
8833
  },
8948
8834
  editor: slateEditor
8949
8835
  }), !0;
8950
- }, $[131] = editorActor, $[132] = onDragEnd, $[133] = slateEditor, $[134] = t32) : t32 = $[134];
8836
+ }, $[132] = editorActor, $[133] = onDragEnd, $[134] = slateEditor, $[135] = t32) : t32 = $[135];
8951
8837
  const handleDragEnd = t32;
8952
8838
  let t33;
8953
- $[135] !== editorActor || $[136] !== onDragEnter || $[137] !== slateEditor ? (t33 = (event_11) => {
8839
+ $[136] !== editorActor || $[137] !== onDragEnter || $[138] !== slateEditor ? (t33 = (event_11) => {
8954
8840
  if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
8955
8841
  return;
8956
8842
  const position_6 = getEventPosition({
@@ -8970,10 +8856,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8970
8856
  },
8971
8857
  editor: slateEditor
8972
8858
  }), !0;
8973
- }, $[135] = editorActor, $[136] = onDragEnter, $[137] = slateEditor, $[138] = t33) : t33 = $[138];
8859
+ }, $[136] = editorActor, $[137] = onDragEnter, $[138] = slateEditor, $[139] = t33) : t33 = $[139];
8974
8860
  const handleDragEnter = t33;
8975
8861
  let t34;
8976
- $[139] !== editorActor || $[140] !== onDragOver || $[141] !== slateEditor ? (t34 = (event_12) => {
8862
+ $[140] !== editorActor || $[141] !== onDragOver || $[142] !== slateEditor ? (t34 = (event_12) => {
8977
8863
  if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
8978
8864
  return;
8979
8865
  const position_7 = getEventPosition({
@@ -8995,10 +8881,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
8995
8881
  editor: slateEditor,
8996
8882
  nativeEvent: event_12
8997
8883
  }), !0;
8998
- }, $[139] = editorActor, $[140] = onDragOver, $[141] = slateEditor, $[142] = t34) : t34 = $[142];
8884
+ }, $[140] = editorActor, $[141] = onDragOver, $[142] = slateEditor, $[143] = t34) : t34 = $[143];
8999
8885
  const handleDragOver = t34;
9000
8886
  let t35;
9001
- $[143] !== editorActor || $[144] !== onDrop || $[145] !== slateEditor ? (t35 = (event_13) => {
8887
+ $[144] !== editorActor || $[145] !== onDrop || $[146] !== slateEditor ? (t35 = (event_13) => {
9002
8888
  if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
9003
8889
  return;
9004
8890
  const position_8 = getEventPosition({
@@ -9023,10 +8909,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
9023
8909
  editor: slateEditor,
9024
8910
  nativeEvent: event_13
9025
8911
  }), !0;
9026
- }, $[143] = editorActor, $[144] = onDrop, $[145] = slateEditor, $[146] = t35) : t35 = $[146];
8912
+ }, $[144] = editorActor, $[145] = onDrop, $[146] = slateEditor, $[147] = t35) : t35 = $[147];
9027
8913
  const handleDrop = t35;
9028
8914
  let t36;
9029
- $[147] !== editorActor || $[148] !== onDragLeave || $[149] !== slateEditor ? (t36 = (event_14) => {
8915
+ $[148] !== editorActor || $[149] !== onDragLeave || $[150] !== slateEditor ? (t36 = (event_14) => {
9030
8916
  if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
9031
8917
  editorActor,
9032
8918
  slateEditor,
@@ -9042,10 +8928,10 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
9042
8928
  },
9043
8929
  editor: slateEditor
9044
8930
  }), !0;
9045
- }, $[147] = editorActor, $[148] = onDragLeave, $[149] = slateEditor, $[150] = t36) : t36 = $[150];
8931
+ }, $[148] = editorActor, $[149] = onDragLeave, $[150] = slateEditor, $[151] = t36) : t36 = $[151];
9046
8932
  const handleDragLeave = t36;
9047
8933
  let t37;
9048
- $[151] !== forwardedRef || $[152] !== validateSelectionActor ? (t37 = (editorElement) => {
8934
+ $[152] !== forwardedRef || $[153] !== validateSelectionActor ? (t37 = (editorElement) => {
9049
8935
  if (typeof forwardedRef == "function" ? forwardedRef(editorElement) : forwardedRef && (forwardedRef.current = editorElement), editorElement) {
9050
8936
  const mutationObserver = new MutationObserver(() => {
9051
8937
  validateSelectionActor.send({
@@ -9063,12 +8949,12 @@ const PortableTextEditable = forwardRef(function(props, forwardedRef) {
9063
8949
  mutationObserver.disconnect();
9064
8950
  };
9065
8951
  }
9066
- }, $[151] = forwardedRef, $[152] = validateSelectionActor, $[153] = t37) : t37 = $[153];
8952
+ }, $[152] = forwardedRef, $[153] = validateSelectionActor, $[154] = t37) : t37 = $[154];
9067
8953
  const callbackRef = t37;
9068
8954
  if (!portableTextEditor)
9069
8955
  return null;
9070
8956
  let t38;
9071
- return $[154] !== callbackRef || $[155] !== decorate || $[156] !== editorActor || $[157] !== handleClick || $[158] !== handleCopy || $[159] !== handleCut || $[160] !== handleDrag || $[161] !== handleDragEnd || $[162] !== handleDragEnter || $[163] !== handleDragLeave || $[164] !== handleDragOver || $[165] !== handleDragStart || $[166] !== handleDrop || $[167] !== handleKeyDown || $[168] !== handleKeyUp || $[169] !== handleOnBeforeInput || $[170] !== handleOnBlur || $[171] !== handleOnFocus || $[172] !== handlePaste || $[173] !== hasInvalidValue || $[174] !== readOnly || $[175] !== renderElement || $[176] !== renderLeaf || $[177] !== restProps || $[178] !== scrollSelectionIntoViewToSlate ? (t38 = hasInvalidValue ? null : /* @__PURE__ */ jsx(SelectionStateProvider, { children: /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, editorActor, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }) }), $[154] = callbackRef, $[155] = decorate, $[156] = editorActor, $[157] = handleClick, $[158] = handleCopy, $[159] = handleCut, $[160] = handleDrag, $[161] = handleDragEnd, $[162] = handleDragEnter, $[163] = handleDragLeave, $[164] = handleDragOver, $[165] = handleDragStart, $[166] = handleDrop, $[167] = handleKeyDown, $[168] = handleKeyUp, $[169] = handleOnBeforeInput, $[170] = handleOnBlur, $[171] = handleOnFocus, $[172] = handlePaste, $[173] = hasInvalidValue, $[174] = readOnly, $[175] = renderElement, $[176] = renderLeaf, $[177] = restProps, $[178] = scrollSelectionIntoViewToSlate, $[179] = t38) : t38 = $[179], t38;
8957
+ return $[155] !== callbackRef || $[156] !== decorate || $[157] !== editorActor || $[158] !== handleClick || $[159] !== handleCopy || $[160] !== handleCut || $[161] !== handleDrag || $[162] !== handleDragEnd || $[163] !== handleDragEnter || $[164] !== handleDragLeave || $[165] !== handleDragOver || $[166] !== handleDragStart || $[167] !== handleDrop || $[168] !== handleKeyDown || $[169] !== handleKeyUp || $[170] !== handleOnBeforeInput || $[171] !== handleOnBlur || $[172] !== handleOnFocus || $[173] !== handlePaste || $[174] !== hasInvalidValue || $[175] !== readOnly || $[176] !== renderElement || $[177] !== renderLeaf || $[178] !== restProps || $[179] !== scrollSelectionIntoViewToSlate ? (t38 = hasInvalidValue ? null : /* @__PURE__ */ jsx(SelectionStateProvider, { children: /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, editorActor, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }) }), $[155] = callbackRef, $[156] = decorate, $[157] = editorActor, $[158] = handleClick, $[159] = handleCopy, $[160] = handleCut, $[161] = handleDrag, $[162] = handleDragEnd, $[163] = handleDragEnter, $[164] = handleDragLeave, $[165] = handleDragOver, $[166] = handleDragStart, $[167] = handleDrop, $[168] = handleKeyDown, $[169] = handleKeyUp, $[170] = handleOnBeforeInput, $[171] = handleOnBlur, $[172] = handleOnFocus, $[173] = handlePaste, $[174] = hasInvalidValue, $[175] = readOnly, $[176] = renderElement, $[177] = renderLeaf, $[178] = restProps, $[179] = scrollSelectionIntoViewToSlate, $[180] = t38) : t38 = $[180], t38;
9072
8958
  });
9073
8959
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
9074
8960
  function noop() {
@@ -9166,7 +9052,7 @@ const converterJson = {
9166
9052
  originEvent: event.originEvent
9167
9053
  } : {
9168
9054
  type: "serialization.success",
9169
- data: JSON.stringify(blocks),
9055
+ data: safeStringify(blocks),
9170
9056
  mimeType: "application/x-portable-text",
9171
9057
  originEvent: event.originEvent
9172
9058
  };
@@ -9175,7 +9061,7 @@ const converterJson = {
9175
9061
  snapshot,
9176
9062
  event
9177
9063
  }) => {
9178
- const blocks = JSON.parse(event.data);
9064
+ const blocks = safeParse(event.data);
9179
9065
  if (!Array.isArray(blocks))
9180
9066
  return {
9181
9067
  type: "deserialization.failure",
@@ -9933,8 +9819,6 @@ function createBehaviorApiPlugin(editorActor) {
9933
9819
  },
9934
9820
  editor
9935
9821
  });
9936
- }, editor.setFragmentData = () => {
9937
- console.error("Unexpected call to .setFragmentData(...)");
9938
9822
  }, editor.undo = () => {
9939
9823
  if (editor.isNormalizingNode || editor.isPerformingBehaviorOperation) {
9940
9824
  console.error("Unexpected call to .undo(...)");
@@ -11425,7 +11309,7 @@ function setNodePatch(schema, children, operation) {
11425
11309
  }
11426
11310
  throw new Error("Could not find a valid block");
11427
11311
  } else
11428
- throw new Error(`Unexpected path encountered: ${JSON.stringify(operation.path)}`);
11312
+ throw new Error(`Unexpected path encountered: ${safeStringify(operation.path)}`);
11429
11313
  }
11430
11314
  function insertNodePatch(schema, children, operation, beforeValue) {
11431
11315
  const block = beforeValue[operation.path[0]];
@@ -11462,7 +11346,7 @@ function removeNodePatch(schema, beforeValue, operation) {
11462
11346
  schema
11463
11347
  }, block) && operation.path.length === 2) {
11464
11348
  const spanToRemove = block.children[operation.path[1]];
11465
- return spanToRemove ? block.children.filter((span) => span._key === operation.node._key).length > 1 ? (console.warn(`Multiple spans have \`_key\` ${operation.node._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)), []) : [unset([{
11349
+ return spanToRemove ? block.children.filter((span) => span._key === operation.node._key).length > 1 ? (console.warn(`Multiple spans have \`_key\` ${operation.node._key}. It's ambiguous which one to remove.`, safeStringify(block, 2)), []) : [unset([{
11466
11350
  _key: block._key
11467
11351
  }, "children", {
11468
11352
  _key: spanToRemove._key
@@ -11503,9 +11387,9 @@ function createPatchesPlugin({
11503
11387
  pluginWithoutHistory(editor, () => {
11504
11388
  for (const patch of patches)
11505
11389
  try {
11506
- changed = applyPatch(editor, patch), changed ? debug$1.syncPatch(`(applied) ${JSON.stringify(patch, null, 2)}`) : debug$1.syncPatch(`(ignored) ${JSON.stringify(patch, null, 2)}`);
11390
+ changed = applyPatch(editor, patch), changed ? debug$1.syncPatch(`(applied) ${safeStringify(patch, 2)}`) : debug$1.syncPatch(`(ignored) ${safeStringify(patch, 2)}`);
11507
11391
  } catch (error) {
11508
- console.error(`Applying patch ${JSON.stringify(patch)} failed due to: ${error instanceof Error ? error.message : error}`);
11392
+ console.error(`Applying patch ${safeStringify(patch)} failed due to: ${error instanceof Error ? error.message : error}`);
11509
11393
  }
11510
11394
  });
11511
11395
  });
@@ -11772,7 +11656,7 @@ function updateValuePlugin(context, editor) {
11772
11656
  } = editor;
11773
11657
  return editor.apply = (operation) => {
11774
11658
  if (editor.isNormalizingNode && debug$1.normalization(`(slate operation)
11775
- ${JSON.stringify(operation, null, 2)}`), operation.type === "set_selection") {
11659
+ ${safeStringify(operation, 2)}`), operation.type === "set_selection") {
11776
11660
  apply2(operation);
11777
11661
  return;
11778
11662
  }
@@ -13329,7 +13213,7 @@ const addAnnotationOperationImplementation = ({
13329
13213
  }
13330
13214
  });
13331
13215
  if (!parsedAnnotation)
13332
- throw new Error(`Failed to parse annotation ${JSON.stringify(operation.annotation)}`);
13216
+ throw new Error(`Failed to parse annotation ${safeStringify(operation.annotation)}`);
13333
13217
  const editor = operation.editor, at = operation.at ? toSlateRange({
13334
13218
  context: {
13335
13219
  schema: context.schema,
@@ -13481,10 +13365,10 @@ const addAnnotationOperationImplementation = ({
13481
13365
  }) => {
13482
13366
  const blockIndex = operation.editor.blockIndexMap.get(operation.at[0]._key);
13483
13367
  if (blockIndex === void 0)
13484
- throw new Error(`Unable to find block index for block at ${JSON.stringify(operation.at)}`);
13368
+ throw new Error(`Unable to find block index for block at ${safeStringify(operation.at)}`);
13485
13369
  const slateBlock = operation.editor.children.at(blockIndex);
13486
13370
  if (!slateBlock)
13487
- throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
13371
+ throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
13488
13372
  if (isTextBlock(context, slateBlock)) {
13489
13373
  const filteredProps = {};
13490
13374
  for (const key of Object.keys(operation.props))
@@ -13539,7 +13423,7 @@ const addAnnotationOperationImplementation = ({
13539
13423
  throw new Error(`Unable to find block index for block key ${blockKey}`);
13540
13424
  const slateBlock = blockIndex !== void 0 ? operation.editor.children.at(blockIndex) : void 0;
13541
13425
  if (!slateBlock)
13542
- throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
13426
+ throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
13543
13427
  if (isTextBlock(context, slateBlock)) {
13544
13428
  const propsToRemove = operation.props.filter((prop) => prop !== "_type" && prop !== "_key" && prop !== "children"), unsetProps2 = {};
13545
13429
  for (const prop of propsToRemove)
@@ -13575,12 +13459,12 @@ const addAnnotationOperationImplementation = ({
13575
13459
  blockIndexMap: operation.editor.blockIndexMap
13576
13460
  });
13577
13461
  if (!location)
13578
- throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
13462
+ throw new Error(`Unable to convert ${safeStringify(operation.at)} into a Slate Range`);
13579
13463
  const childEntry = Editor.node(operation.editor, location, {
13580
13464
  depth: 2
13581
13465
  }), child = childEntry?.[0], childPath = childEntry?.[1];
13582
13466
  if (!child || !childPath)
13583
- throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
13467
+ throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
13584
13468
  if (operation.editor.isTextSpan(child)) {
13585
13469
  const {
13586
13470
  _type,
@@ -13621,7 +13505,7 @@ const addAnnotationOperationImplementation = ({
13621
13505
  }, childPath);
13622
13506
  return;
13623
13507
  }
13624
- throw new Error(`Unable to determine the type of child at ${JSON.stringify(operation.at)}`);
13508
+ throw new Error(`Unable to determine the type of child at ${safeStringify(operation.at)}`);
13625
13509
  }, childUnsetOperationImplementation = ({
13626
13510
  context,
13627
13511
  operation
@@ -13631,20 +13515,20 @@ const addAnnotationOperationImplementation = ({
13631
13515
  throw new Error(`Unable to find block index for block key ${blockKey}`);
13632
13516
  const block = blockIndex !== void 0 ? operation.editor.children.at(blockIndex) : void 0;
13633
13517
  if (!block)
13634
- throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
13518
+ throw new Error(`Unable to find block at ${safeStringify(operation.at)}`);
13635
13519
  if (!isTextBlock(context, block))
13636
- throw new Error(`Block ${JSON.stringify(blockKey)} is not a text block`);
13520
+ throw new Error(`Block ${safeStringify(blockKey)} is not a text block`);
13637
13521
  const childKey = operation.at[2]._key;
13638
13522
  if (!childKey)
13639
- throw new Error(`Unable to find child key at ${JSON.stringify(operation.at)}`);
13523
+ throw new Error(`Unable to find child key at ${safeStringify(operation.at)}`);
13640
13524
  const childIndex = block.children.findIndex((child2) => child2._key === childKey);
13641
13525
  if (childIndex === -1)
13642
- throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
13526
+ throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
13643
13527
  const childEntry = Editor.node(operation.editor, [blockIndex, childIndex], {
13644
13528
  depth: 2
13645
13529
  }), child = childEntry?.[0], childPath = childEntry?.[1];
13646
13530
  if (!child || !childPath)
13647
- throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
13531
+ throw new Error(`Unable to find child at ${safeStringify(operation.at)}`);
13648
13532
  if (operation.editor.isTextSpan(child)) {
13649
13533
  const newNode = {};
13650
13534
  for (const prop of operation.props)
@@ -13670,7 +13554,7 @@ const addAnnotationOperationImplementation = ({
13670
13554
  applySetNode(operation.editor, unsetProps, childPath);
13671
13555
  return;
13672
13556
  }
13673
- throw new Error(`Unable to determine the type of child at ${JSON.stringify(operation.at)}`);
13557
+ throw new Error(`Unable to determine the type of child at ${safeStringify(operation.at)}`);
13674
13558
  }, decoratorAddOperationImplementation = ({
13675
13559
  context,
13676
13560
  operation
@@ -14260,7 +14144,7 @@ const historyUndoOperationImplementation = ({
14260
14144
  }
14261
14145
  });
14262
14146
  if (!parsedBlock)
14263
- throw new Error(`Failed to parse block ${JSON.stringify(operation.block)}`);
14147
+ throw new Error(`Failed to parse block ${safeStringify(operation.block)}`);
14264
14148
  const block = toSlateBlock(parsedBlock, {
14265
14149
  schemaTypes: context.schema
14266
14150
  });
@@ -17023,7 +16907,7 @@ function performEvent({
17023
16907
  nativeEvent,
17024
16908
  sendBack
17025
16909
  }) {
17026
- mode === "send" && !isNativeBehaviorEvent(event) && (editor.undoStepId = defaultKeyGenerator()), debug$1.behaviors(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
16910
+ mode === "send" && !isNativeBehaviorEvent(event) && (editor.undoStepId = defaultKeyGenerator()), debug$1.behaviors(`(${mode}:${eventCategory(event)})`, safeStringify(event, 2));
17027
16911
  const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
17028
16912
  if (behavior.on === "*")
17029
16913
  return !0;
@@ -17032,7 +16916,7 @@ function performEvent({
17032
16916
  });
17033
16917
  if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
17034
16918
  nativeEvent?.preventDefault(), mode === "send" && (editor.undoStepId = void 0), withPerformingBehaviorOperation(editor, () => {
17035
- debug$1.operation(JSON.stringify(event, null, 2)), performOperation({
16919
+ debug$1.operation(safeStringify(event, 2)), performOperation({
17036
16920
  context: {
17037
16921
  keyGenerator,
17038
16922
  schema
@@ -17158,7 +17042,7 @@ function performEvent({
17158
17042
  break;
17159
17043
  }
17160
17044
  !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && (editor.undoStepId = void 0), withPerformingBehaviorOperation(editor, () => {
17161
- debug$1.operation(JSON.stringify(event, null, 2)), performOperation({
17045
+ debug$1.operation(safeStringify(event, 2)), performOperation({
17162
17046
  context: {
17163
17047
  keyGenerator,
17164
17048
  schema
@@ -18446,7 +18330,7 @@ const syncValueCallback = ({
18446
18330
  context
18447
18331
  }) => {
18448
18332
  const isBusy = context.slateEditor.isDeferringMutations || context.slateEditor.isProcessingRemoteChanges;
18449
- return debug$1.syncValue(JSON.stringify({
18333
+ return debug$1.syncValue(safeStringify({
18450
18334
  isBusy,
18451
18335
  isDeferringMutations: context.slateEditor.isDeferringMutations,
18452
18336
  isProcessingRemoteChanges: context.slateEditor.isProcessingRemoteChanges