react-shared-states 1.0.11 → 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.11
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 Se, useMemo as L, useContext as ge, useEffect as te, useSyncExternalStore as V } from "react";
9
- var k = { exports: {} }, j = {};
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 k = { exports: {} }, j = {};
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 M;
20
- function xe() {
21
- if (M) return j;
22
- M = 1;
22
+ var Q;
23
+ function Re() {
24
+ if (Q) return C;
25
+ Q = 1;
23
26
  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, {
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, {
32
35
  $$typeof: i,
33
36
  type: t,
34
- key: a,
35
- ref: n !== void 0 ? n : null,
36
- props: c
37
+ key: n,
38
+ ref: o !== void 0 ? o : null,
39
+ props: a
37
40
  };
38
41
  }
39
- return j.Fragment = e, j.jsx = r, j.jsxs = r, j;
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,47 +51,47 @@ 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 ve() {
53
- return Q || (Q = 1, process.env.NODE_ENV !== "production" && function() {
54
+ var K;
55
+ function _e() {
56
+ return K || (K = 1, process.env.NODE_ENV !== "production" && function() {
54
57
  function i(s) {
55
58
  if (s == null) return null;
56
59
  if (typeof s == "function")
57
- return s.$$typeof === de ? null : s.displayName || s.name || null;
60
+ return s.$$typeof === he ? null : s.displayName || s.name || null;
58
61
  if (typeof s == "string") return s;
59
62
  switch (s) {
60
- case S:
63
+ case x:
61
64
  return "Fragment";
62
- case y:
63
- return "Profiler";
64
65
  case P:
66
+ return "Profiler";
67
+ case O:
65
68
  return "StrictMode";
66
- case ce:
69
+ case fe:
67
70
  return "Suspense";
68
- case ue:
71
+ case le:
69
72
  return "SuspenseList";
70
- case fe:
73
+ case pe:
71
74
  return "Activity";
72
75
  }
73
76
  if (typeof s == "object")
74
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
79
  ), s.$$typeof) {
77
- case p:
80
+ case v:
78
81
  return "Portal";
79
- case ie:
82
+ case ce:
80
83
  return (s.displayName || "Context") + ".Provider";
81
- case ae:
84
+ case ie:
82
85
  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;
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 i(s(o));
94
+ return i(s(u));
92
95
  } catch {
93
96
  }
94
97
  }
@@ -100,73 +103,73 @@ function ve() {
100
103
  function r(s) {
101
104
  try {
102
105
  e(s);
103
- var o = !1;
106
+ var u = !1;
104
107
  } catch {
105
- o = !0;
108
+ u = !0;
106
109
  }
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,
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
116
+ E
114
117
  ), e(s);
115
118
  }
116
119
  }
117
120
  function t(s) {
118
- if (s === S) return "<>";
119
- if (typeof s == "object" && s !== null && s.$$typeof === q)
121
+ if (s === x) return "<>";
122
+ if (typeof s == "object" && s !== null && s.$$typeof === U)
120
123
  return "<...>";
121
124
  try {
122
- var o = i(s);
123
- return o ? "<" + o + ">" : "<...>";
125
+ var u = i(s);
126
+ return u ? "<" + u + ">" : "<...>";
124
127
  } catch {
125
128
  return "<...>";
126
129
  }
127
130
  }
128
- function n() {
129
- var s = N.A;
131
+ function o() {
132
+ var s = $.A;
130
133
  return s === null ? null : s.getOwner();
131
134
  }
132
- function c() {
135
+ function a() {
133
136
  return Error("react-stack-top-frame");
134
137
  }
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;
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
143
  return s.key !== void 0;
141
144
  }
142
- function b(s, o) {
143
- function f() {
144
- z || (z = !0, console.error(
145
+ function f(s, u) {
146
+ function h() {
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
- o
149
+ u
147
150
  ));
148
151
  }
149
- f.isReactWarning = !0, Object.defineProperty(s, "key", {
150
- get: f,
152
+ h.isReactWarning = !0, Object.defineProperty(s, "key", {
153
+ get: h,
151
154
  configurable: !0
152
155
  });
153
156
  }
154
- function E() {
157
+ function c() {
155
158
  var s = i(this.type);
156
- return X[s] || (X[s] = !0, console.error(
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
161
  )), s = this.props.ref, s !== void 0 ? s : null;
159
162
  }
160
- function A(s, o, f, g, w, _, Y, $) {
161
- return f = _.ref, s = {
162
- $$typeof: h,
163
+ function g(s, u, h, E, A, w, Y, I) {
164
+ return h = w.ref, s = {
165
+ $$typeof: b,
163
166
  type: s,
164
- key: o,
165
- props: _,
166
- _owner: w
167
- }, (f !== void 0 ? f : null) !== null ? Object.defineProperty(s, "ref", {
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: E
172
+ get: c
170
173
  }) : Object.defineProperty(s, "ref", { enumerable: !1, value: null }), s._store = {}, Object.defineProperty(s._store, "validated", {
171
174
  configurable: !1,
172
175
  enumerable: !1,
@@ -186,172 +189,172 @@ function ve() {
186
189
  configurable: !1,
187
190
  enumerable: !1,
188
191
  writable: !0,
189
- value: $
192
+ value: I
190
193
  }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
191
194
  }
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);
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 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";
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 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", Z[x + g] || (O = 0 < O.length ? "{" + O.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
- x,
219
- O,
220
- x
221
- ), Z[x + g] = !0);
220
+ E,
221
+ m,
222
+ L,
223
+ m
224
+ ), Z[m + E] = !0);
222
225
  }
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,
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,
230
233
  typeof s == "function" ? s.displayName || s.name || "Unknown" : s
231
- ), A(
234
+ ), g(
232
235
  s,
233
- x,
234
- _,
236
+ m,
235
237
  w,
236
- n(),
237
- f,
238
+ A,
239
+ o(),
240
+ h,
238
241
  Y,
239
- $
242
+ I
240
243
  );
241
244
  }
242
245
  function l(s) {
243
- typeof s == "object" && s !== null && s.$$typeof === h && s._store && (s._store.validated = 1);
246
+ typeof s == "object" && s !== null && s.$$typeof === b && s._store && (s._store.validated = 1);
244
247
  }
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() {
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
- v = {
251
+ R = {
249
252
  react_stack_bottom_frame: function(s) {
250
253
  return s();
251
254
  }
252
255
  };
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(
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(
260
263
  s,
261
- o,
262
- f,
264
+ u,
265
+ h,
263
266
  !1,
264
- g,
265
- w,
266
- _ ? Error("react-stack-top-frame") : B,
267
- _ ? F(t(s)) : H
267
+ E,
268
+ A,
269
+ w ? Error("react-stack-top-frame") : X,
270
+ w ? V(t(s)) : H
268
271
  );
269
- }, C.jsxs = function(s, o, f, g, w) {
270
- var _ = 1e4 > N.recentlyCreatedOwnerStacks++;
271
- return T(
272
+ }, D.jsxs = function(s, u, h, E, A) {
273
+ var w = 1e4 > $.recentlyCreatedOwnerStacks++;
274
+ return p(
272
275
  s,
273
- o,
274
- f,
276
+ u,
277
+ h,
275
278
  !0,
276
- g,
277
- w,
278
- _ ? Error("react-stack-top-frame") : B,
279
- _ ? F(t(s)) : H
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 Ee() {
286
- return K || (K = 1, process.env.NODE_ENV === "production" ? k.exports = xe() : k.exports = ve()), k.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 me = Ee();
289
- let re = !1;
290
- const Oe = (i) => {
291
- re = i;
292
- }, W = (...i) => {
293
- re && 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
299
  ...i
297
300
  );
298
- }, D = (i) => {
301
+ }, j = (i) => {
299
302
  if (!i) throw new Error("Value is empty");
300
303
  return i;
301
- }, se = () => Math.random().toString(36).substring(2, 15), ne = Se(void 0), je = ({ children: i, scopeName: e }) => {
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(() => se(), [])), /* @__PURE__ */ me.jsx(ne.Provider, { value: { scopeName: e }, children: i });
304
- }, Re = () => ge(ne), ee = [];
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), {
314
+ this.data.has(d.prefix(e, r)) || this.data.set(d.prefix(e, r), {
312
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((n) => n !== 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, n = !1) {
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,
325
- isStatic: n,
328
+ isStatic: o,
326
329
  listeners: []
327
330
  });
328
331
  }
329
332
  createStatic(e, r) {
330
- const t = r ?? r ?? "_global", n = {
331
- key: se(),
333
+ const t = r ?? r ?? "_global", o = {
334
+ key: ae(),
332
335
  prefix: t,
333
336
  ...e
334
337
  };
335
- return ee.push(n), this.initStatic(n), n;
338
+ return te.push(o), this.initStatic(o), o;
336
339
  }
337
340
  initStatic(e) {
338
341
  const { key: r, prefix: t } = e;
339
342
  this.init(r, t, this.defaultValue(), !0);
340
343
  }
341
344
  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
+ this.data.forEach((t, o) => {
346
+ const [a, n] = d.extractPrefix(o);
347
+ this.clear(n, a, e, r);
345
348
  });
346
349
  }
347
- clear(e, r, t = !1, n = !1) {
350
+ clear(e, r, t = !1, o = !1) {
348
351
  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);
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);
355
358
  }
356
359
  }
357
360
  get(e, r) {
@@ -360,13 +363,13 @@ class u {
360
363
  return this.data.get(t);
361
364
  }
362
365
  setValue(e, r, t) {
363
- this.data.has(u.prefix(e, r)) && this.data.set(u.prefix(e, r), {
364
- ...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)),
365
368
  ...t
366
369
  });
367
370
  }
368
371
  has(e, r) {
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;
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;
370
373
  }
371
374
  static prefix(e, r) {
372
375
  if (e.includes("//")) throw new Error("key cannot contain '//'");
@@ -376,34 +379,34 @@ class u {
376
379
  return e.split("//");
377
380
  }
378
381
  useEffect(e, r, t = null) {
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);
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);
381
384
  }, []);
382
385
  }
383
386
  }
384
- class U {
387
+ class G {
385
388
  constructor(e) {
386
389
  this.sharedData = e;
387
390
  }
388
391
  get(e, r) {
389
- let t, n = r;
392
+ let t, o = r;
390
393
  if (typeof e != "string") {
391
- const { key: b, prefix: E } = e;
392
- t = b, n = E;
394
+ const { key: f, prefix: c } = e;
395
+ t = f, o = c;
393
396
  } else
394
- t = D(e);
395
- const c = n || "_global";
396
- return this.sharedData.get(t, c);
397
+ t = j(e);
398
+ const a = o || "_global";
399
+ return this.sharedData.get(t, a);
397
400
  }
398
401
  set(e, r, t) {
399
- let n, c = t;
402
+ let o, a = t;
400
403
  if (typeof e != "string") {
401
- const { key: b, prefix: E } = e;
402
- n = b, c = E;
404
+ const { key: f, prefix: c } = e;
405
+ o = f, a = c;
403
406
  } else
404
- n = D(e);
405
- const a = c || "_global";
406
- this.sharedData.setValue(n, a, r);
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);
407
410
  }
408
411
  /**
409
412
  * clear all values from the shared data
@@ -417,10 +420,10 @@ class U {
417
420
  */
418
421
  clearScope(e) {
419
422
  const r = e || "_global";
420
- this.sharedData.data.forEach((t, n) => {
421
- const [c, a] = u.extractPrefix(n);
422
- if (c === r) {
423
- this.sharedData.clear(a, c);
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);
424
427
  return;
425
428
  }
426
429
  });
@@ -434,8 +437,8 @@ class U {
434
437
  return this.get(r, t);
435
438
  }
436
439
  clear(e, r) {
437
- let t, n;
438
- typeof e == "string" ? (t = e, n = r || "_global") : (t = e.key, n = e.prefix), this.sharedData.clear(t, n);
440
+ let t, o;
441
+ typeof e == "string" ? (t = e, o = r || "_global") : (t = e.key, o = e.prefix), this.sharedData.clear(t, o);
439
442
  }
440
443
  /**
441
444
  * check if a value exists in the shared data
@@ -452,30 +455,93 @@ class U {
452
455
  getAll() {
453
456
  const e = {};
454
457
  return this.sharedData.data.forEach((r, t) => {
455
- const [n, c] = u.extractPrefix(t);
456
- e[n] = e[n] || {}, e[n][c] = r;
458
+ const [o, a] = d.extractPrefix(t);
459
+ e[o] = e[o] || {}, e[o][a] = r;
457
460
  }), e;
458
461
  }
459
462
  }
460
- const G = (i) => {
461
- const e = Re();
463
+ const k = (i) => {
464
+ const e = Te();
462
465
  return {
463
466
  prefix: i ?? e?.scopeName ?? "_global"
464
467
  };
465
468
  };
466
- 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 {
467
533
  defaultValue() {
468
534
  return { value: void 0 };
469
535
  }
470
- initValue(e, r, t, n = !1) {
471
- super.init(e, r, { value: t }, n);
536
+ initValue(e, r, t, o = !1) {
537
+ super.init(e, r, { value: t }, o);
472
538
  }
473
539
  initStatic(e) {
474
- const { key: r, prefix: t, initialValue: n } = e;
475
- this.initValue(r, t, n, !0);
540
+ const { key: r, prefix: t, initialValue: o } = e;
541
+ this.initValue(r, t, o, !0);
476
542
  }
477
543
  }
478
- class Te extends U {
544
+ class je extends G {
479
545
  constructor(e) {
480
546
  super(e);
481
547
  }
@@ -490,28 +556,43 @@ class Te extends U {
490
556
  super.set(e, { value: r }, t);
491
557
  }
492
558
  }
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;
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;
496
562
  if (typeof i != "string") {
497
- const { key: l, initialValue: v, prefix: h } = i;
498
- t = l, n = v, c = h;
563
+ const { key: l, initialValue: R, prefix: b } = i;
564
+ t = l, o = R, a = b;
499
565
  } 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));
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));
508
574
  };
509
- return R.useEffect(t, a), [
510
- A,
511
- T
575
+ return _.useEffect(t, n), [
576
+ g,
577
+ p
512
578
  ];
513
579
  }
514
- class Ae 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 {
515
596
  defaultValue() {
516
597
  return {
517
598
  fnState: {
@@ -528,7 +609,7 @@ class Ae extends u {
528
609
  super.setValue(e, r, t);
529
610
  }
530
611
  }
531
- class we extends U {
612
+ class De extends G {
532
613
  constructor(e) {
533
614
  super(e);
534
615
  }
@@ -543,51 +624,51 @@ class we extends U {
543
624
  super.set(e, r, t);
544
625
  }
545
626
  }
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;
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;
549
630
  if (typeof i != "string") {
550
- const { key: l, fn: v, prefix: h } = i;
551
- t = l, n = v, c = h;
631
+ const { key: l, fn: R, prefix: b } = i;
632
+ t = l, o = R, a = b;
552
633
  } 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);
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);
559
640
  }),
560
641
  []
561
- ), E = L(
562
- () => () => m.get(t, a).fnState,
642
+ ), c = T(
643
+ () => () => y.get(t, n).fnState,
563
644
  []
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);
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);
568
649
  try {
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 };
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 };
573
654
  }
574
- m.callListeners(t, a);
655
+ y.callListeners(t, n);
575
656
  };
576
- return m.useEffect(t, a), {
577
- state: A,
657
+ return y.useEffect(t, n), {
658
+ state: g,
578
659
  trigger: (...l) => {
579
- T(!1, ...l);
660
+ p(!1, ...l);
580
661
  },
581
662
  forceTrigger: (...l) => {
582
- T(!0, ...l);
663
+ p(!0, ...l);
583
664
  },
584
665
  clear: () => {
585
- const l = m.get(t, a);
586
- l && (l.fnState = m.defaultValue().fnState, m.callListeners(t, a));
666
+ const l = y.get(t, n);
667
+ l && (l.fnState = y.defaultValue().fnState, y.callListeners(t, n));
587
668
  }
588
669
  };
589
670
  }
590
- class Pe extends u {
671
+ class Fe extends d {
591
672
  defaultValue() {
592
673
  return {
593
674
  fnState: {
@@ -605,8 +686,8 @@ class Pe extends u {
605
686
  super.setValue(e, r, t);
606
687
  }
607
688
  useEffect(e, r) {
608
- te(() => () => {
609
- W(`[${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);
610
691
  }, []), super.useEffect(e, r);
611
692
  }
612
693
  async unsubscribe(e, r) {
@@ -614,7 +695,7 @@ class Pe extends u {
614
695
  t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState = { ...t.fnState, subscribed: !1 }, this.callListeners(e, r));
615
696
  }
616
697
  }
617
- class ye extends U {
698
+ class Ne extends G {
618
699
  constructor(e) {
619
700
  super(e);
620
701
  }
@@ -629,73 +710,74 @@ class ye extends U {
629
710
  super.set(e, r, t);
630
711
  }
631
712
  }
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;
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;
635
716
  if (typeof i != "string") {
636
- const { key: p, subscriber: S, prefix: P } = i;
637
- t = p, n = S, c = P;
717
+ const { key: v, subscriber: x, prefix: O } = i;
718
+ t = v, o = x, a = O;
638
719
  } 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);
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);
645
726
  }),
646
727
  []
647
- ), E = L(
648
- () => () => d.get(t, a).fnState,
728
+ ), c = T(
729
+ () => () => S.get(t, n).fnState,
649
730
  []
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);
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);
663
744
  try {
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 };
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 };
669
750
  }
670
- d.callListeners(t, a);
751
+ S.callListeners(t, n);
671
752
  };
672
- return d.useEffect(t, a), {
673
- state: A,
753
+ return S.useEffect(t, n), {
754
+ state: g,
674
755
  trigger: () => {
675
- h(!1);
756
+ b(!1);
676
757
  },
677
758
  forceTrigger: () => {
678
- h(!0);
759
+ b(!0);
679
760
  },
680
761
  unsubscribe: () => {
681
- d.unsubscribe(t, a);
762
+ S.unsubscribe(t, n);
682
763
  }
683
764
  };
684
765
  }
685
766
  export {
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,
695
- Ne as sharedFunctionsApi,
696
- Ce as sharedStatesApi,
697
- $e as sharedSubscriptionsApi,
698
- Ye as useSharedFunction,
699
- ke as useSharedState,
700
- Ve as useSharedSubscription
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,
782
+ Me as useSharedSubscription
701
783
  };