cogsbox-state 0.5.325 → 0.5.326

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,8 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as mt } from "react/jsx-runtime";
3
- import { useState as X, useRef as Q, useEffect as ot, useLayoutEffect as ct, useMemo as ht, createElement as at, useSyncExternalStore as xt, startTransition as Pt, useCallback as wt } from "react";
3
+ import { useState as X, useRef as Q, useEffect as nt, useLayoutEffect as ct, useMemo as ht, createElement as at, useSyncExternalStore as xt, startTransition as Pt, useCallback as wt } from "react";
4
4
  import { transformStateFunc as _t, isDeepEqual as H, isFunction as J, getNestedValue as z, getDifferences as vt, debounce as Mt } from "./utility.js";
5
- import { pushFunc as St, updateFn as rt, cutFunc as it, ValidationWrapper as jt, FormControlComponent as Ot } from "./Functions.jsx";
5
+ import { pushFunc as St, updateFn as ot, cutFunc as it, ValidationWrapper as jt, FormControlComponent as Ot } from "./Functions.jsx";
6
6
  import Rt from "superjson";
7
7
  import { v4 as yt } from "uuid";
8
8
  import "zod";
@@ -11,8 +11,8 @@ import { useCogsConfig as bt } from "./CogsStateClient.jsx";
11
11
  import { applyPatch as Ut } from "fast-json-patch";
12
12
  import Ft from "react-use-measure";
13
13
  function Et(t, c) {
14
- const h = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, I = h(t) || {};
15
- f(t, {
14
+ const h = o.getState().getInitialOptions, S = o.getState().setInitialStateOptions, I = h(t) || {};
15
+ S(t, {
16
16
  ...I,
17
17
  ...c
18
18
  });
@@ -22,20 +22,20 @@ function At({
22
22
  options: c,
23
23
  initialOptionsPart: h
24
24
  }) {
25
- const f = et(t) || {}, I = h[t] || {}, $ = o.getState().setInitialStateOptions, w = { ...I, ...f };
25
+ const S = et(t) || {}, I = h[t] || {}, b = o.getState().setInitialStateOptions, w = { ...I, ...S };
26
26
  let p = !1;
27
27
  if (c)
28
28
  for (const a in c)
29
29
  w.hasOwnProperty(a) ? (a == "localStorage" && c[a] && w[a].key !== c[a]?.key && (p = !0, w[a] = c[a]), a == "initialState" && c[a] && w[a] !== c[a] && // Different references
30
30
  !H(w[a], c[a]) && (p = !0, w[a] = c[a])) : (p = !0, w[a] = c[a]);
31
- p && $(t, w);
31
+ p && b(t, w);
32
32
  }
33
33
  function ie(t, { formElements: c, validation: h }) {
34
34
  return { initialState: t, formElements: c, validation: h };
35
35
  }
36
36
  const ce = (t, c) => {
37
37
  let h = t;
38
- const [f, I] = _t(h);
38
+ const [S, I] = _t(h);
39
39
  (Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((p) => {
40
40
  I[p] = I[p] || {}, I[p].formElements = {
41
41
  ...c?.formElements,
@@ -44,15 +44,15 @@ const ce = (t, c) => {
44
44
  ...I[p].formElements || {}
45
45
  // State-specific overrides
46
46
  }, et(p) || o.getState().setInitialStateOptions(p, I[p]);
47
- }), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
48
- const $ = (p, a) => {
47
+ }), o.getState().setInitialStates(S), o.getState().setCreatedState(S);
48
+ const b = (p, a) => {
49
49
  const [y] = X(a?.componentId ?? yt());
50
50
  At({
51
51
  stateKey: p,
52
52
  options: a,
53
53
  initialOptionsPart: I
54
54
  });
55
- const n = o.getState().cogsStateStore[p] || f[p], m = a?.modifyState ? a.modifyState(n) : n, [L, R] = Bt(
55
+ const n = o.getState().cogsStateStore[p] || S[p], m = a?.modifyState ? a.modifyState(n) : n, [L, R] = Bt(
56
56
  m,
57
57
  {
58
58
  stateKey: p,
@@ -73,7 +73,7 @@ const ce = (t, c) => {
73
73
  function w(p, a) {
74
74
  At({ stateKey: p, options: a, initialOptionsPart: I }), a.localStorage && Ht(p, a), gt(p);
75
75
  }
76
- return { useCogsState: $, setCogsOptions: w };
76
+ return { useCogsState: b, setCogsOptions: w };
77
77
  }, {
78
78
  setUpdaterState: lt,
79
79
  setState: K,
@@ -85,16 +85,16 @@ const ce = (t, c) => {
85
85
  addValidationError: Lt,
86
86
  removeValidationError: q,
87
87
  setServerSyncActions: Gt
88
- } = o.getState(), $t = (t, c, h, f, I) => {
88
+ } = o.getState(), $t = (t, c, h, S, I) => {
89
89
  h?.log && console.log(
90
90
  "saving to localstorage",
91
91
  c,
92
92
  h.localStorage?.key,
93
- f
93
+ S
94
94
  );
95
- const $ = J(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
96
- if ($ && f) {
97
- const w = `${f}-${c}-${$}`;
95
+ const b = J(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
96
+ if (b && S) {
97
+ const w = `${S}-${c}-${b}`;
98
98
  let p;
99
99
  try {
100
100
  p = ut(w)?.lastSyncedWithServer;
@@ -119,23 +119,23 @@ const ce = (t, c) => {
119
119
  return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
121
  }, Ht = (t, c) => {
122
- const h = o.getState().cogsStateStore[t], { sessionId: f } = bt(), I = J(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
123
- if (I && f) {
124
- const $ = ut(
125
- `${f}-${t}-${I}`
122
+ const h = o.getState().cogsStateStore[t], { sessionId: S } = bt(), I = J(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
123
+ if (I && S) {
124
+ const b = ut(
125
+ `${S}-${t}-${I}`
126
126
  );
127
- if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
128
- return K(t, $.state), gt(t), !0;
127
+ if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
128
+ return K(t, b.state), gt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Vt = (t, c, h, f, I, $) => {
131
+ }, Vt = (t, c, h, S, I, b) => {
132
132
  const w = {
133
133
  initialState: c,
134
134
  updaterState: dt(
135
135
  t,
136
- f,
136
+ S,
137
137
  I,
138
- $
138
+ b
139
139
  ),
140
140
  state: h
141
141
  };
@@ -144,35 +144,35 @@ const ce = (t, c) => {
144
144
  const c = o.getState().stateComponents.get(t);
145
145
  if (!c) return;
146
146
  const h = /* @__PURE__ */ new Set();
147
- c.components.forEach((f) => {
148
- (f ? Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"] : null)?.includes("none") || h.add(() => f.forceUpdate());
147
+ c.components.forEach((S) => {
148
+ (S ? Array.isArray(S.reactiveType) ? S.reactiveType : [S.reactiveType || "component"] : null)?.includes("none") || h.add(() => S.forceUpdate());
149
149
  }), queueMicrotask(() => {
150
- h.forEach((f) => f());
150
+ h.forEach((S) => S());
151
151
  });
152
152
  }, le = (t, c) => {
153
153
  const h = o.getState().stateComponents.get(t);
154
154
  if (h) {
155
- const f = `${t}////${c}`, I = h.components.get(f);
155
+ const S = `${t}////${c}`, I = h.components.get(S);
156
156
  if ((I ? Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"] : null)?.includes("none"))
157
157
  return;
158
158
  I && I.forceUpdate();
159
159
  }
160
- }, zt = (t, c, h, f) => {
160
+ }, zt = (t, c, h, S) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: z(c, f),
165
- newValue: z(h, f)
164
+ oldValue: z(c, S),
165
+ newValue: z(h, S)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: z(h, f)
171
+ newValue: z(h, S)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: z(c, f),
175
+ oldValue: z(c, S),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -183,9 +183,9 @@ const ce = (t, c) => {
183
183
  function Bt(t, {
184
184
  stateKey: c,
185
185
  serverSync: h,
186
- localStorage: f,
186
+ localStorage: S,
187
187
  formElements: I,
188
- reactiveDeps: $,
188
+ reactiveDeps: b,
189
189
  reactiveType: w,
190
190
  componentId: p,
191
191
  initialState: a,
@@ -198,7 +198,7 @@ function Bt(t, {
198
198
  const [v] = X(c ?? yt()), l = o.getState().stateLog[v], st = Q(/* @__PURE__ */ new Set()), Y = Q(p ?? yt()), j = Q(
199
199
  null
200
200
  );
201
- j.current = et(v) ?? null, ot(() => {
201
+ j.current = et(v) ?? null, nt(() => {
202
202
  if (y && y.stateKey === v && y.path?.[0]) {
203
203
  K(v, (r) => ({
204
204
  ...r,
@@ -210,7 +210,7 @@ function Bt(t, {
210
210
  userId: y.userId
211
211
  });
212
212
  }
213
- }, [y]), ot(() => {
213
+ }, [y]), nt(() => {
214
214
  if (a) {
215
215
  Et(v, {
216
216
  initialState: a
@@ -218,16 +218,16 @@ function Bt(t, {
218
218
  const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[v];
219
219
  if (!(i && !H(i, a) || !i) && !s)
220
220
  return;
221
- let u = null;
221
+ let g = null;
222
222
  const E = J(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
- E && U && (u = ut(`${U}-${v}-${E}`));
223
+ E && U && (g = ut(`${U}-${v}-${E}`));
224
224
  let T = a, A = !1;
225
- const P = s ? Date.now() : 0, N = u?.lastUpdated || 0, V = u?.lastSyncedWithServer || 0;
226
- s && P > N ? (T = e.serverState.data, A = !0) : u && N > V && (T = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(v, a), Vt(
225
+ const P = s ? Date.now() : 0, V = g?.lastUpdated || 0, k = g?.lastSyncedWithServer || 0;
226
+ s && P > V ? (T = e.serverState.data, A = !0) : g && V > k && (T = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(v, a), Vt(
227
227
  v,
228
228
  a,
229
229
  T,
230
- nt,
230
+ rt,
231
231
  Y.current,
232
232
  U
233
233
  ), A && E && U && $t(T, v, e, U, Date.now()), gt(v), (Array.isArray(w) ? w : [w || "component"]).includes("none") || R({});
@@ -242,7 +242,7 @@ function Bt(t, {
242
242
  serverSync: h,
243
243
  formElements: I,
244
244
  initialState: a,
245
- localStorage: f,
245
+ localStorage: S,
246
246
  middleware: j.current?.middleware
247
247
  });
248
248
  const e = `${v}////${Y.current}`, r = o.getState().stateComponents.get(v) || {
@@ -252,47 +252,47 @@ function Bt(t, {
252
252
  forceUpdate: () => R({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: $ || void 0,
255
+ depsFunction: b || void 0,
256
256
  reactiveType: w ?? ["component", "deps"]
257
257
  }), o.getState().stateComponents.set(v, r), R({}), () => {
258
258
  r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(v));
259
259
  };
260
260
  }, []);
261
- const nt = (e, r, s, i) => {
261
+ const rt = (e, r, s, i) => {
262
262
  if (Array.isArray(r)) {
263
- const u = `${v}-${r.join(".")}`;
264
- st.current.add(u);
263
+ const g = `${v}-${r.join(".")}`;
264
+ st.current.add(g);
265
265
  }
266
- const g = o.getState();
267
- K(v, (u) => {
268
- const E = J(e) ? e(u) : e, T = `${v}-${r.join(".")}`;
266
+ const u = o.getState();
267
+ K(v, (g) => {
268
+ const E = J(e) ? e(g) : e, T = `${v}-${r.join(".")}`;
269
269
  if (T) {
270
- let M = !1, b = g.signalDomElements.get(T);
271
- if ((!b || b.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
270
+ let M = !1, N = u.signalDomElements.get(T);
271
+ if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
272
  const O = r.slice(0, -1), W = z(E, O);
273
273
  if (Array.isArray(W)) {
274
274
  M = !0;
275
- const S = `${v}-${O.join(".")}`;
276
- b = g.signalDomElements.get(S);
275
+ const f = `${v}-${O.join(".")}`;
276
+ N = u.signalDomElements.get(f);
277
277
  }
278
278
  }
279
- if (b) {
279
+ if (N) {
280
280
  const O = M ? z(E, r.slice(0, -1)) : z(E, r);
281
- b.forEach(({ parentId: W, position: S, effect: k }) => {
281
+ N.forEach(({ parentId: W, position: f, effect: $ }) => {
282
282
  const C = document.querySelector(
283
283
  `[data-parent-id="${W}"]`
284
284
  );
285
285
  if (C) {
286
286
  const _ = Array.from(C.childNodes);
287
- if (_[S]) {
288
- const x = k ? new Function("state", `return (${k})(state)`)(O) : O;
289
- _[S].textContent = String(x);
287
+ if (_[f]) {
288
+ const x = $ ? new Function("state", `return (${$})(state)`)(O) : O;
289
+ _[f].textContent = String(x);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && r && q(
295
+ console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && r && q(
296
296
  (i || j.current?.validation?.key) + "." + r.join(".")
297
297
  );
298
298
  const A = r.slice(0, r.length - 1);
@@ -300,33 +300,33 @@ function Bt(t, {
300
300
  j.current?.validation?.key + "." + A.join(".")
301
301
  ), s.updateType === "insert" && j.current?.validation?.key && Dt(
302
302
  j.current?.validation?.key + "." + A.join(".")
303
- ).filter(([b, O]) => {
304
- let W = b?.split(".").length;
305
- if (b == A.join(".") && W == A.length - 1) {
306
- let S = b + "." + A;
307
- q(b), Lt(S, O);
303
+ ).filter(([N, O]) => {
304
+ let W = N?.split(".").length;
305
+ if (N == A.join(".") && W == A.length - 1) {
306
+ let f = N + "." + A;
307
+ q(N), Lt(f, O);
308
308
  }
309
309
  });
310
- const P = g.stateComponents.get(v);
310
+ const P = u.stateComponents.get(v);
311
311
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", P), P) {
312
- const M = vt(u, E), b = new Set(M), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
312
+ const M = vt(g, E), N = new Set(M), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
313
313
  for (const [
314
314
  W,
315
- S
315
+ f
316
316
  ] of P.components.entries()) {
317
- let k = !1;
318
- const C = Array.isArray(S.reactiveType) ? S.reactiveType : [S.reactiveType || "component"];
319
- if (console.log("component", S), !C.includes("none")) {
317
+ let $ = !1;
318
+ const C = Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"];
319
+ if (console.log("component", f), !C.includes("none")) {
320
320
  if (C.includes("all")) {
321
- S.forceUpdate();
321
+ f.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (C.includes("component") && ((S.paths.has(O) || S.paths.has("")) && (k = !0), !k))
325
- for (const _ of b) {
324
+ if (C.includes("component") && ((f.paths.has(O) || f.paths.has("")) && ($ = !0), !$))
325
+ for (const _ of N) {
326
326
  let x = _;
327
327
  for (; ; ) {
328
- if (S.paths.has(x)) {
329
- k = !0;
328
+ if (f.paths.has(x)) {
329
+ $ = !0;
330
330
  break;
331
331
  }
332
332
  const B = x.lastIndexOf(".");
@@ -337,8 +337,8 @@ function Bt(t, {
337
337
  );
338
338
  if (!isNaN(
339
339
  Number(x.substring(B + 1))
340
- ) && S.paths.has(Z)) {
341
- k = !0;
340
+ ) && f.paths.has(Z)) {
341
+ $ = !0;
342
342
  break;
343
343
  }
344
344
  x = Z;
@@ -347,53 +347,53 @@ function Bt(t, {
347
347
  if (x === "")
348
348
  break;
349
349
  }
350
- if (k) break;
350
+ if ($) break;
351
351
  }
352
- if (!k && C.includes("deps") && S.depsFunction) {
353
- const _ = S.depsFunction(E);
352
+ if (!$ && C.includes("deps") && f.depsFunction) {
353
+ const _ = f.depsFunction(E);
354
354
  let x = !1;
355
- typeof _ == "boolean" ? _ && (x = !0) : H(S.deps, _) || (S.deps = _, x = !0), x && (k = !0);
355
+ typeof _ == "boolean" ? _ && (x = !0) : H(f.deps, _) || (f.deps = _, x = !0), x && ($ = !0);
356
356
  }
357
- k && S.forceUpdate();
357
+ $ && f.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const N = Date.now();
362
- r = r.map((M, b) => {
361
+ const V = Date.now();
362
+ r = r.map((M, N) => {
363
363
  const O = r.slice(0, -1), W = z(E, O);
364
- return b === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : M;
364
+ return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : M;
365
365
  });
366
- const { oldValue: V, newValue: F } = zt(
366
+ const { oldValue: k, newValue: F } = zt(
367
367
  s.updateType,
368
- u,
368
+ g,
369
369
  E,
370
370
  r
371
371
  ), D = {
372
- timeStamp: N,
372
+ timeStamp: V,
373
373
  stateKey: v,
374
374
  path: r,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
- oldValue: V,
377
+ oldValue: k,
378
378
  newValue: F
379
379
  };
380
380
  switch (s.updateType) {
381
381
  case "update":
382
- g.updateShadowAtPath(v, r, E);
382
+ u.updateShadowAtPath(v, r, E);
383
383
  break;
384
384
  case "insert":
385
385
  const M = r.slice(0, -1);
386
- g.insertShadowArrayElement(v, M, F);
386
+ u.insertShadowArrayElement(v, M, F);
387
387
  break;
388
388
  case "cut":
389
- const b = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- g.removeShadowArrayElement(v, b, O);
389
+ const N = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
+ u.removeShadowArrayElement(v, N, O);
391
391
  break;
392
392
  }
393
393
  if (Wt(v, (M) => {
394
- const O = [...M ?? [], D].reduce((W, S) => {
395
- const k = `${S.stateKey}:${JSON.stringify(S.path)}`, C = W.get(k);
396
- return C ? (C.timeStamp = Math.max(C.timeStamp, S.timeStamp), C.newValue = S.newValue, C.oldValue = C.oldValue ?? S.oldValue, C.updateType = S.updateType) : W.set(k, { ...S }), W;
394
+ const O = [...M ?? [], D].reduce((W, f) => {
395
+ const $ = `${f.stateKey}:${JSON.stringify(f.path)}`, C = W.get($);
396
+ return C ? (C.timeStamp = Math.max(C.timeStamp, f.timeStamp), C.newValue = f.newValue, C.oldValue = C.oldValue ?? f.oldValue, C.updateType = f.updateType) : W.set($, { ...f }), W;
397
397
  }, /* @__PURE__ */ new Map());
398
398
  return Array.from(O.values());
399
399
  }), $t(
@@ -405,11 +405,11 @@ function Bt(t, {
405
405
  updateLog: l,
406
406
  update: D
407
407
  }), j.current?.serverSync) {
408
- const M = g.serverState[v], b = j.current?.serverSync;
408
+ const M = u.serverState[v], N = j.current?.serverSync;
409
409
  Gt(v, {
410
- syncKey: typeof b.syncKey == "string" ? b.syncKey : b.syncKey({ state: E }),
410
+ syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
411
411
  rollBackState: M,
412
- actionTimeStamp: Date.now() + (b.debounce ?? 3e3),
412
+ actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
@@ -420,27 +420,27 @@ function Bt(t, {
420
420
  v,
421
421
  dt(
422
422
  v,
423
- nt,
423
+ rt,
424
424
  Y.current,
425
425
  U
426
426
  )
427
427
  ), o.getState().cogsStateStore[v] || K(v, t), o.getState().initialStateGlobal[v] || It(v, t));
428
428
  const d = ht(() => dt(
429
429
  v,
430
- nt,
430
+ rt,
431
431
  Y.current,
432
432
  U
433
433
  ), [v, U]);
434
434
  return [Nt(v), d];
435
435
  }
436
- function dt(t, c, h, f) {
436
+ function dt(t, c, h, S) {
437
437
  const I = /* @__PURE__ */ new Map();
438
- let $ = 0;
438
+ let b = 0;
439
439
  const w = (y) => {
440
440
  const n = y.join(".");
441
441
  for (const [m] of I)
442
442
  (m === n || m.startsWith(n + ".")) && I.delete(m);
443
- $++;
443
+ b++;
444
444
  }, p = {
445
445
  removeValidation: (y) => {
446
446
  y?.validationKey && q(y.validationKey);
@@ -449,8 +449,8 @@ function dt(t, c, h, f) {
449
449
  const n = o.getState().getInitialOptions(t)?.validation;
450
450
  n?.key && q(n?.key), y?.validationKey && q(y.validationKey);
451
451
  const m = o.getState().initialStateGlobal[t];
452
- o.getState().clearSelectedIndexesForState(t), I.clear(), $++;
453
- const L = a(m, []), R = et(t), U = J(R?.localStorage?.key) ? R?.localStorage?.key(m) : R?.localStorage?.key, G = `${f}-${t}-${U}`;
452
+ o.getState().clearSelectedIndexesForState(t), I.clear(), b++;
453
+ const L = a(m, []), R = et(t), U = J(R?.localStorage?.key) ? R?.localStorage?.key(m) : R?.localStorage?.key, G = `${S}-${t}-${U}`;
454
454
  G && localStorage.removeItem(G), lt(t, L), K(t, m);
455
455
  const v = o.getState().stateComponents.get(t);
456
456
  return v && v.components.forEach((l) => {
@@ -458,13 +458,13 @@ function dt(t, c, h, f) {
458
458
  }), m;
459
459
  },
460
460
  updateInitialState: (y) => {
461
- I.clear(), $++;
461
+ I.clear(), b++;
462
462
  const n = dt(
463
463
  t,
464
464
  c,
465
465
  h,
466
- f
467
- ), m = o.getState().initialStateGlobal[t], L = et(t), R = J(L?.localStorage?.key) ? L?.localStorage?.key(m) : L?.localStorage?.key, U = `${f}-${t}-${R}`;
466
+ S
467
+ ), m = o.getState().initialStateGlobal[t], L = et(t), R = J(L?.localStorage?.key) ? L?.localStorage?.key(m) : L?.localStorage?.key, U = `${S}-${t}-${R}`;
468
468
  return localStorage.getItem(U) && localStorage.removeItem(U), Pt(() => {
469
469
  It(t, y), o.getState().initializeShadowState(t, y), lt(t, n), K(t, y);
470
470
  const G = o.getState().stateComponents.get(t);
@@ -530,8 +530,8 @@ function dt(t, c, h, f) {
530
530
  if (r && !r.paths.has("")) {
531
531
  const s = n.join(".");
532
532
  let i = !0;
533
- for (const g of r.paths)
534
- if (s.startsWith(g) && (s === g || s[g.length] === ".")) {
533
+ for (const u of r.paths)
534
+ if (s.startsWith(u) && (s === u || s[u.length] === ".")) {
535
535
  i = !1;
536
536
  break;
537
537
  }
@@ -553,13 +553,13 @@ function dt(t, c, h, 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((u) => {
557
- const E = [s, ...u.path].join(".");
558
- o.getState().addValidationError(E, u.message);
556
+ o.getState().removeValidationError(s), i.errors.forEach((g) => {
557
+ const E = [s, ...g.path].join(".");
558
+ o.getState().addValidationError(E, g.message);
559
559
  });
560
- const g = o.getState().stateComponents.get(t);
561
- g && g.components.forEach((u) => {
562
- u.forceUpdate();
560
+ const u = o.getState().stateComponents.get(t);
561
+ u && u.components.forEach((g) => {
562
+ g.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;
@@ -581,7 +581,7 @@ function dt(t, c, h, f) {
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
584
- const d = o.getState().initialStateGlobal[t], e = et(t), r = J(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${f}-${t}-${r}`;
584
+ const d = o.getState().initialStateGlobal[t], e = et(t), r = J(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${S}-${t}-${r}`;
585
585
  s && localStorage.removeItem(s);
586
586
  };
587
587
  if (l === "showValidationErrors")
@@ -621,94 +621,109 @@ function dt(t, c, h, f) {
621
621
  itemHeight: r = 50,
622
622
  overscan: s = 5,
623
623
  stickToBottom: i = !1
624
- } = e, g = Q(null), [u, E] = X({
624
+ } = e, u = Q(null), [g, E] = X({
625
625
  startIndex: 0,
626
626
  endIndex: 10
627
627
  }), T = Q(i), [A, P] = X(0);
628
- ot(() => o.getState().subscribeToShadowState(t, () => {
629
- P((k) => k + 1);
628
+ nt(() => o.getState().subscribeToShadowState(t, () => {
629
+ P(($) => $ + 1);
630
630
  }), [t]);
631
- const N = o().getNestedState(
631
+ const V = o().getNestedState(
632
632
  t,
633
633
  n
634
- ), V = N.length, { totalHeight: F, positions: D } = ht(() => {
635
- const S = o.getState().getShadowMetadata(t, n) || [];
636
- let k = 0;
634
+ ), k = V.length, { totalHeight: F, positions: D } = ht(() => {
635
+ const f = o.getState().getShadowMetadata(t, n) || [];
636
+ let $ = 0;
637
637
  const C = [];
638
- for (let _ = 0; _ < V; _++) {
639
- C[_] = k;
640
- const x = S[_]?.virtualizer?.itemHeight;
641
- k += x || r;
638
+ for (let _ = 0; _ < k; _++) {
639
+ C[_] = $;
640
+ const x = f[_]?.virtualizer?.itemHeight;
641
+ $ += x || r;
642
642
  }
643
- return { totalHeight: k, positions: C };
643
+ return { totalHeight: $, positions: C };
644
644
  }, [
645
- V,
645
+ k,
646
646
  t,
647
647
  n.join("."),
648
648
  r,
649
649
  A
650
650
  ]), M = ht(() => {
651
- const S = Math.max(0, u.startIndex), k = Math.min(V, u.endIndex), C = Array.from(
652
- { length: k - S },
653
- (x, B) => S + B
654
- ), _ = C.map((x) => N[x]);
651
+ const f = Math.max(0, g.startIndex), $ = Math.min(k, g.endIndex), C = Array.from(
652
+ { length: $ - f },
653
+ (x, B) => f + B
654
+ ), _ = C.map((x) => V[x]);
655
655
  return a(_, n, {
656
656
  ...m,
657
657
  validIndices: C
658
658
  });
659
- }, [u.startIndex, u.endIndex, N, V]);
660
- ct(() => {
661
- const S = g.current;
662
- if (!S) return;
663
- let k;
659
+ }, [g.startIndex, g.endIndex, V, k]);
660
+ nt(() => {
661
+ if (i && k > 0 && u.current) {
662
+ const f = u.current, $ = Math.ceil(
663
+ f.clientHeight / r
664
+ );
665
+ E({
666
+ startIndex: Math.max(
667
+ 0,
668
+ k - $ - s
669
+ ),
670
+ endIndex: k
671
+ }), setTimeout(() => {
672
+ f.scrollTop = f.scrollHeight;
673
+ }, 100);
674
+ }
675
+ }, [k]), ct(() => {
676
+ const f = u.current;
677
+ if (!f) return;
678
+ let $;
664
679
  const C = () => {
665
- if (!S) return;
666
- const { scrollTop: x } = S;
667
- let B = 0, Z = V - 1;
680
+ if (!f) return;
681
+ const { scrollTop: x } = f;
682
+ let B = 0, Z = k - 1;
668
683
  for (; B <= Z; ) {
669
684
  const ft = Math.floor((B + Z) / 2);
670
685
  D[ft] < x ? B = ft + 1 : Z = ft - 1;
671
686
  }
672
687
  const pt = Math.max(0, Z - s);
673
688
  let tt = pt;
674
- const Ct = x + S.clientHeight;
675
- for (; tt < V && D[tt] < Ct; )
689
+ const Ct = x + f.clientHeight;
690
+ for (; tt < k && D[tt] < Ct; )
676
691
  tt++;
677
- tt = Math.min(V, tt + s), E({ startIndex: pt, endIndex: tt });
692
+ tt = Math.min(k, tt + s), E({ startIndex: pt, endIndex: tt });
678
693
  }, _ = () => {
679
- T.current = S.scrollHeight - S.scrollTop - S.clientHeight < 1, C();
694
+ T.current = f.scrollHeight - f.scrollTop - f.clientHeight < 1, C();
680
695
  };
681
- return S.addEventListener("scroll", _, {
696
+ return f.addEventListener("scroll", _, {
682
697
  passive: !0
683
- }), i && (k = setTimeout(() => {
684
- console.log("totalHeight", F), T.current && S.scrollTo({
685
- top: S.scrollHeight,
698
+ }), i && ($ = setTimeout(() => {
699
+ console.log("totalHeight", F), T.current && f.scrollTo({
700
+ top: 999999999,
686
701
  behavior: "auto"
687
702
  // ALWAYS 'auto' for an instant, correct jump.
688
703
  });
689
704
  }, 1e3)), C(), () => {
690
- clearTimeout(k), S.removeEventListener("scroll", _);
705
+ clearTimeout($), f.removeEventListener("scroll", _);
691
706
  };
692
- }, [V, D, F, i]);
693
- const b = wt(
694
- (S = "smooth") => {
695
- g.current && (T.current = !0, g.current.scrollTo({
696
- top: g.current.scrollHeight,
697
- behavior: S
707
+ }, [k, D, F, i]);
708
+ const N = wt(
709
+ (f = "smooth") => {
710
+ u.current && (T.current = !0, u.current.scrollTo({
711
+ top: u.current.scrollHeight,
712
+ behavior: f
698
713
  }));
699
714
  },
700
715
  []
701
716
  ), O = wt(
702
- (S, k = "smooth") => {
703
- g.current && D[S] !== void 0 && (T.current = !1, g.current.scrollTo({
704
- top: D[S],
705
- behavior: k
717
+ (f, $ = "smooth") => {
718
+ u.current && D[f] !== void 0 && (T.current = !1, u.current.scrollTo({
719
+ top: D[f],
720
+ behavior: $
706
721
  }));
707
722
  },
708
723
  [D]
709
724
  ), W = {
710
725
  outer: {
711
- ref: g,
726
+ ref: u,
712
727
  style: { overflowY: "auto", height: "100%" }
713
728
  },
714
729
  inner: {
@@ -719,63 +734,63 @@ function dt(t, c, h, f) {
719
734
  },
720
735
  list: {
721
736
  style: {
722
- transform: `translateY(${D[u.startIndex] || 0}px)`
737
+ transform: `translateY(${D[g.startIndex] || 0}px)`
723
738
  }
724
739
  }
725
740
  };
726
741
  return {
727
742
  virtualState: M,
728
743
  virtualizerProps: W,
729
- scrollToBottom: b,
744
+ scrollToBottom: N,
730
745
  scrollToIndex: O
731
746
  };
732
747
  };
733
748
  if (l === "stateSort")
734
749
  return (e) => {
735
750
  const s = [...d()].sort(
736
- (u, E) => e(u.item, E.item)
737
- ), i = s.map(({ item: u }) => u), g = {
751
+ (g, E) => e(g.item, E.item)
752
+ ), i = s.map(({ item: g }) => g), u = {
738
753
  ...m,
739
754
  validIndices: s.map(
740
- ({ originalIndex: u }) => u
755
+ ({ originalIndex: g }) => g
741
756
  )
742
757
  };
743
- return a(i, n, g);
758
+ return a(i, n, u);
744
759
  };
745
760
  if (l === "stateFilter")
746
761
  return (e) => {
747
762
  const s = d().filter(
748
- ({ item: u }, E) => e(u, E)
749
- ), i = s.map(({ item: u }) => u), g = {
763
+ ({ item: g }, E) => e(g, E)
764
+ ), i = s.map(({ item: g }) => g), u = {
750
765
  ...m,
751
766
  validIndices: s.map(
752
- ({ originalIndex: u }) => u
767
+ ({ originalIndex: g }) => g
753
768
  )
754
769
  };
755
- return a(i, n, g);
770
+ return a(i, n, u);
756
771
  };
757
772
  if (l === "stateMap")
758
773
  return (e) => {
759
774
  const r = o.getState().getNestedState(t, n);
760
- return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
761
- const u = r[i], E = [...n, i.toString()], T = a(u, E, m);
762
- return e(u, T, {
775
+ return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
776
+ const g = r[i], E = [...n, i.toString()], T = a(g, E, m);
777
+ return e(g, T, {
763
778
  register: () => {
764
- const [, P] = X({}), N = `${h}-${n.join(".")}-${i}`;
779
+ const [, P] = X({}), V = `${h}-${n.join(".")}-${i}`;
765
780
  ct(() => {
766
- const V = `${t}////${N}`, F = o.getState().stateComponents.get(t) || {
781
+ const k = `${t}////${V}`, F = o.getState().stateComponents.get(t) || {
767
782
  components: /* @__PURE__ */ new Map()
768
783
  };
769
- return F.components.set(V, {
784
+ return F.components.set(k, {
770
785
  forceUpdate: () => P({}),
771
786
  paths: /* @__PURE__ */ new Set([E.join(".")])
772
787
  }), o.getState().stateComponents.set(t, F), () => {
773
788
  const D = o.getState().stateComponents.get(t);
774
- D && D.components.delete(V);
789
+ D && D.components.delete(k);
775
790
  };
776
- }, [t, N]);
791
+ }, [t, V]);
777
792
  },
778
- index: g,
793
+ index: u,
779
794
  originalIndex: i
780
795
  });
781
796
  }) : (console.warn(
@@ -785,9 +800,9 @@ function dt(t, c, h, f) {
785
800
  };
786
801
  if (l === "stateMapNoRender")
787
802
  return (e) => y.map((s, i) => {
788
- let g;
789
- m?.validIndices && m.validIndices[i] !== void 0 ? g = m.validIndices[i] : g = i;
790
- const u = [...n, g.toString()], E = a(s, u, m);
803
+ let u;
804
+ m?.validIndices && m.validIndices[i] !== void 0 ? u = m.validIndices[i] : u = i;
805
+ const g = [...n, u.toString()], E = a(s, g, m);
791
806
  return e(
792
807
  s,
793
808
  E,
@@ -809,17 +824,17 @@ function dt(t, c, h, f) {
809
824
  if (l === "stateList")
810
825
  return (e) => {
811
826
  const r = o.getState().getNestedState(t, n);
812
- return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
813
- const u = r[i], E = [...n, i.toString()], T = a(u, E, m), A = `${h}-${n.join(".")}-${i}`;
827
+ return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
828
+ const g = r[i], E = [...n, i.toString()], T = a(g, E, m), A = `${h}-${n.join(".")}-${i}`;
814
829
  return at(Yt, {
815
830
  key: i,
816
831
  stateKey: t,
817
832
  itemComponentId: A,
818
833
  itemPath: E,
819
834
  children: e(
820
- u,
821
- T,
822
835
  g,
836
+ T,
837
+ u,
823
838
  r,
824
839
  a(r, n, m)
825
840
  )
@@ -831,7 +846,7 @@ function dt(t, c, h, f) {
831
846
  if (l === "stateFlattenOn")
832
847
  return (e) => {
833
848
  const r = y;
834
- I.clear(), $++;
849
+ I.clear(), b++;
835
850
  const s = r.flatMap(
836
851
  (i) => i[e] ?? []
837
852
  );
@@ -860,24 +875,24 @@ function dt(t, c, h, f) {
860
875
  ));
861
876
  if (l === "uniqueInsert")
862
877
  return (e, r, s) => {
863
- const i = o.getState().getNestedState(t, n), g = J(e) ? e(i) : e;
864
- let u = null;
878
+ const i = o.getState().getNestedState(t, n), u = J(e) ? e(i) : e;
879
+ let g = null;
865
880
  if (!i.some((T) => {
866
881
  if (r) {
867
882
  const P = r.every(
868
- (N) => H(T[N], g[N])
883
+ (V) => H(T[V], u[V])
869
884
  );
870
- return P && (u = T), P;
885
+ return P && (g = T), P;
871
886
  }
872
- const A = H(T, g);
873
- return A && (u = T), A;
887
+ const A = H(T, u);
888
+ return A && (g = T), A;
874
889
  }))
875
- w(n), St(c, g, n, t);
876
- else if (s && u) {
877
- const T = s(u), A = i.map(
878
- (P) => H(P, u) ? T : P
890
+ w(n), St(c, u, n, t);
891
+ else if (s && g) {
892
+ const T = s(g), A = i.map(
893
+ (P) => H(P, g) ? T : P
879
894
  );
880
- w(n), rt(c, A, n);
895
+ w(n), ot(c, A, n);
881
896
  }
882
897
  };
883
898
  if (l === "cut")
@@ -901,7 +916,7 @@ function dt(t, c, h, f) {
901
916
  if (l === "stateFind")
902
917
  return (e) => {
903
918
  const s = d().find(
904
- ({ item: g }, u) => e(g, u)
919
+ ({ item: u }, g) => e(u, g)
905
920
  );
906
921
  if (!s) return;
907
922
  const i = [...n, s.originalIndex.toString()];
@@ -910,11 +925,11 @@ function dt(t, c, h, f) {
910
925
  if (l === "findWith")
911
926
  return (e, r) => {
912
927
  const i = d().find(
913
- ({ item: u }) => u[e] === r
928
+ ({ item: g }) => g[e] === r
914
929
  );
915
930
  if (!i) return;
916
- const g = [...n, i.originalIndex.toString()];
917
- return a(i.item, g, m);
931
+ const u = [...n, i.originalIndex.toString()];
932
+ return a(i.item, u, m);
918
933
  };
919
934
  }
920
935
  const Y = n[n.length - 1];
@@ -952,7 +967,7 @@ function dt(t, c, h, f) {
952
967
  return o.getState().getSyncInfo(d);
953
968
  }
954
969
  if (l == "getLocalStorage")
955
- return (d) => ut(f + "-" + t + "-" + d);
970
+ return (d) => ut(S + "-" + t + "-" + d);
956
971
  if (l === "_selected") {
957
972
  const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
958
973
  return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
@@ -962,7 +977,7 @@ function dt(t, c, h, f) {
962
977
  const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
963
978
  d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
964
979
  const i = o.getState().getNestedState(t, [...e]);
965
- rt(c, i, e), w(e);
980
+ ot(c, i, e), w(e);
966
981
  };
967
982
  if (l === "toggleSelected")
968
983
  return () => {
@@ -973,7 +988,7 @@ function dt(t, c, h, f) {
973
988
  s === e ? void 0 : e
974
989
  );
975
990
  const i = o.getState().getNestedState(t, [...d]);
976
- rt(c, i, d), w(d);
991
+ ot(c, i, d), w(d);
977
992
  };
978
993
  if (n.length == 0) {
979
994
  if (l === "applyJsonPatch")
@@ -985,11 +1000,11 @@ function dt(t, c, h, f) {
985
1000
  s,
986
1001
  c,
987
1002
  h,
988
- f
1003
+ S
989
1004
  );
990
1005
  const i = o.getState().stateComponents.get(t);
991
1006
  if (i) {
992
- const g = vt(e, s), u = new Set(g);
1007
+ const u = vt(e, s), g = new Set(u);
993
1008
  for (const [
994
1009
  E,
995
1010
  T
@@ -1002,42 +1017,42 @@ function dt(t, c, h, f) {
1002
1017
  continue;
1003
1018
  }
1004
1019
  if (P.includes("component") && (T.paths.has("") && (A = !0), !A))
1005
- for (const N of u) {
1006
- if (T.paths.has(N)) {
1020
+ for (const V of g) {
1021
+ if (T.paths.has(V)) {
1007
1022
  A = !0;
1008
1023
  break;
1009
1024
  }
1010
- let V = N.lastIndexOf(".");
1011
- for (; V !== -1; ) {
1012
- const F = N.substring(0, V);
1025
+ let k = V.lastIndexOf(".");
1026
+ for (; k !== -1; ) {
1027
+ const F = V.substring(0, k);
1013
1028
  if (T.paths.has(F)) {
1014
1029
  A = !0;
1015
1030
  break;
1016
1031
  }
1017
- const D = N.substring(
1018
- V + 1
1032
+ const D = V.substring(
1033
+ k + 1
1019
1034
  );
1020
1035
  if (!isNaN(Number(D))) {
1021
1036
  const M = F.lastIndexOf(".");
1022
1037
  if (M !== -1) {
1023
- const b = F.substring(
1038
+ const N = F.substring(
1024
1039
  0,
1025
1040
  M
1026
1041
  );
1027
- if (T.paths.has(b)) {
1042
+ if (T.paths.has(N)) {
1028
1043
  A = !0;
1029
1044
  break;
1030
1045
  }
1031
1046
  }
1032
1047
  }
1033
- V = F.lastIndexOf(".");
1048
+ k = F.lastIndexOf(".");
1034
1049
  }
1035
1050
  if (A) break;
1036
1051
  }
1037
1052
  if (!A && P.includes("deps") && T.depsFunction) {
1038
- const N = T.depsFunction(s);
1039
- let V = !1;
1040
- typeof N == "boolean" ? N && (V = !0) : H(T.deps, N) || (T.deps = N, V = !0), V && (A = !0);
1053
+ const V = T.depsFunction(s);
1054
+ let k = !1;
1055
+ typeof V == "boolean" ? V && (k = !0) : H(T.deps, V) || (T.deps = V, k = !0), k && (A = !0);
1041
1056
  }
1042
1057
  A && T.forceUpdate();
1043
1058
  }
@@ -1055,12 +1070,12 @@ function dt(t, c, h, f) {
1055
1070
  const r = o.getState().cogsStateStore[t];
1056
1071
  try {
1057
1072
  const s = o.getState().getValidationErrors(d.key);
1058
- s && s.length > 0 && s.forEach(([g]) => {
1059
- g && g.startsWith(d.key) && q(g);
1073
+ s && s.length > 0 && s.forEach(([u]) => {
1074
+ u && u.startsWith(d.key) && q(u);
1060
1075
  });
1061
1076
  const i = d.zodSchema.safeParse(r);
1062
- return i.success ? !0 : (i.error.errors.forEach((u) => {
1063
- const E = u.path, T = u.message, A = [d.key, ...E].join(".");
1077
+ return i.success ? !0 : (i.error.errors.forEach((g) => {
1078
+ const E = g.path, T = g.message, A = [d.key, ...E].join(".");
1064
1079
  e(A, T);
1065
1080
  }), gt(t), !1);
1066
1081
  } catch (s) {
@@ -1107,12 +1122,12 @@ function dt(t, c, h, f) {
1107
1122
  return (d, e) => {
1108
1123
  if (e?.debounce)
1109
1124
  Mt(() => {
1110
- rt(c, d, n, "");
1125
+ ot(c, d, n, "");
1111
1126
  const r = o.getState().getNestedState(t, n);
1112
1127
  e?.afterUpdate && e.afterUpdate(r);
1113
1128
  }, e.debounce);
1114
1129
  else {
1115
- rt(c, d, n, "");
1130
+ ot(c, d, n, "");
1116
1131
  const r = o.getState().getNestedState(t, n);
1117
1132
  e?.afterUpdate && e.afterUpdate(r);
1118
1133
  }
@@ -1129,13 +1144,13 @@ function dt(t, c, h, f) {
1129
1144
  formOpts: e
1130
1145
  }
1131
1146
  );
1132
- const j = [...n, l], nt = o.getState().getNestedState(t, j);
1133
- return a(nt, j, m);
1147
+ const j = [...n, l], rt = o.getState().getNestedState(t, j);
1148
+ return a(rt, j, m);
1134
1149
  }
1135
1150
  }, G = new Proxy(R, U);
1136
1151
  return I.set(L, {
1137
1152
  proxy: G,
1138
- stateVersion: $
1153
+ stateVersion: b
1139
1154
  }), G;
1140
1155
  }
1141
1156
  return a(
@@ -1154,17 +1169,17 @@ function qt({
1154
1169
  h,
1155
1170
  t._path
1156
1171
  ).stateMapNoRender(
1157
- (I, $, w, p, a) => t._mapFn(I, $, w, p, a)
1172
+ (I, b, w, p, a) => t._mapFn(I, b, w, p, a)
1158
1173
  ) : null;
1159
1174
  }
1160
1175
  function Jt({
1161
1176
  proxy: t
1162
1177
  }) {
1163
1178
  const c = Q(null), h = `${t._stateKey}-${t._path.join(".")}`;
1164
- return ot(() => {
1165
- const f = c.current;
1166
- if (!f || !f.parentElement) return;
1167
- const I = f.parentElement, w = Array.from(I.childNodes).indexOf(f);
1179
+ return nt(() => {
1180
+ const S = c.current;
1181
+ if (!S || !S.parentElement) return;
1182
+ const I = S.parentElement, w = Array.from(I.childNodes).indexOf(S);
1168
1183
  let p = I.getAttribute("data-parent-id");
1169
1184
  p || (p = `parent-${crypto.randomUUID()}`, I.setAttribute("data-parent-id", p));
1170
1185
  const y = {
@@ -1189,7 +1204,7 @@ function Jt({
1189
1204
  m = n;
1190
1205
  m !== null && typeof m == "object" && (m = JSON.stringify(m));
1191
1206
  const L = document.createTextNode(String(m));
1192
- f.replaceWith(L);
1207
+ S.replaceWith(L);
1193
1208
  }, [t._stateKey, t._path.join("."), t._effect]), at("span", {
1194
1209
  ref: c,
1195
1210
  style: { display: "none" },
@@ -1199,13 +1214,13 @@ function Jt({
1199
1214
  function de(t) {
1200
1215
  const c = xt(
1201
1216
  (h) => {
1202
- const f = o.getState().stateComponents.get(t._stateKey) || {
1217
+ const S = o.getState().stateComponents.get(t._stateKey) || {
1203
1218
  components: /* @__PURE__ */ new Map()
1204
1219
  };
1205
- return f.components.set(t._stateKey, {
1220
+ return S.components.set(t._stateKey, {
1206
1221
  forceUpdate: h,
1207
1222
  paths: /* @__PURE__ */ new Set([t._path.join(".")])
1208
- }), () => f.components.delete(t._stateKey);
1223
+ }), () => S.components.delete(t._stateKey);
1209
1224
  },
1210
1225
  () => o.getState().getNestedState(t._stateKey, t._path)
1211
1226
  );
@@ -1215,10 +1230,10 @@ function Yt({
1215
1230
  stateKey: t,
1216
1231
  itemComponentId: c,
1217
1232
  itemPath: h,
1218
- children: f
1233
+ children: S
1219
1234
  }) {
1220
- const [, I] = X({}), [$, w] = Ft(), p = Q(null);
1221
- return ot(() => {
1235
+ const [, I] = X({}), [b, w] = Ft(), p = Q(null);
1236
+ return nt(() => {
1222
1237
  w.height > 0 && w.height !== p.current && (p.current = w.height, o.getState().setShadowMetadata(t, h, {
1223
1238
  virtualizer: {
1224
1239
  itemHeight: w.height
@@ -1235,7 +1250,7 @@ function Yt({
1235
1250
  const n = o.getState().stateComponents.get(t);
1236
1251
  n && n.components.delete(a);
1237
1252
  };
1238
- }, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref: $, children: f });
1253
+ }, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref: b, children: S });
1239
1254
  }
1240
1255
  export {
1241
1256
  kt as $cogsSignal,