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

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