cogsbox-state 0.5.400 → 0.5.402

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 Ot } from "react/jsx-runtime";
3
- import { useState as K, useRef as q, useEffect as ot, useLayoutEffect as ct, useMemo as wt, createElement as lt, useSyncExternalStore as Ht, startTransition as Ft, useCallback as kt } from "react";
4
- import { transformStateFunc as Bt, isDeepEqual as J, isFunction as tt, getNestedValue as Z, getDifferences as _t, debounce as Wt } from "./utility.js";
5
- import { pushFunc as Et, updateFn as it, cutFunc as ht, ValidationWrapper as zt, FormControlComponent as qt } from "./Functions.jsx";
6
- import Jt from "superjson";
7
- import { v4 as At } from "uuid";
2
+ import { jsx as _t } from "react/jsx-runtime";
3
+ import { useState as K, useRef as q, useEffect as ot, useLayoutEffect as lt, useMemo as wt, createElement as dt, useSyncExternalStore as Bt, startTransition as Ft, useCallback as bt } from "react";
4
+ import { transformStateFunc as Wt, isDeepEqual as J, isFunction as tt, getNestedValue as Z, getDifferences as At, debounce as zt } from "./utility.js";
5
+ import { pushFunc as Ot, updateFn as ct, cutFunc as ht, ValidationWrapper as qt, FormControlComponent as Jt } from "./Functions.jsx";
6
+ import Yt from "superjson";
7
+ import { v4 as Nt } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as o, formRefStore as bt } from "./store.js";
10
- import { useCogsConfig as Gt } from "./CogsStateClient.jsx";
11
- import { applyPatch as Yt } from "fast-json-patch";
12
- import Zt from "react-use-measure";
13
- function Mt(t, c) {
9
+ import { getGlobalStore as o, formRefStore as Mt } from "./store.js";
10
+ import { useCogsConfig as Lt } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Zt } from "fast-json-patch";
12
+ import Xt from "react-use-measure";
13
+ function xt(t, c) {
14
14
  const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, I = m(t) || {};
15
15
  g(t, {
16
16
  ...I,
17
17
  ...c
18
18
  });
19
19
  }
20
- function xt({
20
+ function Pt({
21
21
  stateKey: t,
22
22
  options: c,
23
23
  initialOptionsPart: m
@@ -35,7 +35,7 @@ function Ie(t, { formElements: c, validation: m }) {
35
35
  }
36
36
  const ve = (t, c) => {
37
37
  let m = t;
38
- const [g, I] = Bt(m);
38
+ const [g, I] = Wt(m);
39
39
  (Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((v) => {
40
40
  I[v] = I[v] || {}, I[v].formElements = {
41
41
  ...c?.formElements,
@@ -46,13 +46,13 @@ const ve = (t, c) => {
46
46
  }, rt(v) || o.getState().setInitialStateOptions(v, I[v]);
47
47
  }), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
48
48
  const N = (v, s) => {
49
- const [T] = K(s?.componentId ?? At());
50
- xt({
49
+ const [T] = K(s?.componentId ?? Nt());
50
+ Pt({
51
51
  stateKey: v,
52
52
  options: s,
53
53
  initialOptionsPart: I
54
54
  });
55
- const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] = ne(
55
+ const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] = re(
56
56
  S,
57
57
  {
58
58
  stateKey: v,
@@ -71,21 +71,21 @@ const ve = (t, c) => {
71
71
  return j;
72
72
  };
73
73
  function p(v, s) {
74
- xt({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && te(v, s), dt(v);
74
+ Pt({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && ee(v, s), ut(v);
75
75
  }
76
76
  return { useCogsState: N, setCogsOptions: p };
77
77
  }, {
78
78
  setUpdaterState: Tt,
79
79
  setState: nt,
80
80
  getInitialOptions: rt,
81
- getKeyState: Lt,
82
- getValidationErrors: Xt,
83
- setStateLog: Qt,
84
- updateInitialStateGlobal: Nt,
85
- addValidationError: Rt,
86
- removeValidationError: X,
87
- setServerSyncActions: Kt
88
- } = o.getState(), Pt = (t, c, m, g, I) => {
81
+ getKeyState: Rt,
82
+ getValidationErrors: Qt,
83
+ setStateLog: Kt,
84
+ updateInitialStateGlobal: Ct,
85
+ addValidationError: Dt,
86
+ removeValidationError: Q,
87
+ setServerSyncActions: te
88
+ } = o.getState(), Vt = (t, c, m, g, I) => {
89
89
  m?.log && console.log(
90
90
  "saving to localstorage",
91
91
  c,
@@ -104,7 +104,7 @@ const ve = (t, c) => {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: I ?? v
107
- }, T = Jt.serialize(s);
107
+ }, T = Yt.serialize(s);
108
108
  window.localStorage.setItem(
109
109
  p,
110
110
  JSON.stringify(T.json)
@@ -118,17 +118,17 @@ const ve = (t, c) => {
118
118
  } catch (c) {
119
119
  return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
- }, te = (t, c) => {
122
- const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(), I = tt(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
121
+ }, ee = (t, c) => {
122
+ const m = o.getState().cogsStateStore[t], { sessionId: g } = Lt(), I = tt(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
123
123
  if (I && g) {
124
124
  const N = vt(
125
125
  `${g}-${t}-${I}`
126
126
  );
127
127
  if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
128
- return nt(t, N.state), dt(t), !0;
128
+ return nt(t, N.state), ut(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Dt = (t, c, m, g, I, N) => {
131
+ }, Ht = (t, c, m, g, I, N) => {
132
132
  const p = {
133
133
  initialState: c,
134
134
  updaterState: It(
@@ -139,8 +139,8 @@ const ve = (t, c) => {
139
139
  ),
140
140
  state: m
141
141
  };
142
- Nt(t, p.initialState), Tt(t, p.updaterState), nt(t, p.state);
143
- }, dt = (t) => {
142
+ Ct(t, p.initialState), Tt(t, p.updaterState), nt(t, p.state);
143
+ }, ut = (t) => {
144
144
  const c = o.getState().stateComponents.get(t);
145
145
  if (!c) return;
146
146
  const m = /* @__PURE__ */ new Set();
@@ -157,7 +157,7 @@ const ve = (t, c) => {
157
157
  return;
158
158
  I && I.forceUpdate();
159
159
  }
160
- }, ee = (t, c, m, g) => {
160
+ }, ne = (t, c, m, g) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
@@ -180,7 +180,7 @@ const ve = (t, c) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function ne(t, {
183
+ function re(t, {
184
184
  stateKey: c,
185
185
  serverSync: m,
186
186
  localStorage: g,
@@ -193,12 +193,12 @@ function ne(t, {
193
193
  dependencies: r,
194
194
  serverState: S
195
195
  } = {}) {
196
- const [W, j] = K({}), { sessionId: U } = Gt();
196
+ const [W, j] = K({}), { sessionId: U } = Lt();
197
197
  let z = !c;
198
- const [h] = K(c ?? At()), l = o.getState().stateLog[h], ut = q(/* @__PURE__ */ new Set()), et = q(v ?? At()), L = q(
198
+ const [h] = K(c ?? Nt()), l = o.getState().stateLog[h], gt = q(/* @__PURE__ */ new Set()), et = q(v ?? Nt()), R = q(
199
199
  null
200
200
  );
201
- L.current = rt(h) ?? null, ot(() => {
201
+ R.current = rt(h) ?? null, ot(() => {
202
202
  if (T && T.stateKey === h && T.path?.[0]) {
203
203
  nt(h, (n) => ({
204
204
  ...n,
@@ -212,38 +212,38 @@ function ne(t, {
212
212
  }
213
213
  }, [T]), ot(() => {
214
214
  if (s) {
215
- Mt(h, {
215
+ xt(h, {
216
216
  initialState: s
217
217
  });
218
- const e = L.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
218
+ const e = R.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
219
219
  if (!(i && !J(i, s) || !i) && !a)
220
220
  return;
221
221
  let u = null;
222
222
  const E = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
223
223
  E && U && (u = vt(`${U}-${h}-${E}`));
224
- let y = s, w = !1;
225
- const C = a ? Date.now() : 0, A = u?.lastUpdated || 0, b = u?.lastSyncedWithServer || 0;
226
- a && C > A ? (y = e.serverState.data, w = !0) : u && A > b && (y = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(y)), o.getState().initializeShadowState(h, s), Dt(
224
+ let y = s, _ = !1;
225
+ const C = a ? Date.now() : 0, w = u?.lastUpdated || 0, b = u?.lastSyncedWithServer || 0;
226
+ a && C > w ? (y = e.serverState.data, _ = !0) : u && w > b && (y = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(y)), o.getState().initializeShadowState(h, s), Ht(
227
227
  h,
228
228
  s,
229
229
  y,
230
230
  at,
231
231
  et.current,
232
232
  U
233
- ), w && E && U && Pt(y, h, e, U, Date.now()), dt(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || j({});
233
+ ), _ && E && U && Vt(y, h, e, U, Date.now()), ut(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || j({});
234
234
  }
235
235
  }, [
236
236
  s,
237
237
  S?.status,
238
238
  S?.data,
239
239
  ...r || []
240
- ]), ct(() => {
241
- z && Mt(h, {
240
+ ]), lt(() => {
241
+ z && xt(h, {
242
242
  serverSync: m,
243
243
  formElements: I,
244
244
  initialState: s,
245
245
  localStorage: g,
246
- middleware: L.current?.middleware
246
+ middleware: R.current?.middleware
247
247
  });
248
248
  const e = `${h}////${et.current}`, n = o.getState().stateComponents.get(h) || {
249
249
  components: /* @__PURE__ */ new Map()
@@ -261,154 +261,154 @@ function ne(t, {
261
261
  const at = (e, n, a, i) => {
262
262
  if (Array.isArray(n)) {
263
263
  const u = `${h}-${n.join(".")}`;
264
- ut.current.add(u);
264
+ gt.current.add(u);
265
265
  }
266
266
  const f = o.getState();
267
267
  nt(h, (u) => {
268
268
  const E = tt(e) ? e(u) : e, y = `${h}-${n.join(".")}`;
269
269
  if (y) {
270
- let M = !1, $ = f.signalDomElements.get(y);
270
+ let P = !1, $ = f.signalDomElements.get(y);
271
271
  if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
- const R = n.slice(0, -1), V = Z(E, R);
272
+ const D = n.slice(0, -1), V = Z(E, D);
273
273
  if (Array.isArray(V)) {
274
- M = !0;
275
- const O = `${h}-${R.join(".")}`;
274
+ P = !0;
275
+ const O = `${h}-${D.join(".")}`;
276
276
  $ = f.signalDomElements.get(O);
277
277
  }
278
278
  }
279
279
  if ($) {
280
- const R = M ? Z(E, n.slice(0, -1)) : Z(E, n);
281
- $.forEach(({ parentId: V, position: O, effect: _ }) => {
282
- const D = document.querySelector(
280
+ const D = P ? Z(E, n.slice(0, -1)) : Z(E, n);
281
+ $.forEach(({ parentId: V, position: O, effect: A }) => {
282
+ const H = document.querySelector(
283
283
  `[data-parent-id="${V}"]`
284
284
  );
285
- if (D) {
286
- const G = Array.from(D.childNodes);
285
+ if (H) {
286
+ const G = Array.from(H.childNodes);
287
287
  if (G[O]) {
288
- const B = _ ? new Function("state", `return (${_})(state)`)(R) : R;
289
- G[O].textContent = String(B);
288
+ const F = A ? new Function("state", `return (${A})(state)`)(D) : D;
289
+ G[O].textContent = String(F);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (i || L.current?.validation?.key) && n && X(
296
- (i || L.current?.validation?.key) + "." + n.join(".")
295
+ console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (i || R.current?.validation?.key) && n && Q(
296
+ (i || R.current?.validation?.key) + "." + n.join(".")
297
297
  );
298
- const w = n.slice(0, n.length - 1);
299
- a.updateType === "cut" && L.current?.validation?.key && X(
300
- L.current?.validation?.key + "." + w.join(".")
301
- ), a.updateType === "insert" && L.current?.validation?.key && Xt(
302
- L.current?.validation?.key + "." + w.join(".")
303
- ).filter(([$, R]) => {
298
+ const _ = n.slice(0, n.length - 1);
299
+ a.updateType === "cut" && R.current?.validation?.key && Q(
300
+ R.current?.validation?.key + "." + _.join(".")
301
+ ), a.updateType === "insert" && R.current?.validation?.key && Qt(
302
+ R.current?.validation?.key + "." + _.join(".")
303
+ ).filter(([$, D]) => {
304
304
  let V = $?.split(".").length;
305
- if ($ == w.join(".") && V == w.length - 1) {
306
- let O = $ + "." + w;
307
- X($), Rt(O, R);
305
+ if ($ == _.join(".") && V == _.length - 1) {
306
+ let O = $ + "." + _;
307
+ Q($), Dt(O, D);
308
308
  }
309
309
  });
310
310
  const C = f.stateComponents.get(h);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
312
- const M = _t(u, E), $ = new Set(M), R = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
312
+ const P = At(u, E), $ = new Set(P), D = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
313
313
  for (const [
314
314
  V,
315
315
  O
316
316
  ] of C.components.entries()) {
317
- let _ = !1;
318
- const D = Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"];
319
- if (console.log("component", O), !D.includes("none")) {
320
- if (D.includes("all")) {
317
+ let A = !1;
318
+ const H = Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"];
319
+ if (console.log("component", O), !H.includes("none")) {
320
+ if (H.includes("all")) {
321
321
  O.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (D.includes("component") && ((O.paths.has(R) || O.paths.has("")) && (_ = !0), !_))
324
+ if (H.includes("component") && ((O.paths.has(D) || O.paths.has("")) && (A = !0), !A))
325
325
  for (const G of $) {
326
- let B = G;
326
+ let F = G;
327
327
  for (; ; ) {
328
- if (O.paths.has(B)) {
329
- _ = !0;
328
+ if (O.paths.has(F)) {
329
+ A = !0;
330
330
  break;
331
331
  }
332
- const st = B.lastIndexOf(".");
332
+ const st = F.lastIndexOf(".");
333
333
  if (st !== -1) {
334
- const gt = B.substring(
334
+ const ft = F.substring(
335
335
  0,
336
336
  st
337
337
  );
338
338
  if (!isNaN(
339
- Number(B.substring(st + 1))
340
- ) && O.paths.has(gt)) {
341
- _ = !0;
339
+ Number(F.substring(st + 1))
340
+ ) && O.paths.has(ft)) {
341
+ A = !0;
342
342
  break;
343
343
  }
344
- B = gt;
344
+ F = ft;
345
345
  } else
346
- B = "";
347
- if (B === "")
346
+ F = "";
347
+ if (F === "")
348
348
  break;
349
349
  }
350
- if (_) break;
350
+ if (A) break;
351
351
  }
352
- if (!_ && D.includes("deps") && O.depsFunction) {
352
+ if (!A && H.includes("deps") && O.depsFunction) {
353
353
  const G = O.depsFunction(E);
354
- let B = !1;
355
- typeof G == "boolean" ? G && (B = !0) : J(O.deps, G) || (O.deps = G, B = !0), B && (_ = !0);
354
+ let F = !1;
355
+ typeof G == "boolean" ? G && (F = !0) : J(O.deps, G) || (O.deps = G, F = !0), F && (A = !0);
356
356
  }
357
- _ && O.forceUpdate();
357
+ A && O.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const A = Date.now();
362
- n = n.map((M, $) => {
363
- const R = n.slice(0, -1), V = Z(E, R);
364
- return $ === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (V.length - 1).toString() : M;
361
+ const w = Date.now();
362
+ n = n.map((P, $) => {
363
+ const D = n.slice(0, -1), V = Z(E, D);
364
+ return $ === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (V.length - 1).toString() : P;
365
365
  });
366
- const { oldValue: b, newValue: F } = ee(
366
+ const { oldValue: b, newValue: B } = ne(
367
367
  a.updateType,
368
368
  u,
369
369
  E,
370
370
  n
371
371
  ), Y = {
372
- timeStamp: A,
372
+ timeStamp: w,
373
373
  stateKey: h,
374
374
  path: n,
375
375
  updateType: a.updateType,
376
376
  status: "new",
377
377
  oldValue: b,
378
- newValue: F
378
+ newValue: B
379
379
  };
380
380
  switch (a.updateType) {
381
381
  case "update":
382
382
  f.updateShadowAtPath(h, n, E);
383
383
  break;
384
384
  case "insert":
385
- const M = n.slice(0, -1);
386
- f.insertShadowArrayElement(h, M, F);
385
+ const P = n.slice(0, -1);
386
+ f.insertShadowArrayElement(h, P, B);
387
387
  break;
388
388
  case "cut":
389
- const $ = n.slice(0, -1), R = parseInt(n[n.length - 1]);
390
- f.removeShadowArrayElement(h, $, R);
389
+ const $ = n.slice(0, -1), D = parseInt(n[n.length - 1]);
390
+ f.removeShadowArrayElement(h, $, D);
391
391
  break;
392
392
  }
393
- if (Qt(h, (M) => {
394
- const R = [...M ?? [], Y].reduce((V, O) => {
395
- const _ = `${O.stateKey}:${JSON.stringify(O.path)}`, D = V.get(_);
396
- return D ? (D.timeStamp = Math.max(D.timeStamp, O.timeStamp), D.newValue = O.newValue, D.oldValue = D.oldValue ?? O.oldValue, D.updateType = O.updateType) : V.set(_, { ...O }), V;
393
+ if (Kt(h, (P) => {
394
+ const D = [...P ?? [], Y].reduce((V, O) => {
395
+ const A = `${O.stateKey}:${JSON.stringify(O.path)}`, H = V.get(A);
396
+ return H ? (H.timeStamp = Math.max(H.timeStamp, O.timeStamp), H.newValue = O.newValue, H.oldValue = H.oldValue ?? O.oldValue, H.updateType = O.updateType) : V.set(A, { ...O }), V;
397
397
  }, /* @__PURE__ */ new Map());
398
- return Array.from(R.values());
399
- }), Pt(
398
+ return Array.from(D.values());
399
+ }), Vt(
400
400
  E,
401
401
  h,
402
- L.current,
402
+ R.current,
403
403
  U
404
- ), L.current?.middleware && L.current.middleware({
404
+ ), R.current?.middleware && R.current.middleware({
405
405
  updateLog: l,
406
406
  update: Y
407
- }), L.current?.serverSync) {
408
- const M = f.serverState[h], $ = L.current?.serverSync;
409
- Kt(h, {
407
+ }), R.current?.serverSync) {
408
+ const P = f.serverState[h], $ = R.current?.serverSync;
409
+ te(h, {
410
410
  syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
411
- rollBackState: M,
411
+ rollBackState: P,
412
412
  actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
@@ -424,14 +424,14 @@ function ne(t, {
424
424
  et.current,
425
425
  U
426
426
  )
427
- ), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] || Nt(h, t));
427
+ ), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] || Ct(h, t));
428
428
  const d = wt(() => It(
429
429
  h,
430
430
  at,
431
431
  et.current,
432
432
  U
433
433
  ), [h, U]);
434
- return [Lt(h), d];
434
+ return [Rt(h), d];
435
435
  }
436
436
  function It(t, c, m, g) {
437
437
  const I = /* @__PURE__ */ new Map();
@@ -443,11 +443,11 @@ function It(t, c, m, g) {
443
443
  N++;
444
444
  }, v = {
445
445
  removeValidation: (T) => {
446
- T?.validationKey && X(T.validationKey);
446
+ T?.validationKey && Q(T.validationKey);
447
447
  },
448
448
  revertToInitialState: (T) => {
449
449
  const r = o.getState().getInitialOptions(t)?.validation;
450
- r?.key && X(r?.key), T?.validationKey && X(T.validationKey);
450
+ r?.key && Q(r?.key), T?.validationKey && Q(T.validationKey);
451
451
  const S = o.getState().initialStateGlobal[t];
452
452
  o.getState().clearSelectedIndexesForState(t), I.clear(), N++;
453
453
  const W = s(S, []), j = rt(t), U = tt(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, z = `${g}-${t}-${U}`;
@@ -466,7 +466,7 @@ function It(t, c, m, g) {
466
466
  g
467
467
  ), S = o.getState().initialStateGlobal[t], W = rt(t), j = tt(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${g}-${t}-${j}`;
468
468
  return localStorage.getItem(U) && localStorage.removeItem(U), Ft(() => {
469
- Nt(t, T), o.getState().initializeShadowState(t, T), Tt(t, r), nt(t, T);
469
+ Ct(t, T), o.getState().initializeShadowState(t, T), Tt(t, r), nt(t, T);
470
470
  const z = o.getState().stateComponents.get(t);
471
471
  z && z.components.forEach((h) => {
472
472
  h.forceUpdate();
@@ -480,7 +480,7 @@ function It(t, c, m, g) {
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
482
  const T = o.getState().serverState[t];
483
- return !!(T && J(T, Lt(t)));
483
+ return !!(T && J(T, Rt(t)));
484
484
  }
485
485
  };
486
486
  function s(T, r = [], S) {
@@ -493,14 +493,14 @@ function It(t, c, m, g) {
493
493
  j[h] = v[h];
494
494
  });
495
495
  const U = {
496
- apply(h, l, ut) {
496
+ apply(h, l, gt) {
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(h, l) {
502
502
  S?.validIndices && !Array.isArray(T) && (S = { ...S, validIndices: void 0 });
503
- const ut = /* @__PURE__ */ new Set([
503
+ const gt = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,7 +523,7 @@ function It(t, c, m, g) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ut.has(l)) {
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !gt.has(l)) {
527
527
  const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
528
528
  if (e) {
529
529
  const n = e.components.get(d);
@@ -540,7 +540,7 @@ function It(t, c, m, g) {
540
540
  }
541
541
  }
542
542
  if (l === "getDifferences")
543
- return () => _t(
543
+ return () => At(
544
544
  o.getState().cogsStateStore[t],
545
545
  o.getState().initialStateGlobal[t]
546
546
  );
@@ -622,49 +622,49 @@ function It(t, c, m, g) {
622
622
  overscan: a = 6,
623
623
  stickToBottom: i = !1,
624
624
  dependencies: f = []
625
- } = e, u = q(!1), E = q(null), [y, w] = K({
625
+ } = e, u = q(!1), E = q(null), [y, _] = K({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
- }), [C, A] = K("IDLE_AT_TOP"), b = q(!1), F = q(0), Y = q(f), M = q(0), [$, R] = K(0), V = q(null);
628
+ }), [C, w] = K("IDLE_AT_TOP"), b = q(!1), B = q(0), Y = q(f), P = q(0), [$, D] = K(0), V = q(null);
629
629
  ot(() => o.getState().subscribeToShadowState(t, () => {
630
- R((x) => x + 1);
630
+ D((M) => M + 1);
631
631
  }), [t]);
632
632
  const O = o().getNestedState(
633
633
  t,
634
634
  r
635
- ), _ = O.length, { totalHeight: D, positions: G } = wt(() => {
635
+ ), A = O.length, { totalHeight: H, positions: G } = wt(() => {
636
636
  const k = o.getState().getShadowMetadata(t, r) || [];
637
- let x = 0;
638
- const H = [];
639
- for (let P = 0; P < _; P++) {
640
- H[P] = x;
641
- const Q = k[P]?.virtualizer?.itemHeight;
642
- x += Q || n;
637
+ let M = 0;
638
+ const L = [];
639
+ for (let x = 0; x < A; x++) {
640
+ L[x] = M;
641
+ const X = k[x]?.virtualizer?.itemHeight;
642
+ M += X || n;
643
643
  }
644
- return { totalHeight: x, positions: H };
644
+ return { totalHeight: M, positions: L };
645
645
  }, [
646
- _,
646
+ A,
647
647
  t,
648
648
  r.join("."),
649
649
  n,
650
650
  $
651
- ]), B = wt(() => {
652
- const k = Math.max(0, y.startIndex), x = Math.min(_, y.endIndex), H = Array.from(
653
- { length: x - k },
654
- (Q, ft) => k + ft
655
- ), P = H.map((Q) => O[Q]);
656
- return s(P, r, {
651
+ ]), F = wt(() => {
652
+ const k = Math.max(0, y.startIndex), M = Math.min(A, y.endIndex), L = Array.from(
653
+ { length: M - k },
654
+ (X, it) => k + it
655
+ ), x = L.map((X) => O[X]);
656
+ return s(x, r, {
657
657
  ...S,
658
- validIndices: H
658
+ validIndices: L
659
659
  });
660
- }, [y.startIndex, y.endIndex, O, _]);
661
- ct(() => {
660
+ }, [y.startIndex, y.endIndex, O, A]);
661
+ lt(() => {
662
662
  const k = E.current;
663
663
  if (!k) return;
664
- const x = _ > F.current;
665
- if (x && V.current) {
666
- const { top: H, height: P } = V.current;
667
- b.current = !0, k.scrollTop = H + (k.scrollHeight - P), console.log(
664
+ const M = A > B.current;
665
+ if (M && V.current) {
666
+ const { top: L, height: x } = V.current;
667
+ b.current = !0, k.scrollTop = L + (k.scrollHeight - x), console.log(
668
668
  `ANCHOR RESTORED to scrollTop: ${k.scrollTop}`
669
669
  ), setTimeout(() => {
670
670
  b.current = !1;
@@ -674,99 +674,108 @@ function It(t, c, m, g) {
674
674
  f,
675
675
  Y.current
676
676
  )) {
677
- console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), A("IDLE_AT_TOP");
677
+ console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), w("IDLE_AT_TOP");
678
678
  return;
679
679
  }
680
- x && C === "LOCKED_AT_BOTTOM" && i && (console.log(
680
+ M && C === "LOCKED_AT_BOTTOM" && i && (console.log(
681
681
  "TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
682
- ), A("GETTING_HEIGHTS"));
682
+ ), w("GETTING_HEIGHTS"));
683
683
  }
684
- F.current = _, Y.current = f;
685
- }, [_, ...f]), ct(() => {
684
+ B.current = A, Y.current = f;
685
+ }, [A, ...f]), lt(() => {
686
686
  const k = E.current;
687
687
  if (!k) return;
688
- let x;
689
- if (C === "IDLE_AT_TOP" && i && _ > 0)
688
+ let M;
689
+ if (C === "IDLE_AT_TOP" && i && A > 0)
690
690
  console.log(
691
691
  "ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
692
- ), A("GETTING_HEIGHTS");
693
- else if (C === "GETTING_HEIGHTS")
692
+ ), w("GETTING_HEIGHTS");
693
+ else if (C === "GETTING_HEIGHTS") {
694
694
  console.log(
695
695
  "ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
696
- ), w({
697
- startIndex: Math.max(0, _ - 10 - a),
698
- endIndex: _
699
- }), x = setInterval(() => {
700
- const H = _ - 1;
701
- ((o.getState().getShadowMetadata(t, r) || [])[H]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(x), u.current || (console.log(
696
+ ), _({
697
+ startIndex: Math.max(0, A - 10 - a),
698
+ endIndex: A
699
+ });
700
+ let L = 0;
701
+ const x = 50;
702
+ M = setInterval(() => {
703
+ L++;
704
+ const X = A - 1, yt = (o.getState().getShadowMetadata(t, r) || [])[X]?.virtualizer?.itemHeight || 0;
705
+ console.log(
706
+ `ACTION (GETTING_HEIGHTS): attempt ${L}, lastItemHeight =`,
707
+ yt
708
+ ), yt > 0 ? (clearInterval(M), console.log(
702
709
  "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
703
- ), A("SCROLLING_TO_BOTTOM")));
710
+ ), w("SCROLLING_TO_BOTTOM")) : L >= x && (clearInterval(M), console.log(
711
+ "ACTION (GETTING_HEIGHTS): Timeout - proceeding anyway"
712
+ ), w("SCROLLING_TO_BOTTOM"));
704
713
  }, 100);
705
- else if (C === "SCROLLING_TO_BOTTOM") {
714
+ } else if (C === "SCROLLING_TO_BOTTOM") {
706
715
  console.log(
707
716
  "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
708
717
  ), b.current = !0;
709
- const H = F.current === 0 ? "auto" : "smooth";
718
+ const L = B.current === 0 ? "auto" : "smooth";
710
719
  k.scrollTo({
711
720
  top: k.scrollHeight,
712
- behavior: H
721
+ behavior: L
713
722
  });
714
- const P = setTimeout(
723
+ const x = setTimeout(
715
724
  () => {
716
725
  console.log(
717
726
  "ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
718
- ), b.current = !1, u.current = !1, A("LOCKED_AT_BOTTOM");
727
+ ), b.current = !1, u.current = !1, w("LOCKED_AT_BOTTOM");
719
728
  },
720
- H === "smooth" ? 500 : 50
729
+ L === "smooth" ? 500 : 50
721
730
  );
722
- return () => clearTimeout(P);
731
+ return () => clearTimeout(x);
723
732
  }
724
733
  return () => {
725
- x && clearInterval(x);
734
+ M && clearInterval(M);
726
735
  };
727
- }, [C, _, G]), ot(() => {
736
+ }, [C, A, G]), ot(() => {
728
737
  const k = E.current;
729
738
  if (!k) return;
730
- const x = n, H = () => {
739
+ const M = n, L = () => {
731
740
  if (b.current)
732
741
  return;
733
- const { scrollTop: P, scrollHeight: Q, clientHeight: ft } = k;
734
- if (Q - P - ft < 10 ? (C !== "LOCKED_AT_BOTTOM" && A("LOCKED_AT_BOTTOM"), V.current = null) : (C !== "IDLE_NOT_AT_BOTTOM" && A("IDLE_NOT_AT_BOTTOM"), V.current = {
735
- top: P,
736
- height: Q
737
- }), Math.abs(P - M.current) < x)
742
+ const { scrollTop: x, scrollHeight: X, clientHeight: it } = k;
743
+ if (X - x - it < 10 ? (C !== "LOCKED_AT_BOTTOM" && w("LOCKED_AT_BOTTOM"), V.current = null) : (C !== "IDLE_NOT_AT_BOTTOM" && w("IDLE_NOT_AT_BOTTOM"), V.current = {
744
+ top: x,
745
+ height: X
746
+ }), Math.abs(x - P.current) < M)
738
747
  return;
739
748
  console.log(
740
- `Threshold passed at ${P}px. Recalculating range...`
749
+ `Threshold passed at ${x}px. Recalculating range...`
741
750
  );
742
- let yt = _ - 1, pt = 0, Ct = 0;
743
- for (; pt <= yt; ) {
744
- const mt = Math.floor((pt + yt) / 2);
745
- G[mt] < P ? (Ct = mt, pt = mt + 1) : yt = mt - 1;
751
+ let pt = A - 1, Et = 0, $t = 0;
752
+ for (; Et <= pt; ) {
753
+ const mt = Math.floor((Et + pt) / 2);
754
+ G[mt] < x ? ($t = mt, Et = mt + 1) : pt = mt - 1;
746
755
  }
747
- const $t = Math.max(0, Ct - a);
748
- let St = $t;
749
- const Ut = P + ft;
750
- for (; St < _ && G[St] < Ut; )
756
+ const kt = Math.max(0, $t - a);
757
+ let St = kt;
758
+ const Ut = x + it;
759
+ for (; St < A && G[St] < Ut; )
751
760
  St++;
752
- w({
753
- startIndex: $t,
754
- endIndex: Math.min(_, St + a)
755
- }), M.current = P;
761
+ _({
762
+ startIndex: kt,
763
+ endIndex: Math.min(A, St + a)
764
+ }), P.current = x;
756
765
  };
757
- return k.addEventListener("scroll", H, {
766
+ return k.addEventListener("scroll", L, {
758
767
  passive: !0
759
- }), () => k.removeEventListener("scroll", H);
760
- }, [_, G, n, a, C]);
761
- const st = kt(() => {
768
+ }), () => k.removeEventListener("scroll", L);
769
+ }, [A, G, n, a, C]);
770
+ const st = bt(() => {
762
771
  console.log(
763
772
  "USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
764
- ), A("SCROLLING_TO_BOTTOM");
765
- }, []), gt = kt(
766
- (k, x = "smooth") => {
767
- E.current && G[k] !== void 0 && (A("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
773
+ ), w("SCROLLING_TO_BOTTOM");
774
+ }, []), ft = bt(
775
+ (k, M = "smooth") => {
776
+ E.current && G[k] !== void 0 && (w("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
768
777
  top: G[k],
769
- behavior: x
778
+ behavior: M
770
779
  }));
771
780
  },
772
781
  [G]
@@ -777,7 +786,7 @@ function It(t, c, m, g) {
777
786
  },
778
787
  inner: {
779
788
  style: {
780
- height: `${D}px`,
789
+ height: `${H}px`,
781
790
  position: "relative"
782
791
  }
783
792
  },
@@ -788,10 +797,10 @@ function It(t, c, m, g) {
788
797
  }
789
798
  };
790
799
  return {
791
- virtualState: B,
800
+ virtualState: F,
792
801
  virtualizerProps: jt,
793
802
  scrollToBottom: st,
794
- scrollToIndex: gt
803
+ scrollToIndex: ft
795
804
  };
796
805
  };
797
806
  if (l === "stateSort")
@@ -825,19 +834,19 @@ function It(t, c, m, g) {
825
834
  const u = n[i], E = [...r, i.toString()], y = s(u, E, S);
826
835
  return e(u, y, {
827
836
  register: () => {
828
- const [, C] = K({}), A = `${m}-${r.join(".")}-${i}`;
829
- ct(() => {
830
- const b = `${t}////${A}`, F = o.getState().stateComponents.get(t) || {
837
+ const [, C] = K({}), w = `${m}-${r.join(".")}-${i}`;
838
+ lt(() => {
839
+ const b = `${t}////${w}`, B = o.getState().stateComponents.get(t) || {
831
840
  components: /* @__PURE__ */ new Map()
832
841
  };
833
- return F.components.set(b, {
842
+ return B.components.set(b, {
834
843
  forceUpdate: () => C({}),
835
844
  paths: /* @__PURE__ */ new Set([E.join(".")])
836
- }), o.getState().stateComponents.set(t, F), () => {
845
+ }), o.getState().stateComponents.set(t, B), () => {
837
846
  const Y = o.getState().stateComponents.get(t);
838
847
  Y && Y.components.delete(b);
839
848
  };
840
- }, [t, A]);
849
+ }, [t, w]);
841
850
  },
842
851
  index: f,
843
852
  originalIndex: i
@@ -861,7 +870,7 @@ function It(t, c, m, g) {
861
870
  );
862
871
  });
863
872
  if (l === "$stateMap")
864
- return (e) => lt(re, {
873
+ return (e) => dt(oe, {
865
874
  proxy: {
866
875
  _stateKey: t,
867
876
  _path: r,
@@ -874,11 +883,11 @@ function It(t, c, m, g) {
874
883
  return (e) => {
875
884
  const n = o.getState().getNestedState(t, r);
876
885
  return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
877
- const u = n[i], E = [...r, i.toString()], y = s(u, E, S), w = `${m}-${r.join(".")}-${i}`;
878
- return lt(ae, {
886
+ const u = n[i], E = [...r, i.toString()], y = s(u, E, S), _ = `${m}-${r.join(".")}-${i}`;
887
+ return dt(se, {
879
888
  key: i,
880
889
  stateKey: t,
881
- itemComponentId: w,
890
+ itemComponentId: _,
882
891
  itemPath: E,
883
892
  children: e(
884
893
  u,
@@ -918,7 +927,7 @@ function It(t, c, m, g) {
918
927
  return s(a, i);
919
928
  };
920
929
  if (l === "insert")
921
- return (e) => (p(r), Et(c, e, r, t), s(
930
+ return (e) => (p(r), Ot(c, e, r, t), s(
922
931
  o.getState().getNestedState(t, r),
923
932
  r
924
933
  ));
@@ -929,19 +938,19 @@ function It(t, c, m, g) {
929
938
  if (!i.some((y) => {
930
939
  if (n) {
931
940
  const C = n.every(
932
- (A) => J(y[A], f[A])
941
+ (w) => J(y[w], f[w])
933
942
  );
934
943
  return C && (u = y), C;
935
944
  }
936
- const w = J(y, f);
937
- return w && (u = y), w;
945
+ const _ = J(y, f);
946
+ return _ && (u = y), _;
938
947
  }))
939
- p(r), Et(c, f, r, t);
948
+ p(r), Ot(c, f, r, t);
940
949
  else if (a && u) {
941
- const y = a(u), w = i.map(
950
+ const y = a(u), _ = i.map(
942
951
  (C) => J(C, u) ? y : C
943
952
  );
944
- p(r), it(c, w, r);
953
+ p(r), ct(c, _, r);
945
954
  }
946
955
  };
947
956
  if (l === "cut")
@@ -960,7 +969,7 @@ function It(t, c, m, g) {
960
969
  if (l === "toggleByValue")
961
970
  return (e) => {
962
971
  const n = T.findIndex((a) => a === e);
963
- n > -1 ? ht(c, r, t, n) : Et(c, e, r, t);
972
+ n > -1 ? ht(c, r, t, n) : Ot(c, e, r, t);
964
973
  };
965
974
  if (l === "stateFind")
966
975
  return (e) => {
@@ -1001,13 +1010,13 @@ function It(t, c, m, g) {
1001
1010
  return o.getState().getNestedState(t, r);
1002
1011
  };
1003
1012
  if (l === "$derive")
1004
- return (d) => Vt({
1013
+ return (d) => Gt({
1005
1014
  _stateKey: t,
1006
1015
  _path: r,
1007
1016
  _effect: d.toString()
1008
1017
  });
1009
1018
  if (l === "$get")
1010
- return () => Vt({
1019
+ return () => Gt({
1011
1020
  _stateKey: t,
1012
1021
  _path: r
1013
1022
  });
@@ -1026,7 +1035,7 @@ function It(t, c, m, g) {
1026
1035
  const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
1027
1036
  d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
1028
1037
  const i = o.getState().getNestedState(t, [...e]);
1029
- it(c, i, e), p(e);
1038
+ ct(c, i, e), p(e);
1030
1039
  };
1031
1040
  if (l === "toggleSelected")
1032
1041
  return () => {
@@ -1037,7 +1046,7 @@ function It(t, c, m, g) {
1037
1046
  a === e ? void 0 : e
1038
1047
  );
1039
1048
  const i = o.getState().getNestedState(t, [...d]);
1040
- it(c, i, d), p(d);
1049
+ ct(c, i, d), p(d);
1041
1050
  };
1042
1051
  if (r.length == 0) {
1043
1052
  if (l === "addValidation")
@@ -1045,15 +1054,15 @@ function It(t, c, m, g) {
1045
1054
  const e = o.getState().getInitialOptions(t)?.validation;
1046
1055
  if (!e?.key)
1047
1056
  throw new Error("Validation key not found");
1048
- X(e.key), console.log("addValidationError", d), d.forEach((n) => {
1057
+ Q(e.key), console.log("addValidationError", d), d.forEach((n) => {
1049
1058
  const a = [e.key, ...n.path].join(".");
1050
- console.log("fullErrorPath", a), Rt(a, n.message);
1051
- }), dt(t);
1059
+ console.log("fullErrorPath", a), Dt(a, n.message);
1060
+ }), ut(t);
1052
1061
  };
1053
1062
  if (l === "applyJsonPatch")
1054
1063
  return (d) => {
1055
- const e = o.getState().cogsStateStore[t], a = Yt(e, d).newDocument;
1056
- Dt(
1064
+ const e = o.getState().cogsStateStore[t], a = Zt(e, d).newDocument;
1065
+ Ht(
1057
1066
  t,
1058
1067
  o.getState().initialStateGlobal[t],
1059
1068
  a,
@@ -1063,57 +1072,57 @@ function It(t, c, m, g) {
1063
1072
  );
1064
1073
  const i = o.getState().stateComponents.get(t);
1065
1074
  if (i) {
1066
- const f = _t(e, a), u = new Set(f);
1075
+ const f = At(e, a), u = new Set(f);
1067
1076
  for (const [
1068
1077
  E,
1069
1078
  y
1070
1079
  ] of i.components.entries()) {
1071
- let w = !1;
1080
+ let _ = !1;
1072
1081
  const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
1073
1082
  if (!C.includes("none")) {
1074
1083
  if (C.includes("all")) {
1075
1084
  y.forceUpdate();
1076
1085
  continue;
1077
1086
  }
1078
- if (C.includes("component") && (y.paths.has("") && (w = !0), !w))
1079
- for (const A of u) {
1080
- if (y.paths.has(A)) {
1081
- w = !0;
1087
+ if (C.includes("component") && (y.paths.has("") && (_ = !0), !_))
1088
+ for (const w of u) {
1089
+ if (y.paths.has(w)) {
1090
+ _ = !0;
1082
1091
  break;
1083
1092
  }
1084
- let b = A.lastIndexOf(".");
1093
+ let b = w.lastIndexOf(".");
1085
1094
  for (; b !== -1; ) {
1086
- const F = A.substring(0, b);
1087
- if (y.paths.has(F)) {
1088
- w = !0;
1095
+ const B = w.substring(0, b);
1096
+ if (y.paths.has(B)) {
1097
+ _ = !0;
1089
1098
  break;
1090
1099
  }
1091
- const Y = A.substring(
1100
+ const Y = w.substring(
1092
1101
  b + 1
1093
1102
  );
1094
1103
  if (!isNaN(Number(Y))) {
1095
- const M = F.lastIndexOf(".");
1096
- if (M !== -1) {
1097
- const $ = F.substring(
1104
+ const P = B.lastIndexOf(".");
1105
+ if (P !== -1) {
1106
+ const $ = B.substring(
1098
1107
  0,
1099
- M
1108
+ P
1100
1109
  );
1101
1110
  if (y.paths.has($)) {
1102
- w = !0;
1111
+ _ = !0;
1103
1112
  break;
1104
1113
  }
1105
1114
  }
1106
1115
  }
1107
- b = F.lastIndexOf(".");
1116
+ b = B.lastIndexOf(".");
1108
1117
  }
1109
- if (w) break;
1118
+ if (_) break;
1110
1119
  }
1111
- if (!w && C.includes("deps") && y.depsFunction) {
1112
- const A = y.depsFunction(a);
1120
+ if (!_ && C.includes("deps") && y.depsFunction) {
1121
+ const w = y.depsFunction(a);
1113
1122
  let b = !1;
1114
- typeof A == "boolean" ? A && (b = !0) : J(y.deps, A) || (y.deps = A, b = !0), b && (w = !0);
1123
+ typeof w == "boolean" ? w && (b = !0) : J(y.deps, w) || (y.deps = w, b = !0), b && (_ = !0);
1115
1124
  }
1116
- w && y.forceUpdate();
1125
+ _ && y.forceUpdate();
1117
1126
  }
1118
1127
  }
1119
1128
  }
@@ -1125,18 +1134,18 @@ function It(t, c, m, g) {
1125
1134
  throw new Error("Zod schema not found");
1126
1135
  if (!d?.key)
1127
1136
  throw new Error("Validation key not found");
1128
- X(d.key);
1137
+ Q(d.key);
1129
1138
  const n = o.getState().cogsStateStore[t];
1130
1139
  try {
1131
1140
  const a = o.getState().getValidationErrors(d.key);
1132
1141
  a && a.length > 0 && a.forEach(([f]) => {
1133
- f && f.startsWith(d.key) && X(f);
1142
+ f && f.startsWith(d.key) && Q(f);
1134
1143
  });
1135
1144
  const i = d.zodSchema.safeParse(n);
1136
1145
  return i.success ? !0 : (i.error.errors.forEach((u) => {
1137
- const E = u.path, y = u.message, w = [d.key, ...E].join(".");
1138
- e(w, y);
1139
- }), dt(t), !1);
1146
+ const E = u.path, y = u.message, _ = [d.key, ...E].join(".");
1147
+ e(_, y);
1148
+ }), ut(t), !1);
1140
1149
  } catch (a) {
1141
1150
  return console.error("Zod schema validation failed", a), !1;
1142
1151
  }
@@ -1145,7 +1154,7 @@ function It(t, c, m, g) {
1145
1154
  if (l === "getComponents")
1146
1155
  return () => o().stateComponents.get(t);
1147
1156
  if (l === "getAllFormRefs")
1148
- return () => bt.getState().getFormRefsByStateKey(t);
1157
+ return () => Mt.getState().getFormRefsByStateKey(t);
1149
1158
  if (l === "_initialState")
1150
1159
  return o.getState().initialStateGlobal[t];
1151
1160
  if (l === "_serverState")
@@ -1158,13 +1167,13 @@ function It(t, c, m, g) {
1158
1167
  if (l === "removeValidation") return v.removeValidation;
1159
1168
  }
1160
1169
  if (l === "getFormRef")
1161
- return () => bt.getState().getFormRef(t + "." + r.join("."));
1170
+ return () => Mt.getState().getFormRef(t + "." + r.join("."));
1162
1171
  if (l === "validationWrapper")
1163
1172
  return ({
1164
1173
  children: d,
1165
1174
  hideMessage: e
1166
- }) => /* @__PURE__ */ Ot(
1167
- zt,
1175
+ }) => /* @__PURE__ */ _t(
1176
+ qt,
1168
1177
  {
1169
1178
  formOpts: e ? { validation: { message: "" } } : void 0,
1170
1179
  path: r,
@@ -1180,21 +1189,21 @@ function It(t, c, m, g) {
1180
1189
  if (l === "update")
1181
1190
  return (d, e) => {
1182
1191
  if (e?.debounce)
1183
- Wt(() => {
1184
- it(c, d, r, "");
1192
+ zt(() => {
1193
+ ct(c, d, r, "");
1185
1194
  const n = o.getState().getNestedState(t, r);
1186
1195
  e?.afterUpdate && e.afterUpdate(n);
1187
1196
  }, e.debounce);
1188
1197
  else {
1189
- it(c, d, r, "");
1198
+ ct(c, d, r, "");
1190
1199
  const n = o.getState().getNestedState(t, r);
1191
1200
  e?.afterUpdate && e.afterUpdate(n);
1192
1201
  }
1193
1202
  p(r);
1194
1203
  };
1195
1204
  if (l === "formElement")
1196
- return (d, e) => /* @__PURE__ */ Ot(
1197
- qt,
1205
+ return (d, e) => /* @__PURE__ */ _t(
1206
+ Jt,
1198
1207
  {
1199
1208
  setState: c,
1200
1209
  stateKey: t,
@@ -1203,8 +1212,8 @@ function It(t, c, m, g) {
1203
1212
  formOpts: e
1204
1213
  }
1205
1214
  );
1206
- const L = [...r, l], at = o.getState().getNestedState(t, L);
1207
- return s(at, L, S);
1215
+ const R = [...r, l], at = o.getState().getNestedState(t, R);
1216
+ return s(at, R, S);
1208
1217
  }
1209
1218
  }, z = new Proxy(j, U);
1210
1219
  return I.set(W, {
@@ -1216,10 +1225,10 @@ function It(t, c, m, g) {
1216
1225
  o.getState().getNestedState(t, [])
1217
1226
  );
1218
1227
  }
1219
- function Vt(t) {
1220
- return lt(oe, { proxy: t });
1228
+ function Gt(t) {
1229
+ return dt(ae, { proxy: t });
1221
1230
  }
1222
- function re({
1231
+ function oe({
1223
1232
  proxy: t,
1224
1233
  rebuildStateShape: c
1225
1234
  }) {
@@ -1231,7 +1240,7 @@ function re({
1231
1240
  (I, N, p, v, s) => t._mapFn(I, N, p, v, s)
1232
1241
  ) : null;
1233
1242
  }
1234
- function oe({
1243
+ function ae({
1235
1244
  proxy: t
1236
1245
  }) {
1237
1246
  const c = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
@@ -1264,14 +1273,14 @@ function oe({
1264
1273
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1265
1274
  const W = document.createTextNode(String(S));
1266
1275
  g.replaceWith(W);
1267
- }, [t._stateKey, t._path.join("."), t._effect]), lt("span", {
1276
+ }, [t._stateKey, t._path.join("."), t._effect]), dt("span", {
1268
1277
  ref: c,
1269
1278
  style: { display: "none" },
1270
1279
  "data-signal-id": m
1271
1280
  });
1272
1281
  }
1273
1282
  function pe(t) {
1274
- const c = Ht(
1283
+ const c = Bt(
1275
1284
  (m) => {
1276
1285
  const g = o.getState().stateComponents.get(t._stateKey) || {
1277
1286
  components: /* @__PURE__ */ new Map()
@@ -1283,22 +1292,22 @@ function pe(t) {
1283
1292
  },
1284
1293
  () => o.getState().getNestedState(t._stateKey, t._path)
1285
1294
  );
1286
- return lt("text", {}, String(c));
1295
+ return dt("text", {}, String(c));
1287
1296
  }
1288
- function ae({
1297
+ function se({
1289
1298
  stateKey: t,
1290
1299
  itemComponentId: c,
1291
1300
  itemPath: m,
1292
1301
  children: g
1293
1302
  }) {
1294
- const [, I] = K({}), [N, p] = Zt(), v = q(null);
1303
+ const [, I] = K({}), [N, p] = Xt(), v = q(null);
1295
1304
  return ot(() => {
1296
1305
  p.height > 0 && p.height !== v.current && (v.current = p.height, o.getState().setShadowMetadata(t, m, {
1297
1306
  virtualizer: {
1298
1307
  itemHeight: p.height
1299
1308
  }
1300
1309
  }));
1301
- }, [p.height, t, m]), ct(() => {
1310
+ }, [p.height, t, m]), lt(() => {
1302
1311
  const s = `${t}////${c}`, T = o.getState().stateComponents.get(t) || {
1303
1312
  components: /* @__PURE__ */ new Map()
1304
1313
  };
@@ -1309,14 +1318,14 @@ function ae({
1309
1318
  const r = o.getState().stateComponents.get(t);
1310
1319
  r && r.components.delete(s);
1311
1320
  };
1312
- }, [t, c, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: N, children: g });
1321
+ }, [t, c, m.join(".")]), /* @__PURE__ */ _t("div", { ref: N, children: g });
1313
1322
  }
1314
1323
  export {
1315
- Vt as $cogsSignal,
1324
+ Gt as $cogsSignal,
1316
1325
  pe as $cogsSignalStore,
1317
1326
  Ie as addStateOptions,
1318
1327
  ve as createCogsState,
1319
1328
  ye as notifyComponent,
1320
- ne as useCogsStateFn
1329
+ re as useCogsStateFn
1321
1330
  };
1322
1331
  //# sourceMappingURL=CogsState.jsx.map