@portabletext/editor 2.7.2 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +3 -1
  2. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +10 -4
  4. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -1
  6. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.slice-blocks.cjs +60 -9
  8. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  9. package/lib/_chunks-dts/behavior.types.action.d.cts +149 -149
  10. package/lib/_chunks-dts/behavior.types.action.d.ts +86 -86
  11. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +4 -2
  12. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  13. package/lib/_chunks-es/selector.is-selection-expanded.js +10 -4
  14. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  15. package/lib/_chunks-es/util.merge-text-blocks.js +0 -1
  16. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
  17. package/lib/_chunks-es/util.slice-blocks.js +56 -8
  18. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  19. package/lib/index.cjs +94 -131
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.js +90 -128
  22. package/lib/index.js.map +1 -1
  23. package/lib/plugins/index.d.cts +3 -3
  24. package/lib/selectors/index.d.cts +13 -3
  25. package/lib/selectors/index.d.ts +13 -3
  26. package/package.json +13 -14
  27. package/src/behaviors/behavior.abstract.insert.ts +58 -1
  28. package/src/behaviors/behavior.abstract.split.ts +0 -1
  29. package/src/behaviors/behavior.core.annotations.ts +24 -2
  30. package/src/behaviors/behavior.core.ts +1 -1
  31. package/src/behaviors/behavior.types.event.ts +18 -18
  32. package/src/converters/converter.portable-text.ts +0 -1
  33. package/src/converters/converter.text-html.serialize.test.ts +27 -17
  34. package/src/converters/converter.text-html.ts +0 -1
  35. package/src/converters/converter.text-plain.test.ts +1 -1
  36. package/src/converters/converter.text-plain.ts +0 -1
  37. package/src/editor/Editable.tsx +0 -1
  38. package/src/editor/plugins/createWithEditableAPI.ts +16 -0
  39. package/src/internal-utils/parse-blocks.test.ts +23 -23
  40. package/src/internal-utils/parse-blocks.ts +13 -24
  41. package/src/internal-utils/test-editor.tsx +15 -21
  42. package/src/operations/behavior.operation.annotation.add.ts +2 -13
  43. package/src/operations/behavior.operation.block.set.ts +1 -1
  44. package/src/operations/behavior.operation.block.unset.ts +2 -2
  45. package/src/operations/behavior.operation.insert.block.ts +1 -1
  46. package/src/operations/behavior.operations.ts +0 -18
  47. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +25 -71
  48. package/src/plugins/plugin.markdown.test.tsx +12 -30
  49. package/src/selectors/selector.get-selected-value.test.ts +748 -0
  50. package/src/selectors/selector.get-selected-value.ts +28 -7
  51. package/src/selectors/selector.get-trimmed-selection.test.ts +0 -1
  52. package/src/selectors/selector.is-active-annotation.test.ts +320 -0
  53. package/src/selectors/selector.is-active-annotation.ts +24 -0
  54. package/src/utils/util.merge-text-blocks.ts +1 -1
  55. package/src/utils/util.slice-blocks.ts +36 -3
  56. package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -430
  57. package/src/editor/__tests__/PortableTextEditorTester.tsx +0 -58
  58. package/src/editor/__tests__/RangeDecorations.test.tsx +0 -213
  59. package/src/editor/__tests__/insert-block.test.tsx +0 -224
  60. package/src/editor/__tests__/self-solving.test.tsx +0 -183
  61. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +0 -298
  62. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +0 -177
  63. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +0 -538
  64. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +0 -162
  65. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +0 -65
  66. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +0 -612
  67. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +0 -103
  68. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +0 -147
  69. package/src/internal-utils/__tests__/valueNormalization.test.tsx +0 -79
  70. package/src/operations/behavior.operation.insert-inline-object.ts +0 -59
  71. package/src/operations/behavior.operation.insert-span.ts +0 -48
  72. package/src/utils/util.slice-blocks.test.ts +0 -465
package/lib/index.js CHANGED
@@ -8,15 +8,14 @@ import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transform
8
8
  import { useSelected, useSlateSelector, useSlateStatic, useSlate, Editable, ReactEditor, withReact, Slate } from "slate-react";
9
9
  import debug$f from "debug";
10
10
  import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
11
- import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, parseBlocks, parseBlock, parseAnnotation, parseInlineObject, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText } from "./_chunks-es/util.slice-blocks.js";
11
+ import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText } from "./_chunks-es/util.slice-blocks.js";
12
12
  import { getBlockEndPoint, isSelectionCollapsed, isEqualSelectionPoints, isEmptyTextBlock } from "./_chunks-es/util.is-selection-collapsed.js";
13
13
  import isEqual from "lodash/isEqual.js";
14
14
  import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
15
15
  import { defineSchema } from "@portabletext/schema";
16
16
  import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getSelectionStartPoint as getSelectionStartPoint$1, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.is-selection-expanded.js";
17
- import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getActiveAnnotationsMarks, getTrimmedSelection, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveAnnotation, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
18
- import getRandomValues from "get-random-values-esm";
19
- import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
17
+ import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getActiveAnnotationsMarks, getTrimmedSelection, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
18
+ import { defineBehavior, forward, raise, effect, execute } from "./behaviors/index.js";
20
19
  import uniq from "lodash/uniq.js";
21
20
  import { setup, fromCallback, assign, and, enqueueActions, emit, assertEvent, raise as raise$1, not, createActor } from "xstate";
22
21
  import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
@@ -770,25 +769,6 @@ function getDragSelection({
770
769
  }
771
770
  return dragSelection;
772
771
  }
773
- const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
774
- let table;
775
- return () => {
776
- if (table)
777
- return table;
778
- table = [];
779
- for (let i = 0; i < 256; ++i)
780
- table[i] = (i + 256).toString(16).slice(1);
781
- return table;
782
- };
783
- })();
784
- function whatwgRNG(length = 16) {
785
- const rnds8 = new Uint8Array(length);
786
- return getRandomValues(rnds8), rnds8;
787
- }
788
- function randomKey(length) {
789
- const table = getByteHexTable();
790
- return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
791
- }
792
772
  function createEditorPriority(config) {
793
773
  return {
794
774
  id: defaultKeyGenerator(),
@@ -1968,7 +1948,6 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
1968
1948
  },
1969
1949
  blocks: result_1.insert,
1970
1950
  options: {
1971
- refreshKeys: !1,
1972
1951
  validateFields: !1
1973
1952
  }
1974
1953
  }),
@@ -2433,7 +2412,6 @@ const converterJson = {
2433
2412
  context: snapshot.context,
2434
2413
  block,
2435
2414
  options: {
2436
- refreshKeys: !1,
2437
2415
  validateFields: !1
2438
2416
  }
2439
2417
  });
@@ -2496,7 +2474,6 @@ function createConverterTextHtml(legacySchema) {
2496
2474
  context: snapshot.context,
2497
2475
  block,
2498
2476
  options: {
2499
- refreshKeys: !1,
2500
2477
  validateFields: !1
2501
2478
  }
2502
2479
  });
@@ -2544,7 +2521,6 @@ function createConverterTextPlain(legacySchema) {
2544
2521
  context: snapshot.context,
2545
2522
  block,
2546
2523
  options: {
2547
- refreshKeys: !1,
2548
2524
  validateFields: !1
2549
2525
  }
2550
2526
  });
@@ -4007,7 +3983,6 @@ const addAnnotationOperationImplementation = ({
4007
3983
  },
4008
3984
  context,
4009
3985
  options: {
4010
- refreshKeys: !1,
4011
3986
  validateFields: !0
4012
3987
  }
4013
3988
  });
@@ -4046,9 +4021,9 @@ const addAnnotationOperationImplementation = ({
4046
4021
  for (const [span, path] of children) {
4047
4022
  if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
4048
4023
  continue;
4049
- const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === parsedAnnotation._type));
4024
+ const marks = span.marks ?? [];
4050
4025
  Transforms.setNodes(editor, {
4051
- marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
4026
+ marks: [...marks, annotationKey]
4052
4027
  }, {
4053
4028
  at: path
4054
4029
  }), spanPath = [{
@@ -4170,7 +4145,6 @@ const addAnnotationOperationImplementation = ({
4170
4145
  ...filteredProps
4171
4146
  },
4172
4147
  options: {
4173
- refreshKeys: !1,
4174
4148
  validateFields: !0
4175
4149
  }
4176
4150
  });
@@ -4220,7 +4194,6 @@ const addAnnotationOperationImplementation = ({
4220
4194
  context,
4221
4195
  block: omit(parsedBlock, propsToRemove),
4222
4196
  options: {
4223
- refreshKeys: !1,
4224
4197
  validateFields: !0
4225
4198
  }
4226
4199
  });
@@ -4238,7 +4211,6 @@ const addAnnotationOperationImplementation = ({
4238
4211
  context,
4239
4212
  block: omit(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
4240
4213
  options: {
4241
- refreshKeys: !1,
4242
4214
  validateFields: !0
4243
4215
  }
4244
4216
  });
@@ -4619,77 +4591,7 @@ function domRectsIntersect(rect, compareRect) {
4619
4591
  const middle = (compareRect.top + compareRect.bottom) / 2;
4620
4592
  return rect.top <= middle && rect.bottom >= middle;
4621
4593
  }
4622
- const insertInlineObjectOperationImplementation = ({
4623
- context,
4624
- operation
4625
- }) => {
4626
- const parsedInlineObject = parseInlineObject({
4627
- context,
4628
- inlineObject: {
4629
- _type: operation.inlineObject.name,
4630
- ...operation.inlineObject.value ?? {}
4631
- },
4632
- options: {
4633
- refreshKeys: !1,
4634
- validateFields: !0
4635
- }
4636
- });
4637
- if (!parsedInlineObject)
4638
- throw new Error(`Failed to parse inline object ${JSON.stringify(operation.inlineObject)}`);
4639
- if (!operation.editor.selection) {
4640
- console.error("Unable to insert inline object without selection");
4641
- return;
4642
- }
4643
- const [focusTextBlock] = Array.from(Editor.nodes(operation.editor, {
4644
- at: operation.editor.selection.focus.path,
4645
- match: (node) => operation.editor.isTextBlock(node)
4646
- })).at(0) ?? [void 0, void 0];
4647
- if (!focusTextBlock) {
4648
- console.error("Unable to perform action without focus text block");
4649
- return;
4650
- }
4651
- const child = toSlateValue([{
4652
- _type: context.schema.block.name,
4653
- _key: context.keyGenerator(),
4654
- children: [parsedInlineObject]
4655
- }], {
4656
- schemaTypes: context.schema
4657
- }).at(0)?.children.at(0);
4658
- if (!child) {
4659
- console.error("Unable to insert inline object");
4660
- return;
4661
- }
4662
- Transforms.insertNodes(operation.editor, child);
4663
- }, insertSpanOperationImplementation = ({
4664
- context,
4665
- operation
4666
- }) => {
4667
- if (!operation.editor.selection) {
4668
- console.error("Unable to perform action without selection", operation);
4669
- return;
4670
- }
4671
- const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(operation.editor, {
4672
- at: operation.editor.selection.focus.path,
4673
- match: (node) => operation.editor.isTextBlock(node)
4674
- }))[0] ?? [void 0, void 0];
4675
- if (!focusBlock || !focusBlockPath) {
4676
- console.error("Unable to perform action without focus block", operation);
4677
- return;
4678
- }
4679
- const markDefs = focusBlock.markDefs ?? [], annotations = operation.annotations ? operation.annotations.map((annotation) => ({
4680
- _type: annotation.name,
4681
- _key: context.keyGenerator(),
4682
- ...annotation.value
4683
- })) : void 0;
4684
- annotations && annotations.length > 0 && Transforms.setNodes(operation.editor, {
4685
- markDefs: [...markDefs, ...annotations]
4686
- }), Transforms.insertNodes(operation.editor, {
4687
- _type: "span",
4688
- _key: context.keyGenerator(),
4689
- text: operation.text,
4690
- marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...operation.decorators ?? []]
4691
- });
4692
- }, insertBlockOperationImplementation = ({
4594
+ const insertBlockOperationImplementation = ({
4693
4595
  context,
4694
4596
  operation
4695
4597
  }) => {
@@ -4697,7 +4599,6 @@ const insertInlineObjectOperationImplementation = ({
4697
4599
  block: operation.block,
4698
4600
  context,
4699
4601
  options: {
4700
- refreshKeys: !1,
4701
4602
  validateFields: !0
4702
4603
  }
4703
4604
  });
@@ -4973,8 +4874,6 @@ const moveBackwardOperationImplementation = ({
4973
4874
  "history.redo": historyRedoOperationImplementation,
4974
4875
  "history.undo": historyUndoOperationImplementation,
4975
4876
  "insert.block": insertBlockOperationImplementation,
4976
- "insert.inline object": insertInlineObjectOperationImplementation,
4977
- "insert.span": insertSpanOperationImplementation,
4978
4877
  "insert.text": insertTextOperationImplementation,
4979
4878
  "move.backward": moveBackwardOperationImplementation,
4980
4879
  "move.block": moveBlockOperationImplementation,
@@ -5071,20 +4970,6 @@ function performOperation({
5071
4970
  });
5072
4971
  break;
5073
4972
  }
5074
- case "insert.inline object": {
5075
- behaviorOperationImplementations["insert.inline object"]({
5076
- context,
5077
- operation
5078
- });
5079
- break;
5080
- }
5081
- case "insert.span": {
5082
- behaviorOperationImplementations["insert.span"]({
5083
- context,
5084
- operation
5085
- });
5086
- break;
5087
- }
5088
4973
  case "insert.text": {
5089
4974
  behaviorOperationImplementations["insert.text"]({
5090
4975
  context,
@@ -6713,9 +6598,24 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
6713
6598
  type: "annotation.add",
6714
6599
  annotation: event.annotation
6715
6600
  })]]
6716
- }), coreAnnotationBehaviors = {
6717
- addAnnotationOnCollapsedSelection
6718
- }, defaultKeyboardShortcuts = {
6601
+ }), preventOverlappingAnnotations = defineBehavior({
6602
+ // Given an `annotation.add` event
6603
+ on: "annotation.add",
6604
+ // When the annotation is active in the selection
6605
+ guard: ({
6606
+ snapshot,
6607
+ event
6608
+ }) => isActiveAnnotation(event.annotation.name, {
6609
+ mode: "partial"
6610
+ })(snapshot),
6611
+ // Then the existing annotation is removed
6612
+ actions: [({
6613
+ event
6614
+ }) => [raise({
6615
+ type: "annotation.remove",
6616
+ annotation: event.annotation
6617
+ }), raise(event)]]
6618
+ }), coreAnnotationBehaviors = [addAnnotationOnCollapsedSelection, preventOverlappingAnnotations], defaultKeyboardShortcuts = {
6719
6619
  arrowDown: createKeyboardShortcut({
6720
6620
  default: [{
6721
6621
  key: "ArrowDown",
@@ -7843,7 +7743,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
7843
7743
  inheritListLevel,
7844
7744
  inheritListItem,
7845
7745
  inheritListProperties
7846
- }, 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.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.deletingListFromStart, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
7746
+ }, coreBehaviorsConfig = [...coreAnnotationBehaviors, 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.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.deletingListFromStart, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
7847
7747
  behavior,
7848
7748
  priority: corePriority
7849
7749
  })), abstractAnnotationBehaviors = [defineBehavior({
@@ -8477,6 +8377,23 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
8477
8377
  actions: [() => [raise({
8478
8378
  type: "split"
8479
8379
  })]]
8380
+ }), defineBehavior({
8381
+ on: "insert.inline object",
8382
+ actions: [({
8383
+ snapshot,
8384
+ event
8385
+ }) => [execute({
8386
+ type: "insert.block",
8387
+ block: {
8388
+ _type: snapshot.context.schema.block.name,
8389
+ children: [{
8390
+ _type: event.inlineObject.name,
8391
+ ...event.inlineObject.value
8392
+ }]
8393
+ },
8394
+ placement: "auto",
8395
+ select: "end"
8396
+ })]]
8480
8397
  }), defineBehavior({
8481
8398
  on: "insert.soft break",
8482
8399
  actions: [() => [raise({
@@ -8484,6 +8401,37 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
8484
8401
  text: `
8485
8402
  `
8486
8403
  })]]
8404
+ }), defineBehavior({
8405
+ on: "insert.span",
8406
+ guard: ({
8407
+ snapshot,
8408
+ event
8409
+ }) => ({
8410
+ markDefs: event.annotations?.map((annotation) => ({
8411
+ _type: annotation.name,
8412
+ _key: snapshot.context.keyGenerator(),
8413
+ ...annotation.value
8414
+ })) ?? []
8415
+ }),
8416
+ actions: [({
8417
+ snapshot,
8418
+ event
8419
+ }, {
8420
+ markDefs
8421
+ }) => [execute({
8422
+ type: "insert.block",
8423
+ block: {
8424
+ _type: snapshot.context.schema.block.name,
8425
+ children: [{
8426
+ _type: snapshot.context.schema.span.name,
8427
+ text: event.text,
8428
+ marks: [...event.decorators ?? [], ...markDefs.map((markDef) => markDef._key)]
8429
+ }],
8430
+ markDefs
8431
+ },
8432
+ placement: "auto",
8433
+ select: "end"
8434
+ })]]
8487
8435
  })], abstractKeyboardBehaviors = [
8488
8436
  /**
8489
8437
  * Allow raising an `insert.break` event when pressing Enter on an inline
@@ -8923,7 +8871,6 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
8923
8871
  }),
8924
8872
  context: snapshot.context,
8925
8873
  options: {
8926
- refreshKeys: !1,
8927
8874
  validateFields: !1
8928
8875
  }
8929
8876
  });
@@ -9096,7 +9043,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
9096
9043
  function isSyntheticBehaviorEvent(event) {
9097
9044
  return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
9098
9045
  }
9099
- const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialize.data", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialize.data", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
9046
+ const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialize.data", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.inline object", "insert.soft break", "insert.span", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialize.data", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
9100
9047
  function isAbstractBehaviorEvent(event) {
9101
9048
  return abstractBehaviorEventTypes.includes(event.type);
9102
9049
  }
@@ -10371,7 +10318,22 @@ function createEditableAPI(editor, editorActor) {
10371
10318
  },
10372
10319
  addAnnotation: (type, value) => {
10373
10320
  let paths;
10374
- return Editor.withoutNormalizing(editor, () => {
10321
+ const snapshot = getEditorSnapshot({
10322
+ editorActorSnapshot: editorActor.getSnapshot(),
10323
+ slateEditorInstance: editor
10324
+ });
10325
+ return isActiveAnnotation(type.name, {
10326
+ mode: "partial"
10327
+ })(snapshot) && editorActor.send({
10328
+ type: "behavior event",
10329
+ behaviorEvent: {
10330
+ type: "annotation.remove",
10331
+ annotation: {
10332
+ name: type.name
10333
+ }
10334
+ },
10335
+ editor
10336
+ }), Editor.withoutNormalizing(editor, () => {
10375
10337
  paths = addAnnotationOperationImplementation({
10376
10338
  context: {
10377
10339
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,