1 line
No EOL
30 KiB
JavaScript
1 line
No EOL
30 KiB
JavaScript
!function(){"use strict";var t={d:function(e,s){for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{QueryClient:function(){return K},QueryClientProvider:function(){return G},createQueryClient:function(){return ut},useMutation:function(){return W},useQuery:function(){return ot},useQueryClient:function(){return j}});var s="undefined"==typeof window||"Deno"in window;function i(){}function r(t){return"number"==typeof t&&t>=0&&t!==1/0}function n(t,e){return Math.max(t+(e||0)-Date.now(),0)}function a(t,e){const{type:s="all",exact:i,fetchStatus:r,predicate:n,queryKey:a,stale:o}=t;if(a)if(i){if(e.queryHash!==u(a,e.options))return!1}else if(!c(e.queryKey,a))return!1;if("all"!==s){const t=e.isActive();if("active"===s&&!t)return!1;if("inactive"===s&&t)return!1}return!("boolean"==typeof o&&e.isStale()!==o||void 0!==r&&r!==e.state.fetchStatus||n&&!n(e))}function o(t,e){const{exact:s,status:i,predicate:r,mutationKey:n}=t;if(n){if(!e.options.mutationKey)return!1;if(s){if(h(e.options.mutationKey)!==h(n))return!1}else if(!c(e.options.mutationKey,n))return!1}return!(i&&e.state.status!==i||r&&!r(e))}function u(t,e){return(e?.queryKeyHashFn||h)(t)}function h(t){return JSON.stringify(t,((t,e)=>p(e)?Object.keys(e).sort().reduce(((t,s)=>(t[s]=e[s],t)),{}):e))}function c(t,e){return t===e||typeof t==typeof e&&!(!t||!e||"object"!=typeof t||"object"!=typeof e)&&!Object.keys(e).some((s=>!c(t[s],e[s])))}function l(t,e){if(t===e)return t;const s=f(t)&&f(e);if(s||p(t)&&p(e)){const i=s?t.length:Object.keys(t).length,r=s?e:Object.keys(e),n=r.length,a=s?[]:{};let o=0;for(let i=0;i<n;i++){const n=s?i:r[i];a[n]=l(t[n],e[n]),a[n]===t[n]&&o++}return i===n&&o===i?t:a}return e}function d(t,e){if(t&&!e||e&&!t)return!1;for(const s in t)if(t[s]!==e[s])return!1;return!0}function f(t){return Array.isArray(t)&&t.length===Object.keys(t).length}function p(t){if(!y(t))return!1;const e=t.constructor;if(void 0===e)return!0;const s=e.prototype;return!!y(s)&&!!s.hasOwnProperty("isPrototypeOf")}function y(t){return"[object Object]"===Object.prototype.toString.call(t)}function m(t){return new Promise((e=>{setTimeout(e,t)}))}function v(t){m(0).then(t)}function b(t,e,s){return"function"==typeof s.structuralSharing?s.structuralSharing(t,e):!1!==s.structuralSharing?l(t,e):e}function g(t,e,s=0){const i=[...t,e];return s&&i.length>s?i.slice(1):i}function O(t,e,s=0){const i=[e,...t];return s&&i.length>s?i.slice(0,-1):i}var R=function(){let t=[],e=0,s=t=>{t()},i=t=>{t()};const r=i=>{e?t.push(i):v((()=>{s(i)}))};return{batch:r=>{let n;e++;try{n=r()}finally{e--,e||(()=>{const e=t;t=[],e.length&&v((()=>{i((()=>{e.forEach((t=>{s(t)}))}))}))})()}return n},batchCalls:t=>(...e)=>{r((()=>{t(...e)}))},schedule:r,setNotifyFunction:t=>{s=t},setBatchNotifyFunction:t=>{i=t}}}(),C=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},w=new class extends C{#t;#e;#s;constructor(){super(),this.#s=t=>{if(!s&&window.addEventListener){const e=()=>t();return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#s=t,this.#e?.(),this.#e=t((t=>{"boolean"==typeof t?this.setFocused(t):this.onFocus()}))}setFocused(t){this.#t!==t&&(this.#t=t,this.onFocus())}onFocus(){this.listeners.forEach((t=>{t()}))}isFocused(){return"boolean"==typeof this.#t?this.#t:"hidden"!==globalThis.document?.visibilityState}},S=new class extends C{#i=!0;#e;#s;constructor(){super(),this.#s=t=>{if(!s&&window.addEventListener){const e=()=>t(!0),s=()=>t(!1);return window.addEventListener("online",e,!1),window.addEventListener("offline",s,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",s)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#s=t,this.#e?.(),this.#e=t(this.setOnline.bind(this))}setOnline(t){this.#i!==t&&(this.#i=t,this.listeners.forEach((e=>{e(t)})))}isOnline(){return this.#i}};function q(t){return Math.min(1e3*2**t,3e4)}function Q(t){return"online"!==(t??"online")||S.isOnline()}var F=class{constructor(t){this.revert=t?.revert,this.silent=t?.silent}};function P(t){return t instanceof F}function E(t){let e,i,r,n=!1,a=0,o=!1;const u=new Promise(((t,e)=>{i=t,r=e})),h=()=>!w.isFocused()||"always"!==t.networkMode&&!S.isOnline(),c=s=>{o||(o=!0,t.onSuccess?.(s),e?.(),i(s))},l=s=>{o||(o=!0,t.onError?.(s),e?.(),r(s))},d=()=>new Promise((s=>{e=t=>{const e=o||!h();return e&&s(t),e},t.onPause?.()})).then((()=>{e=void 0,o||t.onContinue?.()})),f=()=>{if(o)return;let e;try{e=t.fn()}catch(t){e=Promise.reject(t)}Promise.resolve(e).then(c).catch((e=>{if(o)return;const i=t.retry??(s?0:3),r=t.retryDelay??q,u="function"==typeof r?r(a,e):r,c=!0===i||"number"==typeof i&&a<i||"function"==typeof i&&i(a,e);!n&&c?(a++,t.onFail?.(a,e),m(u).then((()=>{if(h())return d()})).then((()=>{n?l(e):f()}))):l(e)}))};return Q(t.networkMode)?f():d().then(f),{promise:u,cancel:e=>{o||(l(new F(e)),t.abort?.())},continue:()=>{const t=e?.();return t?u:Promise.resolve()},cancelRetry:()=>{n=!0},continueRetry:()=>{n=!1}}}var M=class{#r;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),r(this.gcTime)&&(this.#r=setTimeout((()=>{this.optionalRemove()}),this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,t??(s?1/0:3e5))}clearGcTimeout(){this.#r&&(clearTimeout(this.#r),this.#r=void 0)}},D=class extends M{constructor(t){super(),this.#n=!1,this.#a=t.defaultOptions,this.#o(t.options),this.#u=[],this.#h=t.cache,this.queryKey=t.queryKey,this.queryHash=t.queryHash,this.#c=t.state||function(t){const e="function"==typeof t.initialData?t.initialData():t.initialData,s=void 0!==e,i=s?"function"==typeof t.initialDataUpdatedAt?t.initialDataUpdatedAt():t.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:s?i??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:s?"success":"pending",fetchStatus:"idle"}}(this.options),this.state=this.#c,this.scheduleGc()}#c;#l;#h;#d;#f;#u;#a;#n;get meta(){return this.options.meta}#o(t){this.options={...this.#a,...t},this.updateGcTime(this.options.gcTime)}optionalRemove(){this.#u.length||"idle"!==this.state.fetchStatus||this.#h.remove(this)}setData(t,e){const s=b(this.state.data,t,this.options);return this.#p({data:s,type:"success",dataUpdatedAt:e?.updatedAt,manual:e?.manual}),s}setState(t,e){this.#p({type:"setState",state:t,setStateOptions:e})}cancel(t){const e=this.#d;return this.#f?.cancel(t),e?e.then(i).catch(i):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#c)}isActive(){return this.#u.some((t=>!1!==t.options.enabled))}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||this.#u.some((t=>t.getCurrentResult().isStale))}isStaleByTime(t=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!n(this.state.dataUpdatedAt,t)}onFocus(){const t=this.#u.find((t=>t.shouldFetchOnWindowFocus()));t?.refetch({cancelRefetch:!1}),this.#f?.continue()}onOnline(){const t=this.#u.find((t=>t.shouldFetchOnReconnect()));t?.refetch({cancelRefetch:!1}),this.#f?.continue()}addObserver(t){this.#u.includes(t)||(this.#u.push(t),this.clearGcTimeout(),this.#h.notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.#u.includes(t)&&(this.#u=this.#u.filter((e=>e!==t)),this.#u.length||(this.#f&&(this.#n?this.#f.cancel({revert:!0}):this.#f.cancelRetry()),this.scheduleGc()),this.#h.notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.#u.length}invalidate(){this.state.isInvalidated||this.#p({type:"invalidate"})}fetch(t,e){if("idle"!==this.state.fetchStatus)if(this.state.dataUpdatedAt&&e?.cancelRefetch)this.cancel({silent:!0});else if(this.#d)return this.#f?.continueRetry(),this.#d;if(t&&this.#o(t),!this.options.queryFn){const t=this.#u.find((t=>t.options.queryFn));t&&this.#o(t.options)}const s=new AbortController,i={queryKey:this.queryKey,meta:this.meta},r=t=>{Object.defineProperty(t,"signal",{enumerable:!0,get:()=>(this.#n=!0,s.signal)})};r(i);const n={fetchOptions:e,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:()=>this.options.queryFn?(this.#n=!1,this.options.persister?this.options.persister(this.options.queryFn,i,this):this.options.queryFn(i)):Promise.reject(new Error(`Missing queryFn: '${this.options.queryHash}'`))};r(n),this.options.behavior?.onFetch(n,this),this.#l=this.state,"idle"!==this.state.fetchStatus&&this.state.fetchMeta===n.fetchOptions?.meta||this.#p({type:"fetch",meta:n.fetchOptions?.meta});const a=t=>{P(t)&&t.silent||this.#p({type:"error",error:t}),P(t)||(this.#h.config.onError?.(t,this),this.#h.config.onSettled?.(this.state.data,t,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return this.#f=E({fn:n.fetchFn,abort:s.abort.bind(s),onSuccess:t=>{void 0!==t?(this.setData(t),this.#h.config.onSuccess?.(t,this),this.#h.config.onSettled?.(t,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1):a(new Error(`${this.queryHash} data is undefined`))},onError:a,onFail:(t,e)=>{this.#p({type:"failed",failureCount:t,error:e})},onPause:()=>{this.#p({type:"pause"})},onContinue:()=>{this.#p({type:"continue"})},retry:n.options.retry,retryDelay:n.options.retryDelay,networkMode:n.options.networkMode}),this.#d=this.#f.promise,this.#d}#p(t){this.state=(e=>{switch(t.type){case"failed":return{...e,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...e,fetchStatus:"paused"};case"continue":return{...e,fetchStatus:"fetching"};case"fetch":return{...e,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:t.meta??null,fetchStatus:Q(this.options.networkMode)?"fetching":"paused",...!e.dataUpdatedAt&&{error:null,status:"pending"}};case"success":return{...e,data:t.data,dataUpdateCount:e.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const s=t.error;return P(s)&&s.revert&&this.#l?{...this.#l,fetchStatus:"idle"}:{...e,error:s,errorUpdateCount:e.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:e.fetchFailureCount+1,fetchFailureReason:s,fetchStatus:"idle",status:"error"};case"invalidate":return{...e,isInvalidated:!0};case"setState":return{...e,...t.state}}})(this.state),R.batch((()=>{this.#u.forEach((t=>{t.onQueryUpdate()})),this.#h.notify({query:this,type:"updated",action:t})}))}},I=class extends C{constructor(t={}){super(),this.config=t,this.#y=new Map}#y;build(t,e,s){const i=e.queryKey,r=e.queryHash??u(i,e);let n=this.get(r);return n||(n=new D({cache:this,queryKey:i,queryHash:r,options:t.defaultQueryOptions(e),state:s,defaultOptions:t.getQueryDefaults(i)}),this.add(n)),n}add(t){this.#y.has(t.queryHash)||(this.#y.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=this.#y.get(t.queryHash);e&&(t.destroy(),e===t&&this.#y.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){R.batch((()=>{this.getAll().forEach((t=>{this.remove(t)}))}))}get(t){return this.#y.get(t)}getAll(){return[...this.#y.values()]}find(t){const e={exact:!0,...t};return this.getAll().find((t=>a(e,t)))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter((e=>a(t,e))):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()}))}))}},A=class extends M{constructor(t){super(),this.mutationId=t.mutationId,this.#a=t.defaultOptions,this.#m=t.mutationCache,this.#u=[],this.state=t.state||{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0},this.setOptions(t.options),this.scheduleGc()}#u;#a;#m;#f;setOptions(t){this.options={...this.#a,...t},this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){this.#u.includes(t)||(this.#u.push(t),this.clearGcTimeout(),this.#m.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#u=this.#u.filter((e=>e!==t)),this.scheduleGc(),this.#m.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#u.length||("pending"===this.state.status?this.scheduleGc():this.#m.remove(this))}continue(){return this.#f?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>(this.#f=E({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(t,e)=>{this.#p({type:"failed",failureCount:t,error:e})},onPause:()=>{this.#p({type:"pause"})},onContinue:()=>{this.#p({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode}),this.#f.promise),s="pending"===this.state.status;try{if(!s){this.#p({type:"pending",variables:t}),await(this.#m.config.onMutate?.(t,this));const e=await(this.options.onMutate?.(t));e!==this.state.context&&this.#p({type:"pending",context:e,variables:t})}const i=await e();return await(this.#m.config.onSuccess?.(i,t,this.state.context,this)),await(this.options.onSuccess?.(i,t,this.state.context)),await(this.#m.config.onSettled?.(i,null,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(i,null,t,this.state.context)),this.#p({type:"success",data:i}),i}catch(e){try{throw await(this.#m.config.onError?.(e,t,this.state.context,this)),await(this.options.onError?.(e,t,this.state.context)),await(this.#m.config.onSettled?.(void 0,e,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(void 0,e,t,this.state.context)),e}finally{this.#p({type:"error",error:e})}}}#p(t){this.state=(e=>{switch(t.type){case"failed":return{...e,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...e,isPaused:!0};case"continue":return{...e,isPaused:!1};case"pending":return{...e,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:!Q(this.options.networkMode),status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...e,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...e,data:void 0,error:t.error,failureCount:e.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}})(this.state),R.batch((()=>{this.#u.forEach((e=>{e.onMutationUpdate(t)})),this.#m.notify({mutation:this,type:"updated",action:t})}))}},T=class extends C{constructor(t={}){super(),this.config=t,this.#v=[],this.#b=0}#v;#b;#g;build(t,e,s){const i=new A({mutationCache:this,mutationId:++this.#b,options:t.defaultMutationOptions(e),state:s});return this.add(i),i}add(t){this.#v.push(t),this.notify({type:"added",mutation:t})}remove(t){this.#v=this.#v.filter((e=>e!==t)),this.notify({type:"removed",mutation:t})}clear(){R.batch((()=>{this.#v.forEach((t=>{this.remove(t)}))}))}getAll(){return this.#v}find(t){const e={exact:!0,...t};return this.#v.find((t=>o(e,t)))}findAll(t={}){return this.#v.filter((e=>o(t,e)))}notify(t){R.batch((()=>{this.listeners.forEach((e=>{e(t)}))}))}resumePausedMutations(){return this.#g=(this.#g??Promise.resolve()).then((()=>{const t=this.#v.filter((t=>t.state.isPaused));return R.batch((()=>t.reduce(((t,e)=>t.then((()=>e.continue().catch(i)))),Promise.resolve())))})).then((()=>{this.#g=void 0})),this.#g}};function x(t,{pages:e,pageParams:s}){const i=e.length-1;return t.getNextPageParam(e[i],e,s[i],s)}function U(t,{pages:e,pageParams:s}){return t.getPreviousPageParam?.(e[0],e,s[0],s)}var K=class{#O;#m;#a;#R;#C;#w;#S;#q;constructor(t={}){this.#O=t.queryCache||new I,this.#m=t.mutationCache||new T,this.#a=t.defaultOptions||{},this.#R=new Map,this.#C=new Map,this.#w=0}mount(){this.#w++,1===this.#w&&(this.#S=w.subscribe((()=>{w.isFocused()&&(this.resumePausedMutations(),this.#O.onFocus())})),this.#q=S.subscribe((()=>{S.isOnline()&&(this.resumePausedMutations(),this.#O.onOnline())})))}unmount(){this.#w--,0===this.#w&&(this.#S?.(),this.#S=void 0,this.#q?.(),this.#q=void 0)}isFetching(t){return this.#O.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#m.findAll({...t,status:"pending"}).length}getQueryData(t){return this.#O.find({queryKey:t})?.state.data}ensureQueryData(t){const e=this.getQueryData(t.queryKey);return void 0!==e?Promise.resolve(e):this.fetchQuery(t)}getQueriesData(t){return this.getQueryCache().findAll(t).map((({queryKey:t,state:e})=>[t,e.data]))}setQueryData(t,e,s){const i=this.#O.find({queryKey:t}),r=i?.state.data,n=function(t,e){return"function"==typeof t?t(e):t}(e,r);if(void 0===n)return;const a=this.defaultQueryOptions({queryKey:t});return this.#O.build(this,a).setData(n,{...s,manual:!0})}setQueriesData(t,e,s){return R.batch((()=>this.getQueryCache().findAll(t).map((({queryKey:t})=>[t,this.setQueryData(t,e,s)]))))}getQueryState(t){return this.#O.find({queryKey:t})?.state}removeQueries(t){const e=this.#O;R.batch((()=>{e.findAll(t).forEach((t=>{e.remove(t)}))}))}resetQueries(t,e){const s=this.#O,i={type:"active",...t};return R.batch((()=>(s.findAll(t).forEach((t=>{t.reset()})),this.refetchQueries(i,e))))}cancelQueries(t={},e={}){const s={revert:!0,...e},r=R.batch((()=>this.#O.findAll(t).map((t=>t.cancel(s)))));return Promise.all(r).then(i).catch(i)}invalidateQueries(t={},e={}){return R.batch((()=>{if(this.#O.findAll(t).forEach((t=>{t.invalidate()})),"none"===t.refetchType)return Promise.resolve();const s={...t,type:t.refetchType??t.type??"active"};return this.refetchQueries(s,e)}))}refetchQueries(t={},e){const s={...e,cancelRefetch:e?.cancelRefetch??!0},r=R.batch((()=>this.#O.findAll(t).filter((t=>!t.isDisabled())).map((t=>{let e=t.fetch(void 0,s);return s.throwOnError||(e=e.catch(i)),"paused"===t.state.fetchStatus?Promise.resolve():e}))));return Promise.all(r).then(i)}fetchQuery(t){const e=this.defaultQueryOptions(t);void 0===e.retry&&(e.retry=!1);const s=this.#O.build(this,e);return s.isStaleByTime(e.staleTime)?s.fetch(e):Promise.resolve(s.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(i).catch(i)}fetchInfiniteQuery(t){return t.behavior=(e=t.pages,{onFetch:(t,s)=>{const i=async()=>{const s=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,r=t.state.data?.pages||[],n=t.state.data?.pageParams||[],a={pages:[],pageParams:[]};let o=!1;const u=t.options.queryFn||(()=>Promise.reject(new Error(`Missing queryFn: '${t.options.queryHash}'`))),h=async(e,s,i)=>{if(o)return Promise.reject();if(null==s&&e.pages.length)return Promise.resolve(e);const r={queryKey:t.queryKey,pageParam:s,direction:i?"backward":"forward",meta:t.options.meta};var n;n=r,Object.defineProperty(n,"signal",{enumerable:!0,get:()=>(t.signal.aborted?o=!0:t.signal.addEventListener("abort",(()=>{o=!0})),t.signal)});const a=await u(r),{maxPages:h}=t.options,c=i?O:g;return{pages:c(e.pages,a,h),pageParams:c(e.pageParams,s,h)}};let c;if(i&&r.length){const t="backward"===i,e={pages:r,pageParams:n},a=(t?U:x)(s,e);c=await h(e,a,t)}else{c=await h(a,n[0]??s.initialPageParam);const t=e??r.length;for(let e=1;e<t;e++){const t=x(s,c);c=await h(c,t)}}return c};t.options.persister?t.fetchFn=()=>t.options.persister?.(i,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},s):t.fetchFn=i}}),this.fetchQuery(t);var e}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(i).catch(i)}resumePausedMutations(){return this.#m.resumePausedMutations()}getQueryCache(){return this.#O}getMutationCache(){return this.#m}getDefaultOptions(){return this.#a}setDefaultOptions(t){this.#a=t}setQueryDefaults(t,e){this.#R.set(h(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#R.values()];let s={};return e.forEach((e=>{c(t,e.queryKey)&&(s={...s,...e.defaultOptions})})),s}setMutationDefaults(t,e){this.#C.set(h(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#C.values()];let s={};return e.forEach((e=>{c(t,e.mutationKey)&&(s={...s,...e.defaultOptions})})),s}defaultQueryOptions(t){if(t?._defaulted)return t;const e={...this.#a.queries,...t?.queryKey&&this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=u(e.queryKey,e)),void 0===e.refetchOnReconnect&&(e.refetchOnReconnect="always"!==e.networkMode),void 0===e.throwOnError&&(e.throwOnError=!!e.suspense),void 0===e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#a.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#O.clear(),this.#m.clear()}},k=window.React,L=k.createContext(void 0),j=t=>{const e=k.useContext(L);if(t)return t;if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e},G=({client:t,children:e})=>(k.useEffect((()=>(t.mount(),()=>{t.unmount()})),[t]),k.createElement(L.Provider,{value:t},e)),H=class extends C{constructor(t,e){super(),this.#Q=void 0,this.#F=t,this.setOptions(e),this.bindMethods(),this.#P()}#F;#Q;#E;#M;bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){const e=this.options;this.options=this.#F.defaultMutationOptions(t),d(e,this.options)||this.#F.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#E,observer:this}),this.#E?.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#E?.removeObserver(this)}onMutationUpdate(t){this.#P(),this.#D(t)}getCurrentResult(){return this.#Q}reset(){this.#E=void 0,this.#P(),this.#D()}mutate(t,e){return this.#M=e,this.#E?.removeObserver(this),this.#E=this.#F.getMutationCache().build(this.#F,this.options),this.#E.addObserver(this),this.#E.execute(t)}#P(){const t=this.#E?.state??{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0};this.#Q={...t,isPending:"pending"===t.status,isSuccess:"success"===t.status,isError:"error"===t.status,isIdle:"idle"===t.status,mutate:this.mutate,reset:this.reset}}#D(t){R.batch((()=>{this.#M&&this.hasListeners()&&("success"===t?.type?(this.#M.onSuccess?.(t.data,this.#Q.variables,this.#Q.context),this.#M.onSettled?.(t.data,null,this.#Q.variables,this.#Q.context)):"error"===t?.type&&(this.#M.onError?.(t.error,this.#Q.variables,this.#Q.context),this.#M.onSettled?.(void 0,t.error,this.#Q.variables,this.#Q.context))),this.listeners.forEach((t=>{t(this.#Q)}))}))}};function _(t,e){return"function"==typeof t?t(...e):!!t}function W(t,e){const s=j(e),[i]=k.useState((()=>new H(s,t)));k.useEffect((()=>{i.setOptions(t)}),[i,t]);const r=k.useSyncExternalStore(k.useCallback((t=>i.subscribe(R.batchCalls(t))),[i]),(()=>i.getCurrentResult()),(()=>i.getCurrentResult())),n=k.useCallback(((t,e)=>{i.mutate(t,e).catch(B)}),[i]);if(r.error&&_(i.options.throwOnError,[r.error]))throw r.error;return{...r,mutate:n,mutateAsync:r.mutate}}function B(){}var N=class extends C{constructor(t,e){super(),this.#I=void 0,this.#A=void 0,this.#Q=void 0,this.#T=new Set,this.#F=t,this.options=e,this.#x=null,this.bindMethods(),this.setOptions(e)}#F;#I;#A;#Q;#U;#K;#x;#k;#L;#j;#G;#H;#_;#T;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.size&&(this.#I.addObserver(this),z(this.#I,this.options)&&this.#W(),this.#B())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return $(this.#I,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return $(this.#I,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#N(),this.#z(),this.#I.removeObserver(this)}setOptions(t,e){const s=this.options,i=this.#I;if(this.options=this.#F.defaultQueryOptions(t),d(s,this.options)||this.#F.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#I,observer:this}),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled)throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=s.queryKey),this.#$();const r=this.hasListeners();r&&V(this.#I,i,this.options,s)&&this.#W(),this.updateResult(e),!r||this.#I===i&&this.options.enabled===s.enabled&&this.options.staleTime===s.staleTime||this.#V();const n=this.#J();!r||this.#I===i&&this.options.enabled===s.enabled&&n===this.#_||this.#X(n)}getOptimisticResult(t){const e=this.#F.getQueryCache().build(this.#F,t),s=this.createResult(e,t);return i=s,!d(this.getCurrentResult(),i)&&(this.#Q=s,this.#K=this.options,this.#U=this.#I.state),s;var i}getCurrentResult(){return this.#Q}trackResult(t){const e={};return Object.keys(t).forEach((s=>{Object.defineProperty(e,s,{configurable:!1,enumerable:!0,get:()=>(this.#T.add(s),t[s])})})),e}getCurrentQuery(){return this.#I}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=this.#F.defaultQueryOptions(t),s=this.#F.getQueryCache().build(this.#F,e);return s.isFetchingOptimistic=!0,s.fetch().then((()=>this.createResult(s,e)))}fetch(t){return this.#W({...t,cancelRefetch:t.cancelRefetch??!0}).then((()=>(this.updateResult(),this.#Q)))}#W(t){this.#$();let e=this.#I.fetch(this.options,t);return t?.throwOnError||(e=e.catch(i)),e}#V(){if(this.#N(),s||this.#Q.isStale||!r(this.options.staleTime))return;const t=n(this.#Q.dataUpdatedAt,this.options.staleTime)+1;this.#G=setTimeout((()=>{this.#Q.isStale||this.updateResult()}),t)}#J(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#I):this.options.refetchInterval)??!1}#X(t){this.#z(),this.#_=t,!s&&!1!==this.options.enabled&&r(this.#_)&&0!==this.#_&&(this.#H=setInterval((()=>{(this.options.refetchIntervalInBackground||w.isFocused())&&this.#W()}),this.#_))}#B(){this.#V(),this.#X(this.#J())}#N(){this.#G&&(clearTimeout(this.#G),this.#G=void 0)}#z(){this.#H&&(clearInterval(this.#H),this.#H=void 0)}createResult(t,e){const s=this.#I,i=this.options,r=this.#Q,n=this.#U,a=this.#K,o=t!==s?t.state:this.#A,{state:u}=t;let h,{error:c,errorUpdatedAt:l,fetchStatus:d,status:f}=u,p=!1;if(e._optimisticResults){const r=this.hasListeners(),n=!r&&z(t,e),a=r&&V(t,s,e,i);(n||a)&&(d=Q(t.options.networkMode)?"fetching":"paused",u.dataUpdatedAt||(f="pending")),"isRestoring"===e._optimisticResults&&(d="idle")}if(e.select&&void 0!==u.data)if(r&&u.data===n?.data&&e.select===this.#k)h=this.#L;else try{this.#k=e.select,h=e.select(u.data),h=b(r?.data,h,e),this.#L=h,this.#x=null}catch(t){this.#x=t}else h=u.data;if(void 0!==e.placeholderData&&void 0===h&&"pending"===f){let t;if(r?.isPlaceholderData&&e.placeholderData===a?.placeholderData)t=r.data;else if(t="function"==typeof e.placeholderData?e.placeholderData(this.#j?.state.data,this.#j):e.placeholderData,e.select&&void 0!==t)try{t=e.select(t),this.#x=null}catch(t){this.#x=t}void 0!==t&&(f="success",h=b(r?.data,t,e),p=!0)}this.#x&&(c=this.#x,h=this.#L,l=Date.now(),f="error");const y="fetching"===d,m="pending"===f,v="error"===f,g=m&&y;return{status:f,fetchStatus:d,isPending:m,isSuccess:"success"===f,isError:v,isInitialLoading:g,isLoading:g,data:h,dataUpdatedAt:u.dataUpdatedAt,error:c,errorUpdatedAt:l,failureCount:u.fetchFailureCount,failureReason:u.fetchFailureReason,errorUpdateCount:u.errorUpdateCount,isFetched:u.dataUpdateCount>0||u.errorUpdateCount>0,isFetchedAfterMount:u.dataUpdateCount>o.dataUpdateCount||u.errorUpdateCount>o.errorUpdateCount,isFetching:y,isRefetching:y&&!m,isLoadingError:v&&0===u.dataUpdatedAt,isPaused:"paused"===d,isPlaceholderData:p,isRefetchError:v&&0!==u.dataUpdatedAt,isStale:J(t,e),refetch:this.refetch}}updateResult(t){const e=this.#Q,s=this.createResult(this.#I,this.options);if(this.#U=this.#I.state,this.#K=this.options,d(s,e))return;void 0!==this.#U.data&&(this.#j=this.#I),this.#Q=s;const i={};!1!==t?.listeners&&(()=>{if(!e)return!0;const{notifyOnChangeProps:t}=this.options,s="function"==typeof t?t():t;if("all"===s||!s&&!this.#T.size)return!0;const i=new Set(s??this.#T);return this.options.throwOnError&&i.add("error"),Object.keys(this.#Q).some((t=>{const s=t;return this.#Q[s]!==e[s]&&i.has(s)}))})()&&(i.listeners=!0),this.#D({...i,...t})}#$(){const t=this.#F.getQueryCache().build(this.#F,this.options);if(t===this.#I)return;const e=this.#I;this.#I=t,this.#A=t.state,this.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#B()}#D(t){R.batch((()=>{t.listeners&&this.listeners.forEach((t=>{t(this.#Q)})),this.#F.getQueryCache().notify({query:this.#I,type:"observerResultsUpdated"})}))}};function z(t,e){return function(t,e){return!(!1===e.enabled||t.state.dataUpdatedAt||"error"===t.state.status&&!1===e.retryOnMount)}(t,e)||t.state.dataUpdatedAt>0&&$(t,e,e.refetchOnMount)}function $(t,e,s){if(!1!==e.enabled){const i="function"==typeof s?s(t):s;return"always"===i||!1!==i&&J(t,e)}return!1}function V(t,e,s,i){return!1!==s.enabled&&(t!==e||!1===i.enabled)&&(!s.suspense||"error"!==t.state.status)&&J(t,s)}function J(t,e){return t.isStaleByTime(e.staleTime)}var X=k.createContext(function(){let t=!1;return{clearReset:()=>{t=!1},reset:()=>{t=!0},isReset:()=>t}}()),Y=()=>k.useContext(X),Z=k.createContext(!1),tt=()=>k.useContext(Z),et=(Z.Provider,(t,e)=>{(t.suspense||t.throwOnError)&&(e.isReset()||(t.retryOnMount=!1))}),st=t=>{k.useEffect((()=>{t.clearReset()}),[t])},it=({result:t,errorResetBoundary:e,throwOnError:s,query:i})=>t.isError&&!e.isReset()&&!t.isFetching&&_(s,[t.error,i]),rt=t=>{t.suspense&&"number"!=typeof t.staleTime&&(t.staleTime=1e3)},nt=(t,e,s)=>t?.suspense&&((t,e)=>t.isLoading&&t.isFetching&&!e)(e,s),at=(t,e,s)=>e.fetchOptimistic(t).catch((()=>{s.clearReset()}));function ot(t,e){return function(t,e,s){const i=j(s),r=tt(),n=Y(),a=i.defaultQueryOptions(t);a._optimisticResults=r?"isRestoring":"optimistic",rt(a),et(a,n),st(n);const[o]=k.useState((()=>new e(i,a))),u=o.getOptimisticResult(a);if(k.useSyncExternalStore(k.useCallback((t=>{const e=r?()=>{}:o.subscribe(R.batchCalls(t));return o.updateResult(),e}),[o,r]),(()=>o.getCurrentResult()),(()=>o.getCurrentResult())),k.useEffect((()=>{o.setOptions(a,{listeners:!1})}),[a,o]),nt(a,u,r))throw at(a,o,n);if(it({result:u,errorResetBoundary:n,throwOnError:a.throwOnError,query:o.getCurrentQuery()}))throw u.error;return a.notifyOnChangeProps?u:o.trackResult(u)}(t,N,e)}function ut(){return new K({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnReconnect:!1}}})}(window.elementorV2=window.elementorV2||{}).query=e}(); |