xstate 6.0.0-beta.2 → 6.0.0-beta.3

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 (65) hide show
  1. package/README.md +4 -2
  2. package/dist/{createActor-20a97166.esm.js → createActor-49ea55ba.esm.js} +17 -8
  3. package/dist/{createActor-c91c9ffe.cjs.js → createActor-73aa92ba.cjs.js} +17 -7
  4. package/dist/{createActor-0250284a.development.esm.js → createActor-a085b20b.development.esm.js} +17 -8
  5. package/dist/{createActor-c029d29f.development.cjs.js → createActor-dfb6b790.development.cjs.js} +17 -7
  6. package/dist/declarations/src/fsm.d.ts +7 -7
  7. package/dist/{effectDescriptor-47f73e7e.cjs.js → effectDescriptor-3402f63e.cjs.js} +1 -1
  8. package/dist/{effectDescriptor-e93df910.esm.js → effectDescriptor-65821048.development.esm.js} +1 -1
  9. package/dist/{effectDescriptor-5ac7dccb.development.esm.js → effectDescriptor-72c62058.esm.js} +1 -1
  10. package/dist/{effectDescriptor-3fff5c51.development.cjs.js → effectDescriptor-d0ea44ad.development.cjs.js} +1 -1
  11. package/dist/{legacySnapshot-ae6594a7.development.esm.js → legacySnapshot-11aba2d2.development.esm.js} +1 -1
  12. package/dist/{legacySnapshot-ebf0b2b8.development.cjs.js → legacySnapshot-2e2c1d3b.development.cjs.js} +1 -1
  13. package/dist/{legacySnapshot-8d595687.cjs.js → legacySnapshot-a85dfbe2.cjs.js} +1 -1
  14. package/dist/{legacySnapshot-9e06feb4.esm.js → legacySnapshot-fffe81a0.esm.js} +1 -1
  15. package/dist/xstate-actors.cjs.js +30 -5
  16. package/dist/xstate-actors.development.cjs.js +30 -5
  17. package/dist/xstate-actors.development.esm.js +31 -6
  18. package/dist/xstate-actors.esm.js +31 -6
  19. package/dist/xstate-actors.umd.min.js +1 -1
  20. package/dist/xstate-actors.umd.min.js.map +1 -1
  21. package/dist/xstate-durable.cjs.js +3 -3
  22. package/dist/xstate-durable.development.cjs.js +3 -3
  23. package/dist/xstate-durable.development.esm.js +3 -3
  24. package/dist/xstate-durable.esm.js +3 -3
  25. package/dist/xstate-durable.umd.min.js +1 -1
  26. package/dist/xstate-durable.umd.min.js.map +1 -1
  27. package/dist/xstate-fsm.cjs.js +61 -31
  28. package/dist/xstate-fsm.development.cjs.js +61 -31
  29. package/dist/xstate-fsm.development.esm.js +61 -31
  30. package/dist/xstate-fsm.esm.js +61 -31
  31. package/dist/xstate-fsm.umd.min.js +1 -1
  32. package/dist/xstate-fsm.umd.min.js.map +1 -1
  33. package/dist/xstate-graph.cjs.js +1 -1
  34. package/dist/xstate-graph.development.cjs.js +1 -1
  35. package/dist/xstate-graph.development.esm.js +2 -2
  36. package/dist/xstate-graph.esm.js +2 -2
  37. package/dist/xstate-persist.cjs.js +2 -2
  38. package/dist/xstate-persist.development.cjs.js +2 -2
  39. package/dist/xstate-persist.development.esm.js +3 -3
  40. package/dist/xstate-persist.esm.js +3 -3
  41. package/dist/xstate-persist.umd.min.js +1 -1
  42. package/dist/xstate-persist.umd.min.js.map +1 -1
  43. package/dist/xstate-validation.cjs.js +1 -1
  44. package/dist/xstate-validation.development.cjs.js +1 -1
  45. package/dist/xstate-validation.development.esm.js +1 -1
  46. package/dist/xstate-validation.esm.js +1 -1
  47. package/dist/xstate.cjs.js +26 -8
  48. package/dist/xstate.development.cjs.js +26 -8
  49. package/dist/xstate.development.esm.js +28 -10
  50. package/dist/xstate.esm.js +28 -10
  51. package/dist/xstate.umd.min.js +1 -1
  52. package/dist/xstate.umd.min.js.map +1 -1
  53. package/docs/actor-logic.md +1 -1
  54. package/docs/api-stability.json +93 -81
  55. package/docs/faq.md +1 -1
  56. package/docs/fsm.md +53 -10
  57. package/docs/index.md +2 -1
  58. package/docs/inspect-actor-systems.md +20 -3
  59. package/docs/inspection.md +5 -1
  60. package/docs/invoke.md +2 -2
  61. package/docs/migrate-inspector.md +141 -0
  62. package/docs/system-transitions.md +2 -0
  63. package/docs/transitions.md +5 -1
  64. package/docs/xstate-v5-to-v6.md +6 -4
  65. package/package.json +1 -1
package/README.md CHANGED
@@ -171,8 +171,8 @@ import { createFSM } from 'xstate/fsm';
171
171
  const machine = createFSM({
172
172
  initial: 'inactive',
173
173
  states: {
174
- inactive: { on: { toggle: 'active' } },
175
- active: { on: { toggle: 'inactive' } }
174
+ inactive: { on: { toggle: { target: 'active' } } },
175
+ active: { on: { toggle: { target: 'inactive' } } }
176
176
  }
177
177
  });
178
178
 
@@ -180,6 +180,8 @@ let state = machine.initialState;
180
180
  [state] = machine.transition(state, { type: 'toggle' });
181
181
  ```
182
182
 
183
+ States can declare eventless `always` transitions. The machine follows them
184
+ during initialization and after handled events until it reaches a stable state.
183
185
  The FSM is also actor logic, so `createActor(machine)` from `xstate` runs it.
184
186
 
185
187
  For typed context, event payloads, or state-specific context snapshots, use
@@ -905,6 +905,7 @@ function resolveRegisteredActorSource(actors, logic) {
905
905
  const systemLogicMetadata = Symbol('xstate.systemLogicMetadata');
906
906
 
907
907
  const subscriptions = /* #__PURE__ */new WeakMap();
908
+ const XSTATE_ATTACHED_FORWARD = 'xstate.attached.forward';
908
909
 
909
910
  /**
910
911
  * Internal factory for actor logic that attaches to another actor on start
@@ -967,9 +968,11 @@ id) {
967
968
  unsubscribe: teardown
968
969
  });
969
970
  },
970
- transition: (state, event, {
971
- self
972
- }) => {
971
+ transition: (state, event, scope) => {
972
+ const self = scope.self;
973
+ if (event.type === XSTATE_ATTACHED_FORWARD) {
974
+ return [state, state.status === 'active' && self._parent ? [createSendToEffect(scope, self._parent, event.event)] : []];
975
+ }
973
976
  if (event.type === XSTATE_STOP) {
974
977
  subscriptions.get(self)?.unsubscribe();
975
978
  subscriptions.delete(self);
@@ -984,7 +987,8 @@ id) {
984
987
  initialTransition,
985
988
  getInitialSnapshot: (actorScope, input) => initialTransition(input)[0],
986
989
  getPersistedSnapshot: snapshot => snapshot,
987
- restoreSnapshot: snapshot => snapshot
990
+ restoreSnapshot: snapshot => snapshot,
991
+ isInternalEventType: eventType => eventType === XSTATE_ATTACHED_FORWARD
988
992
  };
989
993
  Object.defineProperty(logic, systemLogicMetadata, {
990
994
  value: {
@@ -1002,7 +1006,10 @@ function relayMappedToParent(self, system, getEvent) {
1002
1006
  if (self.getSnapshot().status === 'stopped' || !self._parent) {
1003
1007
  return;
1004
1008
  }
1005
- system._relay(self, self._parent, getEvent());
1009
+ system._relay(self, self, {
1010
+ type: XSTATE_ATTACHED_FORWARD,
1011
+ event: getEvent()
1012
+ });
1006
1013
  }
1007
1014
 
1008
1015
  /** @public */
@@ -3868,7 +3875,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3868
3875
  }
3869
3876
  addAncestorStatesToEnter(ancestors, !transition.source.parent && reenter ? undefined : domain);
3870
3877
  }
3871
- if (reenter && domain === transition.source) {
3878
+ if (targets?.length && reenter && domain === transition.source) {
3872
3879
  // A reentering transition whose domain is its own source exits and
3873
3880
  // reenters the source, so the source must be entered explicitly —
3874
3881
  // it has no ancestor inside the domain to add it.
@@ -4417,7 +4424,9 @@ function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps
4417
4424
  if (!internalQueue.length && snapshot.machine._hasEventlessTransitions === false) {
4418
4425
  return completeMacrostep();
4419
4426
  }
4420
- let shouldSelectEventlessTransitions = true;
4427
+
4428
+ // A timer notification must not run eventless transitions before delivery.
4429
+ let shouldSelectEventlessTransitions = event.type !== XSTATE_TIMER;
4421
4430
  const maxIterations = snapshot.machine.options?.maxIterations ?? Infinity;
4422
4431
  let iterationCount = 0;
4423
4432
  // The last few state values visited, for the infinite-loop error.
@@ -7102,4 +7111,4 @@ function createActor(logic, ...[options]) {
7102
7111
  return new Actor(logic, options);
7103
7112
  }
7104
7113
 
7105
- export { resolveRegisteredActorSource as $, isMachineSnapshot as A, listenerLogic as B, subscriptionLogic as C, createListenerLogic as D, createSubscriptionLogic as E, Actor as F, matchesState as G, toObserver as H, InfiniteTransitionError as I, executeEffects as J, isBuiltInExecutableEffect as K, deliverEvent as L, runStep as M, stopActor as N, terminateActor as O, ProcessingStatus as P, createInitEvent as Q, createDeadLetterEffect as R, createCustomEffect as S, XSTATE_LOGIC_EFFECT_START as T, XSTATE_LOGIC_EFFECT_RESOLVE as U, XSTATE_LOGIC_EFFECT_REJECT as V, createEmitEffect as W, XSTATE_STOP_EFFECT as X, createSendToEffect as Y, XSTATE_INIT as Z, publishEmittedEvent as _, assertUnreservedSourceName as a, allocateChildId as a0, assertChildIdFree as a1, reserveChildId as a2, hasUnescapedDot as a3, STATE_DELIMITER as a4, mapValues as a5, createInvokeId as a6, getDelayedTransitions as a7, getCandidates as a8, evaluateCandidate as a9, initialMicrostep as aA, createStartEffect as aB, isStateId as aC, getPersistedSnapshot as aD, detachedScopes as aE, hasAmbientInspector as aF, getProperAncestors as aG, isRemoteActorRef as aH, getAllOwnEvents as aI, matchesEvent as aJ, getRootActorId as aK, RUNTIME_OPERATIONS as aL, createTimerEffect as aM, getSnapshotActorRef as aN, withExecutionOwner as aO, getTimerStart as aP, recordTimerStart as aQ, withSystemInspector as aR, adoptSystem as aS, withExecutionIdentity as aT, diagnoseActorOptions as aU, createRemoteActorRef as aV, createInvokeTimeoutEvent as aW, parseGeneratedActorId as aX, formatTransition as aa, NULL_EVENT as ab, toTransitionConfigArray as ac, matchesActorSession as ad, describeMachine as ae, formatRouteTransitions as af, resolveStateValue as ag, isInFinalState as ah, createInertActorScope as ai, setInertActorScopeSnapshot as aj, beginSpawnAllocation as ak, attachSnapshotActorRef as al, macrostep as am, isInertActorScope as an, setSnapshotActorRef as ao, cloneMachineSnapshot as ap, transitionNode as aq, XSTATE_TIMER as ar, getTransitionResult as as, hasEffect as at, createErrorPlatformEvent as au, withActorSelf as av, resolveActionsWithContext as aw, takeSpawnAllocationCounters as ax, mergeActorIdCounters as ay, createSpawnEffect as az, getStateNodes as b, isActorRefLike as c, diagnoseAuthorConfig as d, createMachineSnapshot as e, diagnoseSetupConfig as f, getAllStateNodes as g, createActor as h, isAtomicStateNode as i, encodeAddressSegment as j, getActorIdPrefix as k, finalizeTransitionResult as l, matchesEventDescriptor as m, getTimerKey as n, isSerializedActorRef as o, parseDelayToMilliseconds as p, readTimerKey as q, resolveInvokedActorLogic as r, systemLogicMetadata as s, toArray as t, XSTATE_STOP as u, createDoneActorEvent as v, createErrorActorEvent as w, xstateError as x, serializeTimerKey as y, matchesTimerKey as z };
7114
+ export { publishEmittedEvent as $, matchesTimerKey as A, isMachineSnapshot as B, listenerLogic as C, subscriptionLogic as D, createListenerLogic as E, createSubscriptionLogic as F, Actor as G, matchesState as H, InfiniteTransitionError as I, toObserver as J, executeEffects as K, isBuiltInExecutableEffect as L, deliverEvent as M, runStep as N, stopActor as O, ProcessingStatus as P, terminateActor as Q, createInitEvent as R, createDeadLetterEffect as S, createCustomEffect as T, XSTATE_LOGIC_EFFECT_START as U, XSTATE_LOGIC_EFFECT_RESOLVE as V, XSTATE_LOGIC_EFFECT_REJECT as W, XSTATE_ATTACHED_FORWARD as X, createEmitEffect as Y, createSendToEffect as Z, XSTATE_INIT as _, assertUnreservedSourceName as a, resolveRegisteredActorSource as a0, allocateChildId as a1, assertChildIdFree as a2, reserveChildId as a3, hasUnescapedDot as a4, STATE_DELIMITER as a5, mapValues as a6, createInvokeId as a7, getDelayedTransitions as a8, getCandidates as a9, createSpawnEffect as aA, initialMicrostep as aB, createStartEffect as aC, isStateId as aD, getPersistedSnapshot as aE, detachedScopes as aF, hasAmbientInspector as aG, getProperAncestors as aH, isRemoteActorRef as aI, getAllOwnEvents as aJ, matchesEvent as aK, getRootActorId as aL, RUNTIME_OPERATIONS as aM, createTimerEffect as aN, getSnapshotActorRef as aO, withExecutionOwner as aP, getTimerStart as aQ, recordTimerStart as aR, withSystemInspector as aS, adoptSystem as aT, withExecutionIdentity as aU, diagnoseActorOptions as aV, createRemoteActorRef as aW, createInvokeTimeoutEvent as aX, parseGeneratedActorId as aY, evaluateCandidate as aa, formatTransition as ab, NULL_EVENT as ac, toTransitionConfigArray as ad, matchesActorSession as ae, describeMachine as af, formatRouteTransitions as ag, resolveStateValue as ah, isInFinalState as ai, createInertActorScope as aj, setInertActorScopeSnapshot as ak, beginSpawnAllocation as al, attachSnapshotActorRef as am, macrostep as an, isInertActorScope as ao, setSnapshotActorRef as ap, cloneMachineSnapshot as aq, transitionNode as ar, XSTATE_TIMER as as, getTransitionResult as at, hasEffect as au, createErrorPlatformEvent as av, withActorSelf as aw, resolveActionsWithContext as ax, takeSpawnAllocationCounters as ay, mergeActorIdCounters as az, getStateNodes as b, isActorRefLike as c, diagnoseAuthorConfig as d, createMachineSnapshot as e, diagnoseSetupConfig as f, getAllStateNodes as g, createActor as h, isAtomicStateNode as i, encodeAddressSegment as j, getActorIdPrefix as k, finalizeTransitionResult as l, matchesEventDescriptor as m, getTimerKey as n, isSerializedActorRef as o, parseDelayToMilliseconds as p, readTimerKey as q, resolveInvokedActorLogic as r, systemLogicMetadata as s, toArray as t, XSTATE_STOP_EFFECT as u, XSTATE_STOP as v, createDoneActorEvent as w, xstateError as x, createErrorActorEvent as y, serializeTimerKey as z };
@@ -907,6 +907,7 @@ function resolveRegisteredActorSource(actors, logic) {
907
907
  const systemLogicMetadata = Symbol('xstate.systemLogicMetadata');
908
908
 
909
909
  const subscriptions = /* #__PURE__ */new WeakMap();
910
+ const XSTATE_ATTACHED_FORWARD = 'xstate.attached.forward';
910
911
 
911
912
  /**
912
913
  * Internal factory for actor logic that attaches to another actor on start
@@ -969,9 +970,11 @@ id) {
969
970
  unsubscribe: teardown
970
971
  });
971
972
  },
972
- transition: (state, event, {
973
- self
974
- }) => {
973
+ transition: (state, event, scope) => {
974
+ const self = scope.self;
975
+ if (event.type === XSTATE_ATTACHED_FORWARD) {
976
+ return [state, state.status === 'active' && self._parent ? [createSendToEffect(scope, self._parent, event.event)] : []];
977
+ }
975
978
  if (event.type === XSTATE_STOP) {
976
979
  subscriptions.get(self)?.unsubscribe();
977
980
  subscriptions.delete(self);
@@ -986,7 +989,8 @@ id) {
986
989
  initialTransition,
987
990
  getInitialSnapshot: (actorScope, input) => initialTransition(input)[0],
988
991
  getPersistedSnapshot: snapshot => snapshot,
989
- restoreSnapshot: snapshot => snapshot
992
+ restoreSnapshot: snapshot => snapshot,
993
+ isInternalEventType: eventType => eventType === XSTATE_ATTACHED_FORWARD
990
994
  };
991
995
  Object.defineProperty(logic, systemLogicMetadata, {
992
996
  value: {
@@ -1004,7 +1008,10 @@ function relayMappedToParent(self, system, getEvent) {
1004
1008
  if (self.getSnapshot().status === 'stopped' || !self._parent) {
1005
1009
  return;
1006
1010
  }
1007
- system._relay(self, self._parent, getEvent());
1011
+ system._relay(self, self, {
1012
+ type: XSTATE_ATTACHED_FORWARD,
1013
+ event: getEvent()
1014
+ });
1008
1015
  }
1009
1016
 
1010
1017
  /** @public */
@@ -3870,7 +3877,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3870
3877
  }
3871
3878
  addAncestorStatesToEnter(ancestors, !transition.source.parent && reenter ? undefined : domain);
3872
3879
  }
3873
- if (reenter && domain === transition.source) {
3880
+ if (targets?.length && reenter && domain === transition.source) {
3874
3881
  // A reentering transition whose domain is its own source exits and
3875
3882
  // reenters the source, so the source must be entered explicitly —
3876
3883
  // it has no ancestor inside the domain to add it.
@@ -4419,7 +4426,9 @@ function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps
4419
4426
  if (!internalQueue.length && snapshot.machine._hasEventlessTransitions === false) {
4420
4427
  return completeMacrostep();
4421
4428
  }
4422
- let shouldSelectEventlessTransitions = true;
4429
+
4430
+ // A timer notification must not run eventless transitions before delivery.
4431
+ let shouldSelectEventlessTransitions = event.type !== XSTATE_TIMER;
4423
4432
  const maxIterations = snapshot.machine.options?.maxIterations ?? Infinity;
4424
4433
  let iterationCount = 0;
4425
4434
  // The last few state values visited, for the infinite-loop error.
@@ -7110,6 +7119,7 @@ exports.NULL_EVENT = NULL_EVENT;
7110
7119
  exports.ProcessingStatus = ProcessingStatus;
7111
7120
  exports.RUNTIME_OPERATIONS = RUNTIME_OPERATIONS;
7112
7121
  exports.STATE_DELIMITER = STATE_DELIMITER;
7122
+ exports.XSTATE_ATTACHED_FORWARD = XSTATE_ATTACHED_FORWARD;
7113
7123
  exports.XSTATE_INIT = XSTATE_INIT;
7114
7124
  exports.XSTATE_LOGIC_EFFECT_REJECT = XSTATE_LOGIC_EFFECT_REJECT;
7115
7125
  exports.XSTATE_LOGIC_EFFECT_RESOLVE = XSTATE_LOGIC_EFFECT_RESOLVE;
@@ -953,6 +953,7 @@ function resolveRegisteredActorSource(actors, logic) {
953
953
  const systemLogicMetadata = Symbol('xstate.systemLogicMetadata');
954
954
 
955
955
  const subscriptions = /* #__PURE__ */new WeakMap();
956
+ const XSTATE_ATTACHED_FORWARD = 'xstate.attached.forward';
956
957
 
957
958
  /**
958
959
  * Internal factory for actor logic that attaches to another actor on start
@@ -1015,9 +1016,11 @@ id) {
1015
1016
  unsubscribe: teardown
1016
1017
  });
1017
1018
  },
1018
- transition: (state, event, {
1019
- self
1020
- }) => {
1019
+ transition: (state, event, scope) => {
1020
+ const self = scope.self;
1021
+ if (event.type === XSTATE_ATTACHED_FORWARD) {
1022
+ return [state, state.status === 'active' && self._parent ? [createSendToEffect(scope, self._parent, event.event)] : []];
1023
+ }
1021
1024
  if (event.type === XSTATE_STOP) {
1022
1025
  subscriptions.get(self)?.unsubscribe();
1023
1026
  subscriptions.delete(self);
@@ -1032,7 +1035,8 @@ id) {
1032
1035
  initialTransition,
1033
1036
  getInitialSnapshot: (actorScope, input) => initialTransition(input)[0],
1034
1037
  getPersistedSnapshot: snapshot => snapshot,
1035
- restoreSnapshot: snapshot => snapshot
1038
+ restoreSnapshot: snapshot => snapshot,
1039
+ isInternalEventType: eventType => eventType === XSTATE_ATTACHED_FORWARD
1036
1040
  };
1037
1041
  Object.defineProperty(logic, systemLogicMetadata, {
1038
1042
  value: {
@@ -1050,7 +1054,10 @@ function relayMappedToParent(self, system, getEvent) {
1050
1054
  if (self.getSnapshot().status === 'stopped' || !self._parent) {
1051
1055
  return;
1052
1056
  }
1053
- system._relay(self, self._parent, getEvent());
1057
+ system._relay(self, self, {
1058
+ type: XSTATE_ATTACHED_FORWARD,
1059
+ event: getEvent()
1060
+ });
1054
1061
  }
1055
1062
 
1056
1063
  /** @public */
@@ -3967,7 +3974,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3967
3974
  }
3968
3975
  addAncestorStatesToEnter(ancestors, !transition.source.parent && reenter ? undefined : domain);
3969
3976
  }
3970
- if (reenter && domain === transition.source) {
3977
+ if (targets?.length && reenter && domain === transition.source) {
3971
3978
  // A reentering transition whose domain is its own source exits and
3972
3979
  // reenters the source, so the source must be entered explicitly —
3973
3980
  // it has no ancestor inside the domain to add it.
@@ -4525,7 +4532,9 @@ function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps
4525
4532
  if (!internalQueue.length && snapshot.machine._hasEventlessTransitions === false) {
4526
4533
  return completeMacrostep();
4527
4534
  }
4528
- let shouldSelectEventlessTransitions = true;
4535
+
4536
+ // A timer notification must not run eventless transitions before delivery.
4537
+ let shouldSelectEventlessTransitions = event.type !== XSTATE_TIMER;
4529
4538
  const maxIterations = snapshot.machine.options?.maxIterations ?? Infinity;
4530
4539
  let iterationCount = 0;
4531
4540
  // The last few state values visited, for the infinite-loop error.
@@ -7375,4 +7384,4 @@ function createActor(logic, ...[options]) {
7375
7384
  return new Actor(logic, options);
7376
7385
  }
7377
7386
 
7378
- export { allocateChildId as $, listenerLogic as A, subscriptionLogic as B, createListenerLogic as C, createSubscriptionLogic as D, Actor as E, matchesState as F, toObserver as G, executeEffects as H, InfiniteTransitionError as I, isBuiltInExecutableEffect as J, deliverEvent as K, runStep as L, stopActor as M, terminateActor as N, createInitEvent as O, ProcessingStatus as P, createDeadLetterEffect as Q, createCustomEffect as R, XSTATE_LOGIC_EFFECT_START as S, XSTATE_LOGIC_EFFECT_RESOLVE as T, XSTATE_LOGIC_EFFECT_REJECT as U, createEmitEffect as V, createSendToEffect as W, XSTATE_STOP_EFFECT as X, XSTATE_INIT as Y, publishEmittedEvent as Z, resolveRegisteredActorSource as _, assertUnreservedSourceName as a, assertChildIdFree as a0, reserveChildId as a1, hasUnescapedDot as a2, STATE_DELIMITER as a3, mapValues as a4, createInvokeId as a5, getDelayedTransitions as a6, getCandidates as a7, evaluateCandidate as a8, formatTransition as a9, initialMicrostep as aA, createStartEffect as aB, isStateId as aC, getPersistedSnapshot as aD, detachedScopes as aE, toStatePath as aF, hasAmbientInspector as aG, getProperAncestors as aH, isRemoteActorRef as aI, getAllOwnEvents as aJ, matchesEvent as aK, getRootActorId as aL, RUNTIME_OPERATIONS as aM, createTimerEffect as aN, getSnapshotActorRef as aO, withExecutionOwner as aP, getTimerStart as aQ, recordTimerStart as aR, withSystemInspector as aS, adoptSystem as aT, withExecutionIdentity as aU, diagnoseActorOptions as aV, createRemoteActorRef as aW, createInvokeTimeoutEvent as aX, parseGeneratedActorId as aY, NULL_EVENT as aa, toTransitionConfigArray as ab, matchesActorSession as ac, describeMachine as ad, formatRouteTransitions as ae, resolveStateValue as af, isInFinalState as ag, createInertActorScope as ah, setInertActorScopeSnapshot as ai, beginSpawnAllocation as aj, attachSnapshotActorRef as ak, macrostep as al, isInertActorScope as am, setSnapshotActorRef as an, cloneMachineSnapshot as ao, transitionNode as ap, XSTATE_TIMER as aq, getTransitionResult as ar, hasEffect as as, createErrorPlatformEvent as at, withActorSelf as au, resolveActionsWithContext as av, freezeContext as aw, takeSpawnAllocationCounters as ax, mergeActorIdCounters as ay, createSpawnEffect as az, getStateNodes as b, isActorRefLike as c, diagnoseAuthorConfig as d, createMachineSnapshot as e, diagnoseSetupConfig as f, getAllStateNodes as g, createActor as h, isAtomicStateNode as i, encodeAddressSegment as j, getActorIdPrefix as k, finalizeTransitionResult as l, matchesEventDescriptor as m, getTimerKey as n, isSerializedActorRef as o, parseDelayToMilliseconds as p, readTimerKey as q, resolveInvokedActorLogic as r, systemLogicMetadata as s, toArray as t, XSTATE_STOP as u, createDoneActorEvent as v, createErrorActorEvent as w, serializeTimerKey as x, matchesTimerKey as y, isMachineSnapshot as z };
7387
+ export { resolveRegisteredActorSource as $, isMachineSnapshot as A, listenerLogic as B, subscriptionLogic as C, createListenerLogic as D, createSubscriptionLogic as E, Actor as F, matchesState as G, toObserver as H, InfiniteTransitionError as I, executeEffects as J, isBuiltInExecutableEffect as K, deliverEvent as L, runStep as M, stopActor as N, terminateActor as O, ProcessingStatus as P, createInitEvent as Q, createDeadLetterEffect as R, createCustomEffect as S, XSTATE_LOGIC_EFFECT_START as T, XSTATE_LOGIC_EFFECT_RESOLVE as U, XSTATE_LOGIC_EFFECT_REJECT as V, createEmitEffect as W, XSTATE_ATTACHED_FORWARD as X, createSendToEffect as Y, XSTATE_INIT as Z, publishEmittedEvent as _, assertUnreservedSourceName as a, allocateChildId as a0, assertChildIdFree as a1, reserveChildId as a2, hasUnescapedDot as a3, STATE_DELIMITER as a4, mapValues as a5, createInvokeId as a6, getDelayedTransitions as a7, getCandidates as a8, evaluateCandidate as a9, createSpawnEffect as aA, initialMicrostep as aB, createStartEffect as aC, isStateId as aD, getPersistedSnapshot as aE, detachedScopes as aF, toStatePath as aG, hasAmbientInspector as aH, getProperAncestors as aI, isRemoteActorRef as aJ, getAllOwnEvents as aK, matchesEvent as aL, getRootActorId as aM, RUNTIME_OPERATIONS as aN, createTimerEffect as aO, getSnapshotActorRef as aP, withExecutionOwner as aQ, getTimerStart as aR, recordTimerStart as aS, withSystemInspector as aT, adoptSystem as aU, withExecutionIdentity as aV, diagnoseActorOptions as aW, createRemoteActorRef as aX, createInvokeTimeoutEvent as aY, parseGeneratedActorId as aZ, formatTransition as aa, NULL_EVENT as ab, toTransitionConfigArray as ac, matchesActorSession as ad, describeMachine as ae, formatRouteTransitions as af, resolveStateValue as ag, isInFinalState as ah, createInertActorScope as ai, setInertActorScopeSnapshot as aj, beginSpawnAllocation as ak, attachSnapshotActorRef as al, macrostep as am, isInertActorScope as an, setSnapshotActorRef as ao, cloneMachineSnapshot as ap, transitionNode as aq, XSTATE_TIMER as ar, getTransitionResult as as, hasEffect as at, createErrorPlatformEvent as au, withActorSelf as av, resolveActionsWithContext as aw, freezeContext as ax, takeSpawnAllocationCounters as ay, mergeActorIdCounters as az, getStateNodes as b, isActorRefLike as c, diagnoseAuthorConfig as d, createMachineSnapshot as e, diagnoseSetupConfig as f, getAllStateNodes as g, createActor as h, isAtomicStateNode as i, encodeAddressSegment as j, getActorIdPrefix as k, finalizeTransitionResult as l, matchesEventDescriptor as m, getTimerKey as n, isSerializedActorRef as o, parseDelayToMilliseconds as p, readTimerKey as q, resolveInvokedActorLogic as r, systemLogicMetadata as s, toArray as t, XSTATE_STOP_EFFECT as u, XSTATE_STOP as v, createDoneActorEvent as w, createErrorActorEvent as x, serializeTimerKey as y, matchesTimerKey as z };
@@ -955,6 +955,7 @@ function resolveRegisteredActorSource(actors, logic) {
955
955
  const systemLogicMetadata = Symbol('xstate.systemLogicMetadata');
956
956
 
957
957
  const subscriptions = /* #__PURE__ */new WeakMap();
958
+ const XSTATE_ATTACHED_FORWARD = 'xstate.attached.forward';
958
959
 
959
960
  /**
960
961
  * Internal factory for actor logic that attaches to another actor on start
@@ -1017,9 +1018,11 @@ id) {
1017
1018
  unsubscribe: teardown
1018
1019
  });
1019
1020
  },
1020
- transition: (state, event, {
1021
- self
1022
- }) => {
1021
+ transition: (state, event, scope) => {
1022
+ const self = scope.self;
1023
+ if (event.type === XSTATE_ATTACHED_FORWARD) {
1024
+ return [state, state.status === 'active' && self._parent ? [createSendToEffect(scope, self._parent, event.event)] : []];
1025
+ }
1023
1026
  if (event.type === XSTATE_STOP) {
1024
1027
  subscriptions.get(self)?.unsubscribe();
1025
1028
  subscriptions.delete(self);
@@ -1034,7 +1037,8 @@ id) {
1034
1037
  initialTransition,
1035
1038
  getInitialSnapshot: (actorScope, input) => initialTransition(input)[0],
1036
1039
  getPersistedSnapshot: snapshot => snapshot,
1037
- restoreSnapshot: snapshot => snapshot
1040
+ restoreSnapshot: snapshot => snapshot,
1041
+ isInternalEventType: eventType => eventType === XSTATE_ATTACHED_FORWARD
1038
1042
  };
1039
1043
  Object.defineProperty(logic, systemLogicMetadata, {
1040
1044
  value: {
@@ -1052,7 +1056,10 @@ function relayMappedToParent(self, system, getEvent) {
1052
1056
  if (self.getSnapshot().status === 'stopped' || !self._parent) {
1053
1057
  return;
1054
1058
  }
1055
- system._relay(self, self._parent, getEvent());
1059
+ system._relay(self, self, {
1060
+ type: XSTATE_ATTACHED_FORWARD,
1061
+ event: getEvent()
1062
+ });
1056
1063
  }
1057
1064
 
1058
1065
  /** @public */
@@ -3969,7 +3976,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3969
3976
  }
3970
3977
  addAncestorStatesToEnter(ancestors, !transition.source.parent && reenter ? undefined : domain);
3971
3978
  }
3972
- if (reenter && domain === transition.source) {
3979
+ if (targets?.length && reenter && domain === transition.source) {
3973
3980
  // A reentering transition whose domain is its own source exits and
3974
3981
  // reenters the source, so the source must be entered explicitly —
3975
3982
  // it has no ancestor inside the domain to add it.
@@ -4527,7 +4534,9 @@ function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps
4527
4534
  if (!internalQueue.length && snapshot.machine._hasEventlessTransitions === false) {
4528
4535
  return completeMacrostep();
4529
4536
  }
4530
- let shouldSelectEventlessTransitions = true;
4537
+
4538
+ // A timer notification must not run eventless transitions before delivery.
4539
+ let shouldSelectEventlessTransitions = event.type !== XSTATE_TIMER;
4531
4540
  const maxIterations = snapshot.machine.options?.maxIterations ?? Infinity;
4532
4541
  let iterationCount = 0;
4533
4542
  // The last few state values visited, for the infinite-loop error.
@@ -7383,6 +7392,7 @@ exports.NULL_EVENT = NULL_EVENT;
7383
7392
  exports.ProcessingStatus = ProcessingStatus;
7384
7393
  exports.RUNTIME_OPERATIONS = RUNTIME_OPERATIONS;
7385
7394
  exports.STATE_DELIMITER = STATE_DELIMITER;
7395
+ exports.XSTATE_ATTACHED_FORWARD = XSTATE_ATTACHED_FORWARD;
7386
7396
  exports.XSTATE_INIT = XSTATE_INIT;
7387
7397
  exports.XSTATE_LOGIC_EFFECT_REJECT = XSTATE_LOGIC_EFFECT_REJECT;
7388
7398
  exports.XSTATE_LOGIC_EFFECT_RESOLVE = XSTATE_LOGIC_EFFECT_RESOLVE;
@@ -1,5 +1,8 @@
1
1
  import type { EventObject, InferEvents, MachineContext, SetupSchemas, SetupStateSchema } from "./base.types.js";
2
2
  import type { StandardSchemaV1 } from "./schema.types.js";
3
+ type FSMInitEvent = {
4
+ type: 'xstate.init';
5
+ };
3
6
  /** @public */
4
7
  export type FSMArgs<TContext extends MachineContext, TEvent extends EventObject> = {
5
8
  context: TContext;
@@ -22,13 +25,14 @@ type EventForType<TEvent extends EventObject, TType extends string> = [
22
25
  type: TType;
23
26
  }>;
24
27
  /** @public */
25
- export type FSMTransition<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TTransitionContext extends MachineContext = TContext> = TState | FSMTransitionConfig<TTransitionContext, TState> | FSMTransitionFunction<TContext, TEvent, TState, TTransitionContext>;
28
+ export type FSMTransition<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TTransitionContext extends MachineContext = TContext> = FSMTransitionConfig<TTransitionContext, TState> | FSMTransitionFunction<TContext, TEvent, TState, TTransitionContext>;
26
29
  type FSMOn<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TTransitionContext extends MachineContext = TContext> = {
27
30
  [TType in TEvent['type'] & string]?: FSMTransition<TContext, EventForType<TEvent, TType>, TState, TTransitionContext>;
28
31
  };
29
32
  /** @public */
30
33
  export type FSMStateConfig<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TTransitionContext extends MachineContext = TContext> = {
31
34
  on?: FSMOn<TContext, TEvent, TState, TTransitionContext>;
35
+ always?: FSMTransition<TContext, TEvent | FSMInitEvent, TState, TTransitionContext>;
32
36
  };
33
37
  type FSMContextConfig<TContext extends MachineContext> = string extends keyof TContext ? {
34
38
  context?: TContext;
@@ -134,14 +138,10 @@ type FSMSetupTransitionConfig<TSourceContext extends MachineContext, TStates ext
134
138
  } | {
135
139
  [TTarget in keyof TStates & string]: FSMSetupTargetTransitionConfig<TSourceContext, TTarget, FSMSetupStateContext<TTarget, TStates, TGlobalContext>>;
136
140
  }[keyof TStates & string];
137
- type FSMSetupStringTransition<TSourceContext extends MachineContext, TStates extends FSMSetupStates, TGlobalContext extends MachineContext> = {
138
- [TTarget in keyof TStates & string]: [TSourceContext] extends [
139
- FSMSetupStateContext<TTarget, TStates, TGlobalContext>
140
- ] ? TTarget : never;
141
- }[keyof TStates & string];
142
141
  type FSMSetupTransitionFunction<TSourceContext extends MachineContext, TEvent extends EventObject, TStates extends FSMSetupStates, TGlobalContext extends MachineContext> = (args: FSMArgs<TSourceContext, TEvent>) => FSMSetupTransitionConfig<TSourceContext, TStates, TGlobalContext> | undefined;
143
- type FSMSetupTransition<TSourceContext extends MachineContext, TEvent extends EventObject, TStates extends FSMSetupStates, TGlobalContext extends MachineContext, TMachineStates extends Record<string, unknown>> = [keyof TStates] extends [never] ? FSMTransition<TSourceContext, TEvent, keyof TMachineStates & string> : FSMSetupStringTransition<TSourceContext, TStates, TGlobalContext> | FSMSetupTransitionConfig<TSourceContext, TStates, TGlobalContext> | FSMSetupTransitionFunction<TSourceContext, TEvent, TStates, TGlobalContext>;
142
+ type FSMSetupTransition<TSourceContext extends MachineContext, TEvent extends EventObject, TStates extends FSMSetupStates, TGlobalContext extends MachineContext, TMachineStates extends Record<string, unknown>> = [keyof TStates] extends [never] ? FSMTransition<TSourceContext, TEvent, keyof TMachineStates & string> : FSMSetupTransitionConfig<TSourceContext, TStates, TGlobalContext> | FSMSetupTransitionFunction<TSourceContext, TEvent, TStates, TGlobalContext>;
144
143
  type FSMSetupStateConfig<TSourceContext extends MachineContext, TEvent extends EventObject, TStates extends FSMSetupStates, TGlobalContext extends MachineContext, TMachineStates extends Record<string, unknown>> = {
144
+ always?: FSMSetupTransition<TSourceContext, TEvent | FSMInitEvent, TStates, TGlobalContext, TMachineStates>;
145
145
  on?: {
146
146
  [TType in TEvent['type'] & string]?: FSMSetupTransition<TSourceContext, EventForType<TEvent, TType>, TStates, TGlobalContext, TMachineStates>;
147
147
  };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-c91c9ffe.cjs.js');
3
+ var createActor = require('./createActor-73aa92ba.cjs.js');
4
4
 
5
5
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
6
6
  const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
@@ -1,4 +1,4 @@
1
- import { ai as createInertActorScope, aj as setInertActorScopeSnapshot, l as finalizeTransitionResult, al as attachSnapshotActorRef, Q as createInitEvent, aF as hasAmbientInspector, ak as beginSpawnAllocation, am as macrostep, az as createSpawnEffect, aA as initialMicrostep, i as isAtomicStateNode, aG as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aH as isRemoteActorRef } from './createActor-20a97166.esm.js';
1
+ import { ai as createInertActorScope, aj as setInertActorScopeSnapshot, l as finalizeTransitionResult, al as attachSnapshotActorRef, Q as createInitEvent, aH as hasAmbientInspector, ak as beginSpawnAllocation, am as macrostep, aA as createSpawnEffect, aB as initialMicrostep, i as isAtomicStateNode, aI as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aJ as isRemoteActorRef } from './createActor-a085b20b.development.esm.js';
2
2
 
3
3
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
4
4
  const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
@@ -1,4 +1,4 @@
1
- import { ah as createInertActorScope, ai as setInertActorScopeSnapshot, l as finalizeTransitionResult, ak as attachSnapshotActorRef, O as createInitEvent, aG as hasAmbientInspector, aj as beginSpawnAllocation, al as macrostep, az as createSpawnEffect, aA as initialMicrostep, i as isAtomicStateNode, aH as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aI as isRemoteActorRef } from './createActor-0250284a.development.esm.js';
1
+ import { aj as createInertActorScope, ak as setInertActorScopeSnapshot, l as finalizeTransitionResult, am as attachSnapshotActorRef, R as createInitEvent, aG as hasAmbientInspector, al as beginSpawnAllocation, an as macrostep, aA as createSpawnEffect, aB as initialMicrostep, i as isAtomicStateNode, aH as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aI as isRemoteActorRef } from './createActor-49ea55ba.esm.js';
2
2
 
3
3
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
4
4
  const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-c029d29f.development.cjs.js');
3
+ var createActor = require('./createActor-dfb6b790.development.cjs.js');
4
4
 
5
5
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
6
6
  const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
@@ -1,4 +1,4 @@
1
- import { _ as resolveRegisteredActorSource, $ as allocateChildId, a0 as assertChildIdFree, a1 as reserveChildId, a2 as hasUnescapedDot, a3 as STATE_DELIMITER, a4 as mapValues, t as toArray, a5 as createInvokeId, a6 as getDelayedTransitions, a7 as getCandidates, a8 as evaluateCandidate, a9 as formatTransition, aa as NULL_EVENT, ab as toTransitionConfigArray, ac as matchesActorSession, ad as describeMachine, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, o as isSerializedActorRef, a as assertUnreservedSourceName, ae as formatRouteTransitions, af as resolveStateValue, e as createMachineSnapshot, ag as isInFinalState, ah as createInertActorScope, ai as setInertActorScopeSnapshot, Q as createDeadLetterEffect, aj as beginSpawnAllocation, ak as attachSnapshotActorRef, al as macrostep, am as isInertActorScope, an as setSnapshotActorRef, ao as cloneMachineSnapshot, ap as transitionNode, aq as XSTATE_TIMER, m as matchesEventDescriptor, ar as getTransitionResult, as as hasEffect, at as createErrorPlatformEvent, au as withActorSelf, av as resolveActionsWithContext, aw as freezeContext, ax as takeSpawnAllocationCounters, ay as mergeActorIdCounters, O as createInitEvent, az as createSpawnEffect, aA as initialMicrostep, aB as createStartEffect, aC as isStateId, aD as getPersistedSnapshot, aE as detachedScopes, aF as toStatePath, h as createActor } from './createActor-0250284a.development.esm.js';
1
+ import { $ as resolveRegisteredActorSource, a0 as allocateChildId, a1 as assertChildIdFree, a2 as reserveChildId, a3 as hasUnescapedDot, a4 as STATE_DELIMITER, a5 as mapValues, t as toArray, a6 as createInvokeId, a7 as getDelayedTransitions, a8 as getCandidates, a9 as evaluateCandidate, aa as formatTransition, ab as NULL_EVENT, ac as toTransitionConfigArray, ad as matchesActorSession, ae as describeMachine, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, o as isSerializedActorRef, a as assertUnreservedSourceName, af as formatRouteTransitions, ag as resolveStateValue, e as createMachineSnapshot, ah as isInFinalState, ai as createInertActorScope, aj as setInertActorScopeSnapshot, R as createDeadLetterEffect, ak as beginSpawnAllocation, al as attachSnapshotActorRef, am as macrostep, an as isInertActorScope, ao as setSnapshotActorRef, ap as cloneMachineSnapshot, aq as transitionNode, ar as XSTATE_TIMER, m as matchesEventDescriptor, as as getTransitionResult, at as hasEffect, au as createErrorPlatformEvent, av as withActorSelf, aw as resolveActionsWithContext, ax as freezeContext, ay as takeSpawnAllocationCounters, az as mergeActorIdCounters, Q as createInitEvent, aA as createSpawnEffect, aB as initialMicrostep, aC as createStartEffect, aD as isStateId, aE as getPersistedSnapshot, aF as detachedScopes, aG as toStatePath, h as createActor } from './createActor-a085b20b.development.esm.js';
2
2
  import { a as assertValid } from './validation-e69470ad.development.esm.js';
3
3
 
4
4
  var isDevelopment = true;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-c029d29f.development.cjs.js');
3
+ var createActor = require('./createActor-dfb6b790.development.cjs.js');
4
4
  var validation = require('./validation-f2714a35.development.cjs.js');
5
5
 
6
6
  var isDevelopment = true;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-c91c9ffe.cjs.js');
3
+ var createActor = require('./createActor-73aa92ba.cjs.js');
4
4
  var validation = require('./validation-4561b43c.cjs.js');
5
5
 
6
6
  var isDevelopment = false;
@@ -1,4 +1,4 @@
1
- import { $ as resolveRegisteredActorSource, a0 as allocateChildId, a1 as assertChildIdFree, a2 as reserveChildId, a3 as hasUnescapedDot, x as xstateError, a4 as STATE_DELIMITER, a5 as mapValues, t as toArray, a6 as createInvokeId, a7 as getDelayedTransitions, a8 as getCandidates, a9 as evaluateCandidate, aa as formatTransition, ab as NULL_EVENT, ac as toTransitionConfigArray, ad as matchesActorSession, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, ae as describeMachine, o as isSerializedActorRef, af as formatRouteTransitions, ag as resolveStateValue, e as createMachineSnapshot, ah as isInFinalState, ai as createInertActorScope, aj as setInertActorScopeSnapshot, R as createDeadLetterEffect, ak as beginSpawnAllocation, al as attachSnapshotActorRef, am as macrostep, an as isInertActorScope, ao as setSnapshotActorRef, ap as cloneMachineSnapshot, aq as transitionNode, ar as XSTATE_TIMER, m as matchesEventDescriptor, as as getTransitionResult, at as hasEffect, au as createErrorPlatformEvent, av as withActorSelf, aw as resolveActionsWithContext, ax as takeSpawnAllocationCounters, ay as mergeActorIdCounters, Q as createInitEvent, az as createSpawnEffect, aA as initialMicrostep, aB as createStartEffect, aC as isStateId, aD as getPersistedSnapshot, aE as detachedScopes, h as createActor } from './createActor-20a97166.esm.js';
1
+ import { a0 as resolveRegisteredActorSource, a1 as allocateChildId, a2 as assertChildIdFree, a3 as reserveChildId, a4 as hasUnescapedDot, x as xstateError, a5 as STATE_DELIMITER, a6 as mapValues, t as toArray, a7 as createInvokeId, a8 as getDelayedTransitions, a9 as getCandidates, aa as evaluateCandidate, ab as formatTransition, ac as NULL_EVENT, ad as toTransitionConfigArray, ae as matchesActorSession, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, af as describeMachine, o as isSerializedActorRef, ag as formatRouteTransitions, ah as resolveStateValue, e as createMachineSnapshot, ai as isInFinalState, aj as createInertActorScope, ak as setInertActorScopeSnapshot, S as createDeadLetterEffect, al as beginSpawnAllocation, am as attachSnapshotActorRef, an as macrostep, ao as isInertActorScope, ap as setSnapshotActorRef, aq as cloneMachineSnapshot, ar as transitionNode, as as XSTATE_TIMER, m as matchesEventDescriptor, at as getTransitionResult, au as hasEffect, av as createErrorPlatformEvent, aw as withActorSelf, ax as resolveActionsWithContext, ay as takeSpawnAllocationCounters, az as mergeActorIdCounters, R as createInitEvent, aA as createSpawnEffect, aB as initialMicrostep, aC as createStartEffect, aD as isStateId, aE as getPersistedSnapshot, aF as detachedScopes, h as createActor } from './createActor-49ea55ba.esm.js';
2
2
  import { a as assertValid } from './validation-05f1d517.esm.js';
3
3
 
4
4
  var isDevelopment = false;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createActor = require('./createActor-c91c9ffe.cjs.js');
5
+ var createActor = require('./createActor-73aa92ba.cjs.js');
6
6
  var validation = require('./validation-4561b43c.cjs.js');
7
7
 
8
8
  /** @public */
@@ -253,6 +253,7 @@ function createStepLogic(config) {
253
253
  }
254
254
 
255
255
  const instanceStates = /* #__PURE__ */new WeakMap();
256
+ const XSTATE_CALLBACK_SEND_BACK = 'xstate.callback.sendBack';
256
257
 
257
258
  /** @public */
258
259
 
@@ -372,8 +373,10 @@ function createCallbackLogic(callbackOrConfig) {
372
373
  const callback = typeof callbackOrConfig === 'function' ? callbackOrConfig : callbackOrConfig.run;
373
374
  const schemas = typeof callbackOrConfig === 'function' ? undefined : callbackOrConfig.schemas;
374
375
  const validator = typeof callbackOrConfig === 'function' ? undefined : callbackOrConfig.validator;
375
- return createStepLogic({
376
- validator,
376
+ const logic = createStepLogic({
377
+ validator: validator && {
378
+ check: request => request.kind === 'event' && request.event.type === XSTATE_CALLBACK_SEND_BACK ? undefined : validator.check(request)
379
+ },
377
380
  schemas,
378
381
  context: undefined,
379
382
  run: (args, enq) => {
@@ -383,6 +386,10 @@ function createCallbackLogic(callbackOrConfig) {
383
386
  self,
384
387
  system
385
388
  } = args;
389
+ if (event.type === XSTATE_CALLBACK_SEND_BACK) {
390
+ enq.sendBack(event.event);
391
+ return;
392
+ }
386
393
  const emit = args.emit;
387
394
  const callbackState = instanceStates.get(self);
388
395
  callbackState?.receivers?.forEach(receiver => receiver(event));
@@ -402,7 +409,10 @@ function createCallbackLogic(callbackOrConfig) {
402
409
  }
403
410
  const parent = self._parent;
404
411
  if (parent) {
405
- system._relay(self, parent, event);
412
+ system._relay(self, self, {
413
+ type: XSTATE_CALLBACK_SEND_BACK,
414
+ event
415
+ });
406
416
  }
407
417
  },
408
418
  receive: listener => {
@@ -419,6 +429,10 @@ function createCallbackLogic(callbackOrConfig) {
419
429
  });
420
430
  }
421
431
  });
432
+ Object.assign(logic, {
433
+ isInternalEventType: eventType => eventType === XSTATE_CALLBACK_SEND_BACK
434
+ });
435
+ return logic;
422
436
  }
423
437
 
424
438
  const XSTATE_OBSERVABLE_NEXT = 'xstate.observable.next';
@@ -667,6 +681,11 @@ function createEventObservableLogic(lazyObservableOrConfig) {
667
681
  return [state, []];
668
682
  }
669
683
  switch (event.type) {
684
+ case XSTATE_OBSERVABLE_NEXT:
685
+ {
686
+ const parent = actorScope.self._parent;
687
+ return [state, parent ? [createActor.createSendToEffect(actorScope, parent, event.data)] : []];
688
+ }
670
689
  case XSTATE_OBSERVABLE_ERROR:
671
690
  return createActor.finalizeTransitionResult(actorScope, state, [{
672
691
  ...state,
@@ -732,7 +751,10 @@ function createEventObservableLogic(lazyObservableOrConfig) {
732
751
  }).subscribe({
733
752
  next: value => {
734
753
  if (self._parent) {
735
- system._relay(self, self._parent, value);
754
+ system._relay(self, self, {
755
+ type: XSTATE_OBSERVABLE_NEXT,
756
+ data: value
757
+ });
736
758
  }
737
759
  },
738
760
  error: err => {
@@ -757,6 +779,9 @@ function createEventObservableLogic(lazyObservableOrConfig) {
757
779
  _subscription: undefined
758
780
  })
759
781
  };
782
+ Object.assign(logic, {
783
+ isInternalEventType: eventType => eventType === XSTATE_OBSERVABLE_NEXT || eventType === XSTATE_OBSERVABLE_ERROR || eventType === XSTATE_OBSERVABLE_COMPLETE
784
+ });
760
785
  return logic;
761
786
  }
762
787