react-shared-states 1.0.2 → 1.0.4
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.js → main.esm.js} +54 -54
- package/dist/main.min.js +4 -4
- package/package.json +1 -1
- package/vite.config.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-shared-states v1.0.
|
|
2
|
+
* react-shared-states v1.0.4
|
|
3
3
|
* (c) Hichem Taboukouyout
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
* Github: github.com/HichemTab-tech/react-shared-states
|
|
@@ -16,24 +16,24 @@ var S = { exports: {} }, R = {};
|
|
|
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
|
|
19
|
+
var y;
|
|
20
20
|
function ce() {
|
|
21
|
-
if (
|
|
22
|
-
|
|
21
|
+
if (y) return R;
|
|
22
|
+
y = 1;
|
|
23
23
|
var s = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
24
|
-
function t(n, i,
|
|
24
|
+
function t(n, i, d) {
|
|
25
25
|
var l = null;
|
|
26
|
-
if (
|
|
27
|
-
|
|
26
|
+
if (d !== void 0 && (l = "" + d), i.key !== void 0 && (l = "" + i.key), "key" in i) {
|
|
27
|
+
d = {};
|
|
28
28
|
for (var m in i)
|
|
29
|
-
m !== "key" && (
|
|
30
|
-
} else
|
|
31
|
-
return i =
|
|
29
|
+
m !== "key" && (d[m] = i[m]);
|
|
30
|
+
} else d = i;
|
|
31
|
+
return i = d.ref, {
|
|
32
32
|
$$typeof: s,
|
|
33
33
|
type: n,
|
|
34
34
|
key: l,
|
|
35
35
|
ref: i !== void 0 ? i : null,
|
|
36
|
-
props:
|
|
36
|
+
props: d
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
return R.Fragment = r, R.jsx = t, R.jsxs = t, R;
|
|
@@ -48,9 +48,9 @@ var x = {};
|
|
|
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
|
|
51
|
+
var U;
|
|
52
52
|
function fe() {
|
|
53
|
-
return
|
|
53
|
+
return U || (U = 1, process.env.NODE_ENV !== "production" && function() {
|
|
54
54
|
function s(e) {
|
|
55
55
|
if (e == null) return null;
|
|
56
56
|
if (typeof e == "function")
|
|
@@ -129,11 +129,11 @@ function fe() {
|
|
|
129
129
|
var e = O.A;
|
|
130
130
|
return e === null ? null : e.getOwner();
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function d() {
|
|
133
133
|
return Error("react-stack-top-frame");
|
|
134
134
|
}
|
|
135
135
|
function l(e) {
|
|
136
|
-
if (
|
|
136
|
+
if (k.call(e, "key")) {
|
|
137
137
|
var a = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
138
138
|
if (a && a.isReactWarning) return !1;
|
|
139
139
|
}
|
|
@@ -141,7 +141,7 @@ function fe() {
|
|
|
141
141
|
}
|
|
142
142
|
function m(e, a) {
|
|
143
143
|
function o() {
|
|
144
|
-
|
|
144
|
+
V || (V = !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
|
a
|
|
147
147
|
));
|
|
@@ -151,7 +151,7 @@ function fe() {
|
|
|
151
151
|
configurable: !0
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function g() {
|
|
155
155
|
var e = s(this.type);
|
|
156
156
|
return $[e] || ($[e] = !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."
|
|
@@ -166,7 +166,7 @@ function fe() {
|
|
|
166
166
|
_owner: h
|
|
167
167
|
}, (o !== void 0 ? o : null) !== null ? Object.defineProperty(e, "ref", {
|
|
168
168
|
enumerable: !1,
|
|
169
|
-
get:
|
|
169
|
+
get: g
|
|
170
170
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
171
171
|
configurable: !1,
|
|
172
172
|
enumerable: !1,
|
|
@@ -189,20 +189,20 @@ function fe() {
|
|
|
189
189
|
value: j
|
|
190
190
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
191
191
|
}
|
|
192
|
-
function
|
|
192
|
+
function N(e, a, o, c, h, E, w, j) {
|
|
193
193
|
var f = a.children;
|
|
194
194
|
if (f !== void 0)
|
|
195
195
|
if (c)
|
|
196
196
|
if (ae(f)) {
|
|
197
197
|
for (c = 0; c < f.length; c++)
|
|
198
|
-
|
|
198
|
+
L(f[c]);
|
|
199
199
|
Object.freeze && Object.freeze(f);
|
|
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
|
|
205
|
-
if (
|
|
204
|
+
else L(f);
|
|
205
|
+
if (k.call(a, "key")) {
|
|
206
206
|
f = s(e);
|
|
207
207
|
var _ = Object.keys(a).filter(function(se) {
|
|
208
208
|
return se !== "key";
|
|
@@ -239,10 +239,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
239
239
|
j
|
|
240
240
|
);
|
|
241
241
|
}
|
|
242
|
-
function
|
|
242
|
+
function L(e) {
|
|
243
243
|
typeof e == "object" && e !== null && e.$$typeof === Y && e._store && (e._store.validated = 1);
|
|
244
244
|
}
|
|
245
|
-
var T = oe, Y = Symbol.for("react.transitional.element"), X = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), B = Symbol.for("react.strict_mode"), D = Symbol.for("react.profiler"), H = Symbol.for("react.consumer"), Z = Symbol.for("react.context"), Q = Symbol.for("react.forward_ref"), K = Symbol.for("react.suspense"), ee = Symbol.for("react.suspense_list"), re = Symbol.for("react.memo"), F = Symbol.for("react.lazy"), te = Symbol.for("react.activity"), ne = Symbol.for("react.client.reference"), O = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
|
|
245
|
+
var T = oe, Y = Symbol.for("react.transitional.element"), X = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), B = Symbol.for("react.strict_mode"), D = Symbol.for("react.profiler"), H = Symbol.for("react.consumer"), Z = Symbol.for("react.context"), Q = Symbol.for("react.forward_ref"), K = Symbol.for("react.suspense"), ee = Symbol.for("react.suspense_list"), re = Symbol.for("react.memo"), F = Symbol.for("react.lazy"), te = Symbol.for("react.activity"), ne = Symbol.for("react.client.reference"), O = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, k = Object.prototype.hasOwnProperty, ae = Array.isArray, P = console.createTask ? console.createTask : function() {
|
|
246
246
|
return null;
|
|
247
247
|
};
|
|
248
248
|
T = {
|
|
@@ -250,13 +250,13 @@ React keys must be passed directly to JSX without using spread:
|
|
|
250
250
|
return e();
|
|
251
251
|
}
|
|
252
252
|
};
|
|
253
|
-
var
|
|
253
|
+
var V, $ = {}, I = T.react_stack_bottom_frame.bind(
|
|
254
254
|
T,
|
|
255
|
-
|
|
256
|
-
)(), M = P(n(
|
|
255
|
+
d
|
|
256
|
+
)(), M = P(n(d)), W = {};
|
|
257
257
|
x.Fragment = A, x.jsx = function(e, a, o, c, h) {
|
|
258
258
|
var E = 1e4 > O.recentlyCreatedOwnerStacks++;
|
|
259
|
-
return
|
|
259
|
+
return N(
|
|
260
260
|
e,
|
|
261
261
|
a,
|
|
262
262
|
o,
|
|
@@ -268,7 +268,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
268
268
|
);
|
|
269
269
|
}, x.jsxs = function(e, a, o, c, h) {
|
|
270
270
|
var E = 1e4 > O.recentlyCreatedOwnerStacks++;
|
|
271
|
-
return
|
|
271
|
+
return N(
|
|
272
272
|
e,
|
|
273
273
|
a,
|
|
274
274
|
o,
|
|
@@ -285,8 +285,8 @@ var q;
|
|
|
285
285
|
function de() {
|
|
286
286
|
return q || (q = 1, process.env.NODE_ENV === "production" ? S.exports = ce() : S.exports = fe()), S.exports;
|
|
287
287
|
}
|
|
288
|
-
var
|
|
289
|
-
const z = ie(void 0), _e = ({ children: s, scopeName: r }) => (r || (r = le(() => Math.random().toString(36).substring(2, 15), [])), /* @__PURE__ */
|
|
288
|
+
var pe = de();
|
|
289
|
+
const z = ie(void 0), _e = ({ children: s, scopeName: r }) => (r || (r = le(() => Math.random().toString(36).substring(2, 15), [])), /* @__PURE__ */ pe.jsx(z.Provider, { value: { scopeName: r }, children: s })), be = () => ue(z);
|
|
290
290
|
class u {
|
|
291
291
|
data = /* @__PURE__ */ new Map();
|
|
292
292
|
defaultValue() {
|
|
@@ -337,12 +337,12 @@ class u {
|
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
const G = (s) => {
|
|
340
|
-
const r =
|
|
340
|
+
const r = be();
|
|
341
341
|
return {
|
|
342
342
|
prefix: s ?? r?.scopeName ?? "_global"
|
|
343
343
|
};
|
|
344
344
|
};
|
|
345
|
-
class
|
|
345
|
+
class ge extends u {
|
|
346
346
|
defaultValue() {
|
|
347
347
|
return { value: void 0 };
|
|
348
348
|
}
|
|
@@ -377,7 +377,7 @@ class me {
|
|
|
377
377
|
return p.data;
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
const Re = new me(), p = new
|
|
380
|
+
const Re = new me(), p = new ge(), xe = (s, r, t) => {
|
|
381
381
|
const { prefix: n } = G(t);
|
|
382
382
|
p.init(s, n, r);
|
|
383
383
|
const i = J((l) => (p.init(s, n, r), p.addListener(s, n, l), () => {
|
|
@@ -411,54 +411,54 @@ class Ee extends u {
|
|
|
411
411
|
class ve {
|
|
412
412
|
get(r, t = "_global") {
|
|
413
413
|
const n = t || "_global";
|
|
414
|
-
return
|
|
414
|
+
return b.get(r, n)?.fnState;
|
|
415
415
|
}
|
|
416
416
|
set(r, t, n = "_global") {
|
|
417
417
|
const i = n || "_global";
|
|
418
|
-
|
|
418
|
+
b.setValue(r, i, t);
|
|
419
419
|
}
|
|
420
420
|
clearAll() {
|
|
421
|
-
|
|
421
|
+
b.clearAll();
|
|
422
422
|
}
|
|
423
423
|
clear(r, t = "_global") {
|
|
424
424
|
const n = t || "_global";
|
|
425
|
-
|
|
425
|
+
b.clear(r, n);
|
|
426
426
|
}
|
|
427
427
|
has(r, t = "_global") {
|
|
428
428
|
const n = t || "_global";
|
|
429
|
-
return !!
|
|
429
|
+
return !!b.has(r, n);
|
|
430
430
|
}
|
|
431
431
|
getAll() {
|
|
432
|
-
return
|
|
432
|
+
return b.data;
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
|
-
const Te = new ve(),
|
|
435
|
+
const Te = new ve(), b = new Ee(), Se = (s, r, t) => {
|
|
436
436
|
const { prefix: n } = G(t);
|
|
437
|
-
|
|
438
|
-
const i = J((l) => (
|
|
439
|
-
|
|
440
|
-
}), () =>
|
|
441
|
-
const
|
|
442
|
-
if (!l && (
|
|
443
|
-
|
|
437
|
+
b.init(s, n);
|
|
438
|
+
const i = J((l) => (b.init(s, n), b.addListener(s, n, l), () => {
|
|
439
|
+
b.removeListener(s, n, l);
|
|
440
|
+
}), () => b.get(s, n).fnState), d = async (l, ...m) => {
|
|
441
|
+
const g = b.get(s, n);
|
|
442
|
+
if (!l && (g.fnState.isLoading || g.fnState.results !== void 0)) return g.fnState;
|
|
443
|
+
g.fnState = { ...g.fnState, isLoading: !0, error: void 0 }, g.listeners.forEach((v) => v());
|
|
444
444
|
try {
|
|
445
445
|
const v = await r(...m);
|
|
446
|
-
|
|
446
|
+
g.fnState = { results: v, isLoading: !1, error: void 0 };
|
|
447
447
|
} catch (v) {
|
|
448
|
-
|
|
448
|
+
g.fnState = { ...g.fnState, isLoading: !1, error: v };
|
|
449
449
|
}
|
|
450
|
-
|
|
450
|
+
g.listeners.forEach((v) => v());
|
|
451
451
|
};
|
|
452
452
|
return {
|
|
453
453
|
state: i,
|
|
454
454
|
trigger: (...l) => {
|
|
455
|
-
|
|
455
|
+
d(!1, ...l);
|
|
456
456
|
},
|
|
457
457
|
forceTrigger: (...l) => {
|
|
458
|
-
|
|
458
|
+
d(!0, ...l);
|
|
459
459
|
},
|
|
460
460
|
clear: () => {
|
|
461
|
-
|
|
461
|
+
b.clear(s, n), b.init(s, n);
|
|
462
462
|
}
|
|
463
463
|
};
|
|
464
464
|
};
|
package/dist/main.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* react-shared-states v1.0.
|
|
2
|
+
* react-shared-states v1.0.4
|
|
3
3
|
* (c) Hichem Taboukouyout
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
* Github: github.com/HichemTab-tech/react-shared-states
|
|
@@ -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 F;function q(){if(F)return x;F=1;var s=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(n,i,
|
|
16
|
+
*/var F;function q(){if(F)return x;F=1;var s=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(n,i,b){var u=null;if(b!==void 0&&(u=""+b),i.key!==void 0&&(u=""+i.key),"key"in i){b={};for(var v in i)v!=="key"&&(b[v]=i[v])}else b=i;return i=b.ref,{$$typeof:s,type:n,key:u,ref:i!==void 0?i:null,props:b}}return x.Fragment=t,x.jsx=r,x.jsxs=r,x}var T={};/**
|
|
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 Y;function D(){return Y||(Y=1,process.env.NODE_ENV!=="production"&&function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ve?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case O:return"Fragment";case ce:return"Profiler";case ue:return"StrictMode";case
|
|
24
|
+
*/var Y;function D(){return Y||(Y=1,process.env.NODE_ENV!=="production"&&function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ve?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case O:return"Fragment";case ce:return"Profiler";case ue:return"StrictMode";case be:return"Suspense";case ge:return"SuspenseList";case me:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case le:return"Portal";case de:return(e.displayName||"Context")+".Provider";case fe:return(e._context.displayName||"Context")+".Consumer";case pe:var a=e.render;return e=e.displayName,e||(e=a.displayName||a.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case he:return a=e.displayName||null,a!==null?a:s(e.type)||"Memo";case U:a=e._payload,e=e._init;try{return s(e(a))}catch{}}return null}function t(e){return""+e}function r(e){try{t(e);var a=!1}catch{a=!0}if(a){a=console;var o=a.error,c=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return o.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",c),t(e)}}function n(e){if(e===O)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===U)return"<...>";try{var a=s(e);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function i(){var e=w.A;return e===null?null:e.getOwner()}function b(){return Error("react-stack-top-frame")}function u(e){if(J.call(e,"key")){var a=Object.getOwnPropertyDescriptor(e,"key").get;if(a&&a.isReactWarning)return!1}return e.key!==void 0}function v(e,a){function o(){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))}o.isReactWarning=!0,Object.defineProperty(e,"key",{get:o,configurable:!0})}function g(){var e=s(this.type);return G[e]||(G[e]=!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.")),e=this.props.ref,e!==void 0?e:null}function _(e,a,o,c,R,E,C,N){return o=E.ref,e={$$typeof:W,type:e,key:a,props:E,_owner:R},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:g}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:C}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:N}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function I(e,a,o,c,R,E,C,N){var f=a.children;if(f!==void 0)if(c)if(Ee(f)){for(c=0;c<f.length;c++)M(f[c]);Object.freeze&&Object.freeze(f)}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 M(f);if(J.call(a,"key")){f=s(e);var S=Object.keys(a).filter(function(_e){return _e!=="key"});c=0<S.length?"{key: someKey, "+S.join(": ..., ")+": ...}":"{key: someKey}",B[f+c]||(S=0<S.length?"{"+S.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} />`,c,f,S,f),B[f+c]=!0)}if(f=null,o!==void 0&&(r(o),f=""+o),u(a)&&(r(a.key),f=""+a.key),"key"in a){o={};for(var
|
|
29
|
+
<%s key={someKey} {...props} />`,c,f,S,f),B[f+c]=!0)}if(f=null,o!==void 0&&(r(o),f=""+o),u(a)&&(r(a.key),f=""+a.key),"key"in a){o={};for(var L in a)L!=="key"&&(o[L]=a[L])}else o=a;return f&&v(o,typeof e=="function"?e.displayName||e.name||"Unknown":e),_(e,f,E,R,i(),o,C,N)}function M(e){typeof e=="object"&&e!==null&&e.$$typeof===W&&e._store&&(e._store.validated=1)}var P=m,W=Symbol.for("react.transitional.element"),le=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),ue=Symbol.for("react.strict_mode"),ce=Symbol.for("react.profiler"),fe=Symbol.for("react.consumer"),de=Symbol.for("react.context"),pe=Symbol.for("react.forward_ref"),be=Symbol.for("react.suspense"),ge=Symbol.for("react.suspense_list"),he=Symbol.for("react.memo"),U=Symbol.for("react.lazy"),me=Symbol.for("react.activity"),ve=Symbol.for("react.client.reference"),w=P.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,J=Object.prototype.hasOwnProperty,Ee=Array.isArray,j=console.createTask?console.createTask:function(){return null};P={react_stack_bottom_frame:function(e){return e()}};var z,G={},X=P.react_stack_bottom_frame.bind(P,b)(),$=j(n(b)),B={};T.Fragment=O,T.jsx=function(e,a,o,c,R){var E=1e4>w.recentlyCreatedOwnerStacks++;return I(e,a,o,!1,c,R,E?Error("react-stack-top-frame"):X,E?j(n(e)):$)},T.jsxs=function(e,a,o,c,R){var E=1e4>w.recentlyCreatedOwnerStacks++;return I(e,a,o,!0,c,R,E?Error("react-stack-top-frame"):X,E?j(n(e)):$)}}()),T}var k;function H(){return k||(k=1,process.env.NODE_ENV==="production"?A.exports=q():A.exports=D()),A.exports}var Z=H();const V=m.createContext(void 0),Q=({children:s,scopeName:t})=>(t||(t=m.useMemo(()=>Math.random().toString(36).substring(2,15),[])),Z.jsx(V.Provider,{value:{scopeName:t},children:s})),K=()=>m.useContext(V);class l{data=new Map;defaultValue(){return{}}addListener(t,r,n){this.data.has(l.prefix(t,r))||this.data.set(l.prefix(t,r),{...this.defaultValue,listeners:[]}),this.data.get(l.prefix(t,r)).listeners.push(n)}removeListener(t,r,n){this.data.has(l.prefix(t,r))&&(this.data.get(l.prefix(t,r)).listeners=this.data.get(l.prefix(t,r)).listeners.filter(i=>i!==n))}callListeners(t,r){this.data.has(l.prefix(t,r))&&this.data.get(l.prefix(t,r)).listeners.forEach(n=>n())}init(t,r,n){this.data.has(l.prefix(t,r))||this.data.set(l.prefix(t,r),{...n,listeners:[]})}clearAll(t=!1){t||this.data.forEach(r=>{r.listeners.forEach(n=>n())}),this.data.clear()}clear(t,r,n=!1){n||this.callListeners(t,r),this.data.delete(l.prefix(t,r))}get(t,r){let n=this.has(t,r);if(n)return this.data.get(n)}setValue(t,r,n){this.data.has(l.prefix(t,r))&&this.data.set(l.prefix(t,r),{...this.data.get(l.prefix(t,r)),...n})}has(t,r){return this.data.has(l.prefix(t,r))?l.prefix(t,r):this.data.has(l.prefix(t,"_global"))?l.prefix(t,"_global"):void 0}static prefix(t,r){return`${r}_${t}`}}const y=s=>{const t=K();return{prefix:s??t?.scopeName??"_global"}};class ee extends l{defaultValue(){return{value:void 0}}init(t,r,n){super.init(t,r,{value:n})}setValue(t,r,n){super.setValue(t,r,{value:n})}}class te{get(t,r="_global"){const n=r||"_global";return d.get(t,n)?.value}set(t,r,n="_global"){const i=n||"_global";d.setValue(t,i,{value:r})}clearAll(){d.clearAll()}clear(t,r="_global"){const n=r||"_global";d.clear(t,n)}has(t,r="_global"){const n=r||"_global";return!!d.has(t,n)}getAll(){return d.data}}const re=new te,d=new ee,ne=(s,t,r)=>{const{prefix:n}=y(r);d.init(s,n,t);const i=m.useSyncExternalStore(u=>(d.init(s,n,t),d.addListener(s,n,u),()=>{d.removeListener(s,n,u)}),()=>d.get(s,n)?.value);return[i,u=>{const v=typeof u=="function"?u(d.get(s,n)?.value):u;v!==i&&(d.setValue(s,n,v),d.callListeners(s,n))}]};class ae extends l{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}init(t,r){super.init(t,r,this.defaultValue())}setValue(t,r,n){super.setValue(t,r,n)}}class se{get(t,r="_global"){const n=r||"_global";return p.get(t,n)?.fnState}set(t,r,n="_global"){const i=n||"_global";p.setValue(t,i,r)}clearAll(){p.clearAll()}clear(t,r="_global"){const n=r||"_global";p.clear(t,n)}has(t,r="_global"){const n=r||"_global";return!!p.has(t,n)}getAll(){return p.data}}const oe=new se,p=new ae,ie=(s,t,r)=>{const{prefix:n}=y(r);p.init(s,n);const i=m.useSyncExternalStore(u=>(p.init(s,n),p.addListener(s,n,u),()=>{p.removeListener(s,n,u)}),()=>p.get(s,n).fnState),b=async(u,...v)=>{const g=p.get(s,n);if(!u&&(g.fnState.isLoading||g.fnState.results!==void 0))return g.fnState;g.fnState={...g.fnState,isLoading:!0,error:void 0},g.listeners.forEach(_=>_());try{const _=await t(...v);g.fnState={results:_,isLoading:!1,error:void 0}}catch(_){g.fnState={...g.fnState,isLoading:!1,error:_}}g.listeners.forEach(_=>_())};return{state:i,trigger:(...u)=>{b(!1,...u)},forceTrigger:(...u)=>{b(!0,...u)},clear:()=>{p.clear(s,n),p.init(s,n)}}};h.SharedStatesProvider=Q,h.sharedFunctionsApi=oe,h.sharedStatesApi=re,h.useSharedFunction=ie,h.useSharedState=ne,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -18,7 +18,7 @@ export default defineConfig({
|
|
|
18
18
|
lib: {
|
|
19
19
|
entry: resolve(__dirname, 'src/index.ts'), // Library entry point
|
|
20
20
|
name: 'ReactSharedStates',
|
|
21
|
-
fileName: (format: string) => `main${format === 'es' ? '' : '.min'}.js`,
|
|
21
|
+
fileName: (format: string) => `main${format === 'es' ? '.esm' : '.min'}.js`,
|
|
22
22
|
formats: ['es', 'umd']
|
|
23
23
|
},
|
|
24
24
|
rollupOptions: {
|