react-shared-states 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.esm.js CHANGED
@@ -1,15 +1,15 @@
1
1
  /*!
2
- * react-shared-states v1.0.13
2
+ * react-shared-states v1.0.15
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 T, useContext as xe, useEffect as ne, useSyncExternalStore as N, useRef as Ee } from "react";
9
- function me(i) {
10
- return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
8
+ import ve, { createContext as be, useMemo as A, useContext as xe, useEffect as se, useSyncExternalStore as V, useRef as Ee } from "react";
9
+ function me(o) {
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
@@ -20,28 +20,28 @@ var F = { exports: {} }, C = {};
20
20
  * LICENSE file in the root directory of this source tree.
21
21
  */
22
22
  var Q;
23
- function Re() {
24
- if (Q) return C;
23
+ function _e() {
24
+ if (Q) return D;
25
25
  Q = 1;
26
- var i = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
27
- function r(t, o, a) {
28
- var n = null;
29
- if (a !== void 0 && (n = "" + a), o.key !== void 0 && (n = "" + o.key), "key" in o) {
30
- a = {};
31
- for (var f in o)
32
- f !== "key" && (a[f] = o[f]);
33
- } else a = o;
34
- return o = a.ref, {
35
- $$typeof: i,
26
+ var o = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
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
+ for (var f in i)
32
+ f !== "key" && (n[f] = i[f]);
33
+ } else n = i;
34
+ return i = n.ref, {
35
+ $$typeof: o,
36
36
  type: t,
37
- key: n,
38
- ref: o !== void 0 ? o : null,
39
- props: a
37
+ key: s,
38
+ ref: i !== void 0 ? i : null,
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
@@ -52,17 +52,17 @@ var D = {};
52
52
  * LICENSE file in the root directory of this source tree.
53
53
  */
54
54
  var K;
55
- function _e() {
55
+ function Re() {
56
56
  return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
57
- function i(s) {
58
- if (s == null) return null;
59
- if (typeof s == "function")
60
- return s.$$typeof === he ? null : s.displayName || s.name || null;
61
- if (typeof s == "string") return s;
62
- switch (s) {
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,130 +73,130 @@ function _e() {
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";
84
- case ie:
85
- return (s._context.displayName || "Context") + ".Consumer";
83
+ return (a.displayName || "Context") + ".Provider";
84
+ case oe:
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 : i(s.type) || "Memo";
91
- case U:
92
- u = s._payload, s = s._init;
90
+ return u = a.displayName || null, u !== null ? u : o(a.type) || "Memo";
91
+ case B:
92
+ u = a._payload, a = a._init;
93
93
  try {
94
- return i(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 === U)
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 = i(s);
125
+ var u = o(a);
126
126
  return u ? "<" + u + ">" : "<...>";
127
127
  } catch {
128
128
  return "<...>";
129
129
  }
130
130
  }
131
- function o() {
132
- var s = $.A;
133
- return s === null ? null : s.getOwner();
131
+ function i() {
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 (B.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
- J || (J = !0, console.error(
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 = i(this.type);
159
- return M[s] || (M[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 g(s, u, h, E, A, w, Y, I) {
164
- return h = w.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
- props: w,
169
- _owner: A
170
- }, (h !== void 0 ? h : null) !== null ? Object.defineProperty(s, "ref", {
168
+ props: T,
169
+ _owner: y
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
- value: Y
188
- }), Object.defineProperty(s, "_debugTask", {
187
+ value: I
188
+ }), Object.defineProperty(a, "_debugTask", {
189
189
  configurable: !1,
190
190
  enumerable: !1,
191
191
  writable: !0,
192
- value: I
193
- }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
192
+ value: q
193
+ }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
194
194
  }
195
- function p(s, u, h, E, A, w, Y, I) {
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)
199
- if (Se(m)) {
199
+ if (ge(m)) {
200
200
  for (E = 0; E < m.length; E++)
201
201
  l(m[E]);
202
202
  Object.freeze && Object.freeze(m);
@@ -205,12 +205,12 @@ function _e() {
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 (B.call(u, "key")) {
209
- m = i(s);
210
- var L = Object.keys(u).filter(function(ge) {
211
- return ge !== "key";
208
+ if (J.call(u, "key")) {
209
+ m = o(a);
210
+ var P = Object.keys(u).filter(function(Se) {
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,92 +219,92 @@ 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
- for (var q in u)
229
- q !== "key" && (h[q] = u[q]);
228
+ for (var W in u)
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
234
- ), g(
235
- s,
233
+ typeof a == "function" ? a.displayName || a.name || "Unknown" : a
234
+ ), S(
235
+ a,
236
236
  m,
237
- w,
238
- A,
239
- o(),
237
+ T,
238
+ y,
239
+ i(),
240
240
  h,
241
- Y,
242
- I
241
+ I,
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 R = ve, b = Symbol.for("react.transitional.element"), v = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), ie = Symbol.for("react.consumer"), ce = Symbol.for("react.context"), ue = Symbol.for("react.forward_ref"), fe = Symbol.for("react.suspense"), le = Symbol.for("react.suspense_list"), de = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), pe = Symbol.for("react.activity"), he = Symbol.for("react.client.reference"), $ = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, Se = Array.isArray, V = console.createTask ? console.createTask : function() {
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
- R = {
252
- react_stack_bottom_frame: function(s) {
253
- return s();
251
+ _ = {
252
+ react_stack_bottom_frame: function(a) {
253
+ return a();
254
254
  }
255
255
  };
256
- var J, M = {}, X = R.react_stack_bottom_frame.bind(
257
- R,
258
- a
259
- )(), H = V(t(a)), Z = {};
260
- D.Fragment = x, D.jsx = function(s, u, h, E, A) {
261
- var w = 1e4 > $.recentlyCreatedOwnerStacks++;
256
+ var M, X = {}, H = _.react_stack_bottom_frame.bind(
257
+ _,
258
+ n
259
+ )(), Z = Y(t(n)), k = {};
260
+ C.Fragment = x, C.jsx = function(a, u, h, E, y) {
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
- A,
269
- w ? Error("react-stack-top-frame") : X,
270
- w ? V(t(s)) : H
268
+ y,
269
+ T ? Error("react-stack-top-frame") : H,
270
+ T ? Y(t(a)) : Z
271
271
  );
272
- }, D.jsxs = function(s, u, h, E, A) {
273
- var w = 1e4 > $.recentlyCreatedOwnerStacks++;
272
+ }, C.jsxs = function(a, u, h, E, y) {
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
- A,
281
- w ? Error("react-stack-top-frame") : X,
282
- w ? V(t(s)) : H
280
+ y,
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
- function ye() {
289
- return ee || (ee = 1, process.env.NODE_ENV === "production" ? F.exports = Re() : F.exports = _e()), F.exports;
288
+ function we() {
289
+ return ee || (ee = 1, process.env.NODE_ENV === "production" ? F.exports = _e() : F.exports = Re()), F.exports;
290
290
  }
291
- var we = ye();
292
- let se = !1;
293
- const $e = (i) => {
294
- se = i;
295
- }, z = (...i) => {
296
- se && console.log(
291
+ var Te = we();
292
+ let ne = !1;
293
+ const $e = (o) => {
294
+ ne = o;
295
+ }, G = (...o) => {
296
+ ne && console.log(
297
297
  "%c[react-shared-states]",
298
298
  "color: #007acc; font-weight: bold",
299
- ...i
299
+ ...o
300
300
  );
301
- }, j = (i) => {
302
- if (!i) throw new Error("Value is empty");
303
- return i;
304
- }, ae = () => Math.random().toString(36).substring(2, 15), oe = be(void 0), Ve = ({ children: i, scopeName: e }) => {
301
+ }, j = (o) => {
302
+ if (!o) throw new Error("Value is empty");
303
+ return o;
304
+ }, ae = () => Math.random().toString(36).substring(2, 15), ie = be(void 0), Ye = ({ children: o, scopeName: e }) => {
305
305
  if (e && e.includes("//")) throw new Error("scopeName cannot contain '//'");
306
- return e || (e = T(() => ae(), [])), /* @__PURE__ */ we.jsx(oe.Provider, { value: { scopeName: e }, children: i });
307
- }, Te = () => xe(oe), te = [];
306
+ return e || (e = A(() => ae(), [])), /* @__PURE__ */ Te.jsx(ie.Provider, { value: { scopeName: e }, children: o });
307
+ }, Ae = () => xe(ie), te = [];
308
308
  class d {
309
309
  data = /* @__PURE__ */ new Map();
310
310
  defaultValue() {
@@ -317,42 +317,42 @@ class d {
317
317
  }), this.data.get(d.prefix(e, r)).listeners.push(t);
318
318
  }
319
319
  removeListener(e, r, t) {
320
- this.data.has(d.prefix(e, r)) && (this.data.get(d.prefix(e, r)).listeners = this.data.get(d.prefix(e, r)).listeners.filter((o) => o !== t));
320
+ this.data.has(d.prefix(e, r)) && (this.data.get(d.prefix(e, r)).listeners = this.data.get(d.prefix(e, r)).listeners.filter((i) => i !== t));
321
321
  }
322
322
  callListeners(e, r) {
323
323
  this.data.has(d.prefix(e, r)) && this.data.get(d.prefix(e, r)).listeners.forEach((t) => t());
324
324
  }
325
- init(e, r, t, o = !1) {
325
+ init(e, r, t, i = !1) {
326
326
  this.data.has(d.prefix(e, r)) || this.data.set(d.prefix(e, r), {
327
327
  ...t,
328
- isStatic: o,
328
+ isStatic: i,
329
329
  listeners: []
330
330
  });
331
331
  }
332
332
  createStatic(e, r) {
333
- const t = r ?? r ?? "_global", o = {
333
+ const t = r ?? r ?? "_global", i = {
334
334
  key: ae(),
335
335
  prefix: t,
336
336
  ...e
337
337
  };
338
- return te.push(o), this.initStatic(o), o;
338
+ return te.push(i), this.initStatic(i), i;
339
339
  }
340
340
  initStatic(e) {
341
341
  const { key: r, prefix: t } = e;
342
342
  this.init(r, t, this.defaultValue(), !0);
343
343
  }
344
344
  clearAll(e = !1, r = !1) {
345
- this.data.forEach((t, o) => {
346
- const [a, n] = d.extractPrefix(o);
347
- this.clear(n, a, e, r);
345
+ this.data.forEach((t, i) => {
346
+ const [n, s] = d.extractPrefix(i);
347
+ this.clear(s, n, e, r);
348
348
  });
349
349
  }
350
- clear(e, r, t = !1, o = !1) {
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 && !o) {
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,34 +379,40 @@ class d {
379
379
  return e.split("//");
380
380
  }
381
381
  useEffect(e, r, t = null) {
382
- ne(() => () => {
383
- t?.(), z(`[${d.prefix(e, r)}]`, "unmount effect"), this.data.get(d.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
382
+ se(() => () => {
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
  }
386
386
  }
387
- class G {
387
+ class U {
388
388
  constructor(e) {
389
389
  this.sharedData = e;
390
390
  }
391
391
  get(e, r) {
392
- let t, o = r;
392
+ let t, i = r;
393
393
  if (typeof e != "string") {
394
394
  const { key: f, prefix: c } = e;
395
- t = f, o = c;
395
+ t = f, i = c;
396
396
  } else
397
397
  t = j(e);
398
- const a = o || "_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 o, a = t;
402
+ let i, n = t;
403
403
  if (typeof e != "string") {
404
404
  const { key: f, prefix: c } = e;
405
- o = f, a = c;
405
+ i = f, n = c;
406
406
  } else
407
- o = j(e);
408
- const n = a || "_global";
409
- this.sharedData.init(o, n, r), this.sharedData.setValue(o, n, r), this.sharedData.callListeners(o, n);
407
+ i = j(e);
408
+ const s = n || "_global";
409
+ this.sharedData.init(i, s, r), this.sharedData.setValue(i, s, r), this.sharedData.callListeners(i, s);
410
+ }
411
+ update(e, r, t) {
412
+ let i;
413
+ typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
414
+ const n = r(i);
415
+ typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
410
416
  }
411
417
  /**
412
418
  * clear all values from the shared data
@@ -420,10 +426,10 @@ class G {
420
426
  */
421
427
  clearScope(e) {
422
428
  const r = e || "_global";
423
- this.sharedData.data.forEach((t, o) => {
424
- const [a, n] = d.extractPrefix(o);
425
- if (a === r) {
426
- this.sharedData.clear(n, a), this.sharedData.callListeners(n, a);
429
+ this.sharedData.data.forEach((t, i) => {
430
+ const [n, s] = d.extractPrefix(i);
431
+ if (n === r) {
432
+ this.sharedData.clear(s, n), this.sharedData.callListeners(s, n);
427
433
  return;
428
434
  }
429
435
  });
@@ -437,8 +443,8 @@ class G {
437
443
  return this.get(r, t);
438
444
  }
439
445
  clear(e, r) {
440
- let t, o;
441
- typeof e == "string" ? (t = e, o = r || "_global") : (t = e.key, o = e.prefix), this.sharedData.clear(t, o);
446
+ let t, i;
447
+ typeof e == "string" ? (t = e, i = r || "_global") : (t = e.key, i = e.prefix), this.sharedData.clear(t, i);
442
448
  }
443
449
  /**
444
450
  * check if a value exists in the shared data
@@ -455,93 +461,99 @@ class G {
455
461
  getAll() {
456
462
  const e = {};
457
463
  return this.sharedData.data.forEach((r, t) => {
458
- const [o, a] = d.extractPrefix(t);
459
- e[o] = e[o] || {}, e[o][a] = r;
464
+ const [i, n] = d.extractPrefix(t);
465
+ e[i] = e[i] || {}, e[i][n] = r;
460
466
  }), e;
461
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
+ }
462
474
  }
463
- const k = (i) => {
464
- const e = Te();
475
+ const N = (o) => {
476
+ const e = Ae();
465
477
  return {
466
- prefix: i ?? e?.scopeName ?? "_global"
478
+ prefix: o ?? e?.scopeName ?? "_global"
467
479
  };
468
480
  };
469
- var W, re;
470
- function Ae() {
471
- if (re) return W;
481
+ var z, re;
482
+ function ye() {
483
+ if (re) return z;
472
484
  re = 1;
473
- var i = typeof Element < "u", e = typeof Map == "function", r = typeof Set == "function", t = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
474
- function o(a, n) {
475
- if (a === n) return !0;
476
- if (a && n && typeof a == "object" && typeof n == "object") {
477
- if (a.constructor !== n.constructor) return !1;
478
- var f, c, g;
479
- if (Array.isArray(a)) {
480
- if (f = a.length, f != n.length) return !1;
485
+ var o = typeof Element < "u", e = typeof Map == "function", r = typeof Set == "function", t = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
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;
490
+ var f, c, S;
491
+ if (Array.isArray(n)) {
492
+ if (f = n.length, f != s.length) return !1;
481
493
  for (c = f; c-- !== 0; )
482
- if (!o(a[c], n[c])) return !1;
494
+ if (!i(n[c], s[c])) return !1;
483
495
  return !0;
484
496
  }
485
497
  var p;
486
- if (e && a instanceof Map && n instanceof Map) {
487
- if (a.size !== n.size) return !1;
488
- for (p = a.entries(); !(c = p.next()).done; )
489
- if (!n.has(c.value[0])) return !1;
490
- for (p = a.entries(); !(c = p.next()).done; )
491
- if (!o(c.value[1], n.get(c.value[0]))) return !1;
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;
492
504
  return !0;
493
505
  }
494
- if (r && a instanceof Set && n instanceof Set) {
495
- if (a.size !== n.size) return !1;
496
- for (p = a.entries(); !(c = p.next()).done; )
497
- if (!n.has(c.value[0])) return !1;
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;
498
510
  return !0;
499
511
  }
500
- if (t && ArrayBuffer.isView(a) && ArrayBuffer.isView(n)) {
501
- 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;
502
514
  for (c = f; c-- !== 0; )
503
- if (a[c] !== n[c]) return !1;
515
+ if (n[c] !== s[c]) return !1;
504
516
  return !0;
505
517
  }
506
- if (a.constructor === RegExp) return a.source === n.source && a.flags === n.flags;
507
- if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf == "function" && typeof n.valueOf == "function") return a.valueOf() === n.valueOf();
508
- if (a.toString !== Object.prototype.toString && typeof a.toString == "function" && typeof n.toString == "function") return a.toString() === n.toString();
509
- if (g = Object.keys(a), f = g.length, f !== Object.keys(n).length) return !1;
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;
510
522
  for (c = f; c-- !== 0; )
511
- if (!Object.prototype.hasOwnProperty.call(n, g[c])) return !1;
512
- if (i && a instanceof Element) return !1;
523
+ if (!Object.prototype.hasOwnProperty.call(s, S[c])) return !1;
524
+ if (o && n instanceof Element) return !1;
513
525
  for (c = f; c-- !== 0; )
514
- if (!((g[c] === "_owner" || g[c] === "__v" || g[c] === "__o") && a.$$typeof) && !o(a[g[c]], n[g[c]]))
526
+ if (!((S[c] === "_owner" || S[c] === "__v" || S[c] === "__o") && n.$$typeof) && !i(n[S[c]], s[S[c]]))
515
527
  return !1;
516
528
  return !0;
517
529
  }
518
- return a !== a && n !== n;
530
+ return n !== n && s !== s;
519
531
  }
520
- return W = function(n, f) {
532
+ return z = function(s, f) {
521
533
  try {
522
- return o(n, f);
534
+ return i(s, f);
523
535
  } catch (c) {
524
536
  if ((c.message || "").match(/stack|recursion/i))
525
537
  return console.warn("react-fast-compare cannot handle circular refs"), !1;
526
538
  throw c;
527
539
  }
528
- }, W;
540
+ }, z;
529
541
  }
530
- var Oe = Ae();
531
- const Pe = /* @__PURE__ */ me(Oe);
532
- class Le extends d {
542
+ var Oe = ye();
543
+ const Le = /* @__PURE__ */ me(Oe);
544
+ class Pe extends d {
533
545
  defaultValue() {
534
546
  return { value: void 0 };
535
547
  }
536
- initValue(e, r, t, o = !1) {
537
- super.init(e, r, { value: t }, o);
548
+ initValue(e, r, t, i = !1) {
549
+ super.init(e, r, { value: t }, i);
538
550
  }
539
551
  initStatic(e) {
540
- const { key: r, prefix: t, initialValue: o } = e;
541
- this.initValue(r, t, o, !0);
552
+ const { key: r, prefix: t, initialValue: i } = e;
553
+ this.initValue(r, t, i, !0);
542
554
  }
543
555
  }
544
- class je extends G {
556
+ class je extends U {
545
557
  constructor(e) {
546
558
  super(e);
547
559
  }
@@ -555,44 +567,50 @@ class je extends G {
555
567
  }
556
568
  super.set(e, { value: r }, t);
557
569
  }
570
+ update(e, r, t = "_global") {
571
+ let i;
572
+ typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
573
+ const n = r(i);
574
+ typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
575
+ }
558
576
  }
559
- const _ = new Le(), Ye = new je(_), Ie = (i, e) => _.createStatic({ initialValue: i }, e);
560
- function qe(i, e, r) {
561
- let t, o, a = r;
562
- if (typeof i != "string") {
563
- const { key: l, initialValue: R, prefix: b } = i;
564
- t = l, o = R, a = b;
577
+ const R = new Pe(), Ie = new je(R), qe = (o, e) => R.createStatic({ initialValue: o }, e);
578
+ function We(o, e, r) {
579
+ let t, i, n = r;
580
+ if (typeof o != "string") {
581
+ const { key: l, initialValue: _, prefix: b } = o;
582
+ t = l, i = _, n = b;
565
583
  } else
566
- t = j(i), o = e;
567
- const { prefix: n } = k(a);
568
- _.initValue(t, n, o);
569
- const f = T(() => (l) => (_.initValue(t, n, e), _.addListener(t, n, l), () => {
570
- _.removeListener(t, n, l);
571
- }), []), c = T(() => () => _.get(t, n)?.value, []), g = N(f, c), p = (l) => {
572
- const R = typeof l == "function" ? l(_.get(t, n)?.value) : l;
573
- R !== g && (_.setValue(t, n, { value: R }), _.callListeners(t, n));
584
+ t = j(o), i = e;
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));
574
592
  };
575
- return _.useEffect(t, n), [
576
- g,
593
+ return R.useEffect(t, s), [
594
+ S,
577
595
  p
578
596
  ];
579
597
  }
580
- function We(i, e, r) {
581
- let t, o = r;
582
- if (typeof i != "string") {
583
- const { key: p, prefix: l } = i;
584
- t = p, o = l;
598
+ function ze(o, e, r) {
599
+ let t, i = r;
600
+ if (typeof o != "string") {
601
+ const { key: p, prefix: l } = o;
602
+ t = p, i = l;
585
603
  } else
586
- t = j(i);
587
- const { prefix: a } = k(o), n = Ee(void 0), f = T(() => (p) => (_.addListener(t, a, p), () => {
588
- _.removeListener(t, a, p);
589
- }), []), c = T(() => () => {
590
- const p = _.get(t, a)?.value, l = e(p);
591
- return Pe(n.current, l) ? n.current : l;
592
- }, []), g = N(f, c);
593
- return _.useEffect(t, a), g;
604
+ t = j(o);
605
+ const { prefix: n } = N(i), s = Ee(void 0), f = A(() => (p) => (R.addListener(t, n, p), () => {
606
+ R.removeListener(t, n, p);
607
+ }), []), c = A(() => () => {
608
+ const p = R.get(t, n)?.value, l = e(p);
609
+ return Le(s.current, l) ? s.current : l;
610
+ }, []), S = V(f, c);
611
+ return R.useEffect(t, n), S;
594
612
  }
595
- class Ce extends d {
613
+ class De extends d {
596
614
  defaultValue() {
597
615
  return {
598
616
  fnState: {
@@ -609,7 +627,7 @@ class Ce extends d {
609
627
  super.setValue(e, r, t);
610
628
  }
611
629
  }
612
- class De extends G {
630
+ class Ce extends U {
613
631
  constructor(e) {
614
632
  super(e);
615
633
  }
@@ -623,39 +641,45 @@ class De extends G {
623
641
  }
624
642
  super.set(e, r, t);
625
643
  }
644
+ update(e, r, t = "_global") {
645
+ let i;
646
+ typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
647
+ const n = r(i);
648
+ typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
649
+ }
626
650
  }
627
- const y = new Ce(), ze = new De(y), Ge = (i, e) => y.createStatic({ fn: i }, e);
628
- function Ue(i, e, r) {
629
- let t, o, a = r;
630
- if (typeof i != "string") {
631
- const { key: l, fn: R, prefix: b } = i;
632
- t = l, o = R, a = b;
651
+ const w = new De(), Ge = new Ce(w), Ue = (o, e) => w.createStatic({ fn: o }, e);
652
+ function Be(o, e, r) {
653
+ let t, i, n = r;
654
+ if (typeof o != "string") {
655
+ const { key: l, fn: _, prefix: b } = o;
656
+ t = l, i = _, n = b;
633
657
  } else
634
- t = j(i), o = e;
635
- const { prefix: n } = k(a);
636
- y.initValue(t, n);
637
- const f = T(
638
- () => (l) => (y.initValue(t, n), y.addListener(t, n, l), () => {
639
- y.removeListener(t, n, l);
658
+ t = j(o), i = e;
659
+ const { prefix: s } = N(n);
660
+ w.initValue(t, s);
661
+ const f = A(
662
+ () => (l) => (w.initValue(t, s), w.addListener(t, s, l), () => {
663
+ w.removeListener(t, s, l);
640
664
  }),
641
665
  []
642
- ), c = T(
643
- () => () => y.get(t, n).fnState,
666
+ ), c = A(
667
+ () => () => w.get(t, s).fnState,
644
668
  []
645
- ), g = N(f, c), p = async (l, ...R) => {
646
- const b = y.get(t, n);
669
+ ), S = V(f, c), p = async (l, ..._) => {
670
+ const b = w.get(t, s);
647
671
  if (!l && (b.fnState.isLoading || b.fnState.results !== void 0)) return b.fnState;
648
- b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, y.callListeners(t, n);
672
+ b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, w.callListeners(t, s);
649
673
  try {
650
- const v = await o(...R);
674
+ const v = await i(..._);
651
675
  b.fnState = { results: v, isLoading: !1, error: void 0 };
652
676
  } catch (v) {
653
677
  b.fnState = { ...b.fnState, isLoading: !1, error: v };
654
678
  }
655
- y.callListeners(t, n);
679
+ w.callListeners(t, s);
656
680
  };
657
- return y.useEffect(t, n), {
658
- state: g,
681
+ return w.useEffect(t, s), {
682
+ state: S,
659
683
  trigger: (...l) => {
660
684
  p(!1, ...l);
661
685
  },
@@ -663,8 +687,8 @@ function Ue(i, e, r) {
663
687
  p(!0, ...l);
664
688
  },
665
689
  clear: () => {
666
- const l = y.get(t, n);
667
- l && (l.fnState = y.defaultValue().fnState, y.callListeners(t, n));
690
+ const l = w.get(t, s);
691
+ l && (l.fnState = w.defaultValue().fnState, w.callListeners(t, s));
668
692
  }
669
693
  };
670
694
  }
@@ -686,8 +710,8 @@ class Fe extends d {
686
710
  super.setValue(e, r, t);
687
711
  }
688
712
  useEffect(e, r) {
689
- ne(() => () => {
690
- z(`[${d.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
713
+ se(() => () => {
714
+ G(`[${d.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
691
715
  }, []), super.useEffect(e, r);
692
716
  }
693
717
  async unsubscribe(e, r) {
@@ -695,7 +719,7 @@ class Fe extends d {
695
719
  t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState = { ...t.fnState, subscribed: !1 }, this.callListeners(e, r));
696
720
  }
697
721
  }
698
- class Ne extends G {
722
+ class Ve extends U {
699
723
  constructor(e) {
700
724
  super(e);
701
725
  }
@@ -709,49 +733,55 @@ class Ne extends G {
709
733
  }
710
734
  super.set(e, r, t);
711
735
  }
736
+ update(e, r, t = "_global") {
737
+ let i;
738
+ typeof e == "string" ? i = this.get(e, t) : i = this.get(e);
739
+ const n = r(i);
740
+ typeof e == "string" ? this.set(e, n, t) : this.set(e, n);
741
+ }
712
742
  }
713
- const S = new Fe(), Be = new Ne(S), Je = (i, e) => S.createStatic({ subscriber: i }, e);
714
- function Me(i, e, r) {
715
- let t, o, a = r;
716
- if (typeof i != "string") {
717
- const { key: v, subscriber: x, prefix: O } = i;
718
- t = v, o = x, a = O;
743
+ const g = new Fe(), Je = new Ve(g), Me = (o, e) => g.createStatic({ subscriber: o }, e);
744
+ function Xe(o, e, r) {
745
+ let t, i, n = r;
746
+ if (typeof o != "string") {
747
+ const { key: v, subscriber: x, prefix: O } = o;
748
+ t = v, i = x, n = O;
719
749
  } else
720
- t = j(i), o = e;
721
- const { prefix: n } = k(a);
722
- S.initValue(t, n);
723
- const f = T(
724
- () => (v) => (S.initValue(t, n), S.addListener(t, n, v), () => {
725
- S.removeListener(t, n, v);
750
+ t = j(o), i = e;
751
+ const { prefix: s } = N(n);
752
+ g.initValue(t, s);
753
+ const f = A(
754
+ () => (v) => (g.initValue(t, s), g.addListener(t, s, v), () => {
755
+ g.removeListener(t, s, v);
726
756
  }),
727
757
  []
728
- ), c = T(
729
- () => () => S.get(t, n).fnState,
758
+ ), c = A(
759
+ () => () => g.get(t, s).fnState,
730
760
  []
731
- ), g = N(f, c), p = (v) => {
732
- const x = S.get(t, n);
733
- x.fnState = { ...x.fnState, data: v }, S.callListeners(t, n);
761
+ ), S = V(f, c), p = (v) => {
762
+ const x = g.get(t, s);
763
+ x.fnState = { ...x.fnState, data: v }, g.callListeners(t, s);
734
764
  }, l = (v) => {
735
- const x = S.get(t, n);
736
- x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: v }, S.callListeners(t, n);
737
- }, R = () => {
738
- const v = S.get(t, n);
739
- v.fnState = { ...v.fnState, isLoading: !1 }, S.callListeners(t, n);
765
+ const x = g.get(t, s);
766
+ x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: v }, g.callListeners(t, s);
767
+ }, _ = () => {
768
+ const v = g.get(t, s);
769
+ v.fnState = { ...v.fnState, isLoading: !1 }, g.callListeners(t, s);
740
770
  }, b = async (v) => {
741
- const x = S.get(t, n);
742
- if (v && (await S.unsubscribe(t, n), x.fnState = { ...x.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), x.fnState.subscribed) return x.fnState;
743
- z("triggered !!"), x.fnState = { ...x.fnState, isLoading: !0, error: void 0 }, S.callListeners(t, n);
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);
744
774
  try {
745
- const O = await o(p, l, R), P = S.get(t, n);
746
- 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;
747
777
  } catch (O) {
748
- const P = S.get(t, n);
749
- P.fnState = { ...P.fnState, isLoading: !1, error: O };
778
+ const L = g.get(t, s);
779
+ L.fnState = { ...L.fnState, isLoading: !1, error: O };
750
780
  }
751
- S.callListeners(t, n);
781
+ g.callListeners(t, s);
752
782
  };
753
- return S.useEffect(t, n), {
754
- state: g,
783
+ return g.useEffect(t, s), {
784
+ state: S,
755
785
  trigger: () => {
756
786
  b(!1);
757
787
  },
@@ -759,25 +789,25 @@ function Me(i, e, r) {
759
789
  b(!0);
760
790
  },
761
791
  unsubscribe: () => {
762
- S.unsubscribe(t, n);
792
+ g.unsubscribe(t, s);
763
793
  }
764
794
  };
765
795
  }
766
796
  export {
767
- De as SharedFunctionsApi,
797
+ Ce as SharedFunctionsApi,
768
798
  je as SharedStatesApi,
769
- Ve as SharedStatesProvider,
770
- Ne as SharedSubscriptionsApi,
771
- Ge as createSharedFunction,
772
- Ie as createSharedState,
773
- Je as createSharedSubscription,
774
- se as isDevMode,
799
+ Ye as SharedStatesProvider,
800
+ Ve as SharedSubscriptionsApi,
801
+ Ue as createSharedFunction,
802
+ qe as createSharedState,
803
+ Me as createSharedSubscription,
804
+ ne as isDevMode,
775
805
  $e as setDevMode,
776
- ze as sharedFunctionsApi,
777
- Ye as sharedStatesApi,
778
- Be as sharedSubscriptionsApi,
779
- Ue as useSharedFunction,
780
- qe as useSharedState,
781
- We as useSharedStateSelector,
782
- Me as useSharedSubscription
806
+ Ge as sharedFunctionsApi,
807
+ Ie as sharedStatesApi,
808
+ Je as sharedSubscriptionsApi,
809
+ Be as useSharedFunction,
810
+ We as useSharedState,
811
+ ze as useSharedStateSelector,
812
+ Xe as useSharedSubscription
783
813
  };