cogsbox-state 0.5.401 → 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 Ut, startTransition as Ft, useCallback as kt } from "react";
4
- import { transformStateFunc as Bt, isDeepEqual as J, isFunction as tt, getNestedValue as X, 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, H] = 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,
@@ -68,24 +68,24 @@ const ve = (t, c) => {
68
68
  serverState: s?.serverState
69
69
  }
70
70
  );
71
- return H;
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,
81
+ getKeyState: Rt,
82
+ getValidationErrors: Qt,
83
+ setStateLog: Kt,
84
+ updateInitialStateGlobal: Ct,
85
+ addValidationError: Dt,
86
86
  removeValidationError: Q,
87
- setServerSyncActions: Kt
88
- } = o.getState(), Pt = (t, c, m, g, I) => {
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,22 +157,22 @@ 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 {
164
- oldValue: X(c, g),
165
- newValue: X(m, g)
164
+ oldValue: Z(c, g),
165
+ newValue: Z(m, g)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: X(m, g)
171
+ newValue: Z(m, g)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: X(c, g),
175
+ oldValue: Z(c, g),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -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, H] = 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,203 +212,203 @@ 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") || H({});
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()
250
250
  };
251
251
  return n.components.set(e, {
252
- forceUpdate: () => H({}),
252
+ forceUpdate: () => j({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
255
  depsFunction: N || void 0,
256
256
  reactiveType: p ?? ["component", "deps"]
257
- }), o.getState().stateComponents.set(h, n), H({}), () => {
257
+ }), o.getState().stateComponents.set(h, n), j({}), () => {
258
258
  n && (n.components.delete(e), n.components.size === 0 && o.getState().stateComponents.delete(h));
259
259
  };
260
260
  }, []);
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 = X(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 ? X(E, n.slice(0, -1)) : X(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 && Q(
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 && Q(
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
- Q($), 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 = X(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();
@@ -450,7 +450,7 @@ function It(t, c, m, g) {
450
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
- const W = s(S, []), H = rt(t), U = tt(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, z = `${g}-${t}-${U}`;
453
+ const W = s(S, []), j = rt(t), U = tt(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, z = `${g}-${t}-${U}`;
454
454
  z && localStorage.removeItem(z), Tt(t, W), nt(t, S);
455
455
  const h = o.getState().stateComponents.get(t);
456
456
  return h && h.components.forEach((l) => {
@@ -464,9 +464,9 @@ function It(t, c, m, g) {
464
464
  c,
465
465
  m,
466
466
  g
467
- ), S = o.getState().initialStateGlobal[t], W = rt(t), H = tt(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${g}-${t}-${H}`;
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,27 +480,27 @@ 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) {
487
487
  const W = r.map(String).join(".");
488
488
  I.get(W);
489
- const H = function() {
489
+ const j = function() {
490
490
  return o().getNestedState(t, r);
491
491
  };
492
492
  Object.keys(v).forEach((h) => {
493
- H[h] = v[h];
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
  );
@@ -568,7 +568,7 @@ function It(t, c, m, g) {
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
571
- const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = X(e, r);
571
+ const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = Z(e, r);
572
572
  return J(d, n) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
@@ -576,7 +576,7 @@ function It(t, c, m, g) {
576
576
  const d = o().getNestedState(
577
577
  t,
578
578
  r
579
- ), e = o.getState().initialStateGlobal[t], n = X(e, r);
579
+ ), e = o.getState().initialStateGlobal[t], n = Z(e, r);
580
580
  return J(d, n) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
@@ -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 j = [];
639
- for (let P = 0; P < _; P++) {
640
- j[P] = x;
641
- const Z = k[P]?.virtualizer?.itemHeight;
642
- x += Z || 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: j };
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), j = Array.from(
653
- { length: x - k },
654
- (Z, ft) => k + ft
655
- ), P = j.map((Z) => O[Z]);
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: j
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: j, height: P } = V.current;
667
- b.current = !0, k.scrollTop = j + (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,104 +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 j = _ - 1, Z = (o.getState().getShadowMetadata(t, r) || [])[j]?.virtualizer?.itemHeight || 0;
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;
701
705
  console.log(
702
- "ACTION (GETTING_HEIGHTS): lastItemHeight =",
703
- Z,
704
- " index =",
705
- j
706
- ), Z > 0 && (clearInterval(x), u.current || (console.log(
706
+ `ACTION (GETTING_HEIGHTS): attempt ${L}, lastItemHeight =`,
707
+ yt
708
+ ), yt > 0 ? (clearInterval(M), console.log(
707
709
  "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
708
- ), 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"));
709
713
  }, 100);
710
- else if (C === "SCROLLING_TO_BOTTOM") {
714
+ } else if (C === "SCROLLING_TO_BOTTOM") {
711
715
  console.log(
712
716
  "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
713
717
  ), b.current = !0;
714
- const j = F.current === 0 ? "auto" : "smooth";
718
+ const L = B.current === 0 ? "auto" : "smooth";
715
719
  k.scrollTo({
716
720
  top: k.scrollHeight,
717
- behavior: j
721
+ behavior: L
718
722
  });
719
- const P = setTimeout(
723
+ const x = setTimeout(
720
724
  () => {
721
725
  console.log(
722
726
  "ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
723
- ), b.current = !1, u.current = !1, A("LOCKED_AT_BOTTOM");
727
+ ), b.current = !1, u.current = !1, w("LOCKED_AT_BOTTOM");
724
728
  },
725
- j === "smooth" ? 500 : 50
729
+ L === "smooth" ? 500 : 50
726
730
  );
727
- return () => clearTimeout(P);
731
+ return () => clearTimeout(x);
728
732
  }
729
733
  return () => {
730
- x && clearInterval(x);
734
+ M && clearInterval(M);
731
735
  };
732
- }, [C, _, G]), ot(() => {
736
+ }, [C, A, G]), ot(() => {
733
737
  const k = E.current;
734
738
  if (!k) return;
735
- const x = n, j = () => {
739
+ const M = n, L = () => {
736
740
  if (b.current)
737
741
  return;
738
- const { scrollTop: P, scrollHeight: Z, clientHeight: ft } = k;
739
- if (Z - 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 = {
740
- top: P,
741
- height: Z
742
- }), 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)
743
747
  return;
744
748
  console.log(
745
- `Threshold passed at ${P}px. Recalculating range...`
749
+ `Threshold passed at ${x}px. Recalculating range...`
746
750
  );
747
- let yt = _ - 1, pt = 0, Ct = 0;
748
- for (; pt <= yt; ) {
749
- const mt = Math.floor((pt + yt) / 2);
750
- 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;
751
755
  }
752
- const $t = Math.max(0, Ct - a);
753
- let St = $t;
754
- const Ht = P + ft;
755
- for (; St < _ && G[St] < Ht; )
756
+ const kt = Math.max(0, $t - a);
757
+ let St = kt;
758
+ const Ut = x + it;
759
+ for (; St < A && G[St] < Ut; )
756
760
  St++;
757
- w({
758
- startIndex: $t,
759
- endIndex: Math.min(_, St + a)
760
- }), M.current = P;
761
+ _({
762
+ startIndex: kt,
763
+ endIndex: Math.min(A, St + a)
764
+ }), P.current = x;
761
765
  };
762
- return k.addEventListener("scroll", j, {
766
+ return k.addEventListener("scroll", L, {
763
767
  passive: !0
764
- }), () => k.removeEventListener("scroll", j);
765
- }, [_, G, n, a, C]);
766
- const st = kt(() => {
768
+ }), () => k.removeEventListener("scroll", L);
769
+ }, [A, G, n, a, C]);
770
+ const st = bt(() => {
767
771
  console.log(
768
772
  "USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
769
- ), A("SCROLLING_TO_BOTTOM");
770
- }, []), gt = kt(
771
- (k, x = "smooth") => {
772
- 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({
773
777
  top: G[k],
774
- behavior: x
778
+ behavior: M
775
779
  }));
776
780
  },
777
781
  [G]
@@ -782,7 +786,7 @@ function It(t, c, m, g) {
782
786
  },
783
787
  inner: {
784
788
  style: {
785
- height: `${D}px`,
789
+ height: `${H}px`,
786
790
  position: "relative"
787
791
  }
788
792
  },
@@ -793,10 +797,10 @@ function It(t, c, m, g) {
793
797
  }
794
798
  };
795
799
  return {
796
- virtualState: B,
800
+ virtualState: F,
797
801
  virtualizerProps: jt,
798
802
  scrollToBottom: st,
799
- scrollToIndex: gt
803
+ scrollToIndex: ft
800
804
  };
801
805
  };
802
806
  if (l === "stateSort")
@@ -830,19 +834,19 @@ function It(t, c, m, g) {
830
834
  const u = n[i], E = [...r, i.toString()], y = s(u, E, S);
831
835
  return e(u, y, {
832
836
  register: () => {
833
- const [, C] = K({}), A = `${m}-${r.join(".")}-${i}`;
834
- ct(() => {
835
- 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) || {
836
840
  components: /* @__PURE__ */ new Map()
837
841
  };
838
- return F.components.set(b, {
842
+ return B.components.set(b, {
839
843
  forceUpdate: () => C({}),
840
844
  paths: /* @__PURE__ */ new Set([E.join(".")])
841
- }), o.getState().stateComponents.set(t, F), () => {
845
+ }), o.getState().stateComponents.set(t, B), () => {
842
846
  const Y = o.getState().stateComponents.get(t);
843
847
  Y && Y.components.delete(b);
844
848
  };
845
- }, [t, A]);
849
+ }, [t, w]);
846
850
  },
847
851
  index: f,
848
852
  originalIndex: i
@@ -866,7 +870,7 @@ function It(t, c, m, g) {
866
870
  );
867
871
  });
868
872
  if (l === "$stateMap")
869
- return (e) => lt(re, {
873
+ return (e) => dt(oe, {
870
874
  proxy: {
871
875
  _stateKey: t,
872
876
  _path: r,
@@ -879,11 +883,11 @@ function It(t, c, m, g) {
879
883
  return (e) => {
880
884
  const n = o.getState().getNestedState(t, r);
881
885
  return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
882
- const u = n[i], E = [...r, i.toString()], y = s(u, E, S), w = `${m}-${r.join(".")}-${i}`;
883
- 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, {
884
888
  key: i,
885
889
  stateKey: t,
886
- itemComponentId: w,
890
+ itemComponentId: _,
887
891
  itemPath: E,
888
892
  children: e(
889
893
  u,
@@ -923,7 +927,7 @@ function It(t, c, m, g) {
923
927
  return s(a, i);
924
928
  };
925
929
  if (l === "insert")
926
- return (e) => (p(r), Et(c, e, r, t), s(
930
+ return (e) => (p(r), Ot(c, e, r, t), s(
927
931
  o.getState().getNestedState(t, r),
928
932
  r
929
933
  ));
@@ -934,19 +938,19 @@ function It(t, c, m, g) {
934
938
  if (!i.some((y) => {
935
939
  if (n) {
936
940
  const C = n.every(
937
- (A) => J(y[A], f[A])
941
+ (w) => J(y[w], f[w])
938
942
  );
939
943
  return C && (u = y), C;
940
944
  }
941
- const w = J(y, f);
942
- return w && (u = y), w;
945
+ const _ = J(y, f);
946
+ return _ && (u = y), _;
943
947
  }))
944
- p(r), Et(c, f, r, t);
948
+ p(r), Ot(c, f, r, t);
945
949
  else if (a && u) {
946
- const y = a(u), w = i.map(
950
+ const y = a(u), _ = i.map(
947
951
  (C) => J(C, u) ? y : C
948
952
  );
949
- p(r), it(c, w, r);
953
+ p(r), ct(c, _, r);
950
954
  }
951
955
  };
952
956
  if (l === "cut")
@@ -965,7 +969,7 @@ function It(t, c, m, g) {
965
969
  if (l === "toggleByValue")
966
970
  return (e) => {
967
971
  const n = T.findIndex((a) => a === e);
968
- 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);
969
973
  };
970
974
  if (l === "stateFind")
971
975
  return (e) => {
@@ -1006,13 +1010,13 @@ function It(t, c, m, g) {
1006
1010
  return o.getState().getNestedState(t, r);
1007
1011
  };
1008
1012
  if (l === "$derive")
1009
- return (d) => Vt({
1013
+ return (d) => Gt({
1010
1014
  _stateKey: t,
1011
1015
  _path: r,
1012
1016
  _effect: d.toString()
1013
1017
  });
1014
1018
  if (l === "$get")
1015
- return () => Vt({
1019
+ return () => Gt({
1016
1020
  _stateKey: t,
1017
1021
  _path: r
1018
1022
  });
@@ -1031,7 +1035,7 @@ function It(t, c, m, g) {
1031
1035
  const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
1032
1036
  d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
1033
1037
  const i = o.getState().getNestedState(t, [...e]);
1034
- it(c, i, e), p(e);
1038
+ ct(c, i, e), p(e);
1035
1039
  };
1036
1040
  if (l === "toggleSelected")
1037
1041
  return () => {
@@ -1042,7 +1046,7 @@ function It(t, c, m, g) {
1042
1046
  a === e ? void 0 : e
1043
1047
  );
1044
1048
  const i = o.getState().getNestedState(t, [...d]);
1045
- it(c, i, d), p(d);
1049
+ ct(c, i, d), p(d);
1046
1050
  };
1047
1051
  if (r.length == 0) {
1048
1052
  if (l === "addValidation")
@@ -1052,13 +1056,13 @@ function It(t, c, m, g) {
1052
1056
  throw new Error("Validation key not found");
1053
1057
  Q(e.key), console.log("addValidationError", d), d.forEach((n) => {
1054
1058
  const a = [e.key, ...n.path].join(".");
1055
- console.log("fullErrorPath", a), Rt(a, n.message);
1056
- }), dt(t);
1059
+ console.log("fullErrorPath", a), Dt(a, n.message);
1060
+ }), ut(t);
1057
1061
  };
1058
1062
  if (l === "applyJsonPatch")
1059
1063
  return (d) => {
1060
- const e = o.getState().cogsStateStore[t], a = Yt(e, d).newDocument;
1061
- Dt(
1064
+ const e = o.getState().cogsStateStore[t], a = Zt(e, d).newDocument;
1065
+ Ht(
1062
1066
  t,
1063
1067
  o.getState().initialStateGlobal[t],
1064
1068
  a,
@@ -1068,57 +1072,57 @@ function It(t, c, m, g) {
1068
1072
  );
1069
1073
  const i = o.getState().stateComponents.get(t);
1070
1074
  if (i) {
1071
- const f = _t(e, a), u = new Set(f);
1075
+ const f = At(e, a), u = new Set(f);
1072
1076
  for (const [
1073
1077
  E,
1074
1078
  y
1075
1079
  ] of i.components.entries()) {
1076
- let w = !1;
1080
+ let _ = !1;
1077
1081
  const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
1078
1082
  if (!C.includes("none")) {
1079
1083
  if (C.includes("all")) {
1080
1084
  y.forceUpdate();
1081
1085
  continue;
1082
1086
  }
1083
- if (C.includes("component") && (y.paths.has("") && (w = !0), !w))
1084
- for (const A of u) {
1085
- if (y.paths.has(A)) {
1086
- 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;
1087
1091
  break;
1088
1092
  }
1089
- let b = A.lastIndexOf(".");
1093
+ let b = w.lastIndexOf(".");
1090
1094
  for (; b !== -1; ) {
1091
- const F = A.substring(0, b);
1092
- if (y.paths.has(F)) {
1093
- w = !0;
1095
+ const B = w.substring(0, b);
1096
+ if (y.paths.has(B)) {
1097
+ _ = !0;
1094
1098
  break;
1095
1099
  }
1096
- const Y = A.substring(
1100
+ const Y = w.substring(
1097
1101
  b + 1
1098
1102
  );
1099
1103
  if (!isNaN(Number(Y))) {
1100
- const M = F.lastIndexOf(".");
1101
- if (M !== -1) {
1102
- const $ = F.substring(
1104
+ const P = B.lastIndexOf(".");
1105
+ if (P !== -1) {
1106
+ const $ = B.substring(
1103
1107
  0,
1104
- M
1108
+ P
1105
1109
  );
1106
1110
  if (y.paths.has($)) {
1107
- w = !0;
1111
+ _ = !0;
1108
1112
  break;
1109
1113
  }
1110
1114
  }
1111
1115
  }
1112
- b = F.lastIndexOf(".");
1116
+ b = B.lastIndexOf(".");
1113
1117
  }
1114
- if (w) break;
1118
+ if (_) break;
1115
1119
  }
1116
- if (!w && C.includes("deps") && y.depsFunction) {
1117
- const A = y.depsFunction(a);
1120
+ if (!_ && C.includes("deps") && y.depsFunction) {
1121
+ const w = y.depsFunction(a);
1118
1122
  let b = !1;
1119
- 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);
1120
1124
  }
1121
- w && y.forceUpdate();
1125
+ _ && y.forceUpdate();
1122
1126
  }
1123
1127
  }
1124
1128
  }
@@ -1139,9 +1143,9 @@ function It(t, c, m, g) {
1139
1143
  });
1140
1144
  const i = d.zodSchema.safeParse(n);
1141
1145
  return i.success ? !0 : (i.error.errors.forEach((u) => {
1142
- const E = u.path, y = u.message, w = [d.key, ...E].join(".");
1143
- e(w, y);
1144
- }), dt(t), !1);
1146
+ const E = u.path, y = u.message, _ = [d.key, ...E].join(".");
1147
+ e(_, y);
1148
+ }), ut(t), !1);
1145
1149
  } catch (a) {
1146
1150
  return console.error("Zod schema validation failed", a), !1;
1147
1151
  }
@@ -1150,7 +1154,7 @@ function It(t, c, m, g) {
1150
1154
  if (l === "getComponents")
1151
1155
  return () => o().stateComponents.get(t);
1152
1156
  if (l === "getAllFormRefs")
1153
- return () => bt.getState().getFormRefsByStateKey(t);
1157
+ return () => Mt.getState().getFormRefsByStateKey(t);
1154
1158
  if (l === "_initialState")
1155
1159
  return o.getState().initialStateGlobal[t];
1156
1160
  if (l === "_serverState")
@@ -1163,13 +1167,13 @@ function It(t, c, m, g) {
1163
1167
  if (l === "removeValidation") return v.removeValidation;
1164
1168
  }
1165
1169
  if (l === "getFormRef")
1166
- return () => bt.getState().getFormRef(t + "." + r.join("."));
1170
+ return () => Mt.getState().getFormRef(t + "." + r.join("."));
1167
1171
  if (l === "validationWrapper")
1168
1172
  return ({
1169
1173
  children: d,
1170
1174
  hideMessage: e
1171
- }) => /* @__PURE__ */ Ot(
1172
- zt,
1175
+ }) => /* @__PURE__ */ _t(
1176
+ qt,
1173
1177
  {
1174
1178
  formOpts: e ? { validation: { message: "" } } : void 0,
1175
1179
  path: r,
@@ -1185,21 +1189,21 @@ function It(t, c, m, g) {
1185
1189
  if (l === "update")
1186
1190
  return (d, e) => {
1187
1191
  if (e?.debounce)
1188
- Wt(() => {
1189
- it(c, d, r, "");
1192
+ zt(() => {
1193
+ ct(c, d, r, "");
1190
1194
  const n = o.getState().getNestedState(t, r);
1191
1195
  e?.afterUpdate && e.afterUpdate(n);
1192
1196
  }, e.debounce);
1193
1197
  else {
1194
- it(c, d, r, "");
1198
+ ct(c, d, r, "");
1195
1199
  const n = o.getState().getNestedState(t, r);
1196
1200
  e?.afterUpdate && e.afterUpdate(n);
1197
1201
  }
1198
1202
  p(r);
1199
1203
  };
1200
1204
  if (l === "formElement")
1201
- return (d, e) => /* @__PURE__ */ Ot(
1202
- qt,
1205
+ return (d, e) => /* @__PURE__ */ _t(
1206
+ Jt,
1203
1207
  {
1204
1208
  setState: c,
1205
1209
  stateKey: t,
@@ -1208,10 +1212,10 @@ function It(t, c, m, g) {
1208
1212
  formOpts: e
1209
1213
  }
1210
1214
  );
1211
- const L = [...r, l], at = o.getState().getNestedState(t, L);
1212
- return s(at, L, S);
1215
+ const R = [...r, l], at = o.getState().getNestedState(t, R);
1216
+ return s(at, R, S);
1213
1217
  }
1214
- }, z = new Proxy(H, U);
1218
+ }, z = new Proxy(j, U);
1215
1219
  return I.set(W, {
1216
1220
  proxy: z,
1217
1221
  stateVersion: N
@@ -1221,10 +1225,10 @@ function It(t, c, m, g) {
1221
1225
  o.getState().getNestedState(t, [])
1222
1226
  );
1223
1227
  }
1224
- function Vt(t) {
1225
- return lt(oe, { proxy: t });
1228
+ function Gt(t) {
1229
+ return dt(ae, { proxy: t });
1226
1230
  }
1227
- function re({
1231
+ function oe({
1228
1232
  proxy: t,
1229
1233
  rebuildStateShape: c
1230
1234
  }) {
@@ -1236,7 +1240,7 @@ function re({
1236
1240
  (I, N, p, v, s) => t._mapFn(I, N, p, v, s)
1237
1241
  ) : null;
1238
1242
  }
1239
- function oe({
1243
+ function ae({
1240
1244
  proxy: t
1241
1245
  }) {
1242
1246
  const c = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
@@ -1261,22 +1265,22 @@ function oe({
1261
1265
  "state",
1262
1266
  `return (${t._effect})(state)`
1263
1267
  )(r);
1264
- } catch (H) {
1265
- console.error("Error evaluating effect function during mount:", H), S = r;
1268
+ } catch (j) {
1269
+ console.error("Error evaluating effect function during mount:", j), S = r;
1266
1270
  }
1267
1271
  else
1268
1272
  S = r;
1269
1273
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1270
1274
  const W = document.createTextNode(String(S));
1271
1275
  g.replaceWith(W);
1272
- }, [t._stateKey, t._path.join("."), t._effect]), lt("span", {
1276
+ }, [t._stateKey, t._path.join("."), t._effect]), dt("span", {
1273
1277
  ref: c,
1274
1278
  style: { display: "none" },
1275
1279
  "data-signal-id": m
1276
1280
  });
1277
1281
  }
1278
1282
  function pe(t) {
1279
- const c = Ut(
1283
+ const c = Bt(
1280
1284
  (m) => {
1281
1285
  const g = o.getState().stateComponents.get(t._stateKey) || {
1282
1286
  components: /* @__PURE__ */ new Map()
@@ -1288,22 +1292,22 @@ function pe(t) {
1288
1292
  },
1289
1293
  () => o.getState().getNestedState(t._stateKey, t._path)
1290
1294
  );
1291
- return lt("text", {}, String(c));
1295
+ return dt("text", {}, String(c));
1292
1296
  }
1293
- function ae({
1297
+ function se({
1294
1298
  stateKey: t,
1295
1299
  itemComponentId: c,
1296
1300
  itemPath: m,
1297
1301
  children: g
1298
1302
  }) {
1299
- const [, I] = K({}), [N, p] = Zt(), v = q(null);
1303
+ const [, I] = K({}), [N, p] = Xt(), v = q(null);
1300
1304
  return ot(() => {
1301
1305
  p.height > 0 && p.height !== v.current && (v.current = p.height, o.getState().setShadowMetadata(t, m, {
1302
1306
  virtualizer: {
1303
1307
  itemHeight: p.height
1304
1308
  }
1305
1309
  }));
1306
- }, [p.height, t, m]), ct(() => {
1310
+ }, [p.height, t, m]), lt(() => {
1307
1311
  const s = `${t}////${c}`, T = o.getState().stateComponents.get(t) || {
1308
1312
  components: /* @__PURE__ */ new Map()
1309
1313
  };
@@ -1314,14 +1318,14 @@ function ae({
1314
1318
  const r = o.getState().stateComponents.get(t);
1315
1319
  r && r.components.delete(s);
1316
1320
  };
1317
- }, [t, c, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: N, children: g });
1321
+ }, [t, c, m.join(".")]), /* @__PURE__ */ _t("div", { ref: N, children: g });
1318
1322
  }
1319
1323
  export {
1320
- Vt as $cogsSignal,
1324
+ Gt as $cogsSignal,
1321
1325
  pe as $cogsSignalStore,
1322
1326
  Ie as addStateOptions,
1323
1327
  ve as createCogsState,
1324
1328
  ye as notifyComponent,
1325
- ne as useCogsStateFn
1329
+ re as useCogsStateFn
1326
1330
  };
1327
1331
  //# sourceMappingURL=CogsState.jsx.map