xstate 4.15.3 → 4.16.2

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.
@@ -1,4 +1,4 @@
1
- const t={};function e(t){return Object.keys(t)}function i(t,n,s="."){const r=o(t,s),a=o(n,s);return S(a)?!!S(r)&&a===r:S(r)?r in a:e(r).every(t=>t in a&&i(r[t],a[t]))}function n(t){try{return S(t)||"number"==typeof t?`${t}`:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function s(t,e){try{return m(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function o(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(m(t))return r(t);if("string"!=typeof t)return t;return r(s(t,e))}function r(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function a(t,i){const n={},s=e(t);for(let e=0;e<s.length;e++){const o=s[e];n[o]=i(t[o],o,t,e)}return n}function c(t,i,n){const s={};for(const o of e(t)){const e=t[o];n(e)&&(s[o]=i(e,o,t))}return s}const h=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function d(t){if(!t)return[[]];if(S(t))return[[t]];return u(e(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?d(t[e]).map(t=>[e].concat(t)):[[e]]}))}function u(t){return[].concat(...t)}function l(t){return m(t)?t:[t]}function f(t){return void 0===t?[]:l(t)}function p(t,e,i){if(b(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];b(o)?n[s]=o(e,i.data):n[s]=o}return n}function g(t){return t instanceof Promise||!(null===t||!b(t)&&"object"!=typeof t||!b(t.then))}function v(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}function y(t,e){return a(t.states,(t,i)=>{if(!t)return;const n=(S(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:y(t,n)}:void 0})}function m(t){return Array.isArray(t)}function b(t){return"function"==typeof t}function S(t){return"string"==typeof t}function w(t,e){if(t)return S(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:b(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}function x(t){try{return"subscribe"in t&&b(t.subscribe)}catch(t){return!1}}const O="function"==typeof Symbol&&Symbol.observable||"@@observable";function _(t){try{return"__xstatenode"in t}catch(t){return!1}}const j=(()=>{let t=0;return()=>(t++,t.toString(16))})();function E(t,e){return S(t)||"number"==typeof t?Object.assign({type:t},e):t}function N(t,e){if(!S(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=E(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function $(t,e){return l(e).map(e=>void 0===e||"string"==typeof e||_(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function T(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return e.predicate(i,n.data,r);const a=o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function k(t){return"string"==typeof t?{type:t}:t}function P(t,n){let s;for(const o of e(t))i(o,n)&&(!s||n.length>s.length)&&(s=o);return t[s]}
1
+ const t={};function e(t){return Object.keys(t)}function i(t,n,s="."){const r=o(t,s),a=o(n,s);return S(a)?!!S(r)&&a===r:S(r)?r in a:e(r).every(t=>t in a&&i(r[t],a[t]))}function n(t){try{return S(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function s(t,e){try{return m(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function o(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(m(t))return r(t);if("string"!=typeof t)return t;return r(s(t,e))}function r(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function a(t,i){const n={},s=e(t);for(let e=0;e<s.length;e++){const o=s[e];n[o]=i(t[o],o,t,e)}return n}function c(t,i,n){const s={};for(const o of e(t)){const e=t[o];n(e)&&(s[o]=i(e,o,t))}return s}const h=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function d(t){if(!t)return[[]];if(S(t))return[[t]];return u(e(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?d(t[e]).map(t=>[e].concat(t)):[[e]]}))}function u(t){return[].concat(...t)}function l(t){return m(t)?t:[t]}function f(t){return void 0===t?[]:l(t)}function p(t,e,i){if(b(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];b(o)?n[s]=o(e,i.data):n[s]=o}return n}function g(t){return t instanceof Promise||!(null===t||!b(t)&&"object"!=typeof t||!b(t.then))}function v(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}function y(t,e){return a(t.states,(t,i)=>{if(!t)return;const n=(S(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:y(t,n)}:void 0})}function m(t){return Array.isArray(t)}function b(t){return"function"==typeof t}function S(t){return"string"==typeof t}function w(t,e){if(t)return S(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:b(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}function x(t){try{return"subscribe"in t&&b(t.subscribe)}catch(t){return!1}}const O="function"==typeof Symbol&&Symbol.observable||"@@observable";function _(t){try{return"__xstatenode"in t}catch(t){return!1}}const j=(()=>{let t=0;return()=>(t++,t.toString(16))})();function E(t,e){return S(t)||"number"==typeof t?Object.assign({type:t},e):t}function N(t,e){if(!S(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=E(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function T(t,e){return l(e).map(e=>void 0===e||"string"==typeof e||_(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function $(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return e.predicate(i,n.data,r);const a=o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function k(t){return"string"==typeof t?{type:t}:t}function P(t,n){let s;for(const o of e(t))i(o,n)&&(!s||n.length>s.length)&&(s=o);return t[s]}
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function C(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}var V,I;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",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.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(V||(V={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(I||(I={}));const L=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function A(t){const e=[t];return L(t)?e:e.concat(u(D(t).map(A)))}function R(t,e){const i=M(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=M(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function M(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function F(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(L(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,M(R([t],e)))}function z(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?D(e).some(e=>"final"===e.type&&z(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=V.Start,B=V.Stop,q=V.Raise,X=V.Send,H=V.Cancel,G=V.NullEvent,K=V.Assign,Q=(V.After,V.DoneState,V.Log),W=V.Init,Y=V.Invoke,Z=(V.ErrorExecution,V.ErrorPlatform),tt=V.ErrorCustom,et=V.Update,it=V.Choose,nt=V.Pure,st=N({type:W});function ot(t,e){return e&&e[t]||void 0}function rt(t,e){let i;if(S(t)||"number"==typeof t){const n=ot(t,e);i=b(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(b(t))i={type:t.name||t.toString(),exec:t};else{const n=ot(t.type,e);if(b(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const at=(t,e)=>{if(!t)return[];return(m(t)?t:[t]).map(t=>rt(t,e))};function ct(t){const e=rt(t);return Object.assign(Object.assign({id:S(t)?t:e.id},e),{type:e.type})}function ht(t){return S(t)?{type:q,event:t}:dt(t,{to:I.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:X,event:b(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:b(t)?t.name:n(t)}}function ut(t,e){return dt(t,Object.assign(Object.assign({},e),{to:I.Parent}))}function lt(){return ut(et)}const ft=(t,e)=>({context:t,event:e});const pt=t=>({type:H,sendId:t});function gt(t){const e=ct(t);return{type:V.Start,activity:e,exec:void 0}}function vt(t){const e=b(t)?t:ct(t);return{type:V.Stop,activity:e,exec:void 0}}const yt=t=>({type:K,assignment:t});function mt(t,e){const i=e?`#${e}`:"";return`${V.After}(${t})${i}`}function bt(t,e){const i=`${V.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function St(t,e){const i=`${V.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function wt(t,e){const i=`${V.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function xt(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,i,n,s,o){const[r,a]=v(o,t=>t.type===K);let c=r.length?function(t,i,n,s){return t?n.reduce((t,n)=>{const{assignment:o}=n,r={state:s,action:n,_event:i};let a={};if(b(o))a=o(t,i.data,r);else for(const n of e(o)){const e=o[n];a[n]=b(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}(n,s,r,i):n;return[u(a.map(e=>{var n;switch(e.type){case q:return{type:q,_event:N(e.event)};case X:return function(t,e,i,n){const s={_event:i},o=N(b(t.event)?t.event(e,i.data,s):t.event);let r;if(S(t.delay)){const o=n&&n[t.delay];r=b(o)?o(e,i.data,s):o}else r=b(t.delay)?t.delay(e,i.data,s):t.delay;const a=b(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(e,c,s,t.options.delays);case Q:return((t,e,i)=>Object.assign(Object.assign({},t),{value:S(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(e,c,s);case it:{const o=null===(n=e.conds.find(e=>{const n=w(e.cond,t.options.guards);return!n||T(t,n,c,s,i)}))||void 0===n?void 0:n.actions;if(!o)return[];const r=Ot(t,i,c,s,at(f(o),t.options.actions));return c=r[1],r[0]}case nt:{const n=e.get(c,s.data);if(!n)return[];const o=Ot(t,i,c,s,at(f(n),t.options.actions));return c=o[1],o[0]}case B:return function(t,e,i){const n=b(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:V.Stop,activity:s}}(e,c,s);default:return rt(e,t.options.actions)}})),c]}function _t(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class jt{constructor(e){this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=e.meta||{},this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,u([...new Set(t.map(t=>t.ownEvents))]);var t}})}static from(t,e){if(t instanceof jt)return t.context!==e?new jt({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new jt({value:t,context:e,_event:st,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new jt(t)}static inert(t,e){if(t instanceof jt){if(!t.actions.length)return t;const i=st;return new jt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return jt.from(t,e)}toStrings(t=this.value,i="."){if(S(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){return C(this,["configuration","transitions"])}matches(t){return i(t,this.value)}}const Et=[],Nt=(t,e)=>{Et.push(t);const i=e(t);return Et.pop(),i};function $t(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}}function Tt(t,e,i){const n=$t(e);return n.deferred=!0,_(t)&&(n.state=Nt(void 0,()=>(i?t.withContext(i):t).initialState)),n}function kt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Y},t),{toJSON(){const e=C(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Y,src:kt(t.src)})}})}const Ct={},Vt=t=>"#"===t[0];class It{constructor(t,i,n){this.config=t,this.context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new It(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Ct;let s=0;!function t(e){e.order=s++;for(const i of D(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>rt(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>rt(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(_(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Pt({src:t.id,id:t.id});if(S(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||b(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Pt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Pt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>ct(t)),this.transition=this.transition.bind(this)}_init(){this.__cache.transitions||A(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new It(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new It(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:a(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=mt(b(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(pt(i)),i};return(m(t)?t.map((t,e)=>{const n=i(t.delay,e);return Object.assign(Object.assign({},t),{event:n})}):u(e(t).map((e,n)=>{const s=t[e],o=S(s)?{target:s}:s,r=isNaN(+e)?e:+e,a=i(r,n);return f(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const i=t instanceof jt?t.value:o(t,this.delimiter);if(S(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this.states[i]]}const n=e(i);return n.map(t=>this.getStateNode(t)).concat(n.reduce((t,e)=>{const n=this.getStateNode(e).getStateNodes(i[e]);return t.concat(n)},[]))}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(R([],this.getStateNodes(t.value)));return new jt(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=u(o.map(t=>t.entrySet)),c=u(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return S(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:d,in:u}=c,l=t.context,f=!u||(S(u)&&Vt(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||T(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=R([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?R(s,t.configuration):s;for(const e of o)z(s,e)||t.entrySet.push(e);for(const e of s)z(o,e)&&!z(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(bt(n.id,n.doneData),bt(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&s.push(bt(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[u(Array.from(a).map(t=>[...t.activities.map(t=>gt(t)),...t.onEntry])).concat(r.map(ht)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>vt(t))]))];return at(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=N(e);let s;if(t instanceof jt)s=void 0===i?t:this.resolveState(jt.from(t,i));else{const e=S(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=i||this.machine.context;s=this.resolveState(jt.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const a=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},c=R([],this.getStateNodes(s.value)),h=a.configuration.length?R(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n=st,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0?F(this.machine,o):void 0,a=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,c=i?i.context:s,h=this.getActions(t,c,n,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===U?d[t.activity.id||t.activity.type]=t:t.type===B&&(d[t.activity.id||t.activity.type]=!1);const[u,l]=Ot(this,i,c,n,h),[f,g]=v(u,t=>t.type===q||t.type===X&&t.to===I.Internal),m=u.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Y}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=k(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?Tt(r,t.id,a):$t(t.id);return c.meta=t,c}(e.activity,this.machine,l,n),t),i?Object.assign({},i.children):{}),b=r?t.configuration:i?i.configuration:[],w=b.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),x=J(b,this),O=new jt({value:r||i.value,context:l,_event:n,_sessionid:i?i._sessionid:null,historyValue:r?a?(_=a,j=r,{current:j,states:y(_,j)}):void 0:i?i.historyValue:void 0,history:!r||t.source?i:void 0,actions:r?g:[],activities:r?d:i?i.activities:{},meta:r?w:i?i.meta:void 0,events:[],configuration:b,transitions:t.transitions,children:m,done:x});var _,j;const E=c!==l;O.changed=n.name===et||E;const{history:N}=O;if(N&&delete N.history,!r)return O;let $=O;if(!x){for((this._transient||o.some(t=>t._transient))&&($=this.resolveRaisedTransition($,{type:G},n));f.length;){const t=f.shift();$=this.resolveRaisedTransition($,t._event,n)}}const T=$.changed||(N?!!$.actions.length||E||typeof N.value!=typeof $.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(S(i)||S(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}($.value,N.value):void 0);return $.changed=T,$.history=N,$}getStateNode(t){if(Vt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=Vt(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&Vt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=s(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Ct;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Ct);case"compound":if(S(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):Ct):this.initialStateValue||{};default:return t||Ct}}getResolvedPath(t){if(Vt(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return s(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||Ct,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=L(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=S(e.target)&&Vt(e.target)?r(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(L(this))return[this];if("compound"===this.type&&!this.initial)return[this];return u(d(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const n=S(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return S(i)?[e.getStateNode(i)]:u(d(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=u(e(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,i=new Set(this.ownEvents);if(t)for(const n of e(t)){const e=t[n];if(e.states)for(const t of e.events)i.add(`${t}`)}return this.__cache.events=Array.from(i)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!S(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>S(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:at(f(t.actions)),cond:w(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>`#${t.id}`):void 0,source:`#${this.id}`})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,n="*",s=i[n],o=void 0===s?[]:s,r=C(i,[n+""]);t=u(e(r).map(t=>$(t,r[t])).concat($("*",o)))}else t=[];const i=this.config.always?$("",this.config.always):[],n=this.config.onDone?$(String(bt(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...$(String(St(t.id)),t.onDone)),t.onError&&e.push(...$(String(wt(t.id)),t.onError)),e})),o=this.after,r=u([...n,...s,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function Lt(t,e,i=t.context){const n="function"==typeof i?i():i;return new It(t,e,n)}function Dt(t,e){const i="function"==typeof t.context?t.context():t.context;return new It(t,e,i)}const At={deferEvents:!1};class Rt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},At),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Mt=new Map;let Ft=0;const zt={bookId:()=>`x:${Ft++}`,register:(t,e)=>(Mt.set(t,e),t),get:t=>Mt.get(t),free(t){Mt.delete(t)}};function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}const Ut={sync:!1,autoForward:!1};var Bt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Bt||(Bt={}));class qt{constructor(t,e=qt.defaultOptions){this.machine=t,this.scheduler=new Rt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Bt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(m(t))return this.batch(t),this.state;const i=N(E(t,e));if(this.status===Bt.Stopped)return this.state;if(this.status!==Bt.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,e)=>{const i=this.parent&&(e===I.Parent||this.parent.id===e),n=i?this.parent:S(e)?this.children.get(e)||zt.get(e):(s=e)&&"function"==typeof s.send?e:void 0;var s;if(n)"machine"in n?n.send(Object.assign(Object.assign({},t),{name:t.name===tt?`${wt(this.id)}`:t.name,origin:this.sessionId})):n.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},qt.defaultOptions),e),{clock:n,logger:s,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=s,this.clock=n,this.parent=o,this.options=i,this.scheduler=new Rt({deferEvents:this.options.deferEvents}),this.sessionId=zt.bookId()}get initialState(){return this._initialState?this._initialState:Nt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(St(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Bt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Bt.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.delete(s)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===Bt.Running)return this;zt.register(this.sessionId,this),this.initialized=!0,this.status=Bt.Running;const e=void 0===t?this.initialState:Nt(this,()=>{return!S(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(jt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,st)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{b(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Bt.Stopped,zt.free(this.sessionId),this}batch(t){if(this.status===Bt.NotStarted&&this.options.deferEvents);else if(this.status!==Bt.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const n=[];for(const s of t){const t=N(s);this.forward(t),e=Nt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>_t(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(Z)&&!this.state.nextEvents.some(t=>0===t.indexOf(Z)))throw e.data.data;return Nt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){const{context:n,_event:s}=e,o=t.exec||ot(t.type,i),r=b(o)?o:o?o.exec:t.exec;if(r)try{return r(n,s.data,{action:t,state:this.state,_event:s})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case X:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case H:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===V.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0,h=b(i)?i(n,s.data,{data:c,src:t}):i;g(h)?this.spawnPromise(Promise.resolve(h),o):b(h)?this.spawnCallback(h,o):x(h)?this.spawnObservable(h,o):_(h)&&this.spawnMachine(c?h.withContext(c):h,{id:o,autoForward:a})}else this.spawnActivity(e);break}case B:this.stopChild(t.activity.id);break;case Q:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),b(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(b(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(n=t)&&"id"in n)return this.spawnActor(t);if(x(t))return this.spawnObservable(t,e);if(_(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n}spawnMachine(t,e={}){const i=new qt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Ut),e);n.sync&&i.onTransition(t=>{this.send(et,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),s}spawnPromise(t,e){let i=!1;t.then(t=>{i||(this.removeChild(e),this.send(N(St(e,t),{origin:e})))},t=>{if(!i){this.removeChild(e);const i=wt(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const n={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=function(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,n),n}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set,o=t=>{s.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let r;try{r=t(o,t=>{n.add(t)})}catch(t){this.send(wt(e,t))}if(g(r))return this.spawnPromise(r,e);const a={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,b(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(wt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(St(e),{origin:e}))}),n={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,n),n}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){const t=Jt();if(this.options.devTools&&t&&t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}}toJSON(){return{id:this.id}}[O](){return this}}qt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),qt.interpret=Ht;function Xt(t,e){const i=(t=>S(t)?Object.assign(Object.assign({},Ut),{name:t}):Object.assign(Object.assign(Object.assign({},Ut),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):Tt(t,i.name))(Et[Et.length-1])}function Ht(t,e){return new qt(t,e)}function Gt(t,e,i){const n=jt.from(t,t instanceof jt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}const Kt={raise:ht,send:dt,sendParent:ut,sendUpdate:lt,log:function(t=ft,e){return{type:Q,label:e,expr:t}},cancel:pt,start:gt,stop:vt,assign:yt,after:mt,done:bt,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:xt,escalate:function(t,e){return ut((e,i,n)=>({type:tt,data:b(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:I.Parent}))},choose:function(t){return{type:V.Choose,conds:t}},pure:function(t){return{type:V.Pure,get:t}}};export{V as ActionTypes,qt as Interpreter,Bt as InterpreterStatus,Lt as Machine,I as SpecialTargets,jt as State,It as StateNode,Kt as actions,yt as assign,Dt as createMachine,St as doneInvoke,xt as forwardTo,Ht as interpret,P as mapState,Gt as matchState,i as matchesState,dt as send,ut as sendParent,lt as sendUpdate,Xt as spawn};
15
+ ***************************************************************************** */function C(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}var V,I;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",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.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(V||(V={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(I||(I={}));const L=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function A(t){const e=[t];return L(t)?e:e.concat(u(D(t).map(A)))}function R(t,e){const i=M(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=M(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function M(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function z(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(L(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,M(R([t],e)))}function F(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?D(e).some(e=>"final"===e.type&&F(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=V.Start,B=V.Stop,q=V.Raise,X=V.Send,H=V.Cancel,G=V.NullEvent,K=V.Assign,Q=(V.After,V.DoneState,V.Log),W=V.Init,Y=V.Invoke,Z=(V.ErrorExecution,V.ErrorPlatform),tt=V.ErrorCustom,et=V.Update,it=V.Choose,nt=V.Pure,st=N({type:W});function ot(t,e){return e&&e[t]||void 0}function rt(t,e){let i;if(S(t)||"number"==typeof t){const n=ot(t,e);i=b(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(b(t))i={type:t.name||t.toString(),exec:t};else{const n=ot(t.type,e);if(b(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const at=(t,e)=>{if(!t)return[];return(m(t)?t:[t]).map(t=>rt(t,e))};function ct(t){const e=rt(t);return Object.assign(Object.assign({id:S(t)?t:e.id},e),{type:e.type})}function ht(t){return S(t)?{type:q,event:t}:dt(t,{to:I.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:X,event:b(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:b(t)?t.name:n(t)}}function ut(t,e){return dt(t,Object.assign(Object.assign({},e),{to:I.Parent}))}function lt(){return ut(et)}const ft=(t,e)=>({context:t,event:e});const pt=t=>({type:H,sendId:t});function gt(t){const e=ct(t);return{type:V.Start,activity:e,exec:void 0}}function vt(t){const e=b(t)?t:ct(t);return{type:V.Stop,activity:e,exec:void 0}}const yt=t=>({type:K,assignment:t});function mt(t,e){const i=e?"#"+e:"";return`${V.After}(${t})${i}`}function bt(t,e){const i=`${V.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function St(t,e){const i=`${V.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function wt(t,e){const i=`${V.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function xt(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,i,n,s,o){const[r,a]=v(o,t=>t.type===K);let c=r.length?function(t,i,n,s){return t?n.reduce((t,n)=>{const{assignment:o}=n,r={state:s,action:n,_event:i};let a={};if(b(o))a=o(t,i.data,r);else for(const n of e(o)){const e=o[n];a[n]=b(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}(n,s,r,i):n;return[u(a.map(e=>{var n;switch(e.type){case q:return{type:q,_event:N(e.event)};case X:return function(t,e,i,n){const s={_event:i},o=N(b(t.event)?t.event(e,i.data,s):t.event);let r;if(S(t.delay)){const o=n&&n[t.delay];r=b(o)?o(e,i.data,s):o}else r=b(t.delay)?t.delay(e,i.data,s):t.delay;const a=b(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(e,c,s,t.options.delays);case Q:return((t,e,i)=>Object.assign(Object.assign({},t),{value:S(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(e,c,s);case it:{const o=null===(n=e.conds.find(e=>{const n=w(e.cond,t.options.guards);return!n||$(t,n,c,s,i)}))||void 0===n?void 0:n.actions;if(!o)return[];const r=Ot(t,i,c,s,at(f(o),t.options.actions));return c=r[1],r[0]}case nt:{const n=e.get(c,s.data);if(!n)return[];const o=Ot(t,i,c,s,at(f(n),t.options.actions));return c=o[1],o[0]}case B:return function(t,e,i){const n=b(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:V.Stop,activity:s}}(e,c,s);default:return rt(e,t.options.actions)}})),c]}function _t(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class jt{constructor(e){this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=e.meta||{},this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,u([...new Set(t.map(t=>t.ownEvents))]);var t}})}static from(t,e){if(t instanceof jt)return t.context!==e?new jt({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new jt({value:t,context:e,_event:st,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new jt(t)}static inert(t,e){if(t instanceof jt){if(!t.actions.length)return t;const i=st;return new jt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return jt.from(t,e)}toStrings(t=this.value,i="."){if(S(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){return C(this,["configuration","transitions"])}matches(t){return i(t,this.value)}}const Et=[],Nt=(t,e)=>{Et.push(t);const i=e(t);return Et.pop(),i};function Tt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}}function $t(t,e,i){const n=Tt(e);return n.deferred=!0,_(t)&&(n.state=Nt(void 0,()=>(i?t.withContext(i):t).initialState)),n}function kt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Y},t),{toJSON(){const e=C(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Y,src:kt(t.src)})}})}const Ct={},Vt=t=>"#"===t[0];class It{constructor(t,i,n){this.config=t,this.context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new It(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Ct;let s=0;!function t(e){e.order=s++;for(const i of D(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>rt(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>rt(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(_(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Pt({src:t.id,id:t.id});if(S(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||b(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Pt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Pt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>ct(t)),this.transition=this.transition.bind(this)}_init(){this.__cache.transitions||A(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new It(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new It(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:a(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=mt(b(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(pt(i)),i};return(m(t)?t.map((t,e)=>{const n=i(t.delay,e);return Object.assign(Object.assign({},t),{event:n})}):u(e(t).map((e,n)=>{const s=t[e],o=S(s)?{target:s}:s,r=isNaN(+e)?e:+e,a=i(r,n);return f(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const i=t instanceof jt?t.value:o(t,this.delimiter);if(S(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this.states[i]]}const n=e(i);return n.map(t=>this.getStateNode(t)).concat(n.reduce((t,e)=>{const n=this.getStateNode(e).getStateNodes(i[e]);return t.concat(n)},[]))}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(R([],this.getStateNodes(t.value)));return new jt(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=u(o.map(t=>t.entrySet)),c=u(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return S(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:d,in:u}=c,l=t.context,f=!u||(S(u)&&Vt(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||$(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=R([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?R(s,t.configuration):s;for(const e of o)F(s,e)||t.entrySet.push(e);for(const e of s)F(o,e)&&!F(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(bt(n.id,n.doneData),bt(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&s.push(bt(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[u(Array.from(a).map(t=>[...t.activities.map(t=>gt(t)),...t.onEntry])).concat(r.map(ht)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>vt(t))]))];return at(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=N(e);let s;if(t instanceof jt)s=void 0===i?t:this.resolveState(jt.from(t,i));else{const e=S(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=i||this.machine.context;s=this.resolveState(jt.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const a=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},c=R([],this.getStateNodes(s.value)),h=a.configuration.length?R(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n=st,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0?z(this.machine,o):void 0,a=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,c=i?i.context:s,h=this.getActions(t,c,n,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===U?d[t.activity.id||t.activity.type]=t:t.type===B&&(d[t.activity.id||t.activity.type]=!1);const[u,l]=Ot(this,i,c,n,h),[f,g]=v(u,t=>t.type===q||t.type===X&&t.to===I.Internal),m=u.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Y}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=k(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?$t(r,t.id,a):Tt(t.id);return c.meta=t,c}(e.activity,this.machine,l,n),t),i?Object.assign({},i.children):{}),b=r?t.configuration:i?i.configuration:[],w=b.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),x=J(b,this),O=new jt({value:r||i.value,context:l,_event:n,_sessionid:i?i._sessionid:null,historyValue:r?a?(_=a,j=r,{current:j,states:y(_,j)}):void 0:i?i.historyValue:void 0,history:!r||t.source?i:void 0,actions:r?g:[],activities:r?d:i?i.activities:{},meta:r?w:i?i.meta:void 0,events:[],configuration:b,transitions:t.transitions,children:m,done:x});var _,j;const E=c!==l;O.changed=n.name===et||E;const{history:N}=O;if(N&&delete N.history,!r)return O;let T=O;if(!x){for((this._transient||o.some(t=>t._transient))&&(T=this.resolveRaisedTransition(T,{type:G},n));f.length;){const t=f.shift();T=this.resolveRaisedTransition(T,t._event,n)}}const $=T.changed||(N?!!T.actions.length||E||typeof N.value!=typeof T.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(S(i)||S(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}(T.value,N.value):void 0);return T.changed=$,T.history=N,T}getStateNode(t){if(Vt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=Vt(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&Vt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=s(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Ct;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Ct);case"compound":if(S(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):Ct):this.initialStateValue||{};default:return t||Ct}}getResolvedPath(t){if(Vt(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return s(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||Ct,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=L(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=S(e.target)&&Vt(e.target)?r(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(L(this))return[this];if("compound"===this.type&&!this.initial)return[this];return u(d(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const n=S(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return S(i)?[e.getStateNode(i)]:u(d(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=u(e(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,i=new Set(this.ownEvents);if(t)for(const n of e(t)){const e=t[n];if(e.states)for(const t of e.events)i.add(""+t)}return this.__cache.events=Array.from(i)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!S(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>S(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:at(f(t.actions)),cond:w(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,n="*",s=i[n],o=void 0===s?[]:s,r=C(i,[n+""]);t=u(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],n=this.config.onDone?T(String(bt(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(St(t.id)),t.onDone)),t.onError&&e.push(...T(String(wt(t.id)),t.onError)),e})),o=this.after,r=u([...n,...s,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function Lt(t,e,i=t.context){const n="function"==typeof i?i():i;return new It(t,e,n)}function Dt(t,e){const i="function"==typeof t.context?t.context():t.context;return new It(t,e,i)}const At={deferEvents:!1};class Rt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},At),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Mt=new Map;let zt=0;const Ft={bookId:()=>"x:"+zt++,register:(t,e)=>(Mt.set(t,e),t),get:t=>Mt.get(t),free(t){Mt.delete(t)}};function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}const Ut={sync:!1,autoForward:!1};var Bt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Bt||(Bt={}));class qt{constructor(t,e=qt.defaultOptions){this.machine=t,this.scheduler=new Rt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Bt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(m(t))return this.batch(t),this.state;const i=N(E(t,e));if(this.status===Bt.Stopped)return this.state;if(this.status!==Bt.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,e)=>{const i=this.parent&&(e===I.Parent||this.parent.id===e),n=i?this.parent:S(e)?this.children.get(e)||Ft.get(e):(s=e)&&"function"==typeof s.send?e:void 0;var s;if(n)"machine"in n?n.send(Object.assign(Object.assign({},t),{name:t.name===tt?""+wt(this.id):t.name,origin:this.sessionId})):n.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},qt.defaultOptions),e),{clock:n,logger:s,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=s,this.clock=n,this.parent=o,this.options=i,this.scheduler=new Rt({deferEvents:this.options.deferEvents}),this.sessionId=Ft.bookId()}get initialState(){return this._initialState?this._initialState:Nt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(St(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Bt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Bt.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.delete(s)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===Bt.Running)return this;Ft.register(this.sessionId,this),this.initialized=!0,this.status=Bt.Running;const e=void 0===t?this.initialState:Nt(this,()=>{return!S(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(jt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,st)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{b(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Bt.Stopped,Ft.free(this.sessionId),this}batch(t){if(this.status===Bt.NotStarted&&this.options.deferEvents);else if(this.status!==Bt.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const n=[];for(const s of t){const t=N(s);this.forward(t),e=Nt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>_t(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(Z)&&!this.state.nextEvents.some(t=>0===t.indexOf(Z)))throw e.data.data;return Nt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){const{context:n,_event:s}=e,o=t.exec||ot(t.type,i),r=b(o)?o:o?o.exec:t.exec;if(r)try{return r(n,s.data,{action:t,state:this.state,_event:s})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case X:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case H:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===V.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0,h=b(i)?i(n,s.data,{data:c,src:t}):i;g(h)?this.spawnPromise(Promise.resolve(h),o):b(h)?this.spawnCallback(h,o):x(h)?this.spawnObservable(h,o):_(h)&&this.spawnMachine(c?h.withContext(c):h,{id:o,autoForward:a})}else this.spawnActivity(e);break}case B:this.stopChild(t.activity.id);break;case Q:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),b(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(b(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(n=t)&&"id"in n)return this.spawnActor(t);if(x(t))return this.spawnObservable(t,e);if(_(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n}spawnMachine(t,e={}){const i=new qt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Ut),e);n.sync&&i.onTransition(t=>{this.send(et,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),s}spawnPromise(t,e){let i=!1;t.then(t=>{i||(this.removeChild(e),this.send(N(St(e,t),{origin:e})))},t=>{if(!i){this.removeChild(e);const i=wt(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const n={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=function(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,n),n}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set,o=t=>{s.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let r;try{r=t(o,t=>{n.add(t)})}catch(t){this.send(wt(e,t))}if(g(r))return this.spawnPromise(r,e);const a={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,b(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(wt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(St(e),{origin:e}))}),n={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,n),n}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){const t=Jt();if(this.options.devTools&&t&&t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}}toJSON(){return{id:this.id}}[O](){return this}}qt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),qt.interpret=Ht;function Xt(t,e){const i=(t=>S(t)?Object.assign(Object.assign({},Ut),{name:t}):Object.assign(Object.assign(Object.assign({},Ut),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):$t(t,i.name))(Et[Et.length-1])}function Ht(t,e){return new qt(t,e)}function Gt(t,e,i){const n=jt.from(t,t instanceof jt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}const Kt={raise:ht,send:dt,sendParent:ut,sendUpdate:lt,log:function(t=ft,e){return{type:Q,label:e,expr:t}},cancel:pt,start:gt,stop:vt,assign:yt,after:mt,done:bt,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:xt,escalate:function(t,e){return ut((e,i,n)=>({type:tt,data:b(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:I.Parent}))},choose:function(t){return{type:V.Choose,conds:t}},pure:function(t){return{type:V.Pure,get:t}}};export{V as ActionTypes,qt as Interpreter,Bt as InterpreterStatus,Lt as Machine,I as SpecialTargets,jt as State,It as StateNode,Kt as actions,yt as assign,Dt as createMachine,St as doneInvoke,xt as forwardTo,Ht as interpret,P as mapState,Gt as matchState,i as matchesState,dt as send,ut as sendParent,lt as sendUpdate,Xt as spawn};
package/es/Actor.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare function createNullActor(id: string): Actor;
18
18
  *
19
19
  * @param invokeDefinition The meta information needed to invoke the actor.
20
20
  */
21
- export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE>, context: TC, _event: SCXML.Event<TE>): Actor;
21
+ export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): Actor;
22
22
  export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): Actor;
23
23
  export declare function isActor(item: any): item is ActorRef<any>;
24
24
  export declare function isSpawnedActor(item: any): item is SpawnedActorRef<any>;
package/es/State.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare function isState<TContext, TEvent extends EventObject, TStateSche
5
5
  value: any;
6
6
  context: TContext;
7
7
  }>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
8
- export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE>): ActionObject<TC, TE>;
8
+ export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
9
9
  export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
10
10
  value: any;
11
11
  context: TContext;
@@ -37,7 +37,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
37
37
  /**
38
38
  * The enabled state nodes representative of the state value.
39
39
  */
40
- configuration: Array<StateNode<TContext, any, TEvent>>;
40
+ configuration: Array<StateNode<TContext, any, TEvent, any>>;
41
41
  /**
42
42
  * The next events that will cause a transition from the current state.
43
43
  */
@@ -55,7 +55,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
55
55
  * @param stateValue
56
56
  * @param context
57
57
  */
58
- static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context?: TC | undefined): State<TC, TE>;
58
+ static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
59
59
  /**
60
60
  * Creates a new State instance for the given `config`.
61
61
  * @param config The state config
@@ -91,9 +91,10 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
91
91
  * Whether the current state value is a subset of the given parent state value.
92
92
  * @param parentStateValue
93
93
  */
94
- matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends {
94
+ matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
95
95
  value: TSV;
96
- } ? TTypestate : never)['context'], TEvent, TStateSchema, TTypestate> & {
96
+ context: any;
97
+ } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
97
98
  value: TSV;
98
99
  };
99
100
  }
package/es/StateNode.d.ts CHANGED
@@ -81,11 +81,11 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
81
81
  /**
82
82
  * The parent state node.
83
83
  */
84
- parent?: StateNode<TContext, any, TEvent>;
84
+ parent?: StateNode<TContext, any, TEvent, any>;
85
85
  /**
86
86
  * The root machine node.
87
87
  */
88
- machine: StateNode<TContext, any, TEvent>;
88
+ machine: StateNode<TContext, any, TEvent, TTypestate>;
89
89
  /**
90
90
  * The meta data associated with this state node, which will be returned in State instances.
91
91
  */
@@ -159,7 +159,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
159
159
  *
160
160
  * @param state The state value or State instance
161
161
  */
162
- getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent>>;
162
+ getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, any>>;
163
163
  /**
164
164
  * Returns `true` if this state node explicitly handles the given event.
165
165
  *
@@ -173,7 +173,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
173
173
  *
174
174
  * @param state The state to resolve
175
175
  */
176
- resolveState(state: State<TContext, TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>;
176
+ resolveState(state: State<TContext, TEvent, any, any>): State<TContext, TEvent, TStateSchema, TTypestate>;
177
177
  private transitionLeafNode;
178
178
  private transitionCompoundNode;
179
179
  private transitionParallelNode;
@@ -205,13 +205,13 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
205
205
  *
206
206
  * @param stateId The state ID. The prefix "#" is removed.
207
207
  */
208
- getStateNodeById(stateId: string): StateNode<TContext, any, TEvent>;
208
+ getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any>;
209
209
  /**
210
210
  * Returns the relative state node from the given `statePath`, or throws.
211
211
  *
212
212
  * @param statePath The string or string array relative path to the state node.
213
213
  */
214
- getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent>;
214
+ getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>;
215
215
  /**
216
216
  * Resolves a partial state value with its full representation in this machine.
217
217
  *
@@ -239,14 +239,14 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
239
239
  * @param resolve Whether state nodes should resolve to initial child state nodes
240
240
  */
241
241
  getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>;
242
- get initialStateNodes(): Array<StateNode<TContext, any, TEvent>>;
242
+ get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>;
243
243
  /**
244
244
  * Retrieves state nodes from a relative path to this state node.
245
245
  *
246
246
  * @param relativePath The relative path from this state node
247
247
  * @param historyValue
248
248
  */
249
- getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent>>;
249
+ getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>;
250
250
  private historyValue;
251
251
  /**
252
252
  * Resolves to the historical value(s) of the parent state node,
package/es/StateNode.js CHANGED
@@ -3,7 +3,7 @@ import { STATE_DELIMITER } from './constants.js';
3
3
  import { IS_PRODUCTION } from './environment.js';
4
4
  import { mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, matchesState, path, evaluateGuard, mapContext, toSCXMLEvent, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine, isFunction } from './utils.js';
5
5
  import { SpecialTargets } from './types.js';
6
- import { getAllStateNodes, getConfiguration, has, getChildren, isInFinalState, getValue, isLeafNode } from './stateUtils.js';
6
+ import { getAllStateNodes, getConfiguration, isInFinalState, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
7
7
  import { start as start$1, stop as stop$1, invoke, update, nullEvent, raise as raise$1, send as send$1 } from './actionTypes.js';
8
8
  import { done, start, raise, stop, toActionObjects, resolveActions, doneInvoke, error, toActionObject, toActivityDefinition, after, send, cancel, initEvent } from './actions.js';
9
9
  import { State, stateValuesEqual } from './State.js';
@@ -425,7 +425,8 @@ function () {
425
425
  var configuration = Array.from(getConfiguration([], this.getStateNodes(state.value)));
426
426
  return new State(__assign(__assign({}, state), {
427
427
  value: this.resolve(state.value),
428
- configuration: configuration
428
+ configuration: configuration,
429
+ done: isInFinalState(configuration, this)
429
430
  }));
430
431
  };
431
432
 
package/es/actions.d.ts CHANGED
@@ -135,5 +135,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
135
135
  */
136
136
  export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
137
137
  export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseConditon<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
138
- export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>): [Array<ActionObject<TContext, TEvent>>, TContext];
138
+ export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>): [Array<ActionObject<TContext, TEvent>>, TContext];
139
139
  //# sourceMappingURL=actions.d.ts.map
package/es/devTools.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Interpreter } from '.';
3
- declare type AnyInterpreter = Interpreter<any, any, any>;
3
+ import { AnyInterpreter } from './types';
4
4
  declare type ServiceListener = (service: AnyInterpreter) => void;
5
5
  export interface XStateDevInterface {
6
6
  register: (service: Interpreter<any>) => void;
@@ -10,7 +10,7 @@ export interface XStateDevInterface {
10
10
  };
11
11
  services: Set<Interpreter<any>>;
12
12
  }
13
- export declare function getGlobal(): (Window & typeof globalThis) | NodeJS.Global | undefined;
13
+ export declare function getGlobal(): (Window & typeof globalThis) | (NodeJS.Global & typeof globalThis) | undefined;
14
14
  export declare function registerService(service: AnyInterpreter): void;
15
15
  export {};
16
16
  //# sourceMappingURL=devTools.d.ts.map
package/es/interpreter.js CHANGED
@@ -550,6 +550,11 @@ function () {
550
550
  }
551
551
  }
552
552
 
553
+ if (!this.initialized) {
554
+ // Interpreter already stopped; do nothing
555
+ return this;
556
+ }
557
+
553
558
  this.state.configuration.forEach(function (stateNode) {
554
559
  var e_11, _a;
555
560
 
package/es/model.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { AssignAction, Assigner, PropertyAssigner, ExtractEvent, EventObject } from './types';
2
+ export interface ContextModel<TContext, TEvent extends EventObject> {
3
+ initialContext: TContext;
4
+ assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
5
+ reset: () => AssignAction<TContext, any>;
6
+ }
7
+ export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): ContextModel<TContext, TEvent>;
8
+ //# sourceMappingURL=model.d.ts.map
@@ -1,10 +1,4 @@
1
- import { Interpreter } from './interpreter';
2
- export declare const provide: <T, TService extends Interpreter<any, any, any, {
3
- value: any;
4
- context: any;
5
- }>>(service: TService | undefined, fn: (service: TService | undefined) => T) => T;
6
- export declare const consume: <T, TService extends Interpreter<any, any, any, {
7
- value: any;
8
- context: any;
9
- }>>(fn: (service: TService) => T) => T;
1
+ import { AnyInterpreter } from './types';
2
+ export declare const provide: <T, TService extends AnyInterpreter>(service: TService | undefined, fn: (service: TService | undefined) => T) => T;
3
+ export declare const consume: <T, TService extends AnyInterpreter>(fn: (service: TService) => T) => T;
10
4
  //# sourceMappingURL=serviceScope.d.ts.map
@@ -1,14 +1,14 @@
1
1
  import { EventObject, StateNode, StateValue } from '.';
2
2
  declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
3
3
  declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
4
- export declare const isLeafNode: (stateNode: StateNode<any, any, any>) => boolean;
4
+ export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
5
5
  export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
6
- export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
7
- export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE>>, stateNodes: Iterable<StateNode<TC, any, TE>>): Iterable<StateNode<TC, any, TE>>;
6
+ export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any>): Array<StateNode<TC, any, TE, any>>;
7
+ export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Iterable<StateNode<TC, any, TE, any>>;
8
8
  export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
9
- export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE>, configuration: Configuration<TC, TE>): StateValue;
9
+ export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
10
10
  export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
11
11
  export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
12
- export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>, stateNode: StateNode<TC, any, TE>): boolean;
12
+ export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any>>, stateNode: StateNode<TC, any, TE, any>): boolean;
13
13
  export {};
14
14
  //# sourceMappingURL=stateUtils.d.ts.map
package/es/types.d.ts CHANGED
@@ -201,7 +201,7 @@ export declare type StatesDefinition<TContext, TStateSchema extends StateSchema,
201
201
  };
202
202
  export declare type TransitionConfigTarget<TContext, TEvent extends EventObject> = string | undefined | StateNode<TContext, any, TEvent>;
203
203
  export declare type TransitionConfigOrTarget<TContext, TEvent extends EventObject> = SingleOrArray<TransitionConfigTarget<TContext, TEvent> | TransitionConfig<TContext, TEvent>>;
204
- declare type TransitionsConfigMap<TContext, TEvent extends EventObject> = {
204
+ export declare type TransitionsConfigMap<TContext, TEvent extends EventObject> = {
205
205
  [K in TEvent['type']]?: TransitionConfigOrTarget<TContext, TEvent extends {
206
206
  type: K;
207
207
  } ? TEvent : never>;
@@ -433,7 +433,7 @@ export interface MachineOptions<TContext, TEvent extends EventObject> {
433
433
  /**
434
434
  * @private
435
435
  */
436
- _parent?: StateNode<TContext, any, TEvent>;
436
+ _parent?: StateNode<TContext, any, TEvent, any>;
437
437
  /**
438
438
  * @private
439
439
  */
@@ -489,13 +489,13 @@ export interface ActivityMap {
489
489
  }
490
490
  export interface StateTransition<TContext, TEvent extends EventObject> {
491
491
  transitions: Array<TransitionDefinition<TContext, TEvent>>;
492
- configuration: Array<StateNode<TContext, any, TEvent>>;
493
- entrySet: Array<StateNode<TContext, any, TEvent>>;
494
- exitSet: Array<StateNode<TContext, any, TEvent>>;
492
+ configuration: Array<StateNode<TContext, any, TEvent, any>>;
493
+ entrySet: Array<StateNode<TContext, any, TEvent, any>>;
494
+ exitSet: Array<StateNode<TContext, any, TEvent, any>>;
495
495
  /**
496
496
  * The source state that preceded the transition.
497
497
  */
498
- source: State<TContext> | undefined;
498
+ source: State<TContext, any, any, any> | undefined;
499
499
  actions: Array<ActionObject<TContext, TEvent>>;
500
500
  }
501
501
  export interface TransitionData<TContext, TEvent extends EventObject> {
@@ -616,8 +616,9 @@ export interface CancelAction extends ActionObject<any, any> {
616
616
  sendId: string | number;
617
617
  }
618
618
  export declare type Assigner<TContext, TEvent extends EventObject> = (context: TContext, event: TEvent, meta: AssignMeta<TContext, TEvent>) => Partial<TContext>;
619
+ export declare type PartialAssigner<TContext, TEvent extends EventObject, TKey extends keyof TContext> = (context: TContext, event: TEvent, meta: AssignMeta<TContext, TEvent>) => TContext[TKey];
619
620
  export declare type PropertyAssigner<TContext, TEvent extends EventObject> = {
620
- [K in keyof TContext]?: ((context: TContext, event: TEvent, meta: AssignMeta<TContext, TEvent>) => TContext[K]) | TContext[K];
621
+ [K in keyof TContext]?: PartialAssigner<TContext, TEvent, K> | TContext[K];
621
622
  };
622
623
  export declare type Mapper<TContext, TEvent extends EventObject, TParams extends {}> = (context: TContext, event: TEvent) => TParams;
623
624
  export declare type PropertyMapper<TContext, TEvent extends EventObject, TParams extends {}> = {
@@ -715,7 +716,7 @@ export interface SCXMLEventMeta<TEvent extends EventObject> {
715
716
  _event: SCXML.Event<TEvent>;
716
717
  }
717
718
  export interface StateMeta<TContext, TEvent extends EventObject> {
718
- state: State<TContext, TEvent>;
719
+ state: State<TContext, TEvent, any, any>;
719
720
  _event: SCXML.Event<TEvent>;
720
721
  }
721
722
  export interface Typestate<TContext> {
@@ -758,7 +759,7 @@ export interface InterpreterOptions {
758
759
  execute: boolean;
759
760
  clock: Clock;
760
761
  logger: (...args: any[]) => void;
761
- parent?: Interpreter<any, any, any>;
762
+ parent?: AnyInterpreter;
762
763
  /**
763
764
  * If `true`, defers processing of sent events until the service
764
765
  * is initialized (`.start()`). Otherwise, an error will be thrown
@@ -854,6 +855,9 @@ export interface Subscribable<T> {
854
855
  subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
855
856
  }
856
857
  export declare type Spawnable = StateMachine<any, any, any> | Promise<any> | InvokeCallback | Subscribable<any>;
858
+ export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
859
+ type: TEventType;
860
+ } ? TEvent : never;
857
861
  export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
858
862
  send: Sender<TEvent>;
859
863
  }
@@ -865,5 +869,6 @@ export interface SpawnedActorRef<TEvent extends EventObject, TEmitted = any> ext
865
869
  export declare type ActorRefFrom<T extends StateMachine<any, any, any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? SpawnedActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
866
870
  state: State<TContext, TEvent, any, TTypestate>;
867
871
  } : never;
872
+ export declare type AnyInterpreter = Interpreter<any, any, any, any>;
868
873
  export {};
869
874
  //# sourceMappingURL=types.d.ts.map
package/es/utils.d.ts CHANGED
@@ -10,12 +10,10 @@ export declare function toStatePath(stateId: string | string[], delimiter: strin
10
10
  export declare function isStateLike(state: any): state is StateLike<any>;
11
11
  export declare function toStateValue(stateValue: StateLike<any> | StateValue | string[], delimiter: string): StateValue;
12
12
  export declare function pathToStateValue(statePath: string[]): StateValue;
13
- export declare function mapValues<T, P>(collection: {
13
+ export declare function mapValues<T, P, O extends {
14
14
  [key: string]: T;
15
- }, iteratee: (item: T, key: string, collection: {
16
- [key: string]: T;
17
- }, i: number) => P): {
18
- [key: string]: P;
15
+ }>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
16
+ [key in keyof O]: P;
19
17
  };
20
18
  export declare function mapFilterValues<T, P>(collection: {
21
19
  [key: string]: T;
@@ -53,7 +51,7 @@ export declare function isFunction(value: any): value is Function;
53
51
  export declare function isString(value: any): value is string;
54
52
  export declare function toGuard<TContext, TEvent extends EventObject>(condition?: Condition<TContext, TEvent>, guardMap?: Record<string, ConditionPredicate<TContext, TEvent>>): Guard<TContext, TEvent> | undefined;
55
53
  export declare function isObservable<T>(value: any): value is Subscribable<T>;
56
- export declare const symbolObservable: string | symbol;
54
+ export declare const symbolObservable: any;
57
55
  export declare function isMachine(value: any): value is StateMachine<any, any, any>;
58
56
  export declare function isActor(value: any): value is Actor;
59
57
  export declare const uniqueId: () => string;
@@ -64,7 +62,7 @@ export declare function toTransitionConfigArray<TContext, TEvent extends EventOb
64
62
  }>;
65
63
  export declare function normalizeTarget<TContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, any, TEvent>> | undefined): Array<string | StateNode<TContext, any, TEvent>> | undefined;
66
64
  export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
67
- export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
65
+ export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
68
66
  export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
69
67
  export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
70
68
  //# sourceMappingURL=utils.d.ts.map
package/lib/Actor.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare function createNullActor(id: string): Actor;
18
18
  *
19
19
  * @param invokeDefinition The meta information needed to invoke the actor.
20
20
  */
21
- export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE>, context: TC, _event: SCXML.Event<TE>): Actor;
21
+ export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): Actor;
22
22
  export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): Actor;
23
23
  export declare function isActor(item: any): item is ActorRef<any>;
24
24
  export declare function isSpawnedActor(item: any): item is SpawnedActorRef<any>;
package/lib/State.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare function isState<TContext, TEvent extends EventObject, TStateSche
5
5
  value: any;
6
6
  context: TContext;
7
7
  }>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
8
- export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE>): ActionObject<TC, TE>;
8
+ export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
9
9
  export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
10
10
  value: any;
11
11
  context: TContext;
@@ -37,7 +37,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
37
37
  /**
38
38
  * The enabled state nodes representative of the state value.
39
39
  */
40
- configuration: Array<StateNode<TContext, any, TEvent>>;
40
+ configuration: Array<StateNode<TContext, any, TEvent, any>>;
41
41
  /**
42
42
  * The next events that will cause a transition from the current state.
43
43
  */
@@ -55,7 +55,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
55
55
  * @param stateValue
56
56
  * @param context
57
57
  */
58
- static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context?: TC | undefined): State<TC, TE>;
58
+ static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
59
59
  /**
60
60
  * Creates a new State instance for the given `config`.
61
61
  * @param config The state config
@@ -91,9 +91,10 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
91
91
  * Whether the current state value is a subset of the given parent state value.
92
92
  * @param parentStateValue
93
93
  */
94
- matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends {
94
+ matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
95
95
  value: TSV;
96
- } ? TTypestate : never)['context'], TEvent, TStateSchema, TTypestate> & {
96
+ context: any;
97
+ } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
97
98
  value: TSV;
98
99
  };
99
100
  }