cogsbox-state 0.5.29 → 0.5.30

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.
@@ -2,10 +2,10 @@
2
2
  import { jsx as it } from "react/jsx-runtime";
3
3
  import { useState as Y, useRef as J, useEffect as K, useLayoutEffect as It, useMemo as Et, createElement as Q, useSyncExternalStore as _t, startTransition as B } from "react";
4
4
  import { transformStateFunc as pt, isFunction as ft, getNestedValue as G, isDeepEqual as W, debounce as wt } from "./utility.js";
5
- import { pushFunc as st, updateFn as z, cutFunc as ct, ValidationWrapper as $t, FormControlComponent as Vt } from "./Functions.jsx";
5
+ import { pushFunc as st, updateFn as z, cutFunc as ct, ValidationWrapper as Nt, FormControlComponent as Vt } from "./Functions.jsx";
6
6
  import "zod";
7
7
  import { getGlobalStore as r, formRefStore as lt } from "./store.js";
8
- import { useCogsConfig as Nt } from "./CogsStateClient.jsx";
8
+ import { useCogsConfig as $t } from "./CogsStateClient.jsx";
9
9
  import tt from "./node_modules/uuid/dist/esm-browser/v4.js";
10
10
  function dt(t, i) {
11
11
  const f = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, d = f(t) || {};
@@ -48,7 +48,7 @@ const zt = (t, i) => {
48
48
  options: S,
49
49
  initialOptionsPart: d
50
50
  });
51
- const u = r.getState().cogsStateStore[v] || g[v], e = S?.modifyState ? S.modifyState(u) : u, [I, N] = Ot(
51
+ const u = r.getState().cogsStateStore[v] || g[v], e = S?.modifyState ? S.modifyState(u) : u, [I, $] = Ot(
52
52
  e,
53
53
  {
54
54
  stateKey: v,
@@ -63,7 +63,7 @@ const zt = (t, i) => {
63
63
  localStorageKey: S?.localStorageKey
64
64
  }
65
65
  );
66
- return N;
66
+ return $;
67
67
  };
68
68
  function _(v, S) {
69
69
  ut({ stateKey: v, options: S, initialOptionsPart: d });
@@ -143,9 +143,9 @@ function Ot(t, {
143
143
  initState: u,
144
144
  syncUpdate: e
145
145
  } = {}) {
146
- const [I, N] = Y({}), { sessionId: F } = Nt();
146
+ const [I, $] = Y({}), { sessionId: F } = $t();
147
147
  let R = !i;
148
- const [l] = Y(i ?? tt()), x = r.getState().stateLog[l], s = J(/* @__PURE__ */ new Set()), M = J(S ?? tt()), C = J(null);
148
+ const [l] = Y(i ?? tt()), x = r.getState().stateLog[l], s = J(/* @__PURE__ */ new Set()), b = J(S ?? tt()), C = J(null);
149
149
  C.current = et(l), K(() => {
150
150
  if (e && e.stateKey === l && e.path?.[0]) {
151
151
  D(l, (o) => ({
@@ -172,9 +172,9 @@ function Ot(t, {
172
172
  u?.initialState,
173
173
  o,
174
174
  L,
175
- M.current,
175
+ b.current,
176
176
  F
177
- ), console.log("newState222", o), mt(l), N({}));
177
+ ), mt(l), $({}));
178
178
  }, [w, ...u?.dependencies || []]), It(() => {
179
179
  R && dt(l, {
180
180
  serverSync: f,
@@ -183,17 +183,17 @@ function Ot(t, {
183
183
  localStorage: g,
184
184
  middleware: E
185
185
  });
186
- const a = `${l}////${M.current}`, o = r.getState().stateComponents.get(l) || {
186
+ const a = `${l}////${b.current}`, o = r.getState().stateComponents.get(l) || {
187
187
  components: /* @__PURE__ */ new Map()
188
188
  };
189
189
  return o.components.set(a, {
190
- forceUpdate: () => N({}),
190
+ forceUpdate: () => $({}),
191
191
  paths: /* @__PURE__ */ new Set(),
192
192
  deps: [],
193
193
  depsFunction: _ || void 0,
194
194
  reactiveType: v ?? ["component", "deps"]
195
- }), r.getState().stateComponents.set(l, o), N({}), () => {
196
- const c = `${l}////${M.current}`;
195
+ }), r.getState().stateComponents.set(l, o), $({}), () => {
196
+ const c = `${l}////${b.current}`;
197
197
  o && (o.components.delete(c), o.components.size === 0 && r.getState().stateComponents.delete(l));
198
198
  };
199
199
  }, []);
@@ -210,21 +210,21 @@ function Ot(t, {
210
210
  const V = o.slice(0, -1), A = G(h, V);
211
211
  if (Array.isArray(A)) {
212
212
  U = !0;
213
- const $ = `${l}-${V.join(".")}`;
214
- y = r.getState().signalDomElements.get($);
213
+ const N = `${l}-${V.join(".")}`;
214
+ y = r.getState().signalDomElements.get(N);
215
215
  }
216
216
  }
217
217
  if (y) {
218
218
  const V = U ? G(h, o.slice(0, -1)) : G(h, o);
219
- y.forEach(({ parentId: A, position: $, effect: k }) => {
220
- const b = document.querySelector(
219
+ y.forEach(({ parentId: A, position: N, effect: k }) => {
220
+ const O = document.querySelector(
221
221
  `[data-parent-id="${A}"]`
222
222
  );
223
- if (b) {
224
- const ot = Array.from(b.childNodes);
225
- if (ot[$]) {
223
+ if (O) {
224
+ const ot = Array.from(O.childNodes);
225
+ if (ot[N]) {
226
226
  const vt = k ? new Function("state", `return (${k})(state)`)(V) : V;
227
- ot[$].textContent = String(vt);
227
+ ot[N].textContent = String(vt);
228
228
  }
229
229
  }
230
230
  });
@@ -241,11 +241,11 @@ function Ot(t, {
241
241
  ).filter(([y, V]) => {
242
242
  let A = y?.split(".").length;
243
243
  if (y == T.join(".") && A == T.length - 1) {
244
- let $ = y + "." + T;
245
- P(y), Ct($, V);
244
+ let N = y + "." + T;
245
+ P(y), Ct(N, V);
246
246
  }
247
247
  });
248
- const O = G(p, o), q = G(h, o), yt = c.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), rt = r.getState().stateComponents.get(l);
248
+ const M = G(p, o), q = G(h, o), yt = c.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), rt = r.getState().stateComponents.get(l);
249
249
  if (rt)
250
250
  for (const [U, y] of rt.components.entries()) {
251
251
  let V = !1;
@@ -256,8 +256,8 @@ function Ot(t, {
256
256
  continue;
257
257
  }
258
258
  if (A.includes("component") && y.paths && (y.paths.has(yt) || y.paths.has("")) && (V = !0), !V && A.includes("deps") && y.depsFunction) {
259
- const $ = y.depsFunction(h);
260
- typeof $ == "boolean" ? $ && (V = !0) : W(y.deps, $) || (y.deps = $, V = !0);
259
+ const N = y.depsFunction(h);
260
+ typeof N == "boolean" ? N && (V = !0) : W(y.deps, N) || (y.deps = N, V = !0);
261
261
  }
262
262
  V && y.forceUpdate();
263
263
  }
@@ -268,13 +268,13 @@ function Ot(t, {
268
268
  path: o,
269
269
  updateType: c.updateType,
270
270
  status: "new",
271
- oldValue: O,
271
+ oldValue: M,
272
272
  newValue: q
273
273
  };
274
274
  if (At(l, (U) => {
275
- const V = [...U ?? [], at].reduce((A, $) => {
276
- const k = `${$.stateKey}:${JSON.stringify($.path)}`, b = A.get(k);
277
- return b ? (b.timeStamp = Math.max(b.timeStamp, $.timeStamp), b.newValue = $.newValue, b.oldValue = b.oldValue ?? $.oldValue, b.updateType = $.updateType) : A.set(k, { ...$ }), A;
275
+ const V = [...U ?? [], at].reduce((A, N) => {
276
+ const k = `${N.stateKey}:${JSON.stringify(N.path)}`, O = A.get(k);
277
+ return O ? (O.timeStamp = Math.max(O.timeStamp, N.timeStamp), O.newValue = N.newValue, O.oldValue = O.oldValue ?? N.oldValue, O.updateType = N.updateType) : A.set(k, { ...N }), A;
278
278
  }, /* @__PURE__ */ new Map());
279
279
  return Array.from(V.values());
280
280
  }), Ft(
@@ -302,14 +302,14 @@ function Ot(t, {
302
302
  H(
303
303
  l,
304
304
  L,
305
- M.current,
305
+ b.current,
306
306
  F
307
307
  )
308
308
  ), r.getState().cogsStateStore[l] || D(l, t), r.getState().initialStateGlobal[l] || nt(l, t));
309
309
  const n = Et(() => H(
310
310
  l,
311
311
  L,
312
- M.current,
312
+ b.current,
313
313
  F
314
314
  ), [l]);
315
315
  return [gt(l), n];
@@ -331,9 +331,9 @@ function H(t, i, f, g) {
331
331
  e?.key && P(e?.key), u?.validationKey && P(u.validationKey);
332
332
  const I = r.getState().initialStateGlobal[t];
333
333
  d.clear(), E++;
334
- const N = w(I, []);
334
+ const $ = w(I, []);
335
335
  B(() => {
336
- Z(t, N), D(t, I);
336
+ Z(t, $), D(t, I);
337
337
  const F = r.getState().stateComponents.get(t);
338
338
  F && F.components.forEach((l) => {
339
339
  l.forceUpdate();
@@ -355,8 +355,8 @@ function H(t, i, f, g) {
355
355
  return B(() => {
356
356
  nt(t, u), Z(t, e), D(t, u);
357
357
  const I = r.getState().stateComponents.get(t);
358
- I && I.components.forEach((N) => {
359
- N.forceUpdate();
358
+ I && I.components.forEach(($) => {
359
+ $.forceUpdate();
360
360
  }), localStorage.removeItem(t);
361
361
  }), {
362
362
  fetchId: (I) => e.get()[I]
@@ -371,8 +371,8 @@ function H(t, i, f, g) {
371
371
  }
372
372
  };
373
373
  function w(u, e = [], I) {
374
- const N = e.map(String).join(".");
375
- d.get(N);
374
+ const $ = e.map(String).join(".");
375
+ d.get($);
376
376
  const F = function() {
377
377
  return r().getNestedState(t, e);
378
378
  };
@@ -380,7 +380,7 @@ function H(t, i, f, g) {
380
380
  F[x] = S[x];
381
381
  });
382
382
  const R = {
383
- apply(x, s, M) {
383
+ apply(x, s, b) {
384
384
  return r().getNestedState(t, e);
385
385
  },
386
386
  get(x, s) {
@@ -479,10 +479,10 @@ function H(t, i, f, g) {
479
479
  let p = null;
480
480
  if (!c.some((j) => {
481
481
  if (a) {
482
- const O = a.every(
482
+ const M = a.every(
483
483
  (q) => W(j[q], m[q])
484
484
  );
485
- return O && (p = j), O;
485
+ return M && (p = j), M;
486
486
  }
487
487
  const T = W(j, m);
488
488
  return T && (p = j), T;
@@ -490,7 +490,7 @@ function H(t, i, f, g) {
490
490
  _(e), st(i, m, e, t);
491
491
  else if (o && p) {
492
492
  const j = o(p), T = c.map(
493
- (O) => W(O, p) ? j : O
493
+ (M) => W(M, p) ? j : M
494
494
  );
495
495
  _(e), z(i, T, e);
496
496
  }
@@ -514,15 +514,15 @@ function H(t, i, f, g) {
514
514
  });
515
515
  };
516
516
  }
517
- const M = e[e.length - 1];
518
- if (!isNaN(Number(M))) {
517
+ const b = e[e.length - 1];
518
+ if (!isNaN(Number(b))) {
519
519
  const n = e.slice(0, -1), a = r.getState().getNestedState(t, n);
520
520
  if (Array.isArray(a) && s === "cut")
521
521
  return () => ct(
522
522
  i,
523
523
  n,
524
524
  t,
525
- Number(M)
525
+ Number(b)
526
526
  );
527
527
  }
528
528
  if (s === "get")
@@ -578,10 +578,8 @@ function H(t, i, f, g) {
578
578
  });
579
579
  const m = n.zodSchema.safeParse(o);
580
580
  return m.success ? !0 : (m.error.errors.forEach((h) => {
581
- const j = h.path, T = h.message, O = [n.key, ...j].join(".");
582
- a(O, T), console.log(
583
- `Validation error at ${O}: ${T}`
584
- );
581
+ const j = h.path, T = h.message, M = [n.key, ...j].join(".");
582
+ a(M, T);
585
583
  }), mt(t), !1);
586
584
  } catch (c) {
587
585
  return console.error("Zod schema validation failed", c), !1;
@@ -610,7 +608,7 @@ function H(t, i, f, g) {
610
608
  children: n,
611
609
  hideMessage: a
612
610
  }) => /* @__PURE__ */ it(
613
- $t,
611
+ Nt,
614
612
  {
615
613
  formOpts: a ? { validation: { message: "" } } : void 0,
616
614
  path: e,
@@ -653,7 +651,7 @@ function H(t, i, f, g) {
653
651
  return w(L, C, I);
654
652
  }
655
653
  }, l = new Proxy(F, R);
656
- return d.set(N, {
654
+ return d.set($, {
657
655
  proxy: l,
658
656
  stateVersion: E
659
657
  }), l;
@@ -670,7 +668,7 @@ function bt({
670
668
  rebuildStateShape: i
671
669
  }) {
672
670
  const f = r().getNestedState(t._stateKey, t._path);
673
- return console.log("value", f), Array.isArray(f) ? i(
671
+ return Array.isArray(f) ? i(
674
672
  f,
675
673
  t._path
676
674
  ).stateMapNoRender(
@@ -702,8 +700,8 @@ function Mt({
702
700
  "state",
703
701
  `return (${t._effect})(state)`
704
702
  )(u);
705
- } catch (N) {
706
- console.error("Error evaluating effect function during mount:", N), e = u;
703
+ } catch ($) {
704
+ console.error("Error evaluating effect function during mount:", $), e = u;
707
705
  }
708
706
  else
709
707
  e = u;