react-shared-states 1.0.15 → 1.0.17

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.
@@ -78,5 +78,5 @@ export declare class SharedValuesApi<T extends SharedValue, V, R = T> {
78
78
  * get all values from the shared data
79
79
  */
80
80
  getAll(): Record<string, Record<string, any>>;
81
- subscribe<S extends string = string>(sharedCreated: SharedCreated, listener: AFunction): void;
81
+ subscribe<S extends string = string>(sharedCreated: SharedCreated, listener: AFunction): () => void;
82
82
  }
@@ -4,3 +4,4 @@ export { useSharedFunction, sharedFunctionsApi, createSharedFunction, SharedFunc
4
4
  export type { SharedFunctionStateReturn } from './use-shared-function';
5
5
  export { useSharedSubscription, sharedSubscriptionsApi, createSharedSubscription, SharedSubscriptionsApi } from './use-shared-subscription';
6
6
  export type { SharedSubscriptionStateReturn } from './use-shared-subscription';
7
+ export { default as useSharedContext } from './use-shared';
package/dist/main.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * react-shared-states v1.0.15
2
+ * react-shared-states v1.0.17
3
3
  * (c) Hichem Taboukouyout
4
4
  * Released under the MIT License.
5
5
  * Github: github.com/HichemTab-tech/react-shared-states
@@ -9,7 +9,7 @@ import ve, { createContext as be, useMemo as A, useContext as xe, useEffect as s
9
9
  function me(o) {
10
10
  return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
11
11
  }
12
- var F = { exports: {} }, D = {};
12
+ var F = { exports: {} }, C = {};
13
13
  /**
14
14
  * @license React
15
15
  * react-jsx-runtime.production.js
@@ -21,7 +21,7 @@ var F = { exports: {} }, D = {};
21
21
  */
22
22
  var Q;
23
23
  function _e() {
24
- if (Q) return D;
24
+ if (Q) return C;
25
25
  Q = 1;
26
26
  var o = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
27
27
  function r(t, i, n) {
@@ -39,9 +39,9 @@ function _e() {
39
39
  props: n
40
40
  };
41
41
  }
42
- return D.Fragment = e, D.jsx = r, D.jsxs = r, D;
42
+ return C.Fragment = e, C.jsx = r, C.jsxs = r, C;
43
43
  }
44
- var C = {};
44
+ var D = {};
45
45
  /**
46
46
  * @license React
47
47
  * react-jsx-runtime.development.js
@@ -79,19 +79,19 @@ function Re() {
79
79
  ), a.$$typeof) {
80
80
  case v:
81
81
  return "Portal";
82
- case ce:
82
+ case ue:
83
83
  return (a.displayName || "Context") + ".Provider";
84
84
  case oe:
85
85
  return (a._context.displayName || "Context") + ".Consumer";
86
- case ue:
87
- var u = a.render;
88
- return a = a.displayName, a || (a = u.displayName || u.name || "", a = a !== "" ? "ForwardRef(" + a + ")" : "ForwardRef"), a;
86
+ case ce:
87
+ var c = a.render;
88
+ return a = a.displayName, a || (a = c.displayName || c.name || "", a = a !== "" ? "ForwardRef(" + a + ")" : "ForwardRef"), a;
89
89
  case de:
90
- return u = a.displayName || null, u !== null ? u : o(a.type) || "Memo";
90
+ return c = a.displayName || null, c !== null ? c : o(a.type) || "Memo";
91
91
  case B:
92
- u = a._payload, a = a._init;
92
+ c = a._payload, a = a._init;
93
93
  try {
94
- return o(a(u));
94
+ return o(a(c));
95
95
  } catch {
96
96
  }
97
97
  }
@@ -103,15 +103,15 @@ function Re() {
103
103
  function r(a) {
104
104
  try {
105
105
  e(a);
106
- var u = !1;
106
+ var c = !1;
107
107
  } catch {
108
- u = !0;
108
+ c = !0;
109
109
  }
110
- if (u) {
111
- u = console;
112
- var h = u.error, E = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
110
+ if (c) {
111
+ c = console;
112
+ var h = c.error, E = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
113
113
  return h.call(
114
- u,
114
+ c,
115
115
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
116
116
  E
117
117
  ), e(a);
@@ -122,8 +122,8 @@ function Re() {
122
122
  if (typeof a == "object" && a !== null && a.$$typeof === B)
123
123
  return "<...>";
124
124
  try {
125
- var u = o(a);
126
- return u ? "<" + u + ">" : "<...>";
125
+ var c = o(a);
126
+ return c ? "<" + c + ">" : "<...>";
127
127
  } catch {
128
128
  return "<...>";
129
129
  }
@@ -137,16 +137,16 @@ function Re() {
137
137
  }
138
138
  function s(a) {
139
139
  if (J.call(a, "key")) {
140
- var u = Object.getOwnPropertyDescriptor(a, "key").get;
141
- if (u && u.isReactWarning) return !1;
140
+ var c = Object.getOwnPropertyDescriptor(a, "key").get;
141
+ if (c && c.isReactWarning) return !1;
142
142
  }
143
143
  return a.key !== void 0;
144
144
  }
145
- function f(a, u) {
145
+ function f(a, c) {
146
146
  function h() {
147
147
  M || (M = !0, console.error(
148
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)",
149
- u
149
+ c
150
150
  ));
151
151
  }
152
152
  h.isReactWarning = !0, Object.defineProperty(a, "key", {
@@ -154,22 +154,22 @@ function Re() {
154
154
  configurable: !0
155
155
  });
156
156
  }
157
- function c() {
157
+ function u() {
158
158
  var a = o(this.type);
159
159
  return X[a] || (X[a] = !0, console.error(
160
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."
161
161
  )), a = this.props.ref, a !== void 0 ? a : null;
162
162
  }
163
- function S(a, u, h, E, y, T, I, q) {
163
+ function S(a, c, h, E, y, T, I, q) {
164
164
  return h = T.ref, a = {
165
165
  $$typeof: b,
166
166
  type: a,
167
- key: u,
167
+ key: c,
168
168
  props: T,
169
169
  _owner: y
170
170
  }, (h !== void 0 ? h : null) !== null ? Object.defineProperty(a, "ref", {
171
171
  enumerable: !1,
172
- get: c
172
+ get: u
173
173
  }) : Object.defineProperty(a, "ref", { enumerable: !1, value: null }), a._store = {}, Object.defineProperty(a._store, "validated", {
174
174
  configurable: !1,
175
175
  enumerable: !1,
@@ -192,8 +192,8 @@ function Re() {
192
192
  value: q
193
193
  }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
194
194
  }
195
- function p(a, u, h, E, y, T, I, q) {
196
- var m = u.children;
195
+ function p(a, c, h, E, y, T, I, q) {
196
+ var m = c.children;
197
197
  if (m !== void 0)
198
198
  if (E)
199
199
  if (ge(m)) {
@@ -205,9 +205,9 @@ function Re() {
205
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."
206
206
  );
207
207
  else l(m);
208
- if (J.call(u, "key")) {
208
+ if (J.call(c, "key")) {
209
209
  m = o(a);
210
- var P = Object.keys(u).filter(function(Se) {
210
+ var P = Object.keys(c).filter(function(Se) {
211
211
  return Se !== "key";
212
212
  });
213
213
  E = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", k[m + E] || (P = 0 < P.length ? "{" + P.join(": ..., ") + ": ...}" : "{}", console.error(
@@ -223,11 +223,11 @@ React keys must be passed directly to JSX without using spread:
223
223
  m
224
224
  ), k[m + E] = !0);
225
225
  }
226
- if (m = null, h !== void 0 && (r(h), m = "" + h), s(u) && (r(u.key), m = "" + u.key), "key" in u) {
226
+ if (m = null, h !== void 0 && (r(h), m = "" + h), s(c) && (r(c.key), m = "" + c.key), "key" in c) {
227
227
  h = {};
228
- for (var W in u)
229
- W !== "key" && (h[W] = u[W]);
230
- } else h = u;
228
+ for (var W in c)
229
+ W !== "key" && (h[W] = c[W]);
230
+ } else h = c;
231
231
  return m && f(
232
232
  h,
233
233
  typeof a == "function" ? a.displayName || a.name || "Unknown" : a
@@ -245,7 +245,7 @@ React keys must be passed directly to JSX without using spread:
245
245
  function l(a) {
246
246
  typeof a == "object" && a !== null && a.$$typeof === b && a._store && (a._store.validated = 1);
247
247
  }
248
- var _ = ve, b = Symbol.for("react.transitional.element"), v = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), L = Symbol.for("react.profiler"), oe = 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"), B = Symbol.for("react.lazy"), pe = Symbol.for("react.activity"), he = Symbol.for("react.client.reference"), $ = _.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, ge = Array.isArray, Y = console.createTask ? console.createTask : function() {
248
+ var _ = ve, b = Symbol.for("react.transitional.element"), v = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), L = Symbol.for("react.profiler"), oe = Symbol.for("react.consumer"), ue = Symbol.for("react.context"), ce = Symbol.for("react.forward_ref"), fe = Symbol.for("react.suspense"), le = Symbol.for("react.suspense_list"), de = Symbol.for("react.memo"), B = Symbol.for("react.lazy"), pe = Symbol.for("react.activity"), he = Symbol.for("react.client.reference"), $ = _.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, ge = Array.isArray, Y = console.createTask ? console.createTask : function() {
249
249
  return null;
250
250
  };
251
251
  _ = {
@@ -257,11 +257,11 @@ React keys must be passed directly to JSX without using spread:
257
257
  _,
258
258
  n
259
259
  )(), Z = Y(t(n)), k = {};
260
- C.Fragment = x, C.jsx = function(a, u, h, E, y) {
260
+ D.Fragment = x, D.jsx = function(a, c, h, E, y) {
261
261
  var T = 1e4 > $.recentlyCreatedOwnerStacks++;
262
262
  return p(
263
263
  a,
264
- u,
264
+ c,
265
265
  h,
266
266
  !1,
267
267
  E,
@@ -269,11 +269,11 @@ React keys must be passed directly to JSX without using spread:
269
269
  T ? Error("react-stack-top-frame") : H,
270
270
  T ? Y(t(a)) : Z
271
271
  );
272
- }, C.jsxs = function(a, u, h, E, y) {
272
+ }, D.jsxs = function(a, c, h, E, y) {
273
273
  var T = 1e4 > $.recentlyCreatedOwnerStacks++;
274
274
  return p(
275
275
  a,
276
- u,
276
+ c,
277
277
  h,
278
278
  !0,
279
279
  E,
@@ -282,7 +282,7 @@ React keys must be passed directly to JSX without using spread:
282
282
  T ? Y(t(a)) : Z
283
283
  );
284
284
  };
285
- })()), C;
285
+ })()), D;
286
286
  }
287
287
  var ee;
288
288
  function we() {
@@ -353,7 +353,7 @@ class d {
353
353
  if (!n) return;
354
354
  const s = { ...n };
355
355
  if (this.data.delete(d.prefix(e, r)), s.isStatic && !i) {
356
- const f = te.find((c) => c.key === e && c.prefix === r);
356
+ const f = te.find((u) => u.key === e && u.prefix === r);
357
357
  f && this.initStatic(f);
358
358
  }
359
359
  }
@@ -391,8 +391,8 @@ class U {
391
391
  get(e, r) {
392
392
  let t, i = r;
393
393
  if (typeof e != "string") {
394
- const { key: f, prefix: c } = e;
395
- t = f, i = c;
394
+ const { key: f, prefix: u } = e;
395
+ t = f, i = u;
396
396
  } else
397
397
  t = j(e);
398
398
  const n = i || "_global";
@@ -401,8 +401,8 @@ class U {
401
401
  set(e, r, t) {
402
402
  let i, n = t;
403
403
  if (typeof e != "string") {
404
- const { key: f, prefix: c } = e;
405
- i = f, n = c;
404
+ const { key: f, prefix: u } = e;
405
+ i = f, n = u;
406
406
  } else
407
407
  i = j(e);
408
408
  const s = n || "_global";
@@ -487,43 +487,43 @@ function ye() {
487
487
  if (n === s) return !0;
488
488
  if (n && s && typeof n == "object" && typeof s == "object") {
489
489
  if (n.constructor !== s.constructor) return !1;
490
- var f, c, S;
490
+ var f, u, S;
491
491
  if (Array.isArray(n)) {
492
492
  if (f = n.length, f != s.length) return !1;
493
- for (c = f; c-- !== 0; )
494
- if (!i(n[c], s[c])) return !1;
493
+ for (u = f; u-- !== 0; )
494
+ if (!i(n[u], s[u])) return !1;
495
495
  return !0;
496
496
  }
497
497
  var p;
498
498
  if (e && n instanceof Map && s instanceof Map) {
499
499
  if (n.size !== s.size) return !1;
500
- for (p = n.entries(); !(c = p.next()).done; )
501
- if (!s.has(c.value[0])) return !1;
502
- for (p = n.entries(); !(c = p.next()).done; )
503
- if (!i(c.value[1], s.get(c.value[0]))) return !1;
500
+ for (p = n.entries(); !(u = p.next()).done; )
501
+ if (!s.has(u.value[0])) return !1;
502
+ for (p = n.entries(); !(u = p.next()).done; )
503
+ if (!i(u.value[1], s.get(u.value[0]))) return !1;
504
504
  return !0;
505
505
  }
506
506
  if (r && n instanceof Set && s instanceof Set) {
507
507
  if (n.size !== s.size) return !1;
508
- for (p = n.entries(); !(c = p.next()).done; )
509
- if (!s.has(c.value[0])) return !1;
508
+ for (p = n.entries(); !(u = p.next()).done; )
509
+ if (!s.has(u.value[0])) return !1;
510
510
  return !0;
511
511
  }
512
512
  if (t && ArrayBuffer.isView(n) && ArrayBuffer.isView(s)) {
513
513
  if (f = n.length, f != s.length) return !1;
514
- for (c = f; c-- !== 0; )
515
- if (n[c] !== s[c]) return !1;
514
+ for (u = f; u-- !== 0; )
515
+ if (n[u] !== s[u]) return !1;
516
516
  return !0;
517
517
  }
518
518
  if (n.constructor === RegExp) return n.source === s.source && n.flags === s.flags;
519
519
  if (n.valueOf !== Object.prototype.valueOf && typeof n.valueOf == "function" && typeof s.valueOf == "function") return n.valueOf() === s.valueOf();
520
520
  if (n.toString !== Object.prototype.toString && typeof n.toString == "function" && typeof s.toString == "function") return n.toString() === s.toString();
521
521
  if (S = Object.keys(n), f = S.length, f !== Object.keys(s).length) return !1;
522
- for (c = f; c-- !== 0; )
523
- if (!Object.prototype.hasOwnProperty.call(s, S[c])) return !1;
522
+ for (u = f; u-- !== 0; )
523
+ if (!Object.prototype.hasOwnProperty.call(s, S[u])) return !1;
524
524
  if (o && n instanceof Element) return !1;
525
- for (c = f; c-- !== 0; )
526
- if (!((S[c] === "_owner" || S[c] === "__v" || S[c] === "__o") && n.$$typeof) && !i(n[S[c]], s[S[c]]))
525
+ for (u = f; u-- !== 0; )
526
+ if (!((S[u] === "_owner" || S[u] === "__v" || S[u] === "__o") && n.$$typeof) && !i(n[S[u]], s[S[u]]))
527
527
  return !1;
528
528
  return !0;
529
529
  }
@@ -532,10 +532,10 @@ function ye() {
532
532
  return z = function(s, f) {
533
533
  try {
534
534
  return i(s, f);
535
- } catch (c) {
536
- if ((c.message || "").match(/stack|recursion/i))
535
+ } catch (u) {
536
+ if ((u.message || "").match(/stack|recursion/i))
537
537
  return console.warn("react-fast-compare cannot handle circular refs"), !1;
538
- throw c;
538
+ throw u;
539
539
  }
540
540
  }, z;
541
541
  }
@@ -586,7 +586,7 @@ function We(o, e, r) {
586
586
  R.initValue(t, s, i);
587
587
  const f = A(() => (l) => (R.initValue(t, s, e), R.addListener(t, s, l), () => {
588
588
  R.removeListener(t, s, l);
589
- }), []), c = A(() => () => R.get(t, s)?.value, []), S = V(f, c), p = (l) => {
589
+ }), []), u = A(() => () => R.get(t, s)?.value, []), S = V(f, u), p = (l) => {
590
590
  const _ = typeof l == "function" ? l(R.get(t, s)?.value) : l;
591
591
  _ !== S && (R.setValue(t, s, { value: _ }), R.callListeners(t, s));
592
592
  };
@@ -604,13 +604,13 @@ function ze(o, e, r) {
604
604
  t = j(o);
605
605
  const { prefix: n } = N(i), s = Ee(void 0), f = A(() => (p) => (R.addListener(t, n, p), () => {
606
606
  R.removeListener(t, n, p);
607
- }), []), c = A(() => () => {
607
+ }), []), u = A(() => () => {
608
608
  const p = R.get(t, n)?.value, l = e(p);
609
609
  return Le(s.current, l) ? s.current : l;
610
- }, []), S = V(f, c);
610
+ }, []), S = V(f, u);
611
611
  return R.useEffect(t, n), S;
612
612
  }
613
- class De extends d {
613
+ class Ce extends d {
614
614
  defaultValue() {
615
615
  return {
616
616
  fnState: {
@@ -627,7 +627,7 @@ class De extends d {
627
627
  super.setValue(e, r, t);
628
628
  }
629
629
  }
630
- class Ce extends U {
630
+ class De extends U {
631
631
  constructor(e) {
632
632
  super(e);
633
633
  }
@@ -648,7 +648,7 @@ class Ce extends U {
648
648
  typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
649
649
  }
650
650
  }
651
- const w = new De(), Ge = new Ce(w), Ue = (o, e) => w.createStatic({ fn: o }, e);
651
+ const w = new Ce(), Ge = new De(w), Ue = (o, e) => w.createStatic({ fn: o }, e);
652
652
  function Be(o, e, r) {
653
653
  let t, i, n = r;
654
654
  if (typeof o != "string") {
@@ -663,10 +663,10 @@ function Be(o, e, r) {
663
663
  w.removeListener(t, s, l);
664
664
  }),
665
665
  []
666
- ), c = A(
666
+ ), u = A(
667
667
  () => () => w.get(t, s).fnState,
668
668
  []
669
- ), S = V(f, c), p = async (l, ..._) => {
669
+ ), S = V(f, u), p = async (l, ..._) => {
670
670
  const b = w.get(t, s);
671
671
  if (!l && (b.fnState.isLoading || b.fnState.results !== void 0)) return b.fnState;
672
672
  b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, w.callListeners(t, s);
@@ -755,10 +755,10 @@ function Xe(o, e, r) {
755
755
  g.removeListener(t, s, v);
756
756
  }),
757
757
  []
758
- ), c = A(
758
+ ), u = A(
759
759
  () => () => g.get(t, s).fnState,
760
760
  []
761
- ), S = V(f, c), p = (v) => {
761
+ ), S = V(f, u), p = (v) => {
762
762
  const x = g.get(t, s);
763
763
  x.fnState = { ...x.fnState, data: v }, g.callListeners(t, s);
764
764
  }, l = (v) => {
@@ -794,7 +794,7 @@ function Xe(o, e, r) {
794
794
  };
795
795
  }
796
796
  export {
797
- Ce as SharedFunctionsApi,
797
+ De as SharedFunctionsApi,
798
798
  je as SharedStatesApi,
799
799
  Ye as SharedStatesProvider,
800
800
  Ve as SharedSubscriptionsApi,
@@ -806,6 +806,7 @@ export {
806
806
  Ge as sharedFunctionsApi,
807
807
  Ie as sharedStatesApi,
808
808
  Je as sharedSubscriptionsApi,
809
+ N as useSharedContext,
809
810
  Be as useSharedFunction,
810
811
  We as useSharedState,
811
812
  ze as useSharedStateSelector,
package/dist/main.min.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * react-shared-states v1.0.15
2
+ * react-shared-states v1.0.17
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
- (function(p,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],h):(p=typeof globalThis<"u"?globalThis:p||self,h(p.ReactSharedStates={},p.React))})(this,(function(p,h){"use strict";function ce(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var V={exports:{}},C={};/**
8
+ (function(p,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],h):(p=typeof globalThis<"u"?globalThis:p||self,h(p.ReactSharedStates={},p.React))})(this,(function(p,h){"use strict";function ce(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var N={exports:{}},C={};/**
9
9
  * @license React
10
10
  * react-jsx-runtime.production.js
11
11
  *
@@ -26,4 +26,4 @@
26
26
  <%s {...props} />
27
27
  React keys must be passed directly to JSX without using spread:
28
28
  let props = %s;
29
- <%s key={someKey} {...props} />`,_,R,D,R),oe[R+_]=!0)}if(R=null,g!==void 0&&(r(g),R=""+g),n(u)&&(r(u.key),R=""+u.key),"key"in u){g={};for(var B in u)B!=="key"&&(g[B]=u[B])}else g=u;return R&&f(g,typeof a=="function"?a.displayName||a.name||"Unknown":a),b(a,R,y,O,i(),g,G,U)}function l(a){typeof a=="object"&&a!==null&&a.$$typeof===E&&a._store&&(a._store.validated=1)}var A=h,E=Symbol.for("react.transitional.element"),m=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),De=Symbol.for("react.consumer"),Ce=Symbol.for("react.context"),Fe=Symbol.for("react.forward_ref"),Ve=Symbol.for("react.suspense"),Ne=Symbol.for("react.suspense_list"),Ye=Symbol.for("react.memo"),te=Symbol.for("react.lazy"),Me=Symbol.for("react.activity"),Ie=Symbol.for("react.client.reference"),W=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,re=Object.prototype.hasOwnProperty,We=Array.isArray,z=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(a){return a()}};var ne,se={},ae=A.react_stack_bottom_frame.bind(A,s)(),ie=z(t(s)),oe={};F.Fragment=x,F.jsx=function(a,u,g,_,O){var y=1e4>W.recentlyCreatedOwnerStacks++;return S(a,u,g,!1,_,O,y?Error("react-stack-top-frame"):ae,y?z(t(a)):ie)},F.jsxs=function(a,u,g,_,O){var y=1e4>W.recentlyCreatedOwnerStacks++;return S(a,u,g,!0,_,O,y?Error("react-stack-top-frame"):ae,y?z(t(a)):ie)}})()),F}var H;function le(){return H||(H=1,process.env.NODE_ENV==="production"?V.exports=ue():V.exports=fe()),V.exports}var de=le();p.isDevMode=!1;const pe=o=>{p.isDevMode=o},Y=(...o)=>{p.isDevMode&&console.log("%c[react-shared-states]","color: #007acc; font-weight: bold",...o)},j=o=>{if(!o)throw new Error("Value is empty");return o},Z=()=>Math.random().toString(36).substring(2,15),k=h.createContext(void 0),he=({children:o,scopeName:e})=>{if(e&&e.includes("//"))throw new Error("scopeName cannot contain '//'");return e||(e=h.useMemo(()=>Z(),[])),de.jsx(k.Provider,{value:{scopeName:e},children:o})},Se=()=>h.useContext(k),Q=[];class d{data=new Map;defaultValue(){return{}}addListener(e,r,t){this.data.has(d.prefix(e,r))||this.data.set(d.prefix(e,r),{...this.defaultValue(),listeners:[]}),this.data.get(d.prefix(e,r)).listeners.push(t)}removeListener(e,r,t){this.data.has(d.prefix(e,r))&&(this.data.get(d.prefix(e,r)).listeners=this.data.get(d.prefix(e,r)).listeners.filter(i=>i!==t))}callListeners(e,r){this.data.has(d.prefix(e,r))&&this.data.get(d.prefix(e,r)).listeners.forEach(t=>t())}init(e,r,t,i=!1){this.data.has(d.prefix(e,r))||this.data.set(d.prefix(e,r),{...t,isStatic:i,listeners:[]})}createStatic(e,r){const t=r??r??"_global",i={key:Z(),prefix:t,...e};return Q.push(i),this.initStatic(i),i}initStatic(e){const{key:r,prefix:t}=e;this.init(r,t,this.defaultValue(),!0)}clearAll(e=!1,r=!1){this.data.forEach((t,i)=>{const[s,n]=d.extractPrefix(i);this.clear(n,s,e,r)})}clear(e,r,t=!1,i=!1){t||this.callListeners(e,r);const s=this.data.get(d.prefix(e,r));if(!s)return;const n={...s};if(this.data.delete(d.prefix(e,r)),n.isStatic&&!i){const f=Q.find(c=>c.key===e&&c.prefix===r);f&&this.initStatic(f)}}get(e,r){let t=this.has(e,r);if(t)return this.data.get(t)}setValue(e,r,t){this.data.has(d.prefix(e,r))&&this.data.set(d.prefix(e,r),{...this.data.get(d.prefix(e,r)),...t})}has(e,r){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}static prefix(e,r){if(e.includes("//"))throw new Error("key cannot contain '//'");return`${r}//${e}`}static extractPrefix(e){return e.split("//")}useEffect(e,r,t=null){h.useEffect(()=>()=>{t?.(),Y(`[${d.prefix(e,r)}]`,"unmount effect"),this.data.get(d.prefix(e,r)).listeners?.length===0&&this.clear(e,r)},[])}}class M{constructor(e){this.sharedData=e}get(e,r){let t,i=r;if(typeof e!="string"){const{key:f,prefix:c}=e;t=f,i=c}else t=j(e);const s=i||"_global";return this.sharedData.get(t,s)}set(e,r,t){let i,s=t;if(typeof e!="string"){const{key:f,prefix:c}=e;i=f,s=c}else i=j(e);const n=s||"_global";this.sharedData.init(i,n,r),this.sharedData.setValue(i,n,r),this.sharedData.callListeners(i,n)}update(e,r,t){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const s=r(i);typeof e=="string"?this.set(e,s,t):this.set(e,s)}clearAll(){this.sharedData.clearAll()}clearScope(e){const r=e||"_global";this.sharedData.data.forEach((t,i)=>{const[s,n]=d.extractPrefix(i);if(s===r){this.sharedData.clear(n,s),this.sharedData.callListeners(n,s);return}})}resolve(e){const{key:r,prefix:t}=e;return this.get(r,t)}clear(e,r){let t,i;typeof e=="string"?(t=e,i=r||"_global"):(t=e.key,i=e.prefix),this.sharedData.clear(t,i)}has(e,r="_global"){const t=r||"_global";return!!this.sharedData.has(e,t)}getAll(){const e={};return this.sharedData.data.forEach((r,t)=>{const[i,s]=d.extractPrefix(t);e[i]=e[i]||{},e[i][s]=r}),e}subscribe(e,r,t){let i,s;return typeof e=="string"?(i=e,s=t||"_global"):(i=e.key,s=e.prefix),this.sharedData.addListener(i,s,r),()=>{this.sharedData.removeListener(i,s,r)}}}const N=o=>{const e=Se();return{prefix:o??e?.scopeName??"_global"}};var I,K;function ge(){if(K)return I;K=1;var o=typeof Element<"u",e=typeof Map=="function",r=typeof Set=="function",t=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function i(s,n){if(s===n)return!0;if(s&&n&&typeof s=="object"&&typeof n=="object"){if(s.constructor!==n.constructor)return!1;var f,c,b;if(Array.isArray(s)){if(f=s.length,f!=n.length)return!1;for(c=f;c--!==0;)if(!i(s[c],n[c]))return!1;return!0}var S;if(e&&s instanceof Map&&n instanceof Map){if(s.size!==n.size)return!1;for(S=s.entries();!(c=S.next()).done;)if(!n.has(c.value[0]))return!1;for(S=s.entries();!(c=S.next()).done;)if(!i(c.value[1],n.get(c.value[0])))return!1;return!0}if(r&&s instanceof Set&&n instanceof Set){if(s.size!==n.size)return!1;for(S=s.entries();!(c=S.next()).done;)if(!n.has(c.value[0]))return!1;return!0}if(t&&ArrayBuffer.isView(s)&&ArrayBuffer.isView(n)){if(f=s.length,f!=n.length)return!1;for(c=f;c--!==0;)if(s[c]!==n[c])return!1;return!0}if(s.constructor===RegExp)return s.source===n.source&&s.flags===n.flags;if(s.valueOf!==Object.prototype.valueOf&&typeof s.valueOf=="function"&&typeof n.valueOf=="function")return s.valueOf()===n.valueOf();if(s.toString!==Object.prototype.toString&&typeof s.toString=="function"&&typeof n.toString=="function")return s.toString()===n.toString();if(b=Object.keys(s),f=b.length,f!==Object.keys(n).length)return!1;for(c=f;c--!==0;)if(!Object.prototype.hasOwnProperty.call(n,b[c]))return!1;if(o&&s instanceof Element)return!1;for(c=f;c--!==0;)if(!((b[c]==="_owner"||b[c]==="__v"||b[c]==="__o")&&s.$$typeof)&&!i(s[b[c]],n[b[c]]))return!1;return!0}return s!==s&&n!==n}return I=function(n,f){try{return i(n,f)}catch(c){if((c.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw c}},I}var ve=ge();const be=ce(ve);class me extends d{defaultValue(){return{value:void 0}}initValue(e,r,t,i=!1){super.init(e,r,{value:t},i)}initStatic(e){const{key:r,prefix:t,initialValue:i}=e;this.initValue(r,t,i,!0)}}class q extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.value:super.get(e,r)?.value}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,{value:r});return}super.set(e,{value:r},t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const s=r(i);typeof e=="string"?this.set(e,s,t):this.set(e,s)}}const w=new me,Ee=new q(w),xe=(o,e)=>w.createStatic({initialValue:o},e);function _e(o,e,r){let t,i,s=r;if(typeof o!="string"){const{key:l,initialValue:A,prefix:E}=o;t=l,i=A,s=E}else t=j(o),i=e;const{prefix:n}=N(s);w.initValue(t,n,i);const f=h.useMemo(()=>l=>(w.initValue(t,n,e),w.addListener(t,n,l),()=>{w.removeListener(t,n,l)}),[]),c=h.useMemo(()=>()=>w.get(t,n)?.value,[]),b=h.useSyncExternalStore(f,c),S=l=>{const A=typeof l=="function"?l(w.get(t,n)?.value):l;A!==b&&(w.setValue(t,n,{value:A}),w.callListeners(t,n))};return w.useEffect(t,n),[b,S]}function Re(o,e,r){let t,i=r;if(typeof o!="string"){const{key:S,prefix:l}=o;t=S,i=l}else t=j(o);const{prefix:s}=N(i),n=h.useRef(void 0),f=h.useMemo(()=>S=>(w.addListener(t,s,S),()=>{w.removeListener(t,s,S)}),[]),c=h.useMemo(()=>()=>{const S=w.get(t,s)?.value,l=e(S);return be(n.current,l)?n.current:l},[]),b=h.useSyncExternalStore(f,c);return w.useEffect(t,s),b}class we extends d{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}initValue(e,r,t=!1){super.init(e,r,this.defaultValue(),t)}setValue(e,r,t){super.setValue(e,r,t)}}class $ extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,r)?.fnState}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,r);return}super.set(e,r,t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const s=r(i);typeof e=="string"?this.set(e,s,t):this.set(e,s)}}const T=new we,Ae=new $(T),Te=(o,e)=>T.createStatic({fn:o},e);function ye(o,e,r){let t,i,s=r;if(typeof o!="string"){const{key:l,fn:A,prefix:E}=o;t=l,i=A,s=E}else t=j(o),i=e;const{prefix:n}=N(s);T.initValue(t,n);const f=h.useMemo(()=>l=>(T.initValue(t,n),T.addListener(t,n,l),()=>{T.removeListener(t,n,l)}),[]),c=h.useMemo(()=>()=>T.get(t,n).fnState,[]),b=h.useSyncExternalStore(f,c),S=async(l,...A)=>{const E=T.get(t,n);if(!l&&(E.fnState.isLoading||E.fnState.results!==void 0))return E.fnState;E.fnState={...E.fnState,isLoading:!0,error:void 0},T.callListeners(t,n);try{const m=await i(...A);E.fnState={results:m,isLoading:!1,error:void 0}}catch(m){E.fnState={...E.fnState,isLoading:!1,error:m}}T.callListeners(t,n)};return T.useEffect(t,n),{state:b,trigger:(...l)=>{S(!1,...l)},forceTrigger:(...l)=>{S(!0,...l)},clear:()=>{const l=T.get(t,n);l&&(l.fnState=T.defaultValue().fnState,T.callListeners(t,n))}}}class Oe extends d{defaultValue(){return{fnState:{data:void 0,isLoading:!1,error:void 0,subscribed:!1}}}initValue(e,r,t=!1){super.init(e,r,this.defaultValue(),t)}setValue(e,r,t){super.setValue(e,r,t)}useEffect(e,r){h.useEffect(()=>()=>{Y(`[${d.prefix(e,r)}]`,"unmount effect2"),this.get(e,r)?.listeners.length===0&&this.unsubscribe(e,r)},[]),super.useEffect(e,r)}async unsubscribe(e,r){const t=this.get(e,r);t&&(t.unsubscribe&&(t.unsubscribe(),t.unsubscribe=void 0),t.fnState={...t.fnState,subscribed:!1},this.callListeners(e,r))}}class ee extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,r)?.fnState}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,r);return}super.set(e,r,t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const s=r(i);typeof e=="string"?this.set(e,s,t):this.set(e,s)}}const v=new Oe,Pe=new ee(v),Le=(o,e)=>v.createStatic({subscriber:o},e);function je(o,e,r){let t,i,s=r;if(typeof o!="string"){const{key:m,subscriber:x,prefix:P}=o;t=m,i=x,s=P}else t=j(o),i=e;const{prefix:n}=N(s);v.initValue(t,n);const f=h.useMemo(()=>m=>(v.initValue(t,n),v.addListener(t,n,m),()=>{v.removeListener(t,n,m)}),[]),c=h.useMemo(()=>()=>v.get(t,n).fnState,[]),b=h.useSyncExternalStore(f,c),S=m=>{const x=v.get(t,n);x.fnState={...x.fnState,data:m},v.callListeners(t,n)},l=m=>{const x=v.get(t,n);x.fnState={...x.fnState,isLoading:!1,data:void 0,error:m},v.callListeners(t,n)},A=()=>{const m=v.get(t,n);m.fnState={...m.fnState,isLoading:!1},v.callListeners(t,n)},E=async m=>{const x=v.get(t,n);if(m&&(await v.unsubscribe(t,n),x.fnState={...x.fnState,isLoading:!1,data:void 0,error:void 0,subscribed:!1}),x.fnState.subscribed)return x.fnState;Y("triggered !!"),x.fnState={...x.fnState,isLoading:!0,error:void 0},v.callListeners(t,n);try{const P=await i(S,l,A),L=v.get(t,n);L.unsubscribe=P,L.fnState.subscribed=!0}catch(P){const L=v.get(t,n);L.fnState={...L.fnState,isLoading:!1,error:P}}v.callListeners(t,n)};return v.useEffect(t,n),{state:b,trigger:()=>{E(!1)},forceTrigger:()=>{E(!0)},unsubscribe:()=>{v.unsubscribe(t,n)}}}p.SharedFunctionsApi=$,p.SharedStatesApi=q,p.SharedStatesProvider=he,p.SharedSubscriptionsApi=ee,p.createSharedFunction=Te,p.createSharedState=xe,p.createSharedSubscription=Le,p.setDevMode=pe,p.sharedFunctionsApi=Ae,p.sharedStatesApi=Ee,p.sharedSubscriptionsApi=Pe,p.useSharedFunction=ye,p.useSharedState=_e,p.useSharedStateSelector=Re,p.useSharedSubscription=je,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
29
+ <%s key={someKey} {...props} />`,_,R,D,R),oe[R+_]=!0)}if(R=null,g!==void 0&&(r(g),R=""+g),n(u)&&(r(u.key),R=""+u.key),"key"in u){g={};for(var B in u)B!=="key"&&(g[B]=u[B])}else g=u;return R&&f(g,typeof a=="function"?a.displayName||a.name||"Unknown":a),b(a,R,y,O,i(),g,G,U)}function l(a){typeof a=="object"&&a!==null&&a.$$typeof===E&&a._store&&(a._store.validated=1)}var A=h,E=Symbol.for("react.transitional.element"),m=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),De=Symbol.for("react.consumer"),Ce=Symbol.for("react.context"),Fe=Symbol.for("react.forward_ref"),Ve=Symbol.for("react.suspense"),Ne=Symbol.for("react.suspense_list"),Ye=Symbol.for("react.memo"),te=Symbol.for("react.lazy"),Me=Symbol.for("react.activity"),Ie=Symbol.for("react.client.reference"),W=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,re=Object.prototype.hasOwnProperty,We=Array.isArray,z=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(a){return a()}};var ne,se={},ae=A.react_stack_bottom_frame.bind(A,s)(),ie=z(t(s)),oe={};F.Fragment=x,F.jsx=function(a,u,g,_,O){var y=1e4>W.recentlyCreatedOwnerStacks++;return S(a,u,g,!1,_,O,y?Error("react-stack-top-frame"):ae,y?z(t(a)):ie)},F.jsxs=function(a,u,g,_,O){var y=1e4>W.recentlyCreatedOwnerStacks++;return S(a,u,g,!0,_,O,y?Error("react-stack-top-frame"):ae,y?z(t(a)):ie)}})()),F}var H;function le(){return H||(H=1,process.env.NODE_ENV==="production"?N.exports=ue():N.exports=fe()),N.exports}var de=le();p.isDevMode=!1;const pe=o=>{p.isDevMode=o},Y=(...o)=>{p.isDevMode&&console.log("%c[react-shared-states]","color: #007acc; font-weight: bold",...o)},j=o=>{if(!o)throw new Error("Value is empty");return o},Z=()=>Math.random().toString(36).substring(2,15),k=h.createContext(void 0),he=({children:o,scopeName:e})=>{if(e&&e.includes("//"))throw new Error("scopeName cannot contain '//'");return e||(e=h.useMemo(()=>Z(),[])),de.jsx(k.Provider,{value:{scopeName:e},children:o})},Se=()=>h.useContext(k),Q=[];class d{data=new Map;defaultValue(){return{}}addListener(e,r,t){this.data.has(d.prefix(e,r))||this.data.set(d.prefix(e,r),{...this.defaultValue(),listeners:[]}),this.data.get(d.prefix(e,r)).listeners.push(t)}removeListener(e,r,t){this.data.has(d.prefix(e,r))&&(this.data.get(d.prefix(e,r)).listeners=this.data.get(d.prefix(e,r)).listeners.filter(i=>i!==t))}callListeners(e,r){this.data.has(d.prefix(e,r))&&this.data.get(d.prefix(e,r)).listeners.forEach(t=>t())}init(e,r,t,i=!1){this.data.has(d.prefix(e,r))||this.data.set(d.prefix(e,r),{...t,isStatic:i,listeners:[]})}createStatic(e,r){const t=r??r??"_global",i={key:Z(),prefix:t,...e};return Q.push(i),this.initStatic(i),i}initStatic(e){const{key:r,prefix:t}=e;this.init(r,t,this.defaultValue(),!0)}clearAll(e=!1,r=!1){this.data.forEach((t,i)=>{const[s,n]=d.extractPrefix(i);this.clear(n,s,e,r)})}clear(e,r,t=!1,i=!1){t||this.callListeners(e,r);const s=this.data.get(d.prefix(e,r));if(!s)return;const n={...s};if(this.data.delete(d.prefix(e,r)),n.isStatic&&!i){const f=Q.find(c=>c.key===e&&c.prefix===r);f&&this.initStatic(f)}}get(e,r){let t=this.has(e,r);if(t)return this.data.get(t)}setValue(e,r,t){this.data.has(d.prefix(e,r))&&this.data.set(d.prefix(e,r),{...this.data.get(d.prefix(e,r)),...t})}has(e,r){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}static prefix(e,r){if(e.includes("//"))throw new Error("key cannot contain '//'");return`${r}//${e}`}static extractPrefix(e){return e.split("//")}useEffect(e,r,t=null){h.useEffect(()=>()=>{t?.(),Y(`[${d.prefix(e,r)}]`,"unmount effect"),this.data.get(d.prefix(e,r)).listeners?.length===0&&this.clear(e,r)},[])}}class M{constructor(e){this.sharedData=e}get(e,r){let t,i=r;if(typeof e!="string"){const{key:f,prefix:c}=e;t=f,i=c}else t=j(e);const s=i||"_global";return this.sharedData.get(t,s)}set(e,r,t){let i,s=t;if(typeof e!="string"){const{key:f,prefix:c}=e;i=f,s=c}else i=j(e);const n=s||"_global";this.sharedData.init(i,n,r),this.sharedData.setValue(i,n,r),this.sharedData.callListeners(i,n)}update(e,r,t){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const s=r(i);typeof e=="string"?this.set(e,s,t):this.set(e,s)}clearAll(){this.sharedData.clearAll()}clearScope(e){const r=e||"_global";this.sharedData.data.forEach((t,i)=>{const[s,n]=d.extractPrefix(i);if(s===r){this.sharedData.clear(n,s),this.sharedData.callListeners(n,s);return}})}resolve(e){const{key:r,prefix:t}=e;return this.get(r,t)}clear(e,r){let t,i;typeof e=="string"?(t=e,i=r||"_global"):(t=e.key,i=e.prefix),this.sharedData.clear(t,i)}has(e,r="_global"){const t=r||"_global";return!!this.sharedData.has(e,t)}getAll(){const e={};return this.sharedData.data.forEach((r,t)=>{const[i,s]=d.extractPrefix(t);e[i]=e[i]||{},e[i][s]=r}),e}subscribe(e,r,t){let i,s;return typeof e=="string"?(i=e,s=t||"_global"):(i=e.key,s=e.prefix),this.sharedData.addListener(i,s,r),()=>{this.sharedData.removeListener(i,s,r)}}}const V=o=>{const e=Se();return{prefix:o??e?.scopeName??"_global"}};var I,K;function ge(){if(K)return I;K=1;var o=typeof Element<"u",e=typeof Map=="function",r=typeof Set=="function",t=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function i(s,n){if(s===n)return!0;if(s&&n&&typeof s=="object"&&typeof n=="object"){if(s.constructor!==n.constructor)return!1;var f,c,b;if(Array.isArray(s)){if(f=s.length,f!=n.length)return!1;for(c=f;c--!==0;)if(!i(s[c],n[c]))return!1;return!0}var S;if(e&&s instanceof Map&&n instanceof Map){if(s.size!==n.size)return!1;for(S=s.entries();!(c=S.next()).done;)if(!n.has(c.value[0]))return!1;for(S=s.entries();!(c=S.next()).done;)if(!i(c.value[1],n.get(c.value[0])))return!1;return!0}if(r&&s instanceof Set&&n instanceof Set){if(s.size!==n.size)return!1;for(S=s.entries();!(c=S.next()).done;)if(!n.has(c.value[0]))return!1;return!0}if(t&&ArrayBuffer.isView(s)&&ArrayBuffer.isView(n)){if(f=s.length,f!=n.length)return!1;for(c=f;c--!==0;)if(s[c]!==n[c])return!1;return!0}if(s.constructor===RegExp)return s.source===n.source&&s.flags===n.flags;if(s.valueOf!==Object.prototype.valueOf&&typeof s.valueOf=="function"&&typeof n.valueOf=="function")return s.valueOf()===n.valueOf();if(s.toString!==Object.prototype.toString&&typeof s.toString=="function"&&typeof n.toString=="function")return s.toString()===n.toString();if(b=Object.keys(s),f=b.length,f!==Object.keys(n).length)return!1;for(c=f;c--!==0;)if(!Object.prototype.hasOwnProperty.call(n,b[c]))return!1;if(o&&s instanceof Element)return!1;for(c=f;c--!==0;)if(!((b[c]==="_owner"||b[c]==="__v"||b[c]==="__o")&&s.$$typeof)&&!i(s[b[c]],n[b[c]]))return!1;return!0}return s!==s&&n!==n}return I=function(n,f){try{return i(n,f)}catch(c){if((c.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw c}},I}var ve=ge();const be=ce(ve);class me extends d{defaultValue(){return{value:void 0}}initValue(e,r,t,i=!1){super.init(e,r,{value:t},i)}initStatic(e){const{key:r,prefix:t,initialValue:i}=e;this.initValue(r,t,i,!0)}}class q extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.value:super.get(e,r)?.value}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,{value:r});return}super.set(e,{value:r},t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const s=r(i);typeof e=="string"?this.set(e,s,t):this.set(e,s)}}const w=new me,Ee=new q(w),xe=(o,e)=>w.createStatic({initialValue:o},e);function _e(o,e,r){let t,i,s=r;if(typeof o!="string"){const{key:l,initialValue:A,prefix:E}=o;t=l,i=A,s=E}else t=j(o),i=e;const{prefix:n}=V(s);w.initValue(t,n,i);const f=h.useMemo(()=>l=>(w.initValue(t,n,e),w.addListener(t,n,l),()=>{w.removeListener(t,n,l)}),[]),c=h.useMemo(()=>()=>w.get(t,n)?.value,[]),b=h.useSyncExternalStore(f,c),S=l=>{const A=typeof l=="function"?l(w.get(t,n)?.value):l;A!==b&&(w.setValue(t,n,{value:A}),w.callListeners(t,n))};return w.useEffect(t,n),[b,S]}function Re(o,e,r){let t,i=r;if(typeof o!="string"){const{key:S,prefix:l}=o;t=S,i=l}else t=j(o);const{prefix:s}=V(i),n=h.useRef(void 0),f=h.useMemo(()=>S=>(w.addListener(t,s,S),()=>{w.removeListener(t,s,S)}),[]),c=h.useMemo(()=>()=>{const S=w.get(t,s)?.value,l=e(S);return be(n.current,l)?n.current:l},[]),b=h.useSyncExternalStore(f,c);return w.useEffect(t,s),b}class we extends d{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}initValue(e,r,t=!1){super.init(e,r,this.defaultValue(),t)}setValue(e,r,t){super.setValue(e,r,t)}}class $ extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,r)?.fnState}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,r);return}super.set(e,r,t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const s=r(i);typeof e=="string"?this.set(e,s,t):this.set(e,s)}}const T=new we,Ae=new $(T),Te=(o,e)=>T.createStatic({fn:o},e);function ye(o,e,r){let t,i,s=r;if(typeof o!="string"){const{key:l,fn:A,prefix:E}=o;t=l,i=A,s=E}else t=j(o),i=e;const{prefix:n}=V(s);T.initValue(t,n);const f=h.useMemo(()=>l=>(T.initValue(t,n),T.addListener(t,n,l),()=>{T.removeListener(t,n,l)}),[]),c=h.useMemo(()=>()=>T.get(t,n).fnState,[]),b=h.useSyncExternalStore(f,c),S=async(l,...A)=>{const E=T.get(t,n);if(!l&&(E.fnState.isLoading||E.fnState.results!==void 0))return E.fnState;E.fnState={...E.fnState,isLoading:!0,error:void 0},T.callListeners(t,n);try{const m=await i(...A);E.fnState={results:m,isLoading:!1,error:void 0}}catch(m){E.fnState={...E.fnState,isLoading:!1,error:m}}T.callListeners(t,n)};return T.useEffect(t,n),{state:b,trigger:(...l)=>{S(!1,...l)},forceTrigger:(...l)=>{S(!0,...l)},clear:()=>{const l=T.get(t,n);l&&(l.fnState=T.defaultValue().fnState,T.callListeners(t,n))}}}class Oe extends d{defaultValue(){return{fnState:{data:void 0,isLoading:!1,error:void 0,subscribed:!1}}}initValue(e,r,t=!1){super.init(e,r,this.defaultValue(),t)}setValue(e,r,t){super.setValue(e,r,t)}useEffect(e,r){h.useEffect(()=>()=>{Y(`[${d.prefix(e,r)}]`,"unmount effect2"),this.get(e,r)?.listeners.length===0&&this.unsubscribe(e,r)},[]),super.useEffect(e,r)}async unsubscribe(e,r){const t=this.get(e,r);t&&(t.unsubscribe&&(t.unsubscribe(),t.unsubscribe=void 0),t.fnState={...t.fnState,subscribed:!1},this.callListeners(e,r))}}class ee extends M{constructor(e){super(e)}get(e,r="_global"){return typeof e!="string"?super.get(e)?.fnState:super.get(e,r)?.fnState}set(e,r,t="_global"){if(typeof e!="string"){super.set(e,r);return}super.set(e,r,t)}update(e,r,t="_global"){let i;typeof e=="string"?i=this.get(e,t):i=this.get(e);const s=r(i);typeof e=="string"?this.set(e,s,t):this.set(e,s)}}const v=new Oe,Pe=new ee(v),Le=(o,e)=>v.createStatic({subscriber:o},e);function je(o,e,r){let t,i,s=r;if(typeof o!="string"){const{key:m,subscriber:x,prefix:P}=o;t=m,i=x,s=P}else t=j(o),i=e;const{prefix:n}=V(s);v.initValue(t,n);const f=h.useMemo(()=>m=>(v.initValue(t,n),v.addListener(t,n,m),()=>{v.removeListener(t,n,m)}),[]),c=h.useMemo(()=>()=>v.get(t,n).fnState,[]),b=h.useSyncExternalStore(f,c),S=m=>{const x=v.get(t,n);x.fnState={...x.fnState,data:m},v.callListeners(t,n)},l=m=>{const x=v.get(t,n);x.fnState={...x.fnState,isLoading:!1,data:void 0,error:m},v.callListeners(t,n)},A=()=>{const m=v.get(t,n);m.fnState={...m.fnState,isLoading:!1},v.callListeners(t,n)},E=async m=>{const x=v.get(t,n);if(m&&(await v.unsubscribe(t,n),x.fnState={...x.fnState,isLoading:!1,data:void 0,error:void 0,subscribed:!1}),x.fnState.subscribed)return x.fnState;Y("triggered !!"),x.fnState={...x.fnState,isLoading:!0,error:void 0},v.callListeners(t,n);try{const P=await i(S,l,A),L=v.get(t,n);L.unsubscribe=P,L.fnState.subscribed=!0}catch(P){const L=v.get(t,n);L.fnState={...L.fnState,isLoading:!1,error:P}}v.callListeners(t,n)};return v.useEffect(t,n),{state:b,trigger:()=>{E(!1)},forceTrigger:()=>{E(!0)},unsubscribe:()=>{v.unsubscribe(t,n)}}}p.SharedFunctionsApi=$,p.SharedStatesApi=q,p.SharedStatesProvider=he,p.SharedSubscriptionsApi=ee,p.createSharedFunction=Te,p.createSharedState=xe,p.createSharedSubscription=Le,p.setDevMode=pe,p.sharedFunctionsApi=Ae,p.sharedStatesApi=Ee,p.sharedSubscriptionsApi=Pe,p.useSharedContext=V,p.useSharedFunction=ye,p.useSharedState=_e,p.useSharedStateSelector=Re,p.useSharedSubscription=je,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-shared-states",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "type": "module",
5
5
  "description": "Global state made as simple as useState, with zero config, built-in async caching, and automatic scoping.",
6
6
  "keywords": [