cogsbox-state 0.5.394 → 0.5.395

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,54 +10,54 @@ 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) {
14
- const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, T = m(t) || {};
13
+ function Mt(t, c) {
14
+ const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, I = m(t) || {};
15
15
  g(t, {
16
- ...T,
17
- ...i
16
+ ...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
- const g = rt(t) || {}, T = m[t] || {}, N = o.getState().setInitialStateOptions, p = { ...T, ...g };
25
+ const g = rt(t) || {}, I = m[t] || {}, N = o.getState().setInitialStateOptions, p = { ...I, ...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 Ie(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
- const [g, T] = Bt(m);
39
- (Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
40
- T[v] = T[v] || {}, T[v].formElements = {
41
- ...i?.formElements,
38
+ const [g, I] = Bt(m);
39
+ (Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((v) => {
40
+ I[v] = I[v] || {}, I[v].formElements = {
41
+ ...c?.formElements,
42
42
  // Global defaults first
43
- ...i?.validation,
44
- ...T[v].formElements || {}
43
+ ...c?.validation,
44
+ ...I[v].formElements || {}
45
45
  // State-specific overrides
46
- }, rt(v) || o.getState().setInitialStateOptions(v, T[v]);
46
+ }, rt(v) || o.getState().setInitialStateOptions(v, I[v]);
47
47
  }), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
48
48
  const N = (v, s) => {
49
- const [I] = K(s?.componentId ?? At());
49
+ const [T] = K(s?.componentId ?? At());
50
50
  xt({
51
51
  stateKey: v,
52
52
  options: s,
53
- initialOptionsPart: T
53
+ initialOptionsPart: I
54
54
  });
55
55
  const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] = ne(
56
56
  S,
57
57
  {
58
58
  stateKey: v,
59
59
  syncUpdate: s?.syncUpdate,
60
- componentId: I,
60
+ componentId: T,
61
61
  localStorage: s?.localStorage,
62
62
  middleware: s?.middleware,
63
63
  enabledSync: s?.enabledSync,
@@ -71,11 +71,11 @@ const ve = (t, i) => {
71
71
  return j;
72
72
  };
73
73
  function p(v, s) {
74
- xt({ stateKey: v, options: s, initialOptionsPart: T }), s.localStorage && te(v, s), dt(v);
74
+ xt({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && te(v, s), dt(v);
75
75
  }
76
76
  return { useCogsState: N, setCogsOptions: p };
77
77
  }, {
78
- setUpdaterState: It,
78
+ setUpdaterState: Tt,
79
79
  setState: nt,
80
80
  getInitialOptions: rt,
81
81
  getKeyState: Lt,
@@ -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, I) => {
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;
@@ -103,65 +103,65 @@ const ve = (t, i) => {
103
103
  const s = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
- lastSyncedWithServer: T ?? v
107
- }, I = Jt.serialize(s);
106
+ lastSyncedWithServer: I ?? v
107
+ }, T = Jt.serialize(s);
108
108
  window.localStorage.setItem(
109
109
  p,
110
- JSON.stringify(I.json)
110
+ JSON.stringify(T.json)
111
111
  );
112
112
  }
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;
123
- if (T && g) {
121
+ }, te = (t, c) => {
122
+ const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(), I = tt(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
123
+ if (I && g) {
124
124
  const N = vt(
125
- `${g}-${t}-${T}`
125
+ `${g}-${t}-${I}`
126
126
  );
127
127
  if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
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, I, N) => {
132
132
  const p = {
133
- initialState: i,
134
- updaterState: Tt(
133
+ initialState: c,
134
+ updaterState: It(
135
135
  t,
136
136
  g,
137
- T,
137
+ I,
138
138
  N
139
139
  ),
140
140
  state: m
141
141
  };
142
- Nt(t, p.initialState), It(t, p.updaterState), nt(t, p.state);
142
+ Nt(t, p.initialState), Tt(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);
156
- if ((T ? Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"] : null)?.includes("none"))
155
+ const g = `${t}////${c}`, I = m.components.get(g);
156
+ if ((I ? Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"] : null)?.includes("none"))
157
157
  return;
158
- T && T.forceUpdate();
158
+ I && I.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,42 +181,42 @@ 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
- formElements: T,
187
+ formElements: I,
188
188
  reactiveDeps: N,
189
189
  reactiveType: p,
190
190
  componentId: v,
191
191
  initialState: s,
192
- syncUpdate: I,
192
+ syncUpdate: T,
193
193
  dependencies: r,
194
194
  serverState: S
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(() => {
202
- if (I && I.stateKey === h && I.path?.[0]) {
202
+ if (T && T.stateKey === h && T.path?.[0]) {
203
203
  nt(h, (n) => ({
204
204
  ...n,
205
- [I.path[0]]: I.newValue
205
+ [T.path[0]]: T.newValue
206
206
  }));
207
- const e = `${I.stateKey}:${I.path.join(".")}`;
207
+ const e = `${T.stateKey}:${T.path.join(".")}`;
208
208
  o.getState().setSyncInfo(e, {
209
- timeStamp: I.timeStamp,
210
- userId: I.userId
209
+ timeStamp: T.timeStamp,
210
+ userId: T.userId
211
211
  });
212
212
  }
213
- }, [I]), ot(() => {
213
+ }, [T]), ot(() => {
214
214
  if (s) {
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;
@@ -240,7 +240,7 @@ function ne(t, {
240
240
  ]), ct(() => {
241
241
  z && Mt(h, {
242
242
  serverSync: m,
243
- formElements: T,
243
+ formElements: I,
244
244
  initialState: s,
245
245
  localStorage: g,
246
246
  middleware: L.current?.middleware
@@ -258,7 +258,7 @@ 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);
@@ -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", f.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(
@@ -416,16 +416,16 @@ function ne(t, {
416
416
  return E;
417
417
  });
418
418
  };
419
- o.getState().updaterState[h] || (It(
419
+ o.getState().updaterState[h] || (Tt(
420
420
  h,
421
- Tt(
421
+ It(
422
422
  h,
423
423
  at,
424
424
  et.current,
425
425
  U
426
426
  )
427
427
  ), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] || Nt(h, t));
428
- const d = wt(() => Tt(
428
+ const d = wt(() => It(
429
429
  h,
430
430
  at,
431
431
  et.current,
@@ -433,40 +433,40 @@ function ne(t, {
433
433
  ), [h, U]);
434
434
  return [Lt(h), d];
435
435
  }
436
- function Tt(t, i, m, g) {
437
- const T = /* @__PURE__ */ new Map();
436
+ function It(t, c, m, g) {
437
+ const I = /* @__PURE__ */ new Map();
438
438
  let N = 0;
439
- const p = (I) => {
440
- const r = I.join(".");
441
- for (const [S] of T)
442
- (S === r || S.startsWith(r + ".")) && T.delete(S);
439
+ const p = (T) => {
440
+ const r = T.join(".");
441
+ for (const [S] of I)
442
+ (S === r || S.startsWith(r + ".")) && I.delete(S);
443
443
  N++;
444
444
  }, v = {
445
- removeValidation: (I) => {
446
- I?.validationKey && X(I.validationKey);
445
+ removeValidation: (T) => {
446
+ T?.validationKey && X(T.validationKey);
447
447
  },
448
- revertToInitialState: (I) => {
448
+ revertToInitialState: (T) => {
449
449
  const r = o.getState().getInitialOptions(t)?.validation;
450
- r?.key && X(r?.key), I?.validationKey && X(I.validationKey);
450
+ r?.key && X(r?.key), T?.validationKey && X(T.validationKey);
451
451
  const S = o.getState().initialStateGlobal[t];
452
- o.getState().clearSelectedIndexesForState(t), T.clear(), N++;
452
+ o.getState().clearSelectedIndexesForState(t), I.clear(), N++;
453
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);
454
+ z && localStorage.removeItem(z), Tt(t, W), nt(t, S);
455
455
  const h = o.getState().stateComponents.get(t);
456
456
  return h && h.components.forEach((l) => {
457
457
  l.forceUpdate();
458
458
  }), S;
459
459
  },
460
- updateInitialState: (I) => {
461
- T.clear(), N++;
462
- const r = Tt(
460
+ updateInitialState: (T) => {
461
+ I.clear(), N++;
462
+ const r = It(
463
463
  t,
464
- i,
464
+ c,
465
465
  m,
466
466
  g
467
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}`;
468
468
  return localStorage.getItem(U) && localStorage.removeItem(U), Ft(() => {
469
- Nt(t, I), o.getState().initializeShadowState(t, I), It(t, r), nt(t, I);
469
+ Nt(t, T), o.getState().initializeShadowState(t, T), Tt(t, r), nt(t, T);
470
470
  const z = o.getState().stateComponents.get(t);
471
471
  z && z.components.forEach((h) => {
472
472
  h.forceUpdate();
@@ -479,13 +479,13 @@ function Tt(t, i, m, g) {
479
479
  _serverState: o.getState().serverState[t],
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
- const I = o.getState().serverState[t];
483
- return !!(I && J(I, Lt(t)));
482
+ const T = o.getState().serverState[t];
483
+ return !!(T && J(T, Lt(t)));
484
484
  }
485
485
  };
486
- function s(I, r = [], S) {
486
+ function s(T, r = [], S) {
487
487
  const W = r.map(String).join(".");
488
- T.get(W);
488
+ I.get(W);
489
489
  const j = function() {
490
490
  return o().getNestedState(t, r);
491
491
  };
@@ -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
+ S?.validIndices && !Array.isArray(T) && (S = { ...S, 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;
532
+ let i = !0;
533
533
  for (const f of n.paths)
534
534
  if (a.startsWith(f) && (a === f || a[f.length] === ".")) {
535
- c = !1;
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,9 +551,9 @@ 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
  });
@@ -562,9 +562,9 @@ function Tt(t, i, m, g) {
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") {
@@ -591,8 +591,8 @@ function Tt(t, i, m, g) {
591
591
  throw new Error("Validation key not found");
592
592
  return o.getState().getValidationErrors(d.key + "." + r.join("."));
593
593
  };
594
- if (Array.isArray(I)) {
595
- const d = () => S?.validIndices ? I.map((n, a) => ({
594
+ if (Array.isArray(T)) {
595
+ const d = () => S?.validIndices ? T.map((n, a) => ({
596
596
  item: n,
597
597
  originalIndex: S.validIndices[a]
598
598
  })) : o.getState().getNestedState(t, r).map((n, a) => ({
@@ -604,7 +604,7 @@ function Tt(t, i, m, g) {
604
604
  const e = o.getState().getSelectedIndex(t, r.join("."));
605
605
  if (e !== void 0)
606
606
  return s(
607
- I[e],
607
+ T[e],
608
608
  [...r, e.toString()],
609
609
  S
610
610
  );
@@ -620,7 +620,7 @@ function Tt(t, i, m, g) {
620
620
  const {
621
621
  itemHeight: n = 50,
622
622
  overscan: a = 6,
623
- stickToBottom: c = !1,
623
+ stickToBottom: i = !1,
624
624
  dependencies: f = []
625
625
  } = e, u = q(!1), E = q(null), [y, w] = K({
626
626
  startIndex: 0,
@@ -677,7 +677,7 @@ function Tt(t, i, m, g) {
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
  }
@@ -686,7 +686,7 @@ function Tt(t, i, m, g) {
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 = {
801
+ ), i = a.map(({ item: u }) => u), f = {
802
802
  ...S,
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, f);
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 = {
813
+ ), i = a.map(({ item: u }) => u), f = {
814
814
  ...S,
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, f);
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) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
825
+ const u = n[i], E = [...r, i.toString()], y = s(u, E, S);
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()
@@ -840,7 +840,7 @@ function Tt(t, i, m, g) {
840
840
  }, [t, A]);
841
841
  },
842
842
  index: f,
843
- originalIndex: c
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) => {
851
+ return (e) => T.map((a, i) => {
852
852
  let f;
853
- S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
853
+ S?.validIndices && S.validIndices[i] !== void 0 ? f = S.validIndices[i] : f = i;
854
854
  const u = [...r, f.toString()], E = s(a, u, S);
855
855
  return e(
856
856
  a,
857
857
  E,
858
- c,
859
- I,
860
- s(I, r, S)
858
+ i,
859
+ T,
860
+ s(T, r, S)
861
861
  );
862
862
  });
863
863
  if (l === "$stateMap")
@@ -873,17 +873,17 @@ 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) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
877
+ const u = n[i], E = [...r, i.toString()], y = s(u, E, S), 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
+ { localIndex: f, originalIndex: i },
887
887
  n,
888
888
  s(n, r, S)
889
889
  )
@@ -894,10 +894,10 @@ function Tt(t, i, m, g) {
894
894
  };
895
895
  if (l === "stateFlattenOn")
896
896
  return (e) => {
897
- const n = I;
898
- T.clear(), N++;
897
+ const n = T;
898
+ I.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,
@@ -907,26 +907,26 @@ function Tt(t, i, m, g) {
907
907
  };
908
908
  if (l === "index")
909
909
  return (e) => {
910
- const n = I[e];
910
+ const n = T[e];
911
911
  return s(n, [...r, e.toString()]);
912
912
  };
913
913
  if (l === "last")
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), f = 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
932
  (A) => J(y[A], f[A])
@@ -936,31 +936,31 @@ function Tt(t, i, m, g) {
936
936
  const w = J(y, f);
937
937
  return w && (u = y), w;
938
938
  }))
939
- p(r), Et(i, f, r, t);
939
+ p(r), Et(c, f, 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
  );
954
954
  };
955
955
  if (l === "cutByValue")
956
956
  return (e) => {
957
- for (let n = 0; n < I.length; n++)
958
- I[n] === e && ht(i, r, t, n);
957
+ for (let n = 0; n < T.length; n++)
958
+ T[n] === e && ht(c, r, t, n);
959
959
  };
960
960
  if (l === "toggleByValue")
961
961
  return (e) => {
962
- const n = I.findIndex((a) => a === e);
963
- n > -1 ? ht(i, r, t, n) : Et(i, e, r, t);
962
+ const n = T.findIndex((a) => a === e);
963
+ n > -1 ? ht(c, r, t, n) : Et(c, e, r, t);
964
964
  };
965
965
  if (l === "stateFind")
966
966
  return (e) => {
@@ -968,17 +968,17 @@ function Tt(t, i, m, g) {
968
968
  ({ item: f }, u) => e(f, 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, S);
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 f = [...r, i.originalIndex.toString()];
981
+ return s(i.item, f, S);
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,7 +994,7 @@ 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 (S?.validIndices && Array.isArray(T)) {
998
998
  const d = o.getState().getNestedState(t, r);
999
999
  return S.validIndices.map((e) => d[e]);
1000
1000
  }
@@ -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) {
1064
+ const i = o.getState().stateComponents.get(t);
1065
+ if (i) {
1066
1066
  const f = _t(e, a), u = new Set(f);
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")) {
@@ -1132,8 +1132,8 @@ function Tt(t, i, m, g) {
1132
1132
  a && a.length > 0 && a.forEach(([f]) => {
1133
1133
  f && f.startsWith(d.key) && X(f);
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);
@@ -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,
@@ -1207,7 +1207,7 @@ function Tt(t, i, m, g) {
1207
1207
  return s(at, L, S);
1208
1208
  }
1209
1209
  }, z = new Proxy(j, U);
1210
- return T.set(W, {
1210
+ return I.set(W, {
1211
1211
  proxy: z,
1212
1212
  stateVersion: N
1213
1213
  }), z;
@@ -1221,33 +1221,33 @@ 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(
1231
- (T, N, p, v, s) => t._mapFn(T, N, p, v, s)
1231
+ (I, N, p, v, s) => t._mapFn(I, N, p, v, s)
1232
1232
  ) : null;
1233
1233
  }
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
- const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
1242
- let v = T.getAttribute("data-parent-id");
1243
- v || (v = `parent-${crypto.randomUUID()}`, T.setAttribute("data-parent-id", v));
1244
- const I = {
1241
+ const I = g.parentElement, p = Array.from(I.childNodes).indexOf(g);
1242
+ let v = I.getAttribute("data-parent-id");
1243
+ v || (v = `parent-${crypto.randomUUID()}`, I.setAttribute("data-parent-id", v));
1244
+ const T = {
1245
1245
  instanceId: `instance-${crypto.randomUUID()}`,
1246
1246
  parentId: v,
1247
1247
  position: p,
1248
1248
  effect: t._effect
1249
1249
  };
1250
- o.getState().addSignalElement(m, I);
1250
+ o.getState().addSignalElement(m, T);
1251
1251
  const r = o.getState().getNestedState(t._stateKey, t._path);
1252
1252
  let S;
1253
1253
  if (t._effect)
@@ -1265,13 +1265,13 @@ function oe({
1265
1265
  const W = document.createTextNode(String(S));
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,15 +1283,15 @@ 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
  }) {
1294
- const [, T] = K({}), [N, p] = Zt(), v = q(null);
1294
+ const [, I] = K({}), [N, p] = Zt(), v = q(null);
1295
1295
  return ot(() => {
1296
1296
  p.height > 0 && p.height !== v.current && (v.current = p.height, o.getState().setShadowMetadata(t, m, {
1297
1297
  virtualizer: {
@@ -1299,22 +1299,22 @@ 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}`, T = o.getState().stateComponents.get(t) || {
1303
1303
  components: /* @__PURE__ */ new Map()
1304
1304
  };
1305
- return I.components.set(s, {
1306
- forceUpdate: () => T({}),
1305
+ return T.components.set(s, {
1306
+ forceUpdate: () => I({}),
1307
1307
  paths: /* @__PURE__ */ new Set([m.join(".")])
1308
- }), o.getState().stateComponents.set(t, I), () => {
1308
+ }), o.getState().stateComponents.set(t, T), () => {
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,
1316
1316
  pe as $cogsSignalStore,
1317
- Te as addStateOptions,
1317
+ Ie as addStateOptions,
1318
1318
  ve as createCogsState,
1319
1319
  ye as notifyComponent,
1320
1320
  ne as useCogsStateFn