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