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