@portabletext/editor 1.44.15 → 1.45.0

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 (66) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +5 -5
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +28 -22
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +154 -129
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-cjs/parse-blocks.cjs +74 -22
  8. package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
  9. package/lib/_chunks-es/behavior.core.js +5 -5
  10. package/lib/_chunks-es/behavior.core.js.map +1 -1
  11. package/lib/_chunks-es/behavior.markdown.js +28 -22
  12. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  13. package/lib/_chunks-es/editor-provider.js +161 -136
  14. package/lib/_chunks-es/editor-provider.js.map +1 -1
  15. package/lib/_chunks-es/parse-blocks.js +75 -23
  16. package/lib/_chunks-es/parse-blocks.js.map +1 -1
  17. package/lib/behaviors/index.cjs +18 -14
  18. package/lib/behaviors/index.cjs.map +1 -1
  19. package/lib/behaviors/index.d.cts +862 -636
  20. package/lib/behaviors/index.d.ts +862 -636
  21. package/lib/behaviors/index.js +18 -14
  22. package/lib/behaviors/index.js.map +1 -1
  23. package/lib/index.cjs +1 -1
  24. package/lib/index.cjs.map +1 -1
  25. package/lib/index.d.cts +40 -17
  26. package/lib/index.d.ts +40 -17
  27. package/lib/index.js +1 -1
  28. package/lib/index.js.map +1 -1
  29. package/lib/plugins/index.cjs +16 -7
  30. package/lib/plugins/index.cjs.map +1 -1
  31. package/lib/plugins/index.d.cts +20 -14
  32. package/lib/plugins/index.d.ts +20 -14
  33. package/lib/plugins/index.js +16 -7
  34. package/lib/plugins/index.js.map +1 -1
  35. package/lib/selectors/index.d.cts +20 -14
  36. package/lib/selectors/index.d.ts +20 -14
  37. package/lib/utils/index.d.cts +20 -14
  38. package/lib/utils/index.d.ts +20 -14
  39. package/package.json +2 -2
  40. package/src/behavior-actions/behavior.action.annotation.add.ts +26 -5
  41. package/src/behavior-actions/behavior.action.decorator.add.ts +4 -4
  42. package/src/behavior-actions/behavior.action.delete.text.ts +1 -4
  43. package/src/behavior-actions/behavior.action.delete.ts +2 -2
  44. package/src/behavior-actions/behavior.action.insert-inline-object.ts +14 -13
  45. package/src/behavior-actions/behavior.action.select.ts +1 -1
  46. package/src/behavior-actions/{behavior.action.insert-break.ts → behavior.action.split.block.ts} +3 -9
  47. package/src/behavior-actions/behavior.actions.ts +9 -20
  48. package/src/behaviors/behavior.abstract.decorator.ts +2 -2
  49. package/src/behaviors/behavior.abstract.insert.ts +9 -1
  50. package/src/behaviors/behavior.abstract.select.ts +2 -2
  51. package/src/behaviors/behavior.core.annotations.ts +1 -1
  52. package/src/behaviors/behavior.core.block-objects.ts +4 -4
  53. package/src/behaviors/behavior.decorator-pair.ts +3 -3
  54. package/src/behaviors/behavior.default.ts +4 -4
  55. package/src/behaviors/behavior.emoji-picker.ts +18 -14
  56. package/src/behaviors/behavior.markdown.ts +28 -22
  57. package/src/behaviors/behavior.types.event.ts +23 -14
  58. package/src/converters/converter.portable-text.deserialize.test.ts +12 -3
  59. package/src/converters/converter.text-html.deserialize.test.ts +3 -1
  60. package/src/editor/Editable.tsx +1 -1
  61. package/src/editor/define-schema.ts +29 -5
  62. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +2 -2
  63. package/src/editor/plugins/create-with-event-listeners.ts +4 -4
  64. package/src/internal-utils/parse-blocks.ts +109 -39
  65. package/src/plugins/plugin.decorator-shortcut.ts +3 -3
  66. package/src/plugins/plugin.one-line.tsx +8 -1
@@ -5,7 +5,7 @@ import { ReactEditor, withReact, Slate } from "slate-react";
5
5
  import { useSelector, useActorRef } from "@xstate/react";
6
6
  import debug$g from "debug";
7
7
  import isEqual from "lodash/isEqual.js";
8
- import { Element, Text, Editor, Path, Operation, Transforms, insertText, Node, Range, Point, createEditor } from "slate";
8
+ import { Element, Text, Editor, Path, Operation, Transforms, Node, Range, Point, createEditor } from "slate";
9
9
  import { setup, stateIn, fromCallback, assign, enqueueActions, emit, assertEvent, and, not, createActor } from "xstate";
10
10
  import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
11
11
  import { isPortableTextTextBlock, isKeySegment, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock, defineType, defineField } from "@sanity/types";
@@ -13,7 +13,7 @@ import flatten from "lodash/flatten.js";
13
13
  import isPlainObject from "lodash/isPlainObject.js";
14
14
  import uniq from "lodash/uniq.js";
15
15
  import getRandomValues from "get-random-values-esm";
16
- import { parseBlock, isTextBlock } from "./parse-blocks.js";
16
+ import { parseBlock, parseAnnotation, isTextBlock, parseInlineObject } from "./parse-blocks.js";
17
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";
@@ -917,8 +917,8 @@ function deisolateChar(diffs, i, dir) {
917
917
  }
918
918
  }
919
919
  if (insertIdx !== null && deleteIdx !== null && hasSharedChar(diffs, insertIdx, deleteIdx, dir)) {
920
- const [insertText2, insertChar] = splitChar(diffs[insertIdx][1], inv), [deleteText] = splitChar(diffs[deleteIdx][1], inv);
921
- diffs[insertIdx][1] = insertText2, diffs[deleteIdx][1] = deleteText, diffs[i][1] = combineChar(diffs[i][1], insertChar, dir);
920
+ const [insertText, insertChar] = splitChar(diffs[insertIdx][1], inv), [deleteText] = splitChar(diffs[deleteIdx][1], inv);
921
+ diffs[insertIdx][1] = insertText, diffs[deleteIdx][1] = deleteText, diffs[i][1] = combineChar(diffs[i][1], insertChar, dir);
922
922
  return;
923
923
  }
924
924
  const [text, char] = splitChar(diffs[i][1], dir);
@@ -2696,74 +2696,10 @@ function createOperationToPatches(types) {
2696
2696
  splitNodePatch
2697
2697
  };
2698
2698
  }
2699
- const insertBreakActionImplementation = ({
2700
- context,
2701
- action
2702
- }) => {
2703
- const keyGenerator = context.keyGenerator, schema = context.schema, editor = action.editor;
2704
- if (!editor.selection)
2705
- return;
2706
- const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
2707
- if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
2708
- Transforms.splitNodes(editor, {
2709
- at: editor.selection,
2710
- always: !0
2711
- });
2712
- const [nextBlock, nextBlockPath] = Editor.node(editor, Path.next(focusBlockPath), {
2713
- depth: 1
2714
- }), nextChild = Node.child(nextBlock, 0);
2715
- if (!editor.isTextSpan(nextChild) && Transforms.insertNodes(editor, {
2716
- _key: context.keyGenerator(),
2717
- _type: "span",
2718
- text: "",
2719
- marks: []
2720
- }, {
2721
- at: [nextBlockPath[0], 0]
2722
- }), Transforms.setSelection(editor, {
2723
- anchor: {
2724
- path: [...nextBlockPath, 0],
2725
- offset: 0
2726
- },
2727
- focus: {
2728
- path: [...nextBlockPath, 0],
2729
- offset: 0
2730
- }
2731
- }), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
2732
- const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = Node.children(editor, nextBlockPath);
2733
- for (const [child, childPath] of children) {
2734
- if (!editor.isTextSpan(child))
2735
- continue;
2736
- const marks = child.marks ?? [];
2737
- for (const mark of marks)
2738
- schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
2739
- const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
2740
- isEqual(marks, newMarks) || Transforms.setNodes(editor, {
2741
- marks: newMarks
2742
- }, {
2743
- at: childPath
2744
- });
2745
- }
2746
- const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
2747
- ...markDef,
2748
- _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
2749
- }));
2750
- isEqual(nextBlock.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
2751
- markDefs: newMarkDefs
2752
- }, {
2753
- at: nextBlockPath,
2754
- match: (node) => editor.isTextBlock(node)
2755
- });
2756
- }
2757
- return;
2758
- }
2759
- Transforms.splitNodes(editor, {
2760
- always: !0
2761
- });
2762
- }, insertSoftBreakActionImplementation = ({
2699
+ const insertTextActionImplementation = ({
2763
2700
  action
2764
2701
  }) => {
2765
- insertText(action.editor, `
2766
- `);
2702
+ action.editor.insertText(action.text);
2767
2703
  };
2768
2704
  function isPortableTextSpan(node) {
2769
2705
  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"));
@@ -3241,6 +3177,18 @@ const addAnnotationActionImplementation = ({
3241
3177
  context,
3242
3178
  action
3243
3179
  }) => {
3180
+ const parsedAnnotation = parseAnnotation({
3181
+ annotation: {
3182
+ _type: action.annotation.name,
3183
+ ...action.annotation.value
3184
+ },
3185
+ context,
3186
+ options: {
3187
+ refreshKeys: !1
3188
+ }
3189
+ });
3190
+ if (!parsedAnnotation)
3191
+ throw new Error(`Failed to parse annotation ${JSON.stringify(action.annotation)}`);
3244
3192
  const editor = action.editor;
3245
3193
  if (!editor.selection || Range.isCollapsed(editor.selection))
3246
3194
  return;
@@ -3250,15 +3198,15 @@ const addAnnotationActionImplementation = ({
3250
3198
  match: (node) => editor.isTextBlock(node),
3251
3199
  reverse: Range.isBackward(editor.selection)
3252
3200
  });
3201
+ let blockIndex = 0;
3253
3202
  for (const [block, blockPath] of selectedBlocks) {
3254
3203
  if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
3255
3204
  continue;
3256
- const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
3257
- markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
3205
+ const annotationKey = blockIndex === 0 ? parsedAnnotation._key : context.keyGenerator(), markDefs = block.markDefs ?? [];
3206
+ markDefs.find((markDef) => markDef._type === parsedAnnotation._type && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
3258
3207
  markDefs: [...markDefs, {
3259
- _type: action.annotation.name,
3260
- _key: annotationKey,
3261
- ...action.annotation.value
3208
+ ...parsedAnnotation,
3209
+ _key: annotationKey
3262
3210
  }]
3263
3211
  }, {
3264
3212
  at: blockPath
@@ -3274,7 +3222,7 @@ const addAnnotationActionImplementation = ({
3274
3222
  for (const [span, path] of children) {
3275
3223
  if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
3276
3224
  continue;
3277
- const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
3225
+ const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === parsedAnnotation._type));
3278
3226
  Transforms.setNodes(editor, {
3279
3227
  marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
3280
3228
  }, {
@@ -3285,6 +3233,7 @@ const addAnnotationActionImplementation = ({
3285
3233
  _key: span._key
3286
3234
  }];
3287
3235
  }
3236
+ blockIndex++;
3288
3237
  }
3289
3238
  return markDefPath && spanPath && (paths = {
3290
3239
  markDefPath,
@@ -3697,13 +3646,13 @@ const decoratorAddActionImplementation = ({
3697
3646
  context,
3698
3647
  action
3699
3648
  }) => {
3700
- const editor = action.editor, mark = action.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = action.offsets?.anchor ? blockOffsetToSpanSelectionPoint({
3649
+ 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 ? blockOffsetToSpanSelectionPoint({
3701
3650
  value,
3702
- blockOffset: action.offsets.anchor,
3651
+ blockOffset: action.at.anchor,
3703
3652
  direction: "backward"
3704
- }) : void 0, manualFocus = action.offsets?.focus ? blockOffsetToSpanSelectionPoint({
3653
+ }) : void 0, manualFocus = action.at?.focus ? blockOffsetToSpanSelectionPoint({
3705
3654
  value,
3706
- blockOffset: action.offsets.focus,
3655
+ blockOffset: action.at.focus,
3707
3656
  direction: "forward"
3708
3657
  }) : void 0, manualSelection = manualAnchor && manualFocus ? {
3709
3658
  anchor: manualAnchor,
@@ -3805,9 +3754,9 @@ const decoratorAddActionImplementation = ({
3805
3754
  }, deleteActionImplementation = ({
3806
3755
  action
3807
3756
  }) => {
3808
- const range = toSlateRange(action.selection, action.editor);
3757
+ const range = toSlateRange(action.at, action.editor);
3809
3758
  if (!range)
3810
- throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.selection)}`);
3759
+ throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.at)}`);
3811
3760
  action.editor.delete({
3812
3761
  at: range
3813
3762
  });
@@ -3845,10 +3794,7 @@ const decoratorAddActionImplementation = ({
3845
3794
  }) => {
3846
3795
  const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), selection = blockOffsetsToSelection({
3847
3796
  value,
3848
- offsets: {
3849
- anchor: action.anchor,
3850
- focus: action.focus
3851
- }
3797
+ offsets: action.at
3852
3798
  });
3853
3799
  if (!selection)
3854
3800
  throw new Error("Unable to find selection from block offsets");
@@ -3883,10 +3829,18 @@ const decoratorAddActionImplementation = ({
3883
3829
  context,
3884
3830
  action
3885
3831
  }) => {
3886
- if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
3887
- console.error("Unable to insert unknown inline object");
3888
- return;
3889
- }
3832
+ const parsedInlineObject = parseInlineObject({
3833
+ context,
3834
+ inlineObject: {
3835
+ _type: action.inlineObject.name,
3836
+ ...action.inlineObject.value ?? {}
3837
+ },
3838
+ options: {
3839
+ refreshKeys: !1
3840
+ }
3841
+ });
3842
+ if (!parsedInlineObject)
3843
+ throw new Error(`Failed to parse inline object ${JSON.stringify(action.inlineObject)}`);
3890
3844
  if (!action.editor.selection) {
3891
3845
  console.error("Unable to insert inline object without selection");
3892
3846
  return;
@@ -3902,11 +3856,7 @@ const decoratorAddActionImplementation = ({
3902
3856
  const child = toSlateValue([{
3903
3857
  _type: context.schema.block.name,
3904
3858
  _key: context.keyGenerator(),
3905
- children: [{
3906
- _type: action.inlineObject.name,
3907
- _key: context.keyGenerator(),
3908
- ...action.inlineObject.value ?? {}
3909
- }]
3859
+ children: [parsedInlineObject]
3910
3860
  }], {
3911
3861
  schemaTypes: context.schema
3912
3862
  }).at(0)?.children.at(0);
@@ -4089,11 +4039,7 @@ function insertBlock({
4089
4039
  }
4090
4040
  }
4091
4041
  }
4092
- const insertTextActionImplementation = ({
4093
- action
4094
- }) => {
4095
- action.editor.insertText(action.text);
4096
- }, moveBlockActionImplementation = ({
4042
+ const moveBlockActionImplementation = ({
4097
4043
  action
4098
4044
  }) => {
4099
4045
  const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
@@ -4106,8 +4052,71 @@ const insertTextActionImplementation = ({
4106
4052
  }, selectActionImplementation = ({
4107
4053
  action
4108
4054
  }) => {
4109
- const newSelection = toSlateRange(action.selection, action.editor);
4055
+ const newSelection = toSlateRange(action.at, action.editor);
4110
4056
  newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
4057
+ }, splitBlockActionImplementation = ({
4058
+ context,
4059
+ action
4060
+ }) => {
4061
+ const keyGenerator = context.keyGenerator, schema = context.schema, editor = action.editor;
4062
+ if (!editor.selection)
4063
+ return;
4064
+ const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
4065
+ if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
4066
+ Transforms.splitNodes(editor, {
4067
+ at: editor.selection,
4068
+ always: !0
4069
+ });
4070
+ const [nextBlock, nextBlockPath] = Editor.node(editor, Path.next(focusBlockPath), {
4071
+ depth: 1
4072
+ }), nextChild = Node.child(nextBlock, 0);
4073
+ if (!editor.isTextSpan(nextChild) && Transforms.insertNodes(editor, {
4074
+ _key: context.keyGenerator(),
4075
+ _type: "span",
4076
+ text: "",
4077
+ marks: []
4078
+ }, {
4079
+ at: [nextBlockPath[0], 0]
4080
+ }), Transforms.setSelection(editor, {
4081
+ anchor: {
4082
+ path: [...nextBlockPath, 0],
4083
+ offset: 0
4084
+ },
4085
+ focus: {
4086
+ path: [...nextBlockPath, 0],
4087
+ offset: 0
4088
+ }
4089
+ }), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
4090
+ const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = Node.children(editor, nextBlockPath);
4091
+ for (const [child, childPath] of children) {
4092
+ if (!editor.isTextSpan(child))
4093
+ continue;
4094
+ const marks = child.marks ?? [];
4095
+ for (const mark of marks)
4096
+ schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
4097
+ const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
4098
+ isEqual(marks, newMarks) || Transforms.setNodes(editor, {
4099
+ marks: newMarks
4100
+ }, {
4101
+ at: childPath
4102
+ });
4103
+ }
4104
+ const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
4105
+ ...markDef,
4106
+ _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
4107
+ }));
4108
+ isEqual(nextBlock.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
4109
+ markDefs: newMarkDefs
4110
+ }, {
4111
+ at: nextBlockPath,
4112
+ match: (node) => editor.isTextBlock(node)
4113
+ });
4114
+ }
4115
+ return;
4116
+ }
4117
+ Transforms.splitNodes(editor, {
4118
+ always: !0
4119
+ });
4111
4120
  }, debug$a = debugWithName("behaviors:action"), behaviorActionImplementations = {
4112
4121
  "annotation.add": addAnnotationActionImplementation,
4113
4122
  "annotation.remove": removeAnnotationActionImplementation,
@@ -4125,15 +4134,14 @@ const insertTextActionImplementation = ({
4125
4134
  "history.redo": historyRedoActionImplementation,
4126
4135
  "history.undo": historyUndoActionImplementation,
4127
4136
  "insert.block": insertBlockActionImplementation,
4128
- "insert.break": insertBreakActionImplementation,
4129
4137
  "insert.inline object": insertInlineObjectActionImplementation,
4130
- "insert.soft break": insertSoftBreakActionImplementation,
4131
4138
  "insert.span": insertSpanActionImplementation,
4132
4139
  "insert.text": insertTextActionImplementation,
4133
4140
  effect: effectActionImplementation,
4134
4141
  "move.block": moveBlockActionImplementation,
4135
4142
  noop: noopActionImplementation,
4136
- select: selectActionImplementation
4143
+ select: selectActionImplementation,
4144
+ "split.block": splitBlockActionImplementation
4137
4145
  };
4138
4146
  function performAction({
4139
4147
  context,
@@ -4266,20 +4274,6 @@ function performAction({
4266
4274
  });
4267
4275
  break;
4268
4276
  }
4269
- case "insert.break": {
4270
- behaviorActionImplementations["insert.break"]({
4271
- context,
4272
- action
4273
- });
4274
- break;
4275
- }
4276
- case "insert.soft break": {
4277
- behaviorActionImplementations["insert.soft break"]({
4278
- context,
4279
- action
4280
- });
4281
- break;
4282
- }
4283
4277
  case "insert.span": {
4284
4278
  behaviorActionImplementations["insert.span"]({
4285
4279
  context,
@@ -4303,6 +4297,13 @@ function performAction({
4303
4297
  }
4304
4298
  case "noop":
4305
4299
  break;
4300
+ case "split.block": {
4301
+ behaviorActionImplementations["split.block"]({
4302
+ context,
4303
+ action
4304
+ });
4305
+ break;
4306
+ }
4306
4307
  default: {
4307
4308
  behaviorActionImplementations.select({
4308
4309
  context,
@@ -4320,7 +4321,7 @@ function createWithEventListeners(editorActor) {
4320
4321
  deleteBackward,
4321
4322
  deleteForward,
4322
4323
  insertBreak,
4323
- insertText: insertText2,
4324
+ insertText,
4324
4325
  select
4325
4326
  } = editor;
4326
4327
  return editor.deleteBackward = (unit) => {
@@ -4376,12 +4377,14 @@ function createWithEventListeners(editorActor) {
4376
4377
  });
4377
4378
  }, editor.insertSoftBreak = () => {
4378
4379
  if (isApplyingBehaviorActions(editor)) {
4379
- insertSoftBreakActionImplementation({
4380
+ insertTextActionImplementation({
4380
4381
  context: {
4381
4382
  keyGenerator: editorActor.getSnapshot().context.keyGenerator,
4382
4383
  schema: editorActor.getSnapshot().context.schema
4383
4384
  },
4384
4385
  action: {
4386
+ text: `
4387
+ `,
4385
4388
  editor
4386
4389
  }
4387
4390
  });
@@ -4396,7 +4399,7 @@ function createWithEventListeners(editorActor) {
4396
4399
  });
4397
4400
  }, editor.insertText = (text, options) => {
4398
4401
  if (isApplyingBehaviorActions(editor)) {
4399
- insertText2(text, options);
4402
+ insertText(text, options);
4400
4403
  return;
4401
4404
  }
4402
4405
  editorActor.send({
@@ -4407,7 +4410,7 @@ function createWithEventListeners(editorActor) {
4407
4410
  },
4408
4411
  editor,
4409
4412
  defaultActionCallback: () => {
4410
- insertText2(text, options);
4413
+ insertText(text, options);
4411
4414
  }
4412
4415
  });
4413
4416
  }, editor.redo = () => {
@@ -4441,7 +4444,7 @@ function createWithEventListeners(editorActor) {
4441
4444
  type: "behavior event",
4442
4445
  behaviorEvent: {
4443
4446
  type: "select",
4444
- selection: slateRangeToSelection({
4447
+ at: slateRangeToSelection({
4445
4448
  schema: editorActor.getSnapshot().context.schema,
4446
4449
  editor,
4447
4450
  range
@@ -5174,7 +5177,10 @@ function compileSchemaDefinition(definition) {
5174
5177
  // This avoids the default title which is a title case of the object name
5175
5178
  defaultObjectTitles[blockObject.name]
5176
5179
  ) : blockObject.title,
5177
- fields: []
5180
+ fields: blockObject.fields?.map((field) => ({
5181
+ name: field.name,
5182
+ type: field.type
5183
+ })) ?? []
5178
5184
  })) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => defineType({
5179
5185
  type: "object",
5180
5186
  // Very naive way to work around `SanitySchema.compile` adding default
@@ -5184,7 +5190,10 @@ function compileSchemaDefinition(definition) {
5184
5190
  // This avoids the default title which is a title case of the object name
5185
5191
  defaultObjectTitles[inlineObject.name]
5186
5192
  ) : inlineObject.title,
5187
- fields: []
5193
+ fields: inlineObject.fields?.map((field) => ({
5194
+ name: field.name,
5195
+ type: field.type
5196
+ })) ?? []
5188
5197
  })) ?? [], portableTextSchema = defineField({
5189
5198
  type: "array",
5190
5199
  name: "portable-text",
@@ -5204,7 +5213,11 @@ function compileSchemaDefinition(definition) {
5204
5213
  annotations: definition?.annotations?.map((annotation) => ({
5205
5214
  name: annotation.name,
5206
5215
  type: "object",
5207
- title: annotation.title
5216
+ title: annotation.title,
5217
+ fields: annotation.fields?.map((field) => ({
5218
+ name: field.name,
5219
+ type: field.type
5220
+ })) ?? []
5208
5221
  })) ?? []
5209
5222
  },
5210
5223
  lists: definition?.lists?.map((list) => ({
@@ -5277,9 +5290,9 @@ const abstractAnnotationBehaviors = [defineBehavior({
5277
5290
  snapshot,
5278
5291
  event
5279
5292
  }) => {
5280
- const manualSelection = event.offsets ? blockOffsetsToSelection({
5293
+ const manualSelection = event.at ? blockOffsetsToSelection({
5281
5294
  value: snapshot.context.value,
5282
- offsets: event.offsets
5295
+ offsets: event.at
5283
5296
  }) : null;
5284
5297
  return manualSelection ? !isActiveDecorator(event.decorator)({
5285
5298
  ...snapshot,
@@ -5335,7 +5348,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
5335
5348
  placement: "auto",
5336
5349
  select: "end"
5337
5350
  })] : event.blocks.flatMap((block, index) => index === 0 ? [raise({
5338
- type: "insert.break"
5351
+ type: "split.block"
5339
5352
  }), raise({
5340
5353
  type: "select.previous block",
5341
5354
  select: "end"
@@ -5371,6 +5384,18 @@ const abstractAnnotationBehaviors = [defineBehavior({
5371
5384
  placement: index === 0 ? "auto" : "after",
5372
5385
  select: "end"
5373
5386
  }))]
5387
+ }), defineBehavior({
5388
+ on: "insert.break",
5389
+ actions: [() => [raise({
5390
+ type: "split.block"
5391
+ })]]
5392
+ }), defineBehavior({
5393
+ on: "insert.soft break",
5394
+ actions: [() => [raise({
5395
+ type: "insert.text",
5396
+ text: `
5397
+ `
5398
+ })]]
5374
5399
  })], abstractListItemBehaviors = [defineBehavior({
5375
5400
  on: "list item.add",
5376
5401
  guard: ({
@@ -5517,7 +5542,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
5517
5542
  selection
5518
5543
  }) => [raise({
5519
5544
  type: "select",
5520
- selection
5545
+ at: selection
5521
5546
  })]]
5522
5547
  }), defineBehavior({
5523
5548
  on: "select.next block",
@@ -5540,7 +5565,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
5540
5565
  selection
5541
5566
  }) => [raise({
5542
5567
  type: "select",
5543
- selection
5568
+ at: selection
5544
5569
  })]]
5545
5570
  })], abstractStyleBehaviors = [defineBehavior({
5546
5571
  on: "style.add",
@@ -5718,7 +5743,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
5718
5743
  originEvent: event
5719
5744
  }), raise({
5720
5745
  type: "delete",
5721
- selection
5746
+ at: selection
5722
5747
  })]]
5723
5748
  }),
5724
5749
  defineBehavior({
@@ -5777,7 +5802,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
5777
5802
  event
5778
5803
  }) => [raise({
5779
5804
  type: "select",
5780
- selection: event.position.selection
5805
+ at: event.position.selection
5781
5806
  }), raise({
5782
5807
  type: "deserialize",
5783
5808
  originEvent: event
@@ -5827,7 +5852,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
5827
5852
  at: block.path
5828
5853
  })) : [raise({
5829
5854
  type: "delete",
5830
- selection: dragOrigin.selection
5855
+ at: dragOrigin.selection
5831
5856
  })], raise({
5832
5857
  type: "insert.blocks",
5833
5858
  blocks: event.data,
@@ -5921,7 +5946,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
5921
5946
  selection
5922
5947
  }) => [raise({
5923
5948
  type: "delete",
5924
- selection
5949
+ at: selection
5925
5950
  }), raise({
5926
5951
  type: "deserialize",
5927
5952
  originEvent: event
@@ -5955,7 +5980,7 @@ const abstractAnnotationBehaviors = [defineBehavior({
5955
5980
  raiseDeserializationSuccessOrFailure,
5956
5981
  raiseSerializationSuccessOrFailure,
5957
5982
  raiseInsertSoftBreak
5958
- ], 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"];
5983
+ ], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "deserialize", "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", "serialization.success", "serialization.failure", "style.add", "style.remove", "style.toggle"];
5959
5984
  function isAbstractBehaviorEvent(event) {
5960
5985
  return abstractBehaviorEventTypes.includes(event.type);
5961
5986
  }