cross-state 0.27.2 → 0.29.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/cjs/index.cjs +9 -9
- package/dist/cjs/react/index.cjs +7 -1
- package/dist/cjs/react/index.cjs.map +1 -1
- package/dist/cjs/react/register.cjs +3 -3
- package/dist/cjs/scope.cjs +570 -349
- package/dist/cjs/scope.cjs.map +1 -1
- package/dist/cjs/scope2.cjs +349 -570
- package/dist/cjs/scope2.cjs.map +1 -1
- package/dist/es/index.mjs +2 -2
- package/dist/es/react/index.mjs +8 -2
- package/dist/es/react/index.mjs.map +1 -1
- package/dist/es/react/register.mjs +3 -3
- package/dist/es/scope.mjs +571 -350
- package/dist/es/scope.mjs.map +1 -1
- package/dist/es/scope2.mjs +350 -571
- package/dist/es/scope2.mjs.map +1 -1
- package/dist/types/react/form/form.d.ts +1 -0
- package/package.json +1 -1
package/dist/es/scope2.mjs
CHANGED
|
@@ -1,614 +1,393 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import require$$0, { useRef, useMemo, useCallback, useLayoutEffect, useDebugValue, useEffect, useContext, createContext } from "react";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
1
|
+
import { a as autobind, S as Store, c as createStore, b as calcDuration, m as makeSelector } from "./store.mjs";
|
|
4
2
|
import { h as hash } from "./hash.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return [value, (other) => equals(value, other)];
|
|
3
|
+
class ResourceGroup {
|
|
4
|
+
constructor(name) {
|
|
5
|
+
this.name = name;
|
|
6
|
+
this.refMap = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
this.refSet = /* @__PURE__ */ new Set();
|
|
8
|
+
autobind(ResourceGroup);
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function trackComplexProp(function_, ...args) {
|
|
18
|
-
const [proxiedValue, equals2, revoke] = trackingProxy(function_(value, ...args));
|
|
19
|
-
deps.push((otherValue) => {
|
|
20
|
-
if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return equals2(function_(otherValue, ...args));
|
|
24
|
-
});
|
|
25
|
-
if (revoke) {
|
|
26
|
-
revokations.push(revoke);
|
|
27
|
-
}
|
|
28
|
-
return proxiedValue;
|
|
10
|
+
add(resource) {
|
|
11
|
+
const ref = new WeakRef(resource);
|
|
12
|
+
this.refMap.set(resource, ref);
|
|
13
|
+
this.refSet.add(ref);
|
|
29
14
|
}
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
delete(resource) {
|
|
16
|
+
const ref = this.refMap.get(resource);
|
|
17
|
+
if (ref) {
|
|
18
|
+
this.refMap.delete(resource);
|
|
19
|
+
this.refSet.delete(ref);
|
|
20
|
+
}
|
|
36
21
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};
|
|
46
|
-
if (writable === false && configurable === false) {
|
|
47
|
-
return target[p];
|
|
22
|
+
invalidateAll() {
|
|
23
|
+
for (const ref of this.refSet) {
|
|
24
|
+
const resource = ref.deref();
|
|
25
|
+
if (resource) {
|
|
26
|
+
resource.invalidateAll();
|
|
27
|
+
} else {
|
|
28
|
+
this.refSet.delete(ref);
|
|
48
29
|
}
|
|
49
|
-
return trackComplexProp(Reflect.get, p, receiver);
|
|
50
|
-
},
|
|
51
|
-
getOwnPropertyDescriptor(target, p) {
|
|
52
|
-
const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};
|
|
53
|
-
if (writable === false && configurable === false) {
|
|
54
|
-
return Reflect.getOwnPropertyDescriptor(target, p);
|
|
55
|
-
}
|
|
56
|
-
return trackComplexProp(Reflect.getOwnPropertyDescriptor, p);
|
|
57
|
-
},
|
|
58
|
-
ownKeys() {
|
|
59
|
-
return trackComplexProp(Reflect.ownKeys);
|
|
60
|
-
},
|
|
61
|
-
getPrototypeOf() {
|
|
62
|
-
return trackSimpleProp(Reflect.getPrototypeOf);
|
|
63
|
-
},
|
|
64
|
-
has(_target, p) {
|
|
65
|
-
return trackSimpleProp(Reflect.has, p);
|
|
66
|
-
},
|
|
67
|
-
isExtensible() {
|
|
68
|
-
return trackSimpleProp(Reflect.isExtensible);
|
|
69
30
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
31
|
+
}
|
|
32
|
+
clearAll() {
|
|
33
|
+
for (const ref of this.refSet) {
|
|
34
|
+
const resource = ref.deref();
|
|
35
|
+
if (resource) {
|
|
36
|
+
resource.clearAll();
|
|
37
|
+
} else {
|
|
38
|
+
this.refSet.delete(ref);
|
|
39
|
+
}
|
|
77
40
|
}
|
|
78
|
-
|
|
41
|
+
}
|
|
79
42
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
hasRequiredUseSyncExternalStoreShim_development = 1;
|
|
98
|
-
if (process.env.NODE_ENV !== "production") {
|
|
99
|
-
(function() {
|
|
100
|
-
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
101
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
102
|
-
}
|
|
103
|
-
var React = require$$0;
|
|
104
|
-
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
105
|
-
function error(format) {
|
|
106
|
-
{
|
|
107
|
-
{
|
|
108
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
109
|
-
args[_key2 - 1] = arguments[_key2];
|
|
110
|
-
}
|
|
111
|
-
printWarning("error", format, args);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function printWarning(level, format, args) {
|
|
116
|
-
{
|
|
117
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
118
|
-
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
119
|
-
if (stack !== "") {
|
|
120
|
-
format += "%s";
|
|
121
|
-
args = args.concat([stack]);
|
|
122
|
-
}
|
|
123
|
-
var argsWithFormat = args.map(function(item) {
|
|
124
|
-
return String(item);
|
|
125
|
-
});
|
|
126
|
-
argsWithFormat.unshift("Warning: " + format);
|
|
127
|
-
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function is(x, y) {
|
|
131
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
132
|
-
}
|
|
133
|
-
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
134
|
-
var useState = React.useState, useEffect2 = React.useEffect, useLayoutEffect2 = React.useLayoutEffect, useDebugValue2 = React.useDebugValue;
|
|
135
|
-
var didWarnOld18Alpha = false;
|
|
136
|
-
var didWarnUncachedGetSnapshot = false;
|
|
137
|
-
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
138
|
-
{
|
|
139
|
-
if (!didWarnOld18Alpha) {
|
|
140
|
-
if (React.startTransition !== void 0) {
|
|
141
|
-
didWarnOld18Alpha = true;
|
|
142
|
-
error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release.");
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
var value = getSnapshot();
|
|
147
|
-
{
|
|
148
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
149
|
-
var cachedValue = getSnapshot();
|
|
150
|
-
if (!objectIs(value, cachedValue)) {
|
|
151
|
-
error("The result of getSnapshot should be cached to avoid an infinite loop");
|
|
152
|
-
didWarnUncachedGetSnapshot = true;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
var _useState = useState({
|
|
157
|
-
inst: {
|
|
158
|
-
value,
|
|
159
|
-
getSnapshot
|
|
160
|
-
}
|
|
161
|
-
}), inst = _useState[0].inst, forceUpdate = _useState[1];
|
|
162
|
-
useLayoutEffect2(function() {
|
|
163
|
-
inst.value = value;
|
|
164
|
-
inst.getSnapshot = getSnapshot;
|
|
165
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
166
|
-
forceUpdate({
|
|
167
|
-
inst
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}, [subscribe, value, getSnapshot]);
|
|
171
|
-
useEffect2(function() {
|
|
172
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
173
|
-
forceUpdate({
|
|
174
|
-
inst
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
var handleStoreChange = function() {
|
|
178
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
179
|
-
forceUpdate({
|
|
180
|
-
inst
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
return subscribe(handleStoreChange);
|
|
185
|
-
}, [subscribe]);
|
|
186
|
-
useDebugValue2(value);
|
|
187
|
-
return value;
|
|
188
|
-
}
|
|
189
|
-
function checkIfSnapshotChanged(inst) {
|
|
190
|
-
var latestGetSnapshot = inst.getSnapshot;
|
|
191
|
-
var prevValue = inst.value;
|
|
192
|
-
try {
|
|
193
|
-
var nextValue = latestGetSnapshot();
|
|
194
|
-
return !objectIs(prevValue, nextValue);
|
|
195
|
-
} catch (error2) {
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
200
|
-
return getSnapshot();
|
|
43
|
+
const allResources = /* @__PURE__ */ new ResourceGroup();
|
|
44
|
+
function createResourceGroup(name) {
|
|
45
|
+
return new ResourceGroup(name);
|
|
46
|
+
}
|
|
47
|
+
class InstanceCache {
|
|
48
|
+
constructor(factory, cacheTime) {
|
|
49
|
+
this.factory = factory;
|
|
50
|
+
this.cacheTime = cacheTime;
|
|
51
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
52
|
+
this.interval = this.cacheTime ? setInterval(() => this.cleanup(), Math.max(this.cacheTime / 10, 1)) : void 0;
|
|
53
|
+
}
|
|
54
|
+
cleanup() {
|
|
55
|
+
var _a;
|
|
56
|
+
const cutoff = this.now() - (this.cacheTime ?? 0);
|
|
57
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
58
|
+
if (entry.ref && entry.t <= cutoff) {
|
|
59
|
+
delete entry.ref;
|
|
201
60
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
var shim2 = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
205
|
-
var useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim2;
|
|
206
|
-
useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
|
|
207
|
-
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
|
|
208
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
61
|
+
if (!entry.ref && !((_a = entry.weakRef) == null ? void 0 : _a.deref())) {
|
|
62
|
+
this.cache.delete(key);
|
|
209
63
|
}
|
|
210
|
-
}
|
|
64
|
+
}
|
|
211
65
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
function h(a, b) {
|
|
231
|
-
return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
|
|
66
|
+
get(...args) {
|
|
67
|
+
var _a;
|
|
68
|
+
const key = hash(args);
|
|
69
|
+
let entry = this.cache.get(key);
|
|
70
|
+
let value = (entry == null ? void 0 : entry.ref) ?? ((_a = entry == null ? void 0 : entry.weakRef) == null ? void 0 : _a.deref());
|
|
71
|
+
if (!entry || !value) {
|
|
72
|
+
value = this.factory(...args);
|
|
73
|
+
entry = {
|
|
74
|
+
t: this.now(),
|
|
75
|
+
ref: value,
|
|
76
|
+
weakRef: new WeakRef(value)
|
|
77
|
+
};
|
|
78
|
+
this.cache.set(key, entry);
|
|
79
|
+
} else {
|
|
80
|
+
entry.t = this.now();
|
|
81
|
+
entry.ref ?? (entry.ref = value);
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
232
84
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
c.getSnapshot = b;
|
|
239
|
-
r(c) && g({ inst: c });
|
|
240
|
-
}, [a, d, b]);
|
|
241
|
-
m(function() {
|
|
242
|
-
r(c) && g({ inst: c });
|
|
243
|
-
return a(function() {
|
|
244
|
-
r(c) && g({ inst: c });
|
|
245
|
-
});
|
|
246
|
-
}, [a]);
|
|
247
|
-
p(d);
|
|
248
|
-
return d;
|
|
85
|
+
values() {
|
|
86
|
+
return [...this.cache.values()].map((entry) => {
|
|
87
|
+
var _a;
|
|
88
|
+
return entry.ref ?? ((_a = entry.weakRef) == null ? void 0 : _a.deref());
|
|
89
|
+
}).filter((value) => !!value);
|
|
249
90
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
try {
|
|
254
|
-
var d = b();
|
|
255
|
-
return !k(a, d);
|
|
256
|
-
} catch (f) {
|
|
257
|
-
return true;
|
|
91
|
+
stop() {
|
|
92
|
+
if (this.interval) {
|
|
93
|
+
clearInterval(this.interval);
|
|
258
94
|
}
|
|
259
95
|
}
|
|
260
|
-
|
|
261
|
-
return
|
|
96
|
+
stats() {
|
|
97
|
+
return {
|
|
98
|
+
count: this.cache.size,
|
|
99
|
+
withRef: [...this.cache.values()].filter((x) => !!x.ref).length,
|
|
100
|
+
withWeakRef: [...this.cache.values()].filter((x) => {
|
|
101
|
+
var _a;
|
|
102
|
+
return !!((_a = x.weakRef) == null ? void 0 : _a.deref());
|
|
103
|
+
}).length
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
now() {
|
|
107
|
+
return performance.now();
|
|
262
108
|
}
|
|
263
|
-
var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
|
|
264
|
-
useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u;
|
|
265
|
-
return useSyncExternalStoreShim_production_min;
|
|
266
109
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
110
|
+
class PromiseWithState extends Promise {
|
|
111
|
+
constructor(value, state = { status: "pending" }) {
|
|
112
|
+
super((resolve) => resolve(value));
|
|
113
|
+
this.state = state;
|
|
114
|
+
value.then((value2) => {
|
|
115
|
+
this.state = { status: "value", value: value2 };
|
|
116
|
+
}).catch((error) => {
|
|
117
|
+
this.state = { status: "error", error };
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
static resolve(value) {
|
|
121
|
+
return new PromiseWithState(Promise.resolve(value), {
|
|
122
|
+
status: "value",
|
|
123
|
+
value
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
static reject(error) {
|
|
127
|
+
return new PromiseWithState(Promise.reject(error), { status: "error", error });
|
|
276
128
|
}
|
|
277
|
-
return shim.exports;
|
|
278
129
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
* LICENSE file in the root directory of this source tree.
|
|
287
|
-
*/
|
|
288
|
-
var hasRequiredWithSelector_development;
|
|
289
|
-
function requireWithSelector_development() {
|
|
290
|
-
if (hasRequiredWithSelector_development)
|
|
291
|
-
return withSelector_development;
|
|
292
|
-
hasRequiredWithSelector_development = 1;
|
|
293
|
-
if (process.env.NODE_ENV !== "production") {
|
|
294
|
-
(function() {
|
|
295
|
-
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
296
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
297
|
-
}
|
|
298
|
-
var React = require$$0;
|
|
299
|
-
var shim2 = requireShim();
|
|
300
|
-
function is(x, y) {
|
|
301
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
302
|
-
}
|
|
303
|
-
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
304
|
-
var useSyncExternalStore = shim2.useSyncExternalStore;
|
|
305
|
-
var useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo2 = React.useMemo, useDebugValue2 = React.useDebugValue;
|
|
306
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
307
|
-
var instRef = useRef2(null);
|
|
308
|
-
var inst;
|
|
309
|
-
if (instRef.current === null) {
|
|
310
|
-
inst = {
|
|
311
|
-
hasValue: false,
|
|
312
|
-
value: null
|
|
313
|
-
};
|
|
314
|
-
instRef.current = inst;
|
|
315
|
-
} else {
|
|
316
|
-
inst = instRef.current;
|
|
130
|
+
class Cache extends Store {
|
|
131
|
+
constructor(getter, options = {}, derivedFromCache, _call) {
|
|
132
|
+
super(
|
|
133
|
+
function() {
|
|
134
|
+
let result = getter.apply(this);
|
|
135
|
+
if (result instanceof Function) {
|
|
136
|
+
result = result(this);
|
|
317
137
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
var nextSelection = selector(nextSnapshot);
|
|
345
|
-
if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
|
|
346
|
-
return prevSelection;
|
|
347
|
-
}
|
|
348
|
-
memoizedSnapshot = nextSnapshot;
|
|
349
|
-
memoizedSelection = nextSelection;
|
|
350
|
-
return nextSelection;
|
|
351
|
-
};
|
|
352
|
-
var maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot;
|
|
353
|
-
var getSnapshotWithSelector = function() {
|
|
354
|
-
return memoizedSelector(getSnapshot());
|
|
355
|
-
};
|
|
356
|
-
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
|
|
357
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
358
|
-
};
|
|
359
|
-
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
360
|
-
}, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
|
|
361
|
-
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
362
|
-
useEffect2(function() {
|
|
363
|
-
inst.hasValue = true;
|
|
364
|
-
inst.value = value;
|
|
365
|
-
}, [value]);
|
|
366
|
-
useDebugValue2(value);
|
|
367
|
-
return value;
|
|
368
|
-
}
|
|
369
|
-
withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
|
|
370
|
-
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
|
|
371
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
138
|
+
return result;
|
|
139
|
+
},
|
|
140
|
+
options,
|
|
141
|
+
void 0,
|
|
142
|
+
_call
|
|
143
|
+
);
|
|
144
|
+
this.options = options;
|
|
145
|
+
this.derivedFromCache = derivedFromCache;
|
|
146
|
+
this.state = createStore({
|
|
147
|
+
status: "pending",
|
|
148
|
+
isStale: true,
|
|
149
|
+
isUpdating: false
|
|
150
|
+
});
|
|
151
|
+
autobind(Cache);
|
|
152
|
+
this.calculationHelper.options.onInvalidate = () => this.invalidate({ invalidateDependencies: false });
|
|
153
|
+
this.watchPromise();
|
|
154
|
+
this.watchFocus();
|
|
155
|
+
}
|
|
156
|
+
get({ update = "whenStale", backgroundUpdate = false } = {}) {
|
|
157
|
+
var _a;
|
|
158
|
+
const promise = (_a = this._value) == null ? void 0 : _a.v;
|
|
159
|
+
const stalePromise = this.stalePromise;
|
|
160
|
+
if (update === "whenMissing" && !promise && !stalePromise || update === "whenStale" && !promise || update === "force") {
|
|
161
|
+
this.calculationHelper.execute();
|
|
162
|
+
if (!promise && !stalePromise || !backgroundUpdate) {
|
|
163
|
+
return super.get();
|
|
372
164
|
}
|
|
373
|
-
}
|
|
165
|
+
}
|
|
166
|
+
if (!promise || stalePromise && backgroundUpdate) {
|
|
167
|
+
return stalePromise;
|
|
168
|
+
}
|
|
169
|
+
return promise;
|
|
374
170
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
var withSelector_production_min = {};
|
|
378
|
-
/**
|
|
379
|
-
* @license React
|
|
380
|
-
* use-sync-external-store-shim/with-selector.production.min.js
|
|
381
|
-
*
|
|
382
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
383
|
-
*
|
|
384
|
-
* This source code is licensed under the MIT license found in the
|
|
385
|
-
* LICENSE file in the root directory of this source tree.
|
|
386
|
-
*/
|
|
387
|
-
var hasRequiredWithSelector_production_min;
|
|
388
|
-
function requireWithSelector_production_min() {
|
|
389
|
-
if (hasRequiredWithSelector_production_min)
|
|
390
|
-
return withSelector_production_min;
|
|
391
|
-
hasRequiredWithSelector_production_min = 1;
|
|
392
|
-
var h = require$$0, n = requireShim();
|
|
393
|
-
function p(a, b) {
|
|
394
|
-
return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
|
|
171
|
+
updateValue(value) {
|
|
172
|
+
this.set(PromiseWithState.resolve(value));
|
|
395
173
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
var f = { hasValue: false, value: null };
|
|
401
|
-
c.current = f;
|
|
402
|
-
} else
|
|
403
|
-
f = c.current;
|
|
404
|
-
c = v(function() {
|
|
405
|
-
function a2(a3) {
|
|
406
|
-
if (!c2) {
|
|
407
|
-
c2 = true;
|
|
408
|
-
d2 = a3;
|
|
409
|
-
a3 = l(a3);
|
|
410
|
-
if (void 0 !== g && f.hasValue) {
|
|
411
|
-
var b2 = f.value;
|
|
412
|
-
if (g(b2, a3))
|
|
413
|
-
return k = b2;
|
|
414
|
-
}
|
|
415
|
-
return k = a3;
|
|
416
|
-
}
|
|
417
|
-
b2 = k;
|
|
418
|
-
if (q(d2, a3))
|
|
419
|
-
return b2;
|
|
420
|
-
var e2 = l(a3);
|
|
421
|
-
if (void 0 !== g && g(b2, e2))
|
|
422
|
-
return b2;
|
|
423
|
-
d2 = a3;
|
|
424
|
-
return k = e2;
|
|
425
|
-
}
|
|
426
|
-
var c2 = false, d2, k, m = void 0 === e ? null : e;
|
|
427
|
-
return [function() {
|
|
428
|
-
return a2(b());
|
|
429
|
-
}, null === m ? void 0 : function() {
|
|
430
|
-
return a2(m());
|
|
431
|
-
}];
|
|
432
|
-
}, [b, e, l, g]);
|
|
433
|
-
var d = r(a, c[0], c[1]);
|
|
434
|
-
u(function() {
|
|
435
|
-
f.hasValue = true;
|
|
436
|
-
f.value = d;
|
|
437
|
-
}, [d]);
|
|
438
|
-
w(d);
|
|
439
|
-
return d;
|
|
440
|
-
};
|
|
441
|
-
return withSelector_production_min;
|
|
442
|
-
}
|
|
443
|
-
if (process.env.NODE_ENV === "production") {
|
|
444
|
-
withSelector.exports = requireWithSelector_production_min();
|
|
445
|
-
} else {
|
|
446
|
-
withSelector.exports = requireWithSelector_development();
|
|
447
|
-
}
|
|
448
|
-
var withSelectorExports = withSelector.exports;
|
|
449
|
-
function useStore(store, argument1, argument2) {
|
|
450
|
-
const selector = makeSelector(
|
|
451
|
-
typeof argument1 === "function" || typeof argument1 === "string" ? argument1 : void 0
|
|
452
|
-
);
|
|
453
|
-
const {
|
|
454
|
-
disableTrackingProxy = true,
|
|
455
|
-
equals = deepEqual,
|
|
456
|
-
withViewTransition,
|
|
457
|
-
...options
|
|
458
|
-
} = typeof argument1 === "object" ? argument1 : argument2 ?? {};
|
|
459
|
-
const lastEqualsRef = useRef();
|
|
460
|
-
const { rootStore, mappingSelector } = useMemo(() => {
|
|
174
|
+
updateError(error) {
|
|
175
|
+
this.set(PromiseWithState.reject(error));
|
|
176
|
+
}
|
|
177
|
+
invalidate({ invalidateDependencies = true } = {}) {
|
|
461
178
|
var _a;
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
179
|
+
const { clearOnInvalidate = createCache.defaultOptions.clearOnInvalidate } = this.options;
|
|
180
|
+
if (clearOnInvalidate) {
|
|
181
|
+
return this.clear({ invalidateDependencies });
|
|
182
|
+
}
|
|
183
|
+
if (invalidateDependencies) {
|
|
184
|
+
this.calculationHelper.invalidateDependencies();
|
|
185
|
+
}
|
|
186
|
+
const { status, isStale, isUpdating } = this.state.get();
|
|
187
|
+
if (status !== "pending" && !isStale && !isUpdating) {
|
|
188
|
+
this.stalePromise = (_a = this._value) == null ? void 0 : _a.v;
|
|
189
|
+
}
|
|
190
|
+
this.state.set((state) => ({
|
|
191
|
+
...state,
|
|
192
|
+
isStale: true,
|
|
193
|
+
isUpdating: false
|
|
194
|
+
}));
|
|
195
|
+
this.calculationHelper.stop();
|
|
196
|
+
super.reset();
|
|
197
|
+
}
|
|
198
|
+
clear({ invalidateDependencies = true } = {}) {
|
|
199
|
+
if (invalidateDependencies) {
|
|
200
|
+
this.calculationHelper.invalidateDependencies();
|
|
471
201
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
202
|
+
this.state.set({
|
|
203
|
+
status: "pending",
|
|
204
|
+
isStale: true,
|
|
205
|
+
isUpdating: false
|
|
206
|
+
});
|
|
207
|
+
delete this.stalePromise;
|
|
208
|
+
this.calculationHelper.stop();
|
|
209
|
+
super.reset();
|
|
210
|
+
}
|
|
211
|
+
mapValue(_selector) {
|
|
212
|
+
const selector = makeSelector(_selector);
|
|
213
|
+
const derivedFromCache = {
|
|
214
|
+
cache: this.derivedFromCache ? this.derivedFromCache.cache : this,
|
|
215
|
+
selectors: this.derivedFromCache ? [...this.derivedFromCache.selectors, _selector] : [_selector]
|
|
216
|
+
};
|
|
217
|
+
const that = this;
|
|
218
|
+
return new Cache(
|
|
219
|
+
async function() {
|
|
220
|
+
const value = await this.use(that);
|
|
221
|
+
return selector(value);
|
|
222
|
+
},
|
|
223
|
+
{},
|
|
224
|
+
derivedFromCache
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
watchPromise() {
|
|
228
|
+
this.subscribe(
|
|
229
|
+
async (promise) => {
|
|
230
|
+
var _a, _b;
|
|
231
|
+
if (promise instanceof PromiseWithState) {
|
|
232
|
+
this.state.set({
|
|
233
|
+
...promise.state,
|
|
234
|
+
isStale: false,
|
|
235
|
+
isUpdating: false
|
|
236
|
+
});
|
|
237
|
+
delete this.stalePromise;
|
|
238
|
+
this.setTimers();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
this.state.set((state) => ({
|
|
242
|
+
...state,
|
|
243
|
+
isUpdating: true
|
|
244
|
+
}));
|
|
245
|
+
this.setTimers();
|
|
246
|
+
try {
|
|
247
|
+
const value = await promise;
|
|
248
|
+
if (promise !== ((_a = this._value) == null ? void 0 : _a.v)) {
|
|
484
249
|
return;
|
|
485
250
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
251
|
+
this.state.set({
|
|
252
|
+
status: "value",
|
|
253
|
+
value,
|
|
254
|
+
isStale: false,
|
|
255
|
+
isUpdating: false
|
|
491
256
|
});
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
257
|
+
delete this.stalePromise;
|
|
258
|
+
this.setTimers();
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (promise !== ((_b = this._value) == null ? void 0 : _b.v)) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
this.state.set({
|
|
264
|
+
status: "error",
|
|
265
|
+
error,
|
|
266
|
+
isStale: false,
|
|
267
|
+
isUpdating: false
|
|
498
268
|
});
|
|
499
|
-
|
|
269
|
+
delete this.stalePromise;
|
|
270
|
+
this.setTimers();
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
{ passive: true }
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
setTimers() {
|
|
277
|
+
if (this.invalidationTimer) {
|
|
278
|
+
clearTimeout(this.invalidationTimer);
|
|
279
|
+
}
|
|
280
|
+
this.invalidationTimer = void 0;
|
|
281
|
+
const state = this.state.get();
|
|
282
|
+
let { invalidateAfter = createCache.defaultOptions.invalidateAfter } = this.options;
|
|
283
|
+
const ref = new WeakRef(this);
|
|
284
|
+
if (state.status === "pending") {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (invalidateAfter instanceof Function) {
|
|
288
|
+
invalidateAfter = invalidateAfter(state);
|
|
289
|
+
}
|
|
290
|
+
if (invalidateAfter !== null && invalidateAfter !== void 0) {
|
|
291
|
+
this.invalidationTimer = setTimeout(
|
|
292
|
+
() => {
|
|
293
|
+
var _a;
|
|
294
|
+
return (_a = ref == null ? void 0 : ref.deref()) == null ? void 0 : _a.invalidate();
|
|
295
|
+
},
|
|
296
|
+
calcDuration(invalidateAfter)
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
watchFocus() {
|
|
301
|
+
const { invalidateOnWindowFocus = createCache.defaultOptions.invalidateOnWindowFocus } = this.options;
|
|
302
|
+
if (!invalidateOnWindowFocus || typeof document === "undefined" || typeof document.addEventListener === "undefined") {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const ref = new WeakRef(this);
|
|
306
|
+
const onFocus = () => {
|
|
307
|
+
const that = ref == null ? void 0 : ref.deref();
|
|
308
|
+
if (!that) {
|
|
309
|
+
document.removeEventListener("visibilitychange", onFocus);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (!document.hidden) {
|
|
313
|
+
that.invalidate();
|
|
500
314
|
}
|
|
501
|
-
|
|
315
|
+
};
|
|
316
|
+
document.addEventListener("visibilitychange", onFocus);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function create(cacheFunction, options) {
|
|
320
|
+
const { clearUnusedAfter = createCache.defaultOptions.clearUnusedAfter, resourceGroup } = options ?? {};
|
|
321
|
+
let baseInstance;
|
|
322
|
+
const instanceCache = new InstanceCache(
|
|
323
|
+
(...args) => {
|
|
324
|
+
if (args.length === 0 && baseInstance) {
|
|
325
|
+
return baseInstance;
|
|
326
|
+
}
|
|
327
|
+
return new Cache(function() {
|
|
328
|
+
return cacheFunction.apply(this, args);
|
|
329
|
+
}, options);
|
|
502
330
|
},
|
|
503
|
-
|
|
331
|
+
clearUnusedAfter ? calcDuration(clearUnusedAfter) : void 0
|
|
504
332
|
);
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
333
|
+
const get = (...args) => {
|
|
334
|
+
return instanceCache.get(...args);
|
|
335
|
+
};
|
|
336
|
+
const invalidateAll = () => {
|
|
337
|
+
for (const instance of instanceCache.values()) {
|
|
338
|
+
instance.invalidate();
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
const clearAll = () => {
|
|
342
|
+
for (const instance of instanceCache.values()) {
|
|
343
|
+
instance.clear();
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
baseInstance = Object.assign(
|
|
347
|
+
new Cache(
|
|
348
|
+
function() {
|
|
349
|
+
return cacheFunction.apply(this);
|
|
350
|
+
},
|
|
351
|
+
options,
|
|
352
|
+
void 0,
|
|
353
|
+
get
|
|
354
|
+
),
|
|
355
|
+
{
|
|
356
|
+
invalidateAll,
|
|
357
|
+
clearAll
|
|
514
358
|
}
|
|
515
359
|
);
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
[value, lastEquals, revoke] = trackingProxy(value, equals);
|
|
360
|
+
const groups = Array.isArray(resourceGroup) ? resourceGroup : resourceGroup ? [resourceGroup] : [];
|
|
361
|
+
for (const group of groups.concat(allResources)) {
|
|
362
|
+
group.add(baseInstance);
|
|
520
363
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
revoke == null ? void 0 : revoke();
|
|
524
|
-
});
|
|
525
|
-
useDebugValue(value);
|
|
526
|
-
return value;
|
|
364
|
+
get(...[]);
|
|
365
|
+
return baseInstance;
|
|
527
366
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
store = store.map(selector, updater);
|
|
367
|
+
const createCache = /* @__PURE__ */ Object.assign(create, {
|
|
368
|
+
defaultOptions: {
|
|
369
|
+
invalidateOnWindowFocus: true,
|
|
370
|
+
invalidateOnActivation: true,
|
|
371
|
+
clearUnusedAfter: { days: 1 }
|
|
534
372
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
function boundUseProp(...args) {
|
|
542
|
-
return useProp(this, ...args);
|
|
543
|
-
}
|
|
544
|
-
const reactMethods = {
|
|
545
|
-
useStore: boundUseStore,
|
|
546
|
-
useProp: boundUseProp
|
|
547
|
-
};
|
|
548
|
-
function useCache(cache, { passive, updateOnMount, withViewTransition, ...options } = {}) {
|
|
549
|
-
if (withViewTransition === true) {
|
|
550
|
-
withViewTransition = (state) => state.value;
|
|
373
|
+
});
|
|
374
|
+
class Scope {
|
|
375
|
+
constructor(defaultValue) {
|
|
376
|
+
this.defaultValue = defaultValue;
|
|
377
|
+
autobind(Scope);
|
|
551
378
|
}
|
|
552
|
-
const mappedState = useMemo(() => {
|
|
553
|
-
var _a;
|
|
554
|
-
const rootCache = ((_a = cache.derivedFromCache) == null ? void 0 : _a.cache) ?? cache;
|
|
555
|
-
let selector = (x) => x;
|
|
556
|
-
if (cache.derivedFromCache) {
|
|
557
|
-
selector = (value) => {
|
|
558
|
-
for (const s of cache.derivedFromCache.selectors) {
|
|
559
|
-
value = makeSelector(s)(value);
|
|
560
|
-
}
|
|
561
|
-
return value;
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
return rootCache.state.map((state) => {
|
|
565
|
-
const value = state.status === "value" ? selector(state.value) : void 0;
|
|
566
|
-
return Object.assign(
|
|
567
|
-
[value, state.error, state.isUpdating, state.isStale],
|
|
568
|
-
{ ...state, value }
|
|
569
|
-
);
|
|
570
|
-
});
|
|
571
|
-
}, [cache]);
|
|
572
|
-
useEffect(() => !passive ? cache.subscribe(() => void 0) : void 0, [cache, passive]);
|
|
573
|
-
useEffect(() => {
|
|
574
|
-
if (updateOnMount) {
|
|
575
|
-
cache.invalidate();
|
|
576
|
-
}
|
|
577
|
-
}, []);
|
|
578
|
-
return useStore(mappedState, { ...options, withViewTransition });
|
|
579
|
-
}
|
|
580
|
-
function getScopeContext(scope) {
|
|
581
|
-
scope.context ?? (scope.context = createContext(createStore(scope.defaultValue)));
|
|
582
|
-
return scope.context;
|
|
583
|
-
}
|
|
584
|
-
function ScopeProvider({ scope, store: inputStore, children }) {
|
|
585
|
-
const context = getScopeContext(scope);
|
|
586
|
-
const currentStore = useMemo(
|
|
587
|
-
() => inputStore ?? createStore(scope.defaultValue),
|
|
588
|
-
[scope, inputStore]
|
|
589
|
-
);
|
|
590
|
-
return /* @__PURE__ */ jsx(context.Provider, { value: currentStore, children });
|
|
591
|
-
}
|
|
592
|
-
function useScope(scope) {
|
|
593
|
-
const context = getScopeContext(scope);
|
|
594
|
-
return useContext(context);
|
|
595
|
-
}
|
|
596
|
-
function useScopeStore(scope, options) {
|
|
597
|
-
const store = useScope(scope);
|
|
598
|
-
return useStore(store, options);
|
|
599
379
|
}
|
|
600
|
-
function
|
|
601
|
-
|
|
602
|
-
return useProp(store, options);
|
|
380
|
+
function createScope(defaultValue) {
|
|
381
|
+
return new Scope(defaultValue);
|
|
603
382
|
}
|
|
604
383
|
export {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
384
|
+
Cache as C,
|
|
385
|
+
InstanceCache as I,
|
|
386
|
+
ResourceGroup as R,
|
|
387
|
+
Scope as S,
|
|
388
|
+
allResources as a,
|
|
389
|
+
createResourceGroup as b,
|
|
390
|
+
createCache as c,
|
|
391
|
+
createScope as d
|
|
613
392
|
};
|
|
614
393
|
//# sourceMappingURL=scope2.mjs.map
|