@veritone-ce/design-system 2.7.2 → 2.7.3
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/cjs/bundled_modules/jotai/esm/react.js +160 -0
- package/dist/cjs/bundled_modules/jotai/esm/vanilla/internals.js +539 -0
- package/dist/cjs/bundled_modules/jotai/esm/vanilla.js +114 -0
- package/dist/cjs/styles.css +1 -1
- package/dist/cjs/unstable/extras/drawers/index.js +69 -0
- package/dist/cjs/unstable/extras/drawers/index.module.scss.js +7 -0
- package/dist/esm/bundled_modules/jotai/esm/react.js +155 -0
- package/dist/esm/bundled_modules/jotai/esm/vanilla/internals.js +535 -0
- package/dist/esm/bundled_modules/jotai/esm/vanilla.js +110 -0
- package/dist/esm/styles.css +1 -1
- package/dist/esm/unstable/extras/drawers/index.js +67 -0
- package/dist/esm/unstable/extras/drawers/index.module.scss.js +3 -0
- package/dist/types/unstable/extras/drawers/index.d.ts +18 -0
- package/package.json +7 -2
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var vanilla = require('./vanilla.js');
|
|
6
|
+
var internals = require('./vanilla/internals.js');
|
|
7
|
+
|
|
8
|
+
const StoreContext = React.createContext(
|
|
9
|
+
void 0
|
|
10
|
+
);
|
|
11
|
+
function useStore(options) {
|
|
12
|
+
const store = React.useContext(StoreContext);
|
|
13
|
+
return store || vanilla.getDefaultStore();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const isPromiseLike = (x) => typeof (x == null ? void 0 : x.then) === "function";
|
|
17
|
+
const attachPromiseStatus = (promise) => {
|
|
18
|
+
if (!promise.status) {
|
|
19
|
+
promise.status = "pending";
|
|
20
|
+
promise.then(
|
|
21
|
+
(v) => {
|
|
22
|
+
promise.status = "fulfilled";
|
|
23
|
+
promise.value = v;
|
|
24
|
+
},
|
|
25
|
+
(e) => {
|
|
26
|
+
promise.status = "rejected";
|
|
27
|
+
promise.reason = e;
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const use = React.use || // A shim for older React versions
|
|
33
|
+
((promise) => {
|
|
34
|
+
if (promise.status === "pending") {
|
|
35
|
+
throw promise;
|
|
36
|
+
} else if (promise.status === "fulfilled") {
|
|
37
|
+
return promise.value;
|
|
38
|
+
} else if (promise.status === "rejected") {
|
|
39
|
+
throw promise.reason;
|
|
40
|
+
} else {
|
|
41
|
+
attachPromiseStatus(promise);
|
|
42
|
+
throw promise;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const continuablePromiseMap = /* @__PURE__ */ new WeakMap();
|
|
46
|
+
const createContinuablePromise = (promise, getValue) => {
|
|
47
|
+
let continuablePromise = continuablePromiseMap.get(promise);
|
|
48
|
+
if (!continuablePromise) {
|
|
49
|
+
continuablePromise = new Promise((resolve, reject) => {
|
|
50
|
+
let curr = promise;
|
|
51
|
+
const onFulfilled = (me) => (v) => {
|
|
52
|
+
if (curr === me) {
|
|
53
|
+
resolve(v);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const onRejected = (me) => (e) => {
|
|
57
|
+
if (curr === me) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const onAbort = () => {
|
|
62
|
+
try {
|
|
63
|
+
const nextValue = getValue();
|
|
64
|
+
if (isPromiseLike(nextValue)) {
|
|
65
|
+
continuablePromiseMap.set(nextValue, continuablePromise);
|
|
66
|
+
curr = nextValue;
|
|
67
|
+
nextValue.then(onFulfilled(nextValue), onRejected(nextValue));
|
|
68
|
+
internals.INTERNAL_registerAbortHandler(nextValue, onAbort);
|
|
69
|
+
} else {
|
|
70
|
+
resolve(nextValue);
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
reject(e);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
promise.then(onFulfilled(promise), onRejected(promise));
|
|
77
|
+
internals.INTERNAL_registerAbortHandler(promise, onAbort);
|
|
78
|
+
});
|
|
79
|
+
continuablePromiseMap.set(promise, continuablePromise);
|
|
80
|
+
}
|
|
81
|
+
return continuablePromise;
|
|
82
|
+
};
|
|
83
|
+
function useAtomValue(atom, options) {
|
|
84
|
+
const { delay, unstable_promiseStatus: promiseStatus = !React.use } = {};
|
|
85
|
+
const store = useStore();
|
|
86
|
+
const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = React.useReducer(
|
|
87
|
+
(prev) => {
|
|
88
|
+
const nextValue = store.get(atom);
|
|
89
|
+
if (Object.is(prev[0], nextValue) && prev[1] === store && prev[2] === atom) {
|
|
90
|
+
return prev;
|
|
91
|
+
}
|
|
92
|
+
return [nextValue, store, atom];
|
|
93
|
+
},
|
|
94
|
+
void 0,
|
|
95
|
+
() => [store.get(atom), store, atom]
|
|
96
|
+
);
|
|
97
|
+
let value = valueFromReducer;
|
|
98
|
+
if (storeFromReducer !== store || atomFromReducer !== atom) {
|
|
99
|
+
rerender();
|
|
100
|
+
value = store.get(atom);
|
|
101
|
+
}
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
const unsub = store.sub(atom, () => {
|
|
104
|
+
if (promiseStatus) {
|
|
105
|
+
try {
|
|
106
|
+
const value2 = store.get(atom);
|
|
107
|
+
if (isPromiseLike(value2)) {
|
|
108
|
+
attachPromiseStatus(
|
|
109
|
+
createContinuablePromise(value2, () => store.get(atom))
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
} catch (e) {
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (typeof delay === "number") {
|
|
116
|
+
setTimeout(rerender, delay);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
rerender();
|
|
120
|
+
});
|
|
121
|
+
rerender();
|
|
122
|
+
return unsub;
|
|
123
|
+
}, [store, atom, delay, promiseStatus]);
|
|
124
|
+
React.useDebugValue(value);
|
|
125
|
+
if (isPromiseLike(value)) {
|
|
126
|
+
const promise = createContinuablePromise(value, () => store.get(atom));
|
|
127
|
+
if (promiseStatus) {
|
|
128
|
+
attachPromiseStatus(promise);
|
|
129
|
+
}
|
|
130
|
+
return use(promise);
|
|
131
|
+
}
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function useSetAtom(atom, options) {
|
|
136
|
+
const store = useStore();
|
|
137
|
+
const setAtom = React.useCallback(
|
|
138
|
+
(...args) => {
|
|
139
|
+
if ((undefined ? undefined.MODE : void 0) !== "production" && !("write" in atom)) {
|
|
140
|
+
throw new Error("not writable atom");
|
|
141
|
+
}
|
|
142
|
+
return store.set(atom, ...args);
|
|
143
|
+
},
|
|
144
|
+
[store, atom]
|
|
145
|
+
);
|
|
146
|
+
return setAtom;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function useAtom(atom, options) {
|
|
150
|
+
return [
|
|
151
|
+
useAtomValue(atom),
|
|
152
|
+
// We do wrong type assertion here, which results in throwing an error.
|
|
153
|
+
useSetAtom(atom)
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
exports.useAtom = useAtom;
|
|
158
|
+
exports.useAtomValue = useAtomValue;
|
|
159
|
+
exports.useSetAtom = useSetAtom;
|
|
160
|
+
exports.useStore = useStore;
|
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isSelfAtom = (atom, a) => atom.unstable_is ? atom.unstable_is(a) : a === atom;
|
|
4
|
+
const hasInitialValue = (atom) => "init" in atom;
|
|
5
|
+
const isActuallyWritableAtom = (atom) => !!atom.write;
|
|
6
|
+
const isAtomStateInitialized = (atomState) => "v" in atomState || "e" in atomState;
|
|
7
|
+
const returnAtomValue = (atomState) => {
|
|
8
|
+
if ("e" in atomState) {
|
|
9
|
+
throw atomState.e;
|
|
10
|
+
}
|
|
11
|
+
if ((undefined ? undefined.MODE : void 0) !== "production" && !("v" in atomState)) {
|
|
12
|
+
throw new Error("[Bug] atom state is not initialized");
|
|
13
|
+
}
|
|
14
|
+
return atomState.v;
|
|
15
|
+
};
|
|
16
|
+
const promiseStateMap = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
const isPendingPromise = (value) => {
|
|
18
|
+
var _a;
|
|
19
|
+
return isPromiseLike(value) && !!((_a = promiseStateMap.get(value)) == null ? void 0 : _a[0]);
|
|
20
|
+
};
|
|
21
|
+
const abortPromise = (promise) => {
|
|
22
|
+
const promiseState = promiseStateMap.get(promise);
|
|
23
|
+
if (promiseState == null ? void 0 : promiseState[0]) {
|
|
24
|
+
promiseState[0] = false;
|
|
25
|
+
promiseState[1].forEach((fn) => fn());
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const registerAbortHandler = (promise, abortHandler) => {
|
|
29
|
+
let promiseState = promiseStateMap.get(promise);
|
|
30
|
+
if (!promiseState) {
|
|
31
|
+
promiseState = [true, /* @__PURE__ */ new Set()];
|
|
32
|
+
promiseStateMap.set(promise, promiseState);
|
|
33
|
+
const settle = () => {
|
|
34
|
+
promiseState[0] = false;
|
|
35
|
+
};
|
|
36
|
+
promise.then(settle, settle);
|
|
37
|
+
}
|
|
38
|
+
promiseState[1].add(abortHandler);
|
|
39
|
+
};
|
|
40
|
+
const isPromiseLike = (p) => typeof (p == null ? void 0 : p.then) === "function";
|
|
41
|
+
const addPendingPromiseToDependency = (atom, promise, dependencyAtomState) => {
|
|
42
|
+
if (!dependencyAtomState.p.has(atom)) {
|
|
43
|
+
dependencyAtomState.p.add(atom);
|
|
44
|
+
promise.then(
|
|
45
|
+
() => {
|
|
46
|
+
dependencyAtomState.p.delete(atom);
|
|
47
|
+
},
|
|
48
|
+
() => {
|
|
49
|
+
dependencyAtomState.p.delete(atom);
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const setAtomStateValueOrPromise = (atom, valueOrPromise, ensureAtomState) => {
|
|
55
|
+
const atomState = ensureAtomState(atom);
|
|
56
|
+
const hasPrevValue = "v" in atomState;
|
|
57
|
+
const prevValue = atomState.v;
|
|
58
|
+
if (isPromiseLike(valueOrPromise)) {
|
|
59
|
+
for (const a of atomState.d.keys()) {
|
|
60
|
+
addPendingPromiseToDependency(atom, valueOrPromise, ensureAtomState(a));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
atomState.v = valueOrPromise;
|
|
64
|
+
delete atomState.e;
|
|
65
|
+
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) {
|
|
66
|
+
++atomState.n;
|
|
67
|
+
if (isPromiseLike(prevValue)) {
|
|
68
|
+
abortPromise(prevValue);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const getMountedOrPendingDependents = (atom, atomState, mountedMap) => {
|
|
73
|
+
var _a;
|
|
74
|
+
const dependents = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const a of ((_a = mountedMap.get(atom)) == null ? void 0 : _a.t) || []) {
|
|
76
|
+
if (mountedMap.has(a)) {
|
|
77
|
+
dependents.add(a);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const atomWithPendingPromise of atomState.p) {
|
|
81
|
+
dependents.add(atomWithPendingPromise);
|
|
82
|
+
}
|
|
83
|
+
return dependents;
|
|
84
|
+
};
|
|
85
|
+
const createStoreHook = () => {
|
|
86
|
+
const callbacks = /* @__PURE__ */ new Set();
|
|
87
|
+
const notify = () => {
|
|
88
|
+
callbacks.forEach((fn) => fn());
|
|
89
|
+
};
|
|
90
|
+
notify.add = (fn) => {
|
|
91
|
+
callbacks.add(fn);
|
|
92
|
+
return () => {
|
|
93
|
+
callbacks.delete(fn);
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
return notify;
|
|
97
|
+
};
|
|
98
|
+
const createStoreHookForAtoms = () => {
|
|
99
|
+
const all = {};
|
|
100
|
+
const callbacks = /* @__PURE__ */ new WeakMap();
|
|
101
|
+
const notify = (atom) => {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
(_a = callbacks.get(all)) == null ? void 0 : _a.forEach((fn) => fn(atom));
|
|
104
|
+
(_b = callbacks.get(atom)) == null ? void 0 : _b.forEach((fn) => fn());
|
|
105
|
+
};
|
|
106
|
+
notify.add = (atom, fn) => {
|
|
107
|
+
const key = atom || all;
|
|
108
|
+
const fns = (callbacks.has(key) ? callbacks : callbacks.set(key, /* @__PURE__ */ new Set())).get(key);
|
|
109
|
+
fns.add(fn);
|
|
110
|
+
return () => {
|
|
111
|
+
fns == null ? void 0 : fns.delete(fn);
|
|
112
|
+
if (!fns.size) {
|
|
113
|
+
callbacks.delete(key);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
return notify;
|
|
118
|
+
};
|
|
119
|
+
const initializeStoreHooks = (storeHooks) => {
|
|
120
|
+
storeHooks.c || (storeHooks.c = createStoreHookForAtoms());
|
|
121
|
+
storeHooks.m || (storeHooks.m = createStoreHookForAtoms());
|
|
122
|
+
storeHooks.u || (storeHooks.u = createStoreHookForAtoms());
|
|
123
|
+
storeHooks.f || (storeHooks.f = createStoreHook());
|
|
124
|
+
return storeHooks;
|
|
125
|
+
};
|
|
126
|
+
const BUILDING_BLOCKS = Symbol();
|
|
127
|
+
const buildStore = (atomStateMap = /* @__PURE__ */ new WeakMap(), mountedMap = /* @__PURE__ */ new WeakMap(), invalidatedAtoms = /* @__PURE__ */ new WeakMap(), changedAtoms = /* @__PURE__ */ new Set(), mountCallbacks = /* @__PURE__ */ new Set(), unmountCallbacks = /* @__PURE__ */ new Set(), storeHooks = {}, atomRead = (atom, ...params) => atom.read(...params), atomWrite = (atom, ...params) => atom.write(...params), atomOnInit = (atom, store) => {
|
|
128
|
+
var _a;
|
|
129
|
+
return (_a = atom.unstable_onInit) == null ? void 0 : _a.call(atom, store);
|
|
130
|
+
}, atomOnMount = (atom, setAtom) => {
|
|
131
|
+
var _a;
|
|
132
|
+
return (_a = atom.onMount) == null ? void 0 : _a.call(atom, setAtom);
|
|
133
|
+
}, ...buildingBlockFunctions) => {
|
|
134
|
+
const ensureAtomState = buildingBlockFunctions[0] || ((atom) => {
|
|
135
|
+
if ((undefined ? undefined.MODE : void 0) !== "production" && !atom) {
|
|
136
|
+
throw new Error("Atom is undefined or null");
|
|
137
|
+
}
|
|
138
|
+
let atomState = atomStateMap.get(atom);
|
|
139
|
+
if (!atomState) {
|
|
140
|
+
atomState = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 };
|
|
141
|
+
atomStateMap.set(atom, atomState);
|
|
142
|
+
atomOnInit == null ? void 0 : atomOnInit(atom, store);
|
|
143
|
+
}
|
|
144
|
+
return atomState;
|
|
145
|
+
});
|
|
146
|
+
const flushCallbacks = buildingBlockFunctions[1] || (() => {
|
|
147
|
+
const errors = [];
|
|
148
|
+
const call = (fn) => {
|
|
149
|
+
try {
|
|
150
|
+
fn();
|
|
151
|
+
} catch (e) {
|
|
152
|
+
errors.push(e);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
do {
|
|
156
|
+
if (storeHooks.f) {
|
|
157
|
+
call(storeHooks.f);
|
|
158
|
+
}
|
|
159
|
+
const callbacks = /* @__PURE__ */ new Set();
|
|
160
|
+
const add = callbacks.add.bind(callbacks);
|
|
161
|
+
changedAtoms.forEach((atom) => {
|
|
162
|
+
var _a;
|
|
163
|
+
return (_a = mountedMap.get(atom)) == null ? void 0 : _a.l.forEach(add);
|
|
164
|
+
});
|
|
165
|
+
changedAtoms.clear();
|
|
166
|
+
unmountCallbacks.forEach(add);
|
|
167
|
+
unmountCallbacks.clear();
|
|
168
|
+
mountCallbacks.forEach(add);
|
|
169
|
+
mountCallbacks.clear();
|
|
170
|
+
callbacks.forEach(call);
|
|
171
|
+
if (changedAtoms.size) {
|
|
172
|
+
recomputeInvalidatedAtoms();
|
|
173
|
+
}
|
|
174
|
+
} while (changedAtoms.size || unmountCallbacks.size || mountCallbacks.size);
|
|
175
|
+
if (errors.length) {
|
|
176
|
+
throw new AggregateError(errors);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const recomputeInvalidatedAtoms = buildingBlockFunctions[2] || (() => {
|
|
180
|
+
const topSortedReversed = [];
|
|
181
|
+
const visiting = /* @__PURE__ */ new WeakSet();
|
|
182
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
183
|
+
const stack = Array.from(changedAtoms);
|
|
184
|
+
while (stack.length) {
|
|
185
|
+
const a = stack[stack.length - 1];
|
|
186
|
+
const aState = ensureAtomState(a);
|
|
187
|
+
if (visited.has(a)) {
|
|
188
|
+
stack.pop();
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (visiting.has(a)) {
|
|
192
|
+
if (invalidatedAtoms.get(a) === aState.n) {
|
|
193
|
+
topSortedReversed.push([a, aState]);
|
|
194
|
+
} else if ((undefined ? undefined.MODE : void 0) !== "production" && invalidatedAtoms.has(a)) {
|
|
195
|
+
throw new Error("[Bug] invalidated atom exists");
|
|
196
|
+
}
|
|
197
|
+
visited.add(a);
|
|
198
|
+
stack.pop();
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
visiting.add(a);
|
|
202
|
+
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
203
|
+
if (!visiting.has(d)) {
|
|
204
|
+
stack.push(d);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
for (let i = topSortedReversed.length - 1; i >= 0; --i) {
|
|
209
|
+
const [a, aState] = topSortedReversed[i];
|
|
210
|
+
let hasChangedDeps = false;
|
|
211
|
+
for (const dep of aState.d.keys()) {
|
|
212
|
+
if (dep !== a && changedAtoms.has(dep)) {
|
|
213
|
+
hasChangedDeps = true;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (hasChangedDeps) {
|
|
218
|
+
readAtomState(a);
|
|
219
|
+
mountDependencies(a);
|
|
220
|
+
}
|
|
221
|
+
invalidatedAtoms.delete(a);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
const readAtomState = buildingBlockFunctions[3] || ((atom) => {
|
|
225
|
+
var _a;
|
|
226
|
+
const atomState = ensureAtomState(atom);
|
|
227
|
+
if (isAtomStateInitialized(atomState)) {
|
|
228
|
+
if (mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n) {
|
|
229
|
+
return atomState;
|
|
230
|
+
}
|
|
231
|
+
if (Array.from(atomState.d).every(
|
|
232
|
+
([a, n]) => (
|
|
233
|
+
// Recursively, read the atom state of the dependency, and
|
|
234
|
+
// check if the atom epoch number is unchanged
|
|
235
|
+
readAtomState(a).n === n
|
|
236
|
+
)
|
|
237
|
+
)) {
|
|
238
|
+
return atomState;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
atomState.d.clear();
|
|
242
|
+
let isSync = true;
|
|
243
|
+
const mountDependenciesIfAsync = () => {
|
|
244
|
+
if (mountedMap.has(atom)) {
|
|
245
|
+
mountDependencies(atom);
|
|
246
|
+
recomputeInvalidatedAtoms();
|
|
247
|
+
flushCallbacks();
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const getter = (a) => {
|
|
251
|
+
var _a2;
|
|
252
|
+
if (isSelfAtom(atom, a)) {
|
|
253
|
+
const aState2 = ensureAtomState(a);
|
|
254
|
+
if (!isAtomStateInitialized(aState2)) {
|
|
255
|
+
if (hasInitialValue(a)) {
|
|
256
|
+
setAtomStateValueOrPromise(a, a.init, ensureAtomState);
|
|
257
|
+
} else {
|
|
258
|
+
throw new Error("no atom init");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return returnAtomValue(aState2);
|
|
262
|
+
}
|
|
263
|
+
const aState = readAtomState(a);
|
|
264
|
+
try {
|
|
265
|
+
return returnAtomValue(aState);
|
|
266
|
+
} finally {
|
|
267
|
+
atomState.d.set(a, aState.n);
|
|
268
|
+
if (isPendingPromise(atomState.v)) {
|
|
269
|
+
addPendingPromiseToDependency(atom, atomState.v, aState);
|
|
270
|
+
}
|
|
271
|
+
(_a2 = mountedMap.get(a)) == null ? void 0 : _a2.t.add(atom);
|
|
272
|
+
if (!isSync) {
|
|
273
|
+
mountDependenciesIfAsync();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
let controller;
|
|
278
|
+
let setSelf;
|
|
279
|
+
const options = {
|
|
280
|
+
get signal() {
|
|
281
|
+
if (!controller) {
|
|
282
|
+
controller = new AbortController();
|
|
283
|
+
}
|
|
284
|
+
return controller.signal;
|
|
285
|
+
},
|
|
286
|
+
get setSelf() {
|
|
287
|
+
if ((undefined ? undefined.MODE : void 0) !== "production" && !isActuallyWritableAtom(atom)) {
|
|
288
|
+
console.warn("setSelf function cannot be used with read-only atom");
|
|
289
|
+
}
|
|
290
|
+
if (!setSelf && isActuallyWritableAtom(atom)) {
|
|
291
|
+
setSelf = (...args) => {
|
|
292
|
+
if ((undefined ? undefined.MODE : void 0) !== "production" && isSync) {
|
|
293
|
+
console.warn("setSelf function cannot be called in sync");
|
|
294
|
+
}
|
|
295
|
+
if (!isSync) {
|
|
296
|
+
try {
|
|
297
|
+
return writeAtomState(atom, ...args);
|
|
298
|
+
} finally {
|
|
299
|
+
recomputeInvalidatedAtoms();
|
|
300
|
+
flushCallbacks();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return setSelf;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const prevEpochNumber = atomState.n;
|
|
309
|
+
try {
|
|
310
|
+
const valueOrPromise = atomRead(atom, getter, options);
|
|
311
|
+
setAtomStateValueOrPromise(atom, valueOrPromise, ensureAtomState);
|
|
312
|
+
if (isPromiseLike(valueOrPromise)) {
|
|
313
|
+
registerAbortHandler(valueOrPromise, () => controller == null ? void 0 : controller.abort());
|
|
314
|
+
valueOrPromise.then(
|
|
315
|
+
mountDependenciesIfAsync,
|
|
316
|
+
mountDependenciesIfAsync
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
return atomState;
|
|
320
|
+
} catch (error) {
|
|
321
|
+
delete atomState.v;
|
|
322
|
+
atomState.e = error;
|
|
323
|
+
++atomState.n;
|
|
324
|
+
return atomState;
|
|
325
|
+
} finally {
|
|
326
|
+
isSync = false;
|
|
327
|
+
if (prevEpochNumber !== atomState.n && invalidatedAtoms.get(atom) === prevEpochNumber) {
|
|
328
|
+
invalidatedAtoms.set(atom, atomState.n);
|
|
329
|
+
changedAtoms.add(atom);
|
|
330
|
+
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, atom);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
const invalidateDependents = buildingBlockFunctions[4] || ((atom) => {
|
|
335
|
+
const stack = [atom];
|
|
336
|
+
while (stack.length) {
|
|
337
|
+
const a = stack.pop();
|
|
338
|
+
const aState = ensureAtomState(a);
|
|
339
|
+
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
340
|
+
const dState = ensureAtomState(d);
|
|
341
|
+
invalidatedAtoms.set(d, dState.n);
|
|
342
|
+
stack.push(d);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
const writeAtomState = buildingBlockFunctions[5] || ((atom, ...args) => {
|
|
347
|
+
let isSync = true;
|
|
348
|
+
const getter = (a) => returnAtomValue(readAtomState(a));
|
|
349
|
+
const setter = (a, ...args2) => {
|
|
350
|
+
var _a;
|
|
351
|
+
const aState = ensureAtomState(a);
|
|
352
|
+
try {
|
|
353
|
+
if (isSelfAtom(atom, a)) {
|
|
354
|
+
if (!hasInitialValue(a)) {
|
|
355
|
+
throw new Error("atom not writable");
|
|
356
|
+
}
|
|
357
|
+
const prevEpochNumber = aState.n;
|
|
358
|
+
const v = args2[0];
|
|
359
|
+
setAtomStateValueOrPromise(a, v, ensureAtomState);
|
|
360
|
+
mountDependencies(a);
|
|
361
|
+
if (prevEpochNumber !== aState.n) {
|
|
362
|
+
changedAtoms.add(a);
|
|
363
|
+
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
364
|
+
invalidateDependents(a);
|
|
365
|
+
}
|
|
366
|
+
return void 0;
|
|
367
|
+
} else {
|
|
368
|
+
return writeAtomState(a, ...args2);
|
|
369
|
+
}
|
|
370
|
+
} finally {
|
|
371
|
+
if (!isSync) {
|
|
372
|
+
recomputeInvalidatedAtoms();
|
|
373
|
+
flushCallbacks();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
try {
|
|
378
|
+
return atomWrite(atom, getter, setter, ...args);
|
|
379
|
+
} finally {
|
|
380
|
+
isSync = false;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
const mountDependencies = buildingBlockFunctions[6] || ((atom) => {
|
|
384
|
+
var _a;
|
|
385
|
+
const atomState = ensureAtomState(atom);
|
|
386
|
+
const mounted = mountedMap.get(atom);
|
|
387
|
+
if (mounted && !isPendingPromise(atomState.v)) {
|
|
388
|
+
for (const [a, n] of atomState.d) {
|
|
389
|
+
if (!mounted.d.has(a)) {
|
|
390
|
+
const aState = ensureAtomState(a);
|
|
391
|
+
const aMounted = mountAtom(a);
|
|
392
|
+
aMounted.t.add(atom);
|
|
393
|
+
mounted.d.add(a);
|
|
394
|
+
if (n !== aState.n) {
|
|
395
|
+
changedAtoms.add(a);
|
|
396
|
+
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
397
|
+
invalidateDependents(a);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
for (const a of mounted.d || []) {
|
|
402
|
+
if (!atomState.d.has(a)) {
|
|
403
|
+
mounted.d.delete(a);
|
|
404
|
+
const aMounted = unmountAtom(a);
|
|
405
|
+
aMounted == null ? void 0 : aMounted.t.delete(atom);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
const mountAtom = buildingBlockFunctions[7] || ((atom) => {
|
|
411
|
+
var _a;
|
|
412
|
+
const atomState = ensureAtomState(atom);
|
|
413
|
+
let mounted = mountedMap.get(atom);
|
|
414
|
+
if (!mounted) {
|
|
415
|
+
readAtomState(atom);
|
|
416
|
+
for (const a of atomState.d.keys()) {
|
|
417
|
+
const aMounted = mountAtom(a);
|
|
418
|
+
aMounted.t.add(atom);
|
|
419
|
+
}
|
|
420
|
+
mounted = {
|
|
421
|
+
l: /* @__PURE__ */ new Set(),
|
|
422
|
+
d: new Set(atomState.d.keys()),
|
|
423
|
+
t: /* @__PURE__ */ new Set()
|
|
424
|
+
};
|
|
425
|
+
mountedMap.set(atom, mounted);
|
|
426
|
+
(_a = storeHooks.m) == null ? void 0 : _a.call(storeHooks, atom);
|
|
427
|
+
if (isActuallyWritableAtom(atom)) {
|
|
428
|
+
const processOnMount = () => {
|
|
429
|
+
let isSync = true;
|
|
430
|
+
const setAtom = (...args) => {
|
|
431
|
+
try {
|
|
432
|
+
return writeAtomState(atom, ...args);
|
|
433
|
+
} finally {
|
|
434
|
+
if (!isSync) {
|
|
435
|
+
recomputeInvalidatedAtoms();
|
|
436
|
+
flushCallbacks();
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
try {
|
|
441
|
+
const onUnmount = atomOnMount(atom, setAtom);
|
|
442
|
+
if (onUnmount) {
|
|
443
|
+
mounted.u = () => {
|
|
444
|
+
isSync = true;
|
|
445
|
+
try {
|
|
446
|
+
onUnmount();
|
|
447
|
+
} finally {
|
|
448
|
+
isSync = false;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
} finally {
|
|
453
|
+
isSync = false;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
mountCallbacks.add(processOnMount);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return mounted;
|
|
460
|
+
});
|
|
461
|
+
const unmountAtom = buildingBlockFunctions[8] || ((atom) => {
|
|
462
|
+
var _a;
|
|
463
|
+
const atomState = ensureAtomState(atom);
|
|
464
|
+
let mounted = mountedMap.get(atom);
|
|
465
|
+
if (mounted && !mounted.l.size && !Array.from(mounted.t).some((a) => {
|
|
466
|
+
var _a2;
|
|
467
|
+
return (_a2 = mountedMap.get(a)) == null ? void 0 : _a2.d.has(atom);
|
|
468
|
+
})) {
|
|
469
|
+
if (mounted.u) {
|
|
470
|
+
unmountCallbacks.add(mounted.u);
|
|
471
|
+
}
|
|
472
|
+
mounted = void 0;
|
|
473
|
+
mountedMap.delete(atom);
|
|
474
|
+
(_a = storeHooks.u) == null ? void 0 : _a.call(storeHooks, atom);
|
|
475
|
+
for (const a of atomState.d.keys()) {
|
|
476
|
+
const aMounted = unmountAtom(a);
|
|
477
|
+
aMounted == null ? void 0 : aMounted.t.delete(atom);
|
|
478
|
+
}
|
|
479
|
+
return void 0;
|
|
480
|
+
}
|
|
481
|
+
return mounted;
|
|
482
|
+
});
|
|
483
|
+
const buildingBlocks = [
|
|
484
|
+
// store state
|
|
485
|
+
atomStateMap,
|
|
486
|
+
mountedMap,
|
|
487
|
+
invalidatedAtoms,
|
|
488
|
+
changedAtoms,
|
|
489
|
+
mountCallbacks,
|
|
490
|
+
unmountCallbacks,
|
|
491
|
+
storeHooks,
|
|
492
|
+
// atom interceptors
|
|
493
|
+
atomRead,
|
|
494
|
+
atomWrite,
|
|
495
|
+
atomOnInit,
|
|
496
|
+
atomOnMount,
|
|
497
|
+
// building-block functions
|
|
498
|
+
ensureAtomState,
|
|
499
|
+
flushCallbacks,
|
|
500
|
+
recomputeInvalidatedAtoms,
|
|
501
|
+
readAtomState,
|
|
502
|
+
invalidateDependents,
|
|
503
|
+
writeAtomState,
|
|
504
|
+
mountDependencies,
|
|
505
|
+
mountAtom,
|
|
506
|
+
unmountAtom
|
|
507
|
+
];
|
|
508
|
+
const store = {
|
|
509
|
+
get: (atom) => returnAtomValue(readAtomState(atom)),
|
|
510
|
+
set: (atom, ...args) => {
|
|
511
|
+
try {
|
|
512
|
+
return writeAtomState(atom, ...args);
|
|
513
|
+
} finally {
|
|
514
|
+
recomputeInvalidatedAtoms();
|
|
515
|
+
flushCallbacks();
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
sub: (atom, listener) => {
|
|
519
|
+
const mounted = mountAtom(atom);
|
|
520
|
+
const listeners = mounted.l;
|
|
521
|
+
listeners.add(listener);
|
|
522
|
+
flushCallbacks();
|
|
523
|
+
return () => {
|
|
524
|
+
listeners.delete(listener);
|
|
525
|
+
unmountAtom(atom);
|
|
526
|
+
flushCallbacks();
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
Object.defineProperty(store, BUILDING_BLOCKS, { value: buildingBlocks });
|
|
531
|
+
return store;
|
|
532
|
+
};
|
|
533
|
+
const INTERNAL_buildStoreRev1 = buildStore;
|
|
534
|
+
const INTERNAL_initializeStoreHooks = initializeStoreHooks;
|
|
535
|
+
const INTERNAL_registerAbortHandler = registerAbortHandler;
|
|
536
|
+
|
|
537
|
+
exports.INTERNAL_buildStoreRev1 = INTERNAL_buildStoreRev1;
|
|
538
|
+
exports.INTERNAL_initializeStoreHooks = INTERNAL_initializeStoreHooks;
|
|
539
|
+
exports.INTERNAL_registerAbortHandler = INTERNAL_registerAbortHandler;
|