react-shared-states 1.0.6 → 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.6
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 de, { createContext as be, useMemo as w, useContext as ge, useEffect as Q, useSyncExternalStore as M } from "react";
9
- var L = { exports: {} }, P = {};
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: {} }, 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 D;
20
- function pe() {
21
- if (D) return P;
22
- D = 1;
23
- var s = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
24
- function r(t, i, b) {
25
- var S = null;
26
- if (b !== void 0 && (S = "" + b), i.key !== void 0 && (S = "" + i.key), "key" in i) {
27
- b = {};
28
- for (var m in i)
29
- m !== "key" && (b[m] = i[m]);
30
- } else b = i;
31
- return i = b.ref, {
32
- $$typeof: s,
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,
33
33
  type: t,
34
- key: S,
35
- ref: i !== void 0 ? i : null,
36
- props: b
34
+ key: o,
35
+ ref: s !== void 0 ? s : null,
36
+ props: f
37
37
  };
38
38
  }
39
- return P.Fragment = e, P.jsx = r, P.jsxs = r, P;
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 H;
52
- function he() {
53
- return H || (H = 1, process.env.NODE_ENV !== "production" && function() {
54
- function s(n) {
51
+ var Q;
52
+ function Ee() {
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 === ce ? 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 te:
62
+ case ne:
63
63
  return "Profiler";
64
- case ee:
64
+ case v:
65
65
  return "StrictMode";
66
- case ae:
66
+ case ie:
67
67
  return "Suspense";
68
- case oe:
69
- return "SuspenseList";
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 k:
77
+ case d:
78
78
  return "Portal";
79
- case ne:
79
+ case ae:
80
80
  return (n.displayName || "Context") + ".Provider";
81
- case re:
82
- return (n._context.displayName || "Context") + ".Consumer";
83
81
  case se:
84
- var a = n.render;
85
- return n = n.displayName, n || (n = a.displayName || a.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
86
- case ie:
87
- return a = n.displayName || null, a !== null ? a : s(n.type) || "Memo";
88
- case U:
89
- a = n._payload, n = n._init;
82
+ return (n._context.displayName || "Context") + ".Consumer";
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;
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 he() {
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, p = 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
- p
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 i() {
129
- var n = N.A;
128
+ function s() {
129
+ var n = F.A;
130
130
  return n === null ? null : n.getOwner();
131
131
  }
132
- function b() {
132
+ function f() {
133
133
  return Error("react-stack-top-frame");
134
134
  }
135
- function S(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 m(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 f() {
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, p, A, _, Y, F) {
161
- return u = _.ref, n = {
162
- $$typeof: x,
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: _,
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: f
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,144 +181,146 @@ function he() {
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 g(n, a, u, p, A, _, Y, F) {
193
- var h = a.children;
194
- if (h !== void 0)
195
- if (p)
196
- if (ue(h)) {
197
- for (p = 0; p < h.length; p++)
198
- c(h[p]);
199
- Object.freeze && Object.freeze(h);
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 c(h);
205
- if (G.call(a, "key")) {
206
- h = s(n);
207
- var O = Object.keys(a).filter(function(fe) {
208
- return fe !== "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
- p = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", X[h + p] || (O = 0 < O.length ? "{" + O.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
+ g,
217
218
  p,
218
- h,
219
- O,
220
- h
221
- ), X[h + p] = !0);
219
+ j,
220
+ p
221
+ ), H[p + g] = !0);
222
222
  }
223
- if (h = null, u !== void 0 && (r(u), h = "" + u), S(a) && (r(a.key), h = "" + a.key), "key" in a) {
224
- u = {};
225
- for (var $ in a)
226
- $ !== "key" && (u[$] = a[$]);
227
- } else u = a;
228
- return h && m(
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
- h,
234
- _,
235
- A,
236
- i(),
237
- u,
238
- Y,
239
- F
233
+ p,
234
+ T,
235
+ P,
236
+ s(),
237
+ b,
238
+ $,
239
+ k
240
240
  );
241
241
  }
242
242
  function c(n) {
243
- typeof n == "object" && n !== null && n.$$typeof === x && n._store && (n._store.validated = 1);
243
+ typeof n == "object" && n !== null && n.$$typeof === h && n._store && (n._store.validated = 1);
244
244
  }
245
- var o = de, x = Symbol.for("react.transitional.element"), k = Symbol.for("react.portal"), C = Symbol.for("react.fragment"), ee = Symbol.for("react.strict_mode"), te = Symbol.for("react.profiler"), re = Symbol.for("react.consumer"), ne = Symbol.for("react.context"), se = Symbol.for("react.forward_ref"), ae = Symbol.for("react.suspense"), oe = Symbol.for("react.suspense_list"), ie = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), le = Symbol.for("react.activity"), ce = Symbol.for("react.client.reference"), N = o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, ue = 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
- o = {
248
+ S = {
249
249
  react_stack_bottom_frame: function(n) {
250
250
  return n();
251
251
  }
252
252
  };
253
- var q, J = {}, z = o.react_stack_bottom_frame.bind(
254
- o,
255
- b
256
- )(), B = V(t(b)), X = {};
257
- j.Fragment = C, j.jsx = function(n, a, u, p, A) {
258
- var _ = 1e4 > N.recentlyCreatedOwnerStacks++;
259
- return g(
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
260
  n,
261
- a,
262
- u,
261
+ i,
262
+ b,
263
263
  !1,
264
- p,
265
- A,
266
- _ ? Error("react-stack-top-frame") : z,
267
- _ ? V(t(n)) : B
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, p, A) {
270
- var _ = 1e4 > N.recentlyCreatedOwnerStacks++;
271
- return g(
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
- p,
277
- A,
278
- _ ? Error("react-stack-top-frame") : z,
279
- _ ? V(t(n)) : B
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 Z;
285
- function Ee() {
286
- return Z || (Z = 1, process.env.NODE_ENV === "production" ? L.exports = pe() : L.exports = he()), 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 = Ee();
289
- const K = be(void 0), Oe = ({ children: s, scopeName: e }) => (e || (e = w(() => Math.random().toString(36).substring(2, 15), [])), /* @__PURE__ */ ve.jsx(K.Provider, { value: { scopeName: e }, children: s })), Se = () => ge(K);
290
- let y = !1;
291
- const Pe = (s) => {
292
- y = s;
293
- }, I = (...s) => {
294
- y && console.log(
288
+ var xe = ve();
289
+ let te = !1;
290
+ const Le = (a) => {
291
+ te = a;
292
+ }, D = (...a) => {
293
+ te && console.log(
295
294
  "%c[react-shared-states]",
296
295
  "color: #007acc; font-weight: bold",
297
- ...s
296
+ ...a
298
297
  );
299
- }, R = (s) => {
300
- if (!s) throw new Error("Value is empty");
301
- return s;
302
- };
303
- class l {
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 {
304
306
  data = /* @__PURE__ */ new Map();
305
307
  defaultValue() {
306
308
  return {};
307
309
  }
308
310
  addListener(e, r, t) {
309
- this.data.has(l.prefix(e, r)) || this.data.set(l.prefix(e, r), {
311
+ this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
310
312
  ...this.defaultValue,
311
313
  listeners: []
312
- }), this.data.get(l.prefix(e, r)).listeners.push(t);
314
+ }), this.data.get(u.prefix(e, r)).listeners.push(t);
313
315
  }
314
316
  removeListener(e, r, t) {
315
- this.data.has(l.prefix(e, r)) && (this.data.get(l.prefix(e, r)).listeners = this.data.get(l.prefix(e, r)).listeners.filter((i) => i !== 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));
316
318
  }
317
319
  callListeners(e, r) {
318
- this.data.has(l.prefix(e, r)) && this.data.get(l.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());
319
321
  }
320
322
  init(e, r, t) {
321
- this.data.has(l.prefix(e, r)) || this.data.set(l.prefix(e, r), {
323
+ this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
322
324
  ...t,
323
325
  listeners: []
324
326
  });
@@ -329,7 +331,7 @@ class l {
329
331
  }), this.data.clear();
330
332
  }
331
333
  clear(e, r, t = !1) {
332
- t || this.callListeners(e, r), this.data.delete(l.prefix(e, r));
334
+ t || this.callListeners(e, r), this.data.delete(u.prefix(e, r));
333
335
  }
334
336
  get(e, r) {
335
337
  let t = this.has(e, r);
@@ -337,30 +339,116 @@ class l {
337
339
  return this.data.get(t);
338
340
  }
339
341
  setValue(e, r, t) {
340
- this.data.has(l.prefix(e, r)) && this.data.set(l.prefix(e, r), {
341
- ...this.data.get(l.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)),
342
344
  ...t
343
345
  });
344
346
  }
345
347
  has(e, r) {
346
- return this.data.has(l.prefix(e, r)) ? l.prefix(e, r) : this.data.has(l.prefix(e, "_global")) ? l.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;
347
349
  }
348
350
  static prefix(e, r) {
349
- return `${r}_${e}`;
351
+ if (e.includes("//")) throw new Error("key cannot contain '//'");
352
+ return `${r}//${e}`;
353
+ }
354
+ static extractPrefix(e) {
355
+ return e.split("//");
350
356
  }
351
357
  useEffect(e, r, t = null) {
352
- Q(() => () => {
353
- t?.(), I(`[${l.prefix(e, r)}]`, "unmount effect"), this.data.get(l.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);
354
360
  }, []);
355
361
  }
356
362
  }
357
- const W = (s) => {
358
- const e = Se();
363
+ class W {
364
+ constructor(e) {
365
+ this.sharedData = e;
366
+ }
367
+ /**
368
+ * get a value from the shared data
369
+ * @param key
370
+ * @param scopeName
371
+ */
372
+ get(e, r) {
373
+ e = R(e);
374
+ const t = r || "_global";
375
+ return this.sharedData.get(e, t);
376
+ }
377
+ /**
378
+ * set a value in the shared data
379
+ * @param key
380
+ * @param value
381
+ * @param scopeName
382
+ */
383
+ set(e, r, t) {
384
+ e = R(e);
385
+ const s = t || "_global";
386
+ this.sharedData.setValue(e, s, r);
387
+ }
388
+ /**
389
+ * clear all values from the shared data
390
+ */
391
+ clearAll() {
392
+ this.sharedData.clearAll();
393
+ }
394
+ /**
395
+ * clear all values from the shared data in a scope
396
+ * @param scopeName
397
+ */
398
+ clearScope(e) {
399
+ 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);
404
+ return;
405
+ }
406
+ });
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
+ }
416
+ /**
417
+ * clear a value from the shared data
418
+ * @param key
419
+ * @param scopeName
420
+ */
421
+ 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);
424
+ }
425
+ /**
426
+ * check if a value exists in the shared data
427
+ * @param key
428
+ * @param scopeName
429
+ */
430
+ has(e, r = "_global") {
431
+ const t = r || "_global";
432
+ return !!this.sharedData.has(e, t);
433
+ }
434
+ /**
435
+ * get all values from the shared data
436
+ */
437
+ getAll() {
438
+ const e = {};
439
+ return this.sharedData.data.forEach((r, t) => {
440
+ const [s, f] = u.extractPrefix(t);
441
+ e[s] = e[s] || {}, e[s][f] = r;
442
+ }), e;
443
+ }
444
+ }
445
+ const U = (a) => {
446
+ const e = me();
359
447
  return {
360
- prefix: s ?? e?.scopeName ?? "_global"
448
+ prefix: a ?? e?.scopeName ?? "_global"
361
449
  };
362
450
  };
363
- class me extends l {
451
+ class _e extends u {
364
452
  defaultValue() {
365
453
  return { value: void 0 };
366
454
  }
@@ -374,48 +462,47 @@ class me extends l {
374
462
  super.removeListener(e, r, t);
375
463
  }
376
464
  }
377
- class xe {
465
+ class Re extends W {
378
466
  get(e, r = "_global") {
379
467
  e = R(e);
380
468
  const t = r || "_global";
381
- return E.get(e, t)?.value;
469
+ return m.get(e, t)?.value;
382
470
  }
383
471
  set(e, r, t = "_global") {
384
472
  e = R(e);
385
- const i = t || "_global";
386
- E.setValue(e, i, { value: r });
387
- }
388
- clearAll() {
389
- E.clearAll();
390
- }
391
- clear(e, r = "_global") {
392
- const t = r || "_global";
393
- E.clear(e, t);
394
- }
395
- has(e, r = "_global") {
396
- const t = r || "_global";
397
- return !!E.has(e, t);
398
- }
399
- getAll() {
400
- return E.data;
473
+ const s = t || "_global";
474
+ m.setValue(e, s, { value: r });
401
475
  }
402
476
  }
403
- const je = new xe(), E = new me(), Le = (s, e, r) => {
404
- s = R(s);
405
- const { prefix: t } = W(r);
406
- E.init(s, t, e);
407
- const i = w(() => (f) => (E.init(s, t, e), E.addListener(s, t, f), () => {
408
- E.removeListener(s, t, f);
409
- }), []), b = w(() => () => E.get(s, t)?.value, []), S = M(i, b), m = (f) => {
410
- const T = typeof f == "function" ? f(E.get(s, t)?.value) : f;
411
- T !== S && (E.setValue(s, t, T), E.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
412
483
  };
413
- return E.useEffect(s, t), [
414
- S,
415
- m
416
- ];
417
484
  };
418
- class _e extends l {
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 {
419
506
  defaultValue() {
420
507
  return {
421
508
  fnState: {
@@ -432,70 +519,70 @@ class _e extends l {
432
519
  super.setValue(e, r, t);
433
520
  }
434
521
  }
435
- class Re {
522
+ class Ae extends W {
436
523
  get(e, r = "_global") {
437
524
  e = R(e);
438
525
  const t = r || "_global";
439
- return v.get(e, t)?.fnState;
526
+ return x.get(e, t)?.fnState;
440
527
  }
441
528
  set(e, r, t = "_global") {
442
529
  e = R(e);
443
- const i = t || "_global";
444
- v.setValue(e, i, r);
445
- }
446
- clearAll() {
447
- v.clearAll();
448
- }
449
- clear(e, r = "_global") {
450
- const t = r || "_global";
451
- v.clear(e, t);
452
- }
453
- has(e, r = "_global") {
454
- const t = r || "_global";
455
- return !!v.has(e, t);
456
- }
457
- getAll() {
458
- return v.data;
530
+ const s = t || "_global";
531
+ x.setValue(e, s, r);
459
532
  }
460
533
  }
461
- const Ce = new Re(), v = new _e(), Ne = (s, e, r) => {
462
- s = R(s);
463
- const { prefix: t } = W(r);
464
- v.init(s, t);
465
- const i = w(
466
- () => (f) => (v.init(s, t), v.addListener(s, t, f), () => {
467
- v.removeListener(s, t, f);
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);
468
554
  }),
469
555
  []
470
- ), b = w(
471
- () => () => v.get(s, t).fnState,
556
+ ), O = L(
557
+ () => () => x.get(t, o).fnState,
472
558
  []
473
- ), S = M(i, b), m = async (f, ...T) => {
474
- const g = v.get(s, t);
475
- if (!f && (g.fnState.isLoading || g.fnState.results !== void 0)) return g.fnState;
476
- g.fnState = { ...g.fnState, isLoading: !0, error: void 0 }, g.listeners.forEach((c) => c());
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());
477
563
  try {
478
- const c = await e(...T);
479
- g.fnState = { results: c, isLoading: !1, error: void 0 };
480
- } catch (c) {
481
- g.fnState = { ...g.fnState, isLoading: !1, error: c };
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 };
482
568
  }
483
- g.listeners.forEach((c) => c());
569
+ h.listeners.forEach((d) => d());
484
570
  };
485
- return v.useEffect(s, t), {
486
- state: S,
487
- trigger: (...f) => {
488
- m(!1, ...f);
571
+ return x.useEffect(t, o), {
572
+ state: w,
573
+ trigger: (...c) => {
574
+ A(!1, ...c);
489
575
  },
490
- forceTrigger: (...f) => {
491
- m(!0, ...f);
576
+ forceTrigger: (...c) => {
577
+ A(!0, ...c);
492
578
  },
493
579
  clear: () => {
494
- v.clear(s, t), v.init(s, t);
580
+ const c = x.get(t, o);
581
+ c && (c.fnState = x.defaultValue().fnState, x.callListeners(t, o));
495
582
  }
496
583
  };
497
- };
498
- class Te extends l {
584
+ }
585
+ class we extends u {
499
586
  defaultValue() {
500
587
  return {
501
588
  fnState: {
@@ -513,94 +600,99 @@ class Te extends l {
513
600
  super.setValue(e, r, t);
514
601
  }
515
602
  useEffect(e, r) {
516
- Q(() => () => {
517
- I(`[${l.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);
518
605
  }, []), super.useEffect(e, r);
519
606
  }
520
607
  async unsubscribe(e, r) {
521
608
  const t = this.get(e, r);
522
- 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));
523
610
  }
524
611
  }
525
- class Ae {
612
+ class Pe extends W {
526
613
  get(e, r = "_global") {
527
614
  e = R(e);
528
615
  const t = r || "_global";
529
- return d.get(e, t)?.fnState;
616
+ return E.get(e, t)?.fnState;
530
617
  }
531
618
  set(e, r, t = "_global") {
532
619
  e = R(e);
533
- const i = t || "_global";
534
- d.setValue(e, i, r);
535
- }
536
- clearAll() {
537
- d.clearAll();
538
- }
539
- clear(e, r = "_global") {
540
- const t = r || "_global";
541
- d.clear(e, t);
542
- }
543
- has(e, r = "_global") {
544
- const t = r || "_global";
545
- return !!d.has(e, t);
546
- }
547
- getAll() {
548
- return d.data;
620
+ const s = t || "_global";
621
+ E.setValue(e, s, r);
549
622
  }
550
623
  }
551
- const Ve = new Ae(), d = new Te(), Ye = (s, e, r) => {
552
- s = R(s);
553
- const { prefix: t } = W(r);
554
- d.init(s, t);
555
- const i = w(
556
- () => (c) => (d.init(s, t), d.addListener(s, t, c), () => {
557
- d.removeListener(s, t, c);
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);
558
644
  }),
559
645
  []
560
- ), b = w(
561
- () => () => d.get(s, t).fnState,
646
+ ), O = L(
647
+ () => () => E.get(t, o).fnState,
562
648
  []
563
- ), S = M(i, b), m = (c) => {
564
- const o = d.get(s, t);
565
- o.fnState = { ...o.fnState, data: c }, o.listeners.forEach((x) => x());
566
- }, f = (c) => {
567
- const o = d.get(s, t);
568
- o.fnState = { ...o.fnState, isLoading: !1, data: void 0, error: c }, o.listeners.forEach((x) => x());
569
- }, T = () => {
570
- const c = d.get(s, t);
571
- c.fnState = { ...c.fnState, isLoading: !1 }, c.listeners.forEach((o) => o());
572
- }, g = async (c) => {
573
- const o = d.get(s, t);
574
- if (c && (await d.unsubscribe(s, t), o.fnState = { ...o.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), o.fnState.subscribed) return o.fnState;
575
- I("triggered !!"), o.fnState = { ...o.fnState, isLoading: !0, error: void 0 }, o.listeners.forEach((x) => x());
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());
576
662
  try {
577
- o.unsubscribe = await e(m, f, T), o.fnState.subscribed = !0;
578
- } catch (x) {
579
- o.fnState = { ...o.fnState, isLoading: !1, error: x };
663
+ l.unsubscribe = await s(A, c, S), l.fnState.subscribed = !0;
664
+ } catch (v) {
665
+ l.fnState = { ...l.fnState, isLoading: !1, error: v };
580
666
  }
581
- o.listeners.forEach((x) => x());
667
+ l.listeners.forEach((v) => v());
582
668
  };
583
- return d.useEffect(s, t), {
584
- state: S,
669
+ return E.useEffect(t, o), {
670
+ state: w,
585
671
  trigger: () => {
586
- g(!1);
672
+ h(!1);
587
673
  },
588
674
  forceTrigger: () => {
589
- g(!0);
675
+ h(!0);
590
676
  },
591
677
  unsubscribe: () => {
592
- d.unsubscribe(s, t);
678
+ E.unsubscribe(t, o);
593
679
  }
594
680
  };
595
- };
681
+ }
596
682
  export {
597
- Oe as SharedStatesProvider,
598
- y as isDevMode,
599
- Pe as setDevMode,
600
- Ce as sharedFunctionsApi,
601
- je as sharedStatesApi,
602
- Ve as sharedSubscriptionsApi,
603
- Ne as useSharedFunction,
604
- Le as useSharedState,
605
- Ye as useSharedSubscription
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,
692
+ Ne as sharedFunctionsApi,
693
+ Ve as sharedStatesApi,
694
+ $e as sharedSubscriptionsApi,
695
+ Ye as useSharedFunction,
696
+ ye as useSharedState,
697
+ Me as useSharedSubscription
606
698
  };