xstate 5.19.2 → 5.19.4

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 (32) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  6. package/actors/dist/xstate-actors.cjs.js +1 -1
  7. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.esm.js +1 -1
  9. package/actors/dist/xstate-actors.esm.js +1 -1
  10. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  11. package/dist/declarations/src/StateMachine.d.ts +3 -4
  12. package/dist/declarations/src/types.d.ts +4 -1
  13. package/dist/{log-0acd9069.development.esm.js → log-5a7b5528.development.esm.js} +7 -3
  14. package/dist/{log-3d9d72a9.esm.js → log-655aa404.esm.js} +7 -3
  15. package/dist/{log-a019fbd0.cjs.js → log-fa2e731a.cjs.js} +7 -3
  16. package/dist/{log-8aa651a0.development.cjs.js → log-fadc8808.development.cjs.js} +7 -3
  17. package/dist/{raise-c17ec2bc.esm.js → raise-3e01e82a.esm.js} +21 -3
  18. package/dist/{raise-60cebf03.cjs.js → raise-5872b9e8.cjs.js} +21 -3
  19. package/dist/{raise-1db27a82.development.esm.js → raise-59549771.development.esm.js} +21 -3
  20. package/dist/{raise-4acdb210.development.cjs.js → raise-7a84f9f0.development.cjs.js} +21 -3
  21. package/dist/xstate.cjs.js +35 -7
  22. package/dist/xstate.development.cjs.js +38 -7
  23. package/dist/xstate.development.esm.js +40 -9
  24. package/dist/xstate.esm.js +37 -9
  25. package/dist/xstate.umd.min.js +1 -1
  26. package/dist/xstate.umd.min.js.map +1 -1
  27. package/guards/dist/xstate-guards.cjs.js +1 -1
  28. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  29. package/guards/dist/xstate-guards.development.esm.js +1 -1
  30. package/guards/dist/xstate-guards.esm.js +1 -1
  31. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  32. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-c17ec2bc.esm.js';
1
+ import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-3e01e82a.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, {
4
4
  machine,
@@ -184,6 +184,8 @@ eventOrExpr) {
184
184
  return emit;
185
185
  }
186
186
 
187
+ // this is needed to make JSDoc `@link` work properly
188
+
187
189
  /**
188
190
  * @remarks
189
191
  * `T | unknown` reduces to `unknown` and that can be problematic when it comes
@@ -203,8 +205,10 @@ eventOrExpr) {
203
205
 
204
206
  // https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
205
207
 
206
- // @TODO: Replace with native `NoInfer` when TS issue gets fixed:
207
- // https://github.com/microsoft/TypeScript/pull/57673
208
+ // @TODO: we can't use native `NoInfer` as we need those:
209
+ // https://github.com/microsoft/TypeScript/pull/61092
210
+ // https://github.com/microsoft/TypeScript/pull/61077
211
+ // but even with those fixes native NoInfer still doesn't work - further issues have to be reproduced and fixed
208
212
 
209
213
  /** @deprecated Use the built-in `NoInfer` type instead */
210
214
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-60cebf03.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-5872b9e8.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -186,6 +186,8 @@ eventOrExpr) {
186
186
  return emit;
187
187
  }
188
188
 
189
+ // this is needed to make JSDoc `@link` work properly
190
+
189
191
  /**
190
192
  * @remarks
191
193
  * `T | unknown` reduces to `unknown` and that can be problematic when it comes
@@ -205,8 +207,10 @@ eventOrExpr) {
205
207
 
206
208
  // https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
207
209
 
208
- // @TODO: Replace with native `NoInfer` when TS issue gets fixed:
209
- // https://github.com/microsoft/TypeScript/pull/57673
210
+ // @TODO: we can't use native `NoInfer` as we need those:
211
+ // https://github.com/microsoft/TypeScript/pull/61092
212
+ // https://github.com/microsoft/TypeScript/pull/61077
213
+ // but even with those fixes native NoInfer still doesn't work - further issues have to be reproduced and fixed
210
214
 
211
215
  /** @deprecated Use the built-in `NoInfer` type instead */
212
216
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-4acdb210.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-7a84f9f0.development.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -198,6 +198,8 @@ eventOrExpr) {
198
198
  return emit;
199
199
  }
200
200
 
201
+ // this is needed to make JSDoc `@link` work properly
202
+
201
203
  /**
202
204
  * @remarks
203
205
  * `T | unknown` reduces to `unknown` and that can be problematic when it comes
@@ -217,8 +219,10 @@ eventOrExpr) {
217
219
 
218
220
  // https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
219
221
 
220
- // @TODO: Replace with native `NoInfer` when TS issue gets fixed:
221
- // https://github.com/microsoft/TypeScript/pull/57673
222
+ // @TODO: we can't use native `NoInfer` as we need those:
223
+ // https://github.com/microsoft/TypeScript/pull/61092
224
+ // https://github.com/microsoft/TypeScript/pull/61077
225
+ // but even with those fixes native NoInfer still doesn't work - further issues have to be reproduced and fixed
222
226
 
223
227
  /** @deprecated Use the built-in `NoInfer` type instead */
224
228
 
@@ -13,7 +13,7 @@ class Mailbox {
13
13
  }
14
14
  clear() {
15
15
  // we can't set _current to null because we might be currently processing
16
- // and enqueue following clear shouldnt start processing the enqueued item immediately
16
+ // and enqueue following clear shouldn't start processing the enqueued item immediately
17
17
  if (this._current) {
18
18
  this._current.next = null;
19
19
  this._last = this._current;
@@ -419,6 +419,8 @@ function createSystem(rootActor, options) {
419
419
  return system;
420
420
  }
421
421
 
422
+ // those are needed to make JSDoc `@link` work properly
423
+
422
424
  let executingCustomAction = false;
423
425
  const $$ACTOR_TYPE = 1;
424
426
 
@@ -2361,7 +2363,7 @@ function macrostep(snapshot, event, actorScope, internalQueue) {
2361
2363
  const transitions = selectTransitions(currentEvent, nextSnapshot);
2362
2364
  if (isErr && !transitions.length) {
2363
2365
  // TODO: we should likely only allow transitions selected by very explicit descriptors
2364
- // `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
2366
+ // `*` shouldn't be matched, likely `xstate.error.*` shouldn't be either
2365
2367
  // similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
2366
2368
  nextSnapshot = cloneMachineSnapshot(snapshot, {
2367
2369
  status: 'error',
@@ -2505,6 +2507,21 @@ function cloneMachineSnapshot(snapshot, config = {}) {
2505
2507
  ...config
2506
2508
  }, snapshot.machine);
2507
2509
  }
2510
+ function serializeHistoryValue(historyValue) {
2511
+ if (typeof historyValue !== 'object' || historyValue === null) {
2512
+ return {};
2513
+ }
2514
+ const result = {};
2515
+ for (const key in historyValue) {
2516
+ const value = historyValue[key];
2517
+ if (Array.isArray(value)) {
2518
+ result[key] = value.map(item => ({
2519
+ id: item.id
2520
+ }));
2521
+ }
2522
+ }
2523
+ return result;
2524
+ }
2508
2525
  function getPersistedSnapshot(snapshot, options) {
2509
2526
  const {
2510
2527
  _nodes: nodes,
@@ -2532,7 +2549,8 @@ function getPersistedSnapshot(snapshot, options) {
2532
2549
  const persisted = {
2533
2550
  ...jsonValues,
2534
2551
  context: persistContext(context),
2535
- children: childrenJson
2552
+ children: childrenJson,
2553
+ historyValue: serializeHistoryValue(jsonValues.historyValue)
2536
2554
  };
2537
2555
  return persisted;
2538
2556
  }
@@ -15,7 +15,7 @@ class Mailbox {
15
15
  }
16
16
  clear() {
17
17
  // we can't set _current to null because we might be currently processing
18
- // and enqueue following clear shouldnt start processing the enqueued item immediately
18
+ // and enqueue following clear shouldn't start processing the enqueued item immediately
19
19
  if (this._current) {
20
20
  this._current.next = null;
21
21
  this._last = this._current;
@@ -421,6 +421,8 @@ function createSystem(rootActor, options) {
421
421
  return system;
422
422
  }
423
423
 
424
+ // those are needed to make JSDoc `@link` work properly
425
+
424
426
  let executingCustomAction = false;
425
427
  const $$ACTOR_TYPE = 1;
426
428
 
@@ -2363,7 +2365,7 @@ function macrostep(snapshot, event, actorScope, internalQueue) {
2363
2365
  const transitions = selectTransitions(currentEvent, nextSnapshot);
2364
2366
  if (isErr && !transitions.length) {
2365
2367
  // TODO: we should likely only allow transitions selected by very explicit descriptors
2366
- // `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
2368
+ // `*` shouldn't be matched, likely `xstate.error.*` shouldn't be either
2367
2369
  // similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
2368
2370
  nextSnapshot = cloneMachineSnapshot(snapshot, {
2369
2371
  status: 'error',
@@ -2507,6 +2509,21 @@ function cloneMachineSnapshot(snapshot, config = {}) {
2507
2509
  ...config
2508
2510
  }, snapshot.machine);
2509
2511
  }
2512
+ function serializeHistoryValue(historyValue) {
2513
+ if (typeof historyValue !== 'object' || historyValue === null) {
2514
+ return {};
2515
+ }
2516
+ const result = {};
2517
+ for (const key in historyValue) {
2518
+ const value = historyValue[key];
2519
+ if (Array.isArray(value)) {
2520
+ result[key] = value.map(item => ({
2521
+ id: item.id
2522
+ }));
2523
+ }
2524
+ }
2525
+ return result;
2526
+ }
2510
2527
  function getPersistedSnapshot(snapshot, options) {
2511
2528
  const {
2512
2529
  _nodes: nodes,
@@ -2534,7 +2551,8 @@ function getPersistedSnapshot(snapshot, options) {
2534
2551
  const persisted = {
2535
2552
  ...jsonValues,
2536
2553
  context: persistContext(context),
2537
- children: childrenJson
2554
+ children: childrenJson,
2555
+ historyValue: serializeHistoryValue(jsonValues.historyValue)
2538
2556
  };
2539
2557
  return persisted;
2540
2558
  }
@@ -13,7 +13,7 @@ class Mailbox {
13
13
  }
14
14
  clear() {
15
15
  // we can't set _current to null because we might be currently processing
16
- // and enqueue following clear shouldnt start processing the enqueued item immediately
16
+ // and enqueue following clear shouldn't start processing the enqueued item immediately
17
17
  if (this._current) {
18
18
  this._current.next = null;
19
19
  this._last = this._current;
@@ -422,6 +422,8 @@ function createSystem(rootActor, options) {
422
422
  return system;
423
423
  }
424
424
 
425
+ // those are needed to make JSDoc `@link` work properly
426
+
425
427
  let executingCustomAction = false;
426
428
  const $$ACTOR_TYPE = 1;
427
429
 
@@ -2411,7 +2413,7 @@ function macrostep(snapshot, event, actorScope, internalQueue) {
2411
2413
  const transitions = selectTransitions(currentEvent, nextSnapshot);
2412
2414
  if (isErr && !transitions.length) {
2413
2415
  // TODO: we should likely only allow transitions selected by very explicit descriptors
2414
- // `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
2416
+ // `*` shouldn't be matched, likely `xstate.error.*` shouldn't be either
2415
2417
  // similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
2416
2418
  nextSnapshot = cloneMachineSnapshot(snapshot, {
2417
2419
  status: 'error',
@@ -2558,6 +2560,21 @@ function cloneMachineSnapshot(snapshot, config = {}) {
2558
2560
  ...config
2559
2561
  }, snapshot.machine);
2560
2562
  }
2563
+ function serializeHistoryValue(historyValue) {
2564
+ if (typeof historyValue !== 'object' || historyValue === null) {
2565
+ return {};
2566
+ }
2567
+ const result = {};
2568
+ for (const key in historyValue) {
2569
+ const value = historyValue[key];
2570
+ if (Array.isArray(value)) {
2571
+ result[key] = value.map(item => ({
2572
+ id: item.id
2573
+ }));
2574
+ }
2575
+ }
2576
+ return result;
2577
+ }
2561
2578
  function getPersistedSnapshot(snapshot, options) {
2562
2579
  const {
2563
2580
  _nodes: nodes,
@@ -2588,7 +2605,8 @@ function getPersistedSnapshot(snapshot, options) {
2588
2605
  const persisted = {
2589
2606
  ...jsonValues,
2590
2607
  context: persistContext(context),
2591
- children: childrenJson
2608
+ children: childrenJson,
2609
+ historyValue: serializeHistoryValue(jsonValues.historyValue)
2592
2610
  };
2593
2611
  return persisted;
2594
2612
  }
@@ -15,7 +15,7 @@ class Mailbox {
15
15
  }
16
16
  clear() {
17
17
  // we can't set _current to null because we might be currently processing
18
- // and enqueue following clear shouldnt start processing the enqueued item immediately
18
+ // and enqueue following clear shouldn't start processing the enqueued item immediately
19
19
  if (this._current) {
20
20
  this._current.next = null;
21
21
  this._last = this._current;
@@ -424,6 +424,8 @@ function createSystem(rootActor, options) {
424
424
  return system;
425
425
  }
426
426
 
427
+ // those are needed to make JSDoc `@link` work properly
428
+
427
429
  exports.executingCustomAction = false;
428
430
  const $$ACTOR_TYPE = 1;
429
431
 
@@ -2413,7 +2415,7 @@ function macrostep(snapshot, event, actorScope, internalQueue) {
2413
2415
  const transitions = selectTransitions(currentEvent, nextSnapshot);
2414
2416
  if (isErr && !transitions.length) {
2415
2417
  // TODO: we should likely only allow transitions selected by very explicit descriptors
2416
- // `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
2418
+ // `*` shouldn't be matched, likely `xstate.error.*` shouldn't be either
2417
2419
  // similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
2418
2420
  nextSnapshot = cloneMachineSnapshot(snapshot, {
2419
2421
  status: 'error',
@@ -2560,6 +2562,21 @@ function cloneMachineSnapshot(snapshot, config = {}) {
2560
2562
  ...config
2561
2563
  }, snapshot.machine);
2562
2564
  }
2565
+ function serializeHistoryValue(historyValue) {
2566
+ if (typeof historyValue !== 'object' || historyValue === null) {
2567
+ return {};
2568
+ }
2569
+ const result = {};
2570
+ for (const key in historyValue) {
2571
+ const value = historyValue[key];
2572
+ if (Array.isArray(value)) {
2573
+ result[key] = value.map(item => ({
2574
+ id: item.id
2575
+ }));
2576
+ }
2577
+ }
2578
+ return result;
2579
+ }
2563
2580
  function getPersistedSnapshot(snapshot, options) {
2564
2581
  const {
2565
2582
  _nodes: nodes,
@@ -2590,7 +2607,8 @@ function getPersistedSnapshot(snapshot, options) {
2590
2607
  const persisted = {
2591
2608
  ...jsonValues,
2592
2609
  context: persistContext(context),
2593
- children: childrenJson
2610
+ children: childrenJson,
2611
+ historyValue: serializeHistoryValue(jsonValues.historyValue)
2594
2612
  };
2595
2613
  return persisted;
2596
2614
  }
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
6
- var guards_dist_xstateGuards = require('./raise-60cebf03.cjs.js');
7
- var log = require('./log-a019fbd0.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-5872b9e8.cjs.js');
7
+ var log = require('./log-fa2e731a.cjs.js');
8
8
  require('../dev/dist/xstate-dev.cjs.js');
9
9
 
10
10
  /**
@@ -367,11 +367,10 @@ class StateMachine {
367
367
  }
368
368
 
369
369
  /**
370
- * Clones this state machine with the provided implementations and merges the
371
- * `context` (if provided).
370
+ * Clones this state machine with the provided implementations.
372
371
  *
373
- * @param implementations Options (`actions`, `guards`, `actors`, `delays`,
374
- * `context`) to recursively merge with the existing options.
372
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`)
373
+ * to recursively merge with the existing options.
375
374
  * @returns A new `StateMachine` instance with the provided implementations.
376
375
  */
377
376
  provide(implementations) {
@@ -536,10 +535,39 @@ class StateMachine {
536
535
  });
537
536
  children[actorId] = actorRef;
538
537
  });
538
+ function resolveHistoryReferencedState(root, referenced) {
539
+ if (referenced instanceof StateNode) {
540
+ return referenced;
541
+ }
542
+ try {
543
+ return root.machine.getStateNodeById(referenced.id);
544
+ } catch {
545
+ }
546
+ }
547
+ function reviveHistoryValue(root, historyValue) {
548
+ if (!historyValue || typeof historyValue !== 'object') {
549
+ return {};
550
+ }
551
+ const revived = {};
552
+ for (const key in historyValue) {
553
+ const arr = historyValue[key];
554
+ for (const item of arr) {
555
+ const resolved = resolveHistoryReferencedState(root, item);
556
+ if (!resolved) {
557
+ continue;
558
+ }
559
+ revived[key] ??= [];
560
+ revived[key].push(resolved);
561
+ }
562
+ }
563
+ return revived;
564
+ }
565
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
539
566
  const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
540
567
  ...snapshot,
541
568
  children,
542
- _nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
569
+ _nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value))),
570
+ historyValue: revivedHistoryValue
543
571
  }, this);
544
572
  const seen = new Set();
545
573
  function reviveContext(contextPart, children) {
@@ -3,8 +3,8 @@
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 guards_dist_xstateGuards = require('./raise-4acdb210.development.cjs.js');
7
- var log = require('./log-8aa651a0.development.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-7a84f9f0.development.cjs.js');
7
+ var log = require('./log-fadc8808.development.cjs.js');
8
8
  require('../dev/dist/xstate-dev.development.cjs.js');
9
9
 
10
10
  /**
@@ -370,11 +370,10 @@ class StateMachine {
370
370
  }
371
371
 
372
372
  /**
373
- * Clones this state machine with the provided implementations and merges the
374
- * `context` (if provided).
373
+ * Clones this state machine with the provided implementations.
375
374
  *
376
- * @param implementations Options (`actions`, `guards`, `actors`, `delays`,
377
- * `context`) to recursively merge with the existing options.
375
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`)
376
+ * to recursively merge with the existing options.
378
377
  * @returns A new `StateMachine` instance with the provided implementations.
379
378
  */
380
379
  provide(implementations) {
@@ -539,10 +538,42 @@ class StateMachine {
539
538
  });
540
539
  children[actorId] = actorRef;
541
540
  });
541
+ function resolveHistoryReferencedState(root, referenced) {
542
+ if (referenced instanceof StateNode) {
543
+ return referenced;
544
+ }
545
+ try {
546
+ return root.machine.getStateNodeById(referenced.id);
547
+ } catch {
548
+ {
549
+ console.warn(`Could not resolve StateNode for id: ${referenced.id}`);
550
+ }
551
+ }
552
+ }
553
+ function reviveHistoryValue(root, historyValue) {
554
+ if (!historyValue || typeof historyValue !== 'object') {
555
+ return {};
556
+ }
557
+ const revived = {};
558
+ for (const key in historyValue) {
559
+ const arr = historyValue[key];
560
+ for (const item of arr) {
561
+ const resolved = resolveHistoryReferencedState(root, item);
562
+ if (!resolved) {
563
+ continue;
564
+ }
565
+ revived[key] ??= [];
566
+ revived[key].push(resolved);
567
+ }
568
+ }
569
+ return revived;
570
+ }
571
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
542
572
  const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
543
573
  ...snapshot,
544
574
  children,
545
- _nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
575
+ _nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value))),
576
+ historyValue: revivedHistoryValue
546
577
  }, this);
547
578
  const seen = new Set();
548
579
  function reviveContext(contextPart, children) {
@@ -1,8 +1,8 @@
1
1
  export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
2
- import { t as toArray, S as STATE_DELIMITER, m as mapValues, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-1db27a82.development.esm.js';
3
- export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-1db27a82.development.esm.js';
4
- import { a as assign } from './log-0acd9069.development.esm.js';
5
- export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-0acd9069.development.esm.js';
2
+ import { t as toArray, S as STATE_DELIMITER, m as mapValues, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-59549771.development.esm.js';
3
+ export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-59549771.development.esm.js';
4
+ import { a as assign } from './log-5a7b5528.development.esm.js';
5
+ export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-5a7b5528.development.esm.js';
6
6
  import '../dev/dist/xstate-dev.development.esm.js';
7
7
 
8
8
  /**
@@ -368,11 +368,10 @@ class StateMachine {
368
368
  }
369
369
 
370
370
  /**
371
- * Clones this state machine with the provided implementations and merges the
372
- * `context` (if provided).
371
+ * Clones this state machine with the provided implementations.
373
372
  *
374
- * @param implementations Options (`actions`, `guards`, `actors`, `delays`,
375
- * `context`) to recursively merge with the existing options.
373
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`)
374
+ * to recursively merge with the existing options.
376
375
  * @returns A new `StateMachine` instance with the provided implementations.
377
376
  */
378
377
  provide(implementations) {
@@ -537,10 +536,42 @@ class StateMachine {
537
536
  });
538
537
  children[actorId] = actorRef;
539
538
  });
539
+ function resolveHistoryReferencedState(root, referenced) {
540
+ if (referenced instanceof StateNode) {
541
+ return referenced;
542
+ }
543
+ try {
544
+ return root.machine.getStateNodeById(referenced.id);
545
+ } catch {
546
+ {
547
+ console.warn(`Could not resolve StateNode for id: ${referenced.id}`);
548
+ }
549
+ }
550
+ }
551
+ function reviveHistoryValue(root, historyValue) {
552
+ if (!historyValue || typeof historyValue !== 'object') {
553
+ return {};
554
+ }
555
+ const revived = {};
556
+ for (const key in historyValue) {
557
+ const arr = historyValue[key];
558
+ for (const item of arr) {
559
+ const resolved = resolveHistoryReferencedState(root, item);
560
+ if (!resolved) {
561
+ continue;
562
+ }
563
+ revived[key] ??= [];
564
+ revived[key].push(resolved);
565
+ }
566
+ }
567
+ return revived;
568
+ }
569
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
540
570
  const restoredSnapshot = createMachineSnapshot({
541
571
  ...snapshot,
542
572
  children,
543
- _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
573
+ _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value))),
574
+ historyValue: revivedHistoryValue
544
575
  }, this);
545
576
  const seen = new Set();
546
577
  function reviveContext(contextPart, children) {
@@ -1,8 +1,8 @@
1
1
  export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
2
- import { t as toArray, S as STATE_DELIMITER, m as mapValues, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-c17ec2bc.esm.js';
3
- export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-c17ec2bc.esm.js';
4
- import { a as assign } from './log-3d9d72a9.esm.js';
5
- export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-3d9d72a9.esm.js';
2
+ import { t as toArray, S as STATE_DELIMITER, m as mapValues, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-3e01e82a.esm.js';
3
+ export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-3e01e82a.esm.js';
4
+ import { a as assign } from './log-655aa404.esm.js';
5
+ export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-655aa404.esm.js';
6
6
  import '../dev/dist/xstate-dev.esm.js';
7
7
 
8
8
  /**
@@ -365,11 +365,10 @@ class StateMachine {
365
365
  }
366
366
 
367
367
  /**
368
- * Clones this state machine with the provided implementations and merges the
369
- * `context` (if provided).
368
+ * Clones this state machine with the provided implementations.
370
369
  *
371
- * @param implementations Options (`actions`, `guards`, `actors`, `delays`,
372
- * `context`) to recursively merge with the existing options.
370
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`)
371
+ * to recursively merge with the existing options.
373
372
  * @returns A new `StateMachine` instance with the provided implementations.
374
373
  */
375
374
  provide(implementations) {
@@ -534,10 +533,39 @@ class StateMachine {
534
533
  });
535
534
  children[actorId] = actorRef;
536
535
  });
536
+ function resolveHistoryReferencedState(root, referenced) {
537
+ if (referenced instanceof StateNode) {
538
+ return referenced;
539
+ }
540
+ try {
541
+ return root.machine.getStateNodeById(referenced.id);
542
+ } catch {
543
+ }
544
+ }
545
+ function reviveHistoryValue(root, historyValue) {
546
+ if (!historyValue || typeof historyValue !== 'object') {
547
+ return {};
548
+ }
549
+ const revived = {};
550
+ for (const key in historyValue) {
551
+ const arr = historyValue[key];
552
+ for (const item of arr) {
553
+ const resolved = resolveHistoryReferencedState(root, item);
554
+ if (!resolved) {
555
+ continue;
556
+ }
557
+ revived[key] ??= [];
558
+ revived[key].push(resolved);
559
+ }
560
+ }
561
+ return revived;
562
+ }
563
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
537
564
  const restoredSnapshot = createMachineSnapshot({
538
565
  ...snapshot,
539
566
  children,
540
- _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
567
+ _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value))),
568
+ historyValue: revivedHistoryValue
541
569
  }, this);
542
570
  const seen = new Set();
543
571
  function reviveContext(contextPart, children) {