@portabletext/editor 2.6.8 → 2.6.9

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 react22 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(): react20.JSX.Element;
218
+ render(): react22.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: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
613
+ declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.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: react20.FocusEvent<HTMLDivElement, Element>;
1342
+ event: react22.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: react22.FocusEvent<HTMLDivElement, Element>;
1355
1355
  } | {
1356
1356
  type: "invalid value";
1357
1357
  resolution: InvalidValueResolution | null;
@@ -2007,7 +2007,7 @@ declare const editorMachine: xstate227.StateMachine<{
2007
2007
  type: "drop";
2008
2008
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2009
2009
  type: "blurred";
2010
- event: react20.FocusEvent<HTMLDivElement, Element>;
2010
+ event: react22.FocusEvent<HTMLDivElement, Element>;
2011
2011
  } | {
2012
2012
  type: "done loading";
2013
2013
  } | {
@@ -2019,7 +2019,7 @@ declare const editorMachine: xstate227.StateMachine<{
2019
2019
  data: unknown;
2020
2020
  } | {
2021
2021
  type: "focused";
2022
- event: react20.FocusEvent<HTMLDivElement, Element>;
2022
+ event: react22.FocusEvent<HTMLDivElement, Element>;
2023
2023
  } | {
2024
2024
  type: "invalid value";
2025
2025
  resolution: InvalidValueResolution | null;
@@ -2890,7 +2890,7 @@ declare const editorMachine: xstate227.StateMachine<{
2890
2890
  type: "drop";
2891
2891
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2892
2892
  type: "blurred";
2893
- event: react20.FocusEvent<HTMLDivElement, Element>;
2893
+ event: react22.FocusEvent<HTMLDivElement, Element>;
2894
2894
  } | {
2895
2895
  type: "done loading";
2896
2896
  } | {
@@ -2902,7 +2902,7 @@ declare const editorMachine: xstate227.StateMachine<{
2902
2902
  data: unknown;
2903
2903
  } | {
2904
2904
  type: "focused";
2905
- event: react20.FocusEvent<HTMLDivElement, Element>;
2905
+ event: react22.FocusEvent<HTMLDivElement, Element>;
2906
2906
  } | {
2907
2907
  type: "invalid value";
2908
2908
  resolution: InvalidValueResolution | null;
package/lib/index.cjs CHANGED
@@ -4882,7 +4882,7 @@ function createWithPatches({
4882
4882
  ...patch,
4883
4883
  origin: "local"
4884
4884
  },
4885
- operationId: getCurrentOperationId(editor),
4885
+ operationId: getCurrentUndoStepId(editor),
4886
4886
  value: editor.value
4887
4887
  });
4888
4888
  return editor;
@@ -6763,6 +6763,51 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
6763
6763
  unit: event.unit,
6764
6764
  at: selection
6765
6765
  })]]
6766
+ }), behaviors_index.defineBehavior({
6767
+ on: "delete",
6768
+ guard: ({
6769
+ snapshot,
6770
+ event
6771
+ }) => {
6772
+ if (event.direction !== "forward")
6773
+ return !1;
6774
+ const nextBlock = selector_isSelectingEntireBlocks.getNextBlock({
6775
+ ...snapshot,
6776
+ context: {
6777
+ ...snapshot.context,
6778
+ selection: event.at
6779
+ }
6780
+ }), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
6781
+ ...snapshot,
6782
+ context: {
6783
+ ...snapshot.context,
6784
+ selection: event.at
6785
+ }
6786
+ });
6787
+ if (!nextBlock || !focusTextBlock || !util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node))
6788
+ return !1;
6789
+ const nextBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
6790
+ context: snapshot.context,
6791
+ block: nextBlock
6792
+ });
6793
+ return {
6794
+ focusTextBlock,
6795
+ nextBlockStartPoint
6796
+ };
6797
+ },
6798
+ actions: [(_, {
6799
+ focusTextBlock,
6800
+ nextBlockStartPoint
6801
+ }) => [behaviors_index.raise({
6802
+ type: "delete.block",
6803
+ at: focusTextBlock.path
6804
+ }), behaviors_index.raise({
6805
+ type: "select",
6806
+ at: {
6807
+ anchor: nextBlockStartPoint,
6808
+ focus: nextBlockStartPoint
6809
+ }
6810
+ })]]
6766
6811
  }), behaviors_index.defineBehavior({
6767
6812
  on: "delete",
6768
6813
  guard: ({
@@ -8651,14 +8696,14 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
8651
8696
  input.slateEditor.apply = originalApply;
8652
8697
  };
8653
8698
  }),
8654
- "mutation debouncer": xstate.fromCallback(({
8699
+ "mutation interval": xstate.fromCallback(({
8655
8700
  sendBack
8656
8701
  }) => {
8657
8702
  const interval = setInterval(() => {
8658
8703
  sendBack({
8659
- type: "mutation delay passed"
8704
+ type: "emit changes"
8660
8705
  });
8661
- }, process.env.NODE_ENV === "test" ? 250 : 0);
8706
+ }, process.env.NODE_ENV === "test" ? 250 : 1e3);
8662
8707
  return () => {
8663
8708
  clearInterval(interval);
8664
8709
  };
@@ -8668,15 +8713,12 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
8668
8713
  "is read-only": ({
8669
8714
  context
8670
8715
  }) => context.readOnly,
8671
- "is typing": xstate.stateIn({
8672
- typing: "typing"
8673
- }),
8674
8716
  "slate is normalizing": ({
8675
8717
  context
8676
8718
  }) => slate.Editor.isNormalizing(context.slateEditor)
8677
8719
  },
8678
8720
  delays: {
8679
- "type debounce": process.env.NODE_ENV === "test" ? 0 : 250
8721
+ "type debounce": 250
8680
8722
  }
8681
8723
  }).createMachine({
8682
8724
  id: "mutation",
@@ -8724,14 +8766,19 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
8724
8766
  after: {
8725
8767
  "type debounce": {
8726
8768
  target: "idle",
8727
- actions: [() => {
8769
+ actions: [xstate.raise({
8770
+ type: "emit changes"
8771
+ }), () => {
8728
8772
  debug$6("exit: typing->typing");
8729
8773
  }]
8730
8774
  }
8731
8775
  },
8732
8776
  on: {
8733
8777
  "not typing": {
8734
- target: "idle"
8778
+ target: "idle",
8779
+ actions: [xstate.raise({
8780
+ type: "emit changes"
8781
+ })]
8735
8782
  },
8736
8783
  typing: {
8737
8784
  target: "typing",
@@ -8770,11 +8817,11 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
8770
8817
  debug$6("exit: mutations->has pending mutations");
8771
8818
  }],
8772
8819
  invoke: {
8773
- src: "mutation debouncer"
8820
+ src: "mutation interval"
8774
8821
  },
8775
8822
  on: {
8776
- "mutation delay passed": {
8777
- guard: xstate.and([xstate.not("is read-only"), xstate.not("is typing"), "slate is normalizing"]),
8823
+ "emit changes": {
8824
+ guard: xstate.and([xstate.not("is read-only"), "slate is normalizing"]),
8778
8825
  target: "idle",
8779
8826
  actions: ["emit pending patch events", "clear pending patch events", "emit mutations", "clear pending mutations"]
8780
8827
  },