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