cogsbox-state 0.5.338 → 0.5.339

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,8 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as ht } from "react/jsx-runtime";
3
- import { useState as Z, useRef as X, useEffect as nt, useLayoutEffect as lt, useMemo as vt, createElement as at, useSyncExternalStore as Pt, startTransition as _t, useCallback as Tt } from "react";
3
+ import { useState as Z, useRef as X, useEffect as ot, useLayoutEffect as lt, useMemo as vt, createElement as at, useSyncExternalStore as Pt, startTransition as _t, useCallback as Tt } from "react";
4
4
  import { transformStateFunc as Mt, isDeepEqual as H, isFunction as q, getNestedValue as z, getDifferences as yt, debounce as jt } from "./utility.js";
5
- import { pushFunc as mt, updateFn as ot, cutFunc as ct, ValidationWrapper as Ot, FormControlComponent as Rt } from "./Functions.jsx";
5
+ import { pushFunc as mt, updateFn as rt, cutFunc as ct, ValidationWrapper as Ot, FormControlComponent as Rt } from "./Functions.jsx";
6
6
  import Ut from "superjson";
7
7
  import { v4 as It } from "uuid";
8
8
  import "zod";
@@ -22,13 +22,13 @@ function $t({
22
22
  options: c,
23
23
  initialOptionsPart: h
24
24
  }) {
25
- const S = et(t) || {}, I = h[t] || {}, b = o.getState().setInitialStateOptions, w = { ...I, ...S };
25
+ const S = et(t) || {}, I = h[t] || {}, $ = o.getState().setInitialStateOptions, w = { ...I, ...S };
26
26
  let p = !1;
27
27
  if (c)
28
28
  for (const a in c)
29
29
  w.hasOwnProperty(a) ? (a == "localStorage" && c[a] && w[a].key !== c[a]?.key && (p = !0, w[a] = c[a]), a == "initialState" && c[a] && w[a] !== c[a] && // Different references
30
30
  !H(w[a], c[a]) && (p = !0, w[a] = c[a])) : (p = !0, w[a] = c[a]);
31
- p && b(t, w);
31
+ p && $(t, w);
32
32
  }
33
33
  function ce(t, { formElements: c, validation: h }) {
34
34
  return { initialState: t, formElements: c, validation: h };
@@ -45,7 +45,7 @@ const le = (t, c) => {
45
45
  // State-specific overrides
46
46
  }, et(p) || o.getState().setInitialStateOptions(p, I[p]);
47
47
  }), o.getState().setInitialStates(S), o.getState().setCreatedState(S);
48
- const b = (p, a) => {
48
+ const $ = (p, a) => {
49
49
  const [y] = Z(a?.componentId ?? It());
50
50
  $t({
51
51
  stateKey: p,
@@ -73,7 +73,7 @@ const le = (t, c) => {
73
73
  function w(p, a) {
74
74
  $t({ stateKey: p, options: a, initialOptionsPart: I }), a.localStorage && zt(p, a), ft(p);
75
75
  }
76
- return { useCogsState: b, setCogsOptions: w };
76
+ return { useCogsState: $, setCogsOptions: w };
77
77
  }, {
78
78
  setUpdaterState: dt,
79
79
  setState: Q,
@@ -92,9 +92,9 @@ const le = (t, c) => {
92
92
  h.localStorage?.key,
93
93
  S
94
94
  );
95
- const b = q(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
96
- if (b && S) {
97
- const w = `${S}-${c}-${b}`;
95
+ const $ = q(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
96
+ if ($ && S) {
97
+ const w = `${S}-${c}-${$}`;
98
98
  let p;
99
99
  try {
100
100
  p = gt(w)?.lastSyncedWithServer;
@@ -121,21 +121,21 @@ const le = (t, c) => {
121
121
  }, zt = (t, c) => {
122
122
  const h = o.getState().cogsStateStore[t], { sessionId: S } = Nt(), I = q(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
123
123
  if (I && S) {
124
- const b = gt(
124
+ const $ = gt(
125
125
  `${S}-${t}-${I}`
126
126
  );
127
- if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
128
- return Q(t, b.state), ft(t), !0;
127
+ if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
128
+ return Q(t, $.state), ft(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Ct = (t, c, h, S, I, b) => {
131
+ }, Ct = (t, c, h, S, I, $) => {
132
132
  const w = {
133
133
  initialState: c,
134
134
  updaterState: ut(
135
135
  t,
136
136
  S,
137
137
  I,
138
- b
138
+ $
139
139
  ),
140
140
  state: h
141
141
  };
@@ -185,7 +185,7 @@ function qt(t, {
185
185
  serverSync: h,
186
186
  localStorage: S,
187
187
  formElements: I,
188
- reactiveDeps: b,
188
+ reactiveDeps: $,
189
189
  reactiveType: w,
190
190
  componentId: p,
191
191
  initialState: a,
@@ -198,7 +198,7 @@ function qt(t, {
198
198
  const [v] = Z(c ?? It()), l = o.getState().stateLog[v], st = X(/* @__PURE__ */ new Set()), J = X(p ?? It()), j = X(
199
199
  null
200
200
  );
201
- j.current = et(v) ?? null, nt(() => {
201
+ j.current = et(v) ?? null, ot(() => {
202
202
  if (y && y.stateKey === v && y.path?.[0]) {
203
203
  Q(v, (r) => ({
204
204
  ...r,
@@ -210,7 +210,7 @@ function qt(t, {
210
210
  userId: y.userId
211
211
  });
212
212
  }
213
- }, [y]), nt(() => {
213
+ }, [y]), ot(() => {
214
214
  if (a) {
215
215
  At(v, {
216
216
  initialState: a
@@ -218,16 +218,16 @@ function qt(t, {
218
218
  const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[v];
219
219
  if (!(i && !H(i, a) || !i) && !s)
220
220
  return;
221
- let f = null;
221
+ let u = null;
222
222
  const E = q(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
- E && U && (f = gt(`${U}-${v}-${E}`));
223
+ E && U && (u = gt(`${U}-${v}-${E}`));
224
224
  let T = a, A = !1;
225
- const P = s ? Date.now() : 0, V = f?.lastUpdated || 0, $ = f?.lastSyncedWithServer || 0;
226
- s && P > V ? (T = e.serverState.data, A = !0) : f && V > $ && (T = f.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(v, a), Ct(
225
+ const P = s ? Date.now() : 0, N = u?.lastUpdated || 0, V = u?.lastSyncedWithServer || 0;
226
+ s && P > N ? (T = e.serverState.data, A = !0) : u && N > V && (T = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(v, a), Ct(
227
227
  v,
228
228
  a,
229
229
  T,
230
- rt,
230
+ nt,
231
231
  J.current,
232
232
  U
233
233
  ), A && E && U && kt(T, v, e, U, Date.now()), ft(v), (Array.isArray(w) ? w : [w || "component"]).includes("none") || R({});
@@ -252,41 +252,41 @@ function qt(t, {
252
252
  forceUpdate: () => R({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: b || void 0,
255
+ depsFunction: $ || void 0,
256
256
  reactiveType: w ?? ["component", "deps"]
257
257
  }), o.getState().stateComponents.set(v, r), R({}), () => {
258
258
  r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(v));
259
259
  };
260
260
  }, []);
261
- const rt = (e, r, s, i) => {
261
+ const nt = (e, r, s, i) => {
262
262
  if (Array.isArray(r)) {
263
- const f = `${v}-${r.join(".")}`;
264
- st.current.add(f);
263
+ const u = `${v}-${r.join(".")}`;
264
+ st.current.add(u);
265
265
  }
266
266
  const g = o.getState();
267
- Q(v, (f) => {
268
- const E = q(e) ? e(f) : e, T = `${v}-${r.join(".")}`;
267
+ Q(v, (u) => {
268
+ const E = q(e) ? e(u) : e, T = `${v}-${r.join(".")}`;
269
269
  if (T) {
270
- let M = !1, N = g.signalDomElements.get(T);
271
- if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
270
+ let M = !1, k = g.signalDomElements.get(T);
271
+ if ((!k || k.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
272
  const O = r.slice(0, -1), W = z(E, O);
273
273
  if (Array.isArray(W)) {
274
274
  M = !0;
275
- const u = `${v}-${O.join(".")}`;
276
- N = g.signalDomElements.get(u);
275
+ const f = `${v}-${O.join(".")}`;
276
+ k = g.signalDomElements.get(f);
277
277
  }
278
278
  }
279
- if (N) {
279
+ if (k) {
280
280
  const O = M ? z(E, r.slice(0, -1)) : z(E, r);
281
- N.forEach(({ parentId: W, position: u, effect: k }) => {
281
+ k.forEach(({ parentId: W, position: f, effect: b }) => {
282
282
  const C = document.querySelector(
283
283
  `[data-parent-id="${W}"]`
284
284
  );
285
285
  if (C) {
286
286
  const _ = Array.from(C.childNodes);
287
- if (_[u]) {
288
- const x = k ? new Function("state", `return (${k})(state)`)(O) : O;
289
- _[u].textContent = String(x);
287
+ if (_[f]) {
288
+ const x = b ? new Function("state", `return (${b})(state)`)(O) : O;
289
+ _[f].textContent = String(x);
290
290
  }
291
291
  }
292
292
  });
@@ -300,33 +300,33 @@ function qt(t, {
300
300
  j.current?.validation?.key + "." + A.join(".")
301
301
  ), s.updateType === "insert" && j.current?.validation?.key && Wt(
302
302
  j.current?.validation?.key + "." + A.join(".")
303
- ).filter(([N, O]) => {
304
- let W = N?.split(".").length;
305
- if (N == A.join(".") && W == A.length - 1) {
306
- let u = N + "." + A;
307
- B(N), Gt(u, O);
303
+ ).filter(([k, O]) => {
304
+ let W = k?.split(".").length;
305
+ if (k == A.join(".") && W == A.length - 1) {
306
+ let f = k + "." + A;
307
+ B(k), Gt(f, O);
308
308
  }
309
309
  });
310
310
  const P = g.stateComponents.get(v);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", P), P) {
312
- const M = yt(f, E), N = new Set(M), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
312
+ const M = yt(u, E), k = new Set(M), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
313
313
  for (const [
314
314
  W,
315
- u
315
+ f
316
316
  ] of P.components.entries()) {
317
- let k = !1;
318
- const C = Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"];
319
- if (console.log("component", u), !C.includes("none")) {
317
+ let b = !1;
318
+ const C = Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"];
319
+ if (console.log("component", f), !C.includes("none")) {
320
320
  if (C.includes("all")) {
321
- u.forceUpdate();
321
+ f.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (C.includes("component") && ((u.paths.has(O) || u.paths.has("")) && (k = !0), !k))
325
- for (const _ of N) {
324
+ if (C.includes("component") && ((f.paths.has(O) || f.paths.has("")) && (b = !0), !b))
325
+ for (const _ of k) {
326
326
  let x = _;
327
327
  for (; ; ) {
328
- if (u.paths.has(x)) {
329
- k = !0;
328
+ if (f.paths.has(x)) {
329
+ b = !0;
330
330
  break;
331
331
  }
332
332
  const Y = x.lastIndexOf(".");
@@ -337,8 +337,8 @@ function qt(t, {
337
337
  );
338
338
  if (!isNaN(
339
339
  Number(x.substring(Y + 1))
340
- ) && u.paths.has(K)) {
341
- k = !0;
340
+ ) && f.paths.has(K)) {
341
+ b = !0;
342
342
  break;
343
343
  }
344
344
  x = K;
@@ -347,34 +347,34 @@ function qt(t, {
347
347
  if (x === "")
348
348
  break;
349
349
  }
350
- if (k) break;
350
+ if (b) break;
351
351
  }
352
- if (!k && C.includes("deps") && u.depsFunction) {
353
- const _ = u.depsFunction(E);
352
+ if (!b && C.includes("deps") && f.depsFunction) {
353
+ const _ = f.depsFunction(E);
354
354
  let x = !1;
355
- typeof _ == "boolean" ? _ && (x = !0) : H(u.deps, _) || (u.deps = _, x = !0), x && (k = !0);
355
+ typeof _ == "boolean" ? _ && (x = !0) : H(f.deps, _) || (f.deps = _, x = !0), x && (b = !0);
356
356
  }
357
- k && u.forceUpdate();
357
+ b && f.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const V = Date.now();
362
- r = r.map((M, N) => {
361
+ const N = Date.now();
362
+ r = r.map((M, k) => {
363
363
  const O = r.slice(0, -1), W = z(E, O);
364
- return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : M;
364
+ return k === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : M;
365
365
  });
366
- const { oldValue: $, newValue: D } = Bt(
366
+ const { oldValue: V, newValue: D } = Bt(
367
367
  s.updateType,
368
- f,
368
+ u,
369
369
  E,
370
370
  r
371
371
  ), F = {
372
- timeStamp: V,
372
+ timeStamp: N,
373
373
  stateKey: v,
374
374
  path: r,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
- oldValue: $,
377
+ oldValue: V,
378
378
  newValue: D
379
379
  };
380
380
  switch (s.updateType) {
@@ -386,14 +386,14 @@ function qt(t, {
386
386
  g.insertShadowArrayElement(v, M, D);
387
387
  break;
388
388
  case "cut":
389
- const N = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- g.removeShadowArrayElement(v, N, O);
389
+ const k = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
+ g.removeShadowArrayElement(v, k, O);
391
391
  break;
392
392
  }
393
393
  if (Lt(v, (M) => {
394
- const O = [...M ?? [], F].reduce((W, u) => {
395
- const k = `${u.stateKey}:${JSON.stringify(u.path)}`, C = W.get(k);
396
- return C ? (C.timeStamp = Math.max(C.timeStamp, u.timeStamp), C.newValue = u.newValue, C.oldValue = C.oldValue ?? u.oldValue, C.updateType = u.updateType) : W.set(k, { ...u }), W;
394
+ const O = [...M ?? [], F].reduce((W, f) => {
395
+ const b = `${f.stateKey}:${JSON.stringify(f.path)}`, C = W.get(b);
396
+ return C ? (C.timeStamp = Math.max(C.timeStamp, f.timeStamp), C.newValue = f.newValue, C.oldValue = C.oldValue ?? f.oldValue, C.updateType = f.updateType) : W.set(b, { ...f }), W;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(O.values());
399
399
  }), kt(
@@ -405,11 +405,11 @@ function qt(t, {
405
405
  updateLog: l,
406
406
  update: F
407
407
  }), j.current?.serverSync) {
408
- const M = g.serverState[v], N = j.current?.serverSync;
408
+ const M = g.serverState[v], k = j.current?.serverSync;
409
409
  Ht(v, {
410
- syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
410
+ syncKey: typeof k.syncKey == "string" ? k.syncKey : k.syncKey({ state: E }),
411
411
  rollBackState: M,
412
- actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
412
+ actionTimeStamp: Date.now() + (k.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
@@ -420,14 +420,14 @@ function qt(t, {
420
420
  v,
421
421
  ut(
422
422
  v,
423
- rt,
423
+ nt,
424
424
  J.current,
425
425
  U
426
426
  )
427
427
  ), o.getState().cogsStateStore[v] || Q(v, t), o.getState().initialStateGlobal[v] || pt(v, t));
428
428
  const d = vt(() => ut(
429
429
  v,
430
- rt,
430
+ nt,
431
431
  J.current,
432
432
  U
433
433
  ), [v, U]);
@@ -435,12 +435,12 @@ function qt(t, {
435
435
  }
436
436
  function ut(t, c, h, S) {
437
437
  const I = /* @__PURE__ */ new Map();
438
- let b = 0;
438
+ let $ = 0;
439
439
  const w = (y) => {
440
440
  const n = y.join(".");
441
441
  for (const [m] of I)
442
442
  (m === n || m.startsWith(n + ".")) && I.delete(m);
443
- b++;
443
+ $++;
444
444
  }, p = {
445
445
  removeValidation: (y) => {
446
446
  y?.validationKey && B(y.validationKey);
@@ -449,7 +449,7 @@ function ut(t, c, h, S) {
449
449
  const n = o.getState().getInitialOptions(t)?.validation;
450
450
  n?.key && B(n?.key), y?.validationKey && B(y.validationKey);
451
451
  const m = o.getState().initialStateGlobal[t];
452
- o.getState().clearSelectedIndexesForState(t), I.clear(), b++;
452
+ o.getState().clearSelectedIndexesForState(t), I.clear(), $++;
453
453
  const L = a(m, []), R = et(t), U = q(R?.localStorage?.key) ? R?.localStorage?.key(m) : R?.localStorage?.key, G = `${S}-${t}-${U}`;
454
454
  G && localStorage.removeItem(G), dt(t, L), Q(t, m);
455
455
  const v = o.getState().stateComponents.get(t);
@@ -458,7 +458,7 @@ function ut(t, c, h, S) {
458
458
  }), m;
459
459
  },
460
460
  updateInitialState: (y) => {
461
- I.clear(), b++;
461
+ I.clear(), $++;
462
462
  const n = ut(
463
463
  t,
464
464
  c,
@@ -553,13 +553,13 @@ function ut(t, c, h, S) {
553
553
  try {
554
554
  const i = await e.action(r);
555
555
  if (i && !i.success && i.errors && s) {
556
- o.getState().removeValidationError(s), i.errors.forEach((f) => {
557
- const E = [s, ...f.path].join(".");
558
- o.getState().addValidationError(E, f.message);
556
+ o.getState().removeValidationError(s), i.errors.forEach((u) => {
557
+ const E = [s, ...u.path].join(".");
558
+ o.getState().addValidationError(E, u.message);
559
559
  });
560
560
  const g = o.getState().stateComponents.get(t);
561
- g && g.components.forEach((f) => {
562
- f.forceUpdate();
561
+ g && g.components.forEach((u) => {
562
+ u.forceUpdate();
563
563
  });
564
564
  }
565
565
  return i?.success && e.onSuccess ? e.onSuccess(i.data) : !i?.success && e.onError && e.onError(i.error), i;
@@ -621,64 +621,49 @@ function ut(t, c, h, S) {
621
621
  itemHeight: r = 50,
622
622
  overscan: s = 5,
623
623
  stickToBottom: i = !1
624
- } = e, g = X(null), [f, E] = Z({
624
+ } = e, g = X(null), [u, E] = Z({
625
625
  startIndex: 0,
626
626
  endIndex: 10
627
627
  }), T = X(i), [A, P] = Z(0);
628
- nt(() => o.getState().subscribeToShadowState(t, () => {
629
- P((k) => k + 1);
628
+ ot(() => o.getState().subscribeToShadowState(t, () => {
629
+ P((b) => b + 1);
630
630
  }), [t]);
631
- const V = o().getNestedState(
631
+ const N = o().getNestedState(
632
632
  t,
633
633
  n
634
- ), $ = V.length, { totalHeight: D, positions: F } = vt(() => {
635
- const u = o.getState().getShadowMetadata(t, n) || [];
636
- let k = 0;
634
+ ), V = N.length, { totalHeight: D, positions: F } = vt(() => {
635
+ const f = o.getState().getShadowMetadata(t, n) || [];
636
+ let b = 0;
637
637
  const C = [];
638
- for (let _ = 0; _ < $; _++) {
639
- C[_] = k;
640
- const x = u[_]?.virtualizer?.itemHeight;
641
- k += x || r;
638
+ for (let _ = 0; _ < V; _++) {
639
+ C[_] = b;
640
+ const x = f[_]?.virtualizer?.itemHeight;
641
+ b += x || r;
642
642
  }
643
- return { totalHeight: k, positions: C };
643
+ return { totalHeight: b, positions: C };
644
644
  }, [
645
- $,
645
+ V,
646
646
  t,
647
647
  n.join("."),
648
648
  r,
649
649
  A
650
650
  ]), M = vt(() => {
651
- const u = Math.max(0, f.startIndex), k = Math.min($, f.endIndex), C = Array.from(
652
- { length: k - u },
653
- (x, Y) => u + Y
654
- ), _ = C.map((x) => V[x]);
651
+ const f = Math.max(0, u.startIndex), b = Math.min(V, u.endIndex), C = Array.from(
652
+ { length: b - f },
653
+ (x, Y) => f + Y
654
+ ), _ = C.map((x) => N[x]);
655
655
  return a(_, n, {
656
656
  ...m,
657
657
  validIndices: C
658
658
  });
659
- }, [f.startIndex, f.endIndex, V, $]);
660
- nt(() => {
661
- if (i && $ > 0 && g.current) {
662
- const u = g.current, k = Math.ceil(
663
- u.clientHeight / r
664
- );
665
- E({
666
- startIndex: Math.max(
667
- 0,
668
- $ - k - s
669
- ),
670
- endIndex: $
671
- }), setTimeout(() => {
672
- u.scrollTop = u.scrollHeight;
673
- }, 100);
674
- }
675
- }, [$]), lt(() => {
676
- const u = g.current;
677
- if (!u) return;
678
- const k = u.scrollHeight - u.scrollTop - u.clientHeight < 1, C = () => {
679
- if (!u) return;
680
- const { scrollTop: x, clientHeight: Y } = u;
681
- let K = 0, it = $ - 1;
659
+ }, [u.startIndex, u.endIndex, N, V]);
660
+ lt(() => {
661
+ const f = g.current;
662
+ if (!f) return;
663
+ const b = f.scrollHeight - f.scrollTop - f.clientHeight < r, C = () => {
664
+ if (!f) return;
665
+ const { scrollTop: x, clientHeight: Y } = f;
666
+ let K = 0, it = V - 1;
682
667
  for (; K <= it; ) {
683
668
  const St = Math.floor((K + it) / 2);
684
669
  F[St] < x ? K = St + 1 : it = St - 1;
@@ -686,31 +671,31 @@ function ut(t, c, h, S) {
686
671
  const wt = Math.max(0, it - s);
687
672
  let tt = wt;
688
673
  const xt = x + Y;
689
- for (; tt < $ && F[tt] < xt; )
674
+ for (; tt < V && F[tt] < xt; )
690
675
  tt++;
691
- tt = Math.min($, tt + s), E({ startIndex: wt, endIndex: tt });
676
+ tt = Math.min(V, tt + s), E({ startIndex: wt, endIndex: tt });
692
677
  }, _ = () => {
693
- T.current = u.scrollHeight - u.scrollTop - u.clientHeight < 1, C();
678
+ T.current = f.scrollHeight - f.scrollTop - f.clientHeight < 1, C();
694
679
  };
695
- return u.addEventListener("scroll", _, {
680
+ return f.addEventListener("scroll", _, {
696
681
  passive: !0
697
- }), i && (T.current || k) && (u.scrollTop = u.scrollHeight), C(), () => {
698
- u.removeEventListener("scroll", _);
682
+ }), i && (T.current || b) && (f.scrollTop = f.scrollHeight), C(), () => {
683
+ f.removeEventListener("scroll", _);
699
684
  };
700
- }, [$, F, D, i]);
701
- const N = Tt(
702
- (u = "smooth") => {
685
+ }, [V, F, D, i]);
686
+ const k = Tt(
687
+ (f = "smooth") => {
703
688
  g.current && (T.current = !0, g.current.scrollTo({
704
689
  top: g.current.scrollHeight,
705
- behavior: u
690
+ behavior: f
706
691
  }));
707
692
  },
708
693
  []
709
694
  ), O = Tt(
710
- (u, k = "smooth") => {
711
- g.current && F[u] !== void 0 && (T.current = !1, g.current.scrollTo({
712
- top: F[u],
713
- behavior: k
695
+ (f, b = "smooth") => {
696
+ g.current && F[f] !== void 0 && (T.current = !1, g.current.scrollTo({
697
+ top: F[f],
698
+ behavior: b
714
699
  }));
715
700
  },
716
701
  [F]
@@ -727,25 +712,25 @@ function ut(t, c, h, S) {
727
712
  },
728
713
  list: {
729
714
  style: {
730
- transform: `translateY(${F[f.startIndex] || 0}px)`
715
+ transform: `translateY(${F[u.startIndex] || 0}px)`
731
716
  }
732
717
  }
733
718
  };
734
719
  return {
735
720
  virtualState: M,
736
721
  virtualizerProps: W,
737
- scrollToBottom: N,
722
+ scrollToBottom: k,
738
723
  scrollToIndex: O
739
724
  };
740
725
  };
741
726
  if (l === "stateSort")
742
727
  return (e) => {
743
728
  const s = [...d()].sort(
744
- (f, E) => e(f.item, E.item)
745
- ), i = s.map(({ item: f }) => f), g = {
729
+ (u, E) => e(u.item, E.item)
730
+ ), i = s.map(({ item: u }) => u), g = {
746
731
  ...m,
747
732
  validIndices: s.map(
748
- ({ originalIndex: f }) => f
733
+ ({ originalIndex: u }) => u
749
734
  )
750
735
  };
751
736
  return a(i, n, g);
@@ -753,11 +738,11 @@ function ut(t, c, h, S) {
753
738
  if (l === "stateFilter")
754
739
  return (e) => {
755
740
  const s = d().filter(
756
- ({ item: f }, E) => e(f, E)
757
- ), i = s.map(({ item: f }) => f), g = {
741
+ ({ item: u }, E) => e(u, E)
742
+ ), i = s.map(({ item: u }) => u), g = {
758
743
  ...m,
759
744
  validIndices: s.map(
760
- ({ originalIndex: f }) => f
745
+ ({ originalIndex: u }) => u
761
746
  )
762
747
  };
763
748
  return a(i, n, g);
@@ -766,22 +751,22 @@ function ut(t, c, h, S) {
766
751
  return (e) => {
767
752
  const r = o.getState().getNestedState(t, n);
768
753
  return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
769
- const f = r[i], E = [...n, i.toString()], T = a(f, E, m);
770
- return e(f, T, {
754
+ const u = r[i], E = [...n, i.toString()], T = a(u, E, m);
755
+ return e(u, T, {
771
756
  register: () => {
772
- const [, P] = Z({}), V = `${h}-${n.join(".")}-${i}`;
757
+ const [, P] = Z({}), N = `${h}-${n.join(".")}-${i}`;
773
758
  lt(() => {
774
- const $ = `${t}////${V}`, D = o.getState().stateComponents.get(t) || {
759
+ const V = `${t}////${N}`, D = o.getState().stateComponents.get(t) || {
775
760
  components: /* @__PURE__ */ new Map()
776
761
  };
777
- return D.components.set($, {
762
+ return D.components.set(V, {
778
763
  forceUpdate: () => P({}),
779
764
  paths: /* @__PURE__ */ new Set([E.join(".")])
780
765
  }), o.getState().stateComponents.set(t, D), () => {
781
766
  const F = o.getState().stateComponents.get(t);
782
- F && F.components.delete($);
767
+ F && F.components.delete(V);
783
768
  };
784
- }, [t, V]);
769
+ }, [t, N]);
785
770
  },
786
771
  index: g,
787
772
  originalIndex: i
@@ -795,7 +780,7 @@ function ut(t, c, h, S) {
795
780
  return (e) => y.map((s, i) => {
796
781
  let g;
797
782
  m?.validIndices && m.validIndices[i] !== void 0 ? g = m.validIndices[i] : g = i;
798
- const f = [...n, g.toString()], E = a(s, f, m);
783
+ const u = [...n, g.toString()], E = a(s, u, m);
799
784
  return e(
800
785
  s,
801
786
  E,
@@ -818,14 +803,14 @@ function ut(t, c, h, S) {
818
803
  return (e) => {
819
804
  const r = o.getState().getNestedState(t, n);
820
805
  return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
821
- const f = r[i], E = [...n, i.toString()], T = a(f, E, m), A = `${h}-${n.join(".")}-${i}`;
806
+ const u = r[i], E = [...n, i.toString()], T = a(u, E, m), A = `${h}-${n.join(".")}-${i}`;
822
807
  return at(Zt, {
823
808
  key: i,
824
809
  stateKey: t,
825
810
  itemComponentId: A,
826
811
  itemPath: E,
827
812
  children: e(
828
- f,
813
+ u,
829
814
  T,
830
815
  g,
831
816
  r,
@@ -839,7 +824,7 @@ function ut(t, c, h, S) {
839
824
  if (l === "stateFlattenOn")
840
825
  return (e) => {
841
826
  const r = y;
842
- I.clear(), b++;
827
+ I.clear(), $++;
843
828
  const s = r.flatMap(
844
829
  (i) => i[e] ?? []
845
830
  );
@@ -869,23 +854,23 @@ function ut(t, c, h, S) {
869
854
  if (l === "uniqueInsert")
870
855
  return (e, r, s) => {
871
856
  const i = o.getState().getNestedState(t, n), g = q(e) ? e(i) : e;
872
- let f = null;
857
+ let u = null;
873
858
  if (!i.some((T) => {
874
859
  if (r) {
875
860
  const P = r.every(
876
- (V) => H(T[V], g[V])
861
+ (N) => H(T[N], g[N])
877
862
  );
878
- return P && (f = T), P;
863
+ return P && (u = T), P;
879
864
  }
880
865
  const A = H(T, g);
881
- return A && (f = T), A;
866
+ return A && (u = T), A;
882
867
  }))
883
868
  w(n), mt(c, g, n, t);
884
- else if (s && f) {
885
- const T = s(f), A = i.map(
886
- (P) => H(P, f) ? T : P
869
+ else if (s && u) {
870
+ const T = s(u), A = i.map(
871
+ (P) => H(P, u) ? T : P
887
872
  );
888
- w(n), ot(c, A, n);
873
+ w(n), rt(c, A, n);
889
874
  }
890
875
  };
891
876
  if (l === "cut")
@@ -909,7 +894,7 @@ function ut(t, c, h, S) {
909
894
  if (l === "stateFind")
910
895
  return (e) => {
911
896
  const s = d().find(
912
- ({ item: g }, f) => e(g, f)
897
+ ({ item: g }, u) => e(g, u)
913
898
  );
914
899
  if (!s) return;
915
900
  const i = [...n, s.originalIndex.toString()];
@@ -918,7 +903,7 @@ function ut(t, c, h, S) {
918
903
  if (l === "findWith")
919
904
  return (e, r) => {
920
905
  const i = d().find(
921
- ({ item: f }) => f[e] === r
906
+ ({ item: u }) => u[e] === r
922
907
  );
923
908
  if (!i) return;
924
909
  const g = [...n, i.originalIndex.toString()];
@@ -970,7 +955,7 @@ function ut(t, c, h, S) {
970
955
  const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
971
956
  d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
972
957
  const i = o.getState().getNestedState(t, [...e]);
973
- ot(c, i, e), w(e);
958
+ rt(c, i, e), w(e);
974
959
  };
975
960
  if (l === "toggleSelected")
976
961
  return () => {
@@ -981,7 +966,7 @@ function ut(t, c, h, S) {
981
966
  s === e ? void 0 : e
982
967
  );
983
968
  const i = o.getState().getNestedState(t, [...d]);
984
- ot(c, i, d), w(d);
969
+ rt(c, i, d), w(d);
985
970
  };
986
971
  if (n.length == 0) {
987
972
  if (l === "applyJsonPatch")
@@ -997,7 +982,7 @@ function ut(t, c, h, S) {
997
982
  );
998
983
  const i = o.getState().stateComponents.get(t);
999
984
  if (i) {
1000
- const g = yt(e, s), f = new Set(g);
985
+ const g = yt(e, s), u = new Set(g);
1001
986
  for (const [
1002
987
  E,
1003
988
  T
@@ -1010,42 +995,42 @@ function ut(t, c, h, S) {
1010
995
  continue;
1011
996
  }
1012
997
  if (P.includes("component") && (T.paths.has("") && (A = !0), !A))
1013
- for (const V of f) {
1014
- if (T.paths.has(V)) {
998
+ for (const N of u) {
999
+ if (T.paths.has(N)) {
1015
1000
  A = !0;
1016
1001
  break;
1017
1002
  }
1018
- let $ = V.lastIndexOf(".");
1019
- for (; $ !== -1; ) {
1020
- const D = V.substring(0, $);
1003
+ let V = N.lastIndexOf(".");
1004
+ for (; V !== -1; ) {
1005
+ const D = N.substring(0, V);
1021
1006
  if (T.paths.has(D)) {
1022
1007
  A = !0;
1023
1008
  break;
1024
1009
  }
1025
- const F = V.substring(
1026
- $ + 1
1010
+ const F = N.substring(
1011
+ V + 1
1027
1012
  );
1028
1013
  if (!isNaN(Number(F))) {
1029
1014
  const M = D.lastIndexOf(".");
1030
1015
  if (M !== -1) {
1031
- const N = D.substring(
1016
+ const k = D.substring(
1032
1017
  0,
1033
1018
  M
1034
1019
  );
1035
- if (T.paths.has(N)) {
1020
+ if (T.paths.has(k)) {
1036
1021
  A = !0;
1037
1022
  break;
1038
1023
  }
1039
1024
  }
1040
1025
  }
1041
- $ = D.lastIndexOf(".");
1026
+ V = D.lastIndexOf(".");
1042
1027
  }
1043
1028
  if (A) break;
1044
1029
  }
1045
1030
  if (!A && P.includes("deps") && T.depsFunction) {
1046
- const V = T.depsFunction(s);
1047
- let $ = !1;
1048
- typeof V == "boolean" ? V && ($ = !0) : H(T.deps, V) || (T.deps = V, $ = !0), $ && (A = !0);
1031
+ const N = T.depsFunction(s);
1032
+ let V = !1;
1033
+ typeof N == "boolean" ? N && (V = !0) : H(T.deps, N) || (T.deps = N, V = !0), V && (A = !0);
1049
1034
  }
1050
1035
  A && T.forceUpdate();
1051
1036
  }
@@ -1067,8 +1052,8 @@ function ut(t, c, h, S) {
1067
1052
  g && g.startsWith(d.key) && B(g);
1068
1053
  });
1069
1054
  const i = d.zodSchema.safeParse(r);
1070
- return i.success ? !0 : (i.error.errors.forEach((f) => {
1071
- const E = f.path, T = f.message, A = [d.key, ...E].join(".");
1055
+ return i.success ? !0 : (i.error.errors.forEach((u) => {
1056
+ const E = u.path, T = u.message, A = [d.key, ...E].join(".");
1072
1057
  e(A, T);
1073
1058
  }), ft(t), !1);
1074
1059
  } catch (s) {
@@ -1115,12 +1100,12 @@ function ut(t, c, h, S) {
1115
1100
  return (d, e) => {
1116
1101
  if (e?.debounce)
1117
1102
  jt(() => {
1118
- ot(c, d, n, "");
1103
+ rt(c, d, n, "");
1119
1104
  const r = o.getState().getNestedState(t, n);
1120
1105
  e?.afterUpdate && e.afterUpdate(r);
1121
1106
  }, e.debounce);
1122
1107
  else {
1123
- ot(c, d, n, "");
1108
+ rt(c, d, n, "");
1124
1109
  const r = o.getState().getNestedState(t, n);
1125
1110
  e?.afterUpdate && e.afterUpdate(r);
1126
1111
  }
@@ -1137,13 +1122,13 @@ function ut(t, c, h, S) {
1137
1122
  formOpts: e
1138
1123
  }
1139
1124
  );
1140
- const j = [...n, l], rt = o.getState().getNestedState(t, j);
1141
- return a(rt, j, m);
1125
+ const j = [...n, l], nt = o.getState().getNestedState(t, j);
1126
+ return a(nt, j, m);
1142
1127
  }
1143
1128
  }, G = new Proxy(R, U);
1144
1129
  return I.set(L, {
1145
1130
  proxy: G,
1146
- stateVersion: b
1131
+ stateVersion: $
1147
1132
  }), G;
1148
1133
  }
1149
1134
  return a(
@@ -1162,14 +1147,14 @@ function Jt({
1162
1147
  h,
1163
1148
  t._path
1164
1149
  ).stateMapNoRender(
1165
- (I, b, w, p, a) => t._mapFn(I, b, w, p, a)
1150
+ (I, $, w, p, a) => t._mapFn(I, $, w, p, a)
1166
1151
  ) : null;
1167
1152
  }
1168
1153
  function Yt({
1169
1154
  proxy: t
1170
1155
  }) {
1171
1156
  const c = X(null), h = `${t._stateKey}-${t._path.join(".")}`;
1172
- return nt(() => {
1157
+ return ot(() => {
1173
1158
  const S = c.current;
1174
1159
  if (!S || !S.parentElement) return;
1175
1160
  const I = S.parentElement, w = Array.from(I.childNodes).indexOf(S);
@@ -1225,8 +1210,8 @@ function Zt({
1225
1210
  itemPath: h,
1226
1211
  children: S
1227
1212
  }) {
1228
- const [, I] = Z({}), [b, w] = Dt(), p = X(null);
1229
- return nt(() => {
1213
+ const [, I] = Z({}), [$, w] = Dt(), p = X(null);
1214
+ return ot(() => {
1230
1215
  w.height > 0 && w.height !== p.current && (p.current = w.height, o.getState().setShadowMetadata(t, h, {
1231
1216
  virtualizer: {
1232
1217
  itemHeight: w.height
@@ -1243,7 +1228,7 @@ function Zt({
1243
1228
  const n = o.getState().stateComponents.get(t);
1244
1229
  n && n.components.delete(a);
1245
1230
  };
1246
- }, [t, c, h.join(".")]), /* @__PURE__ */ ht("div", { ref: b, children: S });
1231
+ }, [t, c, h.join(".")]), /* @__PURE__ */ ht("div", { ref: $, children: S });
1247
1232
  }
1248
1233
  export {
1249
1234
  bt as $cogsSignal,