@portabletext/editor 1.43.1 → 1.44.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 (75) hide show
  1. package/lib/_chunks-cjs/behavior.markdown.cjs +1 -1
  2. package/lib/_chunks-cjs/editor-provider.cjs +555 -794
  3. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  4. package/lib/_chunks-cjs/parse-blocks.cjs +151 -0
  5. package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
  6. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +2 -1
  7. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
  8. package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-selecting-entire-blocks.cjs} +47 -11
  9. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -0
  10. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
  11. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  12. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +0 -149
  13. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  14. package/lib/_chunks-es/behavior.markdown.js +1 -1
  15. package/lib/_chunks-es/editor-provider.js +539 -777
  16. package/lib/_chunks-es/editor-provider.js.map +1 -1
  17. package/lib/_chunks-es/parse-blocks.js +152 -0
  18. package/lib/_chunks-es/parse-blocks.js.map +1 -0
  19. package/lib/_chunks-es/selector.is-overlapping-selection.js +2 -1
  20. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
  21. package/lib/_chunks-es/{selector.is-active-style.js → selector.is-selecting-entire-blocks.js} +49 -12
  22. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -0
  23. package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
  24. package/lib/_chunks-es/util.selection-point-to-block-offset.js +0 -149
  25. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  26. package/lib/behaviors/index.d.cts +2819 -6421
  27. package/lib/behaviors/index.d.ts +2819 -6421
  28. package/lib/index.cjs +4 -4
  29. package/lib/index.cjs.map +1 -1
  30. package/lib/index.d.cts +2496 -6025
  31. package/lib/index.d.ts +2496 -6025
  32. package/lib/index.js +3 -3
  33. package/lib/plugins/index.cjs +1 -1
  34. package/lib/plugins/index.d.cts +2496 -6025
  35. package/lib/plugins/index.d.ts +2496 -6025
  36. package/lib/plugins/index.js +1 -1
  37. package/lib/selectors/index.cjs +12 -11
  38. package/lib/selectors/index.cjs.map +1 -1
  39. package/lib/selectors/index.d.cts +2464 -6018
  40. package/lib/selectors/index.d.ts +2464 -6018
  41. package/lib/selectors/index.js +2 -1
  42. package/lib/utils/index.d.cts +2458 -6022
  43. package/lib/utils/index.d.ts +2458 -6022
  44. package/package.json +2 -2
  45. package/src/behavior-actions/behavior.actions.ts +2 -152
  46. package/src/behaviors/behavior.default.ts +52 -120
  47. package/src/behaviors/behavior.internal.annotation.ts +26 -0
  48. package/src/behaviors/behavior.internal.decorator.ts +47 -0
  49. package/src/behaviors/behavior.internal.insert.ts +118 -0
  50. package/src/behaviors/behavior.internal.list-item.ts +61 -0
  51. package/src/behaviors/behavior.internal.select.ts +62 -0
  52. package/src/behaviors/behavior.internal.style.ts +54 -0
  53. package/src/behaviors/behavior.perform-event.ts +15 -13
  54. package/src/behaviors/behavior.types.event.ts +155 -108
  55. package/src/editor/create-editor.ts +2 -2
  56. package/src/editor/editor-machine.ts +3 -4
  57. package/src/editor/plugins/createWithEditableAPI.ts +1 -32
  58. package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -29
  59. package/src/internal-utils/slate-utils.ts +52 -0
  60. package/src/plugins/plugin.internal.editor-actor-ref.tsx +15 -0
  61. package/src/plugins/plugin.internal.slate-editor-ref.tsx +15 -0
  62. package/src/selectors/index.ts +2 -1
  63. package/src/selectors/selector.get-selected-text-blocks.ts +67 -0
  64. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
  65. package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
  66. package/src/behavior-actions/behavior.action.data-transfer-set.ts +0 -7
  67. package/src/behavior-actions/behavior.action.deserialization.failure.ts +0 -9
  68. package/src/behavior-actions/behavior.action.deserialization.success.ts +0 -16
  69. package/src/behavior-actions/behavior.action.insert-blocks.ts +0 -140
  70. package/src/behavior-actions/behavior.action.list-item.ts +0 -100
  71. package/src/behavior-actions/behavior.action.select.next-block.ts +0 -44
  72. package/src/behavior-actions/behavior.action.select.previous-block.ts +0 -48
  73. package/src/behavior-actions/behavior.action.serialization.failure.ts +0 -9
  74. package/src/behavior-actions/behavior.action.serialization.success.ts +0 -17
  75. package/src/behavior-actions/behavior.action.style.ts +0 -108
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$g = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), omit = require("lodash/omit.js"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), selector_isActiveStyle = require("./selector.is-active-style.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
2
+ var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$g = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), parseBlocks = require("./parse-blocks.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
3
3
  function _interopDefaultCompat(e) {
4
4
  return e && typeof e == "object" && "default" in e ? e : { default: e };
5
5
  }
@@ -383,6 +383,30 @@ function isBlockElement({
383
383
  }, node) {
384
384
  return slate.Element.isElement(node) && !editor.isInline(node) && (schema2.block.name === node._type || schema2.blockObjects.some((blockObject) => blockObject.name === node._type));
385
385
  }
386
+ function isListItemActive({
387
+ editor,
388
+ listItem
389
+ }) {
390
+ if (!editor.selection)
391
+ return !1;
392
+ const selectedBlocks = [...slate.Editor.nodes(editor, {
393
+ at: editor.selection,
394
+ match: (node) => editor.isTextBlock(node)
395
+ })];
396
+ return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
397
+ }
398
+ function isStyleActive({
399
+ editor,
400
+ style
401
+ }) {
402
+ if (!editor.selection)
403
+ return !1;
404
+ const selectedBlocks = [...slate.Editor.nodes(editor, {
405
+ at: editor.selection,
406
+ match: (node) => editor.isTextBlock(node)
407
+ })];
408
+ return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
409
+ }
386
410
  const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), EditorActorContext = React.createContext({}), PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
387
411
  const editor = React.useContext(PortableTextEditorContext);
388
412
  if (!editor)
@@ -2517,7 +2541,7 @@ const converterJson = {
2517
2541
  reason: "Data is not an array"
2518
2542
  };
2519
2543
  const parsedBlocks = blocks.flatMap((block) => {
2520
- const parsedBlock = util_selectionPointToBlockOffset.parseBlock({
2544
+ const parsedBlock = parseBlocks.parseBlock({
2521
2545
  context: snapshot.context,
2522
2546
  block,
2523
2547
  options: {
@@ -2939,131 +2963,7 @@ const insertBreakActionImplementation = ({
2939
2963
  }) => {
2940
2964
  slate.insertText(action.editor, `
2941
2965
  `);
2942
- }, toggleListItemActionImplementation = ({
2943
- context,
2944
- action
2945
- }) => {
2946
- isListItemActive({
2947
- editor: action.editor,
2948
- listItem: action.listItem
2949
- }) ? removeListItemActionImplementation({
2950
- context,
2951
- action: {
2952
- ...action
2953
- }
2954
- }) : addListItemActionImplementation({
2955
- context,
2956
- action: {
2957
- ...action
2958
- }
2959
- });
2960
- }, removeListItemActionImplementation = ({
2961
- context,
2962
- action
2963
- }) => {
2964
- if (!action.editor.selection)
2965
- return;
2966
- const guards = selector_isOverlappingSelection.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
2967
- at: action.editor.selection,
2968
- match: (node) => guards.isListBlock(node)
2969
- })];
2970
- for (const [, at] of selectedBlocks)
2971
- slate.Transforms.unsetNodes(action.editor, ["listItem", "level"], {
2972
- at
2973
- });
2974
- }, addListItemActionImplementation = ({
2975
- context,
2976
- action
2977
- }) => {
2978
- if (!action.editor.selection)
2979
- return;
2980
- const guards = selector_isOverlappingSelection.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
2981
- at: action.editor.selection,
2982
- match: (node) => guards.isTextBlock(node)
2983
- })];
2984
- for (const [, at] of selectedBlocks)
2985
- slate.Transforms.setNodes(action.editor, {
2986
- level: 1,
2987
- listItem: action.listItem
2988
- }, {
2989
- at
2990
- });
2991
- };
2992
- function isListItemActive({
2993
- editor,
2994
- listItem
2995
- }) {
2996
- if (!editor.selection)
2997
- return !1;
2998
- const selectedBlocks = [...slate.Editor.nodes(editor, {
2999
- at: editor.selection,
3000
- match: (node) => editor.isTextBlock(node)
3001
- })];
3002
- return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
3003
- }
3004
- const toggleStyleActionImplementation = ({
3005
- context,
3006
- action
3007
- }) => {
3008
- isStyleActive({
3009
- editor: action.editor,
3010
- style: action.style
3011
- }) ? removeStyleActionImplementation({
3012
- context,
3013
- action: {
3014
- ...action
3015
- }
3016
- }) : addStyleActionImplementation({
3017
- context,
3018
- action: {
3019
- ...action
3020
- }
3021
- });
3022
- }, removeStyleActionImplementation = ({
3023
- context,
3024
- action
3025
- }) => {
3026
- if (!action.editor.selection)
3027
- return;
3028
- const defaultStyle = context.schema.styles[0].value, guards = selector_isOverlappingSelection.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
3029
- at: action.editor.selection,
3030
- match: (node) => guards.isTextBlock(node)
3031
- })];
3032
- for (const [, at] of selectedBlocks)
3033
- slate.Transforms.setNodes(action.editor, {
3034
- style: defaultStyle
3035
- }, {
3036
- at
3037
- });
3038
- }, addStyleActionImplementation = ({
3039
- context,
3040
- action
3041
- }) => {
3042
- if (!action.editor.selection)
3043
- return;
3044
- const guards = selector_isOverlappingSelection.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
3045
- at: action.editor.selection,
3046
- match: (node) => guards.isTextBlock(node)
3047
- })];
3048
- for (const [, at] of selectedBlocks)
3049
- slate.Transforms.setNodes(action.editor, {
3050
- style: action.style
3051
- }, {
3052
- at
3053
- });
3054
2966
  };
3055
- function isStyleActive({
3056
- editor,
3057
- style
3058
- }) {
3059
- if (!editor.selection)
3060
- return !1;
3061
- const selectedBlocks = [...slate.Editor.nodes(editor, {
3062
- at: editor.selection,
3063
- match: (node) => editor.isTextBlock(node)
3064
- })];
3065
- return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
3066
- }
3067
2967
  function isPortableTextSpan(node) {
3068
2968
  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"));
3069
2969
  }
@@ -3079,112 +2979,6 @@ function isPortableTextBlock(node) {
3079
2979
  node.children.every((child) => typeof child == "object" && "_type" in child)
3080
2980
  );
3081
2981
  }
3082
- const decoratorAddActionImplementation = ({
3083
- context,
3084
- action
3085
- }) => {
3086
- 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 ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3087
- value,
3088
- blockOffset: action.offsets.anchor,
3089
- direction: "backward"
3090
- }) : void 0, manualFocus = action.offsets?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
3091
- value,
3092
- blockOffset: action.offsets.focus,
3093
- direction: "forward"
3094
- }) : void 0, manualSelection = manualAnchor && manualFocus ? {
3095
- anchor: manualAnchor,
3096
- focus: manualFocus
3097
- } : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
3098
- if (!selection)
3099
- return;
3100
- const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
3101
- value,
3102
- selectionPoint: editorSelection.anchor
3103
- }) : void 0, focusOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
3104
- value,
3105
- selectionPoint: editorSelection.focus
3106
- }) : void 0;
3107
- if (!anchorOffset || !focusOffset)
3108
- throw new Error("Unable to find anchor or focus offset");
3109
- if (slate.Range.isExpanded(selection)) {
3110
- slate.Transforms.setNodes(editor, {}, {
3111
- at: selection,
3112
- match: slate.Text.isText,
3113
- split: !0,
3114
- hanging: !0
3115
- });
3116
- const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
3117
- value: newValue,
3118
- offsets: {
3119
- anchor: anchorOffset,
3120
- focus: focusOffset
3121
- },
3122
- backward: editorSelection?.backward
3123
- }), trimmedSelection = selector_isActiveStyle.getTrimmedSelection({
3124
- context: {
3125
- activeDecorators: [],
3126
- converters: [],
3127
- keyGenerator: context.keyGenerator,
3128
- readOnly: !1,
3129
- schema: context.schema,
3130
- selection: newSelection,
3131
- value: newValue
3132
- }
3133
- });
3134
- if (!trimmedSelection)
3135
- throw new Error("Unable to find trimmed selection");
3136
- const newRange = toSlateRange(trimmedSelection, editor);
3137
- if (!newRange)
3138
- throw new Error("Unable to find new selection");
3139
- const splitTextNodes = slate.Range.isRange(newRange) ? [...slate.Editor.nodes(editor, {
3140
- at: newRange,
3141
- match: (node) => slate.Text.isText(node)
3142
- })] : [];
3143
- for (const [node, path] of splitTextNodes) {
3144
- const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
3145
- slate.Transforms.setNodes(editor, {
3146
- marks
3147
- }, {
3148
- at: path,
3149
- match: slate.Text.isText,
3150
- split: !0,
3151
- hanging: !0
3152
- });
3153
- }
3154
- } else {
3155
- if (!Array.from(slate.Editor.nodes(editor, {
3156
- at: selection,
3157
- match: (node) => editor.isTextSpan(node)
3158
- }))?.at(0))
3159
- return;
3160
- const [block, blockPath] = slate.Editor.node(editor, selection, {
3161
- depth: 1
3162
- }), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
3163
- if (lonelyEmptySpan) {
3164
- const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
3165
- slate.Transforms.setNodes(editor, {
3166
- marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
3167
- }, {
3168
- at: blockPath,
3169
- match: (node) => editor.isTextSpan(node)
3170
- });
3171
- } else {
3172
- const existingMarks = {
3173
- ...slate.Editor.marks(editor) || {}
3174
- }.marks || [], marks = {
3175
- ...slate.Editor.marks(editor) || {},
3176
- marks: [...existingMarks, mark]
3177
- };
3178
- editor.marks = marks;
3179
- }
3180
- }
3181
- if (editor.selection) {
3182
- const selection2 = editor.selection;
3183
- editor.selection = {
3184
- ...selection2
3185
- };
3186
- }
3187
- };
3188
2982
  function getPreviousSpan({
3189
2983
  editor,
3190
2984
  blockPath,
@@ -3642,25 +3436,7 @@ function isDecoratorActive({
3642
3436
  ...slate.Editor.marks(editor) || {}
3643
3437
  }.marks || []).includes(decorator);
3644
3438
  }
3645
- const toggleDecoratorActionImplementation = ({
3646
- context,
3647
- action
3648
- }) => {
3649
- isDecoratorActive({
3650
- editor: action.editor,
3651
- decorator: action.decorator
3652
- }) ? removeDecoratorActionImplementation({
3653
- action: {
3654
- editor: action.editor,
3655
- decorator: action.decorator
3656
- }
3657
- }) : decoratorAddActionImplementation({
3658
- context,
3659
- action: {
3660
- ...action
3661
- }
3662
- });
3663
- }, debug$a = debugWithName("API:editable");
3439
+ const debug$a = debugWithName("API:editable");
3664
3440
  function createEditableAPI(editor, editorActor) {
3665
3441
  const types2 = editorActor.getSnapshot().context.schema;
3666
3442
  return {
@@ -4131,30 +3907,6 @@ const addAnnotationActionImplementation = ({
4131
3907
  }
4132
3908
  }
4133
3909
  }
4134
- }, toggleAnnotationActionImplementation = ({
4135
- context,
4136
- action
4137
- }) => {
4138
- if (isAnnotationActive({
4139
- editor: action.editor,
4140
- annotation: {
4141
- name: action.annotation.name
4142
- }
4143
- }))
4144
- removeAnnotationActionImplementation({
4145
- action: {
4146
- annotation: action.annotation,
4147
- editor: action.editor
4148
- }
4149
- });
4150
- else
4151
- return addAnnotationActionImplementation({
4152
- context,
4153
- action: {
4154
- annotation: action.annotation,
4155
- editor: action.editor
4156
- }
4157
- });
4158
3910
  }, blockSetBehaviorActionImplementation = ({
4159
3911
  context,
4160
3912
  action
@@ -4182,7 +3934,7 @@ const addAnnotationActionImplementation = ({
4182
3934
  const {
4183
3935
  _type,
4184
3936
  ...filteredProps
4185
- } = action.props, updatedBlock = util_selectionPointToBlockOffset.parseBlock({
3937
+ } = action.props, updatedBlock = parseBlocks.parseBlock({
4186
3938
  context,
4187
3939
  block: {
4188
3940
  ...parsedBlock,
@@ -4226,8 +3978,8 @@ const addAnnotationActionImplementation = ({
4226
3978
  const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
4227
3979
  if (!parsedBlock)
4228
3980
  throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
4229
- if (util_selectionPointToBlockOffset.isTextBlock(context.schema, parsedBlock)) {
4230
- const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_selectionPointToBlockOffset.parseBlock({
3981
+ if (parseBlocks.isTextBlock(context.schema, parsedBlock)) {
3982
+ const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = parseBlocks.parseBlock({
4231
3983
  context,
4232
3984
  block: omit__default.default(parsedBlock, propsToRemove),
4233
3985
  options: {
@@ -4244,7 +3996,7 @@ const addAnnotationActionImplementation = ({
4244
3996
  });
4245
3997
  return;
4246
3998
  }
4247
- const updatedBlockObject = util_selectionPointToBlockOffset.parseBlock({
3999
+ const updatedBlockObject = parseBlocks.parseBlock({
4248
4000
  context,
4249
4001
  block: omit__default.default(parsedBlock, action.props.filter((prop) => prop !== "_type")),
4250
4002
  options: {
@@ -4269,41 +4021,142 @@ const addAnnotationActionImplementation = ({
4269
4021
  action
4270
4022
  }) => {
4271
4023
  slateReact.ReactEditor.blur(action.editor);
4272
- }, dataTransferSetActionImplementation = ({
4273
- action
4274
- }) => {
4275
- action.dataTransfer.setData(action.mimeType, action.data);
4276
- }, deleteActionImplementation = ({
4277
- action
4278
- }) => {
4279
- const range = toSlateRange(action.selection, action.editor);
4280
- if (!range)
4281
- throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.selection)}`);
4282
- action.editor.delete({
4283
- at: range
4284
- });
4285
- }, deleteBackwardActionImplementation = ({
4286
- action
4287
- }) => {
4288
- action.editor.deleteBackward(action.unit);
4289
- }, deleteBlockActionImplementation = ({
4024
+ }, decoratorAddActionImplementation = ({
4025
+ context,
4290
4026
  action
4291
4027
  }) => {
4292
- const range = toSlateRange({
4293
- anchor: {
4294
- path: action.at,
4295
- offset: 0
4296
- },
4297
- focus: {
4298
- path: action.at,
4299
- offset: 0
4300
- }
4301
- }, action.editor);
4302
- if (!range) {
4303
- console.error("Unable to find Slate range from selection points");
4304
- return;
4305
- }
4306
- slate.Transforms.removeNodes(action.editor, {
4028
+ 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 ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
4029
+ value,
4030
+ blockOffset: action.offsets.anchor,
4031
+ direction: "backward"
4032
+ }) : void 0, manualFocus = action.offsets?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
4033
+ value,
4034
+ blockOffset: action.offsets.focus,
4035
+ direction: "forward"
4036
+ }) : void 0, manualSelection = manualAnchor && manualFocus ? {
4037
+ anchor: manualAnchor,
4038
+ focus: manualFocus
4039
+ } : void 0, selection = manualSelection ? toSlateRange(manualSelection, action.editor) ?? editor.selection : editor.selection;
4040
+ if (!selection)
4041
+ return;
4042
+ const editorSelection = toPortableTextRange(value, selection, context.schema), anchorOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
4043
+ value,
4044
+ selectionPoint: editorSelection.anchor
4045
+ }) : void 0, focusOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
4046
+ value,
4047
+ selectionPoint: editorSelection.focus
4048
+ }) : void 0;
4049
+ if (!anchorOffset || !focusOffset)
4050
+ throw new Error("Unable to find anchor or focus offset");
4051
+ if (slate.Range.isExpanded(selection)) {
4052
+ slate.Transforms.setNodes(editor, {}, {
4053
+ at: selection,
4054
+ match: slate.Text.isText,
4055
+ split: !0,
4056
+ hanging: !0
4057
+ });
4058
+ const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
4059
+ value: newValue,
4060
+ offsets: {
4061
+ anchor: anchorOffset,
4062
+ focus: focusOffset
4063
+ },
4064
+ backward: editorSelection?.backward
4065
+ }), trimmedSelection = selector_isSelectingEntireBlocks.getTrimmedSelection({
4066
+ context: {
4067
+ activeDecorators: [],
4068
+ converters: [],
4069
+ keyGenerator: context.keyGenerator,
4070
+ readOnly: !1,
4071
+ schema: context.schema,
4072
+ selection: newSelection,
4073
+ value: newValue
4074
+ }
4075
+ });
4076
+ if (!trimmedSelection)
4077
+ throw new Error("Unable to find trimmed selection");
4078
+ const newRange = toSlateRange(trimmedSelection, editor);
4079
+ if (!newRange)
4080
+ throw new Error("Unable to find new selection");
4081
+ const splitTextNodes = slate.Range.isRange(newRange) ? [...slate.Editor.nodes(editor, {
4082
+ at: newRange,
4083
+ match: (node) => slate.Text.isText(node)
4084
+ })] : [];
4085
+ for (const [node, path] of splitTextNodes) {
4086
+ const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
4087
+ slate.Transforms.setNodes(editor, {
4088
+ marks
4089
+ }, {
4090
+ at: path,
4091
+ match: slate.Text.isText,
4092
+ split: !0,
4093
+ hanging: !0
4094
+ });
4095
+ }
4096
+ } else {
4097
+ if (!Array.from(slate.Editor.nodes(editor, {
4098
+ at: selection,
4099
+ match: (node) => editor.isTextSpan(node)
4100
+ }))?.at(0))
4101
+ return;
4102
+ const [block, blockPath] = slate.Editor.node(editor, selection, {
4103
+ depth: 1
4104
+ }), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
4105
+ if (lonelyEmptySpan) {
4106
+ const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
4107
+ slate.Transforms.setNodes(editor, {
4108
+ marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
4109
+ }, {
4110
+ at: blockPath,
4111
+ match: (node) => editor.isTextSpan(node)
4112
+ });
4113
+ } else {
4114
+ const existingMarks = {
4115
+ ...slate.Editor.marks(editor) || {}
4116
+ }.marks || [], marks = {
4117
+ ...slate.Editor.marks(editor) || {},
4118
+ marks: [...existingMarks, mark]
4119
+ };
4120
+ editor.marks = marks;
4121
+ }
4122
+ }
4123
+ if (editor.selection) {
4124
+ const selection2 = editor.selection;
4125
+ editor.selection = {
4126
+ ...selection2
4127
+ };
4128
+ }
4129
+ }, deleteActionImplementation = ({
4130
+ action
4131
+ }) => {
4132
+ const range = toSlateRange(action.selection, action.editor);
4133
+ if (!range)
4134
+ throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.selection)}`);
4135
+ action.editor.delete({
4136
+ at: range
4137
+ });
4138
+ }, deleteBackwardActionImplementation = ({
4139
+ action
4140
+ }) => {
4141
+ action.editor.deleteBackward(action.unit);
4142
+ }, deleteBlockActionImplementation = ({
4143
+ action
4144
+ }) => {
4145
+ const range = toSlateRange({
4146
+ anchor: {
4147
+ path: action.at,
4148
+ offset: 0
4149
+ },
4150
+ focus: {
4151
+ path: action.at,
4152
+ offset: 0
4153
+ }
4154
+ }, action.editor);
4155
+ if (!range) {
4156
+ console.error("Unable to find Slate range from selection points");
4157
+ return;
4158
+ }
4159
+ slate.Transforms.removeNodes(action.editor, {
4307
4160
  at: range
4308
4161
  });
4309
4162
  }, deleteForwardActionImplementation = ({
@@ -4323,7 +4176,7 @@ const addAnnotationActionImplementation = ({
4323
4176
  });
4324
4177
  if (!selection)
4325
4178
  throw new Error("Unable to find selection from block offsets");
4326
- const trimmedSelection = selector_isActiveStyle.getTrimmedSelection({
4179
+ const trimmedSelection = selector_isSelectingEntireBlocks.getTrimmedSelection({
4327
4180
  context: {
4328
4181
  converters: [],
4329
4182
  schema: context.schema,
@@ -4342,15 +4195,84 @@ const addAnnotationActionImplementation = ({
4342
4195
  slate.Transforms.delete(action.editor, {
4343
4196
  at: range
4344
4197
  });
4345
- }, deserializationFailureActionImplementation = ({
4198
+ }, effectActionImplementation = ({
4199
+ action
4200
+ }) => {
4201
+ action.effect();
4202
+ }, focusActionImplementation = ({
4203
+ action
4204
+ }) => {
4205
+ slateReact.ReactEditor.focus(action.editor);
4206
+ }, insertInlineObjectActionImplementation = ({
4207
+ context,
4208
+ action
4209
+ }) => {
4210
+ if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
4211
+ console.error("Unable to insert unknown inline object");
4212
+ return;
4213
+ }
4214
+ if (!action.editor.selection) {
4215
+ console.error("Unable to insert inline object without selection");
4216
+ return;
4217
+ }
4218
+ const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
4219
+ at: action.editor.selection.focus.path,
4220
+ match: (node) => action.editor.isTextBlock(node)
4221
+ })).at(0) ?? [void 0, void 0];
4222
+ if (!focusTextBlock) {
4223
+ console.error("Unable to perform action without focus text block");
4224
+ return;
4225
+ }
4226
+ const child = toSlateValue([{
4227
+ _type: context.schema.block.name,
4228
+ _key: context.keyGenerator(),
4229
+ children: [{
4230
+ _type: action.inlineObject.name,
4231
+ _key: context.keyGenerator(),
4232
+ ...action.inlineObject.value ?? {}
4233
+ }]
4234
+ }], {
4235
+ schemaTypes: context.schema
4236
+ }).at(0)?.children.at(0);
4237
+ if (!child) {
4238
+ console.error("Unable to insert inline object");
4239
+ return;
4240
+ }
4241
+ slate.Transforms.insertNodes(action.editor, child);
4242
+ }, insertSpanActionImplementation = ({
4243
+ context,
4346
4244
  action
4347
4245
  }) => {
4348
- console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
4246
+ if (!action.editor.selection) {
4247
+ console.error("Unable to perform action without selection", action);
4248
+ return;
4249
+ }
4250
+ const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(action.editor, {
4251
+ at: action.editor.selection.focus.path,
4252
+ match: (node) => action.editor.isTextBlock(node)
4253
+ }))[0] ?? [void 0, void 0];
4254
+ if (!focusBlock || !focusBlockPath) {
4255
+ console.error("Unable to perform action without focus block", action);
4256
+ return;
4257
+ }
4258
+ const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
4259
+ _type: annotation.name,
4260
+ _key: context.keyGenerator(),
4261
+ ...annotation.value
4262
+ })) : void 0;
4263
+ annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
4264
+ markDefs: [...markDefs, ...annotations]
4265
+ }), slate.Transforms.insertNodes(action.editor, {
4266
+ _type: "span",
4267
+ _key: context.keyGenerator(),
4268
+ text: action.text,
4269
+ marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
4270
+ });
4349
4271
  }, insertBlockActionImplementation = ({
4350
4272
  context,
4351
4273
  action
4352
4274
  }) => {
4353
- const parsedBlock = util_selectionPointToBlockOffset.parseBlock({
4275
+ const parsedBlock = parseBlocks.parseBlock({
4354
4276
  block: action.block,
4355
4277
  context,
4356
4278
  options: {
@@ -4433,304 +4355,65 @@ function insertBlock({
4433
4355
  });
4434
4356
  adjustedSelection ? slate.Transforms.select(editor, adjustedSelection) : slate.Transforms.select(editor, currentSelection), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, focusBlockPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, focusBlockPath));
4435
4357
  } else if (placement === "after") {
4436
- const nextPath = [focusBlockPath[0] + 1], currentSelection = editor.selection;
4437
- slate.Transforms.insertNodes(editor, [block], {
4438
- at: nextPath,
4439
- select: !1
4440
- }), slate.Transforms.select(editor, currentSelection), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
4441
- } else {
4442
- const currentSelection = editor.selection, focusBlockStartPoint = slate.Editor.start(editor, focusBlockPath);
4443
- if (editor.isTextBlock(focusBlock) && editor.isTextBlock(block)) {
4444
- if (select === "end") {
4445
- slate.Transforms.insertFragment(editor, [block], {
4446
- voids: !0
4447
- });
4448
- return;
4449
- }
4450
- slate.Transforms.insertFragment(editor, [block], {
4451
- at: currentSelection,
4452
- voids: !0
4453
- }), select === "start" ? slate.Point.equals(currentSelection.anchor, focusBlockStartPoint) ? slate.Transforms.select(editor, slate.Editor.start(editor, focusBlockPath)) : slate.Transforms.select(editor, currentSelection) : slate.Point.equals(currentSelection.anchor, focusBlockStartPoint) || slate.Transforms.select(editor, currentSelection);
4454
- } else if (editor.isTextBlock(focusBlock)) {
4455
- const focusBlockStartPoint2 = slate.Editor.start(editor, focusBlockPath), focusBlockEndPoint = slate.Editor.end(editor, focusBlockPath);
4456
- if (slate.Point.equals(currentSelection.anchor, focusBlockStartPoint2))
4457
- slate.Transforms.insertNodes(editor, [block], {
4458
- at: focusBlockPath,
4459
- select: !1
4460
- }), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, focusBlockPath)), isEqualToEmptyEditor([focusBlock], schema2) && slate.Transforms.removeNodes(editor, {
4461
- at: slate.Path.next(focusBlockPath)
4462
- });
4463
- else if (slate.Point.equals(currentSelection.focus, focusBlockEndPoint)) {
4464
- const nextPath = [focusBlockPath[0] + 1];
4465
- slate.Transforms.insertNodes(editor, [block], {
4466
- at: nextPath,
4467
- select: !1
4468
- }), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, nextPath));
4469
- } else {
4470
- const currentSelection2 = editor.selection, [focusChild] = getFocusChild({
4471
- editor
4472
- });
4473
- if (focusChild && editor.isTextSpan(focusChild))
4474
- slate.Transforms.insertFragment(editor, [block], {
4475
- at: currentSelection2
4476
- }), select === "start" || select === "end" ? slate.Transforms.select(editor, [focusBlockPath[0] + 1]) : slate.Transforms.select(editor, currentSelection2);
4477
- else {
4478
- const nextPath = [focusBlockPath[0] + 1];
4479
- slate.Transforms.insertNodes(editor, [block], {
4480
- at: nextPath,
4481
- select: !1
4482
- }), slate.Transforms.select(editor, currentSelection2), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
4483
- }
4484
- }
4485
- } else {
4486
- slate.Transforms.insertNodes(editor, [block], {
4487
- select: !1
4488
- });
4489
- const nextPath = [focusBlockPath[0] + 1];
4490
- select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
4491
- }
4492
- }
4493
- }
4494
- const selectActionImplementation = ({
4495
- action
4496
- }) => {
4497
- const newSelection = toSlateRange(action.selection, action.editor);
4498
- newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
4499
- }, selectNextBlockActionImplementation = ({
4500
- context,
4501
- action
4502
- }) => {
4503
- if (!action.editor.selection) {
4504
- console.error("Unable to select previous block without a selection");
4505
- return;
4506
- }
4507
- const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1], position = action.select === "end" ? slate.Editor.end(action.editor, nextBlockPath) : slate.Editor.start(action.editor, nextBlockPath), newSelection = toPortableTextRange(action.editor.children, {
4508
- anchor: position,
4509
- focus: position
4510
- }, context.schema);
4511
- if (!newSelection) {
4512
- console.error("Could not find selection for next block");
4513
- return;
4514
- }
4515
- selectActionImplementation({
4516
- action: {
4517
- selection: newSelection,
4518
- editor: action.editor
4519
- }
4520
- });
4521
- }, selectPreviousBlockActionImplementation = ({
4522
- context,
4523
- action
4524
- }) => {
4525
- if (!action.editor.selection) {
4526
- console.error("Unable to select previous block without a selection");
4527
- return;
4528
- }
4529
- const blockPath = action.editor.selection.focus.path.slice(0, 1);
4530
- if (!slate.Path.hasPrevious(blockPath)) {
4531
- console.error("There's no previous block to select");
4532
- return;
4533
- }
4534
- const position = action.select === "end" ? slate.Editor.end(action.editor, slate.Path.previous(blockPath)) : slate.Editor.start(action.editor, slate.Path.previous(blockPath)), newSelection = toPortableTextRange(action.editor.children, {
4535
- anchor: position,
4536
- focus: position
4537
- }, context.schema);
4538
- if (!newSelection) {
4539
- console.error("Could not find selection for previous block");
4540
- return;
4541
- }
4542
- selectActionImplementation({
4543
- action: {
4544
- selection: newSelection,
4545
- editor: action.editor
4546
- }
4547
- });
4548
- }, insertBlocksActionImplementation = ({
4549
- context,
4550
- action
4551
- }) => {
4552
- const parsedBlocks = util_selectionPointToBlockOffset.parseBlocks({
4553
- context,
4554
- blocks: action.blocks,
4555
- options: {
4556
- refreshKeys: !1
4557
- }
4558
- });
4559
- if (parsedBlocks.length === 0)
4560
- throw new Error(`Failed to parse blocks ${JSON.stringify(action.blocks)}`);
4561
- const fragment = toSlateValue(parsedBlocks, {
4562
- schemaTypes: context.schema
4563
- });
4564
- if (fragment.length === 0)
4565
- throw new Error(`Failed to convert blocks to Slate fragment ${JSON.stringify(parsedBlocks)}`);
4566
- const [focusBlock] = getFocusBlock({
4567
- editor: action.editor
4568
- });
4569
- if (action.placement === "before") {
4570
- let index = 0;
4571
- for (const block of fragment)
4572
- insertBlock({
4573
- block,
4574
- placement: index === 0 ? "before" : "after",
4575
- select: "end",
4576
- editor: action.editor,
4577
- schema: context.schema
4578
- }), index++;
4579
- } else if (action.placement === "after")
4580
- for (const block of fragment)
4581
- insertBlock({
4582
- block,
4583
- placement: "after",
4584
- select: "end",
4585
- editor: action.editor,
4586
- schema: context.schema
4587
- });
4588
- else if (focusBlock && action.editor.isTextBlock(focusBlock)) {
4589
- if (fragment.length === 1) {
4590
- insertBlock({
4591
- block: fragment[0],
4592
- placement: "auto",
4593
- select: "end",
4594
- editor: action.editor,
4595
- schema: context.schema
4596
- });
4597
- return;
4598
- }
4599
- let index = 0;
4600
- for (const block of fragment)
4601
- index === 0 ? (insertBreakActionImplementation({
4602
- context,
4603
- action: {
4604
- editor: action.editor
4605
- }
4606
- }), selectPreviousBlockActionImplementation({
4607
- context,
4608
- action: {
4609
- editor: action.editor,
4610
- select: "end"
4611
- }
4612
- }), insertBlock({
4613
- block,
4614
- placement: "auto",
4615
- select: "end",
4616
- editor: action.editor,
4617
- schema: context.schema
4618
- })) : index === fragment.length - 1 ? (selectNextBlockActionImplementation({
4619
- context,
4620
- action: {
4621
- editor: action.editor,
4622
- select: "start"
4623
- }
4624
- }), insertBlock({
4625
- block,
4626
- placement: "auto",
4627
- select: "end",
4628
- editor: action.editor,
4629
- schema: context.schema
4630
- })) : insertBlock({
4631
- block,
4632
- placement: "after",
4633
- select: "end",
4634
- editor: action.editor,
4635
- schema: context.schema
4636
- }), index++;
4637
- } else {
4638
- let index = 0;
4639
- for (const block of fragment)
4640
- insertBlock({
4641
- block,
4642
- placement: index === 0 ? "auto" : "after",
4643
- select: "end",
4644
- editor: action.editor,
4645
- schema: context.schema
4646
- }), index++;
4647
- }
4648
- }, deserializationSuccessActionImplementation = ({
4649
- context,
4650
- action
4651
- }) => {
4652
- insertBlocksActionImplementation({
4653
- context,
4654
- action: {
4655
- blocks: action.data,
4656
- editor: action.editor,
4657
- placement: "auto"
4658
- }
4659
- });
4660
- }, effectActionImplementation = ({
4661
- action
4662
- }) => {
4663
- action.effect();
4664
- }, focusActionImplementation = ({
4665
- action
4666
- }) => {
4667
- slateReact.ReactEditor.focus(action.editor);
4668
- }, insertInlineObjectActionImplementation = ({
4669
- context,
4670
- action
4671
- }) => {
4672
- if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
4673
- console.error("Unable to insert unknown inline object");
4674
- return;
4675
- }
4676
- if (!action.editor.selection) {
4677
- console.error("Unable to insert inline object without selection");
4678
- return;
4679
- }
4680
- const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
4681
- at: action.editor.selection.focus.path,
4682
- match: (node) => action.editor.isTextBlock(node)
4683
- })).at(0) ?? [void 0, void 0];
4684
- if (!focusTextBlock) {
4685
- console.error("Unable to perform action without focus text block");
4686
- return;
4687
- }
4688
- const child = toSlateValue([{
4689
- _type: context.schema.block.name,
4690
- _key: context.keyGenerator(),
4691
- children: [{
4692
- _type: action.inlineObject.name,
4693
- _key: context.keyGenerator(),
4694
- ...action.inlineObject.value ?? {}
4695
- }]
4696
- }], {
4697
- schemaTypes: context.schema
4698
- }).at(0)?.children.at(0);
4699
- if (!child) {
4700
- console.error("Unable to insert inline object");
4701
- return;
4702
- }
4703
- slate.Transforms.insertNodes(action.editor, child);
4704
- }, insertSpanActionImplementation = ({
4705
- context,
4706
- action
4707
- }) => {
4708
- if (!action.editor.selection) {
4709
- console.error("Unable to perform action without selection", action);
4710
- return;
4711
- }
4712
- const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(action.editor, {
4713
- at: action.editor.selection.focus.path,
4714
- match: (node) => action.editor.isTextBlock(node)
4715
- }))[0] ?? [void 0, void 0];
4716
- if (!focusBlock || !focusBlockPath) {
4717
- console.error("Unable to perform action without focus block", action);
4718
- return;
4358
+ const nextPath = [focusBlockPath[0] + 1], currentSelection = editor.selection;
4359
+ slate.Transforms.insertNodes(editor, [block], {
4360
+ at: nextPath,
4361
+ select: !1
4362
+ }), slate.Transforms.select(editor, currentSelection), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
4363
+ } else {
4364
+ const currentSelection = editor.selection, focusBlockStartPoint = slate.Editor.start(editor, focusBlockPath);
4365
+ if (editor.isTextBlock(focusBlock) && editor.isTextBlock(block)) {
4366
+ if (select === "end") {
4367
+ slate.Transforms.insertFragment(editor, [block], {
4368
+ voids: !0
4369
+ });
4370
+ return;
4371
+ }
4372
+ slate.Transforms.insertFragment(editor, [block], {
4373
+ at: currentSelection,
4374
+ voids: !0
4375
+ }), select === "start" ? slate.Point.equals(currentSelection.anchor, focusBlockStartPoint) ? slate.Transforms.select(editor, slate.Editor.start(editor, focusBlockPath)) : slate.Transforms.select(editor, currentSelection) : slate.Point.equals(currentSelection.anchor, focusBlockStartPoint) || slate.Transforms.select(editor, currentSelection);
4376
+ } else if (editor.isTextBlock(focusBlock)) {
4377
+ const focusBlockStartPoint2 = slate.Editor.start(editor, focusBlockPath), focusBlockEndPoint = slate.Editor.end(editor, focusBlockPath);
4378
+ if (slate.Point.equals(currentSelection.anchor, focusBlockStartPoint2))
4379
+ slate.Transforms.insertNodes(editor, [block], {
4380
+ at: focusBlockPath,
4381
+ select: !1
4382
+ }), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, focusBlockPath)), isEqualToEmptyEditor([focusBlock], schema2) && slate.Transforms.removeNodes(editor, {
4383
+ at: slate.Path.next(focusBlockPath)
4384
+ });
4385
+ else if (slate.Point.equals(currentSelection.focus, focusBlockEndPoint)) {
4386
+ const nextPath = [focusBlockPath[0] + 1];
4387
+ slate.Transforms.insertNodes(editor, [block], {
4388
+ at: nextPath,
4389
+ select: !1
4390
+ }), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, nextPath));
4391
+ } else {
4392
+ const currentSelection2 = editor.selection, [focusChild] = getFocusChild({
4393
+ editor
4394
+ });
4395
+ if (focusChild && editor.isTextSpan(focusChild))
4396
+ slate.Transforms.insertFragment(editor, [block], {
4397
+ at: currentSelection2
4398
+ }), select === "start" || select === "end" ? slate.Transforms.select(editor, [focusBlockPath[0] + 1]) : slate.Transforms.select(editor, currentSelection2);
4399
+ else {
4400
+ const nextPath = [focusBlockPath[0] + 1];
4401
+ slate.Transforms.insertNodes(editor, [block], {
4402
+ at: nextPath,
4403
+ select: !1
4404
+ }), slate.Transforms.select(editor, currentSelection2), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
4405
+ }
4406
+ }
4407
+ } else {
4408
+ slate.Transforms.insertNodes(editor, [block], {
4409
+ select: !1
4410
+ });
4411
+ const nextPath = [focusBlockPath[0] + 1];
4412
+ select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
4413
+ }
4719
4414
  }
4720
- const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
4721
- _type: annotation.name,
4722
- _key: context.keyGenerator(),
4723
- ...annotation.value
4724
- })) : void 0;
4725
- annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
4726
- markDefs: [...markDefs, ...annotations]
4727
- }), slate.Transforms.insertNodes(action.editor, {
4728
- _type: "span",
4729
- _key: context.keyGenerator(),
4730
- text: action.text,
4731
- marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
4732
- });
4733
- }, insertTextActionImplementation = ({
4415
+ }
4416
+ const insertTextActionImplementation = ({
4734
4417
  action
4735
4418
  }) => {
4736
4419
  action.editor.insertText(action.text);
@@ -4801,65 +4484,39 @@ const selectActionImplementation = ({
4801
4484
  }
4802
4485
  });
4803
4486
  }, noopActionImplementation = () => {
4804
- }, serializationFailureActionImplementation = ({
4805
- action
4806
- }) => {
4807
- console.warn(`Serialization of ${action.mimeType} failed with reason "${action.reason}"`);
4808
- }, serializationSuccessActionImplementation = ({
4809
- context,
4487
+ }, selectActionImplementation = ({
4810
4488
  action
4811
4489
  }) => {
4812
- dataTransferSetActionImplementation({
4813
- action: {
4814
- data: action.data,
4815
- dataTransfer: action.originEvent.originEvent.dataTransfer,
4816
- mimeType: action.mimeType
4817
- }
4818
- });
4490
+ const newSelection = toSlateRange(action.selection, action.editor);
4491
+ newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
4819
4492
  }, debug$9 = debugWithName("behaviors:action"), behaviorActionImplementations = {
4820
4493
  "annotation.add": addAnnotationActionImplementation,
4821
4494
  "annotation.remove": removeAnnotationActionImplementation,
4822
- "annotation.toggle": toggleAnnotationActionImplementation,
4823
4495
  "block.set": blockSetBehaviorActionImplementation,
4824
4496
  "block.unset": blockUnsetBehaviorActionImplementation,
4825
4497
  blur: blurActionImplementation,
4826
- "data transfer.set": dataTransferSetActionImplementation,
4827
4498
  "decorator.add": decoratorAddActionImplementation,
4828
4499
  "decorator.remove": removeDecoratorActionImplementation,
4829
- "decorator.toggle": toggleDecoratorActionImplementation,
4830
4500
  focus: focusActionImplementation,
4831
4501
  delete: deleteActionImplementation,
4832
4502
  "delete.backward": deleteBackwardActionImplementation,
4833
4503
  "delete.forward": deleteForwardActionImplementation,
4834
4504
  "delete.block": deleteBlockActionImplementation,
4835
4505
  "delete.text": deleteTextActionImplementation,
4836
- "deserialization.failure": deserializationFailureActionImplementation,
4837
- "deserialization.success": deserializationSuccessActionImplementation,
4838
4506
  "history.redo": historyRedoActionImplementation,
4839
4507
  "history.undo": historyUndoActionImplementation,
4840
4508
  "insert.block": insertBlockActionImplementation,
4841
- "insert.blocks": insertBlocksActionImplementation,
4842
4509
  "insert.break": insertBreakActionImplementation,
4843
4510
  "insert.inline object": insertInlineObjectActionImplementation,
4844
4511
  "insert.soft break": insertSoftBreakActionImplementation,
4845
4512
  "insert.span": insertSpanActionImplementation,
4846
4513
  "insert.text": insertTextActionImplementation,
4847
4514
  effect: effectActionImplementation,
4848
- "list item.add": addListItemActionImplementation,
4849
- "list item.remove": removeListItemActionImplementation,
4850
- "list item.toggle": toggleListItemActionImplementation,
4851
4515
  "move.block": moveBlockActionImplementation,
4852
4516
  "move.block down": moveBlockDownActionImplementation,
4853
4517
  "move.block up": moveBlockUpActionImplementation,
4854
4518
  noop: noopActionImplementation,
4855
- select: selectActionImplementation,
4856
- "select.previous block": selectPreviousBlockActionImplementation,
4857
- "select.next block": selectNextBlockActionImplementation,
4858
- "serialization.failure": serializationFailureActionImplementation,
4859
- "serialization.success": serializationSuccessActionImplementation,
4860
- "style.toggle": toggleStyleActionImplementation,
4861
- "style.add": addStyleActionImplementation,
4862
- "style.remove": removeStyleActionImplementation
4519
+ select: selectActionImplementation
4863
4520
  };
4864
4521
  function performAction({
4865
4522
  context,
@@ -4880,13 +4537,6 @@ function performAction({
4880
4537
  });
4881
4538
  break;
4882
4539
  }
4883
- case "annotation.toggle": {
4884
- behaviorActionImplementations["annotation.toggle"]({
4885
- context,
4886
- action
4887
- });
4888
- break;
4889
- }
4890
4540
  case "block.set": {
4891
4541
  behaviorActionImplementations["block.set"]({
4892
4542
  context,
@@ -4908,13 +4558,6 @@ function performAction({
4908
4558
  });
4909
4559
  break;
4910
4560
  }
4911
- case "data transfer.set": {
4912
- behaviorActionImplementations["data transfer.set"]({
4913
- context,
4914
- action
4915
- });
4916
- break;
4917
- }
4918
4561
  case "decorator.add": {
4919
4562
  behaviorActionImplementations["decorator.add"]({
4920
4563
  context,
@@ -4929,13 +4572,6 @@ function performAction({
4929
4572
  });
4930
4573
  break;
4931
4574
  }
4932
- case "decorator.toggle": {
4933
- behaviorActionImplementations["decorator.toggle"]({
4934
- context,
4935
- action
4936
- });
4937
- break;
4938
- }
4939
4575
  case "delete": {
4940
4576
  behaviorActionImplementations.delete({
4941
4577
  context,
@@ -4971,20 +4607,6 @@ function performAction({
4971
4607
  });
4972
4608
  break;
4973
4609
  }
4974
- case "deserialization.failure": {
4975
- behaviorActionImplementations["deserialization.failure"]({
4976
- context,
4977
- action
4978
- });
4979
- break;
4980
- }
4981
- case "deserialization.success": {
4982
- behaviorActionImplementations["deserialization.success"]({
4983
- context,
4984
- action
4985
- });
4986
- break;
4987
- }
4988
4610
  case "effect": {
4989
4611
  behaviorActionImplementations.effect({
4990
4612
  context,
@@ -5020,13 +4642,6 @@ function performAction({
5020
4642
  });
5021
4643
  break;
5022
4644
  }
5023
- case "insert.blocks": {
5024
- behaviorActionImplementations["insert.blocks"]({
5025
- context,
5026
- action
5027
- });
5028
- break;
5029
- }
5030
4645
  case "insert.inline object": {
5031
4646
  behaviorActionImplementations["insert.inline object"]({
5032
4647
  context,
@@ -5062,27 +4677,6 @@ function performAction({
5062
4677
  });
5063
4678
  break;
5064
4679
  }
5065
- case "list item.add": {
5066
- behaviorActionImplementations["list item.add"]({
5067
- context,
5068
- action
5069
- });
5070
- break;
5071
- }
5072
- case "list item.remove": {
5073
- behaviorActionImplementations["list item.remove"]({
5074
- context,
5075
- action
5076
- });
5077
- break;
5078
- }
5079
- case "list item.toggle": {
5080
- behaviorActionImplementations["list item.toggle"]({
5081
- context,
5082
- action
5083
- });
5084
- break;
5085
- }
5086
4680
  case "move.block": {
5087
4681
  behaviorActionImplementations["move.block"]({
5088
4682
  context,
@@ -5106,57 +4700,8 @@ function performAction({
5106
4700
  }
5107
4701
  case "noop":
5108
4702
  break;
5109
- case "select": {
5110
- behaviorActionImplementations.select({
5111
- context,
5112
- action
5113
- });
5114
- break;
5115
- }
5116
- case "select.previous block": {
5117
- behaviorActionImplementations["select.previous block"]({
5118
- context,
5119
- action
5120
- });
5121
- break;
5122
- }
5123
- case "select.next block": {
5124
- behaviorActionImplementations["select.next block"]({
5125
- context,
5126
- action
5127
- });
5128
- break;
5129
- }
5130
- case "serialization.failure": {
5131
- behaviorActionImplementations["serialization.failure"]({
5132
- context,
5133
- action
5134
- });
5135
- break;
5136
- }
5137
- case "serialization.success": {
5138
- behaviorActionImplementations["serialization.success"]({
5139
- context,
5140
- action
5141
- });
5142
- break;
5143
- }
5144
- case "style.add": {
5145
- behaviorActionImplementations["style.add"]({
5146
- context,
5147
- action
5148
- });
5149
- break;
5150
- }
5151
- case "style.remove": {
5152
- behaviorActionImplementations["style.remove"]({
5153
- context,
5154
- action
5155
- });
5156
- break;
5157
- }
5158
4703
  default: {
5159
- behaviorActionImplementations["style.toggle"]({
4704
+ behaviorActionImplementations.select({
5160
4705
  context,
5161
4706
  action
5162
4707
  });
@@ -6065,43 +5610,43 @@ const keyIs = {
6065
5610
  actions: [() => [behavior_core.raise({
6066
5611
  type: "insert.soft break"
6067
5612
  })]]
6068
- }), toggleAnnotationOff = behavior_core.defineBehavior({
5613
+ }), internalAnnotationBehaviors = [behavior_core.defineBehavior({
6069
5614
  on: "annotation.toggle",
6070
5615
  guard: ({
6071
5616
  snapshot,
6072
5617
  event
6073
- }) => selector_isActiveStyle.isActiveAnnotation(event.annotation.name)(snapshot),
5618
+ }) => selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name)(snapshot),
6074
5619
  actions: [({
6075
5620
  event
6076
5621
  }) => [behavior_core.raise({
6077
5622
  type: "annotation.remove",
6078
5623
  annotation: event.annotation
6079
5624
  })]]
6080
- }), toggleAnnotationOn = behavior_core.defineBehavior({
5625
+ }), behavior_core.defineBehavior({
6081
5626
  on: "annotation.toggle",
6082
5627
  guard: ({
6083
5628
  snapshot,
6084
5629
  event
6085
- }) => !selector_isActiveStyle.isActiveAnnotation(event.annotation.name)(snapshot),
5630
+ }) => !selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name)(snapshot),
6086
5631
  actions: [({
6087
5632
  event
6088
5633
  }) => [behavior_core.raise({
6089
5634
  type: "annotation.add",
6090
5635
  annotation: event.annotation
6091
5636
  })]]
6092
- }), toggleDecoratorOff = behavior_core.defineBehavior({
5637
+ })], internalDecoratorBehaviors = [behavior_core.defineBehavior({
6093
5638
  on: "decorator.toggle",
6094
5639
  guard: ({
6095
5640
  snapshot,
6096
5641
  event
6097
- }) => selector_isActiveStyle.isActiveDecorator(event.decorator)(snapshot),
5642
+ }) => selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)(snapshot),
6098
5643
  actions: [({
6099
5644
  event
6100
5645
  }) => [behavior_core.raise({
6101
5646
  type: "decorator.remove",
6102
5647
  decorator: event.decorator
6103
5648
  })]]
6104
- }), toggleDecoratorOn = behavior_core.defineBehavior({
5649
+ }), behavior_core.defineBehavior({
6105
5650
  on: "decorator.toggle",
6106
5651
  guard: ({
6107
5652
  snapshot,
@@ -6111,13 +5656,13 @@ const keyIs = {
6111
5656
  value: snapshot.context.value,
6112
5657
  offsets: event.offsets
6113
5658
  }) : null;
6114
- return manualSelection ? !selector_isActiveStyle.isActiveDecorator(event.decorator)({
5659
+ return manualSelection ? !selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)({
6115
5660
  ...snapshot,
6116
5661
  context: {
6117
5662
  ...snapshot.context,
6118
5663
  selection: manualSelection
6119
5664
  }
6120
- }) : !selector_isActiveStyle.isActiveDecorator(event.decorator)(snapshot);
5665
+ }) : !selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)(snapshot);
6121
5666
  },
6122
5667
  actions: [({
6123
5668
  event
@@ -6125,55 +5670,242 @@ const keyIs = {
6125
5670
  ...event,
6126
5671
  type: "decorator.add"
6127
5672
  })]]
6128
- }), toggleListItemOff = behavior_core.defineBehavior({
5673
+ })], internalInsertBehaviors = [behavior_core.defineBehavior({
5674
+ on: "insert.blocks",
5675
+ guard: ({
5676
+ event
5677
+ }) => event.placement === "before",
5678
+ actions: [({
5679
+ event
5680
+ }) => event.blocks.map((block, index) => behavior_core.raise({
5681
+ type: "insert.block",
5682
+ block,
5683
+ placement: index === 0 ? "before" : "after",
5684
+ select: "end"
5685
+ }))]
5686
+ }), behavior_core.defineBehavior({
5687
+ on: "insert.blocks",
5688
+ guard: ({
5689
+ event
5690
+ }) => event.placement === "after",
5691
+ actions: [({
5692
+ event
5693
+ }) => event.blocks.map((block) => behavior_core.raise({
5694
+ type: "insert.block",
5695
+ block,
5696
+ placement: "after",
5697
+ select: "end"
5698
+ }))]
5699
+ }), behavior_core.defineBehavior({
5700
+ on: "insert.blocks",
5701
+ guard: ({
5702
+ snapshot,
5703
+ event
5704
+ }) => !(event.placement !== "auto" || !selector_isOverlappingSelection.getFocusTextBlock(snapshot)),
5705
+ actions: [({
5706
+ event
5707
+ }) => event.blocks.length === 1 ? [behavior_core.raise({
5708
+ type: "insert.block",
5709
+ block: event.blocks[0],
5710
+ placement: "auto",
5711
+ select: "end"
5712
+ })] : event.blocks.flatMap((block, index) => index === 0 ? [behavior_core.raise({
5713
+ type: "insert.break"
5714
+ }), behavior_core.raise({
5715
+ type: "select.previous block",
5716
+ select: "end"
5717
+ }), behavior_core.raise({
5718
+ type: "insert.block",
5719
+ block,
5720
+ placement: "auto",
5721
+ select: "end"
5722
+ })] : index === event.blocks.length - 1 ? [behavior_core.raise({
5723
+ type: "select.next block",
5724
+ select: "start"
5725
+ }), behavior_core.raise({
5726
+ type: "insert.block",
5727
+ block,
5728
+ placement: "auto",
5729
+ select: "end"
5730
+ })] : [behavior_core.raise({
5731
+ type: "insert.block",
5732
+ block,
5733
+ placement: "after",
5734
+ select: "end"
5735
+ })])]
5736
+ }), behavior_core.defineBehavior({
5737
+ on: "insert.blocks",
5738
+ guard: ({
5739
+ event
5740
+ }) => event.placement === "auto",
5741
+ actions: [({
5742
+ event
5743
+ }) => event.blocks.map((block, index) => behavior_core.raise({
5744
+ type: "insert.block",
5745
+ block,
5746
+ placement: index === 0 ? "auto" : "after",
5747
+ select: "end"
5748
+ }))]
5749
+ })], internalListItemBehaviors = [behavior_core.defineBehavior({
5750
+ on: "list item.add",
5751
+ guard: ({
5752
+ snapshot
5753
+ }) => ({
5754
+ selectedTextBlocks: selector_isSelectingEntireBlocks.getSelectedTextBlocks(snapshot)
5755
+ }),
5756
+ actions: [({
5757
+ event
5758
+ }, {
5759
+ selectedTextBlocks
5760
+ }) => selectedTextBlocks.map((block) => behavior_core.raise({
5761
+ type: "block.set",
5762
+ at: block.path,
5763
+ props: {
5764
+ level: 1,
5765
+ listItem: event.listItem
5766
+ }
5767
+ }))]
5768
+ }), behavior_core.defineBehavior({
5769
+ on: "list item.remove",
5770
+ guard: ({
5771
+ snapshot
5772
+ }) => ({
5773
+ selectedTextBlocks: selector_isSelectingEntireBlocks.getSelectedTextBlocks(snapshot)
5774
+ }),
5775
+ actions: [(_, {
5776
+ selectedTextBlocks
5777
+ }) => selectedTextBlocks.map((block) => behavior_core.raise({
5778
+ type: "block.unset",
5779
+ at: block.path,
5780
+ props: ["level", "listItem"]
5781
+ }))]
5782
+ }), behavior_core.defineBehavior({
6129
5783
  on: "list item.toggle",
6130
5784
  guard: ({
6131
5785
  snapshot,
6132
5786
  event
6133
- }) => selector_isActiveStyle.isActiveListItem(event.listItem)(snapshot),
5787
+ }) => selector_isSelectingEntireBlocks.isActiveListItem(event.listItem)(snapshot),
6134
5788
  actions: [({
6135
5789
  event
6136
5790
  }) => [behavior_core.raise({
6137
5791
  type: "list item.remove",
6138
5792
  listItem: event.listItem
6139
5793
  })]]
6140
- }), toggleListItemOn = behavior_core.defineBehavior({
5794
+ }), behavior_core.defineBehavior({
6141
5795
  on: "list item.toggle",
6142
5796
  guard: ({
6143
5797
  snapshot,
6144
5798
  event
6145
- }) => !selector_isActiveStyle.isActiveListItem(event.listItem)(snapshot),
5799
+ }) => !selector_isSelectingEntireBlocks.isActiveListItem(event.listItem)(snapshot),
6146
5800
  actions: [({
6147
5801
  event
6148
5802
  }) => [behavior_core.raise({
6149
5803
  type: "list item.add",
6150
5804
  listItem: event.listItem
6151
5805
  })]]
6152
- }), toggleStyleOff = behavior_core.defineBehavior({
5806
+ })], internalSelectBehaviors = [behavior_core.defineBehavior({
5807
+ on: "select.previous block",
5808
+ guard: ({
5809
+ snapshot,
5810
+ event
5811
+ }) => {
5812
+ const previousBlock = selector_isOverlappingSelection.getPreviousBlock(snapshot);
5813
+ if (!previousBlock)
5814
+ return !1;
5815
+ const point = event.select === "end" ? util_sliceBlocks.getBlockEndPoint(previousBlock) : util_sliceBlocks.getBlockStartPoint(previousBlock);
5816
+ return {
5817
+ selection: {
5818
+ anchor: point,
5819
+ focus: point
5820
+ }
5821
+ };
5822
+ },
5823
+ actions: [(_, {
5824
+ selection
5825
+ }) => [behavior_core.raise({
5826
+ type: "select",
5827
+ selection
5828
+ })]]
5829
+ }), behavior_core.defineBehavior({
5830
+ on: "select.next block",
5831
+ guard: ({
5832
+ snapshot,
5833
+ event
5834
+ }) => {
5835
+ const nextBlock = selector_isOverlappingSelection.getNextBlock(snapshot);
5836
+ if (!nextBlock)
5837
+ return !1;
5838
+ const point = event.select === "end" ? util_sliceBlocks.getBlockEndPoint(nextBlock) : util_sliceBlocks.getBlockStartPoint(nextBlock);
5839
+ return {
5840
+ selection: {
5841
+ anchor: point,
5842
+ focus: point
5843
+ }
5844
+ };
5845
+ },
5846
+ actions: [(_, {
5847
+ selection
5848
+ }) => [behavior_core.raise({
5849
+ type: "select",
5850
+ selection
5851
+ })]]
5852
+ })], internalStyleBehaviors = [behavior_core.defineBehavior({
5853
+ on: "style.add",
5854
+ guard: ({
5855
+ snapshot
5856
+ }) => ({
5857
+ selectedTextBlocks: selector_isSelectingEntireBlocks.getSelectedTextBlocks(snapshot)
5858
+ }),
5859
+ actions: [({
5860
+ event
5861
+ }, {
5862
+ selectedTextBlocks
5863
+ }) => selectedTextBlocks.map((block) => behavior_core.raise({
5864
+ type: "block.set",
5865
+ at: block.path,
5866
+ props: {
5867
+ style: event.style
5868
+ }
5869
+ }))]
5870
+ }), behavior_core.defineBehavior({
5871
+ on: "style.remove",
5872
+ guard: ({
5873
+ snapshot
5874
+ }) => ({
5875
+ selectedTextBlocks: selector_isSelectingEntireBlocks.getSelectedTextBlocks(snapshot)
5876
+ }),
5877
+ actions: [(_, {
5878
+ selectedTextBlocks
5879
+ }) => selectedTextBlocks.map((block) => behavior_core.raise({
5880
+ type: "block.unset",
5881
+ at: block.path,
5882
+ props: ["style"]
5883
+ }))]
5884
+ }), behavior_core.defineBehavior({
6153
5885
  on: "style.toggle",
6154
5886
  guard: ({
6155
5887
  snapshot,
6156
5888
  event
6157
- }) => selector_isActiveStyle.isActiveStyle(event.style)(snapshot),
5889
+ }) => selector_isSelectingEntireBlocks.isActiveStyle(event.style)(snapshot),
6158
5890
  actions: [({
6159
5891
  event
6160
5892
  }) => [behavior_core.raise({
6161
5893
  type: "style.remove",
6162
5894
  style: event.style
6163
5895
  })]]
6164
- }), toggleStyleOn = behavior_core.defineBehavior({
5896
+ }), behavior_core.defineBehavior({
6165
5897
  on: "style.toggle",
6166
5898
  guard: ({
6167
5899
  snapshot,
6168
5900
  event
6169
- }) => !selector_isActiveStyle.isActiveStyle(event.style)(snapshot),
5901
+ }) => !selector_isSelectingEntireBlocks.isActiveStyle(event.style)(snapshot),
6170
5902
  actions: [({
6171
5903
  event
6172
5904
  }) => [behavior_core.raise({
6173
5905
  type: "style.add",
6174
5906
  style: event.style
6175
5907
  })]]
6176
- }), raiseDeserializationSuccessOrFailure = behavior_core.defineBehavior({
5908
+ })], raiseDeserializationSuccessOrFailure = behavior_core.defineBehavior({
6177
5909
  on: "deserialize",
6178
5910
  guard: ({
6179
5911
  snapshot,
@@ -6290,12 +6022,23 @@ const keyIs = {
6290
6022
  on: "serialization.success",
6291
6023
  actions: [({
6292
6024
  event
6293
- }) => [behavior_core.raise({
6294
- type: "data transfer.set",
6295
- data: event.data,
6296
- dataTransfer: event.originEvent.originEvent.dataTransfer,
6297
- mimeType: event.mimeType
6298
- })]]
6025
+ }) => [{
6026
+ type: "effect",
6027
+ effect: () => {
6028
+ event.originEvent.originEvent.dataTransfer.setData(event.mimeType, event.data);
6029
+ }
6030
+ }]]
6031
+ }),
6032
+ behavior_core.defineBehavior({
6033
+ on: "serialization.failure",
6034
+ actions: [({
6035
+ event
6036
+ }) => [{
6037
+ type: "effect",
6038
+ effect: () => {
6039
+ console.warn(`Serialization of ${event.mimeType} failed with reason "${event.reason}"`);
6040
+ }
6041
+ }]]
6299
6042
  }),
6300
6043
  behavior_core.defineBehavior({
6301
6044
  on: "drag.drop",
@@ -6342,7 +6085,7 @@ const keyIs = {
6342
6085
  ...snapshot.context,
6343
6086
  selection: dragOrigin.selection
6344
6087
  }
6345
- }) : !1, draggingEntireBlocks = selector_isActiveStyle.isSelectingEntireBlocks({
6088
+ }) : !1, draggingEntireBlocks = selector_isSelectingEntireBlocks.isSelectingEntireBlocks({
6346
6089
  context: {
6347
6090
  ...snapshot.context,
6348
6091
  selection: dragOrigin.selection
@@ -6393,9 +6136,9 @@ const keyIs = {
6393
6136
  if (selector_isOverlappingSelection.getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
6394
6137
  const activeDecorators = snapshot.context.activeDecorators;
6395
6138
  return {
6396
- activeAnnotations: selector_isActiveStyle.getActiveAnnotations(snapshot),
6139
+ activeAnnotations: selector_isSelectingEntireBlocks.getActiveAnnotations(snapshot),
6397
6140
  activeDecorators,
6398
- textRuns: event.data.flatMap((block) => util_selectionPointToBlockOffset.isTextBlock(snapshot.context.schema, block) ? [util_sliceBlocks.getTextBlockText(block)] : [])
6141
+ textRuns: event.data.flatMap((block) => parseBlocks.isTextBlock(snapshot.context.schema, block) ? [util_sliceBlocks.getTextBlockText(block)] : [])
6399
6142
  };
6400
6143
  }
6401
6144
  return !1;
@@ -6442,6 +6185,17 @@ const keyIs = {
6442
6185
  placement: "auto"
6443
6186
  })]]
6444
6187
  }),
6188
+ behavior_core.defineBehavior({
6189
+ on: "deserialization.failure",
6190
+ actions: [({
6191
+ event
6192
+ }) => [{
6193
+ type: "effect",
6194
+ effect: () => {
6195
+ console.warn(`Deserialization of ${event.mimeType} failed with reason "${event.reason}"`);
6196
+ }
6197
+ }]]
6198
+ }),
6445
6199
  behavior_core.defineBehavior({
6446
6200
  on: "clipboard.paste",
6447
6201
  guard: ({
@@ -6479,14 +6233,12 @@ const keyIs = {
6479
6233
  originEvent: event
6480
6234
  })]]
6481
6235
  }),
6482
- toggleAnnotationOff,
6483
- toggleAnnotationOn,
6484
- toggleDecoratorOff,
6485
- toggleDecoratorOn,
6486
- toggleListItemOff,
6487
- toggleListItemOn,
6488
- toggleStyleOff,
6489
- toggleStyleOn,
6236
+ ...internalAnnotationBehaviors,
6237
+ ...internalDecoratorBehaviors,
6238
+ ...internalInsertBehaviors,
6239
+ ...internalListItemBehaviors,
6240
+ ...internalStyleBehaviors,
6241
+ ...internalSelectBehaviors,
6490
6242
  raiseDeserializationSuccessOrFailure,
6491
6243
  raiseSerializationSuccessOrFailure,
6492
6244
  raiseInsertSoftBreak
@@ -6494,6 +6246,12 @@ const keyIs = {
6494
6246
  function isKeyboardBehaviorEvent(event) {
6495
6247
  return event.type.startsWith("keyboard.");
6496
6248
  }
6249
+ function isInternalBehaviorEvent(event) {
6250
+ 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.");
6251
+ }
6252
+ function isNativeBehaviorEvent(event) {
6253
+ return isClipboardBehaviorEvent(event) || isDragBehaviorEvent(event) || isInputBehaviorEvent(event) || isKeyboardBehaviorEvent(event) || isMouseBehaviorEvent(event);
6254
+ }
6497
6255
  function isClipboardBehaviorEvent(event) {
6498
6256
  return event.type.startsWith("clipboard.");
6499
6257
  }
@@ -6510,6 +6268,9 @@ function isCustomBehaviorEvent(event) {
6510
6268
  return event.type.startsWith("custom.");
6511
6269
  }
6512
6270
  const debug$2 = debugWithName("behaviors:event");
6271
+ function eventCategory(event) {
6272
+ return isNativeBehaviorEvent(event) ? "native" : isInternalBehaviorEvent(event) ? "internal" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
6273
+ }
6513
6274
  function performEvent({
6514
6275
  behaviors,
6515
6276
  event,
@@ -6520,8 +6281,8 @@ function performEvent({
6520
6281
  nativeEvent,
6521
6282
  defaultActionCallback
6522
6283
  }) {
6523
- debug$2(JSON.stringify(event, null, 2));
6524
- const defaultAction = isCustomBehaviorEvent(event) || isClipboardBehaviorEvent(event) || isDragBehaviorEvent(event) || isInputBehaviorEvent(event) || isKeyboardBehaviorEvent(event) || isMouseBehaviorEvent(event) || event.type === "deserialize" || event.type === "serialize" ? void 0 : {
6284
+ debug$2(`(${eventCategory(event)})`, JSON.stringify(event, null, 2));
6285
+ const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isInternalBehaviorEvent(event) ? void 0 : {
6525
6286
  ...event,
6526
6287
  editor
6527
6288
  }, eventBehaviors = behaviors.filter((behavior) => {
@@ -6913,7 +6674,7 @@ const editorMachine = xstate.setup({
6913
6674
  actions: "handle behavior event",
6914
6675
  guard: ({
6915
6676
  event
6916
- }) => event.behaviorEvent.type === "clipboard.copy" || event.behaviorEvent.type === "data transfer.set" || event.behaviorEvent.type === "serialize" || event.behaviorEvent.type === "serialization.failure" || event.behaviorEvent.type === "serialization.success" || event.behaviorEvent.type === "select"
6677
+ }) => event.behaviorEvent.type === "clipboard.copy" || event.behaviorEvent.type === "serialize" || event.behaviorEvent.type === "serialization.failure" || event.behaviorEvent.type === "serialization.success" || event.behaviorEvent.type === "select"
6917
6678
  }
6918
6679
  },
6919
6680
  states: {