xstate 5.19.4 → 5.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +0 -1
  2. package/actions/dist/xstate-actions.cjs.d.ts +1 -1
  3. package/actions/dist/xstate-actions.cjs.js +8 -7
  4. package/actions/dist/xstate-actions.development.cjs.js +8 -7
  5. package/actions/dist/xstate-actions.development.esm.js +3 -2
  6. package/actions/dist/xstate-actions.esm.js +3 -2
  7. package/actions/dist/xstate-actions.umd.min.js +1 -1
  8. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  9. package/actors/dist/xstate-actors.cjs.d.ts +1 -1
  10. package/actors/dist/xstate-actors.development.esm.js +1 -1
  11. package/actors/dist/xstate-actors.esm.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dev/dist/xstate-dev.cjs.d.ts +1 -1
  14. package/dev/dist/xstate-dev.umd.min.js.map +1 -1
  15. package/dist/StateMachine-1cda96d3.cjs.js +560 -0
  16. package/dist/StateMachine-38b5bb3f.development.cjs.js +566 -0
  17. package/dist/StateMachine-b4e94439.development.esm.js +563 -0
  18. package/dist/StateMachine-c88ea5dd.esm.js +557 -0
  19. package/dist/assign-6313ccb3.development.esm.js +133 -0
  20. package/dist/assign-c3259787.esm.js +127 -0
  21. package/dist/assign-c84786ab.development.cjs.js +135 -0
  22. package/dist/assign-e9c344ea.cjs.js +129 -0
  23. package/dist/declarations/src/StateMachine.d.ts +2 -2
  24. package/dist/declarations/src/createMachine.d.ts +1 -2
  25. package/dist/declarations/src/graph/TestModel.d.ts +70 -0
  26. package/dist/declarations/src/graph/adjacency.d.ts +8 -0
  27. package/dist/declarations/src/graph/graph.d.ts +14 -0
  28. package/dist/declarations/src/graph/index.d.ts +9 -0
  29. package/dist/declarations/src/graph/pathFromEvents.d.ts +3 -0
  30. package/dist/declarations/src/graph/pathGenerators.d.ts +4 -0
  31. package/dist/declarations/src/graph/shortestPaths.d.ts +3 -0
  32. package/dist/declarations/src/graph/simplePaths.d.ts +3 -0
  33. package/dist/declarations/src/graph/types.d.ts +159 -0
  34. package/dist/declarations/src/index.d.ts +1 -1
  35. package/dist/declarations/src/inspection.d.ts +1 -1
  36. package/dist/{log-655aa404.esm.js → log-1c257a58.esm.js} +3 -126
  37. package/dist/{log-fa2e731a.cjs.js → log-215998b6.cjs.js} +2 -126
  38. package/dist/{log-fadc8808.development.cjs.js → log-2c8d7f98.development.cjs.js} +2 -132
  39. package/dist/{log-5a7b5528.development.esm.js → log-ef959da6.development.esm.js} +3 -132
  40. package/dist/{raise-59549771.development.esm.js → raise-78b8dcb8.development.esm.js} +1 -1
  41. package/dist/{raise-3e01e82a.esm.js → raise-b0a4e862.esm.js} +1 -1
  42. package/dist/xstate.cjs.d.ts +1 -1
  43. package/dist/xstate.cjs.js +7 -558
  44. package/dist/xstate.development.cjs.js +7 -564
  45. package/dist/xstate.development.esm.js +7 -564
  46. package/dist/xstate.esm.js +7 -558
  47. package/dist/xstate.umd.min.js +1 -1
  48. package/dist/xstate.umd.min.js.map +1 -1
  49. package/graph/dist/xstate-graph.cjs.d.mts +2 -0
  50. package/graph/dist/xstate-graph.cjs.d.ts +2 -0
  51. package/graph/dist/xstate-graph.cjs.js +901 -0
  52. package/graph/dist/xstate-graph.cjs.mjs +15 -0
  53. package/graph/dist/xstate-graph.development.cjs.js +901 -0
  54. package/graph/dist/xstate-graph.development.cjs.mjs +15 -0
  55. package/graph/dist/xstate-graph.development.esm.js +885 -0
  56. package/graph/dist/xstate-graph.esm.js +885 -0
  57. package/graph/dist/xstate-graph.umd.min.js +2 -0
  58. package/graph/dist/xstate-graph.umd.min.js.map +1 -0
  59. package/graph/package.json +8 -0
  60. package/guards/dist/xstate-guards.cjs.d.ts +1 -1
  61. package/guards/dist/xstate-guards.development.esm.js +1 -1
  62. package/guards/dist/xstate-guards.esm.js +1 -1
  63. package/guards/dist/xstate-guards.umd.min.js +1 -1
  64. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  65. package/package.json +22 -6
@@ -0,0 +1,563 @@
1
+ import { S as STATE_DELIMITER, l as mapValues, t as toArray, q as formatTransitions, u as toTransitionConfigArray, v as formatTransition, N as NULL_EVENT, w as evaluateGuard, x as createInvokeId, y as getDelayedTransitions, z as formatInitialTransition, B as getCandidates, C as resolveStateValue, D as getAllStateNodes, g as getStateNodes, E as createMachineSnapshot, F as isInFinalState, G as macrostep, H as transitionNode, I as resolveActionsAndContext, J as createInitEvent, K as microstep, L as getInitialStateNodes, M as toStatePath, O as isStateId, P as getStateNodeByPath, Q as getPersistedSnapshot, R as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-78b8dcb8.development.esm.js';
2
+ import { a as assign } from './assign-6313ccb3.development.esm.js';
3
+
4
+ const cache = new WeakMap();
5
+ function memo(object, key, fn) {
6
+ let memoizedData = cache.get(object);
7
+ if (!memoizedData) {
8
+ memoizedData = {
9
+ [key]: fn()
10
+ };
11
+ cache.set(object, memoizedData);
12
+ } else if (!(key in memoizedData)) {
13
+ memoizedData[key] = fn();
14
+ }
15
+ return memoizedData[key];
16
+ }
17
+
18
+ const EMPTY_OBJECT = {};
19
+ const toSerializableAction = action => {
20
+ if (typeof action === 'string') {
21
+ return {
22
+ type: action
23
+ };
24
+ }
25
+ if (typeof action === 'function') {
26
+ if ('resolve' in action) {
27
+ return {
28
+ type: action.type
29
+ };
30
+ }
31
+ return {
32
+ type: action.name
33
+ };
34
+ }
35
+ return action;
36
+ };
37
+ class StateNode {
38
+ constructor(/** The raw config used to create the machine. */
39
+ config, options) {
40
+ this.config = config;
41
+ /**
42
+ * The relative key of the state node, which represents its location in the
43
+ * overall state value.
44
+ */
45
+ this.key = void 0;
46
+ /** The unique ID of the state node. */
47
+ this.id = void 0;
48
+ /**
49
+ * The type of this state node:
50
+ *
51
+ * - `'atomic'` - no child state nodes
52
+ * - `'compound'` - nested child state nodes (XOR)
53
+ * - `'parallel'` - orthogonal nested child state nodes (AND)
54
+ * - `'history'` - history state node
55
+ * - `'final'` - final state node
56
+ */
57
+ this.type = void 0;
58
+ /** The string path from the root machine node to this node. */
59
+ this.path = void 0;
60
+ /** The child state nodes. */
61
+ this.states = void 0;
62
+ /**
63
+ * The type of history on this state node. Can be:
64
+ *
65
+ * - `'shallow'` - recalls only top-level historical state value
66
+ * - `'deep'` - recalls historical state value at all levels
67
+ */
68
+ this.history = void 0;
69
+ /** The action(s) to be executed upon entering the state node. */
70
+ this.entry = void 0;
71
+ /** The action(s) to be executed upon exiting the state node. */
72
+ this.exit = void 0;
73
+ /** The parent state node. */
74
+ this.parent = void 0;
75
+ /** The root machine node. */
76
+ this.machine = void 0;
77
+ /**
78
+ * The meta data associated with this state node, which will be returned in
79
+ * State instances.
80
+ */
81
+ this.meta = void 0;
82
+ /**
83
+ * The output data sent with the "xstate.done.state._id_" event if this is a
84
+ * final state node.
85
+ */
86
+ this.output = void 0;
87
+ /**
88
+ * The order this state node appears. Corresponds to the implicit document
89
+ * order.
90
+ */
91
+ this.order = -1;
92
+ this.description = void 0;
93
+ this.tags = [];
94
+ this.transitions = void 0;
95
+ this.always = void 0;
96
+ this.parent = options._parent;
97
+ this.key = options._key;
98
+ this.machine = options._machine;
99
+ this.path = this.parent ? this.parent.path.concat(this.key) : [];
100
+ this.id = this.config.id || [this.machine.id, ...this.path].join(STATE_DELIMITER);
101
+ this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
102
+ this.description = this.config.description;
103
+ this.order = this.machine.idMap.size;
104
+ this.machine.idMap.set(this.id, this);
105
+ this.states = this.config.states ? mapValues(this.config.states, (stateConfig, key) => {
106
+ const stateNode = new StateNode(stateConfig, {
107
+ _parent: this,
108
+ _key: key,
109
+ _machine: this.machine
110
+ });
111
+ return stateNode;
112
+ }) : EMPTY_OBJECT;
113
+ if (this.type === 'compound' && !this.config.initial) {
114
+ 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.`);
115
+ }
116
+
117
+ // History config
118
+ this.history = this.config.history === true ? 'shallow' : this.config.history || false;
119
+ this.entry = toArray(this.config.entry).slice();
120
+ this.exit = toArray(this.config.exit).slice();
121
+ this.meta = this.config.meta;
122
+ this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
123
+ this.tags = toArray(config.tags).slice();
124
+ }
125
+
126
+ /** @internal */
127
+ _initialize() {
128
+ this.transitions = formatTransitions(this);
129
+ if (this.config.always) {
130
+ this.always = toTransitionConfigArray(this.config.always).map(t => formatTransition(this, NULL_EVENT, t));
131
+ }
132
+ Object.keys(this.states).forEach(key => {
133
+ this.states[key]._initialize();
134
+ });
135
+ }
136
+
137
+ /** The well-structured state node definition. */
138
+ get definition() {
139
+ return {
140
+ id: this.id,
141
+ key: this.key,
142
+ version: this.machine.version,
143
+ type: this.type,
144
+ initial: this.initial ? {
145
+ target: this.initial.target,
146
+ source: this,
147
+ actions: this.initial.actions.map(toSerializableAction),
148
+ eventType: null,
149
+ reenter: false,
150
+ toJSON: () => ({
151
+ target: this.initial.target.map(t => `#${t.id}`),
152
+ source: `#${this.id}`,
153
+ actions: this.initial.actions.map(toSerializableAction),
154
+ eventType: null
155
+ })
156
+ } : undefined,
157
+ history: this.history,
158
+ states: mapValues(this.states, state => {
159
+ return state.definition;
160
+ }),
161
+ on: this.on,
162
+ transitions: [...this.transitions.values()].flat().map(t => ({
163
+ ...t,
164
+ actions: t.actions.map(toSerializableAction)
165
+ })),
166
+ entry: this.entry.map(toSerializableAction),
167
+ exit: this.exit.map(toSerializableAction),
168
+ meta: this.meta,
169
+ order: this.order || -1,
170
+ output: this.output,
171
+ invoke: this.invoke,
172
+ description: this.description,
173
+ tags: this.tags
174
+ };
175
+ }
176
+
177
+ /** @internal */
178
+ toJSON() {
179
+ return this.definition;
180
+ }
181
+
182
+ /** The logic invoked as actors by this state node. */
183
+ get invoke() {
184
+ return memo(this, 'invoke', () => toArray(this.config.invoke).map((invokeConfig, i) => {
185
+ const {
186
+ src,
187
+ systemId
188
+ } = invokeConfig;
189
+ const resolvedId = invokeConfig.id ?? createInvokeId(this.id, i);
190
+ const sourceName = typeof src === 'string' ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
191
+ return {
192
+ ...invokeConfig,
193
+ src: sourceName,
194
+ id: resolvedId,
195
+ systemId: systemId,
196
+ toJSON() {
197
+ const {
198
+ onDone,
199
+ onError,
200
+ ...invokeDefValues
201
+ } = invokeConfig;
202
+ return {
203
+ ...invokeDefValues,
204
+ type: 'xstate.invoke',
205
+ src: sourceName,
206
+ id: resolvedId
207
+ };
208
+ }
209
+ };
210
+ }));
211
+ }
212
+
213
+ /** The mapping of events to transitions. */
214
+ get on() {
215
+ return memo(this, 'on', () => {
216
+ const transitions = this.transitions;
217
+ return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
218
+ map[descriptor] = map[descriptor] || [];
219
+ map[descriptor].push(transition);
220
+ return map;
221
+ }, {});
222
+ });
223
+ }
224
+ get after() {
225
+ return memo(this, 'delayedTransitions', () => getDelayedTransitions(this));
226
+ }
227
+ get initial() {
228
+ return memo(this, 'initial', () => formatInitialTransition(this, this.config.initial));
229
+ }
230
+
231
+ /** @internal */
232
+ next(snapshot, event) {
233
+ const eventType = event.type;
234
+ const actions = [];
235
+ let selectedTransition;
236
+ const candidates = memo(this, `candidates-${eventType}`, () => getCandidates(this, eventType));
237
+ for (const candidate of candidates) {
238
+ const {
239
+ guard
240
+ } = candidate;
241
+ const resolvedContext = snapshot.context;
242
+ let guardPassed = false;
243
+ try {
244
+ guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, snapshot);
245
+ } catch (err) {
246
+ const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
247
+ throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
248
+ }
249
+ if (guardPassed) {
250
+ actions.push(...candidate.actions);
251
+ selectedTransition = candidate;
252
+ break;
253
+ }
254
+ }
255
+ return selectedTransition ? [selectedTransition] : undefined;
256
+ }
257
+
258
+ /** All the event types accepted by this state node and its descendants. */
259
+ get events() {
260
+ return memo(this, 'events', () => {
261
+ const {
262
+ states
263
+ } = this;
264
+ const events = new Set(this.ownEvents);
265
+ if (states) {
266
+ for (const stateId of Object.keys(states)) {
267
+ const state = states[stateId];
268
+ if (state.states) {
269
+ for (const event of state.events) {
270
+ events.add(`${event}`);
271
+ }
272
+ }
273
+ }
274
+ }
275
+ return Array.from(events);
276
+ });
277
+ }
278
+
279
+ /**
280
+ * All the events that have transitions directly from this state node.
281
+ *
282
+ * Excludes any inert events.
283
+ */
284
+ get ownEvents() {
285
+ const events = new Set([...this.transitions.keys()].filter(descriptor => {
286
+ return this.transitions.get(descriptor).some(transition => !(!transition.target && !transition.actions.length && !transition.reenter));
287
+ }));
288
+ return Array.from(events);
289
+ }
290
+ }
291
+
292
+ const STATE_IDENTIFIER = '#';
293
+ class StateMachine {
294
+ constructor(/** The raw config used to create the machine. */
295
+ config, implementations) {
296
+ this.config = config;
297
+ /** The machine's own version. */
298
+ this.version = void 0;
299
+ this.schemas = void 0;
300
+ this.implementations = void 0;
301
+ /** @internal */
302
+ this.__xstatenode = true;
303
+ /** @internal */
304
+ this.idMap = new Map();
305
+ this.root = void 0;
306
+ this.id = void 0;
307
+ this.states = void 0;
308
+ this.events = void 0;
309
+ this.id = config.id || '(machine)';
310
+ this.implementations = {
311
+ actors: implementations?.actors ?? {},
312
+ actions: implementations?.actions ?? {},
313
+ delays: implementations?.delays ?? {},
314
+ guards: implementations?.guards ?? {}
315
+ };
316
+ this.version = this.config.version;
317
+ this.schemas = this.config.schemas;
318
+ this.transition = this.transition.bind(this);
319
+ this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
320
+ this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
321
+ this.restoreSnapshot = this.restoreSnapshot.bind(this);
322
+ this.start = this.start.bind(this);
323
+ this.root = new StateNode(config, {
324
+ _key: this.id,
325
+ _machine: this
326
+ });
327
+ this.root._initialize();
328
+ this.states = this.root.states; // TODO: remove!
329
+ this.events = this.root.events;
330
+ if (!('output' in this.root) && Object.values(this.states).some(state => state.type === 'final' && 'output' in state)) {
331
+ console.warn('Missing `machine.output` declaration (top-level final state with output detected)');
332
+ }
333
+ }
334
+
335
+ /**
336
+ * Clones this state machine with the provided implementations.
337
+ *
338
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`) to
339
+ * recursively merge with the existing options.
340
+ * @returns A new `StateMachine` instance with the provided implementations.
341
+ */
342
+ provide(implementations) {
343
+ const {
344
+ actions,
345
+ guards,
346
+ actors,
347
+ delays
348
+ } = this.implementations;
349
+ return new StateMachine(this.config, {
350
+ actions: {
351
+ ...actions,
352
+ ...implementations.actions
353
+ },
354
+ guards: {
355
+ ...guards,
356
+ ...implementations.guards
357
+ },
358
+ actors: {
359
+ ...actors,
360
+ ...implementations.actors
361
+ },
362
+ delays: {
363
+ ...delays,
364
+ ...implementations.delays
365
+ }
366
+ });
367
+ }
368
+ resolveState(config) {
369
+ const resolvedStateValue = resolveStateValue(this.root, config.value);
370
+ const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
371
+ return createMachineSnapshot({
372
+ _nodes: [...nodeSet],
373
+ context: config.context || {},
374
+ children: {},
375
+ status: isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
376
+ output: config.output,
377
+ error: config.error,
378
+ historyValue: config.historyValue
379
+ }, this);
380
+ }
381
+
382
+ /**
383
+ * Determines the next snapshot given the current `snapshot` and received
384
+ * `event`. Calculates a full macrostep from all microsteps.
385
+ *
386
+ * @param snapshot The current snapshot
387
+ * @param event The received event
388
+ */
389
+ transition(snapshot, event, actorScope) {
390
+ return macrostep(snapshot, event, actorScope, []).snapshot;
391
+ }
392
+
393
+ /**
394
+ * Determines the next state given the current `state` and `event`. Calculates
395
+ * a microstep.
396
+ *
397
+ * @param state The current state
398
+ * @param event The received event
399
+ */
400
+ microstep(snapshot, event, actorScope) {
401
+ return macrostep(snapshot, event, actorScope, []).microstates;
402
+ }
403
+ getTransitionData(snapshot, event) {
404
+ return transitionNode(this.root, snapshot.value, snapshot, event) || [];
405
+ }
406
+
407
+ /**
408
+ * The initial state _before_ evaluating any microsteps. This "pre-initial"
409
+ * state is provided to initial actions executed in the initial state.
410
+ */
411
+ getPreInitialState(actorScope, initEvent, internalQueue) {
412
+ const {
413
+ context
414
+ } = this.config;
415
+ const preInitial = createMachineSnapshot({
416
+ context: typeof context !== 'function' && context ? context : {},
417
+ _nodes: [this.root],
418
+ children: {},
419
+ status: 'active'
420
+ }, this);
421
+ if (typeof context === 'function') {
422
+ const assignment = ({
423
+ spawn,
424
+ event,
425
+ self
426
+ }) => context({
427
+ spawn,
428
+ input: event.input,
429
+ self
430
+ });
431
+ return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue, undefined);
432
+ }
433
+ return preInitial;
434
+ }
435
+
436
+ /**
437
+ * Returns the initial `State` instance, with reference to `self` as an
438
+ * `ActorRef`.
439
+ */
440
+ getInitialSnapshot(actorScope, input) {
441
+ const initEvent = createInitEvent(input); // TODO: fix;
442
+ const internalQueue = [];
443
+ const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
444
+ const nextState = microstep([{
445
+ target: [...getInitialStateNodes(this.root)],
446
+ source: this.root,
447
+ reenter: true,
448
+ actions: [],
449
+ eventType: null,
450
+ toJSON: null // TODO: fix
451
+ }], preInitialState, actorScope, initEvent, true, internalQueue);
452
+ const {
453
+ snapshot: macroState
454
+ } = macrostep(nextState, initEvent, actorScope, internalQueue);
455
+ return macroState;
456
+ }
457
+ start(snapshot) {
458
+ Object.values(snapshot.children).forEach(child => {
459
+ if (child.getSnapshot().status === 'active') {
460
+ child.start();
461
+ }
462
+ });
463
+ }
464
+ getStateNodeById(stateId) {
465
+ const fullPath = toStatePath(stateId);
466
+ const relativePath = fullPath.slice(1);
467
+ const resolvedStateId = isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
468
+ const stateNode = this.idMap.get(resolvedStateId);
469
+ if (!stateNode) {
470
+ throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
471
+ }
472
+ return getStateNodeByPath(stateNode, relativePath);
473
+ }
474
+ get definition() {
475
+ return this.root.definition;
476
+ }
477
+ toJSON() {
478
+ return this.definition;
479
+ }
480
+ getPersistedSnapshot(snapshot, options) {
481
+ return getPersistedSnapshot(snapshot, options);
482
+ }
483
+ restoreSnapshot(snapshot, _actorScope) {
484
+ const children = {};
485
+ const snapshotChildren = snapshot.children;
486
+ Object.keys(snapshotChildren).forEach(actorId => {
487
+ const actorData = snapshotChildren[actorId];
488
+ const childState = actorData.snapshot;
489
+ const src = actorData.src;
490
+ const logic = typeof src === 'string' ? resolveReferencedActor(this, src) : src;
491
+ if (!logic) {
492
+ return;
493
+ }
494
+ const actorRef = createActor(logic, {
495
+ id: actorId,
496
+ parent: _actorScope.self,
497
+ syncSnapshot: actorData.syncSnapshot,
498
+ snapshot: childState,
499
+ src,
500
+ systemId: actorData.systemId
501
+ });
502
+ children[actorId] = actorRef;
503
+ });
504
+ function resolveHistoryReferencedState(root, referenced) {
505
+ if (referenced instanceof StateNode) {
506
+ return referenced;
507
+ }
508
+ try {
509
+ return root.machine.getStateNodeById(referenced.id);
510
+ } catch {
511
+ {
512
+ console.warn(`Could not resolve StateNode for id: ${referenced.id}`);
513
+ }
514
+ }
515
+ }
516
+ function reviveHistoryValue(root, historyValue) {
517
+ if (!historyValue || typeof historyValue !== 'object') {
518
+ return {};
519
+ }
520
+ const revived = {};
521
+ for (const key in historyValue) {
522
+ const arr = historyValue[key];
523
+ for (const item of arr) {
524
+ const resolved = resolveHistoryReferencedState(root, item);
525
+ if (!resolved) {
526
+ continue;
527
+ }
528
+ revived[key] ??= [];
529
+ revived[key].push(resolved);
530
+ }
531
+ }
532
+ return revived;
533
+ }
534
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
535
+ const restoredSnapshot = createMachineSnapshot({
536
+ ...snapshot,
537
+ children,
538
+ _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value))),
539
+ historyValue: revivedHistoryValue
540
+ }, this);
541
+ const seen = new Set();
542
+ function reviveContext(contextPart, children) {
543
+ if (seen.has(contextPart)) {
544
+ return;
545
+ }
546
+ seen.add(contextPart);
547
+ for (const key in contextPart) {
548
+ const value = contextPart[key];
549
+ if (value && typeof value === 'object') {
550
+ if ('xstate$$type' in value && value.xstate$$type === $$ACTOR_TYPE) {
551
+ contextPart[key] = children[value.id];
552
+ continue;
553
+ }
554
+ reviveContext(value, children);
555
+ }
556
+ }
557
+ }
558
+ reviveContext(restoredSnapshot.context, children);
559
+ return restoredSnapshot;
560
+ }
561
+ }
562
+
563
+ export { StateMachine as S, StateNode as a };