react-shared-states 1.0.7 → 1.0.8

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