@portabletext/editor 1.35.3 → 1.36.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 (34) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  2. package/lib/_chunks-cjs/editor-provider.cjs +211 -74
  3. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  4. package/lib/_chunks-es/behavior.core.js.map +1 -1
  5. package/lib/_chunks-es/editor-provider.js +212 -75
  6. package/lib/_chunks-es/editor-provider.js.map +1 -1
  7. package/lib/behaviors/index.d.cts +150 -354
  8. package/lib/behaviors/index.d.ts +150 -354
  9. package/lib/index.d.cts +145 -77
  10. package/lib/index.d.ts +145 -77
  11. package/lib/plugins/index.cjs +19 -19
  12. package/lib/plugins/index.cjs.map +1 -1
  13. package/lib/plugins/index.d.cts +134 -77
  14. package/lib/plugins/index.d.ts +134 -77
  15. package/lib/plugins/index.js +21 -21
  16. package/lib/plugins/index.js.map +1 -1
  17. package/lib/selectors/index.d.cts +123 -77
  18. package/lib/selectors/index.d.ts +123 -77
  19. package/lib/utils/index.d.cts +123 -77
  20. package/lib/utils/index.d.ts +123 -77
  21. package/package.json +6 -6
  22. package/src/behavior-actions/behavior.actions.ts +2 -2
  23. package/src/behaviors/behavior.types.ts +10 -7
  24. package/src/editor/PortableTextEditor.tsx +22 -0
  25. package/src/editor/__tests__/self-solving.test.tsx +33 -1
  26. package/src/editor/components/Synchronizer.tsx +17 -3
  27. package/src/editor/editor-machine.ts +31 -15
  28. package/src/editor/mutation-machine.ts +160 -46
  29. package/src/editor/plugins/create-with-event-listeners.ts +1 -0
  30. package/src/editor/plugins/createWithPatches.ts +10 -3
  31. package/src/editor/with-applying-behavior-actions.ts +8 -6
  32. package/src/plugins/index.ts +2 -1
  33. package/src/plugins/plugin.decorator-shortcut.ts +3 -0
  34. package/src/utils/util.slice-blocks.test.ts +64 -0
@@ -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$e = require("debug"), slate = require("slate"), xstate = require("xstate"), isEqual = require("lodash/isEqual.js"), 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_blockOffsetsToSelection = require("./util.block-offsets-to-selection.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"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), selector_isActiveStyle = require("./selector.is-active-style.cjs"), omit = require("lodash/omit.js"), 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$e = 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_blockOffsetsToSelection = require("./util.block-offsets-to-selection.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"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), selector_isActiveStyle = require("./selector.is-active-style.cjs"), omit = require("lodash/omit.js"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.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
  }
@@ -319,7 +319,7 @@ function compileType(rawType) {
319
319
  types: [rawType]
320
320
  }).get(rawType.name);
321
321
  }
322
- const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3, mutationMachine = xstate.setup({
322
+ const mutationMachine = xstate.setup({
323
323
  types: {
324
324
  context: {},
325
325
  events: {},
@@ -330,63 +330,152 @@ const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3,
330
330
  "emit has pending patches": xstate.emit({
331
331
  type: "has pending patches"
332
332
  }),
333
- "emit mutation": xstate.emit(({
334
- context
335
- }) => ({
336
- type: "mutation",
337
- patches: context.pendingPatches,
338
- snapshot: fromSlateValue(context.slateEditor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(context.slateEditor))
339
- })),
340
- "clear pending patches": xstate.assign({
341
- pendingPatches: []
333
+ "emit mutations": xstate.enqueueActions(({
334
+ context,
335
+ enqueue
336
+ }) => {
337
+ for (const bulk of context.pendingMutations)
338
+ enqueue.emit({
339
+ type: "mutation",
340
+ patches: bulk.patches,
341
+ snapshot: bulk.value
342
+ });
343
+ }),
344
+ "clear pending mutations": xstate.assign({
345
+ pendingMutations: []
342
346
  }),
343
347
  "defer patch": xstate.assign({
344
- pendingPatches: ({
348
+ pendingMutations: ({
345
349
  context,
346
350
  event
347
- }) => [...context.pendingPatches, event.patch]
351
+ }) => {
352
+ if (xstate.assertEvent(event, "patch"), context.pendingMutations.length === 0)
353
+ return [{
354
+ actionId: event.actionId,
355
+ value: event.value,
356
+ patches: [event.patch]
357
+ }];
358
+ const lastBulk = context.pendingMutations.at(-1);
359
+ return lastBulk && lastBulk.actionId === event.actionId ? context.pendingMutations.slice(0, -1).concat({
360
+ value: event.value,
361
+ actionId: lastBulk.actionId,
362
+ patches: [...lastBulk.patches, event.patch]
363
+ }) : context.pendingMutations.concat({
364
+ value: event.value,
365
+ actionId: event.actionId,
366
+ patches: [event.patch]
367
+ });
368
+ }
369
+ })
370
+ },
371
+ actors: {
372
+ "type listener": xstate.fromCallback(({
373
+ input,
374
+ sendBack
375
+ }) => {
376
+ const originalApply = input.slateEditor.apply;
377
+ return input.slateEditor.apply = (op) => {
378
+ op.type === "insert_text" || op.type === "remove_text" ? sendBack({
379
+ type: "typing"
380
+ }) : sendBack({
381
+ type: "not typing"
382
+ }), originalApply(op);
383
+ }, () => {
384
+ input.slateEditor.apply = originalApply;
385
+ };
348
386
  })
349
387
  },
350
388
  guards: {
389
+ "is typing": xstate.stateIn({
390
+ typing: "typing"
391
+ }),
392
+ "no pending mutations": ({
393
+ context
394
+ }) => context.pendingMutations.length === 0,
351
395
  "slate is normalizing": ({
352
396
  context
353
397
  }) => slate.Editor.isNormalizing(context.slateEditor)
398
+ },
399
+ delays: {
400
+ "mutation debounce": process.env.NODE_ENV === "test" ? 250 : 0,
401
+ "type debounce": process.env.NODE_ENV === "test" ? 0 : 250
354
402
  }
355
403
  }).createMachine({
356
404
  id: "mutation",
357
405
  context: ({
358
406
  input
359
407
  }) => ({
360
- pendingPatches: [],
408
+ pendingMutations: [],
361
409
  schema: input.schema,
362
410
  slateEditor: input.slateEditor
363
411
  }),
364
- initial: "idle",
412
+ type: "parallel",
365
413
  states: {
366
- idle: {
367
- on: {
368
- patch: {
369
- actions: ["defer patch", "emit has pending patches"],
370
- target: "has pending patches"
414
+ typing: {
415
+ initial: "idle",
416
+ invoke: {
417
+ src: "type listener",
418
+ input: ({
419
+ context
420
+ }) => ({
421
+ slateEditor: context.slateEditor
422
+ })
423
+ },
424
+ states: {
425
+ idle: {
426
+ on: {
427
+ typing: {
428
+ target: "typing"
429
+ }
430
+ }
431
+ },
432
+ typing: {
433
+ after: {
434
+ "type debounce": {
435
+ target: "idle"
436
+ }
437
+ },
438
+ on: {
439
+ "not typing": {
440
+ target: "idle"
441
+ },
442
+ typing: {
443
+ target: "typing",
444
+ reenter: !0
445
+ }
446
+ }
371
447
  }
372
448
  }
373
449
  },
374
- "has pending patches": {
375
- after: {
376
- [FLUSH_PATCHES_THROTTLED_MS]: [{
377
- guard: "slate is normalizing",
378
- target: "idle",
379
- actions: ["emit mutation", "clear pending patches"]
380
- }, {
381
- target: "has pending patches",
382
- reenter: !0
383
- }]
384
- },
385
- on: {
386
- patch: {
387
- target: "has pending patches",
388
- actions: ["defer patch"],
389
- reenter: !0
450
+ mutations: {
451
+ initial: "idle",
452
+ states: {
453
+ idle: {
454
+ on: {
455
+ patch: {
456
+ actions: ["defer patch", "emit has pending patches"],
457
+ target: "emitting mutations"
458
+ }
459
+ }
460
+ },
461
+ "emitting mutations": {
462
+ after: {
463
+ "mutation debounce": [{
464
+ guard: xstate.and([xstate.not("is typing"), "slate is normalizing"]),
465
+ target: "idle",
466
+ actions: ["emit mutations", "clear pending mutations"]
467
+ }, {
468
+ target: "emitting mutations",
469
+ reenter: !0
470
+ }]
471
+ },
472
+ on: {
473
+ patch: {
474
+ target: "emitting mutations",
475
+ actions: ["defer patch"],
476
+ reenter: !0
477
+ }
478
+ }
390
479
  }
391
480
  }
392
481
  }
@@ -1412,13 +1501,15 @@ function randomKey(length) {
1412
1501
  const table = getByteHexTable();
1413
1502
  return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
1414
1503
  }
1415
- const IS_APPLYING_BEHAVIOR_ACTIONS = /* @__PURE__ */ new WeakMap();
1504
+ const CURRENT_ACTION_ID = /* @__PURE__ */ new WeakMap();
1416
1505
  function withApplyingBehaviorActions(editor, fn) {
1417
- const prev = IS_APPLYING_BEHAVIOR_ACTIONS.get(editor);
1418
- IS_APPLYING_BEHAVIOR_ACTIONS.set(editor, !0), slate.Editor.withoutNormalizing(editor, fn), IS_APPLYING_BEHAVIOR_ACTIONS.set(editor, prev);
1506
+ CURRENT_ACTION_ID.set(editor, defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_ACTION_ID.set(editor, void 0);
1507
+ }
1508
+ function getCurrentActionId(editor) {
1509
+ return CURRENT_ACTION_ID.get(editor);
1419
1510
  }
1420
1511
  function isApplyingBehaviorActions(editor) {
1421
- return IS_APPLYING_BEHAVIOR_ACTIONS.get(editor) ?? !1;
1512
+ return getCurrentActionId(editor) !== void 0;
1422
1513
  }
1423
1514
  const CURRENT_BEHAVIOR_ACTION_INTEND_SET = /* @__PURE__ */ new WeakMap();
1424
1515
  function withApplyingBehaviorActionIntendSet(editor, fn) {
@@ -2141,7 +2232,7 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2141
2232
  }
2142
2233
  const debug$b = debugWithName("component:PortableTextEditor:Synchronizer");
2143
2234
  function Synchronizer(props) {
2144
- const $ = reactCompilerRuntime.c(40), {
2235
+ const $ = reactCompilerRuntime.c(41), {
2145
2236
  editorActor,
2146
2237
  slateEditor
2147
2238
  } = props, value = react.useSelector(props.editorActor, _temp), readOnly = react.useSelector(props.editorActor, _temp2);
@@ -2193,7 +2284,7 @@ function Synchronizer(props) {
2193
2284
  };
2194
2285
  }, t8 = [mutationActorRef, syncActorRef, editorActor], $[16] = editorActor, $[17] = mutationActorRef, $[18] = syncActorRef, $[19] = t7, $[20] = t8) : (t7 = $[19], t8 = $[20]), React.useEffect(t7, t8);
2195
2286
  let t10, t9;
2196
- $[21] !== props.editorActor || $[22] !== syncActorRef ? (t9 = () => {
2287
+ $[21] !== props.editorActor || $[22] !== slateEditor || $[23] !== syncActorRef ? (t9 = () => {
2197
2288
  const subscription_0 = syncActorRef.on("*", (event_0) => {
2198
2289
  bb15: switch (event_0.type) {
2199
2290
  case "invalid value": {
@@ -2210,6 +2301,14 @@ function Synchronizer(props) {
2210
2301
  });
2211
2302
  break bb15;
2212
2303
  }
2304
+ case "patch": {
2305
+ props.editorActor.send({
2306
+ ...event_0,
2307
+ type: "internal.patch",
2308
+ value: fromSlateValue(slateEditor.children, props.editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor))
2309
+ });
2310
+ break bb15;
2311
+ }
2213
2312
  default:
2214
2313
  props.editorActor.send(event_0);
2215
2314
  }
@@ -2217,33 +2316,36 @@ function Synchronizer(props) {
2217
2316
  return () => {
2218
2317
  subscription_0.unsubscribe();
2219
2318
  };
2220
- }, t10 = [props.editorActor, syncActorRef], $[21] = props.editorActor, $[22] = syncActorRef, $[23] = t10, $[24] = t9) : (t10 = $[23], t9 = $[24]), React.useEffect(t9, t10);
2319
+ }, t10 = [props.editorActor, slateEditor, syncActorRef], $[21] = props.editorActor, $[22] = slateEditor, $[23] = syncActorRef, $[24] = t10, $[25] = t9) : (t10 = $[24], t9 = $[25]), React.useEffect(t9, t10);
2221
2320
  let t11, t12;
2222
- $[25] !== readOnly || $[26] !== syncActorRef ? (t11 = () => {
2321
+ $[26] !== readOnly || $[27] !== syncActorRef ? (t11 = () => {
2223
2322
  syncActorRef.send({
2224
2323
  type: "update readOnly",
2225
2324
  readOnly
2226
2325
  });
2227
- }, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), React.useEffect(t11, t12);
2326
+ }, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), React.useEffect(t11, t12);
2228
2327
  let t13, t14;
2229
- $[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
2328
+ $[30] !== syncActorRef || $[31] !== value ? (t13 = () => {
2230
2329
  debug$b("Value from props changed, syncing new value"), syncActorRef.send({
2231
2330
  type: "update value",
2232
2331
  value
2233
2332
  });
2234
- }, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), React.useEffect(t13, t14);
2333
+ }, t14 = [syncActorRef, value], $[30] = syncActorRef, $[31] = value, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
2235
2334
  let t15;
2236
- $[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
2335
+ $[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
2237
2336
  debug$b("Subscribing to patch events");
2238
- const sub = editorActor.on("patch", (event_1) => {
2239
- mutationActorRef.send(event_1);
2337
+ const sub = editorActor.on("internal.patch", (event_1) => {
2338
+ mutationActorRef.send({
2339
+ ...event_1,
2340
+ type: "patch"
2341
+ });
2240
2342
  });
2241
2343
  return () => {
2242
2344
  debug$b("Unsubscribing to patch events"), sub.unsubscribe();
2243
2345
  };
2244
- }, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
2346
+ }, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
2245
2347
  let t16;
2246
- return $[36] !== editorActor || $[37] !== mutationActorRef || $[38] !== slateEditor ? (t16 = [editorActor, mutationActorRef, slateEditor], $[36] = editorActor, $[37] = mutationActorRef, $[38] = slateEditor, $[39] = t16) : t16 = $[39], React.useEffect(t15, t16), null;
2348
+ return $[37] !== editorActor || $[38] !== mutationActorRef || $[39] !== slateEditor ? (t16 = [editorActor, mutationActorRef, slateEditor], $[37] = editorActor, $[38] = mutationActorRef, $[39] = slateEditor, $[40] = t16) : t16 = $[40], React.useEffect(t15, t16), null;
2247
2349
  }
2248
2350
  function _temp2(s_0) {
2249
2351
  return s_0.matches({
@@ -4347,7 +4449,7 @@ const blockSetBehaviorActionImplementation = ({
4347
4449
  "deserialization.failure": ({
4348
4450
  action
4349
4451
  }) => {
4350
- console.error(`Deserialization of ${action.mimeType} failed with reason ${action.reason}`);
4452
+ console.warn(`Deserialization of ${action.mimeType} failed with reason ${action.reason}`);
4351
4453
  },
4352
4454
  "deserialization.success": ({
4353
4455
  context,
@@ -4480,7 +4582,7 @@ const blockSetBehaviorActionImplementation = ({
4480
4582
  "serialization.failure": ({
4481
4583
  action
4482
4584
  }) => {
4483
- console.error(`Serialization of ${action.mimeType} failed with reason ${action.reason}`);
4585
+ console.warn(`Serialization of ${action.mimeType} failed with reason ${action.reason}`);
4484
4586
  },
4485
4587
  "serialization.success": ({
4486
4588
  context,
@@ -4844,6 +4946,7 @@ function createWithEventListeners(editorActor, subscriptions) {
4844
4946
  case "loading":
4845
4947
  case "mutation":
4846
4948
  case "patch":
4949
+ case "internal.patch":
4847
4950
  case "patches":
4848
4951
  case "read only":
4849
4952
  case "ready":
@@ -5486,18 +5589,21 @@ function createWithPatches({
5486
5589
  patches$1 = [...patches$1, ...patchFunctions.moveNodePatch(editor, operation, previousChildren)];
5487
5590
  break;
5488
5591
  }
5489
- return !editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches$1 = [...patches$1, patches.unset([])], editorActor.send({
5592
+ if (!editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches$1 = [...patches$1, patches.unset([])], editorActor.send({
5490
5593
  type: "notify.unset",
5491
5594
  previousValue: fromSlateValue(previousChildren, schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
5492
- })), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0 && patches$1.forEach((patch) => {
5493
- editorActor.send({
5494
- type: "patch",
5495
- patch: {
5496
- ...patch,
5497
- origin: "local"
5498
- }
5499
- });
5500
- }), editor;
5595
+ })), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0)
5596
+ for (const patch of patches$1)
5597
+ editorActor.send({
5598
+ type: "internal.patch",
5599
+ patch: {
5600
+ ...patch,
5601
+ origin: "local"
5602
+ },
5603
+ actionId: getCurrentActionId(editor),
5604
+ value: fromSlateValue(editor.children, schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
5605
+ });
5606
+ return editor;
5501
5607
  }, editor;
5502
5608
  };
5503
5609
  }
@@ -5954,9 +6060,15 @@ const editorMachine = xstate.setup({
5954
6060
  event
5955
6061
  }) => (xstate.assertEvent(event, "update schema"), event.schema)
5956
6062
  }),
5957
- "emit patch event": xstate.emit(({
5958
- event
5959
- }) => (xstate.assertEvent(event, "patch"), event)),
6063
+ "emit patch event": xstate.enqueueActions(({
6064
+ event,
6065
+ enqueue
6066
+ }) => {
6067
+ xstate.assertEvent(event, "internal.patch"), enqueue.emit(event), enqueue.emit({
6068
+ type: "patch",
6069
+ patch: event.patch
6070
+ });
6071
+ }),
5960
6072
  "emit mutation event": xstate.emit(({
5961
6073
  event
5962
6074
  }) => (xstate.assertEvent(event, "mutation"), event)),
@@ -5970,14 +6082,17 @@ const editorMachine = xstate.setup({
5970
6082
  pendingEvents: ({
5971
6083
  context,
5972
6084
  event
5973
- }) => (xstate.assertEvent(event, ["patch", "mutation"]), [...context.pendingEvents, event])
6085
+ }) => (xstate.assertEvent(event, ["internal.patch", "mutation"]), [...context.pendingEvents, event])
5974
6086
  }),
5975
6087
  "emit pending events": xstate.enqueueActions(({
5976
6088
  context,
5977
6089
  enqueue
5978
6090
  }) => {
5979
6091
  for (const event of context.pendingEvents)
5980
- enqueue(xstate.emit(event));
6092
+ event.type === "internal.patch" ? (enqueue.emit(event), enqueue.emit({
6093
+ type: "patch",
6094
+ patch: event.patch
6095
+ })) : enqueue.emit(event);
5981
6096
  }),
5982
6097
  "emit ready": xstate.emit({
5983
6098
  type: "ready"
@@ -5995,7 +6110,7 @@ const editorMachine = xstate.setup({
5995
6110
  const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
5996
6111
  ...event.behaviorEvent,
5997
6112
  editor: event.editor
5998
- }, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...foundationalBehaviors, ...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === event.behaviorEvent.type);
6113
+ }, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...foundationalBehaviors, ...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === "*" || behavior.on === event.behaviorEvent.type);
5999
6114
  if (eventBehaviors.length === 0) {
6000
6115
  if (defaultActionCallback) {
6001
6116
  withApplyingBehaviorActions(event.editor, () => {
@@ -6393,7 +6508,7 @@ const editorMachine = xstate.setup({
6393
6508
  "setting up": {
6394
6509
  exit: ["emit ready"],
6395
6510
  on: {
6396
- patch: {
6511
+ "internal.patch": {
6397
6512
  actions: "defer event"
6398
6513
  },
6399
6514
  mutation: {
@@ -6412,7 +6527,7 @@ const editorMachine = xstate.setup({
6412
6527
  normalizing: {
6413
6528
  target: "normalizing"
6414
6529
  },
6415
- patch: {
6530
+ "internal.patch": {
6416
6531
  actions: "defer event",
6417
6532
  target: "#editor.setup.dirty"
6418
6533
  },
@@ -6427,7 +6542,7 @@ const editorMachine = xstate.setup({
6427
6542
  "done normalizing": {
6428
6543
  target: "idle"
6429
6544
  },
6430
- patch: {
6545
+ "internal.patch": {
6431
6546
  actions: "defer event"
6432
6547
  },
6433
6548
  mutation: {
@@ -6440,7 +6555,7 @@ const editorMachine = xstate.setup({
6440
6555
  dirty: {
6441
6556
  entry: ["emit pending events", "clear pending events"],
6442
6557
  on: {
6443
- patch: {
6558
+ "internal.patch": {
6444
6559
  actions: "emit patch event"
6445
6560
  },
6446
6561
  mutation: {
@@ -6960,9 +7075,31 @@ class PortableTextEditor extends React.Component {
6960
7075
  * ```
6961
7076
  */
6962
7077
  static getFragment = (editor) => editor.editable?.getFragment();
7078
+ /**
7079
+ * @deprecated
7080
+ * Use `editor.send(...)` instead
7081
+ *
7082
+ * ```
7083
+ * const editor = useEditor()
7084
+ * editor.send({
7085
+ * type: 'history.undo',
7086
+ * })
7087
+ * ```
7088
+ */
6963
7089
  static undo = (editor) => {
6964
7090
  debug("Host undoing"), editor.editable?.undo();
6965
7091
  };
7092
+ /**
7093
+ * @deprecated
7094
+ * Use `editor.send(...)` instead
7095
+ *
7096
+ * ```
7097
+ * const editor = useEditor()
7098
+ * editor.send({
7099
+ * type: 'history.redo',
7100
+ * })
7101
+ * ```
7102
+ */
6966
7103
  static redo = (editor) => {
6967
7104
  debug("Host redoing"), editor.editable?.redo();
6968
7105
  };