react-shared-states 1.0.8 → 1.0.12

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,15 @@
1
1
  /*!
2
- * react-shared-states v1.0.8
2
+ * react-shared-states v1.0.12
3
3
  * (c) Hichem Taboukouyout
4
4
  * Released under the MIT License.
5
5
  * Github: github.com/HichemTab-tech/react-shared-states
6
6
  */
7
7
 
8
- import he, { createContext as ge, useMemo as L, useContext as pe, useEffect as ee, useSyncExternalStore as I } from "react";
9
- var y = { exports: {} }, V = {};
8
+ import ve, { createContext as be, useMemo as T, useContext as xe, useEffect as ne, useSyncExternalStore as N, useRef as Ee } from "react";
9
+ function me(i) {
10
+ return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
11
+ }
12
+ var F = { exports: {} }, C = {};
10
13
  /**
11
14
  * @license React
12
15
  * react-jsx-runtime.production.js
@@ -16,29 +19,29 @@ var y = { exports: {} }, V = {};
16
19
  * This source code is licensed under the MIT license found in the
17
20
  * LICENSE file in the root directory of this source tree.
18
21
  */
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,
22
+ var Q;
23
+ function Re() {
24
+ if (Q) return C;
25
+ Q = 1;
26
+ var i = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
27
+ function r(t, o, a) {
28
+ var n = null;
29
+ if (a !== void 0 && (n = "" + a), o.key !== void 0 && (n = "" + o.key), "key" in o) {
30
+ a = {};
31
+ for (var f in o)
32
+ f !== "key" && (a[f] = o[f]);
33
+ } else a = o;
34
+ return o = a.ref, {
35
+ $$typeof: i,
33
36
  type: t,
34
- key: o,
35
- ref: s !== void 0 ? s : null,
36
- props: f
37
+ key: n,
38
+ ref: o !== void 0 ? o : null,
39
+ props: a
37
40
  };
38
41
  }
39
- return V.Fragment = e, V.jsx = r, V.jsxs = r, V;
42
+ return C.Fragment = e, C.jsx = r, C.jsxs = r, C;
40
43
  }
41
- var C = {};
44
+ var D = {};
42
45
  /**
43
46
  * @license React
44
47
  * react-jsx-runtime.development.js
@@ -48,290 +51,311 @@ var C = {};
48
51
  * This source code is licensed under the MIT license found in the
49
52
  * LICENSE file in the root directory of this source tree.
50
53
  */
51
- var Q;
52
- function Ee() {
53
- return Q || (Q = 1, process.env.NODE_ENV !== "production" && function() {
54
- function a(n) {
55
- if (n == null) return null;
56
- if (typeof n == "function")
57
- return n.$$typeof === fe ? null : n.displayName || n.name || null;
58
- if (typeof n == "string") return n;
59
- switch (n) {
60
- case l:
54
+ var K;
55
+ function _e() {
56
+ return K || (K = 1, process.env.NODE_ENV !== "production" && function() {
57
+ function i(s) {
58
+ if (s == null) return null;
59
+ if (typeof s == "function")
60
+ return s.$$typeof === he ? null : s.displayName || s.name || null;
61
+ if (typeof s == "string") return s;
62
+ switch (s) {
63
+ case x:
61
64
  return "Fragment";
62
- case ne:
65
+ case P:
63
66
  return "Profiler";
64
- case v:
67
+ case O:
65
68
  return "StrictMode";
66
- case ie:
69
+ case fe:
67
70
  return "Suspense";
68
71
  case le:
69
72
  return "SuspenseList";
70
- case ue:
73
+ case pe:
71
74
  return "Activity";
72
75
  }
73
- if (typeof n == "object")
74
- switch (typeof n.tag == "number" && console.error(
76
+ if (typeof s == "object")
77
+ switch (typeof s.tag == "number" && console.error(
75
78
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
76
- ), n.$$typeof) {
77
- case d:
79
+ ), s.$$typeof) {
80
+ case v:
78
81
  return "Portal";
79
- case ae:
80
- return (n.displayName || "Context") + ".Provider";
81
- case se:
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
82
  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;
83
+ return (s.displayName || "Context") + ".Provider";
84
+ case ie:
85
+ return (s._context.displayName || "Context") + ".Consumer";
86
+ case ue:
87
+ var u = s.render;
88
+ return s = s.displayName, s || (s = u.displayName || u.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
89
+ case de:
90
+ return u = s.displayName || null, u !== null ? u : i(s.type) || "Memo";
91
+ case U:
92
+ u = s._payload, s = s._init;
90
93
  try {
91
- return a(n(i));
94
+ return i(s(u));
92
95
  } catch {
93
96
  }
94
97
  }
95
98
  return null;
96
99
  }
97
- function e(n) {
98
- return "" + n;
100
+ function e(s) {
101
+ return "" + s;
99
102
  }
100
- function r(n) {
103
+ function r(s) {
101
104
  try {
102
- e(n);
103
- var i = !1;
105
+ e(s);
106
+ var u = !1;
104
107
  } catch {
105
- i = !0;
108
+ u = !0;
106
109
  }
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,
110
+ if (u) {
111
+ u = console;
112
+ var h = u.error, E = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
113
+ return h.call(
114
+ u,
112
115
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
113
- g
114
- ), e(n);
116
+ E
117
+ ), e(s);
115
118
  }
116
119
  }
117
- function t(n) {
118
- if (n === l) return "<>";
119
- if (typeof n == "object" && n !== null && n.$$typeof === G)
120
+ function t(s) {
121
+ if (s === x) return "<>";
122
+ if (typeof s == "object" && s !== null && s.$$typeof === U)
120
123
  return "<...>";
121
124
  try {
122
- var i = a(n);
123
- return i ? "<" + i + ">" : "<...>";
125
+ var u = i(s);
126
+ return u ? "<" + u + ">" : "<...>";
124
127
  } catch {
125
128
  return "<...>";
126
129
  }
127
130
  }
128
- function s() {
129
- var n = F.A;
130
- return n === null ? null : n.getOwner();
131
+ function o() {
132
+ var s = $.A;
133
+ return s === null ? null : s.getOwner();
131
134
  }
132
- function f() {
135
+ function a() {
133
136
  return Error("react-stack-top-frame");
134
137
  }
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;
138
+ function n(s) {
139
+ if (B.call(s, "key")) {
140
+ var u = Object.getOwnPropertyDescriptor(s, "key").get;
141
+ if (u && u.isReactWarning) return !1;
139
142
  }
140
- return n.key !== void 0;
143
+ return s.key !== void 0;
141
144
  }
142
- function _(n, i) {
143
- function b() {
145
+ function f(s, u) {
146
+ function h() {
144
147
  J || (J = !0, console.error(
145
148
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
146
- i
149
+ u
147
150
  ));
148
151
  }
149
- b.isReactWarning = !0, Object.defineProperty(n, "key", {
150
- get: b,
152
+ h.isReactWarning = !0, Object.defineProperty(s, "key", {
153
+ get: h,
151
154
  configurable: !0
152
155
  });
153
156
  }
154
- function O() {
155
- var n = a(this.type);
156
- return z[n] || (z[n] = !0, console.error(
157
+ function c() {
158
+ var s = i(this.type);
159
+ return M[s] || (M[s] = !0, console.error(
157
160
  "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;
161
+ )), s = this.props.ref, s !== void 0 ? s : null;
159
162
  }
160
- function w(n, i, b, g, P, T, $, k) {
161
- return b = T.ref, n = {
162
- $$typeof: h,
163
- type: n,
164
- key: i,
165
- props: T,
166
- _owner: P
167
- }, (b !== void 0 ? b : null) !== null ? Object.defineProperty(n, "ref", {
163
+ function g(s, u, h, E, A, w, Y, I) {
164
+ return h = w.ref, s = {
165
+ $$typeof: b,
166
+ type: s,
167
+ key: u,
168
+ props: w,
169
+ _owner: A
170
+ }, (h !== void 0 ? h : null) !== null ? Object.defineProperty(s, "ref", {
168
171
  enumerable: !1,
169
- get: O
170
- }) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
172
+ get: c
173
+ }) : Object.defineProperty(s, "ref", { enumerable: !1, value: null }), s._store = {}, Object.defineProperty(s._store, "validated", {
171
174
  configurable: !1,
172
175
  enumerable: !1,
173
176
  writable: !0,
174
177
  value: 0
175
- }), Object.defineProperty(n, "_debugInfo", {
178
+ }), Object.defineProperty(s, "_debugInfo", {
176
179
  configurable: !1,
177
180
  enumerable: !1,
178
181
  writable: !0,
179
182
  value: null
180
- }), Object.defineProperty(n, "_debugStack", {
183
+ }), Object.defineProperty(s, "_debugStack", {
181
184
  configurable: !1,
182
185
  enumerable: !1,
183
186
  writable: !0,
184
- value: $
185
- }), Object.defineProperty(n, "_debugTask", {
187
+ value: Y
188
+ }), Object.defineProperty(s, "_debugTask", {
186
189
  configurable: !1,
187
190
  enumerable: !1,
188
191
  writable: !0,
189
- value: k
190
- }), Object.freeze && (Object.freeze(n.props), Object.freeze(n)), n;
192
+ value: I
193
+ }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
191
194
  }
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);
195
+ function p(s, u, h, E, A, w, Y, I) {
196
+ var m = u.children;
197
+ if (m !== void 0)
198
+ if (E)
199
+ if (Se(m)) {
200
+ for (E = 0; E < m.length; E++)
201
+ l(m[E]);
202
+ Object.freeze && Object.freeze(m);
200
203
  } else
201
204
  console.error(
202
205
  "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
206
  );
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";
207
+ else l(m);
208
+ if (B.call(u, "key")) {
209
+ m = i(s);
210
+ var L = Object.keys(u).filter(function(ge) {
211
+ return ge !== "key";
209
212
  });
210
- g = 0 < j.length ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}", H[p + g] || (j = 0 < j.length ? "{" + j.join(": ..., ") + ": ...}" : "{}", console.error(
213
+ E = 0 < L.length ? "{key: someKey, " + L.join(": ..., ") + ": ...}" : "{key: someKey}", Z[m + E] || (L = 0 < L.length ? "{" + L.join(": ..., ") + ": ...}" : "{}", console.error(
211
214
  `A props object containing a "key" prop is being spread into JSX:
212
215
  let props = %s;
213
216
  <%s {...props} />
214
217
  React keys must be passed directly to JSX without using spread:
215
218
  let props = %s;
216
219
  <%s key={someKey} {...props} />`,
217
- g,
218
- p,
219
- j,
220
- p
221
- ), H[p + g] = !0);
220
+ E,
221
+ m,
222
+ L,
223
+ m
224
+ ), Z[m + E] = !0);
222
225
  }
223
- if (p = null, b !== void 0 && (r(b), p = "" + b), o(i) && (r(i.key), p = "" + i.key), "key" in i) {
224
- b = {};
225
- for (var M in i)
226
- M !== "key" && (b[M] = i[M]);
227
- } else b = i;
228
- return p && _(
229
- b,
230
- typeof n == "function" ? n.displayName || n.name || "Unknown" : n
231
- ), w(
232
- n,
233
- p,
234
- T,
235
- P,
236
- s(),
237
- b,
238
- $,
239
- k
226
+ if (m = null, h !== void 0 && (r(h), m = "" + h), n(u) && (r(u.key), m = "" + u.key), "key" in u) {
227
+ h = {};
228
+ for (var q in u)
229
+ q !== "key" && (h[q] = u[q]);
230
+ } else h = u;
231
+ return m && f(
232
+ h,
233
+ typeof s == "function" ? s.displayName || s.name || "Unknown" : s
234
+ ), g(
235
+ s,
236
+ m,
237
+ w,
238
+ A,
239
+ o(),
240
+ h,
241
+ Y,
242
+ I
240
243
  );
241
244
  }
242
- function c(n) {
243
- typeof n == "object" && n !== null && n.$$typeof === h && n._store && (n._store.validated = 1);
245
+ function l(s) {
246
+ typeof s == "object" && s !== null && s.$$typeof === b && s._store && (s._store.validated = 1);
244
247
  }
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() {
248
+ var R = ve, b = Symbol.for("react.transitional.element"), v = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), ie = Symbol.for("react.consumer"), ce = Symbol.for("react.context"), ue = Symbol.for("react.forward_ref"), fe = Symbol.for("react.suspense"), le = Symbol.for("react.suspense_list"), de = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), pe = Symbol.for("react.activity"), he = Symbol.for("react.client.reference"), $ = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, Se = Array.isArray, V = console.createTask ? console.createTask : function() {
246
249
  return null;
247
250
  };
248
- S = {
249
- react_stack_bottom_frame: function(n) {
250
- return n();
251
+ R = {
252
+ react_stack_bottom_frame: function(s) {
253
+ return s();
251
254
  }
252
255
  };
253
- var J, z = {}, X = S.react_stack_bottom_frame.bind(
254
- S,
255
- f
256
- )(), B = Y(t(f)), H = {};
257
- C.Fragment = l, C.jsx = function(n, i, b, g, P) {
258
- var T = 1e4 > F.recentlyCreatedOwnerStacks++;
259
- return A(
260
- n,
261
- i,
262
- b,
256
+ var J, M = {}, X = R.react_stack_bottom_frame.bind(
257
+ R,
258
+ a
259
+ )(), H = V(t(a)), Z = {};
260
+ D.Fragment = x, D.jsx = function(s, u, h, E, A) {
261
+ var w = 1e4 > $.recentlyCreatedOwnerStacks++;
262
+ return p(
263
+ s,
264
+ u,
265
+ h,
263
266
  !1,
264
- g,
265
- P,
266
- T ? Error("react-stack-top-frame") : X,
267
- T ? Y(t(n)) : B
267
+ E,
268
+ A,
269
+ w ? Error("react-stack-top-frame") : X,
270
+ w ? V(t(s)) : H
268
271
  );
269
- }, C.jsxs = function(n, i, b, g, P) {
270
- var T = 1e4 > F.recentlyCreatedOwnerStacks++;
271
- return A(
272
- n,
273
- i,
274
- b,
272
+ }, D.jsxs = function(s, u, h, E, A) {
273
+ var w = 1e4 > $.recentlyCreatedOwnerStacks++;
274
+ return p(
275
+ s,
276
+ u,
277
+ h,
275
278
  !0,
276
- g,
277
- P,
278
- T ? Error("react-stack-top-frame") : X,
279
- T ? Y(t(n)) : B
279
+ E,
280
+ A,
281
+ w ? Error("react-stack-top-frame") : X,
282
+ w ? V(t(s)) : H
280
283
  );
281
284
  };
282
- }()), C;
285
+ }()), D;
283
286
  }
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
+ var ee;
288
+ function ye() {
289
+ return ee || (ee = 1, process.env.NODE_ENV === "production" ? F.exports = Re() : F.exports = _e()), F.exports;
287
290
  }
288
- var xe = ve();
289
- let te = !1;
290
- const Le = (a) => {
291
- te = a;
292
- }, D = (...a) => {
293
- te && console.log(
291
+ var we = ye();
292
+ let se = !1;
293
+ const $e = (i) => {
294
+ se = i;
295
+ }, z = (...i) => {
296
+ se && console.log(
294
297
  "%c[react-shared-states]",
295
298
  "color: #007acc; font-weight: bold",
296
- ...a
299
+ ...i
297
300
  );
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 }) => {
301
+ }, j = (i) => {
302
+ if (!i) throw new Error("Value is empty");
303
+ return i;
304
+ }, ae = () => Math.random().toString(36).substring(2, 15), oe = be(void 0), Ve = ({ children: i, scopeName: e }) => {
302
305
  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 {
306
+ return e || (e = T(() => ae(), [])), /* @__PURE__ */ we.jsx(oe.Provider, { value: { scopeName: e }, children: i });
307
+ }, Te = () => xe(oe), te = [];
308
+ class d {
306
309
  data = /* @__PURE__ */ new Map();
307
310
  defaultValue() {
308
311
  return {};
309
312
  }
310
313
  addListener(e, r, t) {
311
- this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
312
- ...this.defaultValue,
314
+ this.data.has(d.prefix(e, r)) || this.data.set(d.prefix(e, r), {
315
+ ...this.defaultValue(),
313
316
  listeners: []
314
- }), this.data.get(u.prefix(e, r)).listeners.push(t);
317
+ }), this.data.get(d.prefix(e, r)).listeners.push(t);
315
318
  }
316
319
  removeListener(e, r, t) {
317
- this.data.has(u.prefix(e, r)) && (this.data.get(u.prefix(e, r)).listeners = this.data.get(u.prefix(e, r)).listeners.filter((s) => s !== t));
320
+ this.data.has(d.prefix(e, r)) && (this.data.get(d.prefix(e, r)).listeners = this.data.get(d.prefix(e, r)).listeners.filter((o) => o !== t));
318
321
  }
319
322
  callListeners(e, r) {
320
- this.data.has(u.prefix(e, r)) && this.data.get(u.prefix(e, r)).listeners.forEach((t) => t());
323
+ this.data.has(d.prefix(e, r)) && this.data.get(d.prefix(e, r)).listeners.forEach((t) => t());
321
324
  }
322
- init(e, r, t) {
323
- this.data.has(u.prefix(e, r)) || this.data.set(u.prefix(e, r), {
325
+ init(e, r, t, o = !1) {
326
+ this.data.has(d.prefix(e, r)) || this.data.set(d.prefix(e, r), {
324
327
  ...t,
328
+ isStatic: o,
325
329
  listeners: []
326
330
  });
327
331
  }
328
- clearAll(e = !1) {
329
- e || this.data.forEach((r) => {
330
- r.listeners.forEach((t) => t());
331
- }), this.data.clear();
332
+ createStatic(e, r) {
333
+ const t = r ?? r ?? "_global", o = {
334
+ key: ae(),
335
+ prefix: t,
336
+ ...e
337
+ };
338
+ return te.push(o), this.initStatic(o), o;
339
+ }
340
+ initStatic(e) {
341
+ const { key: r, prefix: t } = e;
342
+ this.init(r, t, this.defaultValue(), !0);
343
+ }
344
+ clearAll(e = !1, r = !1) {
345
+ this.data.forEach((t, o) => {
346
+ const [a, n] = d.extractPrefix(o);
347
+ this.clear(n, a, e, r);
348
+ });
332
349
  }
333
- clear(e, r, t = !1) {
334
- t || this.callListeners(e, r), this.data.delete(u.prefix(e, r));
350
+ clear(e, r, t = !1, o = !1) {
351
+ t || this.callListeners(e, r);
352
+ const a = this.data.get(d.prefix(e, r));
353
+ if (!a) return;
354
+ const n = { ...a };
355
+ if (this.data.delete(d.prefix(e, r)), n.isStatic && !o) {
356
+ const f = te.find((c) => c.key === e && c.prefix === r);
357
+ f && this.initStatic(f);
358
+ }
335
359
  }
336
360
  get(e, r) {
337
361
  let t = this.has(e, r);
@@ -339,13 +363,13 @@ class u {
339
363
  return this.data.get(t);
340
364
  }
341
365
  setValue(e, r, t) {
342
- this.data.has(u.prefix(e, r)) && this.data.set(u.prefix(e, r), {
343
- ...this.data.get(u.prefix(e, r)),
366
+ this.data.has(d.prefix(e, r)) && this.data.set(d.prefix(e, r), {
367
+ ...this.data.get(d.prefix(e, r)),
344
368
  ...t
345
369
  });
346
370
  }
347
371
  has(e, r) {
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;
372
+ return this.data.has(d.prefix(e, r)) ? d.prefix(e, r) : this.data.has(d.prefix(e, "_global")) ? d.prefix(e, "_global") : void 0;
349
373
  }
350
374
  static prefix(e, r) {
351
375
  if (e.includes("//")) throw new Error("key cannot contain '//'");
@@ -355,35 +379,34 @@ class u {
355
379
  return e.split("//");
356
380
  }
357
381
  useEffect(e, r, t = null) {
358
- ee(() => () => {
359
- t?.(), D(`[${u.prefix(e, r)}]`, "unmount effect"), this.data.get(u.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
382
+ ne(() => () => {
383
+ t?.(), z(`[${d.prefix(e, r)}]`, "unmount effect"), this.data.get(d.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
360
384
  }, []);
361
385
  }
362
386
  }
363
- class W {
387
+ class G {
364
388
  constructor(e) {
365
389
  this.sharedData = e;
366
390
  }
367
- /**
368
- * get a value from the shared data
369
- * @param key
370
- * @param scopeName
371
- */
372
391
  get(e, r) {
373
- e = R(e);
374
- const t = r || "_global";
375
- return this.sharedData.get(e, t);
392
+ let t, o = r;
393
+ if (typeof e != "string") {
394
+ const { key: f, prefix: c } = e;
395
+ t = f, o = c;
396
+ } else
397
+ t = j(e);
398
+ const a = o || "_global";
399
+ return this.sharedData.get(t, a);
376
400
  }
377
- /**
378
- * set a value in the shared data
379
- * @param key
380
- * @param value
381
- * @param scopeName
382
- */
383
401
  set(e, r, t) {
384
- e = R(e);
385
- const s = t || "_global";
386
- this.sharedData.setValue(e, s, r);
402
+ let o, a = t;
403
+ if (typeof e != "string") {
404
+ const { key: f, prefix: c } = e;
405
+ o = f, a = c;
406
+ } else
407
+ o = j(e);
408
+ const n = a || "_global";
409
+ this.sharedData.init(o, n, r), this.sharedData.setValue(o, n, r), this.sharedData.callListeners(o, n);
387
410
  }
388
411
  /**
389
412
  * clear all values from the shared data
@@ -397,10 +420,10 @@ class W {
397
420
  */
398
421
  clearScope(e) {
399
422
  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);
423
+ this.sharedData.data.forEach((t, o) => {
424
+ const [a, n] = d.extractPrefix(o);
425
+ if (a === r) {
426
+ this.sharedData.clear(n, a), this.sharedData.callListeners(n, a);
404
427
  return;
405
428
  }
406
429
  });
@@ -413,14 +436,9 @@ class W {
413
436
  const { key: r, prefix: t } = e;
414
437
  return this.get(r, t);
415
438
  }
416
- /**
417
- * clear a value from the shared data
418
- * @param key
419
- * @param scopeName
420
- */
421
439
  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);
440
+ let t, o;
441
+ typeof e == "string" ? (t = e, o = r || "_global") : (t = e.key, o = e.prefix), this.sharedData.clear(t, o);
424
442
  }
425
443
  /**
426
444
  * check if a value exists in the shared data
@@ -437,72 +455,144 @@ class W {
437
455
  getAll() {
438
456
  const e = {};
439
457
  return this.sharedData.data.forEach((r, t) => {
440
- const [s, f] = u.extractPrefix(t);
441
- e[s] = e[s] || {}, e[s][f] = r;
458
+ const [o, a] = d.extractPrefix(t);
459
+ e[o] = e[o] || {}, e[o][a] = r;
442
460
  }), e;
443
461
  }
444
462
  }
445
- const U = (a) => {
446
- const e = me();
463
+ const k = (i) => {
464
+ const e = Te();
447
465
  return {
448
- prefix: a ?? e?.scopeName ?? "_global"
466
+ prefix: i ?? e?.scopeName ?? "_global"
449
467
  };
450
468
  };
451
- class _e extends u {
469
+ var W, re;
470
+ function Ae() {
471
+ if (re) return W;
472
+ re = 1;
473
+ var i = typeof Element < "u", e = typeof Map == "function", r = typeof Set == "function", t = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
474
+ function o(a, n) {
475
+ if (a === n) return !0;
476
+ if (a && n && typeof a == "object" && typeof n == "object") {
477
+ if (a.constructor !== n.constructor) return !1;
478
+ var f, c, g;
479
+ if (Array.isArray(a)) {
480
+ if (f = a.length, f != n.length) return !1;
481
+ for (c = f; c-- !== 0; )
482
+ if (!o(a[c], n[c])) return !1;
483
+ return !0;
484
+ }
485
+ var p;
486
+ if (e && a instanceof Map && n instanceof Map) {
487
+ if (a.size !== n.size) return !1;
488
+ for (p = a.entries(); !(c = p.next()).done; )
489
+ if (!n.has(c.value[0])) return !1;
490
+ for (p = a.entries(); !(c = p.next()).done; )
491
+ if (!o(c.value[1], n.get(c.value[0]))) return !1;
492
+ return !0;
493
+ }
494
+ if (r && a instanceof Set && n instanceof Set) {
495
+ if (a.size !== n.size) return !1;
496
+ for (p = a.entries(); !(c = p.next()).done; )
497
+ if (!n.has(c.value[0])) return !1;
498
+ return !0;
499
+ }
500
+ if (t && ArrayBuffer.isView(a) && ArrayBuffer.isView(n)) {
501
+ if (f = a.length, f != n.length) return !1;
502
+ for (c = f; c-- !== 0; )
503
+ if (a[c] !== n[c]) return !1;
504
+ return !0;
505
+ }
506
+ if (a.constructor === RegExp) return a.source === n.source && a.flags === n.flags;
507
+ if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf == "function" && typeof n.valueOf == "function") return a.valueOf() === n.valueOf();
508
+ if (a.toString !== Object.prototype.toString && typeof a.toString == "function" && typeof n.toString == "function") return a.toString() === n.toString();
509
+ if (g = Object.keys(a), f = g.length, f !== Object.keys(n).length) return !1;
510
+ for (c = f; c-- !== 0; )
511
+ if (!Object.prototype.hasOwnProperty.call(n, g[c])) return !1;
512
+ if (i && a instanceof Element) return !1;
513
+ for (c = f; c-- !== 0; )
514
+ if (!((g[c] === "_owner" || g[c] === "__v" || g[c] === "__o") && a.$$typeof) && !o(a[g[c]], n[g[c]]))
515
+ return !1;
516
+ return !0;
517
+ }
518
+ return a !== a && n !== n;
519
+ }
520
+ return W = function(n, f) {
521
+ try {
522
+ return o(n, f);
523
+ } catch (c) {
524
+ if ((c.message || "").match(/stack|recursion/i))
525
+ return console.warn("react-fast-compare cannot handle circular refs"), !1;
526
+ throw c;
527
+ }
528
+ }, W;
529
+ }
530
+ var Oe = Ae();
531
+ const Pe = /* @__PURE__ */ me(Oe);
532
+ class Le extends d {
452
533
  defaultValue() {
453
534
  return { value: void 0 };
454
535
  }
455
- init(e, r, t) {
456
- super.init(e, r, { value: t });
457
- }
458
- setValue(e, r, t) {
459
- super.setValue(e, r, { value: t });
536
+ initValue(e, r, t, o = !1) {
537
+ super.init(e, r, { value: t }, o);
460
538
  }
461
- removeListener(e, r, t) {
462
- super.removeListener(e, r, t);
539
+ initStatic(e) {
540
+ const { key: r, prefix: t, initialValue: o } = e;
541
+ this.initValue(r, t, o, !0);
463
542
  }
464
543
  }
465
- class Re extends W {
544
+ class je extends G {
545
+ constructor(e) {
546
+ super(e);
547
+ }
466
548
  get(e, r = "_global") {
467
- e = R(e);
468
- const t = r || "_global";
469
- return m.get(e, t)?.value;
549
+ return typeof e != "string" ? super.get(e)?.value : super.get(e, r)?.value;
470
550
  }
471
551
  set(e, r, t = "_global") {
472
- e = R(e);
473
- const s = t || "_global";
474
- m.setValue(e, s, { value: r });
552
+ if (typeof e != "string") {
553
+ super.set(e, { value: r });
554
+ return;
555
+ }
556
+ super.set(e, { value: r }, t);
475
557
  }
476
558
  }
477
- const m = new _e(), Ve = new Re(m), Ce = (a, e) => {
478
- const r = e ?? e ?? "_global";
479
- return {
480
- key: N(),
481
- prefix: r,
482
- initialValue: a
483
- };
484
- };
485
- function ye(a, e, r) {
486
- let t, s, f = r;
487
- if (typeof a != "string") {
488
- const { key: c, initialValue: S, prefix: h } = a;
489
- t = c, s = S, f = h;
559
+ const _ = new Le(), Ye = new je(_), Ie = (i, e) => _.createStatic({ initialValue: i }, e);
560
+ function qe(i, e, r) {
561
+ let t, o, a = r;
562
+ if (typeof i != "string") {
563
+ const { key: l, initialValue: R, prefix: b } = i;
564
+ t = l, o = R, a = b;
490
565
  } 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));
566
+ t = j(i), o = e;
567
+ const { prefix: n } = k(a);
568
+ _.initValue(t, n, o);
569
+ const f = T(() => (l) => (_.initValue(t, n, e), _.addListener(t, n, l), () => {
570
+ _.removeListener(t, n, l);
571
+ }), []), c = T(() => () => _.get(t, n)?.value, []), g = N(f, c), p = (l) => {
572
+ const R = typeof l == "function" ? l(_.get(t, n)?.value) : l;
573
+ R !== g && (_.setValue(t, n, { value: R }), _.callListeners(t, n));
499
574
  };
500
- return m.useEffect(t, o), [
501
- w,
502
- A
575
+ return _.useEffect(t, n), [
576
+ g,
577
+ p
503
578
  ];
504
579
  }
505
- class Te extends u {
580
+ function We(i, e, r) {
581
+ let t, o = r;
582
+ if (typeof i != "string") {
583
+ const { key: p, prefix: l } = i;
584
+ t = p, o = l;
585
+ } else
586
+ t = j(i);
587
+ const { prefix: a } = k(o), n = Ee(void 0), f = T(() => (p) => (_.addListener(t, a, p), () => {
588
+ _.removeListener(t, a, p);
589
+ }), []), c = T(() => () => {
590
+ const p = _.get(t, a)?.value, l = e(p);
591
+ return Pe(n.current, l) ? n.current : l;
592
+ }, []), g = N(f, c);
593
+ return _.useEffect(t, a), g;
594
+ }
595
+ class Ce extends d {
506
596
  defaultValue() {
507
597
  return {
508
598
  fnState: {
@@ -512,77 +602,73 @@ class Te extends u {
512
602
  }
513
603
  };
514
604
  }
515
- init(e, r) {
516
- super.init(e, r, this.defaultValue());
605
+ initValue(e, r, t = !1) {
606
+ super.init(e, r, this.defaultValue(), t);
517
607
  }
518
608
  setValue(e, r, t) {
519
609
  super.setValue(e, r, t);
520
610
  }
521
611
  }
522
- class Ae extends W {
612
+ class De extends G {
613
+ constructor(e) {
614
+ super(e);
615
+ }
523
616
  get(e, r = "_global") {
524
- e = R(e);
525
- const t = r || "_global";
526
- return x.get(e, t)?.fnState;
617
+ return typeof e != "string" ? super.get(e)?.fnState : super.get(e, r)?.fnState;
527
618
  }
528
619
  set(e, r, t = "_global") {
529
- e = R(e);
530
- const s = t || "_global";
531
- x.setValue(e, s, r);
620
+ if (typeof e != "string") {
621
+ super.set(e, r);
622
+ return;
623
+ }
624
+ super.set(e, r, t);
532
625
  }
533
626
  }
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;
627
+ const y = new Ce(), ze = new De(y), Ge = (i, e) => y.createStatic({ fn: i }, e);
628
+ function Ue(i, e, r) {
629
+ let t, o, a = r;
630
+ if (typeof i != "string") {
631
+ const { key: l, fn: R, prefix: b } = i;
632
+ t = l, o = R, a = b;
547
633
  } 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);
634
+ t = j(i), o = e;
635
+ const { prefix: n } = k(a);
636
+ y.initValue(t, n);
637
+ const f = T(
638
+ () => (l) => (y.initValue(t, n), y.addListener(t, n, l), () => {
639
+ y.removeListener(t, n, l);
554
640
  }),
555
641
  []
556
- ), O = L(
557
- () => () => x.get(t, o).fnState,
642
+ ), c = T(
643
+ () => () => y.get(t, n).fnState,
558
644
  []
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());
645
+ ), g = N(f, c), p = async (l, ...R) => {
646
+ const b = y.get(t, n);
647
+ if (!l && (b.fnState.isLoading || b.fnState.results !== void 0)) return b.fnState;
648
+ b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, y.callListeners(t, n);
563
649
  try {
564
- const d = await s(...S);
565
- h.fnState = { results: d, isLoading: !1, error: void 0 };
566
- } catch (d) {
567
- h.fnState = { ...h.fnState, isLoading: !1, error: d };
650
+ const v = await o(...R);
651
+ b.fnState = { results: v, isLoading: !1, error: void 0 };
652
+ } catch (v) {
653
+ b.fnState = { ...b.fnState, isLoading: !1, error: v };
568
654
  }
569
- h.listeners.forEach((d) => d());
655
+ y.callListeners(t, n);
570
656
  };
571
- return x.useEffect(t, o), {
572
- state: w,
573
- trigger: (...c) => {
574
- A(!1, ...c);
657
+ return y.useEffect(t, n), {
658
+ state: g,
659
+ trigger: (...l) => {
660
+ p(!1, ...l);
575
661
  },
576
- forceTrigger: (...c) => {
577
- A(!0, ...c);
662
+ forceTrigger: (...l) => {
663
+ p(!0, ...l);
578
664
  },
579
665
  clear: () => {
580
- const c = x.get(t, o);
581
- c && (c.fnState = x.defaultValue().fnState, x.callListeners(t, o));
666
+ const l = y.get(t, n);
667
+ l && (l.fnState = y.defaultValue().fnState, y.callListeners(t, n));
582
668
  }
583
669
  };
584
670
  }
585
- class we extends u {
671
+ class Fe extends d {
586
672
  defaultValue() {
587
673
  return {
588
674
  fnState: {
@@ -593,15 +679,15 @@ class we extends u {
593
679
  }
594
680
  };
595
681
  }
596
- init(e, r) {
597
- super.init(e, r, this.defaultValue());
682
+ initValue(e, r, t = !1) {
683
+ super.init(e, r, this.defaultValue(), t);
598
684
  }
599
685
  setValue(e, r, t) {
600
686
  super.setValue(e, r, t);
601
687
  }
602
688
  useEffect(e, r) {
603
- ee(() => () => {
604
- D(`[${u.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
689
+ ne(() => () => {
690
+ z(`[${d.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
605
691
  }, []), super.useEffect(e, r);
606
692
  }
607
693
  async unsubscribe(e, r) {
@@ -609,90 +695,89 @@ class we extends u {
609
695
  t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState = { ...t.fnState, subscribed: !1 }, this.callListeners(e, r));
610
696
  }
611
697
  }
612
- class Pe extends W {
698
+ class Ne extends G {
699
+ constructor(e) {
700
+ super(e);
701
+ }
613
702
  get(e, r = "_global") {
614
- e = R(e);
615
- const t = r || "_global";
616
- return E.get(e, t)?.fnState;
703
+ return typeof e != "string" ? super.get(e)?.fnState : super.get(e, r)?.fnState;
617
704
  }
618
705
  set(e, r, t = "_global") {
619
- e = R(e);
620
- const s = t || "_global";
621
- E.setValue(e, s, r);
706
+ if (typeof e != "string") {
707
+ super.set(e, r);
708
+ return;
709
+ }
710
+ super.set(e, r, t);
622
711
  }
623
712
  }
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;
713
+ const S = new Fe(), Be = new Ne(S), Je = (i, e) => S.createStatic({ subscriber: i }, e);
714
+ function Me(i, e, r) {
715
+ let t, o, a = r;
716
+ if (typeof i != "string") {
717
+ const { key: v, subscriber: x, prefix: O } = i;
718
+ t = v, o = x, a = O;
637
719
  } 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);
720
+ t = j(i), o = e;
721
+ const { prefix: n } = k(a);
722
+ S.initValue(t, n);
723
+ const f = T(
724
+ () => (v) => (S.initValue(t, n), S.addListener(t, n, v), () => {
725
+ S.removeListener(t, n, v);
644
726
  }),
645
727
  []
646
- ), O = L(
647
- () => () => E.get(t, o).fnState,
728
+ ), c = T(
729
+ () => () => S.get(t, n).fnState,
648
730
  []
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());
731
+ ), g = N(f, c), p = (v) => {
732
+ const x = S.get(t, n);
733
+ x.fnState = { ...x.fnState, data: v }, S.callListeners(t, n);
734
+ }, l = (v) => {
735
+ const x = S.get(t, n);
736
+ x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: v }, S.callListeners(t, n);
737
+ }, R = () => {
738
+ const v = S.get(t, n);
739
+ v.fnState = { ...v.fnState, isLoading: !1 }, S.callListeners(t, n);
740
+ }, b = async (v) => {
741
+ const x = S.get(t, n);
742
+ if (v && (await S.unsubscribe(t, n), x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), x.fnState.subscribed) return x.fnState;
743
+ z("triggered !!"), x.fnState = { ...x.fnState, isLoading: !0, error: void 0 }, S.callListeners(t, n);
662
744
  try {
663
- l.unsubscribe = await s(A, c, S), l.fnState.subscribed = !0;
664
- } catch (v) {
665
- l.fnState = { ...l.fnState, isLoading: !1, error: v };
745
+ const O = await o(p, l, R), P = S.get(t, n);
746
+ P.unsubscribe = O, P.fnState.subscribed = !0;
747
+ } catch (O) {
748
+ const P = S.get(t, n);
749
+ P.fnState = { ...P.fnState, isLoading: !1, error: O };
666
750
  }
667
- l.listeners.forEach((v) => v());
751
+ S.callListeners(t, n);
668
752
  };
669
- return E.useEffect(t, o), {
670
- state: w,
753
+ return S.useEffect(t, n), {
754
+ state: g,
671
755
  trigger: () => {
672
- h(!1);
756
+ b(!1);
673
757
  },
674
758
  forceTrigger: () => {
675
- h(!0);
759
+ b(!0);
676
760
  },
677
761
  unsubscribe: () => {
678
- E.unsubscribe(t, o);
762
+ S.unsubscribe(t, n);
679
763
  }
680
764
  };
681
765
  }
682
766
  export {
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,
767
+ De as SharedFunctionsApi,
768
+ je as SharedStatesApi,
769
+ Ve as SharedStatesProvider,
770
+ Ne as SharedSubscriptionsApi,
771
+ Ge as createSharedFunction,
772
+ Ie as createSharedState,
773
+ Je as createSharedSubscription,
774
+ se as isDevMode,
775
+ $e as setDevMode,
776
+ ze as sharedFunctionsApi,
777
+ Ye as sharedStatesApi,
778
+ Be as sharedSubscriptionsApi,
779
+ Ue as useSharedFunction,
780
+ qe as useSharedState,
781
+ We as useSharedStateSelector,
697
782
  Me as useSharedSubscription
698
783
  };