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