cogsbox-state 0.5.407 → 0.5.409

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,23 +1,23 @@
1
1
  "use client";
2
- import { jsx as yt } from "react/jsx-runtime";
3
- import { useState as et, useRef as Q, useEffect as nt, useLayoutEffect as Tt, useMemo as It, createElement as ct, useSyncExternalStore as Mt, startTransition as jt, useCallback as At } from "react";
4
- import { transformStateFunc as Rt, isDeepEqual as J, isFunction as K, getNestedValue as Y, getDifferences as pt, debounce as Ot } from "./utility.js";
5
- import { pushFunc as vt, updateFn as it, cutFunc as gt, ValidationWrapper as Ut, FormControlComponent as Ft } from "./Functions.jsx";
6
- import Dt from "superjson";
7
- import { v4 as wt } from "uuid";
2
+ import { jsx as It } from "react/jsx-runtime";
3
+ import { useState as et, useRef as Q, useEffect as nt, useLayoutEffect as Et, useMemo as pt, createElement as ct, useSyncExternalStore as jt, startTransition as Rt, useCallback as kt } from "react";
4
+ import { transformStateFunc as Ot, isDeepEqual as q, isFunction as K, getNestedValue as J, getDifferences as wt, debounce as Ut } from "./utility.js";
5
+ import { pushFunc as yt, updateFn as it, cutFunc as gt, ValidationWrapper as Ft, FormControlComponent as Dt } from "./Functions.jsx";
6
+ import Wt from "superjson";
7
+ import { v4 as Tt } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as o, formRefStore as kt } from "./store.js";
10
- import { useCogsConfig as Nt } from "./CogsStateClient.jsx";
11
- import { applyPatch as Wt } from "fast-json-patch";
12
- import Lt from "react-use-measure";
13
- function $t(t, c) {
9
+ import { getGlobalStore as o, formRefStore as $t } from "./store.js";
10
+ import { useCogsConfig as Ct } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Lt } from "fast-json-patch";
12
+ import Bt from "react-use-measure";
13
+ function bt(t, c) {
14
14
  const S = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, y = S(t) || {};
15
15
  g(t, {
16
16
  ...y,
17
17
  ...c
18
18
  });
19
19
  }
20
- function bt({
20
+ function xt({
21
21
  stateKey: t,
22
22
  options: c,
23
23
  initialOptionsPart: S
@@ -27,7 +27,7 @@ function bt({
27
27
  if (c)
28
28
  for (const s in c)
29
29
  w.hasOwnProperty(s) ? (s == "localStorage" && c[s] && w[s].key !== c[s]?.key && (I = !0, w[s] = c[s]), s == "initialState" && c[s] && w[s] !== c[s] && // Different references
30
- !J(w[s], c[s]) && (I = !0, w[s] = c[s])) : (I = !0, w[s] = c[s]);
30
+ !q(w[s], c[s]) && (I = !0, w[s] = c[s])) : (I = !0, w[s] = c[s]);
31
31
  I && x(t, w);
32
32
  }
33
33
  function ue(t, { formElements: c, validation: S }) {
@@ -35,7 +35,7 @@ function ue(t, { formElements: c, validation: S }) {
35
35
  }
36
36
  const ge = (t, c) => {
37
37
  let S = t;
38
- const [g, y] = Rt(S);
38
+ const [g, y] = Ot(S);
39
39
  (Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((I) => {
40
40
  y[I] = y[I] || {}, y[I].formElements = {
41
41
  ...c?.formElements,
@@ -46,13 +46,13 @@ const ge = (t, c) => {
46
46
  }, at(I) || o.getState().setInitialStateOptions(I, y[I]);
47
47
  }), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
48
48
  const x = (I, s) => {
49
- const [h] = et(s?.componentId ?? wt());
50
- bt({
49
+ const [h] = et(s?.componentId ?? Tt());
50
+ xt({
51
51
  stateKey: I,
52
52
  options: s,
53
53
  initialOptionsPart: y
54
54
  });
55
- const r = o.getState().cogsStateStore[I] || g[I], f = s?.modifyState ? s.modifyState(r) : r, [G, O] = Jt(
55
+ const r = o.getState().cogsStateStore[I] || g[I], f = s?.modifyState ? s.modifyState(r) : r, [B, O] = Yt(
56
56
  f,
57
57
  {
58
58
  stateKey: I,
@@ -71,21 +71,21 @@ const ge = (t, c) => {
71
71
  return O;
72
72
  };
73
73
  function w(I, s) {
74
- bt({ stateKey: I, options: s, initialOptionsPart: y }), s.localStorage && zt(I, s), lt(I);
74
+ xt({ stateKey: I, options: s, initialOptionsPart: y }), s.localStorage && qt(I, s), lt(I);
75
75
  }
76
76
  return { useCogsState: x, setCogsOptions: w };
77
77
  }, {
78
78
  setUpdaterState: ft,
79
79
  setState: rt,
80
80
  getInitialOptions: at,
81
- getKeyState: Ct,
81
+ getKeyState: Pt,
82
82
  getValidationErrors: Gt,
83
- setStateLog: Bt,
84
- updateInitialStateGlobal: Et,
85
- addValidationError: Pt,
83
+ setStateLog: Ht,
84
+ updateInitialStateGlobal: At,
85
+ addValidationError: _t,
86
86
  removeValidationError: X,
87
- setServerSyncActions: Ht
88
- } = o.getState(), xt = (t, c, S, g, y) => {
87
+ setServerSyncActions: zt
88
+ } = o.getState(), Vt = (t, c, S, g, y) => {
89
89
  S?.log && console.log(
90
90
  "saving to localstorage",
91
91
  c,
@@ -104,7 +104,7 @@ const ge = (t, c) => {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: y ?? I
107
- }, h = Dt.serialize(s);
107
+ }, h = Wt.serialize(s);
108
108
  window.localStorage.setItem(
109
109
  w,
110
110
  JSON.stringify(h.json)
@@ -118,8 +118,8 @@ const ge = (t, c) => {
118
118
  } catch (c) {
119
119
  return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
- }, zt = (t, c) => {
122
- const S = o.getState().cogsStateStore[t], { sessionId: g } = Nt(), y = K(c?.localStorage?.key) ? c.localStorage.key(S) : c?.localStorage?.key;
121
+ }, qt = (t, c) => {
122
+ const S = o.getState().cogsStateStore[t], { sessionId: g } = Ct(), y = K(c?.localStorage?.key) ? c.localStorage.key(S) : c?.localStorage?.key;
123
123
  if (y && g) {
124
124
  const x = mt(
125
125
  `${g}-${t}-${y}`
@@ -128,7 +128,7 @@ const ge = (t, c) => {
128
128
  return rt(t, x.state), lt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, _t = (t, c, S, g, y, x) => {
131
+ }, Mt = (t, c, S, g, y, x) => {
132
132
  const w = {
133
133
  initialState: c,
134
134
  updaterState: St(
@@ -139,7 +139,7 @@ const ge = (t, c) => {
139
139
  ),
140
140
  state: S
141
141
  };
142
- Et(t, w.initialState), ft(t, w.updaterState), rt(t, w.state);
142
+ At(t, w.initialState), ft(t, w.updaterState), rt(t, w.state);
143
143
  }, lt = (t) => {
144
144
  const c = o.getState().stateComponents.get(t);
145
145
  if (!c) return;
@@ -157,22 +157,22 @@ const ge = (t, c) => {
157
157
  return;
158
158
  y && y.forceUpdate();
159
159
  }
160
- }, qt = (t, c, S, g) => {
160
+ }, Jt = (t, c, S, g) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: Y(c, g),
165
- newValue: Y(S, g)
164
+ oldValue: J(c, g),
165
+ newValue: J(S, g)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: Y(S, g)
171
+ newValue: J(S, g)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: Y(c, g),
175
+ oldValue: J(c, g),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -180,7 +180,7 @@ const ge = (t, c) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Jt(t, {
183
+ function Yt(t, {
184
184
  stateKey: c,
185
185
  serverSync: S,
186
186
  localStorage: g,
@@ -193,9 +193,9 @@ function Jt(t, {
193
193
  dependencies: r,
194
194
  serverState: f
195
195
  } = {}) {
196
- const [G, O] = et({}), { sessionId: U } = Nt();
197
- let B = !c;
198
- const [m] = et(c ?? wt()), l = o.getState().stateLog[m], dt = Q(/* @__PURE__ */ new Set()), tt = Q(I ?? wt()), j = Q(
196
+ const [B, O] = et({}), { sessionId: U } = Ct();
197
+ let G = !c;
198
+ const [m] = et(c ?? Tt()), l = o.getState().stateLog[m], dt = Q(/* @__PURE__ */ new Set()), tt = Q(I ?? Tt()), j = Q(
199
199
  null
200
200
  );
201
201
  j.current = at(m) ?? null, nt(() => {
@@ -212,33 +212,33 @@ function Jt(t, {
212
212
  }
213
213
  }, [h]), nt(() => {
214
214
  if (s) {
215
- $t(m, {
215
+ bt(m, {
216
216
  initialState: s
217
217
  });
218
218
  const e = j.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[m];
219
- if (!(i && !J(i, s) || !i) && !a)
219
+ if (!(i && !q(i, s) || !i) && !a)
220
220
  return;
221
221
  let u = null;
222
222
  const p = K(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
223
223
  p && U && (u = mt(`${U}-${m}-${p}`));
224
224
  let T = s, A = !1;
225
225
  const _ = a ? Date.now() : 0, k = u?.lastUpdated || 0, M = u?.lastSyncedWithServer || 0;
226
- a && _ > k ? (T = e.serverState.data, A = !0) : u && k > M && (T = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(m, s), _t(
226
+ a && _ > k ? (T = e.serverState.data, A = !0) : u && k > M && (T = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(m, s), Mt(
227
227
  m,
228
228
  s,
229
229
  T,
230
230
  st,
231
231
  tt.current,
232
232
  U
233
- ), A && p && U && xt(T, m, e, U, Date.now()), lt(m), (Array.isArray(w) ? w : [w || "component"]).includes("none") || O({});
233
+ ), A && p && U && Vt(T, m, e, U, Date.now()), lt(m), (Array.isArray(w) ? w : [w || "component"]).includes("none") || O({});
234
234
  }
235
235
  }, [
236
236
  s,
237
237
  f?.status,
238
238
  f?.data,
239
239
  ...r || []
240
- ]), Tt(() => {
241
- B && $t(m, {
240
+ ]), Et(() => {
241
+ G && bt(m, {
242
242
  serverSync: S,
243
243
  formElements: y,
244
244
  initialState: s,
@@ -269,7 +269,7 @@ function Jt(t, {
269
269
  if (T) {
270
270
  let b = !1, N = v.signalDomElements.get(T);
271
271
  if ((!N || N.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
- const C = n.slice(0, -1), W = Y(p, C);
272
+ const C = n.slice(0, -1), W = J(p, C);
273
273
  if (Array.isArray(W)) {
274
274
  b = !0;
275
275
  const E = `${m}-${C.join(".")}`;
@@ -277,7 +277,7 @@ function Jt(t, {
277
277
  }
278
278
  }
279
279
  if (N) {
280
- const C = b ? Y(p, n.slice(0, -1)) : Y(p, n);
280
+ const C = b ? J(p, n.slice(0, -1)) : J(p, n);
281
281
  N.forEach(({ parentId: W, position: E, effect: F }) => {
282
282
  const R = document.querySelector(
283
283
  `[data-parent-id="${W}"]`
@@ -304,12 +304,12 @@ function Jt(t, {
304
304
  let W = N?.split(".").length;
305
305
  if (N == A.join(".") && W == A.length - 1) {
306
306
  let E = N + "." + A;
307
- X(N), Pt(E, C);
307
+ X(N), _t(E, C);
308
308
  }
309
309
  });
310
310
  const _ = v.stateComponents.get(m);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
312
- const b = pt(u, p), N = new Set(b), C = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
312
+ const b = wt(u, p), N = new Set(b), C = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
313
313
  for (const [
314
314
  W,
315
315
  E
@@ -352,7 +352,7 @@ function Jt(t, {
352
352
  if (!F && R.includes("deps") && E.depsFunction) {
353
353
  const V = E.depsFunction(p);
354
354
  let $ = !1;
355
- typeof V == "boolean" ? V && ($ = !0) : J(E.deps, V) || (E.deps = V, $ = !0), $ && (F = !0);
355
+ typeof V == "boolean" ? V && ($ = !0) : q(E.deps, V) || (E.deps = V, $ = !0), $ && (F = !0);
356
356
  }
357
357
  F && E.forceUpdate();
358
358
  }
@@ -360,10 +360,10 @@ function Jt(t, {
360
360
  }
361
361
  const k = Date.now();
362
362
  n = n.map((b, N) => {
363
- const C = n.slice(0, -1), W = Y(p, C);
363
+ const C = n.slice(0, -1), W = J(p, C);
364
364
  return N === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (W.length - 1).toString() : b;
365
365
  });
366
- const { oldValue: M, newValue: P } = qt(
366
+ const { oldValue: M, newValue: P } = Jt(
367
367
  a.updateType,
368
368
  u,
369
369
  p,
@@ -390,13 +390,13 @@ function Jt(t, {
390
390
  v.removeShadowArrayElement(m, N, C);
391
391
  break;
392
392
  }
393
- if (Bt(m, (b) => {
393
+ if (Ht(m, (b) => {
394
394
  const C = [...b ?? [], H].reduce((W, E) => {
395
395
  const F = `${E.stateKey}:${JSON.stringify(E.path)}`, R = W.get(F);
396
396
  return R ? (R.timeStamp = Math.max(R.timeStamp, E.timeStamp), R.newValue = E.newValue, R.oldValue = R.oldValue ?? E.oldValue, R.updateType = E.updateType) : W.set(F, { ...E }), W;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(C.values());
399
- }), xt(
399
+ }), Vt(
400
400
  p,
401
401
  m,
402
402
  j.current,
@@ -406,7 +406,7 @@ function Jt(t, {
406
406
  update: H
407
407
  }), j.current?.serverSync) {
408
408
  const b = v.serverState[m], N = j.current?.serverSync;
409
- Ht(m, {
409
+ zt(m, {
410
410
  syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: p }),
411
411
  rollBackState: b,
412
412
  actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
@@ -424,14 +424,14 @@ function Jt(t, {
424
424
  tt.current,
425
425
  U
426
426
  )
427
- ), o.getState().cogsStateStore[m] || rt(m, t), o.getState().initialStateGlobal[m] || Et(m, t));
428
- const d = It(() => St(
427
+ ), o.getState().cogsStateStore[m] || rt(m, t), o.getState().initialStateGlobal[m] || At(m, t));
428
+ const d = pt(() => St(
429
429
  m,
430
430
  st,
431
431
  tt.current,
432
432
  U
433
433
  ), [m, U]);
434
- return [Ct(m), d];
434
+ return [Pt(m), d];
435
435
  }
436
436
  function St(t, c, S, g) {
437
437
  const y = /* @__PURE__ */ new Map();
@@ -450,8 +450,8 @@ function St(t, c, S, g) {
450
450
  r?.key && X(r?.key), h?.validationKey && X(h.validationKey);
451
451
  const f = o.getState().initialStateGlobal[t];
452
452
  o.getState().clearSelectedIndexesForState(t), y.clear(), x++;
453
- const G = s(f, []), O = at(t), U = K(O?.localStorage?.key) ? O?.localStorage?.key(f) : O?.localStorage?.key, B = `${g}-${t}-${U}`;
454
- B && localStorage.removeItem(B), ft(t, G), rt(t, f);
453
+ const B = s(f, []), O = at(t), U = K(O?.localStorage?.key) ? O?.localStorage?.key(f) : O?.localStorage?.key, G = `${g}-${t}-${U}`;
454
+ G && localStorage.removeItem(G), ft(t, B), rt(t, f);
455
455
  const m = o.getState().stateComponents.get(t);
456
456
  return m && m.components.forEach((l) => {
457
457
  l.forceUpdate();
@@ -464,15 +464,15 @@ function St(t, c, S, g) {
464
464
  c,
465
465
  S,
466
466
  g
467
- ), f = o.getState().initialStateGlobal[t], G = at(t), O = K(G?.localStorage?.key) ? G?.localStorage?.key(f) : G?.localStorage?.key, U = `${g}-${t}-${O}`;
468
- return localStorage.getItem(U) && localStorage.removeItem(U), jt(() => {
469
- Et(t, h), o.getState().initializeShadowState(t, h), ft(t, r), rt(t, h);
470
- const B = o.getState().stateComponents.get(t);
471
- B && B.components.forEach((m) => {
467
+ ), f = o.getState().initialStateGlobal[t], B = at(t), O = K(B?.localStorage?.key) ? B?.localStorage?.key(f) : B?.localStorage?.key, U = `${g}-${t}-${O}`;
468
+ return localStorage.getItem(U) && localStorage.removeItem(U), Rt(() => {
469
+ At(t, h), o.getState().initializeShadowState(t, h), ft(t, r), rt(t, h);
470
+ const G = o.getState().stateComponents.get(t);
471
+ G && G.components.forEach((m) => {
472
472
  m.forceUpdate();
473
473
  });
474
474
  }), {
475
- fetchId: (B) => r.get()[B]
475
+ fetchId: (G) => r.get()[G]
476
476
  };
477
477
  },
478
478
  _initialState: o.getState().initialStateGlobal[t],
@@ -480,12 +480,12 @@ function St(t, c, S, g) {
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
482
  const h = o.getState().serverState[t];
483
- return !!(h && J(h, Ct(t)));
483
+ return !!(h && q(h, Pt(t)));
484
484
  }
485
485
  };
486
486
  function s(h, r = [], f) {
487
- const G = r.map(String).join(".");
488
- y.get(G);
487
+ const B = r.map(String).join(".");
488
+ y.get(B);
489
489
  const O = function() {
490
490
  return o().getNestedState(t, r);
491
491
  };
@@ -540,7 +540,7 @@ function St(t, c, S, g) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => pt(
543
+ return () => wt(
544
544
  o.getState().cogsStateStore[t],
545
545
  o.getState().initialStateGlobal[t]
546
546
  );
@@ -568,16 +568,16 @@ function St(t, c, S, g) {
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
571
- const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = Y(e, r);
572
- return J(d, n) ? "fresh" : "stale";
571
+ const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = J(e, r);
572
+ return q(d, n) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
575
575
  return function() {
576
576
  const d = o().getNestedState(
577
577
  t,
578
578
  r
579
- ), e = o.getState().initialStateGlobal[t], n = Y(e, r);
580
- return J(d, n) ? "fresh" : "stale";
579
+ ), e = o.getState().initialStateGlobal[t], n = J(e, r);
580
+ return q(d, n) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
@@ -634,14 +634,14 @@ function St(t, c, S, g) {
634
634
  const H = o().getNestedState(
635
635
  t,
636
636
  r
637
- ), b = H.length, { totalHeight: N, positions: C } = It(() => {
637
+ ), b = H.length, { totalHeight: N, positions: C } = pt(() => {
638
638
  const V = o.getState().getShadowMetadata(t, r) || [];
639
639
  let $ = 0;
640
640
  const D = [];
641
641
  for (let L = 0; L < b; L++) {
642
642
  D[L] = $;
643
- const Z = V[L]?.virtualizer?.itemHeight;
644
- $ += Z || n;
643
+ const Y = V[L]?.virtualizer?.itemHeight;
644
+ $ += Y || n;
645
645
  }
646
646
  return { totalHeight: $, positions: D };
647
647
  }, [
@@ -650,11 +650,11 @@ function St(t, c, S, g) {
650
650
  r.join("."),
651
651
  n,
652
652
  A
653
- ]), W = It(() => {
653
+ ]), W = pt(() => {
654
654
  const V = Math.max(0, p.startIndex), $ = Math.min(b, p.endIndex), D = Array.from(
655
655
  { length: $ - V },
656
- (Z, q) => V + q
657
- ), L = D.map((Z) => H[Z]);
656
+ (Y, Z) => V + Z
657
+ ), L = D.map((Y) => H[Y]);
658
658
  return s(L, r, {
659
659
  ...f,
660
660
  validIndices: D
@@ -666,22 +666,22 @@ function St(t, c, S, g) {
666
666
  const V = 50, $ = p.endIndex < V, D = b > p.endIndex + V;
667
667
  if ($ || D) {
668
668
  k.current = !0;
669
- const q = {
669
+ const Z = {
670
670
  startIndex: Math.max(0, b - 20),
671
671
  endIndex: b
672
672
  };
673
- T(q), setTimeout(() => {
673
+ T(Z), setTimeout(() => {
674
674
  k.current = !1;
675
675
  }, 100);
676
676
  }
677
677
  let L = 0;
678
- const Z = 50;
678
+ const Y = 50;
679
679
  return P.current = setInterval(() => {
680
- const q = u.current;
681
- if (!q) return;
680
+ const Z = u.current;
681
+ if (!Z) return;
682
682
  L++;
683
- const { scrollTop: ot, scrollHeight: ut, clientHeight: ht } = q, z = ot + ht;
684
- ut - z < 5 || L >= Z ? (clearInterval(P.current), P.current = null) : (k.current = !0, q.scrollTop = q.scrollHeight, setTimeout(() => {
683
+ const { scrollTop: ht, scrollHeight: ot, clientHeight: ut } = Z, vt = ht + ut;
684
+ ot - vt < 50 || L >= Y ? (clearInterval(P.current), P.current = null) : (k.current = !0, Z.scrollTop = Z.scrollHeight, setTimeout(() => {
685
685
  k.current = !1;
686
686
  }, 50));
687
687
  }, 100), () => {
@@ -693,9 +693,8 @@ function St(t, c, S, g) {
693
693
  const $ = () => {
694
694
  if (k.current)
695
695
  return;
696
- P.current && (clearInterval(P.current), P.current = null);
697
- const { scrollTop: D, scrollHeight: L, clientHeight: Z } = V, q = L - D - Z < 10;
698
- M.current = q;
696
+ const { scrollTop: D, scrollHeight: L, clientHeight: Y } = V, ht = L - D - Y < 50;
697
+ P.current && (clearInterval(P.current), P.current = null), M.current = ht;
699
698
  let ot = 0;
700
699
  for (let z = 0; z < C.length; z++)
701
700
  if (C[z] > D - n * a) {
@@ -703,8 +702,8 @@ function St(t, c, S, g) {
703
702
  break;
704
703
  }
705
704
  let ut = ot;
706
- const ht = D + Z;
707
- for (let z = ot; z < C.length && !(C[z] > ht + n * a); z++)
705
+ const vt = D + Y;
706
+ for (let z = ot; z < C.length && !(C[z] > vt + n * a); z++)
708
707
  ut = z;
709
708
  T({
710
709
  startIndex: Math.max(0, ot),
@@ -717,14 +716,14 @@ function St(t, c, S, g) {
717
716
  V.removeEventListener("scroll", $);
718
717
  };
719
718
  }, [C, b, n, a]);
720
- const E = At(
719
+ const E = kt(
721
720
  (V = "auto") => {
722
721
  M.current = !0, k.current = !0, u.current && (u.current.scrollTop = u.current.scrollHeight), setTimeout(() => {
723
722
  k.current = !1;
724
723
  }, 100);
725
724
  },
726
725
  []
727
- ), F = At(
726
+ ), F = kt(
728
727
  (V, $ = "smooth") => {
729
728
  k.current = !0, u.current && C[V] !== void 0 && u.current.scrollTo({
730
729
  top: C[V],
@@ -790,7 +789,7 @@ function St(t, c, S, g) {
790
789
  return e(u, T, {
791
790
  register: () => {
792
791
  const [, _] = et({}), k = `${S}-${r.join(".")}-${i}`;
793
- Tt(() => {
792
+ Et(() => {
794
793
  const M = `${t}////${k}`, P = o.getState().stateComponents.get(t) || {
795
794
  components: /* @__PURE__ */ new Map()
796
795
  };
@@ -825,7 +824,7 @@ function St(t, c, S, g) {
825
824
  );
826
825
  });
827
826
  if (l === "$stateMap")
828
- return (e) => ct(Yt, {
827
+ return (e) => ct(Zt, {
829
828
  proxy: {
830
829
  _stateKey: t,
831
830
  _path: r,
@@ -839,7 +838,7 @@ function St(t, c, S, g) {
839
838
  const n = o.getState().getNestedState(t, r);
840
839
  return Array.isArray(n) ? (f?.validIndices || Array.from({ length: n.length }, (i, v) => v)).map((i, v) => {
841
840
  const u = n[i], p = [...r, i.toString()], T = s(u, p, f), A = `${S}-${r.join(".")}-${i}`;
842
- return ct(Xt, {
841
+ return ct(Qt, {
843
842
  key: i,
844
843
  stateKey: t,
845
844
  itemComponentId: A,
@@ -882,7 +881,7 @@ function St(t, c, S, g) {
882
881
  return s(a, i);
883
882
  };
884
883
  if (l === "insert")
885
- return (e) => (w(r), vt(c, e, r, t), s(
884
+ return (e) => (w(r), yt(c, e, r, t), s(
886
885
  o.getState().getNestedState(t, r),
887
886
  r
888
887
  ));
@@ -893,17 +892,17 @@ function St(t, c, S, g) {
893
892
  if (!i.some((T) => {
894
893
  if (n) {
895
894
  const _ = n.every(
896
- (k) => J(T[k], v[k])
895
+ (k) => q(T[k], v[k])
897
896
  );
898
897
  return _ && (u = T), _;
899
898
  }
900
- const A = J(T, v);
899
+ const A = q(T, v);
901
900
  return A && (u = T), A;
902
901
  }))
903
- w(r), vt(c, v, r, t);
902
+ w(r), yt(c, v, r, t);
904
903
  else if (a && u) {
905
904
  const T = a(u), A = i.map(
906
- (_) => J(_, u) ? T : _
905
+ (_) => q(_, u) ? T : _
907
906
  );
908
907
  w(r), it(c, A, r);
909
908
  }
@@ -924,7 +923,7 @@ function St(t, c, S, g) {
924
923
  if (l === "toggleByValue")
925
924
  return (e) => {
926
925
  const n = h.findIndex((a) => a === e);
927
- n > -1 ? gt(c, r, t, n) : vt(c, e, r, t);
926
+ n > -1 ? gt(c, r, t, n) : yt(c, e, r, t);
928
927
  };
929
928
  if (l === "stateFind")
930
929
  return (e) => {
@@ -965,13 +964,13 @@ function St(t, c, S, g) {
965
964
  return o.getState().getNestedState(t, r);
966
965
  };
967
966
  if (l === "$derive")
968
- return (d) => Vt({
967
+ return (d) => Nt({
969
968
  _stateKey: t,
970
969
  _path: r,
971
970
  _effect: d.toString()
972
971
  });
973
972
  if (l === "$get")
974
- return () => Vt({
973
+ return () => Nt({
975
974
  _stateKey: t,
976
975
  _path: r
977
976
  });
@@ -1011,13 +1010,13 @@ function St(t, c, S, g) {
1011
1010
  throw new Error("Validation key not found");
1012
1011
  X(e.key), console.log("addValidationError", d), d.forEach((n) => {
1013
1012
  const a = [e.key, ...n.path].join(".");
1014
- console.log("fullErrorPath", a), Pt(a, n.message);
1013
+ console.log("fullErrorPath", a), _t(a, n.message);
1015
1014
  }), lt(t);
1016
1015
  };
1017
1016
  if (l === "applyJsonPatch")
1018
1017
  return (d) => {
1019
- const e = o.getState().cogsStateStore[t], a = Wt(e, d).newDocument;
1020
- _t(
1018
+ const e = o.getState().cogsStateStore[t], a = Lt(e, d).newDocument;
1019
+ Mt(
1021
1020
  t,
1022
1021
  o.getState().initialStateGlobal[t],
1023
1022
  a,
@@ -1027,7 +1026,7 @@ function St(t, c, S, g) {
1027
1026
  );
1028
1027
  const i = o.getState().stateComponents.get(t);
1029
1028
  if (i) {
1030
- const v = pt(e, a), u = new Set(v);
1029
+ const v = wt(e, a), u = new Set(v);
1031
1030
  for (const [
1032
1031
  p,
1033
1032
  T
@@ -1075,7 +1074,7 @@ function St(t, c, S, g) {
1075
1074
  if (!A && _.includes("deps") && T.depsFunction) {
1076
1075
  const k = T.depsFunction(a);
1077
1076
  let M = !1;
1078
- typeof k == "boolean" ? k && (M = !0) : J(T.deps, k) || (T.deps = k, M = !0), M && (A = !0);
1077
+ typeof k == "boolean" ? k && (M = !0) : q(T.deps, k) || (T.deps = k, M = !0), M && (A = !0);
1079
1078
  }
1080
1079
  A && T.forceUpdate();
1081
1080
  }
@@ -1109,7 +1108,7 @@ function St(t, c, S, g) {
1109
1108
  if (l === "getComponents")
1110
1109
  return () => o().stateComponents.get(t);
1111
1110
  if (l === "getAllFormRefs")
1112
- return () => kt.getState().getFormRefsByStateKey(t);
1111
+ return () => $t.getState().getFormRefsByStateKey(t);
1113
1112
  if (l === "_initialState")
1114
1113
  return o.getState().initialStateGlobal[t];
1115
1114
  if (l === "_serverState")
@@ -1122,13 +1121,13 @@ function St(t, c, S, g) {
1122
1121
  if (l === "removeValidation") return I.removeValidation;
1123
1122
  }
1124
1123
  if (l === "getFormRef")
1125
- return () => kt.getState().getFormRef(t + "." + r.join("."));
1124
+ return () => $t.getState().getFormRef(t + "." + r.join("."));
1126
1125
  if (l === "validationWrapper")
1127
1126
  return ({
1128
1127
  children: d,
1129
1128
  hideMessage: e
1130
- }) => /* @__PURE__ */ yt(
1131
- Ut,
1129
+ }) => /* @__PURE__ */ It(
1130
+ Ft,
1132
1131
  {
1133
1132
  formOpts: e ? { validation: { message: "" } } : void 0,
1134
1133
  path: r,
@@ -1144,7 +1143,7 @@ function St(t, c, S, g) {
1144
1143
  if (l === "update")
1145
1144
  return (d, e) => {
1146
1145
  if (e?.debounce)
1147
- Ot(() => {
1146
+ Ut(() => {
1148
1147
  it(c, d, r, "");
1149
1148
  const n = o.getState().getNestedState(t, r);
1150
1149
  e?.afterUpdate && e.afterUpdate(n);
@@ -1157,8 +1156,8 @@ function St(t, c, S, g) {
1157
1156
  w(r);
1158
1157
  };
1159
1158
  if (l === "formElement")
1160
- return (d, e) => /* @__PURE__ */ yt(
1161
- Ft,
1159
+ return (d, e) => /* @__PURE__ */ It(
1160
+ Dt,
1162
1161
  {
1163
1162
  setState: c,
1164
1163
  stateKey: t,
@@ -1170,20 +1169,20 @@ function St(t, c, S, g) {
1170
1169
  const j = [...r, l], st = o.getState().getNestedState(t, j);
1171
1170
  return s(st, j, f);
1172
1171
  }
1173
- }, B = new Proxy(O, U);
1174
- return y.set(G, {
1175
- proxy: B,
1172
+ }, G = new Proxy(O, U);
1173
+ return y.set(B, {
1174
+ proxy: G,
1176
1175
  stateVersion: x
1177
- }), B;
1176
+ }), G;
1178
1177
  }
1179
1178
  return s(
1180
1179
  o.getState().getNestedState(t, [])
1181
1180
  );
1182
1181
  }
1183
- function Vt(t) {
1184
- return ct(Zt, { proxy: t });
1182
+ function Nt(t) {
1183
+ return ct(Xt, { proxy: t });
1185
1184
  }
1186
- function Yt({
1185
+ function Zt({
1187
1186
  proxy: t,
1188
1187
  rebuildStateShape: c
1189
1188
  }) {
@@ -1195,7 +1194,7 @@ function Yt({
1195
1194
  (y, x, w, I, s) => t._mapFn(y, x, w, I, s)
1196
1195
  ) : null;
1197
1196
  }
1198
- function Zt({
1197
+ function Xt({
1199
1198
  proxy: t
1200
1199
  }) {
1201
1200
  const c = Q(null), S = `${t._stateKey}-${t._path.join(".")}`;
@@ -1226,8 +1225,8 @@ function Zt({
1226
1225
  else
1227
1226
  f = r;
1228
1227
  f !== null && typeof f == "object" && (f = JSON.stringify(f));
1229
- const G = document.createTextNode(String(f));
1230
- g.replaceWith(G);
1228
+ const B = document.createTextNode(String(f));
1229
+ g.replaceWith(B);
1231
1230
  }, [t._stateKey, t._path.join("."), t._effect]), ct("span", {
1232
1231
  ref: c,
1233
1232
  style: { display: "none" },
@@ -1235,7 +1234,7 @@ function Zt({
1235
1234
  });
1236
1235
  }
1237
1236
  function Se(t) {
1238
- const c = Mt(
1237
+ const c = jt(
1239
1238
  (S) => {
1240
1239
  const g = o.getState().stateComponents.get(t._stateKey) || {
1241
1240
  components: /* @__PURE__ */ new Map()
@@ -1249,20 +1248,20 @@ function Se(t) {
1249
1248
  );
1250
1249
  return ct("text", {}, String(c));
1251
1250
  }
1252
- function Xt({
1251
+ function Qt({
1253
1252
  stateKey: t,
1254
1253
  itemComponentId: c,
1255
1254
  itemPath: S,
1256
1255
  children: g
1257
1256
  }) {
1258
- const [, y] = et({}), [x, w] = Lt(), I = Q(null);
1257
+ const [, y] = et({}), [x, w] = Bt(), I = Q(null);
1259
1258
  return nt(() => {
1260
1259
  w.height > 0 && w.height !== I.current && (I.current = w.height, o.getState().setShadowMetadata(t, S, {
1261
1260
  virtualizer: {
1262
1261
  itemHeight: w.height
1263
1262
  }
1264
1263
  }));
1265
- }, [w.height, t, S]), Tt(() => {
1264
+ }, [w.height, t, S]), Et(() => {
1266
1265
  const s = `${t}////${c}`, h = o.getState().stateComponents.get(t) || {
1267
1266
  components: /* @__PURE__ */ new Map()
1268
1267
  };
@@ -1273,14 +1272,14 @@ function Xt({
1273
1272
  const r = o.getState().stateComponents.get(t);
1274
1273
  r && r.components.delete(s);
1275
1274
  };
1276
- }, [t, c, S.join(".")]), /* @__PURE__ */ yt("div", { ref: x, children: g });
1275
+ }, [t, c, S.join(".")]), /* @__PURE__ */ It("div", { ref: x, children: g });
1277
1276
  }
1278
1277
  export {
1279
- Vt as $cogsSignal,
1278
+ Nt as $cogsSignal,
1280
1279
  Se as $cogsSignalStore,
1281
1280
  ue as addStateOptions,
1282
1281
  ge as createCogsState,
1283
1282
  fe as notifyComponent,
1284
- Jt as useCogsStateFn
1283
+ Yt as useCogsStateFn
1285
1284
  };
1286
1285
  //# sourceMappingURL=CogsState.jsx.map