xstate 5.0.0-beta.13 → 5.0.0-beta.14

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 (40) hide show
  1. package/actions/dist/xstate-actions.cjs.js +1 -1
  2. package/actions/dist/xstate-actions.development.cjs.js +1 -1
  3. package/actions/dist/xstate-actions.development.esm.js +1 -1
  4. package/actions/dist/xstate-actions.esm.js +1 -1
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/{actions-e4c704f3.cjs.js → actions-17c3bcfa.cjs.js} +803 -853
  14. package/dist/{actions-b34f6ce7.esm.js → actions-444a17c3.esm.js} +804 -854
  15. package/dist/{actions-c8b9504d.development.esm.js → actions-60622c0c.development.esm.js} +829 -879
  16. package/dist/{actions-d9c19f35.development.cjs.js → actions-73b8d456.development.cjs.js} +828 -878
  17. package/dist/declarations/src/State.d.ts +2 -8
  18. package/dist/declarations/src/StateMachine.d.ts +5 -10
  19. package/dist/declarations/src/StateNode.d.ts +1 -1
  20. package/dist/declarations/src/actors/callback.d.ts +2 -2
  21. package/dist/declarations/src/actors/index.d.ts +1 -1
  22. package/dist/declarations/src/actors/observable.d.ts +8 -6
  23. package/dist/declarations/src/actors/promise.d.ts +4 -3
  24. package/dist/declarations/src/actors/transition.d.ts +4 -4
  25. package/dist/declarations/src/interpreter.d.ts +15 -15
  26. package/dist/declarations/src/stateUtils.d.ts +4 -6
  27. package/dist/declarations/src/types.d.ts +23 -33
  28. package/dist/declarations/src/utils.d.ts +7 -7
  29. package/dist/xstate.cjs.js +13 -37
  30. package/dist/xstate.development.cjs.js +13 -37
  31. package/dist/xstate.development.esm.js +14 -38
  32. package/dist/xstate.esm.js +14 -38
  33. package/dist/xstate.umd.min.js +1 -1
  34. package/dist/xstate.umd.min.js.map +1 -1
  35. package/guards/dist/xstate-guards.cjs.js +1 -1
  36. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  37. package/guards/dist/xstate-guards.development.esm.js +1 -1
  38. package/guards/dist/xstate-guards.esm.js +1 -1
  39. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  40. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var actors_dist_xstateActors = require('../../dist/actions-e4c704f3.cjs.js');
5
+ var actors_dist_xstateActors = require('../../dist/actions-17c3bcfa.cjs.js');
6
6
  require('../../dev/dist/xstate-dev.cjs.js');
7
7
 
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var actors_dist_xstateActors = require('../../dist/actions-d9c19f35.development.cjs.js');
5
+ var actors_dist_xstateActors = require('../../dist/actions-73b8d456.development.cjs.js');
6
6
  require('../../dev/dist/xstate-dev.development.cjs.js');
7
7
 
8
8
 
@@ -1,2 +1,2 @@
1
- export { ak as actionTypes, an as after, T as assign, U as cancel, V as choose, A as createInitEvent, ao as done, R as doneInvoke, D as error, aq as escalate, O as forwardTo, J as initEvent, W as log, X as pure, Y as raise, al as resolveActionObject, ap as send, M as sendParent, L as sendTo, Z as stop, am as toActionObject, t as toActionObjects } from '../../dist/actions-c8b9504d.development.esm.js';
1
+ export { ak as actionTypes, an as after, T as assign, U as cancel, V as choose, I as createInitEvent, ao as done, R as doneInvoke, C as error, aq as escalate, O as forwardTo, J as initEvent, W as log, X as pure, Y as raise, al as resolveActionObject, ap as send, M as sendParent, L as sendTo, Z as stop, am as toActionObject, t as toActionObjects } from '../../dist/actions-60622c0c.development.esm.js';
2
2
  import '../../dev/dist/xstate-dev.development.esm.js';
@@ -1,2 +1,2 @@
1
- export { ak as actionTypes, an as after, T as assign, U as cancel, V as choose, A as createInitEvent, ao as done, R as doneInvoke, D as error, aq as escalate, O as forwardTo, J as initEvent, W as log, X as pure, Y as raise, al as resolveActionObject, ap as send, M as sendParent, L as sendTo, Z as stop, am as toActionObject, t as toActionObjects } from '../../dist/actions-b34f6ce7.esm.js';
1
+ export { ak as actionTypes, an as after, T as assign, U as cancel, V as choose, I as createInitEvent, ao as done, R as doneInvoke, C as error, aq as escalate, O as forwardTo, J as initEvent, W as log, X as pure, Y as raise, al as resolveActionObject, ap as send, M as sendParent, L as sendTo, Z as stop, am as toActionObject, t as toActionObjects } from '../../dist/actions-444a17c3.esm.js';
2
2
  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";let e=function(t){return t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Pure="xstate.pure",t.Choose="xstate.choose",t}({}),n=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});const s=e.Stop,o=e.Raise,i=e.Send,r=e.Cancel,a=e.Assign,c=e.After,u=e.DoneState,h=e.Log,d=e.Init,p=e.Invoke,f=e.ErrorExecution,l=e.ErrorPlatform,y=e.ErrorCustom,m=e.Choose,v=e.Pure;var g=Object.freeze({__proto__:null,stop:s,raise:o,send:i,cancel:r,assign:a,after:c,doneState:u,log:h,init:d,invoke:p,errorExecution:f,errorPlatform:l,error:y,choose:m,pure:v});function x(t,e,n="."){const s=_(t,n),o=_(e,n);return $(o)?!!$(s)&&o===s:$(s)?s in o:Object.keys(s).every((t=>t in o&&x(s[t],o[t])))}function _(t,e){if("object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n)return t.value;var n;if(E(t))return b(t);if("string"!=typeof t)return t;const s=function(t,e){try{return E(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}(t,e);return b(s)}function b(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)e===t.length-2?n[t[e]]=t[e+1]:(n[t[e]]={},n=n[t[e]]);return e}function w(t){return[].concat(...t)}function S(t){return void 0===t?[]:function(t){return E(t)?t:[t]}(t)}function E(t){return Array.isArray(t)}function I(t){return"function"==typeof t}function $(t){return"string"==typeof t}function k(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function C(t,e){return{type:t.type,params:t.params,resolve:e}}function T(t){return"object"==typeof t&&null!==t&&"resolve"in t}function j(t,e){return C({type:i,params:{to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:I(t)?t.name:t.type}},((s,{actorContext:o,state:r})=>{const a={to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:I(t)?t.name:t.type},c={context:r.context,event:s,self:o?.self??null,system:o?.system},u=r.machine.options.delays;if("string"==typeof t)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${t}" }) instead`);const h=I(t)?t(c):t;let d;if($(a.delay)){const t=u&&u[a.delay];d=I(t)?t(c):t}else d=I(a.delay)?a.delay(c):a.delay;const p=I(a.to)?a.to(c):a.to;let f;if("string"==typeof p){if(f=p===n.Parent?o?.self._parent:p===n.Internal?o?.self:p.startsWith("#_")?r.children[p.slice(2)]:r.children[p],!f)throw new Error(`Unable to send event to actor '${p}' from machine '${r.machine.id}'.`)}else f=p||o?.self;const l={type:i,params:{...a,to:f,event:h,delay:d,internal:p===n.Internal},execute:t=>{const e=l;if("number"!=typeof e.params.delay){const n=e.params.to,s=e.params.event;t.defer((()=>{n.send(s.type===y?{type:`${ht(t.self.id)}`,data:s.data}:e.params.event)}))}else t.self.delaySend(e)}};return[r,l]}))}function O(t,e){return j(t,{...e,to:n.Parent})}class P{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}const A="function"==typeof Symbol&&Symbol.observable||"@@observable",M="xstate.stop";function D(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const R=t=>{const e=D();e&&e.register(t)};let N=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const q={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class z{constructor(t,e){this.behavior=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new P(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=N.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...q,...e},{clock:s,logger:o,parent:i,id:r,systemId:a}=n;this.system=i?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const o=s.get(t);void 0!==o&&(n.delete(o),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const o=n.get(t);if(o&&o!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),a&&(this._systemId=a,this.system._set(a,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=o,this.clock=s,this._parent=i,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this._initState()}_initState(){this._state=this.options.state?this.behavior.restoreState?this.behavior.restoreState(this.options.state,this._actorContext):this.options.state:this.behavior.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n(t);for(const t of this.observers)t.next?.(e);const s=this.behavior.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._doneEvent=ut(this.id,s.data),this._parent?.send(this._doneEvent),this._complete();break;case"error":this._stopProcedure(),this._parent?.send(ht(this.id,s.data)),this._error(s.data)}}subscribe(t,e,n){const s=function(t,e,n){const s=()=>{},o="object"==typeof t,i=o?t:null;return{next:((o?t.next:t)||s).bind(i),error:((o?t.error:e)||s).bind(i),complete:((o?t.complete:n)||s).bind(i)}}(t,e,n);return this.observers.add(s),this.status===N.Stopped&&(s.complete?.(),this.observers.delete(s)),{unsubscribe:()=>{this.observers.delete(s)}}}start(){return this.status===N.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=N.Running,this.behavior.start&&this.behavior.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}_process(t){try{const e=this.behavior.transition(this._state,t,this._actorContext);this.update(e),t.type===M&&(this._stopProcedure(),this._complete())}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((e=>{e.error?.(t)})),this.stop()}}_stop(){return this.status===N.Stopped?this:(this.mailbox.clear(),this.status===N.NotStarted?(this.status=N.Stopped,this):(this.mailbox.enqueue({type:M}),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)t.complete?.();this.observers.clear()}_error(t){for(const e of this.observers)e.error?.(t);this.observers.clear()}_stopProcedure(){if(this.status!==N.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new P(this._process.bind(this)),this.status=N.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==N.Stopped){if(this.status!==N.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend(t){this.delayedEventsMap[t.params.id]=this.clock.setTimeout((()=>{"to"in t.params&&t.params.to?t.params.to.send(t.params.event):this.send(t.params.event)}),t.params.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:R)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.behavior.getPersistedState?.(this._state)}[A](){return this}getSnapshot(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}function B(t,e){return new z(t,e)}const J=({context:t,event:e})=>({context:t,event:e});const Q=new WeakMap;function V(t,e,n,s){const{machine:o}=s,i=o?.options?.guards?.[t.type]??t.predicate;if(!i)throw new Error(`Guard '${t.type}' is not implemented.'.`);return i({context:e,event:n,state:s,guard:t,evaluate:V})}function W(t,e){return $(t)?{type:t,predicate:e?.(t)||void 0,params:{type:t}}:I(t)?{type:t.name,predicate:t,params:{type:t.name,name:t.name}}:{type:t.type,params:t.params||t,children:t.children?.map((t=>W(t,e))),predicate:e?.(t.type)||t.predicate}}const L=t=>"atomic"===t.type||"final"===t.type;function U(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function G(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function X(t){const e=new Set(t),n=new Set(t),s=H(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of U(t))if("history"!==e.type&&!n.has(e))for(const t of Z(e))n.add(t)}else Z(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function F(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(L(t))return t.key}const s={};for(const t of n)s[t.key]=F(t,e);return s}function H(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function K(t,e){return F(t,H(X(e)))}const Y=t=>"#"===t[0];function Z(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const o of s.initial.target){for(const n of G(o,t))e.add(n);n(o)}else if("parallel"===s.type)for(const t of U(s))n(t)}(t),[...e]}function tt(t,e){if(Y(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function et(t,e){const n=e instanceof nt?e.value:_(e,t.machine.delimiter);if($(n))return[t,t.states[n]];const s=Object.keys(n),o=s.map((e=>tt(t,e))).filter(Boolean);return[t.machine.root,t].concat(o,s.reduce(((e,s)=>{const o=tt(t,s);if(!o)return e;const i=et(o,n[s]);return e.concat(i)}),[]))}class nt{static from(t,e={},n){if(t instanceof nt)return t.context!==e?new nt({value:t.value,context:e,event:t.event,actions:[],meta:{},configuration:[],transitions:[],children:{}},n):t;const s=dt({}),o=X(et(n.root,t));return new nt({value:t,context:e,event:s,actions:[],meta:void 0,configuration:Array.from(o),transitions:[],children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.context=void 0,this.historyValue={},this.actions=[],this.event=void 0,this._internalQueue=void 0,this._initial=!1,this.changed=void 0,this.configuration=void 0,this.transitions=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.event=t.event,this.historyValue=t.historyValue||{},this.actions=t.actions??[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(X(et(e.root,t.value))),this.transitions=t.transitions,this.children=t.children,this.value=K(e.root,this.configuration),this.tags=new Set(w(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output}toStrings(t=this.value,e="."){if($(t))return[t];const n=Object.keys(t);return n.concat(...n.map((n=>this.toStrings(t[n],e).map((t=>n+e+t)))))}toJSON(){const{configuration:t,transitions:e,tags:n,machine:s,...o}=this;return{...o,tags:Array.from(n),meta:this.meta}}matches(t){return x(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return function(t,e,n){let s=Q.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},Q.set(t,s)),s[e]}(this,"nextEvents",(()=>[...new Set(w([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function st(t,e={}){return new nt({...t,...e},t.machine)}function ot(t){return C({type:p,params:t},((e,{state:n,actorContext:s})=>{const o=p,{id:i,src:r}=t;let a;if((c=r)&&"object"==typeof c&&"function"==typeof c.send)a={type:o,params:{...t,ref:r}};else{const c=k(n.machine.options.actors[r]);if(c){const u="input"in t?t.input:c.input,h=B(c.src,{id:i,src:r,parent:s?.self,systemId:t.systemId,input:"function"==typeof u?u({context:n.context,event:e,self:s?.self}):u});a={type:o,params:{...t,ref:h}}}else a={type:o,params:t}}var c;const u=a.params.ref,h=st(n,{children:{...n.children,[i]:u}});return a.execute=t=>{const e=t.self,{id:n,ref:s}=a.params;s&&t.defer((()=>{if(u.status!==N.Stopped)try{u.start?.()}catch(t){return void e.send(ht(n,t))}}))},[h,a]}))}function it(t,e,n,s,o){return(i,r={})=>{const{systemId:a}=r;if($(i)){const c=k(e.options.actors[i]);if(c){const e=r.id??"anon",i="input"in r?r.input:c.input,u=B(c.src,{id:e,parent:t,input:"function"==typeof i?i({context:n,event:s,self:t}):i});return o.push(ot({id:u.id,src:u,ref:u,meta:void 0,input:i,systemId:a})),u}throw new Error(`Behavior '${i}' not implemented in machine '${e.id}'`)}{const e=B(i,{id:r.id||"anonymous",parent:t,input:r.input,systemId:a});return o.push(ot({src:e,ref:e,id:e.id,meta:void 0,input:r.input})),e}}}const rt={type:d};function at(t){if(T(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){const e="xstate.function";return C({type:e,params:{}},((n,{state:s})=>{const o={type:e,params:{function:t},execute:e=>t({context:s.context,event:n,action:o,self:e.self,system:e.system})};return[s,o]}))}return t}const ct=t=>{if(!t)return[];return(E(t)?t:[t]).map(at)};function ut(t,n){const s=`${e.DoneInvoke}.${t}`,o={type:s,output:n,toString:()=>s};return o}function ht(t,n){const s=`${e.ErrorPlatform}.${t}`,o={type:s,data:n,toString:()=>s};return o}function dt(t){return{type:d,input:t}}t.actionTypes=g,t.after=function(t,n){const s=n?`#${n}`:"";return`${e.After}(${t})${s}`},t.assign=function(t){return C({type:a,params:{assignment:t}},((e,{state:n,action:s,actorContext:o})=>{const i=[];if(!n.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const r={context:n.context,event:e,action:s,spawn:it(o?.self,n.machine,n.context,e,i),self:o?.self??{},system:o?.system};let c={};if(I(t))c=t(r);else for(const e of Object.keys(t)){const n=t[e];c[e]=I(n)?n(r):n}const u=Object.assign({},n.context,c);return[st(n,{context:u}),{type:a,params:{context:u,actions:i}}]}))},t.cancel=function(t){return C({type:r,params:{sendId:t}},((e,{state:n,actorContext:s})=>{const o=I(t)?t({context:n.context,event:e,self:s?.self??{},system:s?.system}):t;return[n,{type:"xstate.cancel",params:{sendId:o},execute:t=>{t.self.cancel(o)}}]}))},t.choose=function(t){return C({type:m,params:{guards:t}},((e,{state:n})=>{const s=t.find((t=>{const s=t.guard&&W(t.guard,(t=>n.machine.options.guards[t]));return!s||V(s,n.context,e,n)}))?.actions;return[n,{type:m,params:{actions:ct(s)}}]}))},t.createInitEvent=dt,t.done=function(t,n){const s=`${e.DoneState}.${t}`,o={type:s,output:n,toString:()=>s};return o},t.doneInvoke=ut,t.error=ht,t.escalate=function(t,e){return O((e=>({type:y,data:I(t)?t(e):t})),{...e,to:n.Parent})},t.forwardTo=function(t,e){return j((({event:t})=>t),{...e,to:t})},t.initEvent=rt,t.log=function(t=J,e){return C({type:h,params:{label:e,expr:t}},((n,{state:s,actorContext:o})=>{const i="function"==typeof t?t({context:s.context,event:n,self:o?.self??{},system:o?.system}):t;return[s,{type:"xstate.log",params:{label:e,value:i},execute:t=>{e?t.logger?.(e,i):t.logger?.(i)}}]}))},t.pure=function(t){return C({type:v,params:{get:t}},((e,{state:n})=>[n,{type:v,params:{actions:S(ct(t({context:n.context,event:e})))??[]}}]))},t.raise=function(t,e){return C({type:o,params:{delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type}},((n,{state:s,actorContext:i})=>{const r={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},a={context:s.context,event:n,self:i?.self??{},system:i?.system},c=s.machine.options.delays;if("string"==typeof t)throw new Error(`Only event objects may be used with raise; use raise({ type: "${t}" }) instead`);const u="function"==typeof t?t(a):t;let h;if("string"==typeof r.delay){const t=c&&c[r.delay];h="function"==typeof t?t(a):t}else h="function"==typeof r.delay?r.delay(a):r.delay;const d={type:o,params:{...r,event:u,delay:h},execute:t=>{"number"!=typeof d.params.delay||t.self.delaySend(d)}};return[s,d]}))},t.resolveActionObject=function(t,e){if(T(t))return t;const n=e[t.type];return"function"==typeof n?C({type:"xstate.function",params:t.params??{}},((e,{state:s})=>{const o={type:t.type,params:t.params,execute:t=>n({context:s.context,event:e,action:o,system:t.system,self:t.self})};return[s,o]})):n||t},t.send=j,t.sendParent=O,t.sendTo=function(t,e,n){return j(e,{...n,to:t})},t.stop=function(t){const e=t;return C({type:s,params:{actor:e}},((t,{state:n})=>{const s=I(e)?e({context:n.context,event:t}):e,o="string"==typeof s?n.children[s]:s;return[n,{type:"xstate.stop",params:{actor:o},execute:t=>{o&&(o.status===N.Running?t.defer((()=>{t.stopChild(o)})):t.stopChild(o))}}]}))},t.toActionObject=at,t.toActionObjects=ct,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";let e=function(t){return t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Pure="xstate.pure",t.Choose="xstate.choose",t}({}),n=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});const s=e.Stop,o=e.Raise,i=e.Send,r=e.Cancel,a=e.Assign,c=e.After,u=e.DoneState,d=e.Log,h=e.Init,p=e.Invoke,l=e.ErrorExecution,f=e.ErrorPlatform,y=e.ErrorCustom,m=e.Choose,v=e.Pure;var g=Object.freeze({__proto__:null,stop:s,raise:o,send:i,cancel:r,assign:a,after:c,doneState:u,log:d,init:h,invoke:p,errorExecution:l,errorPlatform:f,error:y,choose:m,pure:v});function x(t,e,n="."){const s=_(t,n),o=_(e,n);return $(o)?!!$(s)&&o===s:$(s)?s in o:Object.keys(s).every((t=>t in o&&x(s[t],o[t])))}function _(t,e){if("object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n)return t.value;var n;if(E(t))return b(t);if("string"!=typeof t)return t;const s=function(t,e){try{return E(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}(t,e);return b(s)}function b(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)e===t.length-2?n[t[e]]=t[e+1]:(n[t[e]]={},n=n[t[e]]);return e}function w(t){return[].concat(...t)}function S(t){return void 0===t?[]:function(t){return E(t)?t:[t]}(t)}function E(t){return Array.isArray(t)}function I(t){return"function"==typeof t}function $(t){return"string"==typeof t}function k(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function C(t,e){return{type:t.type,params:t.params,resolve:e}}function T(t){return"object"==typeof t&&null!==t&&"resolve"in t}function j(t,e){return C({type:i,params:{to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:I(t)?t.name:t.type}},((s,{actorContext:o,state:r})=>{const a={to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:I(t)?t.name:t.type},c={context:r.context,event:s,self:o?.self??null,system:o?.system},u=r.machine.options.delays;if("string"==typeof t)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${t}" }) instead`);const d=I(t)?t(c):t;let h;if($(a.delay)){const t=u&&u[a.delay];h=I(t)?t(c):t}else h=I(a.delay)?a.delay(c):a.delay;const p=I(a.to)?a.to(c):a.to;let l;if("string"==typeof p){if(l=p===n.Parent?o?.self._parent:p===n.Internal?o?.self:p.startsWith("#_")?r.children[p.slice(2)]:r.children[p],!l)throw new Error(`Unable to send event to actor '${p}' from machine '${r.machine.id}'.`)}else l=p||o?.self;const f={type:i,params:{...a,to:l,event:d,delay:h,internal:p===n.Internal},execute:t=>{const e=f;if("number"!=typeof e.params.delay){const n=e.params.to,s=e.params.event;t.defer((()=>{n.send(s.type===y?{type:`${dt(t.self.id)}`,data:s.data}:e.params.event)}))}else t.self.delaySend(e)}};return[r,f]}))}function O(t,e){return j(t,{...e,to:n.Parent})}const P=new WeakMap;const A="function"==typeof Symbol&&Symbol.observable||"@@observable";class M{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}function D(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const R=t=>{const e=D();e&&e.register(t)};let N=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const q={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class z{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new M(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=N.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...q,...e},{clock:s,logger:o,parent:i,id:r,systemId:a}=n;this.system=i?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const o=s.get(t);void 0!==o&&(n.delete(o),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const o=n.get(t);if(o&&o!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),a&&(this._systemId=a,this.system._set(a,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=o,this.clock=s,this._parent=i,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n();for(const t of this.observers)t.next?.(e);const s=this.logic.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._doneEvent=ut(this.id,s.data),this._parent?.send(this._doneEvent),this._complete();break;case"error":this._stopProcedure(),this._parent?.send(dt(this.id,s.data)),this._error(s.data)}}subscribe(t,e,n){const s=function(t,e,n){const s=()=>{},o="object"==typeof t,i=o?t:null;return{next:((o?t.next:t)||s).bind(i),error:((o?t.error:e)||s).bind(i),complete:((o?t.complete:n)||s).bind(i)}}(t,e,n);return this.observers.add(s),this.status===N.Stopped&&(s.complete?.(),this.observers.delete(s)),{unsubscribe:()=>{this.observers.delete(s)}}}start(){return this.status===N.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=N.Running,this.logic.start&&this.logic.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}_process(t){try{const e=this.logic.transition(this._state,t,this._actorContext);this.update(e),t.type===Q&&(this._stopProcedure(),this._complete())}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((e=>{e.error?.(t)})),this.stop()}}_stop(){return this.status===N.Stopped?this:(this.mailbox.clear(),this.status===N.NotStarted?(this.status=N.Stopped,this):(this.mailbox.enqueue({type:Q}),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)t.complete?.();this.observers.clear()}_error(t){for(const e of this.observers)e.error?.(t);this.observers.clear()}_stopProcedure(){if(this.status!==N.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new M(this._process.bind(this)),this.status=N.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==N.Stopped){if(this.status!==N.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend(t){this.delayedEventsMap[t.params.id]=this.clock.setTimeout((()=>{"to"in t.params&&t.params.to?t.params.to.send(t.params.event):this.send(t.params.event)}),t.params.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:R)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[A](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function J(t,e){return new z(t,e)}const Q="xstate.stop";function V(t){return C({type:p,params:t},((e,{state:n,actorContext:s})=>{const o=p,{id:i,src:r}=t;let a;if((c=r)&&"object"==typeof c&&"function"==typeof c.send)a={type:o,params:{...t,ref:r}};else{const c=k(n.machine.options.actors[r]);if(c){const u="input"in t?t.input:c.input,d=J(c.src,{id:i,src:r,parent:s?.self,systemId:t.systemId,input:"function"==typeof u?u({context:n.context,event:e,self:s?.self}):u});a={type:o,params:{...t,ref:d}}}else a={type:o,params:t}}var c;const u=a.params.ref,d=st(n,{children:{...n.children,[i]:u}});return a.execute=t=>{const e=t.self,{id:n,ref:s}=a.params;s&&t.defer((()=>{if(u.status!==N.Stopped)try{u.start?.()}catch(t){return void e.send(dt(n,t))}}))},[d,a]}))}function W(t,e,n,s){const{machine:o}=s,i=o?.options?.guards?.[t.type]??t.predicate;if(!i)throw new Error(`Guard '${t.type}' is not implemented.'.`);return i({context:e,event:n,state:s,guard:t,evaluate:W})}function B(t,e){return $(t)?{type:t,predicate:e?.(t)||void 0,params:{type:t}}:I(t)?{type:t.name,predicate:t,params:{type:t.name,name:t.name}}:{type:t.type,params:t.params||t,children:t.children?.map((t=>B(t,e))),predicate:e?.(t.type)||t.predicate}}const L=t=>"atomic"===t.type||"final"===t.type;function U(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function G(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function X(t){const e=new Set(t),n=new Set(t),s=H(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of U(t))if("history"!==e.type&&!n.has(e))for(const t of Z(e))n.add(t)}else Z(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function F(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(L(t))return t.key}const s={};for(const t of n)s[t.key]=F(t,e);return s}function H(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function K(t,e){return F(t,H(X(e)))}const Y=t=>"#"===t[0];function Z(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const o of s.initial.target){for(const n of G(o,t))e.add(n);n(o)}else if("parallel"===s.type)for(const t of U(s))n(t)}(t),[...e]}function tt(t,e){if(Y(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function et(t,e){const n=e instanceof nt?e.value:_(e,t.machine.delimiter);if($(n))return[t,t.states[n]];const s=Object.keys(n),o=s.map((e=>tt(t,e))).filter(Boolean);return[t.machine.root,t].concat(o,s.reduce(((e,s)=>{const o=tt(t,s);if(!o)return e;const i=et(o,n[s]);return e.concat(i)}),[]))}class nt{static from(t,e={},n){if(t instanceof nt)return t.context!==e?new nt({value:t.value,context:e,meta:{},configuration:[],transitions:[],children:{}},n):t;const s=X(et(n.root,t));return new nt({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.context=void 0,this.historyValue={},this._internalQueue=void 0,this._initial=!1,this.changed=void 0,this.configuration=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(X(et(e.root,t.value))),this.children=t.children,this.value=K(e.root,this.configuration),this.tags=new Set(w(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output}toStrings(t=this.value,e="."){if($(t))return[t];const n=Object.keys(t);return n.concat(...n.map((n=>this.toStrings(t[n],e).map((t=>n+e+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return x(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return function(t,e,n){let s=P.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},P.set(t,s)),s[e]}(this,"nextEvents",(()=>[...new Set(w([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function st(t,e={}){return new nt({...t,...e},t.machine)}const ot=({context:t,event:e})=>({context:t,event:e});function it(t,e,n,s,o){return(i,r={})=>{const{systemId:a}=r;if($(i)){const c=k(e.options.actors[i]);if(c){const e=r.id??"anon",i="input"in r?r.input:c.input,u=J(c.src,{id:e,parent:t,input:"function"==typeof i?i({context:n,event:s,self:t}):i});return o.push(V({id:u.id,src:u,ref:u,meta:void 0,input:i,systemId:a})),u}throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`)}{const e=J(i,{id:r.id||"anonymous",parent:t,input:r.input,systemId:a});return o.push(V({src:e,ref:e,id:e.id,meta:void 0,input:r.input})),e}}}const rt={type:h};function at(t){if(T(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){const e="xstate.function";return C({type:e,params:{}},((n,{state:s})=>{const o={type:e,params:{function:t},execute:e=>t({context:s.context,event:n,action:o,self:e.self,system:e.system})};return[s,o]}))}return t}const ct=t=>{if(!t)return[];return(E(t)?t:[t]).map(at)};function ut(t,n){const s=`${e.DoneInvoke}.${t}`,o={type:s,output:n,toString:()=>s};return o}function dt(t,n){const s=`${e.ErrorPlatform}.${t}`,o={type:s,data:n,toString:()=>s};return o}t.actionTypes=g,t.after=function(t,n){const s=n?`#${n}`:"";return`${e.After}(${t})${s}`},t.assign=function(t){return C({type:a,params:{assignment:t}},((e,{state:n,action:s,actorContext:o})=>{const i=[];if(!n.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const r={context:n.context,event:e,action:s,spawn:it(o?.self,n.machine,n.context,e,i),self:o?.self??{},system:o?.system};let c={};if(I(t))c=t(r);else for(const e of Object.keys(t)){const n=t[e];c[e]=I(n)?n(r):n}const u=Object.assign({},n.context,c);return[st(n,{context:u}),{type:a,params:{context:u,actions:i}}]}))},t.cancel=function(t){return C({type:r,params:{sendId:t}},((e,{state:n,actorContext:s})=>{const o=I(t)?t({context:n.context,event:e,self:s?.self??{},system:s?.system}):t;return[n,{type:"xstate.cancel",params:{sendId:o},execute:t=>{t.self.cancel(o)}}]}))},t.choose=function(t){return C({type:m,params:{guards:t}},((e,{state:n})=>{const s=t.find((t=>{const s=t.guard&&B(t.guard,(t=>n.machine.options.guards[t]));return!s||W(s,n.context,e,n)}))?.actions;return[n,{type:m,params:{actions:ct(s)}}]}))},t.createInitEvent=function(t){return{type:h,input:t}},t.done=function(t,n){const s=`${e.DoneState}.${t}`,o={type:s,output:n,toString:()=>s};return o},t.doneInvoke=ut,t.error=dt,t.escalate=function(t,e){return O((e=>({type:y,data:I(t)?t(e):t})),{...e,to:n.Parent})},t.forwardTo=function(t,e){return j((({event:t})=>t),{...e,to:t})},t.initEvent=rt,t.log=function(t=ot,e){return C({type:d,params:{label:e,expr:t}},((n,{state:s,actorContext:o})=>{const i="function"==typeof t?t({context:s.context,event:n,self:o?.self??{},system:o?.system}):t;return[s,{type:"xstate.log",params:{label:e,value:i},execute:t=>{e?t.logger?.(e,i):t.logger?.(i)}}]}))},t.pure=function(t){return C({type:v,params:{get:t}},((e,{state:n})=>[n,{type:v,params:{actions:S(ct(t({context:n.context,event:e})))??[]}}]))},t.raise=function(t,e){return C({type:o,params:{delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type}},((n,{state:s,actorContext:i})=>{const r={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},a={context:s.context,event:n,self:i?.self??{},system:i?.system},c=s.machine.options.delays;if("string"==typeof t)throw new Error(`Only event objects may be used with raise; use raise({ type: "${t}" }) instead`);const u="function"==typeof t?t(a):t;let d;if("string"==typeof r.delay){const t=c&&c[r.delay];d="function"==typeof t?t(a):t}else d="function"==typeof r.delay?r.delay(a):r.delay;const h={type:o,params:{...r,event:u,delay:d},execute:t=>{"number"!=typeof h.params.delay||t.self.delaySend(h)}};return[s,h]}))},t.resolveActionObject=function(t,e){if(T(t))return t;const n=e[t.type];return"function"==typeof n?C({type:"xstate.function",params:t.params??{}},((e,{state:s})=>{const o={type:t.type,params:t.params,execute:t=>n({context:s.context,event:e,action:o,system:t.system,self:t.self})};return[s,o]})):n||t},t.send=j,t.sendParent=O,t.sendTo=function(t,e,n){return j(e,{...n,to:t})},t.stop=function(t){const e=t;return C({type:s,params:{actor:e}},((t,{state:n})=>{const s=I(e)?e({context:n.context,event:t}):e,o="string"==typeof s?n.children[s]:s;let i=n.children;return o&&(i={...i},delete i[o.id]),[st(n,{children:i}),{type:"xstate.stop",params:{actor:o},execute:t=>{o&&(o.status===N.Running?t.defer((()=>{t.stopChild(o)})):t.stopChild(o))}}]}))},t.toActionObject=at,t.toActionObjects=ct,Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=xstate-actions.umd.min.js.map