UNPKG

climb-onyx-gui

Version:
1,542 lines 4.64 MB
import { jsx as Se, jsxs as ur, Fragment as Jo } from "react/jsx-runtime"; import * as ir from "react"; import Fr, { useContext as Mn, useRef as gr, useState as cr, useCallback as Kr, useEffect as _n, useMemo as Rr, cloneElement as nb, useReducer as HG, createContext as by, useLayoutEffect as lc, forwardRef as lp, useImperativeHandle as ib, Component as GP, Fragment as g2, memo as ks, createElement as BG } from "react"; class Jv { 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 iy = typeof window > "u" || "Deno" in window; function zl() { } function VG(e, t) { return typeof e == "function" ? e(t) : e; } function m2(e) { return typeof e == "number" && e >= 0 && e !== 1 / 0; } function qD(e, t) { return e.filter((r) => !t.includes(r)); } function zG(e, t, r) { const n = e.slice(0); return n[t] = r, n; } function HP(e, t) { return Math.max(e + (t || 0) - Date.now(), 0); } function zm(e, t, r) { return ab(e) ? typeof t == "function" ? { ...r, queryKey: e, queryFn: t } : { ...t, queryKey: e } : e; } function cf(e, t, r) { return ab(e) ? [{ ...t, queryKey: e }, r] : [e || {}, t]; } function e3(e, t) { const { type: r = "all", exact: n, fetchStatus: a, predicate: u, queryKey: o, stale: c } = e; if (ab(o)) { if (n) { if (t.queryHash !== yT(o, t.options)) return !1; } else if (!Iv(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 t3(e, t) { const { exact: r, fetching: n, predicate: a, mutationKey: u } = e; if (ab(u)) { if (!t.options.mutationKey) return !1; if (r) { if (Uh(t.options.mutationKey) !== Uh(u)) return !1; } else if (!Iv(t.options.mutationKey, u)) return !1; } return !(typeof n == "boolean" && t.state.status === "loading" !== n || a && !a(t)); } function yT(e, t) { return ((t == null ? void 0 : t.queryKeyHashFn) || Uh)(e); } function Uh(e) { return JSON.stringify(e, (t, r) => C2(r) ? Object.keys(r).sort().reduce((n, a) => (n[a] = r[a], n), {}) : r); } function Iv(e, t) { return BP(e, t); } function BP(e, t) { return e === t ? !0 : typeof e != typeof t ? !1 : e && t && typeof e == "object" && typeof t == "object" ? !Object.keys(t).some((r) => !BP(e[r], t[r])) : !1; } function VP(e, t) { if (e === t) return e; const r = r3(e) && r3(t); if (r || C2(e) && C2(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] = VP(e[s], t[s]), o[s] === e[s] && c++; } return n === u && c === n ? e : o; } return t; } function y2(e, t) { if (e && !t || t && !e) return !1; for (const r in e) if (e[r] !== t[r]) return !1; return !0; } function r3(e) { return Array.isArray(e) && e.length === Object.keys(e).length; } function C2(e) { if (!n3(e)) return !1; const t = e.constructor; if (typeof t > "u") return !0; const r = t.prototype; return !(!n3(r) || !r.hasOwnProperty("isPrototypeOf")); } function n3(e) { return Object.prototype.toString.call(e) === "[object Object]"; } function ab(e) { return Array.isArray(e); } function zP(e) { return new Promise((t) => { setTimeout(t, e); }); } function i3(e) { zP(0).then(e); } function _G() { if (typeof AbortController == "function") return new AbortController(); } function b2(e, t, r) { return r.isDataEqual != null && r.isDataEqual(e, t) ? e : typeof r.structuralSharing == "function" ? r.structuralSharing(e, t) : r.structuralSharing !== !1 ? VP(e, t) : t; } class WG extends Jv { constructor() { super(), this.setup = (t) => { if (!iy && 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 C1 = new WG(), a3 = ["online", "offline"]; class UG extends Jv { constructor() { super(), this.setup = (t) => { if (!iy && window.addEventListener) { const r = () => t(); return a3.forEach((n) => { window.addEventListener(n, r, !1); }), () => { a3.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 b1 = new UG(); function jG(e) { return Math.min(1e3 * 2 ** e, 3e4); } function ob(e) { return (e ?? "online") === "online" ? b1.isOnline() : !0; } class _P { constructor(t) { this.revert = t == null ? void 0 : t.revert, this.silent = t == null ? void 0 : t.silent; } } function r1(e) { return e instanceof _P; } function WP(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 _P(y)), e.abort == null || e.abort()); }, s = () => { t = !0; }, p = () => { t = !1; }, d = () => !C1.isFocused() || e.networkMode !== "always" && !b1.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 : jG, T = typeof x == "function" ? x(r, g) : x, F = E === !0 || typeof E == "number" && r < E || typeof E == "function" && E(r, g); if (t || !F) { v(g); return; } r++, e.onFail == null || e.onFail(r, g), zP(T).then(() => { if (d()) return m(); }).then(() => { t ? v(g) : C(); }); }); }; return ob(e.networkMode) ? C() : m().then(C), { promise: c, cancel: i, continue: () => (a == null ? void 0 : a()) ? c : Promise.resolve(), cancelRetry: s, continueRetry: p }; } const CT = console; function YG() { 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) : i3(() => { r(p); }); }, o = (p) => (...d) => { u(() => { p(...d); }); }, c = () => { const p = e; e = [], p.length && i3(() => { n(() => { p.forEach((d) => { r(d); }); }); }); }; return { batch: a, batchCalls: o, schedule: u, setNotifyFunction: (p) => { r = p; }, setBatchNotifyFunction: (p) => { n = p; } }; } const Ra = YG(); class UP { destroy() { this.clearGcTimeout(); } scheduleGc() { this.clearGcTimeout(), m2(this.cacheTime) && (this.gcTimeout = setTimeout(() => { this.optionalRemove(); }, this.cacheTime)); } updateCacheTime(t) { this.cacheTime = Math.max(this.cacheTime || 0, t ?? (iy ? 1 / 0 : 5 * 60 * 1e3)); } clearGcTimeout() { this.gcTimeout && (clearTimeout(this.gcTimeout), this.gcTimeout = void 0); } } class $G extends UP { constructor(t) { super(), this.abortSignalConsumed = !1, this.defaultOptions = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.cache = t.cache, this.logger = t.logger || CT, this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.initialState = t.state || XG(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 = b2(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(zl).catch(zl) : 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 || !HP(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 = _G(), 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 (r1(v) && v.silent || this.dispatch({ type: "error", error: v }), !r1(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 = WP({ 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: ob(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 r1(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), Ra.batch(() => { this.observers.forEach((n) => { n.onQueryUpdate(t); }), this.cache.notify({ query: this, type: "updated", action: t }); }); } } function XG(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 ZG extends Jv { 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 : yT(u, r); let c = this.get(o); return c || (c = new $G({ 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() { Ra.batch(() => { this.queries.forEach((t) => { this.remove(t); }); }); } get(t) { return this.queriesMap[t]; } getAll() { return this.queries; } find(t, r) { const [n] = cf(t, r); return typeof n.exact > "u" && (n.exact = !0), this.queries.find((a) => e3(n, a)); } findAll(t, r) { const [n] = cf(t, r); return Object.keys(n).length > 0 ? this.queries.filter((a) => e3(n, a)) : this.queries; } notify(t) { Ra.batch(() => { this.listeners.forEach(({ listener: r }) => { r(t); }); }); } onFocus() { Ra.batch(() => { this.queries.forEach((t) => { t.onFocus(); }); }); } onOnline() { Ra.batch(() => { this.queries.forEach((t) => { t.onOnline(); }); }); } } class KG extends UP { constructor(t) { super(), this.defaultOptions = t.defaultOptions, this.mutationId = t.mutationId, this.mutationCache = t.mutationCache, this.logger = t.logger || CT, this.observers = [], this.state = t.state || QG(), 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 F; return this.retryer = WP({ fn: () => this.options.mutationFn ? this.options.mutationFn(this.state.variables) : Promise.reject("No mutationFn found"), onFail: (D, k) => { this.dispatch({ type: "failed", failureCount: D, error: k }); }, onPause: () => { this.dispatch({ type: "pause" }); }, onContinue: () => { this.dispatch({ type: "continue" }); }, retry: (F = this.options.retry) != null ? F : 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 D = await ((v = (m = this.options).onMutate) == null ? void 0 : v.call(m, this.state.variables)); D !== this.state.context && this.dispatch({ type: "loading", context: D, variables: this.state.variables }); } const F = await t(); return await ((n = (a = this.mutationCache.config).onSuccess) == null ? void 0 : n.call(a, F, this.state.variables, this.state.context, this)), await ((u = (o = this.options).onSuccess) == null ? void 0 : u.call(o, F, this.state.variables, this.state.context)), await ((c = (i = this.mutationCache.config).onSettled) == null ? void 0 : c.call(i, F, null, this.state.variables, this.state.context, this)), await ((s = (p = this.options).onSettled) == null ? void 0 : s.call(p, F, null, this.state.variables, this.state.context)), this.dispatch({ type: "success", data: F }), F; } catch (F) { try { var C, y, g, w, S, E, x, T; throw await ((C = (y = this.mutationCache.config).onError) == null ? void 0 : C.call(y, F, this.state.variables, this.state.context, this)), process.env.NODE_ENV !== "production" && this.logger.error(F), await ((g = (w = this.options).onError) == null ? void 0 : g.call(w, F, this.state.variables, this.state.context)), await ((S = (E = this.mutationCache.config).onSettled) == null ? void 0 : S.call(E, void 0, F, this.state.variables, this.state.context, this)), await ((x = (T = this.options).onSettled) == null ? void 0 : x.call(T, void 0, F, this.state.variables, this.state.context)), F; } finally { this.dispatch({ type: "error", error: F }); } } } 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: !ob(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), Ra.batch(() => { this.observers.forEach((n) => { n.onMutationUpdate(t); }), this.mutationCache.notify({ mutation: this, type: "updated", action: t }); }); } } function QG() { return { context: void 0, data: void 0, error: null, failureCount: 0, failureReason: null, isPaused: !1, status: "idle", variables: void 0 }; } class JG extends Jv { constructor(t) { super(), this.config = t || {}, this.mutations = [], this.mutationId = 0; } build(t, r, n) { const a = new KG({ 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() { Ra.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) => t3(t, r)); } findAll(t) { return this.mutations.filter((r) => t3(t, r)); } notify(t) { Ra.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 Ra.batch(() => r.reduce((n, a) => n.then(() => a.continue().catch(zl)), Promise.resolve())); }).then(() => { this.resuming = void 0; }), this.resuming; } } function qG() { 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 F; if ((F = e.signal) != null && F.aborted) C = !0; else { var D; (D = e.signal) == null || D.addEventListener("abort", () => { C = !0; }); } return e.signal; } }); }, g = e.options.queryFn || (() => Promise.reject("Missing queryFn for queryKey '" + e.options.queryHash + "'")), w = (T, F, D, k) => (m = k ? [F, ...m] : [...m, F], k ? [D, ...T] : [...T, D]), S = (T, F, D, k) => { if (C) return Promise.reject("Cancelled"); if (typeof D > "u" && !F && T.length) return Promise.resolve(T); const M = { queryKey: e.queryKey, pageParam: D, meta: e.options.meta }; y(M); const L = g(M); return Promise.resolve(L).then((O) => w(T, D, O, k)); }; let E; if (!h.length) E = S([]); else if (p) { const T = typeof s < "u", F = T ? s : o3(e.options, h); E = S(h, T, F); } else if (d) { const T = typeof s < "u", F = T ? s : eH(e.options, h); E = S(h, T, F, !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 D = 1; D < h.length; D++) E = E.then((k) => { if (c && h[D] ? c(h[D], D, h) : !0) { const L = T ? v[D] : o3(e.options, k); return S(k, T, L); } return Promise.resolve(w(k, v[D], h[D])); }); } return E.then((T) => ({ pages: T, pageParams: m })); }; } }; } function o3(e, t) { return e.getNextPageParam == null ? void 0 : e.getNextPageParam(t[t.length - 1], t); } function eH(e, t) { return e.getPreviousPageParam == null ? void 0 : e.getPreviousPageParam(t[0], t); } class tH { constructor(t = {}) { this.queryCache = t.queryCache || new ZG(), this.mutationCache = t.mutationCache || new JG(), this.logger = t.logger || CT, 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 = C1.subscribe(() => { C1.isFocused() && (this.resumePausedMutations(), this.queryCache.onFocus()); }), this.unsubscribeOnline = b1.subscribe(() => { b1.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] = cf(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 = zm(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 = VG(r, u); if (typeof o > "u") return; const c = zm(t), i = this.defaultQueryOptions(c); return this.queryCache.build(this, i).setData(o, { ...n, manual: !0 }); } setQueriesData(t, r, n) { return Ra.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] = cf(t, r), a = this.queryCache; Ra.batch(() => { a.findAll(n).forEach((u) => { a.remove(u); }); }); } resetQueries(t, r, n) { const [a, u] = cf(t, r, n), o = this.queryCache, c = { type: "active", ...a }; return Ra.batch(() => (o.findAll(a).forEach((i) => { i.reset(); }), this.refetchQueries(c, u))); } cancelQueries(t, r, n) { const [a, u = {}] = cf(t, r, n); typeof u.revert > "u" && (u.revert = !0); const o = Ra.batch(() => this.queryCache.findAll(a).map((c) => c.cancel(u))); return Promise.all(o).then(zl).catch(zl); } invalidateQueries(t, r, n) { const [a, u] = cf(t, r, n); return Ra.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] = cf(t, r, n), o = Ra.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(zl); return u != null && u.throwOnError || (c = c.catch(zl)), c; } fetchQuery(t, r, n) { const a = zm(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(zl).catch(zl); } fetchInfiniteQuery(t, r, n) { const a = zm(t, r, n); return a.behavior = qG(), this.fetchQuery(a); } prefetchInfiniteQuery(t, r, n) { return this.fetchInfiniteQuery(t, r, n).then(zl).catch(zl); } 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) => Uh(t) === Uh(a.queryKey)); n ? n.defaultOptions = r : this.queryDefaults.push({ queryKey: t, defaultOptions: r }); } getQueryDefaults(t) { if (!t) return; const r = this.queryDefaults.find((n) => Iv(t, n.queryKey)); return process.env.NODE_ENV !== "production" && this.queryDefaults.filter((a) => Iv(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) => Uh(t) === Uh(a.mutationKey)); n ? n.defaultOptions = r : this.mutationDefaults.push({ mutationKey: t, defaultOptions: r }); } getMutationDefaults(t) { if (!t) return; const r = this.mutationDefaults.find((n) => Iv(t, n.mutationKey)); return process.env.NODE_ENV !== "production" && this.mutationDefaults.filter((a) => Iv(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 = yT(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 jP extends Jv { 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), s3(this.currentQuery, this.options) && this.executeFetch(), this.updateTimers()); } onUnsubscribe() { this.hasListeners() || this.destroy(); } shouldFetchOnReconnect() { return w2(this.currentQuery, this.options, this.options.refetchOnReconnect); } shouldFetchOnWindowFocus() { return w2(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"), y2(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 && l3(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 nH(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(zl)), r; } updateStaleTimeout() { if (this.clearStaleTimeout(), iy || this.currentResult.isStale || !m2(this.options.staleTime)) return; const r = HP(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, !(iy || this.options.enabled === !1 || !m2(this.currentRefetchInterval) || this.currentRefetchInterval === 0) && (this.refetchIntervalId = setInterval(() => { (this.options.refetchIntervalInBackground || C1.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 D = this.hasListeners(), k = !D && s3(t, r), M = D && l3(t, n, r, a); (k || M) && (C = ob(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 = b2(u == null ? void 0 : u.data, S, r), this.selectResult = S, this.selectError = null; } catch (D) { process.env.NODE_ENV !== "production" && this.client.getLogger().error(D), this.selectError = D; } else S = d.data; if (typeof r.placeholderData < "u" && typeof S > "u" && y === "loading") { let D; if (u != null && u.isPlaceholderData && r.placeholderData === (c == null ? void 0 : c.placeholderData)) D = u.data; else if (D = typeof r.placeholderData == "function" ? r.placeholderData() : r.placeholderData, r.select && typeof D < "u") try { D = r.select(D), this.selectError = null; } catch (k) { process.env.NODE_ENV !== "production" && this.client.getLogger().error(k), this.selectError = k; } typeof D < "u" && (y = "success", S = b2(u == null ? void 0 : u.data, D, 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: bT(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, y2(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" && !r1(t.error) && (r.onError = !0), this.updateResult(r), this.hasListeners() && this.updateTimers(); } notify(t) { Ra.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 rH(e, t) { return t.enabled !== !1 && !e.state.dataUpdatedAt && !(e.state.status === "error" && t.retryOnMount === !1); } function s3(e, t) { return rH(e, t) || e.state.dataUpdatedAt > 0 && w2(e, t, t.refetchOnMount); } function w2(e, t, r) { if (t.enabled !== !1) { const n = typeof r == "function" ? r(e) : r; return n === "always" || n !== !1 && bT(e, t); } return !1; } function l3(e, t, r, n) { return r.enabled !== !1 && (e !== t || n.enabled === !1) && (!r.suspense || e.state.status !== "error") && bT(e, r); } function bT(e, t) { return e.isStaleByTime(t.staleTime); } function nH(e, t, r) { return r.keepPreviousData ? !1 : r.placeholderData !== void 0 ? t.isPlaceholderData : !y2(e.getCurrentResult(), t); } class iH extends Jv { 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, Ra.batch(() => { const n = this.observers, a = this.findMatchingObservers(this.queries); a.forEach((s) => s.observer.setOptions(s.defaultedQueryO