@portabletext/editor 2.12.2 → 2.12.3

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 react20 from "react";
9
+ import * as react21 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";
@@ -202,7 +202,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
202
202
  componentDidUpdate(prevProps: PortableTextEditorProps): void;
203
203
  componentWillUnmount(): void;
204
204
  setEditable: (editable: EditableAPI) => void;
205
- render(): react20.JSX.Element;
205
+ render(): react21.JSX.Element;
206
206
  /**
207
207
  * @deprecated
208
208
  * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
@@ -597,7 +597,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
597
597
  * ```
598
598
  * @group Components
599
599
  */
600
- declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
600
+ declare const PortableTextEditable: react21.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react21.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
601
601
  type DecoratedRange = BaseRange & {
602
602
  rangeDecoration: RangeDecoration;
603
603
  };
@@ -1339,7 +1339,7 @@ declare const editorMachine: xstate227.StateMachine<{
1339
1339
  initialValue?: Array<PortableTextBlock>;
1340
1340
  }, xstate227.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
1341
1341
  type: "blurred";
1342
- event: react20.FocusEvent<HTMLDivElement, Element>;
1342
+ event: react21.FocusEvent<HTMLDivElement, Element>;
1343
1343
  } | {
1344
1344
  type: "done loading";
1345
1345
  } | {
@@ -1351,7 +1351,7 @@ declare const editorMachine: xstate227.StateMachine<{
1351
1351
  data: unknown;
1352
1352
  } | {
1353
1353
  type: "focused";
1354
- event: react20.FocusEvent<HTMLDivElement, Element>;
1354
+ event: react21.FocusEvent<HTMLDivElement, Element>;
1355
1355
  } | {
1356
1356
  type: "invalid value";
1357
1357
  resolution: InvalidValueResolution | null;
@@ -2014,7 +2014,7 @@ declare const editorMachine: xstate227.StateMachine<{
2014
2014
  type: "drop";
2015
2015
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2016
2016
  type: "blurred";
2017
- event: react20.FocusEvent<HTMLDivElement, Element>;
2017
+ event: react21.FocusEvent<HTMLDivElement, Element>;
2018
2018
  } | {
2019
2019
  type: "done loading";
2020
2020
  } | {
@@ -2026,7 +2026,7 @@ declare const editorMachine: xstate227.StateMachine<{
2026
2026
  data: unknown;
2027
2027
  } | {
2028
2028
  type: "focused";
2029
- event: react20.FocusEvent<HTMLDivElement, Element>;
2029
+ event: react21.FocusEvent<HTMLDivElement, Element>;
2030
2030
  } | {
2031
2031
  type: "invalid value";
2032
2032
  resolution: InvalidValueResolution | null;
@@ -2897,7 +2897,7 @@ declare const editorMachine: xstate227.StateMachine<{
2897
2897
  type: "drop";
2898
2898
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2899
2899
  type: "blurred";
2900
- event: react20.FocusEvent<HTMLDivElement, Element>;
2900
+ event: react21.FocusEvent<HTMLDivElement, Element>;
2901
2901
  } | {
2902
2902
  type: "done loading";
2903
2903
  } | {
@@ -2909,7 +2909,7 @@ declare const editorMachine: xstate227.StateMachine<{
2909
2909
  data: unknown;
2910
2910
  } | {
2911
2911
  type: "focused";
2912
- event: react20.FocusEvent<HTMLDivElement, Element>;
2912
+ event: react21.FocusEvent<HTMLDivElement, Element>;
2913
2913
  } | {
2914
2914
  type: "invalid value";
2915
2915
  resolution: InvalidValueResolution | null;
@@ -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";
@@ -202,7 +202,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
202
202
  componentDidUpdate(prevProps: PortableTextEditorProps): void;
203
203
  componentWillUnmount(): void;
204
204
  setEditable: (editable: EditableAPI) => void;
205
- render(): react22.JSX.Element;
205
+ render(): react20.JSX.Element;
206
206
  /**
207
207
  * @deprecated
208
208
  * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
@@ -597,7 +597,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
597
597
  * ```
598
598
  * @group Components
599
599
  */
600
- declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
600
+ declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
601
601
  type DecoratedRange = BaseRange & {
602
602
  rangeDecoration: RangeDecoration;
603
603
  };
@@ -1339,7 +1339,7 @@ declare const editorMachine: xstate227.StateMachine<{
1339
1339
  initialValue?: Array<PortableTextBlock>;
1340
1340
  }, xstate227.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
1341
1341
  type: "blurred";
1342
- event: react22.FocusEvent<HTMLDivElement, Element>;
1342
+ event: react20.FocusEvent<HTMLDivElement, Element>;
1343
1343
  } | {
1344
1344
  type: "done loading";
1345
1345
  } | {
@@ -1351,7 +1351,7 @@ declare const editorMachine: xstate227.StateMachine<{
1351
1351
  data: unknown;
1352
1352
  } | {
1353
1353
  type: "focused";
1354
- event: react22.FocusEvent<HTMLDivElement, Element>;
1354
+ event: react20.FocusEvent<HTMLDivElement, Element>;
1355
1355
  } | {
1356
1356
  type: "invalid value";
1357
1357
  resolution: InvalidValueResolution | null;
@@ -2014,7 +2014,7 @@ declare const editorMachine: xstate227.StateMachine<{
2014
2014
  type: "drop";
2015
2015
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2016
2016
  type: "blurred";
2017
- event: react22.FocusEvent<HTMLDivElement, Element>;
2017
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2018
2018
  } | {
2019
2019
  type: "done loading";
2020
2020
  } | {
@@ -2026,7 +2026,7 @@ declare const editorMachine: xstate227.StateMachine<{
2026
2026
  data: unknown;
2027
2027
  } | {
2028
2028
  type: "focused";
2029
- event: react22.FocusEvent<HTMLDivElement, Element>;
2029
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2030
2030
  } | {
2031
2031
  type: "invalid value";
2032
2032
  resolution: InvalidValueResolution | null;
@@ -2897,7 +2897,7 @@ declare const editorMachine: xstate227.StateMachine<{
2897
2897
  type: "drop";
2898
2898
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2899
2899
  type: "blurred";
2900
- event: react22.FocusEvent<HTMLDivElement, Element>;
2900
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2901
2901
  } | {
2902
2902
  type: "done loading";
2903
2903
  } | {
@@ -2909,7 +2909,7 @@ declare const editorMachine: xstate227.StateMachine<{
2909
2909
  data: unknown;
2910
2910
  } | {
2911
2911
  type: "focused";
2912
- event: react22.FocusEvent<HTMLDivElement, Element>;
2912
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2913
2913
  } | {
2914
2914
  type: "invalid value";
2915
2915
  resolution: InvalidValueResolution | null;
package/lib/index.cjs CHANGED
@@ -1705,7 +1705,7 @@ function createDecorate(schema2, slateEditor) {
1705
1705
  };
1706
1706
  }
1707
1707
  const RelayActorContext = React.createContext({}), debug$d = debugWithName("component:Editable"), PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
1708
- const $ = reactCompilerRuntime.c(172);
1708
+ const $ = reactCompilerRuntime.c(171);
1709
1709
  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;
1710
1710
  $[0] !== props ? ({
1711
1711
  hotkeys,
@@ -2242,50 +2242,16 @@ const RelayActorContext = React.createContext({}), debug$d = debugWithName("comp
2242
2242
  }, $[140] = editorActor, $[141] = onDragLeave, $[142] = slateEditor, $[143] = t34) : t34 = $[143];
2243
2243
  const handleDragLeave = t34;
2244
2244
  let t35;
2245
- $[144] !== forwardedRef || $[145] !== slateEditor ? (t35 = (node) => {
2246
- if (typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node), node) {
2247
- const mutationObserver = new MutationObserver(() => {
2248
- validateSelection(slateEditor, node);
2249
- });
2250
- return mutationObserver.observe(node, {
2251
- attributeOldValue: !1,
2252
- attributes: !1,
2253
- characterData: !1,
2254
- childList: !0,
2255
- subtree: !0
2256
- }), () => {
2257
- mutationObserver.disconnect();
2258
- };
2259
- }
2260
- }, $[144] = forwardedRef, $[145] = slateEditor, $[146] = t35) : t35 = $[146];
2245
+ $[144] !== forwardedRef ? (t35 = (node) => {
2246
+ typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node);
2247
+ }, $[144] = forwardedRef, $[145] = t35) : t35 = $[145];
2261
2248
  const callbackRef = t35;
2262
2249
  if (!portableTextEditor)
2263
2250
  return null;
2264
2251
  let t36;
2265
- 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;
2252
+ 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;
2266
2253
  });
2267
2254
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
2268
- function validateSelection(slateEditor, activeElement) {
2269
- if (!slateEditor.selection)
2270
- return;
2271
- let root;
2272
- try {
2273
- root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor);
2274
- } catch {
2275
- }
2276
- if (!root || activeElement !== root.activeElement)
2277
- return;
2278
- const domSelection = slateReact.ReactEditor.getWindow(slateEditor).getSelection();
2279
- if (!domSelection || domSelection.rangeCount === 0)
2280
- return;
2281
- const existingDOMRange = domSelection.getRangeAt(0);
2282
- try {
2283
- const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
2284
- (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$d("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
2285
- } catch {
2286
- 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();
2287
- }
2288
- }
2289
2255
  function _temp(s) {
2290
2256
  return s.matches({
2291
2257
  "edit mode": "read only"