@portabletext/editor 1.37.0 → 1.38.1

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 (109) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +84 -49
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/editor-provider.cjs +868 -534
  4. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  5. package/lib/_chunks-cjs/{util.block-offsets-to-selection.cjs → parse-blocks.cjs} +36 -21
  6. package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
  7. package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
  8. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  9. package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-overlapping-selection.cjs} +144 -3
  10. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.slice-blocks.cjs +12 -0
  12. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  13. package/lib/_chunks-es/behavior.core.js +84 -49
  14. package/lib/_chunks-es/behavior.core.js.map +1 -1
  15. package/lib/_chunks-es/editor-provider.js +858 -523
  16. package/lib/_chunks-es/editor-provider.js.map +1 -1
  17. package/lib/_chunks-es/{util.block-offsets-to-selection.js → parse-blocks.js} +37 -22
  18. package/lib/_chunks-es/parse-blocks.js.map +1 -0
  19. package/lib/_chunks-es/selector.get-text-before.js +1 -2
  20. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  21. package/lib/_chunks-es/{selector.is-active-style.js → selector.is-overlapping-selection.js} +146 -5
  22. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -0
  23. package/lib/_chunks-es/util.slice-blocks.js +12 -0
  24. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  25. package/lib/behaviors/index.d.cts +10534 -4689
  26. package/lib/behaviors/index.d.ts +10534 -4689
  27. package/lib/index.cjs +578 -209
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +5296 -1178
  30. package/lib/index.d.ts +5296 -1178
  31. package/lib/index.js +587 -213
  32. package/lib/index.js.map +1 -1
  33. package/lib/plugins/index.cjs +2 -2
  34. package/lib/plugins/index.cjs.map +1 -1
  35. package/lib/plugins/index.d.cts +5296 -1178
  36. package/lib/plugins/index.d.ts +5296 -1178
  37. package/lib/plugins/index.js +1 -1
  38. package/lib/selectors/index.cjs +15 -152
  39. package/lib/selectors/index.cjs.map +1 -1
  40. package/lib/selectors/index.d.cts +5296 -1178
  41. package/lib/selectors/index.d.ts +5296 -1178
  42. package/lib/selectors/index.js +7 -145
  43. package/lib/selectors/index.js.map +1 -1
  44. package/lib/utils/index.cjs +4 -4
  45. package/lib/utils/index.cjs.map +1 -1
  46. package/lib/utils/index.d.cts +5296 -1178
  47. package/lib/utils/index.d.ts +5296 -1178
  48. package/lib/utils/index.js +3 -4
  49. package/lib/utils/index.js.map +1 -1
  50. package/package.json +16 -15
  51. package/src/behavior-actions/behavior.action.blur.ts +8 -0
  52. package/src/behavior-actions/behavior.action.decorator.add.ts +1 -1
  53. package/src/behavior-actions/behavior.action.delete.backward.ts +7 -0
  54. package/src/behavior-actions/behavior.action.delete.block.ts +24 -0
  55. package/src/behavior-actions/behavior.action.delete.forward.ts +7 -0
  56. package/src/behavior-actions/behavior.action.delete.text.ts +1 -1
  57. package/src/behavior-actions/behavior.action.deserialization.failure.ts +9 -0
  58. package/src/behavior-actions/behavior.action.deserialization.success.ts +16 -0
  59. package/src/behavior-actions/behavior.action.effect.ts +7 -0
  60. package/src/behavior-actions/behavior.action.focus.ts +8 -0
  61. package/src/behavior-actions/behavior.action.insert-blocks.ts +118 -139
  62. package/src/behavior-actions/behavior.action.insert-break.ts +1 -0
  63. package/src/behavior-actions/{behavior.action.insert-block-object.ts → behavior.action.insert.block-object.ts} +9 -14
  64. package/src/behavior-actions/behavior.action.insert.block.ts +247 -2
  65. package/src/behavior-actions/behavior.action.insert.text-block.ts +33 -0
  66. package/src/behavior-actions/behavior.action.insert.text.ts +7 -0
  67. package/src/behavior-actions/behavior.action.move.block-down.ts +48 -0
  68. package/src/behavior-actions/behavior.action.move.block-up.ts +53 -0
  69. package/src/behavior-actions/behavior.action.move.block.ts +16 -0
  70. package/src/behavior-actions/behavior.action.noop.ts +5 -0
  71. package/src/behavior-actions/behavior.action.select.next-block.ts +44 -0
  72. package/src/behavior-actions/behavior.action.select.previous-block.ts +48 -0
  73. package/src/behavior-actions/behavior.action.select.ts +15 -0
  74. package/src/behavior-actions/behavior.action.serialization.failure.ts +9 -0
  75. package/src/behavior-actions/behavior.action.serialization.success.ts +14 -0
  76. package/src/behavior-actions/behavior.actions.ts +54 -212
  77. package/src/behaviors/behavior.core.block-objects.ts +35 -6
  78. package/src/behaviors/behavior.core.insert-break.ts +1 -0
  79. package/src/behaviors/behavior.core.ts +2 -0
  80. package/src/behaviors/behavior.default.ts +241 -33
  81. package/src/behaviors/behavior.types.ts +138 -20
  82. package/src/converters/converter.portable-text.ts +5 -2
  83. package/src/converters/converter.text-html.serialize.test.ts +4 -4
  84. package/src/converters/converter.text-html.ts +5 -2
  85. package/src/converters/converter.text-plain.test.ts +6 -6
  86. package/src/converters/converter.text-plain.ts +5 -2
  87. package/src/converters/converter.types.ts +3 -3
  88. package/src/editor/Editable.tsx +401 -48
  89. package/src/editor/components/Element.tsx +133 -18
  90. package/src/editor/components/use-draggable.ts +34 -102
  91. package/src/editor/editor-machine.ts +50 -7
  92. package/src/editor/editor-selector.ts +1 -0
  93. package/src/editor/editor-snapshot.ts +13 -0
  94. package/src/editor/plugins/create-with-event-listeners.ts +6 -40
  95. package/src/internal-utils/create-test-snapshot.ts +1 -0
  96. package/src/internal-utils/event-position.ts +210 -0
  97. package/src/internal-utils/slate-utils.ts +56 -0
  98. package/src/internal-utils/weakMaps.ts +1 -15
  99. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
  100. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +0 -1
  101. package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -14
  102. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +0 -1
  103. package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
  104. package/lib/_chunks-es/util.block-offsets-to-selection.js.map +0 -1
  105. package/lib/_chunks-es/util.reverse-selection.js +0 -15
  106. package/lib/_chunks-es/util.reverse-selection.js.map +0 -1
  107. package/src/behavior-actions/behavior.action-utils.insert-block.ts +0 -61
  108. package/src/editor/__tests__/handleClick.test.tsx +0 -277
  109. package/src/editor/components/use-droppable.ts +0 -135
@@ -5,7 +5,7 @@ import { ReactEditor, withReact, Slate } from "slate-react";
5
5
  import { useSelector, useActorRef } from "@xstate/react";
6
6
  import debug$e from "debug";
7
7
  import isEqual from "lodash/isEqual.js";
8
- import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, Node, insertText, deleteForward, createEditor as createEditor$1 } from "slate";
8
+ import { Editor, Element, Range, Point, Text, Operation, Transforms, Path, Node, insertText, createEditor as createEditor$1 } from "slate";
9
9
  import { setup, emit, enqueueActions, assign, assertEvent, fromCallback, stateIn, and, not, createActor } from "xstate";
10
10
  import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
11
11
  import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
@@ -13,19 +13,20 @@ import flatten from "lodash/flatten.js";
13
13
  import isPlainObject from "lodash/isPlainObject.js";
14
14
  import uniq from "lodash/uniq.js";
15
15
  import getRandomValues from "get-random-values-esm";
16
- import { parseBlock, blockOffsetsToSelection, isTextBlock } from "./util.block-offsets-to-selection.js";
17
- import { sliceBlocks, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset } from "./util.slice-blocks.js";
16
+ import { parseBlock, blockOffsetsToSelection, isTextBlock, parseBlocks } from "./parse-blocks.js";
17
+ import { sliceBlocks, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset, isKeyedSegment as isKeyedSegment$1 } from "./util.slice-blocks.js";
18
18
  import { htmlToBlocks } from "@portabletext/block-tools";
19
19
  import { toHTML } from "@portabletext/to-html";
20
20
  import { Schema } from "@sanity/schema";
21
21
  import get from "lodash/get.js";
22
22
  import isUndefined from "lodash/isUndefined.js";
23
23
  import omitBy from "lodash/omitBy.js";
24
- import { createGuards } from "./selector.is-at-the-start-of-block.js";
25
- import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle } from "./selector.is-active-style.js";
24
+ import { createGuards, getFocusSpan, isSelectionCollapsed, getSelectedBlocks, isSelectionExpanded } from "./selector.is-at-the-start-of-block.js";
25
+ import { getTrimmedSelection, isOverlappingSelection, isSelectingEntireBlocks, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle } from "./selector.is-overlapping-selection.js";
26
26
  import omit from "lodash/omit.js";
27
+ import { DOMEditor } from "slate-dom";
27
28
  import startCase from "lodash.startcase";
28
- import { defineBehavior, raise, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
29
+ import { defineBehavior, raise, isDragBehaviorEvent, isMouseBehaviorEvent, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
29
30
  import { Subject } from "rxjs";
30
31
  import { useEffectEvent } from "use-effect-event";
31
32
  function createEditorSchema(portableTextType) {
@@ -331,7 +332,65 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
331
332
  function isEqualToEmptyEditor(children, schemaTypes) {
332
333
  return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
333
334
  }
334
- const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
335
+ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), EditorActorContext = createContext({});
336
+ function getActiveDecorators({
337
+ schema,
338
+ slateEditorInstance
339
+ }) {
340
+ const decorators = schema.decorators.map((decorator) => decorator.value);
341
+ return ({
342
+ ...Editor.marks(slateEditorInstance) ?? {}
343
+ }.marks ?? []).filter((mark) => decorators.includes(mark));
344
+ }
345
+ function getValue({
346
+ editorActorSnapshot,
347
+ slateEditorInstance
348
+ }) {
349
+ return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
350
+ }
351
+ function defaultCompare(a, b) {
352
+ return a === b;
353
+ }
354
+ function useEditorSelector(editor, selector, t0) {
355
+ const $ = c(3), compare = t0 === void 0 ? defaultCompare : t0;
356
+ let t1;
357
+ return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
358
+ const snapshot = getEditorSnapshot({
359
+ editorActorSnapshot,
360
+ slateEditorInstance: editor._internal.slateEditor.instance
361
+ });
362
+ return selector(snapshot);
363
+ }, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
364
+ }
365
+ function getEditorSnapshot({
366
+ editorActorSnapshot,
367
+ slateEditorInstance
368
+ }) {
369
+ return {
370
+ context: {
371
+ converters: [...editorActorSnapshot.context.converters],
372
+ activeDecorators: getActiveDecorators({
373
+ schema: editorActorSnapshot.context.schema,
374
+ slateEditorInstance
375
+ }),
376
+ keyGenerator: editorActorSnapshot.context.keyGenerator,
377
+ readOnly: editorActorSnapshot.matches({
378
+ "edit mode": "read only"
379
+ }),
380
+ schema: editorActorSnapshot.context.schema,
381
+ selection: editorActorSnapshot.context.selection,
382
+ value: getValue({
383
+ editorActorSnapshot,
384
+ slateEditorInstance
385
+ })
386
+ },
387
+ beta: {
388
+ hasTag: (tag) => editorActorSnapshot.hasTag(tag),
389
+ internalDrag: editorActorSnapshot.context.internalDrag
390
+ }
391
+ };
392
+ }
393
+ const PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
335
394
  const editor = useContext(PortableTextEditorContext);
336
395
  if (!editor)
337
396
  throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
@@ -2425,7 +2484,8 @@ const converterJson = {
2425
2484
  snapshot,
2426
2485
  event
2427
2486
  }) => {
2428
- if (!snapshot.context.selection)
2487
+ const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
2488
+ if (!selection)
2429
2489
  return {
2430
2490
  type: "serialization.failure",
2431
2491
  mimeType: "application/x-portable-text",
@@ -2434,7 +2494,7 @@ const converterJson = {
2434
2494
  };
2435
2495
  const blocks = sliceBlocks({
2436
2496
  blocks: snapshot.context.value,
2437
- selection: snapshot.context.selection
2497
+ selection
2438
2498
  });
2439
2499
  return {
2440
2500
  type: "serialization.success",
@@ -2484,7 +2544,8 @@ const converterJson = {
2484
2544
  snapshot,
2485
2545
  event
2486
2546
  }) => {
2487
- if (!snapshot.context.selection)
2547
+ const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
2548
+ if (!selection)
2488
2549
  return {
2489
2550
  type: "serialization.failure",
2490
2551
  mimeType: "text/html",
@@ -2493,7 +2554,7 @@ const converterJson = {
2493
2554
  };
2494
2555
  const blocks = sliceBlocks({
2495
2556
  blocks: snapshot.context.value,
2496
- selection: snapshot.context.selection
2557
+ selection
2497
2558
  }), html = toHTML(blocks, {
2498
2559
  onMissingComponent: !1,
2499
2560
  components: {
@@ -2537,21 +2598,24 @@ const converterJson = {
2537
2598
  serialize: ({
2538
2599
  snapshot,
2539
2600
  event
2540
- }) => snapshot.context.selection ? {
2541
- type: "serialization.success",
2542
- data: sliceBlocks({
2543
- blocks: snapshot.context.value,
2544
- selection: snapshot.context.selection
2545
- }).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]`).join("") : `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]`).join(`
2601
+ }) => {
2602
+ const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
2603
+ return selection ? {
2604
+ type: "serialization.success",
2605
+ data: sliceBlocks({
2606
+ blocks: snapshot.context.value,
2607
+ selection
2608
+ }).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]`).join("") : `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]`).join(`
2546
2609
 
2547
2610
  `),
2548
- mimeType: "text/plain",
2549
- originEvent: event.originEvent
2550
- } : {
2551
- type: "serialization.failure",
2552
- mimeType: "text/plain",
2553
- originEvent: event.originEvent,
2554
- reason: "No selection"
2611
+ mimeType: "text/plain",
2612
+ originEvent: event.originEvent
2613
+ } : {
2614
+ type: "serialization.failure",
2615
+ mimeType: "text/plain",
2616
+ originEvent: event.originEvent,
2617
+ reason: "No selection"
2618
+ };
2555
2619
  },
2556
2620
  deserialize: ({
2557
2621
  snapshot,
@@ -2815,7 +2879,8 @@ const insertBreakActionImplementation = ({
2815
2879
  const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
2816
2880
  if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
2817
2881
  Transforms.splitNodes(editor, {
2818
- at: editor.selection
2882
+ at: editor.selection,
2883
+ always: !0
2819
2884
  });
2820
2885
  const [nextBlock, nextBlockPath] = Editor.node(editor, Path.next(focusBlockPath), {
2821
2886
  depth: 1
@@ -3059,7 +3124,8 @@ const decoratorAddActionImplementation = ({
3059
3124
  backward: editorSelection?.backward
3060
3125
  }), trimmedSelection = getTrimmedSelection({
3061
3126
  beta: {
3062
- hasTag: () => !1
3127
+ hasTag: () => !1,
3128
+ internalDrag: void 0
3063
3129
  },
3064
3130
  context: {
3065
3131
  activeDecorators: [],
@@ -4098,49 +4164,7 @@ const addAnnotationActionImplementation = ({
4098
4164
  editor: action.editor
4099
4165
  }
4100
4166
  });
4101
- };
4102
- function insertBlock({
4103
- block,
4104
- placement,
4105
- editor,
4106
- schema
4107
- }) {
4108
- if (editor.selection) {
4109
- const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(editor, {
4110
- at: editor.selection.focus.path.slice(0, 1),
4111
- match: (n) => !Editor.isEditor(n)
4112
- }))[0] ?? [void 0, void 0];
4113
- if (placement === "after") {
4114
- const nextPath = [focusBlockPath[0] + 1];
4115
- Transforms.insertNodes(editor, block, {
4116
- at: nextPath
4117
- }), Transforms.select(editor, {
4118
- anchor: {
4119
- path: [nextPath[0], 0],
4120
- offset: 0
4121
- },
4122
- focus: {
4123
- path: [nextPath[0], 0],
4124
- offset: 0
4125
- }
4126
- });
4127
- } else placement === "before" ? Transforms.insertNodes(editor, block, {
4128
- at: focusBlockPath
4129
- }) : (Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock], schema) && Transforms.removeNodes(editor, {
4130
- at: focusBlockPath
4131
- }));
4132
- } else {
4133
- const lastBlock = Array.from(Editor.nodes(editor, {
4134
- match: (n) => !Editor.isEditor(n),
4135
- at: [],
4136
- reverse: !0
4137
- }))[0];
4138
- Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], schema) && Transforms.removeNodes(editor, {
4139
- at: lastBlock[1]
4140
- });
4141
- }
4142
- }
4143
- const blockSetBehaviorActionImplementation = ({
4167
+ }, blockSetBehaviorActionImplementation = ({
4144
4168
  context,
4145
4169
  action
4146
4170
  }) => {
@@ -4250,6 +4274,10 @@ const blockSetBehaviorActionImplementation = ({
4250
4274
  }, {
4251
4275
  at: location
4252
4276
  });
4277
+ }, blurActionImplementation = ({
4278
+ action
4279
+ }) => {
4280
+ ReactEditor.blur(action.editor);
4253
4281
  }, dataTransferSetActionImplementation = ({
4254
4282
  action
4255
4283
  }) => {
@@ -4263,6 +4291,34 @@ const blockSetBehaviorActionImplementation = ({
4263
4291
  action.editor.delete({
4264
4292
  at: range
4265
4293
  });
4294
+ }, deleteBackwardActionImplementation = ({
4295
+ action
4296
+ }) => {
4297
+ action.editor.deleteBackward(action.unit);
4298
+ }, deleteBlockActionImplementation = ({
4299
+ action
4300
+ }) => {
4301
+ const range = toSlateRange({
4302
+ anchor: {
4303
+ path: action.blockPath,
4304
+ offset: 0
4305
+ },
4306
+ focus: {
4307
+ path: action.blockPath,
4308
+ offset: 0
4309
+ }
4310
+ }, action.editor);
4311
+ if (!range) {
4312
+ console.error("Unable to find Slate range from selection points");
4313
+ return;
4314
+ }
4315
+ Transforms.removeNodes(action.editor, {
4316
+ at: range
4317
+ });
4318
+ }, deleteForwardActionImplementation = ({
4319
+ action
4320
+ }) => {
4321
+ action.editor.deleteForward(action.unit);
4266
4322
  }, deleteTextActionImplementation = ({
4267
4323
  context,
4268
4324
  action
@@ -4278,7 +4334,8 @@ const blockSetBehaviorActionImplementation = ({
4278
4334
  throw new Error("Unable to find selection from block offsets");
4279
4335
  const trimmedSelection = getTrimmedSelection({
4280
4336
  beta: {
4281
- hasTag: () => !1
4337
+ hasTag: () => !1,
4338
+ internalDrag: void 0
4282
4339
  },
4283
4340
  context: {
4284
4341
  converters: [],
@@ -4298,157 +4355,395 @@ const blockSetBehaviorActionImplementation = ({
4298
4355
  Transforms.delete(action.editor, {
4299
4356
  at: range
4300
4357
  });
4301
- }, insertBlockObjectActionImplementation = ({
4358
+ }, deserializationFailureActionImplementation = ({
4359
+ action
4360
+ }) => {
4361
+ console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
4362
+ };
4363
+ function getFocusBlock({
4364
+ editor
4365
+ }) {
4366
+ return editor.selection ? Array.from(Editor.nodes(editor, {
4367
+ at: editor.selection.focus.path.slice(0, 1),
4368
+ match: (n) => !Editor.isEditor(n)
4369
+ })).at(0) ?? [void 0, void 0] : [void 0, void 0];
4370
+ }
4371
+ function getFocusChild({
4372
+ editor
4373
+ }) {
4374
+ const [focusBlock, focusBlockPath] = getFocusBlock({
4375
+ editor
4376
+ }), childIndex = editor.selection?.focus.path.at(1);
4377
+ if (!focusBlock || !focusBlockPath || childIndex === void 0)
4378
+ return [void 0, void 0];
4379
+ const focusChild = Node.child(focusBlock, childIndex);
4380
+ return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
4381
+ }
4382
+ function getLastBlock({
4383
+ editor
4384
+ }) {
4385
+ return Array.from(Editor.nodes(editor, {
4386
+ match: (n) => !Editor.isEditor(n),
4387
+ at: [],
4388
+ reverse: !0
4389
+ })).at(0) ?? [void 0, void 0];
4390
+ }
4391
+ const insertBlockActionImplementation = ({
4302
4392
  context,
4303
4393
  action
4304
4394
  }) => {
4305
- const block = toSlateValue([{
4306
- _key: context.keyGenerator(),
4307
- _type: action.blockObject.name,
4308
- ...action.blockObject.value ? action.blockObject.value : {}
4309
- }], {
4395
+ const parsedBlock = parseBlock({
4396
+ block: action.block,
4397
+ context,
4398
+ options: {
4399
+ refreshKeys: !1
4400
+ }
4401
+ });
4402
+ if (!parsedBlock)
4403
+ throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`);
4404
+ const fragment = toSlateValue([parsedBlock], {
4310
4405
  schemaTypes: context.schema
4311
4406
  })[0];
4407
+ if (!fragment)
4408
+ throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
4312
4409
  insertBlock({
4313
- block,
4410
+ block: fragment,
4314
4411
  placement: action.placement,
4412
+ select: action.select ?? "start",
4315
4413
  editor: action.editor,
4316
4414
  schema: context.schema
4317
4415
  });
4318
- }, insertBlocksActionImplementation = ({
4319
- context,
4320
- action
4321
- }) => {
4322
- const fragment = toSlateValue(action.blocks, {
4323
- schemaTypes: context.schema
4324
- });
4325
- if (!action.editor.selection) {
4326
- if (action.placement === "before") {
4327
- action.editor.insertFragment(fragment, {
4328
- at: Editor.start(action.editor, [])
4329
- });
4330
- return;
4331
- }
4332
- if (action.placement === "after") {
4333
- action.editor.insertFragment(fragment, {
4334
- at: Editor.end(action.editor, [])
4335
- });
4336
- return;
4337
- }
4338
- action.editor.insertFragment(fragment);
4339
- return;
4340
- }
4341
- const [focusBlock, focusPath] = Editor.node(action.editor, action.editor.selection, {
4342
- depth: 1
4416
+ };
4417
+ function insertBlock({
4418
+ block,
4419
+ placement,
4420
+ select,
4421
+ editor,
4422
+ schema
4423
+ }) {
4424
+ const [focusBlock, focusBlockPath] = getFocusBlock({
4425
+ editor
4343
4426
  });
4344
- if (action.placement === "before" && focusPath) {
4345
- Transforms.insertNodes(action.editor, fragment, {
4346
- at: focusPath
4347
- });
4348
- return;
4349
- }
4350
- if (action.placement === "after" && focusPath) {
4351
- const nextPath = [focusPath[0] + 1];
4352
- Transforms.insertNodes(action.editor, fragment, {
4353
- at: nextPath
4427
+ if (!editor.selection || !focusBlock || !focusBlockPath) {
4428
+ select !== "none" && DOMEditor.focus(editor);
4429
+ const [lastBlock, lastBlockPath] = getLastBlock({
4430
+ editor
4354
4431
  });
4355
- const [nextBlock, nextBlockPath] = Editor.node(action.editor, Path.next(focusPath), {
4356
- depth: 1
4357
- }), nextChild = Node.child(nextBlock, 0);
4358
- !action.editor.isTextSpan(nextChild) && Transforms.insertNodes(action.editor, {
4359
- _key: context.keyGenerator(),
4360
- _type: "span",
4361
- text: "",
4362
- marks: []
4363
- }, {
4364
- at: [nextBlockPath[0], 0]
4365
- }), Transforms.select(action.editor, {
4366
- anchor: {
4367
- path: [nextPath[0], 0],
4368
- offset: 0
4369
- },
4370
- focus: {
4371
- path: [nextPath[0], 0],
4372
- offset: 0
4432
+ if (placement === "before")
4433
+ Transforms.insertNodes(editor, [block], {
4434
+ at: [0]
4435
+ }), select === "start" ? Transforms.select(editor, Editor.start(editor, [0])) : select === "end" && Transforms.select(editor, Editor.end(editor, [0]));
4436
+ else if (placement === "after") {
4437
+ const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
4438
+ Transforms.insertNodes(editor, [block], {
4439
+ at: nextPath,
4440
+ select: !1
4441
+ }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4442
+ } else {
4443
+ if (lastBlock && isEqualToEmptyEditor([lastBlock], schema)) {
4444
+ Transforms.removeNodes(editor, {
4445
+ at: lastBlockPath
4446
+ }), Transforms.insertNodes(editor, [block], {
4447
+ at: lastBlockPath,
4448
+ select: !1
4449
+ }), Transforms.deselect(editor), select === "start" ? Transforms.select(editor, Editor.start(editor, lastBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, lastBlockPath));
4450
+ return;
4373
4451
  }
4452
+ if (editor.isTextBlock(block) && lastBlock && editor.isTextBlock(lastBlock)) {
4453
+ const selectionBefore = Editor.end(editor, lastBlockPath);
4454
+ Transforms.insertFragment(editor, [block], {
4455
+ at: Editor.end(editor, lastBlockPath)
4456
+ }), select === "start" ? Transforms.select(editor, selectionBefore) : select === "none" && Transforms.deselect(editor);
4457
+ return;
4458
+ }
4459
+ const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
4460
+ Transforms.insertNodes(editor, [block], {
4461
+ at: nextPath,
4462
+ select: !1
4463
+ }), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4464
+ }
4465
+ } else if (placement === "before") {
4466
+ const currentSelection = editor.selection;
4467
+ Transforms.insertNodes(editor, [block], {
4468
+ at: focusBlockPath,
4469
+ select: !1
4374
4470
  });
4375
- return;
4376
- }
4377
- if (!action.editor.isTextBlock(focusBlock)) {
4378
- const nextPath = [focusPath[0] + 1];
4379
- Transforms.insertNodes(action.editor, fragment, {
4380
- at: nextPath
4471
+ const adjustedSelection = Range.transform(currentSelection, {
4472
+ type: "move_node",
4473
+ path: focusBlockPath,
4474
+ newPath: [focusBlockPath[0] + 1]
4381
4475
  });
4382
- const [nextBlock, nextBlockPath] = Editor.node(action.editor, Path.next(focusPath), {
4383
- depth: 1
4384
- }), nextChild = Node.child(nextBlock, 0);
4385
- !action.editor.isTextSpan(nextChild) && Transforms.insertNodes(action.editor, {
4386
- _key: context.keyGenerator(),
4387
- _type: "span",
4388
- text: "",
4389
- marks: []
4390
- }, {
4391
- at: [nextBlockPath[0], 0]
4392
- }), Transforms.select(action.editor, {
4393
- anchor: {
4394
- path: [nextPath[0], 0],
4395
- offset: 0
4396
- },
4397
- focus: {
4398
- path: [nextPath[0], 0],
4399
- offset: 0
4476
+ adjustedSelection ? Transforms.select(editor, adjustedSelection) : Transforms.select(editor, currentSelection), select === "start" ? Transforms.select(editor, Editor.start(editor, focusBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, focusBlockPath));
4477
+ } else if (placement === "after") {
4478
+ const nextPath = [focusBlockPath[0] + 1], currentSelection = editor.selection;
4479
+ Transforms.insertNodes(editor, [block], {
4480
+ at: nextPath,
4481
+ select: !1
4482
+ }), Transforms.select(editor, currentSelection), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4483
+ } else {
4484
+ const currentSelection = editor.selection, focusBlockStartPoint = Editor.start(editor, focusBlockPath);
4485
+ if (editor.isTextBlock(focusBlock) && editor.isTextBlock(block)) {
4486
+ if (select === "end") {
4487
+ Transforms.insertFragment(editor, [block], {
4488
+ voids: !0
4489
+ });
4490
+ return;
4400
4491
  }
4401
- });
4492
+ Transforms.insertFragment(editor, [block], {
4493
+ at: currentSelection,
4494
+ voids: !0
4495
+ }), select === "start" ? Point.equals(currentSelection.anchor, focusBlockStartPoint) ? Transforms.select(editor, Editor.start(editor, focusBlockPath)) : Transforms.select(editor, currentSelection) : Point.equals(currentSelection.anchor, focusBlockStartPoint) || Transforms.select(editor, currentSelection);
4496
+ } else if (editor.isTextBlock(focusBlock)) {
4497
+ const focusBlockStartPoint2 = Editor.start(editor, focusBlockPath), focusBlockEndPoint = Editor.end(editor, focusBlockPath);
4498
+ if (Point.equals(currentSelection.anchor, focusBlockStartPoint2))
4499
+ Transforms.insertNodes(editor, [block], {
4500
+ at: focusBlockPath,
4501
+ select: !1
4502
+ }), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, focusBlockPath)), isEqualToEmptyEditor([focusBlock], schema) && Transforms.removeNodes(editor, {
4503
+ at: Path.next(focusBlockPath)
4504
+ });
4505
+ else if (Point.equals(currentSelection.focus, focusBlockEndPoint)) {
4506
+ const nextPath = [focusBlockPath[0] + 1];
4507
+ Transforms.insertNodes(editor, [block], {
4508
+ at: nextPath,
4509
+ select: !1
4510
+ }), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, nextPath));
4511
+ } else {
4512
+ const currentSelection2 = editor.selection, [focusChild] = getFocusChild({
4513
+ editor
4514
+ });
4515
+ if (focusChild && editor.isTextSpan(focusChild))
4516
+ Transforms.insertFragment(editor, [block], {
4517
+ at: currentSelection2
4518
+ }), select === "start" || select === "end" ? Transforms.select(editor, [focusBlockPath[0] + 1]) : Transforms.select(editor, currentSelection2);
4519
+ else {
4520
+ const nextPath = [focusBlockPath[0] + 1];
4521
+ Transforms.insertNodes(editor, [block], {
4522
+ at: nextPath,
4523
+ select: !1
4524
+ }), Transforms.select(editor, currentSelection2), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4525
+ }
4526
+ }
4527
+ } else {
4528
+ Transforms.insertNodes(editor, [block], {
4529
+ select: !1
4530
+ });
4531
+ const nextPath = [focusBlockPath[0] + 1];
4532
+ select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
4533
+ }
4534
+ }
4535
+ }
4536
+ const selectActionImplementation = ({
4537
+ action
4538
+ }) => {
4539
+ const newSelection = toSlateRange(action.selection, action.editor);
4540
+ newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
4541
+ }, selectNextBlockActionImplementation = ({
4542
+ context,
4543
+ action
4544
+ }) => {
4545
+ if (!action.editor.selection) {
4546
+ console.error("Unable to select previous block without a selection");
4402
4547
  return;
4403
4548
  }
4404
- if (action.editor.isTextBlock(focusBlock) && action.editor.isTextBlock(fragment[0])) {
4405
- const {
4406
- markDefs
4407
- } = focusBlock;
4408
- isEqual(markDefs, fragment[0].markDefs) || Transforms.setNodes(action.editor, {
4409
- markDefs: uniq([...fragment[0].markDefs || [], ...markDefs || []])
4410
- }, {
4411
- at: focusPath,
4412
- mode: "lowest",
4413
- voids: !1
4414
- });
4549
+ const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1], position = action.select === "end" ? Editor.end(action.editor, nextBlockPath) : Editor.start(action.editor, nextBlockPath), newSelection = toPortableTextRange(action.editor.children, {
4550
+ anchor: position,
4551
+ focus: position
4552
+ }, context.schema);
4553
+ if (!newSelection) {
4554
+ console.error("Could not find selection for next block");
4555
+ return;
4415
4556
  }
4416
- isEqualToEmptyEditor(action.editor.children, context.schema) ? (Transforms.splitNodes(action.editor, {
4417
- at: [0, 0]
4418
- }), action.editor.insertFragment(fragment), Transforms.removeNodes(action.editor, {
4419
- at: [0]
4420
- })) : action.editor.insertFragment(fragment);
4421
- }, insertInlineObjectActionImplementation = ({
4557
+ selectActionImplementation({
4558
+ context,
4559
+ action: {
4560
+ type: "select",
4561
+ selection: newSelection,
4562
+ editor: action.editor
4563
+ }
4564
+ });
4565
+ }, selectPreviousBlockActionImplementation = ({
4422
4566
  context,
4423
4567
  action
4424
4568
  }) => {
4425
- if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
4426
- console.error("Unable to insert unknown inline object");
4569
+ if (!action.editor.selection) {
4570
+ console.error("Unable to select previous block without a selection");
4427
4571
  return;
4428
4572
  }
4429
- if (!action.editor.selection) {
4430
- console.error("Unable to insert inline object without selection");
4573
+ const blockPath = action.editor.selection.focus.path.slice(0, 1);
4574
+ if (!Path.hasPrevious(blockPath)) {
4575
+ console.error("There's no previous block to select");
4431
4576
  return;
4432
4577
  }
4433
- const [focusTextBlock] = Array.from(Editor.nodes(action.editor, {
4434
- at: action.editor.selection.focus.path,
4435
- match: (node) => action.editor.isTextBlock(node)
4436
- })).at(0) ?? [void 0, void 0];
4437
- if (!focusTextBlock) {
4438
- console.error("Unable to perform action without focus text block");
4578
+ const position = action.select === "end" ? Editor.end(action.editor, Path.previous(blockPath)) : Editor.start(action.editor, Path.previous(blockPath)), newSelection = toPortableTextRange(action.editor.children, {
4579
+ anchor: position,
4580
+ focus: position
4581
+ }, context.schema);
4582
+ if (!newSelection) {
4583
+ console.error("Could not find selection for previous block");
4439
4584
  return;
4440
4585
  }
4441
- const child = toSlateValue([{
4442
- _type: context.schema.block.name,
4443
- _key: context.keyGenerator(),
4444
- children: [{
4445
- _type: action.inlineObject.name,
4446
- _key: context.keyGenerator(),
4447
- ...action.inlineObject.value ?? {}
4448
- }]
4449
- }], {
4450
- schemaTypes: context.schema
4451
- }).at(0)?.children.at(0);
4586
+ selectActionImplementation({
4587
+ context,
4588
+ action: {
4589
+ type: "select",
4590
+ selection: newSelection,
4591
+ editor: action.editor
4592
+ }
4593
+ });
4594
+ }, insertBlocksActionImplementation = ({
4595
+ context,
4596
+ action
4597
+ }) => {
4598
+ const parsedBlocks = parseBlocks({
4599
+ context,
4600
+ blocks: action.blocks,
4601
+ options: {
4602
+ refreshKeys: !1
4603
+ }
4604
+ });
4605
+ if (parsedBlocks.length === 0)
4606
+ throw new Error(`Failed to parse blocks ${JSON.stringify(action.blocks)}`);
4607
+ const fragment = toSlateValue(parsedBlocks, {
4608
+ schemaTypes: context.schema
4609
+ });
4610
+ if (fragment.length === 0)
4611
+ throw new Error(`Failed to convert blocks to Slate fragment ${JSON.stringify(parsedBlocks)}`);
4612
+ const [focusBlock] = getFocusBlock({
4613
+ editor: action.editor
4614
+ });
4615
+ if (action.placement === "before") {
4616
+ let index = 0;
4617
+ for (const block of fragment)
4618
+ insertBlock({
4619
+ block,
4620
+ placement: index === 0 ? "before" : "after",
4621
+ select: "end",
4622
+ editor: action.editor,
4623
+ schema: context.schema
4624
+ }), index++;
4625
+ } else if (action.placement === "after")
4626
+ for (const block of fragment)
4627
+ insertBlock({
4628
+ block,
4629
+ placement: "after",
4630
+ select: "end",
4631
+ editor: action.editor,
4632
+ schema: context.schema
4633
+ });
4634
+ else if (focusBlock && action.editor.isTextBlock(focusBlock)) {
4635
+ if (fragment.length === 1) {
4636
+ insertBlock({
4637
+ block: fragment[0],
4638
+ placement: "auto",
4639
+ select: "end",
4640
+ editor: action.editor,
4641
+ schema: context.schema
4642
+ });
4643
+ return;
4644
+ }
4645
+ let index = 0;
4646
+ for (const block of fragment)
4647
+ index === 0 ? (insertBreakActionImplementation({
4648
+ context,
4649
+ action: {
4650
+ type: "insert.break",
4651
+ editor: action.editor
4652
+ }
4653
+ }), selectPreviousBlockActionImplementation({
4654
+ context,
4655
+ action: {
4656
+ type: "select.previous block",
4657
+ editor: action.editor,
4658
+ select: "end"
4659
+ }
4660
+ }), insertBlock({
4661
+ block,
4662
+ placement: "auto",
4663
+ select: "end",
4664
+ editor: action.editor,
4665
+ schema: context.schema
4666
+ })) : index === fragment.length - 1 ? (selectNextBlockActionImplementation({
4667
+ context,
4668
+ action: {
4669
+ type: "select.next block",
4670
+ editor: action.editor,
4671
+ select: "start"
4672
+ }
4673
+ }), insertBlock({
4674
+ block,
4675
+ placement: "auto",
4676
+ select: "end",
4677
+ editor: action.editor,
4678
+ schema: context.schema
4679
+ })) : insertBlock({
4680
+ block,
4681
+ placement: "after",
4682
+ select: "end",
4683
+ editor: action.editor,
4684
+ schema: context.schema
4685
+ }), index++;
4686
+ } else
4687
+ for (const block of fragment)
4688
+ insertBlock({
4689
+ block,
4690
+ placement: "auto",
4691
+ select: "end",
4692
+ editor: action.editor,
4693
+ schema: context.schema
4694
+ });
4695
+ }, deserializationSuccessActionImplementation = ({
4696
+ context,
4697
+ action
4698
+ }) => {
4699
+ insertBlocksActionImplementation({
4700
+ context,
4701
+ action: {
4702
+ type: "insert.blocks",
4703
+ blocks: action.data,
4704
+ editor: action.editor,
4705
+ placement: "auto"
4706
+ }
4707
+ });
4708
+ }, effectActionImplementation = ({
4709
+ action
4710
+ }) => {
4711
+ action.effect();
4712
+ }, focusActionImplementation = ({
4713
+ action
4714
+ }) => {
4715
+ ReactEditor.focus(action.editor);
4716
+ }, insertInlineObjectActionImplementation = ({
4717
+ context,
4718
+ action
4719
+ }) => {
4720
+ if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
4721
+ console.error("Unable to insert unknown inline object");
4722
+ return;
4723
+ }
4724
+ if (!action.editor.selection) {
4725
+ console.error("Unable to insert inline object without selection");
4726
+ return;
4727
+ }
4728
+ const [focusTextBlock] = Array.from(Editor.nodes(action.editor, {
4729
+ at: action.editor.selection.focus.path,
4730
+ match: (node) => action.editor.isTextBlock(node)
4731
+ })).at(0) ?? [void 0, void 0];
4732
+ if (!focusTextBlock) {
4733
+ console.error("Unable to perform action without focus text block");
4734
+ return;
4735
+ }
4736
+ const child = toSlateValue([{
4737
+ _type: context.schema.block.name,
4738
+ _key: context.keyGenerator(),
4739
+ children: [{
4740
+ _type: action.inlineObject.name,
4741
+ _key: context.keyGenerator(),
4742
+ ...action.inlineObject.value ?? {}
4743
+ }]
4744
+ }], {
4745
+ schemaTypes: context.schema
4746
+ }).at(0)?.children.at(0);
4452
4747
  if (!child) {
4453
4748
  console.error("Unable to insert inline object");
4454
4749
  return;
@@ -4483,29 +4778,140 @@ const blockSetBehaviorActionImplementation = ({
4483
4778
  text: action.text,
4484
4779
  marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
4485
4780
  });
4486
- }, insertBlockActionImplementation = ({
4781
+ }, insertBlockObjectActionImplementation = ({
4487
4782
  context,
4488
4783
  action
4489
4784
  }) => {
4490
- const parsedBlock = parseBlock({
4491
- block: action.block,
4785
+ insertBlockActionImplementation({
4492
4786
  context,
4493
- options: {
4494
- refreshKeys: !1
4787
+ action: {
4788
+ type: "insert.block",
4789
+ block: {
4790
+ _key: context.keyGenerator(),
4791
+ _type: action.blockObject.name,
4792
+ ...action.blockObject.value ? action.blockObject.value : {}
4793
+ },
4794
+ editor: action.editor,
4795
+ placement: action.placement
4495
4796
  }
4496
4797
  });
4497
- if (!parsedBlock)
4498
- throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`);
4499
- const fragment = toSlateValue([parsedBlock], {
4500
- schemaTypes: context.schema
4501
- })[0];
4502
- if (!fragment)
4503
- throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
4504
- insertBlock({
4505
- block: fragment,
4506
- placement: action.placement,
4507
- editor: action.editor,
4508
- schema: context.schema
4798
+ }, insertTextActionImplementation = ({
4799
+ action
4800
+ }) => {
4801
+ action.editor.insertText(action.text);
4802
+ }, insertTextBlockActionImplementation = ({
4803
+ context,
4804
+ action
4805
+ }) => {
4806
+ insertBlockActionImplementation({
4807
+ context,
4808
+ action: {
4809
+ type: "insert.block",
4810
+ block: {
4811
+ _key: context.keyGenerator(),
4812
+ _type: context.schema.block.name,
4813
+ children: action.textBlock?.children?.map((child) => ({
4814
+ ...child,
4815
+ _key: context.keyGenerator()
4816
+ })) ?? [{
4817
+ _type: context.schema.span.name,
4818
+ _key: context.keyGenerator(),
4819
+ text: "",
4820
+ marks: []
4821
+ }],
4822
+ markDefs: [],
4823
+ style: context.schema.styles[0].value ?? "normal"
4824
+ },
4825
+ editor: action.editor,
4826
+ placement: action.placement,
4827
+ select: "start"
4828
+ }
4829
+ });
4830
+ }, moveBlockActionImplementation = ({
4831
+ action
4832
+ }) => {
4833
+ const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
4834
+ Transforms.moveNodes(action.editor, {
4835
+ at,
4836
+ to,
4837
+ mode: "highest"
4838
+ });
4839
+ }, moveBlockDownActionImplementation = ({
4840
+ context,
4841
+ action
4842
+ }) => {
4843
+ const at = [toSlatePath(action.at, action.editor)[0]], to = [Path.next(at)[0]], selection = toPortableTextRange(action.editor.children, {
4844
+ anchor: {
4845
+ path: to,
4846
+ offset: 0
4847
+ },
4848
+ focus: {
4849
+ path: to,
4850
+ offset: 0
4851
+ }
4852
+ }, context.schema), destinationBlockKey = selection && isKeyedSegment$1(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
4853
+ if (destinationBlockKey === void 0) {
4854
+ console.error("Could not find destination block key");
4855
+ return;
4856
+ }
4857
+ moveBlockActionImplementation({
4858
+ context,
4859
+ action: {
4860
+ type: "move.block",
4861
+ at: action.at,
4862
+ to: [{
4863
+ _key: destinationBlockKey
4864
+ }],
4865
+ editor: action.editor
4866
+ }
4867
+ });
4868
+ }, moveBlockUpActionImplementation = ({
4869
+ context,
4870
+ action
4871
+ }) => {
4872
+ const at = [toSlatePath(action.at, action.editor)[0]];
4873
+ if (!Path.hasPrevious(at))
4874
+ return;
4875
+ const to = [Path.previous(at)[0]], selection = toPortableTextRange(action.editor.children, {
4876
+ anchor: {
4877
+ path: to,
4878
+ offset: 0
4879
+ },
4880
+ focus: {
4881
+ path: to,
4882
+ offset: 0
4883
+ }
4884
+ }, context.schema), destinationBlockKey = selection && isKeyedSegment$1(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
4885
+ if (destinationBlockKey === void 0) {
4886
+ console.error("Could not find destination block key");
4887
+ return;
4888
+ }
4889
+ moveBlockActionImplementation({
4890
+ context,
4891
+ action: {
4892
+ type: "move.block",
4893
+ at: action.at,
4894
+ to: [{
4895
+ _key: destinationBlockKey
4896
+ }],
4897
+ editor: action.editor
4898
+ }
4899
+ });
4900
+ }, noopActionImplementation = () => {
4901
+ }, serializationFailureActionImplementation = ({
4902
+ action
4903
+ }) => {
4904
+ console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
4905
+ }, serializationSuccessActionImplementation = ({
4906
+ context,
4907
+ action
4908
+ }) => {
4909
+ dataTransferSetActionImplementation({
4910
+ context,
4911
+ action: {
4912
+ ...action,
4913
+ type: "data transfer.set"
4914
+ }
4509
4915
  });
4510
4916
  }, behaviorActionImplementations = {
4511
4917
  "annotation.add": addAnnotationActionImplementation,
@@ -4513,72 +4919,19 @@ const blockSetBehaviorActionImplementation = ({
4513
4919
  "annotation.toggle": toggleAnnotationActionImplementation,
4514
4920
  "block.set": blockSetBehaviorActionImplementation,
4515
4921
  "block.unset": blockUnsetBehaviorActionImplementation,
4516
- blur: ({
4517
- action
4518
- }) => {
4519
- ReactEditor.blur(action.editor);
4520
- },
4922
+ blur: blurActionImplementation,
4521
4923
  "data transfer.set": dataTransferSetActionImplementation,
4522
4924
  "decorator.add": decoratorAddActionImplementation,
4523
4925
  "decorator.remove": removeDecoratorActionImplementation,
4524
4926
  "decorator.toggle": toggleDecoratorActionImplementation,
4525
- focus: ({
4526
- action
4527
- }) => {
4528
- ReactEditor.focus(action.editor);
4529
- },
4927
+ focus: focusActionImplementation,
4530
4928
  delete: deleteActionImplementation,
4531
- "delete.backward": ({
4532
- action
4533
- }) => {
4534
- action.editor.deleteBackward(action.unit);
4535
- },
4536
- "delete.forward": ({
4537
- action
4538
- }) => {
4539
- deleteForward(action.editor, action.unit);
4540
- },
4541
- "delete.block": ({
4542
- action
4543
- }) => {
4544
- const range = toSlateRange({
4545
- anchor: {
4546
- path: action.blockPath,
4547
- offset: 0
4548
- },
4549
- focus: {
4550
- path: action.blockPath,
4551
- offset: 0
4552
- }
4553
- }, action.editor);
4554
- if (!range) {
4555
- console.error("Unable to find Slate range from selection points");
4556
- return;
4557
- }
4558
- Transforms.removeNodes(action.editor, {
4559
- at: range
4560
- });
4561
- },
4929
+ "delete.backward": deleteBackwardActionImplementation,
4930
+ "delete.forward": deleteForwardActionImplementation,
4931
+ "delete.block": deleteBlockActionImplementation,
4562
4932
  "delete.text": deleteTextActionImplementation,
4563
- "deserialization.failure": ({
4564
- action
4565
- }) => {
4566
- console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
4567
- },
4568
- "deserialization.success": ({
4569
- context,
4570
- action
4571
- }) => {
4572
- insertBlocksActionImplementation({
4573
- context,
4574
- action: {
4575
- type: "insert.blocks",
4576
- blocks: action.data,
4577
- editor: action.editor,
4578
- placement: "auto"
4579
- }
4580
- });
4581
- },
4933
+ "deserialization.failure": deserializationFailureActionImplementation,
4934
+ "deserialization.success": deserializationSuccessActionImplementation,
4582
4935
  "history.redo": historyRedoActionImplementation,
4583
4936
  "history.undo": historyUndoActionImplementation,
4584
4937
  "insert.block": insertBlockActionImplementation,
@@ -4588,129 +4941,21 @@ const blockSetBehaviorActionImplementation = ({
4588
4941
  "insert.inline object": insertInlineObjectActionImplementation,
4589
4942
  "insert.soft break": insertSoftBreakActionImplementation,
4590
4943
  "insert.span": insertSpanActionImplementation,
4591
- "insert.text": ({
4592
- action
4593
- }) => {
4594
- insertText(action.editor, action.text);
4595
- },
4596
- "insert.text block": ({
4597
- context,
4598
- action
4599
- }) => {
4600
- const block = toSlateValue([{
4601
- _key: context.keyGenerator(),
4602
- _type: context.schema.block.name,
4603
- style: context.schema.styles[0].value ?? "normal",
4604
- markDefs: [],
4605
- children: action.textBlock?.children?.map((child) => ({
4606
- ...child,
4607
- _key: context.keyGenerator()
4608
- })) ?? [{
4609
- _type: context.schema.span.name,
4610
- _key: context.keyGenerator(),
4611
- text: ""
4612
- }]
4613
- }], {
4614
- schemaTypes: context.schema
4615
- })[0];
4616
- insertBlock({
4617
- block,
4618
- editor: action.editor,
4619
- schema: context.schema,
4620
- placement: action.placement
4621
- });
4622
- },
4623
- effect: ({
4624
- action
4625
- }) => {
4626
- action.effect();
4627
- },
4944
+ "insert.text": insertTextActionImplementation,
4945
+ "insert.text block": insertTextBlockActionImplementation,
4946
+ effect: effectActionImplementation,
4628
4947
  "list item.add": addListItemActionImplementation,
4629
4948
  "list item.remove": removeListItemActionImplementation,
4630
4949
  "list item.toggle": toggleListItemActionImplementation,
4631
- "move.block": ({
4632
- action
4633
- }) => {
4634
- const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
4635
- Transforms.moveNodes(action.editor, {
4636
- at,
4637
- to,
4638
- mode: "highest"
4639
- });
4640
- },
4641
- "move.block down": ({
4642
- action
4643
- }) => {
4644
- const at = [toSlatePath(action.at, action.editor)[0]], to = [Path.next(at)[0]];
4645
- Transforms.moveNodes(action.editor, {
4646
- at,
4647
- to,
4648
- mode: "highest"
4649
- });
4650
- },
4651
- "move.block up": ({
4652
- action
4653
- }) => {
4654
- const at = [toSlatePath(action.at, action.editor)[0]];
4655
- if (!Path.hasPrevious(at))
4656
- return;
4657
- const to = [Path.previous(at)[0]];
4658
- Transforms.moveNodes(action.editor, {
4659
- at,
4660
- to,
4661
- mode: "highest"
4662
- });
4663
- },
4664
- noop: () => {
4665
- },
4666
- select: ({
4667
- action
4668
- }) => {
4669
- const newSelection = toSlateRange(action.selection, action.editor);
4670
- newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
4671
- },
4672
- "select.previous block": ({
4673
- action
4674
- }) => {
4675
- if (!action.editor.selection) {
4676
- console.error("Unable to select previous block without a selection");
4677
- return;
4678
- }
4679
- const blockPath = action.editor.selection.focus.path.slice(0, 1);
4680
- if (!Path.hasPrevious(blockPath)) {
4681
- console.error("There's no previous block to select");
4682
- return;
4683
- }
4684
- const previousBlockPath = Path.previous(blockPath);
4685
- Transforms.select(action.editor, previousBlockPath);
4686
- },
4687
- "select.next block": ({
4688
- action
4689
- }) => {
4690
- if (!action.editor.selection) {
4691
- console.error("Unable to select next block without a selection");
4692
- return;
4693
- }
4694
- const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
4695
- Transforms.select(action.editor, nextBlockPath);
4696
- },
4697
- "serialization.failure": ({
4698
- action
4699
- }) => {
4700
- console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
4701
- },
4702
- "serialization.success": ({
4703
- context,
4704
- action
4705
- }) => {
4706
- dataTransferSetActionImplementation({
4707
- context,
4708
- action: {
4709
- ...action,
4710
- type: "data transfer.set"
4711
- }
4712
- });
4713
- },
4950
+ "move.block": moveBlockActionImplementation,
4951
+ "move.block down": moveBlockDownActionImplementation,
4952
+ "move.block up": moveBlockUpActionImplementation,
4953
+ noop: noopActionImplementation,
4954
+ select: selectActionImplementation,
4955
+ "select.previous block": selectPreviousBlockActionImplementation,
4956
+ "select.next block": selectNextBlockActionImplementation,
4957
+ "serialization.failure": serializationFailureActionImplementation,
4958
+ "serialization.success": serializationSuccessActionImplementation,
4714
4959
  "style.toggle": toggleStyleActionImplementation,
4715
4960
  "style.add": addStyleActionImplementation,
4716
4961
  "style.remove": removeStyleActionImplementation
@@ -4718,27 +4963,6 @@ const blockSetBehaviorActionImplementation = ({
4718
4963
  function performAction({
4719
4964
  context,
4720
4965
  action
4721
- }) {
4722
- switch (action.type) {
4723
- case "noop":
4724
- break;
4725
- case "effect": {
4726
- behaviorActionImplementations.effect({
4727
- context,
4728
- action
4729
- });
4730
- break;
4731
- }
4732
- default:
4733
- performDefaultAction({
4734
- context,
4735
- action
4736
- });
4737
- }
4738
- }
4739
- function performDefaultAction({
4740
- context,
4741
- action
4742
4966
  }) {
4743
4967
  switch (action.type) {
4744
4968
  case "annotation.add": {
@@ -4860,6 +5084,13 @@ function performDefaultAction({
4860
5084
  });
4861
5085
  break;
4862
5086
  }
5087
+ case "effect": {
5088
+ behaviorActionImplementations.effect({
5089
+ context,
5090
+ action
5091
+ });
5092
+ break;
5093
+ }
4863
5094
  case "focus": {
4864
5095
  behaviorActionImplementations.focus({
4865
5096
  context,
@@ -4986,6 +5217,8 @@ function performDefaultAction({
4986
5217
  });
4987
5218
  break;
4988
5219
  }
5220
+ case "noop":
5221
+ break;
4989
5222
  case "select": {
4990
5223
  behaviorActionImplementations.select({
4991
5224
  context,
@@ -5091,12 +5324,10 @@ function createWithEventListeners(editorActor, subscriptions) {
5091
5324
  });
5092
5325
  const {
5093
5326
  deleteBackward,
5094
- deleteForward: deleteForward2,
5327
+ deleteForward,
5095
5328
  insertBreak,
5096
- insertData,
5097
5329
  insertText: insertText2,
5098
- select,
5099
- setFragmentData
5330
+ select
5100
5331
  } = editor;
5101
5332
  return editor.deleteBackward = (unit) => {
5102
5333
  if (isApplyingBehaviorActions(editor)) {
@@ -5113,7 +5344,7 @@ function createWithEventListeners(editorActor, subscriptions) {
5113
5344
  });
5114
5345
  }, editor.deleteForward = (unit) => {
5115
5346
  if (isApplyingBehaviorActions(editor)) {
5116
- deleteForward2(unit);
5347
+ deleteForward(unit);
5117
5348
  return;
5118
5349
  }
5119
5350
  editorActor.send({
@@ -5136,19 +5367,8 @@ function createWithEventListeners(editorActor, subscriptions) {
5136
5367
  },
5137
5368
  editor
5138
5369
  });
5139
- }, editor.insertData = (dataTransfer) => {
5140
- if (isApplyingBehaviorActions(editor)) {
5141
- insertData(dataTransfer);
5142
- return;
5143
- }
5144
- editorActor.send({
5145
- type: "behavior event",
5146
- behaviorEvent: {
5147
- type: "deserialize",
5148
- dataTransfer
5149
- },
5150
- editor
5151
- });
5370
+ }, editor.insertData = () => {
5371
+ console.warn("Unexpected call to .insertData(...)");
5152
5372
  }, editor.insertSoftBreak = () => {
5153
5373
  if (isApplyingBehaviorActions(editor)) {
5154
5374
  insertSoftBreakActionImplementation({
@@ -5225,20 +5445,8 @@ function createWithEventListeners(editorActor, subscriptions) {
5225
5445
  select(location);
5226
5446
  }
5227
5447
  });
5228
- }, editor.setFragmentData = (dataTransfer, originEvent) => {
5229
- if (isApplyingBehaviorActions(editor)) {
5230
- setFragmentData(dataTransfer);
5231
- return;
5232
- }
5233
- dataTransfer.clearData(), editorActor.send({
5234
- type: "behavior event",
5235
- behaviorEvent: {
5236
- type: "serialize",
5237
- dataTransfer,
5238
- originEvent: originEvent ?? "unknown"
5239
- },
5240
- editor
5241
- });
5448
+ }, editor.setFragmentData = () => {
5449
+ console.warn("Unexpected call to .setFragmentData(...)");
5242
5450
  }, editor.undo = () => {
5243
5451
  if (isApplyingBehaviorActions(editor)) {
5244
5452
  performAction({
@@ -6069,16 +6277,8 @@ const keyIs = {
6069
6277
  event
6070
6278
  }, deserializeEvent) => [raise({
6071
6279
  ...deserializeEvent,
6072
- dataTransfer: event.dataTransfer
6073
- })]]
6074
- }), raiseInsertBlocks = defineBehavior({
6075
- on: "deserialization.success",
6076
- actions: [({
6077
- event
6078
- }) => [raise({
6079
- type: "insert.blocks",
6080
- blocks: event.data,
6081
- placement: "auto"
6280
+ dataTransfer: event.dataTransfer,
6281
+ originEvent: event.originEvent
6082
6282
  })]]
6083
6283
  }), raiseSerializationSuccessOrFailure = defineBehavior({
6084
6284
  on: "serialize",
@@ -6090,7 +6290,10 @@ const keyIs = {
6090
6290
  return !1;
6091
6291
  const serializeEvents = snapshot.context.converters.map((converter) => converter.serialize({
6092
6292
  snapshot,
6093
- event
6293
+ event: {
6294
+ ...event,
6295
+ originEvent: event.originEvent.type
6296
+ }
6094
6297
  }));
6095
6298
  return serializeEvents.length === 0 ? !1 : serializeEvents;
6096
6299
  },
@@ -6098,9 +6301,69 @@ const keyIs = {
6098
6301
  event
6099
6302
  }, serializeEvents) => serializeEvents.map((serializeEvent) => raise({
6100
6303
  ...serializeEvent,
6304
+ originEvent: event.originEvent,
6101
6305
  dataTransfer: event.dataTransfer
6102
6306
  }))]
6103
- }), raiseDataTransferSet = defineBehavior({
6307
+ }), defaultBehaviors = [defineBehavior({
6308
+ on: "copy",
6309
+ guard: ({
6310
+ snapshot
6311
+ }) => {
6312
+ const focusSpan = getFocusSpan(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
6313
+ return focusSpan && selectionCollapsed;
6314
+ },
6315
+ actions: [() => [{
6316
+ type: "noop"
6317
+ }]]
6318
+ }), defineBehavior({
6319
+ on: "copy",
6320
+ actions: [({
6321
+ event
6322
+ }) => [raise({
6323
+ type: "serialize",
6324
+ dataTransfer: event.data,
6325
+ originEvent: event
6326
+ })]]
6327
+ }), defineBehavior({
6328
+ on: "cut",
6329
+ guard: ({
6330
+ snapshot
6331
+ }) => {
6332
+ const focusSpan = getFocusSpan(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
6333
+ return focusSpan && selectionCollapsed;
6334
+ },
6335
+ actions: [() => [{
6336
+ type: "noop"
6337
+ }]]
6338
+ }), defineBehavior({
6339
+ on: "cut",
6340
+ guard: ({
6341
+ snapshot
6342
+ }) => snapshot.context.selection ? {
6343
+ selection: snapshot.context.selection
6344
+ } : !1,
6345
+ actions: [({
6346
+ event
6347
+ }, {
6348
+ selection
6349
+ }) => [raise({
6350
+ type: "serialize",
6351
+ dataTransfer: event.dataTransfer,
6352
+ originEvent: event
6353
+ }), raise({
6354
+ type: "delete",
6355
+ selection
6356
+ })]]
6357
+ }), defineBehavior({
6358
+ on: "drag.dragstart",
6359
+ actions: [({
6360
+ event
6361
+ }) => [raise({
6362
+ type: "serialize",
6363
+ dataTransfer: event.dataTransfer,
6364
+ originEvent: event
6365
+ })]]
6366
+ }), defineBehavior({
6104
6367
  on: "serialization.success",
6105
6368
  actions: [({
6106
6369
  event
@@ -6110,23 +6373,129 @@ const keyIs = {
6110
6373
  dataTransfer: event.dataTransfer,
6111
6374
  mimeType: event.mimeType
6112
6375
  })]]
6113
- }), defaultBehaviors = [toggleAnnotationOff, toggleAnnotationOn, toggleDecoratorOff, toggleDecoratorOn, toggleListItemOff, toggleListItemOn, toggleStyleOff, toggleStyleOn, raiseDeserializationSuccessOrFailure, raiseInsertBlocks, raiseSerializationSuccessOrFailure, raiseDataTransferSet, raiseInsertSoftBreak];
6114
- function getActiveDecorators({
6115
- schema,
6116
- slateEditorInstance
6117
- }) {
6118
- const decorators = schema.decorators.map((decorator) => decorator.value);
6119
- return ({
6120
- ...Editor.marks(slateEditorInstance) ?? {}
6121
- }.marks ?? []).filter((mark) => decorators.includes(mark));
6122
- }
6376
+ }), defineBehavior({
6377
+ on: "drag.drop",
6378
+ guard: ({
6379
+ snapshot,
6380
+ event
6381
+ }) => {
6382
+ const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
6383
+ return dragOrigin ? isOverlappingSelection(dropPosition)({
6384
+ ...snapshot,
6385
+ context: {
6386
+ ...snapshot.context,
6387
+ selection: dragOrigin.selection
6388
+ }
6389
+ }) : !1;
6390
+ },
6391
+ actions: [() => [{
6392
+ type: "noop"
6393
+ }]]
6394
+ }), defineBehavior({
6395
+ on: "drag.drop",
6396
+ actions: [({
6397
+ event
6398
+ }) => [raise({
6399
+ type: "deserialize",
6400
+ dataTransfer: event.dataTransfer,
6401
+ originEvent: event
6402
+ })]]
6403
+ }), defineBehavior({
6404
+ on: "deserialization.success",
6405
+ guard: ({
6406
+ snapshot,
6407
+ event
6408
+ }) => {
6409
+ if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
6410
+ return !1;
6411
+ const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? isOverlappingSelection(dropPosition)({
6412
+ ...snapshot,
6413
+ context: {
6414
+ ...snapshot.context,
6415
+ selection: dragOrigin.selection
6416
+ }
6417
+ }) : !1, draggingEntireBlocks = isSelectingEntireBlocks({
6418
+ ...snapshot,
6419
+ context: {
6420
+ ...snapshot.context,
6421
+ selection: dragOrigin.selection
6422
+ }
6423
+ }), draggedBlocks = getSelectedBlocks({
6424
+ ...snapshot,
6425
+ context: {
6426
+ ...snapshot.context,
6427
+ selection: dragOrigin.selection
6428
+ }
6429
+ });
6430
+ return droppingOnDragOrigin ? !1 : {
6431
+ draggingEntireBlocks,
6432
+ draggedBlocks,
6433
+ dragOrigin
6434
+ };
6435
+ },
6436
+ actions: [({
6437
+ event
6438
+ }, {
6439
+ draggingEntireBlocks,
6440
+ draggedBlocks,
6441
+ dragOrigin
6442
+ }) => [raise({
6443
+ type: "insert.blocks",
6444
+ blocks: event.data,
6445
+ placement: draggingEntireBlocks ? event.originEvent.position.block === "start" ? "before" : event.originEvent.position.block === "end" ? "after" : "auto" : "auto"
6446
+ }), ...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
6447
+ type: "delete.block",
6448
+ blockPath: block.path
6449
+ })) : [raise({
6450
+ type: "delete",
6451
+ selection: dragOrigin.selection
6452
+ })]]]
6453
+ }), defineBehavior({
6454
+ on: "deserialization.success",
6455
+ actions: [({
6456
+ event
6457
+ }) => [raise({
6458
+ type: "insert.blocks",
6459
+ blocks: event.data,
6460
+ placement: "auto"
6461
+ })]]
6462
+ }), defineBehavior({
6463
+ on: "paste",
6464
+ guard: ({
6465
+ snapshot
6466
+ }) => snapshot.context.selection && isSelectionExpanded(snapshot) ? {
6467
+ selection: snapshot.context.selection
6468
+ } : !1,
6469
+ actions: [({
6470
+ event
6471
+ }, {
6472
+ selection
6473
+ }) => [raise({
6474
+ type: "delete",
6475
+ selection
6476
+ }), raise({
6477
+ type: "deserialize",
6478
+ dataTransfer: event.data,
6479
+ originEvent: event
6480
+ })]]
6481
+ }), defineBehavior({
6482
+ on: "paste",
6483
+ actions: [({
6484
+ event
6485
+ }) => [raise({
6486
+ type: "deserialize",
6487
+ dataTransfer: event.data,
6488
+ originEvent: event
6489
+ })]]
6490
+ }), toggleAnnotationOff, toggleAnnotationOn, toggleDecoratorOff, toggleDecoratorOn, toggleListItemOff, toggleListItemOn, toggleStyleOff, toggleStyleOn, raiseDeserializationSuccessOrFailure, raiseSerializationSuccessOrFailure, raiseInsertSoftBreak];
6123
6491
  function createEditorSnapshot({
6124
6492
  converters,
6125
6493
  editor,
6126
6494
  keyGenerator,
6127
6495
  readOnly,
6128
6496
  schema,
6129
- hasTag
6497
+ hasTag,
6498
+ internalDrag
6130
6499
  }) {
6131
6500
  const value = fromSlateValue(editor.children, schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema);
6132
6501
  return {
@@ -6143,7 +6512,8 @@ function createEditorSnapshot({
6143
6512
  value
6144
6513
  },
6145
6514
  beta: {
6146
- hasTag
6515
+ hasTag,
6516
+ internalDrag
6147
6517
  }
6148
6518
  };
6149
6519
  }
@@ -6225,10 +6595,10 @@ const editorMachine = setup({
6225
6595
  self
6226
6596
  }) => {
6227
6597
  assertEvent(event, ["behavior event", "custom behavior event"]);
6228
- const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
6598
+ const defaultAction = event.type === "custom behavior event" || isDragBehaviorEvent(event.behaviorEvent) || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "cut" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || isMouseBehaviorEvent(event.behaviorEvent) || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
6229
6599
  ...event.behaviorEvent,
6230
6600
  editor: event.editor
6231
- }, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === "*" || behavior.on === event.behaviorEvent.type);
6601
+ }, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === "*" ? !0 : isDragBehaviorEvent(event.behaviorEvent) && behavior.on === "drag.*" || behavior.on === event.behaviorEvent.type);
6232
6602
  if (eventBehaviors.length === 0) {
6233
6603
  if (defaultActionCallback) {
6234
6604
  withApplyingBehaviorActions(event.editor, () => {
@@ -6265,7 +6635,8 @@ const editorMachine = setup({
6265
6635
  "edit mode": "read only"
6266
6636
  }),
6267
6637
  schema: context.schema,
6268
- hasTag: (tag) => self.getSnapshot().hasTag(tag)
6638
+ hasTag: (tag) => self.getSnapshot().hasTag(tag),
6639
+ internalDrag: context.internalDrag
6269
6640
  });
6270
6641
  let behaviorOverwritten = !1;
6271
6642
  for (const eventBehavior of eventBehaviors) {
@@ -6613,11 +6984,26 @@ const editorMachine = setup({
6613
6984
  idle: {
6614
6985
  on: {
6615
6986
  dragstart: {
6987
+ actions: [assign({
6988
+ internalDrag: ({
6989
+ event
6990
+ }) => ({
6991
+ ghost: event.ghost,
6992
+ origin: event.origin
6993
+ })
6994
+ })],
6616
6995
  target: "dragging internally"
6617
6996
  }
6618
6997
  }
6619
6998
  },
6620
6999
  "dragging internally": {
7000
+ exit: [({
7001
+ context
7002
+ }) => {
7003
+ context.internalDrag?.ghost && document.body.removeChild(context.internalDrag.ghost);
7004
+ }, assign({
7005
+ internalDrag: void 0
7006
+ })],
6621
7007
  tags: ["dragging internally"],
6622
7008
  on: {
6623
7009
  dragend: {
@@ -6697,53 +7083,6 @@ const editorMachine = setup({
6697
7083
  }
6698
7084
  }
6699
7085
  });
6700
- function getValue({
6701
- editorActorSnapshot,
6702
- slateEditorInstance
6703
- }) {
6704
- return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
6705
- }
6706
- function defaultCompare(a, b) {
6707
- return a === b;
6708
- }
6709
- function useEditorSelector(editor, selector, t0) {
6710
- const $ = c(3), compare = t0 === void 0 ? defaultCompare : t0;
6711
- let t1;
6712
- return $[0] !== editor._internal.slateEditor.instance || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
6713
- const snapshot = getEditorSnapshot({
6714
- editorActorSnapshot,
6715
- slateEditorInstance: editor._internal.slateEditor.instance
6716
- });
6717
- return selector(snapshot);
6718
- }, $[0] = editor._internal.slateEditor.instance, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
6719
- }
6720
- function getEditorSnapshot({
6721
- editorActorSnapshot,
6722
- slateEditorInstance
6723
- }) {
6724
- return {
6725
- context: {
6726
- converters: [...editorActorSnapshot.context.converters],
6727
- activeDecorators: getActiveDecorators({
6728
- schema: editorActorSnapshot.context.schema,
6729
- slateEditorInstance
6730
- }),
6731
- keyGenerator: editorActorSnapshot.context.keyGenerator,
6732
- readOnly: editorActorSnapshot.matches({
6733
- "edit mode": "read only"
6734
- }),
6735
- schema: editorActorSnapshot.context.schema,
6736
- selection: editorActorSnapshot.context.selection,
6737
- value: getValue({
6738
- editorActorSnapshot,
6739
- slateEditorInstance
6740
- })
6741
- },
6742
- beta: {
6743
- hasTag: (tag) => editorActorSnapshot.hasTag(tag)
6744
- }
6745
- };
6746
- }
6747
7086
  function createEditor(config) {
6748
7087
  const editorActor = createActor(editorMachine, {
6749
7088
  input: editorConfigToMachineInput(config)
@@ -6820,7 +7159,7 @@ function createEditorFromActor(editorActor) {
6820
7159
  }
6821
7160
  };
6822
7161
  }
6823
- const EditorActorContext = createContext({}), PortableTextEditorSelectionContext = createContext(null), usePortableTextEditorSelection = () => {
7162
+ const PortableTextEditorSelectionContext = createContext(null), usePortableTextEditorSelection = () => {
6824
7163
  const selection = useContext(PortableTextEditorSelectionContext);
6825
7164
  if (selection === void 0)
6826
7165
  throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
@@ -7390,21 +7729,17 @@ function useEditor() {
7390
7729
  export {
7391
7730
  EditorActorContext,
7392
7731
  EditorProvider,
7393
- IS_DRAGGING,
7394
- IS_DRAGGING_BLOCK_ELEMENT,
7395
- IS_DRAGGING_BLOCK_TARGET_POSITION,
7396
- IS_DRAGGING_ELEMENT_TARGET,
7397
7732
  KEY_TO_VALUE_ELEMENT,
7398
7733
  PortableTextEditor,
7399
7734
  debugWithName,
7400
7735
  defaultKeyGenerator,
7401
7736
  defineSchema,
7402
7737
  fromSlateValue,
7738
+ getEditorSnapshot,
7403
7739
  isEqualToEmptyEditor,
7404
7740
  moveRangeByOperation,
7405
7741
  toPortableTextRange,
7406
7742
  toSlateRange,
7407
- toSlateValue,
7408
7743
  useEditor,
7409
7744
  useEditorSelector,
7410
7745
  usePortableTextEditor,