@portabletext/editor 1.48.13 → 1.48.15

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 (78) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +682 -609
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-es/editor-provider.js +683 -610
  4. package/lib/_chunks-es/editor-provider.js.map +1 -1
  5. package/lib/behaviors/index.cjs.map +1 -1
  6. package/lib/behaviors/index.d.cts +226 -2772
  7. package/lib/behaviors/index.d.ts +226 -2772
  8. package/lib/behaviors/index.js.map +1 -1
  9. package/lib/index.cjs +22 -6
  10. package/lib/index.cjs.map +1 -1
  11. package/lib/index.d.cts +227 -2780
  12. package/lib/index.d.ts +227 -2780
  13. package/lib/index.js +23 -7
  14. package/lib/index.js.map +1 -1
  15. package/lib/plugins/index.cjs +1 -7
  16. package/lib/plugins/index.cjs.map +1 -1
  17. package/lib/plugins/index.d.cts +226 -2785
  18. package/lib/plugins/index.d.ts +226 -2785
  19. package/lib/plugins/index.js +2 -8
  20. package/lib/plugins/index.js.map +1 -1
  21. package/lib/selectors/index.d.cts +225 -2771
  22. package/lib/selectors/index.d.ts +225 -2771
  23. package/lib/utils/index.d.cts +227 -2772
  24. package/lib/utils/index.d.ts +227 -2772
  25. package/package.json +1 -1
  26. package/src/behaviors/behavior.abstract.keyboard.ts +16 -0
  27. package/src/behaviors/{behavior.default.ts → behavior.abstract.ts} +3 -3
  28. package/src/behaviors/behavior.config.ts +7 -0
  29. package/src/behaviors/behavior.core.ts +6 -5
  30. package/src/behaviors/behavior.perform-event.ts +27 -51
  31. package/src/behaviors/behavior.types.action.ts +1 -11
  32. package/src/editor/PortableTextEditor.tsx +1 -1
  33. package/src/editor/components/Element.tsx +30 -4
  34. package/src/editor/create-editor.ts +17 -5
  35. package/src/editor/editor-machine.ts +23 -17
  36. package/src/editor/mutation-machine.ts +6 -6
  37. package/src/editor/plugins/create-with-event-listeners.ts +25 -25
  38. package/src/editor/plugins/createWithEditableAPI.ts +3 -3
  39. package/src/editor/plugins/createWithPatches.ts +13 -5
  40. package/src/editor/plugins/createWithPortableTextMarkModel.ts +5 -5
  41. package/src/editor/plugins/createWithUndoRedo.ts +8 -8
  42. package/src/editor/with-applying-behavior-operations.ts +18 -0
  43. package/src/editor/{with-applying-behavior-actions.ts → with-undo-step.ts} +1 -19
  44. package/src/index.ts +1 -1
  45. package/src/{behavior-actions/behavior.action.annotation.add.ts → operations/behavior.operation.annotation.add.ts} +7 -7
  46. package/src/{behavior-actions/behavior.action.annotation.remove.ts → operations/behavior.operation.annotation.remove.ts} +6 -6
  47. package/src/{behavior-actions/behavior.action.block.set.ts → operations/behavior.operation.block.set.ts} +14 -14
  48. package/src/{behavior-actions/behavior.action.block.unset.ts → operations/behavior.operation.block.unset.ts} +19 -17
  49. package/src/{behavior-actions/behavior.action.decorator.add.ts → operations/behavior.operation.decorator.add.ts} +10 -10
  50. package/src/operations/behavior.operation.delete.backward.ts +8 -0
  51. package/src/operations/behavior.operation.delete.block.ts +24 -0
  52. package/src/operations/behavior.operation.delete.forward.ts +8 -0
  53. package/src/{behavior-actions/behavior.action.delete.ts → operations/behavior.operation.delete.ts} +8 -8
  54. package/src/{behavior-actions/behavior.action.insert-inline-object.ts → operations/behavior.operation.insert-inline-object.ts} +11 -11
  55. package/src/{behavior-actions/behavior.action.insert-span.ts → operations/behavior.operation.insert-span.ts} +15 -15
  56. package/src/{behavior-actions/behavior.action.insert.block.ts → operations/behavior.operation.insert.block.ts} +8 -8
  57. package/src/operations/behavior.operation.insert.text.ts +17 -0
  58. package/src/operations/behavior.operation.move.backward.ts +12 -0
  59. package/src/operations/behavior.operation.move.block.ts +16 -0
  60. package/src/operations/behavior.operation.move.forward.ts +11 -0
  61. package/src/operations/behavior.operation.select.ts +15 -0
  62. package/src/operations/behavior.operations.ts +239 -0
  63. package/src/plugins/index.ts +0 -1
  64. package/src/priority/priority.core.ts +3 -0
  65. package/src/priority/priority.sort.test.ts +319 -0
  66. package/src/priority/priority.sort.ts +121 -0
  67. package/src/priority/priority.types.ts +24 -0
  68. package/src/behavior-actions/behavior.action.delete.backward.ts +0 -7
  69. package/src/behavior-actions/behavior.action.delete.block.ts +0 -24
  70. package/src/behavior-actions/behavior.action.delete.forward.ts +0 -7
  71. package/src/behavior-actions/behavior.action.insert.text.ts +0 -17
  72. package/src/behavior-actions/behavior.action.move.backward.ts +0 -12
  73. package/src/behavior-actions/behavior.action.move.block.ts +0 -16
  74. package/src/behavior-actions/behavior.action.move.forward.ts +0 -11
  75. package/src/behavior-actions/behavior.action.select.ts +0 -15
  76. package/src/behavior-actions/behavior.actions.ts +0 -219
  77. package/src/behaviors/behavior.default.raise-soft-break.ts +0 -14
  78. package/src/plugins/plugin.core.tsx +0 -9
@@ -149,18 +149,18 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
149
149
  }) => {
150
150
  if (xstate.assertEvent(event, "patch"), context.pendingMutations.length === 0)
151
151
  return [{
152
- actionId: event.actionId,
152
+ operationId: event.operationId,
153
153
  value: event.value,
154
154
  patches: [event.patch]
155
155
  }];
156
156
  const lastBulk = context.pendingMutations.at(-1);
157
- return lastBulk && lastBulk.actionId === event.actionId ? context.pendingMutations.slice(0, -1).concat({
157
+ return lastBulk && lastBulk.operationId === event.operationId ? context.pendingMutations.slice(0, -1).concat({
158
158
  value: event.value,
159
- actionId: lastBulk.actionId,
159
+ operationId: lastBulk.operationId,
160
160
  patches: [...lastBulk.patches, event.patch]
161
161
  }) : context.pendingMutations.concat({
162
162
  value: event.value,
163
- actionId: event.actionId,
163
+ operationId: event.operationId,
164
164
  patches: [event.patch]
165
165
  });
166
166
  }
@@ -1301,16 +1301,6 @@ function randomKey(length) {
1301
1301
  const table = getByteHexTable();
1302
1302
  return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
1303
1303
  }
1304
- const CURRENT_ACTION_ID = /* @__PURE__ */ new WeakMap();
1305
- function withApplyingBehaviorActions(editor, fn) {
1306
- CURRENT_ACTION_ID.set(editor, defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_ACTION_ID.set(editor, void 0);
1307
- }
1308
- function getCurrentActionId(editor) {
1309
- return CURRENT_ACTION_ID.get(editor);
1310
- }
1311
- function isApplyingBehaviorActions(editor) {
1312
- return getCurrentActionId(editor) !== void 0;
1313
- }
1314
1304
  const CURRENT_UNDO_STEP = /* @__PURE__ */ new WeakMap();
1315
1305
  function withUndoStep(editor, fn) {
1316
1306
  const current = CURRENT_UNDO_STEP.get(editor);
@@ -1412,10 +1402,10 @@ function createWithUndoRedo(options) {
1412
1402
  }, editor;
1413
1403
  };
1414
1404
  }
1415
- const historyUndoActionImplementation = ({
1416
- action
1405
+ const historyUndoOperationImplementation = ({
1406
+ operation
1417
1407
  }) => {
1418
- const editor = action.editor, {
1408
+ const editor = operation.editor, {
1419
1409
  undos
1420
1410
  } = editor.history, remotePatches = getRemotePatches(editor);
1421
1411
  if (undos.length > 0) {
@@ -1447,10 +1437,10 @@ const historyUndoActionImplementation = ({
1447
1437
  editor.history.redos.push(step), editor.history.undos.pop();
1448
1438
  }
1449
1439
  }
1450
- }, historyRedoActionImplementation = ({
1451
- action
1440
+ }, historyRedoOperationImplementation = ({
1441
+ operation
1452
1442
  }) => {
1453
- const editor = action.editor, {
1443
+ const editor = operation.editor, {
1454
1444
  redos
1455
1445
  } = editor.history, remotePatches = getRemotePatches(editor);
1456
1446
  if (redos.length > 0) {
@@ -2404,7 +2394,16 @@ function compileType(rawType) {
2404
2394
  types: [rawType]
2405
2395
  }).get(rawType.name);
2406
2396
  }
2407
- const debug$b = debugWithName("operationToPatches");
2397
+ function createEditorPriority(config) {
2398
+ return {
2399
+ id: defaultKeyGenerator(),
2400
+ name: config?.name,
2401
+ reference: config?.reference
2402
+ };
2403
+ }
2404
+ const corePriority = createEditorPriority({
2405
+ name: "core"
2406
+ }), debug$b = debugWithName("operationToPatches");
2408
2407
  function createOperationToPatches(editorActor) {
2409
2408
  const textBlockName = editorActor.getSnapshot().context.schema.block.name;
2410
2409
  function insertTextPatch(editor, operation, beforeValue) {
@@ -2626,13 +2625,214 @@ function createOperationToPatches(editorActor) {
2626
2625
  splitNodePatch
2627
2626
  };
2628
2627
  }
2629
- const insertTextActionImplementation = ({
2630
- action
2628
+ function getFocusBlock({
2629
+ editor
2630
+ }) {
2631
+ if (!editor.selection)
2632
+ return [void 0, void 0];
2633
+ try {
2634
+ return slate.Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0];
2635
+ } catch {
2636
+ return [void 0, void 0];
2637
+ }
2638
+ }
2639
+ function getSelectionStartBlock({
2640
+ editor
2641
+ }) {
2642
+ if (!editor.selection)
2643
+ return [void 0, void 0];
2644
+ const selectionStartPoint = slate.Range.start(editor.selection);
2645
+ return getPointBlock({
2646
+ editor,
2647
+ point: selectionStartPoint
2648
+ });
2649
+ }
2650
+ function getSelectionEndBlock({
2651
+ editor
2652
+ }) {
2653
+ if (!editor.selection)
2654
+ return [void 0, void 0];
2655
+ const selectionEndPoint = slate.Range.end(editor.selection);
2656
+ return getPointBlock({
2657
+ editor,
2658
+ point: selectionEndPoint
2659
+ });
2660
+ }
2661
+ function getPointBlock({
2662
+ editor,
2663
+ point
2664
+ }) {
2665
+ try {
2666
+ const [block] = slate.Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
2667
+ return block ? [block, point.path.slice(0, 1)] : [void 0, void 0];
2668
+ } catch {
2669
+ return [void 0, void 0];
2670
+ }
2671
+ }
2672
+ function getFocusChild({
2673
+ editor
2674
+ }) {
2675
+ const [focusBlock, focusBlockPath] = getFocusBlock({
2676
+ editor
2677
+ }), childIndex = editor.selection?.focus.path.at(1);
2678
+ if (!focusBlock || !focusBlockPath || childIndex === void 0)
2679
+ return [void 0, void 0];
2680
+ try {
2681
+ const focusChild = slate.Node.child(focusBlock, childIndex);
2682
+ return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
2683
+ } catch {
2684
+ return [void 0, void 0];
2685
+ }
2686
+ }
2687
+ function getPointChild({
2688
+ editor,
2689
+ point
2690
+ }) {
2691
+ const [block, blockPath] = getPointBlock({
2692
+ editor,
2693
+ point
2694
+ }), childIndex = point.path.at(1);
2695
+ if (!block || !blockPath || childIndex === void 0)
2696
+ return [void 0, void 0];
2697
+ try {
2698
+ const pointChild = slate.Node.child(block, childIndex);
2699
+ return pointChild ? [pointChild, [...blockPath, childIndex]] : [void 0, void 0];
2700
+ } catch {
2701
+ return [void 0, void 0];
2702
+ }
2703
+ }
2704
+ function getFirstBlock({
2705
+ editor
2706
+ }) {
2707
+ const firstBlockPath = slate.Editor.start(editor, []).path.at(0);
2708
+ try {
2709
+ return firstBlockPath !== void 0 ? slate.Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
2710
+ } catch {
2711
+ return [void 0, void 0];
2712
+ }
2713
+ }
2714
+ function getLastBlock({
2715
+ editor
2716
+ }) {
2717
+ const lastBlockPath = slate.Editor.end(editor, []).path.at(0);
2718
+ try {
2719
+ return lastBlockPath !== void 0 ? slate.Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
2720
+ } catch {
2721
+ return [void 0, void 0];
2722
+ }
2723
+ }
2724
+ function getNodeBlock({
2725
+ editor,
2726
+ schema: schema2,
2727
+ node
2728
+ }) {
2729
+ if (slate.Editor.isEditor(node))
2730
+ return;
2731
+ if (isBlockElement({
2732
+ editor,
2733
+ schema: schema2
2734
+ }, node))
2735
+ return elementToBlock({
2736
+ schema: schema2,
2737
+ element: node
2738
+ });
2739
+ const parent = Array.from(slate.Editor.nodes(editor, {
2740
+ mode: "highest",
2741
+ at: [],
2742
+ match: (n) => isBlockElement({
2743
+ editor,
2744
+ schema: schema2
2745
+ }, n) && n.children.some((child) => child._key === node._key)
2746
+ })).at(0)?.at(0);
2747
+ return slate.Element.isElement(parent) ? elementToBlock({
2748
+ schema: schema2,
2749
+ element: parent
2750
+ }) : void 0;
2751
+ }
2752
+ function elementToBlock({
2753
+ schema: schema2,
2754
+ element
2755
+ }) {
2756
+ return fromSlateValue([element], schema2.block.name)?.at(0);
2757
+ }
2758
+ function isBlockElement({
2759
+ editor,
2760
+ schema: schema2
2761
+ }, node) {
2762
+ return slate.Element.isElement(node) && !editor.isInline(node) && (schema2.block.name === node._type || schema2.blockObjects.some((blockObject) => blockObject.name === node._type));
2763
+ }
2764
+ function isListItemActive({
2765
+ editor,
2766
+ listItem
2767
+ }) {
2768
+ if (!editor.selection)
2769
+ return !1;
2770
+ const selectedBlocks = [...slate.Editor.nodes(editor, {
2771
+ at: editor.selection,
2772
+ match: (node) => editor.isTextBlock(node)
2773
+ })];
2774
+ return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
2775
+ }
2776
+ function isStyleActive({
2777
+ editor,
2778
+ style
2779
+ }) {
2780
+ if (!editor.selection)
2781
+ return !1;
2782
+ const selectedBlocks = [...slate.Editor.nodes(editor, {
2783
+ at: editor.selection,
2784
+ match: (node) => editor.isTextBlock(node)
2785
+ })];
2786
+ return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
2787
+ }
2788
+ function slateRangeToSelection({
2789
+ schema: schema2,
2790
+ editor,
2791
+ range
2792
+ }) {
2793
+ const [anchorBlock] = getPointBlock({
2794
+ editor,
2795
+ point: range.anchor
2796
+ }), [focusBlock] = getPointBlock({
2797
+ editor,
2798
+ point: range.focus
2799
+ });
2800
+ if (!anchorBlock || !focusBlock)
2801
+ return null;
2802
+ const [anchorChild] = anchorBlock._type === schema2.block.name ? getPointChild({
2803
+ editor,
2804
+ point: range.anchor
2805
+ }) : [void 0, void 0], [focusChild] = focusBlock._type === schema2.block.name ? getPointChild({
2806
+ editor,
2807
+ point: range.focus
2808
+ }) : [void 0, void 0], selection = {
2809
+ anchor: {
2810
+ path: [{
2811
+ _key: anchorBlock._key
2812
+ }],
2813
+ offset: range.anchor.offset
2814
+ },
2815
+ focus: {
2816
+ path: [{
2817
+ _key: focusBlock._key
2818
+ }],
2819
+ offset: range.focus.offset
2820
+ },
2821
+ backward: slate.Range.isBackward(range)
2822
+ };
2823
+ return anchorChild && (selection.anchor.path.push("children"), selection.anchor.path.push({
2824
+ _key: anchorChild._key
2825
+ })), focusChild && (selection.focus.path.push("children"), selection.focus.path.push({
2826
+ _key: focusChild._key
2827
+ })), selection;
2828
+ }
2829
+ const insertTextOperationImplementation = ({
2830
+ operation
2631
2831
  }) => {
2632
- action.editor.marks ? slate.Transforms.insertNodes(action.editor, {
2633
- text: action.text,
2634
- ...action.editor.marks
2635
- }) : slate.Transforms.insertText(action.editor, action.text), action.editor.marks = null;
2832
+ operation.editor.marks ? slate.Transforms.insertNodes(operation.editor, {
2833
+ text: operation.text,
2834
+ ...operation.editor.marks
2835
+ }) : slate.Transforms.insertText(operation.editor, operation.text), operation.editor.marks = null;
2636
2836
  };
2637
2837
  function isPortableTextSpan(node) {
2638
2838
  return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
@@ -3032,10 +3232,10 @@ function createWithPortableTextMarkModel(editorActor) {
3032
3232
  }, editor;
3033
3233
  };
3034
3234
  }
3035
- const removeDecoratorActionImplementation = ({
3036
- action
3235
+ const removeDecoratorOperationImplementation = ({
3236
+ operation
3037
3237
  }) => {
3038
- const editor = action.editor, mark = action.decorator, {
3238
+ const editor = operation.editor, mark = operation.decorator, {
3039
3239
  selection
3040
3240
  } = editor;
3041
3241
  if (selection) {
@@ -3106,14 +3306,14 @@ function isDecoratorActive({
3106
3306
  ...slate.Editor.marks(editor) || {}
3107
3307
  }.marks || []).includes(decorator);
3108
3308
  }
3109
- const addAnnotationActionImplementation = ({
3309
+ const addAnnotationOperationImplementation = ({
3110
3310
  context,
3111
- action
3311
+ operation
3112
3312
  }) => {
3113
3313
  const parsedAnnotation = util_sliceBlocks.parseAnnotation({
3114
3314
  annotation: {
3115
- _type: action.annotation.name,
3116
- ...action.annotation.value
3315
+ _type: operation.annotation.name,
3316
+ ...operation.annotation.value
3117
3317
  },
3118
3318
  context,
3119
3319
  options: {
@@ -3121,8 +3321,8 @@ const addAnnotationActionImplementation = ({
3121
3321
  }
3122
3322
  });
3123
3323
  if (!parsedAnnotation)
3124
- throw new Error(`Failed to parse annotation ${JSON.stringify(action.annotation)}`);
3125
- const editor = action.editor;
3324
+ throw new Error(`Failed to parse annotation ${JSON.stringify(operation.annotation)}`);
3325
+ const editor = operation.editor;
3126
3326
  if (!editor.selection || slate.Range.isCollapsed(editor.selection))
3127
3327
  return;
3128
3328
  let paths, spanPath, markDefPath;
@@ -3173,10 +3373,10 @@ const addAnnotationActionImplementation = ({
3173
3373
  markDefPaths,
3174
3374
  spanPath
3175
3375
  }), paths;
3176
- }, removeAnnotationActionImplementation = ({
3177
- action
3376
+ }, removeAnnotationOperationImplementation = ({
3377
+ operation
3178
3378
  }) => {
3179
- const editor = action.editor;
3379
+ const editor = operation.editor;
3180
3380
  if (editor.selection)
3181
3381
  if (slate.Range.isCollapsed(editor.selection)) {
3182
3382
  const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
@@ -3184,7 +3384,7 @@ const addAnnotationActionImplementation = ({
3184
3384
  });
3185
3385
  if (!editor.isTextBlock(block))
3186
3386
  return;
3187
- const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = slate.Editor.node(editor, editor.selection, {
3387
+ const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), [selectedChild, selectedChildPath] = slate.Editor.node(editor, editor.selection, {
3188
3388
  depth: 2
3189
3389
  });
3190
3390
  if (!editor.isTextSpan(selectedChild))
@@ -3229,7 +3429,7 @@ const addAnnotationActionImplementation = ({
3229
3429
  for (const [child, childPath] of children) {
3230
3430
  if (!editor.isTextSpan(child) || !slate.Range.includes(editor.selection, childPath))
3231
3431
  continue;
3232
- const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== action.annotation.name);
3432
+ const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
3233
3433
  marksWithoutAnnotation.length !== marks.length && slate.Transforms.setNodes(editor, {
3234
3434
  marks: marksWithoutAnnotation
3235
3435
  }, {
@@ -3281,34 +3481,34 @@ function moveRangeByOperation(range, operation) {
3281
3481
  focus
3282
3482
  };
3283
3483
  }
3284
- const blockSetBehaviorActionImplementation = ({
3484
+ const blockSetOperationImplementation = ({
3285
3485
  context,
3286
- action
3486
+ operation
3287
3487
  }) => {
3288
3488
  const location = toSlateRange({
3289
3489
  anchor: {
3290
- path: action.at,
3490
+ path: operation.at,
3291
3491
  offset: 0
3292
3492
  },
3293
3493
  focus: {
3294
- path: action.at,
3494
+ path: operation.at,
3295
3495
  offset: 0
3296
3496
  }
3297
- }, action.editor);
3497
+ }, operation.editor);
3298
3498
  if (!location)
3299
- throw new Error(`Unable to convert ${JSON.stringify(action.at)} into a Slate Range`);
3300
- const block = slate.Editor.node(action.editor, location, {
3499
+ throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
3500
+ const block = slate.Editor.node(operation.editor, location, {
3301
3501
  depth: 1
3302
3502
  })?.[0];
3303
3503
  if (!block)
3304
- throw new Error(`Unable to find block at ${JSON.stringify(action.at)}`);
3305
- const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
3504
+ throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
3505
+ const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
3306
3506
  if (!parsedBlock)
3307
- throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
3507
+ throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
3308
3508
  const {
3309
3509
  _type,
3310
3510
  ...filteredProps
3311
- } = action.props, updatedBlock = util_sliceBlocks.parseBlock({
3511
+ } = operation.props, updatedBlock = util_sliceBlocks.parseBlock({
3312
3512
  context,
3313
3513
  block: {
3314
3514
  ...parsedBlock,
@@ -3319,41 +3519,41 @@ const blockSetBehaviorActionImplementation = ({
3319
3519
  }
3320
3520
  });
3321
3521
  if (!updatedBlock)
3322
- throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
3522
+ throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
3323
3523
  const slateBlock = toSlateValue([updatedBlock], {
3324
3524
  schemaTypes: context.schema
3325
3525
  })?.at(0);
3326
3526
  if (!slateBlock)
3327
3527
  throw new Error("Unable to convert block to Slate value");
3328
- slate.Transforms.setNodes(action.editor, slateBlock, {
3528
+ slate.Transforms.setNodes(operation.editor, slateBlock, {
3329
3529
  at: location
3330
3530
  });
3331
- }, blockUnsetBehaviorActionImplementation = ({
3531
+ }, blockUnsetOperationImplementation = ({
3332
3532
  context,
3333
- action
3533
+ operation
3334
3534
  }) => {
3335
3535
  const location = toSlateRange({
3336
3536
  anchor: {
3337
- path: action.at,
3537
+ path: operation.at,
3338
3538
  offset: 0
3339
3539
  },
3340
3540
  focus: {
3341
- path: action.at,
3541
+ path: operation.at,
3342
3542
  offset: 0
3343
3543
  }
3344
- }, action.editor);
3544
+ }, operation.editor);
3345
3545
  if (!location)
3346
- throw new Error(`Unable to convert ${JSON.stringify(action.at)} into a Slate Range`);
3347
- const block = slate.Editor.node(action.editor, location, {
3546
+ throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
3547
+ const block = slate.Editor.node(operation.editor, location, {
3348
3548
  depth: 1
3349
3549
  })?.[0];
3350
3550
  if (!block)
3351
- throw new Error(`Unable to find block at ${JSON.stringify(action.at)}`);
3352
- const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
3551
+ throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
3552
+ const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
3353
3553
  if (!parsedBlock)
3354
- throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
3554
+ throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
3355
3555
  if (util_sliceBlocks.isTextBlock(context, parsedBlock)) {
3356
- const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_sliceBlocks.parseBlock({
3556
+ const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_sliceBlocks.parseBlock({
3357
3557
  context,
3358
3558
  block: omit__default.default(parsedBlock, propsToRemove),
3359
3559
  options: {
@@ -3361,260 +3561,58 @@ const blockSetBehaviorActionImplementation = ({
3361
3561
  }
3362
3562
  });
3363
3563
  if (!updatedTextBlock)
3364
- throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
3564
+ throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
3365
3565
  const propsToSet = {};
3366
3566
  for (const prop of propsToRemove)
3367
3567
  prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
3368
- slate.Transforms.setNodes(action.editor, propsToSet, {
3568
+ slate.Transforms.setNodes(operation.editor, propsToSet, {
3369
3569
  at: location
3370
3570
  });
3371
3571
  return;
3372
3572
  }
3373
3573
  const updatedBlockObject = util_sliceBlocks.parseBlock({
3374
3574
  context,
3375
- block: omit__default.default(parsedBlock, action.props.filter((prop) => prop !== "_type")),
3575
+ block: omit__default.default(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
3376
3576
  options: {
3377
3577
  refreshKeys: !1
3378
3578
  }
3379
3579
  });
3380
3580
  if (!updatedBlockObject)
3381
- throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
3581
+ throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
3382
3582
  const {
3383
- _type,
3384
- _key,
3385
- ...props
3386
- } = updatedBlockObject;
3387
- slate.Transforms.setNodes(action.editor, {
3388
- _type,
3389
- _key,
3390
- value: props
3391
- }, {
3392
- at: location
3393
- });
3394
- };
3395
- function getFocusBlock({
3396
- editor
3397
- }) {
3398
- if (!editor.selection)
3399
- return [void 0, void 0];
3400
- try {
3401
- return slate.Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0];
3402
- } catch {
3403
- return [void 0, void 0];
3404
- }
3405
- }
3406
- function getSelectionStartBlock({
3407
- editor
3408
- }) {
3409
- if (!editor.selection)
3410
- return [void 0, void 0];
3411
- const selectionStartPoint = slate.Range.start(editor.selection);
3412
- return getPointBlock({
3413
- editor,
3414
- point: selectionStartPoint
3415
- });
3416
- }
3417
- function getSelectionEndBlock({
3418
- editor
3419
- }) {
3420
- if (!editor.selection)
3421
- return [void 0, void 0];
3422
- const selectionEndPoint = slate.Range.end(editor.selection);
3423
- return getPointBlock({
3424
- editor,
3425
- point: selectionEndPoint
3426
- });
3427
- }
3428
- function getPointBlock({
3429
- editor,
3430
- point
3431
- }) {
3432
- try {
3433
- const [block] = slate.Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
3434
- return block ? [block, point.path.slice(0, 1)] : [void 0, void 0];
3435
- } catch {
3436
- return [void 0, void 0];
3437
- }
3438
- }
3439
- function getFocusChild({
3440
- editor
3441
- }) {
3442
- const [focusBlock, focusBlockPath] = getFocusBlock({
3443
- editor
3444
- }), childIndex = editor.selection?.focus.path.at(1);
3445
- if (!focusBlock || !focusBlockPath || childIndex === void 0)
3446
- return [void 0, void 0];
3447
- try {
3448
- const focusChild = slate.Node.child(focusBlock, childIndex);
3449
- return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
3450
- } catch {
3451
- return [void 0, void 0];
3452
- }
3453
- }
3454
- function getPointChild({
3455
- editor,
3456
- point
3457
- }) {
3458
- const [block, blockPath] = getPointBlock({
3459
- editor,
3460
- point
3461
- }), childIndex = point.path.at(1);
3462
- if (!block || !blockPath || childIndex === void 0)
3463
- return [void 0, void 0];
3464
- try {
3465
- const pointChild = slate.Node.child(block, childIndex);
3466
- return pointChild ? [pointChild, [...blockPath, childIndex]] : [void 0, void 0];
3467
- } catch {
3468
- return [void 0, void 0];
3469
- }
3470
- }
3471
- function getFirstBlock({
3472
- editor
3473
- }) {
3474
- const firstBlockPath = slate.Editor.start(editor, []).path.at(0);
3475
- try {
3476
- return firstBlockPath !== void 0 ? slate.Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
3477
- } catch {
3478
- return [void 0, void 0];
3479
- }
3480
- }
3481
- function getLastBlock({
3482
- editor
3483
- }) {
3484
- const lastBlockPath = slate.Editor.end(editor, []).path.at(0);
3485
- try {
3486
- return lastBlockPath !== void 0 ? slate.Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
3487
- } catch {
3488
- return [void 0, void 0];
3489
- }
3490
- }
3491
- function getNodeBlock({
3492
- editor,
3493
- schema: schema2,
3494
- node
3495
- }) {
3496
- if (slate.Editor.isEditor(node))
3497
- return;
3498
- if (isBlockElement({
3499
- editor,
3500
- schema: schema2
3501
- }, node))
3502
- return elementToBlock({
3503
- schema: schema2,
3504
- element: node
3505
- });
3506
- const parent = Array.from(slate.Editor.nodes(editor, {
3507
- mode: "highest",
3508
- at: [],
3509
- match: (n) => isBlockElement({
3510
- editor,
3511
- schema: schema2
3512
- }, n) && n.children.some((child) => child._key === node._key)
3513
- })).at(0)?.at(0);
3514
- return slate.Element.isElement(parent) ? elementToBlock({
3515
- schema: schema2,
3516
- element: parent
3517
- }) : void 0;
3518
- }
3519
- function elementToBlock({
3520
- schema: schema2,
3521
- element
3522
- }) {
3523
- return fromSlateValue([element], schema2.block.name)?.at(0);
3524
- }
3525
- function isBlockElement({
3526
- editor,
3527
- schema: schema2
3528
- }, node) {
3529
- return slate.Element.isElement(node) && !editor.isInline(node) && (schema2.block.name === node._type || schema2.blockObjects.some((blockObject) => blockObject.name === node._type));
3530
- }
3531
- function isListItemActive({
3532
- editor,
3533
- listItem
3534
- }) {
3535
- if (!editor.selection)
3536
- return !1;
3537
- const selectedBlocks = [...slate.Editor.nodes(editor, {
3538
- at: editor.selection,
3539
- match: (node) => editor.isTextBlock(node)
3540
- })];
3541
- return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
3542
- }
3543
- function isStyleActive({
3544
- editor,
3545
- style
3546
- }) {
3547
- if (!editor.selection)
3548
- return !1;
3549
- const selectedBlocks = [...slate.Editor.nodes(editor, {
3550
- at: editor.selection,
3551
- match: (node) => editor.isTextBlock(node)
3552
- })];
3553
- return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
3554
- }
3555
- function slateRangeToSelection({
3556
- schema: schema2,
3557
- editor,
3558
- range
3559
- }) {
3560
- const [anchorBlock] = getPointBlock({
3561
- editor,
3562
- point: range.anchor
3563
- }), [focusBlock] = getPointBlock({
3564
- editor,
3565
- point: range.focus
3583
+ _type,
3584
+ _key,
3585
+ ...props
3586
+ } = updatedBlockObject;
3587
+ slate.Transforms.setNodes(operation.editor, {
3588
+ _type,
3589
+ _key,
3590
+ value: props
3591
+ }, {
3592
+ at: location
3566
3593
  });
3567
- if (!anchorBlock || !focusBlock)
3568
- return null;
3569
- const [anchorChild] = anchorBlock._type === schema2.block.name ? getPointChild({
3570
- editor,
3571
- point: range.anchor
3572
- }) : [void 0, void 0], [focusChild] = focusBlock._type === schema2.block.name ? getPointChild({
3573
- editor,
3574
- point: range.focus
3575
- }) : [void 0, void 0], selection = {
3576
- anchor: {
3577
- path: [{
3578
- _key: anchorBlock._key
3579
- }],
3580
- offset: range.anchor.offset
3581
- },
3582
- focus: {
3583
- path: [{
3584
- _key: focusBlock._key
3585
- }],
3586
- offset: range.focus.offset
3587
- },
3588
- backward: slate.Range.isBackward(range)
3589
- };
3590
- return anchorChild && (selection.anchor.path.push("children"), selection.anchor.path.push({
3591
- _key: anchorChild._key
3592
- })), focusChild && (selection.focus.path.push("children"), selection.focus.path.push({
3593
- _key: focusChild._key
3594
- })), selection;
3595
- }
3596
- const decoratorAddActionImplementation = ({
3594
+ }, decoratorAddOperationImplementation = ({
3597
3595
  context,
3598
- action
3596
+ operation
3599
3597
  }) => {
3600
- const editor = action.editor, mark = action.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = action.at?.anchor ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3598
+ const editor = operation.editor, mark = operation.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = operation.at?.anchor ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3601
3599
  context: {
3602
3600
  ...context,
3603
3601
  value
3604
3602
  },
3605
- blockOffset: action.at.anchor,
3603
+ blockOffset: operation.at.anchor,
3606
3604
  direction: "backward"
3607
- }) : void 0, manualFocus = action.at?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3605
+ }) : void 0, manualFocus = operation.at?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3608
3606
  context: {
3609
3607
  ...context,
3610
3608
  value
3611
3609
  },
3612
- blockOffset: action.at.focus,
3610
+ blockOffset: operation.at.focus,
3613
3611
  direction: "forward"
3614
3612
  }) : void 0, manualSelection = manualAnchor && manualFocus ? {
3615
3613
  anchor: manualAnchor,
3616
3614
  focus: manualFocus
3617
- } : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
3615
+ } : void 0, selection = manualSelection ? toSlateRange(manualSelection, operation.editor) ?? editor.selection : editor.selection;
3618
3616
  if (!selection)
3619
3617
  return;
3620
3618
  const editorSelection = slateRangeToSelection({
@@ -3717,82 +3715,82 @@ const decoratorAddActionImplementation = ({
3717
3715
  ...selection2
3718
3716
  };
3719
3717
  }
3720
- }, deleteActionImplementation = ({
3718
+ }, deleteOperationImplementation = ({
3721
3719
  context,
3722
- action
3720
+ operation
3723
3721
  }) => {
3724
- const range = toSlateRange(action.at, action.editor);
3722
+ const range = toSlateRange(operation.at, operation.editor);
3725
3723
  if (!range)
3726
- throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.at)}`);
3724
+ throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
3727
3725
  if (slate.Range.isCollapsed(range)) {
3728
3726
  const [focusBlock] = getFocusBlock({
3729
3727
  editor: {
3730
- ...action.editor,
3728
+ ...operation.editor,
3731
3729
  selection: range
3732
3730
  }
3733
3731
  }), [focusChild] = getFocusChild({
3734
3732
  editor: {
3735
- ...action.editor,
3733
+ ...operation.editor,
3736
3734
  selection: range
3737
3735
  }
3738
3736
  });
3739
3737
  if (focusBlock && focusBlock._type === context.schema.block.name && focusChild && focusChild._type === context.schema.span.name)
3740
3738
  return;
3741
3739
  }
3742
- action.editor.delete({
3740
+ operation.editor.delete({
3743
3741
  at: range
3744
3742
  });
3745
- }, deleteBackwardActionImplementation = ({
3746
- action
3743
+ }, deleteBackwardOperationImplementation = ({
3744
+ operation
3747
3745
  }) => {
3748
- action.editor.deleteBackward(action.unit);
3749
- }, deleteBlockActionImplementation = ({
3750
- action
3746
+ slate.deleteBackward(operation.editor, operation.unit);
3747
+ }, deleteBlockOperationImplementation = ({
3748
+ operation
3751
3749
  }) => {
3752
3750
  const range = toSlateRange({
3753
3751
  anchor: {
3754
- path: action.at,
3752
+ path: operation.at,
3755
3753
  offset: 0
3756
3754
  },
3757
3755
  focus: {
3758
- path: action.at,
3756
+ path: operation.at,
3759
3757
  offset: 0
3760
3758
  }
3761
- }, action.editor);
3759
+ }, operation.editor);
3762
3760
  if (!range) {
3763
3761
  console.error("Unable to find Slate range from selection points");
3764
3762
  return;
3765
3763
  }
3766
- slate.Transforms.removeNodes(action.editor, {
3764
+ slate.Transforms.removeNodes(operation.editor, {
3767
3765
  at: range
3768
3766
  });
3769
- }, deleteForwardActionImplementation = ({
3770
- action
3767
+ }, deleteForwardOperationImplementation = ({
3768
+ operation
3771
3769
  }) => {
3772
- action.editor.deleteForward(action.unit);
3773
- }, insertInlineObjectActionImplementation = ({
3770
+ slate.deleteForward(operation.editor, operation.unit);
3771
+ }, insertInlineObjectOperationImplementation = ({
3774
3772
  context,
3775
- action
3773
+ operation
3776
3774
  }) => {
3777
3775
  const parsedInlineObject = util_sliceBlocks.parseInlineObject({
3778
3776
  context,
3779
3777
  inlineObject: {
3780
- _type: action.inlineObject.name,
3781
- ...action.inlineObject.value ?? {}
3778
+ _type: operation.inlineObject.name,
3779
+ ...operation.inlineObject.value ?? {}
3782
3780
  },
3783
3781
  options: {
3784
3782
  refreshKeys: !1
3785
3783
  }
3786
3784
  });
3787
3785
  if (!parsedInlineObject)
3788
- throw new Error(`Failed to parse inline object ${JSON.stringify(action.inlineObject)}`);
3789
- if (!action.editor.selection) {
3786
+ throw new Error(`Failed to parse inline object ${JSON.stringify(operation.inlineObject)}`);
3787
+ if (!operation.editor.selection) {
3790
3788
  console.error("Unable to insert inline object without selection");
3791
3789
  return;
3792
3790
  }
3793
- const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
3794
- at: action.editor.selection.focus.path,
3795
- match: (node) => action.editor.isTextBlock(node)
3791
+ const [focusTextBlock] = Array.from(slate.Editor.nodes(operation.editor, {
3792
+ at: operation.editor.selection.focus.path,
3793
+ match: (node) => operation.editor.isTextBlock(node)
3796
3794
  })).at(0) ?? [void 0, void 0];
3797
3795
  if (!focusTextBlock) {
3798
3796
  console.error("Unable to perform action without focus text block");
@@ -3809,49 +3807,49 @@ const decoratorAddActionImplementation = ({
3809
3807
  console.error("Unable to insert inline object");
3810
3808
  return;
3811
3809
  }
3812
- slate.Transforms.insertNodes(action.editor, child);
3813
- }, insertSpanActionImplementation = ({
3810
+ slate.Transforms.insertNodes(operation.editor, child);
3811
+ }, insertSpanOperationImplementation = ({
3814
3812
  context,
3815
- action
3813
+ operation
3816
3814
  }) => {
3817
- if (!action.editor.selection) {
3818
- console.error("Unable to perform action without selection", action);
3815
+ if (!operation.editor.selection) {
3816
+ console.error("Unable to perform action without selection", operation);
3819
3817
  return;
3820
3818
  }
3821
- const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(action.editor, {
3822
- at: action.editor.selection.focus.path,
3823
- match: (node) => action.editor.isTextBlock(node)
3819
+ const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(operation.editor, {
3820
+ at: operation.editor.selection.focus.path,
3821
+ match: (node) => operation.editor.isTextBlock(node)
3824
3822
  }))[0] ?? [void 0, void 0];
3825
3823
  if (!focusBlock || !focusBlockPath) {
3826
- console.error("Unable to perform action without focus block", action);
3824
+ console.error("Unable to perform action without focus block", operation);
3827
3825
  return;
3828
3826
  }
3829
- const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
3827
+ const markDefs = focusBlock.markDefs ?? [], annotations = operation.annotations ? operation.annotations.map((annotation) => ({
3830
3828
  _type: annotation.name,
3831
3829
  _key: context.keyGenerator(),
3832
3830
  ...annotation.value
3833
3831
  })) : void 0;
3834
- annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
3832
+ annotations && annotations.length > 0 && slate.Transforms.setNodes(operation.editor, {
3835
3833
  markDefs: [...markDefs, ...annotations]
3836
- }), slate.Transforms.insertNodes(action.editor, {
3834
+ }), slate.Transforms.insertNodes(operation.editor, {
3837
3835
  _type: "span",
3838
3836
  _key: context.keyGenerator(),
3839
- text: action.text,
3840
- marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
3837
+ text: operation.text,
3838
+ marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...operation.decorators ?? []]
3841
3839
  });
3842
- }, insertBlockActionImplementation = ({
3840
+ }, insertBlockOperationImplementation = ({
3843
3841
  context,
3844
- action
3842
+ operation
3845
3843
  }) => {
3846
3844
  const parsedBlock = util_sliceBlocks.parseBlock({
3847
- block: action.block,
3845
+ block: operation.block,
3848
3846
  context,
3849
3847
  options: {
3850
3848
  refreshKeys: !1
3851
3849
  }
3852
3850
  });
3853
3851
  if (!parsedBlock)
3854
- throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`);
3852
+ throw new Error(`Failed to parse block ${JSON.stringify(operation.block)}`);
3855
3853
  const fragment = toSlateValue([parsedBlock], {
3856
3854
  schemaTypes: context.schema
3857
3855
  })[0];
@@ -3859,9 +3857,9 @@ const decoratorAddActionImplementation = ({
3859
3857
  throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
3860
3858
  insertBlock({
3861
3859
  block: fragment,
3862
- placement: action.placement,
3863
- select: action.select ?? "start",
3864
- editor: action.editor,
3860
+ placement: operation.placement,
3861
+ select: operation.select ?? "start",
3862
+ editor: operation.editor,
3865
3863
  schema: context.schema
3866
3864
  });
3867
3865
  };
@@ -4013,218 +4011,229 @@ function insertBlock({
4013
4011
  }
4014
4012
  }
4015
4013
  }
4016
- const moveBackwardActionImplementation = ({
4017
- action
4014
+ const moveBackwardOperationImplementation = ({
4015
+ operation
4018
4016
  }) => {
4019
- slate.Transforms.move(action.editor, {
4017
+ slate.Transforms.move(operation.editor, {
4020
4018
  unit: "character",
4021
- distance: action.distance,
4019
+ distance: operation.distance,
4022
4020
  reverse: !0
4023
4021
  });
4024
- }, moveBlockActionImplementation = ({
4025
- action
4022
+ }, moveBlockOperationImplementation = ({
4023
+ operation
4026
4024
  }) => {
4027
- const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
4028
- slate.Transforms.moveNodes(action.editor, {
4025
+ const at = [toSlatePath(operation.at, operation.editor)[0]], to = [toSlatePath(operation.to, operation.editor)[0]];
4026
+ slate.Transforms.moveNodes(operation.editor, {
4029
4027
  at,
4030
4028
  to,
4031
4029
  mode: "highest"
4032
4030
  });
4033
- }, moveForwardActionImplementation = ({
4034
- action
4031
+ }, moveForwardOperationImplementation = ({
4032
+ operation
4035
4033
  }) => {
4036
- slate.Transforms.move(action.editor, {
4034
+ slate.Transforms.move(operation.editor, {
4037
4035
  unit: "character",
4038
- distance: action.distance
4036
+ distance: operation.distance
4039
4037
  });
4040
- }, selectActionImplementation = ({
4041
- action
4038
+ }, selectOperationImplementation = ({
4039
+ operation
4042
4040
  }) => {
4043
- const newSelection = toSlateRange(action.at, action.editor);
4044
- newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
4045
- }, behaviorActionImplementations = {
4046
- "annotation.add": addAnnotationActionImplementation,
4047
- "annotation.remove": removeAnnotationActionImplementation,
4048
- "block.set": blockSetBehaviorActionImplementation,
4049
- "block.unset": blockUnsetBehaviorActionImplementation,
4050
- "decorator.add": decoratorAddActionImplementation,
4051
- "decorator.remove": removeDecoratorActionImplementation,
4052
- delete: deleteActionImplementation,
4053
- "delete.backward": deleteBackwardActionImplementation,
4054
- "delete.forward": deleteForwardActionImplementation,
4055
- "delete.block": deleteBlockActionImplementation,
4056
- "history.redo": historyRedoActionImplementation,
4057
- "history.undo": historyUndoActionImplementation,
4058
- "insert.block": insertBlockActionImplementation,
4059
- "insert.inline object": insertInlineObjectActionImplementation,
4060
- "insert.span": insertSpanActionImplementation,
4061
- "insert.text": insertTextActionImplementation,
4062
- "move.backward": moveBackwardActionImplementation,
4063
- "move.block": moveBlockActionImplementation,
4064
- "move.forward": moveForwardActionImplementation,
4065
- select: selectActionImplementation
4041
+ const newSelection = toSlateRange(operation.at, operation.editor);
4042
+ newSelection ? slate.Transforms.select(operation.editor, newSelection) : slate.Transforms.deselect(operation.editor);
4043
+ }, behaviorOperationImplementations = {
4044
+ "annotation.add": addAnnotationOperationImplementation,
4045
+ "annotation.remove": removeAnnotationOperationImplementation,
4046
+ "block.set": blockSetOperationImplementation,
4047
+ "block.unset": blockUnsetOperationImplementation,
4048
+ "decorator.add": decoratorAddOperationImplementation,
4049
+ "decorator.remove": removeDecoratorOperationImplementation,
4050
+ delete: deleteOperationImplementation,
4051
+ "delete.backward": deleteBackwardOperationImplementation,
4052
+ "delete.forward": deleteForwardOperationImplementation,
4053
+ "delete.block": deleteBlockOperationImplementation,
4054
+ "history.redo": historyRedoOperationImplementation,
4055
+ "history.undo": historyUndoOperationImplementation,
4056
+ "insert.block": insertBlockOperationImplementation,
4057
+ "insert.inline object": insertInlineObjectOperationImplementation,
4058
+ "insert.span": insertSpanOperationImplementation,
4059
+ "insert.text": insertTextOperationImplementation,
4060
+ "move.backward": moveBackwardOperationImplementation,
4061
+ "move.block": moveBlockOperationImplementation,
4062
+ "move.forward": moveForwardOperationImplementation,
4063
+ select: selectOperationImplementation
4066
4064
  };
4067
- function performAction({
4065
+ function performOperation({
4068
4066
  context,
4069
- action
4067
+ operation
4070
4068
  }) {
4071
- switch (action.type) {
4072
- case "annotation.add": {
4073
- behaviorActionImplementations["annotation.add"]({
4074
- context,
4075
- action
4076
- });
4077
- break;
4078
- }
4079
- case "annotation.remove": {
4080
- behaviorActionImplementations["annotation.remove"]({
4081
- context,
4082
- action
4083
- });
4084
- break;
4085
- }
4086
- case "block.set": {
4087
- behaviorActionImplementations["block.set"]({
4088
- context,
4089
- action
4090
- });
4091
- break;
4092
- }
4093
- case "block.unset": {
4094
- behaviorActionImplementations["block.unset"]({
4095
- context,
4096
- action
4097
- });
4098
- break;
4099
- }
4100
- case "decorator.add": {
4101
- behaviorActionImplementations["decorator.add"]({
4102
- context,
4103
- action
4104
- });
4105
- break;
4106
- }
4107
- case "decorator.remove": {
4108
- behaviorActionImplementations["decorator.remove"]({
4109
- context,
4110
- action
4111
- });
4112
- break;
4113
- }
4114
- case "delete": {
4115
- behaviorActionImplementations.delete({
4116
- context,
4117
- action
4118
- });
4119
- break;
4120
- }
4121
- case "delete.backward": {
4122
- behaviorActionImplementations["delete.backward"]({
4123
- context,
4124
- action
4125
- });
4126
- break;
4127
- }
4128
- case "delete.block": {
4129
- behaviorActionImplementations["delete.block"]({
4130
- context,
4131
- action
4132
- });
4133
- break;
4134
- }
4135
- case "delete.forward": {
4136
- behaviorActionImplementations["delete.forward"]({
4137
- context,
4138
- action
4139
- });
4140
- break;
4141
- }
4142
- case "history.redo": {
4143
- behaviorActionImplementations["history.redo"]({
4144
- context,
4145
- action
4146
- });
4147
- break;
4148
- }
4149
- case "history.undo": {
4150
- behaviorActionImplementations["history.undo"]({
4151
- context,
4152
- action
4153
- });
4154
- break;
4155
- }
4156
- case "insert.block": {
4157
- behaviorActionImplementations["insert.block"]({
4158
- context,
4159
- action
4160
- });
4161
- break;
4162
- }
4163
- case "insert.inline object": {
4164
- behaviorActionImplementations["insert.inline object"]({
4165
- context,
4166
- action
4167
- });
4168
- break;
4169
- }
4170
- case "insert.span": {
4171
- behaviorActionImplementations["insert.span"]({
4172
- context,
4173
- action
4174
- });
4175
- break;
4176
- }
4177
- case "insert.text": {
4178
- behaviorActionImplementations["insert.text"]({
4179
- context,
4180
- action
4181
- });
4182
- break;
4183
- }
4184
- case "move.backward": {
4185
- behaviorActionImplementations["move.backward"]({
4186
- context,
4187
- action
4188
- });
4189
- break;
4190
- }
4191
- case "move.block": {
4192
- behaviorActionImplementations["move.block"]({
4193
- context,
4194
- action
4195
- });
4196
- break;
4197
- }
4198
- case "move.forward": {
4199
- behaviorActionImplementations["move.forward"]({
4200
- context,
4201
- action
4202
- });
4203
- break;
4204
- }
4205
- default: {
4206
- behaviorActionImplementations.select({
4207
- context,
4208
- action
4209
- });
4210
- break;
4069
+ try {
4070
+ switch (operation.type) {
4071
+ case "annotation.add": {
4072
+ behaviorOperationImplementations["annotation.add"]({
4073
+ context,
4074
+ operation
4075
+ });
4076
+ break;
4077
+ }
4078
+ case "annotation.remove": {
4079
+ behaviorOperationImplementations["annotation.remove"]({
4080
+ context,
4081
+ operation
4082
+ });
4083
+ break;
4084
+ }
4085
+ case "block.set": {
4086
+ behaviorOperationImplementations["block.set"]({
4087
+ context,
4088
+ operation
4089
+ });
4090
+ break;
4091
+ }
4092
+ case "block.unset": {
4093
+ behaviorOperationImplementations["block.unset"]({
4094
+ context,
4095
+ operation
4096
+ });
4097
+ break;
4098
+ }
4099
+ case "decorator.add": {
4100
+ behaviorOperationImplementations["decorator.add"]({
4101
+ context,
4102
+ operation
4103
+ });
4104
+ break;
4105
+ }
4106
+ case "decorator.remove": {
4107
+ behaviorOperationImplementations["decorator.remove"]({
4108
+ context,
4109
+ operation
4110
+ });
4111
+ break;
4112
+ }
4113
+ case "delete": {
4114
+ behaviorOperationImplementations.delete({
4115
+ context,
4116
+ operation
4117
+ });
4118
+ break;
4119
+ }
4120
+ case "delete.backward": {
4121
+ behaviorOperationImplementations["delete.backward"]({
4122
+ context,
4123
+ operation
4124
+ });
4125
+ break;
4126
+ }
4127
+ case "delete.block": {
4128
+ behaviorOperationImplementations["delete.block"]({
4129
+ context,
4130
+ operation
4131
+ });
4132
+ break;
4133
+ }
4134
+ case "delete.forward": {
4135
+ behaviorOperationImplementations["delete.forward"]({
4136
+ context,
4137
+ operation
4138
+ });
4139
+ break;
4140
+ }
4141
+ case "history.redo": {
4142
+ behaviorOperationImplementations["history.redo"]({
4143
+ context,
4144
+ operation
4145
+ });
4146
+ break;
4147
+ }
4148
+ case "history.undo": {
4149
+ behaviorOperationImplementations["history.undo"]({
4150
+ context,
4151
+ operation
4152
+ });
4153
+ break;
4154
+ }
4155
+ case "insert.block": {
4156
+ behaviorOperationImplementations["insert.block"]({
4157
+ context,
4158
+ operation
4159
+ });
4160
+ break;
4161
+ }
4162
+ case "insert.inline object": {
4163
+ behaviorOperationImplementations["insert.inline object"]({
4164
+ context,
4165
+ operation
4166
+ });
4167
+ break;
4168
+ }
4169
+ case "insert.span": {
4170
+ behaviorOperationImplementations["insert.span"]({
4171
+ context,
4172
+ operation
4173
+ });
4174
+ break;
4175
+ }
4176
+ case "insert.text": {
4177
+ behaviorOperationImplementations["insert.text"]({
4178
+ context,
4179
+ operation
4180
+ });
4181
+ break;
4182
+ }
4183
+ case "move.backward": {
4184
+ behaviorOperationImplementations["move.backward"]({
4185
+ context,
4186
+ operation
4187
+ });
4188
+ break;
4189
+ }
4190
+ case "move.block": {
4191
+ behaviorOperationImplementations["move.block"]({
4192
+ context,
4193
+ operation
4194
+ });
4195
+ break;
4196
+ }
4197
+ case "move.forward": {
4198
+ behaviorOperationImplementations["move.forward"]({
4199
+ context,
4200
+ operation
4201
+ });
4202
+ break;
4203
+ }
4204
+ default: {
4205
+ behaviorOperationImplementations.select({
4206
+ context,
4207
+ operation
4208
+ });
4209
+ break;
4210
+ }
4211
4211
  }
4212
+ } catch (error) {
4213
+ console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
4212
4214
  }
4213
4215
  }
4216
+ const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
4217
+ function withApplyingBehaviorOperations(editor, fn) {
4218
+ CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
4219
+ }
4220
+ function getCurrentOperationId(editor) {
4221
+ return CURRENT_OPERATION_ID.get(editor);
4222
+ }
4223
+ function isApplyingBehaviorOperations(editor) {
4224
+ return getCurrentOperationId(editor) !== void 0;
4225
+ }
4214
4226
  function createWithEventListeners(editorActor) {
4215
4227
  return function(editor) {
4216
4228
  if (editorActor.getSnapshot().context.maxBlocks !== void 0)
4217
4229
  return editor;
4218
4230
  const {
4219
- deleteBackward,
4220
- deleteForward,
4221
- insertBreak,
4222
4231
  insertText,
4223
4232
  select
4224
4233
  } = editor;
4225
4234
  return editor.deleteBackward = (unit) => {
4226
- if (isApplyingBehaviorActions(editor)) {
4227
- deleteBackward(unit);
4235
+ if (isApplyingBehaviorOperations(editor)) {
4236
+ console.error("Unexpected call to .deleteBackward(...)");
4228
4237
  return;
4229
4238
  }
4230
4239
  editorActor.send({
@@ -4236,8 +4245,8 @@ function createWithEventListeners(editorActor) {
4236
4245
  editor
4237
4246
  });
4238
4247
  }, editor.deleteForward = (unit) => {
4239
- if (isApplyingBehaviorActions(editor)) {
4240
- deleteForward(unit);
4248
+ if (isApplyingBehaviorOperations(editor)) {
4249
+ console.error("Unexpected call to .deleteForward(...)");
4241
4250
  return;
4242
4251
  }
4243
4252
  editorActor.send({
@@ -4249,8 +4258,8 @@ function createWithEventListeners(editorActor) {
4249
4258
  editor
4250
4259
  });
4251
4260
  }, editor.insertBreak = () => {
4252
- if (isApplyingBehaviorActions(editor)) {
4253
- insertBreak();
4261
+ if (isApplyingBehaviorOperations(editor)) {
4262
+ console.error("Unexpected call to .insertBreak(...)");
4254
4263
  return;
4255
4264
  }
4256
4265
  editorActor.send({
@@ -4261,8 +4270,10 @@ function createWithEventListeners(editorActor) {
4261
4270
  editor
4262
4271
  });
4263
4272
  }, editor.insertData = (dataTransfer) => {
4264
- if (isApplyingBehaviorActions(editor))
4265
- throw new Error("Unexpected call to .insertData(...)");
4273
+ if (isApplyingBehaviorOperations(editor)) {
4274
+ console.error("Unexpected call to .insertData(...)");
4275
+ return;
4276
+ }
4266
4277
  editorActor.send({
4267
4278
  type: "behavior event",
4268
4279
  behaviorEvent: {
@@ -4274,13 +4285,13 @@ function createWithEventListeners(editorActor) {
4274
4285
  editor
4275
4286
  });
4276
4287
  }, editor.insertSoftBreak = () => {
4277
- if (isApplyingBehaviorActions(editor)) {
4278
- insertTextActionImplementation({
4288
+ if (isApplyingBehaviorOperations(editor)) {
4289
+ insertTextOperationImplementation({
4279
4290
  context: {
4280
4291
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
4281
4292
  schema: editorActor.getSnapshot().context.schema
4282
4293
  },
4283
- action: {
4294
+ operation: {
4284
4295
  text: `
4285
4296
  `,
4286
4297
  editor
@@ -4296,7 +4307,7 @@ function createWithEventListeners(editorActor) {
4296
4307
  editor
4297
4308
  });
4298
4309
  }, editor.insertText = (text, options) => {
4299
- if (isApplyingBehaviorActions(editor)) {
4310
+ if (isApplyingBehaviorOperations(editor)) {
4300
4311
  insertText(text, options);
4301
4312
  return;
4302
4313
  }
@@ -4309,13 +4320,13 @@ function createWithEventListeners(editorActor) {
4309
4320
  editor
4310
4321
  });
4311
4322
  }, editor.redo = () => {
4312
- if (isApplyingBehaviorActions(editor)) {
4313
- performAction({
4323
+ if (isApplyingBehaviorOperations(editor)) {
4324
+ performOperation({
4314
4325
  context: {
4315
4326
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
4316
4327
  schema: editorActor.getSnapshot().context.schema
4317
4328
  },
4318
- action: {
4329
+ operation: {
4319
4330
  type: "history.redo",
4320
4331
  editor
4321
4332
  }
@@ -4330,7 +4341,7 @@ function createWithEventListeners(editorActor) {
4330
4341
  editor
4331
4342
  });
4332
4343
  }, editor.select = (location) => {
4333
- if (isApplyingBehaviorActions(editor)) {
4344
+ if (isApplyingBehaviorOperations(editor)) {
4334
4345
  select(location);
4335
4346
  return;
4336
4347
  }
@@ -4348,15 +4359,15 @@ function createWithEventListeners(editorActor) {
4348
4359
  editor
4349
4360
  });
4350
4361
  }, editor.setFragmentData = () => {
4351
- console.warn("Unexpected call to .setFragmentData(...)");
4362
+ console.error("Unexpected call to .setFragmentData(...)");
4352
4363
  }, editor.undo = () => {
4353
- if (isApplyingBehaviorActions(editor)) {
4354
- performAction({
4364
+ if (isApplyingBehaviorOperations(editor)) {
4365
+ performOperation({
4355
4366
  context: {
4356
4367
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
4357
4368
  schema: editorActor.getSnapshot().context.schema
4358
4369
  },
4359
- action: {
4370
+ operation: {
4360
4371
  type: "history.undo",
4361
4372
  editor
4362
4373
  }
@@ -4760,9 +4771,14 @@ function createWithPatches({
4760
4771
  slate.Editor.withoutNormalizing(editor, () => {
4761
4772
  withoutPatching(editor, () => {
4762
4773
  withoutSaving(editor, () => {
4763
- patches2.forEach((patch) => {
4764
- debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
4765
- });
4774
+ for (const patch of patches2) {
4775
+ debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`);
4776
+ try {
4777
+ changed = applyPatch(editor, patch);
4778
+ } catch (error) {
4779
+ console.error(`Applying patch ${JSON.stringify(patch)} failed due to: ${error.message}`);
4780
+ }
4781
+ }
4766
4782
  });
4767
4783
  });
4768
4784
  }), changed && (editor.normalize(), editor.onChange());
@@ -4824,7 +4840,7 @@ function createWithPatches({
4824
4840
  ...patch,
4825
4841
  origin: "local"
4826
4842
  },
4827
- actionId: getCurrentActionId(editor),
4843
+ operationId: getCurrentOperationId(editor),
4828
4844
  value: fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
4829
4845
  });
4830
4846
  return editor;
@@ -5566,12 +5582,12 @@ function createEditableAPI(editor, editorActor) {
5566
5582
  addAnnotation: (type, value) => {
5567
5583
  let paths;
5568
5584
  return slate.Editor.withoutNormalizing(editor, () => {
5569
- paths = addAnnotationActionImplementation({
5585
+ paths = addAnnotationOperationImplementation({
5570
5586
  context: {
5571
5587
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
5572
5588
  schema: types2
5573
5589
  },
5574
- action: {
5590
+ operation: {
5575
5591
  annotation: {
5576
5592
  name: type.name,
5577
5593
  value: value ?? {}
@@ -5703,19 +5719,29 @@ function createInternalEditor(editorActor) {
5703
5719
  editorActorSnapshot: editorActor.getSnapshot(),
5704
5720
  slateEditorInstance: slateEditor.instance
5705
5721
  }),
5706
- registerBehavior: (config) => (editorActor.send({
5707
- type: "add behavior",
5708
- behavior: config.behavior
5709
- }), () => {
5710
- editorActor.send({
5711
- type: "remove behavior",
5712
- behavior: config.behavior
5713
- });
5714
- }),
5722
+ registerBehavior: (behaviorConfig) => {
5723
+ const priority = createEditorPriority({
5724
+ name: "custom",
5725
+ reference: {
5726
+ priority: corePriority,
5727
+ importance: "higher"
5728
+ }
5729
+ }), behaviorConfigWithPriority = {
5730
+ ...behaviorConfig,
5731
+ priority
5732
+ };
5733
+ return editorActor.send({
5734
+ type: "add behavior",
5735
+ behaviorConfig: behaviorConfigWithPriority
5736
+ }), () => {
5737
+ editorActor.send({
5738
+ type: "remove behavior",
5739
+ behaviorConfig: behaviorConfigWithPriority
5740
+ });
5741
+ };
5742
+ },
5715
5743
  send: (event) => {
5716
5744
  switch (event.type) {
5717
- case "add behavior":
5718
- case "remove behavior":
5719
5745
  case "update key generator":
5720
5746
  case "update readOnly":
5721
5747
  case "patches":
@@ -6459,7 +6485,10 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6459
6485
  clearListOnEnter,
6460
6486
  indentListOnTab,
6461
6487
  unindentListOnShiftTab
6462
- }, coreBehaviors = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks], abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
6488
+ }, coreBehaviorsConfig = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks].map((behavior) => ({
6489
+ behavior,
6490
+ priority: corePriority
6491
+ })), abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
6463
6492
  on: "annotation.toggle",
6464
6493
  guard: ({
6465
6494
  snapshot,
@@ -6655,7 +6684,24 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6655
6684
  text: `
6656
6685
  `
6657
6686
  })]]
6658
- })], abstractListItemBehaviors = [behaviors_index.defineBehavior({
6687
+ })], keyIs = {
6688
+ lineBreak: (event) => event.key === "Enter" && event.shiftKey
6689
+ }, abstractKeyboardBehaviors = [
6690
+ /**
6691
+ * On WebKit, Shift+Enter results in an `insertParagraph` input event rather
6692
+ * than an `insertLineBreak` input event. This Behavior makes sure we catch
6693
+ * that `keyboard.keydown` event beforehand and raise an `insert.soft break` manually.
6694
+ */
6695
+ behaviors_index.defineBehavior({
6696
+ on: "keyboard.keydown",
6697
+ guard: ({
6698
+ event
6699
+ }) => keyIs.lineBreak(event.originEvent),
6700
+ actions: [() => [behaviors_index.raise({
6701
+ type: "insert.soft break"
6702
+ })]]
6703
+ })
6704
+ ], abstractListItemBehaviors = [behaviors_index.defineBehavior({
6659
6705
  on: "list item.add",
6660
6706
  guard: ({
6661
6707
  snapshot
@@ -6981,17 +7027,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6981
7027
  type: "style.add",
6982
7028
  style: event.style
6983
7029
  })]]
6984
- })], keyIs = {
6985
- lineBreak: (event) => event.key === "Enter" && event.shiftKey
6986
- }, raiseInsertSoftBreak = behaviors_index.defineBehavior({
6987
- on: "keyboard.keydown",
6988
- guard: ({
6989
- event
6990
- }) => keyIs.lineBreak(event.originEvent),
6991
- actions: [() => [behaviors_index.raise({
6992
- type: "insert.soft break"
6993
- })]]
6994
- }), raiseDeserializationSuccessOrFailure = behaviors_index.defineBehavior({
7030
+ })], raiseDeserializationSuccessOrFailure = behaviors_index.defineBehavior({
6995
7031
  on: "deserialize",
6996
7032
  guard: ({
6997
7033
  snapshot,
@@ -7051,7 +7087,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
7051
7087
  ...serializeEvent,
7052
7088
  originEvent: event.originEvent
7053
7089
  }))]
7054
- }), defaultBehaviors = [
7090
+ }), abstractBehaviors = [
7055
7091
  behaviors_index.defineBehavior({
7056
7092
  on: "clipboard.copy",
7057
7093
  guard: ({
@@ -7326,14 +7362,14 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
7326
7362
  ...abstractDecoratorBehaviors,
7327
7363
  ...abstractDeleteBehaviors,
7328
7364
  ...abstractInsertBehaviors,
7365
+ ...abstractKeyboardBehaviors,
7329
7366
  ...abstractListItemBehaviors,
7330
7367
  ...abstractMoveBehaviors,
7331
7368
  ...abstractStyleBehaviors,
7332
7369
  ...abstractSelectBehaviors,
7333
7370
  ...abstractSplitBehaviors,
7334
7371
  raiseDeserializationSuccessOrFailure,
7335
- raiseSerializationSuccessOrFailure,
7336
- raiseInsertSoftBreak
7372
+ raiseSerializationSuccessOrFailure
7337
7373
  ];
7338
7374
  function isSyntheticBehaviorEvent(event) {
7339
7375
  return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
@@ -7365,28 +7401,24 @@ function performEvent({
7365
7401
  nativeEvent
7366
7402
  }) {
7367
7403
  debug$2(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
7368
- const eventBehaviors = [...remainingEventBehaviors, ...defaultBehaviors].filter((behavior) => {
7404
+ const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
7369
7405
  if (behavior.on === "*")
7370
7406
  return !0;
7371
7407
  const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
7372
7408
  return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
7373
7409
  });
7374
7410
  if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
7375
- nativeEvent?.preventDefault(), withApplyingBehaviorActions(editor, () => {
7376
- try {
7377
- debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performAction({
7378
- context: {
7379
- keyGenerator,
7380
- schema: schema2
7381
- },
7382
- action: {
7383
- ...event,
7384
- editor
7385
- }
7386
- });
7387
- } catch (error) {
7388
- console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
7389
- }
7411
+ nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
7412
+ debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
7413
+ context: {
7414
+ keyGenerator,
7415
+ schema: schema2
7416
+ },
7417
+ operation: {
7418
+ ...event,
7419
+ editor
7420
+ }
7421
+ });
7390
7422
  }), editor.onChange();
7391
7423
  return;
7392
7424
  }
@@ -7519,23 +7551,62 @@ function performEvent({
7519
7551
  break;
7520
7552
  }
7521
7553
  }
7522
- !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorActions(editor, () => {
7523
- try {
7524
- debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performAction({
7525
- context: {
7526
- keyGenerator,
7527
- schema: schema2
7528
- },
7529
- action: {
7530
- ...event,
7531
- editor
7532
- }
7533
- });
7534
- } catch (error) {
7535
- console.error(new Error(`Executing "${event.type}" failed due to: ${error.message}`));
7536
- }
7554
+ !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
7555
+ debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
7556
+ context: {
7557
+ keyGenerator,
7558
+ schema: schema2
7559
+ },
7560
+ operation: {
7561
+ ...event,
7562
+ editor
7563
+ }
7564
+ });
7537
7565
  }), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
7538
7566
  }
7567
+ function sortByPriority(items) {
7568
+ if (items.length === 0)
7569
+ return [];
7570
+ const itemsWithPriority = items.filter((item) => item.priority !== void 0), itemsWithoutPriority = items.filter((item) => item.priority === void 0);
7571
+ if (itemsWithPriority.length === 0)
7572
+ return items;
7573
+ const itemsByPriorityId = new Map(itemsWithPriority.map((item) => [item.priority.id, item])), graph = /* @__PURE__ */ new Map(), inDegree = /* @__PURE__ */ new Map();
7574
+ function ensureNode(id) {
7575
+ graph.has(id) || (graph.set(id, /* @__PURE__ */ new Set()), inDegree.set(id, 0));
7576
+ }
7577
+ for (const item of itemsWithPriority) {
7578
+ const id = item.priority.id;
7579
+ ensureNode(id);
7580
+ }
7581
+ function addEdge(fromId, toId) {
7582
+ !graph.has(fromId) || !graph.has(toId) || (graph.get(fromId)?.add(toId), inDegree.set(toId, (inDegree.get(toId) ?? 0) + 1));
7583
+ }
7584
+ for (const item of itemsWithPriority) {
7585
+ const id = item.priority.id, visited = /* @__PURE__ */ new Set();
7586
+ let ref = item.priority.reference;
7587
+ for (; ref; ) {
7588
+ const refId = ref.priority.id;
7589
+ if (ensureNode(refId), visited.has(refId))
7590
+ throw new Error("Circular dependency detected in priorities");
7591
+ visited.add(refId), ref.importance === "higher" ? addEdge(id, refId) : addEdge(refId, id), ref = ref.priority.reference;
7592
+ }
7593
+ }
7594
+ const queue = [];
7595
+ for (const [id, degree] of inDegree)
7596
+ degree === 0 && queue.push(id);
7597
+ const result = [];
7598
+ for (; queue.length > 0; ) {
7599
+ const currentId = queue.shift(), currentItem = itemsByPriorityId.get(currentId);
7600
+ currentItem && result.push(currentItem);
7601
+ for (const neighborId of graph.get(currentId) ?? []) {
7602
+ const newDegree = (inDegree.get(neighborId) ?? 0) - 1;
7603
+ inDegree.set(neighborId, newDegree), newDegree === 0 && queue.push(neighborId);
7604
+ }
7605
+ }
7606
+ for (const item of itemsWithPriority)
7607
+ result.includes(item) || result.push(item);
7608
+ return [...result, ...itemsWithoutPriority];
7609
+ }
7539
7610
  function createEditorSnapshot({
7540
7611
  converters,
7541
7612
  editor,
@@ -7582,13 +7653,13 @@ const editorMachine = xstate.setup({
7582
7653
  behaviors: ({
7583
7654
  context,
7584
7655
  event
7585
- }) => (xstate.assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.behavior]))
7656
+ }) => (xstate.assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.behaviorConfig]))
7586
7657
  }),
7587
7658
  "remove behavior from context": xstate.assign({
7588
7659
  behaviors: ({
7589
7660
  context,
7590
7661
  event
7591
- }) => (xstate.assertEvent(event, "remove behavior"), context.behaviors.delete(event.behavior), /* @__PURE__ */ new Set([...context.behaviors]))
7662
+ }) => (xstate.assertEvent(event, "remove behavior"), context.behaviors.delete(event.behaviorConfig), /* @__PURE__ */ new Set([...context.behaviors]))
7592
7663
  }),
7593
7664
  "assign schema": xstate.assign({
7594
7665
  schema: ({
@@ -7682,10 +7753,11 @@ const editorMachine = xstate.setup({
7682
7753
  }) => {
7683
7754
  xstate.assertEvent(event, ["behavior event"]);
7684
7755
  try {
7756
+ const behaviors = sortByPriority([...context.behaviors.values(), ...coreBehaviorsConfig]).map((config) => config.behavior);
7685
7757
  performEvent({
7686
7758
  mode: "raise",
7687
- behaviors: [...context.behaviors.values()],
7688
- remainingEventBehaviors: [...context.behaviors.values()],
7759
+ behaviors,
7760
+ remainingEventBehaviors: behaviors,
7689
7761
  event: event.behaviorEvent,
7690
7762
  editor: event.editor,
7691
7763
  keyGenerator: context.keyGenerator,
@@ -7718,7 +7790,7 @@ const editorMachine = xstate.setup({
7718
7790
  context: ({
7719
7791
  input
7720
7792
  }) => ({
7721
- behaviors: /* @__PURE__ */ new Set([...coreBehaviors]),
7793
+ behaviors: /* @__PURE__ */ new Set([]),
7722
7794
  converters: new Set(input.converters ?? []),
7723
7795
  getLegacySchema: input.getLegacySchema,
7724
7796
  keyGenerator: input.keyGenerator,
@@ -8636,7 +8708,8 @@ exports.EditorActorContext = EditorActorContext;
8636
8708
  exports.EditorProvider = EditorProvider;
8637
8709
  exports.KEY_TO_VALUE_ELEMENT = KEY_TO_VALUE_ELEMENT;
8638
8710
  exports.PortableTextEditor = PortableTextEditor;
8639
- exports.coreBehaviors = coreBehaviors;
8711
+ exports.corePriority = corePriority;
8712
+ exports.createEditorPriority = createEditorPriority;
8640
8713
  exports.debugWithName = debugWithName;
8641
8714
  exports.defaultKeyGenerator = defaultKeyGenerator;
8642
8715
  exports.defineSchema = defineSchema;