climb-onyx-gui
Version:
Onyx Graphical User Interface
1,542 lines • 4.65 MB
JavaScript
import { jsx as be, jsxs as nr, Fragment as ms } from "react/jsx-runtime";
import * as ar from "react";
import Fr, { useContext as Dn, useRef as pr, useState as fr, useCallback as Zr, useEffect as kn, useMemo as mr, cloneElement as cb, useReducer as tH, createContext as Ry, useLayoutEffect as xu, forwardRef as cp, useImperativeHandle as db, Component as iI, Fragment as M2, memo as Hs, createElement as rH } from "react";
class eg {
constructor() {
this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
}
subscribe(t) {
const r = {
listener: t
};
return this.listeners.add(r), this.onSubscribe(), () => {
this.listeners.delete(r), this.onUnsubscribe();
};
}
hasListeners() {
return this.listeners.size > 0;
}
onSubscribe() {
}
onUnsubscribe() {
}
}
const ly = typeof window > "u" || "Deno" in window;
function jl() {
}
function nH(e, t) {
return typeof e == "function" ? e(t) : e;
}
function D2(e) {
return typeof e == "number" && e >= 0 && e !== 1 / 0;
}
function m3(e, t) {
return e.filter((r) => !t.includes(r));
}
function iH(e, t, r) {
const n = e.slice(0);
return n[t] = r, n;
}
function aI(e, t) {
return Math.max(e + (t || 0) - Date.now(), 0);
}
function jm(e, t, r) {
return fb(e) ? typeof t == "function" ? {
...r,
queryKey: e,
queryFn: t
} : {
...t,
queryKey: e
} : e;
}
function df(e, t, r) {
return fb(e) ? [{
...t,
queryKey: e
}, r] : [e || {}, t];
}
function y3(e, t) {
const {
type: r = "all",
exact: n,
fetchStatus: a,
predicate: u,
queryKey: o,
stale: c
} = e;
if (fb(o)) {
if (n) {
if (t.queryHash !== PT(o, t.options))
return !1;
} else if (!kv(t.queryKey, o))
return !1;
}
if (r !== "all") {
const i = t.isActive();
if (r === "active" && !i || r === "inactive" && i)
return !1;
}
return !(typeof c == "boolean" && t.isStale() !== c || typeof a < "u" && a !== t.state.fetchStatus || u && !u(t));
}
function C3(e, t) {
const {
exact: r,
fetching: n,
predicate: a,
mutationKey: u
} = e;
if (fb(u)) {
if (!t.options.mutationKey)
return !1;
if (r) {
if (Yh(t.options.mutationKey) !== Yh(u))
return !1;
} else if (!kv(t.options.mutationKey, u))
return !1;
}
return !(typeof n == "boolean" && t.state.status === "loading" !== n || a && !a(t));
}
function PT(e, t) {
return ((t == null ? void 0 : t.queryKeyHashFn) || Yh)(e);
}
function Yh(e) {
return JSON.stringify(e, (t, r) => P2(r) ? Object.keys(r).sort().reduce((n, a) => (n[a] = r[a], n), {}) : r);
}
function kv(e, t) {
return oI(e, t);
}
function oI(e, t) {
return e === t ? !0 : typeof e != typeof t ? !1 : e && t && typeof e == "object" && typeof t == "object" ? !Object.keys(t).some((r) => !oI(e[r], t[r])) : !1;
}
function sI(e, t) {
if (e === t)
return e;
const r = b3(e) && b3(t);
if (r || P2(e) && P2(t)) {
const n = r ? e.length : Object.keys(e).length, a = r ? t : Object.keys(t), u = a.length, o = r ? [] : {};
let c = 0;
for (let i = 0; i < u; i++) {
const s = r ? i : a[i];
o[s] = sI(e[s], t[s]), o[s] === e[s] && c++;
}
return n === u && c === n ? e : o;
}
return t;
}
function F2(e, t) {
if (e && !t || t && !e)
return !1;
for (const r in e)
if (e[r] !== t[r])
return !1;
return !0;
}
function b3(e) {
return Array.isArray(e) && e.length === Object.keys(e).length;
}
function P2(e) {
if (!w3(e))
return !1;
const t = e.constructor;
if (typeof t > "u")
return !0;
const r = t.prototype;
return !(!w3(r) || !r.hasOwnProperty("isPrototypeOf"));
}
function w3(e) {
return Object.prototype.toString.call(e) === "[object Object]";
}
function fb(e) {
return Array.isArray(e);
}
function lI(e) {
return new Promise((t) => {
setTimeout(t, e);
});
}
function S3(e) {
lI(0).then(e);
}
function aH() {
if (typeof AbortController == "function")
return new AbortController();
}
function I2(e, t, r) {
return r.isDataEqual != null && r.isDataEqual(e, t) ? e : typeof r.structuralSharing == "function" ? r.structuralSharing(e, t) : r.structuralSharing !== !1 ? sI(e, t) : t;
}
class oH extends eg {
constructor() {
super(), this.setup = (t) => {
if (!ly && window.addEventListener) {
const r = () => t();
return window.addEventListener("visibilitychange", r, !1), window.addEventListener("focus", r, !1), () => {
window.removeEventListener("visibilitychange", r), window.removeEventListener("focus", r);
};
}
};
}
onSubscribe() {
this.cleanup || this.setEventListener(this.setup);
}
onUnsubscribe() {
if (!this.hasListeners()) {
var t;
(t = this.cleanup) == null || t.call(this), this.cleanup = void 0;
}
}
setEventListener(t) {
var r;
this.setup = t, (r = this.cleanup) == null || r.call(this), this.cleanup = t((n) => {
typeof n == "boolean" ? this.setFocused(n) : this.onFocus();
});
}
setFocused(t) {
this.focused !== t && (this.focused = t, this.onFocus());
}
onFocus() {
this.listeners.forEach(({
listener: t
}) => {
t();
});
}
isFocused() {
return typeof this.focused == "boolean" ? this.focused : typeof document > "u" ? !0 : [void 0, "visible", "prerender"].includes(document.visibilityState);
}
}
const A1 = new oH(), x3 = ["online", "offline"];
class sH extends eg {
constructor() {
super(), this.setup = (t) => {
if (!ly && window.addEventListener) {
const r = () => t();
return x3.forEach((n) => {
window.addEventListener(n, r, !1);
}), () => {
x3.forEach((n) => {
window.removeEventListener(n, r);
});
};
}
};
}
onSubscribe() {
this.cleanup || this.setEventListener(this.setup);
}
onUnsubscribe() {
if (!this.hasListeners()) {
var t;
(t = this.cleanup) == null || t.call(this), this.cleanup = void 0;
}
}
setEventListener(t) {
var r;
this.setup = t, (r = this.cleanup) == null || r.call(this), this.cleanup = t((n) => {
typeof n == "boolean" ? this.setOnline(n) : this.onOnline();
});
}
setOnline(t) {
this.online !== t && (this.online = t, this.onOnline());
}
onOnline() {
this.listeners.forEach(({
listener: t
}) => {
t();
});
}
isOnline() {
return typeof this.online == "boolean" ? this.online : typeof navigator > "u" || typeof navigator.onLine > "u" ? !0 : navigator.onLine;
}
}
const E1 = new sH();
function lH(e) {
return Math.min(1e3 * 2 ** e, 3e4);
}
function hb(e) {
return (e ?? "online") === "online" ? E1.isOnline() : !0;
}
class uI {
constructor(t) {
this.revert = t == null ? void 0 : t.revert, this.silent = t == null ? void 0 : t.silent;
}
}
function u1(e) {
return e instanceof uI;
}
function cI(e) {
let t = !1, r = 0, n = !1, a, u, o;
const c = new Promise((y, g) => {
u = y, o = g;
}), i = (y) => {
n || (v(new uI(y)), e.abort == null || e.abort());
}, s = () => {
t = !0;
}, p = () => {
t = !1;
}, d = () => !A1.isFocused() || e.networkMode !== "always" && !E1.isOnline(), h = (y) => {
n || (n = !0, e.onSuccess == null || e.onSuccess(y), a == null || a(), u(y));
}, v = (y) => {
n || (n = !0, e.onError == null || e.onError(y), a == null || a(), o(y));
}, m = () => new Promise((y) => {
a = (g) => {
const w = n || !d();
return w && y(g), w;
}, e.onPause == null || e.onPause();
}).then(() => {
a = void 0, n || e.onContinue == null || e.onContinue();
}), C = () => {
if (n)
return;
let y;
try {
y = e.fn();
} catch (g) {
y = Promise.reject(g);
}
Promise.resolve(y).then(h).catch((g) => {
var w, S;
if (n)
return;
const E = (w = e.retry) != null ? w : 3, x = (S = e.retryDelay) != null ? S : lH, T = typeof x == "function" ? x(r, g) : x, D = E === !0 || typeof E == "number" && r < E || typeof E == "function" && E(r, g);
if (t || !D) {
v(g);
return;
}
r++, e.onFail == null || e.onFail(r, g), lI(T).then(() => {
if (d())
return m();
}).then(() => {
t ? v(g) : C();
});
});
};
return hb(e.networkMode) ? C() : m().then(C), {
promise: c,
cancel: i,
continue: () => (a == null ? void 0 : a()) ? c : Promise.resolve(),
cancelRetry: s,
continueRetry: p
};
}
const IT = console;
function uH() {
let e = [], t = 0, r = (p) => {
p();
}, n = (p) => {
p();
};
const a = (p) => {
let d;
t++;
try {
d = p();
} finally {
t--, t || c();
}
return d;
}, u = (p) => {
t ? e.push(p) : S3(() => {
r(p);
});
}, o = (p) => (...d) => {
u(() => {
p(...d);
});
}, c = () => {
const p = e;
e = [], p.length && S3(() => {
n(() => {
p.forEach((d) => {
r(d);
});
});
});
};
return {
batch: a,
batchCalls: o,
schedule: u,
setNotifyFunction: (p) => {
r = p;
},
setBatchNotifyFunction: (p) => {
n = p;
}
};
}
const Aa = uH();
class dI {
destroy() {
this.clearGcTimeout();
}
scheduleGc() {
this.clearGcTimeout(), D2(this.cacheTime) && (this.gcTimeout = setTimeout(() => {
this.optionalRemove();
}, this.cacheTime));
}
updateCacheTime(t) {
this.cacheTime = Math.max(this.cacheTime || 0, t ?? (ly ? 1 / 0 : 5 * 60 * 1e3));
}
clearGcTimeout() {
this.gcTimeout && (clearTimeout(this.gcTimeout), this.gcTimeout = void 0);
}
}
class cH extends dI {
constructor(t) {
super(), this.abortSignalConsumed = !1, this.defaultOptions = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.cache = t.cache, this.logger = t.logger || IT, this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.initialState = t.state || dH(this.options), this.state = this.initialState, this.scheduleGc();
}
get meta() {
return this.options.meta;
}
setOptions(t) {
this.options = {
...this.defaultOptions,
...t
}, this.updateCacheTime(this.options.cacheTime);
}
optionalRemove() {
!this.observers.length && this.state.fetchStatus === "idle" && this.cache.remove(this);
}
setData(t, r) {
const n = I2(this.state.data, t, this.options);
return this.dispatch({
data: n,
type: "success",
dataUpdatedAt: r == null ? void 0 : r.updatedAt,
manual: r == null ? void 0 : r.manual
}), n;
}
setState(t, r) {
this.dispatch({
type: "setState",
state: t,
setStateOptions: r
});
}
cancel(t) {
var r;
const n = this.promise;
return (r = this.retryer) == null || r.cancel(t), n ? n.then(jl).catch(jl) : Promise.resolve();
}
destroy() {
super.destroy(), this.cancel({
silent: !0
});
}
reset() {
this.destroy(), this.setState(this.initialState);
}
isActive() {
return this.observers.some((t) => t.options.enabled !== !1);
}
isDisabled() {
return this.getObserversCount() > 0 && !this.isActive();
}
isStale() {
return this.state.isInvalidated || !this.state.dataUpdatedAt || this.observers.some((t) => t.getCurrentResult().isStale);
}
isStaleByTime(t = 0) {
return this.state.isInvalidated || !this.state.dataUpdatedAt || !aI(this.state.dataUpdatedAt, t);
}
onFocus() {
var t;
const r = this.observers.find((n) => n.shouldFetchOnWindowFocus());
r && r.refetch({
cancelRefetch: !1
}), (t = this.retryer) == null || t.continue();
}
onOnline() {
var t;
const r = this.observers.find((n) => n.shouldFetchOnReconnect());
r && r.refetch({
cancelRefetch: !1
}), (t = this.retryer) == null || t.continue();
}
addObserver(t) {
this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.cache.notify({
type: "observerAdded",
query: this,
observer: t
}));
}
removeObserver(t) {
this.observers.includes(t) && (this.observers = this.observers.filter((r) => r !== t), this.observers.length || (this.retryer && (this.abortSignalConsumed ? this.retryer.cancel({
revert: !0
}) : this.retryer.cancelRetry()), this.scheduleGc()), this.cache.notify({
type: "observerRemoved",
query: this,
observer: t
}));
}
getObserversCount() {
return this.observers.length;
}
invalidate() {
this.state.isInvalidated || this.dispatch({
type: "invalidate"
});
}
fetch(t, r) {
var n, a;
if (this.state.fetchStatus !== "idle") {
if (this.state.dataUpdatedAt && r != null && r.cancelRefetch)
this.cancel({
silent: !0
});
else if (this.promise) {
var u;
return (u = this.retryer) == null || u.continueRetry(), this.promise;
}
}
if (t && this.setOptions(t), !this.options.queryFn) {
const v = this.observers.find((m) => m.options.queryFn);
v && this.setOptions(v.options);
}
process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || this.logger.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));
const o = aH(), c = {
queryKey: this.queryKey,
pageParam: void 0,
meta: this.meta
}, i = (v) => {
Object.defineProperty(v, "signal", {
enumerable: !0,
get: () => {
if (o)
return this.abortSignalConsumed = !0, o.signal;
}
});
};
i(c);
const s = () => this.options.queryFn ? (this.abortSignalConsumed = !1, this.options.queryFn(c)) : Promise.reject("Missing queryFn for queryKey '" + this.options.queryHash + "'"), p = {
fetchOptions: r,
options: this.options,
queryKey: this.queryKey,
state: this.state,
fetchFn: s
};
if (i(p), (n = this.options.behavior) == null || n.onFetch(p), this.revertState = this.state, this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((a = p.fetchOptions) == null ? void 0 : a.meta)) {
var d;
this.dispatch({
type: "fetch",
meta: (d = p.fetchOptions) == null ? void 0 : d.meta
});
}
const h = (v) => {
if (u1(v) && v.silent || this.dispatch({
type: "error",
error: v
}), !u1(v)) {
var m, C, y, g;
(m = (C = this.cache.config).onError) == null || m.call(C, v, this), (y = (g = this.cache.config).onSettled) == null || y.call(g, this.state.data, v, this), process.env.NODE_ENV !== "production" && this.logger.error(v);
}
this.isFetchingOptimistic || this.scheduleGc(), this.isFetchingOptimistic = !1;
};
return this.retryer = cI({
fn: p.fetchFn,
abort: o == null ? void 0 : o.abort.bind(o),
onSuccess: (v) => {
var m, C, y, g;
if (typeof v > "u") {
process.env.NODE_ENV !== "production" && this.logger.error("Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: " + this.queryHash), h(new Error(this.queryHash + " data is undefined"));
return;
}
this.setData(v), (m = (C = this.cache.config).onSuccess) == null || m.call(C, v, this), (y = (g = this.cache.config).onSettled) == null || y.call(g, v, this.state.error, this), this.isFetchingOptimistic || this.scheduleGc(), this.isFetchingOptimistic = !1;
},
onError: h,
onFail: (v, m) => {
this.dispatch({
type: "failed",
failureCount: v,
error: m
});
},
onPause: () => {
this.dispatch({
type: "pause"
});
},
onContinue: () => {
this.dispatch({
type: "continue"
});
},
retry: p.options.retry,
retryDelay: p.options.retryDelay,
networkMode: p.options.networkMode
}), this.promise = this.retryer.promise, this.promise;
}
dispatch(t) {
const r = (n) => {
var a, u;
switch (t.type) {
case "failed":
return {
...n,
fetchFailureCount: t.failureCount,
fetchFailureReason: t.error
};
case "pause":
return {
...n,
fetchStatus: "paused"
};
case "continue":
return {
...n,
fetchStatus: "fetching"
};
case "fetch":
return {
...n,
fetchFailureCount: 0,
fetchFailureReason: null,
fetchMeta: (a = t.meta) != null ? a : null,
fetchStatus: hb(this.options.networkMode) ? "fetching" : "paused",
...!n.dataUpdatedAt && {
error: null,
status: "loading"
}
};
case "success":
return {
...n,
data: t.data,
dataUpdateCount: n.dataUpdateCount + 1,
dataUpdatedAt: (u = t.dataUpdatedAt) != null ? u : Date.now(),
error: null,
isInvalidated: !1,
status: "success",
...!t.manual && {
fetchStatus: "idle",
fetchFailureCount: 0,
fetchFailureReason: null
}
};
case "error":
const o = t.error;
return u1(o) && o.revert && this.revertState ? {
...this.revertState,
fetchStatus: "idle"
} : {
...n,
error: o,
errorUpdateCount: n.errorUpdateCount + 1,
errorUpdatedAt: Date.now(),
fetchFailureCount: n.fetchFailureCount + 1,
fetchFailureReason: o,
fetchStatus: "idle",
status: "error"
};
case "invalidate":
return {
...n,
isInvalidated: !0
};
case "setState":
return {
...n,
...t.state
};
}
};
this.state = r(this.state), Aa.batch(() => {
this.observers.forEach((n) => {
n.onQueryUpdate(t);
}), this.cache.notify({
query: this,
type: "updated",
action: t
});
});
}
}
function dH(e) {
const t = typeof e.initialData == "function" ? e.initialData() : e.initialData, r = typeof t < "u", n = r ? typeof e.initialDataUpdatedAt == "function" ? e.initialDataUpdatedAt() : e.initialDataUpdatedAt : 0;
return {
data: t,
dataUpdateCount: 0,
dataUpdatedAt: r ? n ?? Date.now() : 0,
error: null,
errorUpdateCount: 0,
errorUpdatedAt: 0,
fetchFailureCount: 0,
fetchFailureReason: null,
fetchMeta: null,
isInvalidated: !1,
status: r ? "success" : "loading",
fetchStatus: "idle"
};
}
class fH extends eg {
constructor(t) {
super(), this.config = t || {}, this.queries = [], this.queriesMap = {};
}
build(t, r, n) {
var a;
const u = r.queryKey, o = (a = r.queryHash) != null ? a : PT(u, r);
let c = this.get(o);
return c || (c = new cH({
cache: this,
logger: t.getLogger(),
queryKey: u,
queryHash: o,
options: t.defaultQueryOptions(r),
state: n,
defaultOptions: t.getQueryDefaults(u)
}), this.add(c)), c;
}
add(t) {
this.queriesMap[t.queryHash] || (this.queriesMap[t.queryHash] = t, this.queries.push(t), this.notify({
type: "added",
query: t
}));
}
remove(t) {
const r = this.queriesMap[t.queryHash];
r && (t.destroy(), this.queries = this.queries.filter((n) => n !== t), r === t && delete this.queriesMap[t.queryHash], this.notify({
type: "removed",
query: t
}));
}
clear() {
Aa.batch(() => {
this.queries.forEach((t) => {
this.remove(t);
});
});
}
get(t) {
return this.queriesMap[t];
}
getAll() {
return this.queries;
}
find(t, r) {
const [n] = df(t, r);
return typeof n.exact > "u" && (n.exact = !0), this.queries.find((a) => y3(n, a));
}
findAll(t, r) {
const [n] = df(t, r);
return Object.keys(n).length > 0 ? this.queries.filter((a) => y3(n, a)) : this.queries;
}
notify(t) {
Aa.batch(() => {
this.listeners.forEach(({
listener: r
}) => {
r(t);
});
});
}
onFocus() {
Aa.batch(() => {
this.queries.forEach((t) => {
t.onFocus();
});
});
}
onOnline() {
Aa.batch(() => {
this.queries.forEach((t) => {
t.onOnline();
});
});
}
}
class hH extends dI {
constructor(t) {
super(), this.defaultOptions = t.defaultOptions, this.mutationId = t.mutationId, this.mutationCache = t.mutationCache, this.logger = t.logger || IT, this.observers = [], this.state = t.state || pH(), this.setOptions(t.options), this.scheduleGc();
}
setOptions(t) {
this.options = {
...this.defaultOptions,
...t
}, this.updateCacheTime(this.options.cacheTime);
}
get meta() {
return this.options.meta;
}
setState(t) {
this.dispatch({
type: "setState",
state: t
});
}
addObserver(t) {
this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.mutationCache.notify({
type: "observerAdded",
mutation: this,
observer: t
}));
}
removeObserver(t) {
this.observers = this.observers.filter((r) => r !== t), this.scheduleGc(), this.mutationCache.notify({
type: "observerRemoved",
mutation: this,
observer: t
});
}
optionalRemove() {
this.observers.length || (this.state.status === "loading" ? this.scheduleGc() : this.mutationCache.remove(this));
}
continue() {
var t, r;
return (t = (r = this.retryer) == null ? void 0 : r.continue()) != null ? t : this.execute();
}
async execute() {
const t = () => {
var D;
return this.retryer = cI({
fn: () => this.options.mutationFn ? this.options.mutationFn(this.state.variables) : Promise.reject("No mutationFn found"),
onFail: (P, k) => {
this.dispatch({
type: "failed",
failureCount: P,
error: k
});
},
onPause: () => {
this.dispatch({
type: "pause"
});
},
onContinue: () => {
this.dispatch({
type: "continue"
});
},
retry: (D = this.options.retry) != null ? D : 0,
retryDelay: this.options.retryDelay,
networkMode: this.options.networkMode
}), this.retryer.promise;
}, r = this.state.status === "loading";
try {
var n, a, u, o, c, i, s, p;
if (!r) {
var d, h, v, m;
this.dispatch({
type: "loading",
variables: this.options.variables
}), await ((d = (h = this.mutationCache.config).onMutate) == null ? void 0 : d.call(h, this.state.variables, this));
const P = await ((v = (m = this.options).onMutate) == null ? void 0 : v.call(m, this.state.variables));
P !== this.state.context && this.dispatch({
type: "loading",
context: P,
variables: this.state.variables
});
}
const D = await t();
return await ((n = (a = this.mutationCache.config).onSuccess) == null ? void 0 : n.call(a, D, this.state.variables, this.state.context, this)), await ((u = (o = this.options).onSuccess) == null ? void 0 : u.call(o, D, this.state.variables, this.state.context)), await ((c = (i = this.mutationCache.config).onSettled) == null ? void 0 : c.call(i, D, null, this.state.variables, this.state.context, this)), await ((s = (p = this.options).onSettled) == null ? void 0 : s.call(p, D, null, this.state.variables, this.state.context)), this.dispatch({
type: "success",
data: D
}), D;
} catch (D) {
try {
var C, y, g, w, S, E, x, T;
throw await ((C = (y = this.mutationCache.config).onError) == null ? void 0 : C.call(y, D, this.state.variables, this.state.context, this)), process.env.NODE_ENV !== "production" && this.logger.error(D), await ((g = (w = this.options).onError) == null ? void 0 : g.call(w, D, this.state.variables, this.state.context)), await ((S = (E = this.mutationCache.config).onSettled) == null ? void 0 : S.call(E, void 0, D, this.state.variables, this.state.context, this)), await ((x = (T = this.options).onSettled) == null ? void 0 : x.call(T, void 0, D, this.state.variables, this.state.context)), D;
} finally {
this.dispatch({
type: "error",
error: D
});
}
}
}
dispatch(t) {
const r = (n) => {
switch (t.type) {
case "failed":
return {
...n,
failureCount: t.failureCount,
failureReason: t.error
};
case "pause":
return {
...n,
isPaused: !0
};
case "continue":
return {
...n,
isPaused: !1
};
case "loading":
return {
...n,
context: t.context,
data: void 0,
failureCount: 0,
failureReason: null,
error: null,
isPaused: !hb(this.options.networkMode),
status: "loading",
variables: t.variables
};
case "success":
return {
...n,
data: t.data,
failureCount: 0,
failureReason: null,
error: null,
status: "success",
isPaused: !1
};
case "error":
return {
...n,
data: void 0,
error: t.error,
failureCount: n.failureCount + 1,
failureReason: t.error,
isPaused: !1,
status: "error"
};
case "setState":
return {
...n,
...t.state
};
}
};
this.state = r(this.state), Aa.batch(() => {
this.observers.forEach((n) => {
n.onMutationUpdate(t);
}), this.mutationCache.notify({
mutation: this,
type: "updated",
action: t
});
});
}
}
function pH() {
return {
context: void 0,
data: void 0,
error: null,
failureCount: 0,
failureReason: null,
isPaused: !1,
status: "idle",
variables: void 0
};
}
class vH extends eg {
constructor(t) {
super(), this.config = t || {}, this.mutations = [], this.mutationId = 0;
}
build(t, r, n) {
const a = new hH({
mutationCache: this,
logger: t.getLogger(),
mutationId: ++this.mutationId,
options: t.defaultMutationOptions(r),
state: n,
defaultOptions: r.mutationKey ? t.getMutationDefaults(r.mutationKey) : void 0
});
return this.add(a), a;
}
add(t) {
this.mutations.push(t), this.notify({
type: "added",
mutation: t
});
}
remove(t) {
this.mutations = this.mutations.filter((r) => r !== t), this.notify({
type: "removed",
mutation: t
});
}
clear() {
Aa.batch(() => {
this.mutations.forEach((t) => {
this.remove(t);
});
});
}
getAll() {
return this.mutations;
}
find(t) {
return typeof t.exact > "u" && (t.exact = !0), this.mutations.find((r) => C3(t, r));
}
findAll(t) {
return this.mutations.filter((r) => C3(t, r));
}
notify(t) {
Aa.batch(() => {
this.listeners.forEach(({
listener: r
}) => {
r(t);
});
});
}
resumePausedMutations() {
var t;
return this.resuming = ((t = this.resuming) != null ? t : Promise.resolve()).then(() => {
const r = this.mutations.filter((n) => n.state.isPaused);
return Aa.batch(() => r.reduce((n, a) => n.then(() => a.continue().catch(jl)), Promise.resolve()));
}).then(() => {
this.resuming = void 0;
}), this.resuming;
}
}
function gH() {
return {
onFetch: (e) => {
e.fetchFn = () => {
var t, r, n, a, u, o;
const c = (t = e.fetchOptions) == null || (r = t.meta) == null ? void 0 : r.refetchPage, i = (n = e.fetchOptions) == null || (a = n.meta) == null ? void 0 : a.fetchMore, s = i == null ? void 0 : i.pageParam, p = (i == null ? void 0 : i.direction) === "forward", d = (i == null ? void 0 : i.direction) === "backward", h = ((u = e.state.data) == null ? void 0 : u.pages) || [], v = ((o = e.state.data) == null ? void 0 : o.pageParams) || [];
let m = v, C = !1;
const y = (T) => {
Object.defineProperty(T, "signal", {
enumerable: !0,
get: () => {
var D;
if ((D = e.signal) != null && D.aborted)
C = !0;
else {
var P;
(P = e.signal) == null || P.addEventListener("abort", () => {
C = !0;
});
}
return e.signal;
}
});
}, g = e.options.queryFn || (() => Promise.reject("Missing queryFn for queryKey '" + e.options.queryHash + "'")), w = (T, D, P, k) => (m = k ? [D, ...m] : [...m, D], k ? [P, ...T] : [...T, P]), S = (T, D, P, k) => {
if (C)
return Promise.reject("Cancelled");
if (typeof P > "u" && !D && T.length)
return Promise.resolve(T);
const M = {
queryKey: e.queryKey,
pageParam: P,
meta: e.options.meta
};
y(M);
const L = g(M);
return Promise.resolve(L).then((O) => w(T, P, O, k));
};
let E;
if (!h.length)
E = S([]);
else if (p) {
const T = typeof s < "u", D = T ? s : T3(e.options, h);
E = S(h, T, D);
} else if (d) {
const T = typeof s < "u", D = T ? s : mH(e.options, h);
E = S(h, T, D, !0);
} else {
m = [];
const T = typeof e.options.getNextPageParam > "u";
E = (c && h[0] ? c(h[0], 0, h) : !0) ? S([], T, v[0]) : Promise.resolve(w([], v[0], h[0]));
for (let P = 1; P < h.length; P++)
E = E.then((k) => {
if (c && h[P] ? c(h[P], P, h) : !0) {
const L = T ? v[P] : T3(e.options, k);
return S(k, T, L);
}
return Promise.resolve(w(k, v[P], h[P]));
});
}
return E.then((T) => ({
pages: T,
pageParams: m
}));
};
}
};
}
function T3(e, t) {
return e.getNextPageParam == null ? void 0 : e.getNextPageParam(t[t.length - 1], t);
}
function mH(e, t) {
return e.getPreviousPageParam == null ? void 0 : e.getPreviousPageParam(t[0], t);
}
class yH {
constructor(t = {}) {
this.queryCache = t.queryCache || new fH(), this.mutationCache = t.mutationCache || new vH(), this.logger = t.logger || IT, this.defaultOptions = t.defaultOptions || {}, this.queryDefaults = [], this.mutationDefaults = [], this.mountCount = 0, process.env.NODE_ENV !== "production" && t.logger && this.logger.error("Passing a custom logger has been deprecated and will be removed in the next major version.");
}
mount() {
this.mountCount++, this.mountCount === 1 && (this.unsubscribeFocus = A1.subscribe(() => {
A1.isFocused() && (this.resumePausedMutations(), this.queryCache.onFocus());
}), this.unsubscribeOnline = E1.subscribe(() => {
E1.isOnline() && (this.resumePausedMutations(), this.queryCache.onOnline());
}));
}
unmount() {
var t, r;
this.mountCount--, this.mountCount === 0 && ((t = this.unsubscribeFocus) == null || t.call(this), this.unsubscribeFocus = void 0, (r = this.unsubscribeOnline) == null || r.call(this), this.unsubscribeOnline = void 0);
}
isFetching(t, r) {
const [n] = df(t, r);
return n.fetchStatus = "fetching", this.queryCache.findAll(n).length;
}
isMutating(t) {
return this.mutationCache.findAll({
...t,
fetching: !0
}).length;
}
getQueryData(t, r) {
var n;
return (n = this.queryCache.find(t, r)) == null ? void 0 : n.state.data;
}
ensureQueryData(t, r, n) {
const a = jm(t, r, n), u = this.getQueryData(a.queryKey);
return u ? Promise.resolve(u) : this.fetchQuery(a);
}
getQueriesData(t) {
return this.getQueryCache().findAll(t).map(({
queryKey: r,
state: n
}) => {
const a = n.data;
return [r, a];
});
}
setQueryData(t, r, n) {
const a = this.queryCache.find(t), u = a == null ? void 0 : a.state.data, o = nH(r, u);
if (typeof o > "u")
return;
const c = jm(t), i = this.defaultQueryOptions(c);
return this.queryCache.build(this, i).setData(o, {
...n,
manual: !0
});
}
setQueriesData(t, r, n) {
return Aa.batch(() => this.getQueryCache().findAll(t).map(({
queryKey: a
}) => [a, this.setQueryData(a, r, n)]));
}
getQueryState(t, r) {
var n;
return (n = this.queryCache.find(t, r)) == null ? void 0 : n.state;
}
removeQueries(t, r) {
const [n] = df(t, r), a = this.queryCache;
Aa.batch(() => {
a.findAll(n).forEach((u) => {
a.remove(u);
});
});
}
resetQueries(t, r, n) {
const [a, u] = df(t, r, n), o = this.queryCache, c = {
type: "active",
...a
};
return Aa.batch(() => (o.findAll(a).forEach((i) => {
i.reset();
}), this.refetchQueries(c, u)));
}
cancelQueries(t, r, n) {
const [a, u = {}] = df(t, r, n);
typeof u.revert > "u" && (u.revert = !0);
const o = Aa.batch(() => this.queryCache.findAll(a).map((c) => c.cancel(u)));
return Promise.all(o).then(jl).catch(jl);
}
invalidateQueries(t, r, n) {
const [a, u] = df(t, r, n);
return Aa.batch(() => {
var o, c;
if (this.queryCache.findAll(a).forEach((s) => {
s.invalidate();
}), a.refetchType === "none")
return Promise.resolve();
const i = {
...a,
type: (o = (c = a.refetchType) != null ? c : a.type) != null ? o : "active"
};
return this.refetchQueries(i, u);
});
}
refetchQueries(t, r, n) {
const [a, u] = df(t, r, n), o = Aa.batch(() => this.queryCache.findAll(a).filter((i) => !i.isDisabled()).map((i) => {
var s;
return i.fetch(void 0, {
...u,
cancelRefetch: (s = u == null ? void 0 : u.cancelRefetch) != null ? s : !0,
meta: {
refetchPage: a.refetchPage
}
});
}));
let c = Promise.all(o).then(jl);
return u != null && u.throwOnError || (c = c.catch(jl)), c;
}
fetchQuery(t, r, n) {
const a = jm(t, r, n), u = this.defaultQueryOptions(a);
typeof u.retry > "u" && (u.retry = !1);
const o = this.queryCache.build(this, u);
return o.isStaleByTime(u.staleTime) ? o.fetch(u) : Promise.resolve(o.state.data);
}
prefetchQuery(t, r, n) {
return this.fetchQuery(t, r, n).then(jl).catch(jl);
}
fetchInfiniteQuery(t, r, n) {
const a = jm(t, r, n);
return a.behavior = gH(), this.fetchQuery(a);
}
prefetchInfiniteQuery(t, r, n) {
return this.fetchInfiniteQuery(t, r, n).then(jl).catch(jl);
}
resumePausedMutations() {
return this.mutationCache.resumePausedMutations();
}
getQueryCache() {
return this.queryCache;
}
getMutationCache() {
return this.mutationCache;
}
getLogger() {
return this.logger;
}
getDefaultOptions() {
return this.defaultOptions;
}
setDefaultOptions(t) {
this.defaultOptions = t;
}
setQueryDefaults(t, r) {
const n = this.queryDefaults.find((a) => Yh(t) === Yh(a.queryKey));
n ? n.defaultOptions = r : this.queryDefaults.push({
queryKey: t,
defaultOptions: r
});
}
getQueryDefaults(t) {
if (!t)
return;
const r = this.queryDefaults.find((n) => kv(t, n.queryKey));
return process.env.NODE_ENV !== "production" && this.queryDefaults.filter((a) => kv(t, a.queryKey)).length > 1 && this.logger.error("[QueryClient] Several query defaults match with key '" + JSON.stringify(t) + "'. The first matching query defaults are used. Please check how query defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydefaults."), r == null ? void 0 : r.defaultOptions;
}
setMutationDefaults(t, r) {
const n = this.mutationDefaults.find((a) => Yh(t) === Yh(a.mutationKey));
n ? n.defaultOptions = r : this.mutationDefaults.push({
mutationKey: t,
defaultOptions: r
});
}
getMutationDefaults(t) {
if (!t)
return;
const r = this.mutationDefaults.find((n) => kv(t, n.mutationKey));
return process.env.NODE_ENV !== "production" && this.mutationDefaults.filter((a) => kv(t, a.mutationKey)).length > 1 && this.logger.error("[QueryClient] Several mutation defaults match with key '" + JSON.stringify(t) + "'. The first matching mutation defaults are used. Please check how mutation defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetmutationdefaults."), r == null ? void 0 : r.defaultOptions;
}
defaultQueryOptions(t) {
if (t != null && t._defaulted)
return t;
const r = {
...this.defaultOptions.queries,
...this.getQueryDefaults(t == null ? void 0 : t.queryKey),
...t,
_defaulted: !0
};
return !r.queryHash && r.queryKey && (r.queryHash = PT(r.queryKey, r)), typeof r.refetchOnReconnect > "u" && (r.refetchOnReconnect = r.networkMode !== "always"), typeof r.useErrorBoundary > "u" && (r.useErrorBoundary = !!r.suspense), r;
}
defaultMutationOptions(t) {
return t != null && t._defaulted ? t : {
...this.defaultOptions.mutations,
...this.getMutationDefaults(t == null ? void 0 : t.mutationKey),
...t,
_defaulted: !0
};
}
clear() {
this.queryCache.clear(), this.mutationCache.clear();
}
}
class fI extends eg {
constructor(t, r) {
super(), this.client = t, this.options = r, this.trackedProps = /* @__PURE__ */ new Set(), this.selectError = null, this.bindMethods(), this.setOptions(r);
}
bindMethods() {
this.remove = this.remove.bind(this), this.refetch = this.refetch.bind(this);
}
onSubscribe() {
this.listeners.size === 1 && (this.currentQuery.addObserver(this), R3(this.currentQuery, this.options) && this.executeFetch(), this.updateTimers());
}
onUnsubscribe() {
this.hasListeners() || this.destroy();
}
shouldFetchOnReconnect() {
return L2(this.currentQuery, this.options, this.options.refetchOnReconnect);
}
shouldFetchOnWindowFocus() {
return L2(this.currentQuery, this.options, this.options.refetchOnWindowFocus);
}
destroy() {
this.listeners = /* @__PURE__ */ new Set(), this.clearStaleTimeout(), this.clearRefetchInterval(), this.currentQuery.removeObserver(this);
}
setOptions(t, r) {
const n = this.options, a = this.currentQuery;
if (this.options = this.client.defaultQueryOptions(t), process.env.NODE_ENV !== "production" && typeof (t == null ? void 0 : t.isDataEqual) < "u" && this.client.getLogger().error("The isDataEqual option has been deprecated and will be removed in the next major version. You can achieve the same functionality by passing a function as the structuralSharing option"), F2(n, this.options) || this.client.getQueryCache().notify({
type: "observerOptionsUpdated",
query: this.currentQuery,
observer: this
}), typeof this.options.enabled < "u" && typeof this.options.enabled != "boolean")
throw new Error("Expected enabled to be a boolean");
this.options.queryKey || (this.options.queryKey = n.queryKey), this.updateQuery();
const u = this.hasListeners();
u && A3(this.currentQuery, a, this.options, n) && this.executeFetch(), this.updateResult(r), u && (this.currentQuery !== a || this.options.enabled !== n.enabled || this.options.staleTime !== n.staleTime) && this.updateStaleTimeout();
const o = this.computeRefetchInterval();
u && (this.currentQuery !== a || this.options.enabled !== n.enabled || o !== this.currentRefetchInterval) && this.updateRefetchInterval(o);
}
getOptimisticResult(t) {
const r = this.client.getQueryCache().build(this.client, t), n = this.createResult(r, t);
return bH(this, n, t) && (this.currentResult = n, this.currentResultOptions = this.options, this.currentResultState = this.currentQuery.state), n;
}
getCurrentResult() {
return this.currentResult;
}
trackResult(t) {
const r = {};
return Object.keys(t).forEach((n) => {
Object.defineProperty(r, n, {
configurable: !1,
enumerable: !0,
get: () => (this.trackedProps.add(n), t[n])
});
}), r;
}
getCurrentQuery() {
return this.currentQuery;
}
remove() {
this.client.getQueryCache().remove(this.currentQuery);
}
refetch({
refetchPage: t,
...r
} = {}) {
return this.fetch({
...r,
meta: {
refetchPage: t
}
});
}
fetchOptimistic(t) {
const r = this.client.defaultQueryOptions(t), n = this.client.getQueryCache().build(this.client, r);
return n.isFetchingOptimistic = !0, n.fetch().then(() => this.createResult(n, r));
}
fetch(t) {
var r;
return this.executeFetch({
...t,
cancelRefetch: (r = t.cancelRefetch) != null ? r : !0
}).then(() => (this.updateResult(), this.currentResult));
}
executeFetch(t) {
this.updateQuery();
let r = this.currentQuery.fetch(this.options, t);
return t != null && t.throwOnError || (r = r.catch(jl)), r;
}
updateStaleTimeout() {
if (this.clearStaleTimeout(), ly || this.currentResult.isStale || !D2(this.options.staleTime))
return;
const r = aI(this.currentResult.dataUpdatedAt, this.options.staleTime) + 1;
this.staleTimeoutId = setTimeout(() => {
this.currentResult.isStale || this.updateResult();
}, r);
}
computeRefetchInterval() {
var t;
return typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(this.currentResult.data, this.currentQuery) : (t = this.options.refetchInterval) != null ? t : !1;
}
updateRefetchInterval(t) {
this.clearRefetchInterval(), this.currentRefetchInterval = t, !(ly || this.options.enabled === !1 || !D2(this.currentRefetchInterval) || this.currentRefetchInterval === 0) && (this.refetchIntervalId = setInterval(() => {
(this.options.refetchIntervalInBackground || A1.isFocused()) && this.executeFetch();
}, this.currentRefetchInterval));
}
updateTimers() {
this.updateStaleTimeout(), this.updateRefetchInterval(this.computeRefetchInterval());
}
clearStaleTimeout() {
this.staleTimeoutId && (clearTimeout(this.staleTimeoutId), this.staleTimeoutId = void 0);
}
clearRefetchInterval() {
this.refetchIntervalId && (clearInterval(this.refetchIntervalId), this.refetchIntervalId = void 0);
}
createResult(t, r) {
const n = this.currentQuery, a = this.options, u = this.currentResult, o = this.currentResultState, c = this.currentResultOptions, i = t !== n, s = i ? t.state : this.currentQueryInitialState, p = i ? this.currentResult : this.previousQueryResult, {
state: d
} = t;
let {
dataUpdatedAt: h,
error: v,
errorUpdatedAt: m,
fetchStatus: C,
status: y
} = d, g = !1, w = !1, S;
if (r._optimisticResults) {
const P = this.hasListeners(), k = !P && R3(t, r), M = P && A3(t, n, r, a);
(k || M) && (C = hb(t.options.networkMode) ? "fetching" : "paused", h || (y = "loading")), r._optimisticResults === "isRestoring" && (C = "idle");
}
if (r.keepPreviousData && !d.dataUpdatedAt && p != null && p.isSuccess && y !== "error")
S = p.data, h = p.dataUpdatedAt, y = p.status, g = !0;
else if (r.select && typeof d.data < "u")
if (u && d.data === (o == null ? void 0 : o.data) && r.select === this.selectFn)
S = this.selectResult;
else
try {
this.selectFn = r.select, S = r.select(d.data), S = I2(u == null ? void 0 : u.data, S, r), this.selectResult = S, this.selectError = null;
} catch (P) {
process.env.NODE_ENV !== "production" && this.client.getLogger().error(P), this.selectError = P;
}
else
S = d.data;
if (typeof r.placeholderData < "u" && typeof S > "u" && y === "loading") {
let P;
if (u != null && u.isPlaceholderData && r.placeholderData === (c == null ? void 0 : c.placeholderData))
P = u.data;
else if (P = typeof r.placeholderData == "function" ? r.placeholderData() : r.placeholderData, r.select && typeof P < "u")
try {
P = r.select(P), this.selectError = null;
} catch (k) {
process.env.NODE_ENV !== "production" && this.client.getLogger().error(k), this.selectError = k;
}
typeof P < "u" && (y = "success", S = I2(u == null ? void 0 : u.data, P, r), w = !0);
}
this.selectError && (v = this.selectError, S = this.selectResult, m = Date.now(), y = "error");
const E = C === "fetching", x = y === "loading", T = y === "error";
return {
status: y,
fetchStatus: C,
isLoading: x,
isSuccess: y === "success",
isError: T,
isInitialLoading: x && E,
data: S,
dataUpdatedAt: h,
error: v,
errorUpdatedAt: m,
failureCount: d.fetchFailureCount,
failureReason: d.fetchFailureReason,
errorUpdateCount: d.errorUpdateCount,
isFetched: d.dataUpdateCount > 0 || d.errorUpdateCount > 0,
isFetchedAfterMount: d.dataUpdateCount > s.dataUpdateCount || d.errorUpdateCount > s.errorUpdateCount,
isFetching: E,
isRefetching: E && !x,
isLoadingError: T && d.dataUpdatedAt === 0,
isPaused: C === "paused",
isPlaceholderData: w,
isPreviousData: g,
isRefetchError: T && d.dataUpdatedAt !== 0,
isStale: LT(t, r),
refetch: this.refetch,
remove: this.remove
};
}
updateResult(t) {
const r = this.currentResult, n = this.createResult(this.currentQuery, this.options);
if (this.currentResultState = this.currentQuery.state, this.currentResultOptions = this.options, F2(n, r))
return;
this.currentResult = n;
const a = {
cache: !0
}, u = () => {
if (!r)
return !0;
const {
notifyOnChangeProps: o
} = this.options, c = typeof o == "function" ? o() : o;
if (c === "all" || !c && !this.trackedProps.size)
return !0;
const i = new Set(c ?? this.trackedProps);
return this.options.useErrorBoundary && i.add("error"), Object.keys(this.currentResult).some((s) => {
const p = s;
return this.currentResult[p] !== r[p] && i.has(p);
});
};
(t == null ? void 0 : t.listeners) !== !1 && u() && (a.listeners = !0), this.notify({
...a,
...t
});
}
updateQuery() {
const t = this.client.getQueryCache().build(this.client, this.options);
if (t === this.currentQuery)
return;
const r = this.currentQuery;
this.currentQuery = t, this.currentQueryInitialState = t.state, this.previousQueryResult = this.currentResult, this.hasListeners() && (r == null || r.removeObserver(this), t.addObserver(this));
}
onQueryUpdate(t) {
const r = {};
t.type === "success" ? r.onSuccess = !t.manual : t.type === "error" && !u1(t.error) && (r.onError = !0), this.updateResult(r), this.hasListeners() && this.updateTimers();
}
notify(t) {
Aa.batch(() => {
if (t.onSuccess) {
var r, n, a, u;
(r = (n = this.options).onSuccess) == null || r.call(n, this.currentResult.data), (a = (u = this.options).onSettled) == null || a.call(u, this.currentResult.data, null);
} else if (t.onError) {
var o, c, i, s;
(o = (c = this.options).onError) == null || o.call(c, this.currentResult.error), (i = (s = this.options).onSettled) == null || i.call(s, void 0, this.currentResult.error);
}
t.listeners && this.listeners.forEach(({
listener: p
}) => {
p(this.currentResult);
}), t.cache && this.client.getQueryCache().notify({
query: this.currentQuery,
type: "observerResultsUpdated"
});
});
}
}
function CH(e, t) {
return t.enabled !== !1 && !e.state.dataUpdatedAt && !(e.state.status === "error" && t.retryOnMount === !1);
}
function R3(e, t) {
return CH(e, t) || e.state.dataUpdatedAt > 0 && L2(e, t, t.refetchOnMount);
}
function L2(e, t, r) {
if (t.enabled !== !1) {
const n = typeof r == "function" ? r(e) : r;
return n === "always" || n !== !1 && LT(e, t);
}
return !1;
}
function A3(e, t, r, n) {
return r.enabled !== !1 && (e !== t || n.enabled === !1) && (!r.suspense || e.state.status !== "error") && LT(e, r);
}
function LT(e, t) {
return e.isStaleByTime(t.staleTime);
}
function bH(e, t, r) {
return r.keepPreviousData ? !1 : r.placeholderData !== void 0 ? t.isPlaceholderData : !F2(e.getCurrentResult(), t);
}
class wH extends eg {
constructor(t, r) {
super(), this.client = t, this.queries = [], this.result = [], this.observers = [], this.observersMap = {}, r && this.setQueries(r);
}
onSubscribe() {
this.listeners.size === 1 && this.observers.forEach((t) => {
t.subscribe((r) => {
this.onUpdate(t, r);
});
});
}
onUnsubscribe() {
this.listeners.size || this.destroy();
}
destroy() {
this.listeners = /* @__PURE__ */ new Set(), this.observers.forEach((t) => {
t.destroy();
});
}
setQueries(t, r) {
this.queries = t, Aa.batch(() => {
const n = this.observers, a = this.findMatchingObservers(this.queries);
a.forEach((s) => s.observer.setOptions(s.defaultedQueryO