cogsbox-state 0.5.263 → 0.5.265

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,13 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as me } from "react/jsx-runtime";
3
- import { useState as K, useRef as Z, useEffect as ne, useLayoutEffect as de, useMemo as Ee, createElement as ae, useSyncExternalStore as xe, startTransition as Ve, useCallback as ye } from "react";
4
- import { transformStateFunc as ke, isDeepEqual as L, isFunction as z, getNestedValue as B, getDifferences as ue, debounce as Ne } from "./utility.js";
3
+ import { useState as K, useRef as Z, useEffect as ne, useLayoutEffect as de, useMemo as Te, createElement as ae, useSyncExternalStore as xe, startTransition as Ve, useCallback as ye } from "react";
4
+ import { transformStateFunc as ke, isDeepEqual as L, isFunction as z, getNestedValue as H, getDifferences as ue, debounce as Ne } from "./utility.js";
5
5
  import { pushFunc as le, updateFn as Q, cutFunc as te, ValidationWrapper as be, FormControlComponent as Ce } from "./Functions.jsx";
6
6
  import Pe from "superjson";
7
7
  import { v4 as ge } from "uuid";
8
8
  import "zod";
9
9
  import { getGlobalStore as r, formRefStore as ve } from "./store.js";
10
- import { useCogsConfig as Te } from "./CogsStateClient.jsx";
10
+ import { useCogsConfig as Ee } from "./CogsStateClient.jsx";
11
11
  import { applyPatch as _e } from "fast-json-patch";
12
12
  function he(e, s) {
13
13
  const h = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, y = h(e) || {};
@@ -51,7 +51,7 @@ const et = (e, s) => {
51
51
  options: i,
52
52
  initialOptionsPart: y
53
53
  });
54
- const o = r.getState().cogsStateStore[p] || g[p], S = i?.modifyState ? i.modifyState(o) : o, [D, O] = De(
54
+ const o = r.getState().cogsStateStore[p] || g[p], S = i?.modifyState ? i.modifyState(o) : o, [W, R] = De(
55
55
  S,
56
56
  {
57
57
  stateKey: p,
@@ -67,7 +67,7 @@ const et = (e, s) => {
67
67
  serverState: i?.serverState
68
68
  }
69
69
  );
70
- return O;
70
+ return R;
71
71
  };
72
72
  function T(p, i) {
73
73
  Ie({ stateKey: p, options: i, initialOptionsPart: y }), i.localStorage && Fe(p, i), se(p);
@@ -82,7 +82,7 @@ const et = (e, s) => {
82
82
  setStateLog: Oe,
83
83
  updateInitialStateGlobal: fe,
84
84
  addValidationError: Re,
85
- removeValidationError: q,
85
+ removeValidationError: B,
86
86
  setServerSyncActions: je
87
87
  } = r.getState(), pe = (e, s, h, g, y) => {
88
88
  h?.log && console.log(
@@ -118,7 +118,7 @@ const et = (e, s) => {
118
118
  return console.error("Error loading from localStorage:", s), null;
119
119
  }
120
120
  }, Fe = (e, s) => {
121
- const h = r.getState().cogsStateStore[e], { sessionId: g } = Te(), y = z(s?.localStorage?.key) ? s.localStorage.key(h) : s?.localStorage?.key;
121
+ const h = r.getState().cogsStateStore[e], { sessionId: g } = Ee(), y = z(s?.localStorage?.key) ? s.localStorage.key(h) : s?.localStorage?.key;
122
122
  if (y && g) {
123
123
  const A = ie(
124
124
  `${g}-${e}-${y}`
@@ -160,18 +160,18 @@ const et = (e, s) => {
160
160
  switch (e) {
161
161
  case "update":
162
162
  return {
163
- oldValue: B(s, g),
164
- newValue: B(h, g)
163
+ oldValue: H(s, g),
164
+ newValue: H(h, g)
165
165
  };
166
166
  case "insert":
167
167
  return {
168
168
  oldValue: null,
169
169
  // or undefined
170
- newValue: B(h, g)
170
+ newValue: H(h, g)
171
171
  };
172
172
  case "cut":
173
173
  return {
174
- oldValue: B(s, g),
174
+ oldValue: H(s, g),
175
175
  newValue: null
176
176
  // or undefined
177
177
  };
@@ -192,12 +192,12 @@ function De(e, {
192
192
  dependencies: o,
193
193
  serverState: S
194
194
  } = {}) {
195
- const [D, O] = K({}), { sessionId: R } = Te();
196
- let W = !s;
197
- const [m] = K(s ?? ge()), l = r.getState().stateLog[m], ee = Z(/* @__PURE__ */ new Set()), H = Z(p ?? ge()), P = Z(
195
+ const [W, R] = K({}), { sessionId: j } = Ee();
196
+ let G = !s;
197
+ const [m] = K(s ?? ge()), l = r.getState().stateLog[m], ee = Z(/* @__PURE__ */ new Set()), q = Z(p ?? ge()), M = Z(
198
198
  null
199
199
  );
200
- P.current = Y(m) ?? null, ne(() => {
200
+ M.current = Y(m) ?? null, ne(() => {
201
201
  if (v && v.stateKey === m && v.path?.[0]) {
202
202
  J(m, (n) => ({
203
203
  ...n,
@@ -214,22 +214,22 @@ function De(e, {
214
214
  he(m, {
215
215
  initialState: i
216
216
  });
217
- const t = P.current, a = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[m];
217
+ const t = M.current, a = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[m];
218
218
  if (!(c && !L(c, i) || !c) && !a)
219
219
  return;
220
220
  let d = null;
221
221
  const V = z(t?.localStorage?.key) ? t?.localStorage?.key(i) : t?.localStorage?.key;
222
- V && R && (d = ie(`${R}-${m}-${V}`));
222
+ V && j && (d = ie(`${j}-${m}-${V}`));
223
223
  let w = i, $ = !1;
224
- const x = a ? Date.now() : 0, N = d?.lastUpdated || 0, _ = d?.lastSyncedWithServer || 0;
225
- a && x > N ? (w = t.serverState.data, $ = !0) : d && N > _ && (w = d.state, t?.localStorage?.onChange && t?.localStorage?.onChange(w)), Ae(
224
+ const x = a ? Date.now() : 0, N = d?.lastUpdated || 0, O = d?.lastSyncedWithServer || 0;
225
+ a && x > N ? (w = t.serverState.data, $ = !0) : d && N > O && (w = d.state, t?.localStorage?.onChange && t?.localStorage?.onChange(w)), Ae(
226
226
  m,
227
227
  i,
228
228
  w,
229
229
  X,
230
- H.current,
231
- R
232
- ), $ && V && R && pe(w, m, t, R, Date.now()), se(m), (Array.isArray(T) ? T : [T || "component"]).includes("none") || O({});
230
+ q.current,
231
+ j
232
+ ), $ && V && j && pe(w, m, t, j, Date.now()), se(m), (Array.isArray(T) ? T : [T || "component"]).includes("none") || R({});
233
233
  }
234
234
  }, [
235
235
  i,
@@ -237,24 +237,24 @@ function De(e, {
237
237
  S?.data,
238
238
  ...o || []
239
239
  ]), de(() => {
240
- W && he(m, {
240
+ G && he(m, {
241
241
  serverSync: h,
242
242
  formElements: y,
243
243
  initialState: i,
244
244
  localStorage: g,
245
- middleware: P.current?.middleware
245
+ middleware: M.current?.middleware
246
246
  });
247
- const t = `${m}////${H.current}`, n = r.getState().stateComponents.get(m) || {
247
+ const t = `${m}////${q.current}`, n = r.getState().stateComponents.get(m) || {
248
248
  components: /* @__PURE__ */ new Map()
249
249
  };
250
250
  return n.components.set(t, {
251
- forceUpdate: () => O({}),
251
+ forceUpdate: () => R({}),
252
252
  paths: /* @__PURE__ */ new Set(),
253
253
  deps: [],
254
254
  depsFunction: A || void 0,
255
255
  reactiveType: T ?? ["component", "deps"]
256
- }), r.getState().stateComponents.set(m, n), O({}), () => {
257
- const a = `${m}////${H.current}`;
256
+ }), r.getState().stateComponents.set(m, n), R({}), () => {
257
+ const a = `${m}////${q.current}`;
258
258
  n && (n.components.delete(a), n.components.size === 0 && r.getState().stateComponents.delete(m));
259
259
  };
260
260
  }, []);
@@ -266,135 +266,135 @@ function De(e, {
266
266
  J(m, (f) => {
267
267
  const d = z(t) ? t(f) : t, V = `${m}-${n.join(".")}`;
268
268
  if (V) {
269
- let C = !1, I = r.getState().signalDomElements.get(V);
269
+ let _ = !1, I = r.getState().signalDomElements.get(V);
270
270
  if ((!I || I.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
271
- const k = n.slice(0, -1), b = B(d, k);
272
- if (Array.isArray(b)) {
273
- C = !0;
271
+ const k = n.slice(0, -1), C = H(d, k);
272
+ if (Array.isArray(C)) {
273
+ _ = !0;
274
274
  const E = `${m}-${k.join(".")}`;
275
275
  I = r.getState().signalDomElements.get(E);
276
276
  }
277
277
  }
278
278
  if (I) {
279
- const k = C ? B(d, n.slice(0, -1)) : B(d, n);
280
- I.forEach(({ parentId: b, position: E, effect: j }) => {
281
- const M = document.querySelector(
282
- `[data-parent-id="${b}"]`
279
+ const k = _ ? H(d, n.slice(0, -1)) : H(d, n);
280
+ I.forEach(({ parentId: C, position: E, effect: b }) => {
281
+ const P = document.querySelector(
282
+ `[data-parent-id="${C}"]`
283
283
  );
284
- if (M) {
285
- const G = Array.from(M.childNodes);
286
- if (G[E]) {
287
- const U = j ? new Function("state", `return (${j})(state)`)(k) : k;
288
- G[E].textContent = String(U);
284
+ if (P) {
285
+ const D = Array.from(P.childNodes);
286
+ if (D[E]) {
287
+ const F = b ? new Function("state", `return (${b})(state)`)(k) : k;
288
+ D[E].textContent = String(F);
289
289
  }
290
290
  }
291
291
  });
292
292
  }
293
293
  }
294
- a.updateType === "update" && (c || P.current?.validation?.key) && n && q(
295
- (c || P.current?.validation?.key) + "." + n.join(".")
294
+ a.updateType === "update" && (c || M.current?.validation?.key) && n && B(
295
+ (c || M.current?.validation?.key) + "." + n.join(".")
296
296
  );
297
297
  const w = n.slice(0, n.length - 1);
298
- a.updateType === "cut" && P.current?.validation?.key && q(
299
- P.current?.validation?.key + "." + w.join(".")
300
- ), a.updateType === "insert" && P.current?.validation?.key && Me(
301
- P.current?.validation?.key + "." + w.join(".")
298
+ a.updateType === "cut" && M.current?.validation?.key && B(
299
+ M.current?.validation?.key + "." + w.join(".")
300
+ ), a.updateType === "insert" && M.current?.validation?.key && Me(
301
+ M.current?.validation?.key + "." + w.join(".")
302
302
  ).filter(([I, k]) => {
303
- let b = I?.split(".").length;
304
- if (I == w.join(".") && b == w.length - 1) {
303
+ let C = I?.split(".").length;
304
+ if (I == w.join(".") && C == w.length - 1) {
305
305
  let E = I + "." + w;
306
- q(I), Re(E, k);
306
+ B(I), Re(E, k);
307
307
  }
308
308
  });
309
309
  const $ = r.getState().stateComponents.get(m);
310
310
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", $), $) {
311
- const C = ue(f, d), I = new Set(C), k = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
311
+ const _ = ue(f, d), I = new Set(_), k = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
312
312
  for (const [
313
- b,
313
+ C,
314
314
  E
315
315
  ] of $.components.entries()) {
316
- let j = !1;
317
- const M = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
318
- if (console.log("component", E), !M.includes("none")) {
319
- if (M.includes("all")) {
316
+ let b = !1;
317
+ const P = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
318
+ if (console.log("component", E), !P.includes("none")) {
319
+ if (P.includes("all")) {
320
320
  E.forceUpdate();
321
321
  continue;
322
322
  }
323
- if (M.includes("component") && ((E.paths.has(k) || E.paths.has("")) && (j = !0), !j))
324
- for (const G of I) {
325
- let U = G;
323
+ if (P.includes("component") && ((E.paths.has(k) || E.paths.has("")) && (b = !0), !b))
324
+ for (const D of I) {
325
+ let F = D;
326
326
  for (; ; ) {
327
- if (E.paths.has(U)) {
328
- j = !0;
327
+ if (E.paths.has(F)) {
328
+ b = !0;
329
329
  break;
330
330
  }
331
- const ce = U.lastIndexOf(".");
331
+ const ce = F.lastIndexOf(".");
332
332
  if (ce !== -1) {
333
- const Se = U.substring(
333
+ const Se = F.substring(
334
334
  0,
335
335
  ce
336
336
  );
337
337
  if (!isNaN(
338
- Number(U.substring(ce + 1))
338
+ Number(F.substring(ce + 1))
339
339
  ) && E.paths.has(Se)) {
340
- j = !0;
340
+ b = !0;
341
341
  break;
342
342
  }
343
- U = Se;
343
+ F = Se;
344
344
  } else
345
- U = "";
346
- if (U === "")
345
+ F = "";
346
+ if (F === "")
347
347
  break;
348
348
  }
349
- if (j) break;
349
+ if (b) break;
350
350
  }
351
- if (!j && M.includes("deps") && E.depsFunction) {
352
- const G = E.depsFunction(d);
353
- let U = !1;
354
- typeof G == "boolean" ? G && (U = !0) : L(E.deps, G) || (E.deps = G, U = !0), U && (j = !0);
351
+ if (!b && P.includes("deps") && E.depsFunction) {
352
+ const D = E.depsFunction(d);
353
+ let F = !1;
354
+ typeof D == "boolean" ? D && (F = !0) : L(E.deps, D) || (E.deps = D, F = !0), F && (b = !0);
355
355
  }
356
- j && E.forceUpdate();
356
+ b && E.forceUpdate();
357
357
  }
358
358
  }
359
359
  }
360
360
  const x = Date.now();
361
- n = n.map((C, I) => {
362
- const k = n.slice(0, -1), b = B(d, k);
363
- return I === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (b.length - 1).toString() : C;
361
+ n = n.map((_, I) => {
362
+ const k = n.slice(0, -1), C = H(d, k);
363
+ return I === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (C.length - 1).toString() : _;
364
364
  });
365
- const { oldValue: N, newValue: _ } = Ue(
365
+ const { oldValue: N, newValue: O } = Ue(
366
366
  a.updateType,
367
367
  f,
368
368
  d,
369
369
  n
370
- ), F = {
370
+ ), U = {
371
371
  timeStamp: x,
372
372
  stateKey: m,
373
373
  path: n,
374
374
  updateType: a.updateType,
375
375
  status: "new",
376
376
  oldValue: N,
377
- newValue: _
377
+ newValue: O
378
378
  };
379
- if (Oe(m, (C) => {
380
- const k = [...C ?? [], F].reduce((b, E) => {
381
- const j = `${E.stateKey}:${JSON.stringify(E.path)}`, M = b.get(j);
382
- return M ? (M.timeStamp = Math.max(M.timeStamp, E.timeStamp), M.newValue = E.newValue, M.oldValue = M.oldValue ?? E.oldValue, M.updateType = E.updateType) : b.set(j, { ...E }), b;
379
+ if (Oe(m, (_) => {
380
+ const k = [..._ ?? [], U].reduce((C, E) => {
381
+ const b = `${E.stateKey}:${JSON.stringify(E.path)}`, P = C.get(b);
382
+ return P ? (P.timeStamp = Math.max(P.timeStamp, E.timeStamp), P.newValue = E.newValue, P.oldValue = P.oldValue ?? E.oldValue, P.updateType = E.updateType) : C.set(b, { ...E }), C;
383
383
  }, /* @__PURE__ */ new Map());
384
384
  return Array.from(k.values());
385
385
  }), pe(
386
386
  d,
387
387
  m,
388
- P.current,
389
- R
390
- ), P.current?.middleware && P.current.middleware({
388
+ M.current,
389
+ j
390
+ ), M.current?.middleware && M.current.middleware({
391
391
  updateLog: l,
392
- update: F
393
- }), P.current?.serverSync) {
394
- const C = r.getState().serverState[m], I = P.current?.serverSync;
392
+ update: U
393
+ }), M.current?.serverSync) {
394
+ const _ = r.getState().serverState[m], I = M.current?.serverSync;
395
395
  je(m, {
396
396
  syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: d }),
397
- rollBackState: C,
397
+ rollBackState: _,
398
398
  actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
399
399
  status: "waiting"
400
400
  });
@@ -407,16 +407,16 @@ function De(e, {
407
407
  oe(
408
408
  m,
409
409
  X,
410
- H.current,
411
- R
410
+ q.current,
411
+ j
412
412
  )
413
413
  ), r.getState().cogsStateStore[m] || J(m, e), r.getState().initialStateGlobal[m] || fe(m, e));
414
- const u = Ee(() => oe(
414
+ const u = Te(() => oe(
415
415
  m,
416
416
  X,
417
- H.current,
418
- R
419
- ), [m, R]);
417
+ q.current,
418
+ j
419
+ ), [m, j]);
420
420
  return [$e(m), u];
421
421
  }
422
422
  function oe(e, s, h, g) {
@@ -429,15 +429,15 @@ function oe(e, s, h, g) {
429
429
  A++;
430
430
  }, p = {
431
431
  removeValidation: (v) => {
432
- v?.validationKey && q(v.validationKey);
432
+ v?.validationKey && B(v.validationKey);
433
433
  },
434
434
  revertToInitialState: (v) => {
435
435
  const o = r.getState().getInitialOptions(e)?.validation;
436
- o?.key && q(o?.key), v?.validationKey && q(v.validationKey);
436
+ o?.key && B(o?.key), v?.validationKey && B(v.validationKey);
437
437
  const S = r.getState().initialStateGlobal[e];
438
438
  r.getState().clearSelectedIndexesForState(e), y.clear(), A++;
439
- const D = i(S, []), O = Y(e), R = z(O?.localStorage?.key) ? O?.localStorage?.key(S) : O?.localStorage?.key, W = `${g}-${e}-${R}`;
440
- W && localStorage.removeItem(W), re(e, D), J(e, S);
439
+ const W = i(S, []), R = Y(e), j = z(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, G = `${g}-${e}-${j}`;
440
+ G && localStorage.removeItem(G), re(e, W), J(e, S);
441
441
  const m = r.getState().stateComponents.get(e);
442
442
  return m && m.components.forEach((l) => {
443
443
  l.forceUpdate();
@@ -450,15 +450,15 @@ function oe(e, s, h, g) {
450
450
  s,
451
451
  h,
452
452
  g
453
- ), S = r.getState().initialStateGlobal[e], D = Y(e), O = z(D?.localStorage?.key) ? D?.localStorage?.key(S) : D?.localStorage?.key, R = `${g}-${e}-${O}`;
454
- return localStorage.getItem(R) && localStorage.removeItem(R), Ve(() => {
453
+ ), S = r.getState().initialStateGlobal[e], W = Y(e), R = z(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, j = `${g}-${e}-${R}`;
454
+ return localStorage.getItem(j) && localStorage.removeItem(j), Ve(() => {
455
455
  fe(e, v), re(e, o), J(e, v);
456
- const W = r.getState().stateComponents.get(e);
457
- W && W.components.forEach((m) => {
456
+ const G = r.getState().stateComponents.get(e);
457
+ G && G.components.forEach((m) => {
458
458
  m.forceUpdate();
459
459
  });
460
460
  }), {
461
- fetchId: (W) => o.get()[W]
461
+ fetchId: (G) => o.get()[G]
462
462
  };
463
463
  },
464
464
  _initialState: r.getState().initialStateGlobal[e],
@@ -470,15 +470,15 @@ function oe(e, s, h, g) {
470
470
  }
471
471
  };
472
472
  function i(v, o = [], S) {
473
- const D = o.map(String).join(".");
474
- y.get(D);
475
- const O = function() {
473
+ const W = o.map(String).join(".");
474
+ y.get(W);
475
+ const R = function() {
476
476
  return r().getNestedState(e, o);
477
477
  };
478
478
  Object.keys(p).forEach((m) => {
479
- O[m] = p[m];
479
+ R[m] = p[m];
480
480
  });
481
- const R = {
481
+ const j = {
482
482
  apply(m, l, ee) {
483
483
  return console.log(
484
484
  `PROXY APPLY TRAP HIT: stateKey=${e}, path=${o.join(".")}`
@@ -554,7 +554,7 @@ function oe(e, s, h, g) {
554
554
  }
555
555
  };
556
556
  if (l === "_status") {
557
- const u = r.getState().getNestedState(e, o), t = r.getState().initialStateGlobal[e], n = B(t, o);
557
+ const u = r.getState().getNestedState(e, o), t = r.getState().initialStateGlobal[e], n = H(t, o);
558
558
  return L(u, n) ? "fresh" : "stale";
559
559
  }
560
560
  if (l === "getStatus")
@@ -562,7 +562,7 @@ function oe(e, s, h, g) {
562
562
  const u = r().getNestedState(
563
563
  e,
564
564
  o
565
- ), t = r.getState().initialStateGlobal[e], n = B(t, o);
565
+ ), t = r.getState().initialStateGlobal[e], n = H(t, o);
566
566
  return L(u, n) ? "fresh" : "stale";
567
567
  };
568
568
  if (l === "removeStorage")
@@ -618,11 +618,11 @@ function oe(e, s, h, g) {
618
618
  }), w = Z(!0), $ = r().getNestedState(
619
619
  e,
620
620
  o
621
- ), x = $.length, N = Ee(() => {
621
+ ), x = $.length, N = Te(() => {
622
622
  const I = Array.from(
623
623
  { length: d.endIndex - d.startIndex },
624
- (b, E) => d.startIndex + E
625
- ).filter((b) => b < x), k = I.map((b) => $[b]);
624
+ (C, E) => d.startIndex + E
625
+ ).filter((C) => C < x), k = I.map((C) => $[C]);
626
626
  return i(k, o, {
627
627
  ...S,
628
628
  validIndices: I
@@ -631,46 +631,53 @@ function oe(e, s, h, g) {
631
631
  de(() => {
632
632
  const I = f.current;
633
633
  if (!I) return;
634
- const k = () => {
635
- const { scrollTop: E, clientHeight: j } = I, M = Math.max(
634
+ let k;
635
+ const C = () => {
636
+ const { scrollTop: b, clientHeight: P } = I, D = Math.max(
636
637
  0,
637
- Math.floor(E / n) - a
638
- ), G = Math.min(
638
+ Math.floor(b / n) - a
639
+ ), F = Math.min(
639
640
  x,
640
- Math.ceil((E + j) / n) + a
641
+ Math.ceil((b + P) / n) + a
641
642
  );
642
- V({ startIndex: M, endIndex: G });
643
- }, b = () => {
644
- k();
643
+ V({ startIndex: D, endIndex: F });
644
+ }, E = () => {
645
+ const { scrollTop: b, scrollHeight: P, clientHeight: D } = I;
646
+ w.current = P - b - D < 5, clearTimeout(k), k = setTimeout(C, 10);
645
647
  };
646
- if (I.addEventListener("scroll", b, {
648
+ if (I.addEventListener("scroll", E, {
647
649
  passive: !0
648
- }), w.current && c && x > 0) {
649
- w.current = !1;
650
- const E = Math.max(
650
+ }), c && x > 0) {
651
+ const b = Math.max(
651
652
  0,
652
653
  x - Math.ceil(I.clientHeight / n) - a
653
654
  );
654
- V({ startIndex: E, endIndex: x }), setTimeout(() => {
655
- I.scrollTop = I.scrollHeight;
656
- }, 0);
655
+ V({ startIndex: b, endIndex: x }), requestAnimationFrame(() => {
656
+ I.scrollTop = I.scrollHeight, w.current = !0;
657
+ });
657
658
  } else
658
- k();
659
+ C();
659
660
  return () => {
660
- I.removeEventListener("scroll", b);
661
+ clearTimeout(k), I.removeEventListener("scroll", E);
661
662
  };
662
- }, [x, n, a]), ne(() => {
663
- if (c && f.current && !w.current) {
663
+ }, [x, n, a, c]), ne(() => {
664
+ if (c && f.current && w.current) {
664
665
  const I = f.current;
665
- I.scrollHeight - I.scrollTop - I.clientHeight < 100 && (I.scrollTop = I.scrollHeight);
666
+ I.scrollTo({
667
+ top: I.scrollHeight,
668
+ behavior: "smooth"
669
+ });
666
670
  }
667
- }, [x]);
668
- const _ = ye(
671
+ }, [x, c]);
672
+ const O = ye(
669
673
  (I = "smooth") => {
670
- f.current && (f.current.scrollTop = f.current.scrollHeight);
674
+ f.current && f.current.scrollTo({
675
+ top: f.current.scrollHeight,
676
+ behavior: I
677
+ });
671
678
  },
672
679
  []
673
- ), F = ye(
680
+ ), U = ye(
674
681
  (I, k = "smooth") => {
675
682
  f.current && f.current.scrollTo({
676
683
  top: I * n,
@@ -678,7 +685,7 @@ function oe(e, s, h, g) {
678
685
  });
679
686
  },
680
687
  [n]
681
- ), C = {
688
+ ), _ = {
682
689
  outer: {
683
690
  ref: f,
684
691
  style: {
@@ -701,9 +708,9 @@ function oe(e, s, h, g) {
701
708
  };
702
709
  return {
703
710
  virtualState: N,
704
- virtualizerProps: C,
705
- scrollToBottom: _,
706
- scrollToIndex: F
711
+ virtualizerProps: _,
712
+ scrollToBottom: O,
713
+ scrollToIndex: U
707
714
  };
708
715
  };
709
716
  if (l === "stateSort")
@@ -739,15 +746,15 @@ function oe(e, s, h, g) {
739
746
  register: () => {
740
747
  const [, x] = K({}), N = `${h}-${o.join(".")}-${c}`;
741
748
  de(() => {
742
- const _ = `${e}////${N}`, F = r.getState().stateComponents.get(e) || {
749
+ const O = `${e}////${N}`, U = r.getState().stateComponents.get(e) || {
743
750
  components: /* @__PURE__ */ new Map()
744
751
  };
745
- return F.components.set(_, {
752
+ return U.components.set(O, {
746
753
  forceUpdate: () => x({}),
747
754
  paths: /* @__PURE__ */ new Set([V.join(".")])
748
- }), r.getState().stateComponents.set(e, F), () => {
749
- const C = r.getState().stateComponents.get(e);
750
- C && C.components.delete(_);
755
+ }), r.getState().stateComponents.set(e, U), () => {
756
+ const _ = r.getState().stateComponents.get(e);
757
+ _ && _.components.delete(O);
751
758
  };
752
759
  }, [e, N]);
753
760
  },
@@ -871,15 +878,15 @@ function oe(e, s, h, g) {
871
878
  return i(c.item, f, S);
872
879
  };
873
880
  }
874
- const H = o[o.length - 1];
875
- if (!isNaN(Number(H))) {
881
+ const q = o[o.length - 1];
882
+ if (!isNaN(Number(q))) {
876
883
  const u = o.slice(0, -1), t = r.getState().getNestedState(e, u);
877
884
  if (Array.isArray(t) && l === "cut")
878
885
  return () => te(
879
886
  s,
880
887
  u,
881
888
  e,
882
- Number(H)
889
+ Number(q)
883
890
  );
884
891
  }
885
892
  if (l === "get")
@@ -961,20 +968,20 @@ function oe(e, s, h, g) {
961
968
  $ = !0;
962
969
  break;
963
970
  }
964
- let _ = N.lastIndexOf(".");
965
- for (; _ !== -1; ) {
966
- const F = N.substring(0, _);
967
- if (w.paths.has(F)) {
971
+ let O = N.lastIndexOf(".");
972
+ for (; O !== -1; ) {
973
+ const U = N.substring(0, O);
974
+ if (w.paths.has(U)) {
968
975
  $ = !0;
969
976
  break;
970
977
  }
971
- const C = N.substring(
972
- _ + 1
978
+ const _ = N.substring(
979
+ O + 1
973
980
  );
974
- if (!isNaN(Number(C))) {
975
- const I = F.lastIndexOf(".");
981
+ if (!isNaN(Number(_))) {
982
+ const I = U.lastIndexOf(".");
976
983
  if (I !== -1) {
977
- const k = F.substring(
984
+ const k = U.substring(
978
985
  0,
979
986
  I
980
987
  );
@@ -984,14 +991,14 @@ function oe(e, s, h, g) {
984
991
  }
985
992
  }
986
993
  }
987
- _ = F.lastIndexOf(".");
994
+ O = U.lastIndexOf(".");
988
995
  }
989
996
  if ($) break;
990
997
  }
991
998
  if (!$ && x.includes("deps") && w.depsFunction) {
992
999
  const N = w.depsFunction(a);
993
- let _ = !1;
994
- typeof N == "boolean" ? N && (_ = !0) : L(w.deps, N) || (w.deps = N, _ = !0), _ && ($ = !0);
1000
+ let O = !1;
1001
+ typeof N == "boolean" ? N && (O = !0) : L(w.deps, N) || (w.deps = N, O = !0), O && ($ = !0);
995
1002
  }
996
1003
  $ && w.forceUpdate();
997
1004
  }
@@ -1005,12 +1012,12 @@ function oe(e, s, h, g) {
1005
1012
  throw new Error("Zod schema not found");
1006
1013
  if (!u?.key)
1007
1014
  throw new Error("Validation key not found");
1008
- q(u.key);
1015
+ B(u.key);
1009
1016
  const n = r.getState().cogsStateStore[e];
1010
1017
  try {
1011
1018
  const a = r.getState().getValidationErrors(u.key);
1012
1019
  a && a.length > 0 && a.forEach(([f]) => {
1013
- f && f.startsWith(u.key) && q(f);
1020
+ f && f.startsWith(u.key) && B(f);
1014
1021
  });
1015
1022
  const c = u.zodSchema.safeParse(n);
1016
1023
  return c.success ? !0 : (c.error.errors.forEach((d) => {
@@ -1083,14 +1090,14 @@ function oe(e, s, h, g) {
1083
1090
  formOpts: t
1084
1091
  }
1085
1092
  );
1086
- const P = [...o, l], X = r.getState().getNestedState(e, P);
1087
- return i(X, P, S);
1093
+ const M = [...o, l], X = r.getState().getNestedState(e, M);
1094
+ return i(X, M, S);
1088
1095
  }
1089
- }, W = new Proxy(O, R);
1090
- return y.set(D, {
1091
- proxy: W,
1096
+ }, G = new Proxy(R, j);
1097
+ return y.set(W, {
1098
+ proxy: G,
1092
1099
  stateVersion: A
1093
- }), W;
1100
+ }), G;
1094
1101
  }
1095
1102
  return i(
1096
1103
  r.getState().getNestedState(e, [])
@@ -1136,14 +1143,14 @@ function Ge({
1136
1143
  "state",
1137
1144
  `return (${e._effect})(state)`
1138
1145
  )(o);
1139
- } catch (O) {
1140
- console.error("Error evaluating effect function during mount:", O), S = o;
1146
+ } catch (R) {
1147
+ console.error("Error evaluating effect function during mount:", R), S = o;
1141
1148
  }
1142
1149
  else
1143
1150
  S = o;
1144
1151
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1145
- const D = document.createTextNode(String(S));
1146
- g.replaceWith(D);
1152
+ const W = document.createTextNode(String(S));
1153
+ g.replaceWith(W);
1147
1154
  }, [e._stateKey, e._path.join("."), e._effect]), ae("span", {
1148
1155
  ref: s,
1149
1156
  style: { display: "none" },