react-shared-states 1.0.7 → 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.7
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 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 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,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) {
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,
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: E,
35
- ref: o !== void 0 ? o : null,
36
- props: f
34
+ key: a,
35
+ ref: n !== void 0 ? n : null,
36
+ props: c
37
37
  };
38
38
  }
39
- return O.Fragment = e, O.jsx = r, O.jsxs = r, O;
39
+ return j.Fragment = e, j.jsx = r, j.jsxs = r, j;
40
40
  }
41
- var j = {};
41
+ var C = {};
42
42
  /**
43
43
  * @license React
44
44
  * react-jsx-runtime.development.js
@@ -48,291 +48,311 @@ 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;
52
- function Ee() {
53
- return Z || (Z = 1, process.env.NODE_ENV !== "production" && function() {
54
- function s(n) {
55
- if (n == null) return null;
56
- if (typeof n == "function")
57
- return n.$$typeof === ue ? null : n.displayName || n.name || null;
58
- if (typeof n == "string") return n;
59
- switch (n) {
60
- case C:
51
+ var Q;
52
+ function ve() {
53
+ return Q || (Q = 1, process.env.NODE_ENV !== "production" && function() {
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 re:
62
+ case y:
63
63
  return "Profiler";
64
- case te:
64
+ case P:
65
65
  return "StrictMode";
66
- case oe:
66
+ case ce:
67
67
  return "Suspense";
68
- case ie:
68
+ case ue:
69
69
  return "SuspenseList";
70
- case le:
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 ee:
76
+ ), s.$$typeof) {
77
+ case p:
78
78
  return "Portal";
79
- case se:
80
- return (n.displayName || "Context") + ".Provider";
81
- case ne:
82
- return (n._context.displayName || "Context") + ".Consumer";
79
+ case ie:
80
+ return (s.displayName || "Context") + ".Provider";
83
81
  case ae:
84
- var a = n.render;
85
- return n = n.displayName, n || (n = a.displayName || a.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
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;
82
+ return (s._context.displayName || "Context") + ".Consumer";
83
+ case oe:
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 s(n(a));
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 a = !1;
102
+ e(s);
103
+ var o = !1;
104
104
  } catch {
105
- a = !0;
105
+ o = !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 (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
- h
114
- ), e(n);
113
+ g
114
+ ), e(s);
115
115
  }
116
116
  }
117
- function t(n) {
118
- if (n === C) return "<>";
119
- if (typeof n == "object" && n !== null && n.$$typeof === U)
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 a = s(n);
123
- return a ? "<" + a + ">" : "<...>";
122
+ var o = i(s);
123
+ return o ? "<" + o + ">" : "<...>";
124
124
  } catch {
125
125
  return "<...>";
126
126
  }
127
127
  }
128
- function o() {
129
- var n = N.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 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 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 S(n, a) {
143
- function u() {
144
- q || (q = !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
- a
146
+ o
147
147
  ));
148
148
  }
149
- u.isReactWarning = !0, Object.defineProperty(n, "key", {
150
- get: u,
149
+ f.isReactWarning = !0, Object.defineProperty(s, "key", {
150
+ get: f,
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 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 T(n, a, u, h, A, R, Y, F) {
161
- return u = R.ref, n = {
162
- $$typeof: v,
163
- type: n,
164
- key: a,
165
- props: R,
166
- _owner: A
167
- }, (u !== void 0 ? u : null) !== null ? Object.defineProperty(n, "ref", {
160
+ function A(s, o, f, g, w, _, Y, $) {
161
+ return f = _.ref, s = {
162
+ $$typeof: h,
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: d
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
184
  value: Y
185
- }), Object.defineProperty(n, "_debugTask", {
185
+ }), Object.defineProperty(s, "_debugTask", {
186
186
  configurable: !1,
187
187
  enumerable: !1,
188
188
  writable: !0,
189
- value: F
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 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 T(s, o, f, g, w, _, Y, $) {
193
+ var x = o.children;
194
+ if (x !== void 0)
195
+ if (g)
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 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 l(x);
205
+ if (J.call(o, "key")) {
206
+ x = i(s);
207
+ var O = Object.keys(o).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 < 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} />
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
+ x,
219
+ O,
220
+ x
221
+ ), Z[x + 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,
230
- typeof n == "function" ? n.displayName || n.name || "Unknown" : n
231
- ), T(
232
- n,
233
- g,
234
- R,
235
- A,
236
- o(),
237
- u,
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
238
  Y,
239
- F
239
+ $
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 l(s) {
243
+ typeof s == "object" && s !== null && s.$$typeof === h && s._store && (s._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 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
- i = {
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 q, J = {}, z = i.react_stack_bottom_frame.bind(
254
- i,
255
- f
256
- )(), X = V(t(f)), B = {};
257
- j.Fragment = C, j.jsx = function(n, a, u, h, A) {
258
- var R = 1e4 > N.recentlyCreatedOwnerStacks++;
259
- return b(
260
- n,
261
- a,
262
- u,
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
- h,
265
- A,
266
- R ? Error("react-stack-top-frame") : z,
267
- R ? V(t(n)) : X
264
+ g,
265
+ w,
266
+ _ ? Error("react-stack-top-frame") : B,
267
+ _ ? F(t(s)) : H
268
268
  );
269
- }, j.jsxs = function(n, a, u, h, A) {
270
- var R = 1e4 > N.recentlyCreatedOwnerStacks++;
271
- return b(
272
- n,
273
- a,
274
- u,
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
- h,
277
- A,
278
- R ? Error("react-stack-top-frame") : z,
279
- R ? V(t(n)) : X
276
+ g,
277
+ w,
278
+ _ ? Error("react-stack-top-frame") : B,
279
+ _ ? F(t(s)) : H
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 Ee() {
286
+ return K || (K = 1, process.env.NODE_ENV === "production" ? k.exports = xe() : k.exports = ve()), k.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 me = Ee();
289
+ let re = !1;
290
+ const Oe = (i) => {
291
+ re = i;
292
+ }, W = (...i) => {
293
+ re && console.log(
298
294
  "%c[react-shared-states]",
299
295
  "color: #007acc; font-weight: bold",
300
- ...s
296
+ ...i
301
297
  );
302
- }, _ = (s) => {
303
- if (!s) throw new Error("Value is empty");
304
- return s;
305
- };
306
- class c {
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
+ if (e && e.includes("//")) throw new Error("scopeName cannot contain '//'");
303
+ return e || (e = L(() => se(), [])), /* @__PURE__ */ me.jsx(ne.Provider, { value: { scopeName: e }, children: i });
304
+ }, Re = () => ge(ne), ee = [];
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), {
313
- ...this.defaultValue,
311
+ this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
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((n) => n !== 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
- init(e, r, t) {
324
- this.data.has(c.prefix(e, r)) || this.data.set(c.prefix(e, r), {
322
+ init(e, r, t, n = !1) {
323
+ this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
325
324
  ...t,
325
+ isStatic: n,
326
326
  listeners: []
327
327
  });
328
328
  }
329
- clearAll(e = !1) {
330
- e || this.data.forEach((r) => {
331
- r.listeners.forEach((t) => t());
332
- }), 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
+ });
333
346
  }
334
- clear(e, r, t = !1) {
335
- t || this.callListeners(e, r), this.data.delete(c.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
+ }
336
356
  }
337
357
  get(e, r) {
338
358
  let t = this.has(e, r);
@@ -340,13 +360,13 @@ class c {
340
360
  return this.data.get(t);
341
361
  }
342
362
  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)),
363
+ this.data.has(u.prefix(e, r)) && this.data.set(u.prefix(e, r), {
364
+ ...this.data.get(u.prefix(e, r)),
345
365
  ...t
346
366
  });
347
367
  }
348
368
  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;
369
+ 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
370
  }
351
371
  static prefix(e, r) {
352
372
  if (e.includes("//")) throw new Error("key cannot contain '//'");
@@ -356,35 +376,34 @@ class c {
356
376
  return e.split("//");
357
377
  }
358
378
  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);
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);
361
381
  }, []);
362
382
  }
363
383
  }
364
- class D {
384
+ class U {
365
385
  constructor(e) {
366
386
  this.sharedData = e;
367
387
  }
368
- /**
369
- * get a value from the shared data
370
- * @param key
371
- * @param scopeName
372
- */
373
388
  get(e, r) {
374
- e = _(e);
375
- const t = r || "_global";
376
- 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);
377
397
  }
378
- /**
379
- * set a value in the shared data
380
- * @param key
381
- * @param value
382
- * @param scopeName
383
- */
384
398
  set(e, r, t) {
385
- e = _(e);
386
- const o = t || "_global";
387
- this.sharedData.setValue(e, o, 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);
388
407
  }
389
408
  /**
390
409
  * clear all values from the shared data
@@ -398,22 +417,25 @@ class D {
398
417
  */
399
418
  clearScope(e) {
400
419
  const r = e || "_global";
401
- this.sharedData.data.forEach((t, o) => {
402
- const [f] = c.extractPrefix(o);
403
- if (f === r) {
404
- this.sharedData.clear(o, f);
420
+ this.sharedData.data.forEach((t, n) => {
421
+ const [c, a] = u.extractPrefix(n);
422
+ if (c === r) {
423
+ this.sharedData.clear(a, c);
405
424
  return;
406
425
  }
407
426
  });
408
427
  }
409
428
  /**
410
- * clear a value from the shared data
411
- * @param key
412
- * @param scopeName
429
+ * resolve a shared created object to a value
430
+ * @param sharedCreated
413
431
  */
432
+ resolve(e) {
433
+ const { key: r, prefix: t } = e;
434
+ return this.get(r, t);
435
+ }
414
436
  clear(e, r) {
415
- const t = r || "_global";
416
- this.sharedData.clear(e, t);
437
+ let t, n;
438
+ typeof e == "string" ? (t = e, n = r || "_global") : (t = e.key, n = e.prefix), this.sharedData.clear(t, n);
417
439
  }
418
440
  /**
419
441
  * check if a value exists in the shared data
@@ -430,59 +452,66 @@ class D {
430
452
  getAll() {
431
453
  const e = {};
432
454
  return this.sharedData.data.forEach((r, t) => {
433
- const [o, f] = c.extractPrefix(t);
434
- e[o] = e[o] || {}, e[o][f] = r;
455
+ const [n, c] = u.extractPrefix(t);
456
+ e[n] = e[n] || {}, e[n][c] = r;
435
457
  }), e;
436
458
  }
437
459
  }
438
- const W = (s) => {
439
- const e = me();
460
+ const G = (i) => {
461
+ const e = Re();
440
462
  return {
441
- prefix: s ?? e?.scopeName ?? "_global"
463
+ prefix: i ?? e?.scopeName ?? "_global"
442
464
  };
443
465
  };
444
- class xe extends c {
466
+ class _e extends u {
445
467
  defaultValue() {
446
468
  return { value: void 0 };
447
469
  }
448
- init(e, r, t) {
449
- super.init(e, r, { value: t });
470
+ initValue(e, r, t, n = !1) {
471
+ super.init(e, r, { value: t }, n);
450
472
  }
451
- setValue(e, r, t) {
452
- super.setValue(e, r, { value: t });
453
- }
454
- removeListener(e, r, t) {
455
- super.removeListener(e, r, t);
473
+ initStatic(e) {
474
+ const { key: r, prefix: t, initialValue: n } = e;
475
+ this.initValue(r, t, n, !0);
456
476
  }
457
477
  }
458
- class _e extends D {
478
+ class Te extends U {
479
+ constructor(e) {
480
+ super(e);
481
+ }
459
482
  get(e, r = "_global") {
460
- e = _(e);
461
- const t = r || "_global";
462
- return m.get(e, t)?.value;
483
+ return typeof e != "string" ? super.get(e)?.value : super.get(e, r)?.value;
463
484
  }
464
485
  set(e, r, t = "_global") {
465
- e = _(e);
466
- const o = t || "_global";
467
- m.setValue(e, o, { value: r });
486
+ if (typeof e != "string") {
487
+ super.set(e, { value: r });
488
+ return;
489
+ }
490
+ super.set(e, { value: r }, t);
468
491
  }
469
492
  }
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));
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;
499
+ } else
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));
479
508
  };
480
- return m.useEffect(s, t), [
481
- E,
482
- S
509
+ return R.useEffect(t, a), [
510
+ A,
511
+ T
483
512
  ];
484
- };
485
- class Re extends c {
513
+ }
514
+ class Ae extends u {
486
515
  defaultValue() {
487
516
  return {
488
517
  fnState: {
@@ -492,63 +521,73 @@ class Re extends c {
492
521
  }
493
522
  };
494
523
  }
495
- init(e, r) {
496
- super.init(e, r, this.defaultValue());
524
+ initValue(e, r, t = !1) {
525
+ super.init(e, r, this.defaultValue(), t);
497
526
  }
498
527
  setValue(e, r, t) {
499
528
  super.setValue(e, r, t);
500
529
  }
501
530
  }
502
- class Te extends D {
531
+ class we extends U {
532
+ constructor(e) {
533
+ super(e);
534
+ }
503
535
  get(e, r = "_global") {
504
- e = _(e);
505
- const t = r || "_global";
506
- return x.get(e, t)?.fnState;
536
+ return typeof e != "string" ? super.get(e)?.fnState : super.get(e, r)?.fnState;
507
537
  }
508
538
  set(e, r, t = "_global") {
509
- e = _(e);
510
- const o = t || "_global";
511
- x.setValue(e, o, r);
539
+ if (typeof e != "string") {
540
+ super.set(e, r);
541
+ return;
542
+ }
543
+ super.set(e, r, t);
512
544
  }
513
545
  }
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);
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;
552
+ } else
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);
521
559
  }),
522
560
  []
523
- ), f = w(
524
- () => () => x.get(s, t).fnState,
561
+ ), E = L(
562
+ () => () => m.get(t, a).fnState,
525
563
  []
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());
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);
530
568
  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 };
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 };
535
573
  }
536
- b.listeners.forEach((l) => l());
574
+ m.callListeners(t, a);
537
575
  };
538
- return x.useEffect(s, t), {
539
- state: E,
540
- trigger: (...d) => {
541
- S(!1, ...d);
576
+ return m.useEffect(t, a), {
577
+ state: A,
578
+ trigger: (...l) => {
579
+ T(!1, ...l);
542
580
  },
543
- forceTrigger: (...d) => {
544
- S(!0, ...d);
581
+ forceTrigger: (...l) => {
582
+ T(!0, ...l);
545
583
  },
546
584
  clear: () => {
547
- x.clear(s, t), x.init(s, t);
585
+ const l = m.get(t, a);
586
+ l && (l.fnState = m.defaultValue().fnState, m.callListeners(t, a));
548
587
  }
549
588
  };
550
- };
551
- class Ae extends c {
589
+ }
590
+ class Pe extends u {
552
591
  defaultValue() {
553
592
  return {
554
593
  fnState: {
@@ -559,87 +598,104 @@ class Ae extends c {
559
598
  }
560
599
  };
561
600
  }
562
- init(e, r) {
563
- super.init(e, r, this.defaultValue());
601
+ initValue(e, r, t = !1) {
602
+ super.init(e, r, this.defaultValue(), t);
564
603
  }
565
604
  setValue(e, r, t) {
566
605
  super.setValue(e, r, t);
567
606
  }
568
607
  useEffect(e, r) {
569
- K(() => () => {
570
- I(`[${c.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);
571
610
  }, []), super.useEffect(e, r);
572
611
  }
573
612
  async unsubscribe(e, r) {
574
613
  const t = this.get(e, r);
575
- t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState.subscribed = !1);
614
+ t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState = { ...t.fnState, subscribed: !1 }, this.callListeners(e, r));
576
615
  }
577
616
  }
578
- class we extends D {
617
+ class ye extends U {
618
+ constructor(e) {
619
+ super(e);
620
+ }
579
621
  get(e, r = "_global") {
580
- e = _(e);
581
- const t = r || "_global";
582
- return p.get(e, t)?.fnState;
622
+ return typeof e != "string" ? super.get(e)?.fnState : super.get(e, r)?.fnState;
583
623
  }
584
624
  set(e, r, t = "_global") {
585
- e = _(e);
586
- const o = t || "_global";
587
- p.setValue(e, o, r);
625
+ if (typeof e != "string") {
626
+ super.set(e, r);
627
+ return;
628
+ }
629
+ super.set(e, r, t);
588
630
  }
589
631
  }
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);
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;
638
+ } else
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);
597
645
  }),
598
646
  []
599
- ), f = w(
600
- () => () => p.get(s, t).fnState,
647
+ ), E = L(
648
+ () => () => d.get(t, a).fnState,
601
649
  []
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());
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);
615
663
  try {
616
- i.unsubscribe = await e(S, d, T), i.fnState.subscribed = !0;
617
- } catch (v) {
618
- i.fnState = { ...i.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 };
619
669
  }
620
- i.listeners.forEach((v) => v());
670
+ d.callListeners(t, a);
621
671
  };
622
- return p.useEffect(s, t), {
623
- state: E,
672
+ return d.useEffect(t, a), {
673
+ state: A,
624
674
  trigger: () => {
625
- b(!1);
675
+ h(!1);
626
676
  },
627
677
  forceTrigger: () => {
628
- b(!0);
678
+ h(!0);
629
679
  },
630
680
  unsubscribe: () => {
631
- p.unsubscribe(s, t);
681
+ d.unsubscribe(t, a);
632
682
  }
633
683
  };
634
- };
684
+ }
635
685
  export {
636
- Oe as SharedStatesProvider,
637
- k as isDevMode,
638
- je as setDevMode,
686
+ we as SharedFunctionsApi,
687
+ Te as SharedStatesApi,
688
+ je as SharedStatesProvider,
689
+ ye as SharedSubscriptionsApi,
690
+ Fe as createSharedFunction,
691
+ De as createSharedState,
692
+ Ie as createSharedSubscription,
693
+ re as isDevMode,
694
+ Oe as setDevMode,
639
695
  Ne as sharedFunctionsApi,
640
- Le as sharedStatesApi,
641
- Ye as sharedSubscriptionsApi,
642
- Ve as useSharedFunction,
643
- Ce as useSharedState,
644
- Fe as useSharedSubscription
696
+ Ce as sharedStatesApi,
697
+ $e as sharedSubscriptionsApi,
698
+ Ye as useSharedFunction,
699
+ ke as useSharedState,
700
+ Ve as useSharedSubscription
645
701
  };