cogsbox-state 0.5.406 → 0.5.408

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,14 +1,14 @@
1
1
  "use client";
2
2
  import { jsx as It } from "react/jsx-runtime";
3
- import { useState as nt, useRef as X, useEffect as rt, useLayoutEffect as kt, useMemo as wt, createElement as ut, useSyncExternalStore as Ut, startTransition as jt, useCallback as bt } from "react";
4
- import { transformStateFunc as Ot, isDeepEqual as q, isFunction as K, getNestedValue as Y, getDifferences as Tt, debounce as Ft } from "./utility.js";
5
- import { pushFunc as yt, updateFn as dt, cutFunc as mt, ValidationWrapper as Dt, FormControlComponent as Wt } from "./Functions.jsx";
6
- import Lt from "superjson";
7
- import { v4 as Et } from "uuid";
3
+ import { useState as et, useRef as Q, useEffect as nt, useLayoutEffect as Et, useMemo as pt, createElement as ct, useSyncExternalStore as Ot, startTransition as Ut, useCallback as $t } from "react";
4
+ import { transformStateFunc as Ft, isDeepEqual as J, isFunction as K, getNestedValue as Y, getDifferences as wt, debounce as Dt } from "./utility.js";
5
+ import { pushFunc as yt, updateFn as it, cutFunc as gt, ValidationWrapper as Wt, FormControlComponent as Lt } from "./Functions.jsx";
6
+ import Gt from "superjson";
7
+ import { v4 as Tt } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as o, formRefStore as $t } from "./store.js";
9
+ import { getGlobalStore as o, formRefStore as bt } from "./store.js";
10
10
  import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
11
- import { applyPatch as Gt } from "fast-json-patch";
11
+ import { applyPatch as Ht } from "fast-json-patch";
12
12
  import Bt from "react-use-measure";
13
13
  function xt(t, c) {
14
14
  const S = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, y = S(t) || {};
@@ -27,15 +27,15 @@ function Vt({
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
- !q(w[s], c[s]) && (I = !0, w[s] = c[s])) : (I = !0, w[s] = c[s]);
30
+ !J(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
- function ue(t, { formElements: c, validation: S }) {
33
+ function ge(t, { formElements: c, validation: S }) {
34
34
  return { initialState: t, formElements: c, validation: S };
35
35
  }
36
- const ge = (t, c) => {
36
+ const fe = (t, c) => {
37
37
  let S = t;
38
- const [g, y] = Ot(S);
38
+ const [g, y] = Ft(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] = nt(s?.componentId ?? Et());
49
+ const [h] = et(s?.componentId ?? Tt());
50
50
  Vt({
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, [H, O] = Zt(
55
+ const r = o.getState().cogsStateStore[I] || g[I], f = s?.modifyState ? s.modifyState(r) : r, [H, U] = Xt(
56
56
  f,
57
57
  {
58
58
  stateKey: I,
@@ -68,24 +68,24 @@ const ge = (t, c) => {
68
68
  serverState: s?.serverState
69
69
  }
70
70
  );
71
- return O;
71
+ return U;
72
72
  };
73
73
  function w(I, s) {
74
- Vt({ stateKey: I, options: s, initialOptionsPart: y }), s.localStorage && qt(I, s), gt(I);
74
+ Vt({ stateKey: I, options: s, initialOptionsPart: y }), s.localStorage && Yt(I, s), lt(I);
75
75
  }
76
76
  return { useCogsState: x, setCogsOptions: w };
77
77
  }, {
78
- setUpdaterState: ht,
79
- setState: ot,
78
+ setUpdaterState: ft,
79
+ setState: rt,
80
80
  getInitialOptions: at,
81
81
  getKeyState: _t,
82
- getValidationErrors: Ht,
83
- setStateLog: zt,
82
+ getValidationErrors: zt,
83
+ setStateLog: qt,
84
84
  updateInitialStateGlobal: At,
85
85
  addValidationError: Mt,
86
- removeValidationError: Z,
86
+ removeValidationError: X,
87
87
  setServerSyncActions: Jt
88
- } = o.getState(), Ct = (t, c, S, g, y) => {
88
+ } = o.getState(), Nt = (t, c, S, g, y) => {
89
89
  S?.log && console.log(
90
90
  "saving to localstorage",
91
91
  c,
@@ -97,20 +97,20 @@ const ge = (t, c) => {
97
97
  const w = `${g}-${c}-${x}`;
98
98
  let I;
99
99
  try {
100
- I = pt(w)?.lastSyncedWithServer;
100
+ I = mt(w)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const s = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: y ?? I
107
- }, h = Lt.serialize(s);
107
+ }, h = Gt.serialize(s);
108
108
  window.localStorage.setItem(
109
109
  w,
110
110
  JSON.stringify(h.json)
111
111
  );
112
112
  }
113
- }, pt = (t) => {
113
+ }, mt = (t) => {
114
114
  if (!t) return null;
115
115
  try {
116
116
  const c = window.localStorage.getItem(t);
@@ -118,20 +118,20 @@ const ge = (t, c) => {
118
118
  } catch (c) {
119
119
  return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
- }, qt = (t, c) => {
121
+ }, Yt = (t, c) => {
122
122
  const S = o.getState().cogsStateStore[t], { sessionId: g } = Pt(), y = K(c?.localStorage?.key) ? c.localStorage.key(S) : c?.localStorage?.key;
123
123
  if (y && g) {
124
- const x = pt(
124
+ const x = mt(
125
125
  `${g}-${t}-${y}`
126
126
  );
127
127
  if (x && x.lastUpdated > (x.lastSyncedWithServer || 0))
128
- return ot(t, x.state), gt(t), !0;
128
+ return rt(t, x.state), lt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Rt = (t, c, S, g, y, x) => {
131
+ }, jt = (t, c, S, g, y, x) => {
132
132
  const w = {
133
133
  initialState: c,
134
- updaterState: vt(
134
+ updaterState: St(
135
135
  t,
136
136
  g,
137
137
  y,
@@ -139,8 +139,8 @@ const ge = (t, c) => {
139
139
  ),
140
140
  state: S
141
141
  };
142
- At(t, w.initialState), ht(t, w.updaterState), ot(t, w.state);
143
- }, gt = (t) => {
142
+ At(t, w.initialState), ft(t, w.updaterState), rt(t, w.state);
143
+ }, lt = (t) => {
144
144
  const c = o.getState().stateComponents.get(t);
145
145
  if (!c) return;
146
146
  const S = /* @__PURE__ */ new Set();
@@ -149,7 +149,7 @@ const ge = (t, c) => {
149
149
  }), queueMicrotask(() => {
150
150
  S.forEach((g) => g());
151
151
  });
152
- }, fe = (t, c) => {
152
+ }, Se = (t, c) => {
153
153
  const S = o.getState().stateComponents.get(t);
154
154
  if (S) {
155
155
  const g = `${t}////${c}`, y = S.components.get(g);
@@ -157,7 +157,7 @@ const ge = (t, c) => {
157
157
  return;
158
158
  y && y.forceUpdate();
159
159
  }
160
- }, Yt = (t, c, S, g) => {
160
+ }, Zt = (t, c, S, g) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
@@ -180,7 +180,7 @@ const ge = (t, c) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Zt(t, {
183
+ function Xt(t, {
184
184
  stateKey: c,
185
185
  serverSync: S,
186
186
  localStorage: g,
@@ -193,14 +193,14 @@ function Zt(t, {
193
193
  dependencies: r,
194
194
  serverState: f
195
195
  } = {}) {
196
- const [H, O] = nt({}), { sessionId: F } = Pt();
197
- let z = !c;
198
- const [m] = nt(c ?? Et()), l = o.getState().stateLog[m], ft = X(/* @__PURE__ */ new Set()), tt = X(I ?? Et()), R = X(
196
+ const [H, U] = et({}), { sessionId: F } = Pt();
197
+ let B = !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
- R.current = at(m) ?? null, rt(() => {
201
+ j.current = at(m) ?? null, nt(() => {
202
202
  if (h && h.stateKey === m && h.path?.[0]) {
203
- ot(m, (n) => ({
203
+ rt(m, (n) => ({
204
204
  ...n,
205
205
  [h.path[0]]: h.newValue
206
206
  }));
@@ -210,166 +210,166 @@ function Zt(t, {
210
210
  userId: h.userId
211
211
  });
212
212
  }
213
- }, [h]), rt(() => {
213
+ }, [h]), nt(() => {
214
214
  if (s) {
215
215
  xt(m, {
216
216
  initialState: s
217
217
  });
218
- const e = R.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[m];
219
- if (!(i && !q(i, s) || !i) && !a)
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)
220
220
  return;
221
221
  let u = null;
222
222
  const p = K(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
223
- p && F && (u = pt(`${F}-${m}-${p}`));
224
- let T = s, b = !1;
225
- const _ = a ? Date.now() : 0, N = u?.lastUpdated || 0, M = u?.lastSyncedWithServer || 0;
226
- a && _ > N ? (T = e.serverState.data, b = !0) : u && N > M && (T = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(m, s), Rt(
223
+ p && F && (u = mt(`${F}-${m}-${p}`));
224
+ let T = s, A = !1;
225
+ const _ = a ? Date.now() : 0, $ = u?.lastUpdated || 0, M = u?.lastSyncedWithServer || 0;
226
+ a && _ > $ ? (T = e.serverState.data, A = !0) : u && $ > M && (T = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(m, s), jt(
227
227
  m,
228
228
  s,
229
229
  T,
230
230
  st,
231
231
  tt.current,
232
232
  F
233
- ), b && p && F && Ct(T, m, e, F, Date.now()), gt(m), (Array.isArray(w) ? w : [w || "component"]).includes("none") || O({});
233
+ ), A && p && F && Nt(T, m, e, F, Date.now()), lt(m), (Array.isArray(w) ? w : [w || "component"]).includes("none") || U({});
234
234
  }
235
235
  }, [
236
236
  s,
237
237
  f?.status,
238
238
  f?.data,
239
239
  ...r || []
240
- ]), kt(() => {
241
- z && xt(m, {
240
+ ]), Et(() => {
241
+ B && xt(m, {
242
242
  serverSync: S,
243
243
  formElements: y,
244
244
  initialState: s,
245
245
  localStorage: g,
246
- middleware: R.current?.middleware
246
+ middleware: j.current?.middleware
247
247
  });
248
248
  const e = `${m}////${tt.current}`, n = o.getState().stateComponents.get(m) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return n.components.set(e, {
252
- forceUpdate: () => O({}),
252
+ forceUpdate: () => U({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
255
  depsFunction: x || void 0,
256
256
  reactiveType: w ?? ["component", "deps"]
257
- }), o.getState().stateComponents.set(m, n), O({}), () => {
257
+ }), o.getState().stateComponents.set(m, n), U({}), () => {
258
258
  n && (n.components.delete(e), n.components.size === 0 && o.getState().stateComponents.delete(m));
259
259
  };
260
260
  }, []);
261
261
  const st = (e, n, a, i) => {
262
262
  if (Array.isArray(n)) {
263
263
  const u = `${m}-${n.join(".")}`;
264
- ft.current.add(u);
264
+ dt.current.add(u);
265
265
  }
266
266
  const v = o.getState();
267
- ot(m, (u) => {
267
+ rt(m, (u) => {
268
268
  const p = K(e) ? e(u) : e, T = `${m}-${n.join(".")}`;
269
269
  if (T) {
270
- let k = !1, V = v.signalDomElements.get(T);
271
- if ((!V || V.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
270
+ let b = !1, N = v.signalDomElements.get(T);
271
+ if ((!N || N.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
272
  const C = n.slice(0, -1), L = Y(p, C);
273
273
  if (Array.isArray(L)) {
274
- k = !0;
275
- const A = `${m}-${C.join(".")}`;
276
- V = v.signalDomElements.get(A);
274
+ b = !0;
275
+ const E = `${m}-${C.join(".")}`;
276
+ N = v.signalDomElements.get(E);
277
277
  }
278
278
  }
279
- if (V) {
280
- const C = k ? Y(p, n.slice(0, -1)) : Y(p, n);
281
- V.forEach(({ parentId: L, position: A, effect: D }) => {
282
- const U = document.querySelector(
279
+ if (N) {
280
+ const C = b ? Y(p, n.slice(0, -1)) : Y(p, n);
281
+ N.forEach(({ parentId: L, position: E, effect: D }) => {
282
+ const R = document.querySelector(
283
283
  `[data-parent-id="${L}"]`
284
284
  );
285
- if (U) {
286
- const $ = Array.from(U.childNodes);
287
- if ($[A]) {
288
- const E = D ? new Function("state", `return (${D})(state)`)(C) : C;
289
- $[A].textContent = String(E);
285
+ if (R) {
286
+ const V = Array.from(R.childNodes);
287
+ if (V[E]) {
288
+ const k = D ? new Function("state", `return (${D})(state)`)(C) : C;
289
+ V[E].textContent = String(k);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", v.shadowStateStore), a.updateType === "update" && (i || R.current?.validation?.key) && n && Z(
296
- (i || R.current?.validation?.key) + "." + n.join(".")
295
+ console.log("shadowState", v.shadowStateStore), a.updateType === "update" && (i || j.current?.validation?.key) && n && X(
296
+ (i || j.current?.validation?.key) + "." + n.join(".")
297
297
  );
298
- const b = n.slice(0, n.length - 1);
299
- a.updateType === "cut" && R.current?.validation?.key && Z(
300
- R.current?.validation?.key + "." + b.join(".")
301
- ), a.updateType === "insert" && R.current?.validation?.key && Ht(
302
- R.current?.validation?.key + "." + b.join(".")
303
- ).filter(([V, C]) => {
304
- let L = V?.split(".").length;
305
- if (V == b.join(".") && L == b.length - 1) {
306
- let A = V + "." + b;
307
- Z(V), Mt(A, C);
298
+ const A = n.slice(0, n.length - 1);
299
+ a.updateType === "cut" && j.current?.validation?.key && X(
300
+ j.current?.validation?.key + "." + A.join(".")
301
+ ), a.updateType === "insert" && j.current?.validation?.key && zt(
302
+ j.current?.validation?.key + "." + A.join(".")
303
+ ).filter(([N, C]) => {
304
+ let L = N?.split(".").length;
305
+ if (N == A.join(".") && L == A.length - 1) {
306
+ let E = N + "." + A;
307
+ X(N), Mt(E, C);
308
308
  }
309
309
  });
310
310
  const _ = v.stateComponents.get(m);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
312
- const k = Tt(u, p), V = new Set(k), 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
  L,
315
- A
315
+ E
316
316
  ] of _.components.entries()) {
317
317
  let D = !1;
318
- const U = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
319
- if (console.log("component", A), !U.includes("none")) {
320
- if (U.includes("all")) {
321
- A.forceUpdate();
318
+ const R = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
319
+ if (console.log("component", E), !R.includes("none")) {
320
+ if (R.includes("all")) {
321
+ E.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (U.includes("component") && ((A.paths.has(C) || A.paths.has("")) && (D = !0), !D))
325
- for (const $ of V) {
326
- let E = $;
324
+ if (R.includes("component") && ((E.paths.has(C) || E.paths.has("")) && (D = !0), !D))
325
+ for (const V of N) {
326
+ let k = V;
327
327
  for (; ; ) {
328
- if (A.paths.has(E)) {
328
+ if (E.paths.has(k)) {
329
329
  D = !0;
330
330
  break;
331
331
  }
332
- const W = E.lastIndexOf(".");
332
+ const W = k.lastIndexOf(".");
333
333
  if (W !== -1) {
334
- const j = E.substring(
334
+ const G = k.substring(
335
335
  0,
336
336
  W
337
337
  );
338
338
  if (!isNaN(
339
- Number(E.substring(W + 1))
340
- ) && A.paths.has(j)) {
339
+ Number(k.substring(W + 1))
340
+ ) && E.paths.has(G)) {
341
341
  D = !0;
342
342
  break;
343
343
  }
344
- E = j;
344
+ k = G;
345
345
  } else
346
- E = "";
347
- if (E === "")
346
+ k = "";
347
+ if (k === "")
348
348
  break;
349
349
  }
350
350
  if (D) break;
351
351
  }
352
- if (!D && U.includes("deps") && A.depsFunction) {
353
- const $ = A.depsFunction(p);
354
- let E = !1;
355
- typeof $ == "boolean" ? $ && (E = !0) : q(A.deps, $) || (A.deps = $, E = !0), E && (D = !0);
352
+ if (!D && R.includes("deps") && E.depsFunction) {
353
+ const V = E.depsFunction(p);
354
+ let k = !1;
355
+ typeof V == "boolean" ? V && (k = !0) : J(E.deps, V) || (E.deps = V, k = !0), k && (D = !0);
356
356
  }
357
- D && A.forceUpdate();
357
+ D && E.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const N = Date.now();
362
- n = n.map((k, V) => {
361
+ const $ = Date.now();
362
+ n = n.map((b, N) => {
363
363
  const C = n.slice(0, -1), L = Y(p, C);
364
- return V === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (L.length - 1).toString() : k;
364
+ return N === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (L.length - 1).toString() : b;
365
365
  });
366
- const { oldValue: M, newValue: P } = Yt(
366
+ const { oldValue: M, newValue: P } = Zt(
367
367
  a.updateType,
368
368
  u,
369
369
  p,
370
370
  n
371
- ), J = {
372
- timeStamp: N,
371
+ ), z = {
372
+ timeStamp: $,
373
373
  stateKey: m,
374
374
  path: n,
375
375
  updateType: a.updateType,
@@ -382,50 +382,50 @@ function Zt(t, {
382
382
  v.updateShadowAtPath(m, n, p);
383
383
  break;
384
384
  case "insert":
385
- const k = n.slice(0, -1);
386
- v.insertShadowArrayElement(m, k, P);
385
+ const b = n.slice(0, -1);
386
+ v.insertShadowArrayElement(m, b, P);
387
387
  break;
388
388
  case "cut":
389
- const V = n.slice(0, -1), C = parseInt(n[n.length - 1]);
390
- v.removeShadowArrayElement(m, V, C);
389
+ const N = n.slice(0, -1), C = parseInt(n[n.length - 1]);
390
+ v.removeShadowArrayElement(m, N, C);
391
391
  break;
392
392
  }
393
- if (zt(m, (k) => {
394
- const C = [...k ?? [], J].reduce((L, A) => {
395
- const D = `${A.stateKey}:${JSON.stringify(A.path)}`, U = L.get(D);
396
- return U ? (U.timeStamp = Math.max(U.timeStamp, A.timeStamp), U.newValue = A.newValue, U.oldValue = U.oldValue ?? A.oldValue, U.updateType = A.updateType) : L.set(D, { ...A }), L;
393
+ if (qt(m, (b) => {
394
+ const C = [...b ?? [], z].reduce((L, E) => {
395
+ const D = `${E.stateKey}:${JSON.stringify(E.path)}`, R = L.get(D);
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) : L.set(D, { ...E }), L;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(C.values());
399
- }), Ct(
399
+ }), Nt(
400
400
  p,
401
401
  m,
402
- R.current,
402
+ j.current,
403
403
  F
404
- ), R.current?.middleware && R.current.middleware({
404
+ ), j.current?.middleware && j.current.middleware({
405
405
  updateLog: l,
406
- update: J
407
- }), R.current?.serverSync) {
408
- const k = v.serverState[m], V = R.current?.serverSync;
406
+ update: z
407
+ }), j.current?.serverSync) {
408
+ const b = v.serverState[m], N = j.current?.serverSync;
409
409
  Jt(m, {
410
- syncKey: typeof V.syncKey == "string" ? V.syncKey : V.syncKey({ state: p }),
411
- rollBackState: k,
412
- actionTimeStamp: Date.now() + (V.debounce ?? 3e3),
410
+ syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: p }),
411
+ rollBackState: b,
412
+ actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
416
  return p;
417
417
  });
418
418
  };
419
- o.getState().updaterState[m] || (ht(
419
+ o.getState().updaterState[m] || (ft(
420
420
  m,
421
- vt(
421
+ St(
422
422
  m,
423
423
  st,
424
424
  tt.current,
425
425
  F
426
426
  )
427
- ), o.getState().cogsStateStore[m] || ot(m, t), o.getState().initialStateGlobal[m] || At(m, t));
428
- const d = wt(() => vt(
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,
@@ -433,7 +433,7 @@ function Zt(t, {
433
433
  ), [m, F]);
434
434
  return [_t(m), d];
435
435
  }
436
- function vt(t, c, S, g) {
436
+ function St(t, c, S, g) {
437
437
  const y = /* @__PURE__ */ new Map();
438
438
  let x = 0;
439
439
  const w = (h) => {
@@ -443,15 +443,15 @@ function vt(t, c, S, g) {
443
443
  x++;
444
444
  }, I = {
445
445
  removeValidation: (h) => {
446
- h?.validationKey && Z(h.validationKey);
446
+ h?.validationKey && X(h.validationKey);
447
447
  },
448
448
  revertToInitialState: (h) => {
449
449
  const r = o.getState().getInitialOptions(t)?.validation;
450
- r?.key && Z(r?.key), h?.validationKey && Z(h.validationKey);
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 H = s(f, []), O = at(t), F = K(O?.localStorage?.key) ? O?.localStorage?.key(f) : O?.localStorage?.key, z = `${g}-${t}-${F}`;
454
- z && localStorage.removeItem(z), ht(t, H), ot(t, f);
453
+ const H = s(f, []), U = at(t), F = K(U?.localStorage?.key) ? U?.localStorage?.key(f) : U?.localStorage?.key, B = `${g}-${t}-${F}`;
454
+ B && localStorage.removeItem(B), ft(t, H), rt(t, f);
455
455
  const m = o.getState().stateComponents.get(t);
456
456
  return m && m.components.forEach((l) => {
457
457
  l.forceUpdate();
@@ -459,20 +459,20 @@ function vt(t, c, S, g) {
459
459
  },
460
460
  updateInitialState: (h) => {
461
461
  y.clear(), x++;
462
- const r = vt(
462
+ const r = St(
463
463
  t,
464
464
  c,
465
465
  S,
466
466
  g
467
- ), f = o.getState().initialStateGlobal[t], H = at(t), O = K(H?.localStorage?.key) ? H?.localStorage?.key(f) : H?.localStorage?.key, F = `${g}-${t}-${O}`;
468
- return localStorage.getItem(F) && localStorage.removeItem(F), jt(() => {
469
- At(t, h), o.getState().initializeShadowState(t, h), ht(t, r), ot(t, h);
470
- const z = o.getState().stateComponents.get(t);
471
- z && z.components.forEach((m) => {
467
+ ), f = o.getState().initialStateGlobal[t], H = at(t), U = K(H?.localStorage?.key) ? H?.localStorage?.key(f) : H?.localStorage?.key, F = `${g}-${t}-${U}`;
468
+ return localStorage.getItem(F) && localStorage.removeItem(F), Ut(() => {
469
+ At(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) => {
472
472
  m.forceUpdate();
473
473
  });
474
474
  }), {
475
- fetchId: (z) => r.get()[z]
475
+ fetchId: (B) => r.get()[B]
476
476
  };
477
477
  },
478
478
  _initialState: o.getState().initialStateGlobal[t],
@@ -480,27 +480,27 @@ function vt(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 && q(h, _t(t)));
483
+ return !!(h && J(h, _t(t)));
484
484
  }
485
485
  };
486
486
  function s(h, r = [], f) {
487
487
  const H = r.map(String).join(".");
488
488
  y.get(H);
489
- const O = function() {
489
+ const U = function() {
490
490
  return o().getNestedState(t, r);
491
491
  };
492
492
  Object.keys(I).forEach((m) => {
493
- O[m] = I[m];
493
+ U[m] = I[m];
494
494
  });
495
495
  const F = {
496
- apply(m, l, ft) {
496
+ apply(m, l, dt) {
497
497
  return console.log(
498
498
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${r.join(".")}`
499
499
  ), console.trace("Apply trap stack trace"), o().getNestedState(t, r);
500
500
  },
501
501
  get(m, l) {
502
502
  f?.validIndices && !Array.isArray(h) && (f = { ...f, validIndices: void 0 });
503
- const ft = /* @__PURE__ */ new Set([
503
+ const dt = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,7 +523,7 @@ function vt(t, c, S, g) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ft.has(l)) {
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !dt.has(l)) {
527
527
  const d = `${t}////${S}`, e = o.getState().stateComponents.get(t);
528
528
  if (e) {
529
529
  const n = e.components.get(d);
@@ -540,7 +540,7 @@ function vt(t, c, S, g) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => Tt(
543
+ return () => wt(
544
544
  o.getState().cogsStateStore[t],
545
545
  o.getState().initialStateGlobal[t]
546
546
  );
@@ -569,7 +569,7 @@ function vt(t, c, S, g) {
569
569
  };
570
570
  if (l === "_status") {
571
571
  const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = Y(e, r);
572
- return q(d, n) ? "fresh" : "stale";
572
+ return J(d, n) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
575
575
  return function() {
@@ -577,7 +577,7 @@ function vt(t, c, S, g) {
577
577
  t,
578
578
  r
579
579
  ), e = o.getState().initialStateGlobal[t], n = Y(e, r);
580
- return q(d, n) ? "fresh" : "stale";
580
+ return J(d, n) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
@@ -622,177 +622,128 @@ function vt(t, c, S, g) {
622
622
  overscan: a = 6,
623
623
  stickToBottom: i = !1,
624
624
  dependencies: v = []
625
- } = e;
626
- console.log("useVirtualView initialized with:", {
627
- itemHeight: n,
628
- overscan: a,
629
- stickToBottom: i
630
- });
631
- const u = X(null), [p, T] = nt({
625
+ } = e, u = Q(null), [p, T] = et({
632
626
  startIndex: 0,
633
627
  endIndex: 10
634
- }), [b, _] = nt(0), N = X(!1), M = X(!0), P = X(
628
+ }), [A, _] = et(0), $ = Q(!1), M = Q(!0), P = Q(
635
629
  null
636
630
  );
637
- rt(() => (console.log("Setting up shadow state subscription"), o.getState().subscribeToShadowState(t, () => {
638
- console.log("Shadow state updated"), _((E) => E + 1);
639
- })), [t]);
640
- const J = o().getNestedState(
631
+ nt(() => o.getState().subscribeToShadowState(t, () => {
632
+ _((k) => k + 1);
633
+ }), [t]);
634
+ const z = o().getNestedState(
641
635
  t,
642
636
  r
643
- ), k = J.length;
644
- console.log("Source array length:", k);
645
- const { totalHeight: V, positions: C } = wt(() => {
646
- console.log("Recalculating heights and positions");
647
- const $ = o.getState().getShadowMetadata(t, r) || [];
648
- let E = 0;
637
+ ), b = z.length, { totalHeight: N, positions: C } = pt(() => {
638
+ const V = o.getState().getShadowMetadata(t, r) || [];
639
+ let k = 0;
649
640
  const W = [];
650
- for (let j = 0; j < k; j++) {
651
- W[j] = E;
652
- const Q = $[j]?.virtualizer?.itemHeight;
653
- E += Q || n;
641
+ for (let G = 0; G < b; G++) {
642
+ W[G] = k;
643
+ const Z = V[G]?.virtualizer?.itemHeight;
644
+ k += Z || n;
654
645
  }
655
- return console.log("Total height calculated:", E), { totalHeight: E, positions: W };
646
+ return { totalHeight: k, positions: W };
656
647
  }, [
657
- k,
648
+ b,
658
649
  t,
659
650
  r.join("."),
660
651
  n,
661
- b
662
- ]), L = wt(() => {
663
- const $ = Math.max(0, p.startIndex), E = Math.min(k, p.endIndex);
664
- console.log("Creating virtual state for range:", {
665
- start: $,
666
- end: E
667
- });
668
- const W = Array.from(
669
- { length: E - $ },
670
- (Q, G) => $ + G
671
- ), j = W.map((Q) => J[Q]);
672
- return s(j, r, {
652
+ A
653
+ ]), L = pt(() => {
654
+ const V = Math.max(0, p.startIndex), k = Math.min(b, p.endIndex), W = Array.from(
655
+ { length: k - V },
656
+ (Z, O) => V + O
657
+ ), G = W.map((Z) => z[Z]);
658
+ return s(G, r, {
673
659
  ...f,
674
660
  validIndices: W
675
661
  });
676
- }, [p.startIndex, p.endIndex, J, k]);
677
- rt(() => {
678
- if (console.log("Auto-scroll effect triggered:", {
679
- stickToBottom: i,
680
- hasContainer: !!u.current,
681
- totalCount: k,
682
- shouldStickToBottom: M.current,
683
- range: p
684
- }), !i) {
685
- console.log("Stick to bottom is false, skipping");
686
- return;
687
- }
688
- if (!u.current) {
689
- console.log("No container ref, skipping");
690
- return;
691
- }
692
- if (k === 0) {
693
- console.log("No items, skipping");
694
- return;
695
- }
696
- if (!M.current) {
697
- console.log(
698
- "Should not stick to bottom (user scrolled), skipping"
699
- );
700
- return;
701
- }
702
- console.log("Proceeding with auto-scroll logic"), P.current && (console.log("Clearing existing scroll interval"), clearInterval(P.current));
703
- const $ = 50, E = p.endIndex < $, W = k > p.endIndex + $;
704
- if (console.log("Jump check:", {
705
- isInitialLoad: E,
706
- isBigJump: W,
707
- totalCount: k,
708
- currentEndIndex: p.endIndex
709
- }), E || W) {
710
- const G = {
711
- startIndex: Math.max(0, k - 20),
712
- endIndex: k
662
+ }, [p.startIndex, p.endIndex, z, b]);
663
+ nt(() => {
664
+ if (!i || !u.current || b === 0 || !M.current) return;
665
+ P.current && clearInterval(P.current);
666
+ const V = 50, k = p.endIndex < V, W = b > p.endIndex + V;
667
+ if (k || W) {
668
+ $.current = !0;
669
+ const O = {
670
+ startIndex: Math.max(0, b - 20),
671
+ endIndex: b
713
672
  };
714
- console.log("Jumping to end range:", G), T(G);
673
+ T(O), setTimeout(() => {
674
+ $.current = !1;
675
+ }, 100);
715
676
  }
716
- let j = 0;
717
- const Q = 50;
718
- return console.log("Starting scroll-to-bottom interval"), P.current = setInterval(() => {
719
- const G = u.current;
720
- if (!G) {
721
- console.log("Container lost during interval");
722
- return;
677
+ let G = 0;
678
+ const Z = 50;
679
+ return P.current = setInterval(() => {
680
+ const O = u.current;
681
+ if (!O) return;
682
+ G++;
683
+ const { scrollTop: ht, scrollHeight: ot, clientHeight: ut } = O, vt = ht + ut, kt = ot - vt < 50;
684
+ if (kt || G >= Z)
685
+ clearInterval(P.current), P.current = null, kt && O.scrollTop < O.scrollHeight - O.clientHeight && (O.scrollTop = O.scrollHeight);
686
+ else {
687
+ const Rt = O.scrollHeight - O.clientHeight;
688
+ Math.abs(O.scrollTop - Rt) > 1 && (O.scrollTop = O.scrollHeight);
723
689
  }
724
- j++;
725
- const { scrollTop: it, scrollHeight: et, clientHeight: ct } = G, St = it + ct, lt = et, B = lt - St < 5;
726
- console.log(`Scroll attempt ${j}:`, {
727
- currentBottom: St,
728
- actualBottom: lt,
729
- isAtBottom: B,
730
- scrollTop: it,
731
- scrollHeight: et,
732
- clientHeight: ct
733
- }), B || j >= Q ? (console.log(
734
- B ? "Successfully reached bottom!" : "Timeout - giving up"
735
- ), clearInterval(P.current), P.current = null) : (console.log("Scrolling to", G.scrollHeight), G.scrollTop = G.scrollHeight);
736
690
  }, 100), () => {
737
- console.log("Cleaning up scroll interval"), P.current && (clearInterval(P.current), P.current = null);
691
+ P.current && (clearInterval(P.current), P.current = null);
738
692
  };
739
- }, [k, i, p.startIndex, p.endIndex]), rt(() => {
740
- const $ = u.current;
741
- if (!$) {
742
- console.log("No container for scroll handler");
743
- return;
744
- }
745
- console.log("Setting up scroll handler");
746
- let E;
747
- const W = () => {
748
- P.current && (console.log("User scrolled - stopping auto-scroll"), clearInterval(P.current), P.current = null);
749
- const { scrollTop: j, scrollHeight: Q, clientHeight: G } = $, it = Q - j - G < 10;
750
- M.current = it, console.log("User scroll - at bottom:", it), clearTimeout(E), N.current = !0, E = setTimeout(() => {
751
- N.current = !1, console.log("User stopped scrolling");
752
- }, 150);
753
- let et = 0;
754
- for (let B = 0; B < C.length; B++)
755
- if (C[B] > j - n * a) {
756
- et = Math.max(0, B - 1);
693
+ }, [b, i, p.startIndex, p.endIndex]), nt(() => {
694
+ const V = u.current;
695
+ if (!V) return;
696
+ const k = () => {
697
+ if ($.current)
698
+ return;
699
+ const { scrollTop: W, scrollHeight: G, clientHeight: Z } = V, ht = G - W - Z < 50;
700
+ P.current && (clearInterval(P.current), P.current = null), M.current = ht;
701
+ let ot = 0;
702
+ for (let q = 0; q < C.length; q++)
703
+ if (C[q] > W - n * a) {
704
+ ot = Math.max(0, q - 1);
757
705
  break;
758
706
  }
759
- let ct = et;
760
- const St = j + G;
761
- for (let B = et; B < C.length && !(C[B] > St + n * a); B++)
762
- ct = B;
763
- const lt = {
764
- startIndex: Math.max(0, et),
765
- endIndex: Math.min(k, ct + 1 + a)
766
- };
767
- console.log("Updating visible range:", lt), T(lt);
707
+ let ut = ot;
708
+ const vt = W + Z;
709
+ for (let q = ot; q < C.length && !(C[q] > vt + n * a); q++)
710
+ ut = q;
711
+ T({
712
+ startIndex: Math.max(0, ot),
713
+ endIndex: Math.min(b, ut + 1 + a)
714
+ });
768
715
  };
769
- return $.addEventListener("scroll", W, {
716
+ return V.addEventListener("scroll", k, {
770
717
  passive: !0
771
- }), console.log("Initial scroll calculation"), W(), () => {
772
- console.log("Removing scroll handler"), $.removeEventListener("scroll", W), clearTimeout(E);
718
+ }), k(), () => {
719
+ V.removeEventListener("scroll", k);
773
720
  };
774
- }, [C, k, n, a]);
775
- const A = bt(
776
- ($ = "auto") => {
777
- console.log("Manual scrollToBottom called"), M.current = !0, u.current && (u.current.scrollTop = u.current.scrollHeight);
721
+ }, [C, b, n, a]);
722
+ const E = $t(
723
+ (V = "auto") => {
724
+ M.current = !0, $.current = !0, u.current && (u.current.scrollTop = u.current.scrollHeight), setTimeout(() => {
725
+ $.current = !1;
726
+ }, 100);
778
727
  },
779
728
  []
780
- ), D = bt(
781
- ($, E = "smooth") => {
782
- console.log("scrollToIndex called:", $), u.current && C[$] !== void 0 && u.current.scrollTo({
783
- top: C[$],
784
- behavior: E
785
- });
729
+ ), D = $t(
730
+ (V, k = "smooth") => {
731
+ $.current = !0, u.current && C[V] !== void 0 && u.current.scrollTo({
732
+ top: C[V],
733
+ behavior: k
734
+ }), setTimeout(() => {
735
+ $.current = !1;
736
+ }, 100);
786
737
  },
787
738
  [C]
788
- ), U = {
739
+ ), R = {
789
740
  outer: {
790
741
  ref: u,
791
742
  style: { overflowY: "auto", height: "100%" }
792
743
  },
793
744
  inner: {
794
745
  style: {
795
- height: `${V}px`,
746
+ height: `${N}px`,
796
747
  position: "relative"
797
748
  }
798
749
  },
@@ -802,14 +753,10 @@ function vt(t, c, S, g) {
802
753
  }
803
754
  }
804
755
  };
805
- return console.log("Returning virtualizer with props:", {
806
- range: p,
807
- totalHeight: V,
808
- startPosition: C[p.startIndex] || 0
809
- }), {
756
+ return {
810
757
  virtualState: L,
811
- virtualizerProps: U,
812
- scrollToBottom: A,
758
+ virtualizerProps: R,
759
+ scrollToBottom: E,
813
760
  scrollToIndex: D
814
761
  };
815
762
  };
@@ -844,19 +791,19 @@ function vt(t, c, S, g) {
844
791
  const u = n[i], p = [...r, i.toString()], T = s(u, p, f);
845
792
  return e(u, T, {
846
793
  register: () => {
847
- const [, _] = nt({}), N = `${S}-${r.join(".")}-${i}`;
848
- kt(() => {
849
- const M = `${t}////${N}`, P = o.getState().stateComponents.get(t) || {
794
+ const [, _] = et({}), $ = `${S}-${r.join(".")}-${i}`;
795
+ Et(() => {
796
+ const M = `${t}////${$}`, P = o.getState().stateComponents.get(t) || {
850
797
  components: /* @__PURE__ */ new Map()
851
798
  };
852
799
  return P.components.set(M, {
853
800
  forceUpdate: () => _({}),
854
801
  paths: /* @__PURE__ */ new Set([p.join(".")])
855
802
  }), o.getState().stateComponents.set(t, P), () => {
856
- const J = o.getState().stateComponents.get(t);
857
- J && J.components.delete(M);
803
+ const z = o.getState().stateComponents.get(t);
804
+ z && z.components.delete(M);
858
805
  };
859
- }, [t, N]);
806
+ }, [t, $]);
860
807
  },
861
808
  index: v,
862
809
  originalIndex: i
@@ -880,7 +827,7 @@ function vt(t, c, S, g) {
880
827
  );
881
828
  });
882
829
  if (l === "$stateMap")
883
- return (e) => ut(Xt, {
830
+ return (e) => ct(Qt, {
884
831
  proxy: {
885
832
  _stateKey: t,
886
833
  _path: r,
@@ -893,11 +840,11 @@ function vt(t, c, S, g) {
893
840
  return (e) => {
894
841
  const n = o.getState().getNestedState(t, r);
895
842
  return Array.isArray(n) ? (f?.validIndices || Array.from({ length: n.length }, (i, v) => v)).map((i, v) => {
896
- const u = n[i], p = [...r, i.toString()], T = s(u, p, f), b = `${S}-${r.join(".")}-${i}`;
897
- return ut(Kt, {
843
+ const u = n[i], p = [...r, i.toString()], T = s(u, p, f), A = `${S}-${r.join(".")}-${i}`;
844
+ return ct(te, {
898
845
  key: i,
899
846
  stateKey: t,
900
- itemComponentId: b,
847
+ itemComponentId: A,
901
848
  itemPath: p,
902
849
  children: e(
903
850
  u,
@@ -948,25 +895,25 @@ function vt(t, c, S, g) {
948
895
  if (!i.some((T) => {
949
896
  if (n) {
950
897
  const _ = n.every(
951
- (N) => q(T[N], v[N])
898
+ ($) => J(T[$], v[$])
952
899
  );
953
900
  return _ && (u = T), _;
954
901
  }
955
- const b = q(T, v);
956
- return b && (u = T), b;
902
+ const A = J(T, v);
903
+ return A && (u = T), A;
957
904
  }))
958
905
  w(r), yt(c, v, r, t);
959
906
  else if (a && u) {
960
- const T = a(u), b = i.map(
961
- (_) => q(_, u) ? T : _
907
+ const T = a(u), A = i.map(
908
+ (_) => J(_, u) ? T : _
962
909
  );
963
- w(r), dt(c, b, r);
910
+ w(r), it(c, A, r);
964
911
  }
965
912
  };
966
913
  if (l === "cut")
967
914
  return (e, n) => {
968
915
  if (!n?.waitForSync)
969
- return w(r), mt(c, r, t, e), s(
916
+ return w(r), gt(c, r, t, e), s(
970
917
  o.getState().getNestedState(t, r),
971
918
  r
972
919
  );
@@ -974,12 +921,12 @@ function vt(t, c, S, g) {
974
921
  if (l === "cutByValue")
975
922
  return (e) => {
976
923
  for (let n = 0; n < h.length; n++)
977
- h[n] === e && mt(c, r, t, n);
924
+ h[n] === e && gt(c, r, t, n);
978
925
  };
979
926
  if (l === "toggleByValue")
980
927
  return (e) => {
981
928
  const n = h.findIndex((a) => a === e);
982
- n > -1 ? mt(c, r, t, n) : yt(c, e, r, t);
929
+ n > -1 ? gt(c, r, t, n) : yt(c, e, r, t);
983
930
  };
984
931
  if (l === "stateFind")
985
932
  return (e) => {
@@ -1004,7 +951,7 @@ function vt(t, c, S, g) {
1004
951
  if (!isNaN(Number(tt))) {
1005
952
  const d = r.slice(0, -1), e = o.getState().getNestedState(t, d);
1006
953
  if (Array.isArray(e) && l === "cut")
1007
- return () => mt(
954
+ return () => gt(
1008
955
  c,
1009
956
  d,
1010
957
  t,
@@ -1020,13 +967,13 @@ function vt(t, c, S, g) {
1020
967
  return o.getState().getNestedState(t, r);
1021
968
  };
1022
969
  if (l === "$derive")
1023
- return (d) => Nt({
970
+ return (d) => Ct({
1024
971
  _stateKey: t,
1025
972
  _path: r,
1026
973
  _effect: d.toString()
1027
974
  });
1028
975
  if (l === "$get")
1029
- return () => Nt({
976
+ return () => Ct({
1030
977
  _stateKey: t,
1031
978
  _path: r
1032
979
  });
@@ -1035,7 +982,7 @@ function vt(t, c, S, g) {
1035
982
  return o.getState().getSyncInfo(d);
1036
983
  }
1037
984
  if (l == "getLocalStorage")
1038
- return (d) => pt(g + "-" + t + "-" + d);
985
+ return (d) => mt(g + "-" + t + "-" + d);
1039
986
  if (l === "_selected") {
1040
987
  const d = r.slice(0, -1), e = d.join("."), n = o.getState().getNestedState(t, d);
1041
988
  return Array.isArray(n) ? Number(r[r.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
@@ -1045,7 +992,7 @@ function vt(t, c, S, g) {
1045
992
  const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
1046
993
  d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
1047
994
  const i = o.getState().getNestedState(t, [...e]);
1048
- dt(c, i, e), w(e);
995
+ it(c, i, e), w(e);
1049
996
  };
1050
997
  if (l === "toggleSelected")
1051
998
  return () => {
@@ -1056,7 +1003,7 @@ function vt(t, c, S, g) {
1056
1003
  a === e ? void 0 : e
1057
1004
  );
1058
1005
  const i = o.getState().getNestedState(t, [...d]);
1059
- dt(c, i, d), w(d);
1006
+ it(c, i, d), w(d);
1060
1007
  };
1061
1008
  if (r.length == 0) {
1062
1009
  if (l === "addValidation")
@@ -1064,15 +1011,15 @@ function vt(t, c, S, g) {
1064
1011
  const e = o.getState().getInitialOptions(t)?.validation;
1065
1012
  if (!e?.key)
1066
1013
  throw new Error("Validation key not found");
1067
- Z(e.key), console.log("addValidationError", d), d.forEach((n) => {
1014
+ X(e.key), console.log("addValidationError", d), d.forEach((n) => {
1068
1015
  const a = [e.key, ...n.path].join(".");
1069
1016
  console.log("fullErrorPath", a), Mt(a, n.message);
1070
- }), gt(t);
1017
+ }), lt(t);
1071
1018
  };
1072
1019
  if (l === "applyJsonPatch")
1073
1020
  return (d) => {
1074
- const e = o.getState().cogsStateStore[t], a = Gt(e, d).newDocument;
1075
- Rt(
1021
+ const e = o.getState().cogsStateStore[t], a = Ht(e, d).newDocument;
1022
+ jt(
1076
1023
  t,
1077
1024
  o.getState().initialStateGlobal[t],
1078
1025
  a,
@@ -1082,57 +1029,57 @@ function vt(t, c, S, g) {
1082
1029
  );
1083
1030
  const i = o.getState().stateComponents.get(t);
1084
1031
  if (i) {
1085
- const v = Tt(e, a), u = new Set(v);
1032
+ const v = wt(e, a), u = new Set(v);
1086
1033
  for (const [
1087
1034
  p,
1088
1035
  T
1089
1036
  ] of i.components.entries()) {
1090
- let b = !1;
1037
+ let A = !1;
1091
1038
  const _ = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
1092
1039
  if (!_.includes("none")) {
1093
1040
  if (_.includes("all")) {
1094
1041
  T.forceUpdate();
1095
1042
  continue;
1096
1043
  }
1097
- if (_.includes("component") && (T.paths.has("") && (b = !0), !b))
1098
- for (const N of u) {
1099
- if (T.paths.has(N)) {
1100
- b = !0;
1044
+ if (_.includes("component") && (T.paths.has("") && (A = !0), !A))
1045
+ for (const $ of u) {
1046
+ if (T.paths.has($)) {
1047
+ A = !0;
1101
1048
  break;
1102
1049
  }
1103
- let M = N.lastIndexOf(".");
1050
+ let M = $.lastIndexOf(".");
1104
1051
  for (; M !== -1; ) {
1105
- const P = N.substring(0, M);
1052
+ const P = $.substring(0, M);
1106
1053
  if (T.paths.has(P)) {
1107
- b = !0;
1054
+ A = !0;
1108
1055
  break;
1109
1056
  }
1110
- const J = N.substring(
1057
+ const z = $.substring(
1111
1058
  M + 1
1112
1059
  );
1113
- if (!isNaN(Number(J))) {
1114
- const k = P.lastIndexOf(".");
1115
- if (k !== -1) {
1116
- const V = P.substring(
1060
+ if (!isNaN(Number(z))) {
1061
+ const b = P.lastIndexOf(".");
1062
+ if (b !== -1) {
1063
+ const N = P.substring(
1117
1064
  0,
1118
- k
1065
+ b
1119
1066
  );
1120
- if (T.paths.has(V)) {
1121
- b = !0;
1067
+ if (T.paths.has(N)) {
1068
+ A = !0;
1122
1069
  break;
1123
1070
  }
1124
1071
  }
1125
1072
  }
1126
1073
  M = P.lastIndexOf(".");
1127
1074
  }
1128
- if (b) break;
1075
+ if (A) break;
1129
1076
  }
1130
- if (!b && _.includes("deps") && T.depsFunction) {
1131
- const N = T.depsFunction(a);
1077
+ if (!A && _.includes("deps") && T.depsFunction) {
1078
+ const $ = T.depsFunction(a);
1132
1079
  let M = !1;
1133
- typeof N == "boolean" ? N && (M = !0) : q(T.deps, N) || (T.deps = N, M = !0), M && (b = !0);
1080
+ typeof $ == "boolean" ? $ && (M = !0) : J(T.deps, $) || (T.deps = $, M = !0), M && (A = !0);
1134
1081
  }
1135
- b && T.forceUpdate();
1082
+ A && T.forceUpdate();
1136
1083
  }
1137
1084
  }
1138
1085
  }
@@ -1144,18 +1091,18 @@ function vt(t, c, S, g) {
1144
1091
  throw new Error("Zod schema not found");
1145
1092
  if (!d?.key)
1146
1093
  throw new Error("Validation key not found");
1147
- Z(d.key);
1094
+ X(d.key);
1148
1095
  const n = o.getState().cogsStateStore[t];
1149
1096
  try {
1150
1097
  const a = o.getState().getValidationErrors(d.key);
1151
1098
  a && a.length > 0 && a.forEach(([v]) => {
1152
- v && v.startsWith(d.key) && Z(v);
1099
+ v && v.startsWith(d.key) && X(v);
1153
1100
  });
1154
1101
  const i = d.zodSchema.safeParse(n);
1155
1102
  return i.success ? !0 : (i.error.errors.forEach((u) => {
1156
- const p = u.path, T = u.message, b = [d.key, ...p].join(".");
1157
- e(b, T);
1158
- }), gt(t), !1);
1103
+ const p = u.path, T = u.message, A = [d.key, ...p].join(".");
1104
+ e(A, T);
1105
+ }), lt(t), !1);
1159
1106
  } catch (a) {
1160
1107
  return console.error("Zod schema validation failed", a), !1;
1161
1108
  }
@@ -1164,7 +1111,7 @@ function vt(t, c, S, g) {
1164
1111
  if (l === "getComponents")
1165
1112
  return () => o().stateComponents.get(t);
1166
1113
  if (l === "getAllFormRefs")
1167
- return () => $t.getState().getFormRefsByStateKey(t);
1114
+ return () => bt.getState().getFormRefsByStateKey(t);
1168
1115
  if (l === "_initialState")
1169
1116
  return o.getState().initialStateGlobal[t];
1170
1117
  if (l === "_serverState")
@@ -1177,13 +1124,13 @@ function vt(t, c, S, g) {
1177
1124
  if (l === "removeValidation") return I.removeValidation;
1178
1125
  }
1179
1126
  if (l === "getFormRef")
1180
- return () => $t.getState().getFormRef(t + "." + r.join("."));
1127
+ return () => bt.getState().getFormRef(t + "." + r.join("."));
1181
1128
  if (l === "validationWrapper")
1182
1129
  return ({
1183
1130
  children: d,
1184
1131
  hideMessage: e
1185
1132
  }) => /* @__PURE__ */ It(
1186
- Dt,
1133
+ Wt,
1187
1134
  {
1188
1135
  formOpts: e ? { validation: { message: "" } } : void 0,
1189
1136
  path: r,
@@ -1199,13 +1146,13 @@ function vt(t, c, S, g) {
1199
1146
  if (l === "update")
1200
1147
  return (d, e) => {
1201
1148
  if (e?.debounce)
1202
- Ft(() => {
1203
- dt(c, d, r, "");
1149
+ Dt(() => {
1150
+ it(c, d, r, "");
1204
1151
  const n = o.getState().getNestedState(t, r);
1205
1152
  e?.afterUpdate && e.afterUpdate(n);
1206
1153
  }, e.debounce);
1207
1154
  else {
1208
- dt(c, d, r, "");
1155
+ it(c, d, r, "");
1209
1156
  const n = o.getState().getNestedState(t, r);
1210
1157
  e?.afterUpdate && e.afterUpdate(n);
1211
1158
  }
@@ -1213,7 +1160,7 @@ function vt(t, c, S, g) {
1213
1160
  };
1214
1161
  if (l === "formElement")
1215
1162
  return (d, e) => /* @__PURE__ */ It(
1216
- Wt,
1163
+ Lt,
1217
1164
  {
1218
1165
  setState: c,
1219
1166
  stateKey: t,
@@ -1222,23 +1169,23 @@ function vt(t, c, S, g) {
1222
1169
  formOpts: e
1223
1170
  }
1224
1171
  );
1225
- const R = [...r, l], st = o.getState().getNestedState(t, R);
1226
- return s(st, R, f);
1172
+ const j = [...r, l], st = o.getState().getNestedState(t, j);
1173
+ return s(st, j, f);
1227
1174
  }
1228
- }, z = new Proxy(O, F);
1175
+ }, B = new Proxy(U, F);
1229
1176
  return y.set(H, {
1230
- proxy: z,
1177
+ proxy: B,
1231
1178
  stateVersion: x
1232
- }), z;
1179
+ }), B;
1233
1180
  }
1234
1181
  return s(
1235
1182
  o.getState().getNestedState(t, [])
1236
1183
  );
1237
1184
  }
1238
- function Nt(t) {
1239
- return ut(Qt, { proxy: t });
1185
+ function Ct(t) {
1186
+ return ct(Kt, { proxy: t });
1240
1187
  }
1241
- function Xt({
1188
+ function Qt({
1242
1189
  proxy: t,
1243
1190
  rebuildStateShape: c
1244
1191
  }) {
@@ -1250,11 +1197,11 @@ function Xt({
1250
1197
  (y, x, w, I, s) => t._mapFn(y, x, w, I, s)
1251
1198
  ) : null;
1252
1199
  }
1253
- function Qt({
1200
+ function Kt({
1254
1201
  proxy: t
1255
1202
  }) {
1256
- const c = X(null), S = `${t._stateKey}-${t._path.join(".")}`;
1257
- return rt(() => {
1203
+ const c = Q(null), S = `${t._stateKey}-${t._path.join(".")}`;
1204
+ return nt(() => {
1258
1205
  const g = c.current;
1259
1206
  if (!g || !g.parentElement) return;
1260
1207
  const y = g.parentElement, w = Array.from(y.childNodes).indexOf(g);
@@ -1275,22 +1222,22 @@ function Qt({
1275
1222
  "state",
1276
1223
  `return (${t._effect})(state)`
1277
1224
  )(r);
1278
- } catch (O) {
1279
- console.error("Error evaluating effect function during mount:", O), f = r;
1225
+ } catch (U) {
1226
+ console.error("Error evaluating effect function during mount:", U), f = r;
1280
1227
  }
1281
1228
  else
1282
1229
  f = r;
1283
1230
  f !== null && typeof f == "object" && (f = JSON.stringify(f));
1284
1231
  const H = document.createTextNode(String(f));
1285
1232
  g.replaceWith(H);
1286
- }, [t._stateKey, t._path.join("."), t._effect]), ut("span", {
1233
+ }, [t._stateKey, t._path.join("."), t._effect]), ct("span", {
1287
1234
  ref: c,
1288
1235
  style: { display: "none" },
1289
1236
  "data-signal-id": S
1290
1237
  });
1291
1238
  }
1292
- function Se(t) {
1293
- const c = Ut(
1239
+ function me(t) {
1240
+ const c = Ot(
1294
1241
  (S) => {
1295
1242
  const g = o.getState().stateComponents.get(t._stateKey) || {
1296
1243
  components: /* @__PURE__ */ new Map()
@@ -1302,22 +1249,22 @@ function Se(t) {
1302
1249
  },
1303
1250
  () => o.getState().getNestedState(t._stateKey, t._path)
1304
1251
  );
1305
- return ut("text", {}, String(c));
1252
+ return ct("text", {}, String(c));
1306
1253
  }
1307
- function Kt({
1254
+ function te({
1308
1255
  stateKey: t,
1309
1256
  itemComponentId: c,
1310
1257
  itemPath: S,
1311
1258
  children: g
1312
1259
  }) {
1313
- const [, y] = nt({}), [x, w] = Bt(), I = X(null);
1314
- return rt(() => {
1260
+ const [, y] = et({}), [x, w] = Bt(), I = Q(null);
1261
+ return nt(() => {
1315
1262
  w.height > 0 && w.height !== I.current && (I.current = w.height, o.getState().setShadowMetadata(t, S, {
1316
1263
  virtualizer: {
1317
1264
  itemHeight: w.height
1318
1265
  }
1319
1266
  }));
1320
- }, [w.height, t, S]), kt(() => {
1267
+ }, [w.height, t, S]), Et(() => {
1321
1268
  const s = `${t}////${c}`, h = o.getState().stateComponents.get(t) || {
1322
1269
  components: /* @__PURE__ */ new Map()
1323
1270
  };
@@ -1331,11 +1278,11 @@ function Kt({
1331
1278
  }, [t, c, S.join(".")]), /* @__PURE__ */ It("div", { ref: x, children: g });
1332
1279
  }
1333
1280
  export {
1334
- Nt as $cogsSignal,
1335
- Se as $cogsSignalStore,
1336
- ue as addStateOptions,
1337
- ge as createCogsState,
1338
- fe as notifyComponent,
1339
- Zt as useCogsStateFn
1281
+ Ct as $cogsSignal,
1282
+ me as $cogsSignalStore,
1283
+ ge as addStateOptions,
1284
+ fe as createCogsState,
1285
+ Se as notifyComponent,
1286
+ Xt as useCogsStateFn
1340
1287
  };
1341
1288
  //# sourceMappingURL=CogsState.jsx.map