react-shared-states 1.0.11 → 1.0.12
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/README.md +84 -415
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/use-shared-state.d.ts +3 -0
- package/dist/main.esm.js +387 -305
- package/dist/main.min.js +5 -5
- package/package.json +9 -2
- package/tests/index.test.tsx +136 -0
- package/pnpm-workspace.yaml +0 -2
package/dist/main.esm.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-shared-states v1.0.
|
|
2
|
+
* react-shared-states v1.0.12
|
|
3
3
|
* (c) Hichem Taboukouyout
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
* Github: github.com/HichemTab-tech/react-shared-states
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
|
|
8
|
+
import ve, { createContext as be, useMemo as T, useContext as xe, useEffect as ne, useSyncExternalStore as N, useRef as Ee } from "react";
|
|
9
|
+
function me(i) {
|
|
10
|
+
return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
|
|
11
|
+
}
|
|
12
|
+
var F = { exports: {} }, C = {};
|
|
10
13
|
/**
|
|
11
14
|
* @license React
|
|
12
15
|
* react-jsx-runtime.production.js
|
|
@@ -16,29 +19,29 @@ var k = { exports: {} }, j = {};
|
|
|
16
19
|
* This source code is licensed under the MIT license found in the
|
|
17
20
|
* LICENSE file in the root directory of this source tree.
|
|
18
21
|
*/
|
|
19
|
-
var
|
|
20
|
-
function
|
|
21
|
-
if (
|
|
22
|
-
|
|
22
|
+
var Q;
|
|
23
|
+
function Re() {
|
|
24
|
+
if (Q) return C;
|
|
25
|
+
Q = 1;
|
|
23
26
|
var i = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
24
|
-
function r(t,
|
|
25
|
-
var
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
for (var
|
|
29
|
-
|
|
30
|
-
} else
|
|
31
|
-
return
|
|
27
|
+
function r(t, o, a) {
|
|
28
|
+
var n = null;
|
|
29
|
+
if (a !== void 0 && (n = "" + a), o.key !== void 0 && (n = "" + o.key), "key" in o) {
|
|
30
|
+
a = {};
|
|
31
|
+
for (var f in o)
|
|
32
|
+
f !== "key" && (a[f] = o[f]);
|
|
33
|
+
} else a = o;
|
|
34
|
+
return o = a.ref, {
|
|
32
35
|
$$typeof: i,
|
|
33
36
|
type: t,
|
|
34
|
-
key:
|
|
35
|
-
ref:
|
|
36
|
-
props:
|
|
37
|
+
key: n,
|
|
38
|
+
ref: o !== void 0 ? o : null,
|
|
39
|
+
props: a
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
|
-
return
|
|
42
|
+
return C.Fragment = e, C.jsx = r, C.jsxs = r, C;
|
|
40
43
|
}
|
|
41
|
-
var
|
|
44
|
+
var D = {};
|
|
42
45
|
/**
|
|
43
46
|
* @license React
|
|
44
47
|
* react-jsx-runtime.development.js
|
|
@@ -48,47 +51,47 @@ var C = {};
|
|
|
48
51
|
* This source code is licensed under the MIT license found in the
|
|
49
52
|
* LICENSE file in the root directory of this source tree.
|
|
50
53
|
*/
|
|
51
|
-
var
|
|
52
|
-
function
|
|
53
|
-
return
|
|
54
|
+
var K;
|
|
55
|
+
function _e() {
|
|
56
|
+
return K || (K = 1, process.env.NODE_ENV !== "production" && function() {
|
|
54
57
|
function i(s) {
|
|
55
58
|
if (s == null) return null;
|
|
56
59
|
if (typeof s == "function")
|
|
57
|
-
return s.$$typeof ===
|
|
60
|
+
return s.$$typeof === he ? null : s.displayName || s.name || null;
|
|
58
61
|
if (typeof s == "string") return s;
|
|
59
62
|
switch (s) {
|
|
60
|
-
case
|
|
63
|
+
case x:
|
|
61
64
|
return "Fragment";
|
|
62
|
-
case y:
|
|
63
|
-
return "Profiler";
|
|
64
65
|
case P:
|
|
66
|
+
return "Profiler";
|
|
67
|
+
case O:
|
|
65
68
|
return "StrictMode";
|
|
66
|
-
case
|
|
69
|
+
case fe:
|
|
67
70
|
return "Suspense";
|
|
68
|
-
case
|
|
71
|
+
case le:
|
|
69
72
|
return "SuspenseList";
|
|
70
|
-
case
|
|
73
|
+
case pe:
|
|
71
74
|
return "Activity";
|
|
72
75
|
}
|
|
73
76
|
if (typeof s == "object")
|
|
74
77
|
switch (typeof s.tag == "number" && console.error(
|
|
75
78
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
76
79
|
), s.$$typeof) {
|
|
77
|
-
case
|
|
80
|
+
case v:
|
|
78
81
|
return "Portal";
|
|
79
|
-
case
|
|
82
|
+
case ce:
|
|
80
83
|
return (s.displayName || "Context") + ".Provider";
|
|
81
|
-
case
|
|
84
|
+
case ie:
|
|
82
85
|
return (s._context.displayName || "Context") + ".Consumer";
|
|
83
|
-
case
|
|
84
|
-
var
|
|
85
|
-
return s = s.displayName, s || (s =
|
|
86
|
-
case
|
|
87
|
-
return
|
|
88
|
-
case
|
|
89
|
-
|
|
86
|
+
case ue:
|
|
87
|
+
var u = s.render;
|
|
88
|
+
return s = s.displayName, s || (s = u.displayName || u.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
|
|
89
|
+
case de:
|
|
90
|
+
return u = s.displayName || null, u !== null ? u : i(s.type) || "Memo";
|
|
91
|
+
case U:
|
|
92
|
+
u = s._payload, s = s._init;
|
|
90
93
|
try {
|
|
91
|
-
return i(s(
|
|
94
|
+
return i(s(u));
|
|
92
95
|
} catch {
|
|
93
96
|
}
|
|
94
97
|
}
|
|
@@ -100,73 +103,73 @@ function ve() {
|
|
|
100
103
|
function r(s) {
|
|
101
104
|
try {
|
|
102
105
|
e(s);
|
|
103
|
-
var
|
|
106
|
+
var u = !1;
|
|
104
107
|
} catch {
|
|
105
|
-
|
|
108
|
+
u = !0;
|
|
106
109
|
}
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
var
|
|
110
|
-
return
|
|
111
|
-
|
|
110
|
+
if (u) {
|
|
111
|
+
u = console;
|
|
112
|
+
var h = u.error, E = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
|
|
113
|
+
return h.call(
|
|
114
|
+
u,
|
|
112
115
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
113
|
-
|
|
116
|
+
E
|
|
114
117
|
), e(s);
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
function t(s) {
|
|
118
|
-
if (s ===
|
|
119
|
-
if (typeof s == "object" && s !== null && s.$$typeof ===
|
|
121
|
+
if (s === x) return "<>";
|
|
122
|
+
if (typeof s == "object" && s !== null && s.$$typeof === U)
|
|
120
123
|
return "<...>";
|
|
121
124
|
try {
|
|
122
|
-
var
|
|
123
|
-
return
|
|
125
|
+
var u = i(s);
|
|
126
|
+
return u ? "<" + u + ">" : "<...>";
|
|
124
127
|
} catch {
|
|
125
128
|
return "<...>";
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
|
-
function
|
|
129
|
-
var s =
|
|
131
|
+
function o() {
|
|
132
|
+
var s = $.A;
|
|
130
133
|
return s === null ? null : s.getOwner();
|
|
131
134
|
}
|
|
132
|
-
function
|
|
135
|
+
function a() {
|
|
133
136
|
return Error("react-stack-top-frame");
|
|
134
137
|
}
|
|
135
|
-
function
|
|
136
|
-
if (
|
|
137
|
-
var
|
|
138
|
-
if (
|
|
138
|
+
function n(s) {
|
|
139
|
+
if (B.call(s, "key")) {
|
|
140
|
+
var u = Object.getOwnPropertyDescriptor(s, "key").get;
|
|
141
|
+
if (u && u.isReactWarning) return !1;
|
|
139
142
|
}
|
|
140
143
|
return s.key !== void 0;
|
|
141
144
|
}
|
|
142
|
-
function
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
+
function f(s, u) {
|
|
146
|
+
function h() {
|
|
147
|
+
J || (J = !0, console.error(
|
|
145
148
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
146
|
-
|
|
149
|
+
u
|
|
147
150
|
));
|
|
148
151
|
}
|
|
149
|
-
|
|
150
|
-
get:
|
|
152
|
+
h.isReactWarning = !0, Object.defineProperty(s, "key", {
|
|
153
|
+
get: h,
|
|
151
154
|
configurable: !0
|
|
152
155
|
});
|
|
153
156
|
}
|
|
154
|
-
function
|
|
157
|
+
function c() {
|
|
155
158
|
var s = i(this.type);
|
|
156
|
-
return
|
|
159
|
+
return M[s] || (M[s] = !0, console.error(
|
|
157
160
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
158
161
|
)), s = this.props.ref, s !== void 0 ? s : null;
|
|
159
162
|
}
|
|
160
|
-
function
|
|
161
|
-
return
|
|
162
|
-
$$typeof:
|
|
163
|
+
function g(s, u, h, E, A, w, Y, I) {
|
|
164
|
+
return h = w.ref, s = {
|
|
165
|
+
$$typeof: b,
|
|
163
166
|
type: s,
|
|
164
|
-
key:
|
|
165
|
-
props:
|
|
166
|
-
_owner:
|
|
167
|
-
}, (
|
|
167
|
+
key: u,
|
|
168
|
+
props: w,
|
|
169
|
+
_owner: A
|
|
170
|
+
}, (h !== void 0 ? h : null) !== null ? Object.defineProperty(s, "ref", {
|
|
168
171
|
enumerable: !1,
|
|
169
|
-
get:
|
|
172
|
+
get: c
|
|
170
173
|
}) : Object.defineProperty(s, "ref", { enumerable: !1, value: null }), s._store = {}, Object.defineProperty(s._store, "validated", {
|
|
171
174
|
configurable: !1,
|
|
172
175
|
enumerable: !1,
|
|
@@ -186,172 +189,172 @@ function ve() {
|
|
|
186
189
|
configurable: !1,
|
|
187
190
|
enumerable: !1,
|
|
188
191
|
writable: !0,
|
|
189
|
-
value:
|
|
192
|
+
value: I
|
|
190
193
|
}), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
|
|
191
194
|
}
|
|
192
|
-
function
|
|
193
|
-
var
|
|
194
|
-
if (
|
|
195
|
-
if (
|
|
196
|
-
if (
|
|
197
|
-
for (
|
|
198
|
-
l(
|
|
199
|
-
Object.freeze && Object.freeze(
|
|
195
|
+
function p(s, u, h, E, A, w, Y, I) {
|
|
196
|
+
var m = u.children;
|
|
197
|
+
if (m !== void 0)
|
|
198
|
+
if (E)
|
|
199
|
+
if (Se(m)) {
|
|
200
|
+
for (E = 0; E < m.length; E++)
|
|
201
|
+
l(m[E]);
|
|
202
|
+
Object.freeze && Object.freeze(m);
|
|
200
203
|
} else
|
|
201
204
|
console.error(
|
|
202
205
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
203
206
|
);
|
|
204
|
-
else l(
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
var
|
|
208
|
-
return
|
|
207
|
+
else l(m);
|
|
208
|
+
if (B.call(u, "key")) {
|
|
209
|
+
m = i(s);
|
|
210
|
+
var L = Object.keys(u).filter(function(ge) {
|
|
211
|
+
return ge !== "key";
|
|
209
212
|
});
|
|
210
|
-
|
|
213
|
+
E = 0 < L.length ? "{key: someKey, " + L.join(": ..., ") + ": ...}" : "{key: someKey}", Z[m + E] || (L = 0 < L.length ? "{" + L.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
211
214
|
`A props object containing a "key" prop is being spread into JSX:
|
|
212
215
|
let props = %s;
|
|
213
216
|
<%s {...props} />
|
|
214
217
|
React keys must be passed directly to JSX without using spread:
|
|
215
218
|
let props = %s;
|
|
216
219
|
<%s key={someKey} {...props} />`,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
), Z[
|
|
220
|
+
E,
|
|
221
|
+
m,
|
|
222
|
+
L,
|
|
223
|
+
m
|
|
224
|
+
), Z[m + E] = !0);
|
|
222
225
|
}
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
for (var
|
|
226
|
-
|
|
227
|
-
} else
|
|
228
|
-
return
|
|
229
|
-
|
|
226
|
+
if (m = null, h !== void 0 && (r(h), m = "" + h), n(u) && (r(u.key), m = "" + u.key), "key" in u) {
|
|
227
|
+
h = {};
|
|
228
|
+
for (var q in u)
|
|
229
|
+
q !== "key" && (h[q] = u[q]);
|
|
230
|
+
} else h = u;
|
|
231
|
+
return m && f(
|
|
232
|
+
h,
|
|
230
233
|
typeof s == "function" ? s.displayName || s.name || "Unknown" : s
|
|
231
|
-
),
|
|
234
|
+
), g(
|
|
232
235
|
s,
|
|
233
|
-
|
|
234
|
-
_,
|
|
236
|
+
m,
|
|
235
237
|
w,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
+
A,
|
|
239
|
+
o(),
|
|
240
|
+
h,
|
|
238
241
|
Y,
|
|
239
|
-
|
|
242
|
+
I
|
|
240
243
|
);
|
|
241
244
|
}
|
|
242
245
|
function l(s) {
|
|
243
|
-
typeof s == "object" && s !== null && s.$$typeof ===
|
|
246
|
+
typeof s == "object" && s !== null && s.$$typeof === b && s._store && (s._store.validated = 1);
|
|
244
247
|
}
|
|
245
|
-
var
|
|
248
|
+
var R = ve, b = Symbol.for("react.transitional.element"), v = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), ie = Symbol.for("react.consumer"), ce = Symbol.for("react.context"), ue = Symbol.for("react.forward_ref"), fe = Symbol.for("react.suspense"), le = Symbol.for("react.suspense_list"), de = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), pe = Symbol.for("react.activity"), he = Symbol.for("react.client.reference"), $ = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, Se = Array.isArray, V = console.createTask ? console.createTask : function() {
|
|
246
249
|
return null;
|
|
247
250
|
};
|
|
248
|
-
|
|
251
|
+
R = {
|
|
249
252
|
react_stack_bottom_frame: function(s) {
|
|
250
253
|
return s();
|
|
251
254
|
}
|
|
252
255
|
};
|
|
253
|
-
var
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
)(), H =
|
|
257
|
-
|
|
258
|
-
var
|
|
259
|
-
return
|
|
256
|
+
var J, M = {}, X = R.react_stack_bottom_frame.bind(
|
|
257
|
+
R,
|
|
258
|
+
a
|
|
259
|
+
)(), H = V(t(a)), Z = {};
|
|
260
|
+
D.Fragment = x, D.jsx = function(s, u, h, E, A) {
|
|
261
|
+
var w = 1e4 > $.recentlyCreatedOwnerStacks++;
|
|
262
|
+
return p(
|
|
260
263
|
s,
|
|
261
|
-
|
|
262
|
-
|
|
264
|
+
u,
|
|
265
|
+
h,
|
|
263
266
|
!1,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
267
|
+
E,
|
|
268
|
+
A,
|
|
269
|
+
w ? Error("react-stack-top-frame") : X,
|
|
270
|
+
w ? V(t(s)) : H
|
|
268
271
|
);
|
|
269
|
-
},
|
|
270
|
-
var
|
|
271
|
-
return
|
|
272
|
+
}, D.jsxs = function(s, u, h, E, A) {
|
|
273
|
+
var w = 1e4 > $.recentlyCreatedOwnerStacks++;
|
|
274
|
+
return p(
|
|
272
275
|
s,
|
|
273
|
-
|
|
274
|
-
|
|
276
|
+
u,
|
|
277
|
+
h,
|
|
275
278
|
!0,
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
E,
|
|
280
|
+
A,
|
|
281
|
+
w ? Error("react-stack-top-frame") : X,
|
|
282
|
+
w ? V(t(s)) : H
|
|
280
283
|
);
|
|
281
284
|
};
|
|
282
|
-
}()),
|
|
285
|
+
}()), D;
|
|
283
286
|
}
|
|
284
|
-
var
|
|
285
|
-
function
|
|
286
|
-
return
|
|
287
|
+
var ee;
|
|
288
|
+
function ye() {
|
|
289
|
+
return ee || (ee = 1, process.env.NODE_ENV === "production" ? F.exports = Re() : F.exports = _e()), F.exports;
|
|
287
290
|
}
|
|
288
|
-
var
|
|
289
|
-
let
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
},
|
|
293
|
-
|
|
291
|
+
var we = ye();
|
|
292
|
+
let se = !1;
|
|
293
|
+
const $e = (i) => {
|
|
294
|
+
se = i;
|
|
295
|
+
}, z = (...i) => {
|
|
296
|
+
se && console.log(
|
|
294
297
|
"%c[react-shared-states]",
|
|
295
298
|
"color: #007acc; font-weight: bold",
|
|
296
299
|
...i
|
|
297
300
|
);
|
|
298
|
-
},
|
|
301
|
+
}, j = (i) => {
|
|
299
302
|
if (!i) throw new Error("Value is empty");
|
|
300
303
|
return i;
|
|
301
|
-
},
|
|
304
|
+
}, ae = () => Math.random().toString(36).substring(2, 15), oe = be(void 0), Ve = ({ children: i, scopeName: e }) => {
|
|
302
305
|
if (e && e.includes("//")) throw new Error("scopeName cannot contain '//'");
|
|
303
|
-
return e || (e =
|
|
304
|
-
},
|
|
305
|
-
class
|
|
306
|
+
return e || (e = T(() => ae(), [])), /* @__PURE__ */ we.jsx(oe.Provider, { value: { scopeName: e }, children: i });
|
|
307
|
+
}, Te = () => xe(oe), te = [];
|
|
308
|
+
class d {
|
|
306
309
|
data = /* @__PURE__ */ new Map();
|
|
307
310
|
defaultValue() {
|
|
308
311
|
return {};
|
|
309
312
|
}
|
|
310
313
|
addListener(e, r, t) {
|
|
311
|
-
this.data.has(
|
|
314
|
+
this.data.has(d.prefix(e, r)) || this.data.set(d.prefix(e, r), {
|
|
312
315
|
...this.defaultValue(),
|
|
313
316
|
listeners: []
|
|
314
|
-
}), this.data.get(
|
|
317
|
+
}), this.data.get(d.prefix(e, r)).listeners.push(t);
|
|
315
318
|
}
|
|
316
319
|
removeListener(e, r, t) {
|
|
317
|
-
this.data.has(
|
|
320
|
+
this.data.has(d.prefix(e, r)) && (this.data.get(d.prefix(e, r)).listeners = this.data.get(d.prefix(e, r)).listeners.filter((o) => o !== t));
|
|
318
321
|
}
|
|
319
322
|
callListeners(e, r) {
|
|
320
|
-
this.data.has(
|
|
323
|
+
this.data.has(d.prefix(e, r)) && this.data.get(d.prefix(e, r)).listeners.forEach((t) => t());
|
|
321
324
|
}
|
|
322
|
-
init(e, r, t,
|
|
323
|
-
this.data.has(
|
|
325
|
+
init(e, r, t, o = !1) {
|
|
326
|
+
this.data.has(d.prefix(e, r)) || this.data.set(d.prefix(e, r), {
|
|
324
327
|
...t,
|
|
325
|
-
isStatic:
|
|
328
|
+
isStatic: o,
|
|
326
329
|
listeners: []
|
|
327
330
|
});
|
|
328
331
|
}
|
|
329
332
|
createStatic(e, r) {
|
|
330
|
-
const t = r ?? r ?? "_global",
|
|
331
|
-
key:
|
|
333
|
+
const t = r ?? r ?? "_global", o = {
|
|
334
|
+
key: ae(),
|
|
332
335
|
prefix: t,
|
|
333
336
|
...e
|
|
334
337
|
};
|
|
335
|
-
return
|
|
338
|
+
return te.push(o), this.initStatic(o), o;
|
|
336
339
|
}
|
|
337
340
|
initStatic(e) {
|
|
338
341
|
const { key: r, prefix: t } = e;
|
|
339
342
|
this.init(r, t, this.defaultValue(), !0);
|
|
340
343
|
}
|
|
341
344
|
clearAll(e = !1, r = !1) {
|
|
342
|
-
this.data.forEach((t,
|
|
343
|
-
const [
|
|
344
|
-
this.clear(
|
|
345
|
+
this.data.forEach((t, o) => {
|
|
346
|
+
const [a, n] = d.extractPrefix(o);
|
|
347
|
+
this.clear(n, a, e, r);
|
|
345
348
|
});
|
|
346
349
|
}
|
|
347
|
-
clear(e, r, t = !1,
|
|
350
|
+
clear(e, r, t = !1, o = !1) {
|
|
348
351
|
t || this.callListeners(e, r);
|
|
349
|
-
const
|
|
350
|
-
if (!
|
|
351
|
-
const
|
|
352
|
-
if (this.data.delete(
|
|
353
|
-
const
|
|
354
|
-
|
|
352
|
+
const a = this.data.get(d.prefix(e, r));
|
|
353
|
+
if (!a) return;
|
|
354
|
+
const n = { ...a };
|
|
355
|
+
if (this.data.delete(d.prefix(e, r)), n.isStatic && !o) {
|
|
356
|
+
const f = te.find((c) => c.key === e && c.prefix === r);
|
|
357
|
+
f && this.initStatic(f);
|
|
355
358
|
}
|
|
356
359
|
}
|
|
357
360
|
get(e, r) {
|
|
@@ -360,13 +363,13 @@ class u {
|
|
|
360
363
|
return this.data.get(t);
|
|
361
364
|
}
|
|
362
365
|
setValue(e, r, t) {
|
|
363
|
-
this.data.has(
|
|
364
|
-
...this.data.get(
|
|
366
|
+
this.data.has(d.prefix(e, r)) && this.data.set(d.prefix(e, r), {
|
|
367
|
+
...this.data.get(d.prefix(e, r)),
|
|
365
368
|
...t
|
|
366
369
|
});
|
|
367
370
|
}
|
|
368
371
|
has(e, r) {
|
|
369
|
-
return this.data.has(
|
|
372
|
+
return this.data.has(d.prefix(e, r)) ? d.prefix(e, r) : this.data.has(d.prefix(e, "_global")) ? d.prefix(e, "_global") : void 0;
|
|
370
373
|
}
|
|
371
374
|
static prefix(e, r) {
|
|
372
375
|
if (e.includes("//")) throw new Error("key cannot contain '//'");
|
|
@@ -376,34 +379,34 @@ class u {
|
|
|
376
379
|
return e.split("//");
|
|
377
380
|
}
|
|
378
381
|
useEffect(e, r, t = null) {
|
|
379
|
-
|
|
380
|
-
t?.(),
|
|
382
|
+
ne(() => () => {
|
|
383
|
+
t?.(), z(`[${d.prefix(e, r)}]`, "unmount effect"), this.data.get(d.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
|
|
381
384
|
}, []);
|
|
382
385
|
}
|
|
383
386
|
}
|
|
384
|
-
class
|
|
387
|
+
class G {
|
|
385
388
|
constructor(e) {
|
|
386
389
|
this.sharedData = e;
|
|
387
390
|
}
|
|
388
391
|
get(e, r) {
|
|
389
|
-
let t,
|
|
392
|
+
let t, o = r;
|
|
390
393
|
if (typeof e != "string") {
|
|
391
|
-
const { key:
|
|
392
|
-
t =
|
|
394
|
+
const { key: f, prefix: c } = e;
|
|
395
|
+
t = f, o = c;
|
|
393
396
|
} else
|
|
394
|
-
t =
|
|
395
|
-
const
|
|
396
|
-
return this.sharedData.get(t,
|
|
397
|
+
t = j(e);
|
|
398
|
+
const a = o || "_global";
|
|
399
|
+
return this.sharedData.get(t, a);
|
|
397
400
|
}
|
|
398
401
|
set(e, r, t) {
|
|
399
|
-
let
|
|
402
|
+
let o, a = t;
|
|
400
403
|
if (typeof e != "string") {
|
|
401
|
-
const { key:
|
|
402
|
-
|
|
404
|
+
const { key: f, prefix: c } = e;
|
|
405
|
+
o = f, a = c;
|
|
403
406
|
} else
|
|
404
|
-
|
|
405
|
-
const
|
|
406
|
-
this.sharedData.
|
|
407
|
+
o = j(e);
|
|
408
|
+
const n = a || "_global";
|
|
409
|
+
this.sharedData.init(o, n, r), this.sharedData.setValue(o, n, r), this.sharedData.callListeners(o, n);
|
|
407
410
|
}
|
|
408
411
|
/**
|
|
409
412
|
* clear all values from the shared data
|
|
@@ -417,10 +420,10 @@ class U {
|
|
|
417
420
|
*/
|
|
418
421
|
clearScope(e) {
|
|
419
422
|
const r = e || "_global";
|
|
420
|
-
this.sharedData.data.forEach((t,
|
|
421
|
-
const [
|
|
422
|
-
if (
|
|
423
|
-
this.sharedData.clear(a,
|
|
423
|
+
this.sharedData.data.forEach((t, o) => {
|
|
424
|
+
const [a, n] = d.extractPrefix(o);
|
|
425
|
+
if (a === r) {
|
|
426
|
+
this.sharedData.clear(n, a), this.sharedData.callListeners(n, a);
|
|
424
427
|
return;
|
|
425
428
|
}
|
|
426
429
|
});
|
|
@@ -434,8 +437,8 @@ class U {
|
|
|
434
437
|
return this.get(r, t);
|
|
435
438
|
}
|
|
436
439
|
clear(e, r) {
|
|
437
|
-
let t,
|
|
438
|
-
typeof e == "string" ? (t = e,
|
|
440
|
+
let t, o;
|
|
441
|
+
typeof e == "string" ? (t = e, o = r || "_global") : (t = e.key, o = e.prefix), this.sharedData.clear(t, o);
|
|
439
442
|
}
|
|
440
443
|
/**
|
|
441
444
|
* check if a value exists in the shared data
|
|
@@ -452,30 +455,93 @@ class U {
|
|
|
452
455
|
getAll() {
|
|
453
456
|
const e = {};
|
|
454
457
|
return this.sharedData.data.forEach((r, t) => {
|
|
455
|
-
const [
|
|
456
|
-
e[
|
|
458
|
+
const [o, a] = d.extractPrefix(t);
|
|
459
|
+
e[o] = e[o] || {}, e[o][a] = r;
|
|
457
460
|
}), e;
|
|
458
461
|
}
|
|
459
462
|
}
|
|
460
|
-
const
|
|
461
|
-
const e =
|
|
463
|
+
const k = (i) => {
|
|
464
|
+
const e = Te();
|
|
462
465
|
return {
|
|
463
466
|
prefix: i ?? e?.scopeName ?? "_global"
|
|
464
467
|
};
|
|
465
468
|
};
|
|
466
|
-
|
|
469
|
+
var W, re;
|
|
470
|
+
function Ae() {
|
|
471
|
+
if (re) return W;
|
|
472
|
+
re = 1;
|
|
473
|
+
var i = typeof Element < "u", e = typeof Map == "function", r = typeof Set == "function", t = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
|
|
474
|
+
function o(a, n) {
|
|
475
|
+
if (a === n) return !0;
|
|
476
|
+
if (a && n && typeof a == "object" && typeof n == "object") {
|
|
477
|
+
if (a.constructor !== n.constructor) return !1;
|
|
478
|
+
var f, c, g;
|
|
479
|
+
if (Array.isArray(a)) {
|
|
480
|
+
if (f = a.length, f != n.length) return !1;
|
|
481
|
+
for (c = f; c-- !== 0; )
|
|
482
|
+
if (!o(a[c], n[c])) return !1;
|
|
483
|
+
return !0;
|
|
484
|
+
}
|
|
485
|
+
var p;
|
|
486
|
+
if (e && a instanceof Map && n instanceof Map) {
|
|
487
|
+
if (a.size !== n.size) return !1;
|
|
488
|
+
for (p = a.entries(); !(c = p.next()).done; )
|
|
489
|
+
if (!n.has(c.value[0])) return !1;
|
|
490
|
+
for (p = a.entries(); !(c = p.next()).done; )
|
|
491
|
+
if (!o(c.value[1], n.get(c.value[0]))) return !1;
|
|
492
|
+
return !0;
|
|
493
|
+
}
|
|
494
|
+
if (r && a instanceof Set && n instanceof Set) {
|
|
495
|
+
if (a.size !== n.size) return !1;
|
|
496
|
+
for (p = a.entries(); !(c = p.next()).done; )
|
|
497
|
+
if (!n.has(c.value[0])) return !1;
|
|
498
|
+
return !0;
|
|
499
|
+
}
|
|
500
|
+
if (t && ArrayBuffer.isView(a) && ArrayBuffer.isView(n)) {
|
|
501
|
+
if (f = a.length, f != n.length) return !1;
|
|
502
|
+
for (c = f; c-- !== 0; )
|
|
503
|
+
if (a[c] !== n[c]) return !1;
|
|
504
|
+
return !0;
|
|
505
|
+
}
|
|
506
|
+
if (a.constructor === RegExp) return a.source === n.source && a.flags === n.flags;
|
|
507
|
+
if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf == "function" && typeof n.valueOf == "function") return a.valueOf() === n.valueOf();
|
|
508
|
+
if (a.toString !== Object.prototype.toString && typeof a.toString == "function" && typeof n.toString == "function") return a.toString() === n.toString();
|
|
509
|
+
if (g = Object.keys(a), f = g.length, f !== Object.keys(n).length) return !1;
|
|
510
|
+
for (c = f; c-- !== 0; )
|
|
511
|
+
if (!Object.prototype.hasOwnProperty.call(n, g[c])) return !1;
|
|
512
|
+
if (i && a instanceof Element) return !1;
|
|
513
|
+
for (c = f; c-- !== 0; )
|
|
514
|
+
if (!((g[c] === "_owner" || g[c] === "__v" || g[c] === "__o") && a.$$typeof) && !o(a[g[c]], n[g[c]]))
|
|
515
|
+
return !1;
|
|
516
|
+
return !0;
|
|
517
|
+
}
|
|
518
|
+
return a !== a && n !== n;
|
|
519
|
+
}
|
|
520
|
+
return W = function(n, f) {
|
|
521
|
+
try {
|
|
522
|
+
return o(n, f);
|
|
523
|
+
} catch (c) {
|
|
524
|
+
if ((c.message || "").match(/stack|recursion/i))
|
|
525
|
+
return console.warn("react-fast-compare cannot handle circular refs"), !1;
|
|
526
|
+
throw c;
|
|
527
|
+
}
|
|
528
|
+
}, W;
|
|
529
|
+
}
|
|
530
|
+
var Oe = Ae();
|
|
531
|
+
const Pe = /* @__PURE__ */ me(Oe);
|
|
532
|
+
class Le extends d {
|
|
467
533
|
defaultValue() {
|
|
468
534
|
return { value: void 0 };
|
|
469
535
|
}
|
|
470
|
-
initValue(e, r, t,
|
|
471
|
-
super.init(e, r, { value: t },
|
|
536
|
+
initValue(e, r, t, o = !1) {
|
|
537
|
+
super.init(e, r, { value: t }, o);
|
|
472
538
|
}
|
|
473
539
|
initStatic(e) {
|
|
474
|
-
const { key: r, prefix: t, initialValue:
|
|
475
|
-
this.initValue(r, t,
|
|
540
|
+
const { key: r, prefix: t, initialValue: o } = e;
|
|
541
|
+
this.initValue(r, t, o, !0);
|
|
476
542
|
}
|
|
477
543
|
}
|
|
478
|
-
class
|
|
544
|
+
class je extends G {
|
|
479
545
|
constructor(e) {
|
|
480
546
|
super(e);
|
|
481
547
|
}
|
|
@@ -490,28 +556,43 @@ class Te extends U {
|
|
|
490
556
|
super.set(e, { value: r }, t);
|
|
491
557
|
}
|
|
492
558
|
}
|
|
493
|
-
const
|
|
494
|
-
function
|
|
495
|
-
let t,
|
|
559
|
+
const _ = new Le(), Ye = new je(_), Ie = (i, e) => _.createStatic({ initialValue: i }, e);
|
|
560
|
+
function qe(i, e, r) {
|
|
561
|
+
let t, o, a = r;
|
|
496
562
|
if (typeof i != "string") {
|
|
497
|
-
const { key: l, initialValue:
|
|
498
|
-
t = l,
|
|
563
|
+
const { key: l, initialValue: R, prefix: b } = i;
|
|
564
|
+
t = l, o = R, a = b;
|
|
499
565
|
} else
|
|
500
|
-
t =
|
|
501
|
-
const { prefix:
|
|
502
|
-
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
}), []),
|
|
506
|
-
const
|
|
507
|
-
|
|
566
|
+
t = j(i), o = e;
|
|
567
|
+
const { prefix: n } = k(a);
|
|
568
|
+
_.initValue(t, n, o);
|
|
569
|
+
const f = T(() => (l) => (_.initValue(t, n, e), _.addListener(t, n, l), () => {
|
|
570
|
+
_.removeListener(t, n, l);
|
|
571
|
+
}), []), c = T(() => () => _.get(t, n)?.value, []), g = N(f, c), p = (l) => {
|
|
572
|
+
const R = typeof l == "function" ? l(_.get(t, n)?.value) : l;
|
|
573
|
+
R !== g && (_.setValue(t, n, { value: R }), _.callListeners(t, n));
|
|
508
574
|
};
|
|
509
|
-
return
|
|
510
|
-
|
|
511
|
-
|
|
575
|
+
return _.useEffect(t, n), [
|
|
576
|
+
g,
|
|
577
|
+
p
|
|
512
578
|
];
|
|
513
579
|
}
|
|
514
|
-
|
|
580
|
+
function We(i, e, r) {
|
|
581
|
+
let t, o = r;
|
|
582
|
+
if (typeof i != "string") {
|
|
583
|
+
const { key: p, prefix: l } = i;
|
|
584
|
+
t = p, o = l;
|
|
585
|
+
} else
|
|
586
|
+
t = j(i);
|
|
587
|
+
const { prefix: a } = k(o), n = Ee(void 0), f = T(() => (p) => (_.addListener(t, a, p), () => {
|
|
588
|
+
_.removeListener(t, a, p);
|
|
589
|
+
}), []), c = T(() => () => {
|
|
590
|
+
const p = _.get(t, a)?.value, l = e(p);
|
|
591
|
+
return Pe(n.current, l) ? n.current : l;
|
|
592
|
+
}, []), g = N(f, c);
|
|
593
|
+
return _.useEffect(t, a), g;
|
|
594
|
+
}
|
|
595
|
+
class Ce extends d {
|
|
515
596
|
defaultValue() {
|
|
516
597
|
return {
|
|
517
598
|
fnState: {
|
|
@@ -528,7 +609,7 @@ class Ae extends u {
|
|
|
528
609
|
super.setValue(e, r, t);
|
|
529
610
|
}
|
|
530
611
|
}
|
|
531
|
-
class
|
|
612
|
+
class De extends G {
|
|
532
613
|
constructor(e) {
|
|
533
614
|
super(e);
|
|
534
615
|
}
|
|
@@ -543,51 +624,51 @@ class we extends U {
|
|
|
543
624
|
super.set(e, r, t);
|
|
544
625
|
}
|
|
545
626
|
}
|
|
546
|
-
const
|
|
547
|
-
function
|
|
548
|
-
let t,
|
|
627
|
+
const y = new Ce(), ze = new De(y), Ge = (i, e) => y.createStatic({ fn: i }, e);
|
|
628
|
+
function Ue(i, e, r) {
|
|
629
|
+
let t, o, a = r;
|
|
549
630
|
if (typeof i != "string") {
|
|
550
|
-
const { key: l, fn:
|
|
551
|
-
t = l,
|
|
631
|
+
const { key: l, fn: R, prefix: b } = i;
|
|
632
|
+
t = l, o = R, a = b;
|
|
552
633
|
} else
|
|
553
|
-
t =
|
|
554
|
-
const { prefix:
|
|
555
|
-
|
|
556
|
-
const
|
|
557
|
-
() => (l) => (
|
|
558
|
-
|
|
634
|
+
t = j(i), o = e;
|
|
635
|
+
const { prefix: n } = k(a);
|
|
636
|
+
y.initValue(t, n);
|
|
637
|
+
const f = T(
|
|
638
|
+
() => (l) => (y.initValue(t, n), y.addListener(t, n, l), () => {
|
|
639
|
+
y.removeListener(t, n, l);
|
|
559
640
|
}),
|
|
560
641
|
[]
|
|
561
|
-
),
|
|
562
|
-
() => () =>
|
|
642
|
+
), c = T(
|
|
643
|
+
() => () => y.get(t, n).fnState,
|
|
563
644
|
[]
|
|
564
|
-
),
|
|
565
|
-
const
|
|
566
|
-
if (!l && (
|
|
567
|
-
|
|
645
|
+
), g = N(f, c), p = async (l, ...R) => {
|
|
646
|
+
const b = y.get(t, n);
|
|
647
|
+
if (!l && (b.fnState.isLoading || b.fnState.results !== void 0)) return b.fnState;
|
|
648
|
+
b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, y.callListeners(t, n);
|
|
568
649
|
try {
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
} catch (
|
|
572
|
-
|
|
650
|
+
const v = await o(...R);
|
|
651
|
+
b.fnState = { results: v, isLoading: !1, error: void 0 };
|
|
652
|
+
} catch (v) {
|
|
653
|
+
b.fnState = { ...b.fnState, isLoading: !1, error: v };
|
|
573
654
|
}
|
|
574
|
-
|
|
655
|
+
y.callListeners(t, n);
|
|
575
656
|
};
|
|
576
|
-
return
|
|
577
|
-
state:
|
|
657
|
+
return y.useEffect(t, n), {
|
|
658
|
+
state: g,
|
|
578
659
|
trigger: (...l) => {
|
|
579
|
-
|
|
660
|
+
p(!1, ...l);
|
|
580
661
|
},
|
|
581
662
|
forceTrigger: (...l) => {
|
|
582
|
-
|
|
663
|
+
p(!0, ...l);
|
|
583
664
|
},
|
|
584
665
|
clear: () => {
|
|
585
|
-
const l =
|
|
586
|
-
l && (l.fnState =
|
|
666
|
+
const l = y.get(t, n);
|
|
667
|
+
l && (l.fnState = y.defaultValue().fnState, y.callListeners(t, n));
|
|
587
668
|
}
|
|
588
669
|
};
|
|
589
670
|
}
|
|
590
|
-
class
|
|
671
|
+
class Fe extends d {
|
|
591
672
|
defaultValue() {
|
|
592
673
|
return {
|
|
593
674
|
fnState: {
|
|
@@ -605,8 +686,8 @@ class Pe extends u {
|
|
|
605
686
|
super.setValue(e, r, t);
|
|
606
687
|
}
|
|
607
688
|
useEffect(e, r) {
|
|
608
|
-
|
|
609
|
-
|
|
689
|
+
ne(() => () => {
|
|
690
|
+
z(`[${d.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
|
|
610
691
|
}, []), super.useEffect(e, r);
|
|
611
692
|
}
|
|
612
693
|
async unsubscribe(e, r) {
|
|
@@ -614,7 +695,7 @@ class Pe extends u {
|
|
|
614
695
|
t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState = { ...t.fnState, subscribed: !1 }, this.callListeners(e, r));
|
|
615
696
|
}
|
|
616
697
|
}
|
|
617
|
-
class
|
|
698
|
+
class Ne extends G {
|
|
618
699
|
constructor(e) {
|
|
619
700
|
super(e);
|
|
620
701
|
}
|
|
@@ -629,73 +710,74 @@ class ye extends U {
|
|
|
629
710
|
super.set(e, r, t);
|
|
630
711
|
}
|
|
631
712
|
}
|
|
632
|
-
const
|
|
633
|
-
function
|
|
634
|
-
let t,
|
|
713
|
+
const S = new Fe(), Be = new Ne(S), Je = (i, e) => S.createStatic({ subscriber: i }, e);
|
|
714
|
+
function Me(i, e, r) {
|
|
715
|
+
let t, o, a = r;
|
|
635
716
|
if (typeof i != "string") {
|
|
636
|
-
const { key:
|
|
637
|
-
t =
|
|
717
|
+
const { key: v, subscriber: x, prefix: O } = i;
|
|
718
|
+
t = v, o = x, a = O;
|
|
638
719
|
} else
|
|
639
|
-
t =
|
|
640
|
-
const { prefix:
|
|
641
|
-
|
|
642
|
-
const
|
|
643
|
-
() => (
|
|
644
|
-
|
|
720
|
+
t = j(i), o = e;
|
|
721
|
+
const { prefix: n } = k(a);
|
|
722
|
+
S.initValue(t, n);
|
|
723
|
+
const f = T(
|
|
724
|
+
() => (v) => (S.initValue(t, n), S.addListener(t, n, v), () => {
|
|
725
|
+
S.removeListener(t, n, v);
|
|
645
726
|
}),
|
|
646
727
|
[]
|
|
647
|
-
),
|
|
648
|
-
() => () =>
|
|
728
|
+
), c = T(
|
|
729
|
+
() => () => S.get(t, n).fnState,
|
|
649
730
|
[]
|
|
650
|
-
),
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
}, l = (
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
},
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
},
|
|
660
|
-
const
|
|
661
|
-
if (
|
|
662
|
-
|
|
731
|
+
), g = N(f, c), p = (v) => {
|
|
732
|
+
const x = S.get(t, n);
|
|
733
|
+
x.fnState = { ...x.fnState, data: v }, S.callListeners(t, n);
|
|
734
|
+
}, l = (v) => {
|
|
735
|
+
const x = S.get(t, n);
|
|
736
|
+
x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: v }, S.callListeners(t, n);
|
|
737
|
+
}, R = () => {
|
|
738
|
+
const v = S.get(t, n);
|
|
739
|
+
v.fnState = { ...v.fnState, isLoading: !1 }, S.callListeners(t, n);
|
|
740
|
+
}, b = async (v) => {
|
|
741
|
+
const x = S.get(t, n);
|
|
742
|
+
if (v && (await S.unsubscribe(t, n), x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), x.fnState.subscribed) return x.fnState;
|
|
743
|
+
z("triggered !!"), x.fnState = { ...x.fnState, isLoading: !0, error: void 0 }, S.callListeners(t, n);
|
|
663
744
|
try {
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
} catch (
|
|
667
|
-
const
|
|
668
|
-
|
|
745
|
+
const O = await o(p, l, R), P = S.get(t, n);
|
|
746
|
+
P.unsubscribe = O, P.fnState.subscribed = !0;
|
|
747
|
+
} catch (O) {
|
|
748
|
+
const P = S.get(t, n);
|
|
749
|
+
P.fnState = { ...P.fnState, isLoading: !1, error: O };
|
|
669
750
|
}
|
|
670
|
-
|
|
751
|
+
S.callListeners(t, n);
|
|
671
752
|
};
|
|
672
|
-
return
|
|
673
|
-
state:
|
|
753
|
+
return S.useEffect(t, n), {
|
|
754
|
+
state: g,
|
|
674
755
|
trigger: () => {
|
|
675
|
-
|
|
756
|
+
b(!1);
|
|
676
757
|
},
|
|
677
758
|
forceTrigger: () => {
|
|
678
|
-
|
|
759
|
+
b(!0);
|
|
679
760
|
},
|
|
680
761
|
unsubscribe: () => {
|
|
681
|
-
|
|
762
|
+
S.unsubscribe(t, n);
|
|
682
763
|
}
|
|
683
764
|
};
|
|
684
765
|
}
|
|
685
766
|
export {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
767
|
+
De as SharedFunctionsApi,
|
|
768
|
+
je as SharedStatesApi,
|
|
769
|
+
Ve as SharedStatesProvider,
|
|
770
|
+
Ne as SharedSubscriptionsApi,
|
|
771
|
+
Ge as createSharedFunction,
|
|
772
|
+
Ie as createSharedState,
|
|
773
|
+
Je as createSharedSubscription,
|
|
774
|
+
se as isDevMode,
|
|
775
|
+
$e as setDevMode,
|
|
776
|
+
ze as sharedFunctionsApi,
|
|
777
|
+
Ye as sharedStatesApi,
|
|
778
|
+
Be as sharedSubscriptionsApi,
|
|
779
|
+
Ue as useSharedFunction,
|
|
780
|
+
qe as useSharedState,
|
|
781
|
+
We as useSharedStateSelector,
|
|
782
|
+
Me as useSharedSubscription
|
|
701
783
|
};
|