@portabletext/editor 2.9.1 → 2.10.0

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.
Files changed (53) hide show
  1. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +9 -1
  2. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  3. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +1 -0
  4. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.slice-blocks.cjs +6 -1
  6. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  7. package/lib/_chunks-dts/behavior.types.action.d.cts +141 -131
  8. package/lib/_chunks-dts/behavior.types.action.d.ts +71 -61
  9. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +9 -1
  10. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  11. package/lib/_chunks-es/util.merge-text-blocks.js +1 -0
  12. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
  13. package/lib/_chunks-es/util.slice-blocks.js +6 -1
  14. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  15. package/lib/index.cjs +419 -309
  16. package/lib/index.cjs.map +1 -1
  17. package/lib/index.js +422 -312
  18. package/lib/index.js.map +1 -1
  19. package/lib/plugins/index.d.cts +3 -3
  20. package/lib/plugins/index.d.ts +3 -3
  21. package/lib/utils/index.d.ts +2 -2
  22. package/package.json +8 -8
  23. package/src/behaviors/behavior.abstract.insert.ts +109 -24
  24. package/src/behaviors/behavior.abstract.split.ts +1 -0
  25. package/src/behaviors/behavior.perform-event.ts +84 -118
  26. package/src/behaviors/behavior.types.event.ts +9 -1
  27. package/src/converters/converter.portable-text.ts +1 -0
  28. package/src/converters/converter.text-html.ts +1 -0
  29. package/src/converters/converter.text-plain.ts +1 -0
  30. package/src/editor/Editable.tsx +1 -0
  31. package/src/editor/editor-selector.ts +10 -1
  32. package/src/editor/plugins/create-with-event-listeners.ts +13 -14
  33. package/src/editor/sync-machine.ts +9 -0
  34. package/src/editor/with-performing-behavior-operation.ts +21 -0
  35. package/src/editor/without-normalizing-conditional.ts +13 -0
  36. package/src/internal-utils/parse-blocks.test.ts +14 -14
  37. package/src/internal-utils/parse-blocks.ts +9 -2
  38. package/src/internal-utils/slate-utils.test.tsx +119 -0
  39. package/src/internal-utils/slate-utils.ts +14 -1
  40. package/src/internal-utils/text-marks.ts +1 -1
  41. package/src/internal-utils/values.ts +1 -55
  42. package/src/operations/behavior.operation.block.set.ts +18 -36
  43. package/src/operations/behavior.operation.block.unset.ts +8 -2
  44. package/src/operations/behavior.operation.insert.block.ts +4 -1
  45. package/src/operations/behavior.operation.insert.child.ts +95 -0
  46. package/src/operations/behavior.operations.ts +140 -128
  47. package/src/selectors/selector.get-mark-state.ts +19 -5
  48. package/src/selectors/selector.get-trimmed-selection.test.ts +1 -0
  49. package/src/types/block-with-optional-key.ts +13 -1
  50. package/src/utils/util.merge-text-blocks.ts +1 -1
  51. package/src/utils/util.slice-blocks.ts +3 -3
  52. package/src/utils/util.slice-text-block.test.ts +54 -28
  53. package/src/editor/with-applying-behavior-operations.ts +0 -18
package/lib/index.js CHANGED
@@ -8,14 +8,14 @@ import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transform
8
8
  import { useSelected, useSlateSelector, useSlateStatic, useSlate, Editable, ReactEditor, withReact, Slate } from "slate-react";
9
9
  import debug$f from "debug";
10
10
  import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
11
- import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText } from "./_chunks-es/util.slice-blocks.js";
11
+ import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, parseSpan, parseInlineObject, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText } from "./_chunks-es/util.slice-blocks.js";
12
12
  import { getBlockEndPoint, isSelectionCollapsed, isEqualSelectionPoints, isEmptyTextBlock } from "./_chunks-es/util.is-selection-collapsed.js";
13
13
  import isEqual from "lodash/isEqual.js";
14
14
  import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
15
15
  import { defineSchema } from "@portabletext/schema";
16
16
  import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getSelectionStartPoint as getSelectionStartPoint$1, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.is-selection-expanded.js";
17
- import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getActiveAnnotationsMarks, getTrimmedSelection, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
18
- import { defineBehavior, forward, raise, effect, execute } from "./behaviors/index.js";
17
+ import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getTrimmedSelection, getActiveAnnotationsMarks, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
18
+ import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
19
19
  import uniq from "lodash/uniq.js";
20
20
  import { setup, fromCallback, assign, and, enqueueActions, emit, assertEvent, raise as raise$1, not, createActor } from "xstate";
21
21
  import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
@@ -185,7 +185,14 @@ function getFocusSpan({
185
185
  if (!editor.selection)
186
186
  return [void 0, void 0];
187
187
  try {
188
- const [node, path] = Editor.node(editor, editor.selection.focus.path);
188
+ const [focusBlock] = getFocusBlock({
189
+ editor
190
+ });
191
+ if (!focusBlock)
192
+ return [void 0, void 0];
193
+ if (!editor.isTextBlock(focusBlock))
194
+ return [void 0, void 0];
195
+ const [node, path] = Editor.node(editor, editor.selection.focus.path.slice(0, 2));
189
196
  if (editor.isTextSpan(node))
190
197
  return [node, path];
191
198
  } catch {
@@ -1111,6 +1118,11 @@ function getEditorSnapshot({
1111
1118
  editorActorSnapshot,
1112
1119
  slateEditorInstance
1113
1120
  }) {
1121
+ const selection = slateEditorInstance.selection ? slateRangeToSelection({
1122
+ schema: editorActorSnapshot.context.schema,
1123
+ editor: slateEditorInstance,
1124
+ range: slateEditorInstance.selection
1125
+ }) : null;
1114
1126
  return {
1115
1127
  blockIndexMap: slateEditorInstance.blockIndexMap,
1116
1128
  context: {
@@ -1120,7 +1132,7 @@ function getEditorSnapshot({
1120
1132
  "edit mode": "read only"
1121
1133
  }),
1122
1134
  schema: editorActorSnapshot.context.schema,
1123
- selection: editorActorSnapshot.context.selection,
1135
+ selection,
1124
1136
  value: slateEditorInstance.value
1125
1137
  },
1126
1138
  decoratorState: slateEditorInstance.decoratorState
@@ -1948,6 +1960,7 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
1948
1960
  },
1949
1961
  blocks: result_1.insert,
1950
1962
  options: {
1963
+ removeUnusedMarkDefs: !0,
1951
1964
  validateFields: !1
1952
1965
  }
1953
1966
  }),
@@ -2416,6 +2429,7 @@ const converterJson = {
2416
2429
  context: snapshot.context,
2417
2430
  block,
2418
2431
  options: {
2432
+ removeUnusedMarkDefs: !0,
2419
2433
  validateFields: !1
2420
2434
  }
2421
2435
  });
@@ -2478,6 +2492,7 @@ function createConverterTextHtml(legacySchema) {
2478
2492
  context: snapshot.context,
2479
2493
  block,
2480
2494
  options: {
2495
+ removeUnusedMarkDefs: !0,
2481
2496
  validateFields: !1
2482
2497
  }
2483
2498
  });
@@ -2525,6 +2540,7 @@ function createConverterTextPlain(legacySchema) {
2525
2540
  context: snapshot.context,
2526
2541
  block,
2527
2542
  options: {
2543
+ removeUnusedMarkDefs: !0,
2528
2544
  validateFields: !1
2529
2545
  }
2530
2546
  });
@@ -2630,46 +2646,6 @@ function createPlaceholderBlock(context) {
2630
2646
  }]
2631
2647
  };
2632
2648
  }
2633
- const insertTextOperationImplementation = ({
2634
- context,
2635
- operation
2636
- }) => {
2637
- const snapshot = {
2638
- blockIndexMap: operation.editor.blockIndexMap,
2639
- context: {
2640
- value: operation.editor.value,
2641
- selection: operation.editor.selection ? slateRangeToSelection({
2642
- schema: context.schema,
2643
- editor: operation.editor,
2644
- range: operation.editor.selection
2645
- }) : null,
2646
- schema: context.schema,
2647
- keyGenerator: context.keyGenerator,
2648
- converters: [],
2649
- readOnly: !1
2650
- },
2651
- decoratorState: operation.editor.decoratorState
2652
- }, markState = getMarkState(snapshot), activeDecorators = getActiveDecorators(snapshot), activeAnnotations = getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
2653
- editor: operation.editor
2654
- });
2655
- if (!focusSpan) {
2656
- Transforms.insertText(operation.editor, operation.text);
2657
- return;
2658
- }
2659
- if (markState && markState.state === "unchanged") {
2660
- const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
2661
- if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
2662
- Transforms.insertText(operation.editor, operation.text);
2663
- return;
2664
- }
2665
- }
2666
- Transforms.insertNodes(operation.editor, {
2667
- _type: focusSpan._type,
2668
- _key: context.keyGenerator(),
2669
- text: operation.text,
2670
- marks: [...activeDecorators, ...activeAnnotations]
2671
- }), EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
2672
- };
2673
2649
  function getPreviousSpan({
2674
2650
  editor,
2675
2651
  blockPath,
@@ -4096,55 +4072,35 @@ const addAnnotationOperationImplementation = ({
4096
4072
  context,
4097
4073
  operation
4098
4074
  }) => {
4099
- const location = toSlateRange({
4100
- context: {
4101
- schema: context.schema,
4102
- value: operation.editor.value,
4103
- selection: {
4104
- anchor: {
4105
- path: operation.at,
4106
- offset: 0
4107
- },
4108
- focus: {
4109
- path: operation.at,
4110
- offset: 0
4111
- }
4112
- }
4113
- },
4114
- blockIndexMap: operation.editor.blockIndexMap
4115
- });
4116
- if (!location)
4117
- throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
4118
- const block = Editor.node(operation.editor, location, {
4119
- depth: 1
4120
- })?.[0];
4075
+ const blockIndex = operation.editor.blockIndexMap.get(operation.at[0]._key);
4076
+ if (blockIndex === void 0)
4077
+ throw new Error(`Unable to find block index for block at ${JSON.stringify(operation.at)}`);
4078
+ const block = operation.editor.value.at(blockIndex);
4121
4079
  if (!block)
4122
4080
  throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
4123
- const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
4124
- if (!parsedBlock)
4125
- throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
4126
4081
  const {
4127
4082
  _type,
4128
4083
  ...filteredProps
4129
- } = operation.props, updatedBlock = parseBlock({
4084
+ } = operation.props, updatedBlock = {
4085
+ ...block,
4086
+ ...filteredProps
4087
+ }, parsedBlock = parseBlock({
4130
4088
  context,
4131
- block: {
4132
- ...parsedBlock,
4133
- ...filteredProps
4134
- },
4089
+ block: updatedBlock,
4135
4090
  options: {
4091
+ removeUnusedMarkDefs: !1,
4136
4092
  validateFields: !0
4137
4093
  }
4138
4094
  });
4139
- if (!updatedBlock)
4095
+ if (!parsedBlock)
4140
4096
  throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
4141
- const slateBlock = toSlateValue([updatedBlock], {
4097
+ const slateBlock = toSlateValue([parsedBlock], {
4142
4098
  schemaTypes: context.schema
4143
4099
  })?.at(0);
4144
4100
  if (!slateBlock)
4145
4101
  throw new Error("Unable to convert block to Slate value");
4146
4102
  Transforms.setNodes(operation.editor, slateBlock, {
4147
- at: location
4103
+ at: [blockIndex]
4148
4104
  });
4149
4105
  }, blockUnsetOperationImplementation = ({
4150
4106
  context,
@@ -4182,6 +4138,7 @@ const addAnnotationOperationImplementation = ({
4182
4138
  context,
4183
4139
  block: omit(parsedBlock, propsToRemove),
4184
4140
  options: {
4141
+ removeUnusedMarkDefs: !0,
4185
4142
  validateFields: !0
4186
4143
  }
4187
4144
  });
@@ -4199,6 +4156,7 @@ const addAnnotationOperationImplementation = ({
4199
4156
  context,
4200
4157
  block: omit(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
4201
4158
  options: {
4159
+ removeUnusedMarkDefs: !0,
4202
4160
  validateFields: !0
4203
4161
  }
4204
4162
  });
@@ -4587,6 +4545,7 @@ const insertBlockOperationImplementation = ({
4587
4545
  block: operation.block,
4588
4546
  context,
4589
4547
  options: {
4548
+ removeUnusedMarkDefs: !0,
4590
4549
  validateFields: !0
4591
4550
  }
4592
4551
  });
@@ -4797,7 +4756,115 @@ function insertBlock({
4797
4756
  }
4798
4757
  }
4799
4758
  }
4800
- const moveBackwardOperationImplementation = ({
4759
+ const insertChildOperationImplementation = ({
4760
+ context,
4761
+ operation
4762
+ }) => {
4763
+ const focus = operation.editor.selection?.focus, focusBlockIndex = focus?.path.at(0), focusChildIndex = focus?.path.at(1);
4764
+ if (focusBlockIndex === void 0 || focusChildIndex === void 0)
4765
+ throw new Error("Unable to insert child without a focus");
4766
+ const [focusBlock, focusBlockPath] = getFocusBlock({
4767
+ editor: operation.editor
4768
+ });
4769
+ if (!focus || !focusBlock || !focusBlockPath)
4770
+ throw new Error("Unable to insert child without a focus block");
4771
+ if (!isTextBlock(context, focusBlock))
4772
+ throw new Error("Unable to insert child into a non-text block");
4773
+ const markDefs = focusBlock.markDefs ?? [], markDefKeyMap = /* @__PURE__ */ new Map();
4774
+ for (const markDef of markDefs)
4775
+ markDefKeyMap.set(markDef._key, markDef._key);
4776
+ const span = parseSpan({
4777
+ span: operation.child,
4778
+ context,
4779
+ markDefKeyMap,
4780
+ options: {
4781
+ validateFields: !0
4782
+ }
4783
+ });
4784
+ if (span) {
4785
+ const [focusSpan] = getFocusSpan({
4786
+ editor: operation.editor
4787
+ });
4788
+ focusSpan ? Transforms.insertNodes(operation.editor, span, {
4789
+ at: focus,
4790
+ select: !0
4791
+ }) : Transforms.insertNodes(operation.editor, span, {
4792
+ at: [focusBlockIndex, focusChildIndex + 1],
4793
+ select: !0
4794
+ });
4795
+ return;
4796
+ }
4797
+ const inlineObject = parseInlineObject({
4798
+ inlineObject: operation.child,
4799
+ context,
4800
+ options: {
4801
+ validateFields: !0
4802
+ }
4803
+ });
4804
+ if (inlineObject) {
4805
+ const {
4806
+ _key,
4807
+ _type,
4808
+ ...rest
4809
+ } = inlineObject;
4810
+ Transforms.insertNodes(operation.editor, {
4811
+ _key,
4812
+ _type,
4813
+ children: [{
4814
+ _key: VOID_CHILD_KEY,
4815
+ _type: "span",
4816
+ text: "",
4817
+ marks: []
4818
+ }],
4819
+ value: rest,
4820
+ __inline: !0
4821
+ }, {
4822
+ at: [focusBlockIndex, focusChildIndex + 1],
4823
+ select: !0
4824
+ });
4825
+ return;
4826
+ }
4827
+ throw new Error("Unable to parse child");
4828
+ }, insertTextOperationImplementation = ({
4829
+ context,
4830
+ operation
4831
+ }) => {
4832
+ const snapshot = {
4833
+ blockIndexMap: operation.editor.blockIndexMap,
4834
+ context: {
4835
+ value: operation.editor.value,
4836
+ selection: operation.editor.selection ? slateRangeToSelection({
4837
+ schema: context.schema,
4838
+ editor: operation.editor,
4839
+ range: operation.editor.selection
4840
+ }) : null,
4841
+ schema: context.schema,
4842
+ keyGenerator: context.keyGenerator,
4843
+ converters: [],
4844
+ readOnly: !1
4845
+ },
4846
+ decoratorState: operation.editor.decoratorState
4847
+ }, markState = getMarkState(snapshot), activeDecorators = getActiveDecorators(snapshot), activeAnnotations = getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
4848
+ editor: operation.editor
4849
+ });
4850
+ if (!focusSpan) {
4851
+ Transforms.insertText(operation.editor, operation.text);
4852
+ return;
4853
+ }
4854
+ if (markState && markState.state === "unchanged") {
4855
+ const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
4856
+ if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
4857
+ Transforms.insertText(operation.editor, operation.text);
4858
+ return;
4859
+ }
4860
+ }
4861
+ Transforms.insertNodes(operation.editor, {
4862
+ _type: focusSpan._type,
4863
+ _key: context.keyGenerator(),
4864
+ text: operation.text,
4865
+ marks: [...activeDecorators, ...activeAnnotations]
4866
+ }), EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
4867
+ }, moveBackwardOperationImplementation = ({
4801
4868
  operation
4802
4869
  }) => {
4803
4870
  Transforms.move(operation.editor, {
@@ -4862,6 +4929,7 @@ const moveBackwardOperationImplementation = ({
4862
4929
  "history.redo": historyRedoOperationImplementation,
4863
4930
  "history.undo": historyUndoOperationImplementation,
4864
4931
  "insert.block": insertBlockOperationImplementation,
4932
+ "insert.child": insertChildOperationImplementation,
4865
4933
  "insert.text": insertTextOperationImplementation,
4866
4934
  "move.backward": moveBackwardOperationImplementation,
4867
4935
  "move.block": moveBlockOperationImplementation,
@@ -4872,141 +4940,148 @@ function performOperation({
4872
4940
  context,
4873
4941
  operation
4874
4942
  }) {
4875
- try {
4876
- switch (operation.type) {
4877
- case "annotation.add": {
4878
- behaviorOperationImplementations["annotation.add"]({
4879
- context,
4880
- operation
4881
- });
4882
- break;
4883
- }
4884
- case "annotation.remove": {
4885
- behaviorOperationImplementations["annotation.remove"]({
4886
- context,
4887
- operation
4888
- });
4889
- break;
4890
- }
4891
- case "block.set": {
4892
- behaviorOperationImplementations["block.set"]({
4893
- context,
4894
- operation
4895
- });
4896
- break;
4897
- }
4898
- case "block.unset": {
4899
- behaviorOperationImplementations["block.unset"]({
4900
- context,
4901
- operation
4902
- });
4903
- break;
4904
- }
4905
- case "child.set": {
4906
- behaviorOperationImplementations["child.set"]({
4907
- context,
4908
- operation
4909
- });
4910
- break;
4911
- }
4912
- case "child.unset": {
4913
- behaviorOperationImplementations["child.unset"]({
4914
- context,
4915
- operation
4916
- });
4917
- break;
4918
- }
4919
- case "decorator.add": {
4920
- behaviorOperationImplementations["decorator.add"]({
4921
- context,
4922
- operation
4923
- });
4924
- break;
4925
- }
4926
- case "decorator.remove": {
4927
- behaviorOperationImplementations["decorator.remove"]({
4928
- context,
4929
- operation
4930
- });
4931
- break;
4932
- }
4933
- case "delete": {
4934
- behaviorOperationImplementations.delete({
4935
- context,
4936
- operation
4937
- });
4938
- break;
4939
- }
4940
- case "history.redo": {
4941
- behaviorOperationImplementations["history.redo"]({
4942
- context,
4943
- operation
4944
- });
4945
- break;
4946
- }
4947
- case "history.undo": {
4948
- behaviorOperationImplementations["history.undo"]({
4949
- context,
4950
- operation
4951
- });
4952
- break;
4953
- }
4954
- case "insert.block": {
4955
- behaviorOperationImplementations["insert.block"]({
4956
- context,
4957
- operation
4958
- });
4959
- break;
4960
- }
4961
- case "insert.text": {
4962
- behaviorOperationImplementations["insert.text"]({
4963
- context,
4964
- operation
4965
- });
4966
- break;
4967
- }
4968
- case "move.backward": {
4969
- behaviorOperationImplementations["move.backward"]({
4970
- context,
4971
- operation
4972
- });
4973
- break;
4974
- }
4975
- case "move.block": {
4976
- behaviorOperationImplementations["move.block"]({
4977
- context,
4978
- operation
4979
- });
4980
- break;
4981
- }
4982
- case "move.forward": {
4983
- behaviorOperationImplementations["move.forward"]({
4984
- context,
4985
- operation
4986
- });
4987
- break;
4988
- }
4989
- default: {
4990
- behaviorOperationImplementations.select({
4991
- context,
4992
- operation
4993
- });
4994
- break;
4943
+ Editor.withoutNormalizing(operation.editor, () => {
4944
+ try {
4945
+ switch (operation.type) {
4946
+ case "annotation.add": {
4947
+ behaviorOperationImplementations["annotation.add"]({
4948
+ context,
4949
+ operation
4950
+ });
4951
+ break;
4952
+ }
4953
+ case "annotation.remove": {
4954
+ behaviorOperationImplementations["annotation.remove"]({
4955
+ context,
4956
+ operation
4957
+ });
4958
+ break;
4959
+ }
4960
+ case "block.set": {
4961
+ behaviorOperationImplementations["block.set"]({
4962
+ context,
4963
+ operation
4964
+ });
4965
+ break;
4966
+ }
4967
+ case "block.unset": {
4968
+ behaviorOperationImplementations["block.unset"]({
4969
+ context,
4970
+ operation
4971
+ });
4972
+ break;
4973
+ }
4974
+ case "child.set": {
4975
+ behaviorOperationImplementations["child.set"]({
4976
+ context,
4977
+ operation
4978
+ });
4979
+ break;
4980
+ }
4981
+ case "child.unset": {
4982
+ behaviorOperationImplementations["child.unset"]({
4983
+ context,
4984
+ operation
4985
+ });
4986
+ break;
4987
+ }
4988
+ case "decorator.add": {
4989
+ behaviorOperationImplementations["decorator.add"]({
4990
+ context,
4991
+ operation
4992
+ });
4993
+ break;
4994
+ }
4995
+ case "decorator.remove": {
4996
+ behaviorOperationImplementations["decorator.remove"]({
4997
+ context,
4998
+ operation
4999
+ });
5000
+ break;
5001
+ }
5002
+ case "delete": {
5003
+ behaviorOperationImplementations.delete({
5004
+ context,
5005
+ operation
5006
+ });
5007
+ break;
5008
+ }
5009
+ case "history.redo": {
5010
+ behaviorOperationImplementations["history.redo"]({
5011
+ context,
5012
+ operation
5013
+ });
5014
+ break;
5015
+ }
5016
+ case "history.undo": {
5017
+ behaviorOperationImplementations["history.undo"]({
5018
+ context,
5019
+ operation
5020
+ });
5021
+ break;
5022
+ }
5023
+ case "insert.block": {
5024
+ behaviorOperationImplementations["insert.block"]({
5025
+ context,
5026
+ operation
5027
+ });
5028
+ break;
5029
+ }
5030
+ case "insert.child": {
5031
+ behaviorOperationImplementations["insert.child"]({
5032
+ context,
5033
+ operation
5034
+ });
5035
+ break;
5036
+ }
5037
+ case "insert.text": {
5038
+ behaviorOperationImplementations["insert.text"]({
5039
+ context,
5040
+ operation
5041
+ });
5042
+ break;
5043
+ }
5044
+ case "move.backward": {
5045
+ behaviorOperationImplementations["move.backward"]({
5046
+ context,
5047
+ operation
5048
+ });
5049
+ break;
5050
+ }
5051
+ case "move.block": {
5052
+ behaviorOperationImplementations["move.block"]({
5053
+ context,
5054
+ operation
5055
+ });
5056
+ break;
5057
+ }
5058
+ case "move.forward": {
5059
+ behaviorOperationImplementations["move.forward"]({
5060
+ context,
5061
+ operation
5062
+ });
5063
+ break;
5064
+ }
5065
+ default: {
5066
+ behaviorOperationImplementations.select({
5067
+ context,
5068
+ operation
5069
+ });
5070
+ break;
5071
+ }
4995
5072
  }
5073
+ } catch (error) {
5074
+ console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
4996
5075
  }
4997
- } catch (error) {
4998
- console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
4999
- }
5000
- }
5001
- const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
5002
- function withApplyingBehaviorOperations(editor, fn) {
5003
- CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator()), Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
5076
+ });
5004
5077
  }
5005
- function getCurrentOperationId(editor) {
5006
- return CURRENT_OPERATION_ID.get(editor);
5078
+ const IS_PERFORMING_OPERATION = /* @__PURE__ */ new WeakMap();
5079
+ function withPerformingBehaviorOperation(editor, fn) {
5080
+ const prev = IS_PERFORMING_OPERATION.get(editor);
5081
+ IS_PERFORMING_OPERATION.set(editor, !0), fn(), IS_PERFORMING_OPERATION.set(editor, prev);
5007
5082
  }
5008
- function isApplyingBehaviorOperations(editor) {
5009
- return getCurrentOperationId(editor) !== void 0;
5083
+ function isPerformingBehaviorOperation(editor) {
5084
+ return IS_PERFORMING_OPERATION.get(editor) ?? !1;
5010
5085
  }
5011
5086
  function createWithEventListeners(editorActor) {
5012
5087
  return function(editor) {
@@ -5017,7 +5092,7 @@ function createWithEventListeners(editorActor) {
5017
5092
  select
5018
5093
  } = editor;
5019
5094
  return editor.delete = (options) => {
5020
- if (isApplyingBehaviorOperations(editor)) {
5095
+ if (isPerformingBehaviorOperation(editor)) {
5021
5096
  editorDelete(options);
5022
5097
  return;
5023
5098
  }
@@ -5046,7 +5121,7 @@ function createWithEventListeners(editorActor) {
5046
5121
  editor
5047
5122
  });
5048
5123
  }, editor.deleteBackward = (unit) => {
5049
- if (isApplyingBehaviorOperations(editor)) {
5124
+ if (isPerformingBehaviorOperation(editor)) {
5050
5125
  console.error("Unexpected call to .deleteBackward(...)");
5051
5126
  return;
5052
5127
  }
@@ -5059,7 +5134,7 @@ function createWithEventListeners(editorActor) {
5059
5134
  editor
5060
5135
  });
5061
5136
  }, editor.deleteForward = (unit) => {
5062
- if (isApplyingBehaviorOperations(editor)) {
5137
+ if (isPerformingBehaviorOperation(editor)) {
5063
5138
  console.error("Unexpected call to .deleteForward(...)");
5064
5139
  return;
5065
5140
  }
@@ -5072,7 +5147,7 @@ function createWithEventListeners(editorActor) {
5072
5147
  editor
5073
5148
  });
5074
5149
  }, editor.insertBreak = () => {
5075
- if (isApplyingBehaviorOperations(editor)) {
5150
+ if (isPerformingBehaviorOperation(editor)) {
5076
5151
  console.error("Unexpected call to .insertBreak(...)");
5077
5152
  return;
5078
5153
  }
@@ -5084,7 +5159,7 @@ function createWithEventListeners(editorActor) {
5084
5159
  editor
5085
5160
  });
5086
5161
  }, editor.insertData = (dataTransfer) => {
5087
- if (isApplyingBehaviorOperations(editor)) {
5162
+ if (isPerformingBehaviorOperation(editor)) {
5088
5163
  console.error("Unexpected call to .insertData(...)");
5089
5164
  return;
5090
5165
  }
@@ -5099,13 +5174,14 @@ function createWithEventListeners(editorActor) {
5099
5174
  editor
5100
5175
  });
5101
5176
  }, editor.insertSoftBreak = () => {
5102
- if (isApplyingBehaviorOperations(editor)) {
5103
- insertTextOperationImplementation({
5177
+ if (isPerformingBehaviorOperation(editor)) {
5178
+ performOperation({
5104
5179
  context: {
5105
5180
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
5106
5181
  schema: editorActor.getSnapshot().context.schema
5107
5182
  },
5108
5183
  operation: {
5184
+ type: "insert.text",
5109
5185
  text: `
5110
5186
  `,
5111
5187
  editor
@@ -5121,13 +5197,14 @@ function createWithEventListeners(editorActor) {
5121
5197
  editor
5122
5198
  });
5123
5199
  }, editor.insertText = (text) => {
5124
- if (isApplyingBehaviorOperations(editor)) {
5125
- insertTextOperationImplementation({
5200
+ if (isPerformingBehaviorOperation(editor)) {
5201
+ performOperation({
5126
5202
  context: {
5127
5203
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
5128
5204
  schema: editorActor.getSnapshot().context.schema
5129
5205
  },
5130
5206
  operation: {
5207
+ type: "insert.text",
5131
5208
  text,
5132
5209
  editor
5133
5210
  }
@@ -5143,7 +5220,7 @@ function createWithEventListeners(editorActor) {
5143
5220
  editor
5144
5221
  });
5145
5222
  }, editor.redo = () => {
5146
- if (isApplyingBehaviorOperations(editor)) {
5223
+ if (isPerformingBehaviorOperation(editor)) {
5147
5224
  performOperation({
5148
5225
  context: {
5149
5226
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
@@ -5164,7 +5241,7 @@ function createWithEventListeners(editorActor) {
5164
5241
  editor
5165
5242
  });
5166
5243
  }, editor.select = (location) => {
5167
- if (isApplyingBehaviorOperations(editor)) {
5244
+ if (isPerformingBehaviorOperation(editor)) {
5168
5245
  select(location);
5169
5246
  return;
5170
5247
  }
@@ -5184,7 +5261,7 @@ function createWithEventListeners(editorActor) {
5184
5261
  }, editor.setFragmentData = () => {
5185
5262
  console.error("Unexpected call to .setFragmentData(...)");
5186
5263
  }, editor.undo = () => {
5187
- if (isApplyingBehaviorOperations(editor)) {
5264
+ if (isPerformingBehaviorOperation(editor)) {
5188
5265
  performOperation({
5189
5266
  context: {
5190
5267
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
@@ -7734,7 +7811,11 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
7734
7811
  }, coreBehaviorsConfig = [...coreAnnotationBehaviors, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.deletingListFromStart, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
7735
7812
  behavior,
7736
7813
  priority: corePriority
7737
- })), abstractAnnotationBehaviors = [defineBehavior({
7814
+ }));
7815
+ function withoutNormalizingConditional(editor, predicate, fn) {
7816
+ predicate() ? Editor.withoutNormalizing(editor, fn) : fn();
7817
+ }
7818
+ const abstractAnnotationBehaviors = [defineBehavior({
7738
7819
  on: "annotation.set",
7739
7820
  guard: ({
7740
7821
  snapshot,
@@ -8516,21 +8597,63 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
8516
8597
  type: "split"
8517
8598
  })]]
8518
8599
  }), defineBehavior({
8519
- on: "insert.inline object",
8600
+ on: "insert.child",
8601
+ guard: ({
8602
+ snapshot
8603
+ }) => {
8604
+ const lastBlock = getLastBlock$1(snapshot);
8605
+ return !lastBlock || snapshot.context.selection ? !1 : {
8606
+ lastBlockEndPoint: getBlockEndPoint({
8607
+ context: snapshot.context,
8608
+ block: lastBlock
8609
+ })
8610
+ };
8611
+ },
8612
+ actions: [({
8613
+ event
8614
+ }, {
8615
+ lastBlockEndPoint
8616
+ }) => [raise({
8617
+ type: "select",
8618
+ at: {
8619
+ anchor: lastBlockEndPoint,
8620
+ focus: lastBlockEndPoint
8621
+ }
8622
+ }), raise(event)]]
8623
+ }), defineBehavior({
8624
+ on: "insert.child",
8625
+ guard: ({
8626
+ snapshot
8627
+ }) => {
8628
+ const focusTextBlock = getFocusTextBlock(snapshot);
8629
+ return snapshot.context.selection && !focusTextBlock;
8630
+ },
8520
8631
  actions: [({
8521
8632
  snapshot,
8522
8633
  event
8523
- }) => [execute({
8634
+ }) => [raise({
8524
8635
  type: "insert.block",
8525
8636
  block: {
8526
8637
  _type: snapshot.context.schema.block.name,
8527
8638
  children: [{
8528
- _type: event.inlineObject.name,
8529
- ...event.inlineObject.value
8639
+ _type: snapshot.context.schema.span.name,
8640
+ text: "",
8641
+ marks: []
8530
8642
  }]
8531
8643
  },
8532
8644
  placement: "auto",
8533
8645
  select: "end"
8646
+ }), raise(event)]]
8647
+ }), defineBehavior({
8648
+ on: "insert.inline object",
8649
+ actions: [({
8650
+ event
8651
+ }) => [raise({
8652
+ type: "insert.child",
8653
+ child: {
8654
+ _type: event.inlineObject.name,
8655
+ ...event.inlineObject.value
8656
+ }
8534
8657
  })]]
8535
8658
  }), defineBehavior({
8536
8659
  on: "insert.soft break",
@@ -8542,33 +8665,59 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
8542
8665
  }), defineBehavior({
8543
8666
  on: "insert.span",
8544
8667
  guard: ({
8545
- snapshot,
8546
- event
8547
- }) => ({
8548
- markDefs: event.annotations?.map((annotation) => ({
8549
- _type: annotation.name,
8550
- _key: snapshot.context.keyGenerator(),
8551
- ...annotation.value
8552
- })) ?? []
8553
- }),
8668
+ snapshot
8669
+ }) => !getFocusTextBlock(snapshot),
8554
8670
  actions: [({
8555
8671
  snapshot,
8556
8672
  event
8557
- }, {
8558
- markDefs
8559
- }) => [execute({
8673
+ }) => [raise({
8560
8674
  type: "insert.block",
8561
8675
  block: {
8562
8676
  _type: snapshot.context.schema.block.name,
8563
8677
  children: [{
8564
8678
  _type: snapshot.context.schema.span.name,
8565
- text: event.text,
8566
- marks: [...event.decorators ?? [], ...markDefs.map((markDef) => markDef._key)]
8567
- }],
8568
- markDefs
8679
+ text: "",
8680
+ marks: []
8681
+ }]
8569
8682
  },
8570
8683
  placement: "auto",
8571
8684
  select: "end"
8685
+ }), raise(event)]]
8686
+ }), defineBehavior({
8687
+ on: "insert.span",
8688
+ guard: ({
8689
+ snapshot,
8690
+ event
8691
+ }) => {
8692
+ const focusTextBlock = getFocusTextBlock(snapshot);
8693
+ return {
8694
+ markDefs: event.annotations?.map((annotation) => ({
8695
+ _type: annotation.name,
8696
+ _key: snapshot.context.keyGenerator(),
8697
+ ...annotation.value
8698
+ })) ?? [],
8699
+ focusTextBlock
8700
+ };
8701
+ },
8702
+ actions: [({
8703
+ snapshot,
8704
+ event
8705
+ }, {
8706
+ markDefs,
8707
+ focusTextBlock
8708
+ }) => [...focusTextBlock ? [raise({
8709
+ type: "block.set",
8710
+ at: focusTextBlock.path,
8711
+ props: {
8712
+ markDefs: [...focusTextBlock.node.markDefs ?? [], ...markDefs]
8713
+ }
8714
+ })] : [], raise({
8715
+ type: "insert.child",
8716
+ child: {
8717
+ _type: snapshot.context.schema.span.name,
8718
+ text: event.text,
8719
+ marks: [...event.decorators ?? [], ...markDefs.map((markDef) => markDef._key)]
8720
+ }
8572
8721
  })]]
8573
8722
  })], abstractKeyboardBehaviors = [
8574
8723
  /**
@@ -9046,6 +9195,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
9046
9195
  }),
9047
9196
  context: snapshot.context,
9048
9197
  options: {
9198
+ removeUnusedMarkDefs: !0,
9049
9199
  validateFields: !1
9050
9200
  }
9051
9201
  });
@@ -9253,7 +9403,7 @@ function performEvent({
9253
9403
  return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
9254
9404
  });
9255
9405
  if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
9256
- nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withApplyingBehaviorOperations(editor, () => {
9406
+ nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
9257
9407
  debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
9258
9408
  context: {
9259
9409
  keyGenerator,
@@ -9295,67 +9445,13 @@ function performEvent({
9295
9445
  } catch (error) {
9296
9446
  console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
9297
9447
  }
9298
- if (actions.length !== 0) {
9299
- if (nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward"), actions.some((action) => action.type === "execute")) {
9300
- createUndoStep(editor);
9301
- for (const action of actions) {
9302
- if (action.type === "effect") {
9303
- try {
9304
- action.effect({
9305
- send: sendBack
9306
- });
9307
- } catch (error) {
9308
- console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
9309
- }
9310
- continue;
9311
- }
9312
- if (action.type === "forward") {
9313
- const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9314
- performEvent({
9315
- mode: "forward",
9316
- behaviors,
9317
- remainingEventBehaviors: remainingEventBehaviors2,
9318
- event: action.event,
9319
- editor,
9320
- keyGenerator,
9321
- schema,
9322
- getSnapshot,
9323
- nativeEvent,
9324
- sendBack
9325
- });
9326
- continue;
9327
- }
9328
- if (action.type === "raise") {
9329
- performEvent({
9330
- mode: "raise",
9331
- behaviors,
9332
- remainingEventBehaviors: behaviors,
9333
- event: action.event,
9334
- editor,
9335
- keyGenerator,
9336
- schema,
9337
- getSnapshot,
9338
- nativeEvent,
9339
- sendBack
9340
- });
9341
- continue;
9342
- }
9343
- performEvent({
9344
- mode: "execute",
9345
- behaviors,
9346
- remainingEventBehaviors: [],
9347
- event: action.event,
9348
- editor,
9349
- keyGenerator,
9350
- schema,
9351
- getSnapshot,
9352
- nativeEvent: void 0,
9353
- sendBack
9354
- });
9355
- }
9356
- clearUndoStep(editor);
9357
- continue;
9358
- }
9448
+ if (actions.length === 0)
9449
+ continue;
9450
+ nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
9451
+ let undoStepCreated = !1;
9452
+ actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
9453
+ const actionTypes = actions.map((action) => action.type), uniqueActionTypes = new Set(actionTypes), raiseGroup = actionTypes.length > 1 && uniqueActionTypes.size === 1 && uniqueActionTypes.has("raise"), executeGroup = actionTypes.length > 1 && uniqueActionTypes.size === 1 && uniqueActionTypes.has("execute");
9454
+ withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
9359
9455
  for (const action of actions) {
9360
9456
  if (action.type === "effect") {
9361
9457
  try {
@@ -9370,7 +9466,7 @@ function performEvent({
9370
9466
  if (action.type === "forward") {
9371
9467
  const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
9372
9468
  performEvent({
9373
- mode: "forward",
9469
+ mode: mode === "execute" ? "execute" : "forward",
9374
9470
  behaviors,
9375
9471
  remainingEventBehaviors: remainingEventBehaviors2,
9376
9472
  event: action.event,
@@ -9385,7 +9481,7 @@ function performEvent({
9385
9481
  }
9386
9482
  if (action.type === "raise") {
9387
9483
  performEvent({
9388
- mode: "raise",
9484
+ mode: mode === "execute" ? "execute" : "raise",
9389
9485
  behaviors,
9390
9486
  remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
9391
9487
  event: action.event,
@@ -9398,14 +9494,25 @@ function performEvent({
9398
9494
  });
9399
9495
  continue;
9400
9496
  }
9401
- action.type === "execute" && console.error("Unexpected action type: `execute`");
9497
+ performEvent({
9498
+ mode: "execute",
9499
+ behaviors,
9500
+ remainingEventBehaviors: [],
9501
+ event: action.event,
9502
+ editor,
9503
+ keyGenerator,
9504
+ schema,
9505
+ getSnapshot,
9506
+ nativeEvent: void 0,
9507
+ sendBack
9508
+ });
9402
9509
  }
9403
- }
9510
+ }), undoStepCreated && clearUndoStep(editor);
9404
9511
  }
9405
9512
  break;
9406
9513
  }
9407
9514
  }
9408
- !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withApplyingBehaviorOperations(editor, () => {
9515
+ !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
9409
9516
  debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
9410
9517
  context: {
9411
9518
  keyGenerator,
@@ -11345,7 +11452,8 @@ async function updateValue({
11345
11452
  slateEditor,
11346
11453
  value
11347
11454
  });
11348
- isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
11455
+ if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
11456
+ break;
11349
11457
  }
11350
11458
  resolve();
11351
11459
  })();
@@ -11374,7 +11482,9 @@ async function updateValue({
11374
11482
  slateEditor,
11375
11483
  value
11376
11484
  });
11377
- isChanged = blockChanged || isChanged, isValid = isValid && blockValid, index++;
11485
+ if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
11486
+ break;
11487
+ index++;
11378
11488
  }
11379
11489
  });
11380
11490
  });