@portabletext/editor 1.47.14 → 1.48.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 (49) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +8 -9
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/editor-provider.cjs +171 -115
  4. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  5. package/lib/_chunks-es/behavior.core.js +8 -9
  6. package/lib/_chunks-es/behavior.core.js.map +1 -1
  7. package/lib/_chunks-es/editor-provider.js +172 -116
  8. package/lib/_chunks-es/editor-provider.js.map +1 -1
  9. package/lib/behaviors/index.cjs +11 -11
  10. package/lib/behaviors/index.cjs.map +1 -1
  11. package/lib/behaviors/index.d.cts +11 -8
  12. package/lib/behaviors/index.d.ts +11 -8
  13. package/lib/behaviors/index.js +12 -12
  14. package/lib/behaviors/index.js.map +1 -1
  15. package/lib/index.cjs +4 -4
  16. package/lib/index.cjs.map +1 -1
  17. package/lib/index.d.cts +6 -4
  18. package/lib/index.d.ts +6 -4
  19. package/lib/index.js +5 -5
  20. package/lib/index.js.map +1 -1
  21. package/lib/plugins/index.cjs +7 -11
  22. package/lib/plugins/index.cjs.map +1 -1
  23. package/lib/plugins/index.d.cts +4 -3
  24. package/lib/plugins/index.d.ts +4 -3
  25. package/lib/plugins/index.js +8 -12
  26. package/lib/plugins/index.js.map +1 -1
  27. package/lib/selectors/index.d.cts +4 -3
  28. package/lib/selectors/index.d.ts +4 -3
  29. package/lib/utils/index.d.cts +4 -3
  30. package/lib/utils/index.d.ts +4 -3
  31. package/package.json +3 -3
  32. package/src/behavior-actions/behavior.actions.ts +0 -9
  33. package/src/behaviors/behavior.core.dnd.ts +1 -1
  34. package/src/behaviors/behavior.default.ts +3 -3
  35. package/src/behaviors/behavior.emoji-picker.ts +7 -9
  36. package/src/behaviors/behavior.perform-event.ts +143 -76
  37. package/src/behaviors/behavior.types.action.ts +14 -11
  38. package/src/behaviors/index.ts +1 -1
  39. package/src/editor/components/Element.tsx +3 -5
  40. package/src/editor/editor-context.tsx +7 -0
  41. package/src/editor/editor-machine.ts +1 -0
  42. package/src/editor/editor-provider.tsx +1 -3
  43. package/src/editor/plugins/createWithUndoRedo.ts +8 -11
  44. package/src/editor/with-applying-behavior-actions.ts +9 -11
  45. package/src/internal-utils/global-scope.ts +19 -0
  46. package/src/internal-utils/globally-scoped-context.ts +39 -0
  47. package/src/plugins/plugin.decorator-shortcut.ts +3 -2
  48. package/src/plugins/plugin.one-line.tsx +3 -3
  49. package/src/behavior-actions/behavior.action.noop.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.47.14",
3
+ "version": "1.48.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -79,8 +79,8 @@
79
79
  "slate-react": "0.112.1",
80
80
  "use-effect-event": "^1.0.2",
81
81
  "xstate": "^5.19.2",
82
- "@portabletext/patches": "1.1.3",
83
- "@portabletext/block-tools": "1.1.21"
82
+ "@portabletext/block-tools": "1.1.21",
83
+ "@portabletext/patches": "1.1.3"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@portabletext/toolkit": "^2.0.17",
@@ -25,7 +25,6 @@ import {insertTextActionImplementation} from './behavior.action.insert.text'
25
25
  import {moveBackwardActionImplementation} from './behavior.action.move.backward'
26
26
  import {moveBlockActionImplementation} from './behavior.action.move.block'
27
27
  import {moveForwardActionImplementation} from './behavior.action.move.forward'
28
- import {noopActionImplementation} from './behavior.action.noop'
29
28
  import {selectActionImplementation} from './behavior.action.select'
30
29
 
31
30
  const debug = debugWithName('behaviors:action')
@@ -71,7 +70,6 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
71
70
  'move.backward': moveBackwardActionImplementation,
72
71
  'move.block': moveBlockActionImplementation,
73
72
  'move.forward': moveForwardActionImplementation,
74
- 'noop': noopActionImplementation,
75
73
  'select': selectActionImplementation,
76
74
  }
77
75
 
@@ -225,13 +223,6 @@ export function performAction({
225
223
  })
226
224
  break
227
225
  }
228
- case 'noop': {
229
- behaviorActionImplementations.noop({
230
- context,
231
- action,
232
- })
233
- break
234
- }
235
226
  default: {
236
227
  behaviorActionImplementations.select({
237
228
  context,
@@ -22,6 +22,6 @@ export const coreDndBehaviors = [
22
22
 
23
23
  return draggingOverDragOrigin
24
24
  },
25
- actions: [() => [{type: 'noop'}]],
25
+ actions: [],
26
26
  }),
27
27
  ]
@@ -111,7 +111,7 @@ export const defaultBehaviors = [
111
111
 
112
112
  return focusSpan && selectionCollapsed
113
113
  },
114
- actions: [() => [{type: 'noop'}]],
114
+ actions: [],
115
115
  }),
116
116
  defineBehavior({
117
117
  on: 'clipboard.copy',
@@ -132,7 +132,7 @@ export const defaultBehaviors = [
132
132
 
133
133
  return focusSpan && selectionCollapsed
134
134
  },
135
- actions: [() => [{type: 'noop'}]],
135
+ actions: [],
136
136
  }),
137
137
  defineBehavior({
138
138
  on: 'clipboard.cut',
@@ -214,7 +214,7 @@ export const defaultBehaviors = [
214
214
  : false
215
215
  return droppingOnDragOrigin
216
216
  },
217
- actions: [() => [{type: 'noop'}]],
217
+ actions: [],
218
218
  }),
219
219
  defineBehavior({
220
220
  on: 'drag.drop',
@@ -1,7 +1,7 @@
1
1
  import {assertEvent, assign, createActor, setup} from 'xstate'
2
2
  import {isHotkey} from '../internal-utils/is-hotkey'
3
3
  import * as selectors from '../selectors'
4
- import {effect, execute, noop} from './behavior.types.action'
4
+ import {effect, execute, forward} from './behavior.types.action'
5
5
  import {defineBehavior} from './behavior.types.behavior'
6
6
 
7
7
  const emojiCharRegEx = /^[a-zA-Z-_0-9]{1}$/
@@ -66,7 +66,7 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
66
66
  return {emojis}
67
67
  },
68
68
  actions: [
69
- (_, params) => [
69
+ ({event}, params) => [
70
70
  {
71
71
  type: 'effect',
72
72
  effect: () => {
@@ -76,6 +76,7 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
76
76
  })
77
77
  },
78
78
  },
79
+ forward(event),
79
80
  ],
80
81
  ],
81
82
  }),
@@ -242,9 +243,7 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
242
243
 
243
244
  if (params.action === 'navigate up') {
244
245
  return [
245
- // If we are navigating then we want to hijack the key event and
246
- // turn it into a noop.
247
- noop(),
246
+ // If we are navigating then we want to hijack the key event
248
247
  effect(() => {
249
248
  emojiPickerActor.send({type: 'navigate up'})
250
249
  }),
@@ -253,9 +252,7 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
253
252
 
254
253
  if (params.action === 'navigate down') {
255
254
  return [
256
- // If we are navigating then we want to hijack the key event and
257
- // turn it into a noop.
258
- noop(),
255
+ // If we are navigating then we want to hijack the key event
259
256
  effect(() => {
260
257
  emojiPickerActor.send({type: 'navigate down'})
261
258
  }),
@@ -298,7 +295,7 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
298
295
  return {emojis}
299
296
  },
300
297
  actions: [
301
- (_, params) => [
298
+ ({event}, params) => [
302
299
  {
303
300
  type: 'effect',
304
301
  effect: () => {
@@ -308,6 +305,7 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
308
305
  })
309
306
  },
310
307
  },
308
+ forward(event),
311
309
  ],
312
310
  ],
313
311
  }),
@@ -4,7 +4,7 @@ import type {EditorSchema} from '../editor/editor-schema'
4
4
  import type {EditorSnapshot} from '../editor/editor-snapshot'
5
5
  import {
6
6
  withApplyingBehaviorActions,
7
- withApplyingBehaviorActionSet,
7
+ withUndoStep,
8
8
  } from '../editor/with-applying-behavior-actions'
9
9
  import {debugWithName} from '../internal-utils/debug'
10
10
  import type {PortableTextSlateEditor} from '../types/editor'
@@ -31,6 +31,7 @@ function eventCategory(event: BehaviorEvent) {
31
31
  export function performEvent({
32
32
  mode,
33
33
  behaviors,
34
+ remainingEventBehaviors,
34
35
  event,
35
36
  editor,
36
37
  keyGenerator,
@@ -38,8 +39,9 @@ export function performEvent({
38
39
  getSnapshot,
39
40
  nativeEvent,
40
41
  }: {
41
- mode: 'raise' | 'execute'
42
+ mode: 'raise' | 'execute' | 'forward'
42
43
  behaviors: Array<Behavior>
44
+ remainingEventBehaviors: Array<Behavior>
43
45
  event: BehaviorEvent
44
46
  editor: PortableTextSlateEditor
45
47
  keyGenerator: () => string
@@ -51,10 +53,7 @@ export function performEvent({
51
53
  }
52
54
  | undefined
53
55
  }) {
54
- debug(
55
- `(${!isNativeBehaviorEvent(event) ? `${mode}:` : ''}${eventCategory(event)})`,
56
- JSON.stringify(event, null, 2),
57
- )
56
+ debug(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2))
58
57
 
59
58
  const defaultAction =
60
59
  isCustomBehaviorEvent(event) ||
@@ -66,9 +65,10 @@ export function performEvent({
66
65
  editor,
67
66
  } satisfies InternalBehaviorAction)
68
67
 
69
- const eventBehaviors = (
70
- mode === 'raise' ? [...behaviors, ...defaultBehaviors] : behaviors
71
- ).filter((behavior) => {
68
+ const eventBehaviors = [
69
+ ...remainingEventBehaviors,
70
+ ...defaultBehaviors,
71
+ ].filter((behavior) => {
72
72
  // Catches all events
73
73
  if (behavior.on === '*') {
74
74
  return true
@@ -135,9 +135,13 @@ export function performEvent({
135
135
 
136
136
  const guardSnapshot = getSnapshot()
137
137
 
138
- let behaviorOverwritten = false
138
+ let nativeEventPrevented = false
139
+ let defaultBehaviorOverwritten = false
140
+ let eventBehaviorIndex = -1
139
141
 
140
142
  for (const eventBehavior of eventBehaviors) {
143
+ eventBehaviorIndex++
144
+
141
145
  const shouldRun =
142
146
  eventBehavior.guard === undefined ||
143
147
  eventBehavior.guard({
@@ -149,6 +153,10 @@ export function performEvent({
149
153
  continue
150
154
  }
151
155
 
156
+ // This Behavior now "owns" the event and we can consider the default
157
+ // action prevented
158
+ defaultBehaviorOverwritten = true
159
+
152
160
  for (const actionSet of eventBehavior.actions) {
153
161
  const actionsSnapshot = getSnapshot()
154
162
 
@@ -164,37 +172,73 @@ export function performEvent({
164
172
  continue
165
173
  }
166
174
 
167
- behaviorOverwritten =
168
- behaviorOverwritten ||
169
- actions.some((action) => action.type !== 'effect')
170
-
171
- withApplyingBehaviorActionSet(editor, () => {
172
- for (const action of actions) {
173
- if (action.type === 'raise') {
174
- performEvent({
175
- mode,
176
- behaviors:
177
- mode === 'execute'
178
- ? isCustomBehaviorEvent(action.event)
179
- ? [...behaviors, ...defaultBehaviors]
180
- : defaultBehaviors
181
- : [...behaviors, ...defaultBehaviors],
182
- event: action.event,
183
- editor,
184
- keyGenerator,
185
- schema,
186
- getSnapshot,
187
- nativeEvent: undefined,
188
- })
175
+ if (actions.some((action) => action.type === 'execute')) {
176
+ // This Behavior now "owns" the event and we can consider the native
177
+ // event prevented
178
+ nativeEventPrevented = true
179
+
180
+ // Since at least one action is about to `execute` changes in the editor,
181
+ // we set up a new undo step.
182
+ // All actions performed recursively from now will be squashed into this
183
+ // undo step
184
+ withUndoStep(editor, () => {
185
+ for (const action of actions) {
186
+ if (action.type === 'effect') {
187
+ performAction({
188
+ context: {
189
+ keyGenerator,
190
+ schema,
191
+ },
192
+ action: {
193
+ ...action,
194
+ editor,
195
+ },
196
+ })
189
197
 
190
- continue
191
- }
198
+ continue
199
+ }
200
+
201
+ if (action.type === 'forward') {
202
+ const remainingEventBehaviors = eventBehaviors.slice(
203
+ eventBehaviorIndex + 1,
204
+ )
205
+
206
+ performEvent({
207
+ mode: 'forward',
208
+ behaviors,
209
+ remainingEventBehaviors: remainingEventBehaviors,
210
+ event: action.event,
211
+ editor,
212
+ keyGenerator,
213
+ schema,
214
+ getSnapshot,
215
+ nativeEvent,
216
+ })
217
+
218
+ continue
219
+ }
220
+
221
+ if (action.type === 'raise') {
222
+ performEvent({
223
+ mode: 'raise',
224
+ behaviors,
225
+ remainingEventBehaviors: behaviors,
226
+ event: action.event,
227
+ editor,
228
+ keyGenerator,
229
+ schema,
230
+ getSnapshot,
231
+ nativeEvent,
232
+ })
233
+
234
+ continue
235
+ }
192
236
 
193
- if (action.type === 'execute') {
194
237
  if (isAbstractBehaviorEvent(action.event)) {
195
238
  performEvent({
196
239
  mode: 'execute',
197
- behaviors: defaultBehaviors,
240
+ behaviors,
241
+ remainingEventBehaviors: behaviors,
198
242
  event: action.event,
199
243
  editor,
200
244
  keyGenerator,
@@ -234,62 +278,82 @@ export function performEvent({
234
278
 
235
279
  editor.onChange()
236
280
  }
237
-
238
- continue
239
281
  }
282
+ })
283
+
284
+ continue
285
+ }
286
+
287
+ for (const action of actions) {
288
+ if (action.type === 'effect') {
289
+ performAction({
290
+ context: {
291
+ keyGenerator,
292
+ schema,
293
+ },
294
+ action: {
295
+ ...action,
296
+ editor,
297
+ },
298
+ })
299
+
300
+ continue
301
+ }
240
302
 
241
- const internalAction = {
242
- ...action,
303
+ if (action.type === 'forward') {
304
+ const remainingEventBehaviors = eventBehaviors.slice(
305
+ eventBehaviorIndex + 1,
306
+ )
307
+
308
+ performEvent({
309
+ mode: 'forward',
310
+ behaviors,
311
+ remainingEventBehaviors: remainingEventBehaviors,
312
+ event: action.event,
243
313
  editor,
244
- }
245
- let actionFailed = false
314
+ keyGenerator,
315
+ schema,
316
+ getSnapshot,
317
+ nativeEvent,
318
+ })
246
319
 
247
- withApplyingBehaviorActions(editor, () => {
248
- try {
249
- performAction({
250
- context: {
251
- keyGenerator,
252
- schema,
253
- },
254
- action: internalAction,
255
- })
256
- } catch (error) {
257
- console.error(
258
- new Error(
259
- `Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`,
260
- ),
261
- )
262
- actionFailed = true
263
- }
320
+ continue
321
+ }
322
+
323
+ if (action.type === 'raise') {
324
+ nativeEventPrevented = true
325
+
326
+ performEvent({
327
+ mode: 'raise',
328
+ behaviors,
329
+ remainingEventBehaviors: behaviors,
330
+ event: action.event,
331
+ editor,
332
+ keyGenerator,
333
+ schema,
334
+ getSnapshot,
335
+ nativeEvent,
264
336
  })
265
337
 
266
- if (actionFailed) {
267
- break
268
- }
338
+ continue
339
+ }
269
340
 
270
- editor.onChange()
341
+ if (action.type === 'execute') {
342
+ console.error('Unexpected action type: `execute`')
271
343
  }
272
- })
344
+ }
273
345
  }
274
346
 
275
- if (behaviorOverwritten) {
276
- nativeEvent?.preventDefault()
277
- break
278
- }
347
+ break
279
348
  }
280
349
 
281
- if (!behaviorOverwritten) {
282
- if (!defaultAction) {
283
- return
284
- }
350
+ if (!defaultBehaviorOverwritten && defaultAction) {
351
+ nativeEvent?.preventDefault()
285
352
 
286
353
  withApplyingBehaviorActions(editor, () => {
287
354
  try {
288
355
  performAction({
289
- context: {
290
- keyGenerator,
291
- schema,
292
- },
356
+ context: {keyGenerator, schema},
293
357
  action: defaultAction,
294
358
  })
295
359
  } catch (error) {
@@ -300,6 +364,9 @@ export function performEvent({
300
364
  )
301
365
  }
302
366
  })
367
+
303
368
  editor.onChange()
369
+ } else if (nativeEventPrevented) {
370
+ nativeEvent?.preventDefault()
304
371
  }
305
372
  }
@@ -4,6 +4,7 @@ import type {PortableTextSlateEditor} from '../types/editor'
4
4
  import type {
5
5
  AbstractBehaviorEventType,
6
6
  CustomBehaviorEvent,
7
+ NativeBehaviorEvent,
7
8
  SyntheticBehaviorEvent,
8
9
  } from './behavior.types.event'
9
10
 
@@ -16,11 +17,12 @@ export type BehaviorAction =
16
17
  event: SyntheticBehaviorEvent
17
18
  }
18
19
  | {
19
- type: 'raise'
20
- event: SyntheticBehaviorEvent | CustomBehaviorEvent
20
+ type: 'forward'
21
+ event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent
21
22
  }
22
23
  | {
23
- type: 'noop'
24
+ type: 'raise'
25
+ event: SyntheticBehaviorEvent | CustomBehaviorEvent
24
26
  }
25
27
  | {
26
28
  type: 'effect'
@@ -36,6 +38,15 @@ export function execute(
36
38
  return {type: 'execute', event}
37
39
  }
38
40
 
41
+ /**
42
+ * @beta
43
+ */
44
+ export function forward(
45
+ event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent,
46
+ ): PickFromUnion<BehaviorAction, 'type', 'forward'> {
47
+ return {type: 'forward', event}
48
+ }
49
+
39
50
  /**
40
51
  * @beta
41
52
  */
@@ -54,13 +65,6 @@ export function effect(
54
65
  return {type: 'effect', effect}
55
66
  }
56
67
 
57
- /**
58
- * @beta
59
- */
60
- export function noop(): PickFromUnion<BehaviorAction, 'type', 'noop'> {
61
- return {type: 'noop'}
62
- }
63
-
64
68
  /**
65
69
  * @beta
66
70
  */
@@ -74,7 +78,6 @@ export type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
74
78
 
75
79
  export type InternalBehaviorAction = (
76
80
  | OmitFromUnion<SyntheticBehaviorEvent, 'type', AbstractBehaviorEventType>
77
- | {type: 'noop'}
78
81
  | {type: 'effect'; effect: () => void}
79
82
  ) & {
80
83
  editor: PortableTextSlateEditor
@@ -15,7 +15,7 @@ export {
15
15
 
16
16
  export {
17
17
  execute,
18
- noop,
18
+ forward,
19
19
  raise,
20
20
  effect,
21
21
  type BehaviorAction,
@@ -21,7 +21,7 @@ import {
21
21
  useSlateStatic,
22
22
  type RenderElementProps,
23
23
  } from 'slate-react'
24
- import {defineBehavior} from '../../behaviors'
24
+ import {defineBehavior, forward} from '../../behaviors'
25
25
  import {debugWithName} from '../../internal-utils/debug'
26
26
  import type {EventPositionBlock} from '../../internal-utils/event-position'
27
27
  import {fromSlateValue} from '../../internal-utils/values'
@@ -146,9 +146,6 @@ export const Element: FunctionComponent<ElementProps> = ({
146
146
  setDragPositionBlock(event.position.block)
147
147
  },
148
148
  },
149
- {
150
- type: 'noop',
151
- },
152
149
  ],
153
150
  ],
154
151
  })
@@ -173,13 +170,14 @@ export const Element: FunctionComponent<ElementProps> = ({
173
170
  return event.type !== 'drag.dragover'
174
171
  },
175
172
  actions: [
176
- () => [
173
+ ({event}) => [
177
174
  {
178
175
  type: 'effect',
179
176
  effect: () => {
180
177
  setDragPositionBlock(undefined)
181
178
  },
182
179
  },
180
+ forward(event),
183
181
  ],
184
182
  ],
185
183
  })
@@ -0,0 +1,7 @@
1
+ import {createGloballyScopedContext} from '../internal-utils/globally-scoped-context'
2
+ import type {Editor} from './create-editor'
3
+
4
+ export const EditorContext = createGloballyScopedContext<Editor | null>(
5
+ '@portabletext/editor/context/editor',
6
+ null,
7
+ )
@@ -336,6 +336,7 @@ export const editorMachine = setup({
336
336
  performEvent({
337
337
  mode: 'raise',
338
338
  behaviors: [...context.behaviors.values()],
339
+ remainingEventBehaviors: [...context.behaviors.values()],
339
340
  event: event.behaviorEvent,
340
341
  editor: event.editor,
341
342
  keyGenerator: context.keyGenerator,
@@ -5,10 +5,10 @@ import {Synchronizer} from './components/Synchronizer'
5
5
  import {
6
6
  createInternalEditor,
7
7
  editorConfigToMachineInput,
8
- type Editor,
9
8
  type EditorConfig,
10
9
  } from './create-editor'
11
10
  import {EditorActorContext} from './editor-actor-context'
11
+ import {EditorContext} from './editor-context'
12
12
  import {editorMachine} from './editor-machine'
13
13
  import {PortableTextEditorContext} from './hooks/usePortableTextEditor'
14
14
  import {PortableTextEditorSelectionProvider} from './hooks/usePortableTextEditorSelection'
@@ -18,8 +18,6 @@ import {
18
18
  type PortableTextEditorProps,
19
19
  } from './PortableTextEditor'
20
20
 
21
- const EditorContext = React.createContext<Editor | undefined>(undefined)
22
-
23
21
  /**
24
22
  * @public
25
23
  */
@@ -34,7 +34,7 @@ import {
34
34
  } from '../../internal-utils/withUndoRedo'
35
35
  import type {PortableTextSlateEditor} from '../../types/editor'
36
36
  import type {EditorActor} from '../editor-machine'
37
- import {getCurrentBehaviorActionSetId} from '../with-applying-behavior-actions'
37
+ import {getCurrentUndoStepId} from '../with-applying-behavior-actions'
38
38
 
39
39
  const debug = debugWithName('plugin:withUndoRedo')
40
40
  const debugVerbose = debug.enabled && false
@@ -79,7 +79,7 @@ export function createWithUndoRedo(
79
79
  editorActor.getSnapshot().context.schema.block.name,
80
80
  )
81
81
  const remotePatches = getRemotePatches(editor)
82
- let previousBehaviorActionSetId = getCurrentBehaviorActionSetId(editor)
82
+ let previousUndoStepId = getCurrentUndoStepId(editor)
83
83
 
84
84
  options.subscriptions.push(() => {
85
85
  debug('Subscribing to patches')
@@ -149,15 +149,13 @@ export function createWithUndoRedo(
149
149
  const overwrite = shouldOverwrite(op, lastOp)
150
150
  const save = isSaving(editor)
151
151
 
152
- const currentBehaviorActionSetId = getCurrentBehaviorActionSetId(editor)
152
+ const currentUndoStepId = getCurrentUndoStepId(editor)
153
153
 
154
154
  let merge =
155
- currentBehaviorActionSetId !== undefined &&
156
- previousBehaviorActionSetId === undefined
155
+ currentUndoStepId !== undefined && previousUndoStepId === undefined
157
156
  ? false
158
- : currentBehaviorActionSetId !== undefined &&
159
- previousBehaviorActionSetId !== undefined
160
- ? currentBehaviorActionSetId === previousBehaviorActionSetId
157
+ : currentUndoStepId !== undefined && previousUndoStepId !== undefined
158
+ ? currentUndoStepId === previousUndoStepId
161
159
  : true
162
160
 
163
161
  if (save) {
@@ -165,8 +163,7 @@ export function createWithUndoRedo(
165
163
  merge = false
166
164
  } else if (operations.length === 0) {
167
165
  merge =
168
- currentBehaviorActionSetId === undefined &&
169
- previousBehaviorActionSetId === undefined
166
+ currentUndoStepId === undefined && previousUndoStepId === undefined
170
167
  ? shouldMerge(op, lastOp) || overwrite
171
168
  : merge
172
169
  }
@@ -196,7 +193,7 @@ export function createWithUndoRedo(
196
193
  }
197
194
  }
198
195
 
199
- previousBehaviorActionSetId = currentBehaviorActionSetId
196
+ previousUndoStepId = currentUndoStepId
200
197
 
201
198
  apply(op)
202
199
  }