cogsbox-state 0.5.326 → 0.5.327

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 mt } from "react/jsx-runtime";
3
- import { useState as X, useRef as Q, useEffect as nt, useLayoutEffect as ct, useMemo as ht, createElement as at, useSyncExternalStore as xt, startTransition as Pt, useCallback as wt } from "react";
4
- import { transformStateFunc as _t, isDeepEqual as H, isFunction as J, getNestedValue as z, getDifferences as vt, debounce as Mt } from "./utility.js";
5
- import { pushFunc as St, updateFn as ot, cutFunc as it, ValidationWrapper as jt, FormControlComponent as Ot } from "./Functions.jsx";
6
- import Rt from "superjson";
7
- import { v4 as yt } from "uuid";
2
+ import { jsx as vt } from "react/jsx-runtime";
3
+ import { useState as Q, useRef as B, useEffect as nt, useLayoutEffect as dt, useMemo as yt, createElement as st, useSyncExternalStore as _t, startTransition as Mt, useCallback as Et } from "react";
4
+ import { transformStateFunc as Rt, isDeepEqual as H, isFunction as Y, getNestedValue as z, getDifferences as It, debounce as jt } from "./utility.js";
5
+ import { pushFunc as ht, updateFn as at, cutFunc as lt, ValidationWrapper as Ot, FormControlComponent as Ut } from "./Functions.jsx";
6
+ import Ft from "superjson";
7
+ import { v4 as pt } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as o, formRefStore as Tt } from "./store.js";
10
- import { useCogsConfig as bt } from "./CogsStateClient.jsx";
11
- import { applyPatch as Ut } from "fast-json-patch";
12
- import Ft from "react-use-measure";
13
- function Et(t, c) {
9
+ import { getGlobalStore as o, formRefStore as At } from "./store.js";
10
+ import { useCogsConfig as Ct } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Dt } from "fast-json-patch";
12
+ import Lt from "react-use-measure";
13
+ function $t(t, c) {
14
14
  const h = o.getState().getInitialOptions, S = o.getState().setInitialStateOptions, I = h(t) || {};
15
15
  S(t, {
16
16
  ...I,
17
17
  ...c
18
18
  });
19
19
  }
20
- function At({
20
+ function kt({
21
21
  stateKey: t,
22
22
  options: c,
23
23
  initialOptionsPart: h
@@ -30,12 +30,12 @@ function At({
30
30
  !H(w[a], c[a]) && (p = !0, w[a] = c[a])) : (p = !0, w[a] = c[a]);
31
31
  p && b(t, w);
32
32
  }
33
- function ie(t, { formElements: c, validation: h }) {
33
+ function le(t, { formElements: c, validation: h }) {
34
34
  return { initialState: t, formElements: c, validation: h };
35
35
  }
36
- const ce = (t, c) => {
36
+ const de = (t, c) => {
37
37
  let h = t;
38
- const [S, I] = _t(h);
38
+ const [S, I] = Rt(h);
39
39
  (Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((p) => {
40
40
  I[p] = I[p] || {}, I[p].formElements = {
41
41
  ...c?.formElements,
@@ -46,13 +46,13 @@ const ce = (t, c) => {
46
46
  }, et(p) || o.getState().setInitialStateOptions(p, I[p]);
47
47
  }), o.getState().setInitialStates(S), o.getState().setCreatedState(S);
48
48
  const b = (p, a) => {
49
- const [y] = X(a?.componentId ?? yt());
50
- At({
49
+ const [y] = Q(a?.componentId ?? pt());
50
+ kt({
51
51
  stateKey: p,
52
52
  options: a,
53
53
  initialOptionsPart: I
54
54
  });
55
- const n = o.getState().cogsStateStore[p] || S[p], m = a?.modifyState ? a.modifyState(n) : n, [L, R] = Bt(
55
+ const n = o.getState().cogsStateStore[p] || S[p], m = a?.modifyState ? a.modifyState(n) : n, [W, O] = Jt(
56
56
  m,
57
57
  {
58
58
  stateKey: p,
@@ -68,49 +68,49 @@ const ce = (t, c) => {
68
68
  serverState: a?.serverState
69
69
  }
70
70
  );
71
- return R;
71
+ return O;
72
72
  };
73
73
  function w(p, a) {
74
- At({ stateKey: p, options: a, initialOptionsPart: I }), a.localStorage && Ht(p, a), gt(p);
74
+ kt({ stateKey: p, options: a, initialOptionsPart: I }), a.localStorage && Bt(p, a), St(p);
75
75
  }
76
76
  return { useCogsState: b, setCogsOptions: w };
77
77
  }, {
78
- setUpdaterState: lt,
78
+ setUpdaterState: ut,
79
79
  setState: K,
80
80
  getInitialOptions: et,
81
- getKeyState: Nt,
82
- getValidationErrors: Dt,
83
- setStateLog: Wt,
84
- updateInitialStateGlobal: It,
85
- addValidationError: Lt,
86
- removeValidationError: q,
87
- setServerSyncActions: Gt
88
- } = o.getState(), $t = (t, c, h, S, I) => {
81
+ getKeyState: Vt,
82
+ getValidationErrors: Wt,
83
+ setStateLog: Gt,
84
+ updateInitialStateGlobal: wt,
85
+ addValidationError: Ht,
86
+ removeValidationError: J,
87
+ setServerSyncActions: zt
88
+ } = o.getState(), bt = (t, c, h, S, I) => {
89
89
  h?.log && console.log(
90
90
  "saving to localstorage",
91
91
  c,
92
92
  h.localStorage?.key,
93
93
  S
94
94
  );
95
- const b = J(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
95
+ const b = Y(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
96
96
  if (b && S) {
97
97
  const w = `${S}-${c}-${b}`;
98
98
  let p;
99
99
  try {
100
- p = ut(w)?.lastSyncedWithServer;
100
+ p = ft(w)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const a = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: I ?? p
107
- }, y = Rt.serialize(a);
107
+ }, y = Ft.serialize(a);
108
108
  window.localStorage.setItem(
109
109
  w,
110
110
  JSON.stringify(y.json)
111
111
  );
112
112
  }
113
- }, ut = (t) => {
113
+ }, ft = (t) => {
114
114
  if (!t) return null;
115
115
  try {
116
116
  const c = window.localStorage.getItem(t);
@@ -118,20 +118,20 @@ const ce = (t, c) => {
118
118
  } catch (c) {
119
119
  return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
- }, Ht = (t, c) => {
122
- const h = o.getState().cogsStateStore[t], { sessionId: S } = bt(), I = J(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
121
+ }, Bt = (t, c) => {
122
+ const h = o.getState().cogsStateStore[t], { sessionId: S } = Ct(), I = Y(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
123
123
  if (I && S) {
124
- const b = ut(
124
+ const b = ft(
125
125
  `${S}-${t}-${I}`
126
126
  );
127
127
  if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
128
- return K(t, b.state), gt(t), !0;
128
+ return K(t, b.state), St(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Vt = (t, c, h, S, I, b) => {
131
+ }, xt = (t, c, h, S, I, b) => {
132
132
  const w = {
133
133
  initialState: c,
134
- updaterState: dt(
134
+ updaterState: gt(
135
135
  t,
136
136
  S,
137
137
  I,
@@ -139,8 +139,8 @@ const ce = (t, c) => {
139
139
  ),
140
140
  state: h
141
141
  };
142
- It(t, w.initialState), lt(t, w.updaterState), K(t, w.state);
143
- }, gt = (t) => {
142
+ wt(t, w.initialState), ut(t, w.updaterState), K(t, w.state);
143
+ }, St = (t) => {
144
144
  const c = o.getState().stateComponents.get(t);
145
145
  if (!c) return;
146
146
  const h = /* @__PURE__ */ new Set();
@@ -149,7 +149,7 @@ const ce = (t, c) => {
149
149
  }), queueMicrotask(() => {
150
150
  h.forEach((S) => S());
151
151
  });
152
- }, le = (t, c) => {
152
+ }, ue = (t, c) => {
153
153
  const h = o.getState().stateComponents.get(t);
154
154
  if (h) {
155
155
  const S = `${t}////${c}`, I = h.components.get(S);
@@ -157,7 +157,7 @@ const ce = (t, c) => {
157
157
  return;
158
158
  I && I.forceUpdate();
159
159
  }
160
- }, zt = (t, c, h, S) => {
160
+ }, qt = (t, c, h, S) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
@@ -180,7 +180,7 @@ const ce = (t, c) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Bt(t, {
183
+ function Jt(t, {
184
184
  stateKey: c,
185
185
  serverSync: h,
186
186
  localStorage: S,
@@ -193,12 +193,12 @@ function Bt(t, {
193
193
  dependencies: n,
194
194
  serverState: m
195
195
  } = {}) {
196
- const [L, R] = X({}), { sessionId: U } = bt();
196
+ const [W, O] = Q({}), { sessionId: U } = Ct();
197
197
  let G = !c;
198
- const [v] = X(c ?? yt()), l = o.getState().stateLog[v], st = Q(/* @__PURE__ */ new Set()), Y = Q(p ?? yt()), j = Q(
198
+ const [v] = Q(c ?? pt()), l = o.getState().stateLog[v], it = B(/* @__PURE__ */ new Set()), Z = B(p ?? pt()), R = B(
199
199
  null
200
200
  );
201
- j.current = et(v) ?? null, nt(() => {
201
+ R.current = et(v) ?? null, nt(() => {
202
202
  if (y && y.stateKey === v && y.path?.[0]) {
203
203
  K(v, (r) => ({
204
204
  ...r,
@@ -212,169 +212,169 @@ function Bt(t, {
212
212
  }
213
213
  }, [y]), nt(() => {
214
214
  if (a) {
215
- Et(v, {
215
+ $t(v, {
216
216
  initialState: a
217
217
  });
218
- const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[v];
218
+ const e = R.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[v];
219
219
  if (!(i && !H(i, a) || !i) && !s)
220
220
  return;
221
221
  let g = null;
222
- const E = J(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
- E && U && (g = ut(`${U}-${v}-${E}`));
224
- let T = a, A = !1;
225
- const P = s ? Date.now() : 0, V = g?.lastUpdated || 0, k = g?.lastSyncedWithServer || 0;
226
- s && P > V ? (T = e.serverState.data, A = !0) : g && V > k && (T = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(v, a), Vt(
222
+ const E = Y(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
+ E && U && (g = ft(`${U}-${v}-${E}`));
224
+ let T = a, $ = !1;
225
+ const P = s ? Date.now() : 0, C = g?.lastUpdated || 0, A = g?.lastSyncedWithServer || 0;
226
+ s && P > C ? (T = e.serverState.data, $ = !0) : g && C > A && (T = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(v, a), xt(
227
227
  v,
228
228
  a,
229
229
  T,
230
230
  rt,
231
- Y.current,
231
+ Z.current,
232
232
  U
233
- ), A && E && U && $t(T, v, e, U, Date.now()), gt(v), (Array.isArray(w) ? w : [w || "component"]).includes("none") || R({});
233
+ ), $ && E && U && bt(T, v, e, U, Date.now()), St(v), (Array.isArray(w) ? w : [w || "component"]).includes("none") || O({});
234
234
  }
235
235
  }, [
236
236
  a,
237
237
  m?.status,
238
238
  m?.data,
239
239
  ...n || []
240
- ]), ct(() => {
241
- G && Et(v, {
240
+ ]), dt(() => {
241
+ G && $t(v, {
242
242
  serverSync: h,
243
243
  formElements: I,
244
244
  initialState: a,
245
245
  localStorage: S,
246
- middleware: j.current?.middleware
246
+ middleware: R.current?.middleware
247
247
  });
248
- const e = `${v}////${Y.current}`, r = o.getState().stateComponents.get(v) || {
248
+ const e = `${v}////${Z.current}`, r = o.getState().stateComponents.get(v) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return r.components.set(e, {
252
- forceUpdate: () => R({}),
252
+ forceUpdate: () => O({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
255
  depsFunction: b || void 0,
256
256
  reactiveType: w ?? ["component", "deps"]
257
- }), o.getState().stateComponents.set(v, r), R({}), () => {
257
+ }), o.getState().stateComponents.set(v, r), O({}), () => {
258
258
  r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(v));
259
259
  };
260
260
  }, []);
261
261
  const rt = (e, r, s, i) => {
262
262
  if (Array.isArray(r)) {
263
263
  const g = `${v}-${r.join(".")}`;
264
- st.current.add(g);
264
+ it.current.add(g);
265
265
  }
266
266
  const u = o.getState();
267
267
  K(v, (g) => {
268
- const E = J(e) ? e(g) : e, T = `${v}-${r.join(".")}`;
268
+ const E = Y(e) ? e(g) : e, T = `${v}-${r.join(".")}`;
269
269
  if (T) {
270
270
  let M = !1, N = u.signalDomElements.get(T);
271
271
  if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
- const O = r.slice(0, -1), W = z(E, O);
273
- if (Array.isArray(W)) {
272
+ const j = r.slice(0, -1), L = z(E, j);
273
+ if (Array.isArray(L)) {
274
274
  M = !0;
275
- const f = `${v}-${O.join(".")}`;
275
+ const f = `${v}-${j.join(".")}`;
276
276
  N = u.signalDomElements.get(f);
277
277
  }
278
278
  }
279
279
  if (N) {
280
- const O = M ? z(E, r.slice(0, -1)) : z(E, r);
281
- N.forEach(({ parentId: W, position: f, effect: $ }) => {
282
- const C = document.querySelector(
283
- `[data-parent-id="${W}"]`
280
+ const j = M ? z(E, r.slice(0, -1)) : z(E, r);
281
+ N.forEach(({ parentId: L, position: f, effect: k }) => {
282
+ const V = document.querySelector(
283
+ `[data-parent-id="${L}"]`
284
284
  );
285
- if (C) {
286
- const _ = Array.from(C.childNodes);
285
+ if (V) {
286
+ const _ = Array.from(V.childNodes);
287
287
  if (_[f]) {
288
- const x = $ ? new Function("state", `return (${$})(state)`)(O) : O;
288
+ const x = k ? new Function("state", `return (${k})(state)`)(j) : j;
289
289
  _[f].textContent = String(x);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && r && q(
296
- (i || j.current?.validation?.key) + "." + r.join(".")
295
+ console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || R.current?.validation?.key) && r && J(
296
+ (i || R.current?.validation?.key) + "." + r.join(".")
297
297
  );
298
- const A = r.slice(0, r.length - 1);
299
- s.updateType === "cut" && j.current?.validation?.key && q(
300
- j.current?.validation?.key + "." + A.join(".")
301
- ), s.updateType === "insert" && j.current?.validation?.key && Dt(
302
- j.current?.validation?.key + "." + A.join(".")
303
- ).filter(([N, O]) => {
304
- let W = N?.split(".").length;
305
- if (N == A.join(".") && W == A.length - 1) {
306
- let f = N + "." + A;
307
- q(N), Lt(f, O);
298
+ const $ = r.slice(0, r.length - 1);
299
+ s.updateType === "cut" && R.current?.validation?.key && J(
300
+ R.current?.validation?.key + "." + $.join(".")
301
+ ), s.updateType === "insert" && R.current?.validation?.key && Wt(
302
+ R.current?.validation?.key + "." + $.join(".")
303
+ ).filter(([N, j]) => {
304
+ let L = N?.split(".").length;
305
+ if (N == $.join(".") && L == $.length - 1) {
306
+ let f = N + "." + $;
307
+ J(N), Ht(f, j);
308
308
  }
309
309
  });
310
310
  const P = u.stateComponents.get(v);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", P), P) {
312
- const M = vt(g, E), N = new Set(M), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
312
+ const M = It(g, E), N = new Set(M), j = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
313
313
  for (const [
314
- W,
314
+ L,
315
315
  f
316
316
  ] of P.components.entries()) {
317
- let $ = !1;
318
- const C = Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"];
319
- if (console.log("component", f), !C.includes("none")) {
320
- if (C.includes("all")) {
317
+ let k = !1;
318
+ const V = Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"];
319
+ if (console.log("component", f), !V.includes("none")) {
320
+ if (V.includes("all")) {
321
321
  f.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (C.includes("component") && ((f.paths.has(O) || f.paths.has("")) && ($ = !0), !$))
324
+ if (V.includes("component") && ((f.paths.has(j) || f.paths.has("")) && (k = !0), !k))
325
325
  for (const _ of N) {
326
326
  let x = _;
327
327
  for (; ; ) {
328
328
  if (f.paths.has(x)) {
329
- $ = !0;
329
+ k = !0;
330
330
  break;
331
331
  }
332
- const B = x.lastIndexOf(".");
333
- if (B !== -1) {
334
- const Z = x.substring(
332
+ const q = x.lastIndexOf(".");
333
+ if (q !== -1) {
334
+ const X = x.substring(
335
335
  0,
336
- B
336
+ q
337
337
  );
338
338
  if (!isNaN(
339
- Number(x.substring(B + 1))
340
- ) && f.paths.has(Z)) {
341
- $ = !0;
339
+ Number(x.substring(q + 1))
340
+ ) && f.paths.has(X)) {
341
+ k = !0;
342
342
  break;
343
343
  }
344
- x = Z;
344
+ x = X;
345
345
  } else
346
346
  x = "";
347
347
  if (x === "")
348
348
  break;
349
349
  }
350
- if ($) break;
350
+ if (k) break;
351
351
  }
352
- if (!$ && C.includes("deps") && f.depsFunction) {
352
+ if (!k && V.includes("deps") && f.depsFunction) {
353
353
  const _ = f.depsFunction(E);
354
354
  let x = !1;
355
- typeof _ == "boolean" ? _ && (x = !0) : H(f.deps, _) || (f.deps = _, x = !0), x && ($ = !0);
355
+ typeof _ == "boolean" ? _ && (x = !0) : H(f.deps, _) || (f.deps = _, x = !0), x && (k = !0);
356
356
  }
357
- $ && f.forceUpdate();
357
+ k && f.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const V = Date.now();
361
+ const C = Date.now();
362
362
  r = r.map((M, N) => {
363
- const O = r.slice(0, -1), W = z(E, O);
364
- return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : M;
363
+ const j = r.slice(0, -1), L = z(E, j);
364
+ return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (L.length - 1).toString() : M;
365
365
  });
366
- const { oldValue: k, newValue: F } = zt(
366
+ const { oldValue: A, newValue: F } = qt(
367
367
  s.updateType,
368
368
  g,
369
369
  E,
370
370
  r
371
371
  ), D = {
372
- timeStamp: V,
372
+ timeStamp: C,
373
373
  stateKey: v,
374
374
  path: r,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
- oldValue: k,
377
+ oldValue: A,
378
378
  newValue: F
379
379
  };
380
380
  switch (s.updateType) {
@@ -386,27 +386,27 @@ function Bt(t, {
386
386
  u.insertShadowArrayElement(v, M, F);
387
387
  break;
388
388
  case "cut":
389
- const N = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- u.removeShadowArrayElement(v, N, O);
389
+ const N = r.slice(0, -1), j = parseInt(r[r.length - 1]);
390
+ u.removeShadowArrayElement(v, N, j);
391
391
  break;
392
392
  }
393
- if (Wt(v, (M) => {
394
- const O = [...M ?? [], D].reduce((W, f) => {
395
- const $ = `${f.stateKey}:${JSON.stringify(f.path)}`, C = W.get($);
396
- return C ? (C.timeStamp = Math.max(C.timeStamp, f.timeStamp), C.newValue = f.newValue, C.oldValue = C.oldValue ?? f.oldValue, C.updateType = f.updateType) : W.set($, { ...f }), W;
393
+ if (Gt(v, (M) => {
394
+ const j = [...M ?? [], D].reduce((L, f) => {
395
+ const k = `${f.stateKey}:${JSON.stringify(f.path)}`, V = L.get(k);
396
+ return V ? (V.timeStamp = Math.max(V.timeStamp, f.timeStamp), V.newValue = f.newValue, V.oldValue = V.oldValue ?? f.oldValue, V.updateType = f.updateType) : L.set(k, { ...f }), L;
397
397
  }, /* @__PURE__ */ new Map());
398
- return Array.from(O.values());
399
- }), $t(
398
+ return Array.from(j.values());
399
+ }), bt(
400
400
  E,
401
401
  v,
402
- j.current,
402
+ R.current,
403
403
  U
404
- ), j.current?.middleware && j.current.middleware({
404
+ ), R.current?.middleware && R.current.middleware({
405
405
  updateLog: l,
406
406
  update: D
407
- }), j.current?.serverSync) {
408
- const M = u.serverState[v], N = j.current?.serverSync;
409
- Gt(v, {
407
+ }), R.current?.serverSync) {
408
+ const M = u.serverState[v], N = R.current?.serverSync;
409
+ zt(v, {
410
410
  syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
411
411
  rollBackState: M,
412
412
  actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
@@ -416,24 +416,24 @@ function Bt(t, {
416
416
  return E;
417
417
  });
418
418
  };
419
- o.getState().updaterState[v] || (lt(
419
+ o.getState().updaterState[v] || (ut(
420
420
  v,
421
- dt(
421
+ gt(
422
422
  v,
423
423
  rt,
424
- Y.current,
424
+ Z.current,
425
425
  U
426
426
  )
427
- ), o.getState().cogsStateStore[v] || K(v, t), o.getState().initialStateGlobal[v] || It(v, t));
428
- const d = ht(() => dt(
427
+ ), o.getState().cogsStateStore[v] || K(v, t), o.getState().initialStateGlobal[v] || wt(v, t));
428
+ const d = yt(() => gt(
429
429
  v,
430
430
  rt,
431
- Y.current,
431
+ Z.current,
432
432
  U
433
433
  ), [v, U]);
434
- return [Nt(v), d];
434
+ return [Vt(v), d];
435
435
  }
436
- function dt(t, c, h, S) {
436
+ function gt(t, c, h, S) {
437
437
  const I = /* @__PURE__ */ new Map();
438
438
  let b = 0;
439
439
  const w = (y) => {
@@ -443,15 +443,15 @@ function dt(t, c, h, S) {
443
443
  b++;
444
444
  }, p = {
445
445
  removeValidation: (y) => {
446
- y?.validationKey && q(y.validationKey);
446
+ y?.validationKey && J(y.validationKey);
447
447
  },
448
448
  revertToInitialState: (y) => {
449
449
  const n = o.getState().getInitialOptions(t)?.validation;
450
- n?.key && q(n?.key), y?.validationKey && q(y.validationKey);
450
+ n?.key && J(n?.key), y?.validationKey && J(y.validationKey);
451
451
  const m = o.getState().initialStateGlobal[t];
452
452
  o.getState().clearSelectedIndexesForState(t), I.clear(), b++;
453
- const L = a(m, []), R = et(t), U = J(R?.localStorage?.key) ? R?.localStorage?.key(m) : R?.localStorage?.key, G = `${S}-${t}-${U}`;
454
- G && localStorage.removeItem(G), lt(t, L), K(t, m);
453
+ const W = a(m, []), O = et(t), U = Y(O?.localStorage?.key) ? O?.localStorage?.key(m) : O?.localStorage?.key, G = `${S}-${t}-${U}`;
454
+ G && localStorage.removeItem(G), ut(t, W), K(t, m);
455
455
  const v = o.getState().stateComponents.get(t);
456
456
  return v && v.components.forEach((l) => {
457
457
  l.forceUpdate();
@@ -459,14 +459,14 @@ function dt(t, c, h, S) {
459
459
  },
460
460
  updateInitialState: (y) => {
461
461
  I.clear(), b++;
462
- const n = dt(
462
+ const n = gt(
463
463
  t,
464
464
  c,
465
465
  h,
466
466
  S
467
- ), m = o.getState().initialStateGlobal[t], L = et(t), R = J(L?.localStorage?.key) ? L?.localStorage?.key(m) : L?.localStorage?.key, U = `${S}-${t}-${R}`;
468
- return localStorage.getItem(U) && localStorage.removeItem(U), Pt(() => {
469
- It(t, y), o.getState().initializeShadowState(t, y), lt(t, n), K(t, y);
467
+ ), m = o.getState().initialStateGlobal[t], W = et(t), O = Y(W?.localStorage?.key) ? W?.localStorage?.key(m) : W?.localStorage?.key, U = `${S}-${t}-${O}`;
468
+ return localStorage.getItem(U) && localStorage.removeItem(U), Mt(() => {
469
+ wt(t, y), o.getState().initializeShadowState(t, y), ut(t, n), K(t, y);
470
470
  const G = o.getState().stateComponents.get(t);
471
471
  G && G.components.forEach((v) => {
472
472
  v.forceUpdate();
@@ -480,27 +480,27 @@ function dt(t, c, h, S) {
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
482
  const y = o.getState().serverState[t];
483
- return !!(y && H(y, Nt(t)));
483
+ return !!(y && H(y, Vt(t)));
484
484
  }
485
485
  };
486
486
  function a(y, n = [], m) {
487
- const L = n.map(String).join(".");
488
- I.get(L);
489
- const R = function() {
487
+ const W = n.map(String).join(".");
488
+ I.get(W);
489
+ const O = function() {
490
490
  return o().getNestedState(t, n);
491
491
  };
492
492
  Object.keys(p).forEach((v) => {
493
- R[v] = p[v];
493
+ O[v] = p[v];
494
494
  });
495
495
  const U = {
496
- apply(v, l, st) {
496
+ apply(v, l, it) {
497
497
  return console.log(
498
498
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
499
499
  ), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
500
500
  },
501
501
  get(v, l) {
502
502
  m?.validIndices && !Array.isArray(y) && (m = { ...m, validIndices: void 0 });
503
- const st = /* @__PURE__ */ new Set([
503
+ const it = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,7 +523,7 @@ function dt(t, c, h, S) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !st.has(l)) {
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !it.has(l)) {
527
527
  const d = `${t}////${h}`, e = o.getState().stateComponents.get(t);
528
528
  if (e) {
529
529
  const r = e.components.get(d);
@@ -540,7 +540,7 @@ function dt(t, c, h, S) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => vt(
543
+ return () => It(
544
544
  o.getState().cogsStateStore[t],
545
545
  o.getState().initialStateGlobal[t]
546
546
  );
@@ -581,7 +581,7 @@ function dt(t, c, h, S) {
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
584
- const d = o.getState().initialStateGlobal[t], e = et(t), r = J(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${S}-${t}-${r}`;
584
+ const d = o.getState().initialStateGlobal[t], e = et(t), r = Y(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${S}-${t}-${r}`;
585
585
  s && localStorage.removeItem(s);
586
586
  };
587
587
  if (l === "showValidationErrors")
@@ -621,91 +621,97 @@ function dt(t, c, h, S) {
621
621
  itemHeight: r = 50,
622
622
  overscan: s = 5,
623
623
  stickToBottom: i = !1
624
- } = e, u = Q(null), [g, E] = X({
624
+ } = e, u = B(null), [g, E] = Q({
625
625
  startIndex: 0,
626
626
  endIndex: 10
627
- }), T = Q(i), [A, P] = X(0);
627
+ }), T = B(i), [$, P] = Q(0);
628
628
  nt(() => o.getState().subscribeToShadowState(t, () => {
629
- P(($) => $ + 1);
629
+ P((k) => k + 1);
630
630
  }), [t]);
631
- const V = o().getNestedState(
631
+ const C = o().getNestedState(
632
632
  t,
633
633
  n
634
- ), k = V.length, { totalHeight: F, positions: D } = ht(() => {
634
+ ), A = C.length, { totalHeight: F, positions: D } = yt(() => {
635
635
  const f = o.getState().getShadowMetadata(t, n) || [];
636
- let $ = 0;
637
- const C = [];
638
- for (let _ = 0; _ < k; _++) {
639
- C[_] = $;
636
+ let k = 0;
637
+ const V = [];
638
+ for (let _ = 0; _ < A; _++) {
639
+ V[_] = k;
640
640
  const x = f[_]?.virtualizer?.itemHeight;
641
- $ += x || r;
641
+ k += x || r;
642
642
  }
643
- return { totalHeight: $, positions: C };
643
+ return { totalHeight: k, positions: V };
644
644
  }, [
645
- k,
645
+ A,
646
646
  t,
647
647
  n.join("."),
648
648
  r,
649
- A
650
- ]), M = ht(() => {
651
- const f = Math.max(0, g.startIndex), $ = Math.min(k, g.endIndex), C = Array.from(
652
- { length: $ - f },
653
- (x, B) => f + B
654
- ), _ = C.map((x) => V[x]);
649
+ $
650
+ ]), M = yt(() => {
651
+ const f = Math.max(0, g.startIndex), k = Math.min(A, g.endIndex), V = Array.from(
652
+ { length: k - f },
653
+ (x, q) => f + q
654
+ ), _ = V.map((x) => C[x]);
655
655
  return a(_, n, {
656
656
  ...m,
657
- validIndices: C
657
+ validIndices: V
658
658
  });
659
- }, [g.startIndex, g.endIndex, V, k]);
659
+ }, [g.startIndex, g.endIndex, C, A]);
660
660
  nt(() => {
661
- if (i && k > 0 && u.current) {
662
- const f = u.current, $ = Math.ceil(
661
+ if (i && A > 0 && u.current) {
662
+ const f = u.current, k = Math.ceil(
663
663
  f.clientHeight / r
664
664
  );
665
665
  E({
666
666
  startIndex: Math.max(
667
667
  0,
668
- k - $ - s
668
+ A - k - s
669
669
  ),
670
- endIndex: k
670
+ endIndex: A
671
671
  }), setTimeout(() => {
672
672
  f.scrollTop = f.scrollHeight;
673
673
  }, 100);
674
674
  }
675
- }, [k]), ct(() => {
675
+ }, [A]), dt(() => {
676
676
  const f = u.current;
677
677
  if (!f) return;
678
- let $;
679
- const C = () => {
678
+ let k;
679
+ const V = () => {
680
680
  if (!f) return;
681
- const { scrollTop: x } = f;
682
- let B = 0, Z = k - 1;
683
- for (; B <= Z; ) {
684
- const ft = Math.floor((B + Z) / 2);
685
- D[ft] < x ? B = ft + 1 : Z = ft - 1;
681
+ const { scrollTop: X } = f;
682
+ let ot = 0, ct = A - 1;
683
+ for (; ot <= ct; ) {
684
+ const mt = Math.floor((ot + ct) / 2);
685
+ D[mt] < X ? ot = mt + 1 : ct = mt - 1;
686
686
  }
687
- const pt = Math.max(0, Z - s);
688
- let tt = pt;
689
- const Ct = x + f.clientHeight;
690
- for (; tt < k && D[tt] < Ct; )
687
+ const Tt = Math.max(0, ct - s);
688
+ let tt = Tt;
689
+ const Pt = X + f.clientHeight;
690
+ for (; tt < A && D[tt] < Pt; )
691
691
  tt++;
692
- tt = Math.min(k, tt + s), E({ startIndex: pt, endIndex: tt });
692
+ tt = Math.min(A, tt + s), E({ startIndex: Tt, endIndex: tt });
693
693
  }, _ = () => {
694
- T.current = f.scrollHeight - f.scrollTop - f.clientHeight < 1, C();
694
+ T.current = f.scrollHeight - f.scrollTop - f.clientHeight < 1, V();
695
695
  };
696
- return f.addEventListener("scroll", _, {
696
+ f.addEventListener("scroll", _, {
697
697
  passive: !0
698
- }), i && ($ = setTimeout(() => {
699
- console.log("totalHeight", F), T.current && f.scrollTo({
700
- top: 999999999,
701
- behavior: "auto"
702
- // ALWAYS 'auto' for an instant, correct jump.
703
- });
704
- }, 1e3)), C(), () => {
705
- clearTimeout($), f.removeEventListener("scroll", _);
698
+ });
699
+ const x = B(!1), q = B(0);
700
+ if (i) {
701
+ const X = !x.current && A > 0, ot = x.current && A > q.current;
702
+ k = setTimeout(() => {
703
+ console.log("totalHeight", F), T.current && f.scrollTo({
704
+ top: 999999999,
705
+ behavior: ot ? "smooth" : "auto"
706
+ // Only smooth for NEW items after initial load
707
+ });
708
+ }, 200), X && (x.current = !0);
709
+ }
710
+ return q.current = A, V(), () => {
711
+ clearTimeout(k), f.removeEventListener("scroll", _);
706
712
  };
707
- }, [k, D, F, i]);
708
- const N = wt(
713
+ }, [A, D, F, i]);
714
+ const N = Et(
709
715
  (f = "smooth") => {
710
716
  u.current && (T.current = !0, u.current.scrollTo({
711
717
  top: u.current.scrollHeight,
@@ -713,15 +719,15 @@ function dt(t, c, h, S) {
713
719
  }));
714
720
  },
715
721
  []
716
- ), O = wt(
717
- (f, $ = "smooth") => {
722
+ ), j = Et(
723
+ (f, k = "smooth") => {
718
724
  u.current && D[f] !== void 0 && (T.current = !1, u.current.scrollTo({
719
725
  top: D[f],
720
- behavior: $
726
+ behavior: k
721
727
  }));
722
728
  },
723
729
  [D]
724
- ), W = {
730
+ ), L = {
725
731
  outer: {
726
732
  ref: u,
727
733
  style: { overflowY: "auto", height: "100%" }
@@ -740,9 +746,9 @@ function dt(t, c, h, S) {
740
746
  };
741
747
  return {
742
748
  virtualState: M,
743
- virtualizerProps: W,
749
+ virtualizerProps: L,
744
750
  scrollToBottom: N,
745
- scrollToIndex: O
751
+ scrollToIndex: j
746
752
  };
747
753
  };
748
754
  if (l === "stateSort")
@@ -776,19 +782,19 @@ function dt(t, c, h, S) {
776
782
  const g = r[i], E = [...n, i.toString()], T = a(g, E, m);
777
783
  return e(g, T, {
778
784
  register: () => {
779
- const [, P] = X({}), V = `${h}-${n.join(".")}-${i}`;
780
- ct(() => {
781
- const k = `${t}////${V}`, F = o.getState().stateComponents.get(t) || {
785
+ const [, P] = Q({}), C = `${h}-${n.join(".")}-${i}`;
786
+ dt(() => {
787
+ const A = `${t}////${C}`, F = o.getState().stateComponents.get(t) || {
782
788
  components: /* @__PURE__ */ new Map()
783
789
  };
784
- return F.components.set(k, {
790
+ return F.components.set(A, {
785
791
  forceUpdate: () => P({}),
786
792
  paths: /* @__PURE__ */ new Set([E.join(".")])
787
793
  }), o.getState().stateComponents.set(t, F), () => {
788
794
  const D = o.getState().stateComponents.get(t);
789
- D && D.components.delete(k);
795
+ D && D.components.delete(A);
790
796
  };
791
- }, [t, V]);
797
+ }, [t, C]);
792
798
  },
793
799
  index: u,
794
800
  originalIndex: i
@@ -812,7 +818,7 @@ function dt(t, c, h, S) {
812
818
  );
813
819
  });
814
820
  if (l === "$stateMap")
815
- return (e) => at(qt, {
821
+ return (e) => st(Yt, {
816
822
  proxy: {
817
823
  _stateKey: t,
818
824
  _path: n,
@@ -825,11 +831,11 @@ function dt(t, c, h, S) {
825
831
  return (e) => {
826
832
  const r = o.getState().getNestedState(t, n);
827
833
  return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
828
- const g = r[i], E = [...n, i.toString()], T = a(g, E, m), A = `${h}-${n.join(".")}-${i}`;
829
- return at(Yt, {
834
+ const g = r[i], E = [...n, i.toString()], T = a(g, E, m), $ = `${h}-${n.join(".")}-${i}`;
835
+ return st(Xt, {
830
836
  key: i,
831
837
  stateKey: t,
832
- itemComponentId: A,
838
+ itemComponentId: $,
833
839
  itemPath: E,
834
840
  children: e(
835
841
  g,
@@ -869,36 +875,36 @@ function dt(t, c, h, S) {
869
875
  return a(s, i);
870
876
  };
871
877
  if (l === "insert")
872
- return (e) => (w(n), St(c, e, n, t), a(
878
+ return (e) => (w(n), ht(c, e, n, t), a(
873
879
  o.getState().getNestedState(t, n),
874
880
  n
875
881
  ));
876
882
  if (l === "uniqueInsert")
877
883
  return (e, r, s) => {
878
- const i = o.getState().getNestedState(t, n), u = J(e) ? e(i) : e;
884
+ const i = o.getState().getNestedState(t, n), u = Y(e) ? e(i) : e;
879
885
  let g = null;
880
886
  if (!i.some((T) => {
881
887
  if (r) {
882
888
  const P = r.every(
883
- (V) => H(T[V], u[V])
889
+ (C) => H(T[C], u[C])
884
890
  );
885
891
  return P && (g = T), P;
886
892
  }
887
- const A = H(T, u);
888
- return A && (g = T), A;
893
+ const $ = H(T, u);
894
+ return $ && (g = T), $;
889
895
  }))
890
- w(n), St(c, u, n, t);
896
+ w(n), ht(c, u, n, t);
891
897
  else if (s && g) {
892
- const T = s(g), A = i.map(
898
+ const T = s(g), $ = i.map(
893
899
  (P) => H(P, g) ? T : P
894
900
  );
895
- w(n), ot(c, A, n);
901
+ w(n), at(c, $, n);
896
902
  }
897
903
  };
898
904
  if (l === "cut")
899
905
  return (e, r) => {
900
906
  if (!r?.waitForSync)
901
- return w(n), it(c, n, t, e), a(
907
+ return w(n), lt(c, n, t, e), a(
902
908
  o.getState().getNestedState(t, n),
903
909
  n
904
910
  );
@@ -906,12 +912,12 @@ function dt(t, c, h, S) {
906
912
  if (l === "cutByValue")
907
913
  return (e) => {
908
914
  for (let r = 0; r < y.length; r++)
909
- y[r] === e && it(c, n, t, r);
915
+ y[r] === e && lt(c, n, t, r);
910
916
  };
911
917
  if (l === "toggleByValue")
912
918
  return (e) => {
913
919
  const r = y.findIndex((s) => s === e);
914
- r > -1 ? it(c, n, t, r) : St(c, e, n, t);
920
+ r > -1 ? lt(c, n, t, r) : ht(c, e, n, t);
915
921
  };
916
922
  if (l === "stateFind")
917
923
  return (e) => {
@@ -932,15 +938,15 @@ function dt(t, c, h, S) {
932
938
  return a(i.item, u, m);
933
939
  };
934
940
  }
935
- const Y = n[n.length - 1];
936
- if (!isNaN(Number(Y))) {
941
+ const Z = n[n.length - 1];
942
+ if (!isNaN(Number(Z))) {
937
943
  const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
938
944
  if (Array.isArray(e) && l === "cut")
939
- return () => it(
945
+ return () => lt(
940
946
  c,
941
947
  d,
942
948
  t,
943
- Number(Y)
949
+ Number(Z)
944
950
  );
945
951
  }
946
952
  if (l === "get")
@@ -952,13 +958,13 @@ function dt(t, c, h, S) {
952
958
  return o.getState().getNestedState(t, n);
953
959
  };
954
960
  if (l === "$derive")
955
- return (d) => kt({
961
+ return (d) => Nt({
956
962
  _stateKey: t,
957
963
  _path: n,
958
964
  _effect: d.toString()
959
965
  });
960
966
  if (l === "$get")
961
- return () => kt({
967
+ return () => Nt({
962
968
  _stateKey: t,
963
969
  _path: n
964
970
  });
@@ -967,7 +973,7 @@ function dt(t, c, h, S) {
967
973
  return o.getState().getSyncInfo(d);
968
974
  }
969
975
  if (l == "getLocalStorage")
970
- return (d) => ut(S + "-" + t + "-" + d);
976
+ return (d) => ft(S + "-" + t + "-" + d);
971
977
  if (l === "_selected") {
972
978
  const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
973
979
  return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
@@ -977,7 +983,7 @@ function dt(t, c, h, S) {
977
983
  const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
978
984
  d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
979
985
  const i = o.getState().getNestedState(t, [...e]);
980
- ot(c, i, e), w(e);
986
+ at(c, i, e), w(e);
981
987
  };
982
988
  if (l === "toggleSelected")
983
989
  return () => {
@@ -988,13 +994,13 @@ function dt(t, c, h, S) {
988
994
  s === e ? void 0 : e
989
995
  );
990
996
  const i = o.getState().getNestedState(t, [...d]);
991
- ot(c, i, d), w(d);
997
+ at(c, i, d), w(d);
992
998
  };
993
999
  if (n.length == 0) {
994
1000
  if (l === "applyJsonPatch")
995
1001
  return (d) => {
996
- const e = o.getState().cogsStateStore[t], s = Ut(e, d).newDocument;
997
- Vt(
1002
+ const e = o.getState().cogsStateStore[t], s = Dt(e, d).newDocument;
1003
+ xt(
998
1004
  t,
999
1005
  o.getState().initialStateGlobal[t],
1000
1006
  s,
@@ -1004,33 +1010,33 @@ function dt(t, c, h, S) {
1004
1010
  );
1005
1011
  const i = o.getState().stateComponents.get(t);
1006
1012
  if (i) {
1007
- const u = vt(e, s), g = new Set(u);
1013
+ const u = It(e, s), g = new Set(u);
1008
1014
  for (const [
1009
1015
  E,
1010
1016
  T
1011
1017
  ] of i.components.entries()) {
1012
- let A = !1;
1018
+ let $ = !1;
1013
1019
  const P = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
1014
1020
  if (!P.includes("none")) {
1015
1021
  if (P.includes("all")) {
1016
1022
  T.forceUpdate();
1017
1023
  continue;
1018
1024
  }
1019
- if (P.includes("component") && (T.paths.has("") && (A = !0), !A))
1020
- for (const V of g) {
1021
- if (T.paths.has(V)) {
1022
- A = !0;
1025
+ if (P.includes("component") && (T.paths.has("") && ($ = !0), !$))
1026
+ for (const C of g) {
1027
+ if (T.paths.has(C)) {
1028
+ $ = !0;
1023
1029
  break;
1024
1030
  }
1025
- let k = V.lastIndexOf(".");
1026
- for (; k !== -1; ) {
1027
- const F = V.substring(0, k);
1031
+ let A = C.lastIndexOf(".");
1032
+ for (; A !== -1; ) {
1033
+ const F = C.substring(0, A);
1028
1034
  if (T.paths.has(F)) {
1029
- A = !0;
1035
+ $ = !0;
1030
1036
  break;
1031
1037
  }
1032
- const D = V.substring(
1033
- k + 1
1038
+ const D = C.substring(
1039
+ A + 1
1034
1040
  );
1035
1041
  if (!isNaN(Number(D))) {
1036
1042
  const M = F.lastIndexOf(".");
@@ -1040,21 +1046,21 @@ function dt(t, c, h, S) {
1040
1046
  M
1041
1047
  );
1042
1048
  if (T.paths.has(N)) {
1043
- A = !0;
1049
+ $ = !0;
1044
1050
  break;
1045
1051
  }
1046
1052
  }
1047
1053
  }
1048
- k = F.lastIndexOf(".");
1054
+ A = F.lastIndexOf(".");
1049
1055
  }
1050
- if (A) break;
1056
+ if ($) break;
1051
1057
  }
1052
- if (!A && P.includes("deps") && T.depsFunction) {
1053
- const V = T.depsFunction(s);
1054
- let k = !1;
1055
- typeof V == "boolean" ? V && (k = !0) : H(T.deps, V) || (T.deps = V, k = !0), k && (A = !0);
1058
+ if (!$ && P.includes("deps") && T.depsFunction) {
1059
+ const C = T.depsFunction(s);
1060
+ let A = !1;
1061
+ typeof C == "boolean" ? C && (A = !0) : H(T.deps, C) || (T.deps = C, A = !0), A && ($ = !0);
1056
1062
  }
1057
- A && T.forceUpdate();
1063
+ $ && T.forceUpdate();
1058
1064
  }
1059
1065
  }
1060
1066
  }
@@ -1066,18 +1072,18 @@ function dt(t, c, h, S) {
1066
1072
  throw new Error("Zod schema not found");
1067
1073
  if (!d?.key)
1068
1074
  throw new Error("Validation key not found");
1069
- q(d.key);
1075
+ J(d.key);
1070
1076
  const r = o.getState().cogsStateStore[t];
1071
1077
  try {
1072
1078
  const s = o.getState().getValidationErrors(d.key);
1073
1079
  s && s.length > 0 && s.forEach(([u]) => {
1074
- u && u.startsWith(d.key) && q(u);
1080
+ u && u.startsWith(d.key) && J(u);
1075
1081
  });
1076
1082
  const i = d.zodSchema.safeParse(r);
1077
1083
  return i.success ? !0 : (i.error.errors.forEach((g) => {
1078
- const E = g.path, T = g.message, A = [d.key, ...E].join(".");
1079
- e(A, T);
1080
- }), gt(t), !1);
1084
+ const E = g.path, T = g.message, $ = [d.key, ...E].join(".");
1085
+ e($, T);
1086
+ }), St(t), !1);
1081
1087
  } catch (s) {
1082
1088
  return console.error("Zod schema validation failed", s), !1;
1083
1089
  }
@@ -1086,7 +1092,7 @@ function dt(t, c, h, S) {
1086
1092
  if (l === "getComponents")
1087
1093
  return () => o().stateComponents.get(t);
1088
1094
  if (l === "getAllFormRefs")
1089
- return () => Tt.getState().getFormRefsByStateKey(t);
1095
+ return () => At.getState().getFormRefsByStateKey(t);
1090
1096
  if (l === "_initialState")
1091
1097
  return o.getState().initialStateGlobal[t];
1092
1098
  if (l === "_serverState")
@@ -1099,13 +1105,13 @@ function dt(t, c, h, S) {
1099
1105
  if (l === "removeValidation") return p.removeValidation;
1100
1106
  }
1101
1107
  if (l === "getFormRef")
1102
- return () => Tt.getState().getFormRef(t + "." + n.join("."));
1108
+ return () => At.getState().getFormRef(t + "." + n.join("."));
1103
1109
  if (l === "validationWrapper")
1104
1110
  return ({
1105
1111
  children: d,
1106
1112
  hideMessage: e
1107
- }) => /* @__PURE__ */ mt(
1108
- jt,
1113
+ }) => /* @__PURE__ */ vt(
1114
+ Ot,
1109
1115
  {
1110
1116
  formOpts: e ? { validation: { message: "" } } : void 0,
1111
1117
  path: n,
@@ -1121,21 +1127,21 @@ function dt(t, c, h, S) {
1121
1127
  if (l === "update")
1122
1128
  return (d, e) => {
1123
1129
  if (e?.debounce)
1124
- Mt(() => {
1125
- ot(c, d, n, "");
1130
+ jt(() => {
1131
+ at(c, d, n, "");
1126
1132
  const r = o.getState().getNestedState(t, n);
1127
1133
  e?.afterUpdate && e.afterUpdate(r);
1128
1134
  }, e.debounce);
1129
1135
  else {
1130
- ot(c, d, n, "");
1136
+ at(c, d, n, "");
1131
1137
  const r = o.getState().getNestedState(t, n);
1132
1138
  e?.afterUpdate && e.afterUpdate(r);
1133
1139
  }
1134
1140
  w(n);
1135
1141
  };
1136
1142
  if (l === "formElement")
1137
- return (d, e) => /* @__PURE__ */ mt(
1138
- Ot,
1143
+ return (d, e) => /* @__PURE__ */ vt(
1144
+ Ut,
1139
1145
  {
1140
1146
  setState: c,
1141
1147
  stateKey: t,
@@ -1144,11 +1150,11 @@ function dt(t, c, h, S) {
1144
1150
  formOpts: e
1145
1151
  }
1146
1152
  );
1147
- const j = [...n, l], rt = o.getState().getNestedState(t, j);
1148
- return a(rt, j, m);
1153
+ const R = [...n, l], rt = o.getState().getNestedState(t, R);
1154
+ return a(rt, R, m);
1149
1155
  }
1150
- }, G = new Proxy(R, U);
1151
- return I.set(L, {
1156
+ }, G = new Proxy(O, U);
1157
+ return I.set(W, {
1152
1158
  proxy: G,
1153
1159
  stateVersion: b
1154
1160
  }), G;
@@ -1157,10 +1163,10 @@ function dt(t, c, h, S) {
1157
1163
  o.getState().getNestedState(t, [])
1158
1164
  );
1159
1165
  }
1160
- function kt(t) {
1161
- return at(Jt, { proxy: t });
1166
+ function Nt(t) {
1167
+ return st(Zt, { proxy: t });
1162
1168
  }
1163
- function qt({
1169
+ function Yt({
1164
1170
  proxy: t,
1165
1171
  rebuildStateShape: c
1166
1172
  }) {
@@ -1172,10 +1178,10 @@ function qt({
1172
1178
  (I, b, w, p, a) => t._mapFn(I, b, w, p, a)
1173
1179
  ) : null;
1174
1180
  }
1175
- function Jt({
1181
+ function Zt({
1176
1182
  proxy: t
1177
1183
  }) {
1178
- const c = Q(null), h = `${t._stateKey}-${t._path.join(".")}`;
1184
+ const c = B(null), h = `${t._stateKey}-${t._path.join(".")}`;
1179
1185
  return nt(() => {
1180
1186
  const S = c.current;
1181
1187
  if (!S || !S.parentElement) return;
@@ -1197,22 +1203,22 @@ function Jt({
1197
1203
  "state",
1198
1204
  `return (${t._effect})(state)`
1199
1205
  )(n);
1200
- } catch (R) {
1201
- console.error("Error evaluating effect function during mount:", R), m = n;
1206
+ } catch (O) {
1207
+ console.error("Error evaluating effect function during mount:", O), m = n;
1202
1208
  }
1203
1209
  else
1204
1210
  m = n;
1205
1211
  m !== null && typeof m == "object" && (m = JSON.stringify(m));
1206
- const L = document.createTextNode(String(m));
1207
- S.replaceWith(L);
1208
- }, [t._stateKey, t._path.join("."), t._effect]), at("span", {
1212
+ const W = document.createTextNode(String(m));
1213
+ S.replaceWith(W);
1214
+ }, [t._stateKey, t._path.join("."), t._effect]), st("span", {
1209
1215
  ref: c,
1210
1216
  style: { display: "none" },
1211
1217
  "data-signal-id": h
1212
1218
  });
1213
1219
  }
1214
- function de(t) {
1215
- const c = xt(
1220
+ function ge(t) {
1221
+ const c = _t(
1216
1222
  (h) => {
1217
1223
  const S = o.getState().stateComponents.get(t._stateKey) || {
1218
1224
  components: /* @__PURE__ */ new Map()
@@ -1224,22 +1230,22 @@ function de(t) {
1224
1230
  },
1225
1231
  () => o.getState().getNestedState(t._stateKey, t._path)
1226
1232
  );
1227
- return at("text", {}, String(c));
1233
+ return st("text", {}, String(c));
1228
1234
  }
1229
- function Yt({
1235
+ function Xt({
1230
1236
  stateKey: t,
1231
1237
  itemComponentId: c,
1232
1238
  itemPath: h,
1233
1239
  children: S
1234
1240
  }) {
1235
- const [, I] = X({}), [b, w] = Ft(), p = Q(null);
1241
+ const [, I] = Q({}), [b, w] = Lt(), p = B(null);
1236
1242
  return nt(() => {
1237
1243
  w.height > 0 && w.height !== p.current && (p.current = w.height, o.getState().setShadowMetadata(t, h, {
1238
1244
  virtualizer: {
1239
1245
  itemHeight: w.height
1240
1246
  }
1241
1247
  }));
1242
- }, [w.height, t, h]), ct(() => {
1248
+ }, [w.height, t, h]), dt(() => {
1243
1249
  const a = `${t}////${c}`, y = o.getState().stateComponents.get(t) || {
1244
1250
  components: /* @__PURE__ */ new Map()
1245
1251
  };
@@ -1250,14 +1256,14 @@ function Yt({
1250
1256
  const n = o.getState().stateComponents.get(t);
1251
1257
  n && n.components.delete(a);
1252
1258
  };
1253
- }, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref: b, children: S });
1259
+ }, [t, c, h.join(".")]), /* @__PURE__ */ vt("div", { ref: b, children: S });
1254
1260
  }
1255
1261
  export {
1256
- kt as $cogsSignal,
1257
- de as $cogsSignalStore,
1258
- ie as addStateOptions,
1259
- ce as createCogsState,
1260
- le as notifyComponent,
1261
- Bt as useCogsStateFn
1262
+ Nt as $cogsSignal,
1263
+ ge as $cogsSignalStore,
1264
+ le as addStateOptions,
1265
+ de as createCogsState,
1266
+ ue as notifyComponent,
1267
+ Jt as useCogsStateFn
1262
1268
  };
1263
1269
  //# sourceMappingURL=CogsState.jsx.map