@storybook/react-native 10.2.2-alpha.5 → 10.2.2-next.6
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/index.js +708 -530
- package/package.json +14 -15
package/dist/index.js
CHANGED
|
@@ -51,6 +51,9 @@ var Platform = {
|
|
|
51
51
|
return true;
|
|
52
52
|
}
|
|
53
53
|
return false;
|
|
54
|
+
},
|
|
55
|
+
get Version() {
|
|
56
|
+
return "0.0.0";
|
|
54
57
|
}
|
|
55
58
|
};
|
|
56
59
|
var Platform_default = Platform;
|
|
@@ -91,609 +94,716 @@ var import_react_native_theming = require("@storybook/react-native-theming");
|
|
|
91
94
|
var import_react3 = __toESM(require("react"));
|
|
92
95
|
var import_react_native2 = require("react-native");
|
|
93
96
|
|
|
94
|
-
// ../../node_modules/jotai/esm/vanilla.mjs
|
|
97
|
+
// ../../node_modules/jotai/esm/vanilla/internals.mjs
|
|
95
98
|
var import_meta = {};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
99
|
+
function hasInitialValue(atom2) {
|
|
100
|
+
return "init" in atom2;
|
|
101
|
+
}
|
|
102
|
+
function isActuallyWritableAtom(atom2) {
|
|
103
|
+
return !!atom2.write;
|
|
104
|
+
}
|
|
105
|
+
function isAtomStateInitialized(atomState) {
|
|
106
|
+
return "v" in atomState || "e" in atomState;
|
|
107
|
+
}
|
|
108
|
+
function returnAtomValue(atomState) {
|
|
109
|
+
if ("e" in atomState) {
|
|
110
|
+
throw atomState.e;
|
|
111
|
+
}
|
|
112
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production" && !("v" in atomState)) {
|
|
113
|
+
throw new Error("[Bug] atom state is not initialized");
|
|
114
|
+
}
|
|
115
|
+
return atomState.v;
|
|
116
|
+
}
|
|
117
|
+
var promiseStateMap = /* @__PURE__ */ new WeakMap();
|
|
118
|
+
function isPendingPromise(value) {
|
|
119
|
+
var _a;
|
|
120
|
+
return isPromiseLike(value) && !!((_a = promiseStateMap.get(value)) == null ? void 0 : _a[0]);
|
|
121
|
+
}
|
|
122
|
+
function abortPromise(promise) {
|
|
123
|
+
const promiseState = promiseStateMap.get(promise);
|
|
124
|
+
if (promiseState == null ? void 0 : promiseState[0]) {
|
|
125
|
+
promiseState[0] = false;
|
|
126
|
+
promiseState[1].forEach((fn) => fn());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function registerAbortHandler(promise, abortHandler) {
|
|
130
|
+
let promiseState = promiseStateMap.get(promise);
|
|
131
|
+
if (!promiseState) {
|
|
132
|
+
promiseState = [true, /* @__PURE__ */ new Set()];
|
|
133
|
+
promiseStateMap.set(promise, promiseState);
|
|
134
|
+
const settle = () => {
|
|
135
|
+
promiseState[0] = false;
|
|
114
136
|
};
|
|
137
|
+
promise.then(settle, settle);
|
|
115
138
|
}
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
promiseState[1].add(abortHandler);
|
|
140
|
+
}
|
|
141
|
+
function isPromiseLike(p) {
|
|
142
|
+
return typeof (p == null ? void 0 : p.then) === "function";
|
|
143
|
+
}
|
|
144
|
+
function addPendingPromiseToDependency(atom2, promise, dependencyAtomState) {
|
|
145
|
+
if (!dependencyAtomState.p.has(atom2)) {
|
|
146
|
+
dependencyAtomState.p.add(atom2);
|
|
147
|
+
const cleanup = () => dependencyAtomState.p.delete(atom2);
|
|
148
|
+
promise.then(cleanup, cleanup);
|
|
118
149
|
}
|
|
119
|
-
return config;
|
|
120
150
|
}
|
|
121
|
-
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
promise.catch(() => {
|
|
127
|
-
}).finally(() => cancelPromiseMap.delete(promise));
|
|
128
|
-
};
|
|
129
|
-
var cancelPromise = (promise, next) => {
|
|
130
|
-
const cancel = cancelPromiseMap.get(promise);
|
|
131
|
-
if (cancel) {
|
|
132
|
-
cancelPromiseMap.delete(promise);
|
|
133
|
-
cancel(next);
|
|
151
|
+
function getMountedOrPendingDependents(atom2, atomState, mountedMap) {
|
|
152
|
+
var _a;
|
|
153
|
+
const dependents = /* @__PURE__ */ new Set();
|
|
154
|
+
for (const a of ((_a = mountedMap.get(atom2)) == null ? void 0 : _a.t) || []) {
|
|
155
|
+
dependents.add(a);
|
|
134
156
|
}
|
|
157
|
+
for (const atomWithPendingPromise of atomState.p) {
|
|
158
|
+
dependents.add(atomWithPendingPromise);
|
|
159
|
+
}
|
|
160
|
+
return dependents;
|
|
161
|
+
}
|
|
162
|
+
var BUILDING_BLOCK_atomRead = (_store, atom2, ...params) => atom2.read(...params);
|
|
163
|
+
var BUILDING_BLOCK_atomWrite = (_store, atom2, ...params) => atom2.write(...params);
|
|
164
|
+
var BUILDING_BLOCK_atomOnInit = (store, atom2) => {
|
|
165
|
+
var _a;
|
|
166
|
+
return (_a = atom2.INTERNAL_onInit) == null ? void 0 : _a.call(atom2, store);
|
|
135
167
|
};
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
var rejectPromise = (promise, e) => {
|
|
141
|
-
promise.status = "rejected";
|
|
142
|
-
promise.reason = e;
|
|
168
|
+
var BUILDING_BLOCK_atomOnMount = (_store, atom2, setAtom) => {
|
|
169
|
+
var _a;
|
|
170
|
+
return (_a = atom2.onMount) == null ? void 0 : _a.call(atom2, setAtom);
|
|
143
171
|
};
|
|
144
|
-
var
|
|
145
|
-
var
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if ("
|
|
151
|
-
throw
|
|
172
|
+
var BUILDING_BLOCK_ensureAtomState = (store, atom2) => {
|
|
173
|
+
var _a;
|
|
174
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
175
|
+
const atomStateMap = buildingBlocks[0];
|
|
176
|
+
const storeHooks = buildingBlocks[6];
|
|
177
|
+
const atomOnInit = buildingBlocks[9];
|
|
178
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production" && !atom2) {
|
|
179
|
+
throw new Error("Atom is undefined or null");
|
|
152
180
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
let storeListenersRev2;
|
|
160
|
-
let mountedAtoms;
|
|
161
|
-
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
162
|
-
storeListenersRev2 = /* @__PURE__ */ new Set();
|
|
163
|
-
mountedAtoms = /* @__PURE__ */ new Set();
|
|
181
|
+
let atomState = atomStateMap.get(atom2);
|
|
182
|
+
if (!atomState) {
|
|
183
|
+
atomState = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 };
|
|
184
|
+
atomStateMap.set(atom2, atomState);
|
|
185
|
+
(_a = storeHooks.i) == null ? void 0 : _a.call(storeHooks, atom2);
|
|
186
|
+
atomOnInit == null ? void 0 : atomOnInit(store, atom2);
|
|
164
187
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
return atomState;
|
|
189
|
+
};
|
|
190
|
+
var BUILDING_BLOCK_flushCallbacks = (store) => {
|
|
191
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
192
|
+
const mountedMap = buildingBlocks[1];
|
|
193
|
+
const changedAtoms = buildingBlocks[3];
|
|
194
|
+
const mountCallbacks = buildingBlocks[4];
|
|
195
|
+
const unmountCallbacks = buildingBlocks[5];
|
|
196
|
+
const storeHooks = buildingBlocks[6];
|
|
197
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
198
|
+
const errors = [];
|
|
199
|
+
const call = (fn) => {
|
|
200
|
+
try {
|
|
201
|
+
fn();
|
|
202
|
+
} catch (e) {
|
|
203
|
+
errors.push(e);
|
|
169
204
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
|
|
205
|
+
};
|
|
206
|
+
do {
|
|
207
|
+
if (storeHooks.f) {
|
|
208
|
+
call(storeHooks.f);
|
|
209
|
+
}
|
|
210
|
+
const callbacks = /* @__PURE__ */ new Set();
|
|
211
|
+
const add = callbacks.add.bind(callbacks);
|
|
212
|
+
changedAtoms.forEach((atom2) => {
|
|
213
|
+
var _a;
|
|
214
|
+
return (_a = mountedMap.get(atom2)) == null ? void 0 : _a.l.forEach(add);
|
|
215
|
+
});
|
|
216
|
+
changedAtoms.clear();
|
|
217
|
+
unmountCallbacks.forEach(add);
|
|
218
|
+
unmountCallbacks.clear();
|
|
219
|
+
mountCallbacks.forEach(add);
|
|
220
|
+
mountCallbacks.clear();
|
|
221
|
+
callbacks.forEach(call);
|
|
222
|
+
if (changedAtoms.size) {
|
|
223
|
+
recomputeInvalidatedAtoms(store);
|
|
224
|
+
}
|
|
225
|
+
} while (changedAtoms.size || unmountCallbacks.size || mountCallbacks.size);
|
|
226
|
+
if (errors.length) {
|
|
227
|
+
throw new AggregateError(errors);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var BUILDING_BLOCK_recomputeInvalidatedAtoms = (store) => {
|
|
231
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
232
|
+
const mountedMap = buildingBlocks[1];
|
|
233
|
+
const invalidatedAtoms = buildingBlocks[2];
|
|
234
|
+
const changedAtoms = buildingBlocks[3];
|
|
235
|
+
const ensureAtomState = buildingBlocks[11];
|
|
236
|
+
const readAtomState = buildingBlocks[14];
|
|
237
|
+
const mountDependencies = buildingBlocks[17];
|
|
238
|
+
const topSortedReversed = [];
|
|
239
|
+
const visiting = /* @__PURE__ */ new WeakSet();
|
|
240
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
241
|
+
const stack = Array.from(changedAtoms);
|
|
242
|
+
while (stack.length) {
|
|
243
|
+
const a = stack[stack.length - 1];
|
|
244
|
+
const aState = ensureAtomState(store, a);
|
|
245
|
+
if (visited.has(a)) {
|
|
246
|
+
stack.pop();
|
|
247
|
+
continue;
|
|
174
248
|
}
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
249
|
+
if (visiting.has(a)) {
|
|
250
|
+
if (invalidatedAtoms.get(a) === aState.n) {
|
|
251
|
+
topSortedReversed.push([a, aState]);
|
|
252
|
+
} else if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production" && invalidatedAtoms.has(a)) {
|
|
253
|
+
throw new Error("[Bug] invalidated atom exists");
|
|
179
254
|
}
|
|
255
|
+
visited.add(a);
|
|
256
|
+
stack.pop();
|
|
257
|
+
continue;
|
|
180
258
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
nextDependencies.forEach((aState, a) => {
|
|
186
|
-
if (!aState && a === atom2) {
|
|
187
|
-
aState = nextAtomState;
|
|
259
|
+
visiting.add(a);
|
|
260
|
+
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
261
|
+
if (!visiting.has(d)) {
|
|
262
|
+
stack.push(d);
|
|
188
263
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
for (let i = topSortedReversed.length - 1; i >= 0; --i) {
|
|
267
|
+
const [a, aState] = topSortedReversed[i];
|
|
268
|
+
let hasChangedDeps = false;
|
|
269
|
+
for (const dep of aState.d.keys()) {
|
|
270
|
+
if (dep !== a && changedAtoms.has(dep)) {
|
|
271
|
+
hasChangedDeps = true;
|
|
272
|
+
break;
|
|
196
273
|
}
|
|
197
|
-
});
|
|
198
|
-
if (changed || nextAtomState.d.size !== dependencies.size) {
|
|
199
|
-
nextAtomState.d = dependencies;
|
|
200
274
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const nextAtomState = {
|
|
205
|
-
d: (prevAtomState == null ? void 0 : prevAtomState.d) || /* @__PURE__ */ new Map(),
|
|
206
|
-
v: value
|
|
207
|
-
};
|
|
208
|
-
if (nextDependencies) {
|
|
209
|
-
updateDependencies(atom2, nextAtomState, nextDependencies);
|
|
275
|
+
if (hasChangedDeps) {
|
|
276
|
+
readAtomState(store, a);
|
|
277
|
+
mountDependencies(store, a);
|
|
210
278
|
}
|
|
211
|
-
|
|
212
|
-
|
|
279
|
+
invalidatedAtoms.delete(a);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
var storeMutationSet = /* @__PURE__ */ new WeakSet();
|
|
283
|
+
var BUILDING_BLOCK_readAtomState = (store, atom2) => {
|
|
284
|
+
var _a, _b;
|
|
285
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
286
|
+
const mountedMap = buildingBlocks[1];
|
|
287
|
+
const invalidatedAtoms = buildingBlocks[2];
|
|
288
|
+
const changedAtoms = buildingBlocks[3];
|
|
289
|
+
const storeHooks = buildingBlocks[6];
|
|
290
|
+
const atomRead = buildingBlocks[7];
|
|
291
|
+
const ensureAtomState = buildingBlocks[11];
|
|
292
|
+
const flushCallbacks = buildingBlocks[12];
|
|
293
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
294
|
+
const readAtomState = buildingBlocks[14];
|
|
295
|
+
const writeAtomState = buildingBlocks[16];
|
|
296
|
+
const mountDependencies = buildingBlocks[17];
|
|
297
|
+
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
298
|
+
const atomState = ensureAtomState(store, atom2);
|
|
299
|
+
if (isAtomStateInitialized(atomState)) {
|
|
300
|
+
if (mountedMap.has(atom2) && invalidatedAtoms.get(atom2) !== atomState.n) {
|
|
301
|
+
return atomState;
|
|
213
302
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
303
|
+
let hasChangedDeps = false;
|
|
304
|
+
for (const [a, n] of atomState.d) {
|
|
305
|
+
if (readAtomState(store, a).n !== n) {
|
|
306
|
+
hasChangedDeps = true;
|
|
307
|
+
break;
|
|
219
308
|
}
|
|
220
309
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
};
|
|
224
|
-
const setAtomValueOrPromise = (atom2, valueOrPromise, nextDependencies, abortPromise) => {
|
|
225
|
-
if (isPromiseLike(valueOrPromise)) {
|
|
226
|
-
let continuePromise;
|
|
227
|
-
const updatePromiseDependencies = () => {
|
|
228
|
-
const prevAtomState = getAtomState(atom2);
|
|
229
|
-
if (!hasPromiseAtomValue(prevAtomState) || prevAtomState.v !== promise) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
const nextAtomState = setAtomValue(
|
|
233
|
-
atom2,
|
|
234
|
-
promise,
|
|
235
|
-
nextDependencies
|
|
236
|
-
);
|
|
237
|
-
if (mountedMap.has(atom2) && prevAtomState.d !== nextAtomState.d) {
|
|
238
|
-
mountDependencies(atom2, nextAtomState, prevAtomState.d);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
const promise = new Promise((resolve, reject) => {
|
|
242
|
-
let settled = false;
|
|
243
|
-
valueOrPromise.then(
|
|
244
|
-
(v) => {
|
|
245
|
-
if (!settled) {
|
|
246
|
-
settled = true;
|
|
247
|
-
resolvePromise(promise, v);
|
|
248
|
-
resolve(v);
|
|
249
|
-
updatePromiseDependencies();
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
(e) => {
|
|
253
|
-
if (!settled) {
|
|
254
|
-
settled = true;
|
|
255
|
-
rejectPromise(promise, e);
|
|
256
|
-
reject(e);
|
|
257
|
-
updatePromiseDependencies();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
continuePromise = (next) => {
|
|
262
|
-
if (!settled) {
|
|
263
|
-
settled = true;
|
|
264
|
-
next.then(
|
|
265
|
-
(v) => resolvePromise(promise, v),
|
|
266
|
-
(e) => rejectPromise(promise, e)
|
|
267
|
-
);
|
|
268
|
-
resolve(next);
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
});
|
|
272
|
-
promise.orig = valueOrPromise;
|
|
273
|
-
promise.status = "pending";
|
|
274
|
-
registerCancelPromise(promise, (next) => {
|
|
275
|
-
if (next) {
|
|
276
|
-
continuePromise(next);
|
|
277
|
-
}
|
|
278
|
-
abortPromise == null ? void 0 : abortPromise();
|
|
279
|
-
});
|
|
280
|
-
return setAtomValue(atom2, promise, nextDependencies);
|
|
310
|
+
if (!hasChangedDeps) {
|
|
311
|
+
return atomState;
|
|
281
312
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (nextDependencies) {
|
|
291
|
-
updateDependencies(atom2, nextAtomState, nextDependencies);
|
|
313
|
+
}
|
|
314
|
+
atomState.d.clear();
|
|
315
|
+
let isSync = true;
|
|
316
|
+
function mountDependenciesIfAsync() {
|
|
317
|
+
if (mountedMap.has(atom2)) {
|
|
318
|
+
mountDependencies(store, atom2);
|
|
319
|
+
recomputeInvalidatedAtoms(store);
|
|
320
|
+
flushCallbacks(store);
|
|
292
321
|
}
|
|
293
|
-
|
|
294
|
-
|
|
322
|
+
}
|
|
323
|
+
function getter(a) {
|
|
324
|
+
var _a2;
|
|
325
|
+
if (a === atom2) {
|
|
326
|
+
const aState2 = ensureAtomState(store, a);
|
|
327
|
+
if (!isAtomStateInitialized(aState2)) {
|
|
328
|
+
if (hasInitialValue(a)) {
|
|
329
|
+
setAtomStateValueOrPromise(store, a, a.init);
|
|
330
|
+
} else {
|
|
331
|
+
throw new Error("no atom init");
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return returnAtomValue(aState2);
|
|
295
335
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
336
|
+
const aState = readAtomState(store, a);
|
|
337
|
+
try {
|
|
338
|
+
return returnAtomValue(aState);
|
|
339
|
+
} finally {
|
|
340
|
+
atomState.d.set(a, aState.n);
|
|
341
|
+
if (isPendingPromise(atomState.v)) {
|
|
342
|
+
addPendingPromiseToDependency(atom2, atomState.v, aState);
|
|
343
|
+
}
|
|
302
344
|
if (mountedMap.has(atom2)) {
|
|
303
|
-
|
|
345
|
+
(_a2 = mountedMap.get(a)) == null ? void 0 : _a2.t.add(atom2);
|
|
304
346
|
}
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
const aState = readAtomState(a);
|
|
310
|
-
return aState === s || isEqualAtomValue(aState, s);
|
|
311
|
-
})) {
|
|
312
|
-
return atomState;
|
|
347
|
+
if (!isSync) {
|
|
348
|
+
mountDependenciesIfAsync();
|
|
313
349
|
}
|
|
314
350
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return returnAtomValue(aState2);
|
|
323
|
-
}
|
|
324
|
-
if (hasInitialValue(a)) {
|
|
325
|
-
nextDependencies.set(a, void 0);
|
|
326
|
-
return a.init;
|
|
327
|
-
}
|
|
328
|
-
throw new Error("no atom init");
|
|
351
|
+
}
|
|
352
|
+
let controller;
|
|
353
|
+
let setSelf;
|
|
354
|
+
const options = {
|
|
355
|
+
get signal() {
|
|
356
|
+
if (!controller) {
|
|
357
|
+
controller = new AbortController();
|
|
329
358
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if (!isSync) {
|
|
353
|
-
return writeAtom(atom2, ...args);
|
|
359
|
+
return controller.signal;
|
|
360
|
+
},
|
|
361
|
+
get setSelf() {
|
|
362
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
363
|
+
console.warn(
|
|
364
|
+
"[DEPRECATED] setSelf is deprecated and will be removed in v3."
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production" && !isActuallyWritableAtom(atom2)) {
|
|
368
|
+
console.warn("setSelf function cannot be used with read-only atom");
|
|
369
|
+
}
|
|
370
|
+
if (!setSelf && isActuallyWritableAtom(atom2)) {
|
|
371
|
+
setSelf = (...args) => {
|
|
372
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production" && isSync) {
|
|
373
|
+
console.warn("setSelf function cannot be called in sync");
|
|
374
|
+
}
|
|
375
|
+
if (!isSync) {
|
|
376
|
+
try {
|
|
377
|
+
return writeAtomState(store, atom2, ...args);
|
|
378
|
+
} finally {
|
|
379
|
+
recomputeInvalidatedAtoms(store);
|
|
380
|
+
flushCallbacks(store);
|
|
354
381
|
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
return setSelf;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
358
384
|
}
|
|
359
|
-
|
|
360
|
-
try {
|
|
361
|
-
const valueOrPromise = atom2.read(getter, options);
|
|
362
|
-
return setAtomValueOrPromise(
|
|
363
|
-
atom2,
|
|
364
|
-
valueOrPromise,
|
|
365
|
-
nextDependencies,
|
|
366
|
-
() => controller == null ? void 0 : controller.abort()
|
|
367
|
-
);
|
|
368
|
-
} catch (error) {
|
|
369
|
-
return setAtomError(atom2, error, nextDependencies);
|
|
370
|
-
} finally {
|
|
371
|
-
isSync = false;
|
|
385
|
+
return setSelf;
|
|
372
386
|
}
|
|
373
387
|
};
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
mounted = mountAtom(atom2);
|
|
388
|
+
const prevEpochNumber = atomState.n;
|
|
389
|
+
try {
|
|
390
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
391
|
+
storeMutationSet.delete(store);
|
|
379
392
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (mounted && canUnmountAtom(atom2, mounted)) {
|
|
386
|
-
unmountAtom(atom2);
|
|
393
|
+
const valueOrPromise = atomRead(store, atom2, getter, options);
|
|
394
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production" && storeMutationSet.has(store)) {
|
|
395
|
+
console.warn(
|
|
396
|
+
"Detected store mutation during atom read. This is not supported."
|
|
397
|
+
);
|
|
387
398
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const setter = (a, ...args2) => {
|
|
445
|
-
let r;
|
|
399
|
+
setAtomStateValueOrPromise(store, atom2, valueOrPromise);
|
|
400
|
+
if (isPromiseLike(valueOrPromise)) {
|
|
401
|
+
registerAbortHandler(valueOrPromise, () => controller == null ? void 0 : controller.abort());
|
|
402
|
+
valueOrPromise.then(mountDependenciesIfAsync, mountDependenciesIfAsync);
|
|
403
|
+
}
|
|
404
|
+
(_a = storeHooks.r) == null ? void 0 : _a.call(storeHooks, atom2);
|
|
405
|
+
return atomState;
|
|
406
|
+
} catch (error) {
|
|
407
|
+
delete atomState.v;
|
|
408
|
+
atomState.e = error;
|
|
409
|
+
++atomState.n;
|
|
410
|
+
return atomState;
|
|
411
|
+
} finally {
|
|
412
|
+
isSync = false;
|
|
413
|
+
if (prevEpochNumber !== atomState.n && invalidatedAtoms.get(atom2) === prevEpochNumber) {
|
|
414
|
+
invalidatedAtoms.set(atom2, atomState.n);
|
|
415
|
+
changedAtoms.add(atom2);
|
|
416
|
+
(_b = storeHooks.c) == null ? void 0 : _b.call(storeHooks, atom2);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var BUILDING_BLOCK_invalidateDependents = (store, atom2) => {
|
|
421
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
422
|
+
const mountedMap = buildingBlocks[1];
|
|
423
|
+
const invalidatedAtoms = buildingBlocks[2];
|
|
424
|
+
const ensureAtomState = buildingBlocks[11];
|
|
425
|
+
const stack = [atom2];
|
|
426
|
+
while (stack.length) {
|
|
427
|
+
const a = stack.pop();
|
|
428
|
+
const aState = ensureAtomState(store, a);
|
|
429
|
+
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
430
|
+
const dState = ensureAtomState(store, d);
|
|
431
|
+
invalidatedAtoms.set(d, dState.n);
|
|
432
|
+
stack.push(d);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
var BUILDING_BLOCK_writeAtomState = (store, atom2, ...args) => {
|
|
437
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
438
|
+
const changedAtoms = buildingBlocks[3];
|
|
439
|
+
const storeHooks = buildingBlocks[6];
|
|
440
|
+
const atomWrite = buildingBlocks[8];
|
|
441
|
+
const ensureAtomState = buildingBlocks[11];
|
|
442
|
+
const flushCallbacks = buildingBlocks[12];
|
|
443
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
444
|
+
const readAtomState = buildingBlocks[14];
|
|
445
|
+
const invalidateDependents = buildingBlocks[15];
|
|
446
|
+
const writeAtomState = buildingBlocks[16];
|
|
447
|
+
const mountDependencies = buildingBlocks[17];
|
|
448
|
+
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
449
|
+
let isSync = true;
|
|
450
|
+
const getter = (a) => returnAtomValue(readAtomState(store, a));
|
|
451
|
+
const setter = (a, ...args2) => {
|
|
452
|
+
var _a;
|
|
453
|
+
const aState = ensureAtomState(store, a);
|
|
454
|
+
try {
|
|
446
455
|
if (a === atom2) {
|
|
447
456
|
if (!hasInitialValue(a)) {
|
|
448
457
|
throw new Error("atom not writable");
|
|
449
458
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
459
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
460
|
+
storeMutationSet.add(store);
|
|
461
|
+
}
|
|
462
|
+
const prevEpochNumber = aState.n;
|
|
463
|
+
const v = args2[0];
|
|
464
|
+
setAtomStateValueOrPromise(store, a, v);
|
|
465
|
+
mountDependencies(store, a);
|
|
466
|
+
if (prevEpochNumber !== aState.n) {
|
|
467
|
+
changedAtoms.add(a);
|
|
468
|
+
invalidateDependents(store, a);
|
|
469
|
+
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
454
470
|
}
|
|
471
|
+
return void 0;
|
|
455
472
|
} else {
|
|
456
|
-
|
|
473
|
+
return writeAtomState(store, a, ...args2);
|
|
457
474
|
}
|
|
475
|
+
} finally {
|
|
458
476
|
if (!isSync) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
storeListenersRev2.forEach(
|
|
462
|
-
(l) => l({ type: "async-write", flushed })
|
|
463
|
-
);
|
|
464
|
-
}
|
|
477
|
+
recomputeInvalidatedAtoms(store);
|
|
478
|
+
flushCallbacks(store);
|
|
465
479
|
}
|
|
466
|
-
return r;
|
|
467
|
-
};
|
|
468
|
-
const result = atom2.write(getter, setter, ...args);
|
|
469
|
-
isSync = false;
|
|
470
|
-
return result;
|
|
471
|
-
};
|
|
472
|
-
const writeAtom = (atom2, ...args) => {
|
|
473
|
-
const result = writeAtomState(atom2, ...args);
|
|
474
|
-
const flushed = flushPending();
|
|
475
|
-
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
476
|
-
storeListenersRev2.forEach(
|
|
477
|
-
(l) => l({ type: "write", flushed })
|
|
478
|
-
);
|
|
479
480
|
}
|
|
480
|
-
return result;
|
|
481
481
|
};
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
482
|
+
try {
|
|
483
|
+
return atomWrite(store, atom2, getter, setter, ...args);
|
|
484
|
+
} finally {
|
|
485
|
+
isSync = false;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
var BUILDING_BLOCK_mountDependencies = (store, atom2) => {
|
|
489
|
+
var _a;
|
|
490
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
491
|
+
const mountedMap = buildingBlocks[1];
|
|
492
|
+
const changedAtoms = buildingBlocks[3];
|
|
493
|
+
const storeHooks = buildingBlocks[6];
|
|
494
|
+
const ensureAtomState = buildingBlocks[11];
|
|
495
|
+
const invalidateDependents = buildingBlocks[15];
|
|
496
|
+
const mountAtom = buildingBlocks[18];
|
|
497
|
+
const unmountAtom = buildingBlocks[19];
|
|
498
|
+
const atomState = ensureAtomState(store, atom2);
|
|
499
|
+
const mounted = mountedMap.get(atom2);
|
|
500
|
+
if (mounted && !isPendingPromise(atomState.v)) {
|
|
501
|
+
for (const [a, n] of atomState.d) {
|
|
502
|
+
if (!mounted.d.has(a)) {
|
|
503
|
+
const aState = ensureAtomState(store, a);
|
|
504
|
+
const aMounted = mountAtom(store, a);
|
|
488
505
|
aMounted.t.add(atom2);
|
|
489
|
-
|
|
490
|
-
if (
|
|
491
|
-
|
|
506
|
+
mounted.d.add(a);
|
|
507
|
+
if (n !== aState.n) {
|
|
508
|
+
changedAtoms.add(a);
|
|
509
|
+
invalidateDependents(store, a);
|
|
510
|
+
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
492
511
|
}
|
|
493
512
|
}
|
|
494
|
-
});
|
|
495
|
-
readAtomState(atom2);
|
|
496
|
-
const mounted = {
|
|
497
|
-
t: new Set(initialDependent && [initialDependent]),
|
|
498
|
-
l: /* @__PURE__ */ new Set()
|
|
499
|
-
};
|
|
500
|
-
mountedMap.set(atom2, mounted);
|
|
501
|
-
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
502
|
-
mountedAtoms.add(atom2);
|
|
503
|
-
}
|
|
504
|
-
if (isActuallyWritableAtom(atom2) && atom2.onMount) {
|
|
505
|
-
const { onMount } = atom2;
|
|
506
|
-
queue.push(() => {
|
|
507
|
-
const onUnmount = onMount((...args) => writeAtom(atom2, ...args));
|
|
508
|
-
if (onUnmount) {
|
|
509
|
-
mounted.u = onUnmount;
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
513
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
var _a;
|
|
520
|
-
const onUnmount = (_a = mountedMap.get(atom2)) == null ? void 0 : _a.u;
|
|
521
|
-
if (onUnmount) {
|
|
522
|
-
onUnmount();
|
|
514
|
+
for (const a of mounted.d) {
|
|
515
|
+
if (!atomState.d.has(a)) {
|
|
516
|
+
mounted.d.delete(a);
|
|
517
|
+
const aMounted = unmountAtom(store, a);
|
|
518
|
+
aMounted == null ? void 0 : aMounted.t.delete(atom2);
|
|
519
|
+
}
|
|
523
520
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
var BUILDING_BLOCK_mountAtom = (store, atom2) => {
|
|
524
|
+
var _a;
|
|
525
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
526
|
+
const mountedMap = buildingBlocks[1];
|
|
527
|
+
const mountCallbacks = buildingBlocks[4];
|
|
528
|
+
const storeHooks = buildingBlocks[6];
|
|
529
|
+
const atomOnMount = buildingBlocks[10];
|
|
530
|
+
const ensureAtomState = buildingBlocks[11];
|
|
531
|
+
const flushCallbacks = buildingBlocks[12];
|
|
532
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
533
|
+
const readAtomState = buildingBlocks[14];
|
|
534
|
+
const writeAtomState = buildingBlocks[16];
|
|
535
|
+
const mountAtom = buildingBlocks[18];
|
|
536
|
+
const atomState = ensureAtomState(store, atom2);
|
|
537
|
+
let mounted = mountedMap.get(atom2);
|
|
538
|
+
if (!mounted) {
|
|
539
|
+
readAtomState(store, atom2);
|
|
540
|
+
for (const a of atomState.d.keys()) {
|
|
541
|
+
const aMounted = mountAtom(store, a);
|
|
542
|
+
aMounted.t.add(atom2);
|
|
527
543
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
544
|
+
mounted = {
|
|
545
|
+
l: /* @__PURE__ */ new Set(),
|
|
546
|
+
d: new Set(atomState.d.keys()),
|
|
547
|
+
t: /* @__PURE__ */ new Set()
|
|
548
|
+
};
|
|
549
|
+
mountedMap.set(atom2, mounted);
|
|
550
|
+
if (isActuallyWritableAtom(atom2)) {
|
|
551
|
+
const processOnMount = () => {
|
|
552
|
+
let isSync = true;
|
|
553
|
+
const setAtom = (...args) => {
|
|
554
|
+
try {
|
|
555
|
+
return writeAtomState(store, atom2, ...args);
|
|
556
|
+
} finally {
|
|
557
|
+
if (!isSync) {
|
|
558
|
+
recomputeInvalidatedAtoms(store);
|
|
559
|
+
flushCallbacks(store);
|
|
540
560
|
}
|
|
541
561
|
}
|
|
562
|
+
};
|
|
563
|
+
try {
|
|
564
|
+
const onUnmount = atomOnMount(store, atom2, setAtom);
|
|
565
|
+
if (onUnmount) {
|
|
566
|
+
mounted.u = () => {
|
|
567
|
+
isSync = true;
|
|
568
|
+
try {
|
|
569
|
+
onUnmount();
|
|
570
|
+
} finally {
|
|
571
|
+
isSync = false;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
} finally {
|
|
576
|
+
isSync = false;
|
|
542
577
|
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
console.warn("[Bug] could not find atom state to unmount", atom2);
|
|
578
|
+
};
|
|
579
|
+
mountCallbacks.add(processOnMount);
|
|
546
580
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
});
|
|
570
|
-
maybeUnmountAtomSet.forEach((a) => {
|
|
571
|
-
const mounted = mountedMap.get(a);
|
|
572
|
-
if (mounted && canUnmountAtom(a, mounted)) {
|
|
573
|
-
unmountAtom(a);
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
};
|
|
577
|
-
const flushPending = () => {
|
|
578
|
-
let flushed;
|
|
579
|
-
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
580
|
-
flushed = /* @__PURE__ */ new Set();
|
|
581
|
+
(_a = storeHooks.m) == null ? void 0 : _a.call(storeHooks, atom2);
|
|
582
|
+
}
|
|
583
|
+
return mounted;
|
|
584
|
+
};
|
|
585
|
+
var BUILDING_BLOCK_unmountAtom = (store, atom2) => {
|
|
586
|
+
var _a, _b;
|
|
587
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
588
|
+
const mountedMap = buildingBlocks[1];
|
|
589
|
+
const unmountCallbacks = buildingBlocks[5];
|
|
590
|
+
const storeHooks = buildingBlocks[6];
|
|
591
|
+
const ensureAtomState = buildingBlocks[11];
|
|
592
|
+
const unmountAtom = buildingBlocks[19];
|
|
593
|
+
const atomState = ensureAtomState(store, atom2);
|
|
594
|
+
let mounted = mountedMap.get(atom2);
|
|
595
|
+
if (!mounted || mounted.l.size) {
|
|
596
|
+
return mounted;
|
|
597
|
+
}
|
|
598
|
+
let isDependent = false;
|
|
599
|
+
for (const a of mounted.t) {
|
|
600
|
+
if ((_a = mountedMap.get(a)) == null ? void 0 : _a.d.has(atom2)) {
|
|
601
|
+
isDependent = true;
|
|
602
|
+
break;
|
|
581
603
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
const atomState = getAtomState(atom2);
|
|
587
|
-
if (atomState) {
|
|
588
|
-
const mounted = mountedMap.get(atom2);
|
|
589
|
-
if (mounted && atomState.d !== (prevAtomState == null ? void 0 : prevAtomState.d)) {
|
|
590
|
-
mountDependencies(atom2, atomState, prevAtomState == null ? void 0 : prevAtomState.d);
|
|
591
|
-
}
|
|
592
|
-
if (mounted && !// TODO This seems pretty hacky. Hope to fix it.
|
|
593
|
-
// Maybe we could `mountDependencies` in `setAtomState`?
|
|
594
|
-
(!hasPromiseAtomValue(prevAtomState) && (isEqualAtomValue(prevAtomState, atomState) || isEqualAtomError(prevAtomState, atomState)))) {
|
|
595
|
-
mounted.l.forEach((listener) => listener());
|
|
596
|
-
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
597
|
-
flushed.add(atom2);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
} else if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
601
|
-
console.warn("[Bug] no atom state to flush");
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
+
}
|
|
605
|
+
if (!isDependent) {
|
|
606
|
+
if (mounted.u) {
|
|
607
|
+
unmountCallbacks.add(mounted.u);
|
|
604
608
|
}
|
|
605
|
-
|
|
606
|
-
|
|
609
|
+
mounted = void 0;
|
|
610
|
+
mountedMap.delete(atom2);
|
|
611
|
+
for (const a of atomState.d.keys()) {
|
|
612
|
+
const aMounted = unmountAtom(store, a);
|
|
613
|
+
aMounted == null ? void 0 : aMounted.t.delete(atom2);
|
|
607
614
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
615
|
+
(_b = storeHooks.u) == null ? void 0 : _b.call(storeHooks, atom2);
|
|
616
|
+
return void 0;
|
|
617
|
+
}
|
|
618
|
+
return mounted;
|
|
619
|
+
};
|
|
620
|
+
var BUILDING_BLOCK_setAtomStateValueOrPromise = (store, atom2, valueOrPromise) => {
|
|
621
|
+
const ensureAtomState = getInternalBuildingBlocks(store)[11];
|
|
622
|
+
const atomState = ensureAtomState(store, atom2);
|
|
623
|
+
const hasPrevValue = "v" in atomState;
|
|
624
|
+
const prevValue = atomState.v;
|
|
625
|
+
if (isPromiseLike(valueOrPromise)) {
|
|
626
|
+
for (const a of atomState.d.keys()) {
|
|
627
|
+
addPendingPromiseToDependency(
|
|
628
|
+
atom2,
|
|
629
|
+
valueOrPromise,
|
|
630
|
+
ensureAtomState(store, a)
|
|
617
631
|
);
|
|
618
632
|
}
|
|
619
|
-
return () => {
|
|
620
|
-
listeners.delete(listener);
|
|
621
|
-
delAtom(atom2);
|
|
622
|
-
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
623
|
-
storeListenersRev2.forEach((l) => l({ type: "unsub" }));
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
};
|
|
627
|
-
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
628
|
-
return {
|
|
629
|
-
get: readAtom,
|
|
630
|
-
set: writeAtom,
|
|
631
|
-
sub: subscribeAtom,
|
|
632
|
-
// store dev methods (these are tentative and subject to change without notice)
|
|
633
|
-
dev_subscribe_store: (l, rev) => {
|
|
634
|
-
if (rev !== 2) {
|
|
635
|
-
throw new Error("The current StoreListener revision is 2.");
|
|
636
|
-
}
|
|
637
|
-
storeListenersRev2.add(l);
|
|
638
|
-
return () => {
|
|
639
|
-
storeListenersRev2.delete(l);
|
|
640
|
-
};
|
|
641
|
-
},
|
|
642
|
-
dev_get_mounted_atoms: () => mountedAtoms.values(),
|
|
643
|
-
dev_get_atom_state: (a) => atomStateMap.get(a),
|
|
644
|
-
dev_get_mounted: (a) => mountedMap.get(a),
|
|
645
|
-
dev_restore_atoms: (values) => {
|
|
646
|
-
for (const [atom2, valueOrPromise] of values) {
|
|
647
|
-
if (hasInitialValue(atom2)) {
|
|
648
|
-
setAtomValueOrPromise(atom2, valueOrPromise);
|
|
649
|
-
recomputeDependents(atom2);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
const flushed = flushPending();
|
|
653
|
-
storeListenersRev2.forEach(
|
|
654
|
-
(l) => l({ type: "restore", flushed })
|
|
655
|
-
);
|
|
656
|
-
}
|
|
657
|
-
};
|
|
658
633
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
634
|
+
atomState.v = valueOrPromise;
|
|
635
|
+
delete atomState.e;
|
|
636
|
+
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) {
|
|
637
|
+
++atomState.n;
|
|
638
|
+
if (isPromiseLike(prevValue)) {
|
|
639
|
+
abortPromise(prevValue);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
var BUILDING_BLOCK_storeGet = (store, atom2) => {
|
|
644
|
+
const readAtomState = getInternalBuildingBlocks(store)[14];
|
|
645
|
+
return returnAtomValue(readAtomState(store, atom2));
|
|
646
|
+
};
|
|
647
|
+
var BUILDING_BLOCK_storeSet = (store, atom2, ...args) => {
|
|
648
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
649
|
+
const flushCallbacks = buildingBlocks[12];
|
|
650
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
651
|
+
const writeAtomState = buildingBlocks[16];
|
|
652
|
+
try {
|
|
653
|
+
return writeAtomState(store, atom2, ...args);
|
|
654
|
+
} finally {
|
|
655
|
+
recomputeInvalidatedAtoms(store);
|
|
656
|
+
flushCallbacks(store);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
var BUILDING_BLOCK_storeSub = (store, atom2, listener) => {
|
|
660
|
+
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
661
|
+
const flushCallbacks = buildingBlocks[12];
|
|
662
|
+
const mountAtom = buildingBlocks[18];
|
|
663
|
+
const unmountAtom = buildingBlocks[19];
|
|
664
|
+
const mounted = mountAtom(store, atom2);
|
|
665
|
+
const listeners = mounted.l;
|
|
666
|
+
listeners.add(listener);
|
|
667
|
+
flushCallbacks(store);
|
|
668
|
+
return () => {
|
|
669
|
+
listeners.delete(listener);
|
|
670
|
+
unmountAtom(store, atom2);
|
|
671
|
+
flushCallbacks(store);
|
|
663
672
|
};
|
|
664
673
|
};
|
|
665
|
-
var
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
674
|
+
var buildingBlockMap = /* @__PURE__ */ new WeakMap();
|
|
675
|
+
var getInternalBuildingBlocks = (store) => {
|
|
676
|
+
const buildingBlocks = buildingBlockMap.get(store);
|
|
677
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production" && !buildingBlocks) {
|
|
678
|
+
throw new Error(
|
|
679
|
+
"Store must be created by buildStore to read its building blocks"
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
return buildingBlocks;
|
|
683
|
+
};
|
|
684
|
+
function buildStore(...buildArgs) {
|
|
685
|
+
const store = {
|
|
686
|
+
get(atom2) {
|
|
687
|
+
const storeGet = getInternalBuildingBlocks(store)[21];
|
|
688
|
+
return storeGet(store, atom2);
|
|
689
|
+
},
|
|
690
|
+
set(atom2, ...args) {
|
|
691
|
+
const storeSet = getInternalBuildingBlocks(store)[22];
|
|
692
|
+
return storeSet(store, atom2, ...args);
|
|
693
|
+
},
|
|
694
|
+
sub(atom2, listener) {
|
|
695
|
+
const storeSub = getInternalBuildingBlocks(store)[23];
|
|
696
|
+
return storeSub(store, atom2, listener);
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
const buildingBlocks = [
|
|
700
|
+
// store state
|
|
701
|
+
/* @__PURE__ */ new WeakMap(),
|
|
702
|
+
// atomStateMap
|
|
703
|
+
/* @__PURE__ */ new WeakMap(),
|
|
704
|
+
// mountedMap
|
|
705
|
+
/* @__PURE__ */ new WeakMap(),
|
|
706
|
+
// invalidatedAtoms
|
|
707
|
+
/* @__PURE__ */ new Set(),
|
|
708
|
+
// changedAtoms
|
|
709
|
+
/* @__PURE__ */ new Set(),
|
|
710
|
+
// mountCallbacks
|
|
711
|
+
/* @__PURE__ */ new Set(),
|
|
712
|
+
// unmountCallbacks
|
|
713
|
+
{},
|
|
714
|
+
// storeHooks
|
|
715
|
+
// atom interceptors
|
|
716
|
+
BUILDING_BLOCK_atomRead,
|
|
717
|
+
BUILDING_BLOCK_atomWrite,
|
|
718
|
+
BUILDING_BLOCK_atomOnInit,
|
|
719
|
+
BUILDING_BLOCK_atomOnMount,
|
|
720
|
+
// building-block functions
|
|
721
|
+
BUILDING_BLOCK_ensureAtomState,
|
|
722
|
+
BUILDING_BLOCK_flushCallbacks,
|
|
723
|
+
BUILDING_BLOCK_recomputeInvalidatedAtoms,
|
|
724
|
+
BUILDING_BLOCK_readAtomState,
|
|
725
|
+
BUILDING_BLOCK_invalidateDependents,
|
|
726
|
+
BUILDING_BLOCK_writeAtomState,
|
|
727
|
+
BUILDING_BLOCK_mountDependencies,
|
|
728
|
+
BUILDING_BLOCK_mountAtom,
|
|
729
|
+
BUILDING_BLOCK_unmountAtom,
|
|
730
|
+
BUILDING_BLOCK_setAtomStateValueOrPromise,
|
|
731
|
+
BUILDING_BLOCK_storeGet,
|
|
732
|
+
BUILDING_BLOCK_storeSet,
|
|
733
|
+
BUILDING_BLOCK_storeSub,
|
|
734
|
+
void 0
|
|
735
|
+
].map((fn, i) => buildArgs[i] || fn);
|
|
736
|
+
buildingBlockMap.set(store, Object.freeze(buildingBlocks));
|
|
737
|
+
return store;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// ../../node_modules/jotai/esm/vanilla.mjs
|
|
741
|
+
var import_meta2 = {};
|
|
742
|
+
var keyCount = 0;
|
|
743
|
+
function atom(read, write) {
|
|
744
|
+
const key = `atom${++keyCount}`;
|
|
745
|
+
const config = {
|
|
746
|
+
toString() {
|
|
747
|
+
return (import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && this.debugLabel ? key + ":" + this.debugLabel : key;
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
if (typeof read === "function") {
|
|
751
|
+
config.read = read;
|
|
669
752
|
} else {
|
|
670
|
-
|
|
753
|
+
config.init = read;
|
|
754
|
+
config.read = defaultRead;
|
|
755
|
+
config.write = defaultWrite;
|
|
756
|
+
}
|
|
757
|
+
if (write) {
|
|
758
|
+
config.write = write;
|
|
671
759
|
}
|
|
760
|
+
return config;
|
|
761
|
+
}
|
|
762
|
+
function defaultRead(get) {
|
|
763
|
+
return get(this);
|
|
764
|
+
}
|
|
765
|
+
function defaultWrite(get, set, arg) {
|
|
766
|
+
return set(
|
|
767
|
+
this,
|
|
768
|
+
typeof arg === "function" ? arg(get(this)) : arg
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
var overriddenCreateStore;
|
|
772
|
+
function createStore() {
|
|
773
|
+
if (overriddenCreateStore) {
|
|
774
|
+
return overriddenCreateStore();
|
|
775
|
+
}
|
|
776
|
+
return buildStore();
|
|
672
777
|
}
|
|
673
|
-
var
|
|
778
|
+
var defaultStore;
|
|
779
|
+
function getDefaultStore() {
|
|
674
780
|
if (!defaultStore) {
|
|
675
781
|
defaultStore = createStore();
|
|
782
|
+
if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production") {
|
|
783
|
+
globalThis.__JOTAI_DEFAULT_STORE__ || (globalThis.__JOTAI_DEFAULT_STORE__ = defaultStore);
|
|
784
|
+
if (globalThis.__JOTAI_DEFAULT_STORE__ !== defaultStore) {
|
|
785
|
+
console.warn(
|
|
786
|
+
"Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
676
790
|
}
|
|
677
791
|
return defaultStore;
|
|
678
|
-
}
|
|
792
|
+
}
|
|
679
793
|
|
|
680
794
|
// ../../node_modules/jotai/esm/react.mjs
|
|
681
795
|
var import_react = __toESM(require("react"), 1);
|
|
682
|
-
var
|
|
683
|
-
var StoreContext = (0, import_react.createContext)(
|
|
684
|
-
|
|
796
|
+
var import_meta3 = {};
|
|
797
|
+
var StoreContext = (0, import_react.createContext)(
|
|
798
|
+
void 0
|
|
799
|
+
);
|
|
800
|
+
function useStore(options) {
|
|
685
801
|
const store = (0, import_react.useContext)(StoreContext);
|
|
686
802
|
return (options == null ? void 0 : options.store) || store || getDefaultStore();
|
|
687
|
-
}
|
|
803
|
+
}
|
|
688
804
|
var isPromiseLike2 = (x) => typeof (x == null ? void 0 : x.then) === "function";
|
|
689
|
-
var
|
|
690
|
-
if (promise.status
|
|
691
|
-
throw promise;
|
|
692
|
-
} else if (promise.status === "fulfilled") {
|
|
693
|
-
return promise.value;
|
|
694
|
-
} else if (promise.status === "rejected") {
|
|
695
|
-
throw promise.reason;
|
|
696
|
-
} else {
|
|
805
|
+
var attachPromiseStatus = (promise) => {
|
|
806
|
+
if (!promise.status) {
|
|
697
807
|
promise.status = "pending";
|
|
698
808
|
promise.then(
|
|
699
809
|
(v) => {
|
|
@@ -705,10 +815,61 @@ var use = import_react.default.use || ((promise) => {
|
|
|
705
815
|
promise.reason = e;
|
|
706
816
|
}
|
|
707
817
|
);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
var use = import_react.default.use || // A shim for older React versions
|
|
821
|
+
((promise) => {
|
|
822
|
+
if (promise.status === "pending") {
|
|
823
|
+
throw promise;
|
|
824
|
+
} else if (promise.status === "fulfilled") {
|
|
825
|
+
return promise.value;
|
|
826
|
+
} else if (promise.status === "rejected") {
|
|
827
|
+
throw promise.reason;
|
|
828
|
+
} else {
|
|
829
|
+
attachPromiseStatus(promise);
|
|
708
830
|
throw promise;
|
|
709
831
|
}
|
|
710
832
|
});
|
|
833
|
+
var continuablePromiseMap = /* @__PURE__ */ new WeakMap();
|
|
834
|
+
var createContinuablePromise = (promise, getValue) => {
|
|
835
|
+
let continuablePromise = continuablePromiseMap.get(promise);
|
|
836
|
+
if (!continuablePromise) {
|
|
837
|
+
continuablePromise = new Promise((resolve, reject) => {
|
|
838
|
+
let curr = promise;
|
|
839
|
+
const onFulfilled = (me) => (v) => {
|
|
840
|
+
if (curr === me) {
|
|
841
|
+
resolve(v);
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
const onRejected = (me) => (e) => {
|
|
845
|
+
if (curr === me) {
|
|
846
|
+
reject(e);
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
const onAbort = () => {
|
|
850
|
+
try {
|
|
851
|
+
const nextValue = getValue();
|
|
852
|
+
if (isPromiseLike2(nextValue)) {
|
|
853
|
+
continuablePromiseMap.set(nextValue, continuablePromise);
|
|
854
|
+
curr = nextValue;
|
|
855
|
+
nextValue.then(onFulfilled(nextValue), onRejected(nextValue));
|
|
856
|
+
registerAbortHandler(nextValue, onAbort);
|
|
857
|
+
} else {
|
|
858
|
+
resolve(nextValue);
|
|
859
|
+
}
|
|
860
|
+
} catch (e) {
|
|
861
|
+
reject(e);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
promise.then(onFulfilled(promise), onRejected(promise));
|
|
865
|
+
registerAbortHandler(promise, onAbort);
|
|
866
|
+
});
|
|
867
|
+
continuablePromiseMap.set(promise, continuablePromise);
|
|
868
|
+
}
|
|
869
|
+
return continuablePromise;
|
|
870
|
+
};
|
|
711
871
|
function useAtomValue(atom2, options) {
|
|
872
|
+
const { delay, unstable_promiseStatus: promiseStatus = !import_react.default.use } = options || {};
|
|
712
873
|
const store = useStore(options);
|
|
713
874
|
const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = (0, import_react.useReducer)(
|
|
714
875
|
(prev) => {
|
|
@@ -726,9 +887,19 @@ function useAtomValue(atom2, options) {
|
|
|
726
887
|
rerender();
|
|
727
888
|
value = store.get(atom2);
|
|
728
889
|
}
|
|
729
|
-
const delay = options == null ? void 0 : options.delay;
|
|
730
890
|
(0, import_react.useEffect)(() => {
|
|
731
891
|
const unsub = store.sub(atom2, () => {
|
|
892
|
+
if (promiseStatus) {
|
|
893
|
+
try {
|
|
894
|
+
const value2 = store.get(atom2);
|
|
895
|
+
if (isPromiseLike2(value2)) {
|
|
896
|
+
attachPromiseStatus(
|
|
897
|
+
createContinuablePromise(value2, () => store.get(atom2))
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
} catch (e) {
|
|
901
|
+
}
|
|
902
|
+
}
|
|
732
903
|
if (typeof delay === "number") {
|
|
733
904
|
setTimeout(rerender, delay);
|
|
734
905
|
return;
|
|
@@ -737,15 +908,22 @@ function useAtomValue(atom2, options) {
|
|
|
737
908
|
});
|
|
738
909
|
rerender();
|
|
739
910
|
return unsub;
|
|
740
|
-
}, [store, atom2, delay]);
|
|
911
|
+
}, [store, atom2, delay, promiseStatus]);
|
|
741
912
|
(0, import_react.useDebugValue)(value);
|
|
742
|
-
|
|
913
|
+
if (isPromiseLike2(value)) {
|
|
914
|
+
const promise = createContinuablePromise(value, () => store.get(atom2));
|
|
915
|
+
if (promiseStatus) {
|
|
916
|
+
attachPromiseStatus(promise);
|
|
917
|
+
}
|
|
918
|
+
return use(promise);
|
|
919
|
+
}
|
|
920
|
+
return value;
|
|
743
921
|
}
|
|
744
922
|
function useSetAtom(atom2, options) {
|
|
745
923
|
const store = useStore(options);
|
|
746
924
|
const setAtom = (0, import_react.useCallback)(
|
|
747
925
|
(...args) => {
|
|
748
|
-
if ((
|
|
926
|
+
if ((import_meta3.env ? import_meta3.env.MODE : void 0) !== "production" && !("write" in atom2)) {
|
|
749
927
|
throw new Error("not writable atom");
|
|
750
928
|
}
|
|
751
929
|
return store.set(atom2, ...args);
|