cogsbox-state 0.5.399 → 0.5.401

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.
@@ -1,58 +1,58 @@
1
1
  "use client";
2
2
  import { jsx as Ot } from "react/jsx-runtime";
3
- import { useState as K, useRef as q, useEffect as at, useLayoutEffect as lt, useMemo as wt, createElement as rt, useSyncExternalStore as Ft, startTransition as Bt, useCallback as kt } from "react";
4
- import { transformStateFunc as Wt, isDeepEqual as J, isFunction as tt, getNestedValue as Z, getDifferences as _t, debounce as zt } from "./utility.js";
5
- import { FormControlComponent as bt, pushFunc as Et, updateFn as ct, cutFunc as ht, ValidationWrapper as qt } from "./Functions.jsx";
3
+ import { useState as K, useRef as q, useEffect as ot, useLayoutEffect as ct, useMemo as wt, createElement as lt, useSyncExternalStore as Ut, startTransition as Ft, useCallback as kt } from "react";
4
+ import { transformStateFunc as Bt, isDeepEqual as J, isFunction as tt, getNestedValue as X, getDifferences as _t, debounce as Wt } from "./utility.js";
5
+ import { pushFunc as Et, updateFn as it, cutFunc as ht, ValidationWrapper as zt, FormControlComponent as qt } from "./Functions.jsx";
6
6
  import Jt from "superjson";
7
7
  import { v4 as At } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as o, formRefStore as Mt } from "./store.js";
10
- import { useCogsConfig as Lt } from "./CogsStateClient.jsx";
9
+ import { getGlobalStore as o, formRefStore as bt } from "./store.js";
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 xt(t, i) {
13
+ function Mt(t, c) {
14
14
  const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, I = m(t) || {};
15
15
  g(t, {
16
16
  ...I,
17
- ...i
17
+ ...c
18
18
  });
19
19
  }
20
- function Pt({
20
+ function xt({
21
21
  stateKey: t,
22
- options: i,
22
+ options: c,
23
23
  initialOptionsPart: m
24
24
  }) {
25
- const g = ot(t) || {}, I = m[t] || {}, N = o.getState().setInitialStateOptions, E = { ...I, ...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
- E.hasOwnProperty(s) ? (s == "localStorage" && i[s] && E[s].key !== i[s]?.key && (v = !0, E[s] = i[s]), s == "initialState" && i[s] && E[s] !== i[s] && // Different references
30
- !J(E[s], i[s]) && (v = !0, E[s] = i[s])) : (v = !0, E[s] = i[s]);
31
- v && N(t, E);
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
+ v && N(t, p);
32
32
  }
33
- function Ie(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, I] = Wt(m);
39
- (Object.keys(I).length > 0 || i && Object.keys(i).length > 0) && Object.keys(I).forEach((v) => {
38
+ const [g, I] = Bt(m);
39
+ (Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((v) => {
40
40
  I[v] = I[v] || {}, I[v].formElements = {
41
- ...i?.formElements,
41
+ ...c?.formElements,
42
42
  // Global defaults first
43
- ...i?.validation,
43
+ ...c?.validation,
44
44
  ...I[v].formElements || {}
45
45
  // State-specific overrides
46
- }, ot(v) || o.getState().setInitialStateOptions(v, I[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
49
  const [T] = K(s?.componentId ?? At());
50
- Pt({
50
+ xt({
51
51
  stateKey: v,
52
52
  options: s,
53
53
  initialOptionsPart: I
54
54
  });
55
- const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] = ne(
55
+ const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, H] = ne(
56
56
  S,
57
57
  {
58
58
  stateKey: v,
@@ -68,36 +68,36 @@ const ve = (t, i) => {
68
68
  serverState: s?.serverState
69
69
  }
70
70
  );
71
- return j;
71
+ return H;
72
72
  };
73
- function E(v, s) {
74
- Pt({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && te(v, s), dt(v);
73
+ function p(v, s) {
74
+ xt({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && te(v, s), dt(v);
75
75
  }
76
- return { useCogsState: N, setCogsOptions: E };
76
+ return { useCogsState: N, setCogsOptions: p };
77
77
  }, {
78
78
  setUpdaterState: Tt,
79
79
  setState: nt,
80
- getInitialOptions: ot,
81
- getKeyState: Rt,
80
+ getInitialOptions: rt,
81
+ getKeyState: Lt,
82
82
  getValidationErrors: Xt,
83
83
  setStateLog: Qt,
84
84
  updateInitialStateGlobal: Nt,
85
- addValidationError: Dt,
86
- removeValidationError: X,
85
+ addValidationError: Rt,
86
+ removeValidationError: Q,
87
87
  setServerSyncActions: Kt
88
- } = o.getState(), Vt = (t, i, m, g, I) => {
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 E = `${g}-${i}-${N}`;
97
+ const p = `${g}-${c}-${N}`;
98
98
  let v;
99
99
  try {
100
- v = vt(E)?.lastSyncedWithServer;
100
+ v = vt(p)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const s = {
@@ -106,20 +106,20 @@ const ve = (t, i) => {
106
106
  lastSyncedWithServer: I ?? v
107
107
  }, T = Jt.serialize(s);
108
108
  window.localStorage.setItem(
109
- E,
109
+ p,
110
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 } = Lt(), I = 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(), I = tt(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
123
123
  if (I && g) {
124
124
  const N = vt(
125
125
  `${g}-${t}-${I}`
@@ -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
- }, jt = (t, i, m, g, I, N) => {
132
- const E = {
133
- initialState: i,
131
+ }, Dt = (t, c, m, g, I, N) => {
132
+ const p = {
133
+ initialState: c,
134
134
  updaterState: It(
135
135
  t,
136
136
  g,
@@ -139,40 +139,40 @@ const ve = (t, i) => {
139
139
  ),
140
140
  state: m
141
141
  };
142
- Nt(t, E.initialState), Tt(t, E.updaterState), nt(t, E.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}`, I = m.components.get(g);
155
+ const g = `${t}////${c}`, I = m.components.get(g);
156
156
  if ((I ? Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"] : null)?.includes("none"))
157
157
  return;
158
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),
165
- newValue: Z(m, g)
164
+ oldValue: X(c, g),
165
+ newValue: X(m, g)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: Z(m, g)
171
+ newValue: X(m, g)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: Z(i, g),
175
+ oldValue: X(c, g),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -181,24 +181,24 @@ 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: I,
188
188
  reactiveDeps: N,
189
- reactiveType: E,
189
+ reactiveType: p,
190
190
  componentId: v,
191
191
  initialState: s,
192
192
  syncUpdate: T,
193
193
  dependencies: r,
194
194
  serverState: S
195
195
  } = {}) {
196
- const [W, j] = K({}), { sessionId: U } = Lt();
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(
196
+ const [W, H] = K({}), { sessionId: U } = Gt();
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
- L.current = ot(h) ?? null, at(() => {
201
+ L.current = rt(h) ?? null, ot(() => {
202
202
  if (T && T.stateKey === h && T.path?.[0]) {
203
203
  nt(h, (n) => ({
204
204
  ...n,
@@ -210,35 +210,35 @@ function ne(t, {
210
210
  userId: T.userId
211
211
  });
212
212
  }
213
- }, [T]), at(() => {
213
+ }, [T]), ot(() => {
214
214
  if (s) {
215
- xt(h, {
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
- const y = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
223
- y && U && (u = vt(`${U}-${h}-${y}`));
224
- let p = s, w = !1;
222
+ const E = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
223
+ E && U && (u = vt(`${U}-${h}-${E}`));
224
+ let y = s, w = !1;
225
225
  const C = a ? Date.now() : 0, A = u?.lastUpdated || 0, b = u?.lastSyncedWithServer || 0;
226
- a && C > A ? (p = e.serverState.data, w = !0) : u && A > b && (p = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), o.getState().initializeShadowState(h, s), jt(
226
+ a && C > A ? (y = e.serverState.data, w = !0) : u && A > b && (y = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(y)), o.getState().initializeShadowState(h, s), Dt(
227
227
  h,
228
228
  s,
229
- p,
230
- st,
229
+ y,
230
+ at,
231
231
  et.current,
232
232
  U
233
- ), w && y && U && Vt(p, h, e, U, Date.now()), dt(h), (Array.isArray(E) ? E : [E || "component"]).includes("none") || j({});
233
+ ), w && E && U && Pt(y, h, e, U, Date.now()), dt(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || H({});
234
234
  }
235
235
  }, [
236
236
  s,
237
237
  S?.status,
238
238
  S?.data,
239
239
  ...r || []
240
- ]), lt(() => {
241
- z && xt(h, {
240
+ ]), ct(() => {
241
+ z && Mt(h, {
242
242
  serverSync: m,
243
243
  formElements: I,
244
244
  initialState: s,
@@ -249,27 +249,27 @@ function ne(t, {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return n.components.set(e, {
252
- forceUpdate: () => j({}),
252
+ forceUpdate: () => H({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
255
  depsFunction: N || void 0,
256
- reactiveType: E ?? ["component", "deps"]
257
- }), o.getState().stateComponents.set(h, n), j({}), () => {
256
+ reactiveType: p ?? ["component", "deps"]
257
+ }), o.getState().stateComponents.set(h, n), H({}), () => {
258
258
  n && (n.components.delete(e), n.components.size === 0 && o.getState().stateComponents.delete(h));
259
259
  };
260
260
  }, []);
261
- const st = (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
266
  const f = o.getState();
267
267
  nt(h, (u) => {
268
- const y = tt(e) ? e(u) : e, p = `${h}-${n.join(".")}`;
269
- if (p) {
270
- let M = !1, $ = f.signalDomElements.get(p);
268
+ const E = tt(e) ? e(u) : e, y = `${h}-${n.join(".")}`;
269
+ if (y) {
270
+ let M = !1, $ = f.signalDomElements.get(y);
271
271
  if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
- const R = n.slice(0, -1), V = Z(y, R);
272
+ const R = n.slice(0, -1), V = X(E, R);
273
273
  if (Array.isArray(V)) {
274
274
  M = !0;
275
275
  const O = `${h}-${R.join(".")}`;
@@ -277,7 +277,7 @@ function ne(t, {
277
277
  }
278
278
  }
279
279
  if ($) {
280
- const R = M ? Z(y, n.slice(0, -1)) : Z(y, n);
280
+ const R = M ? X(E, n.slice(0, -1)) : X(E, n);
281
281
  $.forEach(({ parentId: V, position: O, effect: _ }) => {
282
282
  const D = document.querySelector(
283
283
  `[data-parent-id="${V}"]`
@@ -292,11 +292,11 @@ 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 && Q(
296
+ (i || L.current?.validation?.key) + "." + n.join(".")
297
297
  );
298
298
  const w = n.slice(0, n.length - 1);
299
- a.updateType === "cut" && L.current?.validation?.key && X(
299
+ a.updateType === "cut" && L.current?.validation?.key && Q(
300
300
  L.current?.validation?.key + "." + w.join(".")
301
301
  ), a.updateType === "insert" && L.current?.validation?.key && Xt(
302
302
  L.current?.validation?.key + "." + w.join(".")
@@ -304,12 +304,12 @@ function ne(t, {
304
304
  let V = $?.split(".").length;
305
305
  if ($ == w.join(".") && V == w.length - 1) {
306
306
  let O = $ + "." + w;
307
- X($), Dt(O, R);
307
+ Q($), Rt(O, R);
308
308
  }
309
309
  });
310
310
  const C = f.stateComponents.get(h);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
312
- const M = _t(u, y), $ = new Set(M), R = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
312
+ const M = _t(u, E), $ = new Set(M), R = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
313
313
  for (const [
314
314
  V,
315
315
  O
@@ -329,14 +329,14 @@ function ne(t, {
329
329
  _ = !0;
330
330
  break;
331
331
  }
332
- const it = B.lastIndexOf(".");
333
- if (it !== -1) {
332
+ const st = B.lastIndexOf(".");
333
+ if (st !== -1) {
334
334
  const gt = B.substring(
335
335
  0,
336
- it
336
+ st
337
337
  );
338
338
  if (!isNaN(
339
- Number(B.substring(it + 1))
339
+ Number(B.substring(st + 1))
340
340
  ) && O.paths.has(gt)) {
341
341
  _ = !0;
342
342
  break;
@@ -350,7 +350,7 @@ function ne(t, {
350
350
  if (_) break;
351
351
  }
352
352
  if (!_ && D.includes("deps") && O.depsFunction) {
353
- const G = O.depsFunction(y);
353
+ const G = O.depsFunction(E);
354
354
  let B = !1;
355
355
  typeof G == "boolean" ? G && (B = !0) : J(O.deps, G) || (O.deps = G, B = !0), B && (_ = !0);
356
356
  }
@@ -360,13 +360,13 @@ function ne(t, {
360
360
  }
361
361
  const A = Date.now();
362
362
  n = n.map((M, $) => {
363
- const R = n.slice(0, -1), V = Z(y, R);
363
+ const R = n.slice(0, -1), V = X(E, R);
364
364
  return $ === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (V.length - 1).toString() : M;
365
365
  });
366
366
  const { oldValue: b, newValue: F } = ee(
367
367
  a.updateType,
368
368
  u,
369
- y,
369
+ E,
370
370
  n
371
371
  ), Y = {
372
372
  timeStamp: A,
@@ -379,7 +379,7 @@ function ne(t, {
379
379
  };
380
380
  switch (a.updateType) {
381
381
  case "update":
382
- f.updateShadowAtPath(h, n, y);
382
+ f.updateShadowAtPath(h, n, E);
383
383
  break;
384
384
  case "insert":
385
385
  const M = n.slice(0, -1);
@@ -396,8 +396,8 @@ function ne(t, {
396
396
  return D ? (D.timeStamp = Math.max(D.timeStamp, O.timeStamp), D.newValue = O.newValue, D.oldValue = D.oldValue ?? O.oldValue, D.updateType = O.updateType) : V.set(_, { ...O }), V;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(R.values());
399
- }), Vt(
400
- y,
399
+ }), Pt(
400
+ E,
401
401
  h,
402
402
  L.current,
403
403
  U
@@ -407,50 +407,50 @@ function ne(t, {
407
407
  }), L.current?.serverSync) {
408
408
  const M = f.serverState[h], $ = L.current?.serverSync;
409
409
  Kt(h, {
410
- syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: y }),
410
+ syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
411
411
  rollBackState: M,
412
412
  actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
- return y;
416
+ return E;
417
417
  });
418
418
  };
419
419
  o.getState().updaterState[h] || (Tt(
420
420
  h,
421
421
  It(
422
422
  h,
423
- st,
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
428
  const d = wt(() => It(
429
429
  h,
430
- st,
430
+ at,
431
431
  et.current,
432
432
  U
433
433
  ), [h, U]);
434
- return [Rt(h), d];
434
+ return [Lt(h), d];
435
435
  }
436
- function It(t, i, m, g) {
436
+ function It(t, c, m, g) {
437
437
  const I = /* @__PURE__ */ new Map();
438
438
  let N = 0;
439
- const E = (T) => {
439
+ const p = (T) => {
440
440
  const r = T.join(".");
441
441
  for (const [S] of I)
442
442
  (S === r || S.startsWith(r + ".")) && I.delete(S);
443
443
  N++;
444
444
  }, v = {
445
445
  removeValidation: (T) => {
446
- T?.validationKey && X(T.validationKey);
446
+ T?.validationKey && Q(T.validationKey);
447
447
  },
448
448
  revertToInitialState: (T) => {
449
449
  const r = o.getState().getInitialOptions(t)?.validation;
450
- r?.key && X(r?.key), T?.validationKey && X(T.validationKey);
450
+ r?.key && Q(r?.key), T?.validationKey && Q(T.validationKey);
451
451
  const S = o.getState().initialStateGlobal[t];
452
452
  o.getState().clearSelectedIndexesForState(t), I.clear(), N++;
453
- const W = s(S, []), j = ot(t), U = tt(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, z = `${g}-${t}-${U}`;
453
+ const W = s(S, []), H = rt(t), U = tt(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, z = `${g}-${t}-${U}`;
454
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) => {
@@ -461,11 +461,11 @@ function It(t, i, m, g) {
461
461
  I.clear(), N++;
462
462
  const r = It(
463
463
  t,
464
- i,
464
+ c,
465
465
  m,
466
466
  g
467
- ), S = o.getState().initialStateGlobal[t], W = ot(t), j = tt(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${g}-${t}-${j}`;
468
- return localStorage.getItem(U) && localStorage.removeItem(U), Bt(() => {
467
+ ), S = o.getState().initialStateGlobal[t], W = rt(t), H = tt(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${g}-${t}-${H}`;
468
+ return localStorage.getItem(U) && localStorage.removeItem(U), Ft(() => {
469
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) => {
@@ -480,17 +480,17 @@ function It(t, i, m, g) {
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
482
  const T = o.getState().serverState[t];
483
- return !!(T && J(T, Rt(t)));
483
+ return !!(T && J(T, Lt(t)));
484
484
  }
485
485
  };
486
486
  function s(T, r = [], S) {
487
487
  const W = r.map(String).join(".");
488
488
  I.get(W);
489
- const j = function() {
489
+ const H = function() {
490
490
  return o().getNestedState(t, r);
491
491
  };
492
492
  Object.keys(v).forEach((h) => {
493
- j[h] = v[h];
493
+ H[h] = v[h];
494
494
  });
495
495
  const U = {
496
496
  apply(h, l, ut) {
@@ -529,13 +529,13 @@ function It(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,24 +551,24 @@ function It(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) => {
557
- const y = [a, ...u.path].join(".");
558
- o.getState().addValidationError(y, u.message);
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
+ const E = [a, ...u.path].join(".");
558
+ o.getState().addValidationError(E, u.message);
559
559
  });
560
560
  const f = o.getState().stateComponents.get(t);
561
561
  f && f.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") {
571
- const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = Z(e, r);
571
+ const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = X(e, r);
572
572
  return J(d, n) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
@@ -576,12 +576,12 @@ function It(t, i, m, g) {
576
576
  const d = o().getNestedState(
577
577
  t,
578
578
  r
579
- ), e = o.getState().initialStateGlobal[t], n = Z(e, r);
579
+ ), e = o.getState().initialStateGlobal[t], n = X(e, r);
580
580
  return J(d, n) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
584
- const d = o.getState().initialStateGlobal[t], e = ot(t), n = tt(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${g}-${t}-${n}`;
584
+ const d = o.getState().initialStateGlobal[t], e = rt(t), n = tt(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${g}-${t}-${n}`;
585
585
  a && localStorage.removeItem(a);
586
586
  };
587
587
  if (l === "showValidationErrors")
@@ -620,13 +620,13 @@ function It(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
- } = e, u = q(!1), y = q(null), [p, w] = K({
625
+ } = e, u = q(!1), E = q(null), [y, w] = K({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
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);
629
- at(() => o.getState().subscribeToShadowState(t, () => {
629
+ ot(() => o.getState().subscribeToShadowState(t, () => {
630
630
  R((x) => x + 1);
631
631
  }), [t]);
632
632
  const O = o().getNestedState(
@@ -635,13 +635,13 @@ function It(t, i, m, g) {
635
635
  ), _ = O.length, { totalHeight: D, positions: G } = wt(() => {
636
636
  const k = o.getState().getShadowMetadata(t, r) || [];
637
637
  let x = 0;
638
- const H = [];
638
+ const j = [];
639
639
  for (let P = 0; P < _; P++) {
640
- H[P] = x;
641
- const Q = k[P]?.virtualizer?.itemHeight;
642
- x += Q || n;
640
+ j[P] = x;
641
+ const Z = k[P]?.virtualizer?.itemHeight;
642
+ x += Z || n;
643
643
  }
644
- return { totalHeight: x, positions: H };
644
+ return { totalHeight: x, positions: j };
645
645
  }, [
646
646
  _,
647
647
  t,
@@ -649,22 +649,22 @@ function It(t, i, m, g) {
649
649
  n,
650
650
  $
651
651
  ]), B = wt(() => {
652
- const k = Math.max(0, p.startIndex), x = Math.min(_, p.endIndex), H = Array.from(
652
+ const k = Math.max(0, y.startIndex), x = Math.min(_, y.endIndex), j = Array.from(
653
653
  { length: x - k },
654
- (Q, ft) => k + ft
655
- ), P = H.map((Q) => O[Q]);
654
+ (Z, ft) => k + ft
655
+ ), P = j.map((Z) => O[Z]);
656
656
  return s(P, r, {
657
657
  ...S,
658
- validIndices: H
658
+ validIndices: j
659
659
  });
660
- }, [p.startIndex, p.endIndex, O, _]);
661
- lt(() => {
662
- const k = y.current;
660
+ }, [y.startIndex, y.endIndex, O, _]);
661
+ ct(() => {
662
+ const k = E.current;
663
663
  if (!k) return;
664
664
  const x = _ > F.current;
665
665
  if (x && V.current) {
666
- const { top: H, height: P } = V.current;
667
- b.current = !0, k.scrollTop = H + (k.scrollHeight - P), console.log(
666
+ const { top: j, height: P } = V.current;
667
+ b.current = !0, k.scrollTop = j + (k.scrollHeight - P), console.log(
668
668
  `ANCHOR RESTORED to scrollTop: ${k.scrollTop}`
669
669
  ), setTimeout(() => {
670
670
  b.current = !1;
@@ -677,16 +677,16 @@ function It(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
  }
684
684
  F.current = _, Y.current = f;
685
- }, [_, ...f]), lt(() => {
686
- const k = y.current;
685
+ }, [_, ...f]), ct(() => {
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");
@@ -697,8 +697,13 @@ function It(t, i, m, g) {
697
697
  startIndex: Math.max(0, _ - 10 - a),
698
698
  endIndex: _
699
699
  }), x = setInterval(() => {
700
- const H = _ - 1;
701
- ((o.getState().getShadowMetadata(t, r) || [])[H]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(x), u.current || (console.log(
700
+ const j = _ - 1, Z = (o.getState().getShadowMetadata(t, r) || [])[j]?.virtualizer?.itemHeight || 0;
701
+ console.log(
702
+ "ACTION (GETTING_HEIGHTS): lastItemHeight =",
703
+ Z,
704
+ " index =",
705
+ j
706
+ ), Z > 0 && (clearInterval(x), u.current || (console.log(
702
707
  "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
703
708
  ), A("SCROLLING_TO_BOTTOM")));
704
709
  }, 100);
@@ -706,10 +711,10 @@ function It(t, i, m, g) {
706
711
  console.log(
707
712
  "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
708
713
  ), b.current = !0;
709
- const H = F.current === 0 ? "auto" : "smooth";
714
+ const j = F.current === 0 ? "auto" : "smooth";
710
715
  k.scrollTo({
711
716
  top: k.scrollHeight,
712
- behavior: H
717
+ behavior: j
713
718
  });
714
719
  const P = setTimeout(
715
720
  () => {
@@ -717,23 +722,23 @@ function It(t, i, m, g) {
717
722
  "ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
718
723
  ), b.current = !1, u.current = !1, A("LOCKED_AT_BOTTOM");
719
724
  },
720
- H === "smooth" ? 500 : 50
725
+ j === "smooth" ? 500 : 50
721
726
  );
722
727
  return () => clearTimeout(P);
723
728
  }
724
729
  return () => {
725
730
  x && clearInterval(x);
726
731
  };
727
- }, [C, _, G]), at(() => {
728
- const k = y.current;
732
+ }, [C, _, G]), ot(() => {
733
+ const k = E.current;
729
734
  if (!k) return;
730
- const x = n, H = () => {
735
+ const x = n, j = () => {
731
736
  if (b.current)
732
737
  return;
733
- const { scrollTop: P, scrollHeight: Q, clientHeight: ft } = k;
734
- if (Q - P - ft < 10 ? (C !== "LOCKED_AT_BOTTOM" && A("LOCKED_AT_BOTTOM"), V.current = null) : (C !== "IDLE_NOT_AT_BOTTOM" && A("IDLE_NOT_AT_BOTTOM"), V.current = {
738
+ const { scrollTop: P, scrollHeight: Z, clientHeight: ft } = k;
739
+ if (Z - P - ft < 10 ? (C !== "LOCKED_AT_BOTTOM" && A("LOCKED_AT_BOTTOM"), V.current = null) : (C !== "IDLE_NOT_AT_BOTTOM" && A("IDLE_NOT_AT_BOTTOM"), V.current = {
735
740
  top: P,
736
- height: Q
741
+ height: Z
737
742
  }), Math.abs(P - M.current) < x)
738
743
  return;
739
744
  console.log(
@@ -754,25 +759,25 @@ function It(t, i, m, g) {
754
759
  endIndex: Math.min(_, St + a)
755
760
  }), M.current = P;
756
761
  };
757
- return k.addEventListener("scroll", H, {
762
+ return k.addEventListener("scroll", j, {
758
763
  passive: !0
759
- }), () => k.removeEventListener("scroll", H);
764
+ }), () => k.removeEventListener("scroll", j);
760
765
  }, [_, G, n, a, C]);
761
- const it = kt(() => {
766
+ const st = kt(() => {
762
767
  console.log(
763
768
  "USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
764
769
  ), A("SCROLLING_TO_BOTTOM");
765
770
  }, []), gt = kt(
766
771
  (k, x = "smooth") => {
767
- y.current && G[k] !== void 0 && (A("IDLE_NOT_AT_BOTTOM"), y.current.scrollTo({
772
+ E.current && G[k] !== void 0 && (A("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
768
773
  top: G[k],
769
774
  behavior: x
770
775
  }));
771
776
  },
772
777
  [G]
773
- ), Ut = {
778
+ ), jt = {
774
779
  outer: {
775
- ref: y,
780
+ ref: E,
776
781
  style: { overflowY: "auto", height: "100%" }
777
782
  },
778
783
  inner: {
@@ -783,56 +788,56 @@ function It(t, i, m, g) {
783
788
  },
784
789
  list: {
785
790
  style: {
786
- transform: `translateY(${G[p.startIndex] || 0}px)`
791
+ transform: `translateY(${G[y.startIndex] || 0}px)`
787
792
  }
788
793
  }
789
794
  };
790
795
  return {
791
796
  virtualState: B,
792
- virtualizerProps: Ut,
793
- scrollToBottom: it,
797
+ virtualizerProps: jt,
798
+ scrollToBottom: st,
794
799
  scrollToIndex: gt
795
800
  };
796
801
  };
797
802
  if (l === "stateSort")
798
803
  return (e) => {
799
804
  const a = [...d()].sort(
800
- (u, y) => e(u.item, y.item)
801
- ), c = a.map(({ item: u }) => u), f = {
805
+ (u, E) => e(u.item, E.item)
806
+ ), i = a.map(({ item: u }) => u), f = {
802
807
  ...S,
803
808
  validIndices: a.map(
804
809
  ({ originalIndex: u }) => u
805
810
  )
806
811
  };
807
- return s(c, r, f);
812
+ return s(i, r, f);
808
813
  };
809
814
  if (l === "stateFilter")
810
815
  return (e) => {
811
816
  const a = d().filter(
812
- ({ item: u }, y) => e(u, y)
813
- ), c = a.map(({ item: u }) => u), f = {
817
+ ({ item: u }, E) => e(u, E)
818
+ ), i = a.map(({ item: u }) => u), f = {
814
819
  ...S,
815
820
  validIndices: a.map(
816
821
  ({ originalIndex: u }) => u
817
822
  )
818
823
  };
819
- return s(c, r, f);
824
+ return s(i, r, f);
820
825
  };
821
826
  if (l === "stateMap")
822
827
  return (e) => {
823
828
  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], y = [...r, c.toString()], p = s(u, y, S);
826
- return e(u, p, {
829
+ return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
830
+ const u = n[i], E = [...r, i.toString()], y = s(u, E, S);
831
+ return e(u, y, {
827
832
  register: () => {
828
- const [, C] = K({}), A = `${m}-${r.join(".")}-${c}`;
829
- lt(() => {
833
+ const [, C] = K({}), A = `${m}-${r.join(".")}-${i}`;
834
+ ct(() => {
830
835
  const b = `${t}////${A}`, F = o.getState().stateComponents.get(t) || {
831
836
  components: /* @__PURE__ */ new Map()
832
837
  };
833
838
  return F.components.set(b, {
834
839
  forceUpdate: () => C({}),
835
- paths: /* @__PURE__ */ new Set([y.join(".")])
840
+ paths: /* @__PURE__ */ new Set([E.join(".")])
836
841
  }), o.getState().stateComponents.set(t, F), () => {
837
842
  const Y = o.getState().stateComponents.get(t);
838
843
  Y && Y.components.delete(b);
@@ -840,7 +845,7 @@ function It(t, i, m, g) {
840
845
  }, [t, A]);
841
846
  },
842
847
  index: f,
843
- originalIndex: c
848
+ originalIndex: i
844
849
  });
845
850
  }) : (console.warn(
846
851
  `stateMap called on a non-array value at path: ${r.join(".")}. The current value is:`,
@@ -848,20 +853,20 @@ function It(t, i, m, g) {
848
853
  ), null);
849
854
  };
850
855
  if (l === "stateMapNoRender")
851
- return (e) => T.map((a, c) => {
856
+ return (e) => T.map((a, i) => {
852
857
  let f;
853
- S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
854
- const u = [...r, f.toString()], y = s(a, u, S);
858
+ S?.validIndices && S.validIndices[i] !== void 0 ? f = S.validIndices[i] : f = i;
859
+ const u = [...r, f.toString()], E = s(a, u, S);
855
860
  return e(
856
861
  a,
857
- y,
858
- c,
862
+ E,
863
+ i,
859
864
  T,
860
865
  s(T, r, S)
861
866
  );
862
867
  });
863
868
  if (l === "$stateMap")
864
- return (e) => rt(re, {
869
+ return (e) => lt(re, {
865
870
  proxy: {
866
871
  _stateKey: t,
867
872
  _path: r,
@@ -873,26 +878,20 @@ function It(t, i, m, g) {
873
878
  if (l === "stateList")
874
879
  return (e) => {
875
880
  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], y = [...r, c.toString()], p = s(u, y, S), w = `${m}-${r.join(".")}-${c}`;
878
- return rt(ae, {
879
- key: c,
881
+ return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
882
+ const u = n[i], E = [...r, i.toString()], y = s(u, E, S), w = `${m}-${r.join(".")}-${i}`;
883
+ return lt(ae, {
884
+ key: i,
880
885
  stateKey: t,
881
886
  itemComponentId: w,
882
- itemPath: y,
883
- children: rt(bt, {
884
- setState: i,
885
- stateKey: t,
886
- path: y,
887
- child: () => e(
888
- u,
889
- p,
890
- { localIndex: f, originalIndex: c },
891
- n,
892
- s(n, r, S)
893
- ),
894
- formOpts: void 0
895
- })
887
+ itemPath: E,
888
+ children: e(
889
+ u,
890
+ y,
891
+ { localIndex: f, originalIndex: i },
892
+ n,
893
+ s(n, r, S)
894
+ )
896
895
  });
897
896
  }) : (console.warn(
898
897
  `stateList called on a non-array value at path: ${r.join(".")}.`
@@ -903,7 +902,7 @@ function It(t, i, m, g) {
903
902
  const n = T;
904
903
  I.clear(), N++;
905
904
  const a = n.flatMap(
906
- (c) => c[e] ?? []
905
+ (i) => i[e] ?? []
907
906
  );
908
907
  return s(
909
908
  a,
@@ -920,40 +919,40 @@ function It(t, i, m, g) {
920
919
  return () => {
921
920
  const e = o.getState().getNestedState(t, r);
922
921
  if (e.length === 0) return;
923
- const n = e.length - 1, a = e[n], c = [...r, n.toString()];
924
- return s(a, c);
922
+ const n = e.length - 1, a = e[n], i = [...r, n.toString()];
923
+ return s(a, i);
925
924
  };
926
925
  if (l === "insert")
927
- return (e) => (E(r), Et(i, e, r, t), s(
926
+ return (e) => (p(r), Et(c, e, r, t), s(
928
927
  o.getState().getNestedState(t, r),
929
928
  r
930
929
  ));
931
930
  if (l === "uniqueInsert")
932
931
  return (e, n, a) => {
933
- const c = o.getState().getNestedState(t, r), f = tt(e) ? e(c) : e;
932
+ const i = o.getState().getNestedState(t, r), f = tt(e) ? e(i) : e;
934
933
  let u = null;
935
- if (!c.some((p) => {
934
+ if (!i.some((y) => {
936
935
  if (n) {
937
936
  const C = n.every(
938
- (A) => J(p[A], f[A])
937
+ (A) => J(y[A], f[A])
939
938
  );
940
- return C && (u = p), C;
939
+ return C && (u = y), C;
941
940
  }
942
- const w = J(p, f);
943
- return w && (u = p), w;
941
+ const w = J(y, f);
942
+ return w && (u = y), w;
944
943
  }))
945
- E(r), Et(i, f, r, t);
944
+ p(r), Et(c, f, r, t);
946
945
  else if (a && u) {
947
- const p = a(u), w = c.map(
948
- (C) => J(C, u) ? p : C
946
+ const y = a(u), w = i.map(
947
+ (C) => J(C, u) ? y : C
949
948
  );
950
- E(r), ct(i, w, r);
949
+ p(r), it(c, w, r);
951
950
  }
952
951
  };
953
952
  if (l === "cut")
954
953
  return (e, n) => {
955
954
  if (!n?.waitForSync)
956
- return E(r), ht(i, r, t, e), s(
955
+ return p(r), ht(c, r, t, e), s(
957
956
  o.getState().getNestedState(t, r),
958
957
  r
959
958
  );
@@ -961,12 +960,12 @@ function It(t, i, m, g) {
961
960
  if (l === "cutByValue")
962
961
  return (e) => {
963
962
  for (let n = 0; n < T.length; n++)
964
- T[n] === e && ht(i, r, t, n);
963
+ T[n] === e && ht(c, r, t, n);
965
964
  };
966
965
  if (l === "toggleByValue")
967
966
  return (e) => {
968
967
  const n = T.findIndex((a) => a === e);
969
- n > -1 ? ht(i, r, t, n) : Et(i, e, r, t);
968
+ n > -1 ? ht(c, r, t, n) : Et(c, e, r, t);
970
969
  };
971
970
  if (l === "stateFind")
972
971
  return (e) => {
@@ -974,17 +973,17 @@ function It(t, i, m, g) {
974
973
  ({ item: f }, u) => e(f, u)
975
974
  );
976
975
  if (!a) return;
977
- const c = [...r, a.originalIndex.toString()];
978
- return s(a.item, c, S);
976
+ const i = [...r, a.originalIndex.toString()];
977
+ return s(a.item, i, S);
979
978
  };
980
979
  if (l === "findWith")
981
980
  return (e, n) => {
982
- const c = d().find(
981
+ const i = d().find(
983
982
  ({ item: u }) => u[e] === n
984
983
  );
985
- if (!c) return;
986
- const f = [...r, c.originalIndex.toString()];
987
- return s(c.item, f, S);
984
+ if (!i) return;
985
+ const f = [...r, i.originalIndex.toString()];
986
+ return s(i.item, f, S);
988
987
  };
989
988
  }
990
989
  const et = r[r.length - 1];
@@ -992,7 +991,7 @@ function It(t, i, m, g) {
992
991
  const d = r.slice(0, -1), e = o.getState().getNestedState(t, d);
993
992
  if (Array.isArray(e) && l === "cut")
994
993
  return () => ht(
995
- i,
994
+ c,
996
995
  d,
997
996
  t,
998
997
  Number(et)
@@ -1007,13 +1006,13 @@ function It(t, i, m, g) {
1007
1006
  return o.getState().getNestedState(t, r);
1008
1007
  };
1009
1008
  if (l === "$derive")
1010
- return (d) => Gt({
1009
+ return (d) => Vt({
1011
1010
  _stateKey: t,
1012
1011
  _path: r,
1013
1012
  _effect: d.toString()
1014
1013
  });
1015
1014
  if (l === "$get")
1016
- return () => Gt({
1015
+ return () => Vt({
1017
1016
  _stateKey: t,
1018
1017
  _path: r
1019
1018
  });
@@ -1031,8 +1030,8 @@ function It(t, i, m, g) {
1031
1030
  return (d) => {
1032
1031
  const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
1033
1032
  d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
1034
- const c = o.getState().getNestedState(t, [...e]);
1035
- ct(i, c, e), E(e);
1033
+ const i = o.getState().getNestedState(t, [...e]);
1034
+ it(c, i, e), p(e);
1036
1035
  };
1037
1036
  if (l === "toggleSelected")
1038
1037
  return () => {
@@ -1042,8 +1041,8 @@ function It(t, i, m, g) {
1042
1041
  n,
1043
1042
  a === e ? void 0 : e
1044
1043
  );
1045
- const c = o.getState().getNestedState(t, [...d]);
1046
- ct(i, c, d), E(d);
1044
+ const i = o.getState().getNestedState(t, [...d]);
1045
+ it(c, i, d), p(d);
1047
1046
  };
1048
1047
  if (r.length == 0) {
1049
1048
  if (l === "addValidation")
@@ -1051,46 +1050,46 @@ function It(t, i, m, g) {
1051
1050
  const e = o.getState().getInitialOptions(t)?.validation;
1052
1051
  if (!e?.key)
1053
1052
  throw new Error("Validation key not found");
1054
- X(e.key), console.log("addValidationError", d), d.forEach((n) => {
1053
+ Q(e.key), console.log("addValidationError", d), d.forEach((n) => {
1055
1054
  const a = [e.key, ...n.path].join(".");
1056
- console.log("fullErrorPath", a), Dt(a, n.message);
1055
+ console.log("fullErrorPath", a), Rt(a, n.message);
1057
1056
  }), dt(t);
1058
1057
  };
1059
1058
  if (l === "applyJsonPatch")
1060
1059
  return (d) => {
1061
1060
  const e = o.getState().cogsStateStore[t], a = Yt(e, d).newDocument;
1062
- jt(
1061
+ Dt(
1063
1062
  t,
1064
1063
  o.getState().initialStateGlobal[t],
1065
1064
  a,
1066
- i,
1065
+ c,
1067
1066
  m,
1068
1067
  g
1069
1068
  );
1070
- const c = o.getState().stateComponents.get(t);
1071
- if (c) {
1069
+ const i = o.getState().stateComponents.get(t);
1070
+ if (i) {
1072
1071
  const f = _t(e, a), u = new Set(f);
1073
1072
  for (const [
1074
- y,
1075
- p
1076
- ] of c.components.entries()) {
1073
+ E,
1074
+ y
1075
+ ] of i.components.entries()) {
1077
1076
  let w = !1;
1078
- const C = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
1077
+ const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
1079
1078
  if (!C.includes("none")) {
1080
1079
  if (C.includes("all")) {
1081
- p.forceUpdate();
1080
+ y.forceUpdate();
1082
1081
  continue;
1083
1082
  }
1084
- if (C.includes("component") && (p.paths.has("") && (w = !0), !w))
1083
+ if (C.includes("component") && (y.paths.has("") && (w = !0), !w))
1085
1084
  for (const A of u) {
1086
- if (p.paths.has(A)) {
1085
+ if (y.paths.has(A)) {
1087
1086
  w = !0;
1088
1087
  break;
1089
1088
  }
1090
1089
  let b = A.lastIndexOf(".");
1091
1090
  for (; b !== -1; ) {
1092
1091
  const F = A.substring(0, b);
1093
- if (p.paths.has(F)) {
1092
+ if (y.paths.has(F)) {
1094
1093
  w = !0;
1095
1094
  break;
1096
1095
  }
@@ -1104,7 +1103,7 @@ function It(t, i, m, g) {
1104
1103
  0,
1105
1104
  M
1106
1105
  );
1107
- if (p.paths.has($)) {
1106
+ if (y.paths.has($)) {
1108
1107
  w = !0;
1109
1108
  break;
1110
1109
  }
@@ -1114,12 +1113,12 @@ function It(t, i, m, g) {
1114
1113
  }
1115
1114
  if (w) break;
1116
1115
  }
1117
- if (!w && C.includes("deps") && p.depsFunction) {
1118
- const A = p.depsFunction(a);
1116
+ if (!w && C.includes("deps") && y.depsFunction) {
1117
+ const A = y.depsFunction(a);
1119
1118
  let b = !1;
1120
- typeof A == "boolean" ? A && (b = !0) : J(p.deps, A) || (p.deps = A, b = !0), b && (w = !0);
1119
+ typeof A == "boolean" ? A && (b = !0) : J(y.deps, A) || (y.deps = A, b = !0), b && (w = !0);
1121
1120
  }
1122
- w && p.forceUpdate();
1121
+ w && y.forceUpdate();
1123
1122
  }
1124
1123
  }
1125
1124
  }
@@ -1131,17 +1130,17 @@ function It(t, i, m, g) {
1131
1130
  throw new Error("Zod schema not found");
1132
1131
  if (!d?.key)
1133
1132
  throw new Error("Validation key not found");
1134
- X(d.key);
1133
+ Q(d.key);
1135
1134
  const n = o.getState().cogsStateStore[t];
1136
1135
  try {
1137
1136
  const a = o.getState().getValidationErrors(d.key);
1138
1137
  a && a.length > 0 && a.forEach(([f]) => {
1139
- f && f.startsWith(d.key) && X(f);
1138
+ f && f.startsWith(d.key) && Q(f);
1140
1139
  });
1141
- const c = d.zodSchema.safeParse(n);
1142
- return c.success ? !0 : (c.error.errors.forEach((u) => {
1143
- const y = u.path, p = u.message, w = [d.key, ...y].join(".");
1144
- e(w, p);
1140
+ const i = d.zodSchema.safeParse(n);
1141
+ return i.success ? !0 : (i.error.errors.forEach((u) => {
1142
+ const E = u.path, y = u.message, w = [d.key, ...E].join(".");
1143
+ e(w, y);
1145
1144
  }), dt(t), !1);
1146
1145
  } catch (a) {
1147
1146
  return console.error("Zod schema validation failed", a), !1;
@@ -1151,7 +1150,7 @@ function It(t, i, m, g) {
1151
1150
  if (l === "getComponents")
1152
1151
  return () => o().stateComponents.get(t);
1153
1152
  if (l === "getAllFormRefs")
1154
- return () => Mt.getState().getFormRefsByStateKey(t);
1153
+ return () => bt.getState().getFormRefsByStateKey(t);
1155
1154
  if (l === "_initialState")
1156
1155
  return o.getState().initialStateGlobal[t];
1157
1156
  if (l === "_serverState")
@@ -1164,13 +1163,13 @@ function It(t, i, m, g) {
1164
1163
  if (l === "removeValidation") return v.removeValidation;
1165
1164
  }
1166
1165
  if (l === "getFormRef")
1167
- return () => Mt.getState().getFormRef(t + "." + r.join("."));
1166
+ return () => bt.getState().getFormRef(t + "." + r.join("."));
1168
1167
  if (l === "validationWrapper")
1169
1168
  return ({
1170
1169
  children: d,
1171
1170
  hideMessage: e
1172
1171
  }) => /* @__PURE__ */ Ot(
1173
- qt,
1172
+ zt,
1174
1173
  {
1175
1174
  formOpts: e ? { validation: { message: "" } } : void 0,
1176
1175
  path: r,
@@ -1186,33 +1185,33 @@ function It(t, i, m, g) {
1186
1185
  if (l === "update")
1187
1186
  return (d, e) => {
1188
1187
  if (e?.debounce)
1189
- zt(() => {
1190
- ct(i, d, r, "");
1188
+ Wt(() => {
1189
+ it(c, d, r, "");
1191
1190
  const n = o.getState().getNestedState(t, r);
1192
1191
  e?.afterUpdate && e.afterUpdate(n);
1193
1192
  }, e.debounce);
1194
1193
  else {
1195
- ct(i, d, r, "");
1194
+ it(c, d, r, "");
1196
1195
  const n = o.getState().getNestedState(t, r);
1197
1196
  e?.afterUpdate && e.afterUpdate(n);
1198
1197
  }
1199
- E(r);
1198
+ p(r);
1200
1199
  };
1201
1200
  if (l === "formElement")
1202
1201
  return (d, e) => /* @__PURE__ */ Ot(
1203
- bt,
1202
+ qt,
1204
1203
  {
1205
- setState: i,
1204
+ setState: c,
1206
1205
  stateKey: t,
1207
1206
  path: r,
1208
1207
  child: d,
1209
1208
  formOpts: e
1210
1209
  }
1211
1210
  );
1212
- const L = [...r, l], st = o.getState().getNestedState(t, L);
1213
- return s(st, L, S);
1211
+ const L = [...r, l], at = o.getState().getNestedState(t, L);
1212
+ return s(at, L, S);
1214
1213
  }
1215
- }, z = new Proxy(j, U);
1214
+ }, z = new Proxy(H, U);
1216
1215
  return I.set(W, {
1217
1216
  proxy: z,
1218
1217
  stateVersion: N
@@ -1222,35 +1221,35 @@ function It(t, i, m, g) {
1222
1221
  o.getState().getNestedState(t, [])
1223
1222
  );
1224
1223
  }
1225
- function Gt(t) {
1226
- return rt(oe, { proxy: t });
1224
+ function Vt(t) {
1225
+ return lt(oe, { proxy: t });
1227
1226
  }
1228
1227
  function re({
1229
1228
  proxy: t,
1230
- rebuildStateShape: i
1229
+ rebuildStateShape: c
1231
1230
  }) {
1232
1231
  const m = o().getNestedState(t._stateKey, t._path);
1233
- return Array.isArray(m) ? i(
1232
+ return Array.isArray(m) ? c(
1234
1233
  m,
1235
1234
  t._path
1236
1235
  ).stateMapNoRender(
1237
- (I, N, E, v, s) => t._mapFn(I, N, E, v, s)
1236
+ (I, N, p, v, s) => t._mapFn(I, N, p, v, s)
1238
1237
  ) : null;
1239
1238
  }
1240
1239
  function oe({
1241
1240
  proxy: t
1242
1241
  }) {
1243
- const i = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
1244
- return at(() => {
1245
- const g = i.current;
1242
+ const c = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
1243
+ return ot(() => {
1244
+ const g = c.current;
1246
1245
  if (!g || !g.parentElement) return;
1247
- const I = g.parentElement, E = Array.from(I.childNodes).indexOf(g);
1246
+ const I = g.parentElement, p = Array.from(I.childNodes).indexOf(g);
1248
1247
  let v = I.getAttribute("data-parent-id");
1249
1248
  v || (v = `parent-${crypto.randomUUID()}`, I.setAttribute("data-parent-id", v));
1250
1249
  const T = {
1251
1250
  instanceId: `instance-${crypto.randomUUID()}`,
1252
1251
  parentId: v,
1253
- position: E,
1252
+ position: p,
1254
1253
  effect: t._effect
1255
1254
  };
1256
1255
  o.getState().addSignalElement(m, T);
@@ -1262,22 +1261,22 @@ function oe({
1262
1261
  "state",
1263
1262
  `return (${t._effect})(state)`
1264
1263
  )(r);
1265
- } catch (j) {
1266
- console.error("Error evaluating effect function during mount:", j), S = r;
1264
+ } catch (H) {
1265
+ console.error("Error evaluating effect function during mount:", H), S = r;
1267
1266
  }
1268
1267
  else
1269
1268
  S = r;
1270
1269
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1271
1270
  const W = document.createTextNode(String(S));
1272
1271
  g.replaceWith(W);
1273
- }, [t._stateKey, t._path.join("."), t._effect]), rt("span", {
1274
- ref: i,
1272
+ }, [t._stateKey, t._path.join("."), t._effect]), lt("span", {
1273
+ ref: c,
1275
1274
  style: { display: "none" },
1276
1275
  "data-signal-id": m
1277
1276
  });
1278
1277
  }
1279
1278
  function pe(t) {
1280
- const i = Ft(
1279
+ const c = Ut(
1281
1280
  (m) => {
1282
1281
  const g = o.getState().stateComponents.get(t._stateKey) || {
1283
1282
  components: /* @__PURE__ */ new Map()
@@ -1289,23 +1288,23 @@ function pe(t) {
1289
1288
  },
1290
1289
  () => o.getState().getNestedState(t._stateKey, t._path)
1291
1290
  );
1292
- return rt("text", {}, String(i));
1291
+ return lt("text", {}, String(c));
1293
1292
  }
1294
1293
  function ae({
1295
1294
  stateKey: t,
1296
- itemComponentId: i,
1295
+ itemComponentId: c,
1297
1296
  itemPath: m,
1298
1297
  children: g
1299
1298
  }) {
1300
- const [, I] = K({}), [N, E] = Zt(), v = q(null);
1301
- return at(() => {
1302
- E.height > 0 && E.height !== v.current && (v.current = E.height, o.getState().setShadowMetadata(t, m, {
1299
+ const [, I] = K({}), [N, p] = Zt(), v = q(null);
1300
+ return ot(() => {
1301
+ p.height > 0 && p.height !== v.current && (v.current = p.height, o.getState().setShadowMetadata(t, m, {
1303
1302
  virtualizer: {
1304
- itemHeight: E.height
1303
+ itemHeight: p.height
1305
1304
  }
1306
1305
  }));
1307
- }, [E.height, t, m]), lt(() => {
1308
- const s = `${t}////${i}`, T = o.getState().stateComponents.get(t) || {
1306
+ }, [p.height, t, m]), ct(() => {
1307
+ const s = `${t}////${c}`, T = o.getState().stateComponents.get(t) || {
1309
1308
  components: /* @__PURE__ */ new Map()
1310
1309
  };
1311
1310
  return T.components.set(s, {
@@ -1315,10 +1314,10 @@ function ae({
1315
1314
  const r = o.getState().stateComponents.get(t);
1316
1315
  r && r.components.delete(s);
1317
1316
  };
1318
- }, [t, i, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: N, children: g });
1317
+ }, [t, c, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: N, children: g });
1319
1318
  }
1320
1319
  export {
1321
- Gt as $cogsSignal,
1320
+ Vt as $cogsSignal,
1322
1321
  pe as $cogsSignalStore,
1323
1322
  Ie as addStateOptions,
1324
1323
  ve as createCogsState,