react-shared-states 1.0.14 → 1.0.16

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,4 +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
82
  }
package/dist/main.esm.js CHANGED
@@ -1,15 +1,15 @@
1
1
  /*!
2
- * react-shared-states v1.0.14
2
+ * react-shared-states v1.0.16
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 ve, { createContext as be, useMemo as A, useContext as xe, useEffect as ne, useSyncExternalStore as V, useRef as Ee } from "react";
8
+ import ve, { createContext as be, useMemo as A, useContext as xe, useEffect as se, useSyncExternalStore as V, useRef as Ee } from "react";
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: {} }, C = {};
12
+ var F = { exports: {} }, D = {};
13
13
  /**
14
14
  * @license React
15
15
  * react-jsx-runtime.production.js
@@ -21,27 +21,27 @@ var F = { exports: {} }, C = {};
21
21
  */
22
22
  var Q;
23
23
  function _e() {
24
- if (Q) return C;
24
+ if (Q) return D;
25
25
  Q = 1;
26
26
  var o = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
27
- function r(t, i, a) {
28
- var n = null;
29
- if (a !== void 0 && (n = "" + a), i.key !== void 0 && (n = "" + i.key), "key" in i) {
30
- a = {};
27
+ function r(t, i, n) {
28
+ var s = null;
29
+ if (n !== void 0 && (s = "" + n), i.key !== void 0 && (s = "" + i.key), "key" in i) {
30
+ n = {};
31
31
  for (var f in i)
32
- f !== "key" && (a[f] = i[f]);
33
- } else a = i;
34
- return i = a.ref, {
32
+ f !== "key" && (n[f] = i[f]);
33
+ } else n = i;
34
+ return i = n.ref, {
35
35
  $$typeof: o,
36
36
  type: t,
37
- key: n,
37
+ key: s,
38
38
  ref: i !== void 0 ? i : null,
39
- props: a
39
+ props: n
40
40
  };
41
41
  }
42
- return C.Fragment = e, C.jsx = r, C.jsxs = r, C;
42
+ return D.Fragment = e, D.jsx = r, D.jsxs = r, D;
43
43
  }
44
- var D = {};
44
+ var C = {};
45
45
  /**
46
46
  * @license React
47
47
  * react-jsx-runtime.development.js
@@ -54,15 +54,15 @@ var D = {};
54
54
  var K;
55
55
  function Re() {
56
56
  return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
57
- function o(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) {
57
+ function o(a) {
58
+ if (a == null) return null;
59
+ if (typeof a == "function")
60
+ return a.$$typeof === he ? null : a.displayName || a.name || null;
61
+ if (typeof a == "string") return a;
62
+ switch (a) {
63
63
  case x:
64
64
  return "Fragment";
65
- case P:
65
+ case L:
66
66
  return "Profiler";
67
67
  case O:
68
68
  return "StrictMode";
@@ -73,126 +73,126 @@ function Re() {
73
73
  case pe:
74
74
  return "Activity";
75
75
  }
76
- if (typeof s == "object")
77
- switch (typeof s.tag == "number" && console.error(
76
+ if (typeof a == "object")
77
+ switch (typeof a.tag == "number" && console.error(
78
78
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
79
- ), s.$$typeof) {
79
+ ), a.$$typeof) {
80
80
  case v:
81
81
  return "Portal";
82
82
  case ce:
83
- return (s.displayName || "Context") + ".Provider";
83
+ return (a.displayName || "Context") + ".Provider";
84
84
  case oe:
85
- return (s._context.displayName || "Context") + ".Consumer";
85
+ return (a._context.displayName || "Context") + ".Consumer";
86
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;
87
+ var u = a.render;
88
+ return a = a.displayName, a || (a = u.displayName || u.name || "", a = a !== "" ? "ForwardRef(" + a + ")" : "ForwardRef"), a;
89
89
  case de:
90
- return u = s.displayName || null, u !== null ? u : o(s.type) || "Memo";
90
+ return u = a.displayName || null, u !== null ? u : o(a.type) || "Memo";
91
91
  case B:
92
- u = s._payload, s = s._init;
92
+ u = a._payload, a = a._init;
93
93
  try {
94
- return o(s(u));
94
+ return o(a(u));
95
95
  } catch {
96
96
  }
97
97
  }
98
98
  return null;
99
99
  }
100
- function e(s) {
101
- return "" + s;
100
+ function e(a) {
101
+ return "" + a;
102
102
  }
103
- function r(s) {
103
+ function r(a) {
104
104
  try {
105
- e(s);
105
+ e(a);
106
106
  var u = !1;
107
107
  } catch {
108
108
  u = !0;
109
109
  }
110
110
  if (u) {
111
111
  u = console;
112
- var h = u.error, E = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
112
+ var h = u.error, E = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
113
113
  return h.call(
114
114
  u,
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
- ), e(s);
117
+ ), e(a);
118
118
  }
119
119
  }
120
- function t(s) {
121
- if (s === x) return "<>";
122
- if (typeof s == "object" && s !== null && s.$$typeof === B)
120
+ function t(a) {
121
+ if (a === x) return "<>";
122
+ if (typeof a == "object" && a !== null && a.$$typeof === B)
123
123
  return "<...>";
124
124
  try {
125
- var u = o(s);
125
+ var u = o(a);
126
126
  return u ? "<" + u + ">" : "<...>";
127
127
  } catch {
128
128
  return "<...>";
129
129
  }
130
130
  }
131
131
  function i() {
132
- var s = $.A;
133
- return s === null ? null : s.getOwner();
132
+ var a = $.A;
133
+ return a === null ? null : a.getOwner();
134
134
  }
135
- function a() {
135
+ function n() {
136
136
  return Error("react-stack-top-frame");
137
137
  }
138
- function n(s) {
139
- if (J.call(s, "key")) {
140
- var u = Object.getOwnPropertyDescriptor(s, "key").get;
138
+ function s(a) {
139
+ if (J.call(a, "key")) {
140
+ var u = Object.getOwnPropertyDescriptor(a, "key").get;
141
141
  if (u && u.isReactWarning) return !1;
142
142
  }
143
- return s.key !== void 0;
143
+ return a.key !== void 0;
144
144
  }
145
- function f(s, u) {
145
+ function f(a, u) {
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
149
  u
150
150
  ));
151
151
  }
152
- h.isReactWarning = !0, Object.defineProperty(s, "key", {
152
+ h.isReactWarning = !0, Object.defineProperty(a, "key", {
153
153
  get: h,
154
154
  configurable: !0
155
155
  });
156
156
  }
157
157
  function c() {
158
- var s = o(this.type);
159
- return X[s] || (X[s] = !0, console.error(
158
+ var a = o(this.type);
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
- )), s = this.props.ref, s !== void 0 ? s : null;
161
+ )), a = this.props.ref, a !== void 0 ? a : null;
162
162
  }
163
- function S(s, u, h, E, y, T, I, q) {
164
- return h = T.ref, s = {
163
+ function S(a, u, h, E, y, T, I, q) {
164
+ return h = T.ref, a = {
165
165
  $$typeof: b,
166
- type: s,
166
+ type: a,
167
167
  key: u,
168
168
  props: T,
169
169
  _owner: y
170
- }, (h !== void 0 ? h : null) !== null ? Object.defineProperty(s, "ref", {
170
+ }, (h !== void 0 ? h : null) !== null ? Object.defineProperty(a, "ref", {
171
171
  enumerable: !1,
172
172
  get: c
173
- }) : Object.defineProperty(s, "ref", { enumerable: !1, value: null }), s._store = {}, Object.defineProperty(s._store, "validated", {
173
+ }) : Object.defineProperty(a, "ref", { enumerable: !1, value: null }), a._store = {}, Object.defineProperty(a._store, "validated", {
174
174
  configurable: !1,
175
175
  enumerable: !1,
176
176
  writable: !0,
177
177
  value: 0
178
- }), Object.defineProperty(s, "_debugInfo", {
178
+ }), Object.defineProperty(a, "_debugInfo", {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
182
  value: null
183
- }), Object.defineProperty(s, "_debugStack", {
183
+ }), Object.defineProperty(a, "_debugStack", {
184
184
  configurable: !1,
185
185
  enumerable: !1,
186
186
  writable: !0,
187
187
  value: I
188
- }), Object.defineProperty(s, "_debugTask", {
188
+ }), Object.defineProperty(a, "_debugTask", {
189
189
  configurable: !1,
190
190
  enumerable: !1,
191
191
  writable: !0,
192
192
  value: q
193
- }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
193
+ }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
194
194
  }
195
- function p(s, u, h, E, y, T, I, q) {
195
+ function p(a, u, h, E, y, T, I, q) {
196
196
  var m = u.children;
197
197
  if (m !== void 0)
198
198
  if (E)
@@ -206,11 +206,11 @@ function Re() {
206
206
  );
207
207
  else l(m);
208
208
  if (J.call(u, "key")) {
209
- m = o(s);
210
- var L = Object.keys(u).filter(function(Se) {
209
+ m = o(a);
210
+ var P = Object.keys(u).filter(function(Se) {
211
211
  return Se !== "key";
212
212
  });
213
- E = 0 < L.length ? "{key: someKey, " + L.join(": ..., ") + ": ...}" : "{key: someKey}", Z[m + E] || (L = 0 < L.length ? "{" + L.join(": ..., ") + ": ...}" : "{}", console.error(
213
+ E = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", k[m + E] || (P = 0 < P.length ? "{" + P.join(": ..., ") + ": ...}" : "{}", console.error(
214
214
  `A props object containing a "key" prop is being spread into JSX:
215
215
  let props = %s;
216
216
  <%s {...props} />
@@ -219,20 +219,20 @@ React keys must be passed directly to JSX without using spread:
219
219
  <%s key={someKey} {...props} />`,
220
220
  E,
221
221
  m,
222
- L,
222
+ P,
223
223
  m
224
- ), Z[m + E] = !0);
224
+ ), k[m + E] = !0);
225
225
  }
226
- if (m = null, h !== void 0 && (r(h), m = "" + h), n(u) && (r(u.key), m = "" + u.key), "key" in u) {
226
+ if (m = null, h !== void 0 && (r(h), m = "" + h), s(u) && (r(u.key), m = "" + u.key), "key" in u) {
227
227
  h = {};
228
228
  for (var W in u)
229
229
  W !== "key" && (h[W] = u[W]);
230
230
  } else h = u;
231
231
  return m && f(
232
232
  h,
233
- typeof s == "function" ? s.displayName || s.name || "Unknown" : s
233
+ typeof a == "function" ? a.displayName || a.name || "Unknown" : a
234
234
  ), S(
235
- s,
235
+ a,
236
236
  m,
237
237
  T,
238
238
  y,
@@ -242,58 +242,58 @@ React keys must be passed directly to JSX without using spread:
242
242
  q
243
243
  );
244
244
  }
245
- function l(s) {
246
- typeof s == "object" && s !== null && s.$$typeof === b && s._store && (s._store.validated = 1);
245
+ function l(a) {
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"), P = 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"), 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() {
249
249
  return null;
250
250
  };
251
251
  _ = {
252
- react_stack_bottom_frame: function(s) {
253
- return s();
252
+ react_stack_bottom_frame: function(a) {
253
+ return a();
254
254
  }
255
255
  };
256
- var M, X = {}, k = _.react_stack_bottom_frame.bind(
256
+ var M, X = {}, H = _.react_stack_bottom_frame.bind(
257
257
  _,
258
- a
259
- )(), H = Y(t(a)), Z = {};
260
- D.Fragment = x, D.jsx = function(s, u, h, E, y) {
258
+ n
259
+ )(), Z = Y(t(n)), k = {};
260
+ C.Fragment = x, C.jsx = function(a, u, h, E, y) {
261
261
  var T = 1e4 > $.recentlyCreatedOwnerStacks++;
262
262
  return p(
263
- s,
263
+ a,
264
264
  u,
265
265
  h,
266
266
  !1,
267
267
  E,
268
268
  y,
269
- T ? Error("react-stack-top-frame") : k,
270
- T ? Y(t(s)) : H
269
+ T ? Error("react-stack-top-frame") : H,
270
+ T ? Y(t(a)) : Z
271
271
  );
272
- }, D.jsxs = function(s, u, h, E, y) {
272
+ }, C.jsxs = function(a, u, h, E, y) {
273
273
  var T = 1e4 > $.recentlyCreatedOwnerStacks++;
274
274
  return p(
275
- s,
275
+ a,
276
276
  u,
277
277
  h,
278
278
  !0,
279
279
  E,
280
280
  y,
281
- T ? Error("react-stack-top-frame") : k,
282
- T ? Y(t(s)) : H
281
+ T ? Error("react-stack-top-frame") : H,
282
+ T ? Y(t(a)) : Z
283
283
  );
284
284
  };
285
- })()), D;
285
+ })()), C;
286
286
  }
287
287
  var ee;
288
288
  function we() {
289
289
  return ee || (ee = 1, process.env.NODE_ENV === "production" ? F.exports = _e() : F.exports = Re()), F.exports;
290
290
  }
291
291
  var Te = we();
292
- let se = !1;
292
+ let ne = !1;
293
293
  const $e = (o) => {
294
- se = o;
294
+ ne = o;
295
295
  }, G = (...o) => {
296
- se && console.log(
296
+ ne && console.log(
297
297
  "%c[react-shared-states]",
298
298
  "color: #007acc; font-weight: bold",
299
299
  ...o
@@ -343,16 +343,16 @@ class d {
343
343
  }
344
344
  clearAll(e = !1, r = !1) {
345
345
  this.data.forEach((t, i) => {
346
- const [a, n] = d.extractPrefix(i);
347
- this.clear(n, a, e, r);
346
+ const [n, s] = d.extractPrefix(i);
347
+ this.clear(s, n, e, r);
348
348
  });
349
349
  }
350
350
  clear(e, r, t = !1, i = !1) {
351
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 && !i) {
352
+ const n = this.data.get(d.prefix(e, r));
353
+ if (!n) return;
354
+ const s = { ...n };
355
+ if (this.data.delete(d.prefix(e, r)), s.isStatic && !i) {
356
356
  const f = te.find((c) => c.key === e && c.prefix === r);
357
357
  f && this.initStatic(f);
358
358
  }
@@ -379,7 +379,7 @@ class d {
379
379
  return e.split("//");
380
380
  }
381
381
  useEffect(e, r, t = null) {
382
- ne(() => () => {
382
+ se(() => () => {
383
383
  t?.(), G(`[${d.prefix(e, r)}]`, "unmount effect"), this.data.get(d.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
384
384
  }, []);
385
385
  }
@@ -395,24 +395,24 @@ class U {
395
395
  t = f, i = c;
396
396
  } else
397
397
  t = j(e);
398
- const a = i || "_global";
399
- return this.sharedData.get(t, a);
398
+ const n = i || "_global";
399
+ return this.sharedData.get(t, n);
400
400
  }
401
401
  set(e, r, t) {
402
- let i, a = t;
402
+ let i, n = t;
403
403
  if (typeof e != "string") {
404
404
  const { key: f, prefix: c } = e;
405
- i = f, a = c;
405
+ i = f, n = c;
406
406
  } else
407
407
  i = j(e);
408
- const n = a || "_global";
409
- this.sharedData.init(i, n, r), this.sharedData.setValue(i, n, r), this.sharedData.callListeners(i, n);
408
+ const s = n || "_global";
409
+ this.sharedData.init(i, s, r), this.sharedData.setValue(i, s, r), this.sharedData.callListeners(i, s);
410
410
  }
411
411
  update(e, r, t) {
412
412
  let i;
413
413
  typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
414
- const a = r(i);
415
- typeof e == "string" ? this.set(e, a, t) : this.set(e, a);
414
+ const n = r(i);
415
+ typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
416
416
  }
417
417
  /**
418
418
  * clear all values from the shared data
@@ -427,9 +427,9 @@ class U {
427
427
  clearScope(e) {
428
428
  const r = e || "_global";
429
429
  this.sharedData.data.forEach((t, i) => {
430
- const [a, n] = d.extractPrefix(i);
431
- if (a === r) {
432
- this.sharedData.clear(n, a), this.sharedData.callListeners(n, a);
430
+ const [n, s] = d.extractPrefix(i);
431
+ if (n === r) {
432
+ this.sharedData.clear(s, n), this.sharedData.callListeners(s, n);
433
433
  return;
434
434
  }
435
435
  });
@@ -461,10 +461,16 @@ class U {
461
461
  getAll() {
462
462
  const e = {};
463
463
  return this.sharedData.data.forEach((r, t) => {
464
- const [i, a] = d.extractPrefix(t);
465
- e[i] = e[i] || {}, e[i][a] = r;
464
+ const [i, n] = d.extractPrefix(t);
465
+ e[i] = e[i] || {}, e[i][n] = r;
466
466
  }), e;
467
467
  }
468
+ subscribe(e, r, t) {
469
+ let i, n;
470
+ return typeof e == "string" ? (i = e, n = t || "_global") : (i = e.key, n = e.prefix), this.sharedData.addListener(i, n, r), () => {
471
+ this.sharedData.removeListener(i, n, r);
472
+ };
473
+ }
468
474
  }
469
475
  const N = (o) => {
470
476
  const e = Ae();
@@ -477,55 +483,55 @@ function ye() {
477
483
  if (re) return z;
478
484
  re = 1;
479
485
  var o = typeof Element < "u", e = typeof Map == "function", r = typeof Set == "function", t = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
480
- function i(a, n) {
481
- if (a === n) return !0;
482
- if (a && n && typeof a == "object" && typeof n == "object") {
483
- if (a.constructor !== n.constructor) return !1;
486
+ function i(n, s) {
487
+ if (n === s) return !0;
488
+ if (n && s && typeof n == "object" && typeof s == "object") {
489
+ if (n.constructor !== s.constructor) return !1;
484
490
  var f, c, S;
485
- if (Array.isArray(a)) {
486
- if (f = a.length, f != n.length) return !1;
491
+ if (Array.isArray(n)) {
492
+ if (f = n.length, f != s.length) return !1;
487
493
  for (c = f; c-- !== 0; )
488
- if (!i(a[c], n[c])) return !1;
494
+ if (!i(n[c], s[c])) return !1;
489
495
  return !0;
490
496
  }
491
497
  var p;
492
- if (e && a instanceof Map && n instanceof Map) {
493
- if (a.size !== n.size) return !1;
494
- for (p = a.entries(); !(c = p.next()).done; )
495
- if (!n.has(c.value[0])) return !1;
496
- for (p = a.entries(); !(c = p.next()).done; )
497
- if (!i(c.value[1], n.get(c.value[0]))) return !1;
498
+ if (e && n instanceof Map && s instanceof Map) {
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;
498
504
  return !0;
499
505
  }
500
- if (r && a instanceof Set && n instanceof Set) {
501
- if (a.size !== n.size) return !1;
502
- for (p = a.entries(); !(c = p.next()).done; )
503
- if (!n.has(c.value[0])) return !1;
506
+ if (r && n instanceof Set && s instanceof Set) {
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;
504
510
  return !0;
505
511
  }
506
- if (t && ArrayBuffer.isView(a) && ArrayBuffer.isView(n)) {
507
- if (f = a.length, f != n.length) return !1;
512
+ if (t && ArrayBuffer.isView(n) && ArrayBuffer.isView(s)) {
513
+ if (f = n.length, f != s.length) return !1;
508
514
  for (c = f; c-- !== 0; )
509
- if (a[c] !== n[c]) return !1;
515
+ if (n[c] !== s[c]) return !1;
510
516
  return !0;
511
517
  }
512
- if (a.constructor === RegExp) return a.source === n.source && a.flags === n.flags;
513
- if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf == "function" && typeof n.valueOf == "function") return a.valueOf() === n.valueOf();
514
- if (a.toString !== Object.prototype.toString && typeof a.toString == "function" && typeof n.toString == "function") return a.toString() === n.toString();
515
- if (S = Object.keys(a), f = S.length, f !== Object.keys(n).length) return !1;
518
+ if (n.constructor === RegExp) return n.source === s.source && n.flags === s.flags;
519
+ if (n.valueOf !== Object.prototype.valueOf && typeof n.valueOf == "function" && typeof s.valueOf == "function") return n.valueOf() === s.valueOf();
520
+ if (n.toString !== Object.prototype.toString && typeof n.toString == "function" && typeof s.toString == "function") return n.toString() === s.toString();
521
+ if (S = Object.keys(n), f = S.length, f !== Object.keys(s).length) return !1;
516
522
  for (c = f; c-- !== 0; )
517
- if (!Object.prototype.hasOwnProperty.call(n, S[c])) return !1;
518
- if (o && a instanceof Element) return !1;
523
+ if (!Object.prototype.hasOwnProperty.call(s, S[c])) return !1;
524
+ if (o && n instanceof Element) return !1;
519
525
  for (c = f; c-- !== 0; )
520
- if (!((S[c] === "_owner" || S[c] === "__v" || S[c] === "__o") && a.$$typeof) && !i(a[S[c]], n[S[c]]))
526
+ if (!((S[c] === "_owner" || S[c] === "__v" || S[c] === "__o") && n.$$typeof) && !i(n[S[c]], s[S[c]]))
521
527
  return !1;
522
528
  return !0;
523
529
  }
524
- return a !== a && n !== n;
530
+ return n !== n && s !== s;
525
531
  }
526
- return z = function(n, f) {
532
+ return z = function(s, f) {
527
533
  try {
528
- return i(n, f);
534
+ return i(s, f);
529
535
  } catch (c) {
530
536
  if ((c.message || "").match(/stack|recursion/i))
531
537
  return console.warn("react-fast-compare cannot handle circular refs"), !1;
@@ -534,8 +540,8 @@ function ye() {
534
540
  }, z;
535
541
  }
536
542
  var Oe = ye();
537
- const Pe = /* @__PURE__ */ me(Oe);
538
- class Le extends d {
543
+ const Le = /* @__PURE__ */ me(Oe);
544
+ class Pe extends d {
539
545
  defaultValue() {
540
546
  return { value: void 0 };
541
547
  }
@@ -564,27 +570,27 @@ class je extends U {
564
570
  update(e, r, t = "_global") {
565
571
  let i;
566
572
  typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
567
- const a = r(i);
568
- typeof e == "string" ? this.set(e, a, t) : this.set(e, a);
573
+ const n = r(i);
574
+ typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
569
575
  }
570
576
  }
571
- const R = new Le(), Ie = new je(R), qe = (o, e) => R.createStatic({ initialValue: o }, e);
577
+ const R = new Pe(), Ie = new je(R), qe = (o, e) => R.createStatic({ initialValue: o }, e);
572
578
  function We(o, e, r) {
573
- let t, i, a = r;
579
+ let t, i, n = r;
574
580
  if (typeof o != "string") {
575
581
  const { key: l, initialValue: _, prefix: b } = o;
576
- t = l, i = _, a = b;
582
+ t = l, i = _, n = b;
577
583
  } else
578
584
  t = j(o), i = e;
579
- const { prefix: n } = N(a);
580
- R.initValue(t, n, i);
581
- const f = A(() => (l) => (R.initValue(t, n, e), R.addListener(t, n, l), () => {
582
- R.removeListener(t, n, l);
583
- }), []), c = A(() => () => R.get(t, n)?.value, []), S = V(f, c), p = (l) => {
584
- const _ = typeof l == "function" ? l(R.get(t, n)?.value) : l;
585
- _ !== S && (R.setValue(t, n, { value: _ }), R.callListeners(t, n));
585
+ const { prefix: s } = N(n);
586
+ R.initValue(t, s, i);
587
+ const f = A(() => (l) => (R.initValue(t, s, e), R.addListener(t, s, l), () => {
588
+ R.removeListener(t, s, l);
589
+ }), []), c = A(() => () => R.get(t, s)?.value, []), S = V(f, c), p = (l) => {
590
+ const _ = typeof l == "function" ? l(R.get(t, s)?.value) : l;
591
+ _ !== S && (R.setValue(t, s, { value: _ }), R.callListeners(t, s));
586
592
  };
587
- return R.useEffect(t, n), [
593
+ return R.useEffect(t, s), [
588
594
  S,
589
595
  p
590
596
  ];
@@ -596,15 +602,15 @@ function ze(o, e, r) {
596
602
  t = p, i = l;
597
603
  } else
598
604
  t = j(o);
599
- const { prefix: a } = N(i), n = Ee(void 0), f = A(() => (p) => (R.addListener(t, a, p), () => {
600
- R.removeListener(t, a, p);
605
+ const { prefix: n } = N(i), s = Ee(void 0), f = A(() => (p) => (R.addListener(t, n, p), () => {
606
+ R.removeListener(t, n, p);
601
607
  }), []), c = A(() => () => {
602
- const p = R.get(t, a)?.value, l = e(p);
603
- return Pe(n.current, l) ? n.current : l;
608
+ const p = R.get(t, n)?.value, l = e(p);
609
+ return Le(s.current, l) ? s.current : l;
604
610
  }, []), S = V(f, c);
605
- return R.useEffect(t, a), S;
611
+ return R.useEffect(t, n), S;
606
612
  }
607
- class Ce extends d {
613
+ class De extends d {
608
614
  defaultValue() {
609
615
  return {
610
616
  fnState: {
@@ -621,7 +627,7 @@ class Ce extends d {
621
627
  super.setValue(e, r, t);
622
628
  }
623
629
  }
624
- class De extends U {
630
+ class Ce extends U {
625
631
  constructor(e) {
626
632
  super(e);
627
633
  }
@@ -638,41 +644,41 @@ class De extends U {
638
644
  update(e, r, t = "_global") {
639
645
  let i;
640
646
  typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
641
- const a = r(i);
642
- typeof e == "string" ? this.set(e, a, t) : this.set(e, a);
647
+ const n = r(i);
648
+ typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
643
649
  }
644
650
  }
645
- const w = new Ce(), Ge = new De(w), Ue = (o, e) => w.createStatic({ fn: o }, e);
651
+ const w = new De(), Ge = new Ce(w), Ue = (o, e) => w.createStatic({ fn: o }, e);
646
652
  function Be(o, e, r) {
647
- let t, i, a = r;
653
+ let t, i, n = r;
648
654
  if (typeof o != "string") {
649
655
  const { key: l, fn: _, prefix: b } = o;
650
- t = l, i = _, a = b;
656
+ t = l, i = _, n = b;
651
657
  } else
652
658
  t = j(o), i = e;
653
- const { prefix: n } = N(a);
654
- w.initValue(t, n);
659
+ const { prefix: s } = N(n);
660
+ w.initValue(t, s);
655
661
  const f = A(
656
- () => (l) => (w.initValue(t, n), w.addListener(t, n, l), () => {
657
- w.removeListener(t, n, l);
662
+ () => (l) => (w.initValue(t, s), w.addListener(t, s, l), () => {
663
+ w.removeListener(t, s, l);
658
664
  }),
659
665
  []
660
666
  ), c = A(
661
- () => () => w.get(t, n).fnState,
667
+ () => () => w.get(t, s).fnState,
662
668
  []
663
669
  ), S = V(f, c), p = async (l, ..._) => {
664
- const b = w.get(t, n);
670
+ const b = w.get(t, s);
665
671
  if (!l && (b.fnState.isLoading || b.fnState.results !== void 0)) return b.fnState;
666
- b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, w.callListeners(t, n);
672
+ b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, w.callListeners(t, s);
667
673
  try {
668
674
  const v = await i(..._);
669
675
  b.fnState = { results: v, isLoading: !1, error: void 0 };
670
676
  } catch (v) {
671
677
  b.fnState = { ...b.fnState, isLoading: !1, error: v };
672
678
  }
673
- w.callListeners(t, n);
679
+ w.callListeners(t, s);
674
680
  };
675
- return w.useEffect(t, n), {
681
+ return w.useEffect(t, s), {
676
682
  state: S,
677
683
  trigger: (...l) => {
678
684
  p(!1, ...l);
@@ -681,8 +687,8 @@ function Be(o, e, r) {
681
687
  p(!0, ...l);
682
688
  },
683
689
  clear: () => {
684
- const l = w.get(t, n);
685
- l && (l.fnState = w.defaultValue().fnState, w.callListeners(t, n));
690
+ const l = w.get(t, s);
691
+ l && (l.fnState = w.defaultValue().fnState, w.callListeners(t, s));
686
692
  }
687
693
  };
688
694
  }
@@ -704,7 +710,7 @@ class Fe extends d {
704
710
  super.setValue(e, r, t);
705
711
  }
706
712
  useEffect(e, r) {
707
- ne(() => () => {
713
+ se(() => () => {
708
714
  G(`[${d.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
709
715
  }, []), super.useEffect(e, r);
710
716
  }
@@ -730,51 +736,51 @@ class Ve extends U {
730
736
  update(e, r, t = "_global") {
731
737
  let i;
732
738
  typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
733
- const a = r(i);
734
- typeof e == "string" ? this.set(e, a, t) : this.set(e, a);
739
+ const n = r(i);
740
+ typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
735
741
  }
736
742
  }
737
743
  const g = new Fe(), Je = new Ve(g), Me = (o, e) => g.createStatic({ subscriber: o }, e);
738
744
  function Xe(o, e, r) {
739
- let t, i, a = r;
745
+ let t, i, n = r;
740
746
  if (typeof o != "string") {
741
747
  const { key: v, subscriber: x, prefix: O } = o;
742
- t = v, i = x, a = O;
748
+ t = v, i = x, n = O;
743
749
  } else
744
750
  t = j(o), i = e;
745
- const { prefix: n } = N(a);
746
- g.initValue(t, n);
751
+ const { prefix: s } = N(n);
752
+ g.initValue(t, s);
747
753
  const f = A(
748
- () => (v) => (g.initValue(t, n), g.addListener(t, n, v), () => {
749
- g.removeListener(t, n, v);
754
+ () => (v) => (g.initValue(t, s), g.addListener(t, s, v), () => {
755
+ g.removeListener(t, s, v);
750
756
  }),
751
757
  []
752
758
  ), c = A(
753
- () => () => g.get(t, n).fnState,
759
+ () => () => g.get(t, s).fnState,
754
760
  []
755
761
  ), S = V(f, c), p = (v) => {
756
- const x = g.get(t, n);
757
- x.fnState = { ...x.fnState, data: v }, g.callListeners(t, n);
762
+ const x = g.get(t, s);
763
+ x.fnState = { ...x.fnState, data: v }, g.callListeners(t, s);
758
764
  }, l = (v) => {
759
- const x = g.get(t, n);
760
- x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: v }, g.callListeners(t, n);
765
+ const x = g.get(t, s);
766
+ x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: v }, g.callListeners(t, s);
761
767
  }, _ = () => {
762
- const v = g.get(t, n);
763
- v.fnState = { ...v.fnState, isLoading: !1 }, g.callListeners(t, n);
768
+ const v = g.get(t, s);
769
+ v.fnState = { ...v.fnState, isLoading: !1 }, g.callListeners(t, s);
764
770
  }, b = async (v) => {
765
- const x = g.get(t, n);
766
- if (v && (await g.unsubscribe(t, n), x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), x.fnState.subscribed) return x.fnState;
767
- G("triggered !!"), x.fnState = { ...x.fnState, isLoading: !0, error: void 0 }, g.callListeners(t, n);
771
+ const x = g.get(t, s);
772
+ if (v && (await g.unsubscribe(t, s), x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), x.fnState.subscribed) return x.fnState;
773
+ G("triggered !!"), x.fnState = { ...x.fnState, isLoading: !0, error: void 0 }, g.callListeners(t, s);
768
774
  try {
769
- const O = await i(p, l, _), P = g.get(t, n);
770
- P.unsubscribe = O, P.fnState.subscribed = !0;
775
+ const O = await i(p, l, _), L = g.get(t, s);
776
+ L.unsubscribe = O, L.fnState.subscribed = !0;
771
777
  } catch (O) {
772
- const P = g.get(t, n);
773
- P.fnState = { ...P.fnState, isLoading: !1, error: O };
778
+ const L = g.get(t, s);
779
+ L.fnState = { ...L.fnState, isLoading: !1, error: O };
774
780
  }
775
- g.callListeners(t, n);
781
+ g.callListeners(t, s);
776
782
  };
777
- return g.useEffect(t, n), {
783
+ return g.useEffect(t, s), {
778
784
  state: S,
779
785
  trigger: () => {
780
786
  b(!1);
@@ -783,19 +789,19 @@ function Xe(o, e, r) {
783
789
  b(!0);
784
790
  },
785
791
  unsubscribe: () => {
786
- g.unsubscribe(t, n);
792
+ g.unsubscribe(t, s);
787
793
  }
788
794
  };
789
795
  }
790
796
  export {
791
- De as SharedFunctionsApi,
797
+ Ce as SharedFunctionsApi,
792
798
  je as SharedStatesApi,
793
799
  Ye as SharedStatesProvider,
794
800
  Ve as SharedSubscriptionsApi,
795
801
  Ue as createSharedFunction,
796
802
  qe as createSharedState,
797
803
  Me as createSharedSubscription,
798
- se as isDevMode,
804
+ ne as isDevMode,
799
805
  $e as setDevMode,
800
806
  Ge as sharedFunctionsApi,
801
807
  Ie as sharedStatesApi,
package/dist/main.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * react-shared-states v1.0.14
2
+ * react-shared-states v1.0.16
3
3
  * (c) Hichem Taboukouyout
4
4
  * Released under the MIT License.
5
5
  * Github: github.com/HichemTab-tech/react-shared-states
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * This source code is licensed under the MIT license found in the
15
15
  * LICENSE file in the root directory of this source tree.
16
- */var J;function ue(){if(J)return C;J=1;var o=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function r(t,i,a){var n=null;if(a!==void 0&&(n=""+a),i.key!==void 0&&(n=""+i.key),"key"in i){a={};for(var f in i)f!=="key"&&(a[f]=i[f])}else a=i;return i=a.ref,{$$typeof:o,type:t,key:n,ref:i!==void 0?i:null,props:a}}return C.Fragment=e,C.jsx=r,C.jsxs=r,C}var F={};/**
16
+ */var J;function ue(){if(J)return C;J=1;var o=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function r(t,i,s){var n=null;if(s!==void 0&&(n=""+s),i.key!==void 0&&(n=""+i.key),"key"in i){s={};for(var f in i)f!=="key"&&(s[f]=i[f])}else s=i;return i=s.ref,{$$typeof:o,type:t,key:n,ref:i!==void 0?i:null,props:s}}return C.Fragment=e,C.jsx=r,C.jsxs=r,C}var F={};/**
17
17
  * @license React
18
18
  * react-jsx-runtime.development.js
19
19
  *
@@ -21,9 +21,9 @@
21
21
  *
22
22
  * This source code is licensed under the MIT license found in the
23
23
  * LICENSE file in the root directory of this source tree.
24
- */var X;function fe(){return X||(X=1,process.env.NODE_ENV!=="production"&&(function(){function o(s){if(s==null)return null;if(typeof s=="function")return s.$$typeof===Ie?null:s.displayName||s.name||null;if(typeof s=="string")return s;switch(s){case x:return"Fragment";case j:return"Profiler";case P:return"StrictMode";case Ve:return"Suspense";case Ne:return"SuspenseList";case Me:return"Activity"}if(typeof s=="object")switch(typeof s.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),s.$$typeof){case m:return"Portal";case Ce:return(s.displayName||"Context")+".Provider";case De:return(s._context.displayName||"Context")+".Consumer";case Fe:var u=s.render;return s=s.displayName,s||(s=u.displayName||u.name||"",s=s!==""?"ForwardRef("+s+")":"ForwardRef"),s;case Ye:return u=s.displayName||null,u!==null?u:o(s.type)||"Memo";case te:u=s._payload,s=s._init;try{return o(s(u))}catch{}}return null}function e(s){return""+s}function r(s){try{e(s);var u=!1}catch{u=!0}if(u){u=console;var g=u.error,R=typeof Symbol=="function"&&Symbol.toStringTag&&s[Symbol.toStringTag]||s.constructor.name||"Object";return g.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",R),e(s)}}function t(s){if(s===x)return"<>";if(typeof s=="object"&&s!==null&&s.$$typeof===te)return"<...>";try{var u=o(s);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function i(){var s=W.A;return s===null?null:s.getOwner()}function a(){return Error("react-stack-top-frame")}function n(s){if(re.call(s,"key")){var u=Object.getOwnPropertyDescriptor(s,"key").get;if(u&&u.isReactWarning)return!1}return s.key!==void 0}function f(s,u){function g(){ne||(ne=!0,console.error("%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)",u))}g.isReactWarning=!0,Object.defineProperty(s,"key",{get:g,configurable:!0})}function c(){var s=o(this.type);return se[s]||(se[s]=!0,console.error("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.")),s=this.props.ref,s!==void 0?s:null}function b(s,u,g,R,O,y,G,U){return g=y.ref,s={$$typeof:E,type:s,key:u,props:y,_owner:O},(g!==void 0?g:null)!==null?Object.defineProperty(s,"ref",{enumerable:!1,get:c}):Object.defineProperty(s,"ref",{enumerable:!1,value:null}),s._store={},Object.defineProperty(s._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(s,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(s,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(s,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(s.props),Object.freeze(s)),s}function S(s,u,g,R,O,y,G,U){var _=u.children;if(_!==void 0)if(R)if(We(_)){for(R=0;R<_.length;R++)l(_[R]);Object.freeze&&Object.freeze(_)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else l(_);if(re.call(u,"key")){_=o(s);var D=Object.keys(u).filter(function(ze){return ze!=="key"});R=0<D.length?"{key: someKey, "+D.join(": ..., ")+": ...}":"{key: someKey}",oe[_+R]||(D=0<D.length?"{"+D.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
24
+ */var X;function fe(){return X||(X=1,process.env.NODE_ENV!=="production"&&(function(){function o(a){if(a==null)return null;if(typeof a=="function")return a.$$typeof===Ie?null:a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case x:return"Fragment";case L:return"Profiler";case P:return"StrictMode";case Ve:return"Suspense";case Ne:return"SuspenseList";case Me:return"Activity"}if(typeof a=="object")switch(typeof a.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),a.$$typeof){case m:return"Portal";case Ce:return(a.displayName||"Context")+".Provider";case De:return(a._context.displayName||"Context")+".Consumer";case Fe:var u=a.render;return a=a.displayName,a||(a=u.displayName||u.name||"",a=a!==""?"ForwardRef("+a+")":"ForwardRef"),a;case Ye:return u=a.displayName||null,u!==null?u:o(a.type)||"Memo";case te:u=a._payload,a=a._init;try{return o(a(u))}catch{}}return null}function e(a){return""+a}function r(a){try{e(a);var u=!1}catch{u=!0}if(u){u=console;var g=u.error,_=typeof Symbol=="function"&&Symbol.toStringTag&&a[Symbol.toStringTag]||a.constructor.name||"Object";return g.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",_),e(a)}}function t(a){if(a===x)return"<>";if(typeof a=="object"&&a!==null&&a.$$typeof===te)return"<...>";try{var u=o(a);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function i(){var a=W.A;return a===null?null:a.getOwner()}function s(){return Error("react-stack-top-frame")}function n(a){if(re.call(a,"key")){var u=Object.getOwnPropertyDescriptor(a,"key").get;if(u&&u.isReactWarning)return!1}return a.key!==void 0}function f(a,u){function g(){ne||(ne=!0,console.error("%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)",u))}g.isReactWarning=!0,Object.defineProperty(a,"key",{get:g,configurable:!0})}function c(){var a=o(this.type);return se[a]||(se[a]=!0,console.error("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.")),a=this.props.ref,a!==void 0?a:null}function b(a,u,g,_,O,y,G,U){return g=y.ref,a={$$typeof:E,type:a,key:u,props:y,_owner:O},(g!==void 0?g:null)!==null?Object.defineProperty(a,"ref",{enumerable:!1,get:c}):Object.defineProperty(a,"ref",{enumerable:!1,value:null}),a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(a,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(a,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(a,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a}function S(a,u,g,_,O,y,G,U){var R=u.children;if(R!==void 0)if(_)if(We(R)){for(_=0;_<R.length;_++)l(R[_]);Object.freeze&&Object.freeze(R)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else l(R);if(re.call(u,"key")){R=o(a);var D=Object.keys(u).filter(function(ze){return ze!=="key"});_=0<D.length?"{key: someKey, "+D.join(": ..., ")+": ...}":"{key: someKey}",oe[R+_]||(D=0<D.length?"{"+D.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
25
25
  let props = %s;
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,_),oe[_+R]=!0)}if(_=null,g!==void 0&&(r(g),_=""+g),n(u)&&(r(u.key),_=""+u.key),"key"in u){g={};for(var B in u)B!=="key"&&(g[B]=u[B])}else g=u;return _&&f(g,typeof s=="function"?s.displayName||s.name||"Unknown":s),b(s,_,y,O,i(),g,G,U)}function l(s){typeof s=="object"&&s!==null&&s.$$typeof===E&&s._store&&(s._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"),j=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(s){return s()}};var ne,se={},ae=A.react_stack_bottom_frame.bind(A,a)(),ie=z(t(a)),oe={};F.Fragment=x,F.jsx=function(s,u,g,R,O){var y=1e4>W.recentlyCreatedOwnerStacks++;return S(s,u,g,!1,R,O,y?Error("react-stack-top-frame"):ae,y?z(t(s)):ie)},F.jsxs=function(s,u,g,R,O){var y=1e4>W.recentlyCreatedOwnerStacks++;return S(s,u,g,!0,R,O,y?Error("react-stack-top-frame"):ae,y?z(t(s)):ie)}})()),F}var k;function le(){return k||(k=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)},L=o=>{if(!o)throw new Error("Value is empty");return o},H=()=>Math.random().toString(36).substring(2,15),Z=h.createContext(void 0),he=({children:o,scopeName:e})=>{if(e&&e.includes("//"))throw new Error("scopeName cannot contain '//'");return e||(e=h.useMemo(()=>H(),[])),de.jsx(Z.Provider,{value:{scopeName:e},children:o})},Se=()=>h.useContext(Z),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:H(),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[a,n]=d.extractPrefix(i);this.clear(n,a,e,r)})}clear(e,r,t=!1,i=!1){t||this.callListeners(e,r);const a=this.data.get(d.prefix(e,r));if(!a)return;const n={...a};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=L(e);const a=i||"_global";return this.sharedData.get(t,a)}set(e,r,t){let i,a=t;if(typeof e!="string"){const{key:f,prefix:c}=e;i=f,a=c}else i=L(e);const n=a||"_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 a=r(i);typeof e=="string"?this.set(e,a,t):this.set(e,a)}clearAll(){this.sharedData.clearAll()}clearScope(e){const r=e||"_global";this.sharedData.data.forEach((t,i)=>{const[a,n]=d.extractPrefix(i);if(a===r){this.sharedData.clear(n,a),this.sharedData.callListeners(n,a);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,a]=d.extractPrefix(t);e[i]=e[i]||{},e[i][a]=r}),e}}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(a,n){if(a===n)return!0;if(a&&n&&typeof a=="object"&&typeof n=="object"){if(a.constructor!==n.constructor)return!1;var f,c,b;if(Array.isArray(a)){if(f=a.length,f!=n.length)return!1;for(c=f;c--!==0;)if(!i(a[c],n[c]))return!1;return!0}var S;if(e&&a instanceof Map&&n instanceof Map){if(a.size!==n.size)return!1;for(S=a.entries();!(c=S.next()).done;)if(!n.has(c.value[0]))return!1;for(S=a.entries();!(c=S.next()).done;)if(!i(c.value[1],n.get(c.value[0])))return!1;return!0}if(r&&a instanceof Set&&n instanceof Set){if(a.size!==n.size)return!1;for(S=a.entries();!(c=S.next()).done;)if(!n.has(c.value[0]))return!1;return!0}if(t&&ArrayBuffer.isView(a)&&ArrayBuffer.isView(n)){if(f=a.length,f!=n.length)return!1;for(c=f;c--!==0;)if(a[c]!==n[c])return!1;return!0}if(a.constructor===RegExp)return a.source===n.source&&a.flags===n.flags;if(a.valueOf!==Object.prototype.valueOf&&typeof a.valueOf=="function"&&typeof n.valueOf=="function")return a.valueOf()===n.valueOf();if(a.toString!==Object.prototype.toString&&typeof a.toString=="function"&&typeof n.toString=="function")return a.toString()===n.toString();if(b=Object.keys(a),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&&a instanceof Element)return!1;for(c=f;c--!==0;)if(!((b[c]==="_owner"||b[c]==="__v"||b[c]==="__o")&&a.$$typeof)&&!i(a[b[c]],n[b[c]]))return!1;return!0}return a!==a&&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 a=r(i);typeof e=="string"?this.set(e,a,t):this.set(e,a)}}const w=new me,Ee=new q(w),xe=(o,e)=>w.createStatic({initialValue:o},e);function Re(o,e,r){let t,i,a=r;if(typeof o!="string"){const{key:l,initialValue:A,prefix:E}=o;t=l,i=A,a=E}else t=L(o),i=e;const{prefix:n}=N(a);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 _e(o,e,r){let t,i=r;if(typeof o!="string"){const{key:S,prefix:l}=o;t=S,i=l}else t=L(o);const{prefix:a}=N(i),n=h.useRef(void 0),f=h.useMemo(()=>S=>(w.addListener(t,a,S),()=>{w.removeListener(t,a,S)}),[]),c=h.useMemo(()=>()=>{const S=w.get(t,a)?.value,l=e(S);return be(n.current,l)?n.current:l},[]),b=h.useSyncExternalStore(f,c);return w.useEffect(t,a),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 a=r(i);typeof e=="string"?this.set(e,a,t):this.set(e,a)}}const T=new we,Ae=new $(T),Te=(o,e)=>T.createStatic({fn:o},e);function ye(o,e,r){let t,i,a=r;if(typeof o!="string"){const{key:l,fn:A,prefix:E}=o;t=l,i=A,a=E}else t=L(o),i=e;const{prefix:n}=N(a);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 a=r(i);typeof e=="string"?this.set(e,a,t):this.set(e,a)}}const v=new Oe,Pe=new ee(v),je=(o,e)=>v.createStatic({subscriber:o},e);function Le(o,e,r){let t,i,a=r;if(typeof o!="string"){const{key:m,subscriber:x,prefix:P}=o;t=m,i=x,a=P}else t=L(o),i=e;const{prefix:n}=N(a);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),j=v.get(t,n);j.unsubscribe=P,j.fnState.subscribed=!0}catch(P){const j=v.get(t,n);j.fnState={...j.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=je,p.setDevMode=pe,p.sharedFunctionsApi=Ae,p.sharedStatesApi=Ee,p.sharedSubscriptionsApi=Pe,p.useSharedFunction=ye,p.useSharedState=Re,p.useSharedStateSelector=_e,p.useSharedSubscription=Le,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"?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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-shared-states",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
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": [
@@ -175,6 +175,26 @@ describe('useSharedState', () => {
175
175
  // Get value after clear (should be initial value because createSharedState re-initializes it)
176
176
  expect(sharedStatesApi.get(sharedCounter)).toBe(100);
177
177
  });
178
+
179
+ it('should be able to subscribe to state changes from api', () => {
180
+ const sharedCounter = createSharedState(100);
181
+
182
+ const subscribeCallback = vi.fn();
183
+
184
+ act(() => {
185
+ sharedStatesApi.subscribe(sharedCounter, () => {
186
+ subscribeCallback();
187
+ expect(sharedStatesApi.get(sharedCounter)).toBe(200);
188
+ });
189
+ });
190
+
191
+ // Update the value
192
+ act(() => {
193
+ sharedStatesApi.set(sharedCounter,200);
194
+ });
195
+
196
+ expect(subscribeCallback).toHaveBeenCalledTimes(1);
197
+ });
178
198
  });
179
199
 
180
200
  describe('useSharedFunction', () => {