@portabletext/editor 1.25.0 → 1.26.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 (81) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +131 -36
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +8 -8
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-at-the-start-of-block.cjs} +29 -3
  6. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
  7. package/lib/_chunks-cjs/util.is-empty-text-block.cjs +2 -2
  8. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
  9. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +46 -0
  10. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -16
  12. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
  13. package/lib/_chunks-es/behavior.core.js +99 -4
  14. package/lib/_chunks-es/behavior.core.js.map +1 -1
  15. package/lib/_chunks-es/selector.get-text-before.js +2 -2
  16. package/lib/_chunks-es/{selector.is-active-style.js → selector.is-at-the-start-of-block.js} +29 -2
  17. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
  18. package/lib/_chunks-es/util.is-empty-text-block.js +1 -1
  19. package/lib/_chunks-es/util.is-equal-selection-points.js +47 -0
  20. package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -0
  21. package/lib/_chunks-es/util.reverse-selection.js +0 -16
  22. package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
  23. package/lib/behaviors/index.cjs +27 -27
  24. package/lib/behaviors/index.cjs.map +1 -1
  25. package/lib/behaviors/index.d.cts +413 -0
  26. package/lib/behaviors/index.d.ts +413 -0
  27. package/lib/behaviors/index.js +1 -1
  28. package/lib/index.cjs +147 -106
  29. package/lib/index.cjs.map +1 -1
  30. package/lib/index.d.cts +1653 -222
  31. package/lib/index.d.ts +1653 -222
  32. package/lib/index.js +143 -102
  33. package/lib/index.js.map +1 -1
  34. package/lib/selectors/index.cjs +25 -23
  35. package/lib/selectors/index.cjs.map +1 -1
  36. package/lib/selectors/index.d.cts +16 -0
  37. package/lib/selectors/index.d.ts +16 -0
  38. package/lib/selectors/index.js +3 -1
  39. package/lib/utils/index.cjs +5 -3
  40. package/lib/utils/index.cjs.map +1 -1
  41. package/lib/utils/index.d.cts +19 -0
  42. package/lib/utils/index.d.ts +19 -0
  43. package/lib/utils/index.js +4 -2
  44. package/package.json +1 -1
  45. package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -3
  46. package/src/behavior-actions/behavior.action.block.set.ts +23 -0
  47. package/src/behavior-actions/behavior.action.block.unset.ts +21 -0
  48. package/src/behavior-actions/behavior.action.insert-break.ts +2 -69
  49. package/src/behavior-actions/behavior.action.insert.block.ts +29 -0
  50. package/src/behavior-actions/behavior.actions.ts +28 -9
  51. package/src/behaviors/behavior.core.insert-break.ts +122 -0
  52. package/src/behaviors/behavior.core.ts +6 -2
  53. package/src/behaviors/behavior.types.ts +16 -1
  54. package/src/converters/converter.json.ts +4 -4
  55. package/src/converters/converter.portable-text.deserialize.test.ts +1 -1
  56. package/src/converters/converter.portable-text.ts +4 -4
  57. package/src/converters/converter.text-html.deserialize.test.ts +1 -1
  58. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  59. package/src/converters/converter.text-html.ts +4 -4
  60. package/src/converters/converter.text-plain.test.ts +1 -1
  61. package/src/converters/converter.text-plain.ts +3 -3
  62. package/src/converters/{converter.ts → converter.types.ts} +6 -0
  63. package/src/editor/create-editor.ts +4 -1
  64. package/src/editor/editor-machine.ts +8 -2
  65. package/src/editor/editor-snapshot.ts +1 -1
  66. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +2 -2
  67. package/src/editor/plugins/create-with-event-listeners.ts +3 -0
  68. package/src/selectors/index.ts +2 -0
  69. package/src/selectors/selector.is-at-the-end-of-block.ts +22 -0
  70. package/src/selectors/selector.is-at-the-start-of-block.ts +25 -0
  71. package/src/selectors/selector.is-selection-collapsed.ts +6 -2
  72. package/src/utils/index.ts +2 -0
  73. package/src/utils/util.get-block-end-point.ts +34 -0
  74. package/src/utils/util.is-equal-selection-points.ts +13 -0
  75. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
  76. package/lib/_chunks-cjs/util.is-keyed-segment.cjs +0 -6
  77. package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +0 -1
  78. package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
  79. package/lib/_chunks-es/util.is-keyed-segment.js +0 -7
  80. package/lib/_chunks-es/util.is-keyed-segment.js.map +0 -1
  81. /package/src/converters/{converters.ts → converters.core.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { defineBehavior, isHotkey } from "../_chunks-es/behavior.core.js";
2
2
  import { coreBehavior, coreBehaviors, raise } from "../_chunks-es/behavior.core.js";
3
- import { getFirstBlock, getSelectedBlocks, getLastBlock, getFocusTextBlock, isSelectionCollapsed, getFocusSpan, getFocusBlock } from "../_chunks-es/selector.is-active-style.js";
3
+ import { getFirstBlock, getSelectedBlocks, getLastBlock, getFocusTextBlock, isSelectionCollapsed, getFocusSpan, getFocusBlock } from "../_chunks-es/selector.is-at-the-start-of-block.js";
4
4
  import { createActor, setup, assign, assertEvent } from "xstate";
5
5
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
6
6
  import { isPortableTextTextBlock } from "@sanity/types";
package/lib/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$j = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isActiveStyle = require("./_chunks-cjs/selector.is-active-style.cjs"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm");
3
+ var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$j = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
@@ -2501,6 +2501,7 @@ function _temp(s) {
2501
2501
  }
2502
2502
  Synchronizer.displayName = "Synchronizer";
2503
2503
  const converterJson = {
2504
+ mimeType: "application/json",
2504
2505
  serialize: ({
2505
2506
  context,
2506
2507
  event
@@ -2536,8 +2537,7 @@ const converterJson = {
2536
2537
  mimeType: "application/json",
2537
2538
  reason: "No application/x-portable-text Converter found"
2538
2539
  };
2539
- },
2540
- mimeType: "application/json"
2540
+ }
2541
2541
  };
2542
2542
  function isTypedObject(object) {
2543
2543
  return isRecord(object) && typeof object._type == "string";
@@ -2599,6 +2599,7 @@ function parseBlock({
2599
2599
  return context.schema.lists.find((list) => list.value === block.listItem) || (delete parsedBlock.listItem, delete parsedBlock.level), parsedBlock;
2600
2600
  }
2601
2601
  const converterPortableText = {
2602
+ mimeType: "application/x-portable-text",
2602
2603
  serialize: ({
2603
2604
  context,
2604
2605
  event
@@ -2648,9 +2649,9 @@ const converterPortableText = {
2648
2649
  data: parsedBlocks,
2649
2650
  mimeType: "application/x-portable-text"
2650
2651
  };
2651
- },
2652
- mimeType: "application/x-portable-text"
2652
+ }
2653
2653
  }, converterTextHtml = {
2654
+ mimeType: "text/html",
2654
2655
  serialize: ({
2655
2656
  context,
2656
2657
  event
@@ -2695,8 +2696,7 @@ const converterPortableText = {
2695
2696
  unstable_whitespaceOnPasteMode: context.schema.block.options.unstable_whitespaceOnPasteMode
2696
2697
  }),
2697
2698
  mimeType: "text/html"
2698
- }),
2699
- mimeType: "text/html"
2699
+ })
2700
2700
  }, converterTextPlain = {
2701
2701
  mimeType: "text/plain",
2702
2702
  serialize: ({
@@ -2991,6 +2991,8 @@ function createWithEventListeners(editorActor, subscriptions) {
2991
2991
  case "annotation.add":
2992
2992
  case "annotation.remove":
2993
2993
  case "annotation.toggle":
2994
+ case "block.set":
2995
+ case "block.unset":
2994
2996
  case "blur":
2995
2997
  case "data transfer.set":
2996
2998
  case "decorator.add":
@@ -3003,6 +3005,7 @@ function createWithEventListeners(editorActor, subscriptions) {
3003
3005
  case "deserialization.failure":
3004
3006
  case "deserialization.success":
3005
3007
  case "focus":
3008
+ case "insert.block":
3006
3009
  case "insert.block object":
3007
3010
  case "insert.inline object":
3008
3011
  case "insert.span":
@@ -4431,7 +4434,7 @@ const toggleListItemActionImplementation = ({
4431
4434
  }) => {
4432
4435
  if (!action.editor.selection)
4433
4436
  return;
4434
- const guards = selector_isActiveStyle.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4437
+ const guards = selector_isAtTheStartOfBlock.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4435
4438
  at: action.editor.selection,
4436
4439
  match: (node) => guards.isListBlock(node)
4437
4440
  })];
@@ -4445,7 +4448,7 @@ const toggleListItemActionImplementation = ({
4445
4448
  }) => {
4446
4449
  if (!action.editor.selection)
4447
4450
  return;
4448
- const guards = selector_isActiveStyle.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4451
+ const guards = selector_isAtTheStartOfBlock.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4449
4452
  at: action.editor.selection,
4450
4453
  match: (node) => guards.isTextBlock(node)
4451
4454
  })];
@@ -4495,7 +4498,7 @@ const toggleStyleActionImplementation = ({
4495
4498
  }) => {
4496
4499
  if (!action.editor.selection)
4497
4500
  return;
4498
- const defaultStyle = context.schema.styles[0].value, guards = selector_isActiveStyle.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4501
+ const defaultStyle = context.schema.styles[0].value, guards = selector_isAtTheStartOfBlock.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4499
4502
  at: action.editor.selection,
4500
4503
  match: (node) => guards.isTextBlock(node)
4501
4504
  })];
@@ -4511,7 +4514,7 @@ const toggleStyleActionImplementation = ({
4511
4514
  }) => {
4512
4515
  if (!action.editor.selection)
4513
4516
  return;
4514
- const guards = selector_isActiveStyle.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4517
+ const guards = selector_isAtTheStartOfBlock.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4515
4518
  at: action.editor.selection,
4516
4519
  match: (node) => guards.isTextBlock(node)
4517
4520
  })];
@@ -5052,10 +5055,9 @@ function insertBlock({
5052
5055
  });
5053
5056
  } else placement === "before" ? slate.Transforms.insertNodes(editor, block, {
5054
5057
  at: focusBlockPath
5055
- }) : slate.Editor.insertNode(editor, block);
5056
- focusBlock && isEqualToEmptyEditor([focusBlock], schema2) && slate.Transforms.removeNodes(editor, {
5058
+ }) : (slate.Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock], schema2) && slate.Transforms.removeNodes(editor, {
5057
5059
  at: focusBlockPath
5058
- });
5060
+ }));
5059
5061
  } else {
5060
5062
  const lastBlock = Array.from(slate.Editor.nodes(editor, {
5061
5063
  match: (n) => !slate.Editor.isEditor(n),
@@ -5067,7 +5069,47 @@ function insertBlock({
5067
5069
  });
5068
5070
  }
5069
5071
  }
5070
- const dataTransferSetActionImplementation = ({
5072
+ const blockSetBehaviorActionImplementation = ({
5073
+ action
5074
+ }) => {
5075
+ const location = toSlateRange({
5076
+ anchor: {
5077
+ path: action.at,
5078
+ offset: 0
5079
+ },
5080
+ focus: {
5081
+ path: action.at,
5082
+ offset: 0
5083
+ }
5084
+ }, action.editor);
5085
+ if (!location)
5086
+ return;
5087
+ const {
5088
+ at,
5089
+ editor,
5090
+ type,
5091
+ ...payload
5092
+ } = action;
5093
+ slate.Transforms.setNodes(action.editor, payload, {
5094
+ at: location
5095
+ });
5096
+ }, blockUnsetBehaviorActionImplementation = ({
5097
+ action
5098
+ }) => {
5099
+ const location = toSlateRange({
5100
+ anchor: {
5101
+ path: action.at,
5102
+ offset: 0
5103
+ },
5104
+ focus: {
5105
+ path: action.at,
5106
+ offset: 0
5107
+ }
5108
+ }, action.editor);
5109
+ location && slate.Transforms.unsetNodes(action.editor, action.props, {
5110
+ at: location
5111
+ });
5112
+ }, dataTransferSetActionImplementation = ({
5071
5113
  action
5072
5114
  }) => {
5073
5115
  action.dataTransfer.setData(action.mimeType, action.data);
@@ -5124,96 +5166,54 @@ const dataTransferSetActionImplementation = ({
5124
5166
  const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
5125
5167
  if (!editor.selection)
5126
5168
  return;
5127
- const [focusSpan] = Array.from(slate.Editor.nodes(editor, {
5128
- mode: "lowest",
5129
- at: editor.selection.focus,
5130
- match: (n) => editor.isTextSpan(n),
5131
- voids: !1
5132
- }))[0] ?? [void 0], focusDecorators = focusSpan?.marks?.filter((mark) => schema2.decorators.some((decorator) => decorator.value === mark)) ?? [], focusAnnotations = focusSpan?.marks?.filter((mark) => !schema2.decorators.some((decorator) => decorator.value === mark)) ?? [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
5133
- if (editor.isTextBlock(focusBlock)) {
5134
- const [start, end] = slate.Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual__default.default(start, {
5135
- path: [...focusBlockPath, focusBlock.children.length - 1],
5136
- offset: editor.isTextSpan(lastFocusBlockChild) ? lastFocusBlockChild.text.length : 0
5137
- }), atTheStartOfBlock = isEqual__default.default(end, {
5138
- path: [...focusBlockPath, 0],
5139
- offset: 0
5140
- });
5141
- if (atTheEndOfBlock && slate.Range.isCollapsed(editor.selection)) {
5142
- slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
5143
- decorators: [],
5144
- listItem: focusBlock.listItem,
5145
- level: focusBlock.level
5146
- }));
5147
- return;
5148
- }
5149
- if (atTheStartOfBlock && slate.Range.isCollapsed(editor.selection)) {
5150
- slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
5151
- decorators: focusAnnotations.length === 0 ? focusDecorators : [],
5152
- listItem: focusBlock.listItem,
5153
- level: focusBlock.level
5154
- }));
5155
- const [nextBlockPath] = slate.Path.next(focusBlockPath);
5156
- slate.Transforms.select(editor, {
5169
+ const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
5170
+ if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
5171
+ slate.Editor.withoutNormalizing(editor, () => {
5172
+ if (!editor.selection)
5173
+ return;
5174
+ slate.Transforms.splitNodes(editor, {
5175
+ at: editor.selection
5176
+ });
5177
+ const [nextNode, nextNodePath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
5178
+ depth: 1
5179
+ });
5180
+ if (slate.Transforms.setSelection(editor, {
5157
5181
  anchor: {
5158
- path: [nextBlockPath, 0],
5182
+ path: [...nextNodePath, 0],
5159
5183
  offset: 0
5160
5184
  },
5161
5185
  focus: {
5162
- path: [nextBlockPath, 0],
5186
+ path: [...nextNodePath, 0],
5163
5187
  offset: 0
5164
5188
  }
5165
- });
5166
- return;
5167
- }
5168
- const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
5169
- if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
5170
- slate.Editor.withoutNormalizing(editor, () => {
5171
- if (!editor.selection)
5172
- return;
5173
- slate.Transforms.splitNodes(editor, {
5174
- at: editor.selection
5175
- });
5176
- const [nextNode, nextNodePath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
5177
- depth: 1
5178
- });
5179
- if (slate.Transforms.setSelection(editor, {
5180
- anchor: {
5181
- path: [...nextNodePath, 0],
5182
- offset: 0
5183
- },
5184
- focus: {
5185
- path: [...nextNodePath, 0],
5186
- offset: 0
5187
- }
5188
- }), editor.isTextBlock(nextNode) && nextNode.markDefs && nextNode.markDefs.length > 0) {
5189
- const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(slate.Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextNodePath);
5190
- for (const [child, childPath] of children) {
5191
- if (!editor.isTextSpan(child))
5192
- continue;
5193
- const marks = child.marks ?? [];
5194
- for (const mark of marks)
5195
- schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
5196
- const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
5197
- isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
5198
- marks: newMarks
5199
- }, {
5200
- at: childPath
5201
- });
5202
- }
5203
- const newMarkDefs = nextNode.markDefs.map((markDef) => ({
5204
- ...markDef,
5205
- _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
5206
- }));
5207
- isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
5208
- markDefs: newMarkDefs
5189
+ }), editor.isTextBlock(nextNode) && nextNode.markDefs && nextNode.markDefs.length > 0) {
5190
+ const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(slate.Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextNodePath);
5191
+ for (const [child, childPath] of children) {
5192
+ if (!editor.isTextSpan(child))
5193
+ continue;
5194
+ const marks = child.marks ?? [];
5195
+ for (const mark of marks)
5196
+ schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
5197
+ const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
5198
+ isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
5199
+ marks: newMarks
5209
5200
  }, {
5210
- at: nextNodePath,
5211
- match: (node) => editor.isTextBlock(node)
5201
+ at: childPath
5212
5202
  });
5213
5203
  }
5214
- }), editor.onChange();
5215
- return;
5216
- }
5204
+ const newMarkDefs = nextNode.markDefs.map((markDef) => ({
5205
+ ...markDef,
5206
+ _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
5207
+ }));
5208
+ isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
5209
+ markDefs: newMarkDefs
5210
+ }, {
5211
+ at: nextNodePath,
5212
+ match: (node) => editor.isTextBlock(node)
5213
+ });
5214
+ }
5215
+ }), editor.onChange();
5216
+ return;
5217
5217
  }
5218
5218
  slate.Transforms.splitNodes(editor, {
5219
5219
  always: !0
@@ -5294,6 +5294,27 @@ const dataTransferSetActionImplementation = ({
5294
5294
  text: action.text,
5295
5295
  marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
5296
5296
  });
5297
+ }, insertBlockActionImplementation = ({
5298
+ context,
5299
+ action
5300
+ }) => {
5301
+ const parsedBlock = parseBlock({
5302
+ block: action.block,
5303
+ context
5304
+ });
5305
+ if (!parsedBlock)
5306
+ throw new Error(`Failed to parse block ${JSON.stringify(action.block)}`);
5307
+ const fragment = toSlateValue([parsedBlock], {
5308
+ schemaTypes: context.schema
5309
+ })[0];
5310
+ if (!fragment)
5311
+ throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
5312
+ insertBlock({
5313
+ block: fragment,
5314
+ placement: action.placement,
5315
+ editor: action.editor,
5316
+ schema: context.schema
5317
+ });
5297
5318
  }, textBlockSetActionImplementation = ({
5298
5319
  action
5299
5320
  }) => {
@@ -5340,6 +5361,8 @@ const dataTransferSetActionImplementation = ({
5340
5361
  "annotation.add": addAnnotationActionImplementation,
5341
5362
  "annotation.remove": removeAnnotationActionImplementation,
5342
5363
  "annotation.toggle": toggleAnnotationActionImplementation,
5364
+ "block.set": blockSetBehaviorActionImplementation,
5365
+ "block.unset": blockUnsetBehaviorActionImplementation,
5343
5366
  blur: ({
5344
5367
  action
5345
5368
  }) => {
@@ -5430,6 +5453,7 @@ const dataTransferSetActionImplementation = ({
5430
5453
  }
5431
5454
  });
5432
5455
  },
5456
+ "insert.block": insertBlockActionImplementation,
5433
5457
  "insert.blocks": insertBlocksActionImplementation,
5434
5458
  "insert.block object": insertBlockObjectActionImplementation,
5435
5459
  "insert.break": insertBreakActionImplementation,
@@ -5579,13 +5603,6 @@ function performAction({
5579
5603
  });
5580
5604
  break;
5581
5605
  }
5582
- case "select": {
5583
- behaviorActionImplementations.select({
5584
- context,
5585
- action
5586
- });
5587
- break;
5588
- }
5589
5606
  default:
5590
5607
  performDefaultAction({
5591
5608
  context,
@@ -5619,6 +5636,20 @@ function performDefaultAction({
5619
5636
  });
5620
5637
  break;
5621
5638
  }
5639
+ case "block.set": {
5640
+ behaviorActionImplementations["block.set"]({
5641
+ context,
5642
+ action
5643
+ });
5644
+ break;
5645
+ }
5646
+ case "block.unset": {
5647
+ behaviorActionImplementations["block.unset"]({
5648
+ context,
5649
+ action
5650
+ });
5651
+ break;
5652
+ }
5622
5653
  case "blur": {
5623
5654
  behaviorActionImplementations.blur({
5624
5655
  context,
@@ -5703,6 +5734,13 @@ function performDefaultAction({
5703
5734
  });
5704
5735
  break;
5705
5736
  }
5737
+ case "insert.block": {
5738
+ behaviorActionImplementations["insert.block"]({
5739
+ context,
5740
+ action
5741
+ });
5742
+ break;
5743
+ }
5706
5744
  case "insert.blocks": {
5707
5745
  behaviorActionImplementations["insert.blocks"]({
5708
5746
  context,
@@ -5864,13 +5902,11 @@ function performDefaultAction({
5864
5902
  });
5865
5903
  break;
5866
5904
  }
5867
- case "text block.unset": {
5905
+ default:
5868
5906
  behaviorActionImplementations["text block.unset"]({
5869
5907
  context,
5870
5908
  action
5871
5909
  });
5872
- break;
5873
- }
5874
5910
  }
5875
5911
  }
5876
5912
  function getActiveDecorators({
@@ -6251,6 +6287,11 @@ const editorMachine = xstate.setup({
6251
6287
  event
6252
6288
  }) => event)
6253
6289
  },
6290
+ "block.*": {
6291
+ actions: xstate.emit(({
6292
+ event
6293
+ }) => event)
6294
+ },
6254
6295
  blur: {
6255
6296
  actions: xstate.emit(({
6256
6297
  event