xstate 6.0.0-alpha.47 → 6.0.0-alpha.49

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 (84) hide show
  1. package/README.md +30 -1
  2. package/dist/{StateMachine-7046f677.cjs.js → StateMachine-0adb3a70.cjs.js} +15 -12
  3. package/dist/{StateMachine-70c06bdd.development.cjs.js → StateMachine-29450e6d.development.cjs.js} +15 -12
  4. package/dist/{StateMachine-74929087.esm.js → StateMachine-2af31c11.esm.js} +10 -7
  5. package/dist/{StateMachine-ee10f67e.development.esm.js → StateMachine-faf50c5c.development.esm.js} +10 -7
  6. package/dist/{createActor-915ea40c.esm.js → createActor-268165d4.esm.js} +79 -23
  7. package/dist/{createActor-ff132afa.development.esm.js → createActor-88709f74.development.esm.js} +79 -23
  8. package/dist/{createActor-6736cbbe.development.cjs.js → createActor-a1e0dffb.development.cjs.js} +78 -25
  9. package/dist/{createActor-bfe8b6bd.cjs.js → createActor-b4dd05ae.cjs.js} +78 -25
  10. package/dist/declarations/src/createMachineFromConfig.d.ts +5 -77
  11. package/dist/declarations/src/fsm/createFSMActor.d.ts +67 -0
  12. package/dist/declarations/src/fsm/index.d.ts +2 -0
  13. package/dist/declarations/src/fsm.d.ts +5 -4
  14. package/dist/declarations/src/scxml/index.d.ts +1 -0
  15. package/dist/declarations/src/scxml/runtime.d.ts +251 -0
  16. package/dist/declarations/src/scxml/scxml.d.ts +19 -0
  17. package/dist/declarations/src/types.d.ts +1 -0
  18. package/dist/{effectDescriptor-8be60443.esm.js → effectDescriptor-30c9a744.esm.js} +1 -1
  19. package/dist/{effectDescriptor-fbe67d5a.development.esm.js → effectDescriptor-39d22100.development.esm.js} +1 -1
  20. package/dist/{effectDescriptor-3c699328.development.cjs.js → effectDescriptor-7ff6802f.development.cjs.js} +1 -1
  21. package/dist/{effectDescriptor-a7e2d4d1.cjs.js → effectDescriptor-be348e50.cjs.js} +1 -1
  22. package/dist/fsm-7a2e9697.cjs.js +777 -0
  23. package/dist/fsm-b804b3e9.esm.js +775 -0
  24. package/dist/fsm-c1316948.development.cjs.js +777 -0
  25. package/dist/fsm-e18a7cb4.development.esm.js +775 -0
  26. package/dist/types-3c3455f7.esm.js +185 -0
  27. package/dist/types-adda3842.development.esm.js +185 -0
  28. package/dist/types-b3fea5bd.development.cjs.js +189 -0
  29. package/dist/types-fbabaeee.cjs.js +189 -0
  30. package/dist/validation-05f1d517.esm.js +8 -0
  31. package/dist/validation-4561b43c.cjs.js +10 -0
  32. package/dist/validation-e69470ad.development.esm.js +8 -0
  33. package/dist/validation-f2714a35.development.cjs.js +10 -0
  34. package/dist/xstate-actors.cjs.js +934 -9
  35. package/dist/xstate-actors.development.cjs.js +934 -9
  36. package/dist/xstate-actors.development.esm.js +932 -2
  37. package/dist/xstate-actors.esm.js +932 -2
  38. package/dist/xstate-durable.cjs.js +2 -2
  39. package/dist/xstate-durable.development.cjs.js +2 -2
  40. package/dist/xstate-durable.development.esm.js +2 -2
  41. package/dist/xstate-durable.esm.js +2 -2
  42. package/dist/xstate-fsm.cjs.d.mts +2 -0
  43. package/dist/xstate-fsm.cjs.d.ts +2 -0
  44. package/dist/xstate-fsm.cjs.js +409 -0
  45. package/dist/xstate-fsm.cjs.mjs +5 -0
  46. package/dist/xstate-fsm.development.cjs.js +409 -0
  47. package/dist/xstate-fsm.development.cjs.mjs +5 -0
  48. package/dist/xstate-fsm.development.esm.js +403 -0
  49. package/dist/xstate-fsm.esm.js +403 -0
  50. package/dist/xstate-fsm.umd.min.js +2 -0
  51. package/dist/xstate-fsm.umd.min.js.map +1 -0
  52. package/dist/xstate-graph.cjs.js +4 -3
  53. package/dist/xstate-graph.development.cjs.js +4 -3
  54. package/dist/xstate-graph.development.esm.js +4 -3
  55. package/dist/xstate-graph.esm.js +4 -3
  56. package/dist/xstate-graph.umd.min.js +1 -1
  57. package/dist/xstate-graph.umd.min.js.map +1 -1
  58. package/dist/xstate-scxml.cjs.d.mts +2 -0
  59. package/dist/xstate-scxml.cjs.d.ts +2 -0
  60. package/dist/xstate-scxml.cjs.js +2387 -0
  61. package/dist/xstate-scxml.cjs.mjs +3 -0
  62. package/dist/xstate-scxml.development.cjs.js +2387 -0
  63. package/dist/xstate-scxml.development.cjs.mjs +3 -0
  64. package/dist/xstate-scxml.development.esm.js +2383 -0
  65. package/dist/xstate-scxml.esm.js +2383 -0
  66. package/dist/xstate-scxml.umd.min.js +26 -0
  67. package/dist/xstate-scxml.umd.min.js.map +1 -0
  68. package/dist/xstate-validation.cjs.js +1 -1
  69. package/dist/xstate-validation.development.cjs.js +1 -1
  70. package/dist/xstate-validation.development.esm.js +1 -1
  71. package/dist/xstate-validation.esm.js +1 -1
  72. package/dist/xstate.cjs.js +143 -1412
  73. package/dist/xstate.development.cjs.js +143 -1412
  74. package/dist/xstate.development.esm.js +143 -1411
  75. package/dist/xstate.esm.js +143 -1411
  76. package/dist/xstate.umd.min.js +1 -1
  77. package/dist/xstate.umd.min.js.map +1 -1
  78. package/fsm/package.json +8 -0
  79. package/package.json +37 -3
  80. package/scxml/package.json +8 -0
  81. package/dist/index-0f498ef2.development.cjs.js +0 -946
  82. package/dist/index-70d56425.development.esm.js +0 -937
  83. package/dist/index-b051c924.esm.js +0 -937
  84. package/dist/index-b3fe59bc.cjs.js +0 -946
package/README.md CHANGED
@@ -11,10 +11,35 @@
11
11
  <br />
12
12
  </p>
13
13
 
14
- XState is a state management and orchestration solution for JavaScript and TypeScript apps. It has _zero_ dependencies, and is useful for frontend and backend application logic.
14
+ <!-- runtime dependencies and public entry points from package.json -->
15
+
16
+ XState is a state management and orchestration solution for JavaScript and TypeScript apps. The main `xstate` entry point has _zero_ runtime dependencies; the optional `xstate/scxml` entry point uses an XML parser. XState is useful for frontend and backend application logic.
15
17
 
16
18
  It uses event-driven programming, state machines, statecharts, and the actor model to handle complex logic in predictable, robust, and visual ways. XState provides a powerful and flexible way to manage application and workflow state by allowing developers to model logic as actors and state machines.
17
19
 
20
+ For flat finite state machines, `xstate/fsm` provides a self-contained compact
21
+ runtime and a specialized actor:
22
+
23
+ <!-- public exports from packages/core/src/fsm/index.ts; exact capabilities documented in docs/fsm.md -->
24
+
25
+ ```ts
26
+ import { createFSM, createFSMActor } from 'xstate/fsm';
27
+
28
+ const logic = createFSM({
29
+ initial: 'inactive',
30
+ states: {
31
+ inactive: { on: { toggle: { target: 'active' } } },
32
+ active: { on: { toggle: { target: 'inactive' } } }
33
+ }
34
+ });
35
+
36
+ const actor = createFSMActor(logic).start();
37
+ ```
38
+
39
+ See the [exact supported surface](https://stately.ai/docs/fsm). Use the root `xstate`
40
+ entry point for compound or parallel statecharts, invocation, named sources,
41
+ schemas, serialization and inspection.
42
+
18
43
  ### ✨ Create state machines visually in Stately Studio → [state.new](https://state.new)
19
44
 
20
45
  ---
@@ -27,6 +52,10 @@ It uses event-driven programming, state machines, statecharts, and the actor mod
27
52
 
28
53
  📑 Inspired by the [SCXML specification](https://www.w3.org/TR/scxml/)
29
54
 
55
+ <!-- public SCXML entry point from src/scxml/index.ts -->
56
+
57
+ Create machines from SCXML documents with the opt-in `xstate/scxml` entry point. See the [SCXML guide](../../docs/scxml.md).
58
+
30
59
  💬 Chat on the [Stately Discord Community](https://discord.gg/xstate)
31
60
 
32
61
  ✍️ Browse through the many [XState examples](https://github.com/statelyai/xstate/tree/main/examples)
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-bfe8b6bd.cjs.js');
4
- var dist_xstateActors = require('./index-b3fe59bc.cjs.js');
3
+ var createActor = require('./createActor-b4dd05ae.cjs.js');
4
+ var validation = require('./validation-4561b43c.cjs.js');
5
5
 
6
6
  function createSpawner(actorScope, actors, spawnedChildren) {
7
7
  return (src, options) => {
@@ -387,14 +387,17 @@ function formatTransitions(stateNode) {
387
387
  function formatInitialTransition(stateNode, _target) {
388
388
  const targetString = typeof _target === 'object' && _target !== null ? _target.target : _target;
389
389
  const input = typeof _target === 'object' && _target !== null ? _target.input : undefined;
390
- const resolvedTarget = typeof targetString === 'string' ? stateNode.states[targetString] : undefined;
391
- if (!resolvedTarget && targetString) {
392
- throw new Error(`Initial state "${targetString}" not found on "#${stateNode.id}"`);
390
+ const to = typeof _target === 'object' && _target !== null ? _target.to : undefined;
391
+ const targetStrings = Array.isArray(targetString) ? targetString : targetString ? [targetString] : [];
392
+ const resolvedTargets = targetStrings.map(target => target.startsWith('#') ? stateNode.machine.getStateNodeById(target.slice(1)) : stateNode.states[target]);
393
+ if (resolvedTargets.some(target => !target)) {
394
+ throw new Error(`Initial state not found on "#${stateNode.id}"`);
393
395
  }
394
396
  const transition = {
395
397
  source: stateNode,
396
- target: resolvedTarget ? [resolvedTarget] : undefined,
397
- input
398
+ target: resolvedTargets.length ? resolvedTargets : undefined,
399
+ input,
400
+ to
398
401
  };
399
402
  return transition;
400
403
  }
@@ -712,7 +715,7 @@ class StateMachine {
712
715
  const usesInertScope = !actorScope;
713
716
  const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this, snapshot);
714
717
  if (this.validator) {
715
- dist_xstateActors.assertValid(this.validator, {
718
+ validation.assertValid(this.validator, {
716
719
  kind: 'event',
717
720
  logic: this,
718
721
  event,
@@ -730,7 +733,7 @@ class StateMachine {
730
733
  }
731
734
  const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? createActor.attachSnapshotActorRef(resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
732
735
  if (this.validator) {
733
- dist_xstateActors.assertValid(this.validator, {
736
+ validation.assertValid(this.validator, {
734
737
  kind: 'result',
735
738
  logic: this,
736
739
  snapshot: returnedSnapshot,
@@ -749,7 +752,7 @@ class StateMachine {
749
752
  const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : createActor.attachSnapshotActorRef(resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
750
753
  const effects = this._collectEffects(microsteps);
751
754
  if (this.validator) {
752
- dist_xstateActors.assertValid(this.validator, {
755
+ validation.assertValid(this.validator, {
753
756
  kind: 'result',
754
757
  logic: this,
755
758
  snapshot: returnedSnapshot,
@@ -941,7 +944,7 @@ class StateMachine {
941
944
  }
942
945
  initialTransition(input, actorScope) {
943
946
  if (this.validator) {
944
- dist_xstateActors.assertValid(this.validator, {
947
+ validation.assertValid(this.validator, {
945
948
  kind: 'input',
946
949
  logic: this,
947
950
  input
@@ -961,7 +964,7 @@ class StateMachine {
961
964
  const returnedSnapshot = usesInertScope ? createActor.attachSnapshotActorRef(resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope, true);
962
965
  const effects = this._collectEffects(microsteps);
963
966
  if (this.validator) {
964
- dist_xstateActors.assertValid(this.validator, {
967
+ validation.assertValid(this.validator, {
965
968
  kind: 'result',
966
969
  logic: this,
967
970
  snapshot: returnedSnapshot,
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-6736cbbe.development.cjs.js');
4
- var dist_xstateActors = require('./index-0f498ef2.development.cjs.js');
3
+ var createActor = require('./createActor-a1e0dffb.development.cjs.js');
4
+ var validation = require('./validation-f2714a35.development.cjs.js');
5
5
 
6
6
  function createSpawner(actorScope, actors, spawnedChildren) {
7
7
  return (src, options) => {
@@ -405,14 +405,17 @@ function formatTransitions(stateNode) {
405
405
  function formatInitialTransition(stateNode, _target) {
406
406
  const targetString = typeof _target === 'object' && _target !== null ? _target.target : _target;
407
407
  const input = typeof _target === 'object' && _target !== null ? _target.input : undefined;
408
- const resolvedTarget = typeof targetString === 'string' ? stateNode.states[targetString] : undefined;
409
- if (!resolvedTarget && targetString) {
410
- throw new Error(`Initial state node "${targetString}" not found on parent state node #${stateNode.id}` );
408
+ const to = typeof _target === 'object' && _target !== null ? _target.to : undefined;
409
+ const targetStrings = Array.isArray(targetString) ? targetString : targetString ? [targetString] : [];
410
+ const resolvedTargets = targetStrings.map(target => target.startsWith('#') ? stateNode.machine.getStateNodeById(target.slice(1)) : stateNode.states[target]);
411
+ if (resolvedTargets.some(target => !target)) {
412
+ throw new Error(`Initial state node "${targetStrings.find((_, index) => !resolvedTargets[index])}" not found on parent state node #${stateNode.id}` );
411
413
  }
412
414
  const transition = {
413
415
  source: stateNode,
414
- target: resolvedTarget ? [resolvedTarget] : undefined,
415
- input
416
+ target: resolvedTargets.length ? resolvedTargets : undefined,
417
+ input,
418
+ to
416
419
  };
417
420
  return transition;
418
421
  }
@@ -741,7 +744,7 @@ class StateMachine {
741
744
  const usesInertScope = !actorScope;
742
745
  const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this, snapshot);
743
746
  if (this.validator) {
744
- dist_xstateActors.assertValid(this.validator, {
747
+ validation.assertValid(this.validator, {
745
748
  kind: 'event',
746
749
  logic: this,
747
750
  event,
@@ -759,7 +762,7 @@ class StateMachine {
759
762
  }
760
763
  const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? createActor.attachSnapshotActorRef(resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
761
764
  if (this.validator) {
762
- dist_xstateActors.assertValid(this.validator, {
765
+ validation.assertValid(this.validator, {
763
766
  kind: 'result',
764
767
  logic: this,
765
768
  snapshot: returnedSnapshot,
@@ -778,7 +781,7 @@ class StateMachine {
778
781
  const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : createActor.attachSnapshotActorRef(resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
779
782
  const effects = this._collectEffects(microsteps);
780
783
  if (this.validator) {
781
- dist_xstateActors.assertValid(this.validator, {
784
+ validation.assertValid(this.validator, {
782
785
  kind: 'result',
783
786
  logic: this,
784
787
  snapshot: returnedSnapshot,
@@ -970,7 +973,7 @@ class StateMachine {
970
973
  }
971
974
  initialTransition(input, actorScope) {
972
975
  if (this.validator) {
973
- dist_xstateActors.assertValid(this.validator, {
976
+ validation.assertValid(this.validator, {
974
977
  kind: 'input',
975
978
  logic: this,
976
979
  input
@@ -990,7 +993,7 @@ class StateMachine {
990
993
  const returnedSnapshot = usesInertScope ? createActor.attachSnapshotActorRef(resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope, true);
991
994
  const effects = this._collectEffects(microsteps);
992
995
  if (this.validator) {
993
- dist_xstateActors.assertValid(this.validator, {
996
+ validation.assertValid(this.validator, {
994
997
  kind: 'result',
995
998
  logic: this,
996
999
  snapshot: returnedSnapshot,
@@ -1,5 +1,5 @@
1
- import { Q as resolveRegisteredActorSource, R as allocateChildId, S as assertChildIdFree, T as reserveChildId, U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, x as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, aa as createInertActorScope, ab as setInertActorScopeSnapshot, a as beginSpawnAllocation, ac as attachSnapshotActorRef, ad as macrostep, ae as isInertActorScope, af as setSnapshotActorRef, ag as cloneMachineSnapshot, ah as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ai as getTransitionResult, aj as hasEffect, ak as createErrorPlatformEvent, al as withActorSelf, r as resolveActionsWithContext, am as takeSpawnAllocationCounters, an as mergeActorIdCounters, K as createInitEvent, ao as createSpawnEffect, ap as initialMicrostep, aq as toStatePath, ar as isStateId, as as getStateNodeByPath, at as getPersistedSnapshot, au as createRemoteActorRef, av as resolveReferencedActor, aw as createInvokeTimeoutEvent, ax as parseGeneratedActorId, ay as ACTOR_REF_TYPE, k as createActor } from './createActor-915ea40c.esm.js';
2
- import { g as assertValid } from './index-b051c924.esm.js';
1
+ import { L as resolveRegisteredActorSource, M as allocateChildId, N as assertChildIdFree, O as reserveChildId, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, T as getEventDescriptorKey, U as getCandidates, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as matchesActorSession, a0 as formatRouteTransitions, a1 as resolveStateValue, a2 as getAllStateNodes, f as getStateNodes, a3 as createMachineSnapshot, a4 as isInFinalState, a5 as createInertActorScope, a6 as setInertActorScopeSnapshot, a7 as beginSpawnAllocation, a8 as attachSnapshotActorRef, a9 as macrostep, aa as isInertActorScope, ab as setSnapshotActorRef, ac as cloneMachineSnapshot, ad as transitionNode, J as XSTATE_TIMER, m as matchesEventDescriptor, ae as getTransitionResult, af as hasEffect, ag as createErrorPlatformEvent, ah as withActorSelf, ai as resolveActionsWithContext, aj as takeSpawnAllocationCounters, ak as mergeActorIdCounters, y as createInitEvent, al as createSpawnEffect, am as initialMicrostep, an as toStatePath, ao as isStateId, ap as getStateNodeByPath, aq as getPersistedSnapshot, ar as createRemoteActorRef, as as resolveReferencedActor, at as createInvokeTimeoutEvent, au as parseGeneratedActorId, av as ACTOR_REF_TYPE, c as createActor } from './createActor-268165d4.esm.js';
2
+ import { a as assertValid } from './validation-05f1d517.esm.js';
3
3
 
4
4
  function createSpawner(actorScope, actors, spawnedChildren) {
5
5
  return (src, options) => {
@@ -385,14 +385,17 @@ function formatTransitions(stateNode) {
385
385
  function formatInitialTransition(stateNode, _target) {
386
386
  const targetString = typeof _target === 'object' && _target !== null ? _target.target : _target;
387
387
  const input = typeof _target === 'object' && _target !== null ? _target.input : undefined;
388
- const resolvedTarget = typeof targetString === 'string' ? stateNode.states[targetString] : undefined;
389
- if (!resolvedTarget && targetString) {
390
- throw new Error(`Initial state "${targetString}" not found on "#${stateNode.id}"`);
388
+ const to = typeof _target === 'object' && _target !== null ? _target.to : undefined;
389
+ const targetStrings = Array.isArray(targetString) ? targetString : targetString ? [targetString] : [];
390
+ const resolvedTargets = targetStrings.map(target => target.startsWith('#') ? stateNode.machine.getStateNodeById(target.slice(1)) : stateNode.states[target]);
391
+ if (resolvedTargets.some(target => !target)) {
392
+ throw new Error(`Initial state not found on "#${stateNode.id}"`);
391
393
  }
392
394
  const transition = {
393
395
  source: stateNode,
394
- target: resolvedTarget ? [resolvedTarget] : undefined,
395
- input
396
+ target: resolvedTargets.length ? resolvedTargets : undefined,
397
+ input,
398
+ to
396
399
  };
397
400
  return transition;
398
401
  }
@@ -1,5 +1,5 @@
1
- import { Q as resolveRegisteredActorSource, R as allocateChildId, S as assertChildIdFree, T as reserveChildId, U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, x as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, aa as createInertActorScope, ab as setInertActorScopeSnapshot, a as beginSpawnAllocation, ac as attachSnapshotActorRef, ad as macrostep, ae as isInertActorScope, af as setSnapshotActorRef, ag as cloneMachineSnapshot, ah as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ai as getTransitionResult, aj as hasEffect, ak as createErrorPlatformEvent, al as withActorSelf, r as resolveActionsWithContext, am as takeSpawnAllocationCounters, an as mergeActorIdCounters, K as createInitEvent, ao as createSpawnEffect, ap as initialMicrostep, aq as toStatePath, ar as isStateId, as as getStateNodeByPath, at as getPersistedSnapshot, au as createRemoteActorRef, av as resolveReferencedActor, aw as createInvokeTimeoutEvent, ax as parseGeneratedActorId, ay as ACTOR_REF_TYPE, k as createActor } from './createActor-ff132afa.development.esm.js';
2
- import { g as assertValid } from './index-70d56425.development.esm.js';
1
+ import { L as resolveRegisteredActorSource, M as allocateChildId, N as assertChildIdFree, O as reserveChildId, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, T as getEventDescriptorKey, U as getCandidates, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as matchesActorSession, a0 as formatRouteTransitions, a1 as resolveStateValue, a2 as getAllStateNodes, f as getStateNodes, a3 as createMachineSnapshot, a4 as isInFinalState, a5 as createInertActorScope, a6 as setInertActorScopeSnapshot, a7 as beginSpawnAllocation, a8 as attachSnapshotActorRef, a9 as macrostep, aa as isInertActorScope, ab as setSnapshotActorRef, ac as cloneMachineSnapshot, ad as transitionNode, J as XSTATE_TIMER, m as matchesEventDescriptor, ae as getTransitionResult, af as hasEffect, ag as createErrorPlatformEvent, ah as withActorSelf, ai as resolveActionsWithContext, aj as takeSpawnAllocationCounters, ak as mergeActorIdCounters, y as createInitEvent, al as createSpawnEffect, am as initialMicrostep, an as toStatePath, ao as isStateId, ap as getStateNodeByPath, aq as getPersistedSnapshot, ar as createRemoteActorRef, as as resolveReferencedActor, at as createInvokeTimeoutEvent, au as parseGeneratedActorId, av as ACTOR_REF_TYPE, c as createActor } from './createActor-88709f74.development.esm.js';
2
+ import { a as assertValid } from './validation-e69470ad.development.esm.js';
3
3
 
4
4
  function createSpawner(actorScope, actors, spawnedChildren) {
5
5
  return (src, options) => {
@@ -403,14 +403,17 @@ function formatTransitions(stateNode) {
403
403
  function formatInitialTransition(stateNode, _target) {
404
404
  const targetString = typeof _target === 'object' && _target !== null ? _target.target : _target;
405
405
  const input = typeof _target === 'object' && _target !== null ? _target.input : undefined;
406
- const resolvedTarget = typeof targetString === 'string' ? stateNode.states[targetString] : undefined;
407
- if (!resolvedTarget && targetString) {
408
- throw new Error(`Initial state node "${targetString}" not found on parent state node #${stateNode.id}` );
406
+ const to = typeof _target === 'object' && _target !== null ? _target.to : undefined;
407
+ const targetStrings = Array.isArray(targetString) ? targetString : targetString ? [targetString] : [];
408
+ const resolvedTargets = targetStrings.map(target => target.startsWith('#') ? stateNode.machine.getStateNodeById(target.slice(1)) : stateNode.states[target]);
409
+ if (resolvedTargets.some(target => !target)) {
410
+ throw new Error(`Initial state node "${targetStrings.find((_, index) => !resolvedTargets[index])}" not found on parent state node #${stateNode.id}` );
409
411
  }
410
412
  const transition = {
411
413
  source: stateNode,
412
- target: resolvedTarget ? [resolvedTarget] : undefined,
413
- input
414
+ target: resolvedTargets.length ? resolvedTargets : undefined,
415
+ input,
416
+ to
414
417
  };
415
418
  return transition;
416
419
  }
@@ -2280,7 +2280,8 @@ function resolveHistoryDefaultTransition(stateNode) {
2280
2280
  target,
2281
2281
  source: stateNode,
2282
2282
  reenter: false,
2283
- eventType: ''
2283
+ eventType: '',
2284
+ to: stateNode.config._historyDefaultTransition
2284
2285
  };
2285
2286
  }
2286
2287
  function isHistoryNode(stateNode) {
@@ -2294,7 +2295,9 @@ function getInitialStateNodes(stateNode) {
2294
2295
  }
2295
2296
  set.add(descStateNode);
2296
2297
  if (descStateNode.type === 'compound') {
2297
- iter(descStateNode.initial.target[0]);
2298
+ for (const target of descStateNode.initial.target ?? []) {
2299
+ iter(target);
2300
+ }
2298
2301
  } else if (descStateNode.type === 'parallel') {
2299
2302
  for (const child of getChildren(descStateNode)) {
2300
2303
  iter(child);
@@ -2547,6 +2550,18 @@ function getTransitionDomain(transition, snapshot, resolveTransition) {
2547
2550
  targets,
2548
2551
  reenter
2549
2552
  } = resolveTransition(transition);
2553
+ if (transition._transitionDomain) {
2554
+ if (transition._transitionDomain === 'internal' && transition.source.type === 'compound' && targetStates.every(target => isDescendant(target, transition.source))) {
2555
+ return transition.source;
2556
+ }
2557
+ const [head, ...tail] = targetStates.concat(transition.source);
2558
+ for (const ancestor of getProperAncestors(head, undefined)) {
2559
+ if (ancestor.type === 'compound' && tail.every(stateNode => isDescendant(stateNode, ancestor))) {
2560
+ return ancestor;
2561
+ }
2562
+ }
2563
+ return;
2564
+ }
2550
2565
 
2551
2566
  // A history target that restores the source itself must exit and reenter
2552
2567
  // the source (SCXML domain = the source's ancestor), unlike a plain
@@ -2599,12 +2614,28 @@ function computeExitSet(transitions, stateNodeSet, snapshot, resolveTransition)
2599
2614
  return [...statesToExit];
2600
2615
  }
2601
2616
  function initialMicrostep(root, preInitialState, actorScope, initEvent, internalQueue) {
2617
+ const initialStateNodes = [...getInitialStateNodes(root)];
2618
+ const statesForDefaultEntry = new Set();
2619
+ const collectDefaultEntryStates = stateNode => {
2620
+ if (stateNode.type === 'compound') {
2621
+ statesForDefaultEntry.add(stateNode);
2622
+ for (const target of stateNode.initial.target ?? []) {
2623
+ collectDefaultEntryStates(target);
2624
+ }
2625
+ } else if (stateNode.type === 'parallel') {
2626
+ for (const child of getChildren(stateNode)) {
2627
+ collectDefaultEntryStates(child);
2628
+ }
2629
+ }
2630
+ };
2631
+ collectDefaultEntryStates(root);
2602
2632
  return microstep([{
2603
- target: [...getInitialStateNodes(root)],
2633
+ target: initialStateNodes.filter(stateNode => !initialStateNodes.some(other => other !== stateNode && isDescendant(other, stateNode))),
2604
2634
  source: root,
2605
2635
  reenter: true,
2606
2636
  eventType: null,
2607
- toJSON: null
2637
+ toJSON: null,
2638
+ _statesForDefaultEntry: [...statesForDefaultEntry]
2608
2639
  }], preInitialState, actorScope, initEvent, true, internalQueue);
2609
2640
  }
2610
2641
 
@@ -2783,6 +2814,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2783
2814
  // in other words, those are states for which initial actions should be executed
2784
2815
  // when we target `#deep_child` initial actions of its ancestors shouldn't be executed
2785
2816
  const statesForDefaultEntry = new Set();
2817
+ const historyDefaultsByParent = new Map();
2786
2818
  const addAncestorStatesToEnter = (ancestors, reentrancyDomain) => {
2787
2819
  for (const anc of ancestors) {
2788
2820
  if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
@@ -2811,6 +2843,11 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2811
2843
  }
2812
2844
  } else {
2813
2845
  const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
2846
+ const historyParent = stateNode.parent;
2847
+ statesForDefaultEntry.add(historyParent);
2848
+ const defaults = historyDefaultsByParent.get(historyParent) ?? [];
2849
+ defaults.push(historyDefaultTransition);
2850
+ historyDefaultsByParent.set(historyParent, defaults);
2814
2851
  const {
2815
2852
  targets
2816
2853
  } = getCurrentTransitionResult(historyDefaultTransition);
@@ -2828,13 +2865,19 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2828
2865
  return;
2829
2866
  }
2830
2867
  if (stateNode.type === 'compound') {
2831
- const [initialState] = getCurrentTransitionResult(stateNode.initial).targets;
2832
- if (!isHistoryNode(initialState)) {
2833
- statesToEnter.add(initialState);
2834
- statesForDefaultEntry.add(initialState);
2868
+ const initialStates = getCurrentTransitionResult(stateNode.initial).targets ?? [];
2869
+ for (const initialState of initialStates) {
2870
+ if (!isHistoryNode(initialState)) {
2871
+ statesToEnter.add(initialState);
2872
+ }
2873
+ }
2874
+ statesForDefaultEntry.add(stateNode);
2875
+ for (const initialState of initialStates) {
2876
+ addDescendantStatesToEnter(initialState);
2877
+ }
2878
+ for (const initialState of initialStates) {
2879
+ addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
2835
2880
  }
2836
- addDescendantStatesToEnter(initialState);
2837
- addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
2838
2881
  return;
2839
2882
  }
2840
2883
  if (stateNode.type === 'parallel') {
@@ -2876,7 +2919,9 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2876
2919
  }
2877
2920
  }
2878
2921
  if (isInitial) {
2879
- statesForDefaultEntry.add(currentSnapshot.machine.root);
2922
+ for (const stateNode of filteredTransitions[0]._statesForDefaultEntry ?? [currentSnapshot.machine.root]) {
2923
+ statesForDefaultEntry.add(stateNode);
2924
+ }
2880
2925
  }
2881
2926
  const stateInputMap = {
2882
2927
  ...currentSnapshot._stateInputs
@@ -2961,17 +3006,28 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2961
3006
  nextState.context = context;
2962
3007
  }
2963
3008
  if (statesForDefaultEntry.has(stateNodeToEnter)) {
2964
- const {
2965
- actions: initialActions,
2966
- input: initialInput
2967
- } = getTransitionResult(stateNodeToEnter.initial, nextState, event, actorScope);
2968
- if (initialActions) {
2969
- actions.push(...initialActions);
2970
- }
2971
- if (initialInput && stateNodeToEnter.initial?.target) {
2972
- for (const targetNode of stateNodeToEnter.initial.target) {
2973
- stateInputMap[targetNode.id] = initialInput;
2974
- stateInputsChanged = true;
3009
+ const defaultTransitions = [stateNodeToEnter.initial, ...(historyDefaultsByParent.get(stateNodeToEnter) ?? [])].filter(Boolean);
3010
+ for (const defaultTransition of defaultTransitions) {
3011
+ const {
3012
+ actions: initialActions,
3013
+ context: initialContext,
3014
+ input: initialInput,
3015
+ internalEvents: initialInternalEvents
3016
+ } = getTransitionResult(defaultTransition, nextState, event, actorScope);
3017
+ if (initialActions) {
3018
+ actions.push(...initialActions);
3019
+ }
3020
+ if (initialInternalEvents?.length) {
3021
+ internalQueue.push(...initialInternalEvents);
3022
+ }
3023
+ if (initialContext !== undefined) {
3024
+ nextState.context = mergeContextPatch(nextState.context, initialContext);
3025
+ }
3026
+ if (initialInput && defaultTransition.target) {
3027
+ for (const targetNode of defaultTransition.target) {
3028
+ stateInputMap[targetNode.id] = initialInput;
3029
+ stateInputsChanged = true;
3030
+ }
2975
3031
  }
2976
3032
  }
2977
3033
  }
@@ -5699,4 +5755,4 @@ function createActor(logic, options) {
5699
5755
  return new Actor(logic, options);
5700
5756
  }
5701
5757
 
5702
- export { evaluateCandidate as $, Actor as A, checkStateIn as B, pathToStateValue as C, toObserver as D, executeEffects as E, isBuiltInExecutableAction as F, deliverEvent as G, runStep as H, stopActor as I, terminateActor as J, createInitEvent as K, createCustomEffect as L, XSTATE_LOGIC_EFFECT_START as M, XSTATE_LOGIC_EFFECT_RESOLVE as N, XSTATE_LOGIC_EFFECT_REJECT as O, createEmitEffect as P, resolveRegisteredActorSource as Q, allocateChildId as R, assertChildIdFree as S, reserveChildId as T, STATE_DELIMITER as U, mapValues as V, createInvokeId as W, XSTATE_INIT as X, getDelayedTransitions as Y, getEventDescriptorKey as Z, getCandidates as _, beginSpawnAllocation as a, formatTransition as a0, NULL_EVENT as a1, toTransitionConfigArray as a2, createInvokeTimeoutEventId as a3, matchesActorSession as a4, formatRouteTransitions as a5, resolveStateValue as a6, getAllStateNodes as a7, createMachineSnapshot as a8, isInFinalState as a9, getProperAncestors as aA, isRemoteActorRef as aB, getActorIdPrefix as aC, getAllOwnEvents as aD, matchesEvent as aE, encodeAddressSegment as aF, getRootActorId as aG, RUNTIME_OPERATIONS as aH, withSystemInspector as aI, getSnapshotActorRef as aJ, withExecutionIdentity as aK, createInertActorScope as aa, setInertActorScopeSnapshot as ab, attachSnapshotActorRef as ac, macrostep as ad, isInertActorScope as ae, setSnapshotActorRef as af, cloneMachineSnapshot as ag, transitionNode as ah, getTransitionResult as ai, hasEffect as aj, createErrorPlatformEvent as ak, withActorSelf as al, takeSpawnAllocationCounters as am, mergeActorIdCounters as an, createSpawnEffect as ao, initialMicrostep as ap, toStatePath as aq, isStateId as ar, getStateNodeByPath as as, getPersistedSnapshot as at, createRemoteActorRef as au, resolveReferencedActor as av, createInvokeTimeoutEvent as aw, parseGeneratedActorId as ax, ACTOR_REF_TYPE as ay, hasAmbientInspector as az, builtInActions as b, createTransitionEnqueue as c, deriveDeferredStarts as d, XSTATE_STOP as e, finalizeTransitionResult as f, XSTATE_TIMER as g, createSendToEffect as h, isLazyActorScope as i, isAtomicStateNode as j, createActor as k, createListenerLogic as l, matchesEventDescriptor as m, createSubscriptionLogic as n, listenerLogic as o, parseDelayToMilliseconds as p, getInitialSnapshot as q, resolveActionsWithContext as r, subscriptionLogic as s, toArray as t, getNextSnapshot as u, isMachineSnapshot as v, withActorScope as w, getStateNodes as x, getAllOwnEventDescriptors as y, matchesState as z };
5758
+ export { matchesActorSession as $, Actor as A, XSTATE_LOGIC_EFFECT_START as B, XSTATE_LOGIC_EFFECT_RESOLVE as C, XSTATE_LOGIC_EFFECT_REJECT as D, finalizeTransitionResult as E, createEmitEffect as F, createSendToEffect as G, XSTATE_INIT as H, withActorScope as I, XSTATE_TIMER as J, isLazyActorScope as K, resolveRegisteredActorSource as L, allocateChildId as M, assertChildIdFree as N, reserveChildId as O, mapValues as P, createInvokeId as Q, getDelayedTransitions as R, STATE_DELIMITER as S, getEventDescriptorKey as T, getCandidates as U, evaluateCandidate as V, formatTransition as W, XSTATE_STOP as X, NULL_EVENT as Y, toTransitionConfigArray as Z, createInvokeTimeoutEventId as _, createListenerLogic as a, formatRouteTransitions as a0, resolveStateValue as a1, getAllStateNodes as a2, createMachineSnapshot as a3, isInFinalState as a4, createInertActorScope as a5, setInertActorScopeSnapshot as a6, beginSpawnAllocation as a7, attachSnapshotActorRef as a8, macrostep as a9, getAllOwnEvents as aA, matchesEvent as aB, encodeAddressSegment as aC, getRootActorId as aD, RUNTIME_OPERATIONS as aE, withSystemInspector as aF, getSnapshotActorRef as aG, withExecutionIdentity as aH, isInertActorScope as aa, setSnapshotActorRef as ab, cloneMachineSnapshot as ac, transitionNode as ad, getTransitionResult as ae, hasEffect as af, createErrorPlatformEvent as ag, withActorSelf as ah, resolveActionsWithContext as ai, takeSpawnAllocationCounters as aj, mergeActorIdCounters as ak, createSpawnEffect as al, initialMicrostep as am, toStatePath as an, isStateId as ao, getStateNodeByPath as ap, getPersistedSnapshot as aq, createRemoteActorRef as ar, resolveReferencedActor as as, createInvokeTimeoutEvent as at, parseGeneratedActorId as au, ACTOR_REF_TYPE as av, hasAmbientInspector as aw, getProperAncestors as ax, isRemoteActorRef as ay, getActorIdPrefix as az, createSubscriptionLogic as b, createActor as c, getNextSnapshot as d, isMachineSnapshot as e, getStateNodes as f, getInitialSnapshot as g, getAllOwnEventDescriptors as h, isAtomicStateNode as i, matchesState as j, checkStateIn as k, listenerLogic as l, matchesEventDescriptor as m, pathToStateValue as n, toObserver as o, parseDelayToMilliseconds as p, executeEffects as q, isBuiltInExecutableAction as r, subscriptionLogic as s, toArray as t, deliverEvent as u, runStep as v, stopActor as w, terminateActor as x, createInitEvent as y, createCustomEffect as z };