@portabletext/editor 2.13.1 → 2.13.2

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.
@@ -6,7 +6,7 @@ import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObject
6
6
  import * as xstate227 from "xstate";
7
7
  import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
8
8
  import { BaseRange, Descendant, Operation } from "slate";
9
- import * as react22 from "react";
9
+ import * as react20 from "react";
10
10
  import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
11
11
  import * as xstate_guards12 from "xstate/guards";
12
12
  import { Observable, Subject } from "rxjs";
@@ -198,7 +198,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
198
198
  componentDidUpdate(prevProps: PortableTextEditorProps): void;
199
199
  componentWillUnmount(): void;
200
200
  setEditable: (editable: EditableAPI) => void;
201
- render(): react22.JSX.Element;
201
+ render(): react20.JSX.Element;
202
202
  /**
203
203
  * @deprecated
204
204
  * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
@@ -593,7 +593,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
593
593
  * ```
594
594
  * @group Components
595
595
  */
596
- declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
596
+ declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
597
597
  type DecoratedRange = BaseRange & {
598
598
  rangeDecoration: RangeDecoration;
599
599
  };
@@ -1331,7 +1331,7 @@ declare const editorMachine: xstate227.StateMachine<{
1331
1331
  initialValue?: Array<PortableTextBlock>;
1332
1332
  }, xstate227.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
1333
1333
  type: "blurred";
1334
- event: react22.FocusEvent<HTMLDivElement, Element>;
1334
+ event: react20.FocusEvent<HTMLDivElement, Element>;
1335
1335
  } | {
1336
1336
  type: "done loading";
1337
1337
  } | {
@@ -1343,7 +1343,7 @@ declare const editorMachine: xstate227.StateMachine<{
1343
1343
  data: unknown;
1344
1344
  } | {
1345
1345
  type: "focused";
1346
- event: react22.FocusEvent<HTMLDivElement, Element>;
1346
+ event: react20.FocusEvent<HTMLDivElement, Element>;
1347
1347
  } | {
1348
1348
  type: "invalid value";
1349
1349
  resolution: InvalidValueResolution | null;
@@ -1498,7 +1498,7 @@ declare const editorMachine: xstate227.StateMachine<{
1498
1498
  }, xstate227.AnyEventObject>;
1499
1499
  }) => {
1500
1500
  behaviors: Set<{
1501
- behavior: Behavior<"*" | "split" | `custom.${string}` | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "style.*" | "history.*" | "split.*" | "delete.*" | "select.*" | "deserialize.*" | "serialize.*" | "annotation.*" | "block.*" | "child.*" | "decorator.*" | "insert.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "clipboard.*" | "drag.*" | "keyboard.*" | "mouse.*", true, {
1501
+ behavior: Behavior<"*" | "split" | `custom.${string}` | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "history.*" | "split.*" | "delete.*" | "select.*" | "deserialize.*" | "serialize.*" | "annotation.*" | "block.*" | "child.*" | "decorator.*" | "insert.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "style.*" | "clipboard.*" | "drag.*" | "keyboard.*" | "mouse.*", true, {
1502
1502
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "annotation.add">;
1503
1503
  annotation: {
1504
1504
  name: string;
@@ -2006,7 +2006,7 @@ declare const editorMachine: xstate227.StateMachine<{
2006
2006
  type: "drop";
2007
2007
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2008
2008
  type: "blurred";
2009
- event: react22.FocusEvent<HTMLDivElement, Element>;
2009
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2010
2010
  } | {
2011
2011
  type: "done loading";
2012
2012
  } | {
@@ -2018,7 +2018,7 @@ declare const editorMachine: xstate227.StateMachine<{
2018
2018
  data: unknown;
2019
2019
  } | {
2020
2020
  type: "focused";
2021
- event: react22.FocusEvent<HTMLDivElement, Element>;
2021
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2022
2022
  } | {
2023
2023
  type: "invalid value";
2024
2024
  resolution: InvalidValueResolution | null;
@@ -2889,7 +2889,7 @@ declare const editorMachine: xstate227.StateMachine<{
2889
2889
  type: "drop";
2890
2890
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2891
2891
  type: "blurred";
2892
- event: react22.FocusEvent<HTMLDivElement, Element>;
2892
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2893
2893
  } | {
2894
2894
  type: "done loading";
2895
2895
  } | {
@@ -2901,7 +2901,7 @@ declare const editorMachine: xstate227.StateMachine<{
2901
2901
  data: unknown;
2902
2902
  } | {
2903
2903
  type: "focused";
2904
- event: react22.FocusEvent<HTMLDivElement, Element>;
2904
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2905
2905
  } | {
2906
2906
  type: "invalid value";
2907
2907
  resolution: InvalidValueResolution | null;
package/lib/index.cjs CHANGED
@@ -1884,7 +1884,7 @@ function createDecorate(schema2, slateEditor) {
1884
1884
  };
1885
1885
  }
1886
1886
  const RelayActorContext = React.createContext({}), debug$d = debugWithName("component:Editable"), PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
1887
- const $ = reactCompilerRuntime.c(171);
1887
+ const $ = reactCompilerRuntime.c(172);
1888
1888
  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;
1889
1889
  $[0] !== props ? ({
1890
1890
  hotkeys,
@@ -2421,16 +2421,50 @@ const RelayActorContext = React.createContext({}), debug$d = debugWithName("comp
2421
2421
  }, $[140] = editorActor, $[141] = onDragLeave, $[142] = slateEditor, $[143] = t34) : t34 = $[143];
2422
2422
  const handleDragLeave = t34;
2423
2423
  let t35;
2424
- $[144] !== forwardedRef ? (t35 = (node) => {
2425
- typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node);
2426
- }, $[144] = forwardedRef, $[145] = t35) : t35 = $[145];
2424
+ $[144] !== forwardedRef || $[145] !== slateEditor ? (t35 = (node) => {
2425
+ if (typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node), node) {
2426
+ const mutationObserver = new MutationObserver(() => {
2427
+ validateSelection(slateEditor, node);
2428
+ });
2429
+ return mutationObserver.observe(node, {
2430
+ attributeOldValue: !1,
2431
+ attributes: !1,
2432
+ characterData: !1,
2433
+ childList: !0,
2434
+ subtree: !0
2435
+ }), () => {
2436
+ mutationObserver.disconnect();
2437
+ };
2438
+ }
2439
+ }, $[144] = forwardedRef, $[145] = slateEditor, $[146] = t35) : t35 = $[146];
2427
2440
  const callbackRef = t35;
2428
2441
  if (!portableTextEditor)
2429
2442
  return null;
2430
2443
  let t36;
2431
- return $[146] !== callbackRef || $[147] !== decorate || $[148] !== handleClick || $[149] !== handleCopy || $[150] !== handleCut || $[151] !== handleDrag || $[152] !== handleDragEnd || $[153] !== handleDragEnter || $[154] !== handleDragLeave || $[155] !== handleDragOver || $[156] !== handleDragStart || $[157] !== handleDrop || $[158] !== handleKeyDown || $[159] !== handleKeyUp || $[160] !== handleOnBeforeInput || $[161] !== handleOnBlur || $[162] !== handleOnFocus || $[163] !== handlePaste || $[164] !== hasInvalidValue || $[165] !== readOnly || $[166] !== renderElement || $[167] !== renderLeaf || $[168] !== restProps || $[169] !== scrollSelectionIntoViewToSlate ? (t36 = hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editable, { ...restProps, ref: callbackRef, "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 }), $[146] = callbackRef, $[147] = decorate, $[148] = handleClick, $[149] = handleCopy, $[150] = handleCut, $[151] = handleDrag, $[152] = handleDragEnd, $[153] = handleDragEnter, $[154] = handleDragLeave, $[155] = handleDragOver, $[156] = handleDragStart, $[157] = handleDrop, $[158] = handleKeyDown, $[159] = handleKeyUp, $[160] = handleOnBeforeInput, $[161] = handleOnBlur, $[162] = handleOnFocus, $[163] = handlePaste, $[164] = hasInvalidValue, $[165] = readOnly, $[166] = renderElement, $[167] = renderLeaf, $[168] = restProps, $[169] = scrollSelectionIntoViewToSlate, $[170] = t36) : t36 = $[170], t36;
2444
+ return $[147] !== callbackRef || $[148] !== decorate || $[149] !== handleClick || $[150] !== handleCopy || $[151] !== handleCut || $[152] !== handleDrag || $[153] !== handleDragEnd || $[154] !== handleDragEnter || $[155] !== handleDragLeave || $[156] !== handleDragOver || $[157] !== handleDragStart || $[158] !== handleDrop || $[159] !== handleKeyDown || $[160] !== handleKeyUp || $[161] !== handleOnBeforeInput || $[162] !== handleOnBlur || $[163] !== handleOnFocus || $[164] !== handlePaste || $[165] !== hasInvalidValue || $[166] !== readOnly || $[167] !== renderElement || $[168] !== renderLeaf || $[169] !== restProps || $[170] !== scrollSelectionIntoViewToSlate ? (t36 = hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(slateReact.Editable, { ...restProps, ref: callbackRef, "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 }), $[147] = callbackRef, $[148] = decorate, $[149] = handleClick, $[150] = handleCopy, $[151] = handleCut, $[152] = handleDrag, $[153] = handleDragEnd, $[154] = handleDragEnter, $[155] = handleDragLeave, $[156] = handleDragOver, $[157] = handleDragStart, $[158] = handleDrop, $[159] = handleKeyDown, $[160] = handleKeyUp, $[161] = handleOnBeforeInput, $[162] = handleOnBlur, $[163] = handleOnFocus, $[164] = handlePaste, $[165] = hasInvalidValue, $[166] = readOnly, $[167] = renderElement, $[168] = renderLeaf, $[169] = restProps, $[170] = scrollSelectionIntoViewToSlate, $[171] = t36) : t36 = $[171], t36;
2432
2445
  });
2433
2446
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
2447
+ function validateSelection(slateEditor, activeElement) {
2448
+ if (!slateEditor.selection)
2449
+ return;
2450
+ let root;
2451
+ try {
2452
+ root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor);
2453
+ } catch {
2454
+ }
2455
+ if (!root || activeElement !== root.activeElement)
2456
+ return;
2457
+ const domSelection = slateReact.ReactEditor.getWindow(slateEditor).getSelection();
2458
+ if (!domSelection || domSelection.rangeCount === 0)
2459
+ return;
2460
+ const existingDOMRange = domSelection.getRangeAt(0);
2461
+ try {
2462
+ const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
2463
+ (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$d("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
2464
+ } catch {
2465
+ debug$d("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
2466
+ }
2467
+ }
2434
2468
  function _temp(s) {
2435
2469
  return s.matches({
2436
2470
  "edit mode": "read only"