@scrippsproduct/networks-ui-library 1.1.0-alpha.7 → 1.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +1,1926 @@
1
- import { jsx as S } from "react/jsx-runtime";
2
- import { createContext as g, useState as y, useRef as v, useCallback as x, useEffect as b, useMemo as j } from "react";
3
- const D = g(void 0);
4
- function L({
5
- schedule: r,
6
- weeks: a,
7
- handleDateChanged: o = () => !0,
8
- children: c
1
+ var ye = (e) => {
2
+ throw TypeError(e);
3
+ };
4
+ var $t = (e, t, s) => t.has(e) || ye("Cannot " + s);
5
+ var r = (e, t, s) => ($t(e, t, "read from private field"), s ? s.call(e) : t.get(e)), c = (e, t, s) => t.has(e) ? ye("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), o = (e, t, s, i) => ($t(e, t, "write to private field"), i ? i.call(e, s) : t.set(e, s), s), v = (e, t, s) => ($t(e, t, "access private method"), s);
6
+ var Ht = (e, t, s, i) => ({
7
+ set _(n) {
8
+ o(e, t, n, s);
9
+ },
10
+ get _() {
11
+ return r(e, t, i);
12
+ }
13
+ });
14
+ import { jsx as Bt } from "react/jsx-runtime";
15
+ import * as K from "react";
16
+ import { createContext as ze, useState as pe, useRef as $e, useCallback as We, useEffect as Je, useMemo as Ze } from "react";
17
+ import { f as Wt } from "../../format-YhWt2D8M.mjs";
18
+ import { l as me } from "../../logger-C0N7U0YY.mjs";
19
+ var Kt = class {
20
+ constructor() {
21
+ this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
22
+ }
23
+ subscribe(e) {
24
+ return this.listeners.add(e), this.onSubscribe(), () => {
25
+ this.listeners.delete(e), this.onUnsubscribe();
26
+ };
27
+ }
28
+ hasListeners() {
29
+ return this.listeners.size > 0;
30
+ }
31
+ onSubscribe() {
32
+ }
33
+ onUnsubscribe() {
34
+ }
35
+ }, Xe = {
36
+ // We need the wrapper function syntax below instead of direct references to
37
+ // global setTimeout etc.
38
+ //
39
+ // BAD: `setTimeout: setTimeout`
40
+ // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
41
+ //
42
+ // If we use direct references here, then anything that wants to spy on or
43
+ // replace the global setTimeout (like tests) won't work since we'll already
44
+ // have a hard reference to the original implementation at the time when this
45
+ // file was imported.
46
+ setTimeout: (e, t) => setTimeout(e, t),
47
+ clearTimeout: (e) => clearTimeout(e),
48
+ setInterval: (e, t) => setInterval(e, t),
49
+ clearInterval: (e) => clearInterval(e)
50
+ }, G, ht, Me, Ye = (Me = class {
51
+ constructor() {
52
+ // We cannot have TimeoutManager<T> as we must instantiate it with a concrete
53
+ // type at app boot; and if we leave that type, then any new timer provider
54
+ // would need to support ReturnType<typeof setTimeout>, which is infeasible.
55
+ //
56
+ // We settle for type safety for the TimeoutProvider type, and accept that
57
+ // this class is unsafe internally to allow for extension.
58
+ c(this, G, Xe);
59
+ c(this, ht, !1);
60
+ }
61
+ setTimeoutProvider(e) {
62
+ process.env.NODE_ENV !== "production" && r(this, ht) && e !== r(this, G) && console.error(
63
+ "[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",
64
+ { previous: r(this, G), provider: e }
65
+ ), o(this, G, e), process.env.NODE_ENV !== "production" && o(this, ht, !1);
66
+ }
67
+ setTimeout(e, t) {
68
+ return process.env.NODE_ENV !== "production" && o(this, ht, !0), r(this, G).setTimeout(e, t);
69
+ }
70
+ clearTimeout(e) {
71
+ r(this, G).clearTimeout(e);
72
+ }
73
+ setInterval(e, t) {
74
+ return process.env.NODE_ENV !== "production" && o(this, ht, !0), r(this, G).setInterval(e, t);
75
+ }
76
+ clearInterval(e) {
77
+ r(this, G).clearInterval(e);
78
+ }
79
+ }, G = new WeakMap(), ht = new WeakMap(), Me), ut = new Ye();
80
+ function ts(e) {
81
+ setTimeout(e, 0);
82
+ }
83
+ var bt = typeof window > "u" || "Deno" in globalThis;
84
+ function j() {
85
+ }
86
+ function es(e, t) {
87
+ return typeof e == "function" ? e(t) : e;
88
+ }
89
+ function Jt(e) {
90
+ return typeof e == "number" && e >= 0 && e !== 1 / 0;
91
+ }
92
+ function Ne(e, t) {
93
+ return Math.max(e + (t || 0) - Date.now(), 0);
94
+ }
95
+ function ot(e, t) {
96
+ return typeof e == "function" ? e(t) : e;
97
+ }
98
+ function k(e, t) {
99
+ return typeof e == "function" ? e(t) : e;
100
+ }
101
+ function ve(e, t) {
102
+ const {
103
+ type: s = "all",
104
+ exact: i,
105
+ fetchStatus: n,
106
+ predicate: a,
107
+ queryKey: h,
108
+ stale: u
109
+ } = e;
110
+ if (h) {
111
+ if (i) {
112
+ if (t.queryHash !== le(h, t.options))
113
+ return !1;
114
+ } else if (!xt(t.queryKey, h))
115
+ return !1;
116
+ }
117
+ if (s !== "all") {
118
+ const d = t.isActive();
119
+ if (s === "active" && !d || s === "inactive" && d)
120
+ return !1;
121
+ }
122
+ return !(typeof u == "boolean" && t.isStale() !== u || n && n !== t.state.fetchStatus || a && !a(t));
123
+ }
124
+ function ge(e, t) {
125
+ const { exact: s, status: i, predicate: n, mutationKey: a } = e;
126
+ if (a) {
127
+ if (!t.options.mutationKey)
128
+ return !1;
129
+ if (s) {
130
+ if (At(t.options.mutationKey) !== At(a))
131
+ return !1;
132
+ } else if (!xt(t.options.mutationKey, a))
133
+ return !1;
134
+ }
135
+ return !(i && t.state.status !== i || n && !n(t));
136
+ }
137
+ function le(e, t) {
138
+ return ((t == null ? void 0 : t.queryKeyHashFn) || At)(e);
139
+ }
140
+ function At(e) {
141
+ return JSON.stringify(
142
+ e,
143
+ (t, s) => Yt(s) ? Object.keys(s).sort().reduce((i, n) => (i[n] = s[n], i), {}) : s
144
+ );
145
+ }
146
+ function xt(e, t) {
147
+ return e === t ? !0 : typeof e != typeof t ? !1 : e && t && typeof e == "object" && typeof t == "object" ? Object.keys(t).every((s) => xt(e[s], t[s])) : !1;
148
+ }
149
+ var ss = Object.prototype.hasOwnProperty;
150
+ function Zt(e, t) {
151
+ if (e === t)
152
+ return e;
153
+ const s = be(e) && be(t);
154
+ if (!s && !(Yt(e) && Yt(t))) return t;
155
+ const n = (s ? e : Object.keys(e)).length, a = s ? t : Object.keys(t), h = a.length, u = s ? new Array(h) : {};
156
+ let d = 0;
157
+ for (let b = 0; b < h; b++) {
158
+ const S = s ? b : a[b], f = e[S], O = t[S];
159
+ if (f === O) {
160
+ u[S] = f, (s ? b < n : ss.call(e, S)) && d++;
161
+ continue;
162
+ }
163
+ if (f === null || O === null || typeof f != "object" || typeof O != "object") {
164
+ u[S] = O;
165
+ continue;
166
+ }
167
+ const y = Zt(f, O);
168
+ u[S] = y, y === f && d++;
169
+ }
170
+ return n === h && d === n ? e : u;
171
+ }
172
+ function Xt(e, t) {
173
+ if (!t || Object.keys(e).length !== Object.keys(t).length)
174
+ return !1;
175
+ for (const s in e)
176
+ if (e[s] !== t[s])
177
+ return !1;
178
+ return !0;
179
+ }
180
+ function be(e) {
181
+ return Array.isArray(e) && e.length === Object.keys(e).length;
182
+ }
183
+ function Yt(e) {
184
+ if (!we(e))
185
+ return !1;
186
+ const t = e.constructor;
187
+ if (t === void 0)
188
+ return !0;
189
+ const s = t.prototype;
190
+ return !(!we(s) || !s.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(e) !== Object.prototype);
191
+ }
192
+ function we(e) {
193
+ return Object.prototype.toString.call(e) === "[object Object]";
194
+ }
195
+ function rs(e) {
196
+ return new Promise((t) => {
197
+ ut.setTimeout(t, e);
198
+ });
199
+ }
200
+ function te(e, t, s) {
201
+ if (typeof s.structuralSharing == "function")
202
+ return s.structuralSharing(e, t);
203
+ if (s.structuralSharing !== !1) {
204
+ if (process.env.NODE_ENV !== "production")
205
+ try {
206
+ return Zt(e, t);
207
+ } catch (i) {
208
+ throw console.error(
209
+ `Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${s.queryHash}]: ${i}`
210
+ ), i;
211
+ }
212
+ return Zt(e, t);
213
+ }
214
+ return t;
215
+ }
216
+ function is(e, t, s = 0) {
217
+ const i = [...e, t];
218
+ return s && i.length > s ? i.slice(1) : i;
219
+ }
220
+ function ns(e, t, s = 0) {
221
+ const i = [t, ...e];
222
+ return s && i.length > s ? i.slice(0, -1) : i;
223
+ }
224
+ var Vt = Symbol();
225
+ function _e(e, t) {
226
+ return process.env.NODE_ENV !== "production" && e.queryFn === Vt && console.error(
227
+ `Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`
228
+ ), !e.queryFn && (t != null && t.initialPromise) ? () => t.initialPromise : !e.queryFn || e.queryFn === Vt ? () => Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)) : e.queryFn;
229
+ }
230
+ function as(e, t) {
231
+ return typeof e == "function" ? e(...t) : !!e;
232
+ }
233
+ var ct, tt, Ct, Qe, os = (Qe = class extends Kt {
234
+ constructor() {
235
+ super();
236
+ c(this, ct);
237
+ c(this, tt);
238
+ c(this, Ct);
239
+ o(this, Ct, (t) => {
240
+ if (!bt && window.addEventListener) {
241
+ const s = () => t();
242
+ return window.addEventListener("visibilitychange", s, !1), () => {
243
+ window.removeEventListener("visibilitychange", s);
244
+ };
245
+ }
246
+ });
247
+ }
248
+ onSubscribe() {
249
+ r(this, tt) || this.setEventListener(r(this, Ct));
250
+ }
251
+ onUnsubscribe() {
252
+ var t;
253
+ this.hasListeners() || ((t = r(this, tt)) == null || t.call(this), o(this, tt, void 0));
254
+ }
255
+ setEventListener(t) {
256
+ var s;
257
+ o(this, Ct, t), (s = r(this, tt)) == null || s.call(this), o(this, tt, t((i) => {
258
+ typeof i == "boolean" ? this.setFocused(i) : this.onFocus();
259
+ }));
260
+ }
261
+ setFocused(t) {
262
+ r(this, ct) !== t && (o(this, ct, t), this.onFocus());
263
+ }
264
+ onFocus() {
265
+ const t = this.isFocused();
266
+ this.listeners.forEach((s) => {
267
+ s(t);
268
+ });
269
+ }
270
+ isFocused() {
271
+ var t;
272
+ return typeof r(this, ct) == "boolean" ? r(this, ct) : ((t = globalThis.document) == null ? void 0 : t.visibilityState) !== "hidden";
273
+ }
274
+ }, ct = new WeakMap(), tt = new WeakMap(), Ct = new WeakMap(), Qe), de = new os();
275
+ function ee() {
276
+ let e, t;
277
+ const s = new Promise((n, a) => {
278
+ e = n, t = a;
279
+ });
280
+ s.status = "pending", s.catch(() => {
281
+ });
282
+ function i(n) {
283
+ Object.assign(s, n), delete s.resolve, delete s.reject;
284
+ }
285
+ return s.resolve = (n) => {
286
+ i({
287
+ status: "fulfilled",
288
+ value: n
289
+ }), e(n);
290
+ }, s.reject = (n) => {
291
+ i({
292
+ status: "rejected",
293
+ reason: n
294
+ }), t(n);
295
+ }, s;
296
+ }
297
+ var us = ts;
298
+ function hs() {
299
+ let e = [], t = 0, s = (u) => {
300
+ u();
301
+ }, i = (u) => {
302
+ u();
303
+ }, n = us;
304
+ const a = (u) => {
305
+ t ? e.push(u) : n(() => {
306
+ s(u);
307
+ });
308
+ }, h = () => {
309
+ const u = e;
310
+ e = [], u.length && n(() => {
311
+ i(() => {
312
+ u.forEach((d) => {
313
+ s(d);
314
+ });
315
+ });
316
+ });
317
+ };
318
+ return {
319
+ batch: (u) => {
320
+ let d;
321
+ t++;
322
+ try {
323
+ d = u();
324
+ } finally {
325
+ t--, t || h();
326
+ }
327
+ return d;
328
+ },
329
+ /**
330
+ * All calls to the wrapped function will be batched.
331
+ */
332
+ batchCalls: (u) => (...d) => {
333
+ a(() => {
334
+ u(...d);
335
+ });
336
+ },
337
+ schedule: a,
338
+ /**
339
+ * Use this method to set a custom notify function.
340
+ * This can be used to for example wrap notifications with `React.act` while running tests.
341
+ */
342
+ setNotifyFunction: (u) => {
343
+ s = u;
344
+ },
345
+ /**
346
+ * Use this method to set a custom function to batch notifications together into a single tick.
347
+ * By default React Query will use the batch function provided by ReactDOM or React Native.
348
+ */
349
+ setBatchNotifyFunction: (u) => {
350
+ i = u;
351
+ },
352
+ setScheduler: (u) => {
353
+ n = u;
354
+ }
355
+ };
356
+ }
357
+ var T = hs(), St, et, Ot, De, cs = (De = class extends Kt {
358
+ constructor() {
359
+ super();
360
+ c(this, St, !0);
361
+ c(this, et);
362
+ c(this, Ot);
363
+ o(this, Ot, (t) => {
364
+ if (!bt && window.addEventListener) {
365
+ const s = () => t(!0), i = () => t(!1);
366
+ return window.addEventListener("online", s, !1), window.addEventListener("offline", i, !1), () => {
367
+ window.removeEventListener("online", s), window.removeEventListener("offline", i);
368
+ };
369
+ }
370
+ });
371
+ }
372
+ onSubscribe() {
373
+ r(this, et) || this.setEventListener(r(this, Ot));
374
+ }
375
+ onUnsubscribe() {
376
+ var t;
377
+ this.hasListeners() || ((t = r(this, et)) == null || t.call(this), o(this, et, void 0));
378
+ }
379
+ setEventListener(t) {
380
+ var s;
381
+ o(this, Ot, t), (s = r(this, et)) == null || s.call(this), o(this, et, t(this.setOnline.bind(this)));
382
+ }
383
+ setOnline(t) {
384
+ r(this, St) !== t && (o(this, St, t), this.listeners.forEach((i) => {
385
+ i(t);
386
+ }));
387
+ }
388
+ isOnline() {
389
+ return r(this, St);
390
+ }
391
+ }, St = new WeakMap(), et = new WeakMap(), Ot = new WeakMap(), De), zt = new cs();
392
+ function ls(e) {
393
+ return Math.min(1e3 * 2 ** e, 3e4);
394
+ }
395
+ function ke(e) {
396
+ return (e ?? "online") === "online" ? zt.isOnline() : !0;
397
+ }
398
+ var se = class extends Error {
399
+ constructor(e) {
400
+ super("CancelledError"), this.revert = e == null ? void 0 : e.revert, this.silent = e == null ? void 0 : e.silent;
401
+ }
402
+ };
403
+ function Ke(e) {
404
+ let t = !1, s = 0, i;
405
+ const n = ee(), a = () => n.status !== "pending", h = (p) => {
406
+ var m;
407
+ if (!a()) {
408
+ const P = new se(p);
409
+ O(P), (m = e.onCancel) == null || m.call(e, P);
410
+ }
411
+ }, u = () => {
412
+ t = !0;
413
+ }, d = () => {
414
+ t = !1;
415
+ }, b = () => de.isFocused() && (e.networkMode === "always" || zt.isOnline()) && e.canRun(), S = () => ke(e.networkMode) && e.canRun(), f = (p) => {
416
+ a() || (i == null || i(), n.resolve(p));
417
+ }, O = (p) => {
418
+ a() || (i == null || i(), n.reject(p));
419
+ }, y = () => new Promise((p) => {
420
+ var m;
421
+ i = (P) => {
422
+ (a() || b()) && p(P);
423
+ }, (m = e.onPause) == null || m.call(e);
424
+ }).then(() => {
425
+ var p;
426
+ i = void 0, a() || (p = e.onContinue) == null || p.call(e);
427
+ }), R = () => {
428
+ if (a())
429
+ return;
430
+ let p;
431
+ const m = s === 0 ? e.initialPromise : void 0;
432
+ try {
433
+ p = m ?? e.fn();
434
+ } catch (P) {
435
+ p = Promise.reject(P);
436
+ }
437
+ Promise.resolve(p).then(f).catch((P) => {
438
+ var x;
439
+ if (a())
440
+ return;
441
+ const M = e.retry ?? (bt ? 0 : 3), E = e.retryDelay ?? ls, l = typeof E == "function" ? E(s, P) : E, Q = M === !0 || typeof M == "number" && s < M || typeof M == "function" && M(s, P);
442
+ if (t || !Q) {
443
+ O(P);
444
+ return;
445
+ }
446
+ s++, (x = e.onFail) == null || x.call(e, s, P), rs(l).then(() => b() ? void 0 : y()).then(() => {
447
+ t ? O(P) : R();
448
+ });
449
+ });
450
+ };
451
+ return {
452
+ promise: n,
453
+ status: () => n.status,
454
+ cancel: h,
455
+ continue: () => (i == null || i(), n),
456
+ cancelRetry: u,
457
+ continueRetry: d,
458
+ canStart: S,
459
+ start: () => (S() ? R() : y().then(R), n)
460
+ };
461
+ }
462
+ var lt, Te, Le = (Te = class {
463
+ constructor() {
464
+ c(this, lt);
465
+ }
466
+ destroy() {
467
+ this.clearGcTimeout();
468
+ }
469
+ scheduleGc() {
470
+ this.clearGcTimeout(), Jt(this.gcTime) && o(this, lt, ut.setTimeout(() => {
471
+ this.optionalRemove();
472
+ }, this.gcTime));
473
+ }
474
+ updateGcTime(e) {
475
+ this.gcTime = Math.max(
476
+ this.gcTime || 0,
477
+ e ?? (bt ? 1 / 0 : 300 * 1e3)
478
+ );
479
+ }
480
+ clearGcTimeout() {
481
+ r(this, lt) && (ut.clearTimeout(r(this, lt)), o(this, lt, void 0));
482
+ }
483
+ }, lt = new WeakMap(), Te), dt, Pt, _, ft, D, Ut, yt, L, $, Ie, ds = (Ie = class extends Le {
484
+ constructor(t) {
485
+ super();
486
+ c(this, L);
487
+ c(this, dt);
488
+ c(this, Pt);
489
+ c(this, _);
490
+ c(this, ft);
491
+ c(this, D);
492
+ c(this, Ut);
493
+ c(this, yt);
494
+ o(this, yt, !1), o(this, Ut, t.defaultOptions), this.setOptions(t.options), this.observers = [], o(this, ft, t.client), o(this, _, r(this, ft).getQueryCache()), this.queryKey = t.queryKey, this.queryHash = t.queryHash, o(this, dt, Se(this.options)), this.state = t.state ?? r(this, dt), this.scheduleGc();
495
+ }
496
+ get meta() {
497
+ return this.options.meta;
498
+ }
499
+ get promise() {
500
+ var t;
501
+ return (t = r(this, D)) == null ? void 0 : t.promise;
502
+ }
503
+ setOptions(t) {
504
+ if (this.options = { ...r(this, Ut), ...t }, this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
505
+ const s = Se(this.options);
506
+ s.data !== void 0 && (this.setState(
507
+ Ce(s.data, s.dataUpdatedAt)
508
+ ), o(this, dt, s));
509
+ }
510
+ }
511
+ optionalRemove() {
512
+ !this.observers.length && this.state.fetchStatus === "idle" && r(this, _).remove(this);
513
+ }
514
+ setData(t, s) {
515
+ const i = te(this.state.data, t, this.options);
516
+ return v(this, L, $).call(this, {
517
+ data: i,
518
+ type: "success",
519
+ dataUpdatedAt: s == null ? void 0 : s.updatedAt,
520
+ manual: s == null ? void 0 : s.manual
521
+ }), i;
522
+ }
523
+ setState(t, s) {
524
+ v(this, L, $).call(this, { type: "setState", state: t, setStateOptions: s });
525
+ }
526
+ cancel(t) {
527
+ var i, n;
528
+ const s = (i = r(this, D)) == null ? void 0 : i.promise;
529
+ return (n = r(this, D)) == null || n.cancel(t), s ? s.then(j).catch(j) : Promise.resolve();
530
+ }
531
+ destroy() {
532
+ super.destroy(), this.cancel({ silent: !0 });
533
+ }
534
+ reset() {
535
+ this.destroy(), this.setState(r(this, dt));
536
+ }
537
+ isActive() {
538
+ return this.observers.some(
539
+ (t) => k(t.options.enabled, this) !== !1
540
+ );
541
+ }
542
+ isDisabled() {
543
+ return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === Vt || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
544
+ }
545
+ isStatic() {
546
+ return this.getObserversCount() > 0 ? this.observers.some(
547
+ (t) => ot(t.options.staleTime, this) === "static"
548
+ ) : !1;
549
+ }
550
+ isStale() {
551
+ return this.getObserversCount() > 0 ? this.observers.some(
552
+ (t) => t.getCurrentResult().isStale
553
+ ) : this.state.data === void 0 || this.state.isInvalidated;
554
+ }
555
+ isStaleByTime(t = 0) {
556
+ return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !Ne(this.state.dataUpdatedAt, t);
557
+ }
558
+ onFocus() {
559
+ var s;
560
+ const t = this.observers.find((i) => i.shouldFetchOnWindowFocus());
561
+ t == null || t.refetch({ cancelRefetch: !1 }), (s = r(this, D)) == null || s.continue();
562
+ }
563
+ onOnline() {
564
+ var s;
565
+ const t = this.observers.find((i) => i.shouldFetchOnReconnect());
566
+ t == null || t.refetch({ cancelRefetch: !1 }), (s = r(this, D)) == null || s.continue();
567
+ }
568
+ addObserver(t) {
569
+ this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), r(this, _).notify({ type: "observerAdded", query: this, observer: t }));
570
+ }
571
+ removeObserver(t) {
572
+ this.observers.includes(t) && (this.observers = this.observers.filter((s) => s !== t), this.observers.length || (r(this, D) && (r(this, yt) ? r(this, D).cancel({ revert: !0 }) : r(this, D).cancelRetry()), this.scheduleGc()), r(this, _).notify({ type: "observerRemoved", query: this, observer: t }));
573
+ }
574
+ getObserversCount() {
575
+ return this.observers.length;
576
+ }
577
+ invalidate() {
578
+ this.state.isInvalidated || v(this, L, $).call(this, { type: "invalidate" });
579
+ }
580
+ async fetch(t, s) {
581
+ var d, b, S, f, O, y, R, p, m, P, M, E;
582
+ if (this.state.fetchStatus !== "idle" && // If the promise in the retyer is already rejected, we have to definitely
583
+ // re-start the fetch; there is a chance that the query is still in a
584
+ // pending state when that happens
585
+ ((d = r(this, D)) == null ? void 0 : d.status()) !== "rejected") {
586
+ if (this.state.data !== void 0 && (s != null && s.cancelRefetch))
587
+ this.cancel({ silent: !0 });
588
+ else if (r(this, D))
589
+ return r(this, D).continueRetry(), r(this, D).promise;
590
+ }
591
+ if (t && this.setOptions(t), !this.options.queryFn) {
592
+ const l = this.observers.find((Q) => Q.options.queryFn);
593
+ l && this.setOptions(l.options);
594
+ }
595
+ process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
596
+ "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']"
597
+ ));
598
+ const i = new AbortController(), n = (l) => {
599
+ Object.defineProperty(l, "signal", {
600
+ enumerable: !0,
601
+ get: () => (o(this, yt, !0), i.signal)
602
+ });
603
+ }, a = () => {
604
+ const l = _e(this.options, s), x = (() => {
605
+ const Z = {
606
+ client: r(this, ft),
607
+ queryKey: this.queryKey,
608
+ meta: this.meta
609
+ };
610
+ return n(Z), Z;
611
+ })();
612
+ return o(this, yt, !1), this.options.persister ? this.options.persister(
613
+ l,
614
+ x,
615
+ this
616
+ ) : l(x);
617
+ }, u = (() => {
618
+ const l = {
619
+ fetchOptions: s,
620
+ options: this.options,
621
+ queryKey: this.queryKey,
622
+ client: r(this, ft),
623
+ state: this.state,
624
+ fetchFn: a
625
+ };
626
+ return n(l), l;
627
+ })();
628
+ (b = this.options.behavior) == null || b.onFetch(u, this), o(this, Pt, this.state), (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((S = u.fetchOptions) == null ? void 0 : S.meta)) && v(this, L, $).call(this, { type: "fetch", meta: (f = u.fetchOptions) == null ? void 0 : f.meta }), o(this, D, Ke({
629
+ initialPromise: s == null ? void 0 : s.initialPromise,
630
+ fn: u.fetchFn,
631
+ onCancel: (l) => {
632
+ l instanceof se && l.revert && this.setState({
633
+ ...r(this, Pt),
634
+ fetchStatus: "idle"
635
+ }), i.abort();
636
+ },
637
+ onFail: (l, Q) => {
638
+ v(this, L, $).call(this, { type: "failed", failureCount: l, error: Q });
639
+ },
640
+ onPause: () => {
641
+ v(this, L, $).call(this, { type: "pause" });
642
+ },
643
+ onContinue: () => {
644
+ v(this, L, $).call(this, { type: "continue" });
645
+ },
646
+ retry: u.options.retry,
647
+ retryDelay: u.options.retryDelay,
648
+ networkMode: u.options.networkMode,
649
+ canRun: () => !0
650
+ }));
651
+ try {
652
+ const l = await r(this, D).start();
653
+ if (l === void 0)
654
+ throw process.env.NODE_ENV !== "production" && console.error(
655
+ `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
656
+ ), new Error(`${this.queryHash} data is undefined`);
657
+ return this.setData(l), (y = (O = r(this, _).config).onSuccess) == null || y.call(O, l, this), (p = (R = r(this, _).config).onSettled) == null || p.call(
658
+ R,
659
+ l,
660
+ this.state.error,
661
+ this
662
+ ), l;
663
+ } catch (l) {
664
+ if (l instanceof se) {
665
+ if (l.silent)
666
+ return r(this, D).promise;
667
+ if (l.revert) {
668
+ if (this.state.data === void 0)
669
+ throw l;
670
+ return this.state.data;
671
+ }
672
+ }
673
+ throw v(this, L, $).call(this, {
674
+ type: "error",
675
+ error: l
676
+ }), (P = (m = r(this, _).config).onError) == null || P.call(
677
+ m,
678
+ l,
679
+ this
680
+ ), (E = (M = r(this, _).config).onSettled) == null || E.call(
681
+ M,
682
+ this.state.data,
683
+ l,
684
+ this
685
+ ), l;
686
+ } finally {
687
+ this.scheduleGc();
688
+ }
689
+ }
690
+ }, dt = new WeakMap(), Pt = new WeakMap(), _ = new WeakMap(), ft = new WeakMap(), D = new WeakMap(), Ut = new WeakMap(), yt = new WeakMap(), L = new WeakSet(), $ = function(t) {
691
+ const s = (i) => {
692
+ switch (t.type) {
693
+ case "failed":
694
+ return {
695
+ ...i,
696
+ fetchFailureCount: t.failureCount,
697
+ fetchFailureReason: t.error
698
+ };
699
+ case "pause":
700
+ return {
701
+ ...i,
702
+ fetchStatus: "paused"
703
+ };
704
+ case "continue":
705
+ return {
706
+ ...i,
707
+ fetchStatus: "fetching"
708
+ };
709
+ case "fetch":
710
+ return {
711
+ ...i,
712
+ ...He(i.data, this.options),
713
+ fetchMeta: t.meta ?? null
714
+ };
715
+ case "success":
716
+ const n = {
717
+ ...i,
718
+ ...Ce(t.data, t.dataUpdatedAt),
719
+ dataUpdateCount: i.dataUpdateCount + 1,
720
+ ...!t.manual && {
721
+ fetchStatus: "idle",
722
+ fetchFailureCount: 0,
723
+ fetchFailureReason: null
724
+ }
725
+ };
726
+ return o(this, Pt, t.manual ? n : void 0), n;
727
+ case "error":
728
+ const a = t.error;
729
+ return {
730
+ ...i,
731
+ error: a,
732
+ errorUpdateCount: i.errorUpdateCount + 1,
733
+ errorUpdatedAt: Date.now(),
734
+ fetchFailureCount: i.fetchFailureCount + 1,
735
+ fetchFailureReason: a,
736
+ fetchStatus: "idle",
737
+ status: "error"
738
+ };
739
+ case "invalidate":
740
+ return {
741
+ ...i,
742
+ isInvalidated: !0
743
+ };
744
+ case "setState":
745
+ return {
746
+ ...i,
747
+ ...t.state
748
+ };
749
+ }
750
+ };
751
+ this.state = s(this.state), T.batch(() => {
752
+ this.observers.forEach((i) => {
753
+ i.onQueryUpdate();
754
+ }), r(this, _).notify({ query: this, type: "updated", action: t });
755
+ });
756
+ }, Ie);
757
+ function He(e, t) {
758
+ return {
759
+ fetchFailureCount: 0,
760
+ fetchFailureReason: null,
761
+ fetchStatus: ke(t.networkMode) ? "fetching" : "paused",
762
+ ...e === void 0 && {
763
+ error: null,
764
+ status: "pending"
765
+ }
766
+ };
767
+ }
768
+ function Ce(e, t) {
769
+ return {
770
+ data: e,
771
+ dataUpdatedAt: t ?? Date.now(),
772
+ error: null,
773
+ isInvalidated: !1,
774
+ status: "success"
775
+ };
776
+ }
777
+ function Se(e) {
778
+ const t = typeof e.initialData == "function" ? e.initialData() : e.initialData, s = t !== void 0, i = s ? typeof e.initialDataUpdatedAt == "function" ? e.initialDataUpdatedAt() : e.initialDataUpdatedAt : 0;
779
+ return {
780
+ data: t,
781
+ dataUpdateCount: 0,
782
+ dataUpdatedAt: s ? i ?? Date.now() : 0,
783
+ error: null,
784
+ errorUpdateCount: 0,
785
+ errorUpdatedAt: 0,
786
+ fetchFailureCount: 0,
787
+ fetchFailureReason: null,
788
+ fetchMeta: null,
789
+ isInvalidated: !1,
790
+ status: s ? "success" : "pending",
791
+ fetchStatus: "idle"
792
+ };
793
+ }
794
+ var U, g, jt, q, pt, Et, W, st, Nt, Ft, Rt, mt, vt, rt, Mt, C, qt, re, ie, ne, ae, oe, ue, he, Ge, qe, fs = (qe = class extends Kt {
795
+ constructor(t, s) {
796
+ super();
797
+ c(this, C);
798
+ c(this, U);
799
+ c(this, g);
800
+ c(this, jt);
801
+ c(this, q);
802
+ c(this, pt);
803
+ c(this, Et);
804
+ c(this, W);
805
+ c(this, st);
806
+ c(this, Nt);
807
+ c(this, Ft);
808
+ // This property keeps track of the last query with defined data.
809
+ // It will be used to pass the previous data and query to the placeholder function between renders.
810
+ c(this, Rt);
811
+ c(this, mt);
812
+ c(this, vt);
813
+ c(this, rt);
814
+ c(this, Mt, /* @__PURE__ */ new Set());
815
+ this.options = s, o(this, U, t), o(this, st, null), o(this, W, ee()), this.bindMethods(), this.setOptions(s);
816
+ }
817
+ bindMethods() {
818
+ this.refetch = this.refetch.bind(this);
819
+ }
820
+ onSubscribe() {
821
+ this.listeners.size === 1 && (r(this, g).addObserver(this), Oe(r(this, g), this.options) ? v(this, C, qt).call(this) : this.updateResult(), v(this, C, ae).call(this));
822
+ }
823
+ onUnsubscribe() {
824
+ this.hasListeners() || this.destroy();
825
+ }
826
+ shouldFetchOnReconnect() {
827
+ return ce(
828
+ r(this, g),
829
+ this.options,
830
+ this.options.refetchOnReconnect
831
+ );
832
+ }
833
+ shouldFetchOnWindowFocus() {
834
+ return ce(
835
+ r(this, g),
836
+ this.options,
837
+ this.options.refetchOnWindowFocus
838
+ );
839
+ }
840
+ destroy() {
841
+ this.listeners = /* @__PURE__ */ new Set(), v(this, C, oe).call(this), v(this, C, ue).call(this), r(this, g).removeObserver(this);
842
+ }
843
+ setOptions(t) {
844
+ const s = this.options, i = r(this, g);
845
+ if (this.options = r(this, U).defaultQueryOptions(t), this.options.enabled !== void 0 && typeof this.options.enabled != "boolean" && typeof this.options.enabled != "function" && typeof k(this.options.enabled, r(this, g)) != "boolean")
846
+ throw new Error(
847
+ "Expected enabled to be a boolean or a callback that returns a boolean"
848
+ );
849
+ v(this, C, he).call(this), r(this, g).setOptions(this.options), s._defaulted && !Xt(this.options, s) && r(this, U).getQueryCache().notify({
850
+ type: "observerOptionsUpdated",
851
+ query: r(this, g),
852
+ observer: this
853
+ });
854
+ const n = this.hasListeners();
855
+ n && Pe(
856
+ r(this, g),
857
+ i,
858
+ this.options,
859
+ s
860
+ ) && v(this, C, qt).call(this), this.updateResult(), n && (r(this, g) !== i || k(this.options.enabled, r(this, g)) !== k(s.enabled, r(this, g)) || ot(this.options.staleTime, r(this, g)) !== ot(s.staleTime, r(this, g))) && v(this, C, re).call(this);
861
+ const a = v(this, C, ie).call(this);
862
+ n && (r(this, g) !== i || k(this.options.enabled, r(this, g)) !== k(s.enabled, r(this, g)) || a !== r(this, rt)) && v(this, C, ne).call(this, a);
863
+ }
864
+ getOptimisticResult(t) {
865
+ const s = r(this, U).getQueryCache().build(r(this, U), t), i = this.createResult(s, t);
866
+ return ps(this, i) && (o(this, q, i), o(this, Et, this.options), o(this, pt, r(this, g).state)), i;
867
+ }
868
+ getCurrentResult() {
869
+ return r(this, q);
870
+ }
871
+ trackResult(t, s) {
872
+ return new Proxy(t, {
873
+ get: (i, n) => (this.trackProp(n), s == null || s(n), n === "promise" && (this.trackProp("data"), !this.options.experimental_prefetchInRender && r(this, W).status === "pending" && r(this, W).reject(
874
+ new Error(
875
+ "experimental_prefetchInRender feature flag is not enabled"
876
+ )
877
+ )), Reflect.get(i, n))
878
+ });
879
+ }
880
+ trackProp(t) {
881
+ r(this, Mt).add(t);
882
+ }
883
+ getCurrentQuery() {
884
+ return r(this, g);
885
+ }
886
+ refetch({ ...t } = {}) {
887
+ return this.fetch({
888
+ ...t
889
+ });
890
+ }
891
+ fetchOptimistic(t) {
892
+ const s = r(this, U).defaultQueryOptions(t), i = r(this, U).getQueryCache().build(r(this, U), s);
893
+ return i.fetch().then(() => this.createResult(i, s));
894
+ }
895
+ fetch(t) {
896
+ return v(this, C, qt).call(this, {
897
+ ...t,
898
+ cancelRefetch: t.cancelRefetch ?? !0
899
+ }).then(() => (this.updateResult(), r(this, q)));
900
+ }
901
+ createResult(t, s) {
902
+ var X;
903
+ const i = r(this, g), n = this.options, a = r(this, q), h = r(this, pt), u = r(this, Et), b = t !== i ? t.state : r(this, jt), { state: S } = t;
904
+ let f = { ...S }, O = !1, y;
905
+ if (s._optimisticResults) {
906
+ const w = this.hasListeners(), N = !w && Oe(t, s), wt = w && Pe(t, i, s, n);
907
+ (N || wt) && (f = {
908
+ ...f,
909
+ ...He(S.data, t.options)
910
+ }), s._optimisticResults === "isRestoring" && (f.fetchStatus = "idle");
911
+ }
912
+ let { error: R, errorUpdatedAt: p, status: m } = f;
913
+ y = f.data;
914
+ let P = !1;
915
+ if (s.placeholderData !== void 0 && y === void 0 && m === "pending") {
916
+ let w;
917
+ a != null && a.isPlaceholderData && s.placeholderData === (u == null ? void 0 : u.placeholderData) ? (w = a.data, P = !0) : w = typeof s.placeholderData == "function" ? s.placeholderData(
918
+ (X = r(this, Rt)) == null ? void 0 : X.state.data,
919
+ r(this, Rt)
920
+ ) : s.placeholderData, w !== void 0 && (m = "success", y = te(
921
+ a == null ? void 0 : a.data,
922
+ w,
923
+ s
924
+ ), O = !0);
925
+ }
926
+ if (s.select && y !== void 0 && !P)
927
+ if (a && y === (h == null ? void 0 : h.data) && s.select === r(this, Nt))
928
+ y = r(this, Ft);
929
+ else
930
+ try {
931
+ o(this, Nt, s.select), y = s.select(y), y = te(a == null ? void 0 : a.data, y, s), o(this, Ft, y), o(this, st, null);
932
+ } catch (w) {
933
+ o(this, st, w);
934
+ }
935
+ r(this, st) && (R = r(this, st), y = r(this, Ft), p = Date.now(), m = "error");
936
+ const M = f.fetchStatus === "fetching", E = m === "pending", l = m === "error", Q = E && M, x = y !== void 0, I = {
937
+ status: m,
938
+ fetchStatus: f.fetchStatus,
939
+ isPending: E,
940
+ isSuccess: m === "success",
941
+ isError: l,
942
+ isInitialLoading: Q,
943
+ isLoading: Q,
944
+ data: y,
945
+ dataUpdatedAt: f.dataUpdatedAt,
946
+ error: R,
947
+ errorUpdatedAt: p,
948
+ failureCount: f.fetchFailureCount,
949
+ failureReason: f.fetchFailureReason,
950
+ errorUpdateCount: f.errorUpdateCount,
951
+ isFetched: f.dataUpdateCount > 0 || f.errorUpdateCount > 0,
952
+ isFetchedAfterMount: f.dataUpdateCount > b.dataUpdateCount || f.errorUpdateCount > b.errorUpdateCount,
953
+ isFetching: M,
954
+ isRefetching: M && !E,
955
+ isLoadingError: l && !x,
956
+ isPaused: f.fetchStatus === "paused",
957
+ isPlaceholderData: O,
958
+ isRefetchError: l && x,
959
+ isStale: fe(t, s),
960
+ refetch: this.refetch,
961
+ promise: r(this, W),
962
+ isEnabled: k(s.enabled, t) !== !1
963
+ };
964
+ if (this.options.experimental_prefetchInRender) {
965
+ const w = (Lt) => {
966
+ I.status === "error" ? Lt.reject(I.error) : I.data !== void 0 && Lt.resolve(I.data);
967
+ }, N = () => {
968
+ const Lt = o(this, W, I.promise = ee());
969
+ w(Lt);
970
+ }, wt = r(this, W);
971
+ switch (wt.status) {
972
+ case "pending":
973
+ t.queryHash === i.queryHash && w(wt);
974
+ break;
975
+ case "fulfilled":
976
+ (I.status === "error" || I.data !== wt.value) && N();
977
+ break;
978
+ case "rejected":
979
+ (I.status !== "error" || I.error !== wt.reason) && N();
980
+ break;
981
+ }
982
+ }
983
+ return I;
984
+ }
985
+ updateResult() {
986
+ const t = r(this, q), s = this.createResult(r(this, g), this.options);
987
+ if (o(this, pt, r(this, g).state), o(this, Et, this.options), r(this, pt).data !== void 0 && o(this, Rt, r(this, g)), Xt(s, t))
988
+ return;
989
+ o(this, q, s);
990
+ const i = () => {
991
+ if (!t)
992
+ return !0;
993
+ const { notifyOnChangeProps: n } = this.options, a = typeof n == "function" ? n() : n;
994
+ if (a === "all" || !a && !r(this, Mt).size)
995
+ return !0;
996
+ const h = new Set(
997
+ a ?? r(this, Mt)
998
+ );
999
+ return this.options.throwOnError && h.add("error"), Object.keys(r(this, q)).some((u) => {
1000
+ const d = u;
1001
+ return r(this, q)[d] !== t[d] && h.has(d);
1002
+ });
1003
+ };
1004
+ v(this, C, Ge).call(this, { listeners: i() });
1005
+ }
1006
+ onQueryUpdate() {
1007
+ this.updateResult(), this.hasListeners() && v(this, C, ae).call(this);
1008
+ }
1009
+ }, U = new WeakMap(), g = new WeakMap(), jt = new WeakMap(), q = new WeakMap(), pt = new WeakMap(), Et = new WeakMap(), W = new WeakMap(), st = new WeakMap(), Nt = new WeakMap(), Ft = new WeakMap(), Rt = new WeakMap(), mt = new WeakMap(), vt = new WeakMap(), rt = new WeakMap(), Mt = new WeakMap(), C = new WeakSet(), qt = function(t) {
1010
+ v(this, C, he).call(this);
1011
+ let s = r(this, g).fetch(
1012
+ this.options,
1013
+ t
1014
+ );
1015
+ return t != null && t.throwOnError || (s = s.catch(j)), s;
1016
+ }, re = function() {
1017
+ v(this, C, oe).call(this);
1018
+ const t = ot(
1019
+ this.options.staleTime,
1020
+ r(this, g)
1021
+ );
1022
+ if (bt || r(this, q).isStale || !Jt(t))
1023
+ return;
1024
+ const i = Ne(r(this, q).dataUpdatedAt, t) + 1;
1025
+ o(this, mt, ut.setTimeout(() => {
1026
+ r(this, q).isStale || this.updateResult();
1027
+ }, i));
1028
+ }, ie = function() {
1029
+ return (typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(r(this, g)) : this.options.refetchInterval) ?? !1;
1030
+ }, ne = function(t) {
1031
+ v(this, C, ue).call(this), o(this, rt, t), !(bt || k(this.options.enabled, r(this, g)) === !1 || !Jt(r(this, rt)) || r(this, rt) === 0) && o(this, vt, ut.setInterval(() => {
1032
+ (this.options.refetchIntervalInBackground || de.isFocused()) && v(this, C, qt).call(this);
1033
+ }, r(this, rt)));
1034
+ }, ae = function() {
1035
+ v(this, C, re).call(this), v(this, C, ne).call(this, v(this, C, ie).call(this));
1036
+ }, oe = function() {
1037
+ r(this, mt) && (ut.clearTimeout(r(this, mt)), o(this, mt, void 0));
1038
+ }, ue = function() {
1039
+ r(this, vt) && (ut.clearInterval(r(this, vt)), o(this, vt, void 0));
1040
+ }, he = function() {
1041
+ const t = r(this, U).getQueryCache().build(r(this, U), this.options);
1042
+ if (t === r(this, g))
1043
+ return;
1044
+ const s = r(this, g);
1045
+ o(this, g, t), o(this, jt, t.state), this.hasListeners() && (s == null || s.removeObserver(this), t.addObserver(this));
1046
+ }, Ge = function(t) {
1047
+ T.batch(() => {
1048
+ t.listeners && this.listeners.forEach((s) => {
1049
+ s(r(this, q));
1050
+ }), r(this, U).getQueryCache().notify({
1051
+ query: r(this, g),
1052
+ type: "observerResultsUpdated"
1053
+ });
1054
+ });
1055
+ }, qe);
1056
+ function ys(e, t) {
1057
+ return k(t.enabled, e) !== !1 && e.state.data === void 0 && !(e.state.status === "error" && t.retryOnMount === !1);
1058
+ }
1059
+ function Oe(e, t) {
1060
+ return ys(e, t) || e.state.data !== void 0 && ce(e, t, t.refetchOnMount);
1061
+ }
1062
+ function ce(e, t, s) {
1063
+ if (k(t.enabled, e) !== !1 && ot(t.staleTime, e) !== "static") {
1064
+ const i = typeof s == "function" ? s(e) : s;
1065
+ return i === "always" || i !== !1 && fe(e, t);
1066
+ }
1067
+ return !1;
1068
+ }
1069
+ function Pe(e, t, s, i) {
1070
+ return (e !== t || k(i.enabled, e) === !1) && (!s.suspense || e.state.status !== "error") && fe(e, s);
1071
+ }
1072
+ function fe(e, t) {
1073
+ return k(t.enabled, e) !== !1 && e.isStaleByTime(ot(t.staleTime, e));
1074
+ }
1075
+ function ps(e, t) {
1076
+ return !Xt(e.getCurrentResult(), t);
1077
+ }
1078
+ function Ee(e) {
1079
+ return {
1080
+ onFetch: (t, s) => {
1081
+ var S, f, O, y, R;
1082
+ const i = t.options, n = (O = (f = (S = t.fetchOptions) == null ? void 0 : S.meta) == null ? void 0 : f.fetchMore) == null ? void 0 : O.direction, a = ((y = t.state.data) == null ? void 0 : y.pages) || [], h = ((R = t.state.data) == null ? void 0 : R.pageParams) || [];
1083
+ let u = { pages: [], pageParams: [] }, d = 0;
1084
+ const b = async () => {
1085
+ let p = !1;
1086
+ const m = (E) => {
1087
+ Object.defineProperty(E, "signal", {
1088
+ enumerable: !0,
1089
+ get: () => (t.signal.aborted ? p = !0 : t.signal.addEventListener("abort", () => {
1090
+ p = !0;
1091
+ }), t.signal)
1092
+ });
1093
+ }, P = _e(t.options, t.fetchOptions), M = async (E, l, Q) => {
1094
+ if (p)
1095
+ return Promise.reject();
1096
+ if (l == null && E.pages.length)
1097
+ return Promise.resolve(E);
1098
+ const Z = (() => {
1099
+ const N = {
1100
+ client: t.client,
1101
+ queryKey: t.queryKey,
1102
+ pageParam: l,
1103
+ direction: Q ? "backward" : "forward",
1104
+ meta: t.options.meta
1105
+ };
1106
+ return m(N), N;
1107
+ })(), I = await P(Z), { maxPages: X } = t.options, w = Q ? ns : is;
1108
+ return {
1109
+ pages: w(E.pages, I, X),
1110
+ pageParams: w(E.pageParams, l, X)
1111
+ };
1112
+ };
1113
+ if (n && a.length) {
1114
+ const E = n === "backward", l = E ? ms : Fe, Q = {
1115
+ pages: a,
1116
+ pageParams: h
1117
+ }, x = l(i, Q);
1118
+ u = await M(Q, x, E);
1119
+ } else {
1120
+ const E = e ?? a.length;
1121
+ do {
1122
+ const l = d === 0 ? h[0] ?? i.initialPageParam : Fe(i, u);
1123
+ if (d > 0 && l == null)
1124
+ break;
1125
+ u = await M(u, l), d++;
1126
+ } while (d < E);
1127
+ }
1128
+ return u;
1129
+ };
1130
+ t.options.persister ? t.fetchFn = () => {
1131
+ var p, m;
1132
+ return (m = (p = t.options).persister) == null ? void 0 : m.call(
1133
+ p,
1134
+ b,
1135
+ {
1136
+ client: t.client,
1137
+ queryKey: t.queryKey,
1138
+ meta: t.options.meta,
1139
+ signal: t.signal
1140
+ },
1141
+ s
1142
+ );
1143
+ } : t.fetchFn = b;
1144
+ }
1145
+ };
1146
+ }
1147
+ function Fe(e, { pages: t, pageParams: s }) {
1148
+ const i = t.length - 1;
1149
+ return t.length > 0 ? e.getNextPageParam(
1150
+ t[i],
1151
+ t,
1152
+ s[i],
1153
+ s
1154
+ ) : void 0;
1155
+ }
1156
+ function ms(e, { pages: t, pageParams: s }) {
1157
+ var i;
1158
+ return t.length > 0 ? (i = e.getPreviousPageParam) == null ? void 0 : i.call(e, t[0], t, s[0], s) : void 0;
1159
+ }
1160
+ var _t, B, A, gt, V, Y, Ae, vs = (Ae = class extends Le {
1161
+ constructor(t) {
1162
+ super();
1163
+ c(this, V);
1164
+ c(this, _t);
1165
+ c(this, B);
1166
+ c(this, A);
1167
+ c(this, gt);
1168
+ o(this, _t, t.client), this.mutationId = t.mutationId, o(this, A, t.mutationCache), o(this, B, []), this.state = t.state || gs(), this.setOptions(t.options), this.scheduleGc();
1169
+ }
1170
+ setOptions(t) {
1171
+ this.options = t, this.updateGcTime(this.options.gcTime);
1172
+ }
1173
+ get meta() {
1174
+ return this.options.meta;
1175
+ }
1176
+ addObserver(t) {
1177
+ r(this, B).includes(t) || (r(this, B).push(t), this.clearGcTimeout(), r(this, A).notify({
1178
+ type: "observerAdded",
1179
+ mutation: this,
1180
+ observer: t
1181
+ }));
1182
+ }
1183
+ removeObserver(t) {
1184
+ o(this, B, r(this, B).filter((s) => s !== t)), this.scheduleGc(), r(this, A).notify({
1185
+ type: "observerRemoved",
1186
+ mutation: this,
1187
+ observer: t
1188
+ });
1189
+ }
1190
+ optionalRemove() {
1191
+ r(this, B).length || (this.state.status === "pending" ? this.scheduleGc() : r(this, A).remove(this));
1192
+ }
1193
+ continue() {
1194
+ var t;
1195
+ return ((t = r(this, gt)) == null ? void 0 : t.continue()) ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
1196
+ this.execute(this.state.variables);
1197
+ }
1198
+ async execute(t) {
1199
+ var h, u, d, b, S, f, O, y, R, p, m, P, M, E, l, Q, x, Z, I, X;
1200
+ const s = () => {
1201
+ v(this, V, Y).call(this, { type: "continue" });
1202
+ }, i = {
1203
+ client: r(this, _t),
1204
+ meta: this.options.meta,
1205
+ mutationKey: this.options.mutationKey
1206
+ };
1207
+ o(this, gt, Ke({
1208
+ fn: () => this.options.mutationFn ? this.options.mutationFn(t, i) : Promise.reject(new Error("No mutationFn found")),
1209
+ onFail: (w, N) => {
1210
+ v(this, V, Y).call(this, { type: "failed", failureCount: w, error: N });
1211
+ },
1212
+ onPause: () => {
1213
+ v(this, V, Y).call(this, { type: "pause" });
1214
+ },
1215
+ onContinue: s,
1216
+ retry: this.options.retry ?? 0,
1217
+ retryDelay: this.options.retryDelay,
1218
+ networkMode: this.options.networkMode,
1219
+ canRun: () => r(this, A).canRun(this)
1220
+ }));
1221
+ const n = this.state.status === "pending", a = !r(this, gt).canStart();
1222
+ try {
1223
+ if (n)
1224
+ s();
1225
+ else {
1226
+ v(this, V, Y).call(this, { type: "pending", variables: t, isPaused: a }), await ((u = (h = r(this, A).config).onMutate) == null ? void 0 : u.call(
1227
+ h,
1228
+ t,
1229
+ this,
1230
+ i
1231
+ ));
1232
+ const N = await ((b = (d = this.options).onMutate) == null ? void 0 : b.call(
1233
+ d,
1234
+ t,
1235
+ i
1236
+ ));
1237
+ N !== this.state.context && v(this, V, Y).call(this, {
1238
+ type: "pending",
1239
+ context: N,
1240
+ variables: t,
1241
+ isPaused: a
1242
+ });
1243
+ }
1244
+ const w = await r(this, gt).start();
1245
+ return await ((f = (S = r(this, A).config).onSuccess) == null ? void 0 : f.call(
1246
+ S,
1247
+ w,
1248
+ t,
1249
+ this.state.context,
1250
+ this,
1251
+ i
1252
+ )), await ((y = (O = this.options).onSuccess) == null ? void 0 : y.call(
1253
+ O,
1254
+ w,
1255
+ t,
1256
+ this.state.context,
1257
+ i
1258
+ )), await ((p = (R = r(this, A).config).onSettled) == null ? void 0 : p.call(
1259
+ R,
1260
+ w,
1261
+ null,
1262
+ this.state.variables,
1263
+ this.state.context,
1264
+ this,
1265
+ i
1266
+ )), await ((P = (m = this.options).onSettled) == null ? void 0 : P.call(
1267
+ m,
1268
+ w,
1269
+ null,
1270
+ t,
1271
+ this.state.context,
1272
+ i
1273
+ )), v(this, V, Y).call(this, { type: "success", data: w }), w;
1274
+ } catch (w) {
1275
+ try {
1276
+ throw await ((E = (M = r(this, A).config).onError) == null ? void 0 : E.call(
1277
+ M,
1278
+ w,
1279
+ t,
1280
+ this.state.context,
1281
+ this,
1282
+ i
1283
+ )), await ((Q = (l = this.options).onError) == null ? void 0 : Q.call(
1284
+ l,
1285
+ w,
1286
+ t,
1287
+ this.state.context,
1288
+ i
1289
+ )), await ((Z = (x = r(this, A).config).onSettled) == null ? void 0 : Z.call(
1290
+ x,
1291
+ void 0,
1292
+ w,
1293
+ this.state.variables,
1294
+ this.state.context,
1295
+ this,
1296
+ i
1297
+ )), await ((X = (I = this.options).onSettled) == null ? void 0 : X.call(
1298
+ I,
1299
+ void 0,
1300
+ w,
1301
+ t,
1302
+ this.state.context,
1303
+ i
1304
+ )), w;
1305
+ } finally {
1306
+ v(this, V, Y).call(this, { type: "error", error: w });
1307
+ }
1308
+ } finally {
1309
+ r(this, A).runNext(this);
1310
+ }
1311
+ }
1312
+ }, _t = new WeakMap(), B = new WeakMap(), A = new WeakMap(), gt = new WeakMap(), V = new WeakSet(), Y = function(t) {
1313
+ const s = (i) => {
1314
+ switch (t.type) {
1315
+ case "failed":
1316
+ return {
1317
+ ...i,
1318
+ failureCount: t.failureCount,
1319
+ failureReason: t.error
1320
+ };
1321
+ case "pause":
1322
+ return {
1323
+ ...i,
1324
+ isPaused: !0
1325
+ };
1326
+ case "continue":
1327
+ return {
1328
+ ...i,
1329
+ isPaused: !1
1330
+ };
1331
+ case "pending":
1332
+ return {
1333
+ ...i,
1334
+ context: t.context,
1335
+ data: void 0,
1336
+ failureCount: 0,
1337
+ failureReason: null,
1338
+ error: null,
1339
+ isPaused: t.isPaused,
1340
+ status: "pending",
1341
+ variables: t.variables,
1342
+ submittedAt: Date.now()
1343
+ };
1344
+ case "success":
1345
+ return {
1346
+ ...i,
1347
+ data: t.data,
1348
+ failureCount: 0,
1349
+ failureReason: null,
1350
+ error: null,
1351
+ status: "success",
1352
+ isPaused: !1
1353
+ };
1354
+ case "error":
1355
+ return {
1356
+ ...i,
1357
+ data: void 0,
1358
+ error: t.error,
1359
+ failureCount: i.failureCount + 1,
1360
+ failureReason: t.error,
1361
+ isPaused: !1,
1362
+ status: "error"
1363
+ };
1364
+ }
1365
+ };
1366
+ this.state = s(this.state), T.batch(() => {
1367
+ r(this, B).forEach((i) => {
1368
+ i.onMutationUpdate(t);
1369
+ }), r(this, A).notify({
1370
+ mutation: this,
1371
+ type: "updated",
1372
+ action: t
1373
+ });
1374
+ });
1375
+ }, Ae);
1376
+ function gs() {
1377
+ return {
1378
+ context: void 0,
1379
+ data: void 0,
1380
+ error: null,
1381
+ failureCount: 0,
1382
+ failureReason: null,
1383
+ isPaused: !1,
1384
+ status: "idle",
1385
+ variables: void 0,
1386
+ submittedAt: 0
1387
+ };
1388
+ }
1389
+ var J, H, kt, xe, bs = (xe = class extends Kt {
1390
+ constructor(t = {}) {
1391
+ super();
1392
+ c(this, J);
1393
+ c(this, H);
1394
+ c(this, kt);
1395
+ this.config = t, o(this, J, /* @__PURE__ */ new Set()), o(this, H, /* @__PURE__ */ new Map()), o(this, kt, 0);
1396
+ }
1397
+ build(t, s, i) {
1398
+ const n = new vs({
1399
+ client: t,
1400
+ mutationCache: this,
1401
+ mutationId: ++Ht(this, kt)._,
1402
+ options: t.defaultMutationOptions(s),
1403
+ state: i
1404
+ });
1405
+ return this.add(n), n;
1406
+ }
1407
+ add(t) {
1408
+ r(this, J).add(t);
1409
+ const s = Gt(t);
1410
+ if (typeof s == "string") {
1411
+ const i = r(this, H).get(s);
1412
+ i ? i.push(t) : r(this, H).set(s, [t]);
1413
+ }
1414
+ this.notify({ type: "added", mutation: t });
1415
+ }
1416
+ remove(t) {
1417
+ if (r(this, J).delete(t)) {
1418
+ const s = Gt(t);
1419
+ if (typeof s == "string") {
1420
+ const i = r(this, H).get(s);
1421
+ if (i)
1422
+ if (i.length > 1) {
1423
+ const n = i.indexOf(t);
1424
+ n !== -1 && i.splice(n, 1);
1425
+ } else i[0] === t && r(this, H).delete(s);
1426
+ }
1427
+ }
1428
+ this.notify({ type: "removed", mutation: t });
1429
+ }
1430
+ canRun(t) {
1431
+ const s = Gt(t);
1432
+ if (typeof s == "string") {
1433
+ const i = r(this, H).get(s), n = i == null ? void 0 : i.find(
1434
+ (a) => a.state.status === "pending"
1435
+ );
1436
+ return !n || n === t;
1437
+ } else
1438
+ return !0;
1439
+ }
1440
+ runNext(t) {
1441
+ var i;
1442
+ const s = Gt(t);
1443
+ if (typeof s == "string") {
1444
+ const n = (i = r(this, H).get(s)) == null ? void 0 : i.find((a) => a !== t && a.state.isPaused);
1445
+ return (n == null ? void 0 : n.continue()) ?? Promise.resolve();
1446
+ } else
1447
+ return Promise.resolve();
1448
+ }
1449
+ clear() {
1450
+ T.batch(() => {
1451
+ r(this, J).forEach((t) => {
1452
+ this.notify({ type: "removed", mutation: t });
1453
+ }), r(this, J).clear(), r(this, H).clear();
1454
+ });
1455
+ }
1456
+ getAll() {
1457
+ return Array.from(r(this, J));
1458
+ }
1459
+ find(t) {
1460
+ const s = { exact: !0, ...t };
1461
+ return this.getAll().find(
1462
+ (i) => ge(s, i)
1463
+ );
1464
+ }
1465
+ findAll(t = {}) {
1466
+ return this.getAll().filter((s) => ge(t, s));
1467
+ }
1468
+ notify(t) {
1469
+ T.batch(() => {
1470
+ this.listeners.forEach((s) => {
1471
+ s(t);
1472
+ });
1473
+ });
1474
+ }
1475
+ resumePausedMutations() {
1476
+ const t = this.getAll().filter((s) => s.state.isPaused);
1477
+ return T.batch(
1478
+ () => Promise.all(
1479
+ t.map((s) => s.continue().catch(j))
1480
+ )
1481
+ );
1482
+ }
1483
+ }, J = new WeakMap(), H = new WeakMap(), kt = new WeakMap(), xe);
1484
+ function Gt(e) {
1485
+ var t;
1486
+ return (t = e.options.scope) == null ? void 0 : t.id;
1487
+ }
1488
+ var z, Ue, ws = (Ue = class extends Kt {
1489
+ constructor(t = {}) {
1490
+ super();
1491
+ c(this, z);
1492
+ this.config = t, o(this, z, /* @__PURE__ */ new Map());
1493
+ }
1494
+ build(t, s, i) {
1495
+ const n = s.queryKey, a = s.queryHash ?? le(n, s);
1496
+ let h = this.get(a);
1497
+ return h || (h = new ds({
1498
+ client: t,
1499
+ queryKey: n,
1500
+ queryHash: a,
1501
+ options: t.defaultQueryOptions(s),
1502
+ state: i,
1503
+ defaultOptions: t.getQueryDefaults(n)
1504
+ }), this.add(h)), h;
1505
+ }
1506
+ add(t) {
1507
+ r(this, z).has(t.queryHash) || (r(this, z).set(t.queryHash, t), this.notify({
1508
+ type: "added",
1509
+ query: t
1510
+ }));
1511
+ }
1512
+ remove(t) {
1513
+ const s = r(this, z).get(t.queryHash);
1514
+ s && (t.destroy(), s === t && r(this, z).delete(t.queryHash), this.notify({ type: "removed", query: t }));
1515
+ }
1516
+ clear() {
1517
+ T.batch(() => {
1518
+ this.getAll().forEach((t) => {
1519
+ this.remove(t);
1520
+ });
1521
+ });
1522
+ }
1523
+ get(t) {
1524
+ return r(this, z).get(t);
1525
+ }
1526
+ getAll() {
1527
+ return [...r(this, z).values()];
1528
+ }
1529
+ find(t) {
1530
+ const s = { exact: !0, ...t };
1531
+ return this.getAll().find(
1532
+ (i) => ve(s, i)
1533
+ );
1534
+ }
1535
+ findAll(t = {}) {
1536
+ const s = this.getAll();
1537
+ return Object.keys(t).length > 0 ? s.filter((i) => ve(t, i)) : s;
1538
+ }
1539
+ notify(t) {
1540
+ T.batch(() => {
1541
+ this.listeners.forEach((s) => {
1542
+ s(t);
1543
+ });
1544
+ });
1545
+ }
1546
+ onFocus() {
1547
+ T.batch(() => {
1548
+ this.getAll().forEach((t) => {
1549
+ t.onFocus();
1550
+ });
1551
+ });
1552
+ }
1553
+ onOnline() {
1554
+ T.batch(() => {
1555
+ this.getAll().forEach((t) => {
1556
+ t.onOnline();
1557
+ });
1558
+ });
1559
+ }
1560
+ }, z = new WeakMap(), Ue), F, it, nt, Qt, Dt, at, Tt, It, je, Cs = (je = class {
1561
+ constructor(e = {}) {
1562
+ c(this, F);
1563
+ c(this, it);
1564
+ c(this, nt);
1565
+ c(this, Qt);
1566
+ c(this, Dt);
1567
+ c(this, at);
1568
+ c(this, Tt);
1569
+ c(this, It);
1570
+ o(this, F, e.queryCache || new ws()), o(this, it, e.mutationCache || new bs()), o(this, nt, e.defaultOptions || {}), o(this, Qt, /* @__PURE__ */ new Map()), o(this, Dt, /* @__PURE__ */ new Map()), o(this, at, 0);
1571
+ }
1572
+ mount() {
1573
+ Ht(this, at)._++, r(this, at) === 1 && (o(this, Tt, de.subscribe(async (e) => {
1574
+ e && (await this.resumePausedMutations(), r(this, F).onFocus());
1575
+ })), o(this, It, zt.subscribe(async (e) => {
1576
+ e && (await this.resumePausedMutations(), r(this, F).onOnline());
1577
+ })));
1578
+ }
1579
+ unmount() {
1580
+ var e, t;
1581
+ Ht(this, at)._--, r(this, at) === 0 && ((e = r(this, Tt)) == null || e.call(this), o(this, Tt, void 0), (t = r(this, It)) == null || t.call(this), o(this, It, void 0));
1582
+ }
1583
+ isFetching(e) {
1584
+ return r(this, F).findAll({ ...e, fetchStatus: "fetching" }).length;
1585
+ }
1586
+ isMutating(e) {
1587
+ return r(this, it).findAll({ ...e, status: "pending" }).length;
1588
+ }
1589
+ /**
1590
+ * Imperative (non-reactive) way to retrieve data for a QueryKey.
1591
+ * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
1592
+ *
1593
+ * Hint: Do not use this function inside a component, because it won't receive updates.
1594
+ * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
1595
+ */
1596
+ getQueryData(e) {
1597
+ var s;
1598
+ const t = this.defaultQueryOptions({ queryKey: e });
1599
+ return (s = r(this, F).get(t.queryHash)) == null ? void 0 : s.state.data;
1600
+ }
1601
+ ensureQueryData(e) {
1602
+ const t = this.defaultQueryOptions(e), s = r(this, F).build(this, t), i = s.state.data;
1603
+ return i === void 0 ? this.fetchQuery(e) : (e.revalidateIfStale && s.isStaleByTime(ot(t.staleTime, s)) && this.prefetchQuery(t), Promise.resolve(i));
1604
+ }
1605
+ getQueriesData(e) {
1606
+ return r(this, F).findAll(e).map(({ queryKey: t, state: s }) => {
1607
+ const i = s.data;
1608
+ return [t, i];
1609
+ });
1610
+ }
1611
+ setQueryData(e, t, s) {
1612
+ const i = this.defaultQueryOptions({ queryKey: e }), n = r(this, F).get(
1613
+ i.queryHash
1614
+ ), a = n == null ? void 0 : n.state.data, h = es(t, a);
1615
+ if (h !== void 0)
1616
+ return r(this, F).build(this, i).setData(h, { ...s, manual: !0 });
1617
+ }
1618
+ setQueriesData(e, t, s) {
1619
+ return T.batch(
1620
+ () => r(this, F).findAll(e).map(({ queryKey: i }) => [
1621
+ i,
1622
+ this.setQueryData(i, t, s)
1623
+ ])
1624
+ );
1625
+ }
1626
+ getQueryState(e) {
1627
+ var s;
1628
+ const t = this.defaultQueryOptions({ queryKey: e });
1629
+ return (s = r(this, F).get(
1630
+ t.queryHash
1631
+ )) == null ? void 0 : s.state;
1632
+ }
1633
+ removeQueries(e) {
1634
+ const t = r(this, F);
1635
+ T.batch(() => {
1636
+ t.findAll(e).forEach((s) => {
1637
+ t.remove(s);
1638
+ });
1639
+ });
1640
+ }
1641
+ resetQueries(e, t) {
1642
+ const s = r(this, F);
1643
+ return T.batch(() => (s.findAll(e).forEach((i) => {
1644
+ i.reset();
1645
+ }), this.refetchQueries(
1646
+ {
1647
+ type: "active",
1648
+ ...e
1649
+ },
1650
+ t
1651
+ )));
1652
+ }
1653
+ cancelQueries(e, t = {}) {
1654
+ const s = { revert: !0, ...t }, i = T.batch(
1655
+ () => r(this, F).findAll(e).map((n) => n.cancel(s))
1656
+ );
1657
+ return Promise.all(i).then(j).catch(j);
1658
+ }
1659
+ invalidateQueries(e, t = {}) {
1660
+ return T.batch(() => (r(this, F).findAll(e).forEach((s) => {
1661
+ s.invalidate();
1662
+ }), (e == null ? void 0 : e.refetchType) === "none" ? Promise.resolve() : this.refetchQueries(
1663
+ {
1664
+ ...e,
1665
+ type: (e == null ? void 0 : e.refetchType) ?? (e == null ? void 0 : e.type) ?? "active"
1666
+ },
1667
+ t
1668
+ )));
1669
+ }
1670
+ refetchQueries(e, t = {}) {
1671
+ const s = {
1672
+ ...t,
1673
+ cancelRefetch: t.cancelRefetch ?? !0
1674
+ }, i = T.batch(
1675
+ () => r(this, F).findAll(e).filter((n) => !n.isDisabled() && !n.isStatic()).map((n) => {
1676
+ let a = n.fetch(void 0, s);
1677
+ return s.throwOnError || (a = a.catch(j)), n.state.fetchStatus === "paused" ? Promise.resolve() : a;
1678
+ })
1679
+ );
1680
+ return Promise.all(i).then(j);
1681
+ }
1682
+ fetchQuery(e) {
1683
+ const t = this.defaultQueryOptions(e);
1684
+ t.retry === void 0 && (t.retry = !1);
1685
+ const s = r(this, F).build(this, t);
1686
+ return s.isStaleByTime(
1687
+ ot(t.staleTime, s)
1688
+ ) ? s.fetch(t) : Promise.resolve(s.state.data);
1689
+ }
1690
+ prefetchQuery(e) {
1691
+ return this.fetchQuery(e).then(j).catch(j);
1692
+ }
1693
+ fetchInfiniteQuery(e) {
1694
+ return e.behavior = Ee(e.pages), this.fetchQuery(e);
1695
+ }
1696
+ prefetchInfiniteQuery(e) {
1697
+ return this.fetchInfiniteQuery(e).then(j).catch(j);
1698
+ }
1699
+ ensureInfiniteQueryData(e) {
1700
+ return e.behavior = Ee(e.pages), this.ensureQueryData(e);
1701
+ }
1702
+ resumePausedMutations() {
1703
+ return zt.isOnline() ? r(this, it).resumePausedMutations() : Promise.resolve();
1704
+ }
1705
+ getQueryCache() {
1706
+ return r(this, F);
1707
+ }
1708
+ getMutationCache() {
1709
+ return r(this, it);
1710
+ }
1711
+ getDefaultOptions() {
1712
+ return r(this, nt);
1713
+ }
1714
+ setDefaultOptions(e) {
1715
+ o(this, nt, e);
1716
+ }
1717
+ setQueryDefaults(e, t) {
1718
+ r(this, Qt).set(At(e), {
1719
+ queryKey: e,
1720
+ defaultOptions: t
1721
+ });
1722
+ }
1723
+ getQueryDefaults(e) {
1724
+ const t = [...r(this, Qt).values()], s = {};
1725
+ return t.forEach((i) => {
1726
+ xt(e, i.queryKey) && Object.assign(s, i.defaultOptions);
1727
+ }), s;
1728
+ }
1729
+ setMutationDefaults(e, t) {
1730
+ r(this, Dt).set(At(e), {
1731
+ mutationKey: e,
1732
+ defaultOptions: t
1733
+ });
1734
+ }
1735
+ getMutationDefaults(e) {
1736
+ const t = [...r(this, Dt).values()], s = {};
1737
+ return t.forEach((i) => {
1738
+ xt(e, i.mutationKey) && Object.assign(s, i.defaultOptions);
1739
+ }), s;
1740
+ }
1741
+ defaultQueryOptions(e) {
1742
+ if (e._defaulted)
1743
+ return e;
1744
+ const t = {
1745
+ ...r(this, nt).queries,
1746
+ ...this.getQueryDefaults(e.queryKey),
1747
+ ...e,
1748
+ _defaulted: !0
1749
+ };
1750
+ return t.queryHash || (t.queryHash = le(
1751
+ t.queryKey,
1752
+ t
1753
+ )), t.refetchOnReconnect === void 0 && (t.refetchOnReconnect = t.networkMode !== "always"), t.throwOnError === void 0 && (t.throwOnError = !!t.suspense), !t.networkMode && t.persister && (t.networkMode = "offlineFirst"), t.queryFn === Vt && (t.enabled = !1), t;
1754
+ }
1755
+ defaultMutationOptions(e) {
1756
+ return e != null && e._defaulted ? e : {
1757
+ ...r(this, nt).mutations,
1758
+ ...(e == null ? void 0 : e.mutationKey) && this.getMutationDefaults(e.mutationKey),
1759
+ ...e,
1760
+ _defaulted: !0
1761
+ };
1762
+ }
1763
+ clear() {
1764
+ r(this, F).clear(), r(this, it).clear();
1765
+ }
1766
+ }, F = new WeakMap(), it = new WeakMap(), nt = new WeakMap(), Qt = new WeakMap(), Dt = new WeakMap(), at = new WeakMap(), Tt = new WeakMap(), It = new WeakMap(), je), Be = K.createContext(
1767
+ void 0
1768
+ ), Ss = (e) => {
1769
+ const t = K.useContext(Be);
1770
+ if (!t)
1771
+ throw new Error("No QueryClient set, use QueryClientProvider to set one");
1772
+ return t;
1773
+ }, Os = ({
1774
+ client: e,
1775
+ children: t
1776
+ }) => (K.useEffect(() => (e.mount(), () => {
1777
+ e.unmount();
1778
+ }), [e]), /* @__PURE__ */ Bt(Be.Provider, { value: e, children: t })), Ve = K.createContext(!1), Ps = () => K.useContext(Ve);
1779
+ Ve.Provider;
1780
+ function Es() {
1781
+ let e = !1;
1782
+ return {
1783
+ clearReset: () => {
1784
+ e = !1;
1785
+ },
1786
+ reset: () => {
1787
+ e = !0;
1788
+ },
1789
+ isReset: () => e
1790
+ };
1791
+ }
1792
+ var Fs = K.createContext(Es()), Rs = () => K.useContext(Fs), Ms = (e, t) => {
1793
+ (e.suspense || e.throwOnError || e.experimental_prefetchInRender) && (t.isReset() || (e.retryOnMount = !1));
1794
+ }, Qs = (e) => {
1795
+ K.useEffect(() => {
1796
+ e.clearReset();
1797
+ }, [e]);
1798
+ }, Ds = ({
1799
+ result: e,
1800
+ errorResetBoundary: t,
1801
+ throwOnError: s,
1802
+ query: i,
1803
+ suspense: n
1804
+ }) => e.isError && !t.isReset() && !e.isFetching && i && (n && e.data === void 0 || as(s, [e.error, i])), Ts = (e) => {
1805
+ if (e.suspense) {
1806
+ const s = (n) => n === "static" ? n : Math.max(n ?? 1e3, 1e3), i = e.staleTime;
1807
+ e.staleTime = typeof i == "function" ? (...n) => s(i(...n)) : s(i), typeof e.gcTime == "number" && (e.gcTime = Math.max(
1808
+ e.gcTime,
1809
+ 1e3
1810
+ ));
1811
+ }
1812
+ }, Is = (e, t) => e.isLoading && e.isFetching && !t, qs = (e, t) => (e == null ? void 0 : e.suspense) && t.isPending, Re = (e, t, s) => t.fetchOptimistic(e).catch(() => {
1813
+ s.clearReset();
1814
+ });
1815
+ function As(e, t, s) {
1816
+ var f, O, y, R, p;
1817
+ if (process.env.NODE_ENV !== "production" && (typeof e != "object" || Array.isArray(e)))
1818
+ throw new Error(
1819
+ 'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'
1820
+ );
1821
+ const i = Ps(), n = Rs(), a = Ss(), h = a.defaultQueryOptions(e);
1822
+ (O = (f = a.getDefaultOptions().queries) == null ? void 0 : f._experimental_beforeQuery) == null || O.call(
1823
+ f,
1824
+ h
1825
+ ), process.env.NODE_ENV !== "production" && (h.queryFn || console.error(
1826
+ `[${h.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`
1827
+ )), h._optimisticResults = i ? "isRestoring" : "optimistic", Ts(h), Ms(h, n), Qs(n);
1828
+ const u = !a.getQueryCache().get(h.queryHash), [d] = K.useState(
1829
+ () => new t(
1830
+ a,
1831
+ h
1832
+ )
1833
+ ), b = d.getOptimisticResult(h), S = !i && e.subscribed !== !1;
1834
+ if (K.useSyncExternalStore(
1835
+ K.useCallback(
1836
+ (m) => {
1837
+ const P = S ? d.subscribe(T.batchCalls(m)) : j;
1838
+ return d.updateResult(), P;
1839
+ },
1840
+ [d, S]
1841
+ ),
1842
+ () => d.getCurrentResult(),
1843
+ () => d.getCurrentResult()
1844
+ ), K.useEffect(() => {
1845
+ d.setOptions(h);
1846
+ }, [h, d]), qs(h, b))
1847
+ throw Re(h, d, n);
1848
+ if (Ds({
1849
+ result: b,
1850
+ errorResetBoundary: n,
1851
+ throwOnError: h.throwOnError,
1852
+ query: a.getQueryCache().get(h.queryHash),
1853
+ suspense: h.suspense
1854
+ }))
1855
+ throw b.error;
1856
+ if ((R = (y = a.getDefaultOptions().queries) == null ? void 0 : y._experimental_afterQuery) == null || R.call(
1857
+ y,
1858
+ h,
1859
+ b
1860
+ ), h.experimental_prefetchInRender && !bt && Is(b, i)) {
1861
+ const m = u ? (
1862
+ // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
1863
+ Re(h, d, n)
1864
+ ) : (
1865
+ // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
1866
+ (p = a.getQueryCache().get(h.queryHash)) == null ? void 0 : p.promise
1867
+ );
1868
+ m == null || m.catch(j).finally(() => {
1869
+ d.updateResult();
1870
+ });
1871
+ }
1872
+ return h.notifyOnChangeProps ? b : d.trackResult(b);
1873
+ }
1874
+ function xs(e, t) {
1875
+ return As(e, fs);
1876
+ }
1877
+ const Us = ze(void 0), js = new Cs({
1878
+ defaultOptions: {
1879
+ queries: {
1880
+ retry: 1,
1881
+ refetchOnWindowFocus: !1,
1882
+ staleTime: 1e3 * 60 * 15
1883
+ // 15 minutes
1884
+ }
1885
+ }
1886
+ });
1887
+ function Ns({
1888
+ fetchSchedule: e,
1889
+ initialSchedule: t = [],
1890
+ weeks: s,
1891
+ handleDateChanged: i = () => !0,
1892
+ children: n
9
1893
  }) {
10
- const [i, A] = y(a[0][0].date), [n, f] = y(!1), t = v(r), u = x((e) => {
11
- f(!0), A(e), o(e);
12
- }, [o]);
13
- b(() => {
14
- let e = !1;
15
- typeof r == "object" && !Array.isArray(r) && (r != null && r.queryStatus) ? e = !(typeof t.current == "object" && !Array.isArray(t.current) && "queryStatus" in t.current) : Array.isArray(r) && Array.isArray(t.current) ? e = t.current.length !== r.length || t.current.some((p, C) => {
16
- var s;
17
- return p.id !== ((s = r[C]) == null ? void 0 : s.id);
18
- }) : e = !0, e && n && (f(!1), t.current = r);
19
- }, [r, n]);
20
- const m = j(() => ({
21
- schedule: r,
22
- weeks: a,
23
- currentDate: i,
24
- isLoading: n,
25
- setCurrentDate: u
26
- }), [r, a, i, n, u]);
27
- return /* @__PURE__ */ S(D.Provider, { value: m, children: c });
1894
+ const [a, h] = pe(s[0][0].date), [u, d] = pe(!1), b = $e(Wt(s[0][0].date, "yyyy-MM-dd"));
1895
+ me.setComponent("ScheduleContext"), me.log("fetchSchedule:", e);
1896
+ const S = We((p) => {
1897
+ const m = Wt(p, "yyyy-MM-dd");
1898
+ m !== b.current && (d(!0), b.current = m), h(p), i(p);
1899
+ }, [i]), { data: f, isLoading: O, isError: y } = xs({
1900
+ queryKey: ["schedule", Wt(a, "yyyy-MM-dd")],
1901
+ queryFn: () => e(a),
1902
+ staleTime: 1e3 * 60 * 15,
1903
+ // 15 minutes
1904
+ retry: 1
1905
+ });
1906
+ Je(() => {
1907
+ f !== void 0 && u && d(!1);
1908
+ }, [f, u]);
1909
+ const R = Ze(() => ({
1910
+ schedule: f ?? t,
1911
+ weeks: s,
1912
+ currentDate: a,
1913
+ isLoading: O || u,
1914
+ isError: y,
1915
+ setCurrentDate: S
1916
+ }), [f, t, s, a, O, u, y, S]);
1917
+ return /* @__PURE__ */ Bt(Us.Provider, { value: R, children: n });
1918
+ }
1919
+ function Gs(e) {
1920
+ return /* @__PURE__ */ Bt(Os, { client: js, children: /* @__PURE__ */ Bt(Ns, { ...e }) });
28
1921
  }
29
1922
  export {
30
- D as ScheduleContext,
31
- L as ScheduleProvider,
32
- L as default
1923
+ Us as ScheduleContext,
1924
+ Gs as ScheduleProvider,
1925
+ Gs as default
33
1926
  };