xstate 5.0.0-beta.51 → 5.0.0-beta.52

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 (42) hide show
  1. package/actions/dist/xstate-actions.cjs.js +9 -11
  2. package/actions/dist/xstate-actions.cjs.mjs +0 -2
  3. package/actions/dist/xstate-actions.development.cjs.js +9 -11
  4. package/actions/dist/xstate-actions.development.cjs.mjs +0 -2
  5. package/actions/dist/xstate-actions.development.esm.js +2 -2
  6. package/actions/dist/xstate-actions.esm.js +2 -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.js +1 -1
  10. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  11. package/actors/dist/xstate-actors.development.esm.js +1 -1
  12. package/actors/dist/xstate-actors.esm.js +1 -1
  13. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  14. package/dist/declarations/src/StateMachine.d.ts +2 -2
  15. package/dist/declarations/src/StateNode.d.ts +3 -3
  16. package/dist/declarations/src/actions.d.ts +0 -2
  17. package/dist/declarations/src/actors/index.d.ts +1 -1
  18. package/dist/declarations/src/interpreter.d.ts +2 -2
  19. package/dist/declarations/src/types.d.ts +9 -9
  20. package/dist/{pure-a0f16134.development.cjs.js → log-3d815f5e.cjs.js} +1 -62
  21. package/dist/{pure-296f8ebd.development.esm.js → log-6bc0e1e7.esm.js} +2 -61
  22. package/dist/{pure-aefddc19.esm.js → log-826c9895.development.esm.js} +24 -36
  23. package/dist/{pure-c5f1b46c.cjs.js → log-d160285c.development.cjs.js} +23 -37
  24. package/dist/{raise-acaa3884.development.esm.js → raise-1caefe80.development.esm.js} +10 -10
  25. package/dist/{raise-d5633a02.cjs.js → raise-367eeb6f.cjs.js} +10 -10
  26. package/dist/{raise-528386de.development.cjs.js → raise-9dd3e757.development.cjs.js} +10 -10
  27. package/dist/{raise-4742bf04.esm.js → raise-f71460d6.esm.js} +10 -10
  28. package/dist/xstate.cjs.js +13 -15
  29. package/dist/xstate.cjs.mjs +0 -2
  30. package/dist/xstate.development.cjs.js +13 -15
  31. package/dist/xstate.development.cjs.mjs +0 -2
  32. package/dist/xstate.development.esm.js +6 -6
  33. package/dist/xstate.esm.js +6 -6
  34. package/dist/xstate.umd.min.js +1 -1
  35. package/dist/xstate.umd.min.js.map +1 -1
  36. package/guards/dist/xstate-guards.cjs.js +1 -1
  37. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  38. package/guards/dist/xstate-guards.development.esm.js +1 -1
  39. package/guards/dist/xstate-guards.esm.js +1 -1
  40. package/package.json +1 -1
  41. package/dist/declarations/src/actions/choose.d.ts +0 -9
  42. package/dist/declarations/src/actions/pure.d.ts +0 -10
@@ -2,21 +2,19 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var pure = require('../../dist/pure-c5f1b46c.cjs.js');
6
- var guards_dist_xstateGuards = require('../../dist/raise-d5633a02.cjs.js');
5
+ var log = require('../../dist/log-3d815f5e.cjs.js');
6
+ var guards_dist_xstateGuards = require('../../dist/raise-367eeb6f.cjs.js');
7
7
  require('../../dev/dist/xstate-dev.cjs.js');
8
8
 
9
9
 
10
10
 
11
- exports.assign = pure.assign;
12
- exports.choose = pure.choose;
13
- exports.enqueueActions = pure.enqueueActions;
14
- exports.escalate = pure.escalate;
15
- exports.forwardTo = pure.forwardTo;
16
- exports.log = pure.log;
17
- exports.pure = pure.pure;
18
- exports.sendParent = pure.sendParent;
19
- exports.sendTo = pure.sendTo;
11
+ exports.assign = log.assign;
12
+ exports.enqueueActions = log.enqueueActions;
13
+ exports.escalate = log.escalate;
14
+ exports.forwardTo = log.forwardTo;
15
+ exports.log = log.log;
16
+ exports.sendParent = log.sendParent;
17
+ exports.sendTo = log.sendTo;
20
18
  exports.cancel = guards_dist_xstateGuards.cancel;
21
19
  exports.raise = guards_dist_xstateGuards.raise;
22
20
  exports.spawnChild = guards_dist_xstateGuards.spawnChild;
@@ -1,12 +1,10 @@
1
1
  export {
2
2
  assign,
3
3
  cancel,
4
- choose,
5
4
  enqueueActions,
6
5
  escalate,
7
6
  forwardTo,
8
7
  log,
9
- pure,
10
8
  raise,
11
9
  sendParent,
12
10
  sendTo,
@@ -2,21 +2,19 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var pure = require('../../dist/pure-a0f16134.development.cjs.js');
6
- var guards_dist_xstateGuards = require('../../dist/raise-528386de.development.cjs.js');
5
+ var log = require('../../dist/log-d160285c.development.cjs.js');
6
+ var guards_dist_xstateGuards = require('../../dist/raise-9dd3e757.development.cjs.js');
7
7
  require('../../dev/dist/xstate-dev.development.cjs.js');
8
8
 
9
9
 
10
10
 
11
- exports.assign = pure.assign;
12
- exports.choose = pure.choose;
13
- exports.enqueueActions = pure.enqueueActions;
14
- exports.escalate = pure.escalate;
15
- exports.forwardTo = pure.forwardTo;
16
- exports.log = pure.log;
17
- exports.pure = pure.pure;
18
- exports.sendParent = pure.sendParent;
19
- exports.sendTo = pure.sendTo;
11
+ exports.assign = log.assign;
12
+ exports.enqueueActions = log.enqueueActions;
13
+ exports.escalate = log.escalate;
14
+ exports.forwardTo = log.forwardTo;
15
+ exports.log = log.log;
16
+ exports.sendParent = log.sendParent;
17
+ exports.sendTo = log.sendTo;
20
18
  exports.cancel = guards_dist_xstateGuards.cancel;
21
19
  exports.raise = guards_dist_xstateGuards.raise;
22
20
  exports.spawnChild = guards_dist_xstateGuards.spawnChild;
@@ -1,12 +1,10 @@
1
1
  export {
2
2
  assign,
3
3
  cancel,
4
- choose,
5
4
  enqueueActions,
6
5
  escalate,
7
6
  forwardTo,
8
7
  log,
9
- pure,
10
8
  raise,
11
9
  sendParent,
12
10
  sendTo,
@@ -1,3 +1,3 @@
1
- export { a as assign, c as choose, e as enqueueActions, b as escalate, f as forwardTo, l as log, p as pure, s as sendParent, d as sendTo } from '../../dist/pure-296f8ebd.development.esm.js';
2
- export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-acaa3884.development.esm.js';
1
+ export { a as assign, e as enqueueActions, b as escalate, f as forwardTo, l as log, s as sendParent, c as sendTo } from '../../dist/log-826c9895.development.esm.js';
2
+ export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-1caefe80.development.esm.js';
3
3
  import '../../dev/dist/xstate-dev.development.esm.js';
@@ -1,3 +1,3 @@
1
- export { a as assign, c as choose, e as enqueueActions, b as escalate, f as forwardTo, l as log, p as pure, s as sendParent, d as sendTo } from '../../dist/pure-aefddc19.esm.js';
2
- export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-4742bf04.esm.js';
1
+ export { a as assign, e as enqueueActions, b as escalate, f as forwardTo, l as log, s as sendParent, c as sendTo } from '../../dist/log-6bc0e1e7.esm.js';
2
+ export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-f71460d6.esm.js';
3
3
  import '../../dev/dist/xstate-dev.esm.js';
@@ -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).XStateActions={})}(this,(function(t){"use strict";class e{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}}const s=".",n="xstate.error",i="xstate.stop";function o(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function r(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const c=t=>{const e=r();e&&e.register(t)};function a(t){setTimeout((()=>{throw t}))}const h="function"==typeof Symbol&&Symbol.observable||"@@observable";let u=0;function d(t,e){const s=f(t),n=f(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&d(s[t],n[t])))}function f(t){if((e=t)&&"object"==typeof e&&"machine"in e&&"value"in e)return t.value;var e;if("string"!=typeof t)return t;var n;return function(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}(p(n=t)?n:n.split(s))}function l(t){return void 0===t?[]:function(t){return p(t)?t:[t]}(t)}function p(t){return Array.isArray(t)}function y(t,e,s){const n="object"==typeof t,i=n?t:void 0;return{next:(n?t.next:t)?.bind(i),error:(n?t.error:e)?.bind(i),complete:(n?t.complete:s)?.bind(i)}}function _(t,e){if(e.startsWith("xstate#")){const[,s]=e.match(/\[(\d+)\]$/),n=t.getStateNodeById(e.slice(7,-(s.length+2))).config.invoke;return(Array.isArray(n)?n[s]:n).src}return t.implementations.actors[e]}let v=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const g={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class m{constructor(t,s){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=v.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=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={...g,...s},{clock:i,logger:o,parent:r,syncSnapshot:c,id:a,systemId:h,inspect:d}=n;this.system=r?.system??function(t){const e=new Map,s=new Map,n=new WeakMap,i=new Set,o={_bookId:()=>"x:"+u++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const i=n.get(t);void 0!==i&&(s.delete(i),n.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const i=s.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),n.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)}};return o}(this),d&&!r&&this.system.inspect(y(d)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=o,this.clock=i,this._parent=r,this._syncSnapshot=c,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={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}),h&&(this._systemId=h,this.system._set(h,this)),this._initState(s?.state),h&&"active"!==this._state.status&&this.system._unregister(this)}_initState(t){try{this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}catch(t){this._state={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._state=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._state={...t,status:"error",error:e}}switch(this._state.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,i=this._state.output,{type:`xstate.done.actor.${n}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._state.error)}var n,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=y(t,e,s);if(this._processingStatus!==v.Stopped)this.observers.add(n);else try{n.complete?.()}catch(t){a(t)}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===v.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=v.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":return this.update(this._state,t),this;case"error":return this._error(this._state.error),this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._state={...this._state,status:"error",error:t},this._error(t),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._state,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._state={...this._state,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===i&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===v.Stopped?this:(this.mailbox.clear(),this._processingStatus===v.NotStarted?(this._processingStatus=v.Stopped,this):(this.mailbox.enqueue({type:i}),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){a(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||a(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){a(t)}}this.observers.clear(),e&&a(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,o(this.id,t))}_stopProcedure(){if(this._processingStatus!==v.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=v.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==v.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:s,delay:n}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),n);s&&(this.delayedEventsMap[s]=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:c)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[h](){return this}getSnapshot(){return this._state}}function x(t,e){return new m(t,e)}function b(t,e,s,n,{sendId:i}){return[e,"function"==typeof i?i(s,n):i]}function S(t,e){t.self.cancel(e)}function w(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=b,e.execute=S,e}function I(t,e,s,n,{id:i,systemId:o,src:r,input:c,syncSnapshot:a}){const h="string"==typeof r?_(e.machine,r):r,u="function"==typeof i?i(s):i;let d;return h&&(d=x(h,{id:u,src:r,parent:t?.self,syncSnapshot:a,systemId:o,input:"function"==typeof c?c({context:e.context,event:s.event,self:t?.self}):c})),[G(e,{children:{...e.children,[u]:d}}),{id:i,actorRef:d}]}function E(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==v.Stopped&&s.start()}))}function T(...[t,{id:e,systemId:s,input:n,syncSnapshot:i=!1}={}]){function o(t,e){}return o.type="xstate.spawnChild",o.id=e,o.systemId=s,o.src=t,o.input=n,o.syncSnapshot=i,o.resolve=I,o.execute=E,o}function k(t,e,s,n,{actorRef:i}){const o="function"==typeof i?i(s,n):i,r="string"==typeof o?e.children[o]:o;let c=e.children;return r&&(c={...c},delete c[r.id]),[G(e,{children:c}),r]}function R(t,e){e&&(t.system._unregister(e),e._processingStatus===v.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function $(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=k,e.execute=R,e}const M=$;function j(t,e,s,n){const{machine:i}=n,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 j(r,e,s,n);const c={context:e,event:s},a=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(c,a);return r.check(n,c,r)}const A=t=>"atomic"===t.type||"final"===t.type;function O(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function C(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function P(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(A(t))return t.key}const n={};for(const t of s)n[t.key]=P(t,e);return n}function N(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function q(t,e){const s=function(t){const e=new Set(t),s=N(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of O(t))if("history"!==s.type&&!e.has(s)){const t=D(s);for(const s of t)e.add(s)}}else D(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}(e);return P(t,N(s))}function D(t){const e=function(t){const e=new Set;function s(t){if(!e.has(t))if(e.add(t),"compound"===t.type)s(t.initial.target[0]);else if("parallel"===t.type)for(const e of O(t))s(e)}return s(t),e}(t);for(const s of e)for(const n of C(s,t))e.add(n);return e}const J=function(t){return d(t,this.value)},W=function(t){return this.tags.has(t)},V=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},z=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:i,can:o,hasTag:r,matches:c,...a}=this;return{...a,tags:Array.from(e)}},B=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function G(t,e={}){return function(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:q(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:J,hasTag:W,can:V,getMeta:B,toJSON:z}}({...t,...e},t.machine)}function Q(t,{machine:e,context:s},n,i){return(o,r)=>{const c=((o,r={})=>{const{systemId:c,input:a}=r;if("string"==typeof o){const h=_(e,o);if(!h)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u=x(h,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof a?a({context:s,event:n,self:t.self}):a,src:o,systemId:c});return i[u.id]=u,u}return x(o,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:o,systemId:c})})(o,r);return i[c.id]=c,t.defer((()=>{c._processingStatus!==v.Stopped&&c.start()})),c}}function U(t,e,s,n,{assignment:i}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},r={context:e.context,event:s.event,spawn:Q(t,e,s.event,o),self:t?.self,system:t?.system};let c={};if("function"==typeof i)c=i(r,n);else for(const t of Object.keys(i)){const e=i[t];c[t]="function"==typeof e?e(r,n):e}return[G(e,{context:Object.assign({},e.context,c),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function X(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=U,e}function F(t,e,s,n,{branches:i}){const o=i.find((t=>!t.guard||j(t.guard,e.context,s.event,e)))?.actions;return[e,void 0,l(o)]}function H(t,e,s,n,{event:i,id:o,delay:r},{internalQueue:c}){const a=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const h="function"==typeof i?i(s,n):i;let u;if("string"==typeof r){const t=a&&a[r];u="function"==typeof t?t(s,n):t}else u="function"==typeof r?r(s,n):r;return"number"!=typeof u&&c.push(h),[e,{event:h,id:o,delay:u}]}function K(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function L(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=H,s.execute=K,s}let Y=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Z(t,e,s,n,{to:i,event:o,id:r,delay:c},a){const h=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const u="function"==typeof o?o(s,n):o;let d;if("string"==typeof c){const t=h&&h[c];d="function"==typeof t?t(s,n):t}else d="function"==typeof c?c(s,n):c;const f="function"==typeof i?i(s,n):i;let l;if("string"==typeof f){if(l=f===Y.Parent?t?.self._parent:f===Y.Internal?t?.self:f.startsWith("#_")?e.children[f.slice(2)]:a.deferredActorIds?.includes(f)?f:e.children[f],!l)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else l=f||t?.self;return[e,{to:l,event:u,id:r,delay:d}]}function tt(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function et(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:s,event:i}=e;t?.system._relay(t.self,s,i.type===n?o(t.self.id,i.data):i)})):t.self.delaySend(e)}function st(t,e,s){function n(t,e){}return n.type="xstate.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=Z,n.retryResolve=tt,n.execute=et,n}function nt(t,e){return st(Y.Parent,t,e)}function it(t,e,s,n,{collect:i}){const o=[],r=function(t){o.push(t)};return r.assign=(...t)=>{o.push(X(...t))},r.cancel=(...t)=>{o.push(w(...t))},r.raise=(...t)=>{o.push(L(...t))},r.sendTo=(...t)=>{o.push(st(...t))},r.spawnChild=(...t)=>{o.push(T(...t))},r.stopChild=(...t)=>{o.push($(...t))},i({context:s.context,event:s.event,enqueue:r,check:t=>j(t,e.context,s.event,e)}),[e,void 0,o]}function ot(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=it,e}function rt(t,e,s,n,{value:i,label:o}){return[e,{value:"function"==typeof i?i(s,n):i,label:o}]}function ct({logger:t},{value:e,label:s}){s?t(s,e):t(e)}t.assign=X,t.cancel=w,t.choose=function(t){function e(t,e){}return e.type="xstate.choose",e.branches=t,e.resolve=F,e},t.enqueueActions=ot,t.escalate=function(t,e){return nt((e=>({type:n,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return st(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=rt,s.execute=ct,s},t.pure=function(t){return ot((({context:e,event:s,enqueue:n})=>{l(t({context:e,event:s})).forEach(n)}))},t.raise=L,t.sendParent=nt,t.sendTo=st,t.spawnChild=T,t.stop=M,t.stopChild=$,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).XStateActions={})}(this,(function(t){"use strict";class e{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}}const s=".",n="xstate.error",i="xstate.stop";function o(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function r(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const c=t=>{const e=r();e&&e.register(t)};function a(t){setTimeout((()=>{throw t}))}const h="function"==typeof Symbol&&Symbol.observable||"@@observable";let u=0;function d(t,e){const s=p(t),n=p(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&d(s[t],n[t])))}function f(t){return e=t,Array.isArray(e)?t:t.split(s);var e}function p(t){if((e=t)&&"object"==typeof e&&"machine"in e&&"value"in e)return t.value;var e;if("string"!=typeof t)return t;return function(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}(f(t))}function l(t,e,s){const n="object"==typeof t,i=n?t:void 0;return{next:(n?t.next:t)?.bind(i),error:(n?t.error:e)?.bind(i),complete:(n?t.complete:s)?.bind(i)}}function y(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.implementations.actors[e];const[,n,i]=s,o=t.getStateNodeById(i).config.invoke;return(Array.isArray(o)?o[n]:o).src}let _=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const v={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class g{constructor(t,s){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=_.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=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={...v,...s},{clock:i,logger:o,parent:r,syncSnapshot:c,id:a,systemId:h,inspect:d}=n;this.system=r?.system??function(t){const e=new Map,s=new Map,n=new WeakMap,i=new Set,o={_bookId:()=>"x:"+u++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const i=n.get(t);void 0!==i&&(s.delete(i),n.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const i=s.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),n.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)}};return o}(this),d&&!r&&this.system.inspect(l(d)),this.sessionId=this.system._bookId(),this.id=a??this.sessionId,this.logger=o,this.clock=i,this._parent=r,this._syncSnapshot=c,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={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}),h&&(this._systemId=h,this.system._set(h,this)),this._initState(s?.state),h&&"active"!==this._state.status&&this.system._unregister(this)}_initState(t){try{this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}catch(t){this._state={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._state=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._state={...t,status:"error",error:e}}switch(this._state.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){a(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,i=this._state.output,{type:`xstate.done.actor.${n}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._state.error)}var n,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=l(t,e,s);if(this._processingStatus!==_.Stopped)this.observers.add(n);else try{n.complete?.()}catch(t){a(t)}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===_.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=_.Running;const t={type:"xstate.init",input:this.options.input};this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":return this.update(this._state,t),this;case"error":return this._error(this._state.error),this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._state={...this._state,status:"error",error:t},this._error(t),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._state,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._state={...this._state,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===i&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===_.Stopped?this:(this.mailbox.clear(),this._processingStatus===_.NotStarted?(this._processingStatus=_.Stopped,this):(this.mailbox.enqueue({type:i}),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){a(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||a(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){a(t)}}this.observers.clear(),e&&a(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,o(this.id,t))}_stopProcedure(){if(this._processingStatus!==_.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=_.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==_.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:s,delay:n}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),n);s&&(this.delayedEventsMap[s]=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:c)(this)}}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[h](){return this}getSnapshot(){return this._state}}function m(t,e){return new g(t,e)}function x(t,e,s,n,{sendId:i}){return[e,"function"==typeof i?i(s,n):i]}function b(t,e){t.self.cancel(e)}function S(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=x,e.execute=b,e}function w(t,e,s,n,{id:i,systemId:o,src:r,input:c,syncSnapshot:a}){const h="string"==typeof r?y(e.machine,r):r,u="function"==typeof i?i(s):i;let d;return h&&(d=m(h,{id:u,src:r,parent:t?.self,syncSnapshot:a,systemId:o,input:"function"==typeof c?c({context:e.context,event:s.event,self:t?.self}):c})),[B(e,{children:{...e.children,[u]:d}}),{id:i,actorRef:d}]}function I(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==_.Stopped&&s.start()}))}function E(...[t,{id:e,systemId:s,input:n,syncSnapshot:i=!1}={}]){function o(t,e){}return o.type="xstate.spawnChild",o.id=e,o.systemId=s,o.src=t,o.input=n,o.syncSnapshot=i,o.resolve=w,o.execute=I,o}function T(t,e,s,n,{actorRef:i}){const o="function"==typeof i?i(s,n):i,r="string"==typeof o?e.children[o]:o;let c=e.children;return r&&(c={...c},delete c[r.id]),[B(e,{children:c}),r]}function k(t,e){e&&(t.system._unregister(e),e._processingStatus===_.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function R(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=T,e.execute=k,e}const $=R;function M(t,e,s,n){const{machine:i}=n,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 M(r,e,s,n);const c={context:e,event:s},a=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(c,a);return r.check(n,c,r)}const j=t=>"atomic"===t.type||"final"===t.type;function A(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function O(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function C(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(j(t))return t.key}const n={};for(const t of s)n[t.key]=C(t,e);return n}function P(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function N(t,e){const s=function(t){const e=new Set(t),s=P(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of A(t))if("history"!==s.type&&!e.has(s)){const t=q(s);for(const s of t)e.add(s)}}else q(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}(e);return C(t,P(s))}function q(t){const e=function(t){const e=new Set;function s(t){if(!e.has(t))if(e.add(t),"compound"===t.type)s(t.initial.target[0]);else if("parallel"===t.type)for(const e of A(t))s(e)}return s(t),e}(t);for(const s of e)for(const n of O(s,t))e.add(n);return e}const D=function(t){return d(t,this.value)},J=function(t){return this.tags.has(t)},V=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},W=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:i,can:o,hasTag:r,matches:c,...a}=this;return{...a,tags:Array.from(e)}},z=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function B(t,e={}){return function(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:N(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:D,hasTag:J,can:V,getMeta:z,toJSON:W}}({...t,...e},t.machine)}function G(t,{machine:e,context:s},n,i){return(o,r)=>{const c=((o,r={})=>{const{systemId:c,input:a}=r;if("string"==typeof o){const h=y(e,o);if(!h)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u=m(h,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof a?a({context:s,event:n,self:t.self}):a,src:o,systemId:c});return i[u.id]=u,u}return m(o,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:o,systemId:c})})(o,r);return i[c.id]=c,t.defer((()=>{c._processingStatus!==_.Stopped&&c.start()})),c}}function Q(t,e,s,n,{assignment:i}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},r={context:e.context,event:s.event,spawn:G(t,e,s.event,o),self:t?.self,system:t?.system};let c={};if("function"==typeof i)c=i(r,n);else for(const t of Object.keys(i)){const e=i[t];c[t]="function"==typeof e?e(r,n):e}return[B(e,{context:Object.assign({},e.context,c),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function U(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Q,e}function X(t,e,s,n,{event:i,id:o,delay:r},{internalQueue:c}){const a=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const h="function"==typeof i?i(s,n):i;let u;if("string"==typeof r){const t=a&&a[r];u="function"==typeof t?t(s,n):t}else u="function"==typeof r?r(s,n):r;return"number"!=typeof u&&c.push(h),[e,{event:h,id:o,delay:u}]}function F(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function H(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=X,s.execute=F,s}let K=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function L(t,e,s,n,{to:i,event:o,id:r,delay:c},a){const h=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const u="function"==typeof o?o(s,n):o;let d;if("string"==typeof c){const t=h&&h[c];d="function"==typeof t?t(s,n):t}else d="function"==typeof c?c(s,n):c;const f="function"==typeof i?i(s,n):i;let p;if("string"==typeof f){if(p=f===K.Parent?t?.self._parent:f===K.Internal?t?.self:f.startsWith("#_")?e.children[f.slice(2)]:a.deferredActorIds?.includes(f)?f:e.children[f],!p)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else p=f||t?.self;return[e,{to:p,event:u,id:r,delay:d}]}function Y(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function Z(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:s,event:i}=e;t?.system._relay(t.self,s,i.type===n?o(t.self.id,i.data):i)})):t.self.delaySend(e)}function tt(t,e,s){function n(t,e){}return n.type="xstate.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=L,n.retryResolve=Y,n.execute=Z,n}function et(t,e){return tt(K.Parent,t,e)}function st(t,e,s,n,{collect:i}){const o=[],r=function(t){o.push(t)};return r.assign=(...t)=>{o.push(U(...t))},r.cancel=(...t)=>{o.push(S(...t))},r.raise=(...t)=>{o.push(H(...t))},r.sendTo=(...t)=>{o.push(tt(...t))},r.spawnChild=(...t)=>{o.push(E(...t))},r.stopChild=(...t)=>{o.push(R(...t))},i({context:s.context,event:s.event,enqueue:r,check:t=>M(t,e.context,s.event,e)}),[e,void 0,o]}function nt(t,e,s,n,{value:i,label:o}){return[e,{value:"function"==typeof i?i(s,n):i,label:o}]}function it({logger:t},{value:e,label:s}){s?t(s,e):t(e)}t.assign=U,t.cancel=S,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=st,e},t.escalate=function(t,e){return et((e=>({type:n,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return tt(t,(({event:t})=>t),e)},t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=nt,s.execute=it,s},t.raise=H,t.sendParent=et,t.sendTo=tt,t.spawnChild=E,t.stop=$,t.stopChild=R,Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=xstate-actions.umd.min.js.map