xstate 4.29.0 → 4.30.0
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.
- package/CHANGELOG.md +35 -2
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Machine.d.ts +1 -1
- package/es/State.d.ts +5 -4
- package/es/State.js +4 -4
- package/es/StateNode.d.ts +2 -2
- package/es/StateNode.js +7 -6
- package/es/actions.js +8 -3
- package/es/index.d.ts +2 -20
- package/es/index.js +10 -22
- package/es/interpreter.d.ts +4 -7
- package/es/interpreter.js +2 -2
- package/es/types.d.ts +8 -0
- package/lib/Machine.d.ts +1 -1
- package/lib/State.d.ts +5 -4
- package/lib/State.js +4 -4
- package/lib/StateNode.d.ts +2 -2
- package/lib/StateNode.js +7 -6
- package/lib/actions.js +5 -0
- package/lib/index.d.ts +2 -20
- package/lib/index.js +14 -27
- package/lib/interpreter.d.ts +4 -7
- package/lib/interpreter.js +1 -1
- package/lib/types.d.ts +8 -0
- package/package.json +1 -1
package/dist/xstate.web.js
CHANGED
|
@@ -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 w(a)?!!w(r)&&a===r:w(r)?r in a:e(r).every(t=>t in a&&i(r[t],a[t]))}function n(t){try{return w(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 b(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(b(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
|
|
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 w(a)?!!w(r)&&a===r:w(r)?r in a:e(r).every(t=>t in a&&i(r[t],a[t]))}function n(t){try{return w(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 b(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(b(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(w(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 b(t)?t:[t]}function f(t){return void 0===t?[]:l(t)}function p(t,e,i){if(S(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];S(o)?n[s]=o(e,i.data):n[s]=o}return n}function g(t){return t instanceof Promise||!(null===t||!S(t)&&"object"!=typeof t||!S(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=(w(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:y(t,n)}:void 0})}function m(t,i,n,s){return t?n.reduce((t,n)=>{const{assignment:o}=n,r={state:s,action:n,_event:i};let a={};if(S(o))a=o(t,i.data,r);else for(const n of e(o)){const e=o[n];a[n]=S(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}function b(t){return Array.isArray(t)}function S(t){return"function"==typeof t}function w(t){return"string"==typeof t}function O(t,e){if(t)return w(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:S(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const x=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")(),_={[x]:function(){return this},[Symbol.observable]:function(){return this}};function j(t){try{return"__xstatenode"in t}catch(t){return!1}}const E=(()=>{let t=0;return()=>(t++,t.toString(16))})();function T(t,e){return w(t)||"number"==typeof t?Object.assign({type:t},e):t}function N(t,e){if(!w(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=T(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||j(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function k(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(i,n.data,r);const a=null==o?void 0: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 P(t){return"string"==typeof t?{type:t}:t}function I(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}function C(t,e){return`${t}:invocation[${e}]`}function V(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 L(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 D,A;!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"}(D||(D={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(A||(A={}));const R=t=>"atomic"===t.type||"final"===t.type;function M(t){return e(t.states).map(e=>t.states[e])}function z(t){const e=[t];return R(t)?e:e.concat(d(M(t).map(z)))}function F(t,e){const i=B(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=B(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 M(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 B(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 J(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(R(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,B(F([t],e)))}function U(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function q(t,e){return"compound"===e.type?M(e).some(e=>"final"===e.type&&U(t,e)):"parallel"===e.type&&M(e).every(e=>q(t,e))}function X(t){return new Set(d(t.map(t=>t.tags)))}const H=D.Start,G=D.Stop,K=D.Raise,Q=D.Send,W=D.Cancel,Y=D.NullEvent,Z=D.Assign,tt=(D.After,D.DoneState,D.Log),et=D.Init,it=D.Invoke,nt=(D.ErrorExecution,D.ErrorPlatform),st=D.ErrorCustom,ot=D.Update,rt=D.Choose,at=D.Pure,ct=T({type:et});function ht(t,e){return e&&e[t]||void 0}function ut(t,e){let i;if(w(t)||"number"==typeof t){const n=ht(t,e);i=S(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(S(t))i={type:t.name||t.toString(),exec:t};else{const n=ht(t.type,e);if(S(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 i}const dt=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>ut(t,e))};function lt(t){const e=ut(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function ft(t){return w(t)?{type:K,event:t}:pt(t,{to:A.Internal})}function pt(t,e){return{to:e?e.to:void 0,type:Q,event:S(t)?t:N(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function gt(t,e){return pt(t,Object.assign(Object.assign({},e),{to:A.Parent}))}function vt(){return gt(ot)}const yt=(t,e)=>({context:t,event:e});const mt=t=>({type:W,sendId:t});function bt(t){const e=lt(t);return{type:D.Start,activity:e,exec:void 0}}function St(t){const e=S(t)?t:lt(t);return{type:D.Stop,activity:e,exec:void 0}}const wt=t=>({type:Z,assignment:t});function xt(t,e){const i=e?"#"+e:"";return`${D.After}(${t})${i}`}function Ot(t,e){const i=`${D.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function _t(t,e){const i=`${D.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function jt(t,e){const i=`${D.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function Et(t,e){return pt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Nt(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===Z);let c=r.length?m(i,n,r,e):i;const h=o?[i]:void 0;return[d(a.map(i=>{var s;switch(i.type){case K:return{type:K,_event:T(i.event)};case Q:return function(t,e,i,n){const s={_event:i},o=T(S(t.event)?t.event(e,i.data,s):t.event);let r;if(w(t.delay)){const o=n&&n[t.delay];r=S(o)?o(e,i.data,s):o}else r=S(t.delay)?t.delay(e,i.data,s):t.delay;const a=S(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})}(i,c,n,t.options.delays);case tt:return((t,e,i)=>Object.assign(Object.assign({},t),{value:w(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(i,c,n);case rt:{const r=null===(s=i.conds.find(i=>{const s=x(i.cond,t.options.guards);return!s||k(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,u]=Nt(t,e,c,n,dt(f(r),t.options.actions),o);return c=u,null==h||h.push(c),a}case at:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=Nt(t,e,c,n,dt(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case G:return function(t,e,i){const n=S(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:D.Stop,activity:s}}(i,c,n);case Z:c=m(c,n,[i],e),null==h||h.push(c);break;default:let r=ut(i,t.options.actions);const{exec:a}=r;if(a&&h){const t=h.length-1;r=Object.assign(Object.assign({},r),{exec:(e,...i)=>{a(h[t],...i)}})}return r}}).filter(t=>!!t)),c]}function Tt(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 $t{constructor(e){var i;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=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(e.configuration),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,this.tags=null!==(i=Array.isArray(e.tags)?new Set(e.tags):e.tags)&&void 0!==i?i:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(d([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof $t)return t.context!==e?new $t({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 $t({value:t,context:e,_event:ct,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new $t(t)}static inert(t,e){if(t instanceof $t){if(!t.actions.length)return t;const i=ct;return new $t({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return $t.from(t,e)}toStrings(t=this.value,i="."){if(w(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=L(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const kt=[],Ct=(t,e)=>{kt.push(t);const i=e(t);return kt.pop(),i};function Pt(t){return Object.assign({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})},_)}function Vt(t,e,i){const n=Pt(e);if(n.deferred=!0,j(t)){const e=n.state=Ct(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function It(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Lt(t){return Object.assign(Object.assign({type:it},t),{toJSON(){const e=L(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:it,src:It(t.src)})}})}const Dt={},At=t=>"#"===t[0];class Rt{constructor(t,i,n=("context"in t?t.context:void 0),s){var o;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.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=null==s?void 0:s.parent,this.key=this.config.key||(null==s?void 0:s.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.schema=this.parent?this.machine.schema:null!==(o=this.config.schema)&&void 0!==o?o:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new Rt(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Dt;let r=0;!function t(e){e.order=r++;for(const i of M(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=>ut(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>ut(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(j(t)){const i=V(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Lt({src:i,id:i})}if(w(t.src)){const i=t.id||V(this.id,e);return Lt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(j(t.src)||S(t.src)){const i=t.id||V(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Lt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Lt(Object.assign(Object.assign({id:V(this.id,e)},t),{src:i}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>lt(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||z(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new Rt(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)},null!=e?e:this.context)}withContext(t){return new Rt(this.config,this.options,t)}get context(){return S(this._context)?this._context():this._context}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,description:this.description,tags:this.tags}}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=xt(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(pt(i,{delay:t})),this.onExit.push(mt(i)),i};return(b(t)?t.map((t,e)=>{const n=i(t.delay,e);return Object.assign(Object.assign({},t),{event:n})}):d(e(t).map((e,n)=>{const s=t[e],o=w(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 $t?t.value:o(t,this.delimiter);if(w(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this,this.states[i]]}const n=e(i),s=[this];return s.push(...d(n.map(t=>this.getStateNode(t).getStateNodes(i[t])))),s}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(F([],this.getStateNodes(t.value)));return new $t(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:q(e,this),tags:X(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=d(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=d(o.map(t=>t.entrySet)),c=d(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:d(o.map(t=>t.exitSet)),configuration:c,source:i,actions:d(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}getTransitionData(t,e){return this._transition(t.value,t,T(e))}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:u,in:d}=c,l=t.context,f=!d||(w(d)&&At(d)?t.matches(o(this.getStateNodeById(d).path,this.delimiter)):i(o(d,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!u||k(this.machine,u,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${u.name||u.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=d(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),u=!!r.internal;return{transitions:[r],entrySet:u?[]:d(c.map(t=>this.nodesFromChild(t))),exitSet:u?[]:[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=F([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?F(s,t.configuration):s;for(const e of o)U(s,e)||t.entrySet.push(e);for(const e of s)U(o,e)&&!U(t.exitSet,e.parent)||t.exitSet.push(e);const r=d(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(Ot(n.id,n.doneData),Ot(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&M(r).every(e=>q(t.configuration,e))&&s.push(Ot(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,u]=[d(Array.from(a).map(t=>[...t.activities.map(t=>bt(t)),...t.onEntry])).concat(r.map(ft)),d(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>St(t))]))];return dt(u.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=T(e);let s;if(t instanceof $t)s=void 0===i?t:this.resolveState($t.from(t,i));else{const e=w(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState($t.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=F([],this.getStateNodes(s.value)),h=a.configuration.length?F(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,s.context,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,s=ct){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?J(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=this.getActions(t,n,s,i),u=i?Object.assign({},i.activities):{};for(const t of h)t.type===H?u[t.activity.id||t.activity.type]=t:t.type===G&&(u[t.activity.id||t.activity.type]=!1);const[d,l]=Nt(this,i,n,s,h,this.machine.config.preserveActionOrder),[f,g]=v(d,t=>t.type===K||t.type===Q&&t.to===A.Internal),m=d.filter(t=>{var e;return t.type===H&&(null===(e=t.activity)||void 0===e?void 0:e.type)===it}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=C(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?Vt(r,t.id,a):Pt(t.id);return c.meta=t,c}(e.activity,this.machine,l,s),t),i?Object.assign({},i.children):{}),b=r?t.configuration:i?i.configuration:[],S=q(b,this),x=new $t({value:a||i.value,context:l,_event:s,_sessionid:i?i._sessionid:null,historyValue:a?c?(O=c,_=a,{current:_,states:y(O,_)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?g:[],activities:a?u:i?i.activities:{},events:[],configuration:b,transitions:t.transitions,children:m,done:S,tags:null==i?void 0:i.tags,machine:this});var O,_;const j=n!==l;x.changed=s.name===ot||j;const{history:E}=x;E&&delete E.history;const N=!S&&(this._transient||o.some(t=>t._transient));if(!(r||N&&""!==s.name))return x;let T=x;if(!S)for(N&&(T=this.resolveRaisedTransition(T,{type:Y},s));f.length;){const t=f.shift();T=this.resolveRaisedTransition(T,t._event,s)}const $=T.changed||(E?!!T.actions.length||j||typeof E.value!=typeof T.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(w(i)||w(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,E.value):void 0);return T.changed=$,T.history=E,T.tags=X(T.configuration),T}getStateNode(t){if(At(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=At(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&&At(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||Dt;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Dt);case"compound":if(w(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):Dt):this.initialStateValue||{};default:return t||Dt}}getResolvedPath(t){if(At(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||Dt,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=R(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};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,null!=e?e:this.machine.context,void 0)}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=w(e.target)&&At(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(R(this))return[this];if("compound"===this.type&&!this.initial)return[this];return d(u(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=w(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?d(u(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 w(i)?[e.getStateNode(i)]:d(u(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=d(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(!w(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=>w(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:dt(f(t.actions)),cond:x(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=L(i,[n+""]);t=d(e(r).map(t=>$(t,r[t])).concat($("*",o)))}else t=[];const i=this.config.always?$("",this.config.always):[],n=this.config.onDone?$(String(Ot(this.id)),this.config.onDone):[],s=d(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...$(String(_t(t.id)),t.onDone)),t.onError&&e.push(...$(String(jt(t.id)),t.onError)),e})),o=this.after,r=d([...n,...s,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function Mt(t,e,i=t.context){return new Rt(t,e,i)}function zt(t,e){return new Rt(t,e)}const Ft={deferEvents:!1};class Bt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Ft),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 Jt=new Map;let Ut=0;const qt={bookId:()=>"x:"+Ut++,register:(t,e)=>(Jt.set(t,e),t),get:t=>Jt.get(t),free(t){Jt.delete(t)}};function Xt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Ht(t){if(!Xt())return;const e=function(){const t=Xt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function Gt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=(a={id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,c),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=P(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},Object.assign(Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{}},_),a));var a;const c={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(c):i,r}const Kt={sync:!1,autoForward:!1};var Qt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Qt||(Qt={}));class Wt{constructor(t,e=Wt.defaultOptions){this.machine=t,this.scheduler=new Bt,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=Qt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(b(t))return this.batch(t),this.state;const i=T(N(t,e));if(this.status===Qt.Stopped)return this.state;if(this.status!==Qt.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===A.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||qt.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===st?""+jt(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({},Wt.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 Bt({deferEvents:this.options.deferEvents}),this.sessionId=qt.bookId()}get initialState(){return this._initialState?this._initialState:Ct(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=q(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(_t(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Qt.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===Qt.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===Qt.Running)return this;qt.register(this.sessionId,this),this.initialized=!0,this.status=Qt.Running;const e=void 0===t?this.initialState:Ct(this,()=>{return!w(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState($t.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,ct)}),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].sort((t,e)=>e.order-t.order).forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{S(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=Qt.Stopped,qt.free(this.sessionId),this}batch(t){if(this.status===Qt.NotStarted&&this.options.deferEvents);else if(this.status!==Qt.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=T(s);this.forward(t),e=Ct(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Tt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,T(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=T(t);if(0===e.name.indexOf(nt)&&!this.state.nextEvents.some(t=>0===t.indexOf(nt)))throw e.data.data;return Ct(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||ht(t.type,i),r=S(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 Q: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 W:this.cancel(t.sendId);break;case H:{if(this.status!==Qt.Running)return;const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===D.Invoke){const t=C(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;if("string"==typeof i)return;let h,u=S(i)?i(n,s.data,{data:c,src:t,meta:e.meta}):i;if(!u)return;j(u)&&(u=c?u.withContext(c):u,h={autoForward:a}),this.spawn(u,o,h)}else this.spawnActivity(e);break}case G:this.stopChild(t.activity.id);break;case tt:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),S(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(S(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&S(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(j(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Wt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Kt),e);n.sync&&i.onTransition(t=>{this.send(ot,{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(T(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=Gt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(T(_t(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=jt(e,t);try{this.send(T(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s=Object.assign({id:e,send:()=>{},subscribe:(e,i,n)=>{const s=P(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:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i},_);return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(T(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(jt(e,t))}if(g(a))return this.spawnPromise(a,e);const c=Object.assign({id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,S(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o},_);return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(T(t,{origin:e}))},t=>{this.removeChild(e),this.send(T(jt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(T(_t(e),{origin:e}))}),s=Object.assign({id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e})},_);return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,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,Object.assign({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})},_))}attachDev(){const t=Xt();if(this.options.devTools&&t){if(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)}Ht(this)}}toJSON(){return{id:this.id}}[O](){return this}getSnapshot(){return this.status===Qt.NotStarted?this.initialState:this._state}}Wt.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),Wt.interpret=Zt;function Yt(t,e){const i=(t=>w(t)?Object.assign(Object.assign({},Kt),{name:t}):Object.assign(Object.assign(Object.assign({},Kt),{name:E()}),t))(e);return(e=>e?e.spawn(t,i.name,i):Vt(t,i.name))(kt[kt.length-1])}function Zt(t,e){return new Wt(t,e)}function te(t,e,i){const n=$t.from(t,t instanceof $t?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function ee(t){return t}const ie=ee,ne={raise:ft,send:pt,sendParent:gt,sendTo:function(t,e,i){return pt(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:vt,log:function(t=yt,e){return{type:tt,label:e,expr:t}},cancel:mt,start:bt,stop:St,assign:wt,after:xt,done:Ot,respond:function(t,e){return pt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:Et,escalate:function(t,e){return gt((e,i,n)=>({type:st,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:A.Parent}))},choose:function(t){return{type:D.Choose,conds:t}},pure:function(t){return{type:D.Pure,get:t}}};export{D as ActionTypes,Wt as Interpreter,Qt as InterpreterStatus,Mt as Machine,A as SpecialTargets,$t as State,Rt as StateNode,ne as actions,wt as assign,zt as createMachine,ee as createSchema,_t as doneInvoke,Et as forwardTo,Zt as interpret,I as mapState,te as matchState,i as matchesState,pt as send,gt as sendParent,vt as sendUpdate,Yt as spawn,ie as t};
|
|
15
|
+
***************************************************************************** */function A(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 L,D;!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"}(L||(L={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(D||(D={}));const R=t=>"atomic"===t.type||"final"===t.type;function M(t){return e(t.states).map(e=>t.states[e])}function z(t){const e=[t];return R(t)?e:e.concat(u(M(t).map(z)))}function F(t,e){const i=U(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=U(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 M(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 U(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 B(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(R(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,U(F([t],e)))}function J(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function q(t,e){return"compound"===e.type?M(e).some(e=>"final"===e.type&&J(t,e)):"parallel"===e.type&&M(e).every(e=>q(t,e))}function X(t){return new Set(u(t.map(t=>t.tags)))}const H=L.Start,G=L.Stop,K=L.Raise,Q=L.Send,W=L.Cancel,Y=L.NullEvent,Z=L.Assign,tt=L.After,et=L.DoneState,it=L.Log,nt=L.Init,st=L.Invoke,ot=L.ErrorExecution,rt=L.ErrorPlatform,at=L.ErrorCustom,ct=L.Update,ht=L.Choose,dt=L.Pure;var ut=Object.freeze({__proto__:null,start:H,stop:G,raise:K,send:Q,cancel:W,nullEvent:Y,assign:Z,after:tt,doneState:et,log:it,init:nt,invoke:st,errorExecution:ot,errorPlatform:rt,error:at,update:ct,choose:ht,pure:dt});const lt=N({type:nt});function ft(t,e){return e&&e[t]||void 0}function pt(t,e){let i;if(w(t)||"number"==typeof t){const n=ft(t,e);i=S(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(S(t))i={type:t.name||t.toString(),exec:t};else{const n=ft(t.type,e);if(S(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 i}const gt=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>pt(t,e))};function vt(t){const e=pt(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function yt(t){return w(t)?{type:K,event:t}:bt(t,{to:D.Internal})}function mt(t){return{type:K,_event:N(t.event)}}function bt(t,e){return{to:e?e.to:void 0,type:Q,event:S(t)?t:T(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function St(t,e,i,n){const s={_event:i},o=N(S(t.event)?t.event(e,i.data,s):t.event);let r;if(w(t.delay)){const o=n&&n[t.delay];r=S(o)?o(e,i.data,s):o}else r=S(t.delay)?t.delay(e,i.data,s):t.delay;const a=S(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})}function wt(t,e){return bt(t,Object.assign(Object.assign({},e),{to:D.Parent}))}const Ot=(t,e)=>({context:t,event:e});const xt=(t,e,i)=>Object.assign(Object.assign({},t),{value:w(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),_t=t=>({type:W,sendId:t});function jt(t){const e=vt(t);return{type:L.Start,activity:e,exec:void 0}}function Et(t){const e=S(t)?t:vt(t);return{type:L.Stop,activity:e,exec:void 0}}function Tt(t,e,i){const n=S(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:L.Stop,activity:s}}function Nt(t,e){const i=e?"#"+e:"";return`${L.After}(${t})${i}`}function $t(t,e){const i=`${L.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function kt(t,e){const i=`${L.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function Pt(t,e){const i=`${L.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function It(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===Z);let c=r.length?m(i,n,r,e):i;const h=o?[i]:void 0;return[u(a.map(i=>{var s;switch(i.type){case K:return mt(i);case Q:return St(i,c,n,t.options.delays);case it:return xt(i,c,n);case ht:{const r=null===(s=i.conds.find(i=>{const s=O(i.cond,t.options.guards);return!s||k(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,d]=It(t,e,c,n,gt(f(r),t.options.actions),o);return c=d,null==h||h.push(c),a}case dt:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=It(t,e,c,n,gt(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case G:return Tt(i,c,n);case Z:c=m(c,n,[i],e),null==h||h.push(c);break;default:let r=pt(i,t.options.actions);const{exec:a}=r;if(a&&h){const t=h.length-1;r=Object.assign(Object.assign({},r),{exec:(e,...i)=>{a(h[t],...i)}})}return r}}).filter(t=>!!t)),c]}var Ct=Object.freeze({__proto__:null,actionTypes:ut,initEvent:lt,getActionFunction:ft,toActionObject:pt,toActionObjects:gt,toActivityDefinition:vt,raise:yt,resolveRaise:mt,send:bt,resolveSend:St,sendParent:wt,sendTo:function(t,e,i){return bt(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:function(){return wt(ct)},respond:function(t,e){return bt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},log:function(t=Ot,e){return{type:it,label:e,expr:t}},resolveLog:xt,cancel:_t,start:jt,stop:Et,resolveStop:Tt,assign:t=>({type:Z,assignment:t}),isActionObject:function(t){return"object"==typeof t&&"type"in t},after:Nt,done:$t,doneInvoke:kt,error:Pt,pure:function(t){return{type:L.Pure,get:t}},forwardTo:function(t,e){return bt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))},escalate:function(t,e){return wt((e,i,n)=>({type:at,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:D.Parent}))},choose:function(t){return{type:L.Choose,conds:t}},resolveActions:It});function Vt(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 At{constructor(e){var i;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=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(e.configuration),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,this.tags=null!==(i=Array.isArray(e.tags)?new Set(e.tags):e.tags)&&void 0!==i?i:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(u([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof At)return t.context!==e?new At({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 At({value:t,context:e,_event:lt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new At(t)}static inert(t,e){if(t instanceof At){if(!t.actions.length)return t;const i=lt;return new At({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return At.from(t,e)}toStrings(t=this.value,i="."){if(w(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=A(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Lt=[],Dt=(t,e)=>{Lt.push(t);const i=e(t);return Lt.pop(),i};function Rt(t){return Object.assign({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})},_)}function Mt(t,e,i){const n=Rt(e);if(n.deferred=!0,j(t)){const e=n.state=Dt(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function zt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Ft(t){return Object.assign(Object.assign({type:st},t),{toJSON(){const e=A(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:st,src:zt(t.src)})}})}const Ut={},Bt=t=>"#"===t[0];class Jt{constructor(t,i,n=("context"in t?t.context:void 0),s){var o;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.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=null==s?void 0:s.parent,this.key=this.config.key||(null==s?void 0:s.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.schema=this.parent?this.machine.schema:null!==(o=this.config.schema)&&void 0!==o?o:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new Jt(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Ut;let r=0;!function t(e){e.order=r++;for(const i of M(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=>pt(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>pt(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(j(t)){const i=C(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Ft({src:i,id:i})}if(w(t.src)){const i=t.id||C(this.id,e);return Ft(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(j(t.src)||S(t.src)){const i=t.id||C(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Ft(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Ft(Object.assign(Object.assign({id:C(this.id,e)},t),{src:i}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>vt(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||z(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new Jt(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)},null!=e?e:this.context)}withContext(t){return new Jt(this.config,this.options,t)}get context(){return S(this._context)?this._context():this._context}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,description:this.description,tags:this.tags}}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=Nt(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(bt(i,{delay:t})),this.onExit.push(_t(i)),i};return(b(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=w(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 At?t.value:o(t,this.delimiter);if(w(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this,this.states[i]]}const n=e(i),s=[this];return s.push(...u(n.map(t=>this.getStateNode(t).getStateNodes(i[t])))),s}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=t instanceof At?t:At.create(t),i=Array.from(F([],this.getStateNodes(e.value)));return new At(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:q(i,this),tags:X(i)}))}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 w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}getTransitionData(t,e){return this._transition(t.value,t,N(e))}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||(w(u)&&Bt(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||k(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=F([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?F(s,t.configuration):s;for(const e of o)J(s,e)||t.entrySet.push(e);for(const e of s)J(o,e)&&!J(t.exitSet,e.parent)||t.exitSet.push(e);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($t(n.id,n.doneData),$t(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&M(r).every(e=>q(t.configuration,e))&&s.push($t(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=>jt(t)),...t.onEntry])).concat(r.map(yt)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>Et(t))]))];return gt(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 At)s=void 0===i?t:this.resolveState(At.from(t,i));else{const e=w(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState(At.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=F([],this.getStateNodes(s.value)),h=a.configuration.length?F(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,s.context,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,s=lt){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?B(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=this.getActions(t,n,s,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===H?d[t.activity.id||t.activity.type]=t:t.type===G&&(d[t.activity.id||t.activity.type]=!1);const[u,l]=It(this,i,n,s,h,this.machine.config.preserveActionOrder),[f,g]=v(u,t=>t.type===K||t.type===Q&&t.to===D.Internal),m=u.filter(t=>{var e;return t.type===H&&(null===(e=t.activity)||void 0===e?void 0:e.type)===st}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=P(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?Mt(r,t.id,a):Rt(t.id);return c.meta=t,c}(e.activity,this.machine,l,s),t),i?Object.assign({},i.children):{}),b=r?t.configuration:i?i.configuration:[],S=q(b,this),O=new At({value:a||i.value,context:l,_event:s,_sessionid:i?i._sessionid:null,historyValue:a?c?(x=c,_=a,{current:_,states:y(x,_)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?g:[],activities:a?d:i?i.activities:{},events:[],configuration:b,transitions:t.transitions,children:m,done:S,tags:null==i?void 0:i.tags,machine:this});var x,_;const j=n!==l;O.changed=s.name===ct||j;const{history:E}=O;E&&delete E.history;const T=!S&&(this._transient||o.some(t=>t._transient));if(!(r||T&&""!==s.name))return O;let N=O;if(!S)for(T&&(N=this.resolveRaisedTransition(N,{type:Y},s));f.length;){const t=f.shift();N=this.resolveRaisedTransition(N,t._event,s)}const $=N.changed||(E?!!N.actions.length||j||typeof E.value!=typeof N.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(w(i)||w(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}(N.value,E.value):void 0);return N.changed=$,N.history=E,N.tags=X(N.configuration),N}getStateNode(t){if(Bt(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=Bt(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&&Bt(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||Ut;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Ut);case"compound":if(w(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):Ut):this.initialStateValue||{};default:return t||Ut}}getResolvedPath(t){if(Bt(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||Ut,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=R(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){this._init();const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){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=w(e.target)&&Bt(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(R(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=w(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 w(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(!w(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=>w(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:gt(f(t.actions)),cond:O(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=A(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($t(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...$(String(kt(t.id)),t.onDone)),t.onError&&e.push(...$(String(Pt(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 qt(t,e,i=t.context){return new Jt(t,e,i)}function Xt(t,e){return new Jt(t,e)}const Ht={deferEvents:!1};class Gt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Ht),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 Kt=new Map;let Qt=0;const Wt={bookId:()=>"x:"+Qt++,register:(t,e)=>(Kt.set(t,e),t),get:t=>Kt.get(t),free(t){Kt.delete(t)}};function Yt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Zt(t){if(!Yt())return;const e=function(){const t=Yt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function te(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=(a={id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,c),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=I(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},Object.assign(Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{}},_),a));var a;const c={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(c):i,r}const ee={sync:!1,autoForward:!1};var ie;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(ie||(ie={}));class ne{constructor(t,e=ne.defaultOptions){this.machine=t,this.scheduler=new Gt,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=ie.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(b(t))return this.batch(t),this.state;const i=N(T(t,e));if(this.status===ie.Stopped)return this.state;if(this.status!==ie.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===D.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||Wt.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===at?""+Pt(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({},ne.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 Gt({deferEvents:this.options.deferEvents}),this.sessionId=Wt.bookId()}get initialState(){return this._initialState?this._initialState:Dt(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=q(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(kt(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===ie.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===ie.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===ie.Running)return this;Wt.register(this.sessionId,this),this.initialized=!0,this.status=ie.Running;const e=void 0===t?this.initialState:Dt(this,()=>{return"object"==typeof(e=t)&&null!==e&&"value"in e&&"_event"in e?this.machine.resolveState(t):this.machine.resolveState(At.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,lt)}),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].sort((t,e)=>e.order-t.order).forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{S(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=ie.Stopped,Wt.free(this.sessionId),this}batch(t){if(this.status===ie.NotStarted&&this.options.deferEvents);else if(this.status!==ie.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=Dt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Vt(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(rt)&&!this.state.nextEvents.some(t=>0===t.indexOf(rt)))throw e.data.data;return Dt(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||ft(t.type,i),r=S(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 Q: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 W:this.cancel(t.sendId);break;case H:{if(this.status!==ie.Running)return;const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===L.Invoke){const t=P(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;if("string"==typeof i)return;let h,d=S(i)?i(n,s.data,{data:c,src:t,meta:e.meta}):i;if(!d)return;j(d)&&(d=c?d.withContext(c):d,h={autoForward:a}),this.spawn(d,o,h)}else this.spawnActivity(e);break}case G:this.stopChild(t.activity.id);break;case it:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),S(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(S(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&S(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(j(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new ne(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},ee),e);n.sync&&i.onTransition(t=>{this.send(ct,{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}spawnBehavior(t,e){const i=te(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(N(kt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=Pt(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 s=Object.assign({id:e,send:()=>{},subscribe:(e,i,n)=>{const s=I(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:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i},_);return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(Pt(e,t))}if(g(a))return this.spawnPromise(a,e);const c=Object.assign({id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,S(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o},_);return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(Pt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(kt(e),{origin:e}))}),s=Object.assign({id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e})},_);return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,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,Object.assign({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})},_))}attachDev(){const t=Yt();if(this.options.devTools&&t){if(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)}Zt(this)}}toJSON(){return{id:this.id}}[x](){return this}getSnapshot(){return this.status===ie.NotStarted?this.initialState:this._state}}ne.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),ne.interpret=oe;function se(t,e){const i=(t=>w(t)?Object.assign(Object.assign({},ee),{name:t}):Object.assign(Object.assign(Object.assign({},ee),{name:E()}),t))(e);return(e=>e?e.spawn(t,i.name,i):Mt(t,i.name))(Lt[Lt.length-1])}function oe(t,e){return new ne(t,e)}function re(t,e,i){const n=At.from(t,t instanceof At?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function ae(t){return t}const ce=ae,{assign:he,send:de,sendParent:ue,sendUpdate:le,forwardTo:fe,doneInvoke:pe}=Ct;export{L as ActionTypes,ne as Interpreter,ie as InterpreterStatus,qt as Machine,D as SpecialTargets,At as State,Jt as StateNode,Ct as actions,he as assign,Xt as createMachine,ae as createSchema,pe as doneInvoke,fe as forwardTo,oe as interpret,V as mapState,re as matchState,i as matchesState,de as send,ue as sendParent,le as sendUpdate,se as spawn,ce as t};
|
package/es/Machine.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export declare function Machine<TContext = DefaultContext, TStateSchema extends
|
|
|
9
9
|
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
|
|
10
10
|
value: any;
|
|
11
11
|
context: TContext;
|
|
12
|
-
}, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent, BaseActionObject, TServiceMap, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>): StateMachine<TContext, any, TEvent,
|
|
12
|
+
}, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent, BaseActionObject, TServiceMap, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>): StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>;
|
|
13
13
|
//# sourceMappingURL=Machine.d.ts.map
|
package/es/State.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ import { StateNode } from './StateNode';
|
|
|
3
3
|
import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
|
|
4
4
|
import { BaseActionObject, Prop } from './types';
|
|
5
5
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
6
|
-
export declare function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export declare function isStateConfig<TContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare const isState: typeof isStateConfig;
|
|
10
11
|
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
|
|
11
12
|
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
12
13
|
value: any;
|
package/es/State.js
CHANGED
|
@@ -24,12 +24,12 @@ function stateValuesEqual(a, b) {
|
|
|
24
24
|
return stateValuesEqual(a[key], b[key]);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
if (
|
|
27
|
+
function isStateConfig(state) {
|
|
28
|
+
if (typeof state !== 'object' || state === null) {
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
return 'value' in state && '
|
|
32
|
+
return 'value' in state && '_event' in state;
|
|
33
33
|
}
|
|
34
34
|
function bindActionToState(action, state) {
|
|
35
35
|
var exec = action.exec;
|
|
@@ -271,4 +271,4 @@ function () {
|
|
|
271
271
|
return State;
|
|
272
272
|
}();
|
|
273
273
|
|
|
274
|
-
export { State, bindActionToState,
|
|
274
|
+
export { State, bindActionToState, isStateConfig, stateValuesEqual };
|
package/es/StateNode.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap } from './types';
|
|
1
|
+
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap, StateConfig } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { TypegenDisabled } from './typegenTypes';
|
|
4
4
|
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
@@ -182,7 +182,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
182
182
|
*
|
|
183
183
|
* @param state The state to resolve
|
|
184
184
|
*/
|
|
185
|
-
resolveState(state: State<TContext, TEvent, any, any,
|
|
185
|
+
resolveState(state: State<TContext, TEvent, any, any> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
186
186
|
private transitionLeafNode;
|
|
187
187
|
private transitionCompoundNode;
|
|
188
188
|
private transitionParallelNode;
|
package/es/StateNode.js
CHANGED
|
@@ -437,9 +437,10 @@ function () {
|
|
|
437
437
|
|
|
438
438
|
|
|
439
439
|
StateNode.prototype.resolveState = function (state) {
|
|
440
|
-
var
|
|
441
|
-
|
|
442
|
-
|
|
440
|
+
var stateFromConfig = state instanceof State ? state : State.create(state);
|
|
441
|
+
var configuration = Array.from(getConfiguration([], this.getStateNodes(stateFromConfig.value)));
|
|
442
|
+
return new State(__assign(__assign({}, stateFromConfig), {
|
|
443
|
+
value: this.resolve(stateFromConfig.value),
|
|
443
444
|
configuration: configuration,
|
|
444
445
|
done: isInFinalState(configuration, this),
|
|
445
446
|
tags: getTagsFromConfiguration(configuration)
|
|
@@ -1141,6 +1142,9 @@ function () {
|
|
|
1141
1142
|
});
|
|
1142
1143
|
|
|
1143
1144
|
StateNode.prototype.getInitialState = function (stateValue, context) {
|
|
1145
|
+
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
1146
|
+
|
|
1147
|
+
|
|
1144
1148
|
var configuration = this.getStateNodes(stateValue);
|
|
1145
1149
|
return this.resolveTransition({
|
|
1146
1150
|
configuration: configuration,
|
|
@@ -1158,9 +1162,6 @@ function () {
|
|
|
1158
1162
|
* entering the initial state.
|
|
1159
1163
|
*/
|
|
1160
1164
|
get: function () {
|
|
1161
|
-
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
1165
|
var initialStateValue = this.initialStateValue;
|
|
1165
1166
|
|
|
1166
1167
|
if (!initialStateValue) {
|
package/es/actions.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { __assign, __read, __spreadArray } from './_virtual/_tslib.js';
|
|
2
2
|
import { IS_PRODUCTION } from './environment.js';
|
|
3
|
-
import {
|
|
3
|
+
import { toSCXMLEvent, isString, isFunction, toEventObject, getEventType, partition, updateContext, flatten, toArray, toGuard, evaluateGuard, warn, isArray } from './utils.js';
|
|
4
4
|
import { SpecialTargets, ActionTypes } from './types.js';
|
|
5
|
-
import { send as send$1,
|
|
5
|
+
import { send as send$1, raise as raise$1, update, log as log$1, cancel as cancel$1, assign as assign$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1, init } from './actionTypes.js';
|
|
6
|
+
import * as actionTypes from './actionTypes.js';
|
|
7
|
+
export { actionTypes };
|
|
6
8
|
|
|
7
9
|
var initEvent = /*#__PURE__*/toSCXMLEvent({
|
|
8
10
|
type: init
|
|
@@ -288,6 +290,9 @@ var assign = function (assignment) {
|
|
|
288
290
|
assignment: assignment
|
|
289
291
|
};
|
|
290
292
|
};
|
|
293
|
+
function isActionObject(action) {
|
|
294
|
+
return typeof action === 'object' && 'type' in action;
|
|
295
|
+
}
|
|
291
296
|
/**
|
|
292
297
|
* Returns an event type that represents an implicit event that
|
|
293
298
|
* is sent after the specified `delay`.
|
|
@@ -512,4 +517,4 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
512
517
|
return [resolvedActions, updatedContext];
|
|
513
518
|
}
|
|
514
519
|
|
|
515
|
-
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendTo, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
|
|
520
|
+
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, isActionObject, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendTo, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
|
package/es/index.d.ts
CHANGED
|
@@ -4,29 +4,11 @@ import { StateNode } from './StateNode';
|
|
|
4
4
|
import { State } from './State';
|
|
5
5
|
import { Machine, createMachine } from './Machine';
|
|
6
6
|
import { Actor } from './Actor';
|
|
7
|
-
import
|
|
7
|
+
import * as actions from './actions';
|
|
8
8
|
import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
|
|
9
9
|
import { matchState } from './match';
|
|
10
10
|
import { createSchema, t } from './schema';
|
|
11
|
-
declare const actions:
|
|
12
|
-
raise: typeof raise;
|
|
13
|
-
send: typeof send;
|
|
14
|
-
sendParent: typeof sendParent;
|
|
15
|
-
sendTo: typeof sendTo;
|
|
16
|
-
sendUpdate: typeof sendUpdate;
|
|
17
|
-
log: typeof log;
|
|
18
|
-
cancel: (sendId: string | number) => import("./types").CancelAction;
|
|
19
|
-
start: typeof start;
|
|
20
|
-
stop: typeof stop;
|
|
21
|
-
assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>;
|
|
22
|
-
after: typeof after;
|
|
23
|
-
done: typeof done;
|
|
24
|
-
respond: typeof respond;
|
|
25
|
-
forwardTo: typeof forwardTo;
|
|
26
|
-
escalate: typeof escalate;
|
|
27
|
-
choose: typeof choose;
|
|
28
|
-
pure: typeof pure;
|
|
29
|
-
};
|
|
11
|
+
declare const assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>, send: typeof actions.send, sendParent: typeof actions.sendParent, sendUpdate: typeof actions.sendUpdate, forwardTo: typeof actions.forwardTo, doneInvoke: typeof actions.doneInvoke;
|
|
30
12
|
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
|
|
31
13
|
export * from './types';
|
|
32
14
|
export * from './typegenTypes';
|
package/es/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { matchesState } from './utils.js';
|
|
2
2
|
export { mapState } from './mapState.js';
|
|
3
3
|
export { ActionTypes, SpecialTargets } from './types.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { assign as assign$1, send as send$1, sendParent as sendParent$1, sendUpdate as sendUpdate$1, forwardTo as forwardTo$1, doneInvoke as doneInvoke$1 } from './actions.js';
|
|
5
|
+
import * as actions from './actions.js';
|
|
6
|
+
export { actions };
|
|
6
7
|
export { State } from './State.js';
|
|
7
8
|
export { StateNode } from './StateNode.js';
|
|
8
9
|
export { Machine, createMachine } from './Machine.js';
|
|
@@ -10,24 +11,11 @@ export { Interpreter, InterpreterStatus, interpret, spawn } from './interpreter.
|
|
|
10
11
|
export { matchState } from './match.js';
|
|
11
12
|
export { createSchema, t } from './schema.js';
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
log: log,
|
|
20
|
-
cancel: cancel,
|
|
21
|
-
start: start,
|
|
22
|
-
stop: stop,
|
|
23
|
-
assign: assign,
|
|
24
|
-
after: after,
|
|
25
|
-
done: done,
|
|
26
|
-
respond: respond,
|
|
27
|
-
forwardTo: forwardTo,
|
|
28
|
-
escalate: escalate,
|
|
29
|
-
choose: choose,
|
|
30
|
-
pure: pure
|
|
31
|
-
};
|
|
14
|
+
var assign = assign$1,
|
|
15
|
+
send = send$1,
|
|
16
|
+
sendParent = sendParent$1,
|
|
17
|
+
sendUpdate = sendUpdate$1,
|
|
18
|
+
forwardTo = forwardTo$1,
|
|
19
|
+
doneInvoke = doneInvoke$1;
|
|
32
20
|
|
|
33
|
-
export {
|
|
21
|
+
export { assign, doneInvoke, forwardTo, send, sendParent, sendUpdate };
|
package/es/interpreter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
|
|
3
2
|
import { State } from './State';
|
|
3
|
+
import { StateConfig } from '.';
|
|
4
4
|
import { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
|
|
5
5
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
6
6
|
value: any;
|
|
@@ -37,10 +37,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
37
37
|
static defaultOptions: {
|
|
38
38
|
execute: boolean;
|
|
39
39
|
deferEvents: boolean;
|
|
40
|
-
clock:
|
|
41
|
-
setTimeout: (fn: any, ms: any) => NodeJS.Timeout;
|
|
42
|
-
clearTimeout: (id: any) => void;
|
|
43
|
-
};
|
|
40
|
+
clock: Clock;
|
|
44
41
|
logger: any;
|
|
45
42
|
devTools: boolean;
|
|
46
43
|
};
|
|
@@ -131,12 +128,12 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
131
128
|
/**
|
|
132
129
|
* Alias for Interpreter.prototype.start
|
|
133
130
|
*/
|
|
134
|
-
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | undefined) => this;
|
|
131
|
+
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | undefined) => this;
|
|
135
132
|
/**
|
|
136
133
|
* Starts the interpreter from the given state, or the initial state.
|
|
137
134
|
* @param initialState The state to start the statechart from
|
|
138
135
|
*/
|
|
139
|
-
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateValue): this;
|
|
136
|
+
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
|
|
140
137
|
/**
|
|
141
138
|
* Stops the interpreter and unsubscribe all listeners.
|
|
142
139
|
*
|
package/es/interpreter.js
CHANGED
|
@@ -5,7 +5,7 @@ import { ActionTypes, SpecialTargets } from './types.js';
|
|
|
5
5
|
import { isInFinalState } from './stateUtils.js';
|
|
6
6
|
import { errorPlatform, log, stop, start, cancel, send, update, error as error$1 } from './actionTypes.js';
|
|
7
7
|
import { doneInvoke, initEvent, getActionFunction, error } from './actions.js';
|
|
8
|
-
import {
|
|
8
|
+
import { isStateConfig, State, bindActionToState } from './State.js';
|
|
9
9
|
import { provide, consume } from './serviceScope.js';
|
|
10
10
|
import { isSpawnedActor, createDeferredActor } from './Actor.js';
|
|
11
11
|
import { Scheduler } from './scheduler.js';
|
|
@@ -459,7 +459,7 @@ function () {
|
|
|
459
459
|
this.initialized = true;
|
|
460
460
|
this.status = InterpreterStatus.Running;
|
|
461
461
|
var resolvedState = initialState === undefined ? this.initialState : provide(this, function () {
|
|
462
|
-
return
|
|
462
|
+
return isStateConfig(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
|
|
463
463
|
});
|
|
464
464
|
|
|
465
465
|
if (this.options.devTools) {
|
package/es/types.d.ts
CHANGED
|
@@ -564,6 +564,7 @@ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
|
|
|
564
564
|
history: 'shallow' | 'deep';
|
|
565
565
|
target: StateValue | undefined;
|
|
566
566
|
}
|
|
567
|
+
/** @ts-ignore TS complains about withConfig & withContext not being compatible here when extending StateNode */
|
|
567
568
|
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
|
|
568
569
|
value: any;
|
|
569
570
|
context: TContext;
|
|
@@ -572,12 +573,19 @@ export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent
|
|
|
572
573
|
states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>['states'];
|
|
573
574
|
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
|
|
574
575
|
withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, TResolvedTypesMeta>;
|
|
576
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
575
577
|
__TContext: TContext;
|
|
578
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
576
579
|
__TStateSchema: TStateSchema;
|
|
580
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
577
581
|
__TEvent: TEvent;
|
|
582
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
578
583
|
__TTypestate: TTypestate;
|
|
584
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
579
585
|
__TAction: TAction;
|
|
586
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
580
587
|
__TServiceMap: TServiceMap;
|
|
588
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
581
589
|
__TResolvedTypesMeta: TResolvedTypesMeta;
|
|
582
590
|
}
|
|
583
591
|
export declare type StateFrom<T extends StateMachine<any, any, any, any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any, any, any, any>)> = T extends StateMachine<any, any, any, any, any, any, any> ? ReturnType<T['transition']> : T extends (...args: any[]) => StateMachine<any, any, any, any, any, any, any> ? ReturnType<ReturnType<T>['transition']> : never;
|
package/lib/Machine.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export declare function Machine<TContext = DefaultContext, TStateSchema extends
|
|
|
9
9
|
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
|
|
10
10
|
value: any;
|
|
11
11
|
context: TContext;
|
|
12
|
-
}, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent, BaseActionObject, TServiceMap, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>): StateMachine<TContext, any, TEvent,
|
|
12
|
+
}, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent, BaseActionObject, TServiceMap, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>): StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>;
|
|
13
13
|
//# sourceMappingURL=Machine.d.ts.map
|
package/lib/State.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ import { StateNode } from './StateNode';
|
|
|
3
3
|
import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
|
|
4
4
|
import { BaseActionObject, Prop } from './types';
|
|
5
5
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
6
|
-
export declare function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export declare function isStateConfig<TContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare const isState: typeof isStateConfig;
|
|
10
11
|
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
|
|
11
12
|
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
12
13
|
value: any;
|
package/lib/State.js
CHANGED
|
@@ -28,12 +28,12 @@ function stateValuesEqual(a, b) {
|
|
|
28
28
|
return stateValuesEqual(a[key], b[key]);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
if (
|
|
31
|
+
function isStateConfig(state) {
|
|
32
|
+
if (typeof state !== 'object' || state === null) {
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
return 'value' in state && '
|
|
36
|
+
return 'value' in state && '_event' in state;
|
|
37
37
|
}
|
|
38
38
|
function bindActionToState(action, state) {
|
|
39
39
|
var exec = action.exec;
|
|
@@ -277,5 +277,5 @@ function () {
|
|
|
277
277
|
|
|
278
278
|
exports.State = State;
|
|
279
279
|
exports.bindActionToState = bindActionToState;
|
|
280
|
-
exports.
|
|
280
|
+
exports.isStateConfig = isStateConfig;
|
|
281
281
|
exports.stateValuesEqual = stateValuesEqual;
|
package/lib/StateNode.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap } from './types';
|
|
1
|
+
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap, StateConfig } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { TypegenDisabled } from './typegenTypes';
|
|
4
4
|
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
@@ -182,7 +182,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
182
182
|
*
|
|
183
183
|
* @param state The state to resolve
|
|
184
184
|
*/
|
|
185
|
-
resolveState(state: State<TContext, TEvent, any, any,
|
|
185
|
+
resolveState(state: State<TContext, TEvent, any, any> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
186
186
|
private transitionLeafNode;
|
|
187
187
|
private transitionCompoundNode;
|
|
188
188
|
private transitionParallelNode;
|