@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.
package/lib/index.js CHANGED
@@ -20,7 +20,7 @@ import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
20
20
  import uniq from "lodash/uniq.js";
21
21
  import { Subject } from "rxjs";
22
22
  import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
23
- import { setup, assign, enqueueActions, emit, assertEvent, stateIn, fromCallback, and, not, raise as raise$1, createActor } from "xstate";
23
+ import { setup, assign, enqueueActions, emit, assertEvent, fromCallback, and, raise as raise$1, not, createActor } from "xstate";
24
24
  import { htmlToBlocks } from "@portabletext/block-tools";
25
25
  import { toHTML } from "@portabletext/to-html";
26
26
  import { Schema } from "@sanity/schema";
@@ -4912,7 +4912,7 @@ function createWithPatches({
4912
4912
  ...patch,
4913
4913
  origin: "local"
4914
4914
  },
4915
- operationId: getCurrentOperationId(editor),
4915
+ operationId: getCurrentUndoStepId(editor),
4916
4916
  value: editor.value
4917
4917
  });
4918
4918
  return editor;
@@ -6793,6 +6793,51 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
6793
6793
  unit: event.unit,
6794
6794
  at: selection
6795
6795
  })]]
6796
+ }), defineBehavior({
6797
+ on: "delete",
6798
+ guard: ({
6799
+ snapshot,
6800
+ event
6801
+ }) => {
6802
+ if (event.direction !== "forward")
6803
+ return !1;
6804
+ const nextBlock = getNextBlock({
6805
+ ...snapshot,
6806
+ context: {
6807
+ ...snapshot.context,
6808
+ selection: event.at
6809
+ }
6810
+ }), focusTextBlock = getFocusTextBlock({
6811
+ ...snapshot,
6812
+ context: {
6813
+ ...snapshot.context,
6814
+ selection: event.at
6815
+ }
6816
+ });
6817
+ if (!nextBlock || !focusTextBlock || !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
6818
+ return !1;
6819
+ const nextBlockStartPoint = getBlockStartPoint({
6820
+ context: snapshot.context,
6821
+ block: nextBlock
6822
+ });
6823
+ return {
6824
+ focusTextBlock,
6825
+ nextBlockStartPoint
6826
+ };
6827
+ },
6828
+ actions: [(_, {
6829
+ focusTextBlock,
6830
+ nextBlockStartPoint
6831
+ }) => [raise({
6832
+ type: "delete.block",
6833
+ at: focusTextBlock.path
6834
+ }), raise({
6835
+ type: "select",
6836
+ at: {
6837
+ anchor: nextBlockStartPoint,
6838
+ focus: nextBlockStartPoint
6839
+ }
6840
+ })]]
6796
6841
  }), defineBehavior({
6797
6842
  on: "delete",
6798
6843
  guard: ({
@@ -8681,14 +8726,14 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
8681
8726
  input.slateEditor.apply = originalApply;
8682
8727
  };
8683
8728
  }),
8684
- "mutation debouncer": fromCallback(({
8729
+ "mutation interval": fromCallback(({
8685
8730
  sendBack
8686
8731
  }) => {
8687
8732
  const interval = setInterval(() => {
8688
8733
  sendBack({
8689
- type: "mutation delay passed"
8734
+ type: "emit changes"
8690
8735
  });
8691
- }, process.env.NODE_ENV === "test" ? 250 : 0);
8736
+ }, process.env.NODE_ENV === "test" ? 250 : 1e3);
8692
8737
  return () => {
8693
8738
  clearInterval(interval);
8694
8739
  };
@@ -8698,15 +8743,12 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
8698
8743
  "is read-only": ({
8699
8744
  context
8700
8745
  }) => context.readOnly,
8701
- "is typing": stateIn({
8702
- typing: "typing"
8703
- }),
8704
8746
  "slate is normalizing": ({
8705
8747
  context
8706
8748
  }) => Editor.isNormalizing(context.slateEditor)
8707
8749
  },
8708
8750
  delays: {
8709
- "type debounce": process.env.NODE_ENV === "test" ? 0 : 250
8751
+ "type debounce": 250
8710
8752
  }
8711
8753
  }).createMachine({
8712
8754
  id: "mutation",
@@ -8754,14 +8796,19 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
8754
8796
  after: {
8755
8797
  "type debounce": {
8756
8798
  target: "idle",
8757
- actions: [() => {
8799
+ actions: [raise$1({
8800
+ type: "emit changes"
8801
+ }), () => {
8758
8802
  debug$6("exit: typing->typing");
8759
8803
  }]
8760
8804
  }
8761
8805
  },
8762
8806
  on: {
8763
8807
  "not typing": {
8764
- target: "idle"
8808
+ target: "idle",
8809
+ actions: [raise$1({
8810
+ type: "emit changes"
8811
+ })]
8765
8812
  },
8766
8813
  typing: {
8767
8814
  target: "typing",
@@ -8800,11 +8847,11 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
8800
8847
  debug$6("exit: mutations->has pending mutations");
8801
8848
  }],
8802
8849
  invoke: {
8803
- src: "mutation debouncer"
8850
+ src: "mutation interval"
8804
8851
  },
8805
8852
  on: {
8806
- "mutation delay passed": {
8807
- guard: and([not("is read-only"), not("is typing"), "slate is normalizing"]),
8853
+ "emit changes": {
8854
+ guard: and([not("is read-only"), "slate is normalizing"]),
8808
8855
  target: "idle",
8809
8856
  actions: ["emit pending patch events", "clear pending patch events", "emit mutations", "clear pending mutations"]
8810
8857
  },