xstate 5.19.3 → 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 +1 -1
  13. package/dist/{log-b47a3833.development.esm.js → log-5a7b5528.development.esm.js} +3 -1
  14. package/dist/{log-12aa30c9.esm.js → log-655aa404.esm.js} +3 -1
  15. package/dist/{log-179b5431.cjs.js → log-fa2e731a.cjs.js} +3 -1
  16. package/dist/{log-210b28c2.development.cjs.js → log-fadc8808.development.cjs.js} +3 -1
  17. package/dist/{raise-59f80ebb.esm.js → raise-3e01e82a.esm.js} +4 -2
  18. package/dist/{raise-cbaedcda.cjs.js → raise-5872b9e8.cjs.js} +4 -2
  19. package/dist/{raise-527db318.development.esm.js → raise-59549771.development.esm.js} +4 -2
  20. package/dist/{raise-32fab6fb.development.cjs.js → raise-7a84f9f0.development.cjs.js} +4 -2
  21. package/dist/xstate.cjs.js +21 -25
  22. package/dist/xstate.development.cjs.js +23 -27
  23. package/dist/xstate.development.esm.js +25 -29
  24. package/dist/xstate.esm.js +23 -27
  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
@@ -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',
@@ -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',
@@ -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',
@@ -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',
@@ -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-cbaedcda.cjs.js');
7
- var log = require('./log-179b5431.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,37 +535,34 @@ class StateMachine {
536
535
  });
537
536
  children[actorId] = actorRef;
538
537
  });
539
- function resolveStateNodeFromIdOrPath(idOrPath, root) {
538
+ function resolveHistoryReferencedState(root, referenced) {
539
+ if (referenced instanceof StateNode) {
540
+ return referenced;
541
+ }
540
542
  try {
541
- return root.machine.getStateNodeById(idOrPath);
543
+ return root.machine.getStateNodeById(referenced.id);
542
544
  } catch {
543
- try {
544
- return guards_dist_xstateGuards.getStateNodeByPath(root, idOrPath.split('.'));
545
- } catch {
546
- return idOrPath;
547
- }
548
545
  }
549
546
  }
550
- function reviveHistoryValue(historyValue, root) {
551
- if (!historyValue || typeof historyValue !== 'object') return {};
547
+ function reviveHistoryValue(root, historyValue) {
548
+ if (!historyValue || typeof historyValue !== 'object') {
549
+ return {};
550
+ }
552
551
  const revived = {};
553
552
  for (const key in historyValue) {
554
553
  const arr = historyValue[key];
555
- revived[key] = arr.map(item => {
556
- if (item instanceof StateNode) return item;
557
- if (typeof item === 'object' && 'id' in item && typeof item.id === 'string') {
558
- const resolved = resolveStateNodeFromIdOrPath(item.id, root);
559
- if (resolved instanceof StateNode) return resolved;
554
+ for (const item of arr) {
555
+ const resolved = resolveHistoryReferencedState(root, item);
556
+ if (!resolved) {
557
+ continue;
560
558
  }
561
- return undefined;
562
- }).filter(item => item !== undefined);
563
- if (revived[key].length === 0) {
564
- delete revived[key];
559
+ revived[key] ??= [];
560
+ revived[key].push(resolved);
565
561
  }
566
562
  }
567
563
  return revived;
568
564
  }
569
- const revivedHistoryValue = reviveHistoryValue(snapshot.historyValue, this.root);
565
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
570
566
  const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
571
567
  ...snapshot,
572
568
  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-32fab6fb.development.cjs.js');
7
- var log = require('./log-210b28c2.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,40 +538,37 @@ class StateMachine {
539
538
  });
540
539
  children[actorId] = actorRef;
541
540
  });
542
- function resolveStateNodeFromIdOrPath(idOrPath, root) {
541
+ function resolveHistoryReferencedState(root, referenced) {
542
+ if (referenced instanceof StateNode) {
543
+ return referenced;
544
+ }
543
545
  try {
544
- return root.machine.getStateNodeById(idOrPath);
546
+ return root.machine.getStateNodeById(referenced.id);
545
547
  } catch {
546
- try {
547
- return guards_dist_xstateGuards.getStateNodeByPath(root, idOrPath.split('.'));
548
- } catch {
549
- {
550
- console.warn(`Could not resolve StateNode for id/path: ${idOrPath}`);
551
- }
552
- return idOrPath;
548
+ {
549
+ console.warn(`Could not resolve StateNode for id: ${referenced.id}`);
553
550
  }
554
551
  }
555
552
  }
556
- function reviveHistoryValue(historyValue, root) {
557
- if (!historyValue || typeof historyValue !== 'object') return {};
553
+ function reviveHistoryValue(root, historyValue) {
554
+ if (!historyValue || typeof historyValue !== 'object') {
555
+ return {};
556
+ }
558
557
  const revived = {};
559
558
  for (const key in historyValue) {
560
559
  const arr = historyValue[key];
561
- revived[key] = arr.map(item => {
562
- if (item instanceof StateNode) return item;
563
- if (typeof item === 'object' && 'id' in item && typeof item.id === 'string') {
564
- const resolved = resolveStateNodeFromIdOrPath(item.id, root);
565
- if (resolved instanceof StateNode) return resolved;
560
+ for (const item of arr) {
561
+ const resolved = resolveHistoryReferencedState(root, item);
562
+ if (!resolved) {
563
+ continue;
566
564
  }
567
- return undefined;
568
- }).filter(item => item !== undefined);
569
- if (revived[key].length === 0) {
570
- delete revived[key];
565
+ revived[key] ??= [];
566
+ revived[key].push(resolved);
571
567
  }
572
568
  }
573
569
  return revived;
574
570
  }
575
- const revivedHistoryValue = reviveHistoryValue(snapshot.historyValue, this.root);
571
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
576
572
  const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
577
573
  ...snapshot,
578
574
  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-527db318.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-527db318.development.esm.js';
4
- import { a as assign } from './log-b47a3833.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-b47a3833.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,40 +536,37 @@ class StateMachine {
537
536
  });
538
537
  children[actorId] = actorRef;
539
538
  });
540
- function resolveStateNodeFromIdOrPath(idOrPath, root) {
539
+ function resolveHistoryReferencedState(root, referenced) {
540
+ if (referenced instanceof StateNode) {
541
+ return referenced;
542
+ }
541
543
  try {
542
- return root.machine.getStateNodeById(idOrPath);
544
+ return root.machine.getStateNodeById(referenced.id);
543
545
  } catch {
544
- try {
545
- return getStateNodeByPath(root, idOrPath.split('.'));
546
- } catch {
547
- {
548
- console.warn(`Could not resolve StateNode for id/path: ${idOrPath}`);
549
- }
550
- return idOrPath;
546
+ {
547
+ console.warn(`Could not resolve StateNode for id: ${referenced.id}`);
551
548
  }
552
549
  }
553
550
  }
554
- function reviveHistoryValue(historyValue, root) {
555
- if (!historyValue || typeof historyValue !== 'object') return {};
551
+ function reviveHistoryValue(root, historyValue) {
552
+ if (!historyValue || typeof historyValue !== 'object') {
553
+ return {};
554
+ }
556
555
  const revived = {};
557
556
  for (const key in historyValue) {
558
557
  const arr = historyValue[key];
559
- revived[key] = arr.map(item => {
560
- if (item instanceof StateNode) return item;
561
- if (typeof item === 'object' && 'id' in item && typeof item.id === 'string') {
562
- const resolved = resolveStateNodeFromIdOrPath(item.id, root);
563
- if (resolved instanceof StateNode) return resolved;
558
+ for (const item of arr) {
559
+ const resolved = resolveHistoryReferencedState(root, item);
560
+ if (!resolved) {
561
+ continue;
564
562
  }
565
- return undefined;
566
- }).filter(item => item !== undefined);
567
- if (revived[key].length === 0) {
568
- delete revived[key];
563
+ revived[key] ??= [];
564
+ revived[key].push(resolved);
569
565
  }
570
566
  }
571
567
  return revived;
572
568
  }
573
- const revivedHistoryValue = reviveHistoryValue(snapshot.historyValue, this.root);
569
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
574
570
  const restoredSnapshot = createMachineSnapshot({
575
571
  ...snapshot,
576
572
  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-59f80ebb.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-59f80ebb.esm.js';
4
- import { a as assign } from './log-12aa30c9.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-12aa30c9.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,37 +533,34 @@ class StateMachine {
534
533
  });
535
534
  children[actorId] = actorRef;
536
535
  });
537
- function resolveStateNodeFromIdOrPath(idOrPath, root) {
536
+ function resolveHistoryReferencedState(root, referenced) {
537
+ if (referenced instanceof StateNode) {
538
+ return referenced;
539
+ }
538
540
  try {
539
- return root.machine.getStateNodeById(idOrPath);
541
+ return root.machine.getStateNodeById(referenced.id);
540
542
  } catch {
541
- try {
542
- return getStateNodeByPath(root, idOrPath.split('.'));
543
- } catch {
544
- return idOrPath;
545
- }
546
543
  }
547
544
  }
548
- function reviveHistoryValue(historyValue, root) {
549
- if (!historyValue || typeof historyValue !== 'object') return {};
545
+ function reviveHistoryValue(root, historyValue) {
546
+ if (!historyValue || typeof historyValue !== 'object') {
547
+ return {};
548
+ }
550
549
  const revived = {};
551
550
  for (const key in historyValue) {
552
551
  const arr = historyValue[key];
553
- revived[key] = arr.map(item => {
554
- if (item instanceof StateNode) return item;
555
- if (typeof item === 'object' && 'id' in item && typeof item.id === 'string') {
556
- const resolved = resolveStateNodeFromIdOrPath(item.id, root);
557
- if (resolved instanceof StateNode) return resolved;
552
+ for (const item of arr) {
553
+ const resolved = resolveHistoryReferencedState(root, item);
554
+ if (!resolved) {
555
+ continue;
558
556
  }
559
- return undefined;
560
- }).filter(item => item !== undefined);
561
- if (revived[key].length === 0) {
562
- delete revived[key];
557
+ revived[key] ??= [];
558
+ revived[key].push(resolved);
563
559
  }
564
560
  }
565
561
  return revived;
566
562
  }
567
- const revivedHistoryValue = reviveHistoryValue(snapshot.historyValue, this.root);
563
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
568
564
  const restoredSnapshot = createMachineSnapshot({
569
565
  ...snapshot,
570
566
  children,