@portabletext/editor 1.44.1 → 1.44.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +3 -3
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/editor-provider.cjs +166 -272
  4. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  5. package/lib/_chunks-es/behavior.core.js +3 -3
  6. package/lib/_chunks-es/behavior.core.js.map +1 -1
  7. package/lib/_chunks-es/editor-provider.js +167 -273
  8. package/lib/_chunks-es/editor-provider.js.map +1 -1
  9. package/lib/behaviors/index.cjs +2 -2
  10. package/lib/behaviors/index.cjs.map +1 -1
  11. package/lib/behaviors/index.d.cts +7951 -15846
  12. package/lib/behaviors/index.d.ts +7951 -15846
  13. package/lib/behaviors/index.js +4 -4
  14. package/lib/behaviors/index.js.map +1 -1
  15. package/lib/index.cjs +2 -2
  16. package/lib/index.cjs.map +1 -1
  17. package/lib/index.d.cts +1742 -15478
  18. package/lib/index.d.ts +1742 -15478
  19. package/lib/index.js +2 -2
  20. package/lib/index.js.map +1 -1
  21. package/lib/plugins/index.d.cts +1742 -15479
  22. package/lib/plugins/index.d.ts +1742 -15479
  23. package/lib/selectors/index.d.cts +1739 -15475
  24. package/lib/selectors/index.d.ts +1739 -15475
  25. package/lib/utils/index.d.cts +1739 -15475
  26. package/lib/utils/index.d.ts +1739 -15475
  27. package/package.json +1 -1
  28. package/src/behavior-actions/behavior.actions.ts +0 -18
  29. package/src/behaviors/{behavior.internal.annotation.ts → behavior.abstract.annotation.ts} +1 -1
  30. package/src/behaviors/{behavior.internal.decorator.ts → behavior.abstract.decorator.ts} +1 -1
  31. package/src/behaviors/{behavior.internal.insert.ts → behavior.abstract.insert.ts} +1 -1
  32. package/src/behaviors/{behavior.internal.list-item.ts → behavior.abstract.list-item.ts} +1 -1
  33. package/src/behaviors/behavior.abstract.move.ts +78 -0
  34. package/src/behaviors/{behavior.internal.select.ts → behavior.abstract.select.ts} +1 -1
  35. package/src/behaviors/{behavior.internal.style.ts → behavior.abstract.style.ts} +1 -1
  36. package/src/behaviors/behavior.code-editor.ts +13 -8
  37. package/src/behaviors/behavior.default.ts +14 -12
  38. package/src/behaviors/behavior.perform-event.ts +4 -4
  39. package/src/behaviors/behavior.types.action.ts +3 -3
  40. package/src/behaviors/behavior.types.behavior.ts +4 -3
  41. package/src/behaviors/behavior.types.event.ts +153 -153
  42. package/src/editor/components/Leaf.tsx +2 -2
  43. package/src/editor/create-editor.ts +37 -11
  44. package/src/editor/editor-machine.ts +4 -76
  45. package/src/editor/editor-selector.ts +5 -2
  46. package/src/editor/editor-snapshot.ts +2 -7
  47. package/src/editor/plugins/create-with-event-listeners.ts +1 -64
  48. package/src/editor/plugins/with-plugins.ts +1 -4
  49. package/src/internal-utils/slate-children-to-blocks.ts +49 -0
  50. package/src/internal-utils/slate-utils.ts +6 -8
  51. package/src/type-utils.ts +2 -0
  52. package/src/behavior-actions/behavior.action.move.block-down.ts +0 -48
  53. package/src/behavior-actions/behavior.action.move.block-up.ts +0 -53
@@ -14,7 +14,7 @@ import isPlainObject from "lodash/isPlainObject.js";
14
14
  import uniq from "lodash/uniq.js";
15
15
  import getRandomValues from "get-random-values-esm";
16
16
  import { parseBlock, isTextBlock } from "./parse-blocks.js";
17
- import { sliceBlocks, blockOffsetToSpanSelectionPoint, isKeyedSegment as isKeyedSegment$1, getBlockEndPoint, getBlockStartPoint, getTextBlockText } from "./util.slice-blocks.js";
17
+ import { sliceBlocks, blockOffsetToSpanSelectionPoint, getBlockEndPoint, getBlockStartPoint, getTextBlockText } from "./util.slice-blocks.js";
18
18
  import { htmlToBlocks } from "@portabletext/block-tools";
19
19
  import { toHTML } from "@portabletext/to-html";
20
20
  import { Schema } from "@sanity/schema";
@@ -341,10 +341,7 @@ function isEqualToEmptyEditor(children, schemaTypes) {
341
341
  function getFocusBlock({
342
342
  editor
343
343
  }) {
344
- return editor.selection ? Array.from(Editor.nodes(editor, {
345
- at: editor.selection.focus.path.slice(0, 1),
346
- match: (n) => !Editor.isEditor(n)
347
- })).at(0) ?? [void 0, void 0] : [void 0, void 0];
344
+ return editor.selection ? Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0] : [void 0, void 0];
348
345
  }
349
346
  function getFocusChild({
350
347
  editor
@@ -4452,63 +4449,6 @@ const insertTextActionImplementation = ({
4452
4449
  to,
4453
4450
  mode: "highest"
4454
4451
  });
4455
- }, moveBlockDownActionImplementation = ({
4456
- context,
4457
- action
4458
- }) => {
4459
- const at = [toSlatePath(action.at, action.editor)[0]], to = [Path.next(at)[0]], selection = toPortableTextRange(action.editor.children, {
4460
- anchor: {
4461
- path: to,
4462
- offset: 0
4463
- },
4464
- focus: {
4465
- path: to,
4466
- offset: 0
4467
- }
4468
- }, context.schema), destinationBlockKey = selection && isKeyedSegment$1(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
4469
- if (destinationBlockKey === void 0) {
4470
- console.error("Could not find destination block key");
4471
- return;
4472
- }
4473
- moveBlockActionImplementation({
4474
- action: {
4475
- at: action.at,
4476
- to: [{
4477
- _key: destinationBlockKey
4478
- }],
4479
- editor: action.editor
4480
- }
4481
- });
4482
- }, moveBlockUpActionImplementation = ({
4483
- context,
4484
- action
4485
- }) => {
4486
- const at = [toSlatePath(action.at, action.editor)[0]];
4487
- if (!Path.hasPrevious(at))
4488
- return;
4489
- const to = [Path.previous(at)[0]], selection = toPortableTextRange(action.editor.children, {
4490
- anchor: {
4491
- path: to,
4492
- offset: 0
4493
- },
4494
- focus: {
4495
- path: to,
4496
- offset: 0
4497
- }
4498
- }, context.schema), destinationBlockKey = selection && isKeyedSegment$1(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
4499
- if (destinationBlockKey === void 0) {
4500
- console.error("Could not find destination block key");
4501
- return;
4502
- }
4503
- moveBlockActionImplementation({
4504
- action: {
4505
- at: action.at,
4506
- to: [{
4507
- _key: destinationBlockKey
4508
- }],
4509
- editor: action.editor
4510
- }
4511
- });
4512
4452
  }, noopActionImplementation = () => {
4513
4453
  }, selectActionImplementation = ({
4514
4454
  action
@@ -4539,8 +4479,6 @@ const insertTextActionImplementation = ({
4539
4479
  "insert.text": insertTextActionImplementation,
4540
4480
  effect: effectActionImplementation,
4541
4481
  "move.block": moveBlockActionImplementation,
4542
- "move.block down": moveBlockDownActionImplementation,
4543
- "move.block up": moveBlockUpActionImplementation,
4544
4482
  noop: noopActionImplementation,
4545
4483
  select: selectActionImplementation
4546
4484
  };
@@ -4710,20 +4648,6 @@ function performAction({
4710
4648
  });
4711
4649
  break;
4712
4650
  }
4713
- case "move.block down": {
4714
- behaviorActionImplementations["move.block down"]({
4715
- context,
4716
- action
4717
- });
4718
- break;
4719
- }
4720
- case "move.block up": {
4721
- behaviorActionImplementations["move.block up"]({
4722
- context,
4723
- action
4724
- });
4725
- break;
4726
- }
4727
4651
  case "noop":
4728
4652
  break;
4729
4653
  default: {
@@ -4735,65 +4659,10 @@ function performAction({
4735
4659
  }
4736
4660
  }
4737
4661
  }
4738
- function createWithEventListeners(editorActor, subscriptions) {
4662
+ function createWithEventListeners(editorActor) {
4739
4663
  return function(editor) {
4740
4664
  if (editorActor.getSnapshot().context.maxBlocks !== void 0)
4741
4665
  return editor;
4742
- subscriptions.push(() => {
4743
- const subscription = editorActor.on("*", (event) => {
4744
- switch (event.type) {
4745
- // These events are not relevant for Behaviors
4746
- case "blurred":
4747
- case "done loading":
4748
- case "editable":
4749
- case "error":
4750
- case "focused":
4751
- case "invalid value":
4752
- case "loading":
4753
- case "mutation":
4754
- case "patch":
4755
- case "internal.patch":
4756
- case "patches":
4757
- case "read only":
4758
- case "ready":
4759
- case "selection":
4760
- case "value changed":
4761
- case "unset":
4762
- break;
4763
- case "custom.*":
4764
- editorActor.send({
4765
- type: "custom behavior event",
4766
- behaviorEvent: event.event,
4767
- editor
4768
- });
4769
- break;
4770
- case "insert.block object":
4771
- editorActor.send({
4772
- type: "behavior event",
4773
- behaviorEvent: {
4774
- type: "insert.block",
4775
- block: {
4776
- _type: event.blockObject.name,
4777
- ...event.blockObject.value ?? {}
4778
- },
4779
- placement: event.placement
4780
- },
4781
- editor
4782
- });
4783
- break;
4784
- default:
4785
- editorActor.send({
4786
- type: "behavior event",
4787
- behaviorEvent: event,
4788
- editor
4789
- });
4790
- break;
4791
- }
4792
- });
4793
- return () => {
4794
- subscription.unsubscribe();
4795
- };
4796
- });
4797
4666
  const {
4798
4667
  deleteBackward,
4799
4668
  deleteForward,
@@ -5604,7 +5473,7 @@ const withPlugins = (editor, options) => {
5604
5473
  editorActor,
5605
5474
  schemaTypes
5606
5475
  }), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
5607
- return createWithEventListeners(editorActor, options.subscriptions)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
5476
+ return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
5608
5477
  }, debug$3 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
5609
5478
  function createSlateEditor(config) {
5610
5479
  const existingSlateEditor = slateEditors.get(config.editorActor);
@@ -5626,17 +5495,7 @@ function createSlateEditor(config) {
5626
5495
  };
5627
5496
  return slateEditors.set(config.editorActor, slateEditor), slateEditor;
5628
5497
  }
5629
- const keyIs = {
5630
- lineBreak: (event) => event.key === "Enter" && event.shiftKey
5631
- }, raiseInsertSoftBreak = defineBehavior({
5632
- on: "keyboard.keydown",
5633
- guard: ({
5634
- event
5635
- }) => keyIs.lineBreak(event.originEvent),
5636
- actions: [() => [raise({
5637
- type: "insert.soft break"
5638
- })]]
5639
- }), internalAnnotationBehaviors = [defineBehavior({
5498
+ const abstractAnnotationBehaviors = [defineBehavior({
5640
5499
  on: "annotation.toggle",
5641
5500
  guard: ({
5642
5501
  snapshot,
@@ -5660,7 +5519,7 @@ const keyIs = {
5660
5519
  type: "annotation.add",
5661
5520
  annotation: event.annotation
5662
5521
  })]]
5663
- })], internalDecoratorBehaviors = [defineBehavior({
5522
+ })], abstractDecoratorBehaviors = [defineBehavior({
5664
5523
  on: "decorator.toggle",
5665
5524
  guard: ({
5666
5525
  snapshot,
@@ -5696,7 +5555,7 @@ const keyIs = {
5696
5555
  ...event,
5697
5556
  type: "decorator.add"
5698
5557
  })]]
5699
- })], internalInsertBehaviors = [defineBehavior({
5558
+ })], abstractInsertBehaviors = [defineBehavior({
5700
5559
  on: "insert.blocks",
5701
5560
  guard: ({
5702
5561
  event
@@ -5772,7 +5631,7 @@ const keyIs = {
5772
5631
  placement: index === 0 ? "auto" : "after",
5773
5632
  select: "end"
5774
5633
  }))]
5775
- })], internalListItemBehaviors = [defineBehavior({
5634
+ })], abstractListItemBehaviors = [defineBehavior({
5776
5635
  on: "list item.add",
5777
5636
  guard: ({
5778
5637
  snapshot
@@ -5829,7 +5688,75 @@ const keyIs = {
5829
5688
  type: "list item.add",
5830
5689
  listItem: event.listItem
5831
5690
  })]]
5832
- })], internalSelectBehaviors = [defineBehavior({
5691
+ })], abstractMoveBehaviors = [defineBehavior({
5692
+ on: "move.block up",
5693
+ guard: ({
5694
+ snapshot,
5695
+ event
5696
+ }) => {
5697
+ const previousBlock = getPreviousBlock({
5698
+ context: {
5699
+ ...snapshot.context,
5700
+ selection: {
5701
+ anchor: {
5702
+ path: event.at,
5703
+ offset: 0
5704
+ },
5705
+ focus: {
5706
+ path: event.at,
5707
+ offset: 0
5708
+ }
5709
+ }
5710
+ }
5711
+ });
5712
+ return previousBlock ? {
5713
+ previousBlock
5714
+ } : !1;
5715
+ },
5716
+ actions: [({
5717
+ event
5718
+ }, {
5719
+ previousBlock
5720
+ }) => [raise({
5721
+ type: "move.block",
5722
+ at: event.at,
5723
+ to: previousBlock.path
5724
+ })]]
5725
+ }), defineBehavior({
5726
+ on: "move.block down",
5727
+ guard: ({
5728
+ snapshot,
5729
+ event
5730
+ }) => {
5731
+ const nextBlock = getNextBlock({
5732
+ context: {
5733
+ ...snapshot.context,
5734
+ selection: {
5735
+ anchor: {
5736
+ path: event.at,
5737
+ offset: 0
5738
+ },
5739
+ focus: {
5740
+ path: event.at,
5741
+ offset: 0
5742
+ }
5743
+ }
5744
+ }
5745
+ });
5746
+ return nextBlock ? {
5747
+ nextBlock
5748
+ } : !1;
5749
+ },
5750
+ actions: [({
5751
+ event
5752
+ }, {
5753
+ nextBlock
5754
+ }) => [raise({
5755
+ type: "move.block",
5756
+ at: event.at,
5757
+ to: nextBlock.path
5758
+ })]]
5759
+ })], abstractSelectBehaviors = [defineBehavior({
5833
5760
  on: "select.previous block",
5834
5761
  guard: ({
5835
5762
  snapshot,
@@ -5875,7 +5802,7 @@ const keyIs = {
5875
5802
  type: "select",
5876
5803
  selection
5877
5804
  })]]
5878
- })], internalStyleBehaviors = [defineBehavior({
5805
+ })], abstractStyleBehaviors = [defineBehavior({
5879
5806
  on: "style.add",
5880
5807
  guard: ({
5881
5808
  snapshot
@@ -5931,7 +5858,17 @@ const keyIs = {
5931
5858
  type: "style.add",
5932
5859
  style: event.style
5933
5860
  })]]
5934
- })], raiseDeserializationSuccessOrFailure = defineBehavior({
5861
+ })], keyIs = {
5862
+ lineBreak: (event) => event.key === "Enter" && event.shiftKey
5863
+ }, raiseInsertSoftBreak = defineBehavior({
5864
+ on: "keyboard.keydown",
5865
+ guard: ({
5866
+ event
5867
+ }) => keyIs.lineBreak(event.originEvent),
5868
+ actions: [() => [raise({
5869
+ type: "insert.soft break"
5870
+ })]]
5871
+ }), raiseDeserializationSuccessOrFailure = defineBehavior({
5935
5872
  on: "deserialize",
5936
5873
  guard: ({
5937
5874
  snapshot,
@@ -6259,43 +6196,30 @@ const keyIs = {
6259
6196
  originEvent: event
6260
6197
  })]]
6261
6198
  }),
6262
- ...internalAnnotationBehaviors,
6263
- ...internalDecoratorBehaviors,
6264
- ...internalInsertBehaviors,
6265
- ...internalListItemBehaviors,
6266
- ...internalStyleBehaviors,
6267
- ...internalSelectBehaviors,
6199
+ ...abstractAnnotationBehaviors,
6200
+ ...abstractDecoratorBehaviors,
6201
+ ...abstractInsertBehaviors,
6202
+ ...abstractListItemBehaviors,
6203
+ ...abstractMoveBehaviors,
6204
+ ...abstractStyleBehaviors,
6205
+ ...abstractSelectBehaviors,
6268
6206
  raiseDeserializationSuccessOrFailure,
6269
6207
  raiseSerializationSuccessOrFailure,
6270
6208
  raiseInsertSoftBreak
6271
- ];
6272
- function isKeyboardBehaviorEvent(event) {
6273
- return event.type.startsWith("keyboard.");
6274
- }
6275
- function isInternalBehaviorEvent(event) {
6276
- return event.type === "deserialize" || event.type.startsWith("deserialization.") || event.type === "insert.blocks" || event.type.startsWith("list item.") || event.type === "serialize" || event.type.startsWith("serialization.") || event.type === "select.next block" || event.type === "select.previous block" || event.type.startsWith("style.");
6209
+ ], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "style.add", "style.remove", "style.toggle"];
6210
+ function isAbstractBehaviorEvent(event) {
6211
+ return abstractBehaviorEventTypes.includes(event.type);
6277
6212
  }
6213
+ const nativeBehaviorEventTypes = ["clipboard.copy", "clipboard.cut", "clipboard.paste", "drag.dragstart", "drag.drag", "drag.dragend", "drag.dragenter", "drag.dragover", "drag.dragleave", "drag.drop", "input.*", "keyboard.keydown", "keyboard.keyup", "mouse.click"];
6278
6214
  function isNativeBehaviorEvent(event) {
6279
- return isClipboardBehaviorEvent(event) || isDragBehaviorEvent(event) || isInputBehaviorEvent(event) || isKeyboardBehaviorEvent(event) || isMouseBehaviorEvent(event);
6280
- }
6281
- function isClipboardBehaviorEvent(event) {
6282
- return event.type.startsWith("clipboard.");
6283
- }
6284
- function isDragBehaviorEvent(event) {
6285
- return event.type.startsWith("drag.");
6286
- }
6287
- function isInputBehaviorEvent(event) {
6288
- return event.type.startsWith("input.");
6289
- }
6290
- function isMouseBehaviorEvent(event) {
6291
- return event.type.startsWith("mouse.");
6215
+ return nativeBehaviorEventTypes.includes(event.type);
6292
6216
  }
6293
6217
  function isCustomBehaviorEvent(event) {
6294
6218
  return event.type.startsWith("custom.");
6295
6219
  }
6296
6220
  const debug$2 = debugWithName("behaviors:event");
6297
6221
  function eventCategory(event) {
6298
- return isNativeBehaviorEvent(event) ? "native" : isInternalBehaviorEvent(event) ? "internal" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
6222
+ return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "abstract" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
6299
6223
  }
6300
6224
  function performEvent({
6301
6225
  behaviors,
@@ -6308,7 +6232,7 @@ function performEvent({
6308
6232
  defaultActionCallback
6309
6233
  }) {
6310
6234
  debug$2(`(${eventCategory(event)})`, JSON.stringify(event, null, 2));
6311
- const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isInternalBehaviorEvent(event) ? void 0 : {
6235
+ const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
6312
6236
  ...event,
6313
6237
  editor
6314
6238
  }, eventBehaviors = behaviors.filter((behavior) => {
@@ -6427,6 +6351,34 @@ function performEvent({
6427
6351
  }), editor.onChange();
6428
6352
  }
6429
6353
  }
6354
+ function slateChildrenToBlocks(schema, value) {
6355
+ const blocks = new Array(value.length);
6356
+ for (let blockIndex = 0; blockIndex < value.length; blockIndex++) {
6357
+ const descendant = value[blockIndex];
6358
+ if (descendant._type !== schema.block.name) {
6359
+ blocks[blockIndex] = {
6360
+ _key: descendant._key,
6361
+ _type: descendant._type,
6362
+ ..."value" in descendant && typeof descendant.value == "object" ? descendant.value : {}
6363
+ };
6364
+ continue;
6365
+ }
6366
+ const children = "children" in descendant ? descendant.children : [], processedChildren = new Array(children.length);
6367
+ for (let childIndex = 0; childIndex < children.length; childIndex++) {
6368
+ const child = children[childIndex];
6369
+ processedChildren[childIndex] = child._type === schema.span.name ? child : {
6370
+ _key: child._key,
6371
+ _type: child._type,
6372
+ ..."value" in child && typeof child.value == "object" ? child.value : {}
6373
+ };
6374
+ }
6375
+ blocks[blockIndex] = {
6376
+ ...descendant,
6377
+ children: processedChildren
6378
+ };
6379
+ }
6380
+ return blocks;
6381
+ }
6430
6382
  function getActiveDecorators({
6431
6383
  schema,
6432
6384
  slateEditorInstance
@@ -6445,7 +6397,7 @@ function createEditorSnapshot({
6445
6397
  hasTag,
6446
6398
  internalDrag
6447
6399
  }) {
6448
- const value = fromSlateValue(editor.children, schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema);
6400
+ const value = slateChildrenToBlocks(schema, editor.children), selection = toPortableTextRange(value, editor.selection, schema);
6449
6401
  return {
6450
6402
  context: {
6451
6403
  activeDecorators: getActiveDecorators({
@@ -6541,7 +6493,7 @@ const editorMachine = setup({
6541
6493
  event,
6542
6494
  self
6543
6495
  }) => {
6544
- assertEvent(event, ["behavior event", "custom behavior event"]), performEvent({
6496
+ assertEvent(event, ["behavior event"]), performEvent({
6545
6497
  behaviors: [...context.behaviors.values(), ...defaultBehaviors],
6546
6498
  event: event.behaviorEvent,
6547
6499
  editor: event.editor,
@@ -6740,87 +6692,6 @@ const editorMachine = setup({
6740
6692
  },
6741
6693
  "behavior event": {
6742
6694
  actions: "handle behavior event"
6743
- },
6744
- "custom behavior event": {
6745
- actions: "handle behavior event"
6746
- },
6747
- "annotation.*": {
6748
- actions: emit(({
6749
- event
6750
- }) => event)
6751
- },
6752
- "block.*": {
6753
- actions: emit(({
6754
- event
6755
- }) => event)
6756
- },
6757
- blur: {
6758
- actions: emit(({
6759
- event
6760
- }) => event)
6761
- },
6762
- "custom.*": {
6763
- actions: emit(({
6764
- event
6765
- }) => ({
6766
- type: "custom.*",
6767
- event
6768
- }))
6769
- },
6770
- "decorator.*": {
6771
- actions: emit(({
6772
- event
6773
- }) => event)
6774
- },
6775
- "delete.*": {
6776
- actions: emit(({
6777
- event
6778
- }) => event)
6779
- },
6780
- focus: {
6781
- actions: emit(({
6782
- event
6783
- }) => event)
6784
- },
6785
- "history.*": {
6786
- actions: emit(({
6787
- event
6788
- }) => event)
6789
- },
6790
- "insert.*": {
6791
- actions: emit(({
6792
- event
6793
- }) => event)
6794
- },
6795
- "list item.*": {
6796
- actions: emit(({
6797
- event
6798
- }) => event)
6799
- },
6800
- "move.*": {
6801
- actions: emit(({
6802
- event
6803
- }) => event)
6804
- },
6805
- select: {
6806
- actions: emit(({
6807
- event
6808
- }) => event)
6809
- },
6810
- "select.*": {
6811
- actions: emit(({
6812
- event
6813
- }) => event)
6814
- },
6815
- "style.*": {
6816
- actions: emit(({
6817
- event
6818
- }) => event)
6819
- },
6820
- "text block.*": {
6821
- actions: emit(({
6822
- event
6823
- }) => event)
6824
6695
  }
6825
6696
  },
6826
6697
  initial: "idle",
@@ -6932,12 +6803,6 @@ const editorMachine = setup({
6932
6803
  }
6933
6804
  }
6934
6805
  });
6935
- function getValue({
6936
- editorActorSnapshot,
6937
- slateEditorInstance
6938
- }) {
6939
- return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
6940
- }
6941
6806
  function defaultCompare(a, b) {
6942
6807
  return a === b;
6943
6808
  }
@@ -6969,10 +6834,7 @@ function getEditorSnapshot({
6969
6834
  }),
6970
6835
  schema: editorActorSnapshot.context.schema,
6971
6836
  selection: editorActorSnapshot.context.selection,
6972
- value: getValue({
6973
- editorActorSnapshot,
6974
- slateEditorInstance
6975
- })
6837
+ value: slateChildrenToBlocks(editorActorSnapshot.context.schema, slateEditorInstance.children)
6976
6838
  },
6977
6839
  beta: {
6978
6840
  hasTag: (tag) => editorActorSnapshot.hasTag(tag),
@@ -7028,7 +6890,39 @@ function createInternalEditorFromActor(editorActor) {
7028
6890
  });
7029
6891
  }),
7030
6892
  send: (event) => {
7031
- editorActor.send(event);
6893
+ switch (event.type) {
6894
+ case "add behavior":
6895
+ case "remove behavior":
6896
+ case "update behaviors":
6897
+ case "update key generator":
6898
+ case "update readOnly":
6899
+ case "patches":
6900
+ case "update value":
6901
+ case "update schema":
6902
+ case "update maxBlocks":
6903
+ editorActor.send(event);
6904
+ break;
6905
+ case "insert.block object":
6906
+ editorActor.send({
6907
+ type: "behavior event",
6908
+ behaviorEvent: {
6909
+ type: "insert.block",
6910
+ block: {
6911
+ _type: event.blockObject.name,
6912
+ ...event.blockObject.value ?? {}
6913
+ },
6914
+ placement: event.placement
6915
+ },
6916
+ editor: slateEditor.instance
6917
+ });
6918
+ break;
6919
+ default:
6920
+ editorActor.send({
6921
+ type: "behavior event",
6922
+ behaviorEvent: event,
6923
+ editor: slateEditor.instance
6924
+ });
6925
+ }
7032
6926
  },
7033
6927
  on: (event, listener) => editorActor.on(event, (event2) => {
7034
6928
  switch (event2.type) {