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.
- package/README.md +30 -1
- package/dist/{StateMachine-7046f677.cjs.js → StateMachine-0adb3a70.cjs.js} +15 -12
- package/dist/{StateMachine-70c06bdd.development.cjs.js → StateMachine-29450e6d.development.cjs.js} +15 -12
- package/dist/{StateMachine-74929087.esm.js → StateMachine-2af31c11.esm.js} +10 -7
- package/dist/{StateMachine-ee10f67e.development.esm.js → StateMachine-faf50c5c.development.esm.js} +10 -7
- package/dist/{createActor-915ea40c.esm.js → createActor-268165d4.esm.js} +79 -23
- package/dist/{createActor-ff132afa.development.esm.js → createActor-88709f74.development.esm.js} +79 -23
- package/dist/{createActor-6736cbbe.development.cjs.js → createActor-a1e0dffb.development.cjs.js} +78 -25
- package/dist/{createActor-bfe8b6bd.cjs.js → createActor-b4dd05ae.cjs.js} +78 -25
- package/dist/declarations/src/createMachineFromConfig.d.ts +5 -77
- package/dist/declarations/src/fsm/createFSMActor.d.ts +67 -0
- package/dist/declarations/src/fsm/index.d.ts +2 -0
- package/dist/declarations/src/fsm.d.ts +5 -4
- package/dist/declarations/src/scxml/index.d.ts +1 -0
- package/dist/declarations/src/scxml/runtime.d.ts +251 -0
- package/dist/declarations/src/scxml/scxml.d.ts +19 -0
- package/dist/declarations/src/types.d.ts +1 -0
- package/dist/{effectDescriptor-8be60443.esm.js → effectDescriptor-30c9a744.esm.js} +1 -1
- package/dist/{effectDescriptor-fbe67d5a.development.esm.js → effectDescriptor-39d22100.development.esm.js} +1 -1
- package/dist/{effectDescriptor-3c699328.development.cjs.js → effectDescriptor-7ff6802f.development.cjs.js} +1 -1
- package/dist/{effectDescriptor-a7e2d4d1.cjs.js → effectDescriptor-be348e50.cjs.js} +1 -1
- package/dist/fsm-7a2e9697.cjs.js +777 -0
- package/dist/fsm-b804b3e9.esm.js +775 -0
- package/dist/fsm-c1316948.development.cjs.js +777 -0
- package/dist/fsm-e18a7cb4.development.esm.js +775 -0
- package/dist/types-3c3455f7.esm.js +185 -0
- package/dist/types-adda3842.development.esm.js +185 -0
- package/dist/types-b3fea5bd.development.cjs.js +189 -0
- package/dist/types-fbabaeee.cjs.js +189 -0
- package/dist/validation-05f1d517.esm.js +8 -0
- package/dist/validation-4561b43c.cjs.js +10 -0
- package/dist/validation-e69470ad.development.esm.js +8 -0
- package/dist/validation-f2714a35.development.cjs.js +10 -0
- package/dist/xstate-actors.cjs.js +934 -9
- package/dist/xstate-actors.development.cjs.js +934 -9
- package/dist/xstate-actors.development.esm.js +932 -2
- package/dist/xstate-actors.esm.js +932 -2
- package/dist/xstate-durable.cjs.js +2 -2
- package/dist/xstate-durable.development.cjs.js +2 -2
- package/dist/xstate-durable.development.esm.js +2 -2
- package/dist/xstate-durable.esm.js +2 -2
- package/dist/xstate-fsm.cjs.d.mts +2 -0
- package/dist/xstate-fsm.cjs.d.ts +2 -0
- package/dist/xstate-fsm.cjs.js +409 -0
- package/dist/xstate-fsm.cjs.mjs +5 -0
- package/dist/xstate-fsm.development.cjs.js +409 -0
- package/dist/xstate-fsm.development.cjs.mjs +5 -0
- package/dist/xstate-fsm.development.esm.js +403 -0
- package/dist/xstate-fsm.esm.js +403 -0
- package/dist/xstate-fsm.umd.min.js +2 -0
- package/dist/xstate-fsm.umd.min.js.map +1 -0
- package/dist/xstate-graph.cjs.js +4 -3
- package/dist/xstate-graph.development.cjs.js +4 -3
- package/dist/xstate-graph.development.esm.js +4 -3
- package/dist/xstate-graph.esm.js +4 -3
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-scxml.cjs.d.mts +2 -0
- package/dist/xstate-scxml.cjs.d.ts +2 -0
- package/dist/xstate-scxml.cjs.js +2387 -0
- package/dist/xstate-scxml.cjs.mjs +3 -0
- package/dist/xstate-scxml.development.cjs.js +2387 -0
- package/dist/xstate-scxml.development.cjs.mjs +3 -0
- package/dist/xstate-scxml.development.esm.js +2383 -0
- package/dist/xstate-scxml.esm.js +2383 -0
- package/dist/xstate-scxml.umd.min.js +26 -0
- package/dist/xstate-scxml.umd.min.js.map +1 -0
- package/dist/xstate-validation.cjs.js +1 -1
- package/dist/xstate-validation.development.cjs.js +1 -1
- package/dist/xstate-validation.development.esm.js +1 -1
- package/dist/xstate-validation.esm.js +1 -1
- package/dist/xstate.cjs.js +143 -1412
- package/dist/xstate.development.cjs.js +143 -1412
- package/dist/xstate.development.esm.js +143 -1411
- package/dist/xstate.esm.js +143 -1411
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/fsm/package.json +8 -0
- package/package.json +37 -3
- package/scxml/package.json +8 -0
- package/dist/index-0f498ef2.development.cjs.js +0 -946
- package/dist/index-70d56425.development.esm.js +0 -937
- package/dist/index-b051c924.esm.js +0 -937
- 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
|
-
|
|
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-
|
|
4
|
-
var
|
|
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
|
|
391
|
-
|
|
392
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
967
|
+
validation.assertValid(this.validator, {
|
|
965
968
|
kind: 'result',
|
|
966
969
|
logic: this,
|
|
967
970
|
snapshot: returnedSnapshot,
|
package/dist/{StateMachine-70c06bdd.development.cjs.js → StateMachine-29450e6d.development.cjs.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
4
|
-
var
|
|
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
|
|
409
|
-
|
|
410
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
996
|
+
validation.assertValid(this.validator, {
|
|
994
997
|
kind: 'result',
|
|
995
998
|
logic: this,
|
|
996
999
|
snapshot: returnedSnapshot,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
|
389
|
-
|
|
390
|
-
|
|
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:
|
|
395
|
-
input
|
|
396
|
+
target: resolvedTargets.length ? resolvedTargets : undefined,
|
|
397
|
+
input,
|
|
398
|
+
to
|
|
396
399
|
};
|
|
397
400
|
return transition;
|
|
398
401
|
}
|
package/dist/{StateMachine-ee10f67e.development.esm.js → StateMachine-faf50c5c.development.esm.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
|
407
|
-
|
|
408
|
-
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
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 {
|
|
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 };
|