cogsbox-state 0.5.391 → 0.5.393

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.
@@ -10,37 +10,37 @@ import { getGlobalStore as o, formRefStore as bt } from "./store.js";
10
10
  import { useCogsConfig as Gt } from "./CogsStateClient.jsx";
11
11
  import { applyPatch as Yt } from "fast-json-patch";
12
12
  import Zt from "react-use-measure";
13
- function Mt(t, i) {
13
+ function Mt(t, c) {
14
14
  const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, T = m(t) || {};
15
15
  g(t, {
16
16
  ...T,
17
- ...i
17
+ ...c
18
18
  });
19
19
  }
20
20
  function xt({
21
21
  stateKey: t,
22
- options: i,
22
+ options: c,
23
23
  initialOptionsPart: m
24
24
  }) {
25
25
  const g = rt(t) || {}, T = m[t] || {}, N = o.getState().setInitialStateOptions, p = { ...T, ...g };
26
26
  let v = !1;
27
- if (i)
28
- for (const s in i)
29
- p.hasOwnProperty(s) ? (s == "localStorage" && i[s] && p[s].key !== i[s]?.key && (v = !0, p[s] = i[s]), s == "initialState" && i[s] && p[s] !== i[s] && // Different references
30
- !J(p[s], i[s]) && (v = !0, p[s] = i[s])) : (v = !0, p[s] = i[s]);
27
+ if (c)
28
+ for (const s in c)
29
+ p.hasOwnProperty(s) ? (s == "localStorage" && c[s] && p[s].key !== c[s]?.key && (v = !0, p[s] = c[s]), s == "initialState" && c[s] && p[s] !== c[s] && // Different references
30
+ !J(p[s], c[s]) && (v = !0, p[s] = c[s])) : (v = !0, p[s] = c[s]);
31
31
  v && N(t, p);
32
32
  }
33
- function Te(t, { formElements: i, validation: m }) {
34
- return { initialState: t, formElements: i, validation: m };
33
+ function Te(t, { formElements: c, validation: m }) {
34
+ return { initialState: t, formElements: c, validation: m };
35
35
  }
36
- const ve = (t, i) => {
36
+ const ve = (t, c) => {
37
37
  let m = t;
38
38
  const [g, T] = Bt(m);
39
- (Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
39
+ (Object.keys(T).length > 0 || c && Object.keys(c).length > 0) && Object.keys(T).forEach((v) => {
40
40
  T[v] = T[v] || {}, T[v].formElements = {
41
- ...i?.formElements,
41
+ ...c?.formElements,
42
42
  // Global defaults first
43
- ...i?.validation,
43
+ ...c?.validation,
44
44
  ...T[v].formElements || {}
45
45
  // State-specific overrides
46
46
  }, rt(v) || o.getState().setInitialStateOptions(v, T[v]);
@@ -52,8 +52,8 @@ const ve = (t, i) => {
52
52
  options: s,
53
53
  initialOptionsPart: T
54
54
  });
55
- const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] = ne(
56
- S,
55
+ const r = o.getState().cogsStateStore[v] || g[v], f = s?.modifyState ? s.modifyState(r) : r, [W, j] = ne(
56
+ f,
57
57
  {
58
58
  stateKey: v,
59
59
  syncUpdate: s?.syncUpdate,
@@ -85,16 +85,16 @@ const ve = (t, i) => {
85
85
  addValidationError: Rt,
86
86
  removeValidationError: X,
87
87
  setServerSyncActions: Kt
88
- } = o.getState(), Pt = (t, i, m, g, T) => {
88
+ } = o.getState(), Pt = (t, c, m, g, T) => {
89
89
  m?.log && console.log(
90
90
  "saving to localstorage",
91
- i,
91
+ c,
92
92
  m.localStorage?.key,
93
93
  g
94
94
  );
95
95
  const N = tt(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
96
  if (N && g) {
97
- const p = `${g}-${i}-${N}`;
97
+ const p = `${g}-${c}-${N}`;
98
98
  let v;
99
99
  try {
100
100
  v = vt(p)?.lastSyncedWithServer;
@@ -113,13 +113,13 @@ const ve = (t, i) => {
113
113
  }, vt = (t) => {
114
114
  if (!t) return null;
115
115
  try {
116
- const i = window.localStorage.getItem(t);
117
- return i ? JSON.parse(i) : null;
118
- } catch (i) {
119
- return console.error("Error loading from localStorage:", i), null;
116
+ const c = window.localStorage.getItem(t);
117
+ return c ? JSON.parse(c) : null;
118
+ } catch (c) {
119
+ return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
- }, te = (t, i) => {
122
- const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(), T = tt(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
121
+ }, te = (t, c) => {
122
+ const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(), T = tt(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
123
123
  if (T && g) {
124
124
  const N = vt(
125
125
  `${g}-${t}-${T}`
@@ -128,9 +128,9 @@ const ve = (t, i) => {
128
128
  return nt(t, N.state), dt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Dt = (t, i, m, g, T, N) => {
131
+ }, Dt = (t, c, m, g, T, N) => {
132
132
  const p = {
133
- initialState: i,
133
+ initialState: c,
134
134
  updaterState: Tt(
135
135
  t,
136
136
  g,
@@ -141,27 +141,27 @@ const ve = (t, i) => {
141
141
  };
142
142
  Nt(t, p.initialState), It(t, p.updaterState), nt(t, p.state);
143
143
  }, dt = (t) => {
144
- const i = o.getState().stateComponents.get(t);
145
- if (!i) return;
144
+ const c = o.getState().stateComponents.get(t);
145
+ if (!c) return;
146
146
  const m = /* @__PURE__ */ new Set();
147
- i.components.forEach((g) => {
147
+ c.components.forEach((g) => {
148
148
  (g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || m.add(() => g.forceUpdate());
149
149
  }), queueMicrotask(() => {
150
150
  m.forEach((g) => g());
151
151
  });
152
- }, ye = (t, i) => {
152
+ }, ye = (t, c) => {
153
153
  const m = o.getState().stateComponents.get(t);
154
154
  if (m) {
155
- const g = `${t}////${i}`, T = m.components.get(g);
155
+ const g = `${t}////${c}`, T = m.components.get(g);
156
156
  if ((T ? Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"] : null)?.includes("none"))
157
157
  return;
158
158
  T && T.forceUpdate();
159
159
  }
160
- }, ee = (t, i, m, g) => {
160
+ }, ee = (t, c, m, g) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: Z(i, g),
164
+ oldValue: Z(c, g),
165
165
  newValue: Z(m, g)
166
166
  };
167
167
  case "insert":
@@ -172,7 +172,7 @@ const ve = (t, i) => {
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: Z(i, g),
175
+ oldValue: Z(c, g),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -181,7 +181,7 @@ const ve = (t, i) => {
181
181
  }
182
182
  };
183
183
  function ne(t, {
184
- stateKey: i,
184
+ stateKey: c,
185
185
  serverSync: m,
186
186
  localStorage: g,
187
187
  formElements: T,
@@ -191,11 +191,11 @@ function ne(t, {
191
191
  initialState: s,
192
192
  syncUpdate: I,
193
193
  dependencies: r,
194
- serverState: S
194
+ serverState: f
195
195
  } = {}) {
196
196
  const [W, j] = K({}), { sessionId: U } = Gt();
197
- let z = !i;
198
- const [h] = K(i ?? At()), l = o.getState().stateLog[h], ut = q(/* @__PURE__ */ new Set()), et = q(v ?? At()), L = q(
197
+ let z = !c;
198
+ const [h] = K(c ?? At()), l = o.getState().stateLog[h], ut = q(/* @__PURE__ */ new Set()), et = q(v ?? At()), L = q(
199
199
  null
200
200
  );
201
201
  L.current = rt(h) ?? null, ot(() => {
@@ -215,8 +215,8 @@ function ne(t, {
215
215
  Mt(h, {
216
216
  initialState: s
217
217
  });
218
- const e = L.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[h];
219
- if (!(c && !J(c, s) || !c) && !a)
218
+ const e = L.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
219
+ if (!(i && !J(i, s) || !i) && !a)
220
220
  return;
221
221
  let u = null;
222
222
  const E = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
@@ -234,8 +234,8 @@ function ne(t, {
234
234
  }
235
235
  }, [
236
236
  s,
237
- S?.status,
238
- S?.data,
237
+ f?.status,
238
+ f?.data,
239
239
  ...r || []
240
240
  ]), ct(() => {
241
241
  z && Mt(h, {
@@ -258,22 +258,22 @@ function ne(t, {
258
258
  n && (n.components.delete(e), n.components.size === 0 && o.getState().stateComponents.delete(h));
259
259
  };
260
260
  }, []);
261
- const at = (e, n, a, c) => {
261
+ const at = (e, n, a, i) => {
262
262
  if (Array.isArray(n)) {
263
263
  const u = `${h}-${n.join(".")}`;
264
264
  ut.current.add(u);
265
265
  }
266
- const f = o.getState();
266
+ const S = o.getState();
267
267
  nt(h, (u) => {
268
268
  const E = tt(e) ? e(u) : e, y = `${h}-${n.join(".")}`;
269
269
  if (y) {
270
- let M = !1, $ = f.signalDomElements.get(y);
270
+ let M = !1, $ = S.signalDomElements.get(y);
271
271
  if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
272
  const R = n.slice(0, -1), V = Z(E, R);
273
273
  if (Array.isArray(V)) {
274
274
  M = !0;
275
275
  const O = `${h}-${R.join(".")}`;
276
- $ = f.signalDomElements.get(O);
276
+ $ = S.signalDomElements.get(O);
277
277
  }
278
278
  }
279
279
  if ($) {
@@ -292,8 +292,8 @@ function ne(t, {
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (c || L.current?.validation?.key) && n && X(
296
- (c || L.current?.validation?.key) + "." + n.join(".")
295
+ console.log("shadowState", S.shadowStateStore), a.updateType === "update" && (i || L.current?.validation?.key) && n && X(
296
+ (i || L.current?.validation?.key) + "." + n.join(".")
297
297
  );
298
298
  const w = n.slice(0, n.length - 1);
299
299
  a.updateType === "cut" && L.current?.validation?.key && X(
@@ -307,7 +307,7 @@ function ne(t, {
307
307
  X($), Rt(O, R);
308
308
  }
309
309
  });
310
- const C = f.stateComponents.get(h);
310
+ const C = S.stateComponents.get(h);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
312
312
  const M = _t(u, E), $ = new Set(M), R = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
313
313
  for (const [
@@ -379,15 +379,15 @@ function ne(t, {
379
379
  };
380
380
  switch (a.updateType) {
381
381
  case "update":
382
- f.updateShadowAtPath(h, n, E);
382
+ S.updateShadowAtPath(h, n, E);
383
383
  break;
384
384
  case "insert":
385
385
  const M = n.slice(0, -1);
386
- f.insertShadowArrayElement(h, M, F);
386
+ S.insertShadowArrayElement(h, M, F);
387
387
  break;
388
388
  case "cut":
389
389
  const $ = n.slice(0, -1), R = parseInt(n[n.length - 1]);
390
- f.removeShadowArrayElement(h, $, R);
390
+ S.removeShadowArrayElement(h, $, R);
391
391
  break;
392
392
  }
393
393
  if (Qt(h, (M) => {
@@ -405,7 +405,7 @@ function ne(t, {
405
405
  updateLog: l,
406
406
  update: Y
407
407
  }), L.current?.serverSync) {
408
- const M = f.serverState[h], $ = L.current?.serverSync;
408
+ const M = S.serverState[h], $ = L.current?.serverSync;
409
409
  Kt(h, {
410
410
  syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
411
411
  rollBackState: M,
@@ -433,13 +433,13 @@ function ne(t, {
433
433
  ), [h, U]);
434
434
  return [Lt(h), d];
435
435
  }
436
- function Tt(t, i, m, g) {
436
+ function Tt(t, c, m, g) {
437
437
  const T = /* @__PURE__ */ new Map();
438
438
  let N = 0;
439
439
  const p = (I) => {
440
440
  const r = I.join(".");
441
- for (const [S] of T)
442
- (S === r || S.startsWith(r + ".")) && T.delete(S);
441
+ for (const [f] of T)
442
+ (f === r || f.startsWith(r + ".")) && T.delete(f);
443
443
  N++;
444
444
  }, v = {
445
445
  removeValidation: (I) => {
@@ -448,23 +448,23 @@ function Tt(t, i, m, g) {
448
448
  revertToInitialState: (I) => {
449
449
  const r = o.getState().getInitialOptions(t)?.validation;
450
450
  r?.key && X(r?.key), I?.validationKey && X(I.validationKey);
451
- const S = o.getState().initialStateGlobal[t];
451
+ const f = o.getState().initialStateGlobal[t];
452
452
  o.getState().clearSelectedIndexesForState(t), T.clear(), N++;
453
- const W = s(S, []), j = rt(t), U = tt(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, z = `${g}-${t}-${U}`;
454
- z && localStorage.removeItem(z), It(t, W), nt(t, S);
453
+ const W = s(f, []), j = rt(t), U = tt(j?.localStorage?.key) ? j?.localStorage?.key(f) : j?.localStorage?.key, z = `${g}-${t}-${U}`;
454
+ z && localStorage.removeItem(z), It(t, W), nt(t, f);
455
455
  const h = o.getState().stateComponents.get(t);
456
456
  return h && h.components.forEach((l) => {
457
457
  l.forceUpdate();
458
- }), S;
458
+ }), f;
459
459
  },
460
460
  updateInitialState: (I) => {
461
461
  T.clear(), N++;
462
462
  const r = Tt(
463
463
  t,
464
- i,
464
+ c,
465
465
  m,
466
466
  g
467
- ), S = o.getState().initialStateGlobal[t], W = rt(t), j = tt(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${g}-${t}-${j}`;
467
+ ), f = o.getState().initialStateGlobal[t], W = rt(t), j = tt(W?.localStorage?.key) ? W?.localStorage?.key(f) : W?.localStorage?.key, U = `${g}-${t}-${j}`;
468
468
  return localStorage.getItem(U) && localStorage.removeItem(U), Ft(() => {
469
469
  Nt(t, I), o.getState().initializeShadowState(t, I), It(t, r), nt(t, I);
470
470
  const z = o.getState().stateComponents.get(t);
@@ -483,7 +483,7 @@ function Tt(t, i, m, g) {
483
483
  return !!(I && J(I, Lt(t)));
484
484
  }
485
485
  };
486
- function s(I, r = [], S) {
486
+ function s(I, r = [], f) {
487
487
  const W = r.map(String).join(".");
488
488
  T.get(W);
489
489
  const j = function() {
@@ -499,7 +499,7 @@ function Tt(t, i, m, g) {
499
499
  ), console.trace("Apply trap stack trace"), o().getNestedState(t, r);
500
500
  },
501
501
  get(h, l) {
502
- S?.validIndices && !Array.isArray(I) && (S = { ...S, validIndices: void 0 });
502
+ f?.validIndices && !Array.isArray(I) && (f = { ...f, validIndices: void 0 });
503
503
  const ut = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
@@ -529,13 +529,13 @@ function Tt(t, i, m, g) {
529
529
  const n = e.components.get(d);
530
530
  if (n && !n.paths.has("")) {
531
531
  const a = r.join(".");
532
- let c = !0;
533
- for (const f of n.paths)
534
- if (a.startsWith(f) && (a === f || a[f.length] === ".")) {
535
- c = !1;
532
+ let i = !0;
533
+ for (const S of n.paths)
534
+ if (a.startsWith(S) && (a === S || a[S.length] === ".")) {
535
+ i = !1;
536
536
  break;
537
537
  }
538
- c && n.paths.add(a);
538
+ i && n.paths.add(a);
539
539
  }
540
540
  }
541
541
  }
@@ -551,20 +551,20 @@ function Tt(t, i, m, g) {
551
551
  return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
552
552
  const n = o.getState().getNestedState(t, []), a = d?.validation?.key;
553
553
  try {
554
- const c = await e.action(n);
555
- if (c && !c.success && c.errors && a) {
556
- o.getState().removeValidationError(a), c.errors.forEach((u) => {
554
+ const i = await e.action(n);
555
+ if (i && !i.success && i.errors && a) {
556
+ o.getState().removeValidationError(a), i.errors.forEach((u) => {
557
557
  const E = [a, ...u.path].join(".");
558
558
  o.getState().addValidationError(E, u.message);
559
559
  });
560
- const f = o.getState().stateComponents.get(t);
561
- f && f.components.forEach((u) => {
560
+ const S = o.getState().stateComponents.get(t);
561
+ S && S.components.forEach((u) => {
562
562
  u.forceUpdate();
563
563
  });
564
564
  }
565
- return c?.success && e.onSuccess ? e.onSuccess(c.data) : !c?.success && e.onError && e.onError(c.error), c;
566
- } catch (c) {
567
- return e.onError && e.onError(c), { success: !1, error: c };
565
+ return i?.success && e.onSuccess ? e.onSuccess(i.data) : !i?.success && e.onError && e.onError(i.error), i;
566
+ } catch (i) {
567
+ return e.onError && e.onError(i), { success: !1, error: i };
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
@@ -592,9 +592,9 @@ function Tt(t, i, m, g) {
592
592
  return o.getState().getValidationErrors(d.key + "." + r.join("."));
593
593
  };
594
594
  if (Array.isArray(I)) {
595
- const d = () => S?.validIndices ? I.map((n, a) => ({
595
+ const d = () => f?.validIndices ? I.map((n, a) => ({
596
596
  item: n,
597
- originalIndex: S.validIndices[a]
597
+ originalIndex: f.validIndices[a]
598
598
  })) : o.getState().getNestedState(t, r).map((n, a) => ({
599
599
  item: n,
600
600
  originalIndex: a
@@ -606,7 +606,7 @@ function Tt(t, i, m, g) {
606
606
  return s(
607
607
  I[e],
608
608
  [...r, e.toString()],
609
- S
609
+ f
610
610
  );
611
611
  };
612
612
  if (l === "clearSelected")
@@ -620,12 +620,12 @@ function Tt(t, i, m, g) {
620
620
  const {
621
621
  itemHeight: n = 50,
622
622
  overscan: a = 6,
623
- stickToBottom: c = !1,
624
- dependencies: f = []
623
+ stickToBottom: i = !1,
624
+ dependencies: S = []
625
625
  } = e, u = q(!1), E = q(null), [y, w] = K({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
- }), [C, A] = K("IDLE_AT_TOP"), b = q(!1), F = q(0), Y = q(f), M = q(0), [$, R] = K(0), V = q(null);
628
+ }), [C, A] = K("IDLE_AT_TOP"), b = q(!1), F = q(0), Y = q(S), M = q(0), [$, R] = K(0), V = q(null);
629
629
  ot(() => o.getState().subscribeToShadowState(t, () => {
630
630
  R((x) => x + 1);
631
631
  }), [t]);
@@ -654,7 +654,7 @@ function Tt(t, i, m, g) {
654
654
  (Q, ft) => k + ft
655
655
  ), P = H.map((Q) => O[Q]);
656
656
  return s(P, r, {
657
- ...S,
657
+ ...f,
658
658
  validIndices: H
659
659
  });
660
660
  }, [y.startIndex, y.endIndex, O, _]);
@@ -671,22 +671,22 @@ function Tt(t, i, m, g) {
671
671
  }, 100), V.current = null;
672
672
  } else {
673
673
  if (!J(
674
- f,
674
+ S,
675
675
  Y.current
676
676
  )) {
677
677
  console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), A("IDLE_AT_TOP");
678
678
  return;
679
679
  }
680
- x && C === "LOCKED_AT_BOTTOM" && c && (console.log(
680
+ x && C === "LOCKED_AT_BOTTOM" && i && (console.log(
681
681
  "TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
682
682
  ), A("GETTING_HEIGHTS"));
683
683
  }
684
- F.current = _, Y.current = f;
685
- }, [_, ...f]), ct(() => {
684
+ F.current = _, Y.current = S;
685
+ }, [_, ...S]), ct(() => {
686
686
  const k = E.current;
687
687
  if (!k) return;
688
688
  let x;
689
- if (C === "IDLE_AT_TOP" && c && _ > 0)
689
+ if (C === "IDLE_AT_TOP" && i && _ > 0)
690
690
  console.log(
691
691
  "ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
692
692
  ), A("GETTING_HEIGHTS");
@@ -798,34 +798,34 @@ function Tt(t, i, m, g) {
798
798
  return (e) => {
799
799
  const a = [...d()].sort(
800
800
  (u, E) => e(u.item, E.item)
801
- ), c = a.map(({ item: u }) => u), f = {
802
- ...S,
801
+ ), i = a.map(({ item: u }) => u), S = {
802
+ ...f,
803
803
  validIndices: a.map(
804
804
  ({ originalIndex: u }) => u
805
805
  )
806
806
  };
807
- return s(c, r, f);
807
+ return s(i, r, S);
808
808
  };
809
809
  if (l === "stateFilter")
810
810
  return (e) => {
811
811
  const a = d().filter(
812
812
  ({ item: u }, E) => e(u, E)
813
- ), c = a.map(({ item: u }) => u), f = {
814
- ...S,
813
+ ), i = a.map(({ item: u }) => u), S = {
814
+ ...f,
815
815
  validIndices: a.map(
816
816
  ({ originalIndex: u }) => u
817
817
  )
818
818
  };
819
- return s(c, r, f);
819
+ return s(i, r, S);
820
820
  };
821
821
  if (l === "stateMap")
822
822
  return (e) => {
823
823
  const n = o.getState().getNestedState(t, r);
824
- return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (c, f) => f)).map((c, f) => {
825
- const u = n[c], E = [...r, c.toString()], y = s(u, E, S);
824
+ return Array.isArray(n) ? (f?.validIndices || Array.from({ length: n.length }, (i, S) => S)).map((i, S) => {
825
+ const u = n[i], E = [...r, i.toString()], y = s(u, E, f);
826
826
  return e(u, y, {
827
827
  register: () => {
828
- const [, C] = K({}), A = `${m}-${r.join(".")}-${c}`;
828
+ const [, C] = K({}), A = `${m}-${r.join(".")}-${i}`;
829
829
  ct(() => {
830
830
  const b = `${t}////${A}`, F = o.getState().stateComponents.get(t) || {
831
831
  components: /* @__PURE__ */ new Map()
@@ -839,8 +839,8 @@ function Tt(t, i, m, g) {
839
839
  };
840
840
  }, [t, A]);
841
841
  },
842
- index: f,
843
- originalIndex: c
842
+ index: S,
843
+ originalIndex: i
844
844
  });
845
845
  }) : (console.warn(
846
846
  `stateMap called on a non-array value at path: ${r.join(".")}. The current value is:`,
@@ -848,16 +848,16 @@ function Tt(t, i, m, g) {
848
848
  ), null);
849
849
  };
850
850
  if (l === "stateMapNoRender")
851
- return (e) => I.map((a, c) => {
852
- let f;
853
- S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
854
- const u = [...r, f.toString()], E = s(a, u, S);
851
+ return (e) => I.map((a, i) => {
852
+ let S;
853
+ f?.validIndices && f.validIndices[i] !== void 0 ? S = f.validIndices[i] : S = i;
854
+ const u = [...r, S.toString()], E = s(a, u, f);
855
855
  return e(
856
856
  a,
857
857
  E,
858
- c,
858
+ i,
859
859
  I,
860
- s(I, r, S)
860
+ s(I, r, f)
861
861
  );
862
862
  });
863
863
  if (l === "$stateMap")
@@ -873,19 +873,19 @@ function Tt(t, i, m, g) {
873
873
  if (l === "stateList")
874
874
  return (e) => {
875
875
  const n = o.getState().getNestedState(t, r);
876
- return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (c, f) => f)).map((c, f) => {
877
- const u = n[c], E = [...r, c.toString()], y = s(u, E, S), w = `${m}-${r.join(".")}-${c}`;
876
+ return Array.isArray(n) ? (f?.validIndices || Array.from({ length: n.length }, (i, S) => S)).map((i, S) => {
877
+ const u = n[i], E = [...r, i.toString()], y = s(u, E, f), w = `${m}-${r.join(".")}-${i}`;
878
878
  return lt(ae, {
879
- key: c,
879
+ key: i,
880
880
  stateKey: t,
881
881
  itemComponentId: w,
882
882
  itemPath: E,
883
883
  children: e(
884
884
  u,
885
885
  y,
886
- f,
886
+ i,
887
887
  n,
888
- s(n, r, S)
888
+ s(n, r, f)
889
889
  )
890
890
  });
891
891
  }) : (console.warn(
@@ -897,12 +897,12 @@ function Tt(t, i, m, g) {
897
897
  const n = I;
898
898
  T.clear(), N++;
899
899
  const a = n.flatMap(
900
- (c) => c[e] ?? []
900
+ (i) => i[e] ?? []
901
901
  );
902
902
  return s(
903
903
  a,
904
904
  [...r, "[*]", e],
905
- S
905
+ f
906
906
  );
907
907
  };
908
908
  if (l === "index")
@@ -914,40 +914,40 @@ function Tt(t, i, m, g) {
914
914
  return () => {
915
915
  const e = o.getState().getNestedState(t, r);
916
916
  if (e.length === 0) return;
917
- const n = e.length - 1, a = e[n], c = [...r, n.toString()];
918
- return s(a, c);
917
+ const n = e.length - 1, a = e[n], i = [...r, n.toString()];
918
+ return s(a, i);
919
919
  };
920
920
  if (l === "insert")
921
- return (e) => (p(r), Et(i, e, r, t), s(
921
+ return (e) => (p(r), Et(c, e, r, t), s(
922
922
  o.getState().getNestedState(t, r),
923
923
  r
924
924
  ));
925
925
  if (l === "uniqueInsert")
926
926
  return (e, n, a) => {
927
- const c = o.getState().getNestedState(t, r), f = tt(e) ? e(c) : e;
927
+ const i = o.getState().getNestedState(t, r), S = tt(e) ? e(i) : e;
928
928
  let u = null;
929
- if (!c.some((y) => {
929
+ if (!i.some((y) => {
930
930
  if (n) {
931
931
  const C = n.every(
932
- (A) => J(y[A], f[A])
932
+ (A) => J(y[A], S[A])
933
933
  );
934
934
  return C && (u = y), C;
935
935
  }
936
- const w = J(y, f);
936
+ const w = J(y, S);
937
937
  return w && (u = y), w;
938
938
  }))
939
- p(r), Et(i, f, r, t);
939
+ p(r), Et(c, S, r, t);
940
940
  else if (a && u) {
941
- const y = a(u), w = c.map(
941
+ const y = a(u), w = i.map(
942
942
  (C) => J(C, u) ? y : C
943
943
  );
944
- p(r), it(i, w, r);
944
+ p(r), it(c, w, r);
945
945
  }
946
946
  };
947
947
  if (l === "cut")
948
948
  return (e, n) => {
949
949
  if (!n?.waitForSync)
950
- return p(r), ht(i, r, t, e), s(
950
+ return p(r), ht(c, r, t, e), s(
951
951
  o.getState().getNestedState(t, r),
952
952
  r
953
953
  );
@@ -955,30 +955,30 @@ function Tt(t, i, m, g) {
955
955
  if (l === "cutByValue")
956
956
  return (e) => {
957
957
  for (let n = 0; n < I.length; n++)
958
- I[n] === e && ht(i, r, t, n);
958
+ I[n] === e && ht(c, r, t, n);
959
959
  };
960
960
  if (l === "toggleByValue")
961
961
  return (e) => {
962
962
  const n = I.findIndex((a) => a === e);
963
- n > -1 ? ht(i, r, t, n) : Et(i, e, r, t);
963
+ n > -1 ? ht(c, r, t, n) : Et(c, e, r, t);
964
964
  };
965
965
  if (l === "stateFind")
966
966
  return (e) => {
967
967
  const a = d().find(
968
- ({ item: f }, u) => e(f, u)
968
+ ({ item: S }, u) => e(S, u)
969
969
  );
970
970
  if (!a) return;
971
- const c = [...r, a.originalIndex.toString()];
972
- return s(a.item, c, S);
971
+ const i = [...r, a.originalIndex.toString()];
972
+ return s(a.item, i, f);
973
973
  };
974
974
  if (l === "findWith")
975
975
  return (e, n) => {
976
- const c = d().find(
976
+ const i = d().find(
977
977
  ({ item: u }) => u[e] === n
978
978
  );
979
- if (!c) return;
980
- const f = [...r, c.originalIndex.toString()];
981
- return s(c.item, f, S);
979
+ if (!i) return;
980
+ const S = [...r, i.originalIndex.toString()];
981
+ return s(i.item, S, f);
982
982
  };
983
983
  }
984
984
  const et = r[r.length - 1];
@@ -986,7 +986,7 @@ function Tt(t, i, m, g) {
986
986
  const d = r.slice(0, -1), e = o.getState().getNestedState(t, d);
987
987
  if (Array.isArray(e) && l === "cut")
988
988
  return () => ht(
989
- i,
989
+ c,
990
990
  d,
991
991
  t,
992
992
  Number(et)
@@ -994,9 +994,9 @@ function Tt(t, i, m, g) {
994
994
  }
995
995
  if (l === "get")
996
996
  return () => {
997
- if (S?.validIndices && Array.isArray(I)) {
997
+ if (f?.validIndices && Array.isArray(I)) {
998
998
  const d = o.getState().getNestedState(t, r);
999
- return S.validIndices.map((e) => d[e]);
999
+ return f.validIndices.map((e) => d[e]);
1000
1000
  }
1001
1001
  return o.getState().getNestedState(t, r);
1002
1002
  };
@@ -1025,8 +1025,8 @@ function Tt(t, i, m, g) {
1025
1025
  return (d) => {
1026
1026
  const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
1027
1027
  d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
1028
- const c = o.getState().getNestedState(t, [...e]);
1029
- it(i, c, e), p(e);
1028
+ const i = o.getState().getNestedState(t, [...e]);
1029
+ it(c, i, e), p(e);
1030
1030
  };
1031
1031
  if (l === "toggleSelected")
1032
1032
  return () => {
@@ -1036,8 +1036,8 @@ function Tt(t, i, m, g) {
1036
1036
  n,
1037
1037
  a === e ? void 0 : e
1038
1038
  );
1039
- const c = o.getState().getNestedState(t, [...d]);
1040
- it(i, c, d), p(d);
1039
+ const i = o.getState().getNestedState(t, [...d]);
1040
+ it(c, i, d), p(d);
1041
1041
  };
1042
1042
  if (r.length == 0) {
1043
1043
  if (l === "addValidation")
@@ -1057,17 +1057,17 @@ function Tt(t, i, m, g) {
1057
1057
  t,
1058
1058
  o.getState().initialStateGlobal[t],
1059
1059
  a,
1060
- i,
1060
+ c,
1061
1061
  m,
1062
1062
  g
1063
1063
  );
1064
- const c = o.getState().stateComponents.get(t);
1065
- if (c) {
1066
- const f = _t(e, a), u = new Set(f);
1064
+ const i = o.getState().stateComponents.get(t);
1065
+ if (i) {
1066
+ const S = _t(e, a), u = new Set(S);
1067
1067
  for (const [
1068
1068
  E,
1069
1069
  y
1070
- ] of c.components.entries()) {
1070
+ ] of i.components.entries()) {
1071
1071
  let w = !1;
1072
1072
  const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
1073
1073
  if (!C.includes("none")) {
@@ -1129,11 +1129,11 @@ function Tt(t, i, m, g) {
1129
1129
  const n = o.getState().cogsStateStore[t];
1130
1130
  try {
1131
1131
  const a = o.getState().getValidationErrors(d.key);
1132
- a && a.length > 0 && a.forEach(([f]) => {
1133
- f && f.startsWith(d.key) && X(f);
1132
+ a && a.length > 0 && a.forEach(([S]) => {
1133
+ S && S.startsWith(d.key) && X(S);
1134
1134
  });
1135
- const c = d.zodSchema.safeParse(n);
1136
- return c.success ? !0 : (c.error.errors.forEach((u) => {
1135
+ const i = d.zodSchema.safeParse(n);
1136
+ return i.success ? !0 : (i.error.errors.forEach((u) => {
1137
1137
  const E = u.path, y = u.message, w = [d.key, ...E].join(".");
1138
1138
  e(w, y);
1139
1139
  }), dt(t), !1);
@@ -1170,7 +1170,7 @@ function Tt(t, i, m, g) {
1170
1170
  path: r,
1171
1171
  validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
1172
1172
  stateKey: t,
1173
- validIndices: S?.validIndices,
1173
+ validIndices: f?.validIndices,
1174
1174
  children: d
1175
1175
  }
1176
1176
  );
@@ -1181,12 +1181,12 @@ function Tt(t, i, m, g) {
1181
1181
  return (d, e) => {
1182
1182
  if (e?.debounce)
1183
1183
  Wt(() => {
1184
- it(i, d, r, "");
1184
+ it(c, d, r, "");
1185
1185
  const n = o.getState().getNestedState(t, r);
1186
1186
  e?.afterUpdate && e.afterUpdate(n);
1187
1187
  }, e.debounce);
1188
1188
  else {
1189
- it(i, d, r, "");
1189
+ it(c, d, r, "");
1190
1190
  const n = o.getState().getNestedState(t, r);
1191
1191
  e?.afterUpdate && e.afterUpdate(n);
1192
1192
  }
@@ -1196,7 +1196,7 @@ function Tt(t, i, m, g) {
1196
1196
  return (d, e) => /* @__PURE__ */ Ot(
1197
1197
  qt,
1198
1198
  {
1199
- setState: i,
1199
+ setState: c,
1200
1200
  stateKey: t,
1201
1201
  path: r,
1202
1202
  child: d,
@@ -1204,7 +1204,7 @@ function Tt(t, i, m, g) {
1204
1204
  }
1205
1205
  );
1206
1206
  const L = [...r, l], at = o.getState().getNestedState(t, L);
1207
- return s(at, L, S);
1207
+ return s(at, L, f);
1208
1208
  }
1209
1209
  }, z = new Proxy(j, U);
1210
1210
  return T.set(W, {
@@ -1221,10 +1221,10 @@ function Vt(t) {
1221
1221
  }
1222
1222
  function re({
1223
1223
  proxy: t,
1224
- rebuildStateShape: i
1224
+ rebuildStateShape: c
1225
1225
  }) {
1226
1226
  const m = o().getNestedState(t._stateKey, t._path);
1227
- return Array.isArray(m) ? i(
1227
+ return Array.isArray(m) ? c(
1228
1228
  m,
1229
1229
  t._path
1230
1230
  ).stateMapNoRender(
@@ -1234,9 +1234,9 @@ function re({
1234
1234
  function oe({
1235
1235
  proxy: t
1236
1236
  }) {
1237
- const i = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
1237
+ const c = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
1238
1238
  return ot(() => {
1239
- const g = i.current;
1239
+ const g = c.current;
1240
1240
  if (!g || !g.parentElement) return;
1241
1241
  const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
1242
1242
  let v = T.getAttribute("data-parent-id");
@@ -1249,29 +1249,29 @@ function oe({
1249
1249
  };
1250
1250
  o.getState().addSignalElement(m, I);
1251
1251
  const r = o.getState().getNestedState(t._stateKey, t._path);
1252
- let S;
1252
+ let f;
1253
1253
  if (t._effect)
1254
1254
  try {
1255
- S = new Function(
1255
+ f = new Function(
1256
1256
  "state",
1257
1257
  `return (${t._effect})(state)`
1258
1258
  )(r);
1259
1259
  } catch (j) {
1260
- console.error("Error evaluating effect function during mount:", j), S = r;
1260
+ console.error("Error evaluating effect function during mount:", j), f = r;
1261
1261
  }
1262
1262
  else
1263
- S = r;
1264
- S !== null && typeof S == "object" && (S = JSON.stringify(S));
1265
- const W = document.createTextNode(String(S));
1263
+ f = r;
1264
+ f !== null && typeof f == "object" && (f = JSON.stringify(f));
1265
+ const W = document.createTextNode(String(f));
1266
1266
  g.replaceWith(W);
1267
1267
  }, [t._stateKey, t._path.join("."), t._effect]), lt("span", {
1268
- ref: i,
1268
+ ref: c,
1269
1269
  style: { display: "none" },
1270
1270
  "data-signal-id": m
1271
1271
  });
1272
1272
  }
1273
1273
  function pe(t) {
1274
- const i = Ht(
1274
+ const c = Ht(
1275
1275
  (m) => {
1276
1276
  const g = o.getState().stateComponents.get(t._stateKey) || {
1277
1277
  components: /* @__PURE__ */ new Map()
@@ -1283,11 +1283,11 @@ function pe(t) {
1283
1283
  },
1284
1284
  () => o.getState().getNestedState(t._stateKey, t._path)
1285
1285
  );
1286
- return lt("text", {}, String(i));
1286
+ return lt("text", {}, String(c));
1287
1287
  }
1288
1288
  function ae({
1289
1289
  stateKey: t,
1290
- itemComponentId: i,
1290
+ itemComponentId: c,
1291
1291
  itemPath: m,
1292
1292
  children: g
1293
1293
  }) {
@@ -1299,7 +1299,7 @@ function ae({
1299
1299
  }
1300
1300
  }));
1301
1301
  }, [p.height, t, m]), ct(() => {
1302
- const s = `${t}////${i}`, I = o.getState().stateComponents.get(t) || {
1302
+ const s = `${t}////${c}`, I = o.getState().stateComponents.get(t) || {
1303
1303
  components: /* @__PURE__ */ new Map()
1304
1304
  };
1305
1305
  return I.components.set(s, {
@@ -1309,7 +1309,7 @@ function ae({
1309
1309
  const r = o.getState().stateComponents.get(t);
1310
1310
  r && r.components.delete(s);
1311
1311
  };
1312
- }, [t, i, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: N, children: g });
1312
+ }, [t, c, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: N, children: g });
1313
1313
  }
1314
1314
  export {
1315
1315
  Vt as $cogsSignal,