@tiendanube/live-state 1.0.0-beta.8 → 1.0.0

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.
Files changed (50) hide show
  1. package/README.md +112 -0
  2. package/dist/LiveStateProvider-BEiLZeen.js +1457 -0
  3. package/dist/LiveStateProvider-BEiLZeen.js.map +1 -0
  4. package/dist/LiveStateProvider-B_uOhVFY.cjs +2 -0
  5. package/dist/LiveStateProvider-B_uOhVFY.cjs.map +1 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.js +513 -219
  10. package/dist/index.js.map +1 -1
  11. package/dist/src/components/LiveStateAlert.d.ts +7 -1
  12. package/dist/src/components/LiveStateAlert.d.ts.map +1 -1
  13. package/dist/src/components/LiveStateInfo.d.ts +13 -1
  14. package/dist/src/components/LiveStateInfo.d.ts.map +1 -1
  15. package/dist/src/components/LiveStateRenderer.d.ts +1 -1
  16. package/dist/src/components/LiveStateRenderer.d.ts.map +1 -1
  17. package/dist/src/components/RichText.d.ts +19 -0
  18. package/dist/src/components/RichText.d.ts.map +1 -0
  19. package/dist/src/hooks/useClosable.d.ts.map +1 -1
  20. package/dist/src/hooks/useLiveState.d.ts +13 -4
  21. package/dist/src/hooks/useLiveState.d.ts.map +1 -1
  22. package/dist/src/hooks/useTrackEvent.d.ts.map +1 -1
  23. package/dist/src/index.d.ts +5 -1
  24. package/dist/src/index.d.ts.map +1 -1
  25. package/dist/src/providers/LiveStateProvider.d.ts +11 -9
  26. package/dist/src/providers/LiveStateProvider.d.ts.map +1 -1
  27. package/dist/src/query-client.d.ts +15 -0
  28. package/dist/src/query-client.d.ts.map +1 -0
  29. package/dist/src/testing/index.d.ts +58 -0
  30. package/dist/src/testing/index.d.ts.map +1 -0
  31. package/dist/src/types/index.d.ts +206 -9
  32. package/dist/src/types/index.d.ts.map +1 -1
  33. package/dist/src/utils/analytics.d.ts +19 -19
  34. package/dist/src/utils/analytics.d.ts.map +1 -1
  35. package/dist/src/utils/closable-storage.d.ts +1 -0
  36. package/dist/src/utils/closable-storage.d.ts.map +1 -1
  37. package/dist/src/utils/cta.d.ts +3 -1
  38. package/dist/src/utils/cta.d.ts.map +1 -1
  39. package/dist/src/utils/logger.d.ts +17 -0
  40. package/dist/src/utils/logger.d.ts.map +1 -0
  41. package/dist/src/utils/query.d.ts +38 -0
  42. package/dist/src/utils/query.d.ts.map +1 -0
  43. package/dist/src/utils/sanitize.d.ts +25 -0
  44. package/dist/src/utils/sanitize.d.ts.map +1 -0
  45. package/dist/testing.cjs +2 -0
  46. package/dist/testing.cjs.map +1 -0
  47. package/dist/testing.d.ts +1 -0
  48. package/dist/testing.js +62 -0
  49. package/dist/testing.js.map +1 -0
  50. package/package.json +23 -12
@@ -0,0 +1,1457 @@
1
+ import * as e from "react";
2
+ import { createContext as t, useContext as n, useEffect as r, useMemo as i } from "react";
3
+ import { jsx as a } from "react/jsx-runtime";
4
+ import * as o from "@amplitude/analytics-browser";
5
+ //#region node_modules/@tanstack/query-core/build/modern/subscribable.js
6
+ var s = class {
7
+ constructor() {
8
+ this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
9
+ }
10
+ subscribe(e) {
11
+ return this.listeners.add(e), this.onSubscribe(), () => {
12
+ this.listeners.delete(e), this.onUnsubscribe();
13
+ };
14
+ }
15
+ hasListeners() {
16
+ return this.listeners.size > 0;
17
+ }
18
+ onSubscribe() {}
19
+ onUnsubscribe() {}
20
+ }, c = new class extends s {
21
+ #e;
22
+ #t;
23
+ #n;
24
+ constructor() {
25
+ super(), this.#n = (e) => {
26
+ if (typeof window < "u" && window.addEventListener) {
27
+ let t = () => e();
28
+ return window.addEventListener("visibilitychange", t, !1), () => {
29
+ window.removeEventListener("visibilitychange", t);
30
+ };
31
+ }
32
+ };
33
+ }
34
+ onSubscribe() {
35
+ this.#t || this.setEventListener(this.#n);
36
+ }
37
+ onUnsubscribe() {
38
+ this.hasListeners() || (this.#t?.(), this.#t = void 0);
39
+ }
40
+ setEventListener(e) {
41
+ this.#n = e, this.#t?.(), this.#t = e((e) => {
42
+ typeof e == "boolean" ? this.setFocused(e) : this.onFocus();
43
+ });
44
+ }
45
+ setFocused(e) {
46
+ this.#e !== e && (this.#e = e, this.onFocus());
47
+ }
48
+ onFocus() {
49
+ let e = this.isFocused();
50
+ this.listeners.forEach((t) => {
51
+ t(e);
52
+ });
53
+ }
54
+ isFocused() {
55
+ return typeof this.#e == "boolean" ? this.#e : globalThis.document?.visibilityState !== "hidden";
56
+ }
57
+ }(), l = {
58
+ setTimeout: (e, t) => setTimeout(e, t),
59
+ clearTimeout: (e) => clearTimeout(e),
60
+ setInterval: (e, t) => setInterval(e, t),
61
+ clearInterval: (e) => clearInterval(e)
62
+ }, u = new class {
63
+ #e = l;
64
+ #t = !1;
65
+ setTimeoutProvider(e) {
66
+ process.env.NODE_ENV !== "production" && this.#t && e !== this.#e && console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.", {
67
+ previous: this.#e,
68
+ provider: e
69
+ }), this.#e = e, process.env.NODE_ENV !== "production" && (this.#t = !1);
70
+ }
71
+ setTimeout(e, t) {
72
+ return process.env.NODE_ENV !== "production" && (this.#t = !0), this.#e.setTimeout(e, t);
73
+ }
74
+ clearTimeout(e) {
75
+ this.#e.clearTimeout(e);
76
+ }
77
+ setInterval(e, t) {
78
+ return process.env.NODE_ENV !== "production" && (this.#t = !0), this.#e.setInterval(e, t);
79
+ }
80
+ clearInterval(e) {
81
+ this.#e.clearInterval(e);
82
+ }
83
+ }();
84
+ function d(e) {
85
+ setTimeout(e, 0);
86
+ }
87
+ //#endregion
88
+ //#region node_modules/@tanstack/query-core/build/modern/utils.js
89
+ var f = typeof window > "u" || "Deno" in globalThis;
90
+ function p() {}
91
+ function m(e, t) {
92
+ return typeof e == "function" ? e(t) : e;
93
+ }
94
+ function h(e) {
95
+ return typeof e == "number" && e >= 0 && e !== Infinity;
96
+ }
97
+ function g(e, t) {
98
+ return Math.max(e + (t || 0) - Date.now(), 0);
99
+ }
100
+ function _(e, t) {
101
+ return typeof e == "function" ? e(t) : e;
102
+ }
103
+ function v(e, t) {
104
+ return typeof e == "function" ? e(t) : e;
105
+ }
106
+ function y(e, t) {
107
+ let { type: n = "all", exact: r, fetchStatus: i, predicate: a, queryKey: o, stale: s } = e;
108
+ if (o) {
109
+ if (r) {
110
+ if (t.queryHash !== x(o, t.options)) return !1;
111
+ } else if (!C(t.queryKey, o)) return !1;
112
+ }
113
+ if (n !== "all") {
114
+ let e = t.isActive();
115
+ if (n === "active" && !e || n === "inactive" && e) return !1;
116
+ }
117
+ return !(typeof s == "boolean" && t.isStale() !== s || i && i !== t.state.fetchStatus || a && !a(t));
118
+ }
119
+ function b(e, t) {
120
+ let { exact: n, status: r, predicate: i, mutationKey: a } = e;
121
+ if (a) {
122
+ if (!t.options.mutationKey) return !1;
123
+ if (n) {
124
+ if (S(t.options.mutationKey) !== S(a)) return !1;
125
+ } else if (!C(t.options.mutationKey, a)) return !1;
126
+ }
127
+ return !(r && t.state.status !== r || i && !i(t));
128
+ }
129
+ function x(e, t) {
130
+ return (t?.queryKeyHashFn || S)(e);
131
+ }
132
+ function S(e) {
133
+ return JSON.stringify(e, (e, t) => E(t) ? Object.keys(t).sort().reduce((e, n) => (e[n] = t[n], e), {}) : t);
134
+ }
135
+ function C(e, t) {
136
+ return e === t ? !0 : typeof e == typeof t && e && t && typeof e == "object" && typeof t == "object" ? Object.keys(t).every((n) => C(e[n], t[n])) : !1;
137
+ }
138
+ var ee = Object.prototype.hasOwnProperty;
139
+ function w(e, t, n = 0) {
140
+ if (e === t) return e;
141
+ if (n > 500) return t;
142
+ let r = T(e) && T(t);
143
+ if (!r && !(E(e) && E(t))) return t;
144
+ let i = (r ? e : Object.keys(e)).length, a = r ? t : Object.keys(t), o = a.length, s = r ? Array(o) : {}, c = 0;
145
+ for (let l = 0; l < o; l++) {
146
+ let o = r ? l : a[l], u = e[o], d = t[o];
147
+ if (u === d) {
148
+ s[o] = u, (r ? l < i : ee.call(e, o)) && c++;
149
+ continue;
150
+ }
151
+ if (u === null || d === null || typeof u != "object" || typeof d != "object") {
152
+ s[o] = d;
153
+ continue;
154
+ }
155
+ let f = w(u, d, n + 1);
156
+ s[o] = f, f === u && c++;
157
+ }
158
+ return i === o && c === i ? e : s;
159
+ }
160
+ function te(e, t) {
161
+ if (!t || Object.keys(e).length !== Object.keys(t).length) return !1;
162
+ for (let n in e) if (e[n] !== t[n]) return !1;
163
+ return !0;
164
+ }
165
+ function T(e) {
166
+ return Array.isArray(e) && e.length === Object.keys(e).length;
167
+ }
168
+ function E(e) {
169
+ if (!D(e)) return !1;
170
+ let t = e.constructor;
171
+ if (t === void 0) return !0;
172
+ let n = t.prototype;
173
+ return !(!D(n) || !n.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(e) !== Object.prototype);
174
+ }
175
+ function D(e) {
176
+ return Object.prototype.toString.call(e) === "[object Object]";
177
+ }
178
+ function ne(e) {
179
+ return new Promise((t) => {
180
+ u.setTimeout(t, e);
181
+ });
182
+ }
183
+ function O(e, t, n) {
184
+ if (typeof n.structuralSharing == "function") return n.structuralSharing(e, t);
185
+ if (n.structuralSharing !== !1) {
186
+ if (process.env.NODE_ENV !== "production") try {
187
+ return w(e, t);
188
+ } catch (e) {
189
+ throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${n.queryHash}]: ${e}`), e;
190
+ }
191
+ return w(e, t);
192
+ }
193
+ return t;
194
+ }
195
+ function re(e, t, n = 0) {
196
+ let r = [...e, t];
197
+ return n && r.length > n ? r.slice(1) : r;
198
+ }
199
+ function ie(e, t, n = 0) {
200
+ let r = [t, ...e];
201
+ return n && r.length > n ? r.slice(0, -1) : r;
202
+ }
203
+ var k = /* @__PURE__ */ Symbol();
204
+ function A(e, t) {
205
+ return process.env.NODE_ENV !== "production" && e.queryFn === k && console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`), !e.queryFn && t?.initialPromise ? () => t.initialPromise : !e.queryFn || e.queryFn === k ? () => Promise.reject(/* @__PURE__ */ Error(`Missing queryFn: '${e.queryHash}'`)) : e.queryFn;
206
+ }
207
+ function ae(e, t) {
208
+ return typeof e == "function" ? e(...t) : !!e;
209
+ }
210
+ function oe(e, t, n) {
211
+ let r = !1, i;
212
+ return Object.defineProperty(e, "signal", {
213
+ enumerable: !0,
214
+ get: () => (i ??= t(), r ? i : (r = !0, i.aborted ? n() : i.addEventListener("abort", n, { once: !0 }), i))
215
+ }), e;
216
+ }
217
+ //#endregion
218
+ //#region node_modules/@tanstack/query-core/build/modern/environmentManager.js
219
+ var j = /* @__PURE__ */ (() => {
220
+ let e = () => f;
221
+ return {
222
+ isServer() {
223
+ return e();
224
+ },
225
+ setIsServer(t) {
226
+ e = t;
227
+ }
228
+ };
229
+ })();
230
+ //#endregion
231
+ //#region node_modules/@tanstack/query-core/build/modern/thenable.js
232
+ function M() {
233
+ let e, t, n = new Promise((n, r) => {
234
+ e = n, t = r;
235
+ });
236
+ n.status = "pending", n.catch(() => {});
237
+ function r(e) {
238
+ Object.assign(n, e), delete n.resolve, delete n.reject;
239
+ }
240
+ return n.resolve = (t) => {
241
+ r({
242
+ status: "fulfilled",
243
+ value: t
244
+ }), e(t);
245
+ }, n.reject = (e) => {
246
+ r({
247
+ status: "rejected",
248
+ reason: e
249
+ }), t(e);
250
+ }, n;
251
+ }
252
+ //#endregion
253
+ //#region node_modules/@tanstack/query-core/build/modern/notifyManager.js
254
+ var N = d;
255
+ function se() {
256
+ let e = [], t = 0, n = (e) => {
257
+ e();
258
+ }, r = (e) => {
259
+ e();
260
+ }, i = N, a = (r) => {
261
+ t ? e.push(r) : i(() => {
262
+ n(r);
263
+ });
264
+ }, o = () => {
265
+ let t = e;
266
+ e = [], t.length && i(() => {
267
+ r(() => {
268
+ t.forEach((e) => {
269
+ n(e);
270
+ });
271
+ });
272
+ });
273
+ };
274
+ return {
275
+ batch: (e) => {
276
+ let n;
277
+ t++;
278
+ try {
279
+ n = e();
280
+ } finally {
281
+ t--, t || o();
282
+ }
283
+ return n;
284
+ },
285
+ batchCalls: (e) => (...t) => {
286
+ a(() => {
287
+ e(...t);
288
+ });
289
+ },
290
+ schedule: a,
291
+ setNotifyFunction: (e) => {
292
+ n = e;
293
+ },
294
+ setBatchNotifyFunction: (e) => {
295
+ r = e;
296
+ },
297
+ setScheduler: (e) => {
298
+ i = e;
299
+ }
300
+ };
301
+ }
302
+ var P = se(), F = new class extends s {
303
+ #e = !0;
304
+ #t;
305
+ #n;
306
+ constructor() {
307
+ super(), this.#n = (e) => {
308
+ if (typeof window < "u" && window.addEventListener) {
309
+ let t = () => e(!0), n = () => e(!1);
310
+ return window.addEventListener("online", t, !1), window.addEventListener("offline", n, !1), () => {
311
+ window.removeEventListener("online", t), window.removeEventListener("offline", n);
312
+ };
313
+ }
314
+ };
315
+ }
316
+ onSubscribe() {
317
+ this.#t || this.setEventListener(this.#n);
318
+ }
319
+ onUnsubscribe() {
320
+ this.hasListeners() || (this.#t?.(), this.#t = void 0);
321
+ }
322
+ setEventListener(e) {
323
+ this.#n = e, this.#t?.(), this.#t = e(this.setOnline.bind(this));
324
+ }
325
+ setOnline(e) {
326
+ this.#e !== e && (this.#e = e, this.listeners.forEach((t) => {
327
+ t(e);
328
+ }));
329
+ }
330
+ isOnline() {
331
+ return this.#e;
332
+ }
333
+ }();
334
+ //#endregion
335
+ //#region node_modules/@tanstack/query-core/build/modern/retryer.js
336
+ function ce(e) {
337
+ return Math.min(1e3 * 2 ** e, 3e4);
338
+ }
339
+ function I(e) {
340
+ return (e ?? "online") === "online" ? F.isOnline() : !0;
341
+ }
342
+ var L = class extends Error {
343
+ constructor(e) {
344
+ super("CancelledError"), this.revert = e?.revert, this.silent = e?.silent;
345
+ }
346
+ };
347
+ function R(e) {
348
+ let t = !1, n = 0, r, i = M(), a = () => i.status !== "pending", o = (t) => {
349
+ if (!a()) {
350
+ let n = new L(t);
351
+ p(n), e.onCancel?.(n);
352
+ }
353
+ }, s = () => {
354
+ t = !0;
355
+ }, l = () => {
356
+ t = !1;
357
+ }, u = () => c.isFocused() && (e.networkMode === "always" || F.isOnline()) && e.canRun(), d = () => I(e.networkMode) && e.canRun(), f = (e) => {
358
+ a() || (r?.(), i.resolve(e));
359
+ }, p = (e) => {
360
+ a() || (r?.(), i.reject(e));
361
+ }, m = () => new Promise((t) => {
362
+ r = (e) => {
363
+ (a() || u()) && t(e);
364
+ }, e.onPause?.();
365
+ }).then(() => {
366
+ r = void 0, a() || e.onContinue?.();
367
+ }), h = () => {
368
+ if (a()) return;
369
+ let r, i = n === 0 ? e.initialPromise : void 0;
370
+ try {
371
+ r = i ?? e.fn();
372
+ } catch (e) {
373
+ r = Promise.reject(e);
374
+ }
375
+ Promise.resolve(r).then(f).catch((r) => {
376
+ if (a()) return;
377
+ let i = e.retry ?? (j.isServer() ? 0 : 3), o = e.retryDelay ?? ce, s = typeof o == "function" ? o(n, r) : o, c = i === !0 || typeof i == "number" && n < i || typeof i == "function" && i(n, r);
378
+ if (t || !c) {
379
+ p(r);
380
+ return;
381
+ }
382
+ n++, e.onFail?.(n, r), ne(s).then(() => u() ? void 0 : m()).then(() => {
383
+ t ? p(r) : h();
384
+ });
385
+ });
386
+ };
387
+ return {
388
+ promise: i,
389
+ status: () => i.status,
390
+ cancel: o,
391
+ continue: () => (r?.(), i),
392
+ cancelRetry: s,
393
+ continueRetry: l,
394
+ canStart: d,
395
+ start: () => (d() ? h() : m().then(h), i)
396
+ };
397
+ }
398
+ //#endregion
399
+ //#region node_modules/@tanstack/query-core/build/modern/removable.js
400
+ var z = class {
401
+ #e;
402
+ destroy() {
403
+ this.clearGcTimeout();
404
+ }
405
+ scheduleGc() {
406
+ this.clearGcTimeout(), h(this.gcTime) && (this.#e = u.setTimeout(() => {
407
+ this.optionalRemove();
408
+ }, this.gcTime));
409
+ }
410
+ updateGcTime(e) {
411
+ this.gcTime = Math.max(this.gcTime || 0, e ?? (j.isServer() ? Infinity : 300 * 1e3));
412
+ }
413
+ clearGcTimeout() {
414
+ this.#e !== void 0 && (u.clearTimeout(this.#e), this.#e = void 0);
415
+ }
416
+ };
417
+ //#endregion
418
+ //#region node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js
419
+ function le(e) {
420
+ return { onFetch: (t, n) => {
421
+ let r = t.options, i = t.fetchOptions?.meta?.fetchMore?.direction, a = t.state.data?.pages || [], o = t.state.data?.pageParams || [], s = {
422
+ pages: [],
423
+ pageParams: []
424
+ }, c = 0, l = async () => {
425
+ let n = !1, l = (e) => {
426
+ oe(e, () => t.signal, () => n = !0);
427
+ }, u = A(t.options, t.fetchOptions), d = async (e, r, i) => {
428
+ if (n) return Promise.reject(t.signal.reason);
429
+ if (r == null && e.pages.length) return Promise.resolve(e);
430
+ let a = await u((() => {
431
+ let e = {
432
+ client: t.client,
433
+ queryKey: t.queryKey,
434
+ pageParam: r,
435
+ direction: i ? "backward" : "forward",
436
+ meta: t.options.meta
437
+ };
438
+ return l(e), e;
439
+ })()), { maxPages: o } = t.options, s = i ? ie : re;
440
+ return {
441
+ pages: s(e.pages, a, o),
442
+ pageParams: s(e.pageParams, r, o)
443
+ };
444
+ };
445
+ if (i && a.length) {
446
+ let e = i === "backward", t = e ? ue : B, n = {
447
+ pages: a,
448
+ pageParams: o
449
+ };
450
+ s = await d(n, t(r, n), e);
451
+ } else {
452
+ let t = e ?? a.length;
453
+ do {
454
+ let e = c === 0 ? o[0] ?? r.initialPageParam : B(r, s);
455
+ if (c > 0 && e == null) break;
456
+ s = await d(s, e), c++;
457
+ } while (c < t);
458
+ }
459
+ return s;
460
+ };
461
+ t.options.persister ? t.fetchFn = () => t.options.persister?.(l, {
462
+ client: t.client,
463
+ queryKey: t.queryKey,
464
+ meta: t.options.meta,
465
+ signal: t.signal
466
+ }, n) : t.fetchFn = l;
467
+ } };
468
+ }
469
+ function B(e, { pages: t, pageParams: n }) {
470
+ let r = t.length - 1;
471
+ return t.length > 0 ? e.getNextPageParam(t[r], t, n[r], n) : void 0;
472
+ }
473
+ function ue(e, { pages: t, pageParams: n }) {
474
+ return t.length > 0 ? e.getPreviousPageParam?.(t[0], t, n[0], n) : void 0;
475
+ }
476
+ //#endregion
477
+ //#region node_modules/@tanstack/query-core/build/modern/query.js
478
+ var de = class extends z {
479
+ #e;
480
+ #t;
481
+ #n;
482
+ #r;
483
+ #i;
484
+ #a;
485
+ #o;
486
+ #s;
487
+ constructor(e) {
488
+ super(), this.#s = !1, this.#o = e.defaultOptions, this.setOptions(e.options), this.observers = [], this.#i = e.client, this.#r = this.#i.getQueryCache(), this.queryKey = e.queryKey, this.queryHash = e.queryHash, this.#t = U(this.options), this.state = e.state ?? this.#t, this.scheduleGc();
489
+ }
490
+ get meta() {
491
+ return this.options.meta;
492
+ }
493
+ get queryType() {
494
+ return this.#e;
495
+ }
496
+ get promise() {
497
+ return this.#a?.promise;
498
+ }
499
+ setOptions(e) {
500
+ if (this.options = {
501
+ ...this.#o,
502
+ ...e
503
+ }, e?._type && (this.#e = e._type), this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
504
+ let e = U(this.options);
505
+ e.data !== void 0 && (this.setState(H(e.data, e.dataUpdatedAt)), this.#t = e);
506
+ }
507
+ }
508
+ optionalRemove() {
509
+ !this.observers.length && this.state.fetchStatus === "idle" && this.#r.remove(this);
510
+ }
511
+ setData(e, t) {
512
+ let n = O(this.state.data, e, this.options);
513
+ return this.#l({
514
+ data: n,
515
+ type: "success",
516
+ dataUpdatedAt: t?.updatedAt,
517
+ manual: t?.manual
518
+ }), n;
519
+ }
520
+ setState(e) {
521
+ this.#l({
522
+ type: "setState",
523
+ state: e
524
+ });
525
+ }
526
+ cancel(e) {
527
+ let t = this.#a?.promise;
528
+ return this.#a?.cancel(e), t ? t.then(p).catch(p) : Promise.resolve();
529
+ }
530
+ destroy() {
531
+ super.destroy(), this.cancel({ silent: !0 });
532
+ }
533
+ get resetState() {
534
+ return this.#t;
535
+ }
536
+ reset() {
537
+ this.destroy(), this.setState(this.resetState);
538
+ }
539
+ isActive() {
540
+ return this.observers.some((e) => v(e.options.enabled, this) !== !1);
541
+ }
542
+ isDisabled() {
543
+ return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === k || !this.isFetched();
544
+ }
545
+ isFetched() {
546
+ return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
547
+ }
548
+ isStatic() {
549
+ return this.getObserversCount() > 0 ? this.observers.some((e) => _(e.options.staleTime, this) === "static") : !1;
550
+ }
551
+ isStale() {
552
+ return this.getObserversCount() > 0 ? this.observers.some((e) => e.getCurrentResult().isStale) : this.state.data === void 0 || this.state.isInvalidated;
553
+ }
554
+ isStaleByTime(e = 0) {
555
+ return this.state.data === void 0 ? !0 : e === "static" ? !1 : this.state.isInvalidated ? !0 : !g(this.state.dataUpdatedAt, e);
556
+ }
557
+ onFocus() {
558
+ this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#a?.continue();
559
+ }
560
+ onOnline() {
561
+ this.observers.find((e) => e.shouldFetchOnReconnect())?.refetch({ cancelRefetch: !1 }), this.#a?.continue();
562
+ }
563
+ addObserver(e) {
564
+ this.observers.includes(e) || (this.observers.push(e), this.clearGcTimeout(), this.#r.notify({
565
+ type: "observerAdded",
566
+ query: this,
567
+ observer: e
568
+ }));
569
+ }
570
+ removeObserver(e) {
571
+ this.observers.includes(e) && (this.observers = this.observers.filter((t) => t !== e), this.observers.length || (this.#a && (this.#s || this.#c() ? this.#a.cancel({ revert: !0 }) : this.#a.cancelRetry()), this.scheduleGc()), this.#r.notify({
572
+ type: "observerRemoved",
573
+ query: this,
574
+ observer: e
575
+ }));
576
+ }
577
+ getObserversCount() {
578
+ return this.observers.length;
579
+ }
580
+ #c() {
581
+ return this.state.fetchStatus === "paused" && this.state.status === "pending";
582
+ }
583
+ invalidate() {
584
+ this.state.isInvalidated || this.#l({ type: "invalidate" });
585
+ }
586
+ async fetch(e, t) {
587
+ if (this.state.fetchStatus !== "idle" && this.#a?.status() !== "rejected") {
588
+ if (this.state.data !== void 0 && t?.cancelRefetch) this.cancel({ silent: !0 });
589
+ else if (this.#a) return this.#a.continueRetry(), this.#a.promise;
590
+ }
591
+ if (e && this.setOptions(e), !this.options.queryFn) {
592
+ let e = this.observers.find((e) => e.options.queryFn);
593
+ e && this.setOptions(e.options);
594
+ }
595
+ process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));
596
+ let n = new AbortController(), r = (e) => {
597
+ Object.defineProperty(e, "signal", {
598
+ enumerable: !0,
599
+ get: () => (this.#s = !0, n.signal)
600
+ });
601
+ }, i = () => {
602
+ let e = A(this.options, t), n = (() => {
603
+ let e = {
604
+ client: this.#i,
605
+ queryKey: this.queryKey,
606
+ meta: this.meta
607
+ };
608
+ return r(e), e;
609
+ })();
610
+ return this.#s = !1, this.options.persister ? this.options.persister(e, n, this) : e(n);
611
+ }, a = (() => {
612
+ let e = {
613
+ fetchOptions: t,
614
+ options: this.options,
615
+ queryKey: this.queryKey,
616
+ client: this.#i,
617
+ state: this.state,
618
+ fetchFn: i
619
+ };
620
+ return r(e), e;
621
+ })();
622
+ (this.#e === "infinite" ? le(this.options.pages) : this.options.behavior)?.onFetch(a, this), this.#n = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== a.fetchOptions?.meta) && this.#l({
623
+ type: "fetch",
624
+ meta: a.fetchOptions?.meta
625
+ }), this.#a = R({
626
+ initialPromise: t?.initialPromise,
627
+ fn: a.fetchFn,
628
+ onCancel: (e) => {
629
+ e instanceof L && e.revert && this.setState({
630
+ ...this.#n,
631
+ fetchStatus: "idle"
632
+ }), n.abort();
633
+ },
634
+ onFail: (e, t) => {
635
+ this.#l({
636
+ type: "failed",
637
+ failureCount: e,
638
+ error: t
639
+ });
640
+ },
641
+ onPause: () => {
642
+ this.#l({ type: "pause" });
643
+ },
644
+ onContinue: () => {
645
+ this.#l({ type: "continue" });
646
+ },
647
+ retry: a.options.retry,
648
+ retryDelay: a.options.retryDelay,
649
+ networkMode: a.options.networkMode,
650
+ canRun: () => !0
651
+ });
652
+ try {
653
+ let e = await this.#a.start();
654
+ if (e === void 0) throw process.env.NODE_ENV !== "production" && console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`), Error(`${this.queryHash} data is undefined`);
655
+ return this.setData(e), this.#r.config.onSuccess?.(e, this), this.#r.config.onSettled?.(e, this.state.error, this), e;
656
+ } catch (e) {
657
+ if (e instanceof L) {
658
+ if (e.silent) return this.#a.promise;
659
+ if (e.revert) {
660
+ if (this.state.data === void 0) throw e;
661
+ return this.state.data;
662
+ }
663
+ }
664
+ throw this.#l({
665
+ type: "error",
666
+ error: e
667
+ }), this.#r.config.onError?.(e, this), this.#r.config.onSettled?.(this.state.data, e, this), e;
668
+ } finally {
669
+ this.scheduleGc();
670
+ }
671
+ }
672
+ #l(e) {
673
+ this.state = ((t) => {
674
+ switch (e.type) {
675
+ case "failed": return {
676
+ ...t,
677
+ fetchFailureCount: e.failureCount,
678
+ fetchFailureReason: e.error
679
+ };
680
+ case "pause": return {
681
+ ...t,
682
+ fetchStatus: "paused"
683
+ };
684
+ case "continue": return {
685
+ ...t,
686
+ fetchStatus: "fetching"
687
+ };
688
+ case "fetch": return {
689
+ ...t,
690
+ ...V(t.data, this.options),
691
+ fetchMeta: e.meta ?? null
692
+ };
693
+ case "success":
694
+ let n = {
695
+ ...t,
696
+ ...H(e.data, e.dataUpdatedAt),
697
+ dataUpdateCount: t.dataUpdateCount + 1,
698
+ ...!e.manual && {
699
+ fetchStatus: "idle",
700
+ fetchFailureCount: 0,
701
+ fetchFailureReason: null
702
+ }
703
+ };
704
+ return this.#n = e.manual ? n : void 0, n;
705
+ case "error":
706
+ let r = e.error;
707
+ return {
708
+ ...t,
709
+ error: r,
710
+ errorUpdateCount: t.errorUpdateCount + 1,
711
+ errorUpdatedAt: Date.now(),
712
+ fetchFailureCount: t.fetchFailureCount + 1,
713
+ fetchFailureReason: r,
714
+ fetchStatus: "idle",
715
+ status: "error",
716
+ isInvalidated: !0
717
+ };
718
+ case "invalidate": return {
719
+ ...t,
720
+ isInvalidated: !0
721
+ };
722
+ case "setState": return {
723
+ ...t,
724
+ ...e.state
725
+ };
726
+ }
727
+ })(this.state), P.batch(() => {
728
+ this.observers.forEach((e) => {
729
+ e.onQueryUpdate();
730
+ }), this.#r.notify({
731
+ query: this,
732
+ type: "updated",
733
+ action: e
734
+ });
735
+ });
736
+ }
737
+ };
738
+ function V(e, t) {
739
+ return {
740
+ fetchFailureCount: 0,
741
+ fetchFailureReason: null,
742
+ fetchStatus: I(t.networkMode) ? "fetching" : "paused",
743
+ ...e === void 0 && {
744
+ error: null,
745
+ status: "pending"
746
+ }
747
+ };
748
+ }
749
+ function H(e, t) {
750
+ return {
751
+ data: e,
752
+ dataUpdatedAt: t ?? Date.now(),
753
+ error: null,
754
+ isInvalidated: !1,
755
+ status: "success"
756
+ };
757
+ }
758
+ function U(e) {
759
+ let t = typeof e.initialData == "function" ? e.initialData() : e.initialData, n = t !== void 0, r = n ? typeof e.initialDataUpdatedAt == "function" ? e.initialDataUpdatedAt() : e.initialDataUpdatedAt : 0;
760
+ return {
761
+ data: t,
762
+ dataUpdateCount: 0,
763
+ dataUpdatedAt: n ? r ?? Date.now() : 0,
764
+ error: null,
765
+ errorUpdateCount: 0,
766
+ errorUpdatedAt: 0,
767
+ fetchFailureCount: 0,
768
+ fetchFailureReason: null,
769
+ fetchMeta: null,
770
+ isInvalidated: !1,
771
+ status: n ? "success" : "pending",
772
+ fetchStatus: "idle"
773
+ };
774
+ }
775
+ //#endregion
776
+ //#region node_modules/@tanstack/query-core/build/modern/mutation.js
777
+ var fe = class extends z {
778
+ #e;
779
+ #t;
780
+ #n;
781
+ #r;
782
+ constructor(e) {
783
+ super(), this.#e = e.client, this.mutationId = e.mutationId, this.#n = e.mutationCache, this.#t = [], this.state = e.state || pe(), this.setOptions(e.options), this.scheduleGc();
784
+ }
785
+ setOptions(e) {
786
+ this.options = e, this.updateGcTime(this.options.gcTime);
787
+ }
788
+ get meta() {
789
+ return this.options.meta;
790
+ }
791
+ addObserver(e) {
792
+ this.#t.includes(e) || (this.#t.push(e), this.clearGcTimeout(), this.#n.notify({
793
+ type: "observerAdded",
794
+ mutation: this,
795
+ observer: e
796
+ }));
797
+ }
798
+ removeObserver(e) {
799
+ this.#t = this.#t.filter((t) => t !== e), this.scheduleGc(), this.#n.notify({
800
+ type: "observerRemoved",
801
+ mutation: this,
802
+ observer: e
803
+ });
804
+ }
805
+ optionalRemove() {
806
+ this.#t.length || (this.state.status === "pending" ? this.scheduleGc() : this.#n.remove(this));
807
+ }
808
+ continue() {
809
+ return this.#r?.continue() ?? this.execute(this.state.variables);
810
+ }
811
+ async execute(e) {
812
+ let t = () => {
813
+ this.#i({ type: "continue" });
814
+ }, n = {
815
+ client: this.#e,
816
+ meta: this.options.meta,
817
+ mutationKey: this.options.mutationKey
818
+ };
819
+ this.#r = R({
820
+ fn: () => this.options.mutationFn ? this.options.mutationFn(e, n) : Promise.reject(/* @__PURE__ */ Error("No mutationFn found")),
821
+ onFail: (e, t) => {
822
+ this.#i({
823
+ type: "failed",
824
+ failureCount: e,
825
+ error: t
826
+ });
827
+ },
828
+ onPause: () => {
829
+ this.#i({ type: "pause" });
830
+ },
831
+ onContinue: t,
832
+ retry: this.options.retry ?? 0,
833
+ retryDelay: this.options.retryDelay,
834
+ networkMode: this.options.networkMode,
835
+ canRun: () => this.#n.canRun(this)
836
+ });
837
+ let r = this.state.status === "pending", i = !this.#r.canStart();
838
+ try {
839
+ if (r) t();
840
+ else {
841
+ this.#i({
842
+ type: "pending",
843
+ variables: e,
844
+ isPaused: i
845
+ }), this.#n.config.onMutate && await this.#n.config.onMutate(e, this, n);
846
+ let t = await this.options.onMutate?.(e, n);
847
+ t !== this.state.context && this.#i({
848
+ type: "pending",
849
+ context: t,
850
+ variables: e,
851
+ isPaused: i
852
+ });
853
+ }
854
+ let a = await this.#r.start();
855
+ return await this.#n.config.onSuccess?.(a, e, this.state.context, this, n), await this.options.onSuccess?.(a, e, this.state.context, n), await this.#n.config.onSettled?.(a, null, this.state.variables, this.state.context, this, n), await this.options.onSettled?.(a, null, e, this.state.context, n), this.#i({
856
+ type: "success",
857
+ data: a
858
+ }), a;
859
+ } catch (t) {
860
+ try {
861
+ await this.#n.config.onError?.(t, e, this.state.context, this, n);
862
+ } catch (e) {
863
+ Promise.reject(e);
864
+ }
865
+ try {
866
+ await this.options.onError?.(t, e, this.state.context, n);
867
+ } catch (e) {
868
+ Promise.reject(e);
869
+ }
870
+ try {
871
+ await this.#n.config.onSettled?.(void 0, t, this.state.variables, this.state.context, this, n);
872
+ } catch (e) {
873
+ Promise.reject(e);
874
+ }
875
+ try {
876
+ await this.options.onSettled?.(void 0, t, e, this.state.context, n);
877
+ } catch (e) {
878
+ Promise.reject(e);
879
+ }
880
+ throw this.#i({
881
+ type: "error",
882
+ error: t
883
+ }), t;
884
+ } finally {
885
+ this.#n.runNext(this);
886
+ }
887
+ }
888
+ #i(e) {
889
+ this.state = ((t) => {
890
+ switch (e.type) {
891
+ case "failed": return {
892
+ ...t,
893
+ failureCount: e.failureCount,
894
+ failureReason: e.error
895
+ };
896
+ case "pause": return {
897
+ ...t,
898
+ isPaused: !0
899
+ };
900
+ case "continue": return {
901
+ ...t,
902
+ isPaused: !1
903
+ };
904
+ case "pending": return {
905
+ ...t,
906
+ context: e.context,
907
+ data: void 0,
908
+ failureCount: 0,
909
+ failureReason: null,
910
+ error: null,
911
+ isPaused: e.isPaused,
912
+ status: "pending",
913
+ variables: e.variables,
914
+ submittedAt: Date.now()
915
+ };
916
+ case "success": return {
917
+ ...t,
918
+ data: e.data,
919
+ failureCount: 0,
920
+ failureReason: null,
921
+ error: null,
922
+ status: "success",
923
+ isPaused: !1
924
+ };
925
+ case "error": return {
926
+ ...t,
927
+ data: void 0,
928
+ error: e.error,
929
+ failureCount: t.failureCount + 1,
930
+ failureReason: e.error,
931
+ isPaused: !1,
932
+ status: "error"
933
+ };
934
+ }
935
+ })(this.state), P.batch(() => {
936
+ this.#t.forEach((t) => {
937
+ t.onMutationUpdate(e);
938
+ }), this.#n.notify({
939
+ mutation: this,
940
+ type: "updated",
941
+ action: e
942
+ });
943
+ });
944
+ }
945
+ };
946
+ function pe() {
947
+ return {
948
+ context: void 0,
949
+ data: void 0,
950
+ error: null,
951
+ failureCount: 0,
952
+ failureReason: null,
953
+ isPaused: !1,
954
+ status: "idle",
955
+ variables: void 0,
956
+ submittedAt: 0
957
+ };
958
+ }
959
+ //#endregion
960
+ //#region node_modules/@tanstack/query-core/build/modern/mutationCache.js
961
+ var me = class extends s {
962
+ constructor(e = {}) {
963
+ super(), this.config = e, this.#e = /* @__PURE__ */ new Set(), this.#t = /* @__PURE__ */ new Map(), this.#n = 0;
964
+ }
965
+ #e;
966
+ #t;
967
+ #n;
968
+ build(e, t, n) {
969
+ let r = new fe({
970
+ client: e,
971
+ mutationCache: this,
972
+ mutationId: ++this.#n,
973
+ options: e.defaultMutationOptions(t),
974
+ state: n
975
+ });
976
+ return this.add(r), r;
977
+ }
978
+ add(e) {
979
+ this.#e.add(e);
980
+ let t = W(e);
981
+ if (typeof t == "string") {
982
+ let n = this.#t.get(t);
983
+ n ? n.push(e) : this.#t.set(t, [e]);
984
+ }
985
+ this.notify({
986
+ type: "added",
987
+ mutation: e
988
+ });
989
+ }
990
+ remove(e) {
991
+ if (this.#e.delete(e)) {
992
+ let t = W(e);
993
+ if (typeof t == "string") {
994
+ let n = this.#t.get(t);
995
+ if (n) if (n.length > 1) {
996
+ let t = n.indexOf(e);
997
+ t !== -1 && n.splice(t, 1);
998
+ } else n[0] === e && this.#t.delete(t);
999
+ }
1000
+ }
1001
+ this.notify({
1002
+ type: "removed",
1003
+ mutation: e
1004
+ });
1005
+ }
1006
+ canRun(e) {
1007
+ let t = W(e);
1008
+ if (typeof t == "string") {
1009
+ let n = this.#t.get(t)?.find((e) => e.state.status === "pending");
1010
+ return !n || n === e;
1011
+ } else return !0;
1012
+ }
1013
+ runNext(e) {
1014
+ let t = W(e);
1015
+ return typeof t == "string" ? (this.#t.get(t)?.find((t) => t !== e && t.state.isPaused))?.continue() ?? Promise.resolve() : Promise.resolve();
1016
+ }
1017
+ clear() {
1018
+ P.batch(() => {
1019
+ this.#e.forEach((e) => {
1020
+ this.notify({
1021
+ type: "removed",
1022
+ mutation: e
1023
+ });
1024
+ }), this.#e.clear(), this.#t.clear();
1025
+ });
1026
+ }
1027
+ getAll() {
1028
+ return Array.from(this.#e);
1029
+ }
1030
+ find(e) {
1031
+ let t = {
1032
+ exact: !0,
1033
+ ...e
1034
+ };
1035
+ return this.getAll().find((e) => b(t, e));
1036
+ }
1037
+ findAll(e = {}) {
1038
+ return this.getAll().filter((t) => b(e, t));
1039
+ }
1040
+ notify(e) {
1041
+ P.batch(() => {
1042
+ this.listeners.forEach((t) => {
1043
+ t(e);
1044
+ });
1045
+ });
1046
+ }
1047
+ resumePausedMutations() {
1048
+ let e = this.getAll().filter((e) => e.state.isPaused);
1049
+ return P.batch(() => Promise.all(e.map((e) => e.continue().catch(p))));
1050
+ }
1051
+ };
1052
+ function W(e) {
1053
+ return e.options.scope?.id;
1054
+ }
1055
+ //#endregion
1056
+ //#region node_modules/@tanstack/query-core/build/modern/queryCache.js
1057
+ var he = class extends s {
1058
+ constructor(e = {}) {
1059
+ super(), this.config = e, this.#e = /* @__PURE__ */ new Map();
1060
+ }
1061
+ #e;
1062
+ build(e, t, n) {
1063
+ let r = t.queryKey, i = t.queryHash ?? x(r, t), a = this.get(i);
1064
+ return a || (a = new de({
1065
+ client: e,
1066
+ queryKey: r,
1067
+ queryHash: i,
1068
+ options: e.defaultQueryOptions(t),
1069
+ state: n,
1070
+ defaultOptions: e.getQueryDefaults(r)
1071
+ }), this.add(a)), a;
1072
+ }
1073
+ add(e) {
1074
+ this.#e.has(e.queryHash) || (this.#e.set(e.queryHash, e), this.notify({
1075
+ type: "added",
1076
+ query: e
1077
+ }));
1078
+ }
1079
+ remove(e) {
1080
+ let t = this.#e.get(e.queryHash);
1081
+ t && (e.destroy(), t === e && this.#e.delete(e.queryHash), this.notify({
1082
+ type: "removed",
1083
+ query: e
1084
+ }));
1085
+ }
1086
+ clear() {
1087
+ P.batch(() => {
1088
+ this.getAll().forEach((e) => {
1089
+ this.remove(e);
1090
+ });
1091
+ });
1092
+ }
1093
+ get(e) {
1094
+ return this.#e.get(e);
1095
+ }
1096
+ getAll() {
1097
+ return [...this.#e.values()];
1098
+ }
1099
+ find(e) {
1100
+ let t = {
1101
+ exact: !0,
1102
+ ...e
1103
+ };
1104
+ return this.getAll().find((e) => y(t, e));
1105
+ }
1106
+ findAll(e = {}) {
1107
+ let t = this.getAll();
1108
+ return Object.keys(e).length > 0 ? t.filter((t) => y(e, t)) : t;
1109
+ }
1110
+ notify(e) {
1111
+ P.batch(() => {
1112
+ this.listeners.forEach((t) => {
1113
+ t(e);
1114
+ });
1115
+ });
1116
+ }
1117
+ onFocus() {
1118
+ P.batch(() => {
1119
+ this.getAll().forEach((e) => {
1120
+ e.onFocus();
1121
+ });
1122
+ });
1123
+ }
1124
+ onOnline() {
1125
+ P.batch(() => {
1126
+ this.getAll().forEach((e) => {
1127
+ e.onOnline();
1128
+ });
1129
+ });
1130
+ }
1131
+ }, G = class {
1132
+ #e;
1133
+ #t;
1134
+ #n;
1135
+ #r;
1136
+ #i;
1137
+ #a;
1138
+ #o;
1139
+ #s;
1140
+ constructor(e = {}) {
1141
+ this.#e = e.queryCache || new he(), this.#t = e.mutationCache || new me(), this.#n = e.defaultOptions || {}, this.#r = /* @__PURE__ */ new Map(), this.#i = /* @__PURE__ */ new Map(), this.#a = 0;
1142
+ }
1143
+ mount() {
1144
+ this.#a++, this.#a === 1 && (this.#o = c.subscribe(async (e) => {
1145
+ e && (await this.resumePausedMutations(), this.#e.onFocus());
1146
+ }), this.#s = F.subscribe(async (e) => {
1147
+ e && (await this.resumePausedMutations(), this.#e.onOnline());
1148
+ }));
1149
+ }
1150
+ unmount() {
1151
+ this.#a--, this.#a === 0 && (this.#o?.(), this.#o = void 0, this.#s?.(), this.#s = void 0);
1152
+ }
1153
+ isFetching(e) {
1154
+ return this.#e.findAll({
1155
+ ...e,
1156
+ fetchStatus: "fetching"
1157
+ }).length;
1158
+ }
1159
+ isMutating(e) {
1160
+ return this.#t.findAll({
1161
+ ...e,
1162
+ status: "pending"
1163
+ }).length;
1164
+ }
1165
+ getQueryData(e) {
1166
+ let t = this.defaultQueryOptions({ queryKey: e });
1167
+ return this.#e.get(t.queryHash)?.state.data;
1168
+ }
1169
+ ensureQueryData(e) {
1170
+ let t = this.defaultQueryOptions(e), n = this.#e.build(this, t), r = n.state.data;
1171
+ return r === void 0 ? this.fetchQuery(e) : (e.revalidateIfStale && n.isStaleByTime(_(t.staleTime, n)) && this.prefetchQuery(t), Promise.resolve(r));
1172
+ }
1173
+ getQueriesData(e) {
1174
+ return this.#e.findAll(e).map(({ queryKey: e, state: t }) => [e, t.data]);
1175
+ }
1176
+ setQueryData(e, t, n) {
1177
+ let r = this.defaultQueryOptions({ queryKey: e }), i = this.#e.get(r.queryHash)?.state.data, a = m(t, i);
1178
+ if (a !== void 0) return this.#e.build(this, r).setData(a, {
1179
+ ...n,
1180
+ manual: !0
1181
+ });
1182
+ }
1183
+ setQueriesData(e, t, n) {
1184
+ return P.batch(() => this.#e.findAll(e).map(({ queryKey: e }) => [e, this.setQueryData(e, t, n)]));
1185
+ }
1186
+ getQueryState(e) {
1187
+ let t = this.defaultQueryOptions({ queryKey: e });
1188
+ return this.#e.get(t.queryHash)?.state;
1189
+ }
1190
+ removeQueries(e) {
1191
+ let t = this.#e;
1192
+ P.batch(() => {
1193
+ t.findAll(e).forEach((e) => {
1194
+ t.remove(e);
1195
+ });
1196
+ });
1197
+ }
1198
+ resetQueries(e, t) {
1199
+ let n = this.#e;
1200
+ return P.batch(() => (n.findAll(e).forEach((e) => {
1201
+ e.reset();
1202
+ }), this.refetchQueries({
1203
+ type: "active",
1204
+ ...e
1205
+ }, t)));
1206
+ }
1207
+ cancelQueries(e, t = {}) {
1208
+ let n = {
1209
+ revert: !0,
1210
+ ...t
1211
+ }, r = P.batch(() => this.#e.findAll(e).map((e) => e.cancel(n)));
1212
+ return Promise.all(r).then(p).catch(p);
1213
+ }
1214
+ invalidateQueries(e, t = {}) {
1215
+ return P.batch(() => (this.#e.findAll(e).forEach((e) => {
1216
+ e.invalidate();
1217
+ }), e?.refetchType === "none" ? Promise.resolve() : this.refetchQueries({
1218
+ ...e,
1219
+ type: e?.refetchType ?? e?.type ?? "active"
1220
+ }, t)));
1221
+ }
1222
+ refetchQueries(e, t = {}) {
1223
+ let n = {
1224
+ ...t,
1225
+ cancelRefetch: t.cancelRefetch ?? !0
1226
+ }, r = P.batch(() => this.#e.findAll(e).filter((e) => !e.isDisabled() && !e.isStatic()).map((e) => {
1227
+ let t = e.fetch(void 0, n);
1228
+ return n.throwOnError || (t = t.catch(p)), e.state.fetchStatus === "paused" ? Promise.resolve() : t;
1229
+ }));
1230
+ return Promise.all(r).then(p);
1231
+ }
1232
+ fetchQuery(e) {
1233
+ let t = this.defaultQueryOptions(e);
1234
+ t.retry === void 0 && (t.retry = !1);
1235
+ let n = this.#e.build(this, t);
1236
+ return n.isStaleByTime(_(t.staleTime, n)) ? n.fetch(t) : Promise.resolve(n.state.data);
1237
+ }
1238
+ prefetchQuery(e) {
1239
+ return this.fetchQuery(e).then(p).catch(p);
1240
+ }
1241
+ fetchInfiniteQuery(e) {
1242
+ return e._type = "infinite", this.fetchQuery(e);
1243
+ }
1244
+ prefetchInfiniteQuery(e) {
1245
+ return this.fetchInfiniteQuery(e).then(p).catch(p);
1246
+ }
1247
+ ensureInfiniteQueryData(e) {
1248
+ return e._type = "infinite", this.ensureQueryData(e);
1249
+ }
1250
+ resumePausedMutations() {
1251
+ return F.isOnline() ? this.#t.resumePausedMutations() : Promise.resolve();
1252
+ }
1253
+ getQueryCache() {
1254
+ return this.#e;
1255
+ }
1256
+ getMutationCache() {
1257
+ return this.#t;
1258
+ }
1259
+ getDefaultOptions() {
1260
+ return this.#n;
1261
+ }
1262
+ setDefaultOptions(e) {
1263
+ this.#n = e;
1264
+ }
1265
+ setQueryDefaults(e, t) {
1266
+ this.#r.set(S(e), {
1267
+ queryKey: e,
1268
+ defaultOptions: t
1269
+ });
1270
+ }
1271
+ getQueryDefaults(e) {
1272
+ let t = [...this.#r.values()], n = {};
1273
+ return t.forEach((t) => {
1274
+ C(e, t.queryKey) && Object.assign(n, t.defaultOptions);
1275
+ }), n;
1276
+ }
1277
+ setMutationDefaults(e, t) {
1278
+ this.#i.set(S(e), {
1279
+ mutationKey: e,
1280
+ defaultOptions: t
1281
+ });
1282
+ }
1283
+ getMutationDefaults(e) {
1284
+ let t = [...this.#i.values()], n = {};
1285
+ return t.forEach((t) => {
1286
+ C(e, t.mutationKey) && Object.assign(n, t.defaultOptions);
1287
+ }), n;
1288
+ }
1289
+ defaultQueryOptions(e) {
1290
+ if (e._defaulted) return e;
1291
+ let t = {
1292
+ ...this.#n.queries,
1293
+ ...this.getQueryDefaults(e.queryKey),
1294
+ ...e,
1295
+ _defaulted: !0
1296
+ };
1297
+ return t.queryHash ||= x(t.queryKey, t), 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 === k && (t.enabled = !1), t;
1298
+ }
1299
+ defaultMutationOptions(e) {
1300
+ return e?._defaulted ? e : {
1301
+ ...this.#n.mutations,
1302
+ ...e?.mutationKey && this.getMutationDefaults(e.mutationKey),
1303
+ ...e,
1304
+ _defaulted: !0
1305
+ };
1306
+ }
1307
+ clear() {
1308
+ this.#e.clear(), this.#t.clear();
1309
+ }
1310
+ }, K = e.createContext(void 0), ge = (t) => {
1311
+ let n = e.useContext(K);
1312
+ if (t) return t;
1313
+ if (!n) throw Error("No QueryClient set, use QueryClientProvider to set one");
1314
+ return n;
1315
+ }, q = ({ client: t, children: n }) => (e.useEffect(() => (t.mount(), () => {
1316
+ t.unmount();
1317
+ }), [t]), /* @__PURE__ */ a(K.Provider, {
1318
+ value: t,
1319
+ children: n
1320
+ })), J = new G({ defaultOptions: { queries: { retry: !1 } } }), _e = (e, t, n) => {
1321
+ let r = "[LiveState]";
1322
+ e === "error" ? console.error(r, t, ...n ? [n] : []) : console.warn(r, t, ...n ? [n] : []);
1323
+ };
1324
+ function Y(e) {
1325
+ return (t, n, r) => {
1326
+ e ? e(t, n, r) : _e(t, n, r);
1327
+ };
1328
+ }
1329
+ //#endregion
1330
+ //#region src/utils/analytics.ts
1331
+ var X = o.createInstance();
1332
+ function ve(e, t) {
1333
+ let n = Y(t);
1334
+ try {
1335
+ if (!e) {
1336
+ n("warn", "Amplitude API key not provided");
1337
+ return;
1338
+ }
1339
+ X.init(e, { defaultTracking: !1 });
1340
+ } catch (e) {
1341
+ n("error", "Failed to initialize Amplitude", { error: e });
1342
+ }
1343
+ }
1344
+ async function ye(e, t) {
1345
+ let n = Y(t);
1346
+ try {
1347
+ if (Q()) {
1348
+ n("info", "Clarity already initialized by client");
1349
+ return;
1350
+ }
1351
+ let t = e || be();
1352
+ if (!t) {
1353
+ n("warn", "Clarity project ID not provided");
1354
+ return;
1355
+ }
1356
+ (await import("@microsoft/clarity")).default.init(t);
1357
+ } catch (e) {
1358
+ n("error", "Failed to initialize Clarity", { error: e });
1359
+ }
1360
+ }
1361
+ function be() {
1362
+ try {
1363
+ let e = document.querySelector("script[src*=\"clarity.ms\"]");
1364
+ if (e) return e.getAttribute("src")?.match(/\/([a-z0-9]+)$/)?.[1];
1365
+ let t = Q()?.q?.[0]?.[1];
1366
+ if (typeof t == "string") return t;
1367
+ } catch {}
1368
+ }
1369
+ function xe(e, t, n) {
1370
+ let r = Y(n);
1371
+ try {
1372
+ X.track(e, t);
1373
+ } catch (t) {
1374
+ r("error", "Failed to track Amplitude event", {
1375
+ eventName: e,
1376
+ error: t
1377
+ });
1378
+ }
1379
+ }
1380
+ function Se(e, t, n) {
1381
+ let r = Y(n);
1382
+ try {
1383
+ let n = Q();
1384
+ n && (n("event", e), t && Object.entries(t).forEach(([e, t]) => {
1385
+ n("set", e, String(t));
1386
+ }));
1387
+ } catch (t) {
1388
+ r("error", "Failed to track Clarity event", {
1389
+ eventName: e,
1390
+ error: t
1391
+ });
1392
+ }
1393
+ }
1394
+ function Z(e, t, n, r) {
1395
+ return `${e}${[
1396
+ t,
1397
+ n,
1398
+ r
1399
+ ].filter(Boolean).join("_")}`;
1400
+ }
1401
+ function Ce(e) {
1402
+ return Object.fromEntries(Object.entries(e).filter((e) => e[1] !== void 0));
1403
+ }
1404
+ function we(e, t, n) {
1405
+ xe(e, t, n), Se(e, t, n);
1406
+ }
1407
+ function Q() {
1408
+ return window.clarity;
1409
+ }
1410
+ //#endregion
1411
+ //#region src/providers/LiveStateProvider.tsx
1412
+ var $ = t(null);
1413
+ function Te({ children: e, fetcher: t, analytics: n, onEvent: o, onLog: s, onNavigate: c, mockData: l, disabled: u = !1, refetchInterval: d = !1, queryClient: f }) {
1414
+ let p = i(() => Y(s), [s]);
1415
+ r(() => {
1416
+ u || (n?.amplitudeKey && ve(n.amplitudeKey, p), n?.clarityProjectId && ye(n.clarityProjectId, p));
1417
+ }, [
1418
+ n,
1419
+ u,
1420
+ p
1421
+ ]);
1422
+ let m = i(() => ({
1423
+ fetcher: t,
1424
+ analytics: n,
1425
+ onEvent: o,
1426
+ onNavigate: c,
1427
+ mockData: l,
1428
+ disabled: u,
1429
+ refetchInterval: d,
1430
+ log: p
1431
+ }), [
1432
+ t,
1433
+ n,
1434
+ o,
1435
+ c,
1436
+ l,
1437
+ u,
1438
+ d,
1439
+ p
1440
+ ]);
1441
+ return /* @__PURE__ */ a(q, {
1442
+ client: f ?? J,
1443
+ children: /* @__PURE__ */ a($.Provider, {
1444
+ value: m,
1445
+ children: e
1446
+ })
1447
+ });
1448
+ }
1449
+ function Ee() {
1450
+ let e = n($);
1451
+ if (!e) throw Error("useLiveState must be used within LiveStateProvider");
1452
+ return e;
1453
+ }
1454
+ //#endregion
1455
+ export { u as C, g as S, s as T, O as _, we as a, te as b, q as c, V as d, P as f, p as g, h, Ce as i, ge as l, j as m, Ee as n, Y as o, M as p, Z as r, J as s, Te as t, G as u, v, c as w, ae as x, _ as y };
1456
+
1457
+ //# sourceMappingURL=LiveStateProvider-BEiLZeen.js.map