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