@portabletext/editor 1.24.0 → 1.26.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 (89) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +283 -64
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +8 -8
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +412 -0
  6. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
  7. package/lib/_chunks-cjs/util.is-empty-text-block.cjs +2 -2
  8. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
  9. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +46 -0
  10. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -16
  12. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
  13. package/lib/_chunks-es/behavior.core.js +259 -40
  14. package/lib/_chunks-es/behavior.core.js.map +1 -1
  15. package/lib/_chunks-es/selector.get-text-before.js +2 -2
  16. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +414 -0
  17. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
  18. package/lib/_chunks-es/util.is-empty-text-block.js +1 -1
  19. package/lib/_chunks-es/util.is-equal-selection-points.js +47 -0
  20. package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -0
  21. package/lib/_chunks-es/util.reverse-selection.js +0 -16
  22. package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
  23. package/lib/behaviors/index.cjs +27 -27
  24. package/lib/behaviors/index.cjs.map +1 -1
  25. package/lib/behaviors/index.d.cts +2208 -171
  26. package/lib/behaviors/index.d.ts +2208 -171
  27. package/lib/behaviors/index.js +1 -1
  28. package/lib/index.cjs +306 -298
  29. package/lib/index.cjs.map +1 -1
  30. package/lib/index.d.cts +10499 -521
  31. package/lib/index.d.ts +10499 -521
  32. package/lib/index.js +302 -294
  33. package/lib/index.js.map +1 -1
  34. package/lib/selectors/index.cjs +26 -171
  35. package/lib/selectors/index.cjs.map +1 -1
  36. package/lib/selectors/index.d.cts +16 -0
  37. package/lib/selectors/index.d.ts +16 -0
  38. package/lib/selectors/index.js +5 -151
  39. package/lib/selectors/index.js.map +1 -1
  40. package/lib/utils/index.cjs +5 -3
  41. package/lib/utils/index.cjs.map +1 -1
  42. package/lib/utils/index.d.cts +19 -0
  43. package/lib/utils/index.d.ts +19 -0
  44. package/lib/utils/index.js +4 -2
  45. package/package.json +6 -6
  46. package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -3
  47. package/src/behavior-actions/behavior.action.block.set.ts +23 -0
  48. package/src/behavior-actions/behavior.action.block.unset.ts +21 -0
  49. package/src/behavior-actions/behavior.action.insert-break.ts +2 -69
  50. package/src/behavior-actions/behavior.action.insert.block.ts +29 -0
  51. package/src/behavior-actions/behavior.actions.ts +116 -96
  52. package/src/behaviors/behavior.core.annotations.ts +29 -0
  53. package/src/behaviors/behavior.core.block-objects.ts +13 -13
  54. package/src/behaviors/behavior.core.decorators.ts +19 -0
  55. package/src/behaviors/behavior.core.insert-break.ts +122 -0
  56. package/src/behaviors/behavior.core.lists.ts +57 -23
  57. package/src/behaviors/behavior.core.style.ts +19 -0
  58. package/src/behaviors/behavior.core.ts +18 -2
  59. package/src/behaviors/behavior.types.ts +103 -88
  60. package/src/converters/converter.json.ts +4 -4
  61. package/src/converters/converter.portable-text.deserialize.test.ts +1 -1
  62. package/src/converters/converter.portable-text.ts +4 -4
  63. package/src/converters/converter.text-html.deserialize.test.ts +1 -1
  64. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  65. package/src/converters/converter.text-html.ts +4 -4
  66. package/src/converters/converter.text-plain.test.ts +1 -1
  67. package/src/converters/converter.text-plain.ts +3 -3
  68. package/src/converters/{converter.ts → converter.types.ts} +6 -0
  69. package/src/editor/create-editor.ts +50 -7
  70. package/src/editor/editor-machine.ts +46 -3
  71. package/src/editor/editor-snapshot.ts +1 -1
  72. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +2 -2
  73. package/src/editor/plugins/create-with-event-listeners.ts +41 -106
  74. package/src/selectors/index.ts +2 -0
  75. package/src/selectors/selector.is-at-the-end-of-block.ts +22 -0
  76. package/src/selectors/selector.is-at-the-start-of-block.ts +25 -0
  77. package/src/selectors/selector.is-selection-collapsed.ts +6 -2
  78. package/src/utils/index.ts +2 -0
  79. package/src/utils/util.get-block-end-point.ts +34 -0
  80. package/src/utils/util.is-equal-selection-points.ts +13 -0
  81. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs +0 -231
  82. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +0 -1
  83. package/lib/_chunks-cjs/util.is-keyed-segment.cjs +0 -6
  84. package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +0 -1
  85. package/lib/_chunks-es/selector.is-selection-collapsed.js +0 -232
  86. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +0 -1
  87. package/lib/_chunks-es/util.is-keyed-segment.js +0 -7
  88. package/lib/_chunks-es/util.is-keyed-segment.js.map +0 -1
  89. /package/src/converters/{converters.ts → converters.core.ts} +0 -0
package/lib/index.js CHANGED
@@ -23,7 +23,7 @@ import { toHTML } from "@portabletext/to-html";
23
23
  import get from "lodash/get.js";
24
24
  import isUndefined from "lodash/isUndefined.js";
25
25
  import omitBy from "lodash/omitBy.js";
26
- import { createGuards } from "./_chunks-es/selector.is-selection-collapsed.js";
26
+ import { createGuards } from "./_chunks-es/selector.is-at-the-start-of-block.js";
27
27
  import { blockOffsetToSpanSelectionPoint } from "./_chunks-es/util.is-empty-text-block.js";
28
28
  import { coreBehaviors, isCustomBehaviorEvent, isHotkey } from "./_chunks-es/behavior.core.js";
29
29
  import getRandomValues from "get-random-values-esm";
@@ -2523,6 +2523,7 @@ function _temp(s) {
2523
2523
  }
2524
2524
  Synchronizer.displayName = "Synchronizer";
2525
2525
  const converterJson = {
2526
+ mimeType: "application/json",
2526
2527
  serialize: ({
2527
2528
  context,
2528
2529
  event
@@ -2558,8 +2559,7 @@ const converterJson = {
2558
2559
  mimeType: "application/json",
2559
2560
  reason: "No application/x-portable-text Converter found"
2560
2561
  };
2561
- },
2562
- mimeType: "application/json"
2562
+ }
2563
2563
  };
2564
2564
  function isTypedObject(object) {
2565
2565
  return isRecord(object) && typeof object._type == "string";
@@ -2621,6 +2621,7 @@ function parseBlock({
2621
2621
  return context.schema.lists.find((list) => list.value === block.listItem) || (delete parsedBlock.listItem, delete parsedBlock.level), parsedBlock;
2622
2622
  }
2623
2623
  const converterPortableText = {
2624
+ mimeType: "application/x-portable-text",
2624
2625
  serialize: ({
2625
2626
  context,
2626
2627
  event
@@ -2670,9 +2671,9 @@ const converterPortableText = {
2670
2671
  data: parsedBlocks,
2671
2672
  mimeType: "application/x-portable-text"
2672
2673
  };
2673
- },
2674
- mimeType: "application/x-portable-text"
2674
+ }
2675
2675
  }, converterTextHtml = {
2676
+ mimeType: "text/html",
2676
2677
  serialize: ({
2677
2678
  context,
2678
2679
  event
@@ -2717,8 +2718,7 @@ const converterPortableText = {
2717
2718
  unstable_whitespaceOnPasteMode: context.schema.block.options.unstable_whitespaceOnPasteMode
2718
2719
  }),
2719
2720
  mimeType: "text/html"
2720
- }),
2721
- mimeType: "text/html"
2721
+ })
2722
2722
  }, converterTextPlain = {
2723
2723
  mimeType: "text/plain",
2724
2724
  serialize: ({
@@ -3003,123 +3003,57 @@ function createWithEventListeners(editorActor, subscriptions) {
3003
3003
  subscriptions.push(() => {
3004
3004
  const subscription = editorActor.on("*", (event) => {
3005
3005
  switch (event.type) {
3006
- case "annotation.add": {
3007
- editorActor.send({
3008
- type: "behavior event",
3009
- behaviorEvent: {
3010
- type: "annotation.add",
3011
- annotation: event.annotation
3012
- },
3013
- editor
3014
- });
3015
- break;
3016
- }
3017
- case "annotation.remove": {
3018
- editorActor.send({
3019
- type: "behavior event",
3020
- behaviorEvent: {
3021
- type: "annotation.remove",
3022
- annotation: event.annotation
3023
- },
3024
- editor
3025
- });
3026
- break;
3027
- }
3028
- case "blur": {
3029
- editorActor.send({
3030
- type: "behavior event",
3031
- behaviorEvent: {
3032
- type: "blur"
3033
- },
3034
- editor
3035
- });
3036
- break;
3037
- }
3038
- case "custom.*": {
3006
+ case "custom.*":
3039
3007
  editorActor.send({
3040
3008
  type: "custom behavior event",
3041
3009
  behaviorEvent: event.event,
3042
3010
  editor
3043
3011
  });
3044
3012
  break;
3045
- }
3046
- case "decorator.toggle": {
3047
- editorActor.send({
3048
- type: "behavior event",
3049
- behaviorEvent: {
3050
- type: "decorator.toggle",
3051
- decorator: event.decorator
3052
- },
3053
- editor
3054
- });
3055
- break;
3056
- }
3057
- case "focus": {
3058
- editorActor.send({
3059
- type: "behavior event",
3060
- behaviorEvent: {
3061
- type: "focus"
3062
- },
3063
- editor
3064
- });
3065
- break;
3066
- }
3067
- case "insert.block object": {
3068
- editorActor.send({
3069
- type: "behavior event",
3070
- behaviorEvent: {
3071
- type: "insert.block object",
3072
- placement: event.placement,
3073
- blockObject: event.blockObject
3074
- },
3075
- editor
3076
- });
3077
- break;
3078
- }
3079
- case "insert.inline object": {
3080
- editorActor.send({
3081
- type: "behavior event",
3082
- behaviorEvent: {
3083
- type: "insert.inline object",
3084
- inlineObject: event.inlineObject
3085
- },
3086
- editor
3087
- });
3088
- break;
3089
- }
3090
- case "list item.toggle": {
3013
+ case "annotation.add":
3014
+ case "annotation.remove":
3015
+ case "annotation.toggle":
3016
+ case "block.set":
3017
+ case "block.unset":
3018
+ case "blur":
3019
+ case "data transfer.set":
3020
+ case "decorator.add":
3021
+ case "decorator.remove":
3022
+ case "decorator.toggle":
3023
+ case "delete.backward":
3024
+ case "delete.block":
3025
+ case "delete.forward":
3026
+ case "delete.text":
3027
+ case "deserialization.failure":
3028
+ case "deserialization.success":
3029
+ case "focus":
3030
+ case "insert.block":
3031
+ case "insert.block object":
3032
+ case "insert.inline object":
3033
+ case "insert.span":
3034
+ case "insert.text block":
3035
+ case "list item.add":
3036
+ case "list item.remove":
3037
+ case "list item.toggle":
3038
+ case "move.block":
3039
+ case "move.block down":
3040
+ case "move.block up":
3041
+ case "select":
3042
+ case "select.next block":
3043
+ case "select.previous block":
3044
+ case "serialization.failure":
3045
+ case "serialization.success":
3046
+ case "style.add":
3047
+ case "style.remove":
3048
+ case "style.toggle":
3049
+ case "text block.set":
3050
+ case "text block.unset":
3091
3051
  editorActor.send({
3092
3052
  type: "behavior event",
3093
- behaviorEvent: {
3094
- type: "list item.toggle",
3095
- listItem: event.listItem
3096
- },
3053
+ behaviorEvent: event,
3097
3054
  editor
3098
3055
  });
3099
3056
  break;
3100
- }
3101
- case "select": {
3102
- editorActor.send({
3103
- type: "behavior event",
3104
- behaviorEvent: {
3105
- type: "select",
3106
- selection: event.selection
3107
- },
3108
- editor
3109
- });
3110
- break;
3111
- }
3112
- case "style.toggle": {
3113
- editorActor.send({
3114
- type: "behavior event",
3115
- behaviorEvent: {
3116
- type: "style.toggle",
3117
- style: event.style
3118
- },
3119
- editor
3120
- });
3121
- break;
3122
- }
3123
3057
  }
3124
3058
  });
3125
3059
  return () => {
@@ -5143,10 +5077,9 @@ function insertBlock({
5143
5077
  });
5144
5078
  } else placement === "before" ? Transforms.insertNodes(editor, block, {
5145
5079
  at: focusBlockPath
5146
- }) : Editor.insertNode(editor, block);
5147
- focusBlock && isEqualToEmptyEditor([focusBlock], schema) && Transforms.removeNodes(editor, {
5080
+ }) : (Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock], schema) && Transforms.removeNodes(editor, {
5148
5081
  at: focusBlockPath
5149
- });
5082
+ }));
5150
5083
  } else {
5151
5084
  const lastBlock = Array.from(Editor.nodes(editor, {
5152
5085
  match: (n) => !Editor.isEditor(n),
@@ -5158,7 +5091,47 @@ function insertBlock({
5158
5091
  });
5159
5092
  }
5160
5093
  }
5161
- const dataTransferSetActionImplementation = ({
5094
+ const blockSetBehaviorActionImplementation = ({
5095
+ action
5096
+ }) => {
5097
+ const location = toSlateRange({
5098
+ anchor: {
5099
+ path: action.at,
5100
+ offset: 0
5101
+ },
5102
+ focus: {
5103
+ path: action.at,
5104
+ offset: 0
5105
+ }
5106
+ }, action.editor);
5107
+ if (!location)
5108
+ return;
5109
+ const {
5110
+ at,
5111
+ editor,
5112
+ type,
5113
+ ...payload
5114
+ } = action;
5115
+ Transforms.setNodes(action.editor, payload, {
5116
+ at: location
5117
+ });
5118
+ }, blockUnsetBehaviorActionImplementation = ({
5119
+ action
5120
+ }) => {
5121
+ const location = toSlateRange({
5122
+ anchor: {
5123
+ path: action.at,
5124
+ offset: 0
5125
+ },
5126
+ focus: {
5127
+ path: action.at,
5128
+ offset: 0
5129
+ }
5130
+ }, action.editor);
5131
+ location && Transforms.unsetNodes(action.editor, action.props, {
5132
+ at: location
5133
+ });
5134
+ }, dataTransferSetActionImplementation = ({
5162
5135
  action
5163
5136
  }) => {
5164
5137
  action.dataTransfer.setData(action.mimeType, action.data);
@@ -5215,96 +5188,54 @@ const dataTransferSetActionImplementation = ({
5215
5188
  const keyGenerator = context.keyGenerator, schema = context.schema, editor = action.editor;
5216
5189
  if (!editor.selection)
5217
5190
  return;
5218
- const [focusSpan] = Array.from(Editor.nodes(editor, {
5219
- mode: "lowest",
5220
- at: editor.selection.focus,
5221
- match: (n) => editor.isTextSpan(n),
5222
- voids: !1
5223
- }))[0] ?? [void 0], focusDecorators = focusSpan?.marks?.filter((mark) => schema.decorators.some((decorator) => decorator.value === mark)) ?? [], focusAnnotations = focusSpan?.marks?.filter((mark) => !schema.decorators.some((decorator) => decorator.value === mark)) ?? [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
5224
- if (editor.isTextBlock(focusBlock)) {
5225
- const [start, end] = Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual(start, {
5226
- path: [...focusBlockPath, focusBlock.children.length - 1],
5227
- offset: editor.isTextSpan(lastFocusBlockChild) ? lastFocusBlockChild.text.length : 0
5228
- }), atTheStartOfBlock = isEqual(end, {
5229
- path: [...focusBlockPath, 0],
5230
- offset: 0
5231
- });
5232
- if (atTheEndOfBlock && Range.isCollapsed(editor.selection)) {
5233
- Editor.insertNode(editor, editor.pteCreateTextBlock({
5234
- decorators: [],
5235
- listItem: focusBlock.listItem,
5236
- level: focusBlock.level
5237
- }));
5238
- return;
5239
- }
5240
- if (atTheStartOfBlock && Range.isCollapsed(editor.selection)) {
5241
- Editor.insertNode(editor, editor.pteCreateTextBlock({
5242
- decorators: focusAnnotations.length === 0 ? focusDecorators : [],
5243
- listItem: focusBlock.listItem,
5244
- level: focusBlock.level
5245
- }));
5246
- const [nextBlockPath] = Path.next(focusBlockPath);
5247
- Transforms.select(editor, {
5191
+ const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
5192
+ if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
5193
+ Editor.withoutNormalizing(editor, () => {
5194
+ if (!editor.selection)
5195
+ return;
5196
+ Transforms.splitNodes(editor, {
5197
+ at: editor.selection
5198
+ });
5199
+ const [nextNode, nextNodePath] = Editor.node(editor, Path.next(focusBlockPath), {
5200
+ depth: 1
5201
+ });
5202
+ if (Transforms.setSelection(editor, {
5248
5203
  anchor: {
5249
- path: [nextBlockPath, 0],
5204
+ path: [...nextNodePath, 0],
5250
5205
  offset: 0
5251
5206
  },
5252
5207
  focus: {
5253
- path: [nextBlockPath, 0],
5208
+ path: [...nextNodePath, 0],
5254
5209
  offset: 0
5255
5210
  }
5256
- });
5257
- return;
5258
- }
5259
- const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
5260
- if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
5261
- Editor.withoutNormalizing(editor, () => {
5262
- if (!editor.selection)
5263
- return;
5264
- Transforms.splitNodes(editor, {
5265
- at: editor.selection
5266
- });
5267
- const [nextNode, nextNodePath] = Editor.node(editor, Path.next(focusBlockPath), {
5268
- depth: 1
5269
- });
5270
- if (Transforms.setSelection(editor, {
5271
- anchor: {
5272
- path: [...nextNodePath, 0],
5273
- offset: 0
5274
- },
5275
- focus: {
5276
- path: [...nextNodePath, 0],
5277
- offset: 0
5278
- }
5279
- }), editor.isTextBlock(nextNode) && nextNode.markDefs && nextNode.markDefs.length > 0) {
5280
- const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = Node.children(editor, nextNodePath);
5281
- for (const [child, childPath] of children) {
5282
- if (!editor.isTextSpan(child))
5283
- continue;
5284
- const marks = child.marks ?? [];
5285
- for (const mark of marks)
5286
- schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
5287
- const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
5288
- isEqual(marks, newMarks) || Transforms.setNodes(editor, {
5289
- marks: newMarks
5290
- }, {
5291
- at: childPath
5292
- });
5293
- }
5294
- const newMarkDefs = nextNode.markDefs.map((markDef) => ({
5295
- ...markDef,
5296
- _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
5297
- }));
5298
- isEqual(nextNode.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
5299
- markDefs: newMarkDefs
5211
+ }), editor.isTextBlock(nextNode) && nextNode.markDefs && nextNode.markDefs.length > 0) {
5212
+ const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = Node.children(editor, nextNodePath);
5213
+ for (const [child, childPath] of children) {
5214
+ if (!editor.isTextSpan(child))
5215
+ continue;
5216
+ const marks = child.marks ?? [];
5217
+ for (const mark of marks)
5218
+ schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
5219
+ const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
5220
+ isEqual(marks, newMarks) || Transforms.setNodes(editor, {
5221
+ marks: newMarks
5300
5222
  }, {
5301
- at: nextNodePath,
5302
- match: (node) => editor.isTextBlock(node)
5223
+ at: childPath
5303
5224
  });
5304
5225
  }
5305
- }), editor.onChange();
5306
- return;
5307
- }
5226
+ const newMarkDefs = nextNode.markDefs.map((markDef) => ({
5227
+ ...markDef,
5228
+ _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
5229
+ }));
5230
+ isEqual(nextNode.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
5231
+ markDefs: newMarkDefs
5232
+ }, {
5233
+ at: nextNodePath,
5234
+ match: (node) => editor.isTextBlock(node)
5235
+ });
5236
+ }
5237
+ }), editor.onChange();
5238
+ return;
5308
5239
  }
5309
5240
  Transforms.splitNodes(editor, {
5310
5241
  always: !0
@@ -5385,6 +5316,27 @@ const dataTransferSetActionImplementation = ({
5385
5316
  text: action.text,
5386
5317
  marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
5387
5318
  });
5319
+ }, insertBlockActionImplementation = ({
5320
+ context,
5321
+ action
5322
+ }) => {
5323
+ const parsedBlock = parseBlock({
5324
+ block: action.block,
5325
+ context
5326
+ });
5327
+ if (!parsedBlock)
5328
+ throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`);
5329
+ const fragment = toSlateValue([parsedBlock], {
5330
+ schemaTypes: context.schema
5331
+ })[0];
5332
+ if (!fragment)
5333
+ throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
5334
+ insertBlock({
5335
+ block: fragment,
5336
+ placement: action.placement,
5337
+ editor: action.editor,
5338
+ schema: context.schema
5339
+ });
5388
5340
  }, textBlockSetActionImplementation = ({
5389
5341
  action
5390
5342
  }) => {
@@ -5431,6 +5383,8 @@ const dataTransferSetActionImplementation = ({
5431
5383
  "annotation.add": addAnnotationActionImplementation,
5432
5384
  "annotation.remove": removeAnnotationActionImplementation,
5433
5385
  "annotation.toggle": toggleAnnotationActionImplementation,
5386
+ "block.set": blockSetBehaviorActionImplementation,
5387
+ "block.unset": blockUnsetBehaviorActionImplementation,
5434
5388
  blur: ({
5435
5389
  action
5436
5390
  }) => {
@@ -5521,6 +5475,7 @@ const dataTransferSetActionImplementation = ({
5521
5475
  }
5522
5476
  });
5523
5477
  },
5478
+ "insert.block": insertBlockActionImplementation,
5524
5479
  "insert.blocks": insertBlocksActionImplementation,
5525
5480
  "insert.block object": insertBlockObjectActionImplementation,
5526
5481
  "insert.break": insertBreakActionImplementation,
@@ -5661,302 +5616,316 @@ function performAction({
5661
5616
  action
5662
5617
  }) {
5663
5618
  switch (action.type) {
5664
- case "annotation.toggle": {
5665
- behaviorActionImplementations["annotation.toggle"]({
5619
+ case "noop":
5620
+ break;
5621
+ case "effect": {
5622
+ behaviorActionImplementations.effect({
5666
5623
  context,
5667
5624
  action
5668
5625
  });
5669
5626
  break;
5670
5627
  }
5671
- case "decorator.add": {
5672
- behaviorActionImplementations["decorator.add"]({
5628
+ default:
5629
+ performDefaultAction({
5630
+ context,
5631
+ action
5632
+ });
5633
+ }
5634
+ }
5635
+ function performDefaultAction({
5636
+ context,
5637
+ action
5638
+ }) {
5639
+ switch (action.type) {
5640
+ case "annotation.add": {
5641
+ behaviorActionImplementations["annotation.add"]({
5673
5642
  context,
5674
5643
  action
5675
5644
  });
5676
5645
  break;
5677
5646
  }
5678
- case "decorator.remove": {
5679
- behaviorActionImplementations["decorator.remove"]({
5647
+ case "annotation.remove": {
5648
+ behaviorActionImplementations["annotation.remove"]({
5680
5649
  context,
5681
5650
  action
5682
5651
  });
5683
5652
  break;
5684
5653
  }
5685
- case "delete.block": {
5686
- behaviorActionImplementations["delete.block"]({
5654
+ case "annotation.toggle": {
5655
+ behaviorActionImplementations["annotation.toggle"]({
5687
5656
  context,
5688
5657
  action
5689
5658
  });
5690
5659
  break;
5691
5660
  }
5692
- case "delete.text": {
5693
- behaviorActionImplementations["delete.text"]({
5661
+ case "block.set": {
5662
+ behaviorActionImplementations["block.set"]({
5694
5663
  context,
5695
5664
  action
5696
5665
  });
5697
5666
  break;
5698
5667
  }
5699
- case "insert.span": {
5700
- behaviorActionImplementations["insert.span"]({
5668
+ case "block.unset": {
5669
+ behaviorActionImplementations["block.unset"]({
5701
5670
  context,
5702
5671
  action
5703
5672
  });
5704
5673
  break;
5705
5674
  }
5706
- case "insert.text block": {
5707
- behaviorActionImplementations["insert.text block"]({
5675
+ case "blur": {
5676
+ behaviorActionImplementations.blur({
5708
5677
  context,
5709
5678
  action
5710
5679
  });
5711
5680
  break;
5712
5681
  }
5713
- case "list item.add": {
5714
- behaviorActionImplementations["list item.add"]({
5682
+ case "data transfer.set": {
5683
+ behaviorActionImplementations["data transfer.set"]({
5715
5684
  context,
5716
5685
  action
5717
5686
  });
5718
5687
  break;
5719
5688
  }
5720
- case "list item.remove": {
5721
- behaviorActionImplementations["list item.remove"]({
5689
+ case "decorator.add": {
5690
+ behaviorActionImplementations["decorator.add"]({
5722
5691
  context,
5723
5692
  action
5724
5693
  });
5725
5694
  break;
5726
5695
  }
5727
- case "move.block": {
5728
- behaviorActionImplementations["move.block"]({
5696
+ case "decorator.remove": {
5697
+ behaviorActionImplementations["decorator.remove"]({
5729
5698
  context,
5730
5699
  action
5731
5700
  });
5732
5701
  break;
5733
5702
  }
5734
- case "move.block down": {
5735
- behaviorActionImplementations["move.block down"]({
5703
+ case "decorator.toggle": {
5704
+ behaviorActionImplementations["decorator.toggle"]({
5736
5705
  context,
5737
5706
  action
5738
5707
  });
5739
5708
  break;
5740
5709
  }
5741
- case "move.block up": {
5742
- behaviorActionImplementations["move.block up"]({
5710
+ case "delete.backward": {
5711
+ behaviorActionImplementations["delete.backward"]({
5743
5712
  context,
5744
5713
  action
5745
5714
  });
5746
5715
  break;
5747
5716
  }
5748
- case "noop":
5717
+ case "delete.block": {
5718
+ behaviorActionImplementations["delete.block"]({
5719
+ context,
5720
+ action
5721
+ });
5749
5722
  break;
5750
- case "effect": {
5751
- behaviorActionImplementations.effect({
5723
+ }
5724
+ case "delete.forward": {
5725
+ behaviorActionImplementations["delete.forward"]({
5752
5726
  context,
5753
5727
  action
5754
5728
  });
5755
5729
  break;
5756
5730
  }
5757
- case "select": {
5758
- behaviorActionImplementations.select({
5731
+ case "delete.text": {
5732
+ behaviorActionImplementations["delete.text"]({
5759
5733
  context,
5760
5734
  action
5761
5735
  });
5762
5736
  break;
5763
5737
  }
5764
- case "select.previous block": {
5765
- behaviorActionImplementations["select.previous block"]({
5738
+ case "deserialization.failure": {
5739
+ behaviorActionImplementations["deserialization.failure"]({
5766
5740
  context,
5767
5741
  action
5768
5742
  });
5769
5743
  break;
5770
5744
  }
5771
- case "select.next block": {
5772
- behaviorActionImplementations["select.next block"]({
5745
+ case "deserialization.success": {
5746
+ behaviorActionImplementations["deserialization.success"]({
5773
5747
  context,
5774
5748
  action
5775
5749
  });
5776
5750
  break;
5777
5751
  }
5778
- case "style.add": {
5779
- behaviorActionImplementations["style.add"]({
5752
+ case "focus": {
5753
+ behaviorActionImplementations.focus({
5780
5754
  context,
5781
5755
  action
5782
5756
  });
5783
5757
  break;
5784
5758
  }
5785
- case "style.remove": {
5786
- behaviorActionImplementations["style.remove"]({
5759
+ case "insert.block": {
5760
+ behaviorActionImplementations["insert.block"]({
5787
5761
  context,
5788
5762
  action
5789
5763
  });
5790
5764
  break;
5791
5765
  }
5792
- case "text block.set": {
5793
- behaviorActionImplementations["text block.set"]({
5766
+ case "insert.blocks": {
5767
+ behaviorActionImplementations["insert.blocks"]({
5794
5768
  context,
5795
5769
  action
5796
5770
  });
5797
5771
  break;
5798
5772
  }
5799
- case "text block.unset": {
5800
- behaviorActionImplementations["text block.unset"]({
5773
+ case "insert.block object": {
5774
+ behaviorActionImplementations["insert.block object"]({
5801
5775
  context,
5802
5776
  action
5803
5777
  });
5804
5778
  break;
5805
5779
  }
5806
- default:
5807
- performDefaultAction({
5780
+ case "insert.inline object": {
5781
+ behaviorActionImplementations["insert.inline object"]({
5808
5782
  context,
5809
5783
  action
5810
5784
  });
5811
- }
5812
- }
5813
- function performDefaultAction({
5814
- context,
5815
- action
5816
- }) {
5817
- switch (action.type) {
5818
- case "annotation.add": {
5819
- behaviorActionImplementations["annotation.add"]({
5785
+ break;
5786
+ }
5787
+ case "insert.break": {
5788
+ behaviorActionImplementations["insert.break"]({
5820
5789
  context,
5821
5790
  action
5822
5791
  });
5823
5792
  break;
5824
5793
  }
5825
- case "annotation.remove": {
5826
- behaviorActionImplementations["annotation.remove"]({
5794
+ case "insert.soft break": {
5795
+ behaviorActionImplementations["insert.soft break"]({
5827
5796
  context,
5828
5797
  action
5829
5798
  });
5830
5799
  break;
5831
5800
  }
5832
- case "blur": {
5833
- behaviorActionImplementations.blur({
5801
+ case "insert.span": {
5802
+ behaviorActionImplementations["insert.span"]({
5834
5803
  context,
5835
5804
  action
5836
5805
  });
5837
5806
  break;
5838
5807
  }
5839
- case "data transfer.set": {
5840
- behaviorActionImplementations["data transfer.set"]({
5808
+ case "insert.text": {
5809
+ behaviorActionImplementations["insert.text"]({
5841
5810
  context,
5842
5811
  action
5843
5812
  });
5844
5813
  break;
5845
5814
  }
5846
- case "decorator.toggle": {
5847
- behaviorActionImplementations["decorator.toggle"]({
5815
+ case "insert.text block": {
5816
+ behaviorActionImplementations["insert.text block"]({
5848
5817
  context,
5849
5818
  action
5850
5819
  });
5851
5820
  break;
5852
5821
  }
5853
- case "delete.backward": {
5854
- behaviorActionImplementations["delete.backward"]({
5822
+ case "list item.add": {
5823
+ behaviorActionImplementations["list item.add"]({
5855
5824
  context,
5856
5825
  action
5857
5826
  });
5858
5827
  break;
5859
5828
  }
5860
- case "delete.forward": {
5861
- behaviorActionImplementations["delete.forward"]({
5829
+ case "list item.remove": {
5830
+ behaviorActionImplementations["list item.remove"]({
5862
5831
  context,
5863
5832
  action
5864
5833
  });
5865
5834
  break;
5866
5835
  }
5867
- case "deserialization.failure": {
5868
- behaviorActionImplementations["deserialization.failure"]({
5836
+ case "list item.toggle": {
5837
+ behaviorActionImplementations["list item.toggle"]({
5869
5838
  context,
5870
5839
  action
5871
5840
  });
5872
5841
  break;
5873
5842
  }
5874
- case "deserialization.success": {
5875
- behaviorActionImplementations["deserialization.success"]({
5843
+ case "move.block": {
5844
+ behaviorActionImplementations["move.block"]({
5876
5845
  context,
5877
5846
  action
5878
5847
  });
5879
5848
  break;
5880
5849
  }
5881
- case "focus": {
5882
- behaviorActionImplementations.focus({
5850
+ case "move.block down": {
5851
+ behaviorActionImplementations["move.block down"]({
5883
5852
  context,
5884
5853
  action
5885
5854
  });
5886
5855
  break;
5887
5856
  }
5888
- case "insert.blocks": {
5889
- behaviorActionImplementations["insert.blocks"]({
5857
+ case "move.block up": {
5858
+ behaviorActionImplementations["move.block up"]({
5890
5859
  context,
5891
5860
  action
5892
5861
  });
5893
5862
  break;
5894
5863
  }
5895
- case "insert.block object": {
5896
- behaviorActionImplementations["insert.block object"]({
5864
+ case "select": {
5865
+ behaviorActionImplementations.select({
5897
5866
  context,
5898
5867
  action
5899
5868
  });
5900
5869
  break;
5901
5870
  }
5902
- case "insert.inline object": {
5903
- behaviorActionImplementations["insert.inline object"]({
5871
+ case "select.previous block": {
5872
+ behaviorActionImplementations["select.previous block"]({
5904
5873
  context,
5905
5874
  action
5906
5875
  });
5907
5876
  break;
5908
5877
  }
5909
- case "insert.break": {
5910
- behaviorActionImplementations["insert.break"]({
5878
+ case "select.next block": {
5879
+ behaviorActionImplementations["select.next block"]({
5911
5880
  context,
5912
5881
  action
5913
5882
  });
5914
5883
  break;
5915
5884
  }
5916
- case "insert.soft break": {
5917
- behaviorActionImplementations["insert.soft break"]({
5885
+ case "serialization.failure": {
5886
+ behaviorActionImplementations["serialization.failure"]({
5918
5887
  context,
5919
5888
  action
5920
5889
  });
5921
5890
  break;
5922
5891
  }
5923
- case "insert.text": {
5924
- behaviorActionImplementations["insert.text"]({
5892
+ case "serialization.success": {
5893
+ behaviorActionImplementations["serialization.success"]({
5925
5894
  context,
5926
5895
  action
5927
5896
  });
5928
5897
  break;
5929
5898
  }
5930
- case "list item.toggle": {
5931
- behaviorActionImplementations["list item.toggle"]({
5899
+ case "style.add": {
5900
+ behaviorActionImplementations["style.add"]({
5932
5901
  context,
5933
5902
  action
5934
5903
  });
5935
5904
  break;
5936
5905
  }
5937
- case "select": {
5938
- behaviorActionImplementations.select({
5906
+ case "style.remove": {
5907
+ behaviorActionImplementations["style.remove"]({
5939
5908
  context,
5940
5909
  action
5941
5910
  });
5942
5911
  break;
5943
5912
  }
5944
- case "serialization.failure": {
5945
- behaviorActionImplementations["serialization.failure"]({
5913
+ case "style.toggle": {
5914
+ behaviorActionImplementations["style.toggle"]({
5946
5915
  context,
5947
5916
  action
5948
5917
  });
5949
5918
  break;
5950
5919
  }
5951
- case "serialization.success": {
5952
- behaviorActionImplementations["serialization.success"]({
5920
+ case "text block.set": {
5921
+ behaviorActionImplementations["text block.set"]({
5953
5922
  context,
5954
5923
  action
5955
5924
  });
5956
5925
  break;
5957
5926
  }
5958
5927
  default:
5959
- behaviorActionImplementations["style.toggle"]({
5928
+ behaviorActionImplementations["text block.unset"]({
5960
5929
  context,
5961
5930
  action
5962
5931
  });
@@ -6340,6 +6309,11 @@ const editorMachine = setup({
6340
6309
  event
6341
6310
  }) => event)
6342
6311
  },
6312
+ "block.*": {
6313
+ actions: emit(({
6314
+ event
6315
+ }) => event)
6316
+ },
6343
6317
  blur: {
6344
6318
  actions: emit(({
6345
6319
  event
@@ -6358,6 +6332,11 @@ const editorMachine = setup({
6358
6332
  event
6359
6333
  }) => event)
6360
6334
  },
6335
+ "delete.*": {
6336
+ actions: emit(({
6337
+ event
6338
+ }) => event)
6339
+ },
6361
6340
  focus: {
6362
6341
  actions: emit(({
6363
6342
  event
@@ -6373,15 +6352,30 @@ const editorMachine = setup({
6373
6352
  event
6374
6353
  }) => event)
6375
6354
  },
6355
+ "move.*": {
6356
+ actions: emit(({
6357
+ event
6358
+ }) => event)
6359
+ },
6376
6360
  select: {
6377
6361
  actions: emit(({
6378
6362
  event
6379
6363
  }) => event)
6380
6364
  },
6365
+ "select.*": {
6366
+ actions: emit(({
6367
+ event
6368
+ }) => event)
6369
+ },
6381
6370
  "style.*": {
6382
6371
  actions: emit(({
6383
6372
  event
6384
6373
  }) => event)
6374
+ },
6375
+ "text block.*": {
6376
+ actions: emit(({
6377
+ event
6378
+ }) => event)
6385
6379
  }
6386
6380
  }
6387
6381
  }
@@ -6562,11 +6556,25 @@ function createEditorFromActor(editorActor) {
6562
6556
  send: (event) => {
6563
6557
  editorActor.send(event);
6564
6558
  },
6565
- on: (event, listener) => editorActor.on(
6566
- event,
6567
- // @ts-expect-error
6568
- listener
6569
- ),
6559
+ on: (event, listener) => editorActor.on(event, (event2) => {
6560
+ switch (event2.type) {
6561
+ case "blurred":
6562
+ case "done loading":
6563
+ case "editable":
6564
+ case "error":
6565
+ case "focused":
6566
+ case "invalid value":
6567
+ case "loading":
6568
+ case "mutation":
6569
+ case "patch":
6570
+ case "read only":
6571
+ case "ready":
6572
+ case "selection":
6573
+ case "value changed":
6574
+ listener(event2);
6575
+ break;
6576
+ }
6577
+ }),
6570
6578
  _internal: {
6571
6579
  editable,
6572
6580
  editorActor,