xstate 4.26.0-pr2674-202191175724 → 4.27.0-pr2674-2021926101023
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 +48 -10
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +1 -1
- package/es/Machine.d.ts +3 -3
- package/es/StateNode.d.ts +8 -4
- package/es/StateNode.js +13 -13
- package/es/actions.d.ts +2 -2
- package/es/interpreter.js +2 -1
- package/es/model.types.d.ts +3 -3
- package/es/stateUtils.d.ts +1 -0
- package/es/stateUtils.js +7 -2
- package/es/typegenTypes.d.ts +15 -1
- package/es/types.d.ts +60 -22
- package/lib/Machine.d.ts +3 -3
- package/lib/StateNode.d.ts +8 -4
- package/lib/StateNode.js +12 -12
- package/lib/actions.d.ts +2 -2
- package/lib/interpreter.js +2 -1
- package/lib/model.types.d.ts +3 -3
- package/lib/stateUtils.d.ts +1 -0
- package/lib/stateUtils.js +6 -0
- package/lib/typegenTypes.d.ts +15 -1
- package/lib/types.d.ts +60 -22
- package/package.json +1 -1
package/dist/xstate.web.js
CHANGED
|
@@ -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 V(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 I,L;!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"}(I||(I={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(L||(L={}));const A=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function R(t){const e=[t];return A(t)?e:e.concat(u(D(t).map(R)))}function M(t,e){const i=z(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=z(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function z(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function F(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(A(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,z(M([t],e)))}function B(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?D(e).some(e=>"final"===e.type&&B(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=I.Start,q=I.Stop,X=I.Raise,H=I.Send,G=I.Cancel,K=I.NullEvent,Q=I.Assign,W=(I.After,I.DoneState,I.Log),Y=I.Init,Z=I.Invoke,tt=(I.ErrorExecution,I.ErrorPlatform),et=I.ErrorCustom,it=I.Update,nt=I.Choose,st=I.Pure,ot=N({type:Y});function rt(t,e){return e&&e[t]||void 0}function at(t,e){let i;if(w(t)||"number"==typeof t){const n=rt(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=rt(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 ct=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>at(t,e))};function ht(t){const e=at(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function dt(t){return w(t)?{type:X,event:t}:ut(t,{to:L.Internal})}function ut(t,e){return{to:e?e.to:void 0,type:H,event:S(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function lt(t,e){return ut(t,Object.assign(Object.assign({},e),{to:L.Parent}))}function ft(){return lt(it)}const pt=(t,e)=>({context:t,event:e});const gt=t=>({type:G,sendId:t});function vt(t){const e=ht(t);return{type:I.Start,activity:e,exec:void 0}}function yt(t){const e=S(t)?t:ht(t);return{type:I.Stop,activity:e,exec:void 0}}const mt=t=>({type:Q,assignment:t});function bt(t,e){const i=e?"#"+e:"";return`${I.After}(${t})${i}`}function St(t,e){const i=`${I.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function wt(t,e){const i=`${I.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function xt(t,e){const i=`${I.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function Ot(t,e){return ut((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function _t(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===Q);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 X:return{type:X,_event:N(i.event)};case H:return function(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})}(i,c,n,t.options.delays);case W: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 nt:{const r=null===(s=i.conds.find(i=>{const s=x(i.cond,t.options.guards);return!s||$(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,d]=_t(t,e,c,n,ct(f(r),t.options.actions),o);return c=d,null==h||h.push(c),a}case st:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=_t(t,e,c,n,ct(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case q: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:I.Stop,activity:s}}(i,c,n);case Q:c=m(c,n,[i],e),null==h||h.push(c);break;default:let r=at(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 jt(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 Et{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 Et)return t.context!==e?new Et({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 Et({value:t,context:e,_event:ot,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Et(t)}static inert(t,e){if(t instanceof Et){if(!t.actions.length)return t;const i=ot;return new Et({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Et.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=V(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;return this.machine,!!(null===(e=this.machine)||void 0===e?void 0:e.transition(this,t).changed)}}const Nt=[],Tt=(t,e)=>{Nt.push(t);const i=e(t);return Nt.pop(),i};function $t(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})}}function kt(t,e,i){const n=$t(e);if(n.deferred=!0,_(t)){const e=n.state=Tt(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function Ct(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Z},t),{toJSON(){const e=V(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Z,src:Ct(t.src)})}})}const Vt={},It=t=>"#"===t[0];class Lt{constructor(t,i,n=("context"in t?t.context:void 0)){var s;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=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new Lt(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Vt;let o=0;!function t(e){e.order=o++;for(const i of D(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>at(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>at(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(_(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Pt({src:t.id,id:t.id});if(w(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||S(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Pt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Pt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>ht(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||R(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new Lt(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 Lt(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}}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=bt(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(ut(i,{delay:t})),this.onExit.push(gt(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 Et?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=n.map(t=>this.getStateNode(t));return s.push(this),s.concat(n.reduce((t,e)=>{const n=this.getStateNode(e).getStateNodes(i[e]);return t.concat(n)},[]))}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(M([],this.getStateNodes(t.value)));return new Et(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=u(o.map(t=>t.entrySet)),c=u(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:d,in:u}=c,l=t.context,f=!u||(w(u)&&It(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||$(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=M([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?M(s,t.configuration):s;for(const e of o)B(s,e)||t.entrySet.push(e);for(const e of s)B(o,e)&&!B(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(St(n.id,n.doneData),St(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&s.push(St(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=>vt(t)),...t.onEntry])).concat(r.map(dt)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>yt(t))]))];return ct(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 Et)s=void 0===i?t:this.resolveState(Et.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(Et.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=M([],this.getStateNodes(s.value)),h=a.configuration.length?M(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n=ot,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?F(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=i?i.context:s,d=this.getActions(t,h,n,i),l=i?Object.assign({},i.activities):{};for(const t of d)t.type===U?l[t.activity.id||t.activity.type]=t:t.type===q&&(l[t.activity.id||t.activity.type]=!1);const[f,g]=_t(this,i,h,n,d,this.machine.config.preserveActionOrder),[m,b]=v(f,t=>t.type===X||t.type===H&&t.to===L.Internal),S=f.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Z}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=k(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?kt(r,t.id,a):$t(t.id);return c.meta=t,c}(e.activity,this.machine,g,n),t),i?Object.assign({},i.children):{}),x=a?t.configuration:i?i.configuration:[],O=J(x,this),_=new Et({value:a||i.value,context:g,_event:n,_sessionid:i?i._sessionid:null,historyValue:a?c?(j=c,E=a,{current:E,states:y(j,E)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?b:[],activities:a?l:i?i.activities:{},events:[],configuration:x,transitions:t.transitions,children:S,done:O,tags:null==i?void 0:i.tags,machine:this});var j,E;const N=h!==g;_.changed=n.name===it||N;const{history:T}=_;T&&delete T.history;const $=!O&&(this._transient||o.some(t=>t._transient));if(!(r||$&&""!==n.name))return _;let C=_;if(!O)for($&&(C=this.resolveRaisedTransition(C,{type:K},n));m.length;){const t=m.shift();C=this.resolveRaisedTransition(C,t._event,n)}const P=C.changed||(T?!!C.actions.length||N||typeof T.value!=typeof C.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]))}(C.value,T.value):void 0);return C.changed=P,C.history=T,C.tags=new Set(u(C.configuration.map(t=>t.tags))),C}getStateNode(t){if(It(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=It(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&&It(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||Vt;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Vt);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):Vt):this.initialStateValue||{};default:return t||Vt}}getResolvedPath(t){if(It(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||Vt,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=A(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,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=w(e.target)&&It(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(A(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:ct(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=V(i,[n+""]);t=u(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],n=this.config.onDone?T(String(St(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(wt(t.id)),t.onDone)),t.onError&&e.push(...T(String(xt(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 At(t,e,i=t.context){return new Lt(t,e,i)}function Dt(t,e){return new Lt(t,e)}const Rt={deferEvents:!1};class Mt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Rt),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 zt=new Map;let Ft=0;const Bt={bookId:()=>"x:"+Ft++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Ut(t){if(!Jt())return;const e=function(){const t=Jt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(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=C(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},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 Xt={sync:!1,autoForward:!1};var Ht;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Ht||(Ht={}));class Gt{constructor(t,e=Gt.defaultOptions){this.machine=t,this.scheduler=new Mt,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=Ht.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(E(t,e));if(this.status===Ht.Stopped)return this.state;if(this.status!==Ht.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===L.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||Bt.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===et?""+xt(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({},Gt.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 Mt({deferEvents:this.options.deferEvents}),this.sessionId=Bt.bookId()}get initialState(){return this._initialState?this._initialState:Tt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(wt(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Ht.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===Ht.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===Ht.Running)return this;Bt.register(this.sessionId,this),this.initialized=!0,this.status=Ht.Running;const e=void 0===t?this.initialState:Tt(this,()=>{return!w(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(Et.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,ot)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{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=Ht.Stopped,Bt.free(this.sessionId),this}batch(t){if(this.status===Ht.NotStarted&&this.options.deferEvents);else if(this.status!==Ht.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=Tt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>jt(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(tt)&&!this.state.nextEvents.some(t=>0===t.indexOf(tt)))throw e.data.data;return Tt(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||rt(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 H: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 G:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===I.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0;if("string"==typeof i)return;let h,d=S(i)?i(n,s.data,{data:c,src:t}):i;if(!d)return;_(d)&&(d=c?d.withContext(c):d,h={autoForward:a}),this.spawn(d,o,h)}else this.spawnActivity(e);break}case q:this.stopChild(t.activity.id);break;case W: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(_(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 Gt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Xt),e);n.sync&&i.onTransition(t=>{this.send(it,{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=qt(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(wt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=xt(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={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=C(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(xt(e,t))}if(g(a))return this.spawnPromise(a,e);const c={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(xt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(wt(e),{origin:e}))}),s={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,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})})}attachDev(){const t=Jt();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)}Ut(this)}}toJSON(){return{id:this.id}}[O](){return this}getSnapshot(){return this.status===Ht.NotStarted?this.initialState:this._state}}Gt.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),Gt.interpret=Qt;function Kt(t,e){const i=(t=>w(t)?Object.assign(Object.assign({},Xt),{name:t}):Object.assign(Object.assign(Object.assign({},Xt),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):kt(t,i.name))(Nt[Nt.length-1])}function Qt(t,e){return new Gt(t,e)}function Wt(t,e,i){const n=Et.from(t,t instanceof Et?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function Yt(t){return t}const Zt={raise:dt,send:ut,sendParent:lt,sendUpdate:ft,log:function(t=pt,e){return{type:W,label:e,expr:t}},cancel:gt,start:vt,stop:yt,assign:mt,after:bt,done:St,respond:function(t,e){return ut(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:Ot,escalate:function(t,e){return lt((e,i,n)=>({type:et,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:L.Parent}))},choose:function(t){return{type:I.Choose,conds:t}},pure:function(t){return{type:I.Pure,get:t}}};export{I as ActionTypes,Gt as Interpreter,Ht as InterpreterStatus,At as Machine,L as SpecialTargets,Et as State,Lt as StateNode,Zt as actions,mt as assign,Dt as createMachine,Yt as createSchema,wt as doneInvoke,Ot as forwardTo,Qt as interpret,P as mapState,Wt as matchState,i as matchesState,ut as send,lt as sendParent,ft as sendUpdate,Kt as spawn};
|
|
15
|
+
***************************************************************************** */function V(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 I,L;!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"}(I||(I={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(L||(L={}));const A=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function R(t){const e=[t];return A(t)?e:e.concat(u(D(t).map(R)))}function M(t,e){const i=z(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=z(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function z(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function F(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(A(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,z(M([t],e)))}function B(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?D(e).some(e=>"final"===e.type&&B(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}function U(t){return new Set(u(t.map(t=>t.tags)))}const q=I.Start,X=I.Stop,H=I.Raise,G=I.Send,K=I.Cancel,Q=I.NullEvent,W=I.Assign,Y=(I.After,I.DoneState,I.Log),Z=I.Init,tt=I.Invoke,et=(I.ErrorExecution,I.ErrorPlatform),it=I.ErrorCustom,nt=I.Update,st=I.Choose,ot=I.Pure,rt=N({type:Z});function at(t,e){return e&&e[t]||void 0}function ct(t,e){let i;if(w(t)||"number"==typeof t){const n=at(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=at(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 ht=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>ct(t,e))};function dt(t){const e=ct(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function ut(t){return w(t)?{type:H,event:t}:lt(t,{to:L.Internal})}function lt(t,e){return{to:e?e.to:void 0,type:G,event:S(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function ft(t,e){return lt(t,Object.assign(Object.assign({},e),{to:L.Parent}))}function pt(){return ft(nt)}const gt=(t,e)=>({context:t,event:e});const vt=t=>({type:K,sendId:t});function yt(t){const e=dt(t);return{type:I.Start,activity:e,exec:void 0}}function mt(t){const e=S(t)?t:dt(t);return{type:I.Stop,activity:e,exec:void 0}}const bt=t=>({type:W,assignment:t});function St(t,e){const i=e?"#"+e:"";return`${I.After}(${t})${i}`}function wt(t,e){const i=`${I.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function xt(t,e){const i=`${I.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function Ot(t,e){const i=`${I.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function _t(t,e){return lt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function jt(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===W);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 H:return{type:H,_event:N(i.event)};case G:return function(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})}(i,c,n,t.options.delays);case Y: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 st:{const r=null===(s=i.conds.find(i=>{const s=x(i.cond,t.options.guards);return!s||$(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,d]=jt(t,e,c,n,ht(f(r),t.options.actions),o);return c=d,null==h||h.push(c),a}case ot:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=jt(t,e,c,n,ht(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case X: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:I.Stop,activity:s}}(i,c,n);case W:c=m(c,n,[i],e),null==h||h.push(c);break;default:let r=ct(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 Et(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 Nt{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 Nt)return t.context!==e?new Nt({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 Nt({value:t,context:e,_event:rt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Nt(t)}static inert(t,e){if(t instanceof Nt){if(!t.actions.length)return t;const i=rt;return new Nt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Nt.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=V(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;return this.machine,!!(null===(e=this.machine)||void 0===e?void 0:e.transition(this,t).changed)}}const Tt=[],$t=(t,e)=>{Tt.push(t);const i=e(t);return Tt.pop(),i};function kt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})}}function Ct(t,e,i){const n=kt(e);if(n.deferred=!0,_(t)){const e=n.state=$t(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function Pt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Vt(t){return Object.assign(Object.assign({type:tt},t),{toJSON(){const e=V(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:tt,src:Pt(t.src)})}})}const It={},Lt=t=>"#"===t[0];class At{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 At(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):It;let r=0;!function t(e){e.order=r++;for(const i of D(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>ct(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>ct(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(_(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Vt({src:t.id,id:t.id});if(w(t.src))return Vt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||S(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Vt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Vt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>dt(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||R(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new At(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 At(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=St(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(lt(i,{delay:t})),this.onExit.push(vt(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 Nt?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=n.map(t=>this.getStateNode(t));return s.push(this),s.concat(n.reduce((t,e)=>{const n=this.getStateNode(e).getStateNodes(i[e]);return t.concat(n)},[]))}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(M([],this.getStateNodes(t.value)));return new Nt(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this),tags:U(e)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=u(o.map(t=>t.entrySet)),c=u(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:d,in:u}=c,l=t.context,f=!u||(w(u)&&Lt(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||$(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=M([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?M(s,t.configuration):s;for(const e of o)B(s,e)||t.entrySet.push(e);for(const e of s)B(o,e)&&!B(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(wt(n.id,n.doneData),wt(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&s.push(wt(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=>yt(t)),...t.onEntry])).concat(r.map(ut)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>mt(t))]))];return ht(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 Nt)s=void 0===i?t:this.resolveState(Nt.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(Nt.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=M([],this.getStateNodes(s.value)),h=a.configuration.length?M(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n=rt,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?F(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=i?i.context:s,d=this.getActions(t,h,n,i),u=i?Object.assign({},i.activities):{};for(const t of d)t.type===q?u[t.activity.id||t.activity.type]=t:t.type===X&&(u[t.activity.id||t.activity.type]=!1);const[l,f]=jt(this,i,h,n,d,this.machine.config.preserveActionOrder),[g,m]=v(l,t=>t.type===H||t.type===G&&t.to===L.Internal),b=l.filter(t=>{var e;return t.type===q&&(null===(e=t.activity)||void 0===e?void 0:e.type)===tt}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=k(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?Ct(r,t.id,a):kt(t.id);return c.meta=t,c}(e.activity,this.machine,f,n),t),i?Object.assign({},i.children):{}),S=a?t.configuration:i?i.configuration:[],x=J(S,this),O=new Nt({value:a||i.value,context:f,_event:n,_sessionid:i?i._sessionid:null,historyValue:a?c?(_=c,j=a,{current:j,states:y(_,j)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?m:[],activities:a?u:i?i.activities:{},events:[],configuration:S,transitions:t.transitions,children:b,done:x,tags:null==i?void 0:i.tags,machine:this});var _,j;const E=h!==f;O.changed=n.name===nt||E;const{history:N}=O;N&&delete N.history;const T=!x&&(this._transient||o.some(t=>t._transient));if(!(r||T&&""!==n.name))return O;let $=O;if(!x)for(T&&($=this.resolveRaisedTransition($,{type:Q},n));g.length;){const t=g.shift();$=this.resolveRaisedTransition($,t._event,n)}const C=$.changed||(N?!!$.actions.length||E||typeof N.value!=typeof $.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(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]))}($.value,N.value):void 0);return $.changed=C,$.history=N,$.tags=U($.configuration),$}getStateNode(t){if(Lt(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=Lt(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&&Lt(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||It;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):It);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):It):this.initialStateValue||{};default:return t||It}}getResolvedPath(t){if(Lt(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||It,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=A(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,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=w(e.target)&&Lt(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(A(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:ht(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=V(i,[n+""]);t=u(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],n=this.config.onDone?T(String(wt(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(xt(t.id)),t.onDone)),t.onError&&e.push(...T(String(Ot(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 Dt(t,e,i=t.context){return new At(t,e,i)}function Rt(t,e){return new At(t,e)}const Mt={deferEvents:!1};class zt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Mt),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 Ft=new Map;let Bt=0;const Jt={bookId:()=>"x:"+Bt++,register:(t,e)=>(Ft.set(t,e),t),get:t=>Ft.get(t),free(t){Ft.delete(t)}};function Ut(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function qt(t){if(!Ut())return;const e=function(){const t=Ut();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function Xt(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=C(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},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 Ht={sync:!1,autoForward:!1};var Gt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Gt||(Gt={}));class Kt{constructor(t,e=Kt.defaultOptions){this.machine=t,this.scheduler=new zt,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=Gt.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(E(t,e));if(this.status===Gt.Stopped)return this.state;if(this.status!==Gt.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===L.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||Jt.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===it?""+Ot(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({},Kt.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 zt({deferEvents:this.options.deferEvents}),this.sessionId=Jt.bookId()}get initialState(){return this._initialState?this._initialState:$t(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(xt(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Gt.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===Gt.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===Gt.Running)return this;Jt.register(this.sessionId,this),this.initialized=!0,this.status=Gt.Running;const e=void 0===t?this.initialState:$t(this,()=>{return!w(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(Nt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,rt)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{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=Gt.Stopped,Jt.free(this.sessionId),this}batch(t){if(this.status===Gt.NotStarted&&this.options.deferEvents);else if(this.status!==Gt.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=$t(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Et(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(et)&&!this.state.nextEvents.some(t=>0===t.indexOf(et)))throw e.data.data;return $t(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||at(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 G: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 K:this.cancel(t.sendId);break;case q:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===I.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0;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;_(d)&&(d=c?d.withContext(c):d,h={autoForward:a}),this.spawn(d,o,h)}else this.spawnActivity(e);break}case X:this.stopChild(t.activity.id);break;case Y: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(_(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 Kt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Ht),e);n.sync&&i.onTransition(t=>{this.send(nt,{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=Xt(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(xt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=Ot(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={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=C(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(Ot(e,t))}if(g(a))return this.spawnPromise(a,e);const c={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(Ot(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(xt(e),{origin:e}))}),s={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,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})})}attachDev(){const t=Ut();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)}qt(this)}}toJSON(){return{id:this.id}}[O](){return this}getSnapshot(){return this.status===Gt.NotStarted?this.initialState:this._state}}Kt.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),Kt.interpret=Wt;function Qt(t,e){const i=(t=>w(t)?Object.assign(Object.assign({},Ht),{name:t}):Object.assign(Object.assign(Object.assign({},Ht),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):Ct(t,i.name))(Tt[Tt.length-1])}function Wt(t,e){return new Kt(t,e)}function Yt(t,e,i){const n=Nt.from(t,t instanceof Nt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function Zt(t){return t}const te={raise:ut,send:lt,sendParent:ft,sendUpdate:pt,log:function(t=gt,e){return{type:Y,label:e,expr:t}},cancel:vt,start:yt,stop:mt,assign:bt,after:St,done:wt,respond:function(t,e){return lt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:_t,escalate:function(t,e){return ft((e,i,n)=>({type:it,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:L.Parent}))},choose:function(t){return{type:I.Choose,conds:t}},pure:function(t){return{type:I.Pure,get:t}}};export{I as ActionTypes,Kt as Interpreter,Gt as InterpreterStatus,Dt as Machine,L as SpecialTargets,Nt as State,At as StateNode,te as actions,bt as assign,Rt as createMachine,Zt as createSchema,xt as doneInvoke,_t as forwardTo,Wt as interpret,P as mapState,Yt as matchState,i as matchesState,lt as send,ft as sendParent,pt as sendUpdate,Qt as spawn};
|
package/es/Machine.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Model } from './model.types';
|
|
2
|
-
import { AnyEventObject, BaseActionObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
|
|
3
|
-
import {
|
|
2
|
+
import { AnyEventObject, BaseActionObject, DefaultContext, EventObject, MachineConfig, MachineOptions, InternalMachineOptions, StateMachine, StateSchema, Typestate } from './types';
|
|
3
|
+
import { TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from './typegenTypes';
|
|
4
4
|
/**
|
|
5
5
|
* @deprecated Use `createMachine(...)` instead.
|
|
6
6
|
*/
|
|
@@ -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
|
-
}, TTypesMeta extends TypegenConstraint = TypegenDisabled
|
|
12
|
+
}, 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, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject>>): StateMachine<TContext, any, TEvent, any, BaseActionObject, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject>>;
|
|
13
13
|
//# sourceMappingURL=Machine.d.ts.map
|
package/es/StateNode.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Event, StateValue, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema,
|
|
1
|
+
import { Event, StateValue, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
-
import {
|
|
3
|
+
import { TypegenDisabled } from './typegenTypes';
|
|
4
4
|
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
5
5
|
value: any;
|
|
6
6
|
context: TContext;
|
|
@@ -124,7 +124,11 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
124
124
|
/**
|
|
125
125
|
* The initial extended state
|
|
126
126
|
*/
|
|
127
|
-
_context?: Readonly<TContext> | (() => Readonly<TContext>)
|
|
127
|
+
_context?: Readonly<TContext> | (() => Readonly<TContext>), // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
128
|
+
_stateInfo?: {
|
|
129
|
+
parent: StateNode<any, any, any, any, any>;
|
|
130
|
+
key: string;
|
|
131
|
+
});
|
|
128
132
|
private _init;
|
|
129
133
|
/**
|
|
130
134
|
* Clones this state machine with custom options and context.
|
|
@@ -132,7 +136,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
|
|
|
132
136
|
* @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
|
|
133
137
|
* @param context Custom context (will override predefined context)
|
|
134
138
|
*/
|
|
135
|
-
withConfig(options:
|
|
139
|
+
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
|
|
136
140
|
/**
|
|
137
141
|
* Clones this state machine with custom context.
|
|
138
142
|
*
|
package/es/StateNode.js
CHANGED
|
@@ -3,7 +3,7 @@ import { STATE_DELIMITER } from './constants.js';
|
|
|
3
3
|
import { IS_PRODUCTION } from './environment.js';
|
|
4
4
|
import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, matchesState, path, evaluateGuard, mapContext, toSCXMLEvent, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine } from './utils.js';
|
|
5
5
|
import { SpecialTargets } from './types.js';
|
|
6
|
-
import { getAllStateNodes, getConfiguration, isInFinalState, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
|
|
6
|
+
import { getAllStateNodes, getConfiguration, isInFinalState, getTagsFromConfiguration, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
|
|
7
7
|
import { start as start$1, stop as stop$1, invoke, update, nullEvent, raise as raise$1, send as send$1 } from './actionTypes.js';
|
|
8
8
|
import { done, start, raise, stop, toActionObjects, resolveActions, doneInvoke, error, toActionObject, toActivityDefinition, after, send, cancel, initEvent } from './actions.js';
|
|
9
9
|
import { State, stateValuesEqual } from './State.js';
|
|
@@ -50,8 +50,8 @@ function () {
|
|
|
50
50
|
/**
|
|
51
51
|
* The initial extended state
|
|
52
52
|
*/
|
|
53
|
-
_context // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
54
|
-
) {
|
|
53
|
+
_context, // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
54
|
+
_stateInfo) {
|
|
55
55
|
var _this = this;
|
|
56
56
|
|
|
57
57
|
if (_context === void 0) {
|
|
@@ -81,8 +81,8 @@ function () {
|
|
|
81
81
|
this.idMap = {};
|
|
82
82
|
this.tags = [];
|
|
83
83
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
84
|
-
this.parent =
|
|
85
|
-
this.key = this.config.key ||
|
|
84
|
+
this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
|
|
85
|
+
this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
|
|
86
86
|
this.machine = this.parent ? this.parent.machine : this;
|
|
87
87
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
88
88
|
this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : STATE_DELIMITER);
|
|
@@ -100,9 +100,9 @@ function () {
|
|
|
100
100
|
this.states = this.config.states ? mapValues(this.config.states, function (stateConfig, key) {
|
|
101
101
|
var _a;
|
|
102
102
|
|
|
103
|
-
var stateNode = new StateNode(stateConfig, {
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
var stateNode = new StateNode(stateConfig, {}, undefined, {
|
|
104
|
+
parent: _this,
|
|
105
|
+
key: key
|
|
106
106
|
});
|
|
107
107
|
Object.assign(_this.idMap, __assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
|
|
108
108
|
return stateNode;
|
|
@@ -269,7 +269,8 @@ function () {
|
|
|
269
269
|
order: this.order || -1,
|
|
270
270
|
data: this.doneData,
|
|
271
271
|
invoke: this.invoke,
|
|
272
|
-
description: this.description
|
|
272
|
+
description: this.description,
|
|
273
|
+
tags: this.tags
|
|
273
274
|
};
|
|
274
275
|
},
|
|
275
276
|
enumerable: false,
|
|
@@ -443,7 +444,8 @@ function () {
|
|
|
443
444
|
return new State(__assign(__assign({}, state), {
|
|
444
445
|
value: this.resolve(state.value),
|
|
445
446
|
configuration: configuration,
|
|
446
|
-
done: isInFinalState(configuration, this)
|
|
447
|
+
done: isInFinalState(configuration, this),
|
|
448
|
+
tags: getTagsFromConfiguration(configuration)
|
|
447
449
|
}));
|
|
448
450
|
};
|
|
449
451
|
|
|
@@ -976,9 +978,7 @@ function () {
|
|
|
976
978
|
maybeNextState.changed = changed; // Preserve original history after raised events
|
|
977
979
|
|
|
978
980
|
maybeNextState.history = history;
|
|
979
|
-
maybeNextState.tags =
|
|
980
|
-
return sn.tags;
|
|
981
|
-
})));
|
|
981
|
+
maybeNextState.tags = getTagsFromConfiguration(maybeNextState.configuration);
|
|
982
982
|
return maybeNextState;
|
|
983
983
|
};
|
|
984
984
|
/**
|
package/es/actions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta,
|
|
1
|
+
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, StopAction, StopActionObject } from './types';
|
|
2
2
|
import * as actionTypes from './actionTypes';
|
|
3
3
|
import { State } from './State';
|
|
4
4
|
import { StateNode } from './StateNode';
|
|
@@ -133,6 +133,6 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
133
133
|
* @param options Options to pass into the send action creator.
|
|
134
134
|
*/
|
|
135
135
|
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
|
|
136
|
-
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<
|
|
136
|
+
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
137
137
|
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
138
138
|
//# sourceMappingURL=actions.d.ts.map
|
package/es/interpreter.js
CHANGED
package/es/model.types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, ExtractEvent, MachineConfig, Prop, PropertyAssigner, StateMachine } from './types';
|
|
2
|
-
import {
|
|
1
|
+
import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, ExtractEvent, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions } from './types';
|
|
2
|
+
import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
|
|
3
3
|
export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
|
|
4
4
|
initialContext: TContext;
|
|
5
5
|
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
@@ -7,7 +7,7 @@ export interface Model<TContext, TEvent extends EventObject, TAction extends Bas
|
|
|
7
7
|
actions: Prop<TModelCreators, 'actions'>;
|
|
8
8
|
reset: () => AssignAction<TContext, any>;
|
|
9
9
|
createMachine: {
|
|
10
|
-
<TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TTypesMeta>, implementations?:
|
|
10
|
+
<TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>): StateMachine<TContext, any, TEvent, {
|
|
11
11
|
value: any;
|
|
12
12
|
context: TContext;
|
|
13
13
|
}, TAction, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>;
|
package/es/stateUtils.d.ts
CHANGED
|
@@ -12,5 +12,6 @@ export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
|
|
|
12
12
|
export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
|
|
13
13
|
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any, any>>, stateNode: StateNode<TC, any, TE, any, any>): boolean;
|
|
14
14
|
export declare function getMeta(configuration?: StateNode[]): Record<string, any>;
|
|
15
|
+
export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;
|
|
15
16
|
export {};
|
|
16
17
|
//# sourceMappingURL=stateUtils.d.ts.map
|
package/es/stateUtils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __values, __spreadArray, __read } from './_virtual/_tslib.js';
|
|
2
|
-
import {
|
|
2
|
+
import { flatten, keys } from './utils.js';
|
|
3
3
|
|
|
4
4
|
var isLeafNode = function (stateNode) {
|
|
5
5
|
return stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
@@ -252,5 +252,10 @@ function getMeta(configuration) {
|
|
|
252
252
|
return acc;
|
|
253
253
|
}, {});
|
|
254
254
|
}
|
|
255
|
+
function getTagsFromConfiguration(configuration) {
|
|
256
|
+
return new Set(flatten(configuration.map(function (sn) {
|
|
257
|
+
return sn.tags;
|
|
258
|
+
})));
|
|
259
|
+
}
|
|
255
260
|
|
|
256
|
-
export { getAdjList, getAllStateNodes, getChildren, getConfiguration, getMeta, getValue, has, isInFinalState, isLeafNode, nextEvents };
|
|
261
|
+
export { getAdjList, getAllStateNodes, getChildren, getConfiguration, getMeta, getTagsFromConfiguration, getValue, has, isInFinalState, isLeafNode, nextEvents };
|
package/es/typegenTypes.d.ts
CHANGED
|
@@ -38,10 +38,24 @@ export declare type MarkAllImplementationsAsProvided<TResolvedTypesMeta> = TReso
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
declare type MergeWithInternalEvents<TIndexedEvents, TInternalEvents> = TIndexedEvents & Pick<TInternalEvents, Exclude<keyof TInternalEvents, keyof TIndexedEvents>>;
|
|
41
|
+
declare type AllowAllEvents = {
|
|
42
|
+
eventsCausingActions: Record<string, string>;
|
|
43
|
+
eventsCausingDelays: Record<string, string>;
|
|
44
|
+
eventsCausingGuards: Record<string, string>;
|
|
45
|
+
eventsCausingServices: Record<string, string>;
|
|
46
|
+
};
|
|
41
47
|
export declare type ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TAction extends BaseActionObject> = TTypesMeta extends TypegenEnabled ? TTypesMeta & {
|
|
42
48
|
indexedActions: IndexByType<TAction>;
|
|
43
49
|
indexedEvents: MergeWithInternalEvents<IndexByType<TEvent>, Prop<TTypesMeta, 'internalEvents'>>;
|
|
44
|
-
} : TypegenDisabled
|
|
50
|
+
} : MarkAllImplementationsAsProvided<TypegenDisabled> & AllowAllEvents & {
|
|
51
|
+
indexedActions: IndexByType<TAction>;
|
|
52
|
+
indexedEvents: Record<string, TEvent> & {
|
|
53
|
+
__XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__: {
|
|
54
|
+
data: any;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
invokeSrcNameMap: Record<string, '__XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__'>;
|
|
58
|
+
};
|
|
45
59
|
export declare type TypegenMachineOptionsActions<TContext, TResolvedTypesMeta, TEventsCausingActions = Prop<TResolvedTypesMeta, 'eventsCausingActions'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>, TIndexedActions = Prop<TResolvedTypesMeta, 'indexedActions'>> = {
|
|
46
60
|
[K in keyof TEventsCausingActions]?: ActionObject<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>> | ActionFunction<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>, Cast<Prop<TIndexedActions, K>, BaseActionObject>>;
|
|
47
61
|
};
|
package/es/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Clock, Interpreter } from './interpreter';
|
|
|
2
2
|
import { Model } from './model.types';
|
|
3
3
|
import { State } from './State';
|
|
4
4
|
import { StateNode } from './StateNode';
|
|
5
|
-
import { MarkAllImplementationsAsProvided,
|
|
5
|
+
import { MarkAllImplementationsAsProvided, TypegenDisabled, ResolveTypegenMeta, TypegenConstraint } from './typegenTypes';
|
|
6
6
|
export declare type AnyFunction = (...args: any[]) => any;
|
|
7
7
|
declare type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
|
|
8
8
|
export declare type IsNever<T> = [T] extends [never] ? true : false;
|
|
@@ -69,8 +69,10 @@ export interface AssignMeta<TContext, TEvent extends EventObject> {
|
|
|
69
69
|
action: AssignAction<TContext, TEvent>;
|
|
70
70
|
_event: SCXML.Event<TEvent>;
|
|
71
71
|
}
|
|
72
|
-
export declare type ActionFunction<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> =
|
|
73
|
-
|
|
72
|
+
export declare type ActionFunction<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> = {
|
|
73
|
+
bivarianceHack(context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent, TAction>): void;
|
|
74
|
+
}['bivarianceHack'];
|
|
75
|
+
export interface ChooseCondition<TContext, TEvent extends EventObject> {
|
|
74
76
|
cond?: Condition<TContext, TEvent>;
|
|
75
77
|
actions: Actions<TContext, TEvent>;
|
|
76
78
|
}
|
|
@@ -174,6 +176,7 @@ export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject,
|
|
|
174
176
|
export interface InvokeMeta {
|
|
175
177
|
data: any;
|
|
176
178
|
src: InvokeSourceDefinition;
|
|
179
|
+
meta?: MetaObject;
|
|
177
180
|
}
|
|
178
181
|
/**
|
|
179
182
|
* Returns either a Promises or a callback handler (for streams of events) given the
|
|
@@ -213,6 +216,7 @@ export interface InvokeDefinition<TContext, TEvent extends EventObject> extends
|
|
|
213
216
|
* Data should be mapped to match the child machine's context shape.
|
|
214
217
|
*/
|
|
215
218
|
data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
|
|
219
|
+
meta?: MetaObject;
|
|
216
220
|
}
|
|
217
221
|
export interface Delay {
|
|
218
222
|
id: string;
|
|
@@ -295,6 +299,10 @@ export interface InvokeConfig<TContext, TEvent extends EventObject> {
|
|
|
295
299
|
* The transition to take upon the invoked child machine sending an error event.
|
|
296
300
|
*/
|
|
297
301
|
onError?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
|
|
302
|
+
/**
|
|
303
|
+
* Meta data related to this invocation
|
|
304
|
+
*/
|
|
305
|
+
meta?: MetaObject;
|
|
298
306
|
}
|
|
299
307
|
export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> {
|
|
300
308
|
/**
|
|
@@ -450,6 +458,7 @@ export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema,
|
|
|
450
458
|
data?: FinalStateNodeConfig<TContext, TEvent>['data'];
|
|
451
459
|
invoke: Array<InvokeDefinition<TContext, TEvent>>;
|
|
452
460
|
description?: string;
|
|
461
|
+
tags: string[];
|
|
453
462
|
}
|
|
454
463
|
export declare type AnyStateNodeDefinition = StateNodeDefinition<any, any, any>;
|
|
455
464
|
export interface AtomicStateNodeConfig<TContext, TEvent extends EventObject> extends StateNodeConfig<TContext, StateSchema, TEvent> {
|
|
@@ -479,24 +488,43 @@ export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAct
|
|
|
479
488
|
export declare type DelayFunctionMap<TContext, TEvent extends EventObject> = Record<string, DelayConfig<TContext, TEvent>>;
|
|
480
489
|
export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent>;
|
|
481
490
|
export declare type DelayConfig<TContext, TEvent extends EventObject> = number | DelayExpr<TContext, TEvent>;
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
491
|
+
declare type MachineOptionsActions<TContext, TResolvedTypesMeta, TEventsCausingActions = Prop<TResolvedTypesMeta, 'eventsCausingActions'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>, TIndexedActions = Prop<TResolvedTypesMeta, 'indexedActions'>> = {
|
|
492
|
+
[K in keyof TEventsCausingActions]?: ActionObject<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>> | ActionFunction<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>, Cast<Prop<TIndexedActions, K>, BaseActionObject>>;
|
|
493
|
+
};
|
|
494
|
+
declare type MachineOptionsDelays<TContext, TResolvedTypesMeta, TEventsCausingDelays = Prop<TResolvedTypesMeta, 'eventsCausingDelays'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>> = {
|
|
495
|
+
[K in keyof TEventsCausingDelays]?: DelayConfig<TContext, Cast<Prop<TIndexedEvents, TEventsCausingDelays[K]>, EventObject>>;
|
|
496
|
+
};
|
|
497
|
+
declare type MachineOptionsGuards<TContext, TResolvedTypesMeta, TEventsCausingGuards = Prop<TResolvedTypesMeta, 'eventsCausingGuards'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>> = {
|
|
498
|
+
[K in keyof TEventsCausingGuards]?: ConditionPredicate<TContext, Cast<Prop<TIndexedEvents, TEventsCausingGuards[K]>, EventObject>>;
|
|
499
|
+
};
|
|
500
|
+
declare type MachineOptionsServices<TContext, TResolvedTypesMeta, TEventsCausingServices = Prop<TResolvedTypesMeta, 'eventsCausingServices'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>, TInvokeSrcNameMap = Prop<TResolvedTypesMeta, 'invokeSrcNameMap'>> = {
|
|
501
|
+
[K in keyof TEventsCausingServices]?: StateMachine<any, any, any> | InvokeCreator<TContext, Cast<Prop<TIndexedEvents, TEventsCausingServices[K]>, EventObject>, Prop<Prop<TIndexedEvents, Prop<TInvokeSrcNameMap, K>>, 'data'>>;
|
|
502
|
+
};
|
|
503
|
+
declare type MakeKeysRequired<T extends string> = {
|
|
504
|
+
[K in T]: unknown;
|
|
505
|
+
};
|
|
506
|
+
declare type MaybeMakeMissingImplementationsRequired<TImplementationType, TMissingImplementationsForType, TRequireMissingImplementations> = TRequireMissingImplementations extends true ? IsNever<TMissingImplementationsForType> extends true ? {} : {
|
|
507
|
+
[K in Cast<TImplementationType, string>]: MakeKeysRequired<Cast<TMissingImplementationsForType, string>>;
|
|
508
|
+
} : {};
|
|
509
|
+
declare type GenerateActionsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'actions', Prop<TMissingImplementations, 'actions'>, TRequireMissingImplementations> & {
|
|
510
|
+
actions?: MachineOptionsActions<TContext, TResolvedTypesMeta>;
|
|
511
|
+
};
|
|
512
|
+
declare type GenerateDelaysConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'delays', Prop<TMissingImplementations, 'delays'>, TRequireMissingImplementations> & {
|
|
513
|
+
delays?: MachineOptionsDelays<TContext, TResolvedTypesMeta>;
|
|
514
|
+
};
|
|
515
|
+
declare type GenerateGuardsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'guards', Prop<TMissingImplementations, 'guards'>, TRequireMissingImplementations> & {
|
|
516
|
+
guards?: MachineOptionsGuards<TContext, TResolvedTypesMeta>;
|
|
517
|
+
};
|
|
518
|
+
declare type GenerateServicesConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'services', Prop<TMissingImplementations, 'services'>, TRequireMissingImplementations> & {
|
|
519
|
+
services?: MachineOptionsServices<TContext, TResolvedTypesMeta>;
|
|
520
|
+
};
|
|
521
|
+
export declare type InternalMachineOptions<TContext, TEvent extends EventObject, TResolvedTypesMeta, TRequireMissingImplementations extends boolean = false, TMissingImplementations = Prop<TResolvedTypesMeta, 'missingImplementations'>> = GenerateActionsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateDelaysConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateGuardsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateServicesConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & {
|
|
485
522
|
/**
|
|
486
523
|
* @deprecated Use `services` instead.
|
|
487
524
|
*/
|
|
488
525
|
activities?: Record<string, ActivityConfig<TContext, TEvent>>;
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* @private
|
|
493
|
-
*/
|
|
494
|
-
_parent?: StateNode<TContext, any, TEvent, any, any>;
|
|
495
|
-
/**
|
|
496
|
-
* @private
|
|
497
|
-
*/
|
|
498
|
-
_key?: string;
|
|
499
|
-
}
|
|
526
|
+
};
|
|
527
|
+
export declare type MachineOptions<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>;
|
|
500
528
|
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TTypesMeta = TypegenDisabled> extends StateNodeConfig<TContext, TStateSchema, TEvent, TAction> {
|
|
501
529
|
/**
|
|
502
530
|
* The initial context (extended state)
|
|
@@ -545,8 +573,14 @@ export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent
|
|
|
545
573
|
}, TAction extends BaseActionObject = BaseActionObject, TResolvedTypesMeta = TypegenDisabled> extends StateNode<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta> {
|
|
546
574
|
id: string;
|
|
547
575
|
states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>['states'];
|
|
548
|
-
withConfig(options:
|
|
576
|
+
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, MarkAllImplementationsAsProvided<TResolvedTypesMeta>>;
|
|
549
577
|
withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, TResolvedTypesMeta>;
|
|
578
|
+
__TContext: TContext;
|
|
579
|
+
__TStateSchema: TStateSchema;
|
|
580
|
+
__TEvent: TEvent;
|
|
581
|
+
__TTypestate: TTypestate;
|
|
582
|
+
__TAction: TAction;
|
|
583
|
+
__TResolvedTypesMeta: TResolvedTypesMeta;
|
|
550
584
|
}
|
|
551
585
|
export declare type StateFrom<T extends StateMachine<any, any, any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any, any, any>)> = T extends StateMachine<any, any, any, any, any, any> ? ReturnType<T['transition']> : T extends (...args: any[]) => StateMachine<any, any, any, any, any, any> ? ReturnType<ReturnType<T>['transition']> : never;
|
|
552
586
|
export interface ActionMap<TContext, TEvent extends EventObject> {
|
|
@@ -716,7 +750,7 @@ export interface PureAction<TContext, TEvent extends EventObject> extends Action
|
|
|
716
750
|
}
|
|
717
751
|
export interface ChooseAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
|
|
718
752
|
type: ActionTypes.Choose;
|
|
719
|
-
conds: Array<
|
|
753
|
+
conds: Array<ChooseCondition<TContext, TEvent>>;
|
|
720
754
|
}
|
|
721
755
|
export interface TransitionDefinition<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
|
|
722
756
|
target: Array<StateNode<TContext, any, TEvent>> | undefined;
|
|
@@ -962,8 +996,9 @@ export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventOb
|
|
|
962
996
|
};
|
|
963
997
|
export declare type ActorRefFrom<T> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, any, infer TEvent, infer TTypestate, any, infer TResolvedTypesMeta> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate, TResolvedTypesMeta> : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : T extends (...args: any[]) => Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : never;
|
|
964
998
|
export declare type AnyInterpreter = Interpreter<any, any, any, any, any>;
|
|
965
|
-
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta> : T extends (...args: any[]) => StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta> : never;
|
|
966
|
-
export declare type MachineOptionsFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>), TRequireMissingImplementations extends boolean = false> = T
|
|
999
|
+
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any, any, any>)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta> : T extends (...args: any[]) => StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta> : never;
|
|
1000
|
+
export declare type MachineOptionsFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, any, infer TEvent, any, any, infer TResolvedTypesMeta> ? InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
1001
|
+
export declare type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
967
1002
|
export interface ActorContext<TEvent extends EventObject, TEmitted> {
|
|
968
1003
|
parent?: ActorRef<any, any>;
|
|
969
1004
|
self: ActorRef<TEvent, TEmitted>;
|
|
@@ -976,7 +1011,10 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
|
|
|
976
1011
|
start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
|
|
977
1012
|
}
|
|
978
1013
|
export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
|
|
979
|
-
|
|
1014
|
+
declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : never : never;
|
|
1015
|
+
export declare type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : Extract<TEvent, {
|
|
1016
|
+
type: K;
|
|
1017
|
+
}>;
|
|
980
1018
|
export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___> ? TContext : never : never;
|
|
981
1019
|
export {};
|
|
982
1020
|
//# sourceMappingURL=types.d.ts.map
|