react-shared-states 1.0.6 → 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 {};
@@ -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/main.esm.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * react-shared-states v1.0.6
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 de, { createContext as be, useMemo as w, useContext as ge, useEffect as Q, useSyncExternalStore as M } 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;
19
+ var H;
20
20
  function pe() {
21
- if (D) return P;
22
- D = 1;
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,24 +48,24 @@ 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 he() {
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 === ce ? 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
60
  case C:
61
61
  return "Fragment";
62
- case te:
62
+ case re:
63
63
  return "Profiler";
64
- case ee:
64
+ case te:
65
65
  return "StrictMode";
66
- case ae:
67
- return "Suspense";
68
66
  case oe:
67
+ return "Suspense";
68
+ case ie:
69
69
  return "SuspenseList";
70
70
  case le:
71
71
  return "Activity";
@@ -74,16 +74,16 @@ function he() {
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 k:
77
+ case ee:
78
78
  return "Portal";
79
- case ne:
79
+ case se:
80
80
  return (n.displayName || "Context") + ".Provider";
81
- case re:
81
+ case ne:
82
82
  return (n._context.displayName || "Context") + ".Consumer";
83
- case se:
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 ie:
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,11 +106,11 @@ function he() {
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
  }
@@ -125,21 +125,21 @@ function he() {
125
125
  return "<...>";
126
126
  }
127
127
  }
128
- function i() {
128
+ function o() {
129
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 he() {
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, _, Y, F) {
161
- return u = _.ref, n = {
162
- $$typeof: x,
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: _,
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,136 +189,139 @@ function he() {
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, _, Y, F) {
193
- var h = a.children;
194
- if (h !== void 0)
195
- if (p)
196
- if (ue(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(fe) {
208
- return fe !== "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
- _,
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 === x && 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 = de, x = Symbol.for("react.transitional.element"), k = Symbol.for("react.portal"), C = Symbol.for("react.fragment"), ee = Symbol.for("react.strict_mode"), te = Symbol.for("react.profiler"), re = Symbol.for("react.consumer"), ne = Symbol.for("react.context"), se = Symbol.for("react.forward_ref"), ae = Symbol.for("react.suspense"), oe = Symbol.for("react.suspense_list"), ie = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), le = Symbol.for("react.activity"), ce = Symbol.for("react.client.reference"), N = o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, ue = 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 = C, j.jsx = function(n, a, u, p, A) {
258
- var _ = 1e4 > N.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
- _ ? Error("react-stack-top-frame") : z,
267
- _ ? 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 _ = 1e4 > N.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
- _ ? Error("react-stack-top-frame") : z,
279
- _ ? 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 Ee() {
286
- return Z || (Z = 1, process.env.NODE_ENV === "production" ? L.exports = pe() : L.exports = he()), 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 ve = Ee();
289
- const K = be(void 0), Oe = ({ children: s, scopeName: e }) => (e || (e = w(() => Math.random().toString(36).substring(2, 15), [])), /* @__PURE__ */ ve.jsx(K.Provider, { value: { scopeName: e }, children: s })), Se = () => ge(K);
290
- let y = !1;
291
- const Pe = (s) => {
292
- y = s;
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;
293
296
  }, I = (...s) => {
294
- y && console.log(
297
+ k && console.log(
295
298
  "%c[react-shared-states]",
296
299
  "color: #007acc; font-weight: bold",
297
300
  ...s
298
301
  );
299
- }, R = (s) => {
302
+ }, _ = (s) => {
300
303
  if (!s) throw new Error("Value is empty");
301
304
  return s;
302
305
  };
303
- class l {
306
+ class c {
304
307
  data = /* @__PURE__ */ new Map();
305
308
  defaultValue() {
306
309
  return {};
307
310
  }
308
311
  addListener(e, r, t) {
309
- 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), {
310
313
  ...this.defaultValue,
311
314
  listeners: []
312
- }), this.data.get(l.prefix(e, r)).listeners.push(t);
315
+ }), this.data.get(c.prefix(e, r)).listeners.push(t);
313
316
  }
314
317
  removeListener(e, r, t) {
315
- 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));
316
319
  }
317
320
  callListeners(e, r) {
318
- 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());
319
322
  }
320
323
  init(e, r, t) {
321
- 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), {
322
325
  ...t,
323
326
  listeners: []
324
327
  });
@@ -329,7 +332,7 @@ class l {
329
332
  }), this.data.clear();
330
333
  }
331
334
  clear(e, r, t = !1) {
332
- 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));
333
336
  }
334
337
  get(e, r) {
335
338
  let t = this.has(e, r);
@@ -337,30 +340,108 @@ class l {
337
340
  return this.data.get(t);
338
341
  }
339
342
  setValue(e, r, t) {
340
- this.data.has(l.prefix(e, r)) && this.data.set(l.prefix(e, r), {
341
- ...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)),
342
345
  ...t
343
346
  });
344
347
  }
345
348
  has(e, r) {
346
- 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;
347
350
  }
348
351
  static prefix(e, r) {
349
- 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("//");
350
357
  }
351
358
  useEffect(e, r, t = null) {
352
- Q(() => () => {
353
- t?.(), I(`[${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);
354
361
  }, []);
355
362
  }
356
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
+ }
357
438
  const W = (s) => {
358
- const e = Se();
439
+ const e = me();
359
440
  return {
360
441
  prefix: s ?? e?.scopeName ?? "_global"
361
442
  };
362
443
  };
363
- class me extends l {
444
+ class xe extends c {
364
445
  defaultValue() {
365
446
  return { value: void 0 };
366
447
  }
@@ -374,48 +455,34 @@ class me extends l {
374
455
  super.removeListener(e, r, t);
375
456
  }
376
457
  }
377
- class xe {
458
+ class _e extends D {
378
459
  get(e, r = "_global") {
379
- e = R(e);
460
+ e = _(e);
380
461
  const t = r || "_global";
381
- return E.get(e, t)?.value;
462
+ return m.get(e, t)?.value;
382
463
  }
383
464
  set(e, r, t = "_global") {
384
- e = R(e);
385
- const i = t || "_global";
386
- E.setValue(e, i, { value: r });
387
- }
388
- clearAll() {
389
- E.clearAll();
390
- }
391
- clear(e, r = "_global") {
392
- const t = r || "_global";
393
- E.clear(e, t);
394
- }
395
- has(e, r = "_global") {
396
- const t = r || "_global";
397
- return !!E.has(e, t);
398
- }
399
- getAll() {
400
- return E.data;
465
+ e = _(e);
466
+ const o = t || "_global";
467
+ m.setValue(e, o, { value: r });
401
468
  }
402
469
  }
403
- const je = new xe(), E = new me(), Le = (s, e, r) => {
404
- s = R(s);
470
+ const m = new xe(), Le = new _e(m), Ce = (s, e, r) => {
471
+ s = _(s);
405
472
  const { prefix: t } = W(r);
406
- E.init(s, t, e);
407
- const i = w(() => (f) => (E.init(s, t, e), E.addListener(s, t, f), () => {
408
- E.removeListener(s, t, f);
409
- }), []), b = w(() => () => E.get(s, t)?.value, []), S = M(i, b), m = (f) => {
410
- const T = typeof f == "function" ? f(E.get(s, t)?.value) : f;
411
- 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));
412
479
  };
413
- return E.useEffect(s, t), [
414
- S,
415
- m
480
+ return m.useEffect(s, t), [
481
+ E,
482
+ S
416
483
  ];
417
484
  };
418
- class _e extends l {
485
+ class Re extends c {
419
486
  defaultValue() {
420
487
  return {
421
488
  fnState: {
@@ -432,70 +499,56 @@ class _e extends l {
432
499
  super.setValue(e, r, t);
433
500
  }
434
501
  }
435
- class Re {
502
+ class Te extends D {
436
503
  get(e, r = "_global") {
437
- e = R(e);
504
+ e = _(e);
438
505
  const t = r || "_global";
439
- return v.get(e, t)?.fnState;
506
+ return x.get(e, t)?.fnState;
440
507
  }
441
508
  set(e, r, t = "_global") {
442
- e = R(e);
443
- const i = t || "_global";
444
- v.setValue(e, i, r);
445
- }
446
- clearAll() {
447
- v.clearAll();
448
- }
449
- clear(e, r = "_global") {
450
- const t = r || "_global";
451
- v.clear(e, t);
452
- }
453
- has(e, r = "_global") {
454
- const t = r || "_global";
455
- return !!v.has(e, t);
456
- }
457
- getAll() {
458
- return v.data;
509
+ e = _(e);
510
+ const o = t || "_global";
511
+ x.setValue(e, o, r);
459
512
  }
460
513
  }
461
- const Ce = new Re(), v = new _e(), Ne = (s, e, r) => {
462
- s = R(s);
514
+ const x = new Re(), Ne = new Te(x), Ve = (s, e, r) => {
515
+ s = _(s);
463
516
  const { prefix: t } = W(r);
464
- v.init(s, t);
465
- const i = w(
466
- () => (f) => (v.init(s, t), v.addListener(s, t, f), () => {
467
- 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);
468
521
  }),
469
522
  []
470
- ), b = w(
471
- () => () => v.get(s, t).fnState,
523
+ ), f = w(
524
+ () => () => x.get(s, t).fnState,
472
525
  []
473
- ), S = M(i, b), m = async (f, ...T) => {
474
- const g = v.get(s, t);
475
- if (!f && (g.fnState.isLoading || g.fnState.results !== void 0)) return g.fnState;
476
- 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());
477
530
  try {
478
- const c = await e(...T);
479
- g.fnState = { results: c, isLoading: !1, error: void 0 };
480
- } catch (c) {
481
- 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 };
482
535
  }
483
- g.listeners.forEach((c) => c());
536
+ b.listeners.forEach((l) => l());
484
537
  };
485
- return v.useEffect(s, t), {
486
- state: S,
487
- trigger: (...f) => {
488
- m(!1, ...f);
538
+ return x.useEffect(s, t), {
539
+ state: E,
540
+ trigger: (...d) => {
541
+ S(!1, ...d);
489
542
  },
490
- forceTrigger: (...f) => {
491
- m(!0, ...f);
543
+ forceTrigger: (...d) => {
544
+ S(!0, ...d);
492
545
  },
493
546
  clear: () => {
494
- v.clear(s, t), v.init(s, t);
547
+ x.clear(s, t), x.init(s, t);
495
548
  }
496
549
  };
497
550
  };
498
- class Te extends l {
551
+ class Ae extends c {
499
552
  defaultValue() {
500
553
  return {
501
554
  fnState: {
@@ -513,8 +566,8 @@ class Te extends l {
513
566
  super.setValue(e, r, t);
514
567
  }
515
568
  useEffect(e, r) {
516
- Q(() => () => {
517
- I(`[${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);
518
571
  }, []), super.useEffect(e, r);
519
572
  }
520
573
  async unsubscribe(e, r) {
@@ -522,85 +575,71 @@ class Te extends l {
522
575
  t && (t.unsubscribe && (t.unsubscribe(), t.unsubscribe = void 0), t.fnState.subscribed = !1);
523
576
  }
524
577
  }
525
- class Ae {
578
+ class we extends D {
526
579
  get(e, r = "_global") {
527
- e = R(e);
580
+ e = _(e);
528
581
  const t = r || "_global";
529
- return d.get(e, t)?.fnState;
582
+ return p.get(e, t)?.fnState;
530
583
  }
531
584
  set(e, r, t = "_global") {
532
- e = R(e);
533
- const i = t || "_global";
534
- d.setValue(e, i, r);
535
- }
536
- clearAll() {
537
- d.clearAll();
538
- }
539
- clear(e, r = "_global") {
540
- const t = r || "_global";
541
- d.clear(e, t);
542
- }
543
- has(e, r = "_global") {
544
- const t = r || "_global";
545
- return !!d.has(e, t);
546
- }
547
- getAll() {
548
- return d.data;
585
+ e = _(e);
586
+ const o = t || "_global";
587
+ p.setValue(e, o, r);
549
588
  }
550
589
  }
551
- const Ve = new Ae(), d = new Te(), Ye = (s, e, r) => {
552
- s = R(s);
590
+ const p = new Ae(), Ye = new we(p), Fe = (s, e, r) => {
591
+ s = _(s);
553
592
  const { prefix: t } = W(r);
554
- d.init(s, t);
555
- const i = w(
556
- () => (c) => (d.init(s, t), d.addListener(s, t, c), () => {
557
- 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);
558
597
  }),
559
598
  []
560
- ), b = w(
561
- () => () => d.get(s, t).fnState,
599
+ ), f = w(
600
+ () => () => p.get(s, t).fnState,
562
601
  []
563
- ), S = M(i, b), m = (c) => {
564
- const o = d.get(s, t);
565
- o.fnState = { ...o.fnState, data: c }, o.listeners.forEach((x) => x());
566
- }, f = (c) => {
567
- const o = d.get(s, t);
568
- o.fnState = { ...o.fnState, isLoading: !1, data: void 0, error: c }, o.listeners.forEach((x) => x());
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());
569
608
  }, T = () => {
570
- const c = d.get(s, t);
571
- c.fnState = { ...c.fnState, isLoading: !1 }, c.listeners.forEach((o) => o());
572
- }, g = async (c) => {
573
- const o = d.get(s, t);
574
- 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;
575
- I("triggered !!"), o.fnState = { ...o.fnState, isLoading: !0, error: void 0 }, o.listeners.forEach((x) => x());
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());
576
615
  try {
577
- o.unsubscribe = await e(m, f, T), o.fnState.subscribed = !0;
578
- } catch (x) {
579
- o.fnState = { ...o.fnState, isLoading: !1, error: x };
616
+ i.unsubscribe = await e(S, d, T), i.fnState.subscribed = !0;
617
+ } catch (v) {
618
+ i.fnState = { ...i.fnState, isLoading: !1, error: v };
580
619
  }
581
- o.listeners.forEach((x) => x());
620
+ i.listeners.forEach((v) => v());
582
621
  };
583
- return d.useEffect(s, t), {
584
- state: S,
622
+ return p.useEffect(s, t), {
623
+ state: E,
585
624
  trigger: () => {
586
- g(!1);
625
+ b(!1);
587
626
  },
588
627
  forceTrigger: () => {
589
- g(!0);
628
+ b(!0);
590
629
  },
591
630
  unsubscribe: () => {
592
- d.unsubscribe(s, t);
631
+ p.unsubscribe(s, t);
593
632
  }
594
633
  };
595
634
  };
596
635
  export {
597
636
  Oe as SharedStatesProvider,
598
- y as isDevMode,
599
- Pe as setDevMode,
600
- Ce as sharedFunctionsApi,
601
- je as sharedStatesApi,
602
- Ve as sharedSubscriptionsApi,
603
- Ne as useSharedFunction,
604
- Le as useSharedState,
605
- Ye as useSharedSubscription
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
606
645
  };
package/dist/main.min.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * react-shared-states v1.0.6
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(g,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],f):(g=typeof globalThis<"u"?globalThis:g||self,f(g.ReactSharedStates={},g.React))})(this,function(g,f){"use strict";var C={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,h){var _=null;if(h!==void 0&&(_=""+h),l.key!==void 0&&(_=""+l.key),"key"in l){h={};for(var x in l)x!=="key"&&(h[x]=l[x])}else h=l;return l=h.ref,{$$typeof:s,type:t,key:_,ref:l!==void 0?l:null,props:h}}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===we?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case V:return"Fragment";case ve:return"Profiler";case pe:return"StrictMode";case xe:return"Suspense";case Re:return"SuspenseList";case Ae: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 Se:return"Portal";case me:return(n.displayName||"Context")+".Provider";case Ee: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 Te: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,p=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.",p),e(n)}}function t(n){if(n===V)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===B)return"<...>";try{var a=s(n);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function l(){var n=F.A;return n===null?null:n.getOwner()}function h(){return Error("react-stack-top-frame")}function _(n){if(X.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,p,P,T,I,W){return u=T.ref,n={$$typeof:R,type:n,key:a,props:T,_owner:P},(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 S(n,a,u,p,P,T,I,W){var v=a.children;if(v!==void 0)if(p)if(Pe(v)){for(p=0;p<v.length;p++)c(v[p]);Object.freeze&&Object.freeze(v)}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(v);if(X.call(a,"key")){v=s(n);var O=Object.keys(a).filter(function(Oe){return Oe!=="key"});p=0<O.length?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}",q[v+p]||(O=0<O.length?"{"+O.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} />`,p,v,O,v),q[v+p]=!0)}if(v=null,u!==void 0&&(r(u),v=""+u),_(a)&&(r(a.key),v=""+a.key),"key"in a){u={};for(var U in a)U!=="key"&&(u[U]=a[U])}else u=a;return v&&x(u,typeof n=="function"?n.displayName||n.name||"Unknown":n),w(n,v,T,P,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"),Se=Symbol.for("react.portal"),V=Symbol.for("react.fragment"),pe=Symbol.for("react.strict_mode"),ve=Symbol.for("react.profiler"),Ee=Symbol.for("react.consumer"),me=Symbol.for("react.context"),_e=Symbol.for("react.forward_ref"),xe=Symbol.for("react.suspense"),Re=Symbol.for("react.suspense_list"),Te=Symbol.for("react.memo"),B=Symbol.for("react.lazy"),Ae=Symbol.for("react.activity"),we=Symbol.for("react.client.reference"),F=o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,X=Object.prototype.hasOwnProperty,Pe=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,h)(),K=Y(t(h)),q={};L.Fragment=V,L.jsx=function(n,a,u,p,P){var T=1e4>F.recentlyCreatedOwnerStacks++;return S(n,a,u,!1,p,P,T?Error("react-stack-top-frame"):Q,T?Y(t(n)):K)},L.jsxs=function(n,a,u,p,P){var T=1e4>F.recentlyCreatedOwnerStacks++;return S(n,a,u,!0,p,P,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"?C.exports=y():C.exports=$()),C.exports}var ee=k();const D=f.createContext(void 0),te=({children:s,scopeName:e})=>(e||(e=f.useMemo(()=>Math.random().toString(36).substring(2,15),[])),ee.jsx(D.Provider,{value:{scopeName:e},children:s})),re=()=>f.useContext(D);g.isDevMode=!1;const ne=s=>{g.isDevMode=s},N=(...s)=>{g.isDevMode&&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?.(),N(`[${i.prefix(e,r)}]`,"unmount effect"),this.data.get(i.prefix(e,r)).listeners?.length===0&&this.clear(e,r)},[])}}const M=s=>{const e=re();return{prefix:s??e?.scopeName??"_global"}};class se 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 ae{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 oe=new ae,E=new se,ie=(s,e,r)=>{s=A(s);const{prefix:t}=M(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)}),[]),h=f.useMemo(()=>()=>E.get(s,t)?.value,[]),_=f.useSyncExternalStore(l,h),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 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 ce{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 ue=new ce,m=new le,fe=(s,e,r)=>{s=A(s);const{prefix:t}=M(r);m.init(s,t);const l=f.useMemo(()=>d=>(m.init(s,t),m.addListener(s,t,d),()=>{m.removeListener(s,t,d)}),[]),h=f.useMemo(()=>()=>m.get(s,t).fnState,[]),_=f.useSyncExternalStore(l,h),x=async(d,...w)=>{const S=m.get(s,t);if(!d&&(S.fnState.isLoading||S.fnState.results!==void 0))return S.fnState;S.fnState={...S.fnState,isLoading:!0,error:void 0},S.listeners.forEach(c=>c());try{const c=await e(...w);S.fnState={results:c,isLoading:!1,error:void 0}}catch(c){S.fnState={...S.fnState,isLoading:!1,error:c}}S.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 de 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(()=>()=>{N(`[${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{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 ge=new be,b=new de,he=(s,e,r)=>{s=A(s);const{prefix:t}=M(r);b.init(s,t);const l=f.useMemo(()=>c=>(b.init(s,t),b.addListener(s,t,c),()=>{b.removeListener(s,t,c)}),[]),h=f.useMemo(()=>()=>b.get(s,t).fnState,[]),_=f.useSyncExternalStore(l,h),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())},S=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;N("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:()=>{S(!1)},forceTrigger:()=>{S(!0)},unsubscribe:()=>{b.unsubscribe(s,t)}}};g.SharedStatesProvider=te,g.setDevMode=ne,g.sharedFunctionsApi=ue,g.sharedStatesApi=oe,g.sharedSubscriptionsApi=ge,g.useSharedFunction=fe,g.useSharedState=ie,g.useSharedSubscription=he,Object.defineProperty(g,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.6",
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}`);