@portabletext/editor 1.34.0 → 1.35.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 (113) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +57 -118
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +27 -67
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/plugin.event-listener.cjs +53 -71
  6. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -7
  8. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  9. package/lib/_chunks-cjs/selector.is-active-style.cjs +22 -36
  10. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
  11. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +68 -153
  12. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
  14. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  15. package/lib/_chunks-es/behavior.core.js +57 -118
  16. package/lib/_chunks-es/behavior.core.js.map +1 -1
  17. package/lib/_chunks-es/behavior.markdown.js +27 -67
  18. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  19. package/lib/_chunks-es/plugin.event-listener.js +53 -71
  20. package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
  21. package/lib/_chunks-es/selector.get-text-before.js +5 -7
  22. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  23. package/lib/_chunks-es/selector.is-active-style.js +22 -36
  24. package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
  25. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +68 -153
  26. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  27. package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
  28. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  29. package/lib/behaviors/index.cjs +18 -48
  30. package/lib/behaviors/index.cjs.map +1 -1
  31. package/lib/behaviors/index.d.cts +28 -16
  32. package/lib/behaviors/index.d.ts +28 -16
  33. package/lib/behaviors/index.js +18 -48
  34. package/lib/behaviors/index.js.map +1 -1
  35. package/lib/index.d.cts +132 -71
  36. package/lib/index.d.ts +132 -71
  37. package/lib/plugins/index.cjs +182 -186
  38. package/lib/plugins/index.cjs.map +1 -1
  39. package/lib/plugins/index.d.cts +147 -82
  40. package/lib/plugins/index.d.ts +147 -82
  41. package/lib/plugins/index.js +182 -186
  42. package/lib/plugins/index.js.map +1 -1
  43. package/lib/selectors/index.cjs +22 -50
  44. package/lib/selectors/index.cjs.map +1 -1
  45. package/lib/selectors/index.d.cts +9 -200
  46. package/lib/selectors/index.d.ts +9 -200
  47. package/lib/selectors/index.js +22 -50
  48. package/lib/selectors/index.js.map +1 -1
  49. package/lib/utils/index.cjs.map +1 -1
  50. package/lib/utils/index.d.cts +15 -7
  51. package/lib/utils/index.d.ts +15 -7
  52. package/lib/utils/index.js.map +1 -1
  53. package/package.json +6 -6
  54. package/src/behaviors/behavior.code-editor.ts +6 -6
  55. package/src/behaviors/behavior.core.annotations.ts +5 -4
  56. package/src/behaviors/behavior.core.block-objects.ts +17 -17
  57. package/src/behaviors/behavior.core.decorators.ts +12 -8
  58. package/src/behaviors/behavior.core.insert-break.ts +27 -29
  59. package/src/behaviors/behavior.core.lists.ts +19 -19
  60. package/src/behaviors/behavior.decorator-pair.ts +200 -0
  61. package/src/behaviors/behavior.default.ts +35 -30
  62. package/src/behaviors/behavior.emoji-picker.ts +12 -12
  63. package/src/behaviors/behavior.links.ts +7 -7
  64. package/src/behaviors/behavior.markdown.ts +41 -42
  65. package/src/behaviors/behavior.types.ts +15 -18
  66. package/src/behaviors/index.ts +0 -1
  67. package/src/converters/converter.json.ts +6 -6
  68. package/src/converters/converter.portable-text.deserialize.test.ts +28 -26
  69. package/src/converters/converter.portable-text.ts +6 -6
  70. package/src/converters/converter.text-html.deserialize.test.ts +17 -15
  71. package/src/converters/converter.text-html.serialize.test.ts +57 -53
  72. package/src/converters/converter.text-html.ts +14 -10
  73. package/src/converters/converter.text-plain.test.ts +17 -15
  74. package/src/converters/converter.text-plain.ts +15 -11
  75. package/src/converters/converter.types.ts +8 -7
  76. package/src/editor/editor-machine.ts +6 -1
  77. package/src/editor/plugins/create-with-event-listeners.ts +0 -5
  78. package/src/index.ts +3 -3
  79. package/src/internal-utils/get-text-to-emphasize.ts +29 -7
  80. package/src/plugins/plugin.decorator-shortcut.ts +235 -0
  81. package/src/plugins/plugin.markdown.tsx +56 -8
  82. package/src/plugins/plugin.one-line.tsx +17 -17
  83. package/src/selectors/selector.get-active-list-item.ts +4 -4
  84. package/src/selectors/selector.get-active-style.ts +6 -6
  85. package/src/selectors/selector.get-anchor-block.ts +5 -5
  86. package/src/selectors/selector.get-anchor-child.ts +5 -5
  87. package/src/selectors/selector.get-anchor-span.ts +2 -2
  88. package/src/selectors/selector.get-anchor-text-block.ts +2 -2
  89. package/src/selectors/selector.get-block-offsets.ts +8 -7
  90. package/src/selectors/selector.get-caret-word-selection.ts +19 -16
  91. package/src/selectors/selector.get-next-inline-object.ts +4 -4
  92. package/src/selectors/selector.get-previous-inline-object.ts +4 -4
  93. package/src/selectors/selector.get-selected-slice.ts +7 -4
  94. package/src/selectors/selector.get-selected-spans.ts +9 -9
  95. package/src/selectors/selector.get-selection-end-point.ts +5 -5
  96. package/src/selectors/selector.get-selection-start-point.ts +5 -5
  97. package/src/selectors/selector.get-selection-text.ts +2 -2
  98. package/src/selectors/selector.get-selection.ts +2 -2
  99. package/src/selectors/selector.get-text-before.ts +8 -8
  100. package/src/selectors/selector.get-trimmed-selection.ts +15 -13
  101. package/src/selectors/selector.get-value.ts +4 -4
  102. package/src/selectors/selector.is-at-the-end-of-block.ts +6 -3
  103. package/src/selectors/selector.is-at-the-start-of-block.ts +3 -3
  104. package/src/selectors/selector.is-overlapping-selection.ts +8 -6
  105. package/src/selectors/selector.is-selection-collapsed.ts +6 -5
  106. package/src/selectors/selector.is-selection-expanded.ts +2 -2
  107. package/src/selectors/selectors.ts +59 -59
  108. package/src/types/block-offset.ts +9 -0
  109. package/src/utils/index.ts +0 -1
  110. package/src/utils/util.block-offset.ts +1 -1
  111. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  112. package/src/utils/util.child-selection-point-to-block-offset.ts +1 -1
  113. package/src/behaviors/behavior.markdown-emphasis.ts +0 -437
@@ -2,6 +2,7 @@ import { c } from "react-compiler-runtime";
2
2
  import React, { useEffect } from "react";
3
3
  import { useEditor } from "../_chunks-es/plugin.event-listener.js";
4
4
  import { EventListenerPlugin } from "../_chunks-es/plugin.event-listener.js";
5
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
5
6
  import { createMarkdownBehaviors } from "../_chunks-es/behavior.markdown.js";
6
7
  import { useActorRef } from "@xstate/react";
7
8
  import isEqual from "lodash/isEqual.js";
@@ -12,7 +13,6 @@ import { blockOffsetsToSelection } from "../_chunks-es/util.block-offsets-to-sel
12
13
  import { childSelectionPointToBlockOffset, isTextBlock, splitTextBlock, mergeTextBlocks } from "../utils/index.js";
13
14
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
14
15
  import { defineBehavior, raise } from "../_chunks-es/behavior.core.js";
15
- import { jsx } from "react/jsx-runtime";
16
16
  function BehaviorPlugin(props) {
17
17
  const $ = c(4), editor = useEditor();
18
18
  let t0, t1;
@@ -34,114 +34,72 @@ const EditorRefPlugin = React.forwardRef((_, ref) => {
34
34
  return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = () => portableTextEditorRef.current, t1 = [], $[0] = t0, $[1] = t1) : (t0 = $[0], t1 = $[1]), React.useImperativeHandle(ref, t0, t1), null;
35
35
  });
36
36
  EditorRefPlugin.displayName = "EditorRefPlugin";
37
- const asteriskPairRegex = "(?<!\\*)\\*(?!\\s)([^*\\n]+?)(?<!\\s)\\*(?!\\*)", underscorePairRegex = "(?<!_)_(?!\\s)([^_\\n]+?)(?<!\\s)_(?!_)", italicRegex = new RegExp(`(${asteriskPairRegex}|${underscorePairRegex})$`), doubleAsteriskPairRegex = "(?<!\\*)\\*\\*(?!\\s)([^*\\n]+?)(?<!\\s)\\*\\*(?!\\*)", doubleUnderscorePairRegex = "(?<!_)__(?!\\s)([^_\\n]+?)(?<!\\s)__(?!_)", boldRegex = new RegExp(`(${doubleAsteriskPairRegex}|${doubleUnderscorePairRegex})$`);
38
- function getTextToItalic(text) {
39
- return text.match(italicRegex)?.at(0);
37
+ function createPairRegex(char, amount) {
38
+ const prePrefix = `(?<!\\${char})`, prefix = `\\${char}`.repeat(Math.max(amount, 1)), postPrefix = "(?!\\s)", content = `([^${char}\\n]+?)`, preSuffix = "(?<!\\s)", suffix = `\\${char}`.repeat(Math.max(amount, 1)), postSuffix = `(?!\\${char})`;
39
+ return `${prePrefix}${prefix}${postPrefix}${content}${preSuffix}${suffix}${postSuffix}`;
40
40
  }
41
- function getTextToBold(text) {
42
- return text.match(boldRegex)?.at(0);
43
- }
44
- function useMarkdownEmphasisBehaviors(props) {
45
- const $ = c(10), editor = useEditor();
46
- let t0;
47
- $[0] !== editor || $[1] !== props.config ? (t0 = props.config.boldDecorator?.({
48
- schema: editor.getSnapshot().context.schema
49
- }), $[0] = editor, $[1] = props.config, $[2] = t0) : t0 = $[2];
50
- let t1;
51
- $[3] !== editor || $[4] !== props.config ? (t1 = props.config.italicDecorator?.({
52
- schema: editor.getSnapshot().context.schema
53
- }), $[3] = editor, $[4] = props.config, $[5] = t1) : t1 = $[5];
54
- let t2;
55
- $[6] !== editor || $[7] !== t0 || $[8] !== t1 ? (t2 = {
56
- input: {
57
- editor,
58
- boldDecorator: t0,
59
- italicDecorator: t1
60
- }
61
- }, $[6] = editor, $[7] = t0, $[8] = t1, $[9] = t2) : t2 = $[9], useActorRef(emphasisMachine, t2);
62
- }
63
- const emphasisListener = ({
64
- sendBack,
65
- input
66
- }) => input.editor.registerBehavior({
67
- behavior: defineBehavior({
41
+ function createDecoratorPairBehavior(config) {
42
+ config.pair.amount < 1 && console.warn("The amount of characters in the pair should be greater than 0");
43
+ const pairRegex = createPairRegex(config.pair.char, config.pair.amount), regEx = new RegExp(`(${pairRegex})$`);
44
+ return defineBehavior({
68
45
  on: "insert.text",
69
46
  guard: ({
70
- context,
47
+ snapshot,
71
48
  event
72
49
  }) => {
73
- const boldDecorator = input.boldDecorator, italicDecorator = input.italicDecorator;
74
- if (boldDecorator === void 0 && italicDecorator === void 0)
50
+ if (config.pair.amount < 1)
75
51
  return !1;
76
- const focusTextBlock = getFocusTextBlock({
77
- context
78
- }), selectionStartPoint = getSelectionStartPoint({
79
- context
80
- }), selectionStartOffset = selectionStartPoint ? spanSelectionPointToBlockOffset({
81
- value: context.value,
52
+ const decorator = config.decorator({
53
+ schema: snapshot.context.schema
54
+ });
55
+ if (decorator === void 0)
56
+ return !1;
57
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? spanSelectionPointToBlockOffset({
58
+ value: snapshot.context.value,
82
59
  selectionPoint: selectionStartPoint
83
60
  }) : void 0;
84
61
  if (!focusTextBlock || !selectionStartOffset)
85
62
  return !1;
86
- const textBefore = getBlockTextBefore({
87
- context
88
- }), textToItalic = getTextToItalic(`${textBefore}${event.text}`);
89
- if (textToItalic !== void 0 && italicDecorator !== void 0) {
90
- const prefixOffsets = {
91
- anchor: {
92
- path: focusTextBlock.path,
93
- // Example: "foo *bar*".length - "*bar*".length = 4
94
- offset: `${textBefore}${event.text}`.length - textToItalic.length
95
- },
96
- focus: {
97
- path: focusTextBlock.path,
98
- // Example: "foo *bar*".length - "*bar*".length + 1 = 5
99
- offset: `${textBefore}${event.text}`.length - textToItalic.length + 1
100
- }
101
- }, suffixOffsets = {
102
- anchor: {
103
- path: focusTextBlock.path,
104
- // Example: "foo *bar|" (8) + "*".length - 1 = 8
105
- offset: selectionStartOffset.offset + event.text.length - 1
106
- },
107
- focus: {
108
- path: focusTextBlock.path,
109
- // Example: "foo *bar|" (8) + "*".length = 9
110
- offset: selectionStartOffset.offset + event.text.length
111
- }
112
- };
113
- return {
114
- prefixOffsets,
115
- suffixOffsets,
116
- decorator: italicDecorator
117
- };
118
- }
119
- const textToBold = getTextToBold(`${textBefore}${event.text}`);
120
- if (textToBold !== void 0 && boldDecorator !== void 0) {
121
- const prefixOffsets = {
122
- anchor: {
123
- path: focusTextBlock.path,
124
- // Example: "foo **bar**".length - "**bar**".length = 4
125
- offset: `${textBefore}${event.text}`.length - textToBold.length
126
- },
127
- focus: {
128
- path: focusTextBlock.path,
129
- // Example: "foo **bar**".length - "**bar**".length + 2 = 6
130
- offset: `${textBefore}${event.text}`.length - textToBold.length + 2
131
- }
132
- }, prefixSelection = blockOffsetsToSelection({
133
- value: context.value,
63
+ const newText = `${getBlockTextBefore(snapshot)}${event.text}`, textToDecorate = newText.match(regEx)?.at(0);
64
+ if (textToDecorate === void 0)
65
+ return !1;
66
+ const prefixOffsets = {
67
+ anchor: {
68
+ path: focusTextBlock.path,
69
+ // Example: "foo **bar**".length - "**bar**".length = 4
70
+ offset: newText.length - textToDecorate.length
71
+ },
72
+ focus: {
73
+ path: focusTextBlock.path,
74
+ // Example: "foo **bar**".length - "**bar**".length + "*".length * 2 = 6
75
+ offset: newText.length - textToDecorate.length + config.pair.char.length * config.pair.amount
76
+ }
77
+ }, suffixOffsets = {
78
+ anchor: {
79
+ path: focusTextBlock.path,
80
+ // Example: "foo **bar*|" (10) + "*".length - 2 = 9
81
+ offset: selectionStartOffset.offset + event.text.length - config.pair.char.length * config.pair.amount
82
+ },
83
+ focus: {
84
+ path: focusTextBlock.path,
85
+ // Example: "foo **bar*|" (10) + "*".length = 11
86
+ offset: selectionStartOffset.offset + event.text.length
87
+ }
88
+ };
89
+ if (prefixOffsets.focus.offset - prefixOffsets.anchor.offset > 1) {
90
+ const prefixSelection = blockOffsetsToSelection({
91
+ value: snapshot.context.value,
134
92
  offsets: prefixOffsets
135
93
  }), inlineObjectBeforePrefixFocus = getPreviousInlineObject({
136
94
  context: {
137
- ...context,
95
+ ...snapshot.context,
138
96
  selection: prefixSelection ? {
139
97
  anchor: prefixSelection.focus,
140
98
  focus: prefixSelection.focus
141
99
  } : null
142
100
  }
143
101
  }), inlineObjectBeforePrefixFocusOffset = inlineObjectBeforePrefixFocus ? childSelectionPointToBlockOffset({
144
- value: context.value,
102
+ value: snapshot.context.value,
145
103
  selectionPoint: {
146
104
  path: inlineObjectBeforePrefixFocus.path,
147
105
  offset: 0
@@ -149,68 +107,95 @@ const emphasisListener = ({
149
107
  }) : void 0;
150
108
  if (inlineObjectBeforePrefixFocusOffset && inlineObjectBeforePrefixFocusOffset.offset > prefixOffsets.anchor.offset && inlineObjectBeforePrefixFocusOffset.offset < prefixOffsets.focus.offset)
151
109
  return !1;
152
- const suffixOffsets = {
153
- anchor: {
154
- path: focusTextBlock.path,
155
- // Example: "foo **bar*|" (10) + "*".length - 2 = 9
156
- offset: selectionStartOffset.offset + event.text.length - 2
157
- },
158
- focus: {
159
- path: focusTextBlock.path,
160
- // Example: "foo **bar*|" (10) + "*".length = 11
161
- offset: selectionStartOffset.offset + event.text.length
162
- }
163
- }, previousInlineObject = getPreviousInlineObject({
164
- context
165
- }), previousInlineObjectOffset = previousInlineObject ? childSelectionPointToBlockOffset({
166
- value: context.value,
110
+ }
111
+ if (suffixOffsets.focus.offset - suffixOffsets.anchor.offset > 1) {
112
+ const previousInlineObject = getPreviousInlineObject(snapshot), previousInlineObjectOffset = previousInlineObject ? childSelectionPointToBlockOffset({
113
+ value: snapshot.context.value,
167
114
  selectionPoint: {
168
115
  path: previousInlineObject.path,
169
116
  offset: 0
170
117
  }
171
118
  }) : void 0;
172
- return previousInlineObjectOffset && previousInlineObjectOffset.offset > suffixOffsets.anchor.offset && previousInlineObjectOffset.offset < suffixOffsets.focus.offset ? !1 : {
173
- prefixOffsets,
174
- suffixOffsets,
175
- decorator: boldDecorator
176
- };
119
+ if (previousInlineObjectOffset && previousInlineObjectOffset.offset > suffixOffsets.anchor.offset && previousInlineObjectOffset.offset < suffixOffsets.focus.offset)
120
+ return !1;
177
121
  }
178
- return !1;
122
+ return {
123
+ prefixOffsets,
124
+ suffixOffsets,
125
+ decorator
126
+ };
179
127
  },
180
- actions: [({
181
- event
182
- }) => [event], (_, {
183
- prefixOffsets,
184
- suffixOffsets,
185
- decorator
186
- }) => [{
187
- type: "decorator.add",
188
- decorator,
189
- offsets: {
190
- anchor: prefixOffsets.focus,
191
- focus: suffixOffsets.anchor
192
- }
193
- }, {
194
- type: "delete.text",
195
- ...suffixOffsets
196
- }, {
197
- type: "delete.text",
198
- ...prefixOffsets
199
- }, {
200
- type: "decorator.remove",
201
- decorator
202
- }, {
203
- type: "effect",
204
- effect: () => {
205
- sendBack({
206
- type: "emphasis.add",
207
- blockOffset: {
208
- ...suffixOffsets.anchor,
209
- offset: suffixOffsets.anchor.offset - (prefixOffsets.focus.offset - prefixOffsets.anchor.offset)
128
+ actions: [
129
+ // Insert the text as usual in its own undo step
130
+ ({
131
+ event
132
+ }) => [event],
133
+ (_, {
134
+ prefixOffsets,
135
+ suffixOffsets,
136
+ decorator
137
+ }) => [
138
+ // Decorate the text between the prefix and suffix
139
+ {
140
+ type: "decorator.add",
141
+ decorator,
142
+ offsets: {
143
+ anchor: prefixOffsets.focus,
144
+ focus: suffixOffsets.anchor
210
145
  }
211
- });
212
- }
213
- }]]
146
+ },
147
+ // Delete the suffix
148
+ {
149
+ type: "delete.text",
150
+ ...suffixOffsets
151
+ },
152
+ // Delete the prefix
153
+ {
154
+ type: "delete.text",
155
+ ...prefixOffsets
156
+ },
157
+ // Toggle the decorator off so the next inserted text isn't emphasized
158
+ {
159
+ type: "decorator.remove",
160
+ decorator
161
+ },
162
+ {
163
+ type: "effect",
164
+ effect: () => {
165
+ config.onDecorate({
166
+ ...suffixOffsets.anchor,
167
+ offset: suffixOffsets.anchor.offset - (prefixOffsets.focus.offset - prefixOffsets.anchor.offset)
168
+ });
169
+ }
170
+ }
171
+ ]
172
+ ]
173
+ });
174
+ }
175
+ function DecoratorShortcutPlugin(config) {
176
+ const $ = c(4), editor = useEditor();
177
+ let t0;
178
+ return $[0] !== config.decorator || $[1] !== config.pair || $[2] !== editor ? (t0 = {
179
+ input: {
180
+ editor,
181
+ decorator: config.decorator,
182
+ pair: config.pair
183
+ }
184
+ }, $[0] = config.decorator, $[1] = config.pair, $[2] = editor, $[3] = t0) : t0 = $[3], useActorRef(decoratorPairMachine, t0), null;
185
+ }
186
+ const emphasisListener = ({
187
+ sendBack,
188
+ input
189
+ }) => input.editor.registerBehavior({
190
+ behavior: createDecoratorPairBehavior({
191
+ decorator: input.decorator,
192
+ pair: input.pair,
193
+ onDecorate: (offset) => {
194
+ sendBack({
195
+ type: "emphasis.add",
196
+ blockOffset: offset
197
+ });
198
+ }
214
199
  })
215
200
  }), selectionListenerCallback = ({
216
201
  sendBack,
@@ -219,7 +204,7 @@ const emphasisListener = ({
219
204
  behavior: defineBehavior({
220
205
  on: "select",
221
206
  guard: ({
222
- context,
207
+ snapshot,
223
208
  event
224
209
  }) => {
225
210
  if (!event.selection)
@@ -227,10 +212,10 @@ const emphasisListener = ({
227
212
  blockOffsets: void 0
228
213
  };
229
214
  const anchor = spanSelectionPointToBlockOffset({
230
- value: context.value,
215
+ value: snapshot.context.value,
231
216
  selectionPoint: event.selection.anchor
232
217
  }), focus = spanSelectionPointToBlockOffset({
233
- value: context.value,
218
+ value: snapshot.context.value,
234
219
  selectionPoint: event.selection.focus
235
220
  });
236
221
  return !anchor || !focus ? {
@@ -271,7 +256,7 @@ const emphasisListener = ({
271
256
  }
272
257
  }]]
273
258
  })
274
- }), emphasisMachine = setup({
259
+ }), decoratorPairMachine = setup({
275
260
  types: {
276
261
  context: {},
277
262
  input: {},
@@ -283,13 +268,13 @@ const emphasisListener = ({
283
268
  "selection listener": fromCallback(selectionListenerCallback)
284
269
  }
285
270
  }).createMachine({
286
- id: "emphasis",
271
+ id: "decorator pair",
287
272
  context: ({
288
273
  input
289
274
  }) => ({
290
- boldDecorator: input.boldDecorator,
291
- italicDecorator: input.italicDecorator,
292
- editor: input.editor
275
+ decorator: input.decorator,
276
+ editor: input.editor,
277
+ pair: input.pair
293
278
  }),
294
279
  initial: "idle",
295
280
  states: {
@@ -299,9 +284,9 @@ const emphasisListener = ({
299
284
  input: ({
300
285
  context
301
286
  }) => ({
287
+ decorator: context.decorator,
302
288
  editor: context.editor,
303
- boldDecorator: context.boldDecorator,
304
- italicDecorator: context.italicDecorator
289
+ pair: context.pair
305
290
  })
306
291
  }],
307
292
  on: {
@@ -354,9 +339,7 @@ const emphasisListener = ({
354
339
  });
355
340
  function MarkdownPlugin(props) {
356
341
  const editor = useEditor();
357
- return useMarkdownEmphasisBehaviors({
358
- config: props.config
359
- }), useEffect(() => {
342
+ return useEffect(() => {
360
343
  const unregisterBehaviors = createMarkdownBehaviors(props.config).map((behavior) => editor.registerBehavior({
361
344
  behavior
362
345
  }));
@@ -364,7 +347,36 @@ function MarkdownPlugin(props) {
364
347
  for (const unregisterBehavior of unregisterBehaviors)
365
348
  unregisterBehavior();
366
349
  };
367
- }, [editor, props.config]), null;
350
+ }, [editor, props.config]), /* @__PURE__ */ jsxs(Fragment, { children: [
351
+ props.config.boldDecorator ? /* @__PURE__ */ jsxs(Fragment, { children: [
352
+ /* @__PURE__ */ jsx(DecoratorShortcutPlugin, { decorator: props.config.boldDecorator, pair: {
353
+ char: "*",
354
+ amount: 2
355
+ } }),
356
+ /* @__PURE__ */ jsx(DecoratorShortcutPlugin, { decorator: props.config.boldDecorator, pair: {
357
+ char: "_",
358
+ amount: 2
359
+ } })
360
+ ] }) : null,
361
+ props.config.codeDecorator ? /* @__PURE__ */ jsx(DecoratorShortcutPlugin, { decorator: props.config.codeDecorator, pair: {
362
+ char: "`",
363
+ amount: 1
364
+ } }) : null,
365
+ props.config.italicDecorator ? /* @__PURE__ */ jsxs(Fragment, { children: [
366
+ /* @__PURE__ */ jsx(DecoratorShortcutPlugin, { decorator: props.config.italicDecorator, pair: {
367
+ char: "*",
368
+ amount: 1
369
+ } }),
370
+ /* @__PURE__ */ jsx(DecoratorShortcutPlugin, { decorator: props.config.italicDecorator, pair: {
371
+ char: "_",
372
+ amount: 1
373
+ } })
374
+ ] }) : null,
375
+ props.config.strikeThroughDecorator ? /* @__PURE__ */ jsx(DecoratorShortcutPlugin, { decorator: props.config.strikeThroughDecorator, pair: {
376
+ char: "~",
377
+ amount: 2
378
+ } }) : null
379
+ ] });
368
380
  }
369
381
  const oneLineBehaviors = [
370
382
  /**
@@ -373,12 +385,8 @@ const oneLineBehaviors = [
373
385
  */
374
386
  defineBehavior({
375
387
  on: "insert.break",
376
- guard: ({
377
- context
378
- }) => context.selection && isSelectionExpanded({
379
- context
380
- }) ? {
381
- selection: context.selection
388
+ guard: (snapshot) => snapshot.context.selection && isSelectionExpanded(snapshot) ? {
389
+ selection: snapshot.context.selection
382
390
  } : !1,
383
391
  actions: [(_, {
384
392
  selection
@@ -417,17 +425,11 @@ const oneLineBehaviors = [
417
425
  defineBehavior({
418
426
  on: "insert.block",
419
427
  guard: ({
420
- context,
428
+ snapshot,
421
429
  event
422
430
  }) => {
423
- const focusTextBlock = getFocusTextBlock({
424
- context
425
- }), selectionStartPoint = getSelectionStartPoint({
426
- context
427
- }), selectionEndPoint = getSelectionEndPoint({
428
- context
429
- });
430
- if (!focusTextBlock || !isTextBlock(context, event.block) || !selectionStartPoint || !selectionEndPoint)
431
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
432
+ if (!focusTextBlock || !isTextBlock(snapshot.context, event.block) || !selectionStartPoint || !selectionEndPoint)
431
433
  return !1;
432
434
  const blockStartPoint = getBlockStartPoint(focusTextBlock), blockEndPoint = getBlockEndPoint(focusTextBlock), newFocus = getBlockEndPoint({
433
435
  node: event.block,
@@ -467,31 +469,25 @@ const oneLineBehaviors = [
467
469
  defineBehavior({
468
470
  on: "insert.block",
469
471
  guard: ({
470
- context,
472
+ snapshot,
471
473
  event
472
474
  }) => {
473
- const focusTextBlock = getFocusTextBlock({
474
- context
475
- }), selectionStartPoint = getSelectionStartPoint({
476
- context
477
- }), selectionEndPoint = getSelectionEndPoint({
478
- context
479
- });
480
- if (!focusTextBlock || !isTextBlock(context, event.block) || !selectionStartPoint || !selectionEndPoint)
475
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
476
+ if (!focusTextBlock || !isTextBlock(snapshot.context, event.block) || !selectionStartPoint || !selectionEndPoint)
481
477
  return !1;
482
478
  const blockBeforeStartPoint = splitTextBlock({
483
- context,
479
+ context: snapshot.context,
484
480
  block: focusTextBlock.node,
485
481
  point: selectionStartPoint
486
482
  })?.before, blockAfterEndPoint = splitTextBlock({
487
- context,
483
+ context: snapshot.context,
488
484
  block: focusTextBlock.node,
489
485
  point: selectionEndPoint
490
486
  })?.after;
491
487
  if (!blockBeforeStartPoint || !blockAfterEndPoint)
492
488
  return !1;
493
489
  const targetBlock = mergeTextBlocks({
494
- context,
490
+ context: snapshot.context,
495
491
  targetBlock: blockBeforeStartPoint,
496
492
  incomingBlock: event.block
497
493
  }), newFocus = getBlockEndPoint({
@@ -500,7 +496,7 @@ const oneLineBehaviors = [
500
496
  _key: targetBlock._key
501
497
  }]
502
498
  }), mergedBlock = mergeTextBlocks({
503
- context,
499
+ context: snapshot.context,
504
500
  targetBlock,
505
501
  incomingBlock: blockAfterEndPoint
506
502
  });