@gaddario98/react-core 2.0.8 → 2.1.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.
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +2 -2
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +1 -1
- package/dist/auth/index.mjs.map +1 -1
- package/dist/form/index.js +52 -3930
- package/dist/form/index.js.map +1 -1
- package/dist/form/index.mjs +2 -3880
- package/dist/form/index.mjs.map +1 -1
- package/dist/index.d.ts +627 -97
- package/dist/index.js +14 -20037
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -20031
- package/dist/index.mjs.map +1 -1
- package/dist/notifications/index.d.ts +2 -2
- package/dist/notifications/index.js +3 -3
- package/dist/notifications/index.js.map +1 -1
- package/dist/notifications/index.mjs +2 -2
- package/dist/notifications/index.mjs.map +1 -1
- package/dist/pages/index.d.ts +3 -3
- package/dist/pages/index.js +58 -1789
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/index.mjs +13 -1744
- package/dist/pages/index.mjs.map +1 -1
- package/dist/queries/index.js +235 -7463
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +228 -7456
- package/dist/queries/index.mjs.map +1 -1
- package/dist/state/index.js +10 -1783
- package/dist/state/index.js.map +1 -1
- package/dist/state/index.mjs +2 -1775
- package/dist/state/index.mjs.map +1 -1
- package/package.json +8 -6
package/dist/pages/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jsx,jsxs}from'react/jsx-runtime';import
|
|
1
|
+
import {jsx,jsxs}from'react/jsx-runtime';import {useRef,useState,useEffect,useCallback,memo,useMemo,createContext,useContext}from'react';import {useApiValues,useApiConfigValue,useApi,queriesAtom}from'@gaddario98/react-queries';import {atom,useAtom,useStore}from'jotai';import {c}from'react/compiler-runtime';import {atomStateGenerator}from'@gaddario98/react-state';import equal from'fast-deep-equal';import {useFormValues,useFormManager}from'@gaddario98/react-form';import {atomFamily}from'jotai-family';import {QueryObserver}from'@tanstack/react-query';/******************************************************************************
|
|
2
2
|
Copyright (c) Microsoft Corporation.
|
|
3
3
|
|
|
4
4
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -25,839 +25,7 @@ function __rest(s, e) {
|
|
|
25
25
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
26
26
|
var e = new Error(message);
|
|
27
27
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
28
|
-
}
|
|
29
|
-
return "init" in atom;
|
|
30
|
-
}
|
|
31
|
-
function isActuallyWritableAtom(atom) {
|
|
32
|
-
return !!atom.write;
|
|
33
|
-
}
|
|
34
|
-
function isAtomStateInitialized(atomState) {
|
|
35
|
-
return "v" in atomState || "e" in atomState;
|
|
36
|
-
}
|
|
37
|
-
function returnAtomValue(atomState) {
|
|
38
|
-
if ("e" in atomState) {
|
|
39
|
-
throw atomState.e;
|
|
40
|
-
}
|
|
41
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !("v" in atomState)) {
|
|
42
|
-
throw new Error("[Bug] atom state is not initialized");
|
|
43
|
-
}
|
|
44
|
-
return atomState.v;
|
|
45
|
-
}
|
|
46
|
-
const promiseStateMap = /* @__PURE__ */ new WeakMap();
|
|
47
|
-
function isPendingPromise(value) {
|
|
48
|
-
var _a;
|
|
49
|
-
return isPromiseLike$1(value) && !!((_a = promiseStateMap.get(value)) == null ? void 0 : _a[0]);
|
|
50
|
-
}
|
|
51
|
-
function abortPromise(promise) {
|
|
52
|
-
const promiseState = promiseStateMap.get(promise);
|
|
53
|
-
if (promiseState == null ? void 0 : promiseState[0]) {
|
|
54
|
-
promiseState[0] = false;
|
|
55
|
-
promiseState[1].forEach((fn) => fn());
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function registerAbortHandler(promise, abortHandler) {
|
|
59
|
-
let promiseState = promiseStateMap.get(promise);
|
|
60
|
-
if (!promiseState) {
|
|
61
|
-
promiseState = [true, /* @__PURE__ */ new Set()];
|
|
62
|
-
promiseStateMap.set(promise, promiseState);
|
|
63
|
-
const settle = () => {
|
|
64
|
-
promiseState[0] = false;
|
|
65
|
-
};
|
|
66
|
-
promise.then(settle, settle);
|
|
67
|
-
}
|
|
68
|
-
promiseState[1].add(abortHandler);
|
|
69
|
-
}
|
|
70
|
-
function isPromiseLike$1(p) {
|
|
71
|
-
return typeof (p == null ? void 0 : p.then) === "function";
|
|
72
|
-
}
|
|
73
|
-
function addPendingPromiseToDependency(atom, promise, dependencyAtomState) {
|
|
74
|
-
if (!dependencyAtomState.p.has(atom)) {
|
|
75
|
-
dependencyAtomState.p.add(atom);
|
|
76
|
-
const cleanup = () => dependencyAtomState.p.delete(atom);
|
|
77
|
-
promise.then(cleanup, cleanup);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function getMountedOrPendingDependents(atom, atomState, mountedMap) {
|
|
81
|
-
var _a;
|
|
82
|
-
const dependents = /* @__PURE__ */ new Set();
|
|
83
|
-
for (const a of ((_a = mountedMap.get(atom)) == null ? void 0 : _a.t) || []) {
|
|
84
|
-
dependents.add(a);
|
|
85
|
-
}
|
|
86
|
-
for (const atomWithPendingPromise of atomState.p) {
|
|
87
|
-
dependents.add(atomWithPendingPromise);
|
|
88
|
-
}
|
|
89
|
-
return dependents;
|
|
90
|
-
}
|
|
91
|
-
const BUILDING_BLOCK_atomRead = (_store, atom, ...params) => atom.read(...params);
|
|
92
|
-
const BUILDING_BLOCK_atomWrite = (_store, atom, ...params) => atom.write(...params);
|
|
93
|
-
const BUILDING_BLOCK_atomOnInit = (store, atom) => {
|
|
94
|
-
var _a;
|
|
95
|
-
return (_a = atom.INTERNAL_onInit) == null ? void 0 : _a.call(atom, store);
|
|
96
|
-
};
|
|
97
|
-
const BUILDING_BLOCK_atomOnMount = (_store, atom, setAtom) => {
|
|
98
|
-
var _a;
|
|
99
|
-
return (_a = atom.onMount) == null ? void 0 : _a.call(atom, setAtom);
|
|
100
|
-
};
|
|
101
|
-
const BUILDING_BLOCK_ensureAtomState = (store, atom) => {
|
|
102
|
-
var _a;
|
|
103
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
104
|
-
const atomStateMap = buildingBlocks[0];
|
|
105
|
-
const storeHooks = buildingBlocks[6];
|
|
106
|
-
const atomOnInit = buildingBlocks[9];
|
|
107
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !atom) {
|
|
108
|
-
throw new Error("Atom is undefined or null");
|
|
109
|
-
}
|
|
110
|
-
let atomState = atomStateMap.get(atom);
|
|
111
|
-
if (!atomState) {
|
|
112
|
-
atomState = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 };
|
|
113
|
-
atomStateMap.set(atom, atomState);
|
|
114
|
-
(_a = storeHooks.i) == null ? void 0 : _a.call(storeHooks, atom);
|
|
115
|
-
atomOnInit == null ? void 0 : atomOnInit(store, atom);
|
|
116
|
-
}
|
|
117
|
-
return atomState;
|
|
118
|
-
};
|
|
119
|
-
const BUILDING_BLOCK_flushCallbacks = (store) => {
|
|
120
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
121
|
-
const mountedMap = buildingBlocks[1];
|
|
122
|
-
const changedAtoms = buildingBlocks[3];
|
|
123
|
-
const mountCallbacks = buildingBlocks[4];
|
|
124
|
-
const unmountCallbacks = buildingBlocks[5];
|
|
125
|
-
const storeHooks = buildingBlocks[6];
|
|
126
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
127
|
-
const errors = [];
|
|
128
|
-
const call = (fn) => {
|
|
129
|
-
try {
|
|
130
|
-
fn();
|
|
131
|
-
} catch (e) {
|
|
132
|
-
errors.push(e);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
do {
|
|
136
|
-
if (storeHooks.f) {
|
|
137
|
-
call(storeHooks.f);
|
|
138
|
-
}
|
|
139
|
-
const callbacks = /* @__PURE__ */ new Set();
|
|
140
|
-
const add = callbacks.add.bind(callbacks);
|
|
141
|
-
changedAtoms.forEach((atom) => {
|
|
142
|
-
var _a;
|
|
143
|
-
return (_a = mountedMap.get(atom)) == null ? void 0 : _a.l.forEach(add);
|
|
144
|
-
});
|
|
145
|
-
changedAtoms.clear();
|
|
146
|
-
unmountCallbacks.forEach(add);
|
|
147
|
-
unmountCallbacks.clear();
|
|
148
|
-
mountCallbacks.forEach(add);
|
|
149
|
-
mountCallbacks.clear();
|
|
150
|
-
callbacks.forEach(call);
|
|
151
|
-
if (changedAtoms.size) {
|
|
152
|
-
recomputeInvalidatedAtoms(store);
|
|
153
|
-
}
|
|
154
|
-
} while (changedAtoms.size || unmountCallbacks.size || mountCallbacks.size);
|
|
155
|
-
if (errors.length) {
|
|
156
|
-
throw new AggregateError(errors);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const BUILDING_BLOCK_recomputeInvalidatedAtoms = (store) => {
|
|
160
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
161
|
-
const mountedMap = buildingBlocks[1];
|
|
162
|
-
const invalidatedAtoms = buildingBlocks[2];
|
|
163
|
-
const changedAtoms = buildingBlocks[3];
|
|
164
|
-
const ensureAtomState = buildingBlocks[11];
|
|
165
|
-
const readAtomState = buildingBlocks[14];
|
|
166
|
-
const mountDependencies = buildingBlocks[17];
|
|
167
|
-
const topSortedReversed = [];
|
|
168
|
-
const visiting = /* @__PURE__ */ new WeakSet();
|
|
169
|
-
const visited = /* @__PURE__ */ new WeakSet();
|
|
170
|
-
const stack = Array.from(changedAtoms);
|
|
171
|
-
while (stack.length) {
|
|
172
|
-
const a = stack[stack.length - 1];
|
|
173
|
-
const aState = ensureAtomState(store, a);
|
|
174
|
-
if (visited.has(a)) {
|
|
175
|
-
stack.pop();
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
if (visiting.has(a)) {
|
|
179
|
-
if (invalidatedAtoms.get(a) === aState.n) {
|
|
180
|
-
topSortedReversed.push([a, aState]);
|
|
181
|
-
} else if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && invalidatedAtoms.has(a)) {
|
|
182
|
-
throw new Error("[Bug] invalidated atom exists");
|
|
183
|
-
}
|
|
184
|
-
visited.add(a);
|
|
185
|
-
stack.pop();
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
visiting.add(a);
|
|
189
|
-
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
190
|
-
if (!visiting.has(d)) {
|
|
191
|
-
stack.push(d);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
for (let i = topSortedReversed.length - 1; i >= 0; --i) {
|
|
196
|
-
const [a, aState] = topSortedReversed[i];
|
|
197
|
-
let hasChangedDeps = false;
|
|
198
|
-
for (const dep of aState.d.keys()) {
|
|
199
|
-
if (dep !== a && changedAtoms.has(dep)) {
|
|
200
|
-
hasChangedDeps = true;
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (hasChangedDeps) {
|
|
205
|
-
readAtomState(store, a);
|
|
206
|
-
mountDependencies(store, a);
|
|
207
|
-
}
|
|
208
|
-
invalidatedAtoms.delete(a);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
const storeMutationSet = /* @__PURE__ */ new WeakSet();
|
|
212
|
-
const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
213
|
-
var _a, _b;
|
|
214
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
215
|
-
const mountedMap = buildingBlocks[1];
|
|
216
|
-
const invalidatedAtoms = buildingBlocks[2];
|
|
217
|
-
const changedAtoms = buildingBlocks[3];
|
|
218
|
-
const storeHooks = buildingBlocks[6];
|
|
219
|
-
const atomRead = buildingBlocks[7];
|
|
220
|
-
const ensureAtomState = buildingBlocks[11];
|
|
221
|
-
const flushCallbacks = buildingBlocks[12];
|
|
222
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
223
|
-
const readAtomState = buildingBlocks[14];
|
|
224
|
-
const writeAtomState = buildingBlocks[16];
|
|
225
|
-
const mountDependencies = buildingBlocks[17];
|
|
226
|
-
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
227
|
-
const atomState = ensureAtomState(store, atom);
|
|
228
|
-
if (isAtomStateInitialized(atomState)) {
|
|
229
|
-
if (mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n) {
|
|
230
|
-
return atomState;
|
|
231
|
-
}
|
|
232
|
-
let hasChangedDeps = false;
|
|
233
|
-
for (const [a, n] of atomState.d) {
|
|
234
|
-
if (readAtomState(store, a).n !== n) {
|
|
235
|
-
hasChangedDeps = true;
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (!hasChangedDeps) {
|
|
240
|
-
return atomState;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
atomState.d.clear();
|
|
244
|
-
let isSync = true;
|
|
245
|
-
function mountDependenciesIfAsync() {
|
|
246
|
-
if (mountedMap.has(atom)) {
|
|
247
|
-
mountDependencies(store, atom);
|
|
248
|
-
recomputeInvalidatedAtoms(store);
|
|
249
|
-
flushCallbacks(store);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
function getter(a) {
|
|
253
|
-
var _a2;
|
|
254
|
-
if (a === atom) {
|
|
255
|
-
const aState2 = ensureAtomState(store, a);
|
|
256
|
-
if (!isAtomStateInitialized(aState2)) {
|
|
257
|
-
if (hasInitialValue(a)) {
|
|
258
|
-
setAtomStateValueOrPromise(store, a, a.init);
|
|
259
|
-
} else {
|
|
260
|
-
throw new Error("no atom init");
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return returnAtomValue(aState2);
|
|
264
|
-
}
|
|
265
|
-
const aState = readAtomState(store, a);
|
|
266
|
-
try {
|
|
267
|
-
return returnAtomValue(aState);
|
|
268
|
-
} finally {
|
|
269
|
-
atomState.d.set(a, aState.n);
|
|
270
|
-
if (isPendingPromise(atomState.v)) {
|
|
271
|
-
addPendingPromiseToDependency(atom, atomState.v, aState);
|
|
272
|
-
}
|
|
273
|
-
if (mountedMap.has(atom)) {
|
|
274
|
-
(_a2 = mountedMap.get(a)) == null ? void 0 : _a2.t.add(atom);
|
|
275
|
-
}
|
|
276
|
-
if (!isSync) {
|
|
277
|
-
mountDependenciesIfAsync();
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
let controller;
|
|
282
|
-
let setSelf;
|
|
283
|
-
const options = {
|
|
284
|
-
get signal() {
|
|
285
|
-
if (!controller) {
|
|
286
|
-
controller = new AbortController();
|
|
287
|
-
}
|
|
288
|
-
return controller.signal;
|
|
289
|
-
},
|
|
290
|
-
get setSelf() {
|
|
291
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
|
|
292
|
-
console.warn(
|
|
293
|
-
"[DEPRECATED] setSelf is deprecated and will be removed in v3."
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !isActuallyWritableAtom(atom)) {
|
|
297
|
-
console.warn("setSelf function cannot be used with read-only atom");
|
|
298
|
-
}
|
|
299
|
-
if (!setSelf && isActuallyWritableAtom(atom)) {
|
|
300
|
-
setSelf = (...args) => {
|
|
301
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && isSync) {
|
|
302
|
-
console.warn("setSelf function cannot be called in sync");
|
|
303
|
-
}
|
|
304
|
-
if (!isSync) {
|
|
305
|
-
try {
|
|
306
|
-
return writeAtomState(store, atom, ...args);
|
|
307
|
-
} finally {
|
|
308
|
-
recomputeInvalidatedAtoms(store);
|
|
309
|
-
flushCallbacks(store);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
return setSelf;
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
const prevEpochNumber = atomState.n;
|
|
318
|
-
try {
|
|
319
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
|
|
320
|
-
storeMutationSet.delete(store);
|
|
321
|
-
}
|
|
322
|
-
const valueOrPromise = atomRead(store, atom, getter, options);
|
|
323
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && storeMutationSet.has(store)) {
|
|
324
|
-
console.warn(
|
|
325
|
-
"Detected store mutation during atom read. This is not supported."
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
setAtomStateValueOrPromise(store, atom, valueOrPromise);
|
|
329
|
-
if (isPromiseLike$1(valueOrPromise)) {
|
|
330
|
-
registerAbortHandler(valueOrPromise, () => controller == null ? void 0 : controller.abort());
|
|
331
|
-
valueOrPromise.then(mountDependenciesIfAsync, mountDependenciesIfAsync);
|
|
332
|
-
}
|
|
333
|
-
(_a = storeHooks.r) == null ? void 0 : _a.call(storeHooks, atom);
|
|
334
|
-
return atomState;
|
|
335
|
-
} catch (error) {
|
|
336
|
-
delete atomState.v;
|
|
337
|
-
atomState.e = error;
|
|
338
|
-
++atomState.n;
|
|
339
|
-
return atomState;
|
|
340
|
-
} finally {
|
|
341
|
-
isSync = false;
|
|
342
|
-
if (prevEpochNumber !== atomState.n && invalidatedAtoms.get(atom) === prevEpochNumber) {
|
|
343
|
-
invalidatedAtoms.set(atom, atomState.n);
|
|
344
|
-
changedAtoms.add(atom);
|
|
345
|
-
(_b = storeHooks.c) == null ? void 0 : _b.call(storeHooks, atom);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
const BUILDING_BLOCK_invalidateDependents = (store, atom) => {
|
|
350
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
351
|
-
const mountedMap = buildingBlocks[1];
|
|
352
|
-
const invalidatedAtoms = buildingBlocks[2];
|
|
353
|
-
const ensureAtomState = buildingBlocks[11];
|
|
354
|
-
const stack = [atom];
|
|
355
|
-
while (stack.length) {
|
|
356
|
-
const a = stack.pop();
|
|
357
|
-
const aState = ensureAtomState(store, a);
|
|
358
|
-
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
359
|
-
const dState = ensureAtomState(store, d);
|
|
360
|
-
invalidatedAtoms.set(d, dState.n);
|
|
361
|
-
stack.push(d);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
const BUILDING_BLOCK_writeAtomState = (store, atom, ...args) => {
|
|
366
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
367
|
-
const changedAtoms = buildingBlocks[3];
|
|
368
|
-
const storeHooks = buildingBlocks[6];
|
|
369
|
-
const atomWrite = buildingBlocks[8];
|
|
370
|
-
const ensureAtomState = buildingBlocks[11];
|
|
371
|
-
const flushCallbacks = buildingBlocks[12];
|
|
372
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
373
|
-
const readAtomState = buildingBlocks[14];
|
|
374
|
-
const invalidateDependents = buildingBlocks[15];
|
|
375
|
-
const writeAtomState = buildingBlocks[16];
|
|
376
|
-
const mountDependencies = buildingBlocks[17];
|
|
377
|
-
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
378
|
-
let isSync = true;
|
|
379
|
-
const getter = (a) => returnAtomValue(readAtomState(store, a));
|
|
380
|
-
const setter = (a, ...args2) => {
|
|
381
|
-
var _a;
|
|
382
|
-
const aState = ensureAtomState(store, a);
|
|
383
|
-
try {
|
|
384
|
-
if (a === atom) {
|
|
385
|
-
if (!hasInitialValue(a)) {
|
|
386
|
-
throw new Error("atom not writable");
|
|
387
|
-
}
|
|
388
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
|
|
389
|
-
storeMutationSet.add(store);
|
|
390
|
-
}
|
|
391
|
-
const prevEpochNumber = aState.n;
|
|
392
|
-
const v = args2[0];
|
|
393
|
-
setAtomStateValueOrPromise(store, a, v);
|
|
394
|
-
mountDependencies(store, a);
|
|
395
|
-
if (prevEpochNumber !== aState.n) {
|
|
396
|
-
changedAtoms.add(a);
|
|
397
|
-
invalidateDependents(store, a);
|
|
398
|
-
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
399
|
-
}
|
|
400
|
-
return void 0;
|
|
401
|
-
} else {
|
|
402
|
-
return writeAtomState(store, a, ...args2);
|
|
403
|
-
}
|
|
404
|
-
} finally {
|
|
405
|
-
if (!isSync) {
|
|
406
|
-
recomputeInvalidatedAtoms(store);
|
|
407
|
-
flushCallbacks(store);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
try {
|
|
412
|
-
return atomWrite(store, atom, getter, setter, ...args);
|
|
413
|
-
} finally {
|
|
414
|
-
isSync = false;
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
const BUILDING_BLOCK_mountDependencies = (store, atom) => {
|
|
418
|
-
var _a;
|
|
419
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
420
|
-
const mountedMap = buildingBlocks[1];
|
|
421
|
-
const changedAtoms = buildingBlocks[3];
|
|
422
|
-
const storeHooks = buildingBlocks[6];
|
|
423
|
-
const ensureAtomState = buildingBlocks[11];
|
|
424
|
-
const invalidateDependents = buildingBlocks[15];
|
|
425
|
-
const mountAtom = buildingBlocks[18];
|
|
426
|
-
const unmountAtom = buildingBlocks[19];
|
|
427
|
-
const atomState = ensureAtomState(store, atom);
|
|
428
|
-
const mounted = mountedMap.get(atom);
|
|
429
|
-
if (mounted && !isPendingPromise(atomState.v)) {
|
|
430
|
-
for (const [a, n] of atomState.d) {
|
|
431
|
-
if (!mounted.d.has(a)) {
|
|
432
|
-
const aState = ensureAtomState(store, a);
|
|
433
|
-
const aMounted = mountAtom(store, a);
|
|
434
|
-
aMounted.t.add(atom);
|
|
435
|
-
mounted.d.add(a);
|
|
436
|
-
if (n !== aState.n) {
|
|
437
|
-
changedAtoms.add(a);
|
|
438
|
-
invalidateDependents(store, a);
|
|
439
|
-
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
for (const a of mounted.d) {
|
|
444
|
-
if (!atomState.d.has(a)) {
|
|
445
|
-
mounted.d.delete(a);
|
|
446
|
-
const aMounted = unmountAtom(store, a);
|
|
447
|
-
aMounted == null ? void 0 : aMounted.t.delete(atom);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
const BUILDING_BLOCK_mountAtom = (store, atom) => {
|
|
453
|
-
var _a;
|
|
454
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
455
|
-
const mountedMap = buildingBlocks[1];
|
|
456
|
-
const mountCallbacks = buildingBlocks[4];
|
|
457
|
-
const storeHooks = buildingBlocks[6];
|
|
458
|
-
const atomOnMount = buildingBlocks[10];
|
|
459
|
-
const ensureAtomState = buildingBlocks[11];
|
|
460
|
-
const flushCallbacks = buildingBlocks[12];
|
|
461
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
462
|
-
const readAtomState = buildingBlocks[14];
|
|
463
|
-
const writeAtomState = buildingBlocks[16];
|
|
464
|
-
const mountAtom = buildingBlocks[18];
|
|
465
|
-
const atomState = ensureAtomState(store, atom);
|
|
466
|
-
let mounted = mountedMap.get(atom);
|
|
467
|
-
if (!mounted) {
|
|
468
|
-
readAtomState(store, atom);
|
|
469
|
-
for (const a of atomState.d.keys()) {
|
|
470
|
-
const aMounted = mountAtom(store, a);
|
|
471
|
-
aMounted.t.add(atom);
|
|
472
|
-
}
|
|
473
|
-
mounted = {
|
|
474
|
-
l: /* @__PURE__ */ new Set(),
|
|
475
|
-
d: new Set(atomState.d.keys()),
|
|
476
|
-
t: /* @__PURE__ */ new Set()
|
|
477
|
-
};
|
|
478
|
-
mountedMap.set(atom, mounted);
|
|
479
|
-
if (isActuallyWritableAtom(atom)) {
|
|
480
|
-
const processOnMount = () => {
|
|
481
|
-
let isSync = true;
|
|
482
|
-
const setAtom = (...args) => {
|
|
483
|
-
try {
|
|
484
|
-
return writeAtomState(store, atom, ...args);
|
|
485
|
-
} finally {
|
|
486
|
-
if (!isSync) {
|
|
487
|
-
recomputeInvalidatedAtoms(store);
|
|
488
|
-
flushCallbacks(store);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
try {
|
|
493
|
-
const onUnmount = atomOnMount(store, atom, setAtom);
|
|
494
|
-
if (onUnmount) {
|
|
495
|
-
mounted.u = () => {
|
|
496
|
-
isSync = true;
|
|
497
|
-
try {
|
|
498
|
-
onUnmount();
|
|
499
|
-
} finally {
|
|
500
|
-
isSync = false;
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
} finally {
|
|
505
|
-
isSync = false;
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
mountCallbacks.add(processOnMount);
|
|
509
|
-
}
|
|
510
|
-
(_a = storeHooks.m) == null ? void 0 : _a.call(storeHooks, atom);
|
|
511
|
-
}
|
|
512
|
-
return mounted;
|
|
513
|
-
};
|
|
514
|
-
const BUILDING_BLOCK_unmountAtom = (store, atom) => {
|
|
515
|
-
var _a, _b;
|
|
516
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
517
|
-
const mountedMap = buildingBlocks[1];
|
|
518
|
-
const unmountCallbacks = buildingBlocks[5];
|
|
519
|
-
const storeHooks = buildingBlocks[6];
|
|
520
|
-
const ensureAtomState = buildingBlocks[11];
|
|
521
|
-
const unmountAtom = buildingBlocks[19];
|
|
522
|
-
const atomState = ensureAtomState(store, atom);
|
|
523
|
-
let mounted = mountedMap.get(atom);
|
|
524
|
-
if (!mounted || mounted.l.size) {
|
|
525
|
-
return mounted;
|
|
526
|
-
}
|
|
527
|
-
let isDependent = false;
|
|
528
|
-
for (const a of mounted.t) {
|
|
529
|
-
if ((_a = mountedMap.get(a)) == null ? void 0 : _a.d.has(atom)) {
|
|
530
|
-
isDependent = true;
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
if (!isDependent) {
|
|
535
|
-
if (mounted.u) {
|
|
536
|
-
unmountCallbacks.add(mounted.u);
|
|
537
|
-
}
|
|
538
|
-
mounted = void 0;
|
|
539
|
-
mountedMap.delete(atom);
|
|
540
|
-
for (const a of atomState.d.keys()) {
|
|
541
|
-
const aMounted = unmountAtom(store, a);
|
|
542
|
-
aMounted == null ? void 0 : aMounted.t.delete(atom);
|
|
543
|
-
}
|
|
544
|
-
(_b = storeHooks.u) == null ? void 0 : _b.call(storeHooks, atom);
|
|
545
|
-
return void 0;
|
|
546
|
-
}
|
|
547
|
-
return mounted;
|
|
548
|
-
};
|
|
549
|
-
const BUILDING_BLOCK_setAtomStateValueOrPromise = (store, atom, valueOrPromise) => {
|
|
550
|
-
const ensureAtomState = getInternalBuildingBlocks(store)[11];
|
|
551
|
-
const atomState = ensureAtomState(store, atom);
|
|
552
|
-
const hasPrevValue = "v" in atomState;
|
|
553
|
-
const prevValue = atomState.v;
|
|
554
|
-
if (isPromiseLike$1(valueOrPromise)) {
|
|
555
|
-
for (const a of atomState.d.keys()) {
|
|
556
|
-
addPendingPromiseToDependency(
|
|
557
|
-
atom,
|
|
558
|
-
valueOrPromise,
|
|
559
|
-
ensureAtomState(store, a)
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
atomState.v = valueOrPromise;
|
|
564
|
-
delete atomState.e;
|
|
565
|
-
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) {
|
|
566
|
-
++atomState.n;
|
|
567
|
-
if (isPromiseLike$1(prevValue)) {
|
|
568
|
-
abortPromise(prevValue);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
const BUILDING_BLOCK_storeGet = (store, atom) => {
|
|
573
|
-
const readAtomState = getInternalBuildingBlocks(store)[14];
|
|
574
|
-
return returnAtomValue(readAtomState(store, atom));
|
|
575
|
-
};
|
|
576
|
-
const BUILDING_BLOCK_storeSet = (store, atom, ...args) => {
|
|
577
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
578
|
-
const flushCallbacks = buildingBlocks[12];
|
|
579
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
580
|
-
const writeAtomState = buildingBlocks[16];
|
|
581
|
-
try {
|
|
582
|
-
return writeAtomState(store, atom, ...args);
|
|
583
|
-
} finally {
|
|
584
|
-
recomputeInvalidatedAtoms(store);
|
|
585
|
-
flushCallbacks(store);
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
const BUILDING_BLOCK_storeSub = (store, atom, listener) => {
|
|
589
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
590
|
-
const flushCallbacks = buildingBlocks[12];
|
|
591
|
-
const mountAtom = buildingBlocks[18];
|
|
592
|
-
const unmountAtom = buildingBlocks[19];
|
|
593
|
-
const mounted = mountAtom(store, atom);
|
|
594
|
-
const listeners = mounted.l;
|
|
595
|
-
listeners.add(listener);
|
|
596
|
-
flushCallbacks(store);
|
|
597
|
-
return () => {
|
|
598
|
-
listeners.delete(listener);
|
|
599
|
-
unmountAtom(store, atom);
|
|
600
|
-
flushCallbacks(store);
|
|
601
|
-
};
|
|
602
|
-
};
|
|
603
|
-
const buildingBlockMap = /* @__PURE__ */ new WeakMap();
|
|
604
|
-
const getInternalBuildingBlocks = (store) => {
|
|
605
|
-
const buildingBlocks = buildingBlockMap.get(store);
|
|
606
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !buildingBlocks) {
|
|
607
|
-
throw new Error(
|
|
608
|
-
"Store must be created by buildStore to read its building blocks"
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
return buildingBlocks;
|
|
612
|
-
};
|
|
613
|
-
function buildStore(...buildArgs) {
|
|
614
|
-
const store = {
|
|
615
|
-
get(atom) {
|
|
616
|
-
const storeGet = getInternalBuildingBlocks(store)[21];
|
|
617
|
-
return storeGet(store, atom);
|
|
618
|
-
},
|
|
619
|
-
set(atom, ...args) {
|
|
620
|
-
const storeSet = getInternalBuildingBlocks(store)[22];
|
|
621
|
-
return storeSet(store, atom, ...args);
|
|
622
|
-
},
|
|
623
|
-
sub(atom, listener) {
|
|
624
|
-
const storeSub = getInternalBuildingBlocks(store)[23];
|
|
625
|
-
return storeSub(store, atom, listener);
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
const buildingBlocks = [
|
|
629
|
-
// store state
|
|
630
|
-
/* @__PURE__ */ new WeakMap(),
|
|
631
|
-
// atomStateMap
|
|
632
|
-
/* @__PURE__ */ new WeakMap(),
|
|
633
|
-
// mountedMap
|
|
634
|
-
/* @__PURE__ */ new WeakMap(),
|
|
635
|
-
// invalidatedAtoms
|
|
636
|
-
/* @__PURE__ */ new Set(),
|
|
637
|
-
// changedAtoms
|
|
638
|
-
/* @__PURE__ */ new Set(),
|
|
639
|
-
// mountCallbacks
|
|
640
|
-
/* @__PURE__ */ new Set(),
|
|
641
|
-
// unmountCallbacks
|
|
642
|
-
{},
|
|
643
|
-
// storeHooks
|
|
644
|
-
// atom interceptors
|
|
645
|
-
BUILDING_BLOCK_atomRead,
|
|
646
|
-
BUILDING_BLOCK_atomWrite,
|
|
647
|
-
BUILDING_BLOCK_atomOnInit,
|
|
648
|
-
BUILDING_BLOCK_atomOnMount,
|
|
649
|
-
// building-block functions
|
|
650
|
-
BUILDING_BLOCK_ensureAtomState,
|
|
651
|
-
BUILDING_BLOCK_flushCallbacks,
|
|
652
|
-
BUILDING_BLOCK_recomputeInvalidatedAtoms,
|
|
653
|
-
BUILDING_BLOCK_readAtomState,
|
|
654
|
-
BUILDING_BLOCK_invalidateDependents,
|
|
655
|
-
BUILDING_BLOCK_writeAtomState,
|
|
656
|
-
BUILDING_BLOCK_mountDependencies,
|
|
657
|
-
BUILDING_BLOCK_mountAtom,
|
|
658
|
-
BUILDING_BLOCK_unmountAtom,
|
|
659
|
-
BUILDING_BLOCK_setAtomStateValueOrPromise,
|
|
660
|
-
BUILDING_BLOCK_storeGet,
|
|
661
|
-
BUILDING_BLOCK_storeSet,
|
|
662
|
-
BUILDING_BLOCK_storeSub,
|
|
663
|
-
void 0
|
|
664
|
-
].map((fn, i) => buildArgs[i] || fn);
|
|
665
|
-
buildingBlockMap.set(store, Object.freeze(buildingBlocks));
|
|
666
|
-
return store;
|
|
667
|
-
}let keyCount = 0;
|
|
668
|
-
function atom(read, write) {
|
|
669
|
-
const key = `atom${++keyCount}`;
|
|
670
|
-
const config = {
|
|
671
|
-
toString() {
|
|
672
|
-
return (import.meta.env ? import.meta.env.MODE : void 0) !== "production" && this.debugLabel ? key + ":" + this.debugLabel : key;
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
if (typeof read === "function") {
|
|
676
|
-
config.read = read;
|
|
677
|
-
} else {
|
|
678
|
-
config.init = read;
|
|
679
|
-
config.read = defaultRead;
|
|
680
|
-
config.write = defaultWrite;
|
|
681
|
-
}
|
|
682
|
-
if (write) {
|
|
683
|
-
config.write = write;
|
|
684
|
-
}
|
|
685
|
-
return config;
|
|
686
|
-
}
|
|
687
|
-
function defaultRead(get) {
|
|
688
|
-
return get(this);
|
|
689
|
-
}
|
|
690
|
-
function defaultWrite(get, set, arg) {
|
|
691
|
-
return set(
|
|
692
|
-
this,
|
|
693
|
-
typeof arg === "function" ? arg(get(this)) : arg
|
|
694
|
-
);
|
|
695
|
-
}
|
|
696
|
-
function createStore() {
|
|
697
|
-
return buildStore();
|
|
698
|
-
}
|
|
699
|
-
let defaultStore;
|
|
700
|
-
function getDefaultStore() {
|
|
701
|
-
if (!defaultStore) {
|
|
702
|
-
defaultStore = createStore();
|
|
703
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
|
|
704
|
-
globalThis.__JOTAI_DEFAULT_STORE__ || (globalThis.__JOTAI_DEFAULT_STORE__ = defaultStore);
|
|
705
|
-
if (globalThis.__JOTAI_DEFAULT_STORE__ !== defaultStore) {
|
|
706
|
-
console.warn(
|
|
707
|
-
"Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
|
|
708
|
-
);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
return defaultStore;
|
|
713
|
-
}const StoreContext = createContext(
|
|
714
|
-
void 0
|
|
715
|
-
);
|
|
716
|
-
function useStore(options) {
|
|
717
|
-
const store = useContext(StoreContext);
|
|
718
|
-
return store || getDefaultStore();
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
const isPromiseLike = (x) => typeof (x == null ? void 0 : x.then) === "function";
|
|
722
|
-
const attachPromiseStatus = (promise) => {
|
|
723
|
-
if (!promise.status) {
|
|
724
|
-
promise.status = "pending";
|
|
725
|
-
promise.then(
|
|
726
|
-
(v) => {
|
|
727
|
-
promise.status = "fulfilled";
|
|
728
|
-
promise.value = v;
|
|
729
|
-
},
|
|
730
|
-
(e) => {
|
|
731
|
-
promise.status = "rejected";
|
|
732
|
-
promise.reason = e;
|
|
733
|
-
}
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
const use = React.use || // A shim for older React versions
|
|
738
|
-
((promise) => {
|
|
739
|
-
if (promise.status === "pending") {
|
|
740
|
-
throw promise;
|
|
741
|
-
} else if (promise.status === "fulfilled") {
|
|
742
|
-
return promise.value;
|
|
743
|
-
} else if (promise.status === "rejected") {
|
|
744
|
-
throw promise.reason;
|
|
745
|
-
} else {
|
|
746
|
-
attachPromiseStatus(promise);
|
|
747
|
-
throw promise;
|
|
748
|
-
}
|
|
749
|
-
});
|
|
750
|
-
const continuablePromiseMap = /* @__PURE__ */ new WeakMap();
|
|
751
|
-
const createContinuablePromise = (promise, getValue) => {
|
|
752
|
-
let continuablePromise = continuablePromiseMap.get(promise);
|
|
753
|
-
if (!continuablePromise) {
|
|
754
|
-
continuablePromise = new Promise((resolve, reject) => {
|
|
755
|
-
let curr = promise;
|
|
756
|
-
const onFulfilled = (me) => (v) => {
|
|
757
|
-
if (curr === me) {
|
|
758
|
-
resolve(v);
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
const onRejected = (me) => (e) => {
|
|
762
|
-
if (curr === me) {
|
|
763
|
-
reject(e);
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
const onAbort = () => {
|
|
767
|
-
try {
|
|
768
|
-
const nextValue = getValue();
|
|
769
|
-
if (isPromiseLike(nextValue)) {
|
|
770
|
-
continuablePromiseMap.set(nextValue, continuablePromise);
|
|
771
|
-
curr = nextValue;
|
|
772
|
-
nextValue.then(onFulfilled(nextValue), onRejected(nextValue));
|
|
773
|
-
registerAbortHandler(nextValue, onAbort);
|
|
774
|
-
} else {
|
|
775
|
-
resolve(nextValue);
|
|
776
|
-
}
|
|
777
|
-
} catch (e) {
|
|
778
|
-
reject(e);
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
promise.then(onFulfilled(promise), onRejected(promise));
|
|
782
|
-
registerAbortHandler(promise, onAbort);
|
|
783
|
-
});
|
|
784
|
-
continuablePromiseMap.set(promise, continuablePromise);
|
|
785
|
-
}
|
|
786
|
-
return continuablePromise;
|
|
787
|
-
};
|
|
788
|
-
function useAtomValue(atom, options) {
|
|
789
|
-
const { delay, unstable_promiseStatus: promiseStatus = !React.use } = {};
|
|
790
|
-
const store = useStore();
|
|
791
|
-
const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = useReducer(
|
|
792
|
-
(prev) => {
|
|
793
|
-
const nextValue = store.get(atom);
|
|
794
|
-
if (Object.is(prev[0], nextValue) && prev[1] === store && prev[2] === atom) {
|
|
795
|
-
return prev;
|
|
796
|
-
}
|
|
797
|
-
return [nextValue, store, atom];
|
|
798
|
-
},
|
|
799
|
-
void 0,
|
|
800
|
-
() => [store.get(atom), store, atom]
|
|
801
|
-
);
|
|
802
|
-
let value = valueFromReducer;
|
|
803
|
-
if (storeFromReducer !== store || atomFromReducer !== atom) {
|
|
804
|
-
rerender();
|
|
805
|
-
value = store.get(atom);
|
|
806
|
-
}
|
|
807
|
-
useEffect(() => {
|
|
808
|
-
const unsub = store.sub(atom, () => {
|
|
809
|
-
if (promiseStatus) {
|
|
810
|
-
try {
|
|
811
|
-
const value2 = store.get(atom);
|
|
812
|
-
if (isPromiseLike(value2)) {
|
|
813
|
-
attachPromiseStatus(
|
|
814
|
-
createContinuablePromise(value2, () => store.get(atom))
|
|
815
|
-
);
|
|
816
|
-
}
|
|
817
|
-
} catch (e) {
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
if (typeof delay === "number") {
|
|
821
|
-
setTimeout(rerender, delay);
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
rerender();
|
|
825
|
-
});
|
|
826
|
-
rerender();
|
|
827
|
-
return unsub;
|
|
828
|
-
}, [store, atom, delay, promiseStatus]);
|
|
829
|
-
useDebugValue(value);
|
|
830
|
-
if (isPromiseLike(value)) {
|
|
831
|
-
const promise = createContinuablePromise(value, () => store.get(atom));
|
|
832
|
-
if (promiseStatus) {
|
|
833
|
-
attachPromiseStatus(promise);
|
|
834
|
-
}
|
|
835
|
-
return use(promise);
|
|
836
|
-
}
|
|
837
|
-
return value;
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
function useSetAtom(atom, options) {
|
|
841
|
-
const store = useStore();
|
|
842
|
-
const setAtom = useCallback(
|
|
843
|
-
(...args) => {
|
|
844
|
-
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !("write" in atom)) {
|
|
845
|
-
throw new Error("not writable atom");
|
|
846
|
-
}
|
|
847
|
-
return store.set(atom, ...args);
|
|
848
|
-
},
|
|
849
|
-
[store, atom]
|
|
850
|
-
);
|
|
851
|
-
return setAtom;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
function useAtom(atom, options) {
|
|
855
|
-
return [
|
|
856
|
-
useAtomValue(atom),
|
|
857
|
-
// We do wrong type assertion here, which results in throwing an error.
|
|
858
|
-
useSetAtom(atom)
|
|
859
|
-
];
|
|
860
|
-
}/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
28
|
+
};/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
861
29
|
/**
|
|
862
30
|
* Optimized shallow equality check for objects and functions
|
|
863
31
|
* @param objA - First object to compare
|
|
@@ -982,61 +150,6 @@ function memoize(fn, cacheKeyFn) {
|
|
|
982
150
|
cache.set(cacheKey, result);
|
|
983
151
|
return result;
|
|
984
152
|
};
|
|
985
|
-
}function atomFamily(initializeAtom, areEqual) {
|
|
986
|
-
let shouldRemove = null;
|
|
987
|
-
const atoms = new Map();
|
|
988
|
-
const listeners = new Set();
|
|
989
|
-
function createAtom(param) {
|
|
990
|
-
let item;
|
|
991
|
-
{
|
|
992
|
-
item = atoms.get(param);
|
|
993
|
-
}
|
|
994
|
-
if (item !== undefined) {
|
|
995
|
-
if (shouldRemove?.(item[1], param)) {
|
|
996
|
-
createAtom.remove(param);
|
|
997
|
-
}
|
|
998
|
-
else {
|
|
999
|
-
return item[0];
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
const newAtom = initializeAtom(param);
|
|
1003
|
-
atoms.set(param, [newAtom, Date.now()]);
|
|
1004
|
-
notifyListeners('CREATE', param, newAtom);
|
|
1005
|
-
return newAtom;
|
|
1006
|
-
}
|
|
1007
|
-
function notifyListeners(type, param, atom) {
|
|
1008
|
-
for (const listener of listeners) {
|
|
1009
|
-
listener({ type, param, atom });
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
createAtom.unstable_listen = (callback) => {
|
|
1013
|
-
listeners.add(callback);
|
|
1014
|
-
return () => {
|
|
1015
|
-
listeners.delete(callback);
|
|
1016
|
-
};
|
|
1017
|
-
};
|
|
1018
|
-
createAtom.getParams = () => atoms.keys();
|
|
1019
|
-
createAtom.remove = (param) => {
|
|
1020
|
-
{
|
|
1021
|
-
if (!atoms.has(param))
|
|
1022
|
-
return;
|
|
1023
|
-
const [atom] = atoms.get(param);
|
|
1024
|
-
atoms.delete(param);
|
|
1025
|
-
notifyListeners('REMOVE', param, atom);
|
|
1026
|
-
}
|
|
1027
|
-
};
|
|
1028
|
-
createAtom.setShouldRemove = (fn) => {
|
|
1029
|
-
shouldRemove = fn;
|
|
1030
|
-
if (!shouldRemove)
|
|
1031
|
-
return;
|
|
1032
|
-
for (const [key, [atom, createdAt]] of atoms) {
|
|
1033
|
-
if (shouldRemove(createdAt, key)) {
|
|
1034
|
-
atoms.delete(key);
|
|
1035
|
-
notifyListeners('REMOVE', key, atom);
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
};
|
|
1039
|
-
return createAtom;
|
|
1040
153
|
}const pageVariablesAtomFamily = atomFamily(_pageId => atom({}));
|
|
1041
154
|
/**
|
|
1042
155
|
* Global atom storing all page variables.
|
|
@@ -2187,9 +1300,9 @@ let _pageConfig = {
|
|
|
2187
1300
|
HeaderContainer: DefaultContainer,
|
|
2188
1301
|
FooterContainer: DefaultContainer,
|
|
2189
1302
|
BodyContainer: DefaultContainer,
|
|
2190
|
-
authPageImage:
|
|
1303
|
+
authPageImage: "",
|
|
2191
1304
|
authPageProps: {
|
|
2192
|
-
id:
|
|
1305
|
+
id: "auth-page"
|
|
2193
1306
|
},
|
|
2194
1307
|
isLogged: val => !!(val === null || val === void 0 ? void 0 : val.id) && !!val.isLogged,
|
|
2195
1308
|
ItemsContainer: ({
|
|
@@ -2199,8 +1312,8 @@ let _pageConfig = {
|
|
|
2199
1312
|
children
|
|
2200
1313
|
}) => children,
|
|
2201
1314
|
meta: {
|
|
2202
|
-
title:
|
|
2203
|
-
description:
|
|
1315
|
+
title: "",
|
|
1316
|
+
description: ""
|
|
2204
1317
|
},
|
|
2205
1318
|
// Metadata configuration
|
|
2206
1319
|
defaultMetadata: {},
|
|
@@ -2213,7 +1326,7 @@ let _pageConfig = {
|
|
|
2213
1326
|
preloadOnHover: false,
|
|
2214
1327
|
preloadOnFocus: false,
|
|
2215
1328
|
timeout: 30000,
|
|
2216
|
-
logMetrics: process.env.NODE_ENV ===
|
|
1329
|
+
logMetrics: process.env.NODE_ENV === "development"
|
|
2217
1330
|
}
|
|
2218
1331
|
};
|
|
2219
1332
|
/**
|
|
@@ -2225,9 +1338,9 @@ function initializePageConfig() {
|
|
|
2225
1338
|
HeaderContainer: DefaultContainer,
|
|
2226
1339
|
FooterContainer: DefaultContainer,
|
|
2227
1340
|
BodyContainer: DefaultContainer,
|
|
2228
|
-
authPageImage:
|
|
1341
|
+
authPageImage: "",
|
|
2229
1342
|
authPageProps: {
|
|
2230
|
-
id:
|
|
1343
|
+
id: "auth-page"
|
|
2231
1344
|
},
|
|
2232
1345
|
isLogged: val => !!(val === null || val === void 0 ? void 0 : val.id) && !!val.isLogged,
|
|
2233
1346
|
ItemsContainer: ({
|
|
@@ -2237,8 +1350,8 @@ function initializePageConfig() {
|
|
|
2237
1350
|
children
|
|
2238
1351
|
}) => children,
|
|
2239
1352
|
meta: {
|
|
2240
|
-
title:
|
|
2241
|
-
description:
|
|
1353
|
+
title: "",
|
|
1354
|
+
description: ""
|
|
2242
1355
|
},
|
|
2243
1356
|
// Metadata configuration
|
|
2244
1357
|
defaultMetadata: {},
|
|
@@ -2251,7 +1364,7 @@ function initializePageConfig() {
|
|
|
2251
1364
|
preloadOnHover: false,
|
|
2252
1365
|
preloadOnFocus: false,
|
|
2253
1366
|
timeout: 30000,
|
|
2254
|
-
logMetrics: process.env.NODE_ENV ===
|
|
1367
|
+
logMetrics: process.env.NODE_ENV === "development"
|
|
2255
1368
|
}
|
|
2256
1369
|
};
|
|
2257
1370
|
return _pageConfig;
|
|
@@ -2266,7 +1379,7 @@ const {
|
|
|
2266
1379
|
useState: usePageConfigState,
|
|
2267
1380
|
useReset: usePageConfigReset
|
|
2268
1381
|
} = atomStateGenerator({
|
|
2269
|
-
key:
|
|
1382
|
+
key: "pageConfig",
|
|
2270
1383
|
defaultValue: _pageConfig,
|
|
2271
1384
|
persist: false
|
|
2272
1385
|
});/**
|
|
@@ -2377,850 +1490,6 @@ function useFormData({
|
|
|
2377
1490
|
mappedFormData,
|
|
2378
1491
|
formSubmit
|
|
2379
1492
|
};
|
|
2380
|
-
}// src/subscribable.ts
|
|
2381
|
-
var Subscribable = class {
|
|
2382
|
-
constructor() {
|
|
2383
|
-
this.listeners = /* @__PURE__ */new Set();
|
|
2384
|
-
this.subscribe = this.subscribe.bind(this);
|
|
2385
|
-
}
|
|
2386
|
-
subscribe(listener) {
|
|
2387
|
-
this.listeners.add(listener);
|
|
2388
|
-
this.onSubscribe();
|
|
2389
|
-
return () => {
|
|
2390
|
-
this.listeners.delete(listener);
|
|
2391
|
-
this.onUnsubscribe();
|
|
2392
|
-
};
|
|
2393
|
-
}
|
|
2394
|
-
hasListeners() {
|
|
2395
|
-
return this.listeners.size > 0;
|
|
2396
|
-
}
|
|
2397
|
-
onSubscribe() {}
|
|
2398
|
-
onUnsubscribe() {}
|
|
2399
|
-
};// src/timeoutManager.ts
|
|
2400
|
-
var defaultTimeoutProvider = {
|
|
2401
|
-
// We need the wrapper function syntax below instead of direct references to
|
|
2402
|
-
// global setTimeout etc.
|
|
2403
|
-
//
|
|
2404
|
-
// BAD: `setTimeout: setTimeout`
|
|
2405
|
-
// GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
|
|
2406
|
-
//
|
|
2407
|
-
// If we use direct references here, then anything that wants to spy on or
|
|
2408
|
-
// replace the global setTimeout (like tests) won't work since we'll already
|
|
2409
|
-
// have a hard reference to the original implementation at the time when this
|
|
2410
|
-
// file was imported.
|
|
2411
|
-
setTimeout: (callback, delay) => setTimeout(callback, delay),
|
|
2412
|
-
clearTimeout: timeoutId => clearTimeout(timeoutId),
|
|
2413
|
-
setInterval: (callback, delay) => setInterval(callback, delay),
|
|
2414
|
-
clearInterval: intervalId => clearInterval(intervalId)
|
|
2415
|
-
};
|
|
2416
|
-
var TimeoutManager = class {
|
|
2417
|
-
// We cannot have TimeoutManager<T> as we must instantiate it with a concrete
|
|
2418
|
-
// type at app boot; and if we leave that type, then any new timer provider
|
|
2419
|
-
// would need to support ReturnType<typeof setTimeout>, which is infeasible.
|
|
2420
|
-
//
|
|
2421
|
-
// We settle for type safety for the TimeoutProvider type, and accept that
|
|
2422
|
-
// this class is unsafe internally to allow for extension.
|
|
2423
|
-
#provider = defaultTimeoutProvider;
|
|
2424
|
-
#providerCalled = false;
|
|
2425
|
-
setTimeoutProvider(provider) {
|
|
2426
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2427
|
-
if (this.#providerCalled && provider !== this.#provider) {
|
|
2428
|
-
console.error(`[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`, {
|
|
2429
|
-
previous: this.#provider,
|
|
2430
|
-
provider
|
|
2431
|
-
});
|
|
2432
|
-
}
|
|
2433
|
-
}
|
|
2434
|
-
this.#provider = provider;
|
|
2435
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2436
|
-
this.#providerCalled = false;
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
setTimeout(callback, delay) {
|
|
2440
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2441
|
-
this.#providerCalled = true;
|
|
2442
|
-
}
|
|
2443
|
-
return this.#provider.setTimeout(callback, delay);
|
|
2444
|
-
}
|
|
2445
|
-
clearTimeout(timeoutId) {
|
|
2446
|
-
this.#provider.clearTimeout(timeoutId);
|
|
2447
|
-
}
|
|
2448
|
-
setInterval(callback, delay) {
|
|
2449
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2450
|
-
this.#providerCalled = true;
|
|
2451
|
-
}
|
|
2452
|
-
return this.#provider.setInterval(callback, delay);
|
|
2453
|
-
}
|
|
2454
|
-
clearInterval(intervalId) {
|
|
2455
|
-
this.#provider.clearInterval(intervalId);
|
|
2456
|
-
}
|
|
2457
|
-
};
|
|
2458
|
-
var timeoutManager = new TimeoutManager();
|
|
2459
|
-
function systemSetTimeoutZero(callback) {
|
|
2460
|
-
setTimeout(callback, 0);
|
|
2461
|
-
}// src/utils.ts
|
|
2462
|
-
var isServer = typeof window === "undefined" || "Deno" in globalThis;
|
|
2463
|
-
function noop() {}
|
|
2464
|
-
function isValidTimeout(value) {
|
|
2465
|
-
return typeof value === "number" && value >= 0 && value !== Infinity;
|
|
2466
|
-
}
|
|
2467
|
-
function timeUntilStale(updatedAt, staleTime) {
|
|
2468
|
-
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
|
|
2469
|
-
}
|
|
2470
|
-
function resolveStaleTime(staleTime, query) {
|
|
2471
|
-
return typeof staleTime === "function" ? staleTime(query) : staleTime;
|
|
2472
|
-
}
|
|
2473
|
-
function resolveEnabled(enabled, query) {
|
|
2474
|
-
return typeof enabled === "function" ? enabled(query) : enabled;
|
|
2475
|
-
}
|
|
2476
|
-
var hasOwn = Object.prototype.hasOwnProperty;
|
|
2477
|
-
function replaceEqualDeep(a, b, depth = 0) {
|
|
2478
|
-
if (a === b) {
|
|
2479
|
-
return a;
|
|
2480
|
-
}
|
|
2481
|
-
if (depth > 500) return b;
|
|
2482
|
-
const array = isPlainArray(a) && isPlainArray(b);
|
|
2483
|
-
if (!array && !(isPlainObject(a) && isPlainObject(b))) return b;
|
|
2484
|
-
const aItems = array ? a : Object.keys(a);
|
|
2485
|
-
const aSize = aItems.length;
|
|
2486
|
-
const bItems = array ? b : Object.keys(b);
|
|
2487
|
-
const bSize = bItems.length;
|
|
2488
|
-
const copy = array ? new Array(bSize) : {};
|
|
2489
|
-
let equalItems = 0;
|
|
2490
|
-
for (let i = 0; i < bSize; i++) {
|
|
2491
|
-
const key = array ? i : bItems[i];
|
|
2492
|
-
const aItem = a[key];
|
|
2493
|
-
const bItem = b[key];
|
|
2494
|
-
if (aItem === bItem) {
|
|
2495
|
-
copy[key] = aItem;
|
|
2496
|
-
if (array ? i < aSize : hasOwn.call(a, key)) equalItems++;
|
|
2497
|
-
continue;
|
|
2498
|
-
}
|
|
2499
|
-
if (aItem === null || bItem === null || typeof aItem !== "object" || typeof bItem !== "object") {
|
|
2500
|
-
copy[key] = bItem;
|
|
2501
|
-
continue;
|
|
2502
|
-
}
|
|
2503
|
-
const v = replaceEqualDeep(aItem, bItem, depth + 1);
|
|
2504
|
-
copy[key] = v;
|
|
2505
|
-
if (v === aItem) equalItems++;
|
|
2506
|
-
}
|
|
2507
|
-
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
2508
|
-
}
|
|
2509
|
-
function shallowEqualObjects(a, b) {
|
|
2510
|
-
if (!b || Object.keys(a).length !== Object.keys(b).length) {
|
|
2511
|
-
return false;
|
|
2512
|
-
}
|
|
2513
|
-
for (const key in a) {
|
|
2514
|
-
if (a[key] !== b[key]) {
|
|
2515
|
-
return false;
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
return true;
|
|
2519
|
-
}
|
|
2520
|
-
function isPlainArray(value) {
|
|
2521
|
-
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
2522
|
-
}
|
|
2523
|
-
function isPlainObject(o) {
|
|
2524
|
-
if (!hasObjectPrototype(o)) {
|
|
2525
|
-
return false;
|
|
2526
|
-
}
|
|
2527
|
-
const ctor = o.constructor;
|
|
2528
|
-
if (ctor === void 0) {
|
|
2529
|
-
return true;
|
|
2530
|
-
}
|
|
2531
|
-
const prot = ctor.prototype;
|
|
2532
|
-
if (!hasObjectPrototype(prot)) {
|
|
2533
|
-
return false;
|
|
2534
|
-
}
|
|
2535
|
-
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
2536
|
-
return false;
|
|
2537
|
-
}
|
|
2538
|
-
if (Object.getPrototypeOf(o) !== Object.prototype) {
|
|
2539
|
-
return false;
|
|
2540
|
-
}
|
|
2541
|
-
return true;
|
|
2542
|
-
}
|
|
2543
|
-
function hasObjectPrototype(o) {
|
|
2544
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
2545
|
-
}
|
|
2546
|
-
function replaceData(prevData, data, options) {
|
|
2547
|
-
if (typeof options.structuralSharing === "function") {
|
|
2548
|
-
return options.structuralSharing(prevData, data);
|
|
2549
|
-
} else if (options.structuralSharing !== false) {
|
|
2550
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2551
|
-
try {
|
|
2552
|
-
return replaceEqualDeep(prevData, data);
|
|
2553
|
-
} catch (error) {
|
|
2554
|
-
console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${options.queryHash}]: ${error}`);
|
|
2555
|
-
throw error;
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
return replaceEqualDeep(prevData, data);
|
|
2559
|
-
}
|
|
2560
|
-
return data;
|
|
2561
|
-
}// src/focusManager.ts
|
|
2562
|
-
var FocusManager = class extends Subscribable {
|
|
2563
|
-
#focused;
|
|
2564
|
-
#cleanup;
|
|
2565
|
-
#setup;
|
|
2566
|
-
constructor() {
|
|
2567
|
-
super();
|
|
2568
|
-
this.#setup = onFocus => {
|
|
2569
|
-
if (!isServer && window.addEventListener) {
|
|
2570
|
-
const listener = () => onFocus();
|
|
2571
|
-
window.addEventListener("visibilitychange", listener, false);
|
|
2572
|
-
return () => {
|
|
2573
|
-
window.removeEventListener("visibilitychange", listener);
|
|
2574
|
-
};
|
|
2575
|
-
}
|
|
2576
|
-
return;
|
|
2577
|
-
};
|
|
2578
|
-
}
|
|
2579
|
-
onSubscribe() {
|
|
2580
|
-
if (!this.#cleanup) {
|
|
2581
|
-
this.setEventListener(this.#setup);
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
2584
|
-
onUnsubscribe() {
|
|
2585
|
-
if (!this.hasListeners()) {
|
|
2586
|
-
this.#cleanup?.();
|
|
2587
|
-
this.#cleanup = void 0;
|
|
2588
|
-
}
|
|
2589
|
-
}
|
|
2590
|
-
setEventListener(setup) {
|
|
2591
|
-
this.#setup = setup;
|
|
2592
|
-
this.#cleanup?.();
|
|
2593
|
-
this.#cleanup = setup(focused => {
|
|
2594
|
-
if (typeof focused === "boolean") {
|
|
2595
|
-
this.setFocused(focused);
|
|
2596
|
-
} else {
|
|
2597
|
-
this.onFocus();
|
|
2598
|
-
}
|
|
2599
|
-
});
|
|
2600
|
-
}
|
|
2601
|
-
setFocused(focused) {
|
|
2602
|
-
const changed = this.#focused !== focused;
|
|
2603
|
-
if (changed) {
|
|
2604
|
-
this.#focused = focused;
|
|
2605
|
-
this.onFocus();
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
onFocus() {
|
|
2609
|
-
const isFocused = this.isFocused();
|
|
2610
|
-
this.listeners.forEach(listener => {
|
|
2611
|
-
listener(isFocused);
|
|
2612
|
-
});
|
|
2613
|
-
}
|
|
2614
|
-
isFocused() {
|
|
2615
|
-
if (typeof this.#focused === "boolean") {
|
|
2616
|
-
return this.#focused;
|
|
2617
|
-
}
|
|
2618
|
-
return globalThis.document?.visibilityState !== "hidden";
|
|
2619
|
-
}
|
|
2620
|
-
};
|
|
2621
|
-
var focusManager = new FocusManager();// src/thenable.ts
|
|
2622
|
-
function pendingThenable() {
|
|
2623
|
-
let resolve;
|
|
2624
|
-
let reject;
|
|
2625
|
-
const thenable = new Promise((_resolve, _reject) => {
|
|
2626
|
-
resolve = _resolve;
|
|
2627
|
-
reject = _reject;
|
|
2628
|
-
});
|
|
2629
|
-
thenable.status = "pending";
|
|
2630
|
-
thenable.catch(() => {});
|
|
2631
|
-
function finalize(data) {
|
|
2632
|
-
Object.assign(thenable, data);
|
|
2633
|
-
delete thenable.resolve;
|
|
2634
|
-
delete thenable.reject;
|
|
2635
|
-
}
|
|
2636
|
-
thenable.resolve = value => {
|
|
2637
|
-
finalize({
|
|
2638
|
-
status: "fulfilled",
|
|
2639
|
-
value
|
|
2640
|
-
});
|
|
2641
|
-
resolve(value);
|
|
2642
|
-
};
|
|
2643
|
-
thenable.reject = reason => {
|
|
2644
|
-
finalize({
|
|
2645
|
-
status: "rejected",
|
|
2646
|
-
reason
|
|
2647
|
-
});
|
|
2648
|
-
reject(reason);
|
|
2649
|
-
};
|
|
2650
|
-
return thenable;
|
|
2651
|
-
}// src/notifyManager.ts
|
|
2652
|
-
var defaultScheduler = systemSetTimeoutZero;
|
|
2653
|
-
function createNotifyManager() {
|
|
2654
|
-
let queue = [];
|
|
2655
|
-
let transactions = 0;
|
|
2656
|
-
let notifyFn = callback => {
|
|
2657
|
-
callback();
|
|
2658
|
-
};
|
|
2659
|
-
let batchNotifyFn = callback => {
|
|
2660
|
-
callback();
|
|
2661
|
-
};
|
|
2662
|
-
let scheduleFn = defaultScheduler;
|
|
2663
|
-
const schedule = callback => {
|
|
2664
|
-
if (transactions) {
|
|
2665
|
-
queue.push(callback);
|
|
2666
|
-
} else {
|
|
2667
|
-
scheduleFn(() => {
|
|
2668
|
-
notifyFn(callback);
|
|
2669
|
-
});
|
|
2670
|
-
}
|
|
2671
|
-
};
|
|
2672
|
-
const flush = () => {
|
|
2673
|
-
const originalQueue = queue;
|
|
2674
|
-
queue = [];
|
|
2675
|
-
if (originalQueue.length) {
|
|
2676
|
-
scheduleFn(() => {
|
|
2677
|
-
batchNotifyFn(() => {
|
|
2678
|
-
originalQueue.forEach(callback => {
|
|
2679
|
-
notifyFn(callback);
|
|
2680
|
-
});
|
|
2681
|
-
});
|
|
2682
|
-
});
|
|
2683
|
-
}
|
|
2684
|
-
};
|
|
2685
|
-
return {
|
|
2686
|
-
batch: callback => {
|
|
2687
|
-
let result;
|
|
2688
|
-
transactions++;
|
|
2689
|
-
try {
|
|
2690
|
-
result = callback();
|
|
2691
|
-
} finally {
|
|
2692
|
-
transactions--;
|
|
2693
|
-
if (!transactions) {
|
|
2694
|
-
flush();
|
|
2695
|
-
}
|
|
2696
|
-
}
|
|
2697
|
-
return result;
|
|
2698
|
-
},
|
|
2699
|
-
/**
|
|
2700
|
-
* All calls to the wrapped function will be batched.
|
|
2701
|
-
*/
|
|
2702
|
-
batchCalls: callback => {
|
|
2703
|
-
return (...args) => {
|
|
2704
|
-
schedule(() => {
|
|
2705
|
-
callback(...args);
|
|
2706
|
-
});
|
|
2707
|
-
};
|
|
2708
|
-
},
|
|
2709
|
-
schedule,
|
|
2710
|
-
/**
|
|
2711
|
-
* Use this method to set a custom notify function.
|
|
2712
|
-
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
2713
|
-
*/
|
|
2714
|
-
setNotifyFunction: fn => {
|
|
2715
|
-
notifyFn = fn;
|
|
2716
|
-
},
|
|
2717
|
-
/**
|
|
2718
|
-
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
2719
|
-
* By default React Query will use the batch function provided by ReactDOM or React Native.
|
|
2720
|
-
*/
|
|
2721
|
-
setBatchNotifyFunction: fn => {
|
|
2722
|
-
batchNotifyFn = fn;
|
|
2723
|
-
},
|
|
2724
|
-
setScheduler: fn => {
|
|
2725
|
-
scheduleFn = fn;
|
|
2726
|
-
}
|
|
2727
|
-
};
|
|
2728
|
-
}
|
|
2729
|
-
var notifyManager = createNotifyManager();// src/onlineManager.ts
|
|
2730
|
-
var OnlineManager = class extends Subscribable {
|
|
2731
|
-
#online = true;
|
|
2732
|
-
#cleanup;
|
|
2733
|
-
#setup;
|
|
2734
|
-
constructor() {
|
|
2735
|
-
super();
|
|
2736
|
-
this.#setup = onOnline => {
|
|
2737
|
-
if (!isServer && window.addEventListener) {
|
|
2738
|
-
const onlineListener = () => onOnline(true);
|
|
2739
|
-
const offlineListener = () => onOnline(false);
|
|
2740
|
-
window.addEventListener("online", onlineListener, false);
|
|
2741
|
-
window.addEventListener("offline", offlineListener, false);
|
|
2742
|
-
return () => {
|
|
2743
|
-
window.removeEventListener("online", onlineListener);
|
|
2744
|
-
window.removeEventListener("offline", offlineListener);
|
|
2745
|
-
};
|
|
2746
|
-
}
|
|
2747
|
-
return;
|
|
2748
|
-
};
|
|
2749
|
-
}
|
|
2750
|
-
onSubscribe() {
|
|
2751
|
-
if (!this.#cleanup) {
|
|
2752
|
-
this.setEventListener(this.#setup);
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
onUnsubscribe() {
|
|
2756
|
-
if (!this.hasListeners()) {
|
|
2757
|
-
this.#cleanup?.();
|
|
2758
|
-
this.#cleanup = void 0;
|
|
2759
|
-
}
|
|
2760
|
-
}
|
|
2761
|
-
setEventListener(setup) {
|
|
2762
|
-
this.#setup = setup;
|
|
2763
|
-
this.#cleanup?.();
|
|
2764
|
-
this.#cleanup = setup(this.setOnline.bind(this));
|
|
2765
|
-
}
|
|
2766
|
-
setOnline(online) {
|
|
2767
|
-
const changed = this.#online !== online;
|
|
2768
|
-
if (changed) {
|
|
2769
|
-
this.#online = online;
|
|
2770
|
-
this.listeners.forEach(listener => {
|
|
2771
|
-
listener(online);
|
|
2772
|
-
});
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
2775
|
-
isOnline() {
|
|
2776
|
-
return this.#online;
|
|
2777
|
-
}
|
|
2778
|
-
};
|
|
2779
|
-
var onlineManager = new OnlineManager();// src/retryer.ts
|
|
2780
|
-
function canFetch(networkMode) {
|
|
2781
|
-
return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
|
|
2782
|
-
}// src/query.ts
|
|
2783
|
-
function fetchState(data, options) {
|
|
2784
|
-
return {
|
|
2785
|
-
fetchFailureCount: 0,
|
|
2786
|
-
fetchFailureReason: null,
|
|
2787
|
-
fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
|
|
2788
|
-
...(data === void 0 && {
|
|
2789
|
-
error: null,
|
|
2790
|
-
status: "pending"
|
|
2791
|
-
})
|
|
2792
|
-
};
|
|
2793
|
-
}// src/queryObserver.ts
|
|
2794
|
-
var QueryObserver = class extends Subscribable {
|
|
2795
|
-
constructor(client, options) {
|
|
2796
|
-
super();
|
|
2797
|
-
this.options = options;
|
|
2798
|
-
this.#client = client;
|
|
2799
|
-
this.#selectError = null;
|
|
2800
|
-
this.#currentThenable = pendingThenable();
|
|
2801
|
-
this.bindMethods();
|
|
2802
|
-
this.setOptions(options);
|
|
2803
|
-
}
|
|
2804
|
-
#client;
|
|
2805
|
-
#currentQuery = void 0;
|
|
2806
|
-
#currentQueryInitialState = void 0;
|
|
2807
|
-
#currentResult = void 0;
|
|
2808
|
-
#currentResultState;
|
|
2809
|
-
#currentResultOptions;
|
|
2810
|
-
#currentThenable;
|
|
2811
|
-
#selectError;
|
|
2812
|
-
#selectFn;
|
|
2813
|
-
#selectResult;
|
|
2814
|
-
// This property keeps track of the last query with defined data.
|
|
2815
|
-
// It will be used to pass the previous data and query to the placeholder function between renders.
|
|
2816
|
-
#lastQueryWithDefinedData;
|
|
2817
|
-
#staleTimeoutId;
|
|
2818
|
-
#refetchIntervalId;
|
|
2819
|
-
#currentRefetchInterval;
|
|
2820
|
-
#trackedProps = /* @__PURE__ */new Set();
|
|
2821
|
-
bindMethods() {
|
|
2822
|
-
this.refetch = this.refetch.bind(this);
|
|
2823
|
-
}
|
|
2824
|
-
onSubscribe() {
|
|
2825
|
-
if (this.listeners.size === 1) {
|
|
2826
|
-
this.#currentQuery.addObserver(this);
|
|
2827
|
-
if (shouldFetchOnMount(this.#currentQuery, this.options)) {
|
|
2828
|
-
this.#executeFetch();
|
|
2829
|
-
} else {
|
|
2830
|
-
this.updateResult();
|
|
2831
|
-
}
|
|
2832
|
-
this.#updateTimers();
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
|
-
onUnsubscribe() {
|
|
2836
|
-
if (!this.hasListeners()) {
|
|
2837
|
-
this.destroy();
|
|
2838
|
-
}
|
|
2839
|
-
}
|
|
2840
|
-
shouldFetchOnReconnect() {
|
|
2841
|
-
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
|
|
2842
|
-
}
|
|
2843
|
-
shouldFetchOnWindowFocus() {
|
|
2844
|
-
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
|
|
2845
|
-
}
|
|
2846
|
-
destroy() {
|
|
2847
|
-
this.listeners = /* @__PURE__ */new Set();
|
|
2848
|
-
this.#clearStaleTimeout();
|
|
2849
|
-
this.#clearRefetchInterval();
|
|
2850
|
-
this.#currentQuery.removeObserver(this);
|
|
2851
|
-
}
|
|
2852
|
-
setOptions(options) {
|
|
2853
|
-
const prevOptions = this.options;
|
|
2854
|
-
const prevQuery = this.#currentQuery;
|
|
2855
|
-
this.options = this.#client.defaultQueryOptions(options);
|
|
2856
|
-
if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean" && typeof this.options.enabled !== "function" && typeof resolveEnabled(this.options.enabled, this.#currentQuery) !== "boolean") {
|
|
2857
|
-
throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");
|
|
2858
|
-
}
|
|
2859
|
-
this.#updateQuery();
|
|
2860
|
-
this.#currentQuery.setOptions(this.options);
|
|
2861
|
-
if (prevOptions._defaulted && !shallowEqualObjects(this.options, prevOptions)) {
|
|
2862
|
-
this.#client.getQueryCache().notify({
|
|
2863
|
-
type: "observerOptionsUpdated",
|
|
2864
|
-
query: this.#currentQuery,
|
|
2865
|
-
observer: this
|
|
2866
|
-
});
|
|
2867
|
-
}
|
|
2868
|
-
const mounted = this.hasListeners();
|
|
2869
|
-
if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) {
|
|
2870
|
-
this.#executeFetch();
|
|
2871
|
-
}
|
|
2872
|
-
this.updateResult();
|
|
2873
|
-
if (mounted && (this.#currentQuery !== prevQuery || resolveEnabled(this.options.enabled, this.#currentQuery) !== resolveEnabled(prevOptions.enabled, this.#currentQuery) || resolveStaleTime(this.options.staleTime, this.#currentQuery) !== resolveStaleTime(prevOptions.staleTime, this.#currentQuery))) {
|
|
2874
|
-
this.#updateStaleTimeout();
|
|
2875
|
-
}
|
|
2876
|
-
const nextRefetchInterval = this.#computeRefetchInterval();
|
|
2877
|
-
if (mounted && (this.#currentQuery !== prevQuery || resolveEnabled(this.options.enabled, this.#currentQuery) !== resolveEnabled(prevOptions.enabled, this.#currentQuery) || nextRefetchInterval !== this.#currentRefetchInterval)) {
|
|
2878
|
-
this.#updateRefetchInterval(nextRefetchInterval);
|
|
2879
|
-
}
|
|
2880
|
-
}
|
|
2881
|
-
getOptimisticResult(options) {
|
|
2882
|
-
const query = this.#client.getQueryCache().build(this.#client, options);
|
|
2883
|
-
const result = this.createResult(query, options);
|
|
2884
|
-
if (shouldAssignObserverCurrentProperties(this, result)) {
|
|
2885
|
-
this.#currentResult = result;
|
|
2886
|
-
this.#currentResultOptions = this.options;
|
|
2887
|
-
this.#currentResultState = this.#currentQuery.state;
|
|
2888
|
-
}
|
|
2889
|
-
return result;
|
|
2890
|
-
}
|
|
2891
|
-
getCurrentResult() {
|
|
2892
|
-
return this.#currentResult;
|
|
2893
|
-
}
|
|
2894
|
-
trackResult(result, onPropTracked) {
|
|
2895
|
-
return new Proxy(result, {
|
|
2896
|
-
get: (target, key) => {
|
|
2897
|
-
this.trackProp(key);
|
|
2898
|
-
onPropTracked?.(key);
|
|
2899
|
-
if (key === "promise") {
|
|
2900
|
-
this.trackProp("data");
|
|
2901
|
-
if (!this.options.experimental_prefetchInRender && this.#currentThenable.status === "pending") {
|
|
2902
|
-
this.#currentThenable.reject(new Error("experimental_prefetchInRender feature flag is not enabled"));
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
return Reflect.get(target, key);
|
|
2906
|
-
}
|
|
2907
|
-
});
|
|
2908
|
-
}
|
|
2909
|
-
trackProp(key) {
|
|
2910
|
-
this.#trackedProps.add(key);
|
|
2911
|
-
}
|
|
2912
|
-
getCurrentQuery() {
|
|
2913
|
-
return this.#currentQuery;
|
|
2914
|
-
}
|
|
2915
|
-
refetch({
|
|
2916
|
-
...options
|
|
2917
|
-
} = {}) {
|
|
2918
|
-
return this.fetch({
|
|
2919
|
-
...options
|
|
2920
|
-
});
|
|
2921
|
-
}
|
|
2922
|
-
fetchOptimistic(options) {
|
|
2923
|
-
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
2924
|
-
const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
|
|
2925
|
-
return query.fetch().then(() => this.createResult(query, defaultedOptions));
|
|
2926
|
-
}
|
|
2927
|
-
fetch(fetchOptions) {
|
|
2928
|
-
return this.#executeFetch({
|
|
2929
|
-
...fetchOptions,
|
|
2930
|
-
cancelRefetch: fetchOptions.cancelRefetch ?? true
|
|
2931
|
-
}).then(() => {
|
|
2932
|
-
this.updateResult();
|
|
2933
|
-
return this.#currentResult;
|
|
2934
|
-
});
|
|
2935
|
-
}
|
|
2936
|
-
#executeFetch(fetchOptions) {
|
|
2937
|
-
this.#updateQuery();
|
|
2938
|
-
let promise = this.#currentQuery.fetch(this.options, fetchOptions);
|
|
2939
|
-
if (!fetchOptions?.throwOnError) {
|
|
2940
|
-
promise = promise.catch(noop);
|
|
2941
|
-
}
|
|
2942
|
-
return promise;
|
|
2943
|
-
}
|
|
2944
|
-
#updateStaleTimeout() {
|
|
2945
|
-
this.#clearStaleTimeout();
|
|
2946
|
-
const staleTime = resolveStaleTime(this.options.staleTime, this.#currentQuery);
|
|
2947
|
-
if (isServer || this.#currentResult.isStale || !isValidTimeout(staleTime)) {
|
|
2948
|
-
return;
|
|
2949
|
-
}
|
|
2950
|
-
const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime);
|
|
2951
|
-
const timeout = time + 1;
|
|
2952
|
-
this.#staleTimeoutId = timeoutManager.setTimeout(() => {
|
|
2953
|
-
if (!this.#currentResult.isStale) {
|
|
2954
|
-
this.updateResult();
|
|
2955
|
-
}
|
|
2956
|
-
}, timeout);
|
|
2957
|
-
}
|
|
2958
|
-
#computeRefetchInterval() {
|
|
2959
|
-
return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.#currentQuery) : this.options.refetchInterval) ?? false;
|
|
2960
|
-
}
|
|
2961
|
-
#updateRefetchInterval(nextInterval) {
|
|
2962
|
-
this.#clearRefetchInterval();
|
|
2963
|
-
this.#currentRefetchInterval = nextInterval;
|
|
2964
|
-
if (isServer || resolveEnabled(this.options.enabled, this.#currentQuery) === false || !isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
|
|
2965
|
-
return;
|
|
2966
|
-
}
|
|
2967
|
-
this.#refetchIntervalId = timeoutManager.setInterval(() => {
|
|
2968
|
-
if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
|
|
2969
|
-
this.#executeFetch();
|
|
2970
|
-
}
|
|
2971
|
-
}, this.#currentRefetchInterval);
|
|
2972
|
-
}
|
|
2973
|
-
#updateTimers() {
|
|
2974
|
-
this.#updateStaleTimeout();
|
|
2975
|
-
this.#updateRefetchInterval(this.#computeRefetchInterval());
|
|
2976
|
-
}
|
|
2977
|
-
#clearStaleTimeout() {
|
|
2978
|
-
if (this.#staleTimeoutId) {
|
|
2979
|
-
timeoutManager.clearTimeout(this.#staleTimeoutId);
|
|
2980
|
-
this.#staleTimeoutId = void 0;
|
|
2981
|
-
}
|
|
2982
|
-
}
|
|
2983
|
-
#clearRefetchInterval() {
|
|
2984
|
-
if (this.#refetchIntervalId) {
|
|
2985
|
-
timeoutManager.clearInterval(this.#refetchIntervalId);
|
|
2986
|
-
this.#refetchIntervalId = void 0;
|
|
2987
|
-
}
|
|
2988
|
-
}
|
|
2989
|
-
createResult(query, options) {
|
|
2990
|
-
const prevQuery = this.#currentQuery;
|
|
2991
|
-
const prevOptions = this.options;
|
|
2992
|
-
const prevResult = this.#currentResult;
|
|
2993
|
-
const prevResultState = this.#currentResultState;
|
|
2994
|
-
const prevResultOptions = this.#currentResultOptions;
|
|
2995
|
-
const queryChange = query !== prevQuery;
|
|
2996
|
-
const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
|
|
2997
|
-
const {
|
|
2998
|
-
state
|
|
2999
|
-
} = query;
|
|
3000
|
-
let newState = {
|
|
3001
|
-
...state
|
|
3002
|
-
};
|
|
3003
|
-
let isPlaceholderData = false;
|
|
3004
|
-
let data;
|
|
3005
|
-
if (options._optimisticResults) {
|
|
3006
|
-
const mounted = this.hasListeners();
|
|
3007
|
-
const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
|
|
3008
|
-
const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
|
|
3009
|
-
if (fetchOnMount || fetchOptionally) {
|
|
3010
|
-
newState = {
|
|
3011
|
-
...newState,
|
|
3012
|
-
...fetchState(state.data, query.options)
|
|
3013
|
-
};
|
|
3014
|
-
}
|
|
3015
|
-
if (options._optimisticResults === "isRestoring") {
|
|
3016
|
-
newState.fetchStatus = "idle";
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
let {
|
|
3020
|
-
error,
|
|
3021
|
-
errorUpdatedAt,
|
|
3022
|
-
status
|
|
3023
|
-
} = newState;
|
|
3024
|
-
data = newState.data;
|
|
3025
|
-
let skipSelect = false;
|
|
3026
|
-
if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
|
|
3027
|
-
let placeholderData;
|
|
3028
|
-
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
3029
|
-
placeholderData = prevResult.data;
|
|
3030
|
-
skipSelect = true;
|
|
3031
|
-
} else {
|
|
3032
|
-
placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
|
|
3033
|
-
}
|
|
3034
|
-
if (placeholderData !== void 0) {
|
|
3035
|
-
status = "success";
|
|
3036
|
-
data = replaceData(prevResult?.data, placeholderData, options);
|
|
3037
|
-
isPlaceholderData = true;
|
|
3038
|
-
}
|
|
3039
|
-
}
|
|
3040
|
-
if (options.select && data !== void 0 && !skipSelect) {
|
|
3041
|
-
if (prevResult && data === prevResultState?.data && options.select === this.#selectFn) {
|
|
3042
|
-
data = this.#selectResult;
|
|
3043
|
-
} else {
|
|
3044
|
-
try {
|
|
3045
|
-
this.#selectFn = options.select;
|
|
3046
|
-
data = options.select(data);
|
|
3047
|
-
data = replaceData(prevResult?.data, data, options);
|
|
3048
|
-
this.#selectResult = data;
|
|
3049
|
-
this.#selectError = null;
|
|
3050
|
-
} catch (selectError) {
|
|
3051
|
-
this.#selectError = selectError;
|
|
3052
|
-
}
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
if (this.#selectError) {
|
|
3056
|
-
error = this.#selectError;
|
|
3057
|
-
data = this.#selectResult;
|
|
3058
|
-
errorUpdatedAt = Date.now();
|
|
3059
|
-
status = "error";
|
|
3060
|
-
}
|
|
3061
|
-
const isFetching = newState.fetchStatus === "fetching";
|
|
3062
|
-
const isPending = status === "pending";
|
|
3063
|
-
const isError = status === "error";
|
|
3064
|
-
const isLoading = isPending && isFetching;
|
|
3065
|
-
const hasData = data !== void 0;
|
|
3066
|
-
const result = {
|
|
3067
|
-
status,
|
|
3068
|
-
fetchStatus: newState.fetchStatus,
|
|
3069
|
-
isPending,
|
|
3070
|
-
isSuccess: status === "success",
|
|
3071
|
-
isError,
|
|
3072
|
-
isInitialLoading: isLoading,
|
|
3073
|
-
isLoading,
|
|
3074
|
-
data,
|
|
3075
|
-
dataUpdatedAt: newState.dataUpdatedAt,
|
|
3076
|
-
error,
|
|
3077
|
-
errorUpdatedAt,
|
|
3078
|
-
failureCount: newState.fetchFailureCount,
|
|
3079
|
-
failureReason: newState.fetchFailureReason,
|
|
3080
|
-
errorUpdateCount: newState.errorUpdateCount,
|
|
3081
|
-
isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
|
|
3082
|
-
isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
|
|
3083
|
-
isFetching,
|
|
3084
|
-
isRefetching: isFetching && !isPending,
|
|
3085
|
-
isLoadingError: isError && !hasData,
|
|
3086
|
-
isPaused: newState.fetchStatus === "paused",
|
|
3087
|
-
isPlaceholderData,
|
|
3088
|
-
isRefetchError: isError && hasData,
|
|
3089
|
-
isStale: isStale(query, options),
|
|
3090
|
-
refetch: this.refetch,
|
|
3091
|
-
promise: this.#currentThenable,
|
|
3092
|
-
isEnabled: resolveEnabled(options.enabled, query) !== false
|
|
3093
|
-
};
|
|
3094
|
-
const nextResult = result;
|
|
3095
|
-
if (this.options.experimental_prefetchInRender) {
|
|
3096
|
-
const hasResultData = nextResult.data !== void 0;
|
|
3097
|
-
const isErrorWithoutData = nextResult.status === "error" && !hasResultData;
|
|
3098
|
-
const finalizeThenableIfPossible = thenable => {
|
|
3099
|
-
if (isErrorWithoutData) {
|
|
3100
|
-
thenable.reject(nextResult.error);
|
|
3101
|
-
} else if (hasResultData) {
|
|
3102
|
-
thenable.resolve(nextResult.data);
|
|
3103
|
-
}
|
|
3104
|
-
};
|
|
3105
|
-
const recreateThenable = () => {
|
|
3106
|
-
const pending = this.#currentThenable = nextResult.promise = pendingThenable();
|
|
3107
|
-
finalizeThenableIfPossible(pending);
|
|
3108
|
-
};
|
|
3109
|
-
const prevThenable = this.#currentThenable;
|
|
3110
|
-
switch (prevThenable.status) {
|
|
3111
|
-
case "pending":
|
|
3112
|
-
if (query.queryHash === prevQuery.queryHash) {
|
|
3113
|
-
finalizeThenableIfPossible(prevThenable);
|
|
3114
|
-
}
|
|
3115
|
-
break;
|
|
3116
|
-
case "fulfilled":
|
|
3117
|
-
if (isErrorWithoutData || nextResult.data !== prevThenable.value) {
|
|
3118
|
-
recreateThenable();
|
|
3119
|
-
}
|
|
3120
|
-
break;
|
|
3121
|
-
case "rejected":
|
|
3122
|
-
if (!isErrorWithoutData || nextResult.error !== prevThenable.reason) {
|
|
3123
|
-
recreateThenable();
|
|
3124
|
-
}
|
|
3125
|
-
break;
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
3128
|
-
return nextResult;
|
|
3129
|
-
}
|
|
3130
|
-
updateResult() {
|
|
3131
|
-
const prevResult = this.#currentResult;
|
|
3132
|
-
const nextResult = this.createResult(this.#currentQuery, this.options);
|
|
3133
|
-
this.#currentResultState = this.#currentQuery.state;
|
|
3134
|
-
this.#currentResultOptions = this.options;
|
|
3135
|
-
if (this.#currentResultState.data !== void 0) {
|
|
3136
|
-
this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
3137
|
-
}
|
|
3138
|
-
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
3139
|
-
return;
|
|
3140
|
-
}
|
|
3141
|
-
this.#currentResult = nextResult;
|
|
3142
|
-
const shouldNotifyListeners = () => {
|
|
3143
|
-
if (!prevResult) {
|
|
3144
|
-
return true;
|
|
3145
|
-
}
|
|
3146
|
-
const {
|
|
3147
|
-
notifyOnChangeProps
|
|
3148
|
-
} = this.options;
|
|
3149
|
-
const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
|
|
3150
|
-
if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) {
|
|
3151
|
-
return true;
|
|
3152
|
-
}
|
|
3153
|
-
const includedProps = new Set(notifyOnChangePropsValue ?? this.#trackedProps);
|
|
3154
|
-
if (this.options.throwOnError) {
|
|
3155
|
-
includedProps.add("error");
|
|
3156
|
-
}
|
|
3157
|
-
return Object.keys(this.#currentResult).some(key => {
|
|
3158
|
-
const typedKey = key;
|
|
3159
|
-
const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
|
|
3160
|
-
return changed && includedProps.has(typedKey);
|
|
3161
|
-
});
|
|
3162
|
-
};
|
|
3163
|
-
this.#notify({
|
|
3164
|
-
listeners: shouldNotifyListeners()
|
|
3165
|
-
});
|
|
3166
|
-
}
|
|
3167
|
-
#updateQuery() {
|
|
3168
|
-
const query = this.#client.getQueryCache().build(this.#client, this.options);
|
|
3169
|
-
if (query === this.#currentQuery) {
|
|
3170
|
-
return;
|
|
3171
|
-
}
|
|
3172
|
-
const prevQuery = this.#currentQuery;
|
|
3173
|
-
this.#currentQuery = query;
|
|
3174
|
-
this.#currentQueryInitialState = query.state;
|
|
3175
|
-
if (this.hasListeners()) {
|
|
3176
|
-
prevQuery?.removeObserver(this);
|
|
3177
|
-
query.addObserver(this);
|
|
3178
|
-
}
|
|
3179
|
-
}
|
|
3180
|
-
onQueryUpdate() {
|
|
3181
|
-
this.updateResult();
|
|
3182
|
-
if (this.hasListeners()) {
|
|
3183
|
-
this.#updateTimers();
|
|
3184
|
-
}
|
|
3185
|
-
}
|
|
3186
|
-
#notify(notifyOptions) {
|
|
3187
|
-
notifyManager.batch(() => {
|
|
3188
|
-
if (notifyOptions.listeners) {
|
|
3189
|
-
this.listeners.forEach(listener => {
|
|
3190
|
-
listener(this.#currentResult);
|
|
3191
|
-
});
|
|
3192
|
-
}
|
|
3193
|
-
this.#client.getQueryCache().notify({
|
|
3194
|
-
query: this.#currentQuery,
|
|
3195
|
-
type: "observerResultsUpdated"
|
|
3196
|
-
});
|
|
3197
|
-
});
|
|
3198
|
-
}
|
|
3199
|
-
};
|
|
3200
|
-
function shouldLoadOnMount(query, options) {
|
|
3201
|
-
return resolveEnabled(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && options.retryOnMount === false);
|
|
3202
|
-
}
|
|
3203
|
-
function shouldFetchOnMount(query, options) {
|
|
3204
|
-
return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
|
|
3205
|
-
}
|
|
3206
|
-
function shouldFetchOn(query, options, field) {
|
|
3207
|
-
if (resolveEnabled(options.enabled, query) !== false && resolveStaleTime(options.staleTime, query) !== "static") {
|
|
3208
|
-
const value = typeof field === "function" ? field(query) : field;
|
|
3209
|
-
return value === "always" || value !== false && isStale(query, options);
|
|
3210
|
-
}
|
|
3211
|
-
return false;
|
|
3212
|
-
}
|
|
3213
|
-
function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
|
|
3214
|
-
return (query !== prevQuery || resolveEnabled(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
|
|
3215
|
-
}
|
|
3216
|
-
function isStale(query, options) {
|
|
3217
|
-
return resolveEnabled(options.enabled, query) !== false && query.isStaleByTime(resolveStaleTime(options.staleTime, query));
|
|
3218
|
-
}
|
|
3219
|
-
function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
|
|
3220
|
-
if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
|
|
3221
|
-
return true;
|
|
3222
|
-
}
|
|
3223
|
-
return false;
|
|
3224
1493
|
}const usePageFormManager = ({
|
|
3225
1494
|
form,
|
|
3226
1495
|
pageId,
|