@clicktap/state 0.14.0 → 0.14.1
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/index.js +1 -1
- package/index.mjs +4 -6
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("react/jsx-runtime"),R=require("react");function Sn(e,t){for(var n=0;n<t.length;n++){const s=t[n];if(typeof s!="string"&&!Array.isArray(s)){for(const r in s)if(r!=="default"&&!(r in e)){const i=Object.getOwnPropertyDescriptor(s,r);i&&Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:()=>s[r]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function In(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function An(){const e=In();if(e.__xstate__)return e.__xstate__}const xn=e=>{if(typeof window>"u")return;const t=An();t&&t.register(e)};class gt{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const n={value:t,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const Bt=".",wn="",jt="",bn="#",Nn="*",$t="xstate.init",Cn="xstate.error",de="xstate.stop";function On(e,t){return{type:`xstate.after.${e}.${t}`}}function $e(e,t){return{type:`xstate.done.state.${e}`,output:t}}function kn(e,t){return{type:`xstate.done.actor.${e}`,output:t}}function Vt(e,t){return{type:`xstate.error.actor.${e}`,error:t}}function Ht(e){return{type:$t,input:e}}function j(e){setTimeout(()=>{throw e})}const Dn=(()=>typeof Symbol=="function"&&Symbol.observable||"@@observable")();function Et(e,t){return`${e.sessionId}.${t}`}let Rn=0;function qn(e,t){const n=new Map,s=new Map,r=new WeakMap,i=new Set,o={},{clock:a,logger:c}=t,u={schedule:(f,m,y,v,I=Math.random().toString(36).slice(2))=>{const x={source:f,target:m,event:y,delay:v,id:I,startedAt:Date.now()},q=Et(f,I);d._snapshot._scheduledEvents[q]=x;const k=a.setTimeout(()=>{delete o[q],delete d._snapshot._scheduledEvents[q],d._relay(f,m,y)},v);o[q]=k},cancel:(f,m)=>{const y=Et(f,m),v=o[y];delete o[y],delete d._snapshot._scheduledEvents[y],a.clearTimeout(v)},cancelAll:f=>{for(const m in d._snapshot._scheduledEvents){const y=d._snapshot._scheduledEvents[m];y.source===f&&u.cancel(f,y.id)}}},h=f=>{if(!i.size)return;const m={...f,rootId:e.sessionId};i.forEach(y=>{var v;return(v=y.next)==null?void 0:v.call(y,m)})},d={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${Rn++}`,_register:(f,m)=>(n.set(f,m),f),_unregister:f=>{n.delete(f.sessionId);const m=r.get(f);m!==void 0&&(s.delete(m),r.delete(f))},get:f=>s.get(f),_set:(f,m)=>{const y=s.get(f);if(y&&y!==m)throw new Error(`Actor with system ID '${f}' already exists.`);s.set(f,m),r.set(m,f)},inspect:f=>{i.add(f)},_sendInspectionEvent:h,_relay:(f,m,y)=>{d._sendInspectionEvent({type:"@xstate.event",sourceRef:f,actorRef:m,event:y}),m._send(y)},scheduler:u,getSnapshot:()=>({_scheduledEvents:{...d._snapshot._scheduledEvents}}),start:()=>{const f=d._snapshot._scheduledEvents;d._snapshot._scheduledEvents={};for(const m in f){const{source:y,target:v,event:I,delay:x,id:q}=f[m];u.schedule(y,v,I,x,q)}},_clock:a,_logger:c};return d}function zt(e,t){const n=vt(e),s=vt(t);return typeof s=="string"?typeof n=="string"?s===n:!1:typeof n=="string"?n in s:Object.keys(n).every(r=>r in s?zt(n[r],s[r]):!1)}function et(e){if(Jt(e))return e;let t=[],n="";for(let s=0;s<e.length;s++){switch(e.charCodeAt(s)){case 92:n+=e[s+1],s++;continue;case 46:t.push(n),n="";continue}n+=e[s]}return t.push(n),t}function vt(e){if(ls(e))return e.value;if(typeof e!="string")return e;const t=et(e);return Mn(t)}function Mn(e){if(e.length===1)return e[0];const t={};let n=t;for(let s=0;s<e.length-1;s++)if(s===e.length-2)n[e[s]]=e[s+1];else{const r=n;n={},r[e[s]]=n}return t}function Tt(e,t){const n={},s=Object.keys(e);for(let r=0;r<s.length;r++){const i=s[r];n[i]=t(e[i],i,e,r)}return n}function Gt(e){return Jt(e)?e:[e]}function $(e){return e===void 0?[]:Gt(e)}function Ve(e,t,n,s){return typeof e=="function"?e({context:t,event:n,self:s}):e}function Jt(e){return Array.isArray(e)}function Ln(e){return e.type.startsWith("xstate.error.actor")}function Z(e){return Gt(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function Yt(e){if(!(e===void 0||e===wn))return $(e)}function _t(e,t,n){var i,o,a;const s=typeof e=="object",r=s?e:void 0;return{next:(i=s?e.next:e)==null?void 0:i.bind(r),error:(o=s?e.error:t)==null?void 0:o.bind(r),complete:(a=s?e.complete:n)==null?void 0:a.bind(r)}}function St(e,t){return`${t}.${e}`}function tt(e,t){const n=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return e.implementations.actors[t];const[,s,r]=n,o=e.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}const nt=1;let D=function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e}({});const Pn={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class Un{constructor(t,n){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new gt(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=D.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const s={...Pn,...n},{clock:r,logger:i,parent:o,syncSnapshot:a,id:c,systemId:u,inspect:h}=s;this.system=o?o.system:qn(this,{clock:r,logger:i}),h&&!o&&this.system.inspect(_t(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=(n==null?void 0:n.logger)??this.system._logger,this.clock=(n==null?void 0:n.clock)??this.system._clock,this._parent=o,this._syncSnapshot=a,this.options=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:d=>{this._deferred.push(d)},system:this.system,stopChild:d=>{if(d._parent!==this)throw new Error(`Cannot stop child actor ${d.id} of ${this.id} because it is not a child`);d._stop()},emit:d=>{const f=this.eventListeners.get(d.type),m=this.eventListeners.get("*");if(!f&&!m)return;const y=new Set([...f?f.values():[],...m?m.values():[]]);for(const v of Array.from(y))v(d)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),u&&(this._systemId=u,this.system._set(u,this)),this._initState((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),u&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){var n;try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,(n=this.options)==null?void 0:n.input)}catch(s){this._snapshot={status:"error",output:void 0,error:s}}}update(t,n){var r,i;this._snapshot=t;let s;for(;s=this._deferred.shift();)try{s()}catch(o){this._deferred.length=0,this._snapshot={...t,status:"error",error:o}}switch(this._snapshot.status){case"active":for(const o of this.observers)try{(r=o.next)==null||r.call(o,t)}catch(a){j(a)}break;case"done":for(const o of this.observers)try{(i=o.next)==null||i.call(o,t)}catch(a){j(a)}this._stopProcedure(),this._complete(),this._doneEvent=kn(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:n,snapshot:t})}subscribe(t,n,s){var i;const r=_t(t,n,s);if(this._processingStatus!==D.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(i=r.complete)==null||i.call(r)}catch(o){j(o)}break;case"error":{const o=this._snapshot.error;if(!r.error)j(o);else try{r.error(o)}catch(a){j(a)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(t,n){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const r=n.bind(void 0);return s.add(r),{unsubscribe:()=>{s.delete(r)}}}start(){if(this._processingStatus===D.Running)return this;this._syncSnapshot&&this.subscribe({next:s=>{s.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:s})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=D.Running;const t=Ht(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(s){return this._snapshot={...this._snapshot,status:"error",error:s},this._error(s),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let n,s;try{n=this.logic.transition(this._snapshot,t,this._actorScope)}catch(r){s={err:r}}if(s){const{err:r}=s;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(n,t),t.type===de&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===D.Stopped?this:(this.mailbox.clear(),this._processingStatus===D.NotStarted?(this._processingStatus=D.Stopped,this):(this.mailbox.enqueue({type:de}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var t;for(const n of this.observers)try{(t=n.complete)==null||t.call(n)}catch(s){j(s)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||j(t);return}let n=!1;for(const s of this.observers){const r=s.error;n||(n=!r);try{r==null||r(t)}catch(i){j(i)}}this.observers.clear(),n&&j(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Vt(this.id,t))}_stopProcedure(){return this._processingStatus!==D.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new gt(this._process.bind(this)),this._processingStatus=D.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==D.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:xn)(this)}toJSON(){return{xstate$$type:nt,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[Dn](){return this}getSnapshot(){return this._snapshot}}function F(e,...[t]){return new Un(e,t)}function Fn(e,t,n,s,{sendId:r}){const i=typeof r=="function"?r(n,s):r;return[t,i]}function Bn(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t)})}function jn(e){function t(n,s){}return t.type="xstate.cancel",t.sendId=e,t.resolve=Fn,t.execute=Bn,t}function $n(e,t,n,s,{id:r,systemId:i,src:o,input:a,syncSnapshot:c}){const u=typeof o=="string"?tt(t.machine,o):o,h=typeof r=="function"?r(n):r;let d;return u&&(d=F(u,{id:h,src:o,parent:e.self,syncSnapshot:c,systemId:i,input:typeof a=="function"?a({context:t.context,event:n.event,self:e.self}):a})),[Q(t,{children:{...t.children,[h]:d}}),{id:r,actorRef:d}]}function Vn(e,{id:t,actorRef:n}){n&&e.defer(()=>{n._processingStatus!==D.Stopped&&n.start()})}function Hn(...[e,{id:t,systemId:n,input:s,syncSnapshot:r=!1}={}]){function i(o,a){}return i.type="snapshot.spawnChild",i.id=t,i.systemId=n,i.src=e,i.input=s,i.syncSnapshot=r,i.resolve=$n,i.execute=Vn,i}function zn(e,t,n,s,{actorRef:r}){const i=typeof r=="function"?r(n,s):r,o=typeof i=="string"?t.children[i]:i;let a=t.children;return o&&(a={...a},delete a[o.id]),[Q(t,{children:a}),o]}function Gn(e,t){if(t){if(e.system._unregister(t),t._processingStatus!==D.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function Qt(e){function t(n,s){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=zn,t.execute=Gn,t}function st(e,t,n,s){const{machine:r}=s,i=typeof e=="function",o=i?e:r.implementations.guards[typeof e=="string"?e:e.type];if(!i&&!o)throw new Error(`Guard '${typeof e=="string"?e:e.type}' is not implemented.'.`);if(typeof o!="function")return st(o,t,n,s);const a={context:t,event:n},c=i||typeof e=="string"?void 0:"params"in e?typeof e.params=="function"?e.params({context:t,event:n}):e.params:void 0;return"check"in o?o.check(s,a,o):o(a,c)}const rt=e=>e.type==="atomic"||e.type==="final";function ne(e){return Object.values(e.states).filter(t=>t.type!=="history")}function he(e,t){const n=[];if(t===e)return n;let s=e.parent;for(;s&&s!==t;)n.push(s),s=s.parent;return n}function Ie(e){const t=new Set(e),n=Wt(t);for(const s of t)if(s.type==="compound"&&(!n.get(s)||!n.get(s).length))It(s).forEach(r=>t.add(r));else if(s.type==="parallel"){for(const r of ne(s))if(r.type!=="history"&&!t.has(r)){const i=It(r);for(const o of i)t.add(o)}}for(const s of t){let r=s.parent;for(;r;)t.add(r),r=r.parent}return t}function Xt(e,t){const n=t.get(e);if(!n)return{};if(e.type==="compound"){const r=n[0];if(r){if(rt(r))return r.key}else return{}}const s={};for(const r of n)s[r.key]=Xt(r,t);return s}function Wt(e){const t=new Map;for(const n of e)t.has(n)||t.set(n,[]),n.parent&&(t.has(n.parent)||t.set(n.parent,[]),t.get(n.parent).push(n));return t}function Kt(e,t){const n=Ie(t);return Xt(e,Wt(n))}function it(e,t){return t.type==="compound"?ne(t).some(n=>n.type==="final"&&e.has(n)):t.type==="parallel"?ne(t).every(n=>it(e,n)):t.type==="final"}const Ne=e=>e[0]===bn;function Jn(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(s=>{if(s===Nn)return!0;if(!s.endsWith(".*"))return!1;const r=s.split("."),i=t.split(".");for(let o=0;o<r.length;o++){const a=r[o],c=i[o];if(a==="*")return o===r.length-1;if(a!==c)return!1}return!0}).sort((s,r)=>r.length-s.length).flatMap(s=>e.transitions.get(s))}function Yn(e){const t=e.config.after;if(!t)return[];const n=(r,i)=>{const o=On(r,e.id),a=o.type;return e.entry.push(Ts(o,{id:a,delay:r})),e.exit.push(jn(a)),a};return Object.keys(t).flatMap((r,i)=>{const o=t[r],a=typeof o=="string"?{target:o}:o,c=Number.isNaN(+r)?r:+r,u=n(c);return $(a).map(h=>({...h,event:u,delay:c}))}).map(r=>{const{delay:i}=r;return{...J(e,r.event,r),delay:i}})}function J(e,t,n){const s=Yt(n.target),r=n.reenter??!1,i=Wn(e,s),o={...n,actions:$(n.actions),guard:n.guard,target:i,source:e,reenter:r,eventType:t,toJSON:()=>({...o,source:`#${e.id}`,target:i?i.map(a=>`#${a.id}`):void 0})};return o}function Qn(e){const t=new Map;if(e.config.on)for(const n of Object.keys(e.config.on)){if(n===jt)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=e.config.on[n];t.set(n,Z(s).map(r=>J(e,n,r)))}if(e.config.onDone){const n=`xstate.done.state.${e.id}`;t.set(n,Z(e.config.onDone).map(s=>J(e,n,s)))}for(const n of e.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;t.set(s,Z(n.onDone).map(r=>J(e,s,r)))}if(n.onError){const s=`xstate.error.actor.${n.id}`;t.set(s,Z(n.onError).map(r=>J(e,s,r)))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;t.set(s,Z(n.onSnapshot).map(r=>J(e,s,r)))}}for(const n of e.after){let s=t.get(n.eventType);s||(s=[],t.set(n.eventType,s)),s.push(n)}return t}function Xn(e,t){const n=typeof t=="string"?e.states[t]:t?e.states[t.target]:void 0;if(!n&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${e.id}`);const s={source:e,actions:!t||typeof t=="string"?[]:$(t.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return s}function Wn(e,t){if(t!==void 0)return t.map(n=>{if(typeof n!="string")return n;if(Ne(n))return e.machine.getStateNodeById(n);const s=n[0]===Bt;if(s&&!e.parent)return Ae(e,n.slice(1));const r=s?e.key+n:n;if(e.parent)try{return Ae(e.parent,r)}catch(i){throw new Error(`Invalid transition definition for state node '${e.id}':
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("react/jsx-runtime"),R=require("react");function Sn(e,t){for(var n=0;n<t.length;n++){const s=t[n];if(typeof s!="string"&&!Array.isArray(s)){for(const r in s)if(r!=="default"&&!(r in e)){const i=Object.getOwnPropertyDescriptor(s,r);i&&Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:()=>s[r]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function In(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function An(){const e=In();if(e.__xstate__)return e.__xstate__}const xn=e=>{if(typeof window>"u")return;const t=An();t&&t.register(e)};class gt{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const n={value:t,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const Bt=".",wn="",jt="",bn="#",Nn="*",$t="xstate.init",Cn="xstate.error",de="xstate.stop";function On(e,t){return{type:`xstate.after.${e}.${t}`}}function $e(e,t){return{type:`xstate.done.state.${e}`,output:t}}function kn(e,t){return{type:`xstate.done.actor.${e}`,output:t}}function Vt(e,t){return{type:`xstate.error.actor.${e}`,error:t}}function Ht(e){return{type:$t,input:e}}function j(e){setTimeout(()=>{throw e})}const Dn=(()=>typeof Symbol=="function"&&Symbol.observable||"@@observable")();function Et(e,t){return`${e.sessionId}.${t}`}let Rn=0;function qn(e,t){const n=new Map,s=new Map,r=new WeakMap,i=new Set,o={},{clock:a,logger:c}=t,u={schedule:(f,m,y,v,I=Math.random().toString(36).slice(2))=>{const x={source:f,target:m,event:y,delay:v,id:I,startedAt:Date.now()},q=Et(f,I);d._snapshot._scheduledEvents[q]=x;const k=a.setTimeout(()=>{delete o[q],delete d._snapshot._scheduledEvents[q],d._relay(f,m,y)},v);o[q]=k},cancel:(f,m)=>{const y=Et(f,m),v=o[y];delete o[y],delete d._snapshot._scheduledEvents[y],a.clearTimeout(v)},cancelAll:f=>{for(const m in d._snapshot._scheduledEvents){const y=d._snapshot._scheduledEvents[m];y.source===f&&u.cancel(f,y.id)}}},h=f=>{if(!i.size)return;const m={...f,rootId:e.sessionId};i.forEach(y=>{var v;return(v=y.next)==null?void 0:v.call(y,m)})},d={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${Rn++}`,_register:(f,m)=>(n.set(f,m),f),_unregister:f=>{n.delete(f.sessionId);const m=r.get(f);m!==void 0&&(s.delete(m),r.delete(f))},get:f=>s.get(f),_set:(f,m)=>{const y=s.get(f);if(y&&y!==m)throw new Error(`Actor with system ID '${f}' already exists.`);s.set(f,m),r.set(m,f)},inspect:f=>{i.add(f)},_sendInspectionEvent:h,_relay:(f,m,y)=>{d._sendInspectionEvent({type:"@xstate.event",sourceRef:f,actorRef:m,event:y}),m._send(y)},scheduler:u,getSnapshot:()=>({_scheduledEvents:{...d._snapshot._scheduledEvents}}),start:()=>{const f=d._snapshot._scheduledEvents;d._snapshot._scheduledEvents={};for(const m in f){const{source:y,target:v,event:I,delay:x,id:q}=f[m];u.schedule(y,v,I,x,q)}},_clock:a,_logger:c};return d}function zt(e,t){const n=vt(e),s=vt(t);return typeof s=="string"?typeof n=="string"?s===n:!1:typeof n=="string"?n in s:Object.keys(n).every(r=>r in s?zt(n[r],s[r]):!1)}function et(e){if(Jt(e))return e;let t=[],n="";for(let s=0;s<e.length;s++){switch(e.charCodeAt(s)){case 92:n+=e[s+1],s++;continue;case 46:t.push(n),n="";continue}n+=e[s]}return t.push(n),t}function vt(e){if(ls(e))return e.value;if(typeof e!="string")return e;const t=et(e);return Mn(t)}function Mn(e){if(e.length===1)return e[0];const t={};let n=t;for(let s=0;s<e.length-1;s++)if(s===e.length-2)n[e[s]]=e[s+1];else{const r=n;n={},r[e[s]]=n}return t}function Tt(e,t){const n={},s=Object.keys(e);for(let r=0;r<s.length;r++){const i=s[r];n[i]=t(e[i],i,e,r)}return n}function Gt(e){return Jt(e)?e:[e]}function $(e){return e===void 0?[]:Gt(e)}function Ve(e,t,n,s){return typeof e=="function"?e({context:t,event:n,self:s}):e}function Jt(e){return Array.isArray(e)}function Ln(e){return e.type.startsWith("xstate.error.actor")}function Z(e){return Gt(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function Yt(e){if(!(e===void 0||e===wn))return $(e)}function _t(e,t,n){var i,o,a;const s=typeof e=="object",r=s?e:void 0;return{next:(i=s?e.next:e)==null?void 0:i.bind(r),error:(o=s?e.error:t)==null?void 0:o.bind(r),complete:(a=s?e.complete:n)==null?void 0:a.bind(r)}}function St(e,t){return`${t}.${e}`}function tt(e,t){const n=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return e.implementations.actors[t];const[,s,r]=n,o=e.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}const nt=1;let D=function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e}({});const Pn={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class Un{constructor(t,n){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new gt(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=D.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const s={...Pn,...n},{clock:r,logger:i,parent:o,syncSnapshot:a,id:c,systemId:u,inspect:h}=s;this.system=o?o.system:qn(this,{clock:r,logger:i}),h&&!o&&this.system.inspect(_t(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=(n==null?void 0:n.logger)??this.system._logger,this.clock=(n==null?void 0:n.clock)??this.system._clock,this._parent=o,this._syncSnapshot=a,this.options=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:d=>{this._deferred.push(d)},system:this.system,stopChild:d=>{if(d._parent!==this)throw new Error(`Cannot stop child actor ${d.id} of ${this.id} because it is not a child`);d._stop()},emit:d=>{const f=this.eventListeners.get(d.type);if(f)for(const m of Array.from(f))m(d)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),u&&(this._systemId=u,this.system._set(u,this)),this._initState((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),u&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){var n;try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,(n=this.options)==null?void 0:n.input)}catch(s){this._snapshot={status:"error",output:void 0,error:s}}}update(t,n){var r,i;this._snapshot=t;let s;for(;s=this._deferred.shift();)try{s()}catch(o){this._deferred.length=0,this._snapshot={...t,status:"error",error:o}}switch(this._snapshot.status){case"active":for(const o of this.observers)try{(r=o.next)==null||r.call(o,t)}catch(a){j(a)}break;case"done":for(const o of this.observers)try{(i=o.next)==null||i.call(o,t)}catch(a){j(a)}this._stopProcedure(),this._complete(),this._doneEvent=kn(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:n,snapshot:t})}subscribe(t,n,s){var i;const r=_t(t,n,s);if(this._processingStatus!==D.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(i=r.complete)==null||i.call(r)}catch(o){j(o)}break;case"error":{const o=this._snapshot.error;if(!r.error)j(o);else try{r.error(o)}catch(a){j(a)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(t,n){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const r=n.bind(void 0);return s.add(r),{unsubscribe:()=>{s.delete(r)}}}start(){if(this._processingStatus===D.Running)return this;this._syncSnapshot&&this.subscribe({next:s=>{s.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:s})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=D.Running;const t=Ht(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(s){return this._snapshot={...this._snapshot,status:"error",error:s},this._error(s),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let n,s;try{n=this.logic.transition(this._snapshot,t,this._actorScope)}catch(r){s={err:r}}if(s){const{err:r}=s;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(n,t),t.type===de&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===D.Stopped?this:(this.mailbox.clear(),this._processingStatus===D.NotStarted?(this._processingStatus=D.Stopped,this):(this.mailbox.enqueue({type:de}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var t;for(const n of this.observers)try{(t=n.complete)==null||t.call(n)}catch(s){j(s)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||j(t);return}let n=!1;for(const s of this.observers){const r=s.error;n||(n=!r);try{r==null||r(t)}catch(i){j(i)}}this.observers.clear(),n&&j(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Vt(this.id,t))}_stopProcedure(){return this._processingStatus!==D.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new gt(this._process.bind(this)),this._processingStatus=D.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==D.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:xn)(this)}toJSON(){return{xstate$$type:nt,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[Dn](){return this}getSnapshot(){return this._snapshot}}function F(e,...[t]){return new Un(e,t)}function Fn(e,t,n,s,{sendId:r}){const i=typeof r=="function"?r(n,s):r;return[t,i]}function Bn(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t)})}function jn(e){function t(n,s){}return t.type="xstate.cancel",t.sendId=e,t.resolve=Fn,t.execute=Bn,t}function $n(e,t,n,s,{id:r,systemId:i,src:o,input:a,syncSnapshot:c}){const u=typeof o=="string"?tt(t.machine,o):o,h=typeof r=="function"?r(n):r;let d;return u&&(d=F(u,{id:h,src:o,parent:e.self,syncSnapshot:c,systemId:i,input:typeof a=="function"?a({context:t.context,event:n.event,self:e.self}):a})),[Q(t,{children:{...t.children,[h]:d}}),{id:r,actorRef:d}]}function Vn(e,{id:t,actorRef:n}){n&&e.defer(()=>{n._processingStatus!==D.Stopped&&n.start()})}function Hn(...[e,{id:t,systemId:n,input:s,syncSnapshot:r=!1}={}]){function i(o,a){}return i.type="snapshot.spawnChild",i.id=t,i.systemId=n,i.src=e,i.input=s,i.syncSnapshot=r,i.resolve=$n,i.execute=Vn,i}function zn(e,t,n,s,{actorRef:r}){const i=typeof r=="function"?r(n,s):r,o=typeof i=="string"?t.children[i]:i;let a=t.children;return o&&(a={...a},delete a[o.id]),[Q(t,{children:a}),o]}function Gn(e,t){if(t){if(e.system._unregister(t),t._processingStatus!==D.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function Qt(e){function t(n,s){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=zn,t.execute=Gn,t}function st(e,t,n,s){const{machine:r}=s,i=typeof e=="function",o=i?e:r.implementations.guards[typeof e=="string"?e:e.type];if(!i&&!o)throw new Error(`Guard '${typeof e=="string"?e:e.type}' is not implemented.'.`);if(typeof o!="function")return st(o,t,n,s);const a={context:t,event:n},c=i||typeof e=="string"?void 0:"params"in e?typeof e.params=="function"?e.params({context:t,event:n}):e.params:void 0;return"check"in o?o.check(s,a,o):o(a,c)}const rt=e=>e.type==="atomic"||e.type==="final";function ne(e){return Object.values(e.states).filter(t=>t.type!=="history")}function he(e,t){const n=[];if(t===e)return n;let s=e.parent;for(;s&&s!==t;)n.push(s),s=s.parent;return n}function Ie(e){const t=new Set(e),n=Wt(t);for(const s of t)if(s.type==="compound"&&(!n.get(s)||!n.get(s).length))It(s).forEach(r=>t.add(r));else if(s.type==="parallel"){for(const r of ne(s))if(r.type!=="history"&&!t.has(r)){const i=It(r);for(const o of i)t.add(o)}}for(const s of t){let r=s.parent;for(;r;)t.add(r),r=r.parent}return t}function Xt(e,t){const n=t.get(e);if(!n)return{};if(e.type==="compound"){const r=n[0];if(r){if(rt(r))return r.key}else return{}}const s={};for(const r of n)s[r.key]=Xt(r,t);return s}function Wt(e){const t=new Map;for(const n of e)t.has(n)||t.set(n,[]),n.parent&&(t.has(n.parent)||t.set(n.parent,[]),t.get(n.parent).push(n));return t}function Kt(e,t){const n=Ie(t);return Xt(e,Wt(n))}function it(e,t){return t.type==="compound"?ne(t).some(n=>n.type==="final"&&e.has(n)):t.type==="parallel"?ne(t).every(n=>it(e,n)):t.type==="final"}const Ne=e=>e[0]===bn;function Jn(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(s=>{if(s===Nn)return!0;if(!s.endsWith(".*"))return!1;const r=s.split("."),i=t.split(".");for(let o=0;o<r.length;o++){const a=r[o],c=i[o];if(a==="*")return o===r.length-1;if(a!==c)return!1}return!0}).sort((s,r)=>r.length-s.length).flatMap(s=>e.transitions.get(s))}function Yn(e){const t=e.config.after;if(!t)return[];const n=(r,i)=>{const o=On(r,e.id),a=o.type;return e.entry.push(Ts(o,{id:a,delay:r})),e.exit.push(jn(a)),a};return Object.keys(t).flatMap((r,i)=>{const o=t[r],a=typeof o=="string"?{target:o}:o,c=Number.isNaN(+r)?r:+r,u=n(c);return $(a).map(h=>({...h,event:u,delay:c}))}).map(r=>{const{delay:i}=r;return{...J(e,r.event,r),delay:i}})}function J(e,t,n){const s=Yt(n.target),r=n.reenter??!1,i=Wn(e,s),o={...n,actions:$(n.actions),guard:n.guard,target:i,source:e,reenter:r,eventType:t,toJSON:()=>({...o,source:`#${e.id}`,target:i?i.map(a=>`#${a.id}`):void 0})};return o}function Qn(e){const t=new Map;if(e.config.on)for(const n of Object.keys(e.config.on)){if(n===jt)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=e.config.on[n];t.set(n,Z(s).map(r=>J(e,n,r)))}if(e.config.onDone){const n=`xstate.done.state.${e.id}`;t.set(n,Z(e.config.onDone).map(s=>J(e,n,s)))}for(const n of e.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;t.set(s,Z(n.onDone).map(r=>J(e,s,r)))}if(n.onError){const s=`xstate.error.actor.${n.id}`;t.set(s,Z(n.onError).map(r=>J(e,s,r)))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;t.set(s,Z(n.onSnapshot).map(r=>J(e,s,r)))}}for(const n of e.after){let s=t.get(n.eventType);s||(s=[],t.set(n.eventType,s)),s.push(n)}return t}function Xn(e,t){const n=typeof t=="string"?e.states[t]:t?e.states[t.target]:void 0;if(!n&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${e.id}`);const s={source:e,actions:!t||typeof t=="string"?[]:$(t.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return s}function Wn(e,t){if(t!==void 0)return t.map(n=>{if(typeof n!="string")return n;if(Ne(n))return e.machine.getStateNodeById(n);const s=n[0]===Bt;if(s&&!e.parent)return Ae(e,n.slice(1));const r=s?e.key+n:n;if(e.parent)try{return Ae(e.parent,r)}catch(i){throw new Error(`Invalid transition definition for state node '${e.id}':
|
|
2
2
|
${i.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function Zt(e){const t=Yt(e.config.target);return t?{target:t.map(n=>typeof n=="string"?Ae(e.parent,n):n)}:e.parent.initial}function Y(e){return e.type==="history"}function It(e){const t=en(e);for(const n of t)for(const s of he(n,e))t.add(s);return t}function en(e){const t=new Set;function n(s){if(!t.has(s)){if(t.add(s),s.type==="compound")n(s.initial.target[0]);else if(s.type==="parallel")for(const r of ne(s))n(r)}}return n(e),t}function se(e,t){if(Ne(t))return e.machine.getStateNodeById(t);if(!e.states)throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);const n=e.states[t];if(!n)throw new Error(`Child state '${t}' does not exist on '${e.id}'`);return n}function Ae(e,t){if(typeof t=="string"&&Ne(t))try{return e.machine.getStateNodeById(t)}catch{}const n=et(t).slice();let s=e;for(;n.length;){const r=n.shift();if(!r.length)break;s=se(s,r)}return s}function xe(e,t){if(typeof t=="string"){const r=e.states[t];if(!r)throw new Error(`State '${t}' does not exist on '${e.id}'`);return[e,r]}const n=Object.keys(t),s=n.map(r=>se(e,r)).filter(Boolean);return[e.machine.root,e].concat(s,n.reduce((r,i)=>{const o=se(e,i);if(!o)return r;const a=xe(o,t[i]);return r.concat(a)},[]))}function Kn(e,t,n,s){const i=se(e,t).next(n,s);return!i||!i.length?e.next(n,s):i}function Zn(e,t,n,s){const r=Object.keys(t),i=se(e,r[0]),o=ot(i,t[r[0]],n,s);return!o||!o.length?e.next(n,s):o}function es(e,t,n,s){const r=[];for(const i of Object.keys(t)){const o=t[i];if(!o)continue;const a=se(e,i),c=ot(a,o,n,s);c&&r.push(...c)}return r.length?r:e.next(n,s)}function ot(e,t,n,s){return typeof t=="string"?Kn(e,t,n,s):Object.keys(t).length===1?Zn(e,t,n,s):es(e,t,n,s)}function ts(e){return Object.keys(e.states).map(t=>e.states[t]).filter(t=>t.type==="history")}function V(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function ns(e,t){const n=new Set(e),s=new Set(t);for(const r of n)if(s.has(r))return!0;for(const r of s)if(n.has(r))return!0;return!1}function tn(e,t,n){const s=new Set;for(const r of e){let i=!1;const o=new Set;for(const a of s)if(ns(He([r],t,n),He([a],t,n)))if(V(r.source,a.source))o.add(a);else{i=!0;break}if(!i){for(const a of o)s.delete(a);s.add(r)}}return Array.from(s)}function ss(e){const[t,...n]=e;for(const s of he(t,void 0))if(n.every(r=>V(r,s)))return s}function at(e,t){if(!e.target)return[];const n=new Set;for(const s of e.target)if(Y(s))if(t[s.id])for(const r of t[s.id])n.add(r);else for(const r of at(Zt(s),t))n.add(r);else n.add(s);return[...n]}function nn(e,t){const n=at(e,t);if(!n)return;if(!e.reenter&&n.every(r=>r===e.source||V(r,e.source)))return e.source;const s=ss(n.concat(e.source));if(s)return s;if(!e.reenter)return e.source.machine.root}function He(e,t,n){var r;const s=new Set;for(const i of e)if((r=i.target)!=null&&r.length){const o=nn(i,n);i.reenter&&i.source===o&&s.add(o);for(const a of t)V(a,o)&&s.add(a)}return[...s]}function rs(e,t){if(e.length!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function ze(e,t,n,s,r,i){if(!e.length)return t;const o=new Set(t._nodes);let a=t.historyValue;const c=tn(e,o,a);let u=t;r||([u,a]=cs(u,s,n,c,o,a,i)),u=re(u,s,n,c.flatMap(d=>d.actions),i),u=os(u,s,n,c,o,i,a,r);const h=[...o];u.status==="done"&&(u=re(u,s,n,h.sort((d,f)=>f.order-d.order).flatMap(d=>d.exit),i));try{return a===t.historyValue&&rs(t._nodes,o)?u:Q(u,{_nodes:h,historyValue:a})}catch(d){throw d}}function is(e,t,n,s,r){if(s.output===void 0)return;const i=$e(r.id,r.output!==void 0&&r.parent?Ve(r.output,e.context,t,n.self):void 0);return Ve(s.output,e.context,i,n.self)}function os(e,t,n,s,r,i,o,a){let c=e;const u=new Set,h=new Set;as(s,o,h,u),a&&h.add(e.machine.root);const d=new Set;for(const f of[...u].sort((m,y)=>m.order-y.order)){r.add(f);const m=[];m.push(...f.entry);for(const y of f.invoke)m.push(Hn(y.src,{...y,syncSnapshot:!!y.onSnapshot}));if(h.has(f)){const y=f.initial.actions;m.push(...y)}if(c=re(c,t,n,m,i,f.invoke.map(y=>y.id)),f.type==="final"){const y=f.parent;let v=(y==null?void 0:y.type)==="parallel"?y:y==null?void 0:y.parent,I=v||f;for((y==null?void 0:y.type)==="compound"&&i.push($e(y.id,f.output!==void 0?Ve(f.output,c.context,t,n.self):void 0));(v==null?void 0:v.type)==="parallel"&&!d.has(v)&&it(r,v);)d.add(v),i.push($e(v.id)),I=v,v=v.parent;if(v)continue;c=Q(c,{status:"done",output:is(c,t,n,c.machine.root,I)})}}return c}function as(e,t,n,s){for(const r of e){const i=nn(r,t);for(const a of r.target||[])!Y(a)&&(r.source!==a||r.source!==i||r.reenter)&&(s.add(a),n.add(a)),ee(a,t,n,s);const o=at(r,t);for(const a of o){const c=he(a,i);(i==null?void 0:i.type)==="parallel"&&c.push(i),sn(s,t,n,c,!r.source.parent&&r.reenter?void 0:i)}}}function ee(e,t,n,s){var r;if(Y(e))if(t[e.id]){const i=t[e.id];for(const o of i)s.add(o),ee(o,t,n,s);for(const o of i)qe(o,e.parent,s,t,n)}else{const i=Zt(e);for(const o of i.target)s.add(o),i===((r=e.parent)==null?void 0:r.initial)&&n.add(e.parent),ee(o,t,n,s);for(const o of i.target)qe(o,e.parent,s,t,n)}else if(e.type==="compound"){const[i]=e.initial.target;Y(i)||(s.add(i),n.add(i)),ee(i,t,n,s),qe(i,e,s,t,n)}else if(e.type==="parallel")for(const i of ne(e).filter(o=>!Y(o)))[...s].some(o=>V(o,i))||(Y(i)||(s.add(i),n.add(i)),ee(i,t,n,s))}function sn(e,t,n,s,r){for(const i of s)if((!r||V(i,r))&&e.add(i),i.type==="parallel")for(const o of ne(i).filter(a=>!Y(a)))[...e].some(a=>V(a,o))||(e.add(o),ee(o,t,n,e))}function qe(e,t,n,s,r){sn(n,s,r,he(e,t))}function cs(e,t,n,s,r,i,o){let a=e;const c=He(s,r,i);c.sort((h,d)=>d.order-h.order);let u;for(const h of c)for(const d of ts(h)){let f;d.history==="deep"?f=m=>rt(m)&&V(m,h):f=m=>m.parent===h,u??(u={...i}),u[d.id]=Array.from(r).filter(f)}for(const h of c)a=re(a,t,n,[...h.exit,...h.invoke.map(d=>Qt(d.id))],o),r.delete(h);return[a,u||i]}let At=!1;function rn(e,t,n,s,r,i){const{machine:o}=e;let a=e;for(const c of s){let m=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:typeof c=="string"?c:typeof c=="object"?c.type:c.name||"(anonymous)",params:f}});try{At=h,h(d,f)}finally{At=!1}};const u=typeof c=="function",h=u?c:o.implementations.actions[typeof c=="string"?c:c.type];if(!h)continue;const d={context:a.context,event:t,self:n.self,system:n.system},f=u||typeof c=="string"?void 0:"params"in c?typeof c.params=="function"?c.params({context:a.context,event:t}):c.params:void 0;if(!("resolve"in h)){n.self._processingStatus===D.Running?m():n.defer(()=>{m()});continue}const y=h,[v,I,x]=y.resolve(n,a,d,f,h,r);a=v,"retryResolve"in y&&(i==null||i.push([y,I])),"execute"in y&&(n.self._processingStatus===D.Running?y.execute(n,I):n.defer(y.execute.bind(null,n,I))),x&&(a=rn(a,t,n,x,r,i))}return a}function re(e,t,n,s,r,i){const o=i?[]:void 0,a=rn(e,t,n,s,{internalQueue:r,deferredActorIds:i},o);return o==null||o.forEach(([c,u])=>{c.retryResolve(n,a,u)}),a}function Me(e,t,n,s=[]){let r=e;const i=[];function o(u,h,d){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:h,snapshot:u,_transitions:d}),i.push(u)}if(t.type===de)return r=Q(xt(r,t,n),{status:"stopped"}),o(r,t,[]),{snapshot:r,microstates:i};let a=t;if(a.type!==$t){const u=a,h=Ln(u),d=wt(u,r);if(h&&!d.length)return r=Q(e,{status:"error",error:u.error}),o(r,u,[]),{snapshot:r,microstates:i};r=ze(d,e,n,a,!1,s),o(r,u,d)}let c=!0;for(;r.status==="active";){let u=c?us(r,a):[];const h=u.length?r:void 0;if(!u.length){if(!s.length)break;a=s.shift(),u=wt(a,r)}r=ze(u,r,n,a,!1,s),c=r!==h,o(r,a,u)}return r.status!=="active"&&xt(r,a,n),{snapshot:r,microstates:i}}function xt(e,t,n){return re(e,t,n,Object.values(e.children).map(s=>Qt(s)),[])}function wt(e,t){return t.machine.getTransitionData(t,e)}function us(e,t){const n=new Set,s=e._nodes.filter(rt);for(const r of s)e:for(const i of[r].concat(he(r,void 0)))if(i.always){for(const o of i.always)if(o.guard===void 0||st(o.guard,e.context,t,e)){n.add(o);break e}}return tn(Array.from(n),new Set(e._nodes),e.historyValue)}function ds(e,t){const n=Ie(xe(e,t));return Kt(e,[...n])}function ls(e){return!!e&&typeof e=="object"&&"machine"in e&&"value"in e}const hs=function(t){return zt(t,this.value)},fs=function(t){return this.tags.has(t)},ps=function(t){const n=this.machine.getTransitionData(this,t);return!!(n!=null&&n.length)&&n.some(s=>s.target!==void 0||s.actions.length)},ys=function(){const{_nodes:t,tags:n,machine:s,getMeta:r,toJSON:i,can:o,hasTag:a,matches:c,...u}=this;return{...u,tags:Array.from(n)}},ms=function(){return this._nodes.reduce((t,n)=>(n.meta!==void 0&&(t[n.id]=n.meta),t),{})};function ve(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:Kt(t.root,e._nodes),tags:new Set(e._nodes.flatMap(n=>n.tags)),children:e.children,historyValue:e.historyValue||{},matches:hs,hasTag:fs,can:ps,getMeta:ms,toJSON:ys}}function Q(e,t={}){return ve({...e,...t},e.machine)}function gs(e,t){const{_nodes:n,tags:s,machine:r,children:i,context:o,can:a,hasTag:c,matches:u,getMeta:h,toJSON:d,...f}=e,m={};for(const v in i){const I=i[v];m[v]={snapshot:I.getPersistedSnapshot(t),src:I.src,systemId:I._systemId,syncSnapshot:I._syncSnapshot}}return{...f,context:on(o),children:m}}function on(e){let t;for(const n in e){const s=e[n];if(s&&typeof s=="object")if("sessionId"in s&&"send"in s&&"ref"in s)t??(t=Array.isArray(e)?e.slice():{...e}),t[n]={xstate$$type:nt,id:s.id};else{const r=on(s);r!==s&&(t??(t=Array.isArray(e)?e.slice():{...e}),t[n]=r)}}return t??e}function Es(e,t,n,s,{event:r,id:i,delay:o},{internalQueue:a}){const c=t.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);const u=typeof r=="function"?r(n,s):r;let h;if(typeof o=="string"){const d=c&&c[o];h=typeof d=="function"?d(n,s):d}else h=typeof o=="function"?o(n,s):o;return typeof h!="number"&&a.push(u),[t,{event:u,id:i,delay:h}]}function vs(e,t){const{event:n,delay:s,id:r}=t;if(typeof s=="number"){e.defer(()=>{const i=e.self;e.system.scheduler.schedule(i,i,n,s,r)});return}}function Ts(e,t){function n(s,r){}return n.type="xstate.raise",n.event=e,n.id=t==null?void 0:t.id,n.delay=t==null?void 0:t.delay,n.resolve=Es,n.execute=vs,n}const bt=new WeakMap;function _s(e){return{config:e,start:(n,s)=>{const{self:r,system:i}=s,o={receivers:void 0,dispose:void 0};bt.set(r,o),o.dispose=e({input:n.input,system:i,self:r,sendBack:a=>{r.getSnapshot().status!=="stopped"&&r._parent&&i._relay(r,r._parent,a)},receive:a=>{o.receivers??(o.receivers=new Set),o.receivers.add(a)}})},transition:(n,s,r)=>{var o,a;const i=bt.get(r.self);return s.type===de?(n={...n,status:"stopped",error:void 0},(o=i.dispose)==null||o.call(i),n):((a=i.receivers)==null||a.forEach(c=>c(s)),n)},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}const Nt="xstate.promise.resolve",Ct="xstate.promise.reject",ge=new WeakMap;function H(e){return{config:e,transition:(n,s,r)=>{var i;if(n.status!=="active")return n;switch(s.type){case Nt:{const o=s.data;return{...n,status:"done",output:o,input:void 0}}case Ct:return{...n,status:"error",error:s.data,input:void 0};case de:return(i=ge.get(r.self))==null||i.abort(),{...n,status:"stopped",input:void 0};default:return n}},start:(n,{self:s,system:r})=>{if(n.status!=="active")return;const i=new AbortController;ge.set(s,i),Promise.resolve(e({input:n.input,system:r,self:s,signal:i.signal})).then(a=>{s.getSnapshot().status==="active"&&(ge.delete(s),r._relay(s,s,{type:Nt,data:a}))},a=>{s.getSnapshot().status==="active"&&(ge.delete(s),r._relay(s,s,{type:Ct,data:a}))})},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}function Ss(e,{machine:t,context:n},s,r){const i=(o,a={})=>{const{systemId:c,input:u}=a;if(typeof o=="string"){const h=tt(t,o);if(!h)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const d=F(h,{id:a.id,parent:e.self,syncSnapshot:a.syncSnapshot,input:typeof u=="function"?u({context:n,event:s,self:e.self}):u,src:o,systemId:c});return r[d.id]=d,d}else return F(o,{id:a.id,parent:e.self,syncSnapshot:a.syncSnapshot,input:a.input,src:o,systemId:c})};return(o,a)=>{const c=i(o,a);return r[c.id]=c,e.defer(()=>{c._processingStatus!==D.Stopped&&c.start()}),c}}function Is(e,t,n,s,{assignment:r}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:t.context,event:n.event,spawn:Ss(e,t,n.event,i),self:e.self,system:e.system};let a={};if(typeof r=="function")a=r(o,s);else for(const u of Object.keys(r)){const h=r[u];a[u]=typeof h=="function"?h(o,s):h}const c=Object.assign({},t.context,a);return[Q(t,{context:c,children:Object.keys(i).length?{...t.children,...i}:t.children})]}function O(e){function t(n,s){}return t.type="xstate.assign",t.assignment=e,t.resolve=Is,t}function As(e,t,n,s,{event:r}){const i=typeof r=="function"?r(n,s):r;return[t,{event:i}]}function xs(e,{event:t}){e.defer(()=>e.emit(t))}function Le(e){function t(n,s){}return t.type="xstate.emit",t.event=e,t.resolve=As,t.execute=xs,t}let Ot=function(e){return e.Parent="#_parent",e.Internal="#_internal",e}({});function ws(e,t,n,s,{to:r,event:i,id:o,delay:a},c){var y;const u=t.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const h=typeof i=="function"?i(n,s):i;let d;if(typeof a=="string"){const v=u&&u[a];d=typeof v=="function"?v(n,s):v}else d=typeof a=="function"?a(n,s):a;const f=typeof r=="function"?r(n,s):r;let m;if(typeof f=="string"){if(f===Ot.Parent?m=e.self._parent:f===Ot.Internal?m=e.self:f.startsWith("#_")?m=t.children[f.slice(2)]:m=(y=c.deferredActorIds)!=null&&y.includes(f)?f:t.children[f],!m)throw new Error(`Unable to send event to actor '${f}' from machine '${t.machine.id}'.`)}else m=f||e.self;return[t,{to:m,event:h,id:o,delay:d}]}function bs(e,t,n){typeof n.to=="string"&&(n.to=t.children[n.to])}function Ns(e,t){e.defer(()=>{const{to:n,event:s,delay:r,id:i}=t;if(typeof r=="number"){e.system.scheduler.schedule(e.self,n,s,r,i);return}e.system._relay(e.self,n,s.type===Cn?Vt(e.self.id,s.data):s)})}function kt(e,t,n){function s(r,i){}return s.type="xsnapshot.sendTo",s.to=e,s.event=t,s.id=n==null?void 0:n.id,s.delay=n==null?void 0:n.delay,s.resolve=ws,s.retryResolve=bs,s.execute=Ns,s}const Dt=new WeakMap;function W(e,t,n){let s=Dt.get(e);return s?t in s||(s[t]=n()):(s={[t]:n()},Dt.set(e,s)),s[t]}const Cs={},ae=e=>typeof e=="string"?{type:e}:typeof e=="function"?"resolve"in e?{type:e.type}:{type:e.name}:e;class ct{constructor(t,n){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(Bt),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?Tt(this.config.states,(s,r)=>new ct(s,{_parent:this,_key:r,_machine:this.machine})):Cs,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=$(this.config.entry).slice(),this.exit=$(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=$(t.tags).slice()}_initialize(){this.transitions=Qn(this),this.config.always&&(this.always=Z(this.config.always).map(t=>J(this,jt,t))),Object.keys(this.states).forEach(t=>{this.states[t]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(ae),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(ae),eventType:null})}:void 0,history:this.history,states:Tt(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(ae)})),entry:this.entry.map(ae),exit:this.exit.map(ae),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return W(this,"invoke",()=>$(this.config.invoke).map((t,n)=>{const{src:s,systemId:r}=t,i=t.id??St(this.id,n),o=typeof s=="string"?s:`xstate.invoke.${St(this.id,n)}`;return{...t,src:o,id:i,systemId:r,toJSON(){const{onDone:a,onError:c,...u}=t;return{...u,type:"xstate.invoke",src:o,id:i}}}}))}get on(){return W(this,"on",()=>[...this.transitions].flatMap(([n,s])=>s.map(r=>[n,r])).reduce((n,[s,r])=>(n[s]=n[s]||[],n[s].push(r),n),{}))}get after(){return W(this,"delayedTransitions",()=>Yn(this))}get initial(){return W(this,"initial",()=>Xn(this,this.config.initial))}next(t,n){const s=n.type,r=[];let i;const o=W(this,`candidates-${s}`,()=>Jn(this,s));for(const a of o){const{guard:c}=a,u=t.context;let h=!1;try{h=!c||st(c,u,n,t)}catch(d){const f=typeof c=="string"?c:typeof c=="object"?c.type:void 0;throw new Error(`Unable to evaluate guard ${f?`'${f}' `:""}in transition for event '${s}' in state node '${this.id}':
|
|
3
3
|
${d.message}`)}if(h){r.push(...a.actions),i=a;break}}return i?[i]:void 0}get events(){return W(this,"events",()=>{const{states:t}=this,n=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const r=t[s];if(r.states)for(const i of r.events)n.add(`${i}`)}return Array.from(n)})}get ownEvents(){const t=new Set([...this.transitions.keys()].filter(n=>this.transitions.get(n).some(s=>!(!s.target&&!s.actions.length&&!s.reenter))));return Array.from(t)}}const Os="#";class ut{constructor(t,n){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.implementations={actors:(n==null?void 0:n.actors)??{},actions:(n==null?void 0:n.actions)??{},delays:(n==null?void 0:n.delays)??{},guards:(n==null?void 0:n.guards)??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new ct(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:n,guards:s,actors:r,delays:i}=this.implementations;return new ut(this.config,{actions:{...n,...t.actions},guards:{...s,...t.guards},actors:{...r,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const n=ds(this.root,t.value),s=Ie(xe(this.root,n));return ve({_nodes:[...s],context:t.context||{},children:{},status:it(s,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,n,s){return Me(t,n,s).snapshot}microstep(t,n,s){return Me(t,n,s).microstates}getTransitionData(t,n){return ot(this.root,t.value,t,n)||[]}getPreInitialState(t,n,s){const{context:r}=this.config,i=ve({context:typeof r!="function"&&r?r:{},_nodes:[this.root],children:{},status:"active"},this);return typeof r=="function"?re(i,n,t,[O(({spawn:a,event:c,self:u})=>r({spawn:a,input:c.input,self:u}))],s):i}getInitialSnapshot(t,n){const s=Ht(n),r=[],i=this.getPreInitialState(t,s,r),o=ze([{target:[...en(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,t,s,!0,r),{snapshot:a}=Me(o,s,t,r);return a}start(t){Object.values(t.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(t){const n=et(t),s=n.slice(1),r=Ne(n[0])?n[0].slice(Os.length):n[0],i=this.idMap.get(r);if(!i)throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);return Ae(i,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,n){return gs(t,n)}restoreSnapshot(t,n){const s={},r=t.children;Object.keys(r).forEach(c=>{const u=r[c],h=u.snapshot,d=u.src,f=typeof d=="string"?tt(this,d):d;if(!f)return;const m=F(f,{id:c,parent:n.self,syncSnapshot:u.syncSnapshot,snapshot:h,src:d,systemId:u.systemId});s[c]=m});const i=ve({...t,children:s,_nodes:Array.from(Ie(xe(this.root,t.value)))},this);let o=new Set;function a(c,u){if(!o.has(c)){o.add(c);for(let h in c){const d=c[h];if(d&&typeof d=="object"){if("xstate$$type"in d&&d.xstate$$type===nt){c[h]=u[d.id];continue}a(d,u)}}}}return a(i.context,s),i}}function ks(e,t){return new ut(e,t)}function fe({schemas:e,actors:t,actions:n,guards:s,delays:r}){return{createMachine:i=>ks({...i,schemas:e},{actors:t,actions:n,guards:s,delays:r})}}function an(e,t){const n=$(t);if(!n.includes(e.type)){const s=n.length===1?`type "${n[0]}"`:`one of types "${n.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(e)} to have ${s}`)}}function Ds({context:e,event:t}){if(!t.type.includes("xstate.error.actor"))return e;const n=t;return{errors:[...e.errors,String(n.error).replace("Error: ","")]}}function Rs(){return{errors:[]}}function qs({context:e,event:t}){if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="REFRESH_TOKEN_SUCCESS"?e:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}function Ms(){return{ignoreRefreshToken:!0}}function Ls({context:e,event:t}){if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="AUTHENTICATE_SUCCESS"?e:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}function Ps(){return{refreshToken:""}}function Us(){return{user:null,accessToken:"",refreshToken:"",ignoreRefreshToken:!1}}async function Ge(e,t){const n=await fetch(e,t);return n.status===200?n.json():Promise.resolve({message:n.statusText,success:!1})}const Fs=H(async({input:e})=>{var n;const t=await Ge(e.endpoint.client,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({username:e.username,password:e.password}).toString()});if(!t.success)throw new Error(((n=t.message)==null?void 0:n.toString())??"Sign in failed. Please try again.");return{type:"AUTHENTICATE_SUCCESS",user:null,accessToken:t.accessToken??""}}),Bs=H(async({input:e})=>{if(!e.endpoint.client||e.endpoint.client==="")throw new Error("No client endpoint provided.");if(!e.endpoint.server||e.endpoint.server==="")throw new Error("No server endpoint provided.");let t;if(typeof window>"u"){if(e.refreshToken==="")throw new Error("Unauthorized.");try{if(t=await Ge(e.endpoint.server,{method:"POST",mode:"cors",credentials:"include",headers:{Cookie:`refresh_token=${e.refreshToken}`,"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"}}),typeof t.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:t.accessToken}}catch(n){throw console.log(n),new Error("Could not complete refresh request (server)")}}else{if(t=await Ge(e.endpoint.client,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({grant_type:"refresh_token"}).toString()}),typeof t.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:t.accessToken}}}),js=H(async({input:e})=>(await fetch(e.endpoint.client,{method:"POST",mode:"cors",credentials:"include",headers:{"clicktap-scope":"view","clicktap-scope-id":"default"}}),{type:"UNAUTHENTICATE_SUCCESS"})),Je=fe({types:{context:{},events:{},input:{}},actions:{addError:O(Ds),clearErrors:O(Rs),setAccessToken:O(qs),setIgnoreRefreshToken:O(Ms),setUserContext:O(Ls),unsetRefreshToken:O(Ps),unsetUserContext:O(Us)},actors:{authenticate:Fs,refreshAccessToken:Bs,unauthenticate:js}}).createMachine({id:"auth",context:({input:e})=>{var t,n;return{user:null,accessToken:"",refreshToken:((t=e==null?void 0:e.initialContext)==null?void 0:t.refreshToken)??"",ignoreRefreshToken:!1,endpoints:((n=e==null?void 0:e.initialContext)==null?void 0:n.endpoints)??{login:"",logout:"",refresh:"",ssrRefresh:""},errors:[]}},initial:"refreshing",states:{authenticating:{invoke:{src:"authenticate",input:({context:e,event:t})=>(an(t,"LOGIN"),{endpoint:{client:e.endpoints.login},username:t.username,password:t.password}),onDone:[{actions:"setUserContext",target:"loggedIn"}],onError:[{actions:"addError",target:"loggedOut"}]}},unauthenticating:{invoke:{src:"unauthenticate",input:({context:e})=>({endpoint:{client:e.endpoints.logout}}),onDone:[{actions:"unsetUserContext",target:"loggedOut"}],onError:[{actions:["unsetUserContext","setIgnoreRefreshToken"],target:"loggedOut"}]}},refreshing:{invoke:{src:"refreshAccessToken",input:({context:e})=>({accessToken:e.accessToken,endpoint:{client:e.endpoints.refresh,server:e.endpoints.ssrRefresh},refreshToken:e.refreshToken}),onDone:[{actions:["unsetRefreshToken","setAccessToken"],target:"loggedIn"}],onError:[{actions:"unsetRefreshToken",target:"unauthenticating"}]}},loggedOut:{on:{LOGIN:{target:"authenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}},loggedIn:{after:{84e4:{guard:()=>typeof window<"u",target:"refreshing"}},on:{LOGOUT:{target:"unauthenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}}}}),dt=R.createContext({}),$s=()=>{const e=R.useContext(dt),[t,n]=R.useState(typeof window<"u"&&e.getSnapshot().value==="loggedIn");return R.useEffect(()=>{if(typeof window>"u")return;const s=e.subscribe(r=>{(r.value==="loggedIn"||r.value==="loggedOut")&&n(r.value==="loggedIn")});return()=>{s.unsubscribe()}},[e]),{authActor:e,isLoggedIn:t}},Vs=async(e="",t={inspect:void 0,endpoints:{login:"",logout:"",refresh:"",ssrRefresh:""}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),F(Je,{inspect:t.inspect,input:{initialContext:{endpoints:t.endpoints}}}).start()):F(Je,{input:{initialContext:{endpoints:t.endpoints,refreshToken:e}},inspect:t.inspect}).start();function Hs({actor:e,children:t}){return be.jsx(dt.Provider,{value:e,children:t})}function zs({context:e,event:t}){var r,i;if(!t.type.includes("xstate.done.actor")||t.output.type!=="SUBMIT_STEP_DATA_SUCCESS")return e;const s=(i=(r=e.steps)==null?void 0:r.find(o=>o.name===e.currentStep))==null?void 0:i.next;return s?(console.log("nextStep currentStep",e.currentStep),console.log("nextStep next",s),{currentStep:s??e.currentStep}):e}const lt=JSON,Gs=e=>e.toUpperCase(),Js=e=>{const t={};return e.forEach((n,s)=>{t[s]=n}),t},Ys=(e,t,n)=>e.document?e:{document:e,variables:t,requestHeaders:n,signal:void 0},Qs=(e,t,n)=>e.query?e:{query:e,variables:t,requestHeaders:n,signal:void 0},Xs=(e,t)=>e.documents?e:{documents:e,requestHeaders:t,signal:void 0},Ws=(e,t,...n)=>{const[s,r]=n;return e.document?e:{url:e,document:t,variables:s,requestHeaders:r,signal:void 0}};function Te(e,t){if(!!!e)throw new Error(t)}function Ks(e){return typeof e=="object"&&e!==null}function Zs(e,t){if(!!!e)throw new Error(t??"Unexpected invariant triggered.")}const er=/\r\n|[\n\r]/g;function Ye(e,t){let n=0,s=1;for(const r of e.body.matchAll(er)){if(typeof r.index=="number"||Zs(!1),r.index>=t)break;n=r.index+r[0].length,s+=1}return{line:s,column:t+1-n}}function tr(e){return cn(e.source,Ye(e.source,e.start))}function cn(e,t){const n=e.locationOffset.column-1,s="".padStart(n)+e.body,r=t.line-1,i=e.locationOffset.line-1,o=t.line+i,a=t.line===1?n:0,c=t.column+a,u=`${e.name}:${o}:${c}
|
|
4
4
|
`,h=s.split(/\r\n|[\n\r]/g),d=h[r];if(d.length>120){const f=Math.floor(c/80),m=c%80,y=[];for(let v=0;v<d.length;v+=80)y.push(d.slice(v,v+80));return u+Rt([[`${o} |`,y[0]],...y.slice(1,f+1).map(v=>["|",v]),["|","^".padStart(m)],["|",y[f+1]]])}return u+Rt([[`${o-1} |`,h[r-1]],[`${o} |`,d],["|","^".padStart(c)],[`${o+1} |`,h[r+1]]])}function Rt(e){const t=e.filter(([s,r])=>r!==void 0),n=Math.max(...t.map(([s])=>s.length));return t.map(([s,r])=>s.padStart(n)+(r?" "+r:"")).join(`
|
package/index.mjs
CHANGED
|
@@ -351,12 +351,10 @@ class jn {
|
|
|
351
351
|
d._stop();
|
|
352
352
|
},
|
|
353
353
|
emit: (d) => {
|
|
354
|
-
const f = this.eventListeners.get(d.type)
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
for (const v of Array.from(y))
|
|
359
|
-
v(d);
|
|
354
|
+
const f = this.eventListeners.get(d.type);
|
|
355
|
+
if (f)
|
|
356
|
+
for (const m of Array.from(f))
|
|
357
|
+
m(d);
|
|
360
358
|
}
|
|
361
359
|
}, this.send = this.send.bind(this), this.system._sendInspectionEvent({
|
|
362
360
|
type: "@xstate.actor",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clicktap/state",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Clicktap",
|
|
6
6
|
"description": "A state management library for Clicktap reference frontend.",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"cookie": "^0.5.0",
|
|
20
20
|
"graphql": "^16.6.0",
|
|
21
21
|
"graphql-request": "^6.1.0",
|
|
22
|
-
"xstate": "
|
|
22
|
+
"xstate": "5.13.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/cookie": "^0.5.1",
|