xstate 5.27.0 → 5.29.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 (53) hide show
  1. package/actions/dist/xstate-actions.cjs.js +3 -3
  2. package/actions/dist/xstate-actions.development.cjs.js +3 -3
  3. package/actions/dist/xstate-actions.development.esm.js +3 -3
  4. package/actions/dist/xstate-actions.esm.js +3 -3
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/{StateMachine-c3376229.development.cjs.js → StateMachine-89436b8f.development.cjs.js} +3 -2
  14. package/dist/{StateMachine-93271b59.development.esm.js → StateMachine-a5d156db.development.esm.js} +3 -2
  15. package/dist/{StateMachine-a4db5a91.esm.js → StateMachine-bf2cec8d.esm.js} +3 -2
  16. package/dist/{StateMachine-e93afc18.cjs.js → StateMachine-d3e2432b.cjs.js} +3 -2
  17. package/dist/{assign-227b928a.esm.js → assign-128c3f01.esm.js} +1 -1
  18. package/dist/{assign-d5291869.development.esm.js → assign-4254ecc7.development.esm.js} +1 -1
  19. package/dist/{assign-8ef0e332.development.cjs.js → assign-8c16ea04.development.cjs.js} +1 -1
  20. package/dist/{assign-e36553db.cjs.js → assign-f10db67b.cjs.js} +1 -1
  21. package/dist/declarations/src/actions/spawnChild.d.ts +1 -1
  22. package/dist/declarations/src/actions.d.ts +1 -1
  23. package/dist/declarations/src/createActor.d.ts +2 -1
  24. package/dist/declarations/src/index.d.ts +2 -1
  25. package/dist/declarations/src/setup.d.ts +6 -3
  26. package/dist/declarations/src/stateUtils.d.ts +5 -0
  27. package/dist/declarations/src/types.d.ts +18 -0
  28. package/dist/{log-7dbbb7c2.development.esm.js → log-0e01d593.development.esm.js} +2 -2
  29. package/dist/{log-e54c2eff.cjs.js → log-30abbb83.cjs.js} +2 -2
  30. package/dist/{log-fa76d888.esm.js → log-678e6837.esm.js} +2 -2
  31. package/dist/{log-72d5ee02.development.cjs.js → log-f3a45f9f.development.cjs.js} +2 -2
  32. package/dist/{raise-a7794093.development.esm.js → raise-964ef086.development.esm.js} +59 -1
  33. package/dist/{raise-e5d81555.esm.js → raise-b47daa89.esm.js} +59 -1
  34. package/dist/{raise-3a84be1f.cjs.js → raise-f051f097.cjs.js} +59 -0
  35. package/dist/{raise-ecea0c53.development.cjs.js → raise-f3874442.development.cjs.js} +59 -0
  36. package/dist/xstate.cjs.js +4 -4
  37. package/dist/xstate.development.cjs.js +4 -4
  38. package/dist/xstate.development.esm.js +8 -8
  39. package/dist/xstate.esm.js +8 -8
  40. package/dist/xstate.umd.min.js +1 -1
  41. package/dist/xstate.umd.min.js.map +1 -1
  42. package/graph/dist/xstate-graph.cjs.js +3 -3
  43. package/graph/dist/xstate-graph.development.cjs.js +3 -3
  44. package/graph/dist/xstate-graph.development.esm.js +3 -3
  45. package/graph/dist/xstate-graph.esm.js +3 -3
  46. package/graph/dist/xstate-graph.umd.min.js +1 -1
  47. package/graph/dist/xstate-graph.umd.min.js.map +1 -1
  48. package/guards/dist/xstate-guards.cjs.js +1 -1
  49. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  50. package/guards/dist/xstate-guards.development.esm.js +1 -1
  51. package/guards/dist/xstate-guards.esm.js +1 -1
  52. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  53. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-ecea0c53.development.cjs.js');
4
- var assign = require('./assign-8ef0e332.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-f3874442.development.cjs.js');
4
+ var assign = require('./assign-8c16ea04.development.cjs.js');
5
5
 
6
6
  const cache = new WeakMap();
7
7
  function memo(object, key, fn) {
@@ -328,6 +328,7 @@ class StateMachine {
328
328
  _machine: this
329
329
  });
330
330
  this.root._initialize();
331
+ guards_dist_xstateGuards.formatRouteTransitions(this.root);
331
332
  this.states = this.root.states; // TODO: remove!
332
333
  this.events = this.root.events;
333
334
  if (!('output' in this.root) && Object.values(this.states).some(state => state.type === 'final' && 'output' in state)) {
@@ -1,5 +1,5 @@
1
- import { S as STATE_DELIMITER, y as mapValues, t as toArray, z as formatTransitions, B as toTransitionConfigArray, C as formatTransition, N as NULL_EVENT, D as evaluateGuard, E as createInvokeId, F as getDelayedTransitions, G as formatInitialTransition, H as getCandidates, I as resolveStateValue, J as getAllStateNodes, p as getStateNodes, K as createMachineSnapshot, L as isInFinalState, d as macrostep, M as transitionNode, O as resolveActionsAndContext, e as createInitEvent, i as initialMicrostep, P as toStatePath, Q as isStateId, R as getStateNodeByPath, T as getPersistedSnapshot, U as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-a7794093.development.esm.js';
2
- import { a as assign } from './assign-d5291869.development.esm.js';
1
+ import { S as STATE_DELIMITER, y as mapValues, t as toArray, z as formatTransitions, B as toTransitionConfigArray, C as formatTransition, N as NULL_EVENT, D as evaluateGuard, E as createInvokeId, F as getDelayedTransitions, G as formatInitialTransition, H as getCandidates, I as formatRouteTransitions, J as resolveStateValue, K as getAllStateNodes, p as getStateNodes, L as createMachineSnapshot, M as isInFinalState, d as macrostep, O as transitionNode, P as resolveActionsAndContext, e as createInitEvent, i as initialMicrostep, Q as toStatePath, R as isStateId, T as getStateNodeByPath, U as getPersistedSnapshot, V as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-964ef086.development.esm.js';
2
+ import { a as assign } from './assign-4254ecc7.development.esm.js';
3
3
 
4
4
  const cache = new WeakMap();
5
5
  function memo(object, key, fn) {
@@ -326,6 +326,7 @@ class StateMachine {
326
326
  _machine: this
327
327
  });
328
328
  this.root._initialize();
329
+ formatRouteTransitions(this.root);
329
330
  this.states = this.root.states; // TODO: remove!
330
331
  this.events = this.root.events;
331
332
  if (!('output' in this.root) && Object.values(this.states).some(state => state.type === 'final' && 'output' in state)) {
@@ -1,5 +1,5 @@
1
- import { S as STATE_DELIMITER, y as mapValues, t as toArray, z as formatTransitions, B as toTransitionConfigArray, C as formatTransition, N as NULL_EVENT, D as evaluateGuard, E as createInvokeId, F as getDelayedTransitions, G as formatInitialTransition, H as getCandidates, I as resolveStateValue, J as getAllStateNodes, p as getStateNodes, K as createMachineSnapshot, L as isInFinalState, d as macrostep, M as transitionNode, O as resolveActionsAndContext, e as createInitEvent, i as initialMicrostep, P as toStatePath, Q as isStateId, R as getStateNodeByPath, T as getPersistedSnapshot, U as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-e5d81555.esm.js';
2
- import { a as assign } from './assign-227b928a.esm.js';
1
+ import { S as STATE_DELIMITER, y as mapValues, t as toArray, z as formatTransitions, B as toTransitionConfigArray, C as formatTransition, N as NULL_EVENT, D as evaluateGuard, E as createInvokeId, F as getDelayedTransitions, G as formatInitialTransition, H as getCandidates, I as formatRouteTransitions, J as resolveStateValue, K as getAllStateNodes, p as getStateNodes, L as createMachineSnapshot, M as isInFinalState, d as macrostep, O as transitionNode, P as resolveActionsAndContext, e as createInitEvent, i as initialMicrostep, Q as toStatePath, R as isStateId, T as getStateNodeByPath, U as getPersistedSnapshot, V as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-b47daa89.esm.js';
2
+ import { a as assign } from './assign-128c3f01.esm.js';
3
3
 
4
4
  const cache = new WeakMap();
5
5
  function memo(object, key, fn) {
@@ -326,6 +326,7 @@ class StateMachine {
326
326
  _machine: this
327
327
  });
328
328
  this.root._initialize();
329
+ formatRouteTransitions(this.root);
329
330
  this.states = this.root.states; // TODO: remove!
330
331
  this.events = this.root.events;
331
332
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-3a84be1f.cjs.js');
4
- var assign = require('./assign-e36553db.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-f051f097.cjs.js');
4
+ var assign = require('./assign-f10db67b.cjs.js');
5
5
 
6
6
  const cache = new WeakMap();
7
7
  function memo(object, key, fn) {
@@ -328,6 +328,7 @@ class StateMachine {
328
328
  _machine: this
329
329
  });
330
330
  this.root._initialize();
331
+ guards_dist_xstateGuards.formatRouteTransitions(this.root);
331
332
  this.states = this.root.states; // TODO: remove!
332
333
  this.events = this.root.events;
333
334
  }
@@ -1,4 +1,4 @@
1
- import { Y as ProcessingStatus, U as resolveReferencedActor, c as createActor, Z as cloneMachineSnapshot } from './raise-e5d81555.esm.js';
1
+ import { Z as ProcessingStatus, V as resolveReferencedActor, c as createActor, _ as cloneMachineSnapshot } from './raise-b47daa89.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, {
4
4
  machine,
@@ -1,4 +1,4 @@
1
- import { Z as ProcessingStatus, U as resolveReferencedActor, c as createActor, _ as cloneMachineSnapshot, V as executingCustomAction } from './raise-a7794093.development.esm.js';
1
+ import { _ as ProcessingStatus, V as resolveReferencedActor, c as createActor, a0 as cloneMachineSnapshot, W as executingCustomAction } from './raise-964ef086.development.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, {
4
4
  machine,
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-ecea0c53.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-f3874442.development.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-3a84be1f.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-f051f097.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -4,7 +4,7 @@ export interface SpawnAction<TContext extends MachineContext, TExpressionEvent e
4
4
  (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
5
5
  _out_TActor?: TActor;
6
6
  }
7
- interface SpawnActionOptions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor> {
7
+ export interface SpawnActionOptions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor> {
8
8
  id?: ResolvableActorId<TContext, TExpressionEvent, TEvent, TActor['id']>;
9
9
  systemId?: string;
10
10
  input?: Mapper<TContext, TEvent, InputFrom<TActor['logic']>, TEvent> | InputFrom<TActor['logic']>;
@@ -5,5 +5,5 @@ export { enqueueActions, type EnqueueActionsAction } from "./actions/enqueueActi
5
5
  export { log, type LogAction } from "./actions/log.js";
6
6
  export { raise, type RaiseAction } from "./actions/raise.js";
7
7
  export { forwardTo, sendParent, sendTo, type SendToAction } from "./actions/send.js";
8
- export { spawnChild, type SpawnAction } from "./actions/spawnChild.js";
8
+ export { spawnChild, type SpawnAction, type SpawnActionOptions } from "./actions/spawnChild.js";
9
9
  export { stop, stopChild, type StopAction } from "./actions/stopChild.js";
@@ -1,7 +1,7 @@
1
1
  import { symbolObservable } from "./symbolObservable.js";
2
2
  import { AnyActorSystem, Clock } from "./system.js";
3
3
  export declare let executingCustomAction: boolean;
4
- import type { AnyActorLogic, AnyActorRef, ConditionalRequired, EmittedFrom, EventFromLogic, InputFrom, IsNotNever, Snapshot, SnapshotFrom } from "./types.js";
4
+ import type { AnyActorLogic, AnyActorRef, ConditionalRequired, EmittedFrom, EventFromLogic, InputFrom, IsNotNever, Readable, Snapshot, SnapshotFrom } from "./types.js";
5
5
  import { ActorOptions, ActorRef, InteropSubscribable, Observer, Subscription } from "./types.js";
6
6
  export declare const $$ACTOR_TYPE = 1;
7
7
  export declare enum ProcessingStatus {
@@ -115,6 +115,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
115
115
  on<TType extends EmittedFrom<TLogic>['type'] | '*'>(type: TType, handler: (emitted: EmittedFrom<TLogic> & (TType extends '*' ? unknown : {
116
116
  type: TType;
117
117
  })) => void): Subscription;
118
+ select<TSelected>(selector: (snapshot: SnapshotFrom<TLogic>) => TSelected, equalityFn?: (a: TSelected, b: TSelected) => boolean): Readable<TSelected>;
118
119
  /** Starts the Actor from the initial state */
119
120
  start(): this;
120
121
  private _process;
@@ -5,8 +5,9 @@ export { Actor, createActor, interpret, type Interpreter, type RequiredActorOpti
5
5
  export { createMachine } from "./createMachine.js";
6
6
  export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
7
7
  export { and, not, or, stateIn } from "./guards.js";
8
+ export type { GuardPredicate, GuardArgs } from "./guards.js";
8
9
  export type { InspectedActionEvent, InspectedActorEvent, InspectedEventEvent, InspectedMicrostepEvent, InspectedSnapshotEvent, InspectionEvent } from "./inspection.js";
9
- export { setup } from "./setup.js";
10
+ export { setup, type SetupReturn } from "./setup.js";
10
11
  export { SimulatedClock } from "./SimulatedClock.js";
11
12
  export { type Spawner } from "./spawn.js";
12
13
  export { isMachineSnapshot, type MachineSnapshot } from "./State.js";
@@ -9,7 +9,7 @@ import { sendTo } from "./actions/send.js";
9
9
  import { spawnChild } from "./actions/spawnChild.js";
10
10
  import { stopChild } from "./actions/stopChild.js";
11
11
  import { GuardPredicate } from "./guards.js";
12
- import { ActionFunction, AnyActorRef, AnyEventObject, Cast, DelayConfig, EventObject, Invert, IsNever, MachineConfig, MachineContext, MetaObject, NonReducibleUnknown, ParameterizedObject, SetupTypes, StateNodeConfig, StateSchema, ToChildren, ToStateValue, UnknownActorLogic, Values } from "./types.js";
12
+ import { ActionFunction, AnyActorRef, AnyEventObject, Cast, DelayConfig, EventObject, Invert, IsNever, MachineConfig, MachineContext, MetaObject, NonReducibleUnknown, ParameterizedObject, RoutableStateId, SetupTypes, StateNodeConfig, StateSchema, ToChildren, ToStateValue, UnknownActorLogic, Values } from "./types.js";
13
13
  type ToParameterizedObject<TParameterizedMap extends Record<string, ParameterizedObject['params'] | undefined>> = Values<{
14
14
  [K in keyof TParameterizedMap as K & string]: {
15
15
  type: K & string;
@@ -29,7 +29,7 @@ type ToStateSchema<TSchema extends StateSchema> = {
29
29
  } : TSchema[K];
30
30
  };
31
31
  type RequiredSetupKeys<TChildrenMap> = IsNever<keyof TChildrenMap> extends true ? never : 'actors';
32
- type SetupReturn<TContext extends MachineContext, TEvent extends AnyEventObject, TActors extends Record<string, UnknownActorLogic>, TChildrenMap extends Record<string, string>, TActions extends Record<string, ParameterizedObject['params'] | undefined>, TGuards extends Record<string, ParameterizedObject['params'] | undefined>, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TEmitted extends EventObject, TMeta extends MetaObject> = {
32
+ export type SetupReturn<TContext extends MachineContext, TEvent extends AnyEventObject, TActors extends Record<string, UnknownActorLogic>, TChildrenMap extends Record<string, string>, TActions extends Record<string, ParameterizedObject['params'] | undefined>, TGuards extends Record<string, ParameterizedObject['params'] | undefined>, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TEmitted extends EventObject, TMeta extends MetaObject> = {
33
33
  extend: <TExtendActions extends Record<string, ParameterizedObject['params'] | undefined> = {}, TExtendGuards extends Record<string, ParameterizedObject['params'] | undefined> = {}, TExtendDelays extends string = never>({ actions, guards, delays }: {
34
34
  actions?: {
35
35
  [K in keyof TExtendActions]: ActionFunction<TContext, TEvent, TEvent, TExtendActions[K], ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions & TExtendActions>, ToParameterizedObject<TGuards & TExtendGuards>, TDelay | TExtendDelays, TEmitted>;
@@ -96,7 +96,10 @@ type SetupReturn<TContext extends MachineContext, TEvent extends AnyEventObject,
96
96
  * ```
97
97
  */
98
98
  createAction: (action: ActionFunction<TContext, TEvent, TEvent, unknown, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TEmitted>) => typeof action;
99
- createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>>(config: TConfig) => StateMachine<TContext, TEvent, Cast<ToChildren<ToProvidedActor<TChildrenMap, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, ToStateValue<TConfig>, TTag, TInput, TOutput, TEmitted, TMeta, ToStateSchema<TConfig>>;
99
+ createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>>(config: TConfig) => StateMachine<TContext, TEvent | ([RoutableStateId<TConfig>] extends [never] ? never : {
100
+ type: 'xstate.route';
101
+ to: RoutableStateId<TConfig>;
102
+ }), Cast<ToChildren<ToProvidedActor<TChildrenMap, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, ToStateValue<TConfig>, TTag, TInput, TOutput, TEmitted, TMeta, ToStateSchema<TConfig>>;
100
103
  assign: typeof assign<TContext, TEvent, undefined, TEvent, ToProvidedActor<TChildrenMap, TActors>>;
101
104
  sendTo: <TTargetActor extends AnyActorRef>(...args: Parameters<typeof sendTo<TContext, TEvent, undefined, TTargetActor, TEvent, TDelay, TDelay>>) => ReturnType<typeof sendTo<TContext, TEvent, undefined, TTargetActor, TEvent, TDelay, TDelay>>;
102
105
  raise: typeof raise<TContext, TEvent, TEvent, undefined, TDelay, TDelay>;
@@ -14,6 +14,11 @@ export declare function getCandidates<TEvent extends EventObject>(stateNode: Sta
14
14
  export declare function getDelayedTransitions(stateNode: AnyStateNode): Array<DelayedTransitionDefinition<MachineContext, EventObject>>;
15
15
  export declare function formatTransition(stateNode: AnyStateNode, descriptor: string, transitionConfig: AnyTransitionConfig): AnyTransitionDefinition;
16
16
  export declare function formatTransitions<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode): Map<string, TransitionDefinition<TContext, TEvent>[]>;
17
+ /**
18
+ * Collects route transitions from all descendants with explicit IDs. Called
19
+ * once on the root node to avoid O(N²) repeated traversals.
20
+ */
21
+ export declare function formatRouteTransitions(rootStateNode: AnyStateNode): void;
17
22
  export declare function formatInitialTransition<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, _target: string | undefined | InitialTransitionConfig<TContext, TEvent, TODO, TODO, TODO, TODO>): InitialTransitionDefinition<TContext, TEvent>;
18
23
  /**
19
24
  * Returns the relative state node from the given `statePath`, or throws.
@@ -341,6 +341,13 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
341
341
  description?: string;
342
342
  /** A default target for a history state */
343
343
  target?: string | undefined;
344
+ route?: RouteTransitionConfig<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>;
345
+ }
346
+ export interface RouteTransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> {
347
+ guard?: Guard<TContext, TExpressionEvent, undefined, TGuard>;
348
+ actions?: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
349
+ meta?: Record<string, any>;
350
+ description?: string;
344
351
  }
345
352
  export type AnyStateNodeConfig = StateNodeConfig<any, any, any, any, any, any, any, any, any, // emitted
346
353
  any>;
@@ -729,6 +736,9 @@ export type Observer<T> = {
729
736
  export interface Subscription {
730
737
  unsubscribe(): void;
731
738
  }
739
+ export interface Readable<T> extends Subscribable<T> {
740
+ get: () => T;
741
+ }
732
742
  export interface InteropObservable<T> {
733
743
  [Symbol.observable]: () => InteropSubscribable<T>;
734
744
  }
@@ -763,6 +773,7 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
763
773
  on: <TType extends TEmitted['type'] | '*'>(type: TType, handler: (emitted: TEmitted & (TType extends '*' ? unknown : {
764
774
  type: TType;
765
775
  })) => void) => Subscription;
776
+ select<TSelected>(selector: (snapshot: TSnapshot) => TSelected, equalityFn?: (a: TSelected, b: TSelected) => boolean): Readable<TSelected>;
766
777
  }
767
778
  export type AnyActorRef = ActorRef<any, any, // TODO: shouldn't this be AnyEventObject?
768
779
  any>;
@@ -907,6 +918,7 @@ export type ToChildren<TActor extends ProvidedActor> = string extends TActor['sr
907
918
  }[undefined extends TActor['id'] ? 'include' : string extends TActor['id'] ? 'include' : 'exclude']>;
908
919
  export type StateSchema = {
909
920
  id?: string;
921
+ route?: unknown;
910
922
  states?: Record<string, StateSchema>;
911
923
  type?: unknown;
912
924
  invoke?: unknown;
@@ -926,6 +938,12 @@ export type StateId<TSchema extends StateSchema, TKey extends string = '(machine
926
938
  } ? TSchema['id'] : TParentKey extends null ? TKey : `${TParentKey}.${TKey}`) | (TSchema['states'] extends Record<string, any> ? Values<{
927
939
  [K in keyof TSchema['states'] & string]: StateId<TSchema['states'][K], K, TParentKey extends string ? `${TParentKey}.${TKey}` : TSchema['id'] extends string ? TSchema['id'] : TKey>;
928
940
  }> : never);
941
+ export type RoutableStateId<TSchema extends StateSchema> = (TSchema extends {
942
+ route: any;
943
+ id: string;
944
+ } ? `#${TSchema['id']}` : never) | (TSchema['states'] extends Record<string, any> ? Values<{
945
+ [K in keyof TSchema['states'] & string]: RoutableStateId<TSchema['states'][K]>;
946
+ }> : never);
929
947
  export interface StateMachineTypes {
930
948
  context: MachineContext;
931
949
  events: EventObject;
@@ -1,5 +1,5 @@
1
- import { V as executingCustomAction, W as XSTATE_ERROR, Y as createErrorActorEvent, D as evaluateGuard, a as cancel, r as raise, b as spawnChild, s as stopChild } from './raise-a7794093.development.esm.js';
2
- import { a as assign } from './assign-d5291869.development.esm.js';
1
+ import { W as executingCustomAction, Y as XSTATE_ERROR, Z as createErrorActorEvent, D as evaluateGuard, a as cancel, r as raise, b as spawnChild, s as stopChild } from './raise-964ef086.development.esm.js';
2
+ import { a as assign } from './assign-4254ecc7.development.esm.js';
3
3
 
4
4
  function resolveEmit(_, snapshot, args, actionParams, {
5
5
  event: eventOrExpr
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-3a84be1f.cjs.js');
4
- var assign = require('./assign-e36553db.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-f051f097.cjs.js');
4
+ var assign = require('./assign-f10db67b.cjs.js');
5
5
 
6
6
  function resolveEmit(_, snapshot, args, actionParams, {
7
7
  event: eventOrExpr
@@ -1,5 +1,5 @@
1
- import { V as XSTATE_ERROR, W as createErrorActorEvent, D as evaluateGuard, a as cancel, r as raise, b as spawnChild, s as stopChild } from './raise-e5d81555.esm.js';
2
- import { a as assign } from './assign-227b928a.esm.js';
1
+ import { W as XSTATE_ERROR, Y as createErrorActorEvent, D as evaluateGuard, a as cancel, r as raise, b as spawnChild, s as stopChild } from './raise-b47daa89.esm.js';
2
+ import { a as assign } from './assign-128c3f01.esm.js';
3
3
 
4
4
  function resolveEmit(_, snapshot, args, actionParams, {
5
5
  event: eventOrExpr
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-ecea0c53.development.cjs.js');
4
- var assign = require('./assign-8ef0e332.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-f3874442.development.cjs.js');
4
+ var assign = require('./assign-8c16ea04.development.cjs.js');
5
5
 
6
6
  function resolveEmit(_, snapshot, args, actionParams, {
7
7
  event: eventOrExpr
@@ -835,6 +835,23 @@ class Actor {
835
835
  }
836
836
  };
837
837
  }
838
+ select(selector, equalityFn = Object.is) {
839
+ return {
840
+ subscribe: observerOrFn => {
841
+ const observer = toObserver(observerOrFn);
842
+ const snapshot = this.getSnapshot();
843
+ let previousSelected = selector(snapshot);
844
+ return this.subscribe(snapshot => {
845
+ const nextSelected = selector(snapshot);
846
+ if (!equalityFn(previousSelected, nextSelected)) {
847
+ previousSelected = nextSelected;
848
+ observer.next?.(nextSelected);
849
+ }
850
+ });
851
+ },
852
+ get: () => selector(this.getSnapshot())
853
+ };
854
+ }
838
855
 
839
856
  /** Starts the Actor from the initial state */
840
857
  start() {
@@ -1789,6 +1806,47 @@ function formatTransitions(stateNode) {
1789
1806
  }
1790
1807
  return transitions;
1791
1808
  }
1809
+
1810
+ /**
1811
+ * Collects route transitions from all descendants with explicit IDs. Called
1812
+ * once on the root node to avoid O(N²) repeated traversals.
1813
+ */
1814
+ function formatRouteTransitions(rootStateNode) {
1815
+ const routeTransitions = [];
1816
+ const collectRoutes = states => {
1817
+ Object.values(states).forEach(sn => {
1818
+ if (sn.config.route && sn.config.id) {
1819
+ const routeId = sn.config.id;
1820
+ const userGuard = sn.config.route.guard;
1821
+ const routeGuard = (args, params) => {
1822
+ if (args.event.to !== `#${routeId}`) {
1823
+ return false;
1824
+ }
1825
+ if (!userGuard) {
1826
+ return true;
1827
+ }
1828
+ if (typeof userGuard === 'function') {
1829
+ return userGuard(args, params);
1830
+ }
1831
+ return true;
1832
+ };
1833
+ const transition = {
1834
+ ...sn.config.route,
1835
+ guard: routeGuard,
1836
+ target: `#${routeId}`
1837
+ };
1838
+ routeTransitions.push(formatTransition(rootStateNode, 'xstate.route', transition));
1839
+ }
1840
+ if (sn.states) {
1841
+ collectRoutes(sn.states);
1842
+ }
1843
+ });
1844
+ };
1845
+ collectRoutes(rootStateNode.states);
1846
+ if (routeTransitions.length > 0) {
1847
+ rootStateNode.transitions.set('xstate.route', routeTransitions);
1848
+ }
1849
+ }
1792
1850
  function formatInitialTransition(stateNode, _target) {
1793
1851
  const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
1794
1852
  if (!resolvedTarget && _target) {
@@ -2765,4 +2823,4 @@ function raise(eventOrExpr, options) {
2765
2823
  return raise;
2766
2824
  }
2767
2825
 
2768
- export { $$ACTOR_TYPE as $, Actor as A, toTransitionConfigArray as B, formatTransition as C, evaluateGuard as D, createInvokeId as E, getDelayedTransitions as F, formatInitialTransition as G, getCandidates as H, resolveStateValue as I, getAllStateNodes as J, createMachineSnapshot as K, isInFinalState as L, transitionNode as M, NULL_EVENT as N, resolveActionsAndContext as O, toStatePath as P, isStateId as Q, getStateNodeByPath as R, STATE_DELIMITER as S, getPersistedSnapshot as T, resolveReferencedActor as U, executingCustomAction as V, XSTATE_ERROR as W, XSTATE_STOP as X, createErrorActorEvent as Y, ProcessingStatus as Z, cloneMachineSnapshot as _, cancel as a, spawnChild as b, createActor as c, macrostep as d, createInitEvent as e, isAtomicStateNode as f, getProperAncestors as g, interpret as h, initialMicrostep as i, and as j, stateIn as k, isMachineSnapshot as l, matchesEventDescriptor as m, not as n, or as o, getStateNodes as p, getAllOwnEventDescriptors as q, raise as r, stopChild as s, toArray as t, matchesState as u, pathToStateValue as v, toObserver as w, stop as x, mapValues as y, formatTransitions as z };
2826
+ export { $$ACTOR_TYPE as $, Actor as A, toTransitionConfigArray as B, formatTransition as C, evaluateGuard as D, createInvokeId as E, getDelayedTransitions as F, formatInitialTransition as G, getCandidates as H, formatRouteTransitions as I, resolveStateValue as J, getAllStateNodes as K, createMachineSnapshot as L, isInFinalState as M, NULL_EVENT as N, transitionNode as O, resolveActionsAndContext as P, toStatePath as Q, isStateId as R, STATE_DELIMITER as S, getStateNodeByPath as T, getPersistedSnapshot as U, resolveReferencedActor as V, executingCustomAction as W, XSTATE_STOP as X, XSTATE_ERROR as Y, createErrorActorEvent as Z, ProcessingStatus as _, cancel as a, cloneMachineSnapshot as a0, spawnChild as b, createActor as c, macrostep as d, createInitEvent as e, isAtomicStateNode as f, getProperAncestors as g, interpret as h, initialMicrostep as i, and as j, stateIn as k, isMachineSnapshot as l, matchesEventDescriptor as m, not as n, or as o, getStateNodes as p, getAllOwnEventDescriptors as q, raise as r, stopChild as s, toArray as t, matchesState as u, pathToStateValue as v, toObserver as w, stop as x, mapValues as y, formatTransitions as z };
@@ -826,6 +826,23 @@ class Actor {
826
826
  }
827
827
  };
828
828
  }
829
+ select(selector, equalityFn = Object.is) {
830
+ return {
831
+ subscribe: observerOrFn => {
832
+ const observer = toObserver(observerOrFn);
833
+ const snapshot = this.getSnapshot();
834
+ let previousSelected = selector(snapshot);
835
+ return this.subscribe(snapshot => {
836
+ const nextSelected = selector(snapshot);
837
+ if (!equalityFn(previousSelected, nextSelected)) {
838
+ previousSelected = nextSelected;
839
+ observer.next?.(nextSelected);
840
+ }
841
+ });
842
+ },
843
+ get: () => selector(this.getSnapshot())
844
+ };
845
+ }
829
846
 
830
847
  /** Starts the Actor from the initial state */
831
848
  start() {
@@ -1742,6 +1759,47 @@ function formatTransitions(stateNode) {
1742
1759
  }
1743
1760
  return transitions;
1744
1761
  }
1762
+
1763
+ /**
1764
+ * Collects route transitions from all descendants with explicit IDs. Called
1765
+ * once on the root node to avoid O(N²) repeated traversals.
1766
+ */
1767
+ function formatRouteTransitions(rootStateNode) {
1768
+ const routeTransitions = [];
1769
+ const collectRoutes = states => {
1770
+ Object.values(states).forEach(sn => {
1771
+ if (sn.config.route && sn.config.id) {
1772
+ const routeId = sn.config.id;
1773
+ const userGuard = sn.config.route.guard;
1774
+ const routeGuard = (args, params) => {
1775
+ if (args.event.to !== `#${routeId}`) {
1776
+ return false;
1777
+ }
1778
+ if (!userGuard) {
1779
+ return true;
1780
+ }
1781
+ if (typeof userGuard === 'function') {
1782
+ return userGuard(args, params);
1783
+ }
1784
+ return true;
1785
+ };
1786
+ const transition = {
1787
+ ...sn.config.route,
1788
+ guard: routeGuard,
1789
+ target: `#${routeId}`
1790
+ };
1791
+ routeTransitions.push(formatTransition(rootStateNode, 'xstate.route', transition));
1792
+ }
1793
+ if (sn.states) {
1794
+ collectRoutes(sn.states);
1795
+ }
1796
+ });
1797
+ };
1798
+ collectRoutes(rootStateNode.states);
1799
+ if (routeTransitions.length > 0) {
1800
+ rootStateNode.transitions.set('xstate.route', routeTransitions);
1801
+ }
1802
+ }
1745
1803
  function formatInitialTransition(stateNode, _target) {
1746
1804
  const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
1747
1805
  if (!resolvedTarget && _target) {
@@ -2703,4 +2761,4 @@ function raise(eventOrExpr, options) {
2703
2761
  return raise;
2704
2762
  }
2705
2763
 
2706
- export { $$ACTOR_TYPE as $, Actor as A, toTransitionConfigArray as B, formatTransition as C, evaluateGuard as D, createInvokeId as E, getDelayedTransitions as F, formatInitialTransition as G, getCandidates as H, resolveStateValue as I, getAllStateNodes as J, createMachineSnapshot as K, isInFinalState as L, transitionNode as M, NULL_EVENT as N, resolveActionsAndContext as O, toStatePath as P, isStateId as Q, getStateNodeByPath as R, STATE_DELIMITER as S, getPersistedSnapshot as T, resolveReferencedActor as U, XSTATE_ERROR as V, createErrorActorEvent as W, XSTATE_STOP as X, ProcessingStatus as Y, cloneMachineSnapshot as Z, cancel as a, spawnChild as b, createActor as c, macrostep as d, createInitEvent as e, isAtomicStateNode as f, getProperAncestors as g, interpret as h, initialMicrostep as i, and as j, stateIn as k, isMachineSnapshot as l, matchesEventDescriptor as m, not as n, or as o, getStateNodes as p, getAllOwnEventDescriptors as q, raise as r, stopChild as s, toArray as t, matchesState as u, pathToStateValue as v, toObserver as w, stop as x, mapValues as y, formatTransitions as z };
2764
+ export { $$ACTOR_TYPE as $, Actor as A, toTransitionConfigArray as B, formatTransition as C, evaluateGuard as D, createInvokeId as E, getDelayedTransitions as F, formatInitialTransition as G, getCandidates as H, formatRouteTransitions as I, resolveStateValue as J, getAllStateNodes as K, createMachineSnapshot as L, isInFinalState as M, NULL_EVENT as N, transitionNode as O, resolveActionsAndContext as P, toStatePath as Q, isStateId as R, STATE_DELIMITER as S, getStateNodeByPath as T, getPersistedSnapshot as U, resolveReferencedActor as V, XSTATE_ERROR as W, XSTATE_STOP as X, createErrorActorEvent as Y, ProcessingStatus as Z, cloneMachineSnapshot as _, cancel as a, spawnChild as b, createActor as c, macrostep as d, createInitEvent as e, isAtomicStateNode as f, getProperAncestors as g, interpret as h, initialMicrostep as i, and as j, stateIn as k, isMachineSnapshot as l, matchesEventDescriptor as m, not as n, or as o, getStateNodes as p, getAllOwnEventDescriptors as q, raise as r, stopChild as s, toArray as t, matchesState as u, pathToStateValue as v, toObserver as w, stop as x, mapValues as y, formatTransitions as z };
@@ -828,6 +828,23 @@ class Actor {
828
828
  }
829
829
  };
830
830
  }
831
+ select(selector, equalityFn = Object.is) {
832
+ return {
833
+ subscribe: observerOrFn => {
834
+ const observer = toObserver(observerOrFn);
835
+ const snapshot = this.getSnapshot();
836
+ let previousSelected = selector(snapshot);
837
+ return this.subscribe(snapshot => {
838
+ const nextSelected = selector(snapshot);
839
+ if (!equalityFn(previousSelected, nextSelected)) {
840
+ previousSelected = nextSelected;
841
+ observer.next?.(nextSelected);
842
+ }
843
+ });
844
+ },
845
+ get: () => selector(this.getSnapshot())
846
+ };
847
+ }
831
848
 
832
849
  /** Starts the Actor from the initial state */
833
850
  start() {
@@ -1744,6 +1761,47 @@ function formatTransitions(stateNode) {
1744
1761
  }
1745
1762
  return transitions;
1746
1763
  }
1764
+
1765
+ /**
1766
+ * Collects route transitions from all descendants with explicit IDs. Called
1767
+ * once on the root node to avoid O(N²) repeated traversals.
1768
+ */
1769
+ function formatRouteTransitions(rootStateNode) {
1770
+ const routeTransitions = [];
1771
+ const collectRoutes = states => {
1772
+ Object.values(states).forEach(sn => {
1773
+ if (sn.config.route && sn.config.id) {
1774
+ const routeId = sn.config.id;
1775
+ const userGuard = sn.config.route.guard;
1776
+ const routeGuard = (args, params) => {
1777
+ if (args.event.to !== `#${routeId}`) {
1778
+ return false;
1779
+ }
1780
+ if (!userGuard) {
1781
+ return true;
1782
+ }
1783
+ if (typeof userGuard === 'function') {
1784
+ return userGuard(args, params);
1785
+ }
1786
+ return true;
1787
+ };
1788
+ const transition = {
1789
+ ...sn.config.route,
1790
+ guard: routeGuard,
1791
+ target: `#${routeId}`
1792
+ };
1793
+ routeTransitions.push(formatTransition(rootStateNode, 'xstate.route', transition));
1794
+ }
1795
+ if (sn.states) {
1796
+ collectRoutes(sn.states);
1797
+ }
1798
+ });
1799
+ };
1800
+ collectRoutes(rootStateNode.states);
1801
+ if (routeTransitions.length > 0) {
1802
+ rootStateNode.transitions.set('xstate.route', routeTransitions);
1803
+ }
1804
+ }
1747
1805
  function formatInitialTransition(stateNode, _target) {
1748
1806
  const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
1749
1807
  if (!resolvedTarget && _target) {
@@ -2722,6 +2780,7 @@ exports.createInvokeId = createInvokeId;
2722
2780
  exports.createMachineSnapshot = createMachineSnapshot;
2723
2781
  exports.evaluateGuard = evaluateGuard;
2724
2782
  exports.formatInitialTransition = formatInitialTransition;
2783
+ exports.formatRouteTransitions = formatRouteTransitions;
2725
2784
  exports.formatTransition = formatTransition;
2726
2785
  exports.formatTransitions = formatTransitions;
2727
2786
  exports.getAllOwnEventDescriptors = getAllOwnEventDescriptors;
@@ -837,6 +837,23 @@ class Actor {
837
837
  }
838
838
  };
839
839
  }
840
+ select(selector, equalityFn = Object.is) {
841
+ return {
842
+ subscribe: observerOrFn => {
843
+ const observer = toObserver(observerOrFn);
844
+ const snapshot = this.getSnapshot();
845
+ let previousSelected = selector(snapshot);
846
+ return this.subscribe(snapshot => {
847
+ const nextSelected = selector(snapshot);
848
+ if (!equalityFn(previousSelected, nextSelected)) {
849
+ previousSelected = nextSelected;
850
+ observer.next?.(nextSelected);
851
+ }
852
+ });
853
+ },
854
+ get: () => selector(this.getSnapshot())
855
+ };
856
+ }
840
857
 
841
858
  /** Starts the Actor from the initial state */
842
859
  start() {
@@ -1791,6 +1808,47 @@ function formatTransitions(stateNode) {
1791
1808
  }
1792
1809
  return transitions;
1793
1810
  }
1811
+
1812
+ /**
1813
+ * Collects route transitions from all descendants with explicit IDs. Called
1814
+ * once on the root node to avoid O(N²) repeated traversals.
1815
+ */
1816
+ function formatRouteTransitions(rootStateNode) {
1817
+ const routeTransitions = [];
1818
+ const collectRoutes = states => {
1819
+ Object.values(states).forEach(sn => {
1820
+ if (sn.config.route && sn.config.id) {
1821
+ const routeId = sn.config.id;
1822
+ const userGuard = sn.config.route.guard;
1823
+ const routeGuard = (args, params) => {
1824
+ if (args.event.to !== `#${routeId}`) {
1825
+ return false;
1826
+ }
1827
+ if (!userGuard) {
1828
+ return true;
1829
+ }
1830
+ if (typeof userGuard === 'function') {
1831
+ return userGuard(args, params);
1832
+ }
1833
+ return true;
1834
+ };
1835
+ const transition = {
1836
+ ...sn.config.route,
1837
+ guard: routeGuard,
1838
+ target: `#${routeId}`
1839
+ };
1840
+ routeTransitions.push(formatTransition(rootStateNode, 'xstate.route', transition));
1841
+ }
1842
+ if (sn.states) {
1843
+ collectRoutes(sn.states);
1844
+ }
1845
+ });
1846
+ };
1847
+ collectRoutes(rootStateNode.states);
1848
+ if (routeTransitions.length > 0) {
1849
+ rootStateNode.transitions.set('xstate.route', routeTransitions);
1850
+ }
1851
+ }
1794
1852
  function formatInitialTransition(stateNode, _target) {
1795
1853
  const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
1796
1854
  if (!resolvedTarget && _target) {
@@ -2784,6 +2842,7 @@ exports.createInvokeId = createInvokeId;
2784
2842
  exports.createMachineSnapshot = createMachineSnapshot;
2785
2843
  exports.evaluateGuard = evaluateGuard;
2786
2844
  exports.formatInitialTransition = formatInitialTransition;
2845
+ exports.formatRouteTransitions = formatRouteTransitions;
2787
2846
  exports.formatTransition = formatTransition;
2788
2847
  exports.formatTransitions = formatTransitions;
2789
2848
  exports.getAllOwnEventDescriptors = getAllOwnEventDescriptors;
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
6
- var guards_dist_xstateGuards = require('./raise-3a84be1f.cjs.js');
7
- var StateMachine = require('./StateMachine-e93afc18.cjs.js');
8
- var assign = require('./assign-e36553db.cjs.js');
9
- var log = require('./log-e54c2eff.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-f051f097.cjs.js');
7
+ var StateMachine = require('./StateMachine-d3e2432b.cjs.js');
8
+ var assign = require('./assign-f10db67b.cjs.js');
9
+ var log = require('./log-30abbb83.cjs.js');
10
10
  require('../dev/dist/xstate-dev.cjs.js');
11
11
 
12
12
  /**