react-shared-states 1.0.5 → 1.0.7

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/.editorconfig CHANGED
@@ -6,4 +6,7 @@ root = true
6
6
  indent_size = 4
7
7
 
8
8
  [*.md]
9
+ indent_size = 2
10
+
11
+ [*.yml]
9
12
  indent_size = 2
@@ -13,14 +13,49 @@ export declare abstract class SharedData<T> {
13
13
  setValue(key: string, prefix: Prefix, data: T): void;
14
14
  has(key: string, prefix: Prefix): string | undefined;
15
15
  static prefix(key: string, prefix: Prefix): string;
16
+ static extractPrefix(mapKey: string): string[];
16
17
  useEffect(key: string, prefix: Prefix, unsub?: (() => void) | null): void;
17
18
  }
18
- export interface SharedApi<T> {
19
- get: <S extends string = string>(key: S, scopeName: Prefix) => T;
20
- set: <S extends string = string>(key: S, value: T, scopeName: Prefix) => void;
21
- clearAll: () => void;
22
- clear: (key: string, scopeName: Prefix) => void;
23
- has: (key: string, scopeName: Prefix) => boolean;
24
- getAll: () => Map<string, DataMapValue>;
19
+ export declare class SharedApi<T> {
20
+ private sharedData;
21
+ constructor(sharedData: SharedData<T>);
22
+ /**
23
+ * get a value from the shared data
24
+ * @param key
25
+ * @param scopeName
26
+ */
27
+ get<S extends string = string>(key: S, scopeName: Prefix): T;
28
+ /**
29
+ * set a value in the shared data
30
+ * @param key
31
+ * @param value
32
+ * @param scopeName
33
+ */
34
+ set<S extends string = string>(key: S, value: T, scopeName: Prefix): void;
35
+ /**
36
+ * clear all values from the shared data
37
+ */
38
+ clearAll(): void;
39
+ /**
40
+ * clear all values from the shared data in a scope
41
+ * @param scopeName
42
+ */
43
+ clearScope(scopeName?: Prefix): void;
44
+ /**
45
+ * clear a value from the shared data
46
+ * @param key
47
+ * @param scopeName
48
+ */
49
+ clear(key: string, scopeName: Prefix): void;
50
+ /**
51
+ * check if a value exists in the shared data
52
+ * @param key
53
+ * @param scopeName
54
+ */
55
+ has(key: string, scopeName?: Prefix): boolean;
56
+ /**
57
+ * get all values from the shared data
58
+ */
59
+ getAll(): Record<string, Record<string, any>>;
25
60
  }
26
61
  export {};
@@ -0,0 +1,2 @@
1
+ export declare let isDevMode: boolean;
2
+ export declare const setDevMode: (value: boolean) => void;
@@ -7,13 +7,9 @@ type SharedFunctionsState<T> = {
7
7
  error?: unknown;
8
8
  };
9
9
  };
10
- export declare class SharedFunctionsApi implements SharedApi<SharedFunctionsState<unknown>> {
10
+ export declare class SharedFunctionsApi extends SharedApi<SharedFunctionsState<unknown>> {
11
11
  get<T, S extends string = string>(key: S, scopeName?: Prefix): T;
12
12
  set<T, S extends string = string>(key: S, fnState: SharedFunctionsState<T>, scopeName?: Prefix): void;
13
- clearAll(): void;
14
- clear(key: string, scopeName?: Prefix): void;
15
- has(key: string, scopeName?: Prefix): boolean;
16
- getAll(): Map<string, import('..').DataMapValue & SharedFunctionsState<unknown>>;
17
13
  }
18
14
  export declare const sharedFunctionsApi: SharedFunctionsApi;
19
15
  export declare const useSharedFunction: <T, Args extends unknown[], S extends string = string>(key: S, fn: AFunction<T, Args>, scopeName?: Prefix) => {
@@ -1,16 +1,10 @@
1
1
  import { Prefix } from '../types';
2
2
  import { SharedApi } from '../SharedData';
3
- declare class SharedStatesApi implements SharedApi<{
3
+ declare class SharedStatesApi extends SharedApi<{
4
4
  value: unknown;
5
5
  }> {
6
6
  get<T, S extends string = string>(key: S, scopeName?: Prefix): T;
7
7
  set<T, S extends string = string>(key: S, value: T, scopeName?: Prefix): void;
8
- clearAll(): void;
9
- clear(key: string, scopeName?: Prefix): void;
10
- has(key: string, scopeName?: Prefix): boolean;
11
- getAll(): Map<string, import('..').DataMapValue & {
12
- value: unknown;
13
- }>;
14
8
  }
15
9
  export declare const sharedStatesApi: SharedStatesApi;
16
10
  export declare const useSharedState: <T, S extends string = string>(key: S, value: T, scopeName?: Prefix) => readonly [T, (newValueOrCallbackToNewValue: T | ((prev: T) => T)) => void];
@@ -16,13 +16,9 @@ type SharedSubscriptionsState<T> = {
16
16
  };
17
17
  unsubscribe?: Unsubscribe | void;
18
18
  };
19
- export declare class SharedSubscriptionsApi implements SharedApi<SharedSubscriptionsState<unknown>> {
19
+ export declare class SharedSubscriptionsApi extends SharedApi<SharedSubscriptionsState<unknown>> {
20
20
  get<T, S extends string = string>(key: S, scopeName?: Prefix): T;
21
21
  set<T, S extends string = string>(key: S, fnState: SharedSubscriptionsState<T>, scopeName?: Prefix): void;
22
- clearAll(): void;
23
- clear(key: string, scopeName?: Prefix): void;
24
- has(key: string, scopeName?: Prefix): boolean;
25
- getAll(): Map<string, import('..').DataMapValue & SharedSubscriptionsState<unknown>>;
26
22
  }
27
23
  export declare const sharedSubscriptionsApi: SharedSubscriptionsApi;
28
24
  export declare const useSharedSubscription: <T, S extends string = string>(key: S, subscriber: Subscriber<T>, scopeName?: Prefix) => {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './context';
2
2
  export * from './hooks';
3
3
  export * from './types';
4
+ export * from './config';
package/dist/main.esm.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * react-shared-states v1.0.5
2
+ * react-shared-states v1.0.7
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 fe, { createContext as de, useMemo as w, useContext as be, useEffect as Q, useSyncExternalStore as I } from "react";
9
- var L = { exports: {} }, P = {};
8
+ import be, { createContext as he, useMemo as w, useContext as ge, useEffect as K, useSyncExternalStore as M } from "react";
9
+ var L = { exports: {} }, O = {};
10
10
  /**
11
11
  * @license React
12
12
  * react-jsx-runtime.production.js
@@ -16,27 +16,27 @@ var L = { exports: {} }, P = {};
16
16
  * This source code is licensed under the MIT license found in the
17
17
  * LICENSE file in the root directory of this source tree.
18
18
  */
19
- var D;
20
- function ge() {
21
- if (D) return P;
22
- D = 1;
19
+ var H;
20
+ function pe() {
21
+ if (H) return O;
22
+ H = 1;
23
23
  var s = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
24
- function r(t, i, b) {
25
- var S = null;
26
- if (b !== void 0 && (S = "" + b), i.key !== void 0 && (S = "" + i.key), "key" in i) {
27
- b = {};
28
- for (var m in i)
29
- m !== "key" && (b[m] = i[m]);
30
- } else b = i;
31
- return i = b.ref, {
24
+ function r(t, o, f) {
25
+ var E = null;
26
+ if (f !== void 0 && (E = "" + f), o.key !== void 0 && (E = "" + o.key), "key" in o) {
27
+ f = {};
28
+ for (var S in o)
29
+ S !== "key" && (f[S] = o[S]);
30
+ } else f = o;
31
+ return o = f.ref, {
32
32
  $$typeof: s,
33
33
  type: t,
34
- key: S,
35
- ref: i !== void 0 ? i : null,
36
- props: b
34
+ key: E,
35
+ ref: o !== void 0 ? o : null,
36
+ props: f
37
37
  };
38
38
  }
39
- return P.Fragment = e, P.jsx = r, P.jsxs = r, P;
39
+ return O.Fragment = e, O.jsx = r, O.jsxs = r, O;
40
40
  }
41
41
  var j = {};
42
42
  /**
@@ -48,42 +48,42 @@ var j = {};
48
48
  * This source code is licensed under the MIT license found in the
49
49
  * LICENSE file in the root directory of this source tree.
50
50
  */
51
- var H;
52
- function pe() {
53
- return H || (H = 1, process.env.NODE_ENV !== "production" && function() {
51
+ var Z;
52
+ function Ee() {
53
+ return Z || (Z = 1, process.env.NODE_ENV !== "production" && function() {
54
54
  function s(n) {
55
55
  if (n == null) return null;
56
56
  if (typeof n == "function")
57
- return n.$$typeof === le ? null : n.displayName || n.name || null;
57
+ return n.$$typeof === ue ? null : n.displayName || n.name || null;
58
58
  if (typeof n == "string") return n;
59
59
  switch (n) {
60
- case N:
60
+ case C:
61
61
  return "Fragment";
62
- case ee:
62
+ case re:
63
63
  return "Profiler";
64
- case k:
64
+ case te:
65
65
  return "StrictMode";
66
- case se:
66
+ case oe:
67
67
  return "Suspense";
68
- case ae:
69
- return "SuspenseList";
70
68
  case ie:
69
+ return "SuspenseList";
70
+ case le:
71
71
  return "Activity";
72
72
  }
73
73
  if (typeof n == "object")
74
74
  switch (typeof n.tag == "number" && console.error(
75
75
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
76
76
  ), n.$$typeof) {
77
- case y:
77
+ case ee:
78
78
  return "Portal";
79
- case re:
79
+ case se:
80
80
  return (n.displayName || "Context") + ".Provider";
81
- case te:
82
- return (n._context.displayName || "Context") + ".Consumer";
83
81
  case ne:
82
+ return (n._context.displayName || "Context") + ".Consumer";
83
+ case ae:
84
84
  var a = n.render;
85
85
  return n = n.displayName, n || (n = a.displayName || a.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
86
- case oe:
86
+ case ce:
87
87
  return a = n.displayName || null, a !== null ? a : s(n.type) || "Memo";
88
88
  case U:
89
89
  a = n._payload, n = n._init;
@@ -106,16 +106,16 @@ function pe() {
106
106
  }
107
107
  if (a) {
108
108
  a = console;
109
- var u = a.error, p = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
109
+ var u = a.error, h = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
110
110
  return u.call(
111
111
  a,
112
112
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
113
- p
113
+ h
114
114
  ), e(n);
115
115
  }
116
116
  }
117
117
  function t(n) {
118
- if (n === N) return "<>";
118
+ if (n === C) return "<>";
119
119
  if (typeof n == "object" && n !== null && n.$$typeof === U)
120
120
  return "<...>";
121
121
  try {
@@ -125,21 +125,21 @@ function pe() {
125
125
  return "<...>";
126
126
  }
127
127
  }
128
- function i() {
129
- var n = C.A;
128
+ function o() {
129
+ var n = N.A;
130
130
  return n === null ? null : n.getOwner();
131
131
  }
132
- function b() {
132
+ function f() {
133
133
  return Error("react-stack-top-frame");
134
134
  }
135
- function S(n) {
135
+ function E(n) {
136
136
  if (G.call(n, "key")) {
137
137
  var a = Object.getOwnPropertyDescriptor(n, "key").get;
138
138
  if (a && a.isReactWarning) return !1;
139
139
  }
140
140
  return n.key !== void 0;
141
141
  }
142
- function m(n, a) {
142
+ function S(n, a) {
143
143
  function u() {
144
144
  q || (q = !0, console.error(
145
145
  "%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)",
@@ -151,22 +151,22 @@ function pe() {
151
151
  configurable: !0
152
152
  });
153
153
  }
154
- function f() {
154
+ function d() {
155
155
  var n = s(this.type);
156
156
  return J[n] || (J[n] = !0, console.error(
157
157
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
158
158
  )), n = this.props.ref, n !== void 0 ? n : null;
159
159
  }
160
- function T(n, a, u, p, A, x, Y, F) {
161
- return u = x.ref, n = {
162
- $$typeof: _,
160
+ function T(n, a, u, h, A, R, Y, F) {
161
+ return u = R.ref, n = {
162
+ $$typeof: v,
163
163
  type: n,
164
164
  key: a,
165
- props: x,
165
+ props: R,
166
166
  _owner: A
167
167
  }, (u !== void 0 ? u : null) !== null ? Object.defineProperty(n, "ref", {
168
168
  enumerable: !1,
169
- get: f
169
+ get: d
170
170
  }) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
171
171
  configurable: !1,
172
172
  enumerable: !1,
@@ -189,132 +189,139 @@ function pe() {
189
189
  value: F
190
190
  }), Object.freeze && (Object.freeze(n.props), Object.freeze(n)), n;
191
191
  }
192
- function g(n, a, u, p, A, x, Y, F) {
193
- var h = a.children;
194
- if (h !== void 0)
195
- if (p)
196
- if (ce(h)) {
197
- for (p = 0; p < h.length; p++)
198
- c(h[p]);
199
- Object.freeze && Object.freeze(h);
192
+ function b(n, a, u, h, A, R, Y, F) {
193
+ var g = a.children;
194
+ if (g !== void 0)
195
+ if (h)
196
+ if (fe(g)) {
197
+ for (h = 0; h < g.length; h++)
198
+ l(g[h]);
199
+ Object.freeze && Object.freeze(g);
200
200
  } else
201
201
  console.error(
202
202
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
203
203
  );
204
- else c(h);
204
+ else l(g);
205
205
  if (G.call(a, "key")) {
206
- h = s(n);
207
- var O = Object.keys(a).filter(function(ue) {
208
- return ue !== "key";
206
+ g = s(n);
207
+ var P = Object.keys(a).filter(function(de) {
208
+ return de !== "key";
209
209
  });
210
- p = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", X[h + p] || (O = 0 < O.length ? "{" + O.join(": ..., ") + ": ...}" : "{}", console.error(
210
+ h = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", B[g + h] || (P = 0 < P.length ? "{" + P.join(": ..., ") + ": ...}" : "{}", console.error(
211
211
  `A props object containing a "key" prop is being spread into JSX:
212
212
  let props = %s;
213
213
  <%s {...props} />
214
214
  React keys must be passed directly to JSX without using spread:
215
215
  let props = %s;
216
216
  <%s key={someKey} {...props} />`,
217
- p,
218
217
  h,
219
- O,
220
- h
221
- ), X[h + p] = !0);
218
+ g,
219
+ P,
220
+ g
221
+ ), B[g + h] = !0);
222
222
  }
223
- if (h = null, u !== void 0 && (r(u), h = "" + u), S(a) && (r(a.key), h = "" + a.key), "key" in a) {
223
+ if (g = null, u !== void 0 && (r(u), g = "" + u), E(a) && (r(a.key), g = "" + a.key), "key" in a) {
224
224
  u = {};
225
225
  for (var $ in a)
226
226
  $ !== "key" && (u[$] = a[$]);
227
227
  } else u = a;
228
- return h && m(
228
+ return g && S(
229
229
  u,
230
230
  typeof n == "function" ? n.displayName || n.name || "Unknown" : n
231
231
  ), T(
232
232
  n,
233
- h,
234
- x,
233
+ g,
234
+ R,
235
235
  A,
236
- i(),
236
+ o(),
237
237
  u,
238
238
  Y,
239
239
  F
240
240
  );
241
241
  }
242
- function c(n) {
243
- typeof n == "object" && n !== null && n.$$typeof === _ && n._store && (n._store.validated = 1);
242
+ function l(n) {
243
+ typeof n == "object" && n !== null && n.$$typeof === v && n._store && (n._store.validated = 1);
244
244
  }
245
- var o = fe, _ = Symbol.for("react.transitional.element"), y = Symbol.for("react.portal"), N = Symbol.for("react.fragment"), k = Symbol.for("react.strict_mode"), ee = Symbol.for("react.profiler"), te = Symbol.for("react.consumer"), re = Symbol.for("react.context"), ne = Symbol.for("react.forward_ref"), se = Symbol.for("react.suspense"), ae = Symbol.for("react.suspense_list"), oe = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), ie = Symbol.for("react.activity"), le = Symbol.for("react.client.reference"), C = o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, ce = Array.isArray, V = console.createTask ? console.createTask : function() {
245
+ var i = be, v = Symbol.for("react.transitional.element"), ee = Symbol.for("react.portal"), C = Symbol.for("react.fragment"), te = Symbol.for("react.strict_mode"), re = Symbol.for("react.profiler"), ne = Symbol.for("react.consumer"), se = Symbol.for("react.context"), ae = Symbol.for("react.forward_ref"), oe = Symbol.for("react.suspense"), ie = Symbol.for("react.suspense_list"), ce = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), le = Symbol.for("react.activity"), ue = Symbol.for("react.client.reference"), N = i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, fe = Array.isArray, V = console.createTask ? console.createTask : function() {
246
246
  return null;
247
247
  };
248
- o = {
248
+ i = {
249
249
  react_stack_bottom_frame: function(n) {
250
250
  return n();
251
251
  }
252
252
  };
253
- var q, J = {}, z = o.react_stack_bottom_frame.bind(
254
- o,
255
- b
256
- )(), B = V(t(b)), X = {};
257
- j.Fragment = N, j.jsx = function(n, a, u, p, A) {
258
- var x = 1e4 > C.recentlyCreatedOwnerStacks++;
259
- return g(
253
+ var q, J = {}, z = i.react_stack_bottom_frame.bind(
254
+ i,
255
+ f
256
+ )(), X = V(t(f)), B = {};
257
+ j.Fragment = C, j.jsx = function(n, a, u, h, A) {
258
+ var R = 1e4 > N.recentlyCreatedOwnerStacks++;
259
+ return b(
260
260
  n,
261
261
  a,
262
262
  u,
263
263
  !1,
264
- p,
264
+ h,
265
265
  A,
266
- x ? Error("react-stack-top-frame") : z,
267
- x ? V(t(n)) : B
266
+ R ? Error("react-stack-top-frame") : z,
267
+ R ? V(t(n)) : X
268
268
  );
269
- }, j.jsxs = function(n, a, u, p, A) {
270
- var x = 1e4 > C.recentlyCreatedOwnerStacks++;
271
- return g(
269
+ }, j.jsxs = function(n, a, u, h, A) {
270
+ var R = 1e4 > N.recentlyCreatedOwnerStacks++;
271
+ return b(
272
272
  n,
273
273
  a,
274
274
  u,
275
275
  !0,
276
- p,
276
+ h,
277
277
  A,
278
- x ? Error("react-stack-top-frame") : z,
279
- x ? V(t(n)) : B
278
+ R ? Error("react-stack-top-frame") : z,
279
+ R ? V(t(n)) : X
280
280
  );
281
281
  };
282
282
  }()), j;
283
283
  }
284
- var Z;
285
- function he() {
286
- return Z || (Z = 1, process.env.NODE_ENV === "production" ? L.exports = ge() : L.exports = pe()), L.exports;
284
+ var Q;
285
+ function Se() {
286
+ return Q || (Q = 1, process.env.NODE_ENV === "production" ? L.exports = pe() : L.exports = Ee()), L.exports;
287
287
  }
288
- var Ee = he();
289
- const K = de(void 0), we = ({ children: s, scopeName: e }) => (e || (e = w(() => Math.random().toString(36).substring(2, 15), [])), /* @__PURE__ */ Ee.jsx(K.Provider, { value: { scopeName: e }, children: s })), ve = () => be(K), M = (...s) => {
290
- process.env.NODE_ENV === "development" && console.log(
288
+ var ve = Se();
289
+ const y = he(void 0), Oe = ({ children: s, scopeName: e }) => {
290
+ if (e && e.includes("//")) throw new Error("scopeName cannot contain '//'");
291
+ return e || (e = w(() => Math.random().toString(36).substring(2, 15), [])), /* @__PURE__ */ ve.jsx(y.Provider, { value: { scopeName: e }, children: s });
292
+ }, me = () => ge(y);
293
+ let k = !1;
294
+ const je = (s) => {
295
+ k = s;
296
+ }, I = (...s) => {
297
+ k && console.log(
291
298
  "%c[react-shared-states]",
292
299
  "color: #007acc; font-weight: bold",
293
300
  ...s
294
301
  );
295
- }, R = (s) => {
302
+ }, _ = (s) => {
296
303
  if (!s) throw new Error("Value is empty");
297
304
  return s;
298
305
  };
299
- class l {
306
+ class c {
300
307
  data = /* @__PURE__ */ new Map();
301
308
  defaultValue() {
302
309
  return {};
303
310
  }
304
311
  addListener(e, r, t) {
305
- this.data.has(l.prefix(e, r)) || this.data.set(l.prefix(e, r), {
312
+ this.data.has(c.prefix(e, r)) || this.data.set(c.prefix(e, r), {
306
313
  ...this.defaultValue,
307
314
  listeners: []
308
- }), this.data.get(l.prefix(e, r)).listeners.push(t);
315
+ }), this.data.get(c.prefix(e, r)).listeners.push(t);
309
316
  }
310
317
  removeListener(e, r, t) {
311
- this.data.has(l.prefix(e, r)) && (this.data.get(l.prefix(e, r)).listeners = this.data.get(l.prefix(e, r)).listeners.filter((i) => i !== t));
318
+ this.data.has(c.prefix(e, r)) && (this.data.get(c.prefix(e, r)).listeners = this.data.get(c.prefix(e, r)).listeners.filter((o) => o !== t));
312
319
  }
313
320
  callListeners(e, r) {
314
- this.data.has(l.prefix(e, r)) && this.data.get(l.prefix(e, r)).listeners.forEach((t) => t());
321
+ this.data.has(c.prefix(e, r)) && this.data.get(c.prefix(e, r)).listeners.forEach((t) => t());
315
322
  }
316
323
  init(e, r, t) {
317
- this.data.has(l.prefix(e, r)) || this.data.set(l.prefix(e, r), {
324
+ this.data.has(c.prefix(e, r)) || this.data.set(c.prefix(e, r), {
318
325
  ...t,
319
326
  listeners: []
320
327
  });
@@ -325,7 +332,7 @@ class l {
325
332
  }), this.data.clear();
326
333
  }
327
334
  clear(e, r, t = !1) {
328
- t || this.callListeners(e, r), this.data.delete(l.prefix(e, r));
335
+ t || this.callListeners(e, r), this.data.delete(c.prefix(e, r));
329
336
  }
330
337
  get(e, r) {
331
338
  let t = this.has(e, r);
@@ -333,30 +340,108 @@ class l {
333
340
  return this.data.get(t);
334
341
  }
335
342
  setValue(e, r, t) {
336
- this.data.has(l.prefix(e, r)) && this.data.set(l.prefix(e, r), {
337
- ...this.data.get(l.prefix(e, r)),
343
+ this.data.has(c.prefix(e, r)) && this.data.set(c.prefix(e, r), {
344
+ ...this.data.get(c.prefix(e, r)),
338
345
  ...t
339
346
  });
340
347
  }
341
348
  has(e, r) {
342
- return this.data.has(l.prefix(e, r)) ? l.prefix(e, r) : this.data.has(l.prefix(e, "_global")) ? l.prefix(e, "_global") : void 0;
349
+ return this.data.has(c.prefix(e, r)) ? c.prefix(e, r) : this.data.has(c.prefix(e, "_global")) ? c.prefix(e, "_global") : void 0;
343
350
  }
344
351
  static prefix(e, r) {
345
- return `${r}_${e}`;
352
+ if (e.includes("//")) throw new Error("key cannot contain '//'");
353
+ return `${r}//${e}`;
354
+ }
355
+ static extractPrefix(e) {
356
+ return e.split("//");
346
357
  }
347
358
  useEffect(e, r, t = null) {
348
- Q(() => () => {
349
- t?.(), M(`[${l.prefix(e, r)}]`, "unmount effect"), this.data.get(l.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
359
+ K(() => () => {
360
+ t?.(), I(`[${c.prefix(e, r)}]`, "unmount effect"), this.data.get(c.prefix(e, r)).listeners?.length === 0 && this.clear(e, r);
350
361
  }, []);
351
362
  }
352
363
  }
364
+ class D {
365
+ constructor(e) {
366
+ this.sharedData = e;
367
+ }
368
+ /**
369
+ * get a value from the shared data
370
+ * @param key
371
+ * @param scopeName
372
+ */
373
+ get(e, r) {
374
+ e = _(e);
375
+ const t = r || "_global";
376
+ return this.sharedData.get(e, t);
377
+ }
378
+ /**
379
+ * set a value in the shared data
380
+ * @param key
381
+ * @param value
382
+ * @param scopeName
383
+ */
384
+ set(e, r, t) {
385
+ e = _(e);
386
+ const o = t || "_global";
387
+ this.sharedData.setValue(e, o, r);
388
+ }
389
+ /**
390
+ * clear all values from the shared data
391
+ */
392
+ clearAll() {
393
+ this.sharedData.clearAll();
394
+ }
395
+ /**
396
+ * clear all values from the shared data in a scope
397
+ * @param scopeName
398
+ */
399
+ clearScope(e) {
400
+ const r = e || "_global";
401
+ this.sharedData.data.forEach((t, o) => {
402
+ const [f] = c.extractPrefix(o);
403
+ if (f === r) {
404
+ this.sharedData.clear(o, f);
405
+ return;
406
+ }
407
+ });
408
+ }
409
+ /**
410
+ * clear a value from the shared data
411
+ * @param key
412
+ * @param scopeName
413
+ */
414
+ clear(e, r) {
415
+ const t = r || "_global";
416
+ this.sharedData.clear(e, t);
417
+ }
418
+ /**
419
+ * check if a value exists in the shared data
420
+ * @param key
421
+ * @param scopeName
422
+ */
423
+ has(e, r = "_global") {
424
+ const t = r || "_global";
425
+ return !!this.sharedData.has(e, t);
426
+ }
427
+ /**
428
+ * get all values from the shared data
429
+ */
430
+ getAll() {
431
+ const e = {};
432
+ return this.sharedData.data.forEach((r, t) => {
433
+ const [o, f] = c.extractPrefix(t);
434
+ e[o] = e[o] || {}, e[o][f] = r;
435
+ }), e;
436
+ }
437
+ }
353
438
  const W = (s) => {
354
- const e = ve();
439
+ const e = me();
355
440
  return {
356
441
  prefix: s ?? e?.scopeName ?? "_global"
357
442
  };
358
443
  };
359
- class Se extends l {
444
+ class xe extends c {
360
445
  defaultValue() {
361
446
  return { value: void 0 };
362
447
  }
@@ -370,48 +455,34 @@ class Se extends l {
370
455
  super.removeListener(e, r, t);
371
456
  }
372
457
  }
373
- class me {
458
+ class _e extends D {
374
459
  get(e, r = "_global") {
375
- e = R(e);
460
+ e = _(e);
376
461
  const t = r || "_global";
377
- return E.get(e, t)?.value;
462
+ return m.get(e, t)?.value;
378
463
  }
379
464
  set(e, r, t = "_global") {
380
- e = R(e);
381
- const i = t || "_global";
382
- E.setValue(e, i, { value: r });
383
- }
384
- clearAll() {
385
- E.clearAll();
386
- }
387
- clear(e, r = "_global") {
388
- const t = r || "_global";
389
- E.clear(e, t);
390
- }
391
- has(e, r = "_global") {
392
- const t = r || "_global";
393
- return !!E.has(e, t);
394
- }
395
- getAll() {
396
- return E.data;
465
+ e = _(e);
466
+ const o = t || "_global";
467
+ m.setValue(e, o, { value: r });
397
468
  }
398
469
  }
399
- const Oe = new me(), E = new Se(), Pe = (s, e, r) => {
400
- s = R(s);
470
+ const m = new xe(), Le = new _e(m), Ce = (s, e, r) => {
471
+ s = _(s);
401
472
  const { prefix: t } = W(r);
402
- E.init(s, t, e);
403
- const i = w(() => (f) => (E.init(s, t, e), E.addListener(s, t, f), () => {
404
- E.removeListener(s, t, f);
405
- }), []), b = w(() => () => E.get(s, t)?.value, []), S = I(i, b), m = (f) => {
406
- const T = typeof f == "function" ? f(E.get(s, t)?.value) : f;
407
- T !== S && (E.setValue(s, t, T), E.callListeners(s, t));
473
+ m.init(s, t, e);
474
+ const o = w(() => (d) => (m.init(s, t, e), m.addListener(s, t, d), () => {
475
+ m.removeListener(s, t, d);
476
+ }), []), f = w(() => () => m.get(s, t)?.value, []), E = M(o, f), S = (d) => {
477
+ const T = typeof d == "function" ? d(m.get(s, t)?.value) : d;
478
+ T !== E && (m.setValue(s, t, T), m.callListeners(s, t));
408
479
  };
409
- return E.useEffect(s, t), [
410
- S,
411
- m
480
+ return m.useEffect(s, t), [
481
+ E,
482
+ S
412
483
  ];
413
484
  };
414
- class _e extends l {
485
+ class Re extends c {
415
486
  defaultValue() {
416
487
  return {
417
488
  fnState: {
@@ -428,70 +499,56 @@ class _e extends l {
428
499
  super.setValue(e, r, t);
429
500
  }
430
501
  }
431
- class xe {
502
+ class Te extends D {
432
503
  get(e, r = "_global") {
433
- e = R(e);
504
+ e = _(e);
434
505
  const t = r || "_global";
435
- return v.get(e, t)?.fnState;
506
+ return x.get(e, t)?.fnState;
436
507
  }
437
508
  set(e, r, t = "_global") {
438
- e = R(e);
439
- const i = t || "_global";
440
- v.setValue(e, i, r);
441
- }
442
- clearAll() {
443
- v.clearAll();
444
- }
445
- clear(e, r = "_global") {
446
- const t = r || "_global";
447
- v.clear(e, t);
448
- }
449
- has(e, r = "_global") {
450
- const t = r || "_global";
451
- return !!v.has(e, t);
452
- }
453
- getAll() {
454
- return v.data;
509
+ e = _(e);
510
+ const o = t || "_global";
511
+ x.setValue(e, o, r);
455
512
  }
456
513
  }
457
- const je = new xe(), v = new _e(), Le = (s, e, r) => {
458
- s = R(s);
514
+ const x = new Re(), Ne = new Te(x), Ve = (s, e, r) => {
515
+ s = _(s);
459
516
  const { prefix: t } = W(r);
460
- v.init(s, t);
461
- const i = w(
462
- () => (f) => (v.init(s, t), v.addListener(s, t, f), () => {
463
- v.removeListener(s, t, f);
517
+ x.init(s, t);
518
+ const o = w(
519
+ () => (d) => (x.init(s, t), x.addListener(s, t, d), () => {
520
+ x.removeListener(s, t, d);
464
521
  }),
465
522
  []
466
- ), b = w(
467
- () => () => v.get(s, t).fnState,
523
+ ), f = w(
524
+ () => () => x.get(s, t).fnState,
468
525
  []
469
- ), S = I(i, b), m = async (f, ...T) => {
470
- const g = v.get(s, t);
471
- if (!f && (g.fnState.isLoading || g.fnState.results !== void 0)) return g.fnState;
472
- g.fnState = { ...g.fnState, isLoading: !0, error: void 0 }, g.listeners.forEach((c) => c());
526
+ ), E = M(o, f), S = async (d, ...T) => {
527
+ const b = x.get(s, t);
528
+ if (!d && (b.fnState.isLoading || b.fnState.results !== void 0)) return b.fnState;
529
+ b.fnState = { ...b.fnState, isLoading: !0, error: void 0 }, b.listeners.forEach((l) => l());
473
530
  try {
474
- const c = await e(...T);
475
- g.fnState = { results: c, isLoading: !1, error: void 0 };
476
- } catch (c) {
477
- g.fnState = { ...g.fnState, isLoading: !1, error: c };
531
+ const l = await e(...T);
532
+ b.fnState = { results: l, isLoading: !1, error: void 0 };
533
+ } catch (l) {
534
+ b.fnState = { ...b.fnState, isLoading: !1, error: l };
478
535
  }
479
- g.listeners.forEach((c) => c());
536
+ b.listeners.forEach((l) => l());
480
537
  };
481
- return v.useEffect(s, t), {
482
- state: S,
483
- trigger: (...f) => {
484
- m(!1, ...f);
538
+ return x.useEffect(s, t), {
539
+ state: E,
540
+ trigger: (...d) => {
541
+ S(!1, ...d);
485
542
  },
486
- forceTrigger: (...f) => {
487
- m(!0, ...f);
543
+ forceTrigger: (...d) => {
544
+ S(!0, ...d);
488
545
  },
489
546
  clear: () => {
490
- v.clear(s, t), v.init(s, t);
547
+ x.clear(s, t), x.init(s, t);
491
548
  }
492
549
  };
493
550
  };
494
- class Re extends l {
551
+ class Ae extends c {
495
552
  defaultValue() {
496
553
  return {
497
554
  fnState: {
@@ -509,8 +566,8 @@ class Re extends l {
509
566
  super.setValue(e, r, t);
510
567
  }
511
568
  useEffect(e, r) {
512
- Q(() => () => {
513
- M(`[${l.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
569
+ K(() => () => {
570
+ I(`[${c.prefix(e, r)}]`, "unmount effect2"), this.get(e, r)?.listeners.length === 0 && this.unsubscribe(e, r);
514
571
  }, []), super.useEffect(e, r);
515
572
  }
516
573
  async unsubscribe(e, r) {
@@ -518,83 +575,71 @@ class Re extends l {
518
575
  t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState.subscribed = !1);
519
576
  }
520
577
  }
521
- class Te {
578
+ class we extends D {
522
579
  get(e, r = "_global") {
523
- e = R(e);
580
+ e = _(e);
524
581
  const t = r || "_global";
525
- return d.get(e, t)?.fnState;
582
+ return p.get(e, t)?.fnState;
526
583
  }
527
584
  set(e, r, t = "_global") {
528
- e = R(e);
529
- const i = t || "_global";
530
- d.setValue(e, i, r);
531
- }
532
- clearAll() {
533
- d.clearAll();
534
- }
535
- clear(e, r = "_global") {
536
- const t = r || "_global";
537
- d.clear(e, t);
538
- }
539
- has(e, r = "_global") {
540
- const t = r || "_global";
541
- return !!d.has(e, t);
542
- }
543
- getAll() {
544
- return d.data;
585
+ e = _(e);
586
+ const o = t || "_global";
587
+ p.setValue(e, o, r);
545
588
  }
546
589
  }
547
- const Ne = new Te(), d = new Re(), Ce = (s, e, r) => {
548
- s = R(s);
590
+ const p = new Ae(), Ye = new we(p), Fe = (s, e, r) => {
591
+ s = _(s);
549
592
  const { prefix: t } = W(r);
550
- d.init(s, t);
551
- const i = w(
552
- () => (c) => (d.init(s, t), d.addListener(s, t, c), () => {
553
- d.removeListener(s, t, c);
593
+ p.init(s, t);
594
+ const o = w(
595
+ () => (l) => (p.init(s, t), p.addListener(s, t, l), () => {
596
+ p.removeListener(s, t, l);
554
597
  }),
555
598
  []
556
- ), b = w(
557
- () => () => d.get(s, t).fnState,
599
+ ), f = w(
600
+ () => () => p.get(s, t).fnState,
558
601
  []
559
- ), S = I(i, b), m = (c) => {
560
- const o = d.get(s, t);
561
- o.fnState = { ...o.fnState, data: c }, o.listeners.forEach((_) => _());
562
- }, f = (c) => {
563
- const o = d.get(s, t);
564
- o.fnState = { ...o.fnState, isLoading: !1, data: void 0, error: c }, o.listeners.forEach((_) => _());
602
+ ), E = M(o, f), S = (l) => {
603
+ const i = p.get(s, t);
604
+ i.fnState = { ...i.fnState, data: l }, i.listeners.forEach((v) => v());
605
+ }, d = (l) => {
606
+ const i = p.get(s, t);
607
+ i.fnState = { ...i.fnState, isLoading: !1, data: void 0, error: l }, i.listeners.forEach((v) => v());
565
608
  }, T = () => {
566
- const c = d.get(s, t);
567
- c.fnState = { ...c.fnState, isLoading: !1 }, c.listeners.forEach((o) => o());
568
- }, g = async (c) => {
569
- const o = d.get(s, t);
570
- if (c && (await d.unsubscribe(s, t), o.fnState = { ...o.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), o.fnState.subscribed) return o.fnState;
571
- M("triggered !!"), o.fnState = { ...o.fnState, isLoading: !0, error: void 0 }, o.listeners.forEach((_) => _());
609
+ const l = p.get(s, t);
610
+ l.fnState = { ...l.fnState, isLoading: !1 }, l.listeners.forEach((i) => i());
611
+ }, b = async (l) => {
612
+ const i = p.get(s, t);
613
+ if (l && (await p.unsubscribe(s, t), i.fnState = { ...i.fnState, isLoading: !1, data: void 0, error: void 0, subscribed: !1 }), i.fnState.subscribed) return i.fnState;
614
+ I("triggered !!"), i.fnState = { ...i.fnState, isLoading: !0, error: void 0 }, i.listeners.forEach((v) => v());
572
615
  try {
573
- o.unsubscribe = await e(m, f, T), o.fnState.subscribed = !0;
574
- } catch (_) {
575
- o.fnState = { ...o.fnState, isLoading: !1, error: _ };
616
+ i.unsubscribe = await e(S, d, T), i.fnState.subscribed = !0;
617
+ } catch (v) {
618
+ i.fnState = { ...i.fnState, isLoading: !1, error: v };
576
619
  }
577
- o.listeners.forEach((_) => _());
620
+ i.listeners.forEach((v) => v());
578
621
  };
579
- return d.useEffect(s, t), {
580
- state: S,
622
+ return p.useEffect(s, t), {
623
+ state: E,
581
624
  trigger: () => {
582
- g(!1);
625
+ b(!1);
583
626
  },
584
627
  forceTrigger: () => {
585
- g(!0);
628
+ b(!0);
586
629
  },
587
630
  unsubscribe: () => {
588
- d.unsubscribe(s, t);
631
+ p.unsubscribe(s, t);
589
632
  }
590
633
  };
591
634
  };
592
635
  export {
593
- we as SharedStatesProvider,
594
- je as sharedFunctionsApi,
595
- Oe as sharedStatesApi,
596
- Ne as sharedSubscriptionsApi,
597
- Le as useSharedFunction,
598
- Pe as useSharedState,
599
- Ce as useSharedSubscription
636
+ Oe as SharedStatesProvider,
637
+ k as isDevMode,
638
+ je as setDevMode,
639
+ Ne as sharedFunctionsApi,
640
+ Le as sharedStatesApi,
641
+ Ye as sharedSubscriptionsApi,
642
+ Ve as useSharedFunction,
643
+ Ce as useSharedState,
644
+ Fe as useSharedSubscription
600
645
  };
package/dist/main.min.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * react-shared-states v1.0.5
2
+ * react-shared-states v1.0.7
3
3
  * (c) Hichem Taboukouyout
4
4
  * Released under the MIT License.
5
5
  * Github: github.com/HichemTab-tech/react-shared-states
6
6
  */
7
7
 
8
- (function(v,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],f):(v=typeof globalThis<"u"?globalThis:v||self,f(v.ReactSharedStates={},v.React))})(this,function(v,f){"use strict";var N={exports:{}},j={};/**
8
+ (function(b,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(b=typeof globalThis<"u"?globalThis:b||self,d(b.ReactSharedStates={},b.React))})(this,function(b,d){"use strict";var C={exports:{}},j={};/**
9
9
  * @license React
10
10
  * react-jsx-runtime.production.js
11
11
  *
@@ -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 G;function y(){if(G)return j;G=1;var s=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function r(t,l,g){var _=null;if(g!==void 0&&(_=""+g),l.key!==void 0&&(_=""+l.key),"key"in l){g={};for(var x in l)x!=="key"&&(g[x]=l[x])}else g=l;return l=g.ref,{$$typeof:s,type:t,key:_,ref:l!==void 0?l:null,props:g}}return j.Fragment=e,j.jsx=r,j.jsxs=r,j}var L={};/**
16
+ */var G;function y(){if(G)return j;G=1;var s=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function r(t,o,f){var x=null;if(f!==void 0&&(x=""+f),o.key!==void 0&&(x=""+o.key),"key"in o){f={};for(var _ in o)_!=="key"&&(f[_]=o[_])}else f=o;return o=f.ref,{$$typeof:s,type:t,key:x,ref:o!==void 0?o:null,props:f}}return j.Fragment=e,j.jsx=r,j.jsxs=r,j}var L={};/**
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 J;function $(){return J||(J=1,process.env.NODE_ENV!=="production"&&function(){function s(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===Ae?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case F:return"Fragment";case Se:return"Profiler";case he:return"StrictMode";case _e:return"Suspense";case xe:return"SuspenseList";case Te:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case pe:return"Portal";case me:return(n.displayName||"Context")+".Provider";case Ee:return(n._context.displayName||"Context")+".Consumer";case ve:var a=n.render;return n=n.displayName,n||(n=a.displayName||a.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case Re:return a=n.displayName||null,a!==null?a:s(n.type)||"Memo";case X:a=n._payload,n=n._init;try{return s(n(a))}catch{}}return null}function e(n){return""+n}function r(n){try{e(n);var a=!1}catch{a=!0}if(a){a=console;var u=a.error,h=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return u.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",h),e(n)}}function t(n){if(n===F)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===X)return"<...>";try{var a=s(n);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function l(){var n=M.A;return n===null?null:n.getOwner()}function g(){return Error("react-stack-top-frame")}function _(n){if(D.call(n,"key")){var a=Object.getOwnPropertyDescriptor(n,"key").get;if(a&&a.isReactWarning)return!1}return n.key!==void 0}function x(n,a){function u(){H||(H=!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)",a))}u.isReactWarning=!0,Object.defineProperty(n,"key",{get:u,configurable:!0})}function d(){var n=s(this.type);return Z[n]||(Z[n]=!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.")),n=this.props.ref,n!==void 0?n:null}function w(n,a,u,h,O,T,I,W){return u=T.ref,n={$$typeof:R,type:n,key:a,props:T,_owner:O},(u!==void 0?u:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:d}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:I}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:W}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function p(n,a,u,h,O,T,I,W){var S=a.children;if(S!==void 0)if(h)if(we(S)){for(h=0;h<S.length;h++)c(S[h]);Object.freeze&&Object.freeze(S)}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 c(S);if(D.call(a,"key")){S=s(n);var P=Object.keys(a).filter(function(Oe){return Oe!=="key"});h=0<P.length?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}",q[S+h]||(P=0<P.length?"{"+P.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
24
+ */var J;function k(){return J||(J=1,process.env.NODE_ENV!=="production"&&function(){function s(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===Pe?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case F:return"Fragment";case ve:return"Profiler";case Ee:return"StrictMode";case Re:return"Suspense";case Te:return"SuspenseList";case we:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case pe:return"Portal";case xe:return(n.displayName||"Context")+".Provider";case me:return(n._context.displayName||"Context")+".Consumer";case _e:var a=n.render;return n=n.displayName,n||(n=a.displayName||a.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case Ae:return a=n.displayName||null,a!==null?a:s(n.type)||"Memo";case B:a=n._payload,n=n._init;try{return s(n(a))}catch{}}return null}function e(n){return""+n}function r(n){try{e(n);var a=!1}catch{a=!0}if(a){a=console;var u=a.error,S=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return u.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",S),e(n)}}function t(n){if(n===F)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===B)return"<...>";try{var a=s(n);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function o(){var n=Y.A;return n===null?null:n.getOwner()}function f(){return Error("react-stack-top-frame")}function x(n){if(H.call(n,"key")){var a=Object.getOwnPropertyDescriptor(n,"key").get;if(a&&a.isReactWarning)return!1}return n.key!==void 0}function _(n,a){function u(){Z||(Z=!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)",a))}u.isReactWarning=!0,Object.defineProperty(n,"key",{get:u,configurable:!0})}function h(){var n=s(this.type);return Q[n]||(Q[n]=!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.")),n=this.props.ref,n!==void 0?n:null}function w(n,a,u,S,P,A,I,W){return u=A.ref,n={$$typeof:R,type:n,key:a,props:A,_owner:P},(u!==void 0?u:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:h}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:I}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:W}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function g(n,a,u,S,P,A,I,W){var p=a.children;if(p!==void 0)if(S)if(Oe(p)){for(S=0;S<p.length;S++)l(p[S]);Object.freeze&&Object.freeze(p)}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(p);if(H.call(a,"key")){p=s(n);var O=Object.keys(a).filter(function(je){return je!=="key"});S=0<O.length?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}",$[p+S]||(O=0<O.length?"{"+O.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} />`,h,S,P,S),q[S+h]=!0)}if(S=null,u!==void 0&&(r(u),S=""+u),_(a)&&(r(a.key),S=""+a.key),"key"in a){u={};for(var U in a)U!=="key"&&(u[U]=a[U])}else u=a;return S&&x(u,typeof n=="function"?n.displayName||n.name||"Unknown":n),w(n,S,T,O,l(),u,I,W)}function c(n){typeof n=="object"&&n!==null&&n.$$typeof===R&&n._store&&(n._store.validated=1)}var o=f,R=Symbol.for("react.transitional.element"),pe=Symbol.for("react.portal"),F=Symbol.for("react.fragment"),he=Symbol.for("react.strict_mode"),Se=Symbol.for("react.profiler"),Ee=Symbol.for("react.consumer"),me=Symbol.for("react.context"),ve=Symbol.for("react.forward_ref"),_e=Symbol.for("react.suspense"),xe=Symbol.for("react.suspense_list"),Re=Symbol.for("react.memo"),X=Symbol.for("react.lazy"),Te=Symbol.for("react.activity"),Ae=Symbol.for("react.client.reference"),M=o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=Object.prototype.hasOwnProperty,we=Array.isArray,Y=console.createTask?console.createTask:function(){return null};o={react_stack_bottom_frame:function(n){return n()}};var H,Z={},Q=o.react_stack_bottom_frame.bind(o,g)(),K=Y(t(g)),q={};L.Fragment=F,L.jsx=function(n,a,u,h,O){var T=1e4>M.recentlyCreatedOwnerStacks++;return p(n,a,u,!1,h,O,T?Error("react-stack-top-frame"):Q,T?Y(t(n)):K)},L.jsxs=function(n,a,u,h,O){var T=1e4>M.recentlyCreatedOwnerStacks++;return p(n,a,u,!0,h,O,T?Error("react-stack-top-frame"):Q,T?Y(t(n)):K)}}()),L}var z;function k(){return z||(z=1,process.env.NODE_ENV==="production"?N.exports=y():N.exports=$()),N.exports}var ee=k();const B=f.createContext(void 0),te=({children:s,scopeName:e})=>(e||(e=f.useMemo(()=>Math.random().toString(36).substring(2,15),[])),ee.jsx(B.Provider,{value:{scopeName:e},children:s})),re=()=>f.useContext(B),C=(...s)=>{process.env.NODE_ENV==="development"&&console.log("%c[react-shared-states]","color: #007acc; font-weight: bold",...s)},A=s=>{if(!s)throw new Error("Value is empty");return s};class i{data=new Map;defaultValue(){return{}}addListener(e,r,t){this.data.has(i.prefix(e,r))||this.data.set(i.prefix(e,r),{...this.defaultValue,listeners:[]}),this.data.get(i.prefix(e,r)).listeners.push(t)}removeListener(e,r,t){this.data.has(i.prefix(e,r))&&(this.data.get(i.prefix(e,r)).listeners=this.data.get(i.prefix(e,r)).listeners.filter(l=>l!==t))}callListeners(e,r){this.data.has(i.prefix(e,r))&&this.data.get(i.prefix(e,r)).listeners.forEach(t=>t())}init(e,r,t){this.data.has(i.prefix(e,r))||this.data.set(i.prefix(e,r),{...t,listeners:[]})}clearAll(e=!1){e||this.data.forEach(r=>{r.listeners.forEach(t=>t())}),this.data.clear()}clear(e,r,t=!1){t||this.callListeners(e,r),this.data.delete(i.prefix(e,r))}get(e,r){let t=this.has(e,r);if(t)return this.data.get(t)}setValue(e,r,t){this.data.has(i.prefix(e,r))&&this.data.set(i.prefix(e,r),{...this.data.get(i.prefix(e,r)),...t})}has(e,r){return this.data.has(i.prefix(e,r))?i.prefix(e,r):this.data.has(i.prefix(e,"_global"))?i.prefix(e,"_global"):void 0}static prefix(e,r){return`${r}_${e}`}useEffect(e,r,t=null){f.useEffect(()=>()=>{t?.(),C(`[${i.prefix(e,r)}]`,"unmount effect"),this.data.get(i.prefix(e,r)).listeners?.length===0&&this.clear(e,r)},[])}}const V=s=>{const e=re();return{prefix:s??e?.scopeName??"_global"}};class ne extends i{defaultValue(){return{value:void 0}}init(e,r,t){super.init(e,r,{value:t})}setValue(e,r,t){super.setValue(e,r,{value:t})}removeListener(e,r,t){super.removeListener(e,r,t)}}class se{get(e,r="_global"){e=A(e);const t=r||"_global";return E.get(e,t)?.value}set(e,r,t="_global"){e=A(e);const l=t||"_global";E.setValue(e,l,{value:r})}clearAll(){E.clearAll()}clear(e,r="_global"){const t=r||"_global";E.clear(e,t)}has(e,r="_global"){const t=r||"_global";return!!E.has(e,t)}getAll(){return E.data}}const ae=new se,E=new ne,oe=(s,e,r)=>{s=A(s);const{prefix:t}=V(r);E.init(s,t,e);const l=f.useMemo(()=>d=>(E.init(s,t,e),E.addListener(s,t,d),()=>{E.removeListener(s,t,d)}),[]),g=f.useMemo(()=>()=>E.get(s,t)?.value,[]),_=f.useSyncExternalStore(l,g),x=d=>{const w=typeof d=="function"?d(E.get(s,t)?.value):d;w!==_&&(E.setValue(s,t,w),E.callListeners(s,t))};return E.useEffect(s,t),[_,x]};class ie extends i{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}init(e,r){super.init(e,r,this.defaultValue())}setValue(e,r,t){super.setValue(e,r,t)}}class le{get(e,r="_global"){e=A(e);const t=r||"_global";return m.get(e,t)?.fnState}set(e,r,t="_global"){e=A(e);const l=t||"_global";m.setValue(e,l,r)}clearAll(){m.clearAll()}clear(e,r="_global"){const t=r||"_global";m.clear(e,t)}has(e,r="_global"){const t=r||"_global";return!!m.has(e,t)}getAll(){return m.data}}const ce=new le,m=new ie,ue=(s,e,r)=>{s=A(s);const{prefix:t}=V(r);m.init(s,t);const l=f.useMemo(()=>d=>(m.init(s,t),m.addListener(s,t,d),()=>{m.removeListener(s,t,d)}),[]),g=f.useMemo(()=>()=>m.get(s,t).fnState,[]),_=f.useSyncExternalStore(l,g),x=async(d,...w)=>{const p=m.get(s,t);if(!d&&(p.fnState.isLoading||p.fnState.results!==void 0))return p.fnState;p.fnState={...p.fnState,isLoading:!0,error:void 0},p.listeners.forEach(c=>c());try{const c=await e(...w);p.fnState={results:c,isLoading:!1,error:void 0}}catch(c){p.fnState={...p.fnState,isLoading:!1,error:c}}p.listeners.forEach(c=>c())};return m.useEffect(s,t),{state:_,trigger:(...d)=>{x(!1,...d)},forceTrigger:(...d)=>{x(!0,...d)},clear:()=>{m.clear(s,t),m.init(s,t)}}};class fe extends i{defaultValue(){return{fnState:{data:void 0,isLoading:!1,error:void 0,subscribed:!1}}}init(e,r){super.init(e,r,this.defaultValue())}setValue(e,r,t){super.setValue(e,r,t)}useEffect(e,r){f.useEffect(()=>()=>{C(`[${i.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.subscribed=!1)}}class de{get(e,r="_global"){e=A(e);const t=r||"_global";return b.get(e,t)?.fnState}set(e,r,t="_global"){e=A(e);const l=t||"_global";b.setValue(e,l,r)}clearAll(){b.clearAll()}clear(e,r="_global"){const t=r||"_global";b.clear(e,t)}has(e,r="_global"){const t=r||"_global";return!!b.has(e,t)}getAll(){return b.data}}const be=new de,b=new fe,ge=(s,e,r)=>{s=A(s);const{prefix:t}=V(r);b.init(s,t);const l=f.useMemo(()=>c=>(b.init(s,t),b.addListener(s,t,c),()=>{b.removeListener(s,t,c)}),[]),g=f.useMemo(()=>()=>b.get(s,t).fnState,[]),_=f.useSyncExternalStore(l,g),x=c=>{const o=b.get(s,t);o.fnState={...o.fnState,data:c},o.listeners.forEach(R=>R())},d=c=>{const o=b.get(s,t);o.fnState={...o.fnState,isLoading:!1,data:void 0,error:c},o.listeners.forEach(R=>R())},w=()=>{const c=b.get(s,t);c.fnState={...c.fnState,isLoading:!1},c.listeners.forEach(o=>o())},p=async c=>{const o=b.get(s,t);if(c&&(await b.unsubscribe(s,t),o.fnState={...o.fnState,isLoading:!1,data:void 0,error:void 0,subscribed:!1}),o.fnState.subscribed)return o.fnState;C("triggered !!"),o.fnState={...o.fnState,isLoading:!0,error:void 0},o.listeners.forEach(R=>R());try{o.unsubscribe=await e(x,d,w),o.fnState.subscribed=!0}catch(R){o.fnState={...o.fnState,isLoading:!1,error:R}}o.listeners.forEach(R=>R())};return b.useEffect(s,t),{state:_,trigger:()=>{p(!1)},forceTrigger:()=>{p(!0)},unsubscribe:()=>{b.unsubscribe(s,t)}}};v.SharedStatesProvider=te,v.sharedFunctionsApi=ce,v.sharedStatesApi=ae,v.sharedSubscriptionsApi=be,v.useSharedFunction=ue,v.useSharedState=oe,v.useSharedSubscription=ge,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
29
+ <%s key={someKey} {...props} />`,S,p,O,p),$[p+S]=!0)}if(p=null,u!==void 0&&(r(u),p=""+u),x(a)&&(r(a.key),p=""+a.key),"key"in a){u={};for(var U in a)U!=="key"&&(u[U]=a[U])}else u=a;return p&&_(u,typeof n=="function"?n.displayName||n.name||"Unknown":n),w(n,p,A,P,o(),u,I,W)}function l(n){typeof n=="object"&&n!==null&&n.$$typeof===R&&n._store&&(n._store.validated=1)}var c=d,R=Symbol.for("react.transitional.element"),pe=Symbol.for("react.portal"),F=Symbol.for("react.fragment"),Ee=Symbol.for("react.strict_mode"),ve=Symbol.for("react.profiler"),me=Symbol.for("react.consumer"),xe=Symbol.for("react.context"),_e=Symbol.for("react.forward_ref"),Re=Symbol.for("react.suspense"),Te=Symbol.for("react.suspense_list"),Ae=Symbol.for("react.memo"),B=Symbol.for("react.lazy"),we=Symbol.for("react.activity"),Pe=Symbol.for("react.client.reference"),Y=c.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,H=Object.prototype.hasOwnProperty,Oe=Array.isArray,D=console.createTask?console.createTask:function(){return null};c={react_stack_bottom_frame:function(n){return n()}};var Z,Q={},K=c.react_stack_bottom_frame.bind(c,f)(),q=D(t(f)),$={};L.Fragment=F,L.jsx=function(n,a,u,S,P){var A=1e4>Y.recentlyCreatedOwnerStacks++;return g(n,a,u,!1,S,P,A?Error("react-stack-top-frame"):K,A?D(t(n)):q)},L.jsxs=function(n,a,u,S,P){var A=1e4>Y.recentlyCreatedOwnerStacks++;return g(n,a,u,!0,S,P,A?Error("react-stack-top-frame"):K,A?D(t(n)):q)}}()),L}var z;function ee(){return z||(z=1,process.env.NODE_ENV==="production"?C.exports=y():C.exports=k()),C.exports}var te=ee();const X=d.createContext(void 0),re=({children:s,scopeName:e})=>{if(e&&e.includes("//"))throw new Error("scopeName cannot contain '//'");return e||(e=d.useMemo(()=>Math.random().toString(36).substring(2,15),[])),te.jsx(X.Provider,{value:{scopeName:e},children:s})},ne=()=>d.useContext(X);b.isDevMode=!1;const se=s=>{b.isDevMode=s},M=(...s)=>{b.isDevMode&&console.log("%c[react-shared-states]","color: #007acc; font-weight: bold",...s)},T=s=>{if(!s)throw new Error("Value is empty");return s};class i{data=new Map;defaultValue(){return{}}addListener(e,r,t){this.data.has(i.prefix(e,r))||this.data.set(i.prefix(e,r),{...this.defaultValue,listeners:[]}),this.data.get(i.prefix(e,r)).listeners.push(t)}removeListener(e,r,t){this.data.has(i.prefix(e,r))&&(this.data.get(i.prefix(e,r)).listeners=this.data.get(i.prefix(e,r)).listeners.filter(o=>o!==t))}callListeners(e,r){this.data.has(i.prefix(e,r))&&this.data.get(i.prefix(e,r)).listeners.forEach(t=>t())}init(e,r,t){this.data.has(i.prefix(e,r))||this.data.set(i.prefix(e,r),{...t,listeners:[]})}clearAll(e=!1){e||this.data.forEach(r=>{r.listeners.forEach(t=>t())}),this.data.clear()}clear(e,r,t=!1){t||this.callListeners(e,r),this.data.delete(i.prefix(e,r))}get(e,r){let t=this.has(e,r);if(t)return this.data.get(t)}setValue(e,r,t){this.data.has(i.prefix(e,r))&&this.data.set(i.prefix(e,r),{...this.data.get(i.prefix(e,r)),...t})}has(e,r){return this.data.has(i.prefix(e,r))?i.prefix(e,r):this.data.has(i.prefix(e,"_global"))?i.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){d.useEffect(()=>()=>{t?.(),M(`[${i.prefix(e,r)}]`,"unmount effect"),this.data.get(i.prefix(e,r)).listeners?.length===0&&this.clear(e,r)},[])}}class N{constructor(e){this.sharedData=e}get(e,r){e=T(e);const t=r||"_global";return this.sharedData.get(e,t)}set(e,r,t){e=T(e);const o=t||"_global";this.sharedData.setValue(e,o,r)}clearAll(){this.sharedData.clearAll()}clearScope(e){const r=e||"_global";this.sharedData.data.forEach((t,o)=>{const[f]=i.extractPrefix(o);if(f===r){this.sharedData.clear(o,f);return}})}clear(e,r){const t=r||"_global";this.sharedData.clear(e,t)}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[o,f]=i.extractPrefix(t);e[o]=e[o]||{},e[o][f]=r}),e}}const V=s=>{const e=ne();return{prefix:s??e?.scopeName??"_global"}};class ae extends i{defaultValue(){return{value:void 0}}init(e,r,t){super.init(e,r,{value:t})}setValue(e,r,t){super.setValue(e,r,{value:t})}removeListener(e,r,t){super.removeListener(e,r,t)}}class oe extends N{get(e,r="_global"){e=T(e);const t=r||"_global";return v.get(e,t)?.value}set(e,r,t="_global"){e=T(e);const o=t||"_global";v.setValue(e,o,{value:r})}}const v=new ae,ie=new oe(v),ce=(s,e,r)=>{s=T(s);const{prefix:t}=V(r);v.init(s,t,e);const o=d.useMemo(()=>h=>(v.init(s,t,e),v.addListener(s,t,h),()=>{v.removeListener(s,t,h)}),[]),f=d.useMemo(()=>()=>v.get(s,t)?.value,[]),x=d.useSyncExternalStore(o,f),_=h=>{const w=typeof h=="function"?h(v.get(s,t)?.value):h;w!==x&&(v.setValue(s,t,w),v.callListeners(s,t))};return v.useEffect(s,t),[x,_]};class le extends i{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}init(e,r){super.init(e,r,this.defaultValue())}setValue(e,r,t){super.setValue(e,r,t)}}class ue extends N{get(e,r="_global"){e=T(e);const t=r||"_global";return m.get(e,t)?.fnState}set(e,r,t="_global"){e=T(e);const o=t||"_global";m.setValue(e,o,r)}}const m=new le,fe=new ue(m),de=(s,e,r)=>{s=T(s);const{prefix:t}=V(r);m.init(s,t);const o=d.useMemo(()=>h=>(m.init(s,t),m.addListener(s,t,h),()=>{m.removeListener(s,t,h)}),[]),f=d.useMemo(()=>()=>m.get(s,t).fnState,[]),x=d.useSyncExternalStore(o,f),_=async(h,...w)=>{const g=m.get(s,t);if(!h&&(g.fnState.isLoading||g.fnState.results!==void 0))return g.fnState;g.fnState={...g.fnState,isLoading:!0,error:void 0},g.listeners.forEach(l=>l());try{const l=await e(...w);g.fnState={results:l,isLoading:!1,error:void 0}}catch(l){g.fnState={...g.fnState,isLoading:!1,error:l}}g.listeners.forEach(l=>l())};return m.useEffect(s,t),{state:x,trigger:(...h)=>{_(!1,...h)},forceTrigger:(...h)=>{_(!0,...h)},clear:()=>{m.clear(s,t),m.init(s,t)}}};class he extends i{defaultValue(){return{fnState:{data:void 0,isLoading:!1,error:void 0,subscribed:!1}}}init(e,r){super.init(e,r,this.defaultValue())}setValue(e,r,t){super.setValue(e,r,t)}useEffect(e,r){d.useEffect(()=>()=>{M(`[${i.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.subscribed=!1)}}class be extends N{get(e,r="_global"){e=T(e);const t=r||"_global";return E.get(e,t)?.fnState}set(e,r,t="_global"){e=T(e);const o=t||"_global";E.setValue(e,o,r)}}const E=new he,ge=new be(E),Se=(s,e,r)=>{s=T(s);const{prefix:t}=V(r);E.init(s,t);const o=d.useMemo(()=>l=>(E.init(s,t),E.addListener(s,t,l),()=>{E.removeListener(s,t,l)}),[]),f=d.useMemo(()=>()=>E.get(s,t).fnState,[]),x=d.useSyncExternalStore(o,f),_=l=>{const c=E.get(s,t);c.fnState={...c.fnState,data:l},c.listeners.forEach(R=>R())},h=l=>{const c=E.get(s,t);c.fnState={...c.fnState,isLoading:!1,data:void 0,error:l},c.listeners.forEach(R=>R())},w=()=>{const l=E.get(s,t);l.fnState={...l.fnState,isLoading:!1},l.listeners.forEach(c=>c())},g=async l=>{const c=E.get(s,t);if(l&&(await E.unsubscribe(s,t),c.fnState={...c.fnState,isLoading:!1,data:void 0,error:void 0,subscribed:!1}),c.fnState.subscribed)return c.fnState;M("triggered !!"),c.fnState={...c.fnState,isLoading:!0,error:void 0},c.listeners.forEach(R=>R());try{c.unsubscribe=await e(_,h,w),c.fnState.subscribed=!0}catch(R){c.fnState={...c.fnState,isLoading:!1,error:R}}c.listeners.forEach(R=>R())};return E.useEffect(s,t),{state:x,trigger:()=>{g(!1)},forceTrigger:()=>{g(!0)},unsubscribe:()=>{E.unsubscribe(s,t)}}};b.SharedStatesProvider=re,b.setDevMode=se,b.sharedFunctionsApi=fe,b.sharedStatesApi=ie,b.sharedSubscriptionsApi=ge,b.useSharedFunction=de,b.useSharedState=ce,b.useSharedSubscription=Se,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-shared-states",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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": [
@@ -39,6 +39,7 @@
39
39
  "vitest": "^3.2.4"
40
40
  },
41
41
  "scripts": {
42
+ "bump": "node scripts/bumper.js",
42
43
  "build": "vite build",
43
44
  "test": "vitest",
44
45
  "preview": "vite preview",
@@ -0,0 +1,24 @@
1
+ import fs from 'fs';
2
+
3
+ const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
4
+ const version = packageJson.version;
5
+ const [major, minor, patchWord] = version.split('.');
6
+ let newPatch;
7
+ if (patchWord.includes('-')) {
8
+ // Handle pre-release versions by extracting the numeric part
9
+ newPatch = parseInt(patchWord.split('-')[0], 10);
10
+ newPatch += 1;
11
+ // Reconstruct the pre-release version
12
+ newPatch = `${newPatch}-${patchWord.split('-')[1]}`;
13
+ }
14
+ else{
15
+ newPatch = parseInt(patchWord, 10) + 1;
16
+ }
17
+
18
+ // Increment patch version
19
+ packageJson.version = `${major}.${minor}.${newPatch}`;
20
+
21
+ // Write back to package.json with proper formatting
22
+ fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2) + '\n');
23
+
24
+ console.log(`Version bumped from ${version} to ${packageJson.version}`);
package/vite.config.ts CHANGED
@@ -41,5 +41,8 @@ export default defineConfig({
41
41
  exclude: ['node_modules', 'dist'], // Exclude unnecessary files
42
42
  })
43
43
 
44
- ]
44
+ ],
45
+ define: {
46
+ __REACT_SHARED_STATES_DEV__: process.env.NODE_ENV === 'development' ? 'true' : 'false',
47
+ }
45
48
  });