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