@portabletext/editor 1.48.13 → 1.48.14

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 (67) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +633 -628
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-es/editor-provider.js +634 -629
  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 +4 -2564
  7. package/lib/behaviors/index.d.ts +4 -2564
  8. package/lib/behaviors/index.js.map +1 -1
  9. package/lib/index.d.cts +5 -2564
  10. package/lib/index.d.ts +5 -2564
  11. package/lib/plugins/index.cjs +1 -7
  12. package/lib/plugins/index.cjs.map +1 -1
  13. package/lib/plugins/index.d.cts +4 -2569
  14. package/lib/plugins/index.d.ts +4 -2569
  15. package/lib/plugins/index.js +2 -8
  16. package/lib/plugins/index.js.map +1 -1
  17. package/lib/selectors/index.d.cts +3 -2563
  18. package/lib/selectors/index.d.ts +3 -2563
  19. package/lib/utils/index.d.cts +5 -2564
  20. package/lib/utils/index.d.ts +5 -2564
  21. package/package.json +1 -1
  22. package/src/behaviors/behavior.abstract.keyboard.ts +16 -0
  23. package/src/behaviors/{behavior.default.ts → behavior.abstract.ts} +3 -3
  24. package/src/behaviors/behavior.core.ts +0 -3
  25. package/src/behaviors/behavior.perform-event.ts +27 -51
  26. package/src/behaviors/behavior.types.action.ts +1 -11
  27. package/src/editor/PortableTextEditor.tsx +1 -1
  28. package/src/editor/editor-machine.ts +7 -4
  29. package/src/editor/mutation-machine.ts +6 -6
  30. package/src/editor/plugins/create-with-event-listeners.ts +25 -25
  31. package/src/editor/plugins/createWithEditableAPI.ts +3 -3
  32. package/src/editor/plugins/createWithPatches.ts +13 -5
  33. package/src/editor/plugins/createWithPortableTextMarkModel.ts +5 -5
  34. package/src/editor/plugins/createWithUndoRedo.ts +8 -8
  35. package/src/editor/with-applying-behavior-operations.ts +18 -0
  36. package/src/editor/{with-applying-behavior-actions.ts → with-undo-step.ts} +1 -19
  37. package/src/index.ts +1 -1
  38. package/src/{behavior-actions/behavior.action.annotation.add.ts → operations/behavior.operation.annotation.add.ts} +7 -7
  39. package/src/{behavior-actions/behavior.action.annotation.remove.ts → operations/behavior.operation.annotation.remove.ts} +6 -6
  40. package/src/{behavior-actions/behavior.action.block.set.ts → operations/behavior.operation.block.set.ts} +14 -14
  41. package/src/{behavior-actions/behavior.action.block.unset.ts → operations/behavior.operation.block.unset.ts} +19 -17
  42. package/src/{behavior-actions/behavior.action.decorator.add.ts → operations/behavior.operation.decorator.add.ts} +10 -10
  43. package/src/operations/behavior.operation.delete.backward.ts +8 -0
  44. package/src/operations/behavior.operation.delete.block.ts +24 -0
  45. package/src/operations/behavior.operation.delete.forward.ts +8 -0
  46. package/src/{behavior-actions/behavior.action.delete.ts → operations/behavior.operation.delete.ts} +8 -8
  47. package/src/{behavior-actions/behavior.action.insert-inline-object.ts → operations/behavior.operation.insert-inline-object.ts} +11 -11
  48. package/src/{behavior-actions/behavior.action.insert-span.ts → operations/behavior.operation.insert-span.ts} +15 -15
  49. package/src/{behavior-actions/behavior.action.insert.block.ts → operations/behavior.operation.insert.block.ts} +8 -8
  50. package/src/operations/behavior.operation.insert.text.ts +17 -0
  51. package/src/operations/behavior.operation.move.backward.ts +12 -0
  52. package/src/operations/behavior.operation.move.block.ts +16 -0
  53. package/src/operations/behavior.operation.move.forward.ts +11 -0
  54. package/src/operations/behavior.operation.select.ts +15 -0
  55. package/src/operations/behavior.operations.ts +239 -0
  56. package/src/plugins/index.ts +0 -1
  57. package/src/behavior-actions/behavior.action.delete.backward.ts +0 -7
  58. package/src/behavior-actions/behavior.action.delete.block.ts +0 -24
  59. package/src/behavior-actions/behavior.action.delete.forward.ts +0 -7
  60. package/src/behavior-actions/behavior.action.insert.text.ts +0 -17
  61. package/src/behavior-actions/behavior.action.move.backward.ts +0 -12
  62. package/src/behavior-actions/behavior.action.move.block.ts +0 -16
  63. package/src/behavior-actions/behavior.action.move.forward.ts +0 -11
  64. package/src/behavior-actions/behavior.action.select.ts +0 -15
  65. package/src/behavior-actions/behavior.actions.ts +0 -219
  66. package/src/behaviors/behavior.default.raise-soft-break.ts +0 -14
  67. 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) {
@@ -2626,13 +2616,214 @@ function createOperationToPatches(editorActor) {
2626
2616
  splitNodePatch
2627
2617
  };
2628
2618
  }
2629
- const insertTextActionImplementation = ({
2630
- action
2619
+ function getFocusBlock({
2620
+ editor
2621
+ }) {
2622
+ if (!editor.selection)
2623
+ return [void 0, void 0];
2624
+ try {
2625
+ return slate.Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0];
2626
+ } catch {
2627
+ return [void 0, void 0];
2628
+ }
2629
+ }
2630
+ function getSelectionStartBlock({
2631
+ editor
2632
+ }) {
2633
+ if (!editor.selection)
2634
+ return [void 0, void 0];
2635
+ const selectionStartPoint = slate.Range.start(editor.selection);
2636
+ return getPointBlock({
2637
+ editor,
2638
+ point: selectionStartPoint
2639
+ });
2640
+ }
2641
+ function getSelectionEndBlock({
2642
+ editor
2643
+ }) {
2644
+ if (!editor.selection)
2645
+ return [void 0, void 0];
2646
+ const selectionEndPoint = slate.Range.end(editor.selection);
2647
+ return getPointBlock({
2648
+ editor,
2649
+ point: selectionEndPoint
2650
+ });
2651
+ }
2652
+ function getPointBlock({
2653
+ editor,
2654
+ point
2655
+ }) {
2656
+ try {
2657
+ const [block] = slate.Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
2658
+ return block ? [block, point.path.slice(0, 1)] : [void 0, void 0];
2659
+ } catch {
2660
+ return [void 0, void 0];
2661
+ }
2662
+ }
2663
+ function getFocusChild({
2664
+ editor
2665
+ }) {
2666
+ const [focusBlock, focusBlockPath] = getFocusBlock({
2667
+ editor
2668
+ }), childIndex = editor.selection?.focus.path.at(1);
2669
+ if (!focusBlock || !focusBlockPath || childIndex === void 0)
2670
+ return [void 0, void 0];
2671
+ try {
2672
+ const focusChild = slate.Node.child(focusBlock, childIndex);
2673
+ return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
2674
+ } catch {
2675
+ return [void 0, void 0];
2676
+ }
2677
+ }
2678
+ function getPointChild({
2679
+ editor,
2680
+ point
2681
+ }) {
2682
+ const [block, blockPath] = getPointBlock({
2683
+ editor,
2684
+ point
2685
+ }), childIndex = point.path.at(1);
2686
+ if (!block || !blockPath || childIndex === void 0)
2687
+ return [void 0, void 0];
2688
+ try {
2689
+ const pointChild = slate.Node.child(block, childIndex);
2690
+ return pointChild ? [pointChild, [...blockPath, childIndex]] : [void 0, void 0];
2691
+ } catch {
2692
+ return [void 0, void 0];
2693
+ }
2694
+ }
2695
+ function getFirstBlock({
2696
+ editor
2697
+ }) {
2698
+ const firstBlockPath = slate.Editor.start(editor, []).path.at(0);
2699
+ try {
2700
+ return firstBlockPath !== void 0 ? slate.Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
2701
+ } catch {
2702
+ return [void 0, void 0];
2703
+ }
2704
+ }
2705
+ function getLastBlock({
2706
+ editor
2707
+ }) {
2708
+ const lastBlockPath = slate.Editor.end(editor, []).path.at(0);
2709
+ try {
2710
+ return lastBlockPath !== void 0 ? slate.Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
2711
+ } catch {
2712
+ return [void 0, void 0];
2713
+ }
2714
+ }
2715
+ function getNodeBlock({
2716
+ editor,
2717
+ schema: schema2,
2718
+ node
2719
+ }) {
2720
+ if (slate.Editor.isEditor(node))
2721
+ return;
2722
+ if (isBlockElement({
2723
+ editor,
2724
+ schema: schema2
2725
+ }, node))
2726
+ return elementToBlock({
2727
+ schema: schema2,
2728
+ element: node
2729
+ });
2730
+ const parent = Array.from(slate.Editor.nodes(editor, {
2731
+ mode: "highest",
2732
+ at: [],
2733
+ match: (n) => isBlockElement({
2734
+ editor,
2735
+ schema: schema2
2736
+ }, n) && n.children.some((child) => child._key === node._key)
2737
+ })).at(0)?.at(0);
2738
+ return slate.Element.isElement(parent) ? elementToBlock({
2739
+ schema: schema2,
2740
+ element: parent
2741
+ }) : void 0;
2742
+ }
2743
+ function elementToBlock({
2744
+ schema: schema2,
2745
+ element
2746
+ }) {
2747
+ return fromSlateValue([element], schema2.block.name)?.at(0);
2748
+ }
2749
+ function isBlockElement({
2750
+ editor,
2751
+ schema: schema2
2752
+ }, node) {
2753
+ return slate.Element.isElement(node) && !editor.isInline(node) && (schema2.block.name === node._type || schema2.blockObjects.some((blockObject) => blockObject.name === node._type));
2754
+ }
2755
+ function isListItemActive({
2756
+ editor,
2757
+ listItem
2758
+ }) {
2759
+ if (!editor.selection)
2760
+ return !1;
2761
+ const selectedBlocks = [...slate.Editor.nodes(editor, {
2762
+ at: editor.selection,
2763
+ match: (node) => editor.isTextBlock(node)
2764
+ })];
2765
+ return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
2766
+ }
2767
+ function isStyleActive({
2768
+ editor,
2769
+ style
2770
+ }) {
2771
+ if (!editor.selection)
2772
+ return !1;
2773
+ const selectedBlocks = [...slate.Editor.nodes(editor, {
2774
+ at: editor.selection,
2775
+ match: (node) => editor.isTextBlock(node)
2776
+ })];
2777
+ return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
2778
+ }
2779
+ function slateRangeToSelection({
2780
+ schema: schema2,
2781
+ editor,
2782
+ range
2783
+ }) {
2784
+ const [anchorBlock] = getPointBlock({
2785
+ editor,
2786
+ point: range.anchor
2787
+ }), [focusBlock] = getPointBlock({
2788
+ editor,
2789
+ point: range.focus
2790
+ });
2791
+ if (!anchorBlock || !focusBlock)
2792
+ return null;
2793
+ const [anchorChild] = anchorBlock._type === schema2.block.name ? getPointChild({
2794
+ editor,
2795
+ point: range.anchor
2796
+ }) : [void 0, void 0], [focusChild] = focusBlock._type === schema2.block.name ? getPointChild({
2797
+ editor,
2798
+ point: range.focus
2799
+ }) : [void 0, void 0], selection = {
2800
+ anchor: {
2801
+ path: [{
2802
+ _key: anchorBlock._key
2803
+ }],
2804
+ offset: range.anchor.offset
2805
+ },
2806
+ focus: {
2807
+ path: [{
2808
+ _key: focusBlock._key
2809
+ }],
2810
+ offset: range.focus.offset
2811
+ },
2812
+ backward: slate.Range.isBackward(range)
2813
+ };
2814
+ return anchorChild && (selection.anchor.path.push("children"), selection.anchor.path.push({
2815
+ _key: anchorChild._key
2816
+ })), focusChild && (selection.focus.path.push("children"), selection.focus.path.push({
2817
+ _key: focusChild._key
2818
+ })), selection;
2819
+ }
2820
+ const insertTextOperationImplementation = ({
2821
+ operation
2631
2822
  }) => {
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;
2823
+ operation.editor.marks ? slate.Transforms.insertNodes(operation.editor, {
2824
+ text: operation.text,
2825
+ ...operation.editor.marks
2826
+ }) : slate.Transforms.insertText(operation.editor, operation.text), operation.editor.marks = null;
2636
2827
  };
2637
2828
  function isPortableTextSpan(node) {
2638
2829
  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 +3223,10 @@ function createWithPortableTextMarkModel(editorActor) {
3032
3223
  }, editor;
3033
3224
  };
3034
3225
  }
3035
- const removeDecoratorActionImplementation = ({
3036
- action
3226
+ const removeDecoratorOperationImplementation = ({
3227
+ operation
3037
3228
  }) => {
3038
- const editor = action.editor, mark = action.decorator, {
3229
+ const editor = operation.editor, mark = operation.decorator, {
3039
3230
  selection
3040
3231
  } = editor;
3041
3232
  if (selection) {
@@ -3106,14 +3297,14 @@ function isDecoratorActive({
3106
3297
  ...slate.Editor.marks(editor) || {}
3107
3298
  }.marks || []).includes(decorator);
3108
3299
  }
3109
- const addAnnotationActionImplementation = ({
3300
+ const addAnnotationOperationImplementation = ({
3110
3301
  context,
3111
- action
3302
+ operation
3112
3303
  }) => {
3113
3304
  const parsedAnnotation = util_sliceBlocks.parseAnnotation({
3114
3305
  annotation: {
3115
- _type: action.annotation.name,
3116
- ...action.annotation.value
3306
+ _type: operation.annotation.name,
3307
+ ...operation.annotation.value
3117
3308
  },
3118
3309
  context,
3119
3310
  options: {
@@ -3121,8 +3312,8 @@ const addAnnotationActionImplementation = ({
3121
3312
  }
3122
3313
  });
3123
3314
  if (!parsedAnnotation)
3124
- throw new Error(`Failed to parse annotation ${JSON.stringify(action.annotation)}`);
3125
- const editor = action.editor;
3315
+ throw new Error(`Failed to parse annotation ${JSON.stringify(operation.annotation)}`);
3316
+ const editor = operation.editor;
3126
3317
  if (!editor.selection || slate.Range.isCollapsed(editor.selection))
3127
3318
  return;
3128
3319
  let paths, spanPath, markDefPath;
@@ -3173,10 +3364,10 @@ const addAnnotationActionImplementation = ({
3173
3364
  markDefPaths,
3174
3365
  spanPath
3175
3366
  }), paths;
3176
- }, removeAnnotationActionImplementation = ({
3177
- action
3367
+ }, removeAnnotationOperationImplementation = ({
3368
+ operation
3178
3369
  }) => {
3179
- const editor = action.editor;
3370
+ const editor = operation.editor;
3180
3371
  if (editor.selection)
3181
3372
  if (slate.Range.isCollapsed(editor.selection)) {
3182
3373
  const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
@@ -3184,7 +3375,7 @@ const addAnnotationActionImplementation = ({
3184
3375
  });
3185
3376
  if (!editor.isTextBlock(block))
3186
3377
  return;
3187
- const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = slate.Editor.node(editor, editor.selection, {
3378
+ const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), [selectedChild, selectedChildPath] = slate.Editor.node(editor, editor.selection, {
3188
3379
  depth: 2
3189
3380
  });
3190
3381
  if (!editor.isTextSpan(selectedChild))
@@ -3229,7 +3420,7 @@ const addAnnotationActionImplementation = ({
3229
3420
  for (const [child, childPath] of children) {
3230
3421
  if (!editor.isTextSpan(child) || !slate.Range.includes(editor.selection, childPath))
3231
3422
  continue;
3232
- const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== action.annotation.name);
3423
+ const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
3233
3424
  marksWithoutAnnotation.length !== marks.length && slate.Transforms.setNodes(editor, {
3234
3425
  marks: marksWithoutAnnotation
3235
3426
  }, {
@@ -3281,34 +3472,34 @@ function moveRangeByOperation(range, operation) {
3281
3472
  focus
3282
3473
  };
3283
3474
  }
3284
- const blockSetBehaviorActionImplementation = ({
3475
+ const blockSetOperationImplementation = ({
3285
3476
  context,
3286
- action
3477
+ operation
3287
3478
  }) => {
3288
3479
  const location = toSlateRange({
3289
3480
  anchor: {
3290
- path: action.at,
3481
+ path: operation.at,
3291
3482
  offset: 0
3292
3483
  },
3293
3484
  focus: {
3294
- path: action.at,
3485
+ path: operation.at,
3295
3486
  offset: 0
3296
3487
  }
3297
- }, action.editor);
3488
+ }, operation.editor);
3298
3489
  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, {
3490
+ throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
3491
+ const block = slate.Editor.node(operation.editor, location, {
3301
3492
  depth: 1
3302
3493
  })?.[0];
3303
3494
  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);
3495
+ throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
3496
+ const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
3306
3497
  if (!parsedBlock)
3307
- throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
3498
+ throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
3308
3499
  const {
3309
3500
  _type,
3310
3501
  ...filteredProps
3311
- } = action.props, updatedBlock = util_sliceBlocks.parseBlock({
3502
+ } = operation.props, updatedBlock = util_sliceBlocks.parseBlock({
3312
3503
  context,
3313
3504
  block: {
3314
3505
  ...parsedBlock,
@@ -3319,302 +3510,100 @@ const blockSetBehaviorActionImplementation = ({
3319
3510
  }
3320
3511
  });
3321
3512
  if (!updatedBlock)
3322
- throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
3513
+ throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
3323
3514
  const slateBlock = toSlateValue([updatedBlock], {
3324
3515
  schemaTypes: context.schema
3325
3516
  })?.at(0);
3326
3517
  if (!slateBlock)
3327
3518
  throw new Error("Unable to convert block to Slate value");
3328
- slate.Transforms.setNodes(action.editor, slateBlock, {
3519
+ slate.Transforms.setNodes(operation.editor, slateBlock, {
3329
3520
  at: location
3330
3521
  });
3331
- }, blockUnsetBehaviorActionImplementation = ({
3522
+ }, blockUnsetOperationImplementation = ({
3332
3523
  context,
3333
- action
3524
+ operation
3334
3525
  }) => {
3335
- const location = toSlateRange({
3336
- anchor: {
3337
- path: action.at,
3338
- offset: 0
3339
- },
3340
- focus: {
3341
- path: action.at,
3342
- offset: 0
3343
- }
3344
- }, action.editor);
3345
- 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, {
3348
- depth: 1
3349
- })?.[0];
3350
- 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);
3353
- if (!parsedBlock)
3354
- throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
3355
- if (util_sliceBlocks.isTextBlock(context, parsedBlock)) {
3356
- const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_sliceBlocks.parseBlock({
3357
- context,
3358
- block: omit__default.default(parsedBlock, propsToRemove),
3359
- options: {
3360
- refreshKeys: !1
3361
- }
3362
- });
3363
- if (!updatedTextBlock)
3364
- throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
3365
- const propsToSet = {};
3366
- for (const prop of propsToRemove)
3367
- prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
3368
- slate.Transforms.setNodes(action.editor, propsToSet, {
3369
- at: location
3370
- });
3371
- return;
3372
- }
3373
- const updatedBlockObject = util_sliceBlocks.parseBlock({
3374
- context,
3375
- block: omit__default.default(parsedBlock, action.props.filter((prop) => prop !== "_type")),
3376
- options: {
3377
- refreshKeys: !1
3378
- }
3379
- });
3380
- if (!updatedBlockObject)
3381
- throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
3382
- 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
3566
- });
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
3526
+ const location = toSlateRange({
3527
+ anchor: {
3528
+ path: operation.at,
3529
+ offset: 0
3581
3530
  },
3582
3531
  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 = ({
3532
+ path: operation.at,
3533
+ offset: 0
3534
+ }
3535
+ }, operation.editor);
3536
+ if (!location)
3537
+ throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
3538
+ const block = slate.Editor.node(operation.editor, location, {
3539
+ depth: 1
3540
+ })?.[0];
3541
+ if (!block)
3542
+ throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
3543
+ const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
3544
+ if (!parsedBlock)
3545
+ throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
3546
+ if (util_sliceBlocks.isTextBlock(context, parsedBlock)) {
3547
+ const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_sliceBlocks.parseBlock({
3548
+ context,
3549
+ block: omit__default.default(parsedBlock, propsToRemove),
3550
+ options: {
3551
+ refreshKeys: !1
3552
+ }
3553
+ });
3554
+ if (!updatedTextBlock)
3555
+ throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
3556
+ const propsToSet = {};
3557
+ for (const prop of propsToRemove)
3558
+ prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
3559
+ slate.Transforms.setNodes(operation.editor, propsToSet, {
3560
+ at: location
3561
+ });
3562
+ return;
3563
+ }
3564
+ const updatedBlockObject = util_sliceBlocks.parseBlock({
3565
+ context,
3566
+ block: omit__default.default(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
3567
+ options: {
3568
+ refreshKeys: !1
3569
+ }
3570
+ });
3571
+ if (!updatedBlockObject)
3572
+ throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
3573
+ const {
3574
+ _type,
3575
+ _key,
3576
+ ...props
3577
+ } = updatedBlockObject;
3578
+ slate.Transforms.setNodes(operation.editor, {
3579
+ _type,
3580
+ _key,
3581
+ value: props
3582
+ }, {
3583
+ at: location
3584
+ });
3585
+ }, decoratorAddOperationImplementation = ({
3597
3586
  context,
3598
- action
3587
+ operation
3599
3588
  }) => {
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({
3589
+ 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
3590
  context: {
3602
3591
  ...context,
3603
3592
  value
3604
3593
  },
3605
- blockOffset: action.at.anchor,
3594
+ blockOffset: operation.at.anchor,
3606
3595
  direction: "backward"
3607
- }) : void 0, manualFocus = action.at?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3596
+ }) : void 0, manualFocus = operation.at?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3608
3597
  context: {
3609
3598
  ...context,
3610
3599
  value
3611
3600
  },
3612
- blockOffset: action.at.focus,
3601
+ blockOffset: operation.at.focus,
3613
3602
  direction: "forward"
3614
3603
  }) : void 0, manualSelection = manualAnchor && manualFocus ? {
3615
3604
  anchor: manualAnchor,
3616
3605
  focus: manualFocus
3617
- } : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
3606
+ } : void 0, selection = manualSelection ? toSlateRange(manualSelection, operation.editor) ?? editor.selection : editor.selection;
3618
3607
  if (!selection)
3619
3608
  return;
3620
3609
  const editorSelection = slateRangeToSelection({
@@ -3717,82 +3706,82 @@ const decoratorAddActionImplementation = ({
3717
3706
  ...selection2
3718
3707
  };
3719
3708
  }
3720
- }, deleteActionImplementation = ({
3709
+ }, deleteOperationImplementation = ({
3721
3710
  context,
3722
- action
3711
+ operation
3723
3712
  }) => {
3724
- const range = toSlateRange(action.at, action.editor);
3713
+ const range = toSlateRange(operation.at, operation.editor);
3725
3714
  if (!range)
3726
- throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.at)}`);
3715
+ throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
3727
3716
  if (slate.Range.isCollapsed(range)) {
3728
3717
  const [focusBlock] = getFocusBlock({
3729
3718
  editor: {
3730
- ...action.editor,
3719
+ ...operation.editor,
3731
3720
  selection: range
3732
3721
  }
3733
3722
  }), [focusChild] = getFocusChild({
3734
3723
  editor: {
3735
- ...action.editor,
3724
+ ...operation.editor,
3736
3725
  selection: range
3737
3726
  }
3738
3727
  });
3739
3728
  if (focusBlock && focusBlock._type === context.schema.block.name && focusChild && focusChild._type === context.schema.span.name)
3740
3729
  return;
3741
3730
  }
3742
- action.editor.delete({
3731
+ operation.editor.delete({
3743
3732
  at: range
3744
3733
  });
3745
- }, deleteBackwardActionImplementation = ({
3746
- action
3734
+ }, deleteBackwardOperationImplementation = ({
3735
+ operation
3747
3736
  }) => {
3748
- action.editor.deleteBackward(action.unit);
3749
- }, deleteBlockActionImplementation = ({
3750
- action
3737
+ slate.deleteBackward(operation.editor, operation.unit);
3738
+ }, deleteBlockOperationImplementation = ({
3739
+ operation
3751
3740
  }) => {
3752
3741
  const range = toSlateRange({
3753
3742
  anchor: {
3754
- path: action.at,
3743
+ path: operation.at,
3755
3744
  offset: 0
3756
3745
  },
3757
3746
  focus: {
3758
- path: action.at,
3747
+ path: operation.at,
3759
3748
  offset: 0
3760
3749
  }
3761
- }, action.editor);
3750
+ }, operation.editor);
3762
3751
  if (!range) {
3763
3752
  console.error("Unable to find Slate range from selection points");
3764
3753
  return;
3765
3754
  }
3766
- slate.Transforms.removeNodes(action.editor, {
3755
+ slate.Transforms.removeNodes(operation.editor, {
3767
3756
  at: range
3768
3757
  });
3769
- }, deleteForwardActionImplementation = ({
3770
- action
3758
+ }, deleteForwardOperationImplementation = ({
3759
+ operation
3771
3760
  }) => {
3772
- action.editor.deleteForward(action.unit);
3773
- }, insertInlineObjectActionImplementation = ({
3761
+ slate.deleteForward(operation.editor, operation.unit);
3762
+ }, insertInlineObjectOperationImplementation = ({
3774
3763
  context,
3775
- action
3764
+ operation
3776
3765
  }) => {
3777
3766
  const parsedInlineObject = util_sliceBlocks.parseInlineObject({
3778
3767
  context,
3779
3768
  inlineObject: {
3780
- _type: action.inlineObject.name,
3781
- ...action.inlineObject.value ?? {}
3769
+ _type: operation.inlineObject.name,
3770
+ ...operation.inlineObject.value ?? {}
3782
3771
  },
3783
3772
  options: {
3784
3773
  refreshKeys: !1
3785
3774
  }
3786
3775
  });
3787
3776
  if (!parsedInlineObject)
3788
- throw new Error(`Failed to parse inline object ${JSON.stringify(action.inlineObject)}`);
3789
- if (!action.editor.selection) {
3777
+ throw new Error(`Failed to parse inline object ${JSON.stringify(operation.inlineObject)}`);
3778
+ if (!operation.editor.selection) {
3790
3779
  console.error("Unable to insert inline object without selection");
3791
3780
  return;
3792
3781
  }
3793
- const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
3794
- at: action.editor.selection.focus.path,
3795
- match: (node) => action.editor.isTextBlock(node)
3782
+ const [focusTextBlock] = Array.from(slate.Editor.nodes(operation.editor, {
3783
+ at: operation.editor.selection.focus.path,
3784
+ match: (node) => operation.editor.isTextBlock(node)
3796
3785
  })).at(0) ?? [void 0, void 0];
3797
3786
  if (!focusTextBlock) {
3798
3787
  console.error("Unable to perform action without focus text block");
@@ -3809,49 +3798,49 @@ const decoratorAddActionImplementation = ({
3809
3798
  console.error("Unable to insert inline object");
3810
3799
  return;
3811
3800
  }
3812
- slate.Transforms.insertNodes(action.editor, child);
3813
- }, insertSpanActionImplementation = ({
3801
+ slate.Transforms.insertNodes(operation.editor, child);
3802
+ }, insertSpanOperationImplementation = ({
3814
3803
  context,
3815
- action
3804
+ operation
3816
3805
  }) => {
3817
- if (!action.editor.selection) {
3818
- console.error("Unable to perform action without selection", action);
3806
+ if (!operation.editor.selection) {
3807
+ console.error("Unable to perform action without selection", operation);
3819
3808
  return;
3820
3809
  }
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)
3810
+ const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(operation.editor, {
3811
+ at: operation.editor.selection.focus.path,
3812
+ match: (node) => operation.editor.isTextBlock(node)
3824
3813
  }))[0] ?? [void 0, void 0];
3825
3814
  if (!focusBlock || !focusBlockPath) {
3826
- console.error("Unable to perform action without focus block", action);
3815
+ console.error("Unable to perform action without focus block", operation);
3827
3816
  return;
3828
3817
  }
3829
- const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
3818
+ const markDefs = focusBlock.markDefs ?? [], annotations = operation.annotations ? operation.annotations.map((annotation) => ({
3830
3819
  _type: annotation.name,
3831
3820
  _key: context.keyGenerator(),
3832
3821
  ...annotation.value
3833
3822
  })) : void 0;
3834
- annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
3823
+ annotations && annotations.length > 0 && slate.Transforms.setNodes(operation.editor, {
3835
3824
  markDefs: [...markDefs, ...annotations]
3836
- }), slate.Transforms.insertNodes(action.editor, {
3825
+ }), slate.Transforms.insertNodes(operation.editor, {
3837
3826
  _type: "span",
3838
3827
  _key: context.keyGenerator(),
3839
- text: action.text,
3840
- marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
3828
+ text: operation.text,
3829
+ marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...operation.decorators ?? []]
3841
3830
  });
3842
- }, insertBlockActionImplementation = ({
3831
+ }, insertBlockOperationImplementation = ({
3843
3832
  context,
3844
- action
3833
+ operation
3845
3834
  }) => {
3846
3835
  const parsedBlock = util_sliceBlocks.parseBlock({
3847
- block: action.block,
3836
+ block: operation.block,
3848
3837
  context,
3849
3838
  options: {
3850
3839
  refreshKeys: !1
3851
3840
  }
3852
3841
  });
3853
3842
  if (!parsedBlock)
3854
- throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`);
3843
+ throw new Error(`Failed to parse block ${JSON.stringify(operation.block)}`);
3855
3844
  const fragment = toSlateValue([parsedBlock], {
3856
3845
  schemaTypes: context.schema
3857
3846
  })[0];
@@ -3859,9 +3848,9 @@ const decoratorAddActionImplementation = ({
3859
3848
  throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
3860
3849
  insertBlock({
3861
3850
  block: fragment,
3862
- placement: action.placement,
3863
- select: action.select ?? "start",
3864
- editor: action.editor,
3851
+ placement: operation.placement,
3852
+ select: operation.select ?? "start",
3853
+ editor: operation.editor,
3865
3854
  schema: context.schema
3866
3855
  });
3867
3856
  };
@@ -4013,218 +4002,229 @@ function insertBlock({
4013
4002
  }
4014
4003
  }
4015
4004
  }
4016
- const moveBackwardActionImplementation = ({
4017
- action
4005
+ const moveBackwardOperationImplementation = ({
4006
+ operation
4018
4007
  }) => {
4019
- slate.Transforms.move(action.editor, {
4008
+ slate.Transforms.move(operation.editor, {
4020
4009
  unit: "character",
4021
- distance: action.distance,
4010
+ distance: operation.distance,
4022
4011
  reverse: !0
4023
4012
  });
4024
- }, moveBlockActionImplementation = ({
4025
- action
4013
+ }, moveBlockOperationImplementation = ({
4014
+ operation
4026
4015
  }) => {
4027
- const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
4028
- slate.Transforms.moveNodes(action.editor, {
4016
+ const at = [toSlatePath(operation.at, operation.editor)[0]], to = [toSlatePath(operation.to, operation.editor)[0]];
4017
+ slate.Transforms.moveNodes(operation.editor, {
4029
4018
  at,
4030
4019
  to,
4031
4020
  mode: "highest"
4032
4021
  });
4033
- }, moveForwardActionImplementation = ({
4034
- action
4022
+ }, moveForwardOperationImplementation = ({
4023
+ operation
4035
4024
  }) => {
4036
- slate.Transforms.move(action.editor, {
4025
+ slate.Transforms.move(operation.editor, {
4037
4026
  unit: "character",
4038
- distance: action.distance
4027
+ distance: operation.distance
4039
4028
  });
4040
- }, selectActionImplementation = ({
4041
- action
4029
+ }, selectOperationImplementation = ({
4030
+ operation
4042
4031
  }) => {
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
4032
+ const newSelection = toSlateRange(operation.at, operation.editor);
4033
+ newSelection ? slate.Transforms.select(operation.editor, newSelection) : slate.Transforms.deselect(operation.editor);
4034
+ }, behaviorOperationImplementations = {
4035
+ "annotation.add": addAnnotationOperationImplementation,
4036
+ "annotation.remove": removeAnnotationOperationImplementation,
4037
+ "block.set": blockSetOperationImplementation,
4038
+ "block.unset": blockUnsetOperationImplementation,
4039
+ "decorator.add": decoratorAddOperationImplementation,
4040
+ "decorator.remove": removeDecoratorOperationImplementation,
4041
+ delete: deleteOperationImplementation,
4042
+ "delete.backward": deleteBackwardOperationImplementation,
4043
+ "delete.forward": deleteForwardOperationImplementation,
4044
+ "delete.block": deleteBlockOperationImplementation,
4045
+ "history.redo": historyRedoOperationImplementation,
4046
+ "history.undo": historyUndoOperationImplementation,
4047
+ "insert.block": insertBlockOperationImplementation,
4048
+ "insert.inline object": insertInlineObjectOperationImplementation,
4049
+ "insert.span": insertSpanOperationImplementation,
4050
+ "insert.text": insertTextOperationImplementation,
4051
+ "move.backward": moveBackwardOperationImplementation,
4052
+ "move.block": moveBlockOperationImplementation,
4053
+ "move.forward": moveForwardOperationImplementation,
4054
+ select: selectOperationImplementation
4066
4055
  };
4067
- function performAction({
4056
+ function performOperation({
4068
4057
  context,
4069
- action
4058
+ operation
4070
4059
  }) {
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;
4060
+ try {
4061
+ switch (operation.type) {
4062
+ case "annotation.add": {
4063
+ behaviorOperationImplementations["annotation.add"]({
4064
+ context,
4065
+ operation
4066
+ });
4067
+ break;
4068
+ }
4069
+ case "annotation.remove": {
4070
+ behaviorOperationImplementations["annotation.remove"]({
4071
+ context,
4072
+ operation
4073
+ });
4074
+ break;
4075
+ }
4076
+ case "block.set": {
4077
+ behaviorOperationImplementations["block.set"]({
4078
+ context,
4079
+ operation
4080
+ });
4081
+ break;
4082
+ }
4083
+ case "block.unset": {
4084
+ behaviorOperationImplementations["block.unset"]({
4085
+ context,
4086
+ operation
4087
+ });
4088
+ break;
4089
+ }
4090
+ case "decorator.add": {
4091
+ behaviorOperationImplementations["decorator.add"]({
4092
+ context,
4093
+ operation
4094
+ });
4095
+ break;
4096
+ }
4097
+ case "decorator.remove": {
4098
+ behaviorOperationImplementations["decorator.remove"]({
4099
+ context,
4100
+ operation
4101
+ });
4102
+ break;
4103
+ }
4104
+ case "delete": {
4105
+ behaviorOperationImplementations.delete({
4106
+ context,
4107
+ operation
4108
+ });
4109
+ break;
4110
+ }
4111
+ case "delete.backward": {
4112
+ behaviorOperationImplementations["delete.backward"]({
4113
+ context,
4114
+ operation
4115
+ });
4116
+ break;
4117
+ }
4118
+ case "delete.block": {
4119
+ behaviorOperationImplementations["delete.block"]({
4120
+ context,
4121
+ operation
4122
+ });
4123
+ break;
4124
+ }
4125
+ case "delete.forward": {
4126
+ behaviorOperationImplementations["delete.forward"]({
4127
+ context,
4128
+ operation
4129
+ });
4130
+ break;
4131
+ }
4132
+ case "history.redo": {
4133
+ behaviorOperationImplementations["history.redo"]({
4134
+ context,
4135
+ operation
4136
+ });
4137
+ break;
4138
+ }
4139
+ case "history.undo": {
4140
+ behaviorOperationImplementations["history.undo"]({
4141
+ context,
4142
+ operation
4143
+ });
4144
+ break;
4145
+ }
4146
+ case "insert.block": {
4147
+ behaviorOperationImplementations["insert.block"]({
4148
+ context,
4149
+ operation
4150
+ });
4151
+ break;
4152
+ }
4153
+ case "insert.inline object": {
4154
+ behaviorOperationImplementations["insert.inline object"]({
4155
+ context,
4156
+ operation
4157
+ });
4158
+ break;
4159
+ }
4160
+ case "insert.span": {
4161
+ behaviorOperationImplementations["insert.span"]({
4162
+ context,
4163
+ operation
4164
+ });
4165
+ break;
4166
+ }
4167
+ case "insert.text": {
4168
+ behaviorOperationImplementations["insert.text"]({
4169
+ context,
4170
+ operation
4171
+ });
4172
+ break;
4173
+ }
4174
+ case "move.backward": {
4175
+ behaviorOperationImplementations["move.backward"]({
4176
+ context,
4177
+ operation
4178
+ });
4179
+ break;
4180
+ }
4181
+ case "move.block": {
4182
+ behaviorOperationImplementations["move.block"]({
4183
+ context,
4184
+ operation
4185
+ });
4186
+ break;
4187
+ }
4188
+ case "move.forward": {
4189
+ behaviorOperationImplementations["move.forward"]({
4190
+ context,
4191
+ operation
4192
+ });
4193
+ break;
4194
+ }
4195
+ default: {
4196
+ behaviorOperationImplementations.select({
4197
+ context,
4198
+ operation
4199
+ });
4200
+ break;
4201
+ }
4211
4202
  }
4203
+ } catch (error) {
4204
+ console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
4212
4205
  }
4213
4206
  }
4207
+ const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
4208
+ function withApplyingBehaviorOperations(editor, fn) {
4209
+ CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
4210
+ }
4211
+ function getCurrentOperationId(editor) {
4212
+ return CURRENT_OPERATION_ID.get(editor);
4213
+ }
4214
+ function isApplyingBehaviorOperations(editor) {
4215
+ return getCurrentOperationId(editor) !== void 0;
4216
+ }
4214
4217
  function createWithEventListeners(editorActor) {
4215
4218
  return function(editor) {
4216
4219
  if (editorActor.getSnapshot().context.maxBlocks !== void 0)
4217
4220
  return editor;
4218
4221
  const {
4219
- deleteBackward,
4220
- deleteForward,
4221
- insertBreak,
4222
4222
  insertText,
4223
4223
  select
4224
4224
  } = editor;
4225
4225
  return editor.deleteBackward = (unit) => {
4226
- if (isApplyingBehaviorActions(editor)) {
4227
- deleteBackward(unit);
4226
+ if (isApplyingBehaviorOperations(editor)) {
4227
+ console.error("Unexpected call to .deleteBackward(...)");
4228
4228
  return;
4229
4229
  }
4230
4230
  editorActor.send({
@@ -4236,8 +4236,8 @@ function createWithEventListeners(editorActor) {
4236
4236
  editor
4237
4237
  });
4238
4238
  }, editor.deleteForward = (unit) => {
4239
- if (isApplyingBehaviorActions(editor)) {
4240
- deleteForward(unit);
4239
+ if (isApplyingBehaviorOperations(editor)) {
4240
+ console.error("Unexpected call to .deleteForward(...)");
4241
4241
  return;
4242
4242
  }
4243
4243
  editorActor.send({
@@ -4249,8 +4249,8 @@ function createWithEventListeners(editorActor) {
4249
4249
  editor
4250
4250
  });
4251
4251
  }, editor.insertBreak = () => {
4252
- if (isApplyingBehaviorActions(editor)) {
4253
- insertBreak();
4252
+ if (isApplyingBehaviorOperations(editor)) {
4253
+ console.error("Unexpected call to .insertBreak(...)");
4254
4254
  return;
4255
4255
  }
4256
4256
  editorActor.send({
@@ -4261,8 +4261,10 @@ function createWithEventListeners(editorActor) {
4261
4261
  editor
4262
4262
  });
4263
4263
  }, editor.insertData = (dataTransfer) => {
4264
- if (isApplyingBehaviorActions(editor))
4265
- throw new Error("Unexpected call to .insertData(...)");
4264
+ if (isApplyingBehaviorOperations(editor)) {
4265
+ console.error("Unexpected call to .insertData(...)");
4266
+ return;
4267
+ }
4266
4268
  editorActor.send({
4267
4269
  type: "behavior event",
4268
4270
  behaviorEvent: {
@@ -4274,13 +4276,13 @@ function createWithEventListeners(editorActor) {
4274
4276
  editor
4275
4277
  });
4276
4278
  }, editor.insertSoftBreak = () => {
4277
- if (isApplyingBehaviorActions(editor)) {
4278
- insertTextActionImplementation({
4279
+ if (isApplyingBehaviorOperations(editor)) {
4280
+ insertTextOperationImplementation({
4279
4281
  context: {
4280
4282
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
4281
4283
  schema: editorActor.getSnapshot().context.schema
4282
4284
  },
4283
- action: {
4285
+ operation: {
4284
4286
  text: `
4285
4287
  `,
4286
4288
  editor
@@ -4296,7 +4298,7 @@ function createWithEventListeners(editorActor) {
4296
4298
  editor
4297
4299
  });
4298
4300
  }, editor.insertText = (text, options) => {
4299
- if (isApplyingBehaviorActions(editor)) {
4301
+ if (isApplyingBehaviorOperations(editor)) {
4300
4302
  insertText(text, options);
4301
4303
  return;
4302
4304
  }
@@ -4309,13 +4311,13 @@ function createWithEventListeners(editorActor) {
4309
4311
  editor
4310
4312
  });
4311
4313
  }, editor.redo = () => {
4312
- if (isApplyingBehaviorActions(editor)) {
4313
- performAction({
4314
+ if (isApplyingBehaviorOperations(editor)) {
4315
+ performOperation({
4314
4316
  context: {
4315
4317
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
4316
4318
  schema: editorActor.getSnapshot().context.schema
4317
4319
  },
4318
- action: {
4320
+ operation: {
4319
4321
  type: "history.redo",
4320
4322
  editor
4321
4323
  }
@@ -4330,7 +4332,7 @@ function createWithEventListeners(editorActor) {
4330
4332
  editor
4331
4333
  });
4332
4334
  }, editor.select = (location) => {
4333
- if (isApplyingBehaviorActions(editor)) {
4335
+ if (isApplyingBehaviorOperations(editor)) {
4334
4336
  select(location);
4335
4337
  return;
4336
4338
  }
@@ -4348,15 +4350,15 @@ function createWithEventListeners(editorActor) {
4348
4350
  editor
4349
4351
  });
4350
4352
  }, editor.setFragmentData = () => {
4351
- console.warn("Unexpected call to .setFragmentData(...)");
4353
+ console.error("Unexpected call to .setFragmentData(...)");
4352
4354
  }, editor.undo = () => {
4353
- if (isApplyingBehaviorActions(editor)) {
4354
- performAction({
4355
+ if (isApplyingBehaviorOperations(editor)) {
4356
+ performOperation({
4355
4357
  context: {
4356
4358
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
4357
4359
  schema: editorActor.getSnapshot().context.schema
4358
4360
  },
4359
- action: {
4361
+ operation: {
4360
4362
  type: "history.undo",
4361
4363
  editor
4362
4364
  }
@@ -4760,9 +4762,14 @@ function createWithPatches({
4760
4762
  slate.Editor.withoutNormalizing(editor, () => {
4761
4763
  withoutPatching(editor, () => {
4762
4764
  withoutSaving(editor, () => {
4763
- patches2.forEach((patch) => {
4764
- debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
4765
- });
4765
+ for (const patch of patches2) {
4766
+ debug$8.enabled && debug$8(`Handling remote patch ${JSON.stringify(patch)}`);
4767
+ try {
4768
+ changed = applyPatch(editor, patch);
4769
+ } catch (error) {
4770
+ console.error(`Applying patch ${JSON.stringify(patch)} failed due to: ${error.message}`);
4771
+ }
4772
+ }
4766
4773
  });
4767
4774
  });
4768
4775
  }), changed && (editor.normalize(), editor.onChange());
@@ -4824,7 +4831,7 @@ function createWithPatches({
4824
4831
  ...patch,
4825
4832
  origin: "local"
4826
4833
  },
4827
- actionId: getCurrentActionId(editor),
4834
+ operationId: getCurrentOperationId(editor),
4828
4835
  value: fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
4829
4836
  });
4830
4837
  return editor;
@@ -5566,12 +5573,12 @@ function createEditableAPI(editor, editorActor) {
5566
5573
  addAnnotation: (type, value) => {
5567
5574
  let paths;
5568
5575
  return slate.Editor.withoutNormalizing(editor, () => {
5569
- paths = addAnnotationActionImplementation({
5576
+ paths = addAnnotationOperationImplementation({
5570
5577
  context: {
5571
5578
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
5572
5579
  schema: types2
5573
5580
  },
5574
- action: {
5581
+ operation: {
5575
5582
  annotation: {
5576
5583
  name: type.name,
5577
5584
  value: value ?? {}
@@ -6655,7 +6662,24 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6655
6662
  text: `
6656
6663
  `
6657
6664
  })]]
6658
- })], abstractListItemBehaviors = [behaviors_index.defineBehavior({
6665
+ })], keyIs = {
6666
+ lineBreak: (event) => event.key === "Enter" && event.shiftKey
6667
+ }, abstractKeyboardBehaviors = [
6668
+ /**
6669
+ * On WebKit, Shift+Enter results in an `insertParagraph` input event rather
6670
+ * than an `insertLineBreak` input event. This Behavior makes sure we catch
6671
+ * that `keyboard.keydown` event beforehand and raise an `insert.soft break` manually.
6672
+ */
6673
+ behaviors_index.defineBehavior({
6674
+ on: "keyboard.keydown",
6675
+ guard: ({
6676
+ event
6677
+ }) => keyIs.lineBreak(event.originEvent),
6678
+ actions: [() => [behaviors_index.raise({
6679
+ type: "insert.soft break"
6680
+ })]]
6681
+ })
6682
+ ], abstractListItemBehaviors = [behaviors_index.defineBehavior({
6659
6683
  on: "list item.add",
6660
6684
  guard: ({
6661
6685
  snapshot
@@ -6981,17 +7005,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
6981
7005
  type: "style.add",
6982
7006
  style: event.style
6983
7007
  })]]
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({
7008
+ })], raiseDeserializationSuccessOrFailure = behaviors_index.defineBehavior({
6995
7009
  on: "deserialize",
6996
7010
  guard: ({
6997
7011
  snapshot,
@@ -7051,7 +7065,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
7051
7065
  ...serializeEvent,
7052
7066
  originEvent: event.originEvent
7053
7067
  }))]
7054
- }), defaultBehaviors = [
7068
+ }), abstractBehaviors = [
7055
7069
  behaviors_index.defineBehavior({
7056
7070
  on: "clipboard.copy",
7057
7071
  guard: ({
@@ -7326,14 +7340,14 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
7326
7340
  ...abstractDecoratorBehaviors,
7327
7341
  ...abstractDeleteBehaviors,
7328
7342
  ...abstractInsertBehaviors,
7343
+ ...abstractKeyboardBehaviors,
7329
7344
  ...abstractListItemBehaviors,
7330
7345
  ...abstractMoveBehaviors,
7331
7346
  ...abstractStyleBehaviors,
7332
7347
  ...abstractSelectBehaviors,
7333
7348
  ...abstractSplitBehaviors,
7334
7349
  raiseDeserializationSuccessOrFailure,
7335
- raiseSerializationSuccessOrFailure,
7336
- raiseInsertSoftBreak
7350
+ raiseSerializationSuccessOrFailure
7337
7351
  ];
7338
7352
  function isSyntheticBehaviorEvent(event) {
7339
7353
  return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
@@ -7365,28 +7379,24 @@ function performEvent({
7365
7379
  nativeEvent
7366
7380
  }) {
7367
7381
  debug$2(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2));
7368
- const eventBehaviors = [...remainingEventBehaviors, ...defaultBehaviors].filter((behavior) => {
7382
+ const eventBehaviors = [...remainingEventBehaviors, ...abstractBehaviors].filter((behavior) => {
7369
7383
  if (behavior.on === "*")
7370
7384
  return !0;
7371
7385
  const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
7372
7386
  return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
7373
7387
  });
7374
7388
  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
- }
7389
+ nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
7390
+ debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
7391
+ context: {
7392
+ keyGenerator,
7393
+ schema: schema2
7394
+ },
7395
+ operation: {
7396
+ ...event,
7397
+ editor
7398
+ }
7399
+ });
7390
7400
  }), editor.onChange();
7391
7401
  return;
7392
7402
  }
@@ -7519,21 +7529,17 @@ function performEvent({
7519
7529
  break;
7520
7530
  }
7521
7531
  }
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
- }
7532
+ !defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), withApplyingBehaviorOperations(editor, () => {
7533
+ debug$2(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
7534
+ context: {
7535
+ keyGenerator,
7536
+ schema: schema2
7537
+ },
7538
+ operation: {
7539
+ ...event,
7540
+ editor
7541
+ }
7542
+ });
7537
7543
  }), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
7538
7544
  }
7539
7545
  function createEditorSnapshot({
@@ -7684,8 +7690,8 @@ const editorMachine = xstate.setup({
7684
7690
  try {
7685
7691
  performEvent({
7686
7692
  mode: "raise",
7687
- behaviors: [...context.behaviors.values()],
7688
- remainingEventBehaviors: [...context.behaviors.values()],
7693
+ behaviors: [...context.behaviors.values(), ...coreBehaviors],
7694
+ remainingEventBehaviors: [...context.behaviors.values(), ...coreBehaviors],
7689
7695
  event: event.behaviorEvent,
7690
7696
  editor: event.editor,
7691
7697
  keyGenerator: context.keyGenerator,
@@ -7718,7 +7724,7 @@ const editorMachine = xstate.setup({
7718
7724
  context: ({
7719
7725
  input
7720
7726
  }) => ({
7721
- behaviors: /* @__PURE__ */ new Set([...coreBehaviors]),
7727
+ behaviors: /* @__PURE__ */ new Set([]),
7722
7728
  converters: new Set(input.converters ?? []),
7723
7729
  getLegacySchema: input.getLegacySchema,
7724
7730
  keyGenerator: input.keyGenerator,
@@ -8636,7 +8642,6 @@ exports.EditorActorContext = EditorActorContext;
8636
8642
  exports.EditorProvider = EditorProvider;
8637
8643
  exports.KEY_TO_VALUE_ELEMENT = KEY_TO_VALUE_ELEMENT;
8638
8644
  exports.PortableTextEditor = PortableTextEditor;
8639
- exports.coreBehaviors = coreBehaviors;
8640
8645
  exports.debugWithName = debugWithName;
8641
8646
  exports.defaultKeyGenerator = defaultKeyGenerator;
8642
8647
  exports.defineSchema = defineSchema;