xstate 5.0.0-beta.35 → 5.0.0-beta.37
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/actions/dist/xstate-actions.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +0 -1
- package/dist/declarations/src/stateUtils.d.ts +3 -3
- package/dist/declarations/src/typegenTypes.d.ts +2 -0
- package/dist/declarations/src/types.d.ts +1 -2
- package/dist/declarations/src/utils.d.ts +6 -6
- package/dist/declarations/src/waitFor.d.ts +1 -1
- package/dist/{interpreter-5c4e6634.development.esm.js → interpreter-1c52b23c.development.esm.js} +13 -23
- package/dist/{interpreter-de5217bc.esm.js → interpreter-8def682e.esm.js} +13 -23
- package/dist/{interpreter-69605bf0.cjs.js → interpreter-97aff8d2.cjs.js} +13 -23
- package/dist/{interpreter-d3567419.development.cjs.js → interpreter-e58ca48d.development.cjs.js} +13 -23
- package/dist/{raise-26e4d83c.development.cjs.js → raise-1fd59c65.development.cjs.js} +129 -102
- package/dist/{raise-511399cc.esm.js → raise-21c417c1.esm.js} +129 -102
- package/dist/{raise-0ff57677.cjs.js → raise-800296d7.cjs.js} +129 -102
- package/dist/{raise-cdcdf834.development.esm.js → raise-e342a840.development.esm.js} +129 -102
- package/dist/{send-19ffc568.cjs.js → send-4cc29786.cjs.js} +7 -4
- package/dist/{send-1de74f4d.development.esm.js → send-83ccc98b.development.esm.js} +7 -4
- package/dist/{send-211a2a94.esm.js → send-92854675.esm.js} +7 -4
- package/dist/{send-894c4b18.development.cjs.js → send-b309ef4e.development.cjs.js} +7 -4
- package/dist/xstate.cjs.js +11 -19
- package/dist/xstate.development.cjs.js +11 -19
- package/dist/xstate.development.esm.js +14 -22
- package/dist/xstate.esm.js +14 -22
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
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 interpreter = require('./interpreter-
|
|
7
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
8
|
-
var send = require('./send-
|
|
6
|
+
var interpreter = require('./interpreter-97aff8d2.cjs.js');
|
|
7
|
+
var guards_dist_xstateGuards = require('./raise-800296d7.cjs.js');
|
|
8
|
+
var send = require('./send-4cc29786.cjs.js');
|
|
9
9
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
10
10
|
|
|
11
11
|
class SimulatedClock {
|
|
@@ -255,15 +255,7 @@ class StateNode {
|
|
|
255
255
|
systemId
|
|
256
256
|
} = invokeConfig;
|
|
257
257
|
const resolvedId = invokeConfig.id || interpreter.createInvokeId(this.id, i);
|
|
258
|
-
|
|
259
|
-
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
260
|
-
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
261
|
-
this.machine.implementations.actors = {
|
|
262
|
-
...this.machine.implementations.actors,
|
|
263
|
-
// TODO: this should accept `src` as-is
|
|
264
|
-
[resolvedId]: src
|
|
265
|
-
};
|
|
266
|
-
}
|
|
258
|
+
const resolvedSrc = typeof src === 'string' ? src : `xstate#${interpreter.createInvokeId(this.id, i)}`;
|
|
267
259
|
return {
|
|
268
260
|
...invokeConfig,
|
|
269
261
|
src: resolvedSrc,
|
|
@@ -518,7 +510,7 @@ class StateMachine {
|
|
|
518
510
|
* The initial state _before_ evaluating any microsteps.
|
|
519
511
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
520
512
|
*/
|
|
521
|
-
getPreInitialState(actorCtx, initEvent) {
|
|
513
|
+
getPreInitialState(actorCtx, initEvent, internalQueue) {
|
|
522
514
|
const {
|
|
523
515
|
context
|
|
524
516
|
} = this.config;
|
|
@@ -539,7 +531,7 @@ class StateMachine {
|
|
|
539
531
|
spawn,
|
|
540
532
|
input: event.input
|
|
541
533
|
});
|
|
542
|
-
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorCtx, [send.assign(assignment)]);
|
|
534
|
+
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorCtx, [send.assign(assignment)], internalQueue);
|
|
543
535
|
}
|
|
544
536
|
return preInitial;
|
|
545
537
|
}
|
|
@@ -549,8 +541,8 @@ class StateMachine {
|
|
|
549
541
|
*/
|
|
550
542
|
getInitialState(actorCtx, input) {
|
|
551
543
|
const initEvent = interpreter.createInitEvent(input); // TODO: fix;
|
|
552
|
-
|
|
553
|
-
const preInitialState = this.getPreInitialState(actorCtx, initEvent);
|
|
544
|
+
const internalQueue = [];
|
|
545
|
+
const preInitialState = this.getPreInitialState(actorCtx, initEvent, internalQueue);
|
|
554
546
|
const nextState = guards_dist_xstateGuards.microstep([{
|
|
555
547
|
target: [...guards_dist_xstateGuards.getInitialStateNodes(this.root)],
|
|
556
548
|
source: this.root,
|
|
@@ -558,10 +550,10 @@ class StateMachine {
|
|
|
558
550
|
actions: [],
|
|
559
551
|
eventType: null,
|
|
560
552
|
toJSON: null // TODO: fix
|
|
561
|
-
}], preInitialState, actorCtx, initEvent, true);
|
|
553
|
+
}], preInitialState, actorCtx, initEvent, true, internalQueue);
|
|
562
554
|
const {
|
|
563
555
|
state: macroState
|
|
564
|
-
} = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorCtx);
|
|
556
|
+
} = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorCtx, internalQueue);
|
|
565
557
|
return macroState;
|
|
566
558
|
}
|
|
567
559
|
start(state) {
|
|
@@ -599,7 +591,7 @@ class StateMachine {
|
|
|
599
591
|
const actorData = snapshot.children[actorId];
|
|
600
592
|
const childState = actorData.state;
|
|
601
593
|
const src = actorData.src;
|
|
602
|
-
const logic = src ? interpreter.resolveReferencedActor(this
|
|
594
|
+
const logic = src ? interpreter.resolveReferencedActor(this, src)?.src : undefined;
|
|
603
595
|
if (!logic) {
|
|
604
596
|
return;
|
|
605
597
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var interpreter = require('./interpreter-
|
|
7
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
8
|
-
var send = require('./send-
|
|
6
|
+
var interpreter = require('./interpreter-e58ca48d.development.cjs.js');
|
|
7
|
+
var guards_dist_xstateGuards = require('./raise-1fd59c65.development.cjs.js');
|
|
8
|
+
var send = require('./send-b309ef4e.development.cjs.js');
|
|
9
9
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
10
10
|
|
|
11
11
|
class SimulatedClock {
|
|
@@ -255,15 +255,7 @@ class StateNode {
|
|
|
255
255
|
systemId
|
|
256
256
|
} = invokeConfig;
|
|
257
257
|
const resolvedId = invokeConfig.id || interpreter.createInvokeId(this.id, i);
|
|
258
|
-
|
|
259
|
-
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
260
|
-
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
261
|
-
this.machine.implementations.actors = {
|
|
262
|
-
...this.machine.implementations.actors,
|
|
263
|
-
// TODO: this should accept `src` as-is
|
|
264
|
-
[resolvedId]: src
|
|
265
|
-
};
|
|
266
|
-
}
|
|
258
|
+
const resolvedSrc = typeof src === 'string' ? src : `xstate#${interpreter.createInvokeId(this.id, i)}`;
|
|
267
259
|
return {
|
|
268
260
|
...invokeConfig,
|
|
269
261
|
src: resolvedSrc,
|
|
@@ -521,7 +513,7 @@ class StateMachine {
|
|
|
521
513
|
* The initial state _before_ evaluating any microsteps.
|
|
522
514
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
523
515
|
*/
|
|
524
|
-
getPreInitialState(actorCtx, initEvent) {
|
|
516
|
+
getPreInitialState(actorCtx, initEvent, internalQueue) {
|
|
525
517
|
const {
|
|
526
518
|
context
|
|
527
519
|
} = this.config;
|
|
@@ -542,7 +534,7 @@ class StateMachine {
|
|
|
542
534
|
spawn,
|
|
543
535
|
input: event.input
|
|
544
536
|
});
|
|
545
|
-
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorCtx, [send.assign(assignment)]);
|
|
537
|
+
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorCtx, [send.assign(assignment)], internalQueue);
|
|
546
538
|
}
|
|
547
539
|
return preInitial;
|
|
548
540
|
}
|
|
@@ -552,8 +544,8 @@ class StateMachine {
|
|
|
552
544
|
*/
|
|
553
545
|
getInitialState(actorCtx, input) {
|
|
554
546
|
const initEvent = interpreter.createInitEvent(input); // TODO: fix;
|
|
555
|
-
|
|
556
|
-
const preInitialState = this.getPreInitialState(actorCtx, initEvent);
|
|
547
|
+
const internalQueue = [];
|
|
548
|
+
const preInitialState = this.getPreInitialState(actorCtx, initEvent, internalQueue);
|
|
557
549
|
const nextState = guards_dist_xstateGuards.microstep([{
|
|
558
550
|
target: [...guards_dist_xstateGuards.getInitialStateNodes(this.root)],
|
|
559
551
|
source: this.root,
|
|
@@ -561,10 +553,10 @@ class StateMachine {
|
|
|
561
553
|
actions: [],
|
|
562
554
|
eventType: null,
|
|
563
555
|
toJSON: null // TODO: fix
|
|
564
|
-
}], preInitialState, actorCtx, initEvent, true);
|
|
556
|
+
}], preInitialState, actorCtx, initEvent, true, internalQueue);
|
|
565
557
|
const {
|
|
566
558
|
state: macroState
|
|
567
|
-
} = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorCtx);
|
|
559
|
+
} = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorCtx, internalQueue);
|
|
568
560
|
return macroState;
|
|
569
561
|
}
|
|
570
562
|
start(state) {
|
|
@@ -602,7 +594,7 @@ class StateMachine {
|
|
|
602
594
|
const actorData = snapshot.children[actorId];
|
|
603
595
|
const childState = actorData.state;
|
|
604
596
|
const src = actorData.src;
|
|
605
|
-
const logic = src ? interpreter.resolveReferencedActor(this
|
|
597
|
+
const logic = src ? interpreter.resolveReferencedActor(this, src)?.src : undefined;
|
|
606
598
|
if (!logic) {
|
|
607
599
|
return;
|
|
608
600
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, $ as $$ACTOR_TYPE, e as matchesState } from './interpreter-
|
|
3
|
-
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-
|
|
4
|
-
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as getInitialStateNodes, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-
|
|
5
|
-
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-
|
|
6
|
-
import { a as assign } from './send-
|
|
7
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, $ as $$ACTOR_TYPE, e as matchesState } from './interpreter-1c52b23c.development.esm.js';
|
|
3
|
+
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-1c52b23c.development.esm.js';
|
|
4
|
+
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as getInitialStateNodes, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-e342a840.development.esm.js';
|
|
5
|
+
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-e342a840.development.esm.js';
|
|
6
|
+
import { a as assign } from './send-83ccc98b.development.esm.js';
|
|
7
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-83ccc98b.development.esm.js';
|
|
8
8
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -254,15 +254,7 @@ class StateNode {
|
|
|
254
254
|
systemId
|
|
255
255
|
} = invokeConfig;
|
|
256
256
|
const resolvedId = invokeConfig.id || createInvokeId(this.id, i);
|
|
257
|
-
|
|
258
|
-
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
259
|
-
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
260
|
-
this.machine.implementations.actors = {
|
|
261
|
-
...this.machine.implementations.actors,
|
|
262
|
-
// TODO: this should accept `src` as-is
|
|
263
|
-
[resolvedId]: src
|
|
264
|
-
};
|
|
265
|
-
}
|
|
257
|
+
const resolvedSrc = typeof src === 'string' ? src : `xstate#${createInvokeId(this.id, i)}`;
|
|
266
258
|
return {
|
|
267
259
|
...invokeConfig,
|
|
268
260
|
src: resolvedSrc,
|
|
@@ -520,7 +512,7 @@ class StateMachine {
|
|
|
520
512
|
* The initial state _before_ evaluating any microsteps.
|
|
521
513
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
522
514
|
*/
|
|
523
|
-
getPreInitialState(actorCtx, initEvent) {
|
|
515
|
+
getPreInitialState(actorCtx, initEvent, internalQueue) {
|
|
524
516
|
const {
|
|
525
517
|
context
|
|
526
518
|
} = this.config;
|
|
@@ -541,7 +533,7 @@ class StateMachine {
|
|
|
541
533
|
spawn,
|
|
542
534
|
input: event.input
|
|
543
535
|
});
|
|
544
|
-
return resolveActionsAndContext(preInitial, initEvent, actorCtx, [assign(assignment)]);
|
|
536
|
+
return resolveActionsAndContext(preInitial, initEvent, actorCtx, [assign(assignment)], internalQueue);
|
|
545
537
|
}
|
|
546
538
|
return preInitial;
|
|
547
539
|
}
|
|
@@ -551,8 +543,8 @@ class StateMachine {
|
|
|
551
543
|
*/
|
|
552
544
|
getInitialState(actorCtx, input) {
|
|
553
545
|
const initEvent = createInitEvent(input); // TODO: fix;
|
|
554
|
-
|
|
555
|
-
const preInitialState = this.getPreInitialState(actorCtx, initEvent);
|
|
546
|
+
const internalQueue = [];
|
|
547
|
+
const preInitialState = this.getPreInitialState(actorCtx, initEvent, internalQueue);
|
|
556
548
|
const nextState = microstep([{
|
|
557
549
|
target: [...getInitialStateNodes(this.root)],
|
|
558
550
|
source: this.root,
|
|
@@ -560,10 +552,10 @@ class StateMachine {
|
|
|
560
552
|
actions: [],
|
|
561
553
|
eventType: null,
|
|
562
554
|
toJSON: null // TODO: fix
|
|
563
|
-
}], preInitialState, actorCtx, initEvent, true);
|
|
555
|
+
}], preInitialState, actorCtx, initEvent, true, internalQueue);
|
|
564
556
|
const {
|
|
565
557
|
state: macroState
|
|
566
|
-
} = macrostep(nextState, initEvent, actorCtx);
|
|
558
|
+
} = macrostep(nextState, initEvent, actorCtx, internalQueue);
|
|
567
559
|
return macroState;
|
|
568
560
|
}
|
|
569
561
|
start(state) {
|
|
@@ -601,7 +593,7 @@ class StateMachine {
|
|
|
601
593
|
const actorData = snapshot.children[actorId];
|
|
602
594
|
const childState = actorData.state;
|
|
603
595
|
const src = actorData.src;
|
|
604
|
-
const logic = src ? resolveReferencedActor(this
|
|
596
|
+
const logic = src ? resolveReferencedActor(this, src)?.src : undefined;
|
|
605
597
|
if (!logic) {
|
|
606
598
|
return;
|
|
607
599
|
}
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, $ as $$ACTOR_TYPE, e as matchesState } from './interpreter-
|
|
3
|
-
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-
|
|
4
|
-
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as getInitialStateNodes, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-
|
|
5
|
-
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-
|
|
6
|
-
import { a as assign } from './send-
|
|
7
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, $ as $$ACTOR_TYPE, e as matchesState } from './interpreter-8def682e.esm.js';
|
|
3
|
+
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-8def682e.esm.js';
|
|
4
|
+
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as getInitialStateNodes, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-21c417c1.esm.js';
|
|
5
|
+
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-21c417c1.esm.js';
|
|
6
|
+
import { a as assign } from './send-92854675.esm.js';
|
|
7
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-92854675.esm.js';
|
|
8
8
|
import '../dev/dist/xstate-dev.esm.js';
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -254,15 +254,7 @@ class StateNode {
|
|
|
254
254
|
systemId
|
|
255
255
|
} = invokeConfig;
|
|
256
256
|
const resolvedId = invokeConfig.id || createInvokeId(this.id, i);
|
|
257
|
-
|
|
258
|
-
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
259
|
-
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
260
|
-
this.machine.implementations.actors = {
|
|
261
|
-
...this.machine.implementations.actors,
|
|
262
|
-
// TODO: this should accept `src` as-is
|
|
263
|
-
[resolvedId]: src
|
|
264
|
-
};
|
|
265
|
-
}
|
|
257
|
+
const resolvedSrc = typeof src === 'string' ? src : `xstate#${createInvokeId(this.id, i)}`;
|
|
266
258
|
return {
|
|
267
259
|
...invokeConfig,
|
|
268
260
|
src: resolvedSrc,
|
|
@@ -517,7 +509,7 @@ class StateMachine {
|
|
|
517
509
|
* The initial state _before_ evaluating any microsteps.
|
|
518
510
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
519
511
|
*/
|
|
520
|
-
getPreInitialState(actorCtx, initEvent) {
|
|
512
|
+
getPreInitialState(actorCtx, initEvent, internalQueue) {
|
|
521
513
|
const {
|
|
522
514
|
context
|
|
523
515
|
} = this.config;
|
|
@@ -538,7 +530,7 @@ class StateMachine {
|
|
|
538
530
|
spawn,
|
|
539
531
|
input: event.input
|
|
540
532
|
});
|
|
541
|
-
return resolveActionsAndContext(preInitial, initEvent, actorCtx, [assign(assignment)]);
|
|
533
|
+
return resolveActionsAndContext(preInitial, initEvent, actorCtx, [assign(assignment)], internalQueue);
|
|
542
534
|
}
|
|
543
535
|
return preInitial;
|
|
544
536
|
}
|
|
@@ -548,8 +540,8 @@ class StateMachine {
|
|
|
548
540
|
*/
|
|
549
541
|
getInitialState(actorCtx, input) {
|
|
550
542
|
const initEvent = createInitEvent(input); // TODO: fix;
|
|
551
|
-
|
|
552
|
-
const preInitialState = this.getPreInitialState(actorCtx, initEvent);
|
|
543
|
+
const internalQueue = [];
|
|
544
|
+
const preInitialState = this.getPreInitialState(actorCtx, initEvent, internalQueue);
|
|
553
545
|
const nextState = microstep([{
|
|
554
546
|
target: [...getInitialStateNodes(this.root)],
|
|
555
547
|
source: this.root,
|
|
@@ -557,10 +549,10 @@ class StateMachine {
|
|
|
557
549
|
actions: [],
|
|
558
550
|
eventType: null,
|
|
559
551
|
toJSON: null // TODO: fix
|
|
560
|
-
}], preInitialState, actorCtx, initEvent, true);
|
|
552
|
+
}], preInitialState, actorCtx, initEvent, true, internalQueue);
|
|
561
553
|
const {
|
|
562
554
|
state: macroState
|
|
563
|
-
} = macrostep(nextState, initEvent, actorCtx);
|
|
555
|
+
} = macrostep(nextState, initEvent, actorCtx, internalQueue);
|
|
564
556
|
return macroState;
|
|
565
557
|
}
|
|
566
558
|
start(state) {
|
|
@@ -598,7 +590,7 @@ class StateMachine {
|
|
|
598
590
|
const actorData = snapshot.children[actorId];
|
|
599
591
|
const childState = actorData.state;
|
|
600
592
|
const src = actorData.src;
|
|
601
|
-
const logic = src ? resolveReferencedActor(this
|
|
593
|
+
const logic = src ? resolveReferencedActor(this, src)?.src : undefined;
|
|
602
594
|
if (!logic) {
|
|
603
595
|
return;
|
|
604
596
|
}
|
package/dist/xstate.umd.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";const e=".",n="",s="",i="xstate.init",o="xstate.error",r="xstate.stop";class a{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}function c(t,e){return{type:`xstate.done.state.${t}`,output:e}}function u(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function h(t){return{type:i,input:t}}function f(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const d=t=>{const e=f();e&&e.register(t)};function l(t){setTimeout((()=>{throw t}))}const p="function"==typeof Symbol&&Symbol.observable||"@@observable";let y=0;function v(t,e){const n=m(t),s=m(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&v(n[t],s[t])))}function g(t){try{return k(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function m(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(k(t))return _(t);if("string"!=typeof t)return t;return _(g(t))}function _(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function x(t,e){const n={},s=Object.keys(t);for(let i=0;i<s.length;i++){const o=s[i];n[o]=e(t[o],o,t,i)}return n}function b(t){return[].concat(...t)}function S(t){return k(t)?t:[t]}function w(t){return void 0===t?[]:S(t)}function $(t,e,n,s){return"function"==typeof t?t({context:e,event:n,self:s}):t}function k(t){return Array.isArray(t)}function I(t){return S(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function T(t){if(void 0!==t&&t!==n)return w(t)}function E(t,e,n){const s="object"==typeof t,i=s?t:void 0;return{next:(s?t.next:t)?.bind(i),error:(s?t.error:e)?.bind(i),complete:(s?t.complete:n)?.bind(i)}}function O(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}const j=1;let A=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const M=A,P={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class N{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new a(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=A.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...P,...e},{clock:s,logger:i,parent:o,id:r,systemId:c,inspect:u}=n;this.system=o?.system??function(t){const e=new Map,n=new Map,s=new WeakMap,i=new Set,o={_bookId:()=>"x:"+y++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const n={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(n)))},_relay:(t,e,n)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,targetRef:e,event:n}),e._send(n)}};return o}(this),u&&!o&&this.system.inspect(E(u)),c&&(this._systemId=c,this.system._set(c,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=i,this.clock=s,this._parent=o,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),this._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t,e){let n;for(this._state=t;n=this._deferred.shift();)n();for(const e of this.observers)try{e.next?.(t)}catch(t){l(t)}switch(this._state.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(s=this.id,i=this._state.output,{type:`xstate.done.actor.${s}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._stopProcedure(),this._error(this._state.error),this._parent&&this.system._relay(this,this._parent,u(this.id,this._state.error))}var s,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,n){const s=E(t,e,n);if(this.status!==A.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){l(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this.status===A.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=A.Running;const t=h(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,targetRef:this,event:t});switch(this._state.status){case"done":this.update(this._state,t);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorContext)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(u(this.id,t)),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._state,t,this._actorContext)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._stopProcedure(),this._error(t),void this._parent?.send(u(this.id,t))}this.update(e,t),t.type===r&&(this._stopProcedure(),this._complete())}_stop(){return this.status===A.Stopped?this:(this.mailbox.clear(),this.status===A.NotStarted?(this.status=A.Stopped,this):(this.mailbox.enqueue({type:r}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){l(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||l(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){l(t)}}this.observers.clear(),e&&l(t)}_stopProcedure(){if(this.status!==A.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new a(this._process.bind(this)),this.status=A.Stopped,this.system._unregister(this),this}_send(t){this.status!==A.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:n,delay:s}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),s);n&&(this.delayedEventsMap[n]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:d)(this)}}toJSON(){return{xstate$$type:j,id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[p](){return this}getSnapshot(){return this._state}}function R(t,e){return new N(t,e)}const C=R,D=new WeakMap;function Q(t,e,n){let s=D.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},D.set(t,s)),s[e]}function V(t,e,n,{sendId:s}){return[e,"function"==typeof s?s(n):s]}function J(t,e){t.self.cancel(e)}function B(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=V,e.execute=J,e}function z(t,e,n,{id:s,systemId:i,src:o,input:r,syncSnapshot:a}){const c=O(e.machine.implementations.actors[o]);let u;if(c){const h=r||c.input;u=R(c.src,{id:s,src:o,parent:t?.self,systemId:i,input:"function"==typeof h?h({context:e.context,event:n.event,self:t?.self}):h}),a&&u.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${s}`,snapshot:e})},error:()=>{}})}return[Jt(e,{children:{...e.children,[s]:u}}),{id:s,actorRef:u}]}function U(t,{id:e,actorRef:n}){n&&t.defer((()=>{if(n.status!==A.Stopped)try{n.start?.()}catch(n){return void t.self.send(u(e,n))}}))}function W({id:t,systemId:e,src:n,input:s,onSnapshot:i}){function o(t){}return o.type="xstate.invoke",o.id=t,o.systemId=e,o.src=n,o.input=s,o.syncSnapshot=!!i,o.resolve=z,o.execute=U,o}function q(t,e,n,{actorRef:s}){const i="function"==typeof s?s(n):s,o="string"==typeof i?e.children[i]:i;let r=e.children;return o&&(r={...r},delete r[o.id]),[Jt(e,{children:r}),o]}function G(t,e){e&&(e.status===A.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function F(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=q,e.execute=G,e}function X(t,e,{stateValue:n}){return"string"==typeof n&&at(n)?t.configuration.some((t=>t.id===n.slice(1))):t.matches(n)}function H(t,{context:e,event:n},{guards:s}){return!Y(s[0],e,n,t)}function K(t,{context:e,event:n},{guards:s}){return s.every((s=>Y(s,e,n,t)))}function L(t,{context:e,event:n},{guards:s}){return s.some((s=>Y(s,e,n,t)))}function Y(t,e,n,s){const{machine:i}=s,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return Y(r,e,n,s);const a={context:e,event:n,guard:o?void 0:"string"==typeof t?{type:t}:"function"==typeof t.params?{type:t.type,params:t.params({context:e,event:n})}:t};if(!("check"in r))return r(a);return r.check(s,a,r)}const Z=t=>"atomic"===t.type||"final"===t.type;function tt(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function et(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function nt(t){const e=new Set(t),n=new Set(t),s=it(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of tt(t))if("history"!==e.type&&!n.has(e)){const t=dt(e);for(const e of t)n.add(e)}}else dt(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function st(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(Z(t))return t.key}const s={};for(const t of n)s[t.key]=st(t,e);return s}function it(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function ot(t,e){return st(t,it(nt(e)))}function rt(t,e){return"compound"===e.type?tt(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?tt(e).every((e=>rt(t,e))):"final"===e.type}const at=t=>"#"===t[0];function ct(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((n,s)=>{const i=e[n],o="string"==typeof i?{target:i}:i,r=isNaN(+n)?n:+n,a=((e,n)=>{const s=(o="function"==typeof e?`${t.id}:delay[${n}]`:e,r=t.id,{type:`xstate.after(${o})${r?`#${r}`:""}`}),i=s.type;var o,r;return t.entry.push(Lt(s,{id:i,delay:e})),t.exit.push(B(i)),i})(r,s);return w(o).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:n}=e;return{...ut(t,e.event,e),delay:n}}))}function ut(t,n,s){const i=T(s.target),o=s.reenter??!1,r=function(t,n){if(void 0===n)return;return n.map((n=>{if("string"!=typeof n)return n;if(at(n))return t.machine.getStateNodeById(n);const s=n[0]===e;if(s&&!t.parent)return yt(t,n.slice(1));const i=s?t.key+n:n;if(!t.parent)throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`);try{return yt(t.parent,i)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,i),a={...s,actions:w(s.actions),guard:s.guard,target:r,source:t,reenter:o,eventType:n,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ht(t){const e=T(t.config.target);return e?e.map((e=>"string"==typeof e?yt(t.parent,e):e)):t.parent.initial.target}function ft(t){return"history"===t.type}function dt(t){const e=lt(t);for(const n of e)for(const s of et(n,t))e.add(s);return e}function lt(t){const e=new Set;return function t(n){if(!e.has(n))if(e.add(n),"compound"===n.type)t(n.initial.target[0]);else if("parallel"===n.type)for(const e of tt(n))t(e)}(t),e}function pt(t,e){if(at(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function yt(t,e){if("string"==typeof e&&at(e))try{return t.machine.getStateNodeById(e)}catch(t){}const n=g(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=pt(s,t)}return s}function vt(t,e){const n=e instanceof Vt?e.value:m(e);if("string"==typeof n)return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>pt(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=pt(t,s);if(!i)return e;const o=vt(i,n[s]);return e.concat(o)}),[]))}function gt(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const i=pt(t,e).next(n,s);return i&&i.length?i:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const i=Object.keys(e),o=gt(pt(t,i[0]),e[i[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const i=[];for(const o of Object.keys(e)){const r=e[o];if(!r)continue;const a=gt(pt(t,o),r,n,s);a&&i.push(...a)}return i.length?i:t.next(n,s)}(t,e,n,s)}function mt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function _t(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function xt(t){const e=[];let n=t.parent;for(;n;)e.unshift(n),n=n.parent;return e}function bt(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function St(t,e,n){const s=new Set;for(const i of t){let t=!1;const o=new Set;for(const r of s)if(bt(kt([i],e,n),kt([r],e,n))){if(!_t(i.source,r.source)){t=!0;break}o.add(r)}if(!t){for(const t of o)s.delete(t);s.add(i)}}return Array.from(s)}function wt(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(ft(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of wt({target:ht(s)},e))n.add(t);else n.add(s);return[...n]}function $t(t,e){const n=wt(t,e);if(!n)return null;if(!t.reenter&&"parallel"!==t.source.type&&n.every((e=>_t(e,t.source))))return t.source;return function(t){const[e]=t;let n=xt(e),s=[];for(const e of t){const t=xt(e);s=n.filter((e=>t.includes(e))),n=s,s=[]}return n[n.length-1]}(n.concat(t.source))}function kt(t,e,n){const s=new Set;for(const i of t)if(i.target?.length){const t=$t(i,n);for(const n of e)_t(n,t)&&s.add(n)}return[...s]}function It(t,e,n,s,i){const o=new Set(e.configuration);if(!t.length)return e;const r=function(t,e,n,s,i,o){const r={...e.historyValue},a=St(t,n,r),u=[...e._internalQueue];let h=Jt(e,{_internalQueue:[]});o||(h=function(t,e,n,s,i,o){let r=t;const a=kt(s,i,o);a.sort(((t,e)=>e.order-t.order));for(const t of a)for(const e of mt(t)){let n;n="deep"===e.history?e=>Z(e)&&_t(e,t):e=>e.parent===t,o[e.id]=Array.from(i).filter(n)}for(const t of a)r=Mt(r,e,n,[...t.exit,...t.invoke.map((t=>F(t.id)))]),i.delete(t);return r}(h,s,i,a,n,r));h=Mt(h,s,i,a.flatMap((t=>t.actions))),h=function(t,e,n,s,i,o,r,a){let u=t;const h=new Set,f=new Set;Et(s,r,f,h),a&&f.add(t.machine.root);const d=new Set;for(const s of[...h].sort(((t,e)=>t.order-e.order))){i.add(s);const r=[];r.push(...s.entry);for(const t of s.invoke)r.push(W(t));if(f.has(s)){const t=s.initial.actions;r.push(...t)}if(u=Mt(u,e,n,r,s.invoke.map((t=>t.id))),"final"===s.type){const r=s.parent;if(d.has(r))continue;d.add(r);let a="parallel"===r?.type?r:s,h=r?.parent;if(h)for(o.push(c(r.id,s.output?$(s.output,u.context,e,n.self):void 0));"parallel"===h?.type&&!d.has(h)&&rt(i,h);)d.add(h),o.push(c(h.id)),a=h,h=h.parent;if(h)continue;u=Jt(u,{status:"done",output:Tt(u,e,n,t.configuration[0].machine.root,a)})}}return u}(h,s,i,a,n,u,r,o);const f=[...n];"done"===h.status&&(h=Mt(h,s,i,f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit))));try{return u.push(...h._internalQueue),Jt(h,{configuration:f,historyValue:r,_internalQueue:u})}catch(t){throw t}}(t,e,o,s,n,i);return Jt(r,{value:{}})}function Tt(t,e,n,s,i){if(!s.output)return;const o=c(i.id,i.output&&i.parent?$(i.output,t.context,e,n.self):void 0);return $(s.output,t.context,o,n.self)}function Et(t,e,n,s){for(const i of t){for(const t of i.target||[])Ot(t,e,n,s);const t=$t(i,e),o=wt(i,e);for(const i of o)jt(i,t,s,e,n)}}function Ot(t,e,n,s){if(ft(t))if(e[t.id]){const i=e[t.id];for(const t of i)Ot(t,e,n,s);for(const o of i){jt(o,t.parent,s,e,n);for(const t of n)n.add(t)}}else{const i=ht(t);for(const t of i)Ot(t,e,n,s);for(const o of i){jt(o,t,s,e,n);for(const t of n)n.add(t)}}else if(s.add(t),"compound"===t.type){n.add(t);const[i]=t.initial.target;Ot(i,e,n,s),jt(i,t,s,e,n)}else if("parallel"===t.type)for(const i of tt(t).filter((t=>!ft(t))))[...s].some((t=>_t(t,i)))||Ot(i,e,n,s)}function jt(t,e,n,s,i){const o=et(t,e);for(const t of o)if(n.add(t),"parallel"===t.type)for(const e of tt(t).filter((t=>!ft(t))))[...n].some((t=>_t(t,e)))||Ot(e,s,i,n)}function At(t,e,n,s,i,o){const{machine:r}=t;let a=t;for(const t of s){const s="function"==typeof t,c=s?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:n?.self,system:n?.system,action:s?void 0:"string"==typeof t?{type:t}:"function"==typeof t.params?{type:t.type,params:t.params({context:a.context,event:e})}:t};if(!("resolve"in c)){n?.self.status===A.Running?c(u):n?.defer((()=>{c(u)}));continue}const h=c,[f,d,l]=h.resolve(n,a,u,c,i);a=f,"retryResolve"in h&&o?.push([h,d]),"execute"in h&&(n?.self.status===A.Running?h.execute(n,d):n?.defer(h.execute.bind(null,n,d))),l&&(a=At(a,e,n,l,i,o))}return a}function Mt(t,e,n,s,i){const o=i?[]:void 0,r=At(t,e,n,s,i&&{deferredActorIds:i},o);return o?.forEach((([t,e])=>{t.retryResolve(n,r,e)})),r}function Pt(t,e,n){let s=t;const o=[];if(e.type===r)return s=Nt(e,s,n),o.push(s),{state:s,microstates:o};let a=e;if(a.type!==i){s=It(Rt(a,s),t,n,a,!1),o.push(s)}for(;"active"===s.status;){let t=Ct(s,a);if(t.length)s=It(t,s,n,a,!1),o.push(s);else{if(!s._internalQueue.length)break;a=s._internalQueue[0];s=It(Rt(a,s),s,n,a,!1),s._internalQueue.shift(),o.push(s)}}return"active"!==s.status&&Nt(a,s,n),{state:s,microstates:o}}function Nt(t,e,n){const s=[];for(const t of e.configuration.sort(((t,e)=>e.order-t.order)))s.push(...t.exit);for(const t of Object.values(e.children))s.push(F(t));return Mt(e,t,n,s)}function Rt(t,e){return e.machine.getTransitionData(e,t)}function Ct(t,e){const n=new Set,s=t.configuration.filter(Z);for(const i of s)t:for(const s of[i].concat(et(i,null)))if(s.always)for(const i of s.always)if(void 0===i.guard||Y(i.guard,t.context,e,t)){n.add(i);break t}return St(Array.from(n),new Set(t.configuration),t.historyValue)}function Dt(t,e){return ot(t,[...nt(vt(t,e))])}function Qt(t){const e=[],n=t.initial,s=new Set;Et([n],{},new Set([t]),s);for(const t of[...s].sort(((t,e)=>t.order-e.order)))e.push(t);return e}class Vt{static from(t,e={},n){if(t instanceof Vt)return t.context!==e?new Vt({value:t.value,context:e,meta:{},configuration:[],children:{},status:"active"},n):t;const s=nt(vt(n.root,t));return new Vt({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{},status:"active"},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.status=void 0,this.error=void 0,this.context=void 0,this.historyValue={},this._internalQueue=void 0,this.configuration=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(nt(vt(e.root,t.value))),this.children=t.children,this.value=ot(e.root,this.configuration),this.tags=new Set(b(this.configuration.map((t=>t.tags)))),this.status=t.status,this.output=t.output,this.error=t.error}toStrings(t=this.value){if("string"==typeof t)return[t];const n=Object.keys(t);return n.concat(...n.map((n=>this.toStrings(t[n]).map((t=>n+e+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return v(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return Q(this,"nextEvents",(()=>[...new Set(b([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function Jt(t,e={}){return new Vt({...t,...e},t.machine)}function Bt(t){let e;for(const n in t){const s=t[n];if(s&&"object"==typeof s)if("sessionId"in s&&"send"in s&&"ref"in s)e??=Array.isArray(t)?t.slice():{...t},e[n]={xstate$$type:j,id:s.id};else{const i=Bt(s);i!==s&&(e??=Array.isArray(t)?t.slice():{...t},e[n]=i)}}return e??t}function zt(t,{machine:e,context:n},s,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a}=r;if("string"==typeof o){const c=O(e.implementations.actors[o]);if(!c)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u="input"in r?r.input:c.input,h=R(c.src,{id:r.id,parent:t.self,input:"function"==typeof u?u({context:n,event:s,self:t.self}):u,src:o,systemId:a});return i[h.id]=h,r.syncSnapshot&&h.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${h.id}`,snapshot:e})},error:()=>{}}),h}{const e=R(o,{id:r.id,parent:t.self,input:r.input,src:void 0,systemId:a});return r.syncSnapshot&&e.subscribe({next:n=>{"active"===n.status&&t.self.send({type:`xstate.snapshot.${e.id}`,snapshot:n,id:e.id})},error:()=>{}}),e}})(o,r);return i[a.id]=a,t.defer((()=>{if(a.status!==A.Stopped)try{a.start?.()}catch(e){return void t.self.send(u(a.id,e))}})),a}}function Ut(t,e,n,{assignment:s}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,action:n.action,spawn:zt(t,e,n.event,i),self:t?.self,system:t?.system};let r={};if("function"==typeof s)r=s(o);else for(const t of Object.keys(s)){const e=s[t];r[t]="function"==typeof e?e(o):e}return[Jt(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Wt(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=Ut,e}function qt(t,e,n,{branches:s}){const i=s.find((t=>!t.guard||Y(t.guard,e.context,n.event,e)))?.actions;return[e,void 0,w(i)]}function Gt(t,e,n,{value:s,label:i}){return[e,{value:"function"==typeof s?s(n):s,label:i}]}function Ft({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function Xt(t,e,n,{get:s}){return[e,void 0,w(s({context:n.context,event:n.event}))]}function Ht(t,e,n,{event:s,id:i,delay:o}){const r=e.machine.implementations.delays;if("string"==typeof s)throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);const a="function"==typeof s?s(n):s;let c;if("string"==typeof o){const t=r&&r[o];c="function"==typeof t?t(n):t}else c="function"==typeof o?o(n):o;return["number"!=typeof c?Jt(e,{_internalQueue:e._internalQueue.concat(a)}):e,{event:a,id:i,delay:c}]}function Kt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function Lt(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Ht,n.execute=Kt,n}let Yt=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Zt(t,e,n,{to:s,event:i,id:o,delay:r},a){const c=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const u="function"==typeof i?i(n):i;let h;if("string"==typeof r){const t=c&&c[r];h="function"==typeof t?t(n):t}else h="function"==typeof r?r(n):r;const f="function"==typeof s?s(n):s;let d;if("string"==typeof f){if(d=f===Yt.Parent?t?.self._parent:f===Yt.Internal?t?.self:f.startsWith("#_")?e.children[f.slice(2)]:a?.deferredActorIds.includes(f)?f:e.children[f],!d)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else d=f||t?.self;return[e,{to:d,event:u,id:o,delay:h}]}function te(t,e,n){"string"==typeof n.to&&(n.to=e.children[n.to])}function ee(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:n,event:s}=e;t?.system._relay(t.self,n,s.type===o?u(t.self.id,s.data):s)})):t.self.delaySend(e)}function ne(t,e,n){function s(t){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=Zt,s.retryResolve=te,s.execute=ee,s}function se(t,e){return ne(Yt.Parent,t,e)}function ie(t,e){return{config:t,transition:(e,n,s)=>({...e,context:t(e.context,n,s)}),getInitialState:(t,n)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:n}):e}),getPersistedState:t=>t,restoreState:t=>t}}const oe="$$xstate.resolve",re="$$xstate.reject";const ae=ie((t=>{}),void 0);const ce={},ue=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class he{constructor(t,n){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(e),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?x(this.config.states,((t,e)=>new he(t,{_parent:this,_key:e,_machine:this.machine}))):ce,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=w(this.config.entry).slice(),this.exit=w(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=w(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===s)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const i=t.config.on[n];e.set(n,I(i).map((e=>ut(t,n,e))))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,I(t.config.onDone).map((e=>ut(t,n,e))))}for(const n of t.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;e.set(s,I(n.onDone).map((e=>ut(t,s,e))))}if(n.onError){const s=`xstate.error.actor.${n.id}`;e.set(s,I(n.onError).map((e=>ut(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,I(n.onSnapshot).map((e=>ut(t,s,e))))}}for(const n of t.after){let t=e.get(n.eventType);t||(t=[],e.set(n.eventType,t)),t.push(n)}return e}(this),this.config.always&&(this.always=I(this.config.always).map((t=>ut(this,s,t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(ue),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(ue),eventType:null})}:void 0,history:this.history,states:x(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(ue)}))),entry:this.entry.map(ue),exit:this.exit.map(ue),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return Q(this,"invoke",(()=>w(this.config.invoke).map(((t,e)=>{const{src:n,systemId:s}=t,i=t.id||`${this.id}:invocation[${e}]`;const o="string"==typeof n||"type"in n?n:i;return this.machine.implementations.actors[i]||"string"==typeof n||"type"in n||(this.machine.implementations.actors={...this.machine.implementations.actors,[i]:n}),{...t,src:o,id:i,systemId:s,toJSON(){const{onDone:e,onError:n,...s}=t;return{...s,type:"xstate.invoke",src:o,id:i}}}}))))}get on(){return Q(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,n])=>(t[e]=t[e]||[],t[e].push(n),t)),{})))}get after(){return Q(this,"delayedTransitions",(()=>ct(this)))}get initial(){return Q(this,"initial",(()=>function(t,e){const n="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const s={source:t,actions:e&&"string"!=typeof e?w(e.actions):[],eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return s}(this,this.config.initial)))}next(t,e){const n=e.type,s=[];let i;const o=Q(this,`candidates-${n}`,(()=>{return e=n,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),s=e.split(".");for(let t=0;t<n.length;t++){const e=n[t],i=s[t];if("*"===e)return t===n.length-1;if(e!==i)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of o){const{guard:o}=r,a=t.context;let c=!1;try{c=!o||Y(o,a,e,t)}catch(t){const e="string"==typeof o?o:"object"==typeof o?o.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(c){s.push(...r.actions),i=r;break}}return i?[i]:void 0}get events(){return Q(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class fe{constructor(t,e){this.config=t,this.version=void 0,this.implementations=void 0,this.types=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TContext=void 0,this.__TEvent=void 0,this.__TActor=void 0,this.__TAction=void 0,this.__TGuard=void 0,this.__TDelay=void 0,this.__TTag=void 0,this.__TInput=void 0,this.__TOutput=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.types=this.config.types??{},this.transition=this.transition.bind(this),this.getInitialState=this.getInitialState.bind(this),this.restoreState=this.restoreState.bind(this),this.start=this.start.bind(this),this.getPersistedState=this.getPersistedState.bind(this),this.root=new he(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:i}=this.implementations;return new fe(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=nt(vt(this.root,t.value)),n=Array.from(e);return this.createState({...t,value:Dt(this.root,t.value),configuration:n,status:rt(e,this.root)?"done":t.status})}resolveStateValue(t,...[e]){const n=Dt(this.root,t);return this.resolveState(Vt.from(n,e,this))}transition(t,e,n){if(function(t){return t.type.startsWith("xstate.error.actor")}(e)&&!t.nextEvents.some((t=>t===e.type)))return Jt(t,{status:"error",error:e.data});const{state:s}=Pt(t,e,n);return s}microstep(t,e,n){return Pt(t,e,n).microstates}getTransitionData(t,e){return gt(this.root,t.value,t,e)||[]}getPreInitialState(t,e){const{context:n}=this.config,s=this.resolveState(this.createState({value:{},context:"function"!=typeof n&&n?n:{},meta:void 0,configuration:Qt(this.root),children:{},status:"active"}));if("function"==typeof n){return Mt(s,e,t,[Wt((({spawn:t,event:e})=>n({spawn:t,input:e.input})))])}return s}getInitialState(t,e){const n=h(e),s=this.getPreInitialState(t,n),i=It([{target:[...lt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],s,t,n,!0),{state:o}=Pt(i,n,t);return o}start(t){Object.values(t.children).forEach((t=>{0===t.status&&t.start()}))}getStateNodeById(t){const n=t.split(e),s=n.slice(1),i=at(n[0])?n[0].slice(1):n[0],o=this.idMap.get(i);if(!o)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return yt(o,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedState(t){return function(t){const{configuration:e,tags:n,machine:s,children:i,context:o,...r}=t,a={};for(const t in i){const e=i[t];a[t]={state:e.getPersistedState?.(),src:e.src}}return{...r,context:Bt(o),children:a}}(t)}createState(t){return t instanceof Vt?t:new Vt(t,this)}restoreState(t,e){const n={};Object.keys(t.children).forEach((s=>{const i=t.children[s],o=i.state,r=i.src,a=r?O(this.implementations.actors[r])?.src:void 0;if(!a)return;const c=a.restoreState?.(o,e),u=R(a,{id:s,parent:e?.self,state:c});n[s]=u}));const s=this.createState(new Vt({...t,children:n},this));let i=new Set;return function t(e,n){if(!i.has(e)){i.add(e);for(let s in e){const i=e[s];if(i&&"object"==typeof i){if("xstate$$type"in i&&i.xstate$$type===j){e[s]=n[i.id];continue}t(i,n)}}}}(s.context,n),s}}const de={timeout:1e4};t.Actor=N,t.ActorStatus=A,t.InterpreterStatus=M,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0}now(){return this._now}getId(){return this._id++}setTimeout(t,e){const n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}clearTimeout(t){this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){[...this.timeouts].sort((([t,e],[n,s])=>{const i=e.start+e.timeout;return s.start+s.timeout>i?-1:1})).forEach((([t,e])=>{this.now()-e.start>=e.timeout&&(this.timeouts.delete(t),e.fn.call(null))}))}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=Yt,t.State=Vt,t.StateMachine=fe,t.StateNode=he,t.and=function(t){function e(t){return!1}return e.check=K,e.guards=t,e},t.assign=Wt,t.cancel=B,t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=qt,e},t.createActor=R,t.createEmptyActor=function(){return R(ae)},t.createMachine=function(t,e){return new fe(t,e)},t.escalate=function(t,e){return se((e=>({type:o,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return ne(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(t,{self:e,system:n})=>{n._relay(e,e,{type:"xstate.create"})},transition:(e,n,{self:s,system:i})=>{if("xstate.create"===n.type){const n=t=>{"stopped"!==e.status&&s._parent&&i._relay(s,s._parent,t)},o=t=>{e._receivers.add(t)};return e._dispose=t({input:e.input,system:i,self:s,sendBack:n,receive:o}),e}return n.type===r?("function"==typeof(e={...e,status:"stopped",error:void 0})._dispose&&e._dispose(),e):(e._receivers.forEach((t=>t(n))),e)},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e,_receivers:new Set,_dispose:void 0}),getPersistedState:({_dispose:t,_receivers:e,...n})=>n,restoreState:t=>({_receivers:new Set,_dispose:void 0,...t})}},t.fromEventObservable=function(t){const e="$$xstate.error",n="$$xstate.complete";return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case e:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case n:return{...t,status:"done",input:void 0,_subscription:void 0};case r:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(s,{self:i,system:o})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:o,self:i}).subscribe({next:t=>{i._parent&&o._relay(i,i._parent,t)},error:t=>{o._relay(i,i,{type:e,data:t})},complete:()=>{o._relay(i,i,{type:n})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",n="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,i,{self:o,id:a,defer:c,system:u})=>{if("active"!==t.status)return t;switch(i.type){case e:return{...t,context:i.data};case n:return{...t,status:"error",error:i.data,input:void 0,_subscription:void 0};case s:return{...t,status:"done",input:void 0,_subscription:void 0};case r:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(i,{self:o,system:r})=>{"done"!==i.status&&(i._subscription=t({input:i.input,system:r,self:o}).subscribe({next:t=>{r._relay(o,o,{type:e,data:t})},error:t=>{r._relay(o,o,{type:n,data:t})},complete:()=>{r._relay(o,o,{type:s})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case oe:{const n=e.data;return{...t,status:"done",output:n,input:void 0}}case re:return{...t,status:"error",error:e.data,input:void 0};case r:return{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:n,system:s})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:s,self:n})).then((t=>{"active"===n.getSnapshot().status&&s._relay(n,n,{type:oe,data:t})}),(t=>{"active"===n.getSnapshot().status&&s._relay(n,n,{type:re,data:t})}))},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=ie,t.getStateNodes=vt,t.interpret=C,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=Gt,n.execute=Ft,n},t.mapState=function(t,e){let n;for(const s of Object.keys(t))v(s,e)&&(!n||e.length>n.length)&&(n=s);return t[n]},t.matchesState=v,t.not=function(t){function e(t){return!1}return e.check=H,e.guards=[t],e},t.or=function(t){function e(t){return!1}return e.check=L,e.guards=t,e},t.pathToStateValue=_,t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=Xt,e},t.raise=Lt,t.sendParent=se,t.sendTo=ne,t.stateIn=function(t){function e(t){return!1}return e.check=X,e.stateValue=t,e},t.stop=F,t.toObserver=E,t.waitFor=function(t,e,n){const s={...de,...n};return new Promise(((n,i)=>{let o=!1;const r=s.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),i(new Error(`Timeout of ${s.timeout} ms exceeded`))}),s.timeout),a=()=>{clearTimeout(r),o=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),n(t))}let u;c(t.getSnapshot()),o||(u=t.subscribe({next:c,error:t=>{a(),i(t)},complete:()=>{a(),i(new Error("Actor terminated without satisfying predicate"))}}),o&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";const e=".",n="",s="",i="xstate.init",o="xstate.error",r="xstate.stop";class a{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}function c(t,e){return{type:`xstate.done.state.${t}`,output:e}}function u(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function f(t){return{type:i,input:t}}function h(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const d=t=>{const e=h();e&&e.register(t)};function p(t){setTimeout((()=>{throw t}))}const l="function"==typeof Symbol&&Symbol.observable||"@@observable";let y=0;function v(t,e){const n=m(t),s=m(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&v(n[t],s[t])))}function g(t){try{return k(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function m(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(k(t))return _(t);if("string"!=typeof t)return t;return _(g(t))}function _(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function x(t,e){const n={},s=Object.keys(t);for(let i=0;i<s.length;i++){const o=s[i];n[o]=e(t[o],o,t,i)}return n}function b(t){return[].concat(...t)}function S(t){return k(t)?t:[t]}function w(t){return void 0===t?[]:S(t)}function $(t,e,n,s){return"function"==typeof t?t({context:e,event:n,self:s}):t}function k(t){return Array.isArray(t)}function I(t){return S(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function T(t){if(void 0!==t&&t!==n)return w(t)}function E(t,e,n){const s="object"==typeof t,i=s?t:void 0;return{next:(s?t.next:t)?.bind(i),error:(s?t.error:e)?.bind(i),complete:(s?t.complete:n)?.bind(i)}}function O(t,e){return`${t}[${e}]`}function j(t,e){if(e.startsWith("xstate#")){const[,n]=e.match(/\[(\d+)\]$/),s=t.getStateNodeById(e.slice(7,-(n.length+2))).config.invoke;return{src:(Array.isArray(s)?s[n]:s).src,input:void 0}}const n=t.implementations.actors[e];return n?"transition"in n?{src:n,input:void 0}:n:void 0}const A=1;let M=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const P=M,N={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class R{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new a(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=M.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...N,...e},{clock:s,logger:i,parent:o,id:r,systemId:c,inspect:u}=n;this.system=o?.system??function(t){const e=new Map,n=new Map,s=new WeakMap,i=new Set,o={_bookId:()=>"x:"+y++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const n={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(n)))},_relay:(t,e,n)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,targetRef:e,event:n}),e._send(n)}};return o}(this),u&&!o&&this.system.inspect(E(u)),c&&(this._systemId=c,this.system._set(c,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=i,this.clock=s,this._parent=o,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),this._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t,e){let n;for(this._state=t;n=this._deferred.shift();)n();for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}switch(this._state.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=(s=this.id,i=this._state.output,{type:`xstate.done.actor.${s}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._stopProcedure(),this._error(this._state.error),this._parent&&this.system._relay(this,this._parent,u(this.id,this._state.error))}var s,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,n){const s=E(t,e,n);if(this.status!==M.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){p(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this.status===M.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=M.Running;const t=f(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,targetRef:this,event:t});switch(this._state.status){case"done":this.update(this._state,t);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorContext)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(u(this.id,t)),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._state,t,this._actorContext)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._stopProcedure(),this._error(t),void this._parent?.send(u(this.id,t))}this.update(e,t),t.type===r&&(this._stopProcedure(),this._complete())}_stop(){return this.status===M.Stopped?this:(this.mailbox.clear(),this.status===M.NotStarted?(this.status=M.Stopped,this):(this.mailbox.enqueue({type:r}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){p(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||p(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){p(t)}}this.observers.clear(),e&&p(t)}_stopProcedure(){if(this.status!==M.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new a(this._process.bind(this)),this.status=M.Stopped,this.system._unregister(this),this}_send(t){this.status!==M.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:n,delay:s}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),s);n&&(this.delayedEventsMap[n]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:d)(this)}}toJSON(){return{xstate$$type:A,id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[l](){return this}getSnapshot(){return this._state}}function C(t,e){return new R(t,e)}const D=C,V=new WeakMap;function J(t,e,n){let s=V.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},V.set(t,s)),s[e]}function B(t,e,n,{sendId:s}){return[e,"function"==typeof s?s(n):s]}function z(t,e){t.self.cancel(e)}function W(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=B,e.execute=z,e}function U(t,e,n,{id:s,systemId:i,src:o,input:r,syncSnapshot:a}){const c="string"==typeof o?j(e.machine,o):{src:o,input:void 0};let u;if(c){const f=r||c.input;u=C(c.src,{id:s,src:"string"==typeof o?o:void 0,parent:t?.self,systemId:i,input:"function"==typeof f?f({context:e.context,event:n.event,self:t?.self}):f}),a&&u.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${s}`,snapshot:e})},error:()=>{}})}return[zt(e,{children:{...e.children,[s]:u}}),{id:s,actorRef:u}]}function q(t,{id:e,actorRef:n}){n&&t.defer((()=>{if(n.status!==M.Stopped)try{n.start?.()}catch(n){return void t.self.send(u(e,n))}}))}function G({id:t,systemId:e,src:n,input:s,onSnapshot:i}){function o(t){}return o.type="xstate.invoke",o.id=t,o.systemId=e,o.src=n,o.input=s,o.syncSnapshot=!!i,o.resolve=U,o.execute=q,o}function Q(t,e,n,{actorRef:s}){const i="function"==typeof s?s(n):s,o="string"==typeof i?e.children[i]:i;let r=e.children;return o&&(r={...r},delete r[o.id]),[zt(e,{children:r}),o]}function F(t,e){e&&(e.status===M.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function X(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=Q,e.execute=F,e}function H(t,e,{stateValue:n}){if("string"==typeof n&&ct(n)){const e=t.machine.getStateNodeById(n);return t.configuration.some((t=>t===e))}return t.matches(n)}function K(t,{context:e,event:n},{guards:s}){return!Z(s[0],e,n,t)}function L(t,{context:e,event:n},{guards:s}){return s.every((s=>Z(s,e,n,t)))}function Y(t,{context:e,event:n},{guards:s}){return s.some((s=>Z(s,e,n,t)))}function Z(t,e,n,s){const{machine:i}=s,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return Z(r,e,n,s);const a={context:e,event:n,guard:o?void 0:"string"==typeof t?{type:t}:"function"==typeof t.params?{type:t.type,params:t.params({context:e,event:n})}:t};if(!("check"in r))return r(a);return r.check(s,a,r)}const tt=t=>"atomic"===t.type||"final"===t.type;function et(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function nt(t,e){const n=[];if(e===t)return n;let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function st(t){const e=new Set(t),n=new Set(t),s=ot(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of et(t))if("history"!==e.type&&!n.has(e)){const t=pt(e);for(const e of t)n.add(e)}}else pt(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function it(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(tt(t))return t.key}const s={};for(const t of n)s[t.key]=it(t,e);return s}function ot(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function rt(t,e){return it(t,ot(st(e)))}function at(t,e){return"compound"===e.type?et(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?et(e).every((e=>at(t,e))):"final"===e.type}const ct=t=>"#"===t[0];function ut(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((n,s)=>{const i=e[n],o="string"==typeof i?{target:i}:i,r=isNaN(+n)?n:+n,a=((e,n)=>{const s=(o="function"==typeof e?`${t.id}:delay[${n}]`:e,r=t.id,{type:`xstate.after(${o})${r?`#${r}`:""}`}),i=s.type;var o,r;return t.entry.push(Yt(s,{id:i,delay:e})),t.exit.push(W(i)),i})(r,s);return w(o).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:n}=e;return{...ft(t,e.event,e),delay:n}}))}function ft(t,n,s){const i=T(s.target),o=s.reenter??!1,r=function(t,n){if(void 0===n)return;return n.map((n=>{if("string"!=typeof n)return n;if(ct(n))return t.machine.getStateNodeById(n);const s=n[0]===e;if(s&&!t.parent)return vt(t,n.slice(1));const i=s?t.key+n:n;if(!t.parent)throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`);try{return vt(t.parent,i)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,i),a={...s,actions:w(s.actions),guard:s.guard,target:r,source:t,reenter:o,eventType:n,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ht(t){const e=T(t.config.target);return e?{target:e.map((e=>"string"==typeof e?vt(t.parent,e):e))}:t.parent.initial}function dt(t){return"history"===t.type}function pt(t){const e=lt(t);for(const n of e)for(const s of nt(n,t))e.add(s);return e}function lt(t){const e=new Set;return function t(n){if(!e.has(n))if(e.add(n),"compound"===n.type)t(n.initial.target[0]);else if("parallel"===n.type)for(const e of et(n))t(e)}(t),e}function yt(t,e){if(ct(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function vt(t,e){if("string"==typeof e&&ct(e))try{return t.machine.getStateNodeById(e)}catch(t){}const n=g(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=yt(s,t)}return s}function gt(t,e){const n=e instanceof Bt?e.value:m(e);if("string"==typeof n)return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>yt(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=yt(t,s);if(!i)return e;const o=gt(i,n[s]);return e.concat(o)}),[]))}function mt(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const i=yt(t,e).next(n,s);return i&&i.length?i:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const i=Object.keys(e),o=mt(yt(t,i[0]),e[i[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const i=[];for(const o of Object.keys(e)){const r=e[o];if(!r)continue;const a=mt(yt(t,o),r,n,s);a&&i.push(...a)}return i.length?i:t.next(n,s)}(t,e,n,s)}function _t(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function xt(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function bt(t){const e=[];let n=t.parent;for(;n;)e.unshift(n),n=n.parent;return e}function St(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function wt(t,e,n){const s=new Set;for(const i of t){let t=!1;const o=new Set;for(const r of s)if(St(It([i],e,n),It([r],e,n))){if(!xt(i.source,r.source)){t=!0;break}o.add(r)}if(!t){for(const t of o)s.delete(t);s.add(i)}}return Array.from(s)}function $t(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(dt(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of $t(ht(s),e))n.add(t);else n.add(s);return[...n]}function kt(t,e){const n=$t(t,e);if(!n)return;if(!t.reenter&&n.every((e=>e===t.source||xt(e,t.source))))return t.source;return function(t){const[e]=t;let n=bt(e),s=[];for(const e of t){const t=bt(e);s=n.filter((e=>t.includes(e))),n=s,s=[]}return n[n.length-1]}(n.concat(t.source))}function It(t,e,n){const s=new Set;for(const i of t)if(i.target?.length){const t=kt(i,n);i.reenter&&i.source===t&&s.add(t);for(const n of e)xt(n,t)&&s.add(n)}return[...s]}function Tt(t,e,n,s,i,o){if(!t.length)return e;const r=new Set(e.configuration);let a=e.historyValue;const u=wt(t,r,a);let f=e;i||([f,a]=function(t,e,n,s,i,o,r){let a=t;const c=It(s,i,o);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of _t(t)){let n;n="deep"===e.history?e=>tt(e)&&xt(e,t):e=>e.parent===t,u??={...o},u[e.id]=Array.from(i).filter(n)}for(const t of c)a=Pt(a,e,n,[...t.exit,...t.invoke.map((t=>X(t.id)))],r),i.delete(t);return[a,u||o]}(f,s,n,u,r,a,o)),f=Pt(f,s,n,u.flatMap((t=>t.actions)),o),f=function(t,e,n,s,i,o,r,a){let u=t;const f=new Set,h=new Set;Ot(s,r,h,f),a&&h.add(t.machine.root);const d=new Set;for(const s of[...f].sort(((t,e)=>t.order-e.order))){i.add(s);const r=[];r.push(...s.entry);for(const t of s.invoke)r.push(G(t));if(h.has(s)){const t=s.initial.actions;r.push(...t)}if(u=Pt(u,e,n,r,o,s.invoke.map((t=>t.id))),"final"===s.type){const r=s.parent;let a="parallel"===r?.type?r:r?.parent,f=a||s;for("compound"===r?.type&&o.push(c(r.id,s.output?$(s.output,u.context,e,n.self):void 0));"parallel"===a?.type&&!d.has(a)&&at(i,a);)d.add(a),o.push(c(a.id)),f=a,a=a.parent;if(a)continue;u=zt(u,{status:"done",output:Et(u,e,n,t.configuration[0].machine.root,f)})}}return u}(f,s,n,u,r,o,a,i);const h=[...r];"done"===f.status&&(f=Pt(f,s,n,h.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),o));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}(e.configuration,r)?f:zt(f,{configuration:h,historyValue:a})}catch(t){throw t}}function Et(t,e,n,s,i){if(!s.output)return;const o=c(i.id,i.output&&i.parent?$(i.output,t.context,e,n.self):void 0);return $(s.output,t.context,o,n.self)}function Ot(t,e,n,s){for(const i of t){const t=kt(i,e);for(const o of i.target||[])dt(o)||i.source===o&&i.source===t&&!i.reenter||(s.add(o),n.add(o)),jt(o,e,n,s);const o=$t(i,e);for(const i of o)At(i,t,s,e,n)}}function jt(t,e,n,s){if(dt(t))if(e[t.id]){const i=e[t.id];for(const t of i)s.add(t),jt(t,e,n,s);for(const o of i)At(o,t.parent,s,e,n)}else{const i=ht(t);for(const o of i.target)s.add(o),i===t.parent?.initial&&n.add(t.parent),jt(o,e,n,s);for(const o of i.target)At(o,t,s,e,n)}else if("compound"===t.type){const[i]=t.initial.target;dt(i)||(s.add(i),n.add(i)),jt(i,e,n,s),At(i,t,s,e,n)}else if("parallel"===t.type)for(const i of et(t).filter((t=>!dt(t))))[...s].some((t=>xt(t,i)))||(dt(i)||(s.add(i),n.add(i)),jt(i,e,n,s))}function At(t,e,n,s,i){const o=nt(t,e);for(const t of o)if(n.add(t),"parallel"===t.type)for(const e of et(t).filter((t=>!dt(t))))[...n].some((t=>xt(t,e)))||(n.add(e),jt(e,s,i,n))}function Mt(t,e,n,s,i,o){const{machine:r}=t;let a=t;for(const t of s){const s="function"==typeof t,c=s?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:n?.self,system:n?.system,action:s?void 0:"string"==typeof t?{type:t}:"function"==typeof t.params?{type:t.type,params:t.params({context:a.context,event:e})}:t};if(!("resolve"in c)){n?.self.status===M.Running?c(u):n?.defer((()=>{c(u)}));continue}const f=c,[h,d,p]=f.resolve(n,a,u,c,i);a=h,"retryResolve"in f&&o?.push([f,d]),"execute"in f&&(n?.self.status===M.Running?f.execute(n,d):n?.defer(f.execute.bind(null,n,d))),p&&(a=Mt(a,e,n,p,i,o))}return a}function Pt(t,e,n,s,i,o){const r=o?[]:void 0,a=Mt(t,e,n,s,{internalQueue:i,deferredActorIds:o},r);return r?.forEach((([t,e])=>{t.retryResolve(n,a,e)})),a}function Nt(t,e,n,s=[]){let o=t;const a=[];if(e.type===r)return o=Rt(o,e,n),a.push(o),{state:o,microstates:a};let c=e;if(c.type!==i){o=Tt(Ct(c,o),t,n,c,!1,s),a.push(o)}let u=!0;for(;"active"===o.status;){let t=u?Dt(o,c):[];const e=t.length?o:void 0;if(!t.length){if(!s.length)break;c=s.shift(),t=Ct(c,o)}o=Tt(t,o,n,c,!1,s),u=o!==e,a.push(o)}return"active"!==o.status&&Rt(o,c,n),{state:o,microstates:a}}function Rt(t,e,n){return Pt(t,e,n,Object.values(t.children).map((t=>X(t))),[])}function Ct(t,e){return e.machine.getTransitionData(e,t)}function Dt(t,e){const n=new Set,s=t.configuration.filter(tt);for(const i of s)t:for(const s of[i].concat(nt(i,void 0)))if(s.always)for(const i of s.always)if(void 0===i.guard||Z(i.guard,t.context,e,t)){n.add(i);break t}return wt(Array.from(n),new Set(t.configuration),t.historyValue)}function Vt(t,e){return rt(t,[...st(gt(t,e))])}function Jt(t){const e=[],n=t.initial,s=new Set;Ot([n],{},new Set([t]),s);for(const t of[...s].sort(((t,e)=>t.order-e.order)))e.push(t);return e}class Bt{static from(t,e={},n){if(t instanceof Bt)return t.context!==e?new Bt({value:t.value,context:e,meta:{},configuration:[],children:{},status:"active"},n):t;const s=st(gt(n.root,t));return new Bt({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{},status:"active"},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.status=void 0,this.error=void 0,this.context=void 0,this.historyValue={},this.configuration=void 0,this.children=void 0,this.context=t.context,this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(st(gt(e.root,t.value))),this.children=t.children,this.value=rt(e.root,this.configuration),this.tags=new Set(b(this.configuration.map((t=>t.tags)))),this.status=t.status,this.output=t.output,this.error=t.error}toStrings(t=this.value){if("string"==typeof t)return[t];const n=Object.keys(t);return n.concat(...n.map((n=>this.toStrings(t[n]).map((t=>n+e+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return v(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return J(this,"nextEvents",(()=>[...new Set(b([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function zt(t,e={}){return new Bt({...t,...e},t.machine)}function Wt(t){let e;for(const n in t){const s=t[n];if(s&&"object"==typeof s)if("sessionId"in s&&"send"in s&&"ref"in s)e??=Array.isArray(t)?t.slice():{...t},e[n]={xstate$$type:A,id:s.id};else{const i=Wt(s);i!==s&&(e??=Array.isArray(t)?t.slice():{...t},e[n]=i)}}return e??t}function Ut(t,{machine:e,context:n},s,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a}=r;if("string"==typeof o){const c=j(e,o);if(!c)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u="input"in r?r.input:c.input,f=C(c.src,{id:r.id,parent:t.self,input:"function"==typeof u?u({context:n,event:s,self:t.self}):u,src:o,systemId:a});return i[f.id]=f,r.syncSnapshot&&f.subscribe({next:e=>{"active"===e.status&&t.self.send({type:`xstate.snapshot.${f.id}`,snapshot:e})},error:()=>{}}),f}{const e=C(o,{id:r.id,parent:t.self,input:r.input,src:void 0,systemId:a});return r.syncSnapshot&&e.subscribe({next:n=>{"active"===n.status&&t.self.send({type:`xstate.snapshot.${e.id}`,snapshot:n,id:e.id})},error:()=>{}}),e}})(o,r);return i[a.id]=a,t.defer((()=>{if(a.status!==M.Stopped)try{a.start?.()}catch(e){return void t.self.send(u(a.id,e))}})),a}}function qt(t,e,n,{assignment:s}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,action:n.action,spawn:Ut(t,e,n.event,i),self:t?.self,system:t?.system};let r={};if("function"==typeof s)r=s(o);else for(const t of Object.keys(s)){const e=s[t];r[t]="function"==typeof e?e(o):e}return[zt(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Gt(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=qt,e}function Qt(t,e,n,{branches:s}){const i=s.find((t=>!t.guard||Z(t.guard,e.context,n.event,e)))?.actions;return[e,void 0,w(i)]}function Ft(t,e,n,{value:s,label:i}){return[e,{value:"function"==typeof s?s(n):s,label:i}]}function Xt({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function Ht(t,e,n,{get:s}){return[e,void 0,w(s({context:n.context,event:n.event}))]}function Kt(t,e,n,{event:s,id:i,delay:o},{internalQueue:r}){const a=e.machine.implementations.delays;if("string"==typeof s)throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);const c="function"==typeof s?s(n):s;let u;if("string"==typeof o){const t=a&&a[o];u="function"==typeof t?t(n):t}else u="function"==typeof o?o(n):o;return"number"!=typeof u&&r.push(c),[e,{event:c,id:i,delay:u}]}function Lt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function Yt(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Kt,n.execute=Lt,n}let Zt=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function te(t,e,n,{to:s,event:i,id:o,delay:r},a){const c=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const u="function"==typeof i?i(n):i;let f;if("string"==typeof r){const t=c&&c[r];f="function"==typeof t?t(n):t}else f="function"==typeof r?r(n):r;const h="function"==typeof s?s(n):s;let d;if("string"==typeof h){if(d=h===Zt.Parent?t?.self._parent:h===Zt.Internal?t?.self:h.startsWith("#_")?e.children[h.slice(2)]:a.deferredActorIds?.includes(h)?h:e.children[h],!d)throw new Error(`Unable to send event to actor '${h}' from machine '${e.machine.id}'.`)}else d=h||t?.self;return[e,{to:d,event:u,id:o,delay:f}]}function ee(t,e,n){"string"==typeof n.to&&(n.to=e.children[n.to])}function ne(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:n,event:s}=e;t?.system._relay(t.self,n,s.type===o?u(t.self.id,s.data):s)})):t.self.delaySend(e)}function se(t,e,n){function s(t){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=te,s.retryResolve=ee,s.execute=ne,s}function ie(t,e){return se(Zt.Parent,t,e)}function oe(t,e){return{config:t,transition:(e,n,s)=>({...e,context:t(e.context,n,s)}),getInitialState:(t,n)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:n}):e}),getPersistedState:t=>t,restoreState:t=>t}}const re="$$xstate.resolve",ae="$$xstate.reject";const ce=oe((t=>{}),void 0);const ue={},fe=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class he{constructor(t,n){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(e),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?x(this.config.states,((t,e)=>new he(t,{_parent:this,_key:e,_machine:this.machine}))):ue,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=w(this.config.entry).slice(),this.exit=w(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=w(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===s)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const i=t.config.on[n];e.set(n,I(i).map((e=>ft(t,n,e))))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,I(t.config.onDone).map((e=>ft(t,n,e))))}for(const n of t.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;e.set(s,I(n.onDone).map((e=>ft(t,s,e))))}if(n.onError){const s=`xstate.error.actor.${n.id}`;e.set(s,I(n.onError).map((e=>ft(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,I(n.onSnapshot).map((e=>ft(t,s,e))))}}for(const n of t.after){let t=e.get(n.eventType);t||(t=[],e.set(n.eventType,t)),t.push(n)}return e}(this),this.config.always&&(this.always=I(this.config.always).map((t=>ft(this,s,t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(fe),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(fe),eventType:null})}:void 0,history:this.history,states:x(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(fe)}))),entry:this.entry.map(fe),exit:this.exit.map(fe),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return J(this,"invoke",(()=>w(this.config.invoke).map(((t,e)=>{const{src:n,systemId:s}=t,i=t.id||O(this.id,e),o="string"==typeof n?n:`xstate#${O(this.id,e)}`;return{...t,src:o,id:i,systemId:s,toJSON(){const{onDone:e,onError:n,...s}=t;return{...s,type:"xstate.invoke",src:o,id:i}}}}))))}get on(){return J(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,n])=>(t[e]=t[e]||[],t[e].push(n),t)),{})))}get after(){return J(this,"delayedTransitions",(()=>ut(this)))}get initial(){return J(this,"initial",(()=>function(t,e){const n="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const s={source:t,actions:e&&"string"!=typeof e?w(e.actions):[],eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return s}(this,this.config.initial)))}next(t,e){const n=e.type,s=[];let i;const o=J(this,`candidates-${n}`,(()=>{return e=n,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),s=e.split(".");for(let t=0;t<n.length;t++){const e=n[t],i=s[t];if("*"===e)return t===n.length-1;if(e!==i)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of o){const{guard:o}=r,a=t.context;let c=!1;try{c=!o||Z(o,a,e,t)}catch(t){const e="string"==typeof o?o:"object"==typeof o?o.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(c){s.push(...r.actions),i=r;break}}return i?[i]:void 0}get events(){return J(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class de{constructor(t,e){this.config=t,this.version=void 0,this.implementations=void 0,this.types=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TContext=void 0,this.__TEvent=void 0,this.__TActor=void 0,this.__TAction=void 0,this.__TGuard=void 0,this.__TDelay=void 0,this.__TTag=void 0,this.__TInput=void 0,this.__TOutput=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.types=this.config.types??{},this.transition=this.transition.bind(this),this.getInitialState=this.getInitialState.bind(this),this.restoreState=this.restoreState.bind(this),this.start=this.start.bind(this),this.getPersistedState=this.getPersistedState.bind(this),this.root=new he(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:i}=this.implementations;return new de(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=st(gt(this.root,t.value)),n=Array.from(e);return this.createState({...t,value:Vt(this.root,t.value),configuration:n,status:at(e,this.root)?"done":t.status})}resolveStateValue(t,...[e]){const n=Vt(this.root,t);return this.resolveState(Bt.from(n,e,this))}transition(t,e,n){if(function(t){return t.type.startsWith("xstate.error.actor")}(e)&&!t.nextEvents.some((t=>t===e.type)))return zt(t,{status:"error",error:e.data});const{state:s}=Nt(t,e,n);return s}microstep(t,e,n){return Nt(t,e,n).microstates}getTransitionData(t,e){return mt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,n){const{context:s}=this.config,i=this.resolveState(this.createState({value:{},context:"function"!=typeof s&&s?s:{},meta:void 0,configuration:Jt(this.root),children:{},status:"active"}));if("function"==typeof s){return Pt(i,e,t,[Gt((({spawn:t,event:e})=>s({spawn:t,input:e.input})))],n)}return i}getInitialState(t,e){const n=f(e),s=[],i=this.getPreInitialState(t,n,s),o=Tt([{target:[...lt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,t,n,!0,s),{state:r}=Nt(o,n,t,s);return r}start(t){Object.values(t.children).forEach((t=>{0===t.status&&t.start()}))}getStateNodeById(t){const n=t.split(e),s=n.slice(1),i=ct(n[0])?n[0].slice(1):n[0],o=this.idMap.get(i);if(!o)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return vt(o,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedState(t){return function(t){const{configuration:e,tags:n,machine:s,children:i,context:o,...r}=t,a={};for(const t in i){const e=i[t];a[t]={state:e.getPersistedState?.(),src:e.src}}return{...r,context:Wt(o),children:a}}(t)}createState(t){return t instanceof Bt?t:new Bt(t,this)}restoreState(t,e){const n={};Object.keys(t.children).forEach((s=>{const i=t.children[s],o=i.state,r=i.src,a=r?j(this,r)?.src:void 0;if(!a)return;const c=a.restoreState?.(o,e),u=C(a,{id:s,parent:e?.self,state:c});n[s]=u}));const s=this.createState(new Bt({...t,children:n},this));let i=new Set;return function t(e,n){if(!i.has(e)){i.add(e);for(let s in e){const i=e[s];if(i&&"object"==typeof i){if("xstate$$type"in i&&i.xstate$$type===A){e[s]=n[i.id];continue}t(i,n)}}}}(s.context,n),s}}const pe={timeout:1e4};t.Actor=R,t.ActorStatus=M,t.InterpreterStatus=P,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0}now(){return this._now}getId(){return this._id++}setTimeout(t,e){const n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}clearTimeout(t){this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){[...this.timeouts].sort((([t,e],[n,s])=>{const i=e.start+e.timeout;return s.start+s.timeout>i?-1:1})).forEach((([t,e])=>{this.now()-e.start>=e.timeout&&(this.timeouts.delete(t),e.fn.call(null))}))}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=Zt,t.State=Bt,t.StateMachine=de,t.StateNode=he,t.and=function(t){function e(t){return!1}return e.check=L,e.guards=t,e},t.assign=Gt,t.cancel=W,t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=Qt,e},t.createActor=C,t.createEmptyActor=function(){return C(ce)},t.createMachine=function(t,e){return new de(t,e)},t.escalate=function(t,e){return ie((e=>({type:o,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return se(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(t,{self:e,system:n})=>{n._relay(e,e,{type:"xstate.create"})},transition:(e,n,{self:s,system:i})=>{if("xstate.create"===n.type){const n=t=>{"stopped"!==e.status&&s._parent&&i._relay(s,s._parent,t)},o=t=>{e._receivers.add(t)};return e._dispose=t({input:e.input,system:i,self:s,sendBack:n,receive:o}),e}return n.type===r?("function"==typeof(e={...e,status:"stopped",error:void 0})._dispose&&e._dispose(),e):(e._receivers.forEach((t=>t(n))),e)},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e,_receivers:new Set,_dispose:void 0}),getPersistedState:({_dispose:t,_receivers:e,...n})=>n,restoreState:t=>({_receivers:new Set,_dispose:void 0,...t})}},t.fromEventObservable=function(t){const e="$$xstate.error",n="$$xstate.complete";return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case e:return{...t,status:"error",error:s.data,input:void 0,_subscription:void 0};case n:return{...t,status:"done",input:void 0,_subscription:void 0};case r:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(s,{self:i,system:o})=>{"done"!==s.status&&(s._subscription=t({input:s.input,system:o,self:i}).subscribe({next:t=>{i._parent&&o._relay(i,i._parent,t)},error:t=>{o._relay(i,i,{type:e,data:t})},complete:()=>{o._relay(i,i,{type:n})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",n="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,i,{self:o,id:a,defer:c,system:u})=>{if("active"!==t.status)return t;switch(i.type){case e:return{...t,context:i.data};case n:return{...t,status:"error",error:i.data,input:void 0,_subscription:void 0};case s:return{...t,status:"done",input:void 0,_subscription:void 0};case r:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(i,{self:o,system:r})=>{"done"!==i.status&&(i._subscription=t({input:i.input,system:r,self:o}).subscribe({next:t=>{r._relay(o,o,{type:e,data:t})},error:t=>{r._relay(o,o,{type:n,data:t})},complete:()=>{r._relay(o,o,{type:s})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case re:{const n=e.data;return{...t,status:"done",output:n,input:void 0}}case ae:return{...t,status:"error",error:e.data,input:void 0};case r:return{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:n,system:s})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:s,self:n})).then((t=>{"active"===n.getSnapshot().status&&s._relay(n,n,{type:re,data:t})}),(t=>{"active"===n.getSnapshot().status&&s._relay(n,n,{type:ae,data:t})}))},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=oe,t.getStateNodes=gt,t.interpret=D,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=Ft,n.execute=Xt,n},t.mapState=function(t,e){let n;for(const s of Object.keys(t))v(s,e)&&(!n||e.length>n.length)&&(n=s);return t[n]},t.matchesState=v,t.not=function(t){function e(t){return!1}return e.check=K,e.guards=[t],e},t.or=function(t){function e(t){return!1}return e.check=Y,e.guards=t,e},t.pathToStateValue=_,t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=Ht,e},t.raise=Yt,t.sendParent=ie,t.sendTo=se,t.stateIn=function(t){function e(t){return!1}return e.check=H,e.stateValue=t,e},t.stop=X,t.toObserver=E,t.waitFor=function(t,e,n){const s={...pe,...n};return new Promise(((n,i)=>{let o=!1;const r=s.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),i(new Error(`Timeout of ${s.timeout} ms exceeded`))}),s.timeout),a=()=>{clearTimeout(r),o=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),n(t))}let u;c(t.getSnapshot()),o||(u=t.subscribe({next:c,error:t=>{a(),i(t)},complete:()=>{a(),i(new Error("Actor terminated without satisfying predicate"))}}),o&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate.umd.min.js.map
|