cogsbox-state 0.5.307 → 0.5.309

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,34 +1,34 @@
1
1
  "use client";
2
2
  import { jsx as It } from "react/jsx-runtime";
3
- import { useState as tt, useRef as q, useEffect as st, useLayoutEffect as at, useMemo as pt, createElement as it, useSyncExternalStore as jt, startTransition as Ot, useCallback as Et } from "react";
4
- import { transformStateFunc as Rt, isDeepEqual as B, isFunction as Z, getNestedValue as J, getDifferences as wt, debounce as Ft } from "./utility.js";
5
- import { pushFunc as yt, updateFn as ot, cutFunc as ut, ValidationWrapper as Ut, FormControlComponent as Dt } from "./Functions.jsx";
6
- import Wt from "superjson";
3
+ import { useState as tt, useRef as J, useEffect as at, useLayoutEffect as ut, useMemo as pt, createElement as st, useSyncExternalStore as jt, startTransition as Ot, useCallback as Et } from "react";
4
+ import { transformStateFunc as Rt, isDeepEqual as z, isFunction as Z, getNestedValue as q, getDifferences as wt, debounce as Ut } from "./utility.js";
5
+ import { pushFunc as yt, updateFn as ot, cutFunc as dt, ValidationWrapper as Ft, FormControlComponent as Dt } from "./Functions.jsx";
6
+ import Gt from "superjson";
7
7
  import { v4 as Tt } from "uuid";
8
8
  import "zod";
9
9
  import { getGlobalStore as o, formRefStore as $t } from "./store.js";
10
10
  import { useCogsConfig as Vt } from "./CogsStateClient.jsx";
11
- import { applyPatch as Gt } from "fast-json-patch";
11
+ import { applyPatch as Wt } from "fast-json-patch";
12
12
  import Lt from "react-use-measure";
13
- function bt(t, c) {
13
+ function kt(t, c) {
14
14
  const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, y = m(t) || {};
15
15
  f(t, {
16
16
  ...y,
17
17
  ...c
18
18
  });
19
19
  }
20
- function kt({
20
+ function bt({
21
21
  stateKey: t,
22
22
  options: c,
23
23
  initialOptionsPart: m
24
24
  }) {
25
- const f = nt(t) || {}, y = m[t] || {}, k = o.getState().setInitialStateOptions, p = { ...y, ...f };
25
+ const f = nt(t) || {}, y = m[t] || {}, b = o.getState().setInitialStateOptions, p = { ...y, ...f };
26
26
  let I = !1;
27
27
  if (c)
28
28
  for (const a in c)
29
29
  p.hasOwnProperty(a) ? (a == "localStorage" && c[a] && p[a].key !== c[a]?.key && (I = !0, p[a] = c[a]), a == "initialState" && c[a] && p[a] !== c[a] && // Different references
30
- !B(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
31
- I && k(t, p);
30
+ !z(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
31
+ I && b(t, p);
32
32
  }
33
33
  function ue(t, { formElements: c, validation: m }) {
34
34
  return { initialState: t, formElements: c, validation: m };
@@ -45,9 +45,9 @@ const ge = (t, c) => {
45
45
  // State-specific overrides
46
46
  }, nt(I) || o.getState().setInitialStateOptions(I, y[I]);
47
47
  }), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
48
- const k = (I, a) => {
48
+ const b = (I, a) => {
49
49
  const [v] = tt(a?.componentId ?? Tt());
50
- kt({
50
+ bt({
51
51
  stateKey: I,
52
52
  options: a,
53
53
  initialOptionsPart: y
@@ -71,30 +71,30 @@ const ge = (t, c) => {
71
71
  return R;
72
72
  };
73
73
  function p(I, a) {
74
- kt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Jt(I, a), mt(I);
74
+ bt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Jt(I, a), mt(I);
75
75
  }
76
- return { useCogsState: k, setCogsOptions: p };
76
+ return { useCogsState: b, setCogsOptions: p };
77
77
  }, {
78
78
  setUpdaterState: gt,
79
79
  setState: et,
80
80
  getInitialOptions: nt,
81
81
  getKeyState: xt,
82
82
  getValidationErrors: Ht,
83
- setStateLog: zt,
83
+ setStateLog: Bt,
84
84
  updateInitialStateGlobal: At,
85
- addValidationError: Bt,
85
+ addValidationError: zt,
86
86
  removeValidationError: Y,
87
87
  setServerSyncActions: qt
88
- } = o.getState(), Ct = (t, c, m, f, y) => {
88
+ } = o.getState(), Nt = (t, c, m, f, y) => {
89
89
  m?.log && console.log(
90
90
  "saving to localstorage",
91
91
  c,
92
92
  m.localStorage?.key,
93
93
  f
94
94
  );
95
- const k = Z(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
- if (k && f) {
97
- const p = `${f}-${c}-${k}`;
95
+ const b = Z(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
+ if (b && f) {
97
+ const p = `${f}-${c}-${b}`;
98
98
  let I;
99
99
  try {
100
100
  I = St(p)?.lastSyncedWithServer;
@@ -104,7 +104,7 @@ const ge = (t, c) => {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
106
  lastSyncedWithServer: y ?? I
107
- }, v = Wt.serialize(a);
107
+ }, v = Gt.serialize(a);
108
108
  window.localStorage.setItem(
109
109
  p,
110
110
  JSON.stringify(v.json)
@@ -121,21 +121,21 @@ const ge = (t, c) => {
121
121
  }, Jt = (t, c) => {
122
122
  const m = o.getState().cogsStateStore[t], { sessionId: f } = Vt(), y = Z(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
123
123
  if (y && f) {
124
- const k = St(
124
+ const b = St(
125
125
  `${f}-${t}-${y}`
126
126
  );
127
- if (k && k.lastUpdated > (k.lastSyncedWithServer || 0))
128
- return et(t, k.state), mt(t), !0;
127
+ if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
128
+ return et(t, b.state), mt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Pt = (t, c, m, f, y, k) => {
131
+ }, Pt = (t, c, m, f, y, b) => {
132
132
  const p = {
133
133
  initialState: c,
134
134
  updaterState: ft(
135
135
  t,
136
136
  f,
137
137
  y,
138
- k
138
+ b
139
139
  ),
140
140
  state: m
141
141
  };
@@ -161,18 +161,18 @@ const ge = (t, c) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: J(c, f),
165
- newValue: J(m, f)
164
+ oldValue: q(c, f),
165
+ newValue: q(m, f)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: J(m, f)
171
+ newValue: q(m, f)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: J(c, f),
175
+ oldValue: q(c, f),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -185,7 +185,7 @@ function Zt(t, {
185
185
  serverSync: m,
186
186
  localStorage: f,
187
187
  formElements: y,
188
- reactiveDeps: k,
188
+ reactiveDeps: b,
189
189
  reactiveType: p,
190
190
  componentId: I,
191
191
  initialState: a,
@@ -193,12 +193,12 @@ function Zt(t, {
193
193
  dependencies: n,
194
194
  serverState: S
195
195
  } = {}) {
196
- const [L, R] = tt({}), { sessionId: F } = Vt();
196
+ const [L, R] = tt({}), { sessionId: U } = Vt();
197
197
  let H = !c;
198
- const [h] = tt(c ?? Tt()), l = o.getState().stateLog[h], ct = q(/* @__PURE__ */ new Set()), X = q(I ?? Tt()), j = q(
198
+ const [h] = tt(c ?? Tt()), l = o.getState().stateLog[h], it = J(/* @__PURE__ */ new Set()), X = J(I ?? Tt()), M = J(
199
199
  null
200
200
  );
201
- j.current = nt(h) ?? null, st(() => {
201
+ M.current = nt(h) ?? null, at(() => {
202
202
  if (v && v.stateKey === h && v.path?.[0]) {
203
203
  et(h, (r) => ({
204
204
  ...r,
@@ -210,40 +210,40 @@ function Zt(t, {
210
210
  userId: v.userId
211
211
  });
212
212
  }
213
- }, [v]), st(() => {
213
+ }, [v]), at(() => {
214
214
  if (a) {
215
- bt(h, {
215
+ kt(h, {
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[h];
219
- if (!(i && !B(i, a) || !i) && !s)
218
+ const e = M.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
219
+ if (!(i && !z(i, a) || !i) && !s)
220
220
  return;
221
- let g = null;
221
+ let u = null;
222
222
  const A = Z(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
- A && F && (g = St(`${F}-${h}-${A}`));
224
- let w = a, E = !1;
225
- const N = s ? Date.now() : 0, C = g?.lastUpdated || 0, M = g?.lastSyncedWithServer || 0;
226
- s && N > C ? (w = e.serverState.data, E = !0) : g && C > M && (w = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), Pt(
223
+ A && U && (u = St(`${U}-${h}-${A}`));
224
+ let w = a, $ = !1;
225
+ const x = s ? Date.now() : 0, N = u?.lastUpdated || 0, j = u?.lastSyncedWithServer || 0;
226
+ s && x > N ? (w = e.serverState.data, $ = !0) : u && N > j && (w = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), Pt(
227
227
  h,
228
228
  a,
229
229
  w,
230
230
  rt,
231
231
  X.current,
232
- F
233
- ), E && A && F && Ct(w, h, e, F, Date.now()), mt(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
232
+ U
233
+ ), $ && A && U && Nt(w, h, e, U, Date.now()), mt(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
234
234
  }
235
235
  }, [
236
236
  a,
237
237
  S?.status,
238
238
  S?.data,
239
239
  ...n || []
240
- ]), at(() => {
241
- H && bt(h, {
240
+ ]), ut(() => {
241
+ H && kt(h, {
242
242
  serverSync: m,
243
243
  formElements: y,
244
244
  initialState: a,
245
245
  localStorage: f,
246
- middleware: j.current?.middleware
246
+ middleware: M.current?.middleware
247
247
  });
248
248
  const e = `${h}////${X.current}`, r = o.getState().stateComponents.get(h) || {
249
249
  components: /* @__PURE__ */ new Map()
@@ -252,7 +252,7 @@ function Zt(t, {
252
252
  forceUpdate: () => R({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: k || void 0,
255
+ depsFunction: b || void 0,
256
256
  reactiveType: p ?? ["component", "deps"]
257
257
  }), o.getState().stateComponents.set(h, r), R({}), () => {
258
258
  r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
@@ -260,156 +260,156 @@ function Zt(t, {
260
260
  }, []);
261
261
  const rt = (e, r, s, i) => {
262
262
  if (Array.isArray(r)) {
263
- const g = `${h}-${r.join(".")}`;
264
- ct.current.add(g);
263
+ const u = `${h}-${r.join(".")}`;
264
+ it.current.add(u);
265
265
  }
266
- const u = o.getState();
267
- et(h, (g) => {
268
- const A = Z(e) ? e(g) : e, w = `${h}-${r.join(".")}`;
266
+ const g = o.getState();
267
+ et(h, (u) => {
268
+ const A = Z(e) ? e(u) : e, w = `${h}-${r.join(".")}`;
269
269
  if (w) {
270
- let V = !1, $ = u.signalDomElements.get(w);
271
- if ((!$ || $.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
- const O = r.slice(0, -1), W = J(A, O);
273
- if (Array.isArray(W)) {
274
- V = !0;
275
- const b = `${h}-${O.join(".")}`;
276
- $ = u.signalDomElements.get(b);
270
+ let P = !1, E = g.signalDomElements.get(w);
271
+ if ((!E || E.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
+ const O = r.slice(0, -1), G = q(A, O);
273
+ if (Array.isArray(G)) {
274
+ P = !0;
275
+ const k = `${h}-${O.join(".")}`;
276
+ E = g.signalDomElements.get(k);
277
277
  }
278
278
  }
279
- if ($) {
280
- const O = V ? J(A, r.slice(0, -1)) : J(A, r);
281
- $.forEach(({ parentId: W, position: b, effect: U }) => {
279
+ if (E) {
280
+ const O = P ? q(A, r.slice(0, -1)) : q(A, r);
281
+ E.forEach(({ parentId: G, position: k, effect: F }) => {
282
282
  const T = document.querySelector(
283
- `[data-parent-id="${W}"]`
283
+ `[data-parent-id="${G}"]`
284
284
  );
285
285
  if (T) {
286
- const x = Array.from(T.childNodes);
287
- if (x[b]) {
288
- const P = U ? new Function("state", `return (${U})(state)`)(O) : O;
289
- x[b].textContent = String(P);
286
+ const C = Array.from(T.childNodes);
287
+ if (C[k]) {
288
+ const V = F ? new Function("state", `return (${F})(state)`)(O) : O;
289
+ C[k].textContent = String(V);
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 && Y(
296
- (i || j.current?.validation?.key) + "." + r.join(".")
295
+ console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || M.current?.validation?.key) && r && Y(
296
+ (i || M.current?.validation?.key) + "." + r.join(".")
297
297
  );
298
- const E = r.slice(0, r.length - 1);
299
- s.updateType === "cut" && j.current?.validation?.key && Y(
300
- j.current?.validation?.key + "." + E.join(".")
301
- ), s.updateType === "insert" && j.current?.validation?.key && Ht(
302
- j.current?.validation?.key + "." + E.join(".")
303
- ).filter(([$, O]) => {
304
- let W = $?.split(".").length;
305
- if ($ == E.join(".") && W == E.length - 1) {
306
- let b = $ + "." + E;
307
- Y($), Bt(b, O);
298
+ const $ = r.slice(0, r.length - 1);
299
+ s.updateType === "cut" && M.current?.validation?.key && Y(
300
+ M.current?.validation?.key + "." + $.join(".")
301
+ ), s.updateType === "insert" && M.current?.validation?.key && Ht(
302
+ M.current?.validation?.key + "." + $.join(".")
303
+ ).filter(([E, O]) => {
304
+ let G = E?.split(".").length;
305
+ if (E == $.join(".") && G == $.length - 1) {
306
+ let k = E + "." + $;
307
+ Y(E), zt(k, O);
308
308
  }
309
309
  });
310
- const N = u.stateComponents.get(h);
311
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", N), N) {
312
- const V = wt(g, A), $ = new Set(V), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
310
+ const x = g.stateComponents.get(h);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
312
+ const P = wt(u, A), E = new Set(P), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
313
313
  for (const [
314
- W,
315
- b
316
- ] of N.components.entries()) {
317
- let U = !1;
318
- const T = Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"];
319
- if (console.log("component", b), !T.includes("none")) {
314
+ G,
315
+ k
316
+ ] of x.components.entries()) {
317
+ let F = !1;
318
+ const T = Array.isArray(k.reactiveType) ? k.reactiveType : [k.reactiveType || "component"];
319
+ if (console.log("component", k), !T.includes("none")) {
320
320
  if (T.includes("all")) {
321
- b.forceUpdate();
321
+ k.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (T.includes("component") && ((b.paths.has(O) || b.paths.has("")) && (U = !0), !U))
325
- for (const x of $) {
326
- let P = x;
324
+ if (T.includes("component") && ((k.paths.has(O) || k.paths.has("")) && (F = !0), !F))
325
+ for (const C of E) {
326
+ let V = C;
327
327
  for (; ; ) {
328
- if (b.paths.has(P)) {
329
- U = !0;
328
+ if (k.paths.has(V)) {
329
+ F = !0;
330
330
  break;
331
331
  }
332
- const G = P.lastIndexOf(".");
333
- if (G !== -1) {
334
- const z = P.substring(
332
+ const W = V.lastIndexOf(".");
333
+ if (W !== -1) {
334
+ const B = V.substring(
335
335
  0,
336
- G
336
+ W
337
337
  );
338
338
  if (!isNaN(
339
- Number(P.substring(G + 1))
340
- ) && b.paths.has(z)) {
341
- U = !0;
339
+ Number(V.substring(W + 1))
340
+ ) && k.paths.has(B)) {
341
+ F = !0;
342
342
  break;
343
343
  }
344
- P = z;
344
+ V = B;
345
345
  } else
346
- P = "";
347
- if (P === "")
346
+ V = "";
347
+ if (V === "")
348
348
  break;
349
349
  }
350
- if (U) break;
350
+ if (F) break;
351
351
  }
352
- if (!U && T.includes("deps") && b.depsFunction) {
353
- const x = b.depsFunction(A);
354
- let P = !1;
355
- typeof x == "boolean" ? x && (P = !0) : B(b.deps, x) || (b.deps = x, P = !0), P && (U = !0);
352
+ if (!F && T.includes("deps") && k.depsFunction) {
353
+ const C = k.depsFunction(A);
354
+ let V = !1;
355
+ typeof C == "boolean" ? C && (V = !0) : z(k.deps, C) || (k.deps = C, V = !0), V && (F = !0);
356
356
  }
357
- U && b.forceUpdate();
357
+ F && k.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const C = Date.now();
362
- r = r.map((V, $) => {
363
- const O = r.slice(0, -1), W = J(A, O);
364
- return $ === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : V;
361
+ const N = Date.now();
362
+ r = r.map((P, E) => {
363
+ const O = r.slice(0, -1), G = q(A, O);
364
+ return E === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (G.length - 1).toString() : P;
365
365
  });
366
- const { oldValue: M, newValue: D } = Yt(
366
+ const { oldValue: j, newValue: D } = Yt(
367
367
  s.updateType,
368
- g,
368
+ u,
369
369
  A,
370
370
  r
371
371
  ), _ = {
372
- timeStamp: C,
372
+ timeStamp: N,
373
373
  stateKey: h,
374
374
  path: r,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
- oldValue: M,
377
+ oldValue: j,
378
378
  newValue: D
379
379
  };
380
380
  switch (s.updateType) {
381
381
  case "update":
382
- u.updateShadowAtPath(h, r, A);
382
+ g.updateShadowAtPath(h, r, A);
383
383
  break;
384
384
  case "insert":
385
- const V = r.slice(0, -1);
386
- u.insertShadowArrayElement(h, V, D);
385
+ const P = r.slice(0, -1);
386
+ g.insertShadowArrayElement(h, P, D);
387
387
  break;
388
388
  case "cut":
389
- const $ = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- u.removeShadowArrayElement(h, $, O);
389
+ const E = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
+ g.removeShadowArrayElement(h, E, O);
391
391
  break;
392
392
  }
393
- if (zt(h, (V) => {
394
- const O = [...V ?? [], _].reduce((W, b) => {
395
- const U = `${b.stateKey}:${JSON.stringify(b.path)}`, T = W.get(U);
396
- return T ? (T.timeStamp = Math.max(T.timeStamp, b.timeStamp), T.newValue = b.newValue, T.oldValue = T.oldValue ?? b.oldValue, T.updateType = b.updateType) : W.set(U, { ...b }), W;
393
+ if (Bt(h, (P) => {
394
+ const O = [...P ?? [], _].reduce((G, k) => {
395
+ const F = `${k.stateKey}:${JSON.stringify(k.path)}`, T = G.get(F);
396
+ return T ? (T.timeStamp = Math.max(T.timeStamp, k.timeStamp), T.newValue = k.newValue, T.oldValue = T.oldValue ?? k.oldValue, T.updateType = k.updateType) : G.set(F, { ...k }), G;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(O.values());
399
- }), Ct(
399
+ }), Nt(
400
400
  A,
401
401
  h,
402
- j.current,
403
- F
404
- ), j.current?.middleware && j.current.middleware({
402
+ M.current,
403
+ U
404
+ ), M.current?.middleware && M.current.middleware({
405
405
  updateLog: l,
406
406
  update: _
407
- }), j.current?.serverSync) {
408
- const V = u.serverState[h], $ = j.current?.serverSync;
407
+ }), M.current?.serverSync) {
408
+ const P = g.serverState[h], E = M.current?.serverSync;
409
409
  qt(h, {
410
- syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: A }),
411
- rollBackState: V,
412
- actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
410
+ syncKey: typeof E.syncKey == "string" ? E.syncKey : E.syncKey({ state: A }),
411
+ rollBackState: P,
412
+ actionTimeStamp: Date.now() + (E.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
@@ -422,25 +422,25 @@ function Zt(t, {
422
422
  h,
423
423
  rt,
424
424
  X.current,
425
- F
425
+ U
426
426
  )
427
427
  ), o.getState().cogsStateStore[h] || et(h, t), o.getState().initialStateGlobal[h] || At(h, t));
428
428
  const d = pt(() => ft(
429
429
  h,
430
430
  rt,
431
431
  X.current,
432
- F
433
- ), [h, F]);
432
+ U
433
+ ), [h, U]);
434
434
  return [xt(h), d];
435
435
  }
436
436
  function ft(t, c, m, f) {
437
437
  const y = /* @__PURE__ */ new Map();
438
- let k = 0;
438
+ let b = 0;
439
439
  const p = (v) => {
440
440
  const n = v.join(".");
441
441
  for (const [S] of y)
442
442
  (S === n || S.startsWith(n + ".")) && y.delete(S);
443
- k++;
443
+ b++;
444
444
  }, I = {
445
445
  removeValidation: (v) => {
446
446
  v?.validationKey && Y(v.validationKey);
@@ -449,8 +449,8 @@ function ft(t, c, m, f) {
449
449
  const n = o.getState().getInitialOptions(t)?.validation;
450
450
  n?.key && Y(n?.key), v?.validationKey && Y(v.validationKey);
451
451
  const S = o.getState().initialStateGlobal[t];
452
- o.getState().clearSelectedIndexesForState(t), y.clear(), k++;
453
- const L = a(S, []), R = nt(t), F = Z(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, H = `${f}-${t}-${F}`;
452
+ o.getState().clearSelectedIndexesForState(t), y.clear(), b++;
453
+ const L = a(S, []), R = nt(t), U = Z(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, H = `${f}-${t}-${U}`;
454
454
  H && localStorage.removeItem(H), gt(t, L), et(t, S);
455
455
  const h = o.getState().stateComponents.get(t);
456
456
  return h && h.components.forEach((l) => {
@@ -458,14 +458,14 @@ function ft(t, c, m, f) {
458
458
  }), S;
459
459
  },
460
460
  updateInitialState: (v) => {
461
- y.clear(), k++;
461
+ y.clear(), b++;
462
462
  const n = ft(
463
463
  t,
464
464
  c,
465
465
  m,
466
466
  f
467
- ), S = o.getState().initialStateGlobal[t], L = nt(t), R = Z(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, F = `${f}-${t}-${R}`;
468
- return localStorage.getItem(F) && localStorage.removeItem(F), Ot(() => {
467
+ ), S = o.getState().initialStateGlobal[t], L = nt(t), R = Z(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, U = `${f}-${t}-${R}`;
468
+ return localStorage.getItem(U) && localStorage.removeItem(U), Ot(() => {
469
469
  At(t, v), o.getState().initializeShadowState(t, v), gt(t, n), et(t, v);
470
470
  const H = o.getState().stateComponents.get(t);
471
471
  H && H.components.forEach((h) => {
@@ -480,7 +480,7 @@ function ft(t, c, m, f) {
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
482
  const v = o.getState().serverState[t];
483
- return !!(v && B(v, xt(t)));
483
+ return !!(v && z(v, xt(t)));
484
484
  }
485
485
  };
486
486
  function a(v, n = [], S) {
@@ -492,15 +492,15 @@ function ft(t, c, m, f) {
492
492
  Object.keys(I).forEach((h) => {
493
493
  R[h] = I[h];
494
494
  });
495
- const F = {
496
- apply(h, l, ct) {
495
+ const U = {
496
+ apply(h, 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(h, l) {
502
502
  S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
503
- const ct = /* @__PURE__ */ new Set([
503
+ const it = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,15 +523,15 @@ function ft(t, c, m, f) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ct.has(l)) {
526
+ if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !it.has(l)) {
527
527
  const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
528
528
  if (e) {
529
529
  const r = e.components.get(d);
530
530
  if (r && !r.paths.has("")) {
531
531
  const s = n.join(".");
532
532
  let i = !0;
533
- for (const u of r.paths)
534
- if (s.startsWith(u) && (s === u || s[u.length] === ".")) {
533
+ for (const g of r.paths)
534
+ if (s.startsWith(g) && (s === g || s[g.length] === ".")) {
535
535
  i = !1;
536
536
  break;
537
537
  }
@@ -553,13 +553,13 @@ function ft(t, c, m, f) {
553
553
  try {
554
554
  const i = await e.action(r);
555
555
  if (i && !i.success && i.errors && s) {
556
- o.getState().removeValidationError(s), i.errors.forEach((g) => {
557
- const A = [s, ...g.path].join(".");
558
- o.getState().addValidationError(A, g.message);
556
+ o.getState().removeValidationError(s), i.errors.forEach((u) => {
557
+ const A = [s, ...u.path].join(".");
558
+ o.getState().addValidationError(A, u.message);
559
559
  });
560
- const u = o.getState().stateComponents.get(t);
561
- u && u.components.forEach((g) => {
562
- g.forceUpdate();
560
+ const g = o.getState().stateComponents.get(t);
561
+ g && g.components.forEach((u) => {
562
+ u.forceUpdate();
563
563
  });
564
564
  }
565
565
  return i?.success && e.onSuccess ? e.onSuccess(i.data) : !i?.success && e.onError && e.onError(i.error), i;
@@ -568,16 +568,16 @@ function ft(t, c, m, f) {
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
571
- const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = J(e, n);
572
- return B(d, r) ? "fresh" : "stale";
571
+ const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = q(e, n);
572
+ return z(d, r) ? "fresh" : "stale";
573
573
  }
574
574
  if (l === "getStatus")
575
575
  return function() {
576
576
  const d = o().getNestedState(
577
577
  t,
578
578
  n
579
- ), e = o.getState().initialStateGlobal[t], r = J(e, n);
580
- return B(d, r) ? "fresh" : "stale";
579
+ ), e = o.getState().initialStateGlobal[t], r = q(e, n);
580
+ return z(d, r) ? "fresh" : "stale";
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
@@ -621,164 +621,168 @@ function ft(t, c, m, f) {
621
621
  itemHeight: r = 50,
622
622
  overscan: s = 5,
623
623
  stickToBottom: i = !1
624
- } = e, u = q(null), [g, A] = tt({
624
+ } = e, g = J(null), [u, A] = tt({
625
625
  startIndex: 0,
626
626
  endIndex: 10
627
- }), [, w] = tt({}), E = q(i), N = q(0), C = q(!0), M = q(0);
628
- st(() => o.getState().subscribeToShadowState(t, () => w({})), [t]);
627
+ }), w = J(i), $ = J(0), x = J(!0), [N, j] = tt(0);
628
+ at(() => o.getState().subscribeToShadowState(t, () => {
629
+ j((C) => C + 1);
630
+ }), [t]);
629
631
  const D = o().getNestedState(
630
632
  t,
631
633
  n
632
- ), _ = D.length, { totalHeight: V, positions: $ } = pt(() => {
634
+ ), _ = D.length, { totalHeight: P, positions: E } = pt(() => {
633
635
  const T = o.getState().getShadowMetadata(t, n) || [];
634
- let x = 0;
635
- const P = [];
636
- for (let G = 0; G < _; G++) {
637
- P[G] = x;
638
- const z = T[G]?.virtualizer?.itemHeight;
639
- x += z || r;
636
+ let C = 0;
637
+ const V = [];
638
+ for (let W = 0; W < _; W++) {
639
+ V[W] = C;
640
+ const B = T[W]?.virtualizer?.itemHeight;
641
+ C += B || r;
640
642
  }
641
- return { totalHeight: x, positions: P };
642
- }, [_, t, n.join("."), r]);
643
- at(() => {
644
- const T = u.current;
645
- if (!T) return;
646
- const x = V !== M.current;
647
- M.current = V, x && E.current && !C.current && T.scrollTo({
648
- top: T.scrollHeight,
649
- behavior: "auto"
650
- });
651
- }, [V]);
643
+ return { totalHeight: C, positions: V };
644
+ }, [
645
+ _,
646
+ t,
647
+ n.join("."),
648
+ r,
649
+ N
650
+ ]);
651
+ console.log("height", P);
652
652
  const O = pt(() => {
653
- const T = Math.max(0, g.startIndex), x = Math.min(_, g.endIndex), P = Array.from(
654
- { length: x - T },
655
- (z, lt) => T + lt
656
- ), G = P.map((z) => D[z]);
657
- return a(G, n, {
653
+ const T = Math.max(0, u.startIndex), C = Math.min(_, u.endIndex), V = Array.from(
654
+ { length: C - T },
655
+ (B, ct) => T + ct
656
+ ), W = V.map((B) => D[B]);
657
+ return a(W, n, {
658
658
  ...S,
659
- validIndices: P
659
+ validIndices: V
660
660
  });
661
- }, [g.startIndex, g.endIndex, D, _]);
662
- at(() => {
663
- const T = u.current;
661
+ }, [u.startIndex, u.endIndex, D, _]);
662
+ ut(() => {
663
+ const T = g.current;
664
664
  if (!T) return;
665
- const x = E.current, P = _ > N.current;
666
- N.current = _;
667
- const G = () => {
668
- const { scrollTop: z, clientHeight: lt, scrollHeight: _t } = T;
669
- E.current = _t - z - lt < 10;
670
- let ht = 0, dt = _ - 1;
671
- for (; ht <= dt; ) {
672
- const K = Math.floor((ht + dt) / 2);
673
- $[K] < z ? ht = K + 1 : dt = K - 1;
665
+ const C = w.current, V = _ > $.current;
666
+ $.current = _;
667
+ const W = () => {
668
+ const { scrollTop: B, clientHeight: ct, scrollHeight: _t } = T;
669
+ w.current = _t - B - ct < 10;
670
+ let ht = 0, lt = _ - 1;
671
+ for (; ht <= lt; ) {
672
+ const K = Math.floor((ht + lt) / 2);
673
+ E[K] < B ? ht = K + 1 : lt = K - 1;
674
674
  }
675
- const vt = Math.max(0, dt - s);
675
+ const vt = Math.max(0, lt - s);
676
676
  let Q = vt;
677
- const Mt = z + lt;
678
- for (; Q < _ && $[Q] < Mt; )
677
+ const Mt = B + ct;
678
+ for (; Q < _ && E[Q] < Mt; )
679
679
  Q++;
680
680
  Q = Math.min(_, Q + s), A((K) => K.startIndex !== vt || K.endIndex !== Q ? { startIndex: vt, endIndex: Q } : K);
681
681
  };
682
- return T.addEventListener("scroll", G, {
682
+ return T.addEventListener("scroll", W, {
683
683
  passive: !0
684
- }), i && C.current && _ > 0 ? (E.current = !0, requestAnimationFrame(() => {
685
- u.current && (u.current.scrollTo({
686
- top: u.current.scrollHeight,
687
- behavior: "auto"
688
- }), C.current = !1);
689
- })) : !C.current && x && P && requestAnimationFrame(() => {
684
+ }), i && (x.current ? (console.log(
685
+ "stickToBottom initial mount",
686
+ T.scrollHeight
687
+ ), T.scrollTo({
688
+ top: T.scrollHeight,
689
+ behavior: "auto"
690
+ }), x.current = !1) : C && V && (console.log(
691
+ "stickToBottom wasAtBottom && listGrew",
692
+ T.scrollHeight
693
+ ), requestAnimationFrame(() => {
690
694
  T.scrollTo({
691
695
  top: T.scrollHeight,
692
696
  behavior: "smooth"
693
697
  });
694
- }), G(), () => T.removeEventListener("scroll", G);
695
- }, [_, $, s, i]);
696
- const W = Et(
698
+ }))), console.log("wasAtBottom && listGrew", C, V), W(), () => T.removeEventListener("scroll", W);
699
+ }, [_, E, s, i]);
700
+ const G = Et(
697
701
  (T = "smooth") => {
698
- u.current && u.current.scrollTo({
699
- top: u.current.scrollHeight,
702
+ g.current && g.current.scrollTo({
703
+ top: g.current.scrollHeight,
700
704
  behavior: T
701
705
  });
702
706
  },
703
707
  []
704
- ), b = Et(
705
- (T, x = "smooth") => {
706
- u.current && $[T] !== void 0 && u.current.scrollTo({
707
- top: $[T],
708
- behavior: x
708
+ ), k = Et(
709
+ (T, C = "smooth") => {
710
+ g.current && E[T] !== void 0 && g.current.scrollTo({
711
+ top: E[T],
712
+ behavior: C
709
713
  });
710
714
  },
711
- [$]
712
- ), U = {
715
+ [E]
716
+ ), F = {
713
717
  outer: {
714
- ref: u,
718
+ ref: g,
715
719
  style: { overflowY: "auto", height: "100%" }
716
720
  },
717
721
  inner: {
718
722
  style: {
719
- height: `${V}px`,
723
+ height: `${P}px`,
720
724
  position: "relative"
721
725
  }
722
726
  },
723
727
  list: {
724
728
  style: {
725
- transform: `translateY(${$[g.startIndex] || 0}px)`
729
+ transform: `translateY(${E[u.startIndex] || 0}px)`
726
730
  }
727
731
  }
728
732
  };
729
733
  return {
730
734
  virtualState: O,
731
- virtualizerProps: U,
732
- scrollToBottom: W,
733
- scrollToIndex: b
735
+ virtualizerProps: F,
736
+ scrollToBottom: G,
737
+ scrollToIndex: k
734
738
  };
735
739
  };
736
740
  if (l === "stateSort")
737
741
  return (e) => {
738
742
  const s = [...d()].sort(
739
- (g, A) => e(g.item, A.item)
740
- ), i = s.map(({ item: g }) => g), u = {
743
+ (u, A) => e(u.item, A.item)
744
+ ), i = s.map(({ item: u }) => u), g = {
741
745
  ...S,
742
746
  validIndices: s.map(
743
- ({ originalIndex: g }) => g
747
+ ({ originalIndex: u }) => u
744
748
  )
745
749
  };
746
- return a(i, n, u);
750
+ return a(i, n, g);
747
751
  };
748
752
  if (l === "stateFilter")
749
753
  return (e) => {
750
754
  const s = d().filter(
751
- ({ item: g }, A) => e(g, A)
752
- ), i = s.map(({ item: g }) => g), u = {
755
+ ({ item: u }, A) => e(u, A)
756
+ ), i = s.map(({ item: u }) => u), g = {
753
757
  ...S,
754
758
  validIndices: s.map(
755
- ({ originalIndex: g }) => g
759
+ ({ originalIndex: u }) => u
756
760
  )
757
761
  };
758
- return a(i, n, u);
762
+ return a(i, n, g);
759
763
  };
760
764
  if (l === "stateMap")
761
765
  return (e) => {
762
766
  const r = o.getState().getNestedState(t, n);
763
- return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
764
- const g = r[i], A = [...n, i.toString()], w = a(g, A, S);
765
- return e(g, w, {
767
+ return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
768
+ const u = r[i], A = [...n, i.toString()], w = a(u, A, S);
769
+ return e(u, w, {
766
770
  register: () => {
767
- const [, N] = tt({}), C = `${m}-${n.join(".")}-${i}`;
768
- at(() => {
769
- const M = `${t}////${C}`, D = o.getState().stateComponents.get(t) || {
771
+ const [, x] = tt({}), N = `${m}-${n.join(".")}-${i}`;
772
+ ut(() => {
773
+ const j = `${t}////${N}`, D = o.getState().stateComponents.get(t) || {
770
774
  components: /* @__PURE__ */ new Map()
771
775
  };
772
- return D.components.set(M, {
773
- forceUpdate: () => N({}),
776
+ return D.components.set(j, {
777
+ forceUpdate: () => x({}),
774
778
  paths: /* @__PURE__ */ new Set([A.join(".")])
775
779
  }), o.getState().stateComponents.set(t, D), () => {
776
780
  const _ = o.getState().stateComponents.get(t);
777
- _ && _.components.delete(M);
781
+ _ && _.components.delete(j);
778
782
  };
779
- }, [t, C]);
783
+ }, [t, N]);
780
784
  },
781
- index: u,
785
+ index: g,
782
786
  originalIndex: i
783
787
  });
784
788
  }) : (console.warn(
@@ -788,9 +792,9 @@ function ft(t, c, m, f) {
788
792
  };
789
793
  if (l === "stateMapNoRender")
790
794
  return (e) => v.map((s, i) => {
791
- let u;
792
- S?.validIndices && S.validIndices[i] !== void 0 ? u = S.validIndices[i] : u = i;
793
- const g = [...n, u.toString()], A = a(s, g, S);
795
+ let g;
796
+ S?.validIndices && S.validIndices[i] !== void 0 ? g = S.validIndices[i] : g = i;
797
+ const u = [...n, g.toString()], A = a(s, u, S);
794
798
  return e(
795
799
  s,
796
800
  A,
@@ -800,7 +804,7 @@ function ft(t, c, m, f) {
800
804
  );
801
805
  });
802
806
  if (l === "$stateMap")
803
- return (e) => it(Xt, {
807
+ return (e) => st(Xt, {
804
808
  proxy: {
805
809
  _stateKey: t,
806
810
  _path: n,
@@ -812,17 +816,17 @@ function ft(t, c, m, f) {
812
816
  if (l === "stateList")
813
817
  return (e) => {
814
818
  const r = o.getState().getNestedState(t, n);
815
- return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
816
- const g = r[i], A = [...n, i.toString()], w = a(g, A, S), E = `${m}-${n.join(".")}-${i}`;
817
- return it(Kt, {
819
+ return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
820
+ const u = r[i], A = [...n, i.toString()], w = a(u, A, S), $ = `${m}-${n.join(".")}-${i}`;
821
+ return st(Kt, {
818
822
  key: i,
819
823
  stateKey: t,
820
- itemComponentId: E,
824
+ itemComponentId: $,
821
825
  itemPath: A,
822
826
  children: e(
823
- g,
824
- w,
825
827
  u,
828
+ w,
829
+ g,
826
830
  r,
827
831
  a(r, n, S)
828
832
  )
@@ -834,7 +838,7 @@ function ft(t, c, m, f) {
834
838
  if (l === "stateFlattenOn")
835
839
  return (e) => {
836
840
  const r = v;
837
- y.clear(), k++;
841
+ y.clear(), b++;
838
842
  const s = r.flatMap(
839
843
  (i) => i[e] ?? []
840
844
  );
@@ -863,30 +867,30 @@ function ft(t, c, m, f) {
863
867
  ));
864
868
  if (l === "uniqueInsert")
865
869
  return (e, r, s) => {
866
- const i = o.getState().getNestedState(t, n), u = Z(e) ? e(i) : e;
867
- let g = null;
870
+ const i = o.getState().getNestedState(t, n), g = Z(e) ? e(i) : e;
871
+ let u = null;
868
872
  if (!i.some((w) => {
869
873
  if (r) {
870
- const N = r.every(
871
- (C) => B(w[C], u[C])
874
+ const x = r.every(
875
+ (N) => z(w[N], g[N])
872
876
  );
873
- return N && (g = w), N;
877
+ return x && (u = w), x;
874
878
  }
875
- const E = B(w, u);
876
- return E && (g = w), E;
879
+ const $ = z(w, g);
880
+ return $ && (u = w), $;
877
881
  }))
878
- p(n), yt(c, u, n, t);
879
- else if (s && g) {
880
- const w = s(g), E = i.map(
881
- (N) => B(N, g) ? w : N
882
+ p(n), yt(c, g, n, t);
883
+ else if (s && u) {
884
+ const w = s(u), $ = i.map(
885
+ (x) => z(x, u) ? w : x
882
886
  );
883
- p(n), ot(c, E, n);
887
+ p(n), ot(c, $, n);
884
888
  }
885
889
  };
886
890
  if (l === "cut")
887
891
  return (e, r) => {
888
892
  if (!r?.waitForSync)
889
- return p(n), ut(c, n, t, e), a(
893
+ return p(n), dt(c, n, t, e), a(
890
894
  o.getState().getNestedState(t, n),
891
895
  n
892
896
  );
@@ -894,17 +898,17 @@ function ft(t, c, m, f) {
894
898
  if (l === "cutByValue")
895
899
  return (e) => {
896
900
  for (let r = 0; r < v.length; r++)
897
- v[r] === e && ut(c, n, t, r);
901
+ v[r] === e && dt(c, n, t, r);
898
902
  };
899
903
  if (l === "toggleByValue")
900
904
  return (e) => {
901
905
  const r = v.findIndex((s) => s === e);
902
- r > -1 ? ut(c, n, t, r) : yt(c, e, n, t);
906
+ r > -1 ? dt(c, n, t, r) : yt(c, e, n, t);
903
907
  };
904
908
  if (l === "stateFind")
905
909
  return (e) => {
906
910
  const s = d().find(
907
- ({ item: u }, g) => e(u, g)
911
+ ({ item: g }, u) => e(g, u)
908
912
  );
909
913
  if (!s) return;
910
914
  const i = [...n, s.originalIndex.toString()];
@@ -913,18 +917,18 @@ function ft(t, c, m, f) {
913
917
  if (l === "findWith")
914
918
  return (e, r) => {
915
919
  const i = d().find(
916
- ({ item: g }) => g[e] === r
920
+ ({ item: u }) => u[e] === r
917
921
  );
918
922
  if (!i) return;
919
- const u = [...n, i.originalIndex.toString()];
920
- return a(i.item, u, S);
923
+ const g = [...n, i.originalIndex.toString()];
924
+ return a(i.item, g, S);
921
925
  };
922
926
  }
923
927
  const X = n[n.length - 1];
924
928
  if (!isNaN(Number(X))) {
925
929
  const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
926
930
  if (Array.isArray(e) && l === "cut")
927
- return () => ut(
931
+ return () => dt(
928
932
  c,
929
933
  d,
930
934
  t,
@@ -940,13 +944,13 @@ function ft(t, c, m, f) {
940
944
  return o.getState().getNestedState(t, n);
941
945
  };
942
946
  if (l === "$derive")
943
- return (d) => Nt({
947
+ return (d) => Ct({
944
948
  _stateKey: t,
945
949
  _path: n,
946
950
  _effect: d.toString()
947
951
  });
948
952
  if (l === "$get")
949
- return () => Nt({
953
+ return () => Ct({
950
954
  _stateKey: t,
951
955
  _path: n
952
956
  });
@@ -981,7 +985,7 @@ function ft(t, c, m, f) {
981
985
  if (n.length == 0) {
982
986
  if (l === "applyJsonPatch")
983
987
  return (d) => {
984
- const e = o.getState().cogsStateStore[t], s = Gt(e, d).newDocument;
988
+ const e = o.getState().cogsStateStore[t], s = Wt(e, d).newDocument;
985
989
  Pt(
986
990
  t,
987
991
  o.getState().initialStateGlobal[t],
@@ -992,57 +996,57 @@ function ft(t, c, m, f) {
992
996
  );
993
997
  const i = o.getState().stateComponents.get(t);
994
998
  if (i) {
995
- const u = wt(e, s), g = new Set(u);
999
+ const g = wt(e, s), u = new Set(g);
996
1000
  for (const [
997
1001
  A,
998
1002
  w
999
1003
  ] of i.components.entries()) {
1000
- let E = !1;
1001
- const N = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
1002
- if (!N.includes("none")) {
1003
- if (N.includes("all")) {
1004
+ let $ = !1;
1005
+ const x = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
1006
+ if (!x.includes("none")) {
1007
+ if (x.includes("all")) {
1004
1008
  w.forceUpdate();
1005
1009
  continue;
1006
1010
  }
1007
- if (N.includes("component") && (w.paths.has("") && (E = !0), !E))
1008
- for (const C of g) {
1009
- if (w.paths.has(C)) {
1010
- E = !0;
1011
+ if (x.includes("component") && (w.paths.has("") && ($ = !0), !$))
1012
+ for (const N of u) {
1013
+ if (w.paths.has(N)) {
1014
+ $ = !0;
1011
1015
  break;
1012
1016
  }
1013
- let M = C.lastIndexOf(".");
1014
- for (; M !== -1; ) {
1015
- const D = C.substring(0, M);
1017
+ let j = N.lastIndexOf(".");
1018
+ for (; j !== -1; ) {
1019
+ const D = N.substring(0, j);
1016
1020
  if (w.paths.has(D)) {
1017
- E = !0;
1021
+ $ = !0;
1018
1022
  break;
1019
1023
  }
1020
- const _ = C.substring(
1021
- M + 1
1024
+ const _ = N.substring(
1025
+ j + 1
1022
1026
  );
1023
1027
  if (!isNaN(Number(_))) {
1024
- const V = D.lastIndexOf(".");
1025
- if (V !== -1) {
1026
- const $ = D.substring(
1028
+ const P = D.lastIndexOf(".");
1029
+ if (P !== -1) {
1030
+ const E = D.substring(
1027
1031
  0,
1028
- V
1032
+ P
1029
1033
  );
1030
- if (w.paths.has($)) {
1031
- E = !0;
1034
+ if (w.paths.has(E)) {
1035
+ $ = !0;
1032
1036
  break;
1033
1037
  }
1034
1038
  }
1035
1039
  }
1036
- M = D.lastIndexOf(".");
1040
+ j = D.lastIndexOf(".");
1037
1041
  }
1038
- if (E) break;
1042
+ if ($) break;
1039
1043
  }
1040
- if (!E && N.includes("deps") && w.depsFunction) {
1041
- const C = w.depsFunction(s);
1042
- let M = !1;
1043
- typeof C == "boolean" ? C && (M = !0) : B(w.deps, C) || (w.deps = C, M = !0), M && (E = !0);
1044
+ if (!$ && x.includes("deps") && w.depsFunction) {
1045
+ const N = w.depsFunction(s);
1046
+ let j = !1;
1047
+ typeof N == "boolean" ? N && (j = !0) : z(w.deps, N) || (w.deps = N, j = !0), j && ($ = !0);
1044
1048
  }
1045
- E && w.forceUpdate();
1049
+ $ && w.forceUpdate();
1046
1050
  }
1047
1051
  }
1048
1052
  }
@@ -1058,13 +1062,13 @@ function ft(t, c, m, f) {
1058
1062
  const r = o.getState().cogsStateStore[t];
1059
1063
  try {
1060
1064
  const s = o.getState().getValidationErrors(d.key);
1061
- s && s.length > 0 && s.forEach(([u]) => {
1062
- u && u.startsWith(d.key) && Y(u);
1065
+ s && s.length > 0 && s.forEach(([g]) => {
1066
+ g && g.startsWith(d.key) && Y(g);
1063
1067
  });
1064
1068
  const i = d.zodSchema.safeParse(r);
1065
- return i.success ? !0 : (i.error.errors.forEach((g) => {
1066
- const A = g.path, w = g.message, E = [d.key, ...A].join(".");
1067
- e(E, w);
1069
+ return i.success ? !0 : (i.error.errors.forEach((u) => {
1070
+ const A = u.path, w = u.message, $ = [d.key, ...A].join(".");
1071
+ e($, w);
1068
1072
  }), mt(t), !1);
1069
1073
  } catch (s) {
1070
1074
  return console.error("Zod schema validation failed", s), !1;
@@ -1093,7 +1097,7 @@ function ft(t, c, m, f) {
1093
1097
  children: d,
1094
1098
  hideMessage: e
1095
1099
  }) => /* @__PURE__ */ It(
1096
- Ut,
1100
+ Ft,
1097
1101
  {
1098
1102
  formOpts: e ? { validation: { message: "" } } : void 0,
1099
1103
  path: n,
@@ -1109,7 +1113,7 @@ function ft(t, c, m, f) {
1109
1113
  if (l === "update")
1110
1114
  return (d, e) => {
1111
1115
  if (e?.debounce)
1112
- Ft(() => {
1116
+ Ut(() => {
1113
1117
  ot(c, d, n, "");
1114
1118
  const r = o.getState().getNestedState(t, n);
1115
1119
  e?.afterUpdate && e.afterUpdate(r);
@@ -1132,21 +1136,21 @@ function ft(t, c, m, f) {
1132
1136
  formOpts: e
1133
1137
  }
1134
1138
  );
1135
- const j = [...n, l], rt = o.getState().getNestedState(t, j);
1136
- return a(rt, j, S);
1139
+ const M = [...n, l], rt = o.getState().getNestedState(t, M);
1140
+ return a(rt, M, S);
1137
1141
  }
1138
- }, H = new Proxy(R, F);
1142
+ }, H = new Proxy(R, U);
1139
1143
  return y.set(L, {
1140
1144
  proxy: H,
1141
- stateVersion: k
1145
+ stateVersion: b
1142
1146
  }), H;
1143
1147
  }
1144
1148
  return a(
1145
1149
  o.getState().getNestedState(t, [])
1146
1150
  );
1147
1151
  }
1148
- function Nt(t) {
1149
- return it(Qt, { proxy: t });
1152
+ function Ct(t) {
1153
+ return st(Qt, { proxy: t });
1150
1154
  }
1151
1155
  function Xt({
1152
1156
  proxy: t,
@@ -1157,14 +1161,14 @@ function Xt({
1157
1161
  m,
1158
1162
  t._path
1159
1163
  ).stateMapNoRender(
1160
- (y, k, p, I, a) => t._mapFn(y, k, p, I, a)
1164
+ (y, b, p, I, a) => t._mapFn(y, b, p, I, a)
1161
1165
  ) : null;
1162
1166
  }
1163
1167
  function Qt({
1164
1168
  proxy: t
1165
1169
  }) {
1166
- const c = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
1167
- return st(() => {
1170
+ const c = J(null), m = `${t._stateKey}-${t._path.join(".")}`;
1171
+ return at(() => {
1168
1172
  const f = c.current;
1169
1173
  if (!f || !f.parentElement) return;
1170
1174
  const y = f.parentElement, p = Array.from(y.childNodes).indexOf(f);
@@ -1193,7 +1197,7 @@ function Qt({
1193
1197
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1194
1198
  const L = document.createTextNode(String(S));
1195
1199
  f.replaceWith(L);
1196
- }, [t._stateKey, t._path.join("."), t._effect]), it("span", {
1200
+ }, [t._stateKey, t._path.join("."), t._effect]), st("span", {
1197
1201
  ref: c,
1198
1202
  style: { display: "none" },
1199
1203
  "data-signal-id": m
@@ -1212,7 +1216,7 @@ function Se(t) {
1212
1216
  },
1213
1217
  () => o.getState().getNestedState(t._stateKey, t._path)
1214
1218
  );
1215
- return it("text", {}, String(c));
1219
+ return st("text", {}, String(c));
1216
1220
  }
1217
1221
  function Kt({
1218
1222
  stateKey: t,
@@ -1220,14 +1224,14 @@ function Kt({
1220
1224
  itemPath: m,
1221
1225
  children: f
1222
1226
  }) {
1223
- const [, y] = tt({}), [k, p] = Lt(), I = q(null);
1224
- return st(() => {
1227
+ const [, y] = tt({}), [b, p] = Lt(), I = J(null);
1228
+ return at(() => {
1225
1229
  p.height > 0 && p.height !== I.current && (I.current = p.height, o.getState().setShadowMetadata(t, m, {
1226
1230
  virtualizer: {
1227
1231
  itemHeight: p.height
1228
1232
  }
1229
1233
  }));
1230
- }, [p.height, t, m]), at(() => {
1234
+ }, [p.height, t, m]), ut(() => {
1231
1235
  const a = `${t}////${c}`, v = o.getState().stateComponents.get(t) || {
1232
1236
  components: /* @__PURE__ */ new Map()
1233
1237
  };
@@ -1238,10 +1242,10 @@ function Kt({
1238
1242
  const n = o.getState().stateComponents.get(t);
1239
1243
  n && n.components.delete(a);
1240
1244
  };
1241
- }, [t, c, m.join(".")]), /* @__PURE__ */ It("div", { ref: k, children: f });
1245
+ }, [t, c, m.join(".")]), /* @__PURE__ */ It("div", { ref: b, children: f });
1242
1246
  }
1243
1247
  export {
1244
- Nt as $cogsSignal,
1248
+ Ct as $cogsSignal,
1245
1249
  Se as $cogsSignalStore,
1246
1250
  ue as addStateOptions,
1247
1251
  ge as createCogsState,