@portabletext/editor 2.3.5 → 2.3.7

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";
@@ -215,7 +215,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
215
215
  componentDidUpdate(prevProps: PortableTextEditorProps): void;
216
216
  componentWillUnmount(): void;
217
217
  setEditable: (editable: EditableAPI) => void;
218
- render(): react22.JSX.Element;
218
+ render(): react20.JSX.Element;
219
219
  /**
220
220
  * @deprecated
221
221
  * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
@@ -610,7 +610,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
610
610
  * ```
611
611
  * @group Components
612
612
  */
613
- declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
613
+ declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
614
614
  type DecoratedRange = BaseRange & {
615
615
  rangeDecoration: RangeDecoration;
616
616
  };
@@ -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;
@@ -1998,7 +1998,7 @@ declare const editorMachine: xstate227.StateMachine<{
1998
1998
  type: "drop";
1999
1999
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2000
2000
  type: "blurred";
2001
- event: react22.FocusEvent<HTMLDivElement, Element>;
2001
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2002
2002
  } | {
2003
2003
  type: "done loading";
2004
2004
  } | {
@@ -2010,7 +2010,7 @@ declare const editorMachine: xstate227.StateMachine<{
2010
2010
  data: unknown;
2011
2011
  } | {
2012
2012
  type: "focused";
2013
- event: react22.FocusEvent<HTMLDivElement, Element>;
2013
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2014
2014
  } | {
2015
2015
  type: "invalid value";
2016
2016
  resolution: InvalidValueResolution | null;
@@ -2881,7 +2881,7 @@ declare const editorMachine: xstate227.StateMachine<{
2881
2881
  type: "drop";
2882
2882
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2883
2883
  type: "blurred";
2884
- event: react22.FocusEvent<HTMLDivElement, Element>;
2884
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2885
2885
  } | {
2886
2886
  type: "done loading";
2887
2887
  } | {
@@ -2893,7 +2893,7 @@ declare const editorMachine: xstate227.StateMachine<{
2893
2893
  data: unknown;
2894
2894
  } | {
2895
2895
  type: "focused";
2896
- event: react22.FocusEvent<HTMLDivElement, Element>;
2896
+ event: react20.FocusEvent<HTMLDivElement, Element>;
2897
2897
  } | {
2898
2898
  type: "invalid value";
2899
2899
  resolution: InvalidValueResolution | null;
package/lib/index.cjs CHANGED
@@ -1386,21 +1386,6 @@ const insertTextOperationImplementation = ({
1386
1386
  marks: [...activeDecorators, ...activeAnnotations]
1387
1387
  }), slateDom.EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
1388
1388
  };
1389
- function isPortableTextSpan(node) {
1390
- return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
1391
- }
1392
- function isPortableTextBlock(node) {
1393
- return (
1394
- // A block doesn't _have_ to be named 'block' - to differentiate between
1395
- // allowed child types and marks, one might name them differently
1396
- typeof node._type == "string" && // Toolkit-types like nested spans are @-prefixed
1397
- node._type[0] !== "@" && // `markDefs` isn't _required_ per say, but if it's there, it needs to be an array
1398
- (!("markDefs" in node) || !node.markDefs || Array.isArray(node.markDefs) && // Every mark definition needs to have an `_key` to be mappable in child spans
1399
- node.markDefs.every((def) => typeof def._key == "string")) && // `children` is required and needs to be an array
1400
- "children" in node && Array.isArray(node.children) && // All children are objects with `_type` (usually spans, but can contain other stuff)
1401
- node.children.every((child) => typeof child == "object" && "_type" in child)
1402
- );
1403
- }
1404
1389
  function getPreviousSpan({
1405
1390
  editor,
1406
1391
  blockPath,
@@ -1673,7 +1658,7 @@ function createWithPortableTextMarkModel(editorActor) {
1673
1658
  blockPath,
1674
1659
  spanPath: [op.path[0], op.path[1] - 1]
1675
1660
  }), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
1676
- if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
1661
+ if (atTheEndOfAnnotation && util_sliceBlocks.isSpan(editorActor.getSnapshot().context, op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
1677
1662
  slate.Transforms.insertNodes(editor, {
1678
1663
  ...op.node,
1679
1664
  _key: editorActor.getSnapshot().context.keyGenerator(),
@@ -1682,7 +1667,7 @@ function createWithPortableTextMarkModel(editorActor) {
1682
1667
  return;
1683
1668
  }
1684
1669
  const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
1685
- if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
1670
+ if (atTheStartOfAnnotation && util_sliceBlocks.isSpan(editorActor.getSnapshot().context, op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
1686
1671
  slate.Transforms.insertNodes(editor, {
1687
1672
  ...op.node,
1688
1673
  _key: editorActor.getSnapshot().context.keyGenerator(),
@@ -1691,7 +1676,7 @@ function createWithPortableTextMarkModel(editorActor) {
1691
1676
  return;
1692
1677
  }
1693
1678
  const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
1694
- if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
1679
+ if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && util_sliceBlocks.isSpan(editorActor.getSnapshot().context, op.node) && op.node.marks?.length === 0) {
1695
1680
  slate.Transforms.insertNodes(editor, {
1696
1681
  ...op.node,
1697
1682
  _key: editorActor.getSnapshot().context.keyGenerator(),
@@ -1738,7 +1723,7 @@ function createWithPortableTextMarkModel(editorActor) {
1738
1723
  match: (n) => editor.isTextSpan(n),
1739
1724
  voids: !1
1740
1725
  }))[0] ?? [void 0, void 0];
1741
- if (span && block && isPortableTextBlock(block)) {
1726
+ if (span && block && util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, block)) {
1742
1727
  const markDefs = block.markDefs ?? [], marks = span.marks ?? [], spanHasAnnotations = marks.some((mark) => markDefs.find((markDef) => markDef._key === mark)), deletingFromTheEnd = op.offset + op.text.length === span.text.length, deletingAllText = op.offset === 0 && deletingFromTheEnd, previousSpan = getPreviousSpan({
1743
1728
  editor,
1744
1729
  blockPath,