@hortiview/modulebase 1.0.4 → 1.1.0-alpha.8ea7f643.1

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,157 +1,66 @@
1
- import { e as A, d as k, f as K, g as Q, R as T, r as E, a as P, i as M, j as N, k as G, t as j, c as H, C, n as _, l as x } from "./QueryClientProvider-Bak-4BVu.js";
2
- import * as w from "react";
3
- function B(t) {
4
- return {
5
- onFetch: (e, r) => {
6
- const a = e.options, u = e.fetchOptions?.meta?.fetchMore?.direction, f = e.state.data?.pages || [], n = e.state.data?.pageParams || [];
7
- let c = { pages: [], pageParams: [] }, s = 0;
8
- const h = async () => {
9
- let l = !1;
10
- const p = (i) => {
11
- Q(
12
- i,
13
- () => e.signal,
14
- () => l = !0
15
- );
16
- }, R = A(e.options, e.fetchOptions), v = async (i, o, d) => {
17
- if (l)
18
- return Promise.reject(e.signal.reason);
19
- if (o == null && i.pages.length)
20
- return Promise.resolve(i);
21
- const O = (() => {
22
- const b = {
23
- client: e.client,
24
- queryKey: e.queryKey,
25
- pageParam: o,
26
- direction: d ? "backward" : "forward",
27
- meta: e.options.meta
28
- };
29
- return p(b), b;
30
- })(), I = await R(O), { maxPages: m } = e.options, F = d ? k : K;
31
- return {
32
- pages: F(i.pages, I, m),
33
- pageParams: F(i.pageParams, o, m)
34
- };
35
- };
36
- if (u && f.length) {
37
- const i = u === "backward", o = i ? D : y, d = {
38
- pages: f,
39
- pageParams: n
40
- }, g = o(a, d);
41
- c = await v(d, g, i);
42
- } else {
43
- const i = t ?? f.length;
44
- do {
45
- const o = s === 0 ? n[0] ?? a.initialPageParam : y(a, c);
46
- if (s > 0 && o == null)
47
- break;
48
- c = await v(c, o), s++;
49
- } while (s < i);
50
- }
51
- return c;
52
- };
53
- e.options.persister ? e.fetchFn = () => e.options.persister?.(
54
- h,
55
- {
56
- client: e.client,
57
- queryKey: e.queryKey,
58
- meta: e.options.meta,
59
- signal: e.signal
60
- },
61
- r
62
- ) : e.fetchFn = h;
63
- }
64
- };
65
- }
66
- function y(t, { pages: e, pageParams: r }) {
67
- const a = e.length - 1;
68
- return e.length > 0 ? t.getNextPageParam(
69
- e[a],
70
- e,
71
- r[a],
72
- r
73
- ) : void 0;
74
- }
75
- function D(t, { pages: e, pageParams: r }) {
76
- return e.length > 0 ? t.getPreviousPageParam?.(e[0], e, r[0], r) : void 0;
77
- }
78
- function W(t, e) {
79
- return e ? y(t, e) != null : !1;
80
- }
81
- function z(t, e) {
82
- return !e || !t.getPreviousPageParam ? !1 : D(t, e) != null;
83
- }
84
- var J = class extends T {
1
+ import { R as v, r as m, a as c, d as b, e as C, f as S, t as F, c as g, C as d, n as q, g as A, i as D } from "./QueryClientProvider-DyiNrPkn.js";
2
+ import * as p from "react";
3
+ var w = class extends v {
4
+ #i;
85
5
  #n;
6
+ #e;
86
7
  #r;
8
+ #t;
87
9
  #o;
88
- #e;
89
10
  #a;
90
- #t;
91
- #u;
92
- #i;
93
11
  constructor(t) {
94
- super(), this.#i = !1, this.#u = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.#a = t.client, this.#e = this.#a.getQueryCache(), this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.#r = q(this.options), this.state = t.state ?? this.#r, this.scheduleGc();
12
+ super(), this.#a = !1, this.#o = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.#r = t.client, this.#e = this.#r.getQueryCache(), this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.#i = f(this.options), this.state = t.state ?? this.#i, this.scheduleGc();
95
13
  }
96
14
  get meta() {
97
15
  return this.options.meta;
98
16
  }
99
- get queryType() {
100
- return this.#n;
101
- }
102
17
  get promise() {
103
18
  return this.#t?.promise;
104
19
  }
105
20
  setOptions(t) {
106
- if (this.options = { ...this.#u, ...t }, t?._type && (this.#n = t._type), this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
107
- const e = q(this.options);
21
+ if (this.options = { ...this.#o, ...t }, this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
22
+ const e = f(this.options);
108
23
  e.data !== void 0 && (this.setState(
109
- S(e.data, e.dataUpdatedAt)
110
- ), this.#r = e);
24
+ l(e.data, e.dataUpdatedAt)
25
+ ), this.#i = e);
111
26
  }
112
27
  }
113
28
  optionalRemove() {
114
29
  !this.observers.length && this.state.fetchStatus === "idle" && this.#e.remove(this);
115
30
  }
116
31
  setData(t, e) {
117
- const r = E(this.state.data, t, this.options);
32
+ const i = m(this.state.data, t, this.options);
118
33
  return this.#s({
119
- data: r,
34
+ data: i,
120
35
  type: "success",
121
36
  dataUpdatedAt: e?.updatedAt,
122
37
  manual: e?.manual
123
- }), r;
38
+ }), i;
124
39
  }
125
- setState(t) {
126
- this.#s({ type: "setState", state: t });
40
+ setState(t, e) {
41
+ this.#s({ type: "setState", state: t, setStateOptions: e });
127
42
  }
128
43
  cancel(t) {
129
44
  const e = this.#t?.promise;
130
- return this.#t?.cancel(t), e ? e.then(P).catch(P) : Promise.resolve();
45
+ return this.#t?.cancel(t), e ? e.then(c).catch(c) : Promise.resolve();
131
46
  }
132
47
  destroy() {
133
48
  super.destroy(), this.cancel({ silent: !0 });
134
49
  }
135
- get resetState() {
136
- return this.#r;
137
- }
138
50
  reset() {
139
- this.destroy(), this.setState(this.resetState);
51
+ this.destroy(), this.setState(this.#i);
140
52
  }
141
53
  isActive() {
142
54
  return this.observers.some(
143
- (t) => M(t.options.enabled, this) !== !1
55
+ (t) => b(t.options.enabled, this) !== !1
144
56
  );
145
57
  }
146
58
  isDisabled() {
147
- return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === N || !this.isFetched();
148
- }
149
- isFetched() {
150
- return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
59
+ return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === C || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
151
60
  }
152
61
  isStatic() {
153
62
  return this.getObserversCount() > 0 ? this.observers.some(
154
- (t) => G(t.options.staleTime, this) === "static"
63
+ (t) => S(t.options.staleTime, this) === "static"
155
64
  ) : !1;
156
65
  }
157
66
  isStale() {
@@ -160,7 +69,7 @@ var J = class extends T {
160
69
  ) : this.state.data === void 0 || this.state.isInvalidated;
161
70
  }
162
71
  isStaleByTime(t = 0) {
163
- return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !j(this.state.dataUpdatedAt, t);
72
+ return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !F(this.state.dataUpdatedAt, t);
164
73
  }
165
74
  onFocus() {
166
75
  this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#t?.continue();
@@ -172,14 +81,11 @@ var J = class extends T {
172
81
  this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.#e.notify({ type: "observerAdded", query: this, observer: t }));
173
82
  }
174
83
  removeObserver(t) {
175
- this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#t && (this.#i || this.#h() ? this.#t.cancel({ revert: !0 }) : this.#t.cancelRetry()), this.scheduleGc()), this.#e.notify({ type: "observerRemoved", query: this, observer: t }));
84
+ this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#t && (this.#a ? this.#t.cancel({ revert: !0 }) : this.#t.cancelRetry()), this.scheduleGc()), this.#e.notify({ type: "observerRemoved", query: this, observer: t }));
176
85
  }
177
86
  getObserversCount() {
178
87
  return this.observers.length;
179
88
  }
180
- #h() {
181
- return this.state.fetchStatus === "paused" && this.state.status === "pending";
182
- }
183
89
  invalidate() {
184
90
  this.state.isInvalidated || this.#s({ type: "invalidate" });
185
91
  }
@@ -194,55 +100,53 @@ var J = class extends T {
194
100
  return this.#t.continueRetry(), this.#t.promise;
195
101
  }
196
102
  if (t && this.setOptions(t), !this.options.queryFn) {
197
- const s = this.observers.find((h) => h.options.queryFn);
103
+ const s = this.observers.find((o) => o.options.queryFn);
198
104
  s && this.setOptions(s.options);
199
105
  }
200
106
  process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
201
107
  "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']"
202
108
  ));
203
- const r = new AbortController(), a = (s) => {
109
+ const i = new AbortController(), r = (s) => {
204
110
  Object.defineProperty(s, "signal", {
205
111
  enumerable: !0,
206
- get: () => (this.#i = !0, r.signal)
112
+ get: () => (this.#a = !0, i.signal)
207
113
  });
208
- }, u = () => {
209
- const s = A(this.options, e), l = (() => {
210
- const p = {
211
- client: this.#a,
114
+ }, n = () => {
115
+ const s = A(this.options, e), h = (() => {
116
+ const u = {
117
+ client: this.#r,
212
118
  queryKey: this.queryKey,
213
119
  meta: this.meta
214
120
  };
215
- return a(p), p;
121
+ return r(u), u;
216
122
  })();
217
- return this.#i = !1, this.options.persister ? this.options.persister(
123
+ return this.#a = !1, this.options.persister ? this.options.persister(
218
124
  s,
219
- l,
125
+ h,
220
126
  this
221
- ) : s(l);
222
- }, n = (() => {
127
+ ) : s(h);
128
+ }, a = (() => {
223
129
  const s = {
224
130
  fetchOptions: e,
225
131
  options: this.options,
226
132
  queryKey: this.queryKey,
227
- client: this.#a,
133
+ client: this.#r,
228
134
  state: this.state,
229
- fetchFn: u
135
+ fetchFn: n
230
136
  };
231
- return a(s), s;
137
+ return r(s), s;
232
138
  })();
233
- (this.#n === "infinite" ? B(
234
- this.options.pages
235
- ) : this.options.behavior)?.onFetch(n, this), this.#o = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== n.fetchOptions?.meta) && this.#s({ type: "fetch", meta: n.fetchOptions?.meta }), this.#t = H({
139
+ this.options.behavior?.onFetch(a, this), this.#n = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== a.fetchOptions?.meta) && this.#s({ type: "fetch", meta: a.fetchOptions?.meta }), this.#t = g({
236
140
  initialPromise: e?.initialPromise,
237
- fn: n.fetchFn,
141
+ fn: a.fetchFn,
238
142
  onCancel: (s) => {
239
- s instanceof C && s.revert && this.setState({
240
- ...this.#o,
143
+ s instanceof d && s.revert && this.setState({
144
+ ...this.#n,
241
145
  fetchStatus: "idle"
242
- }), r.abort();
146
+ }), i.abort();
243
147
  },
244
- onFail: (s, h) => {
245
- this.#s({ type: "failed", failureCount: s, error: h });
148
+ onFail: (s, o) => {
149
+ this.#s({ type: "failed", failureCount: s, error: o });
246
150
  },
247
151
  onPause: () => {
248
152
  this.#s({ type: "pause" });
@@ -250,9 +154,9 @@ var J = class extends T {
250
154
  onContinue: () => {
251
155
  this.#s({ type: "continue" });
252
156
  },
253
- retry: n.options.retry,
254
- retryDelay: n.options.retryDelay,
255
- networkMode: n.options.networkMode,
157
+ retry: a.options.retry,
158
+ retryDelay: a.options.retryDelay,
159
+ networkMode: a.options.networkMode,
256
160
  canRun: () => !0
257
161
  });
258
162
  try {
@@ -267,7 +171,7 @@ var J = class extends T {
267
171
  this
268
172
  ), s;
269
173
  } catch (s) {
270
- if (s instanceof C) {
174
+ if (s instanceof d) {
271
175
  if (s.silent)
272
176
  return this.#t.promise;
273
177
  if (s.revert) {
@@ -292,51 +196,51 @@ var J = class extends T {
292
196
  }
293
197
  }
294
198
  #s(t) {
295
- const e = (r) => {
199
+ const e = (i) => {
296
200
  switch (t.type) {
297
201
  case "failed":
298
202
  return {
299
- ...r,
203
+ ...i,
300
204
  fetchFailureCount: t.failureCount,
301
205
  fetchFailureReason: t.error
302
206
  };
303
207
  case "pause":
304
208
  return {
305
- ...r,
209
+ ...i,
306
210
  fetchStatus: "paused"
307
211
  };
308
212
  case "continue":
309
213
  return {
310
- ...r,
214
+ ...i,
311
215
  fetchStatus: "fetching"
312
216
  };
313
217
  case "fetch":
314
218
  return {
315
- ...r,
316
- ...V(r.data, this.options),
219
+ ...i,
220
+ ...U(i.data, this.options),
317
221
  fetchMeta: t.meta ?? null
318
222
  };
319
223
  case "success":
320
- const a = {
321
- ...r,
322
- ...S(t.data, t.dataUpdatedAt),
323
- dataUpdateCount: r.dataUpdateCount + 1,
224
+ const r = {
225
+ ...i,
226
+ ...l(t.data, t.dataUpdatedAt),
227
+ dataUpdateCount: i.dataUpdateCount + 1,
324
228
  ...!t.manual && {
325
229
  fetchStatus: "idle",
326
230
  fetchFailureCount: 0,
327
231
  fetchFailureReason: null
328
232
  }
329
233
  };
330
- return this.#o = t.manual ? a : void 0, a;
234
+ return this.#n = t.manual ? r : void 0, r;
331
235
  case "error":
332
- const u = t.error;
236
+ const n = t.error;
333
237
  return {
334
- ...r,
335
- error: u,
336
- errorUpdateCount: r.errorUpdateCount + 1,
238
+ ...i,
239
+ error: n,
240
+ errorUpdateCount: i.errorUpdateCount + 1,
337
241
  errorUpdatedAt: Date.now(),
338
- fetchFailureCount: r.fetchFailureCount + 1,
339
- fetchFailureReason: u,
242
+ fetchFailureCount: i.fetchFailureCount + 1,
243
+ fetchFailureReason: n,
340
244
  fetchStatus: "idle",
341
245
  status: "error",
342
246
  // flag existing data as invalidated if we get a background error
@@ -345,35 +249,35 @@ var J = class extends T {
345
249
  };
346
250
  case "invalidate":
347
251
  return {
348
- ...r,
252
+ ...i,
349
253
  isInvalidated: !0
350
254
  };
351
255
  case "setState":
352
256
  return {
353
- ...r,
257
+ ...i,
354
258
  ...t.state
355
259
  };
356
260
  }
357
261
  };
358
- this.state = e(this.state), _.batch(() => {
359
- this.observers.forEach((r) => {
360
- r.onQueryUpdate();
262
+ this.state = e(this.state), q.batch(() => {
263
+ this.observers.forEach((i) => {
264
+ i.onQueryUpdate();
361
265
  }), this.#e.notify({ query: this, type: "updated", action: t });
362
266
  });
363
267
  }
364
268
  };
365
- function V(t, e) {
269
+ function U(t, e) {
366
270
  return {
367
271
  fetchFailureCount: 0,
368
272
  fetchFailureReason: null,
369
- fetchStatus: x(e.networkMode) ? "fetching" : "paused",
273
+ fetchStatus: D(e.networkMode) ? "fetching" : "paused",
370
274
  ...t === void 0 && {
371
275
  error: null,
372
276
  status: "pending"
373
277
  }
374
278
  };
375
279
  }
376
- function S(t, e) {
280
+ function l(t, e) {
377
281
  return {
378
282
  data: t,
379
283
  dataUpdatedAt: e ?? Date.now(),
@@ -382,12 +286,12 @@ function S(t, e) {
382
286
  status: "success"
383
287
  };
384
288
  }
385
- function q(t) {
386
- const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, r = e !== void 0, a = r ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
289
+ function f(t) {
290
+ const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, i = e !== void 0, r = i ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
387
291
  return {
388
292
  data: e,
389
293
  dataUpdateCount: 0,
390
- dataUpdatedAt: r ? a ?? Date.now() : 0,
294
+ dataUpdatedAt: i ? r ?? Date.now() : 0,
391
295
  error: null,
392
296
  errorUpdateCount: 0,
393
297
  errorUpdatedAt: 0,
@@ -395,16 +299,14 @@ function q(t) {
395
299
  fetchFailureReason: null,
396
300
  fetchMeta: null,
397
301
  isInvalidated: !1,
398
- status: r ? "success" : "pending",
302
+ status: i ? "success" : "pending",
399
303
  fetchStatus: "idle"
400
304
  };
401
305
  }
402
- var U = w.createContext(!1), L = () => w.useContext(U), X = U.Provider;
306
+ var y = p.createContext(!1), x = () => p.useContext(y), I = y.Provider;
403
307
  export {
404
- X as I,
405
- J as Q,
406
- W as a,
407
- V as f,
408
- z as h,
409
- L as u
308
+ I,
309
+ w as Q,
310
+ U as f,
311
+ x as u
410
312
  };