2 lines
52 KiB
JavaScript
2 lines
52 KiB
JavaScript
var le=s=>{throw TypeError(s)};var Lt=(s,t,e)=>t.has(s)||le("Cannot "+e);var n=(s,t,e)=>(Lt(s,t,"read from private field"),e?e.call(s):t.get(s)),g=(s,t,e)=>t.has(s)?le("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),y=(s,t,e,i)=>(Lt(s,t,"write to private field"),i?i.call(s,e):t.set(s,e),e),w=(s,t,e)=>(Lt(s,t,"access private method"),e);var It=(s,t,e,i)=>({set _(r){y(s,t,r,e)},get _(){return n(s,t,i)}});import"./vendor_A_react-Bhse1i8S.js";var Tt=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(s){return this.listeners.add(s),this.onSubscribe(),()=>{this.listeners.delete(s),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},wt=typeof window>"u"||"Deno"in globalThis;function _(){}function Ge(s,t){return typeof s=="function"?s(t):s}function xt(s){return typeof s=="number"&&s>=0&&s!==1/0}function Ee(s,t){return Math.max(s+(t||0)-Date.now(),0)}function ut(s,t){return typeof s=="function"?s(t):s}function q(s,t){return typeof s=="function"?s(t):s}function ue(s,t){const{type:e="all",exact:i,fetchStatus:r,predicate:a,queryKey:o,stale:l}=s;if(o){if(i){if(t.queryHash!==re(o,t.options))return!1}else if(!Ot(t.queryKey,o))return!1}if(e!=="all"){const c=t.isActive();if(e==="active"&&!c||e==="inactive"&&c)return!1}return!(typeof l=="boolean"&&t.isStale()!==l||r&&r!==t.state.fetchStatus||a&&!a(t))}function he(s,t){const{exact:e,status:i,predicate:r,mutationKey:a}=s;if(a){if(!t.options.mutationKey)return!1;if(e){if(Pt(t.options.mutationKey)!==Pt(a))return!1}else if(!Ot(t.options.mutationKey,a))return!1}return!(i&&t.state.status!==i||r&&!r(t))}function re(s,t){return((t==null?void 0:t.queryKeyHashFn)||Pt)(s)}function Pt(s){return JSON.stringify(s,(t,e)=>$t(e)?Object.keys(e).sort().reduce((i,r)=>(i[r]=e[r],i),{}):e)}function Ot(s,t){return s===t?!0:typeof s!=typeof t?!1:s&&t&&typeof s=="object"&&typeof t=="object"?!Object.keys(t).some(e=>!Ot(s[e],t[e])):!1}function De(s,t){if(s===t)return s;const e=ce(s)&&ce(t);if(e||$t(s)&&$t(t)){const i=e?s:Object.keys(s),r=i.length,a=e?t:Object.keys(t),o=a.length,l=e?[]:{};let c=0;for(let d=0;d<o;d++){const u=e?d:a[d];(!e&&i.includes(u)||e)&&s[u]===void 0&&t[u]===void 0?(l[u]=void 0,c++):(l[u]=De(s[u],t[u]),l[u]===s[u]&&s[u]!==void 0&&c++)}return r===o&&c===r?s:l}return t}function Bt(s,t){if(!t||Object.keys(s).length!==Object.keys(t).length)return!1;for(const e in s)if(s[e]!==t[e])return!1;return!0}function ce(s){return Array.isArray(s)&&s.length===Object.keys(s).length}function $t(s){if(!de(s))return!1;const t=s.constructor;if(t===void 0)return!0;const e=t.prototype;return!(!de(e)||!e.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(s)!==Object.prototype)}function de(s){return Object.prototype.toString.call(s)==="[object Object]"}function ze(s){return new Promise(t=>{setTimeout(t,s)})}function Ht(s,t,e){return typeof e.structuralSharing=="function"?e.structuralSharing(s,t):e.structuralSharing!==!1?De(s,t):t}function We(s,t,e=0){const i=[...s,t];return e&&i.length>e?i.slice(1):i}function Je(s,t,e=0){const i=[t,...s];return e&&i.length>e?i.slice(0,-1):i}var Re=Symbol();function Te(s,t){return!s.queryFn&&(t!=null&&t.initialPromise)?()=>t.initialPromise:!s.queryFn||s.queryFn===Re?()=>Promise.reject(new Error(`Missing queryFn: '${s.queryHash}'`)):s.queryFn}var et,W,ht,Fe,Xe=(Fe=class extends Tt{constructor(){super();g(this,et);g(this,W);g(this,ht);y(this,ht,t=>{if(!wt&&window.addEventListener){const e=()=>t();return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}})}onSubscribe(){n(this,W)||this.setEventListener(n(this,ht))}onUnsubscribe(){var t;this.hasListeners()||((t=n(this,W))==null||t.call(this),y(this,W,void 0))}setEventListener(t){var e;y(this,ht,t),(e=n(this,W))==null||e.call(this),y(this,W,t(i=>{typeof i=="boolean"?this.setFocused(i):this.onFocus()}))}setFocused(t){n(this,et)!==t&&(y(this,et,t),this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach(e=>{e(t)})}isFocused(){var t;return typeof n(this,et)=="boolean"?n(this,et):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},et=new WeakMap,W=new WeakMap,ht=new WeakMap,Fe),ae=new Xe,ct,J,dt,Me,Ye=(Me=class extends Tt{constructor(){super();g(this,ct,!0);g(this,J);g(this,dt);y(this,dt,t=>{if(!wt&&window.addEventListener){const e=()=>t(!0),i=()=>t(!1);return window.addEventListener("online",e,!1),window.addEventListener("offline",i,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",i)}}})}onSubscribe(){n(this,J)||this.setEventListener(n(this,dt))}onUnsubscribe(){var t;this.hasListeners()||((t=n(this,J))==null||t.call(this),y(this,J,void 0))}setEventListener(t){var e;y(this,dt,t),(e=n(this,J))==null||e.call(this),y(this,J,t(this.setOnline.bind(this)))}setOnline(t){n(this,ct)!==t&&(y(this,ct,t),this.listeners.forEach(i=>{i(t)}))}isOnline(){return n(this,ct)}},ct=new WeakMap,J=new WeakMap,dt=new WeakMap,Me),_t=new Ye;function Ze(s){return Math.min(1e3*2**s,3e4)}function Ie(s){return(s??"online")==="online"?_t.isOnline():!0}var Qe=class{constructor(s){this.revert=s==null?void 0:s.revert,this.silent=s==null?void 0:s.silent}};function jt(s){return s instanceof Qe}function ke(s){let t=!1,e=0,i=!1,r,a,o;const l=new Promise((M,m)=>{a=M,o=m}),c=M=>{var m;i||(S(new Qe(M)),(m=s.abort)==null||m.call(s))},d=()=>{t=!0},u=()=>{t=!1},h=()=>ae.isFocused()&&(s.networkMode==="always"||_t.isOnline())&&s.canRun(),f=()=>Ie(s.networkMode)&&s.canRun(),v=M=>{var m;i||(i=!0,(m=s.onSuccess)==null||m.call(s,M),r==null||r(),a(M))},S=M=>{var m;i||(i=!0,(m=s.onError)==null||m.call(s,M),r==null||r(),o(M))},p=()=>new Promise(M=>{var m;r=b=>{(i||h())&&M(b)},(m=s.onPause)==null||m.call(s)}).then(()=>{var M;r=void 0,i||(M=s.onContinue)==null||M.call(s)}),F=()=>{if(i)return;let M;const m=e===0?s.initialPromise:void 0;try{M=m??s.fn()}catch(b){M=Promise.reject(b)}Promise.resolve(M).then(v).catch(b=>{var V;if(i)return;const O=s.retry??(wt?0:3),E=s.retryDelay??Ze,K=typeof E=="function"?E(e,b):E,N=O===!0||typeof O=="number"&&e<O||typeof O=="function"&&O(e,b);if(t||!N){S(b);return}e++,(V=s.onFail)==null||V.call(s,e,b),ze(K).then(()=>h()?void 0:p()).then(()=>{t?S(b):F()})})};return{promise:l,cancel:c,continue:()=>(r==null||r(),l),cancelRetry:d,continueRetry:u,canStart:f,start:()=>(f()?F():p().then(F),l)}}function ts(){let s=[],t=0,e=f=>{f()},i=f=>{f()},r=f=>setTimeout(f,0);const a=f=>{r=f},o=f=>{let v;t++;try{v=f()}finally{t--,t||d()}return v},l=f=>{t?s.push(f):r(()=>{e(f)})},c=f=>(...v)=>{l(()=>{f(...v)})},d=()=>{const f=s;s=[],f.length&&r(()=>{i(()=>{f.forEach(v=>{e(v)})})})};return{batch:o,batchCalls:c,schedule:l,setNotifyFunction:f=>{e=f},setBatchNotifyFunction:f=>{i=f},setScheduler:a}}var R=ts(),st,Se,Ue=(Se=class{constructor(){g(this,st)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),xt(this.gcTime)&&y(this,st,setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(s){this.gcTime=Math.max(this.gcTime||0,s??(wt?1/0:5*60*1e3))}clearGcTimeout(){n(this,st)&&(clearTimeout(n(this,st)),y(this,st,void 0))}},st=new WeakMap,Se),ft,yt,U,D,Ct,it,j,G,we,es=(we=class extends Ue{constructor(t){super();g(this,j);g(this,ft);g(this,yt);g(this,U);g(this,D);g(this,Ct);g(this,it);y(this,it,!1),y(this,Ct,t.defaultOptions),this.setOptions(t.options),this.observers=[],y(this,U,t.cache),this.queryKey=t.queryKey,this.queryHash=t.queryHash,y(this,ft,t.state||ss(this.options)),this.state=n(this,ft),this.scheduleGc()}get meta(){return this.options.meta}get promise(){var t;return(t=n(this,D))==null?void 0:t.promise}setOptions(t){this.options={...n(this,Ct),...t},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&n(this,U).remove(this)}setData(t,e){const i=Ht(this.state.data,t,this.options);return w(this,j,G).call(this,{data:i,type:"success",dataUpdatedAt:e==null?void 0:e.updatedAt,manual:e==null?void 0:e.manual}),i}setState(t,e){w(this,j,G).call(this,{type:"setState",state:t,setStateOptions:e})}cancel(t){var i,r;const e=(i=n(this,D))==null?void 0:i.promise;return(r=n(this,D))==null||r.cancel(t),e?e.then(_).catch(_):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(n(this,ft))}isActive(){return this.observers.some(t=>q(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated?!0:this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0}isStaleByTime(t=0){return this.state.isInvalidated||this.state.data===void 0||!Ee(this.state.dataUpdatedAt,t)}onFocus(){var e;const t=this.observers.find(i=>i.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(e=n(this,D))==null||e.continue()}onOnline(){var e;const t=this.observers.find(i=>i.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(e=n(this,D))==null||e.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),n(this,U).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(e=>e!==t),this.observers.length||(n(this,D)&&(n(this,it)?n(this,D).cancel({revert:!0}):n(this,D).cancelRetry()),this.scheduleGc()),n(this,U).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||w(this,j,G).call(this,{type:"invalidate"})}fetch(t,e){var c,d,u;if(this.state.fetchStatus!=="idle"){if(this.state.data!==void 0&&(e!=null&&e.cancelRefetch))this.cancel({silent:!0});else if(n(this,D))return n(this,D).continueRetry(),n(this,D).promise}if(t&&this.setOptions(t),!this.options.queryFn){const h=this.observers.find(f=>f.options.queryFn);h&&this.setOptions(h.options)}const i=new AbortController,r=h=>{Object.defineProperty(h,"signal",{enumerable:!0,get:()=>(y(this,it,!0),i.signal)})},a=()=>{const h=Te(this.options,e),f={queryKey:this.queryKey,meta:this.meta};return r(f),y(this,it,!1),this.options.persister?this.options.persister(h,f,this):h(f)},o={fetchOptions:e,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:a};r(o),(c=this.options.behavior)==null||c.onFetch(o,this),y(this,yt,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((d=o.fetchOptions)==null?void 0:d.meta))&&w(this,j,G).call(this,{type:"fetch",meta:(u=o.fetchOptions)==null?void 0:u.meta});const l=h=>{var f,v,S,p;jt(h)&&h.silent||w(this,j,G).call(this,{type:"error",error:h}),jt(h)||((v=(f=n(this,U).config).onError)==null||v.call(f,h,this),(p=(S=n(this,U).config).onSettled)==null||p.call(S,this.state.data,h,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return y(this,D,ke({initialPromise:e==null?void 0:e.initialPromise,fn:o.fetchFn,abort:i.abort.bind(i),onSuccess:h=>{var f,v,S,p;if(h===void 0){l(new Error(`${this.queryHash} data is undefined`));return}this.setData(h),(v=(f=n(this,U).config).onSuccess)==null||v.call(f,h,this),(p=(S=n(this,U).config).onSettled)==null||p.call(S,h,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1},onError:l,onFail:(h,f)=>{w(this,j,G).call(this,{type:"failed",failureCount:h,error:f})},onPause:()=>{w(this,j,G).call(this,{type:"pause"})},onContinue:()=>{w(this,j,G).call(this,{type:"continue"})},retry:o.options.retry,retryDelay:o.options.retryDelay,networkMode:o.options.networkMode,canRun:()=>!0})),n(this,D).start()}},ft=new WeakMap,yt=new WeakMap,U=new WeakMap,D=new WeakMap,Ct=new WeakMap,it=new WeakMap,j=new WeakSet,G=function(t){const e=i=>{switch(t.type){case"failed":return{...i,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...i,fetchStatus:"paused"};case"continue":return{...i,fetchStatus:"fetching"};case"fetch":return{...i,..._e(i.data,this.options),fetchMeta:t.meta??null};case"success":return{...i,data:t.data,dataUpdateCount:i.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const r=t.error;return jt(r)&&r.revert&&n(this,yt)?{...n(this,yt),fetchStatus:"idle"}:{...i,error:r,errorUpdateCount:i.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:i.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:"idle",status:"error"};case"invalidate":return{...i,isInvalidated:!0};case"setState":return{...i,...t.state}}};this.state=e(this.state),R.batch(()=>{this.observers.forEach(i=>{i.onQueryUpdate()}),n(this,U).notify({query:this,type:"updated",action:t})})},we);function _e(s,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Ie(t.networkMode)?"fetching":"paused",...s===void 0&&{error:null,status:"pending"}}}function ss(s){const t=typeof s.initialData=="function"?s.initialData():s.initialData,e=t!==void 0,i=e?typeof s.initialDataUpdatedAt=="function"?s.initialDataUpdatedAt():s.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:e?i??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:e?"success":"pending",fetchStatus:"idle"}}var x,Ae,is=(Ae=class extends Tt{constructor(t={}){super();g(this,x);this.config=t,y(this,x,new Map)}build(t,e,i){const r=e.queryKey,a=e.queryHash??re(r,e);let o=this.get(a);return o||(o=new es({cache:this,queryKey:r,queryHash:a,options:t.defaultQueryOptions(e),state:i,defaultOptions:t.getQueryDefaults(r)}),this.add(o)),o}add(t){n(this,x).has(t.queryHash)||(n(this,x).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=n(this,x).get(t.queryHash);e&&(t.destroy(),e===t&&n(this,x).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){R.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return n(this,x).get(t)}getAll(){return[...n(this,x).values()]}find(t){const e={exact:!0,...t};return this.getAll().find(i=>ue(e,i))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter(i=>ue(t,i)):e}notify(t){R.batch(()=>{this.listeners.forEach(e=>{e(t)})})}onFocus(){R.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){R.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},x=new WeakMap,Ae),B,T,rt,$,z,Ve,rs=(Ve=class extends Ue{constructor(t){super();g(this,$);g(this,B);g(this,T);g(this,rt);this.mutationId=t.mutationId,y(this,T,t.mutationCache),y(this,B,[]),this.state=t.state||as(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){n(this,B).includes(t)||(n(this,B).push(t),this.clearGcTimeout(),n(this,T).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){y(this,B,n(this,B).filter(e=>e!==t)),this.scheduleGc(),n(this,T).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){n(this,B).length||(this.state.status==="pending"?this.scheduleGc():n(this,T).remove(this))}continue(){var t;return((t=n(this,rt))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var r,a,o,l,c,d,u,h,f,v,S,p,F,M,m,b,O,E,K,N;y(this,rt,ke({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(V,L)=>{w(this,$,z).call(this,{type:"failed",failureCount:V,error:L})},onPause:()=>{w(this,$,z).call(this,{type:"pause"})},onContinue:()=>{w(this,$,z).call(this,{type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>n(this,T).canRun(this)}));const e=this.state.status==="pending",i=!n(this,rt).canStart();try{if(!e){w(this,$,z).call(this,{type:"pending",variables:t,isPaused:i}),await((a=(r=n(this,T).config).onMutate)==null?void 0:a.call(r,t,this));const L=await((l=(o=this.options).onMutate)==null?void 0:l.call(o,t));L!==this.state.context&&w(this,$,z).call(this,{type:"pending",context:L,variables:t,isPaused:i})}const V=await n(this,rt).start();return await((d=(c=n(this,T).config).onSuccess)==null?void 0:d.call(c,V,t,this.state.context,this)),await((h=(u=this.options).onSuccess)==null?void 0:h.call(u,V,t,this.state.context)),await((v=(f=n(this,T).config).onSettled)==null?void 0:v.call(f,V,null,this.state.variables,this.state.context,this)),await((p=(S=this.options).onSettled)==null?void 0:p.call(S,V,null,t,this.state.context)),w(this,$,z).call(this,{type:"success",data:V}),V}catch(V){try{throw await((M=(F=n(this,T).config).onError)==null?void 0:M.call(F,V,t,this.state.context,this)),await((b=(m=this.options).onError)==null?void 0:b.call(m,V,t,this.state.context)),await((E=(O=n(this,T).config).onSettled)==null?void 0:E.call(O,void 0,V,this.state.variables,this.state.context,this)),await((N=(K=this.options).onSettled)==null?void 0:N.call(K,void 0,V,t,this.state.context)),V}finally{w(this,$,z).call(this,{type:"error",error:V})}}finally{n(this,T).runNext(this)}}},B=new WeakMap,T=new WeakMap,rt=new WeakMap,$=new WeakSet,z=function(t){const e=i=>{switch(t.type){case"failed":return{...i,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...i,isPaused:!0};case"continue":return{...i,isPaused:!1};case"pending":return{...i,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...i,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...i,data:void 0,error:t.error,failureCount:i.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=e(this.state),R.batch(()=>{n(this,B).forEach(i=>{i.onMutationUpdate(t)}),n(this,T).notify({mutation:this,type:"updated",action:t})})},Ve);function as(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var k,Et,Pe,ns=(Pe=class extends Tt{constructor(t={}){super();g(this,k);g(this,Et);this.config=t,y(this,k,new Map),y(this,Et,Date.now())}build(t,e,i){const r=new rs({mutationCache:this,mutationId:++It(this,Et)._,options:t.defaultMutationOptions(e),state:i});return this.add(r),r}add(t){const e=Qt(t),i=n(this,k).get(e)??[];i.push(t),n(this,k).set(e,i),this.notify({type:"added",mutation:t})}remove(t){var i;const e=Qt(t);if(n(this,k).has(e)){const r=(i=n(this,k).get(e))==null?void 0:i.filter(a=>a!==t);r&&(r.length===0?n(this,k).delete(e):n(this,k).set(e,r))}this.notify({type:"removed",mutation:t})}canRun(t){var i;const e=(i=n(this,k).get(Qt(t)))==null?void 0:i.find(r=>r.state.status==="pending");return!e||e===t}runNext(t){var i;const e=(i=n(this,k).get(Qt(t)))==null?void 0:i.find(r=>r!==t&&r.state.isPaused);return(e==null?void 0:e.continue())??Promise.resolve()}clear(){R.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}getAll(){return[...n(this,k).values()].flat()}find(t){const e={exact:!0,...t};return this.getAll().find(i=>he(e,i))}findAll(t={}){return this.getAll().filter(e=>he(t,e))}notify(t){R.batch(()=>{this.listeners.forEach(e=>{e(t)})})}resumePausedMutations(){const t=this.getAll().filter(e=>e.state.isPaused);return R.batch(()=>Promise.all(t.map(e=>e.continue().catch(_))))}},k=new WeakMap,Et=new WeakMap,Pe);function Qt(s){var t;return((t=s.options.scope)==null?void 0:t.id)??String(s.mutationId)}function os(s){return{onFetch:(t,e)=>{const i=async()=>{var S,p,F,M,m;const r=t.options,a=(F=(p=(S=t.fetchOptions)==null?void 0:S.meta)==null?void 0:p.fetchMore)==null?void 0:F.direction,o=((M=t.state.data)==null?void 0:M.pages)||[],l=((m=t.state.data)==null?void 0:m.pageParams)||[],c={pages:[],pageParams:[]};let d=!1;const u=b=>{Object.defineProperty(b,"signal",{enumerable:!0,get:()=>(t.signal.aborted?d=!0:t.signal.addEventListener("abort",()=>{d=!0}),t.signal)})},h=Te(t.options,t.fetchOptions),f=async(b,O,E)=>{if(d)return Promise.reject();if(O==null&&b.pages.length)return Promise.resolve(b);const K={queryKey:t.queryKey,pageParam:O,direction:E?"backward":"forward",meta:t.options.meta};u(K);const N=await h(K),{maxPages:V}=t.options,L=E?Je:We;return{pages:L(b.pages,N,V),pageParams:L(b.pageParams,O,V)}};let v;if(a&&o.length){const b=a==="backward",O=b?ls:fe,E={pages:o,pageParams:l},K=O(r,E);v=await f(E,K,b)}else{v=await f(c,l[0]??r.initialPageParam);const b=s??o.length;for(let O=1;O<b;O++){const E=fe(r,v);v=await f(v,E)}}return v};t.options.persister?t.fetchFn=()=>{var r,a;return(a=(r=t.options).persister)==null?void 0:a.call(r,i,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},e)}:t.fetchFn=i}}}function fe(s,{pages:t,pageParams:e}){const i=t.length-1;return t.length>0?s.getNextPageParam(t[i],t,e[i],e):void 0}function ls(s,{pages:t,pageParams:e}){var i;return t.length>0?(i=s.getPreviousPageParam)==null?void 0:i.call(s,t[0],t,e[0],e):void 0}var C,X,Y,vt,mt,Z,pt,gt,Oe,Ms=(Oe=class{constructor(s={}){g(this,C);g(this,X);g(this,Y);g(this,vt);g(this,mt);g(this,Z);g(this,pt);g(this,gt);y(this,C,s.queryCache||new is),y(this,X,s.mutationCache||new ns),y(this,Y,s.defaultOptions||{}),y(this,vt,new Map),y(this,mt,new Map),y(this,Z,0)}mount(){It(this,Z)._++,n(this,Z)===1&&(y(this,pt,ae.subscribe(async s=>{s&&(await this.resumePausedMutations(),n(this,C).onFocus())})),y(this,gt,_t.subscribe(async s=>{s&&(await this.resumePausedMutations(),n(this,C).onOnline())})))}unmount(){var s,t;It(this,Z)._--,n(this,Z)===0&&((s=n(this,pt))==null||s.call(this),y(this,pt,void 0),(t=n(this,gt))==null||t.call(this),y(this,gt,void 0))}isFetching(s){return n(this,C).findAll({...s,fetchStatus:"fetching"}).length}isMutating(s){return n(this,X).findAll({...s,status:"pending"}).length}getQueryData(s){var e;const t=this.defaultQueryOptions({queryKey:s});return(e=n(this,C).get(t.queryHash))==null?void 0:e.state.data}ensureQueryData(s){const t=this.getQueryData(s.queryKey);if(t===void 0)return this.fetchQuery(s);{const e=this.defaultQueryOptions(s),i=n(this,C).build(this,e);return s.revalidateIfStale&&i.isStaleByTime(ut(e.staleTime,i))&&this.prefetchQuery(e),Promise.resolve(t)}}getQueriesData(s){return n(this,C).findAll(s).map(({queryKey:t,state:e})=>{const i=e.data;return[t,i]})}setQueryData(s,t,e){const i=this.defaultQueryOptions({queryKey:s}),r=n(this,C).get(i.queryHash),a=r==null?void 0:r.state.data,o=Ge(t,a);if(o!==void 0)return n(this,C).build(this,i).setData(o,{...e,manual:!0})}setQueriesData(s,t,e){return R.batch(()=>n(this,C).findAll(s).map(({queryKey:i})=>[i,this.setQueryData(i,t,e)]))}getQueryState(s){var e;const t=this.defaultQueryOptions({queryKey:s});return(e=n(this,C).get(t.queryHash))==null?void 0:e.state}removeQueries(s){const t=n(this,C);R.batch(()=>{t.findAll(s).forEach(e=>{t.remove(e)})})}resetQueries(s,t){const e=n(this,C),i={type:"active",...s};return R.batch(()=>(e.findAll(s).forEach(r=>{r.reset()}),this.refetchQueries(i,t)))}cancelQueries(s={},t={}){const e={revert:!0,...t},i=R.batch(()=>n(this,C).findAll(s).map(r=>r.cancel(e)));return Promise.all(i).then(_).catch(_)}invalidateQueries(s={},t={}){return R.batch(()=>{if(n(this,C).findAll(s).forEach(i=>{i.invalidate()}),s.refetchType==="none")return Promise.resolve();const e={...s,type:s.refetchType??s.type??"active"};return this.refetchQueries(e,t)})}refetchQueries(s={},t){const e={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},i=R.batch(()=>n(this,C).findAll(s).filter(r=>!r.isDisabled()).map(r=>{let a=r.fetch(void 0,e);return e.throwOnError||(a=a.catch(_)),r.state.fetchStatus==="paused"?Promise.resolve():a}));return Promise.all(i).then(_)}fetchQuery(s){const t=this.defaultQueryOptions(s);t.retry===void 0&&(t.retry=!1);const e=n(this,C).build(this,t);return e.isStaleByTime(ut(t.staleTime,e))?e.fetch(t):Promise.resolve(e.state.data)}prefetchQuery(s){return this.fetchQuery(s).then(_).catch(_)}fetchInfiniteQuery(s){return s.behavior=os(s.pages),this.fetchQuery(s)}prefetchInfiniteQuery(s){return this.fetchInfiniteQuery(s).then(_).catch(_)}resumePausedMutations(){return _t.isOnline()?n(this,X).resumePausedMutations():Promise.resolve()}getQueryCache(){return n(this,C)}getMutationCache(){return n(this,X)}getDefaultOptions(){return n(this,Y)}setDefaultOptions(s){y(this,Y,s)}setQueryDefaults(s,t){n(this,vt).set(Pt(s),{queryKey:s,defaultOptions:t})}getQueryDefaults(s){const t=[...n(this,vt).values()];let e={};return t.forEach(i=>{Ot(s,i.queryKey)&&(e={...e,...i.defaultOptions})}),e}setMutationDefaults(s,t){n(this,mt).set(Pt(s),{mutationKey:s,defaultOptions:t})}getMutationDefaults(s){const t=[...n(this,mt).values()];let e={};return t.forEach(i=>{Ot(s,i.mutationKey)&&(e={...e,...i.defaultOptions})}),e}defaultQueryOptions(s){if(s._defaulted)return s;const t={...n(this,Y).queries,...this.getQueryDefaults(s.queryKey),...s,_defaulted:!0};return t.queryHash||(t.queryHash=re(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.enabled!==!0&&t.queryFn===Re&&(t.enabled=!1),t}defaultMutationOptions(s){return s!=null&&s._defaulted?s:{...n(this,Y).mutations,...(s==null?void 0:s.mutationKey)&&this.getMutationDefaults(s.mutationKey),...s,_defaulted:!0}}clear(){n(this,C).clear(),n(this,X).clear()}},C=new WeakMap,X=new WeakMap,Y=new WeakMap,vt=new WeakMap,mt=new WeakMap,Z=new WeakMap,pt=new WeakMap,gt=new WeakMap,Oe),Q,A,Dt,I,at,bt,H,Rt,Ft,Mt,nt,ot,tt,St,P,At,Nt,Gt,zt,Wt,Jt,Xt,Yt,Le,Ce,Ss=(Ce=class extends Tt{constructor(t,e){super();g(this,P);g(this,Q);g(this,A);g(this,Dt);g(this,I);g(this,at);g(this,bt);g(this,H);g(this,Rt);g(this,Ft);g(this,Mt);g(this,nt);g(this,ot);g(this,tt);g(this,St,new Set);this.options=e,y(this,Q,t),y(this,H,null),this.bindMethods(),this.setOptions(e)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(n(this,A).addObserver(this),ye(n(this,A),this.options)?w(this,P,At).call(this):this.updateResult(),w(this,P,Wt).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Zt(n(this,A),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Zt(n(this,A),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,w(this,P,Jt).call(this),w(this,P,Xt).call(this),n(this,A).removeObserver(this)}setOptions(t,e){const i=this.options,r=n(this,A);if(this.options=n(this,Q).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof q(this.options.enabled,n(this,A))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");w(this,P,Yt).call(this),n(this,A).setOptions(this.options),i._defaulted&&!Bt(this.options,i)&&n(this,Q).getQueryCache().notify({type:"observerOptionsUpdated",query:n(this,A),observer:this});const a=this.hasListeners();a&&ve(n(this,A),r,this.options,i)&&w(this,P,At).call(this),this.updateResult(e),a&&(n(this,A)!==r||q(this.options.enabled,n(this,A))!==q(i.enabled,n(this,A))||ut(this.options.staleTime,n(this,A))!==ut(i.staleTime,n(this,A)))&&w(this,P,Nt).call(this);const o=w(this,P,Gt).call(this);a&&(n(this,A)!==r||q(this.options.enabled,n(this,A))!==q(i.enabled,n(this,A))||o!==n(this,tt))&&w(this,P,zt).call(this,o)}getOptimisticResult(t){const e=n(this,Q).getQueryCache().build(n(this,Q),t),i=this.createResult(e,t);return hs(this,i)&&(y(this,I,i),y(this,bt,this.options),y(this,at,n(this,A).state)),i}getCurrentResult(){return n(this,I)}trackResult(t,e){const i={};return Object.keys(t).forEach(r=>{Object.defineProperty(i,r,{configurable:!1,enumerable:!0,get:()=>(this.trackProp(r),e==null||e(r),t[r])})}),i}trackProp(t){n(this,St).add(t)}getCurrentQuery(){return n(this,A)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=n(this,Q).defaultQueryOptions(t),i=n(this,Q).getQueryCache().build(n(this,Q),e);return i.isFetchingOptimistic=!0,i.fetch().then(()=>this.createResult(i,e))}fetch(t){return w(this,P,At).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),n(this,I)))}createResult(t,e){var N;const i=n(this,A),r=this.options,a=n(this,I),o=n(this,at),l=n(this,bt),d=t!==i?t.state:n(this,Dt),{state:u}=t;let h={...u},f=!1,v;if(e._optimisticResults){const V=this.hasListeners(),L=!V&&ye(t,e),Ne=V&&ve(t,i,e,r);(L||Ne)&&(h={...h,..._e(u.data,t.options)}),e._optimisticResults==="isRestoring"&&(h.fetchStatus="idle")}let{error:S,errorUpdatedAt:p,status:F}=h;if(e.select&&h.data!==void 0)if(a&&h.data===(o==null?void 0:o.data)&&e.select===n(this,Rt))v=n(this,Ft);else try{y(this,Rt,e.select),v=e.select(h.data),v=Ht(a==null?void 0:a.data,v,e),y(this,Ft,v),y(this,H,null)}catch(V){y(this,H,V)}else v=h.data;if(e.placeholderData!==void 0&&v===void 0&&F==="pending"){let V;if(a!=null&&a.isPlaceholderData&&e.placeholderData===(l==null?void 0:l.placeholderData))V=a.data;else if(V=typeof e.placeholderData=="function"?e.placeholderData((N=n(this,Mt))==null?void 0:N.state.data,n(this,Mt)):e.placeholderData,e.select&&V!==void 0)try{V=e.select(V),y(this,H,null)}catch(L){y(this,H,L)}V!==void 0&&(F="success",v=Ht(a==null?void 0:a.data,V,e),f=!0)}n(this,H)&&(S=n(this,H),v=n(this,Ft),p=Date.now(),F="error");const M=h.fetchStatus==="fetching",m=F==="pending",b=F==="error",O=m&&M,E=v!==void 0;return{status:F,fetchStatus:h.fetchStatus,isPending:m,isSuccess:F==="success",isError:b,isInitialLoading:O,isLoading:O,data:v,dataUpdatedAt:h.dataUpdatedAt,error:S,errorUpdatedAt:p,failureCount:h.fetchFailureCount,failureReason:h.fetchFailureReason,errorUpdateCount:h.errorUpdateCount,isFetched:h.dataUpdateCount>0||h.errorUpdateCount>0,isFetchedAfterMount:h.dataUpdateCount>d.dataUpdateCount||h.errorUpdateCount>d.errorUpdateCount,isFetching:M,isRefetching:M&&!m,isLoadingError:b&&!E,isPaused:h.fetchStatus==="paused",isPlaceholderData:f,isRefetchError:b&&E,isStale:ne(t,e),refetch:this.refetch}}updateResult(t){const e=n(this,I),i=this.createResult(n(this,A),this.options);if(y(this,at,n(this,A).state),y(this,bt,this.options),n(this,at).data!==void 0&&y(this,Mt,n(this,A)),Bt(i,e))return;y(this,I,i);const r={},a=()=>{if(!e)return!0;const{notifyOnChangeProps:o}=this.options,l=typeof o=="function"?o():o;if(l==="all"||!l&&!n(this,St).size)return!0;const c=new Set(l??n(this,St));return this.options.throwOnError&&c.add("error"),Object.keys(n(this,I)).some(d=>{const u=d;return n(this,I)[u]!==e[u]&&c.has(u)})};(t==null?void 0:t.listeners)!==!1&&a()&&(r.listeners=!0),w(this,P,Le).call(this,{...r,...t})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&w(this,P,Wt).call(this)}},Q=new WeakMap,A=new WeakMap,Dt=new WeakMap,I=new WeakMap,at=new WeakMap,bt=new WeakMap,H=new WeakMap,Rt=new WeakMap,Ft=new WeakMap,Mt=new WeakMap,nt=new WeakMap,ot=new WeakMap,tt=new WeakMap,St=new WeakMap,P=new WeakSet,At=function(t){w(this,P,Yt).call(this);let e=n(this,A).fetch(this.options,t);return t!=null&&t.throwOnError||(e=e.catch(_)),e},Nt=function(){w(this,P,Jt).call(this);const t=ut(this.options.staleTime,n(this,A));if(wt||n(this,I).isStale||!xt(t))return;const i=Ee(n(this,I).dataUpdatedAt,t)+1;y(this,nt,setTimeout(()=>{n(this,I).isStale||this.updateResult()},i))},Gt=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(n(this,A)):this.options.refetchInterval)??!1},zt=function(t){w(this,P,Xt).call(this),y(this,tt,t),!(wt||q(this.options.enabled,n(this,A))===!1||!xt(n(this,tt))||n(this,tt)===0)&&y(this,ot,setInterval(()=>{(this.options.refetchIntervalInBackground||ae.isFocused())&&w(this,P,At).call(this)},n(this,tt)))},Wt=function(){w(this,P,Nt).call(this),w(this,P,zt).call(this,w(this,P,Gt).call(this))},Jt=function(){n(this,nt)&&(clearTimeout(n(this,nt)),y(this,nt,void 0))},Xt=function(){n(this,ot)&&(clearInterval(n(this,ot)),y(this,ot,void 0))},Yt=function(){const t=n(this,Q).getQueryCache().build(n(this,Q),this.options);if(t===n(this,A))return;const e=n(this,A);y(this,A,t),y(this,Dt,t.state),this.hasListeners()&&(e==null||e.removeObserver(this),t.addObserver(this))},Le=function(t){R.batch(()=>{t.listeners&&this.listeners.forEach(e=>{e(n(this,I))}),n(this,Q).getQueryCache().notify({query:n(this,A),type:"observerResultsUpdated"})})},Ce);function us(s,t){return q(t.enabled,s)!==!1&&s.state.data===void 0&&!(s.state.status==="error"&&t.retryOnMount===!1)}function ye(s,t){return us(s,t)||s.state.data!==void 0&&Zt(s,t,t.refetchOnMount)}function Zt(s,t,e){if(q(t.enabled,s)!==!1){const i=typeof e=="function"?e(s):e;return i==="always"||i!==!1&&ne(s,t)}return!1}function ve(s,t,e,i){return(s!==t||q(i.enabled,s)===!1)&&(!e.suspense||s.state.status!=="error")&&ne(s,e)}function ne(s,t){return q(t.enabled,s)!==!1&&s.isStaleByTime(ut(t.staleTime,s))}function hs(s,t){return!Bt(s.getCurrentResult(),t)}const me="pushstate",pe="popstate",je="beforeunload",qe=s=>(s.preventDefault(),s.returnValue=""),cs=()=>{removeEventListener(je,qe,{capture:!0})};function Ke(s){let t=s.getLocation();const e=new Set;let i=[];const r=()=>{t=s.getLocation(),e.forEach(o=>o())},a=async(o,l)=>{var c;if(!((l==null?void 0:l.ignoreBlocker)??!1)&&typeof document<"u"&&i.length){for(const u of i)if(!await u()){(c=s.onBlocked)==null||c.call(s,r);return}}o()};return{get location(){return t},subscribers:e,subscribe:o=>(e.add(o),()=>{e.delete(o)}),push:(o,l,c)=>{l=Vt(l),a(()=>{s.pushState(o,l),r()},c)},replace:(o,l,c)=>{l=Vt(l),a(()=>{s.replaceState(o,l),r()},c)},go:(o,l)=>{a(()=>{s.go(o),r()},l)},back:o=>{a(()=>{s.back(),r()},o)},forward:o=>{a(()=>{s.forward(),r()},o)},createHref:o=>s.createHref(o),block:o=>(i.push(o),i.length===1&&addEventListener(je,qe,{capture:!0}),()=>{i=i.filter(l=>l!==o),i.length||cs()}),flush:()=>{var o;return(o=s.flush)==null?void 0:o.call(s)},destroy:()=>{var o;return(o=s.destroy)==null?void 0:o.call(s)},notify:r}}function Vt(s){return s||(s={}),{...s,key:xe()}}function ws(s){const t=typeof document<"u"?window:void 0,e=t.history.pushState,i=t.history.replaceState,r=p=>p,a=()=>te(`${t.location.pathname}${t.location.search}${t.location.hash}`,t.history.state);let o=a(),l;const c=()=>o;let d,u;const h=()=>{if(!d)return;(d.isPush?e:i).call(t.history,d.state,"",d.href),d=void 0,u=void 0,l=void 0},f=(p,F,M)=>{const m=r(F);u||(l=o),o=te(F,M),d={href:m,state:M,isPush:(d==null?void 0:d.isPush)||p==="push"},u||(u=Promise.resolve().then(()=>h()))},v=()=>{o=a(),S.notify()},S=Ke({getLocation:c,pushState:(p,F)=>f("push",p,F),replaceState:(p,F)=>f("replace",p,F),back:()=>t.history.back(),forward:()=>t.history.forward(),go:p=>t.history.go(p),createHref:p=>r(p),flush:h,destroy:()=>{t.history.pushState=e,t.history.replaceState=i,t.removeEventListener(me,v),t.removeEventListener(pe,v)},onBlocked:p=>{l&&o!==l&&(o=l,p())}});return t.addEventListener(me,v),t.addEventListener(pe,v),t.history.pushState=function(...p){const F=e.apply(t.history,p);return v(),F},t.history.replaceState=function(...p){const F=i.apply(t.history,p);return v(),F},S}function As(s={initialEntries:["/"]}){const t=s.initialEntries;let e=s.initialIndex??t.length-1,i={key:xe()};return Ke({getLocation:()=>te(t[e],i),pushState:(a,o)=>{i=o,t.splice,e<t.length-1&&t.splice(e+1),t.push(a),e=Math.max(t.length-1,0)},replaceState:(a,o)=>{i=o,t[e]=a},back:()=>{i=Vt(i),e=Math.max(e-1,0)},forward:()=>{i=Vt(i),e=Math.min(e+1,t.length-1)},go:a=>{i=Vt(i),e=Math.min(Math.max(e+a,0),t.length-1)},createHref:a=>a})}function te(s,t){const e=s.indexOf("#"),i=s.indexOf("?");return{href:s,pathname:s.substring(0,e>0?i>0?Math.min(e,i):e:i>0?i:s.length),hash:e>-1?s.substring(e):"",search:i>-1?s.slice(i,e===-1?void 0:e):"",state:t||{}}}function xe(){return(Math.random()+1).toString(36).substring(7)}class Be{constructor(t,e){this.listeners=new Set,this._batching=!1,this._flushing=0,this.subscribe=i=>{var r,a;this.listeners.add(i);const o=(a=(r=this.options)==null?void 0:r.onSubscribe)==null?void 0:a.call(r,i,this);return()=>{this.listeners.delete(i),o==null||o()}},this.setState=i=>{var r,a,o;const l=this.state;this.state=(r=this.options)!=null&&r.updateFn?this.options.updateFn(l)(i):i(l),(o=(a=this.options)==null?void 0:a.onUpdate)==null||o.call(a),this._flush()},this._flush=()=>{if(this._batching)return;const i=++this._flushing;this.listeners.forEach(r=>{this._flushing===i&&r()})},this.batch=i=>{if(this._batching)return i();this._batching=!0,i(),this._batching=!1,this._flush()},this.state=t,this.options=e}}function $e(s,t){return typeof s=="function"?s(t):s}function He(s,t){return oe(t).reduce((i,r)=>{if(i===null)return null;if(typeof i<"u")return i[r]},s)}function qt(s,t,e){const i=oe(t);function r(a){if(!i.length)return $e(e,a);const o=i.shift();if(typeof o=="string")return typeof a=="object"?(a===null&&(a={}),{...a,[o]:r(a[o])}):{[o]:r()};if(Array.isArray(a)&&o!==void 0){const l=a.slice(0,o);return[...l.length?l:new Array(o),r(a[o]),...a.slice(o+1)]}return[...new Array(o),r()]}return r(s)}function ds(s,t){const e=oe(t);function i(r){if(!r)return;if(e.length===1){const o=e[0];if(Array.isArray(r)&&typeof o=="number")return r.filter((d,u)=>u!==o);const{[o]:l,...c}=r;return c}const a=e.shift();if(typeof a=="string"&&typeof r=="object")return{...r,[a]:i(r[a])};if(typeof a=="number"&&Array.isArray(r)){if(a>=r.length)return r;const o=r.slice(0,a);return[...o.length?o:new Array(a),i(r[a]),...r.slice(a+1)]}throw new Error("It seems we have created an infinite loop in deleteBy. ")}return i(s)}const fs=/^(\d*)$/gm,ys=/\.(\d*)\./gm,vs=/^(\d*)\./gm,ms=/\.(\d*$)/gm,ps=/\.{2,}/gm,ee="__int__",kt=`${ee}$1`;function oe(s){if(typeof s!="string")throw new Error("Path must be a string.");return s.replaceAll("[",".").replaceAll("]","").replace(fs,kt).replace(ys,`.${kt}.`).replace(vs,`${kt}.`).replace(ms,`.${kt}`).replace(ps,".").split(".").map(t=>t.indexOf(ee)===0?parseInt(t.substring(ee.length),10):t)}function gs(s){return!(Array.isArray(s)&&s.length===0)}function se(s,t){const{asyncDebounceMs:e}=t,{onChangeAsync:i,onBlurAsync:r,onSubmitAsync:a,onBlurAsyncDebounceMs:o,onChangeAsyncDebounceMs:l}=t.validators||{},c=e??0,d={cause:"change",validate:i,debounceMs:l??c},u={cause:"blur",validate:r,debounceMs:o??c},h={cause:"submit",validate:a,debounceMs:0},f=v=>({...v,debounceMs:0});switch(s){case"submit":return[f(d),f(u),h];case"blur":return[u];case"change":return[d];case"server":default:return[]}}function ie(s,t){const{onChange:e,onBlur:i,onSubmit:r}=t.validators||{},a={cause:"change",validate:e},o={cause:"blur",validate:i},l={cause:"submit",validate:r},c={cause:"server",validate:()=>{}};switch(s){case"submit":return[a,o,l,c];case"server":return[c];case"blur":return[o,c];case"change":default:return[a,c]}}function Kt(s){return{values:s.values??{},errors:s.errors??[],errorMap:s.errorMap??{},fieldMeta:s.fieldMeta??{},canSubmit:s.canSubmit??!0,isFieldsValid:s.isFieldsValid??!1,isFieldsValidating:s.isFieldsValidating??!1,isFormValid:s.isFormValid??!1,isFormValidating:s.isFormValidating??!1,isSubmitted:s.isSubmitted??!1,isSubmitting:s.isSubmitting??!1,isTouched:s.isTouched??!1,isPristine:s.isPristine??!0,isDirty:s.isDirty??!1,isValid:s.isValid??!1,isValidating:s.isValidating??!1,submissionAttempts:s.submissionAttempts??0,validationMetaMap:s.validationMetaMap??{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0}}}class Vs{constructor(t){var e;this.options={},this.fieldInfo={},this.prevTransformArray=[],this.mount=()=>{const{onMount:i}=this.options.validators||{};if(!i)return;const r=this.runValidator({validate:i,value:{value:this.state.values,formApi:this},type:"validate"});r&&this.store.setState(a=>({...a,errorMap:{...a.errorMap,onMount:r}}))},this.update=i=>{if(!i)return;const r=this.options;this.options=i,this.store.batch(()=>{const a=i.defaultValues&&i.defaultValues!==r.defaultValues&&!this.state.isTouched,o=i.defaultState!==r.defaultState&&!this.state.isTouched;this.store.setState(()=>Kt(Object.assign({},this.state,o?i.defaultState:{},a?{values:i.defaultValues}:{})))})},this.reset=()=>{const{fieldMeta:i}=this.state,r=this.resetFieldMeta(i);this.store.setState(()=>{var a;return Kt({...this.options.defaultState,values:this.options.defaultValues??((a=this.options.defaultState)==null?void 0:a.values),fieldMeta:r})})},this.validateAllFields=async i=>{const r=[];return this.store.batch(()=>{Object.values(this.fieldInfo).forEach(o=>{if(!o.instance)return;const l=o.instance;r.push(Promise.resolve().then(()=>l.validate(i))),o.instance.state.meta.isTouched||o.instance.setMeta(c=>({...c,isTouched:!0}))})}),(await Promise.all(r)).flat()},this.validateArrayFieldsStartingFrom=async(i,r,a)=>{const o=this.getFieldValue(i),l=Array.isArray(o)?Math.max(o.length-1,0):null,c=[`${i}[${r}]`];for(let f=r+1;f<=(l??0);f++)c.push(`${i}[${f}]`);const d=Object.keys(this.fieldInfo).filter(f=>c.some(v=>f.startsWith(v))),u=[];return this.store.batch(()=>{d.forEach(f=>{u.push(Promise.resolve().then(()=>this.validateField(f,a)))})}),(await Promise.all(u)).flat()},this.validateField=(i,r)=>{var a;const o=(a=this.fieldInfo[i])==null?void 0:a.instance;return o?(o.state.meta.isTouched||o.setMeta(l=>({...l,isTouched:!0})),o.validate(r)):[]},this.validateSync=i=>{const r=ie(i,this.options);let a=!1;this.store.batch(()=>{for(const l of r){if(!l.validate)continue;const c=ge(this.runValidator({validate:l.validate,value:{value:this.state.values,formApi:this},type:"validate"})),d=Ut(l.cause);this.state.errorMap[d]!==c&&this.store.setState(u=>({...u,errorMap:{...u.errorMap,[d]:c}})),c&&(a=!0)}});const o=Ut("submit");return this.state.errorMap[o]&&i!=="submit"&&!a&&this.store.setState(l=>({...l,errorMap:{...l.errorMap,[o]:void 0}})),{hasErrored:a}},this.validateAsync=async i=>{const r=se(i,this.options);this.state.isFormValidating||this.store.setState(l=>({...l,isFormValidating:!0}));const a=[];for(const l of r){if(!l.validate)continue;const c=Ut(l.cause),d=this.state.validationMetaMap[c];d==null||d.lastAbortController.abort();const u=new AbortController;this.state.validationMetaMap[c]={lastAbortController:u},a.push(new Promise(async h=>{let f;try{f=await new Promise((S,p)=>{setTimeout(async()=>{if(u.signal.aborted)return S(void 0);try{S(await this.runValidator({validate:l.validate,value:{value:this.state.values,formApi:this,signal:u.signal},type:"validateAsync"}))}catch(F){p(F)}},l.debounceMs)})}catch(S){f=S}const v=ge(f);this.store.setState(S=>({...S,errorMap:{...S.errorMap,[Ut(i)]:v}})),h(v)}))}let o=[];return a.length&&(o=await Promise.all(a)),this.store.setState(l=>({...l,isFormValidating:!1})),o.filter(Boolean)},this.validate=i=>{const{hasErrored:r}=this.validateSync(i);return r&&!this.options.asyncAlways?this.state.errors:this.validateAsync(i)},this.handleSubmit=async()=>{var i,r,a,o,l,c;if(this.store.setState(u=>({...u,isSubmitted:!1,submissionAttempts:u.submissionAttempts+1})),!this.state.canSubmit)return;this.store.setState(u=>({...u,isSubmitting:!0}));const d=()=>{this.store.setState(u=>({...u,isSubmitting:!1}))};if(await this.validateAllFields("submit"),!this.state.isFieldsValid){d(),(r=(i=this.options).onSubmitInvalid)==null||r.call(i,{value:this.state.values,formApi:this});return}if(await this.validate("submit"),!this.state.isValid){d(),(o=(a=this.options).onSubmitInvalid)==null||o.call(a,{value:this.state.values,formApi:this});return}try{await((c=(l=this.options).onSubmit)==null?void 0:c.call(l,{value:this.state.values,formApi:this})),this.store.batch(()=>{this.store.setState(u=>({...u,isSubmitted:!0})),d()})}catch(u){throw d(),u}},this.getFieldValue=i=>He(this.state.values,i),this.getFieldMeta=i=>this.state.fieldMeta[i],this.getFieldInfo=i=>{var r;return(r=this.fieldInfo)[i]||(r[i]={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0}})},this.setFieldMeta=(i,r)=>{this.store.setState(a=>({...a,fieldMeta:{...a.fieldMeta,[i]:$e(r,a.fieldMeta[i])}}))},this.resetFieldMeta=i=>Object.keys(i).reduce((r,a)=>{const o=a;return r[o]={isValidating:!1,isTouched:!1,isDirty:!1,isPristine:!0,errors:[],errorMap:{}},r},{}),this.setFieldValue=(i,r,a)=>{const o=(a==null?void 0:a.dontUpdateMeta)??!1;this.store.batch(()=>{o||this.setFieldMeta(i,l=>({...l,isTouched:!0,isDirty:!0})),this.store.setState(l=>({...l,values:qt(l.values,i,r)}))})},this.deleteField=i=>{this.store.setState(r=>{const a={...r};return a.values=ds(a.values,i),delete a.fieldMeta[i],a}),delete this.fieldInfo[i]},this.pushFieldValue=(i,r,a)=>{this.setFieldValue(i,o=>[...Array.isArray(o)?o:[],r],a),this.validateField(i,"change")},this.insertFieldValue=async(i,r,a,o)=>{this.setFieldValue(i,l=>[...l.slice(0,r),a,...l.slice(r)],o),await this.validateField(i,"change")},this.replaceFieldValue=async(i,r,a,o)=>{this.setFieldValue(i,l=>l.map((c,d)=>d===r?a:c),o),await this.validateField(i,"change"),await this.validateArrayFieldsStartingFrom(i,r,"change")},this.removeFieldValue=async(i,r,a)=>{const o=this.getFieldValue(i),l=Array.isArray(o)?Math.max(o.length-1,0):null;if(this.setFieldValue(i,c=>c.filter((d,u)=>u!==r),a),l!==null){const c=`${i}[${l}]`;Object.keys(this.fieldInfo).filter(u=>u.startsWith(c)).forEach(u=>this.deleteField(u))}await this.validateField(i,"change"),await this.validateArrayFieldsStartingFrom(i,r,"change")},this.swapFieldValues=(i,r,a,o)=>{this.setFieldValue(i,l=>{const c=l[r],d=l[a];return qt(qt(l,`${r}`,d),`${a}`,c)},o),this.validateField(i,"change"),this.validateField(`${i}[${r}]`,"change"),this.validateField(`${i}[${a}]`,"change")},this.moveFieldValues=(i,r,a,o)=>{this.setFieldValue(i,l=>(l.splice(a,0,l.splice(r,1)[0]),l),o),this.validateField(i,"change"),this.validateField(`${i}[${r}]`,"change"),this.validateField(`${i}[${a}]`,"change")},this.store=new Be(Kt({...t==null?void 0:t.defaultState,values:(t==null?void 0:t.defaultValues)??((e=t==null?void 0:t.defaultState)==null?void 0:e.values),isFormValid:!0}),{onUpdate:()=>{var i,r;let{state:a}=this.store;const o=Object.values(a.fieldMeta),l=o.some(m=>m==null?void 0:m.isValidating),c=!o.some(m=>(m==null?void 0:m.errorMap)&&gs(Object.values(m.errorMap).filter(Boolean))),d=o.some(m=>m==null?void 0:m.isTouched),u=o.some(m=>m==null?void 0:m.isDirty),h=!u,f=l||a.isFormValidating;a.errors=Object.values(a.errorMap).filter(m=>m!==void 0);const v=a.errors.length===0,S=c&&v,p=a.submissionAttempts===0&&!d||!f&&!a.isSubmitting&&S;a={...a,isFieldsValidating:l,isFieldsValid:c,isFormValid:v,isValid:S,canSubmit:p,isTouched:d,isPristine:h,isDirty:u},this.state=a,this.store.state=this.state;const F=((i=this.options.transform)==null?void 0:i.deps)??[];(F.length!==this.prevTransformArray.length||F.some((m,b)=>m!==this.prevTransformArray[b]))&&((r=this.options.transform)==null||r.fn(this),this.store.state=this.state,this.prevTransformArray=F)}}),this.state=this.store.state,this.update(t||{})}runValidator(t){const e=this.options.validatorAdapter;return e&&typeof t.validate!="function"?e()[t.type](t.value,t.validate):t.validate(t.value)}}function ge(s){if(s)return typeof s!="string"?"Invalid Form Values":s}function Ut(s){switch(s){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"change":default:return"onChange"}}class Ps{constructor(t){this.options={},this.mount=()=>{const e=this.getInfo();e.instance=this;const i=this.form.store.subscribe(()=>{this.store.batch(()=>{const a=this.getValue(),o=this.getMeta();a!==this.state.value&&this.store.setState(l=>({...l,value:a})),o!==this.state.meta&&this.store.setState(l=>({...l,meta:o}))})});this.update(this.options);const{onMount:r}=this.options.validators||{};if(r){const a=this.runValidator({validate:r,value:{value:this.state.value,fieldApi:this},type:"validate"});a&&this.setMeta(o=>({...o,errorMap:{...o==null?void 0:o.errorMap,onMount:a}}))}return()=>{i()}},this.update=e=>{if(this.state.value===void 0){const i=He(e.form.options.defaultValues,e.name);e.defaultValue!==void 0?this.setValue(e.defaultValue,{dontUpdateMeta:!0}):i!==void 0&&this.setValue(i,{dontUpdateMeta:!0})}this._getMeta()===void 0&&this.setMeta(this.state.meta),this.options=e},this.getValue=()=>this.form.getFieldValue(this.name),this.setValue=(e,i)=>{this.form.setFieldValue(this.name,e,i),this.validate("change")},this._getMeta=()=>this.form.getFieldMeta(this.name),this.getMeta=()=>this._getMeta()??{isValidating:!1,isTouched:!1,isDirty:!1,isPristine:!0,errors:[],errorMap:{},...this.options.defaultMeta},this.setMeta=e=>this.form.setFieldMeta(this.name,e),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=(e,i)=>this.form.pushFieldValue(this.name,e,i),this.insertValue=(e,i,r)=>this.form.insertFieldValue(this.name,e,i,r),this.replaceValue=(e,i,r)=>this.form.replaceFieldValue(this.name,e,i,r),this.removeValue=(e,i)=>this.form.removeFieldValue(this.name,e,i),this.swapValues=(e,i,r)=>this.form.swapFieldValues(this.name,e,i,r),this.moveValue=(e,i,r)=>this.form.moveFieldValues(this.name,e,i,r),this.getLinkedFields=e=>{const i=Object.values(this.form.fieldInfo),r=[];for(const a of i){if(!a.instance)continue;const{onChangeListenTo:o,onBlurListenTo:l}=a.instance.options.validators||{};e==="change"&&(o!=null&&o.includes(this.name))&&r.push(a.instance),e==="blur"&&(l!=null&&l.includes(this.name))&&r.push(a.instance)}return r},this.validateSync=e=>{const i=ie(e,this.options),a=this.getLinkedFields(e).reduce((c,d)=>{const u=ie(e,d.options);return u.forEach(h=>{h.field=d}),c.concat(u)},[]);let o=!1;this.form.store.batch(()=>{const c=(d,u)=>{const h=be(d.runValidator({validate:u.validate,value:{value:d.getValue(),fieldApi:d},type:"validate"})),f=lt(u.cause);d.state.meta.errorMap[f]!==h&&d.setMeta(v=>({...v,errorMap:{...v.errorMap,[lt(u.cause)]:h}})),h&&(o=!0)};for(const d of i)d.validate&&c(this,d);for(const d of a)d.validate&&c(d.field,d)});const l=lt("submit");return this.state.meta.errorMap[l]&&e!=="submit"&&!o&&this.setMeta(c=>({...c,errorMap:{...c.errorMap,[l]:void 0}})),{hasErrored:o}},this.validateAsync=async e=>{const i=se(e,this.options),r=this.getLinkedFields(e),a=r.reduce((u,h)=>{const f=se(e,h.options);return f.forEach(v=>{v.field=h}),u.concat(f)},[]);this.state.meta.isValidating||this.setMeta(u=>({...u,isValidating:!0}));for(const u of r)u.setMeta(h=>({...h,isValidating:!0}));const o=[],l=[],c=(u,h,f)=>{const v=lt(h.cause),S=u.getInfo().validationMetaMap[v];S==null||S.lastAbortController.abort();const p=new AbortController;this.getInfo().validationMetaMap[v]={lastAbortController:p},f.push(new Promise(async F=>{let M;try{M=await new Promise((b,O)=>{setTimeout(async()=>{if(p.signal.aborted)return b(void 0);try{b(await this.runValidator({validate:h.validate,value:{value:u.getValue(),fieldApi:u,signal:p.signal},type:"validateAsync"}))}catch(E){O(E)}},h.debounceMs)})}catch(b){M=b}if(p.signal.aborted)return F(void 0);const m=be(M);u.setMeta(b=>({...b,errorMap:{...b==null?void 0:b.errorMap,[lt(e)]:m}})),F(m)}))};for(const u of i)u.validate&&c(this,u,o);for(const u of a)u.validate&&c(u.field,u,l);let d=[];(o.length||l.length)&&(d=await Promise.all(o),await Promise.all(l)),this.setMeta(u=>({...u,isValidating:!1}));for(const u of r)u.setMeta(h=>({...h,isValidating:!1}));return d.filter(Boolean)},this.validate=e=>{var i;if(!this.state.meta.isTouched)return[];try{this.form.validate(e)}catch{}const{hasErrored:r}=this.validateSync(e);return r&&!this.options.asyncAlways?((i=this.getInfo().validationMetaMap[lt(e)])==null||i.lastAbortController.abort(),this.state.meta.errors):this.validateAsync(e)},this.handleChange=e=>{this.setValue(e)},this.handleBlur=()=>{this.state.meta.isTouched||(this.setMeta(i=>({...i,isTouched:!0})),this.validate("change")),this.validate("blur")},this.form=t.form,this.name=t.name,t.defaultValue!==void 0&&this.form.setFieldValue(this.name,t.defaultValue,{dontUpdateMeta:!0}),this.store=new Be({value:this.getValue(),meta:this._getMeta()??{isValidating:!1,isTouched:!1,isDirty:!1,isPristine:!0,errors:[],errorMap:{},...t.defaultMeta}},{onUpdate:()=>{const e=this.store.state;e.meta.errors=Object.values(e.meta.errorMap).filter(i=>i!==void 0),e.meta.isPristine=!e.meta.isDirty,this.prevState=e,this.state=e}}),this.state=this.store.state,this.prevState=this.state,this.options=t}runValidator(t){const e=[this.form.options.validatorAdapter,this.options.validatorAdapter];for(const i of e)if(i&&typeof t.validate!="function")return i()[t.type](t.value,t.validate);return t.validate(t.value)}}function be(s){if(s)return typeof s!="string"?"Invalid Form Values":s}function lt(s){switch(s){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"change":default:return"onChange"}}export{Ps as F,Ss as Q,Be as S,ws as a,Vs as b,As as c,Ms as d,$e as f,R as n};
|