cogsbox-state 0.5.334 → 0.5.336

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,63 +1,63 @@
1
1
  "use client";
2
2
  import { jsx as mt } from "react/jsx-runtime";
3
- import { useState as Q, useRef as Z, useEffect as ot, useLayoutEffect as ct, useMemo as ht, createElement as at, useSyncExternalStore as xt, startTransition as Pt, useCallback as wt } from "react";
4
- import { transformStateFunc as _t, isDeepEqual as H, isFunction as Y, 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 Rt } from "./Functions.jsx";
6
- import Ot from "superjson";
3
+ import { useState as X, useRef as Q, useEffect as nt, useLayoutEffect as ct, useMemo as ht, createElement as at, useSyncExternalStore as xt, startTransition as Pt, useCallback as wt } from "react";
4
+ import { transformStateFunc as _t, isDeepEqual as H, isFunction as J, getNestedValue as z, getDifferences as vt, debounce as Mt } from "./utility.js";
5
+ import { pushFunc as St, updateFn as ot, cutFunc as it, ValidationWrapper as jt, FormControlComponent as Ot } from "./Functions.jsx";
6
+ import Rt from "superjson";
7
7
  import { v4 as yt } from "uuid";
8
8
  import "zod";
9
9
  import { getGlobalStore as o, formRefStore as Tt } from "./store.js";
10
10
  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
- function Et(t, i) {
14
- const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, y = m(t) || {};
15
- f(t, {
16
- ...y,
17
- ...i
13
+ function Et(t, c) {
14
+ const h = o.getState().getInitialOptions, S = o.getState().setInitialStateOptions, I = h(t) || {};
15
+ S(t, {
16
+ ...I,
17
+ ...c
18
18
  });
19
19
  }
20
20
  function At({
21
21
  stateKey: t,
22
- options: i,
23
- initialOptionsPart: m
22
+ options: c,
23
+ initialOptionsPart: h
24
24
  }) {
25
- const f = et(t) || {}, y = m[t] || {}, b = o.getState().setInitialStateOptions, w = { ...y, ...f };
26
- let I = !1;
27
- if (i)
28
- for (const a in i)
29
- w.hasOwnProperty(a) ? (a == "localStorage" && i[a] && w[a].key !== i[a]?.key && (I = !0, w[a] = i[a]), a == "initialState" && i[a] && w[a] !== i[a] && // Different references
30
- !H(w[a], i[a]) && (I = !0, w[a] = i[a])) : (I = !0, w[a] = i[a]);
31
- I && b(t, w);
25
+ const S = et(t) || {}, I = h[t] || {}, b = o.getState().setInitialStateOptions, w = { ...I, ...S };
26
+ let p = !1;
27
+ if (c)
28
+ for (const a in c)
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
+ !H(w[a], c[a]) && (p = !0, w[a] = c[a])) : (p = !0, w[a] = c[a]);
31
+ p && b(t, w);
32
32
  }
33
- function ie(t, { formElements: i, validation: m }) {
34
- return { initialState: t, formElements: i, validation: m };
33
+ function ie(t, { formElements: c, validation: h }) {
34
+ return { initialState: t, formElements: c, validation: h };
35
35
  }
36
- const ce = (t, i) => {
37
- let m = t;
38
- const [f, y] = _t(m);
39
- (Object.keys(y).length > 0 || i && Object.keys(i).length > 0) && Object.keys(y).forEach((I) => {
40
- y[I] = y[I] || {}, y[I].formElements = {
41
- ...i?.formElements,
36
+ const ce = (t, c) => {
37
+ let h = t;
38
+ const [S, I] = _t(h);
39
+ (Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((p) => {
40
+ I[p] = I[p] || {}, I[p].formElements = {
41
+ ...c?.formElements,
42
42
  // Global defaults first
43
- ...i?.validation,
44
- ...y[I].formElements || {}
43
+ ...c?.validation,
44
+ ...I[p].formElements || {}
45
45
  // State-specific overrides
46
- }, et(I) || o.getState().setInitialStateOptions(I, y[I]);
47
- }), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
48
- const b = (I, a) => {
49
- const [v] = Q(a?.componentId ?? yt());
46
+ }, et(p) || o.getState().setInitialStateOptions(p, I[p]);
47
+ }), o.getState().setInitialStates(S), o.getState().setCreatedState(S);
48
+ const b = (p, a) => {
49
+ const [y] = X(a?.componentId ?? yt());
50
50
  At({
51
- stateKey: I,
51
+ stateKey: p,
52
52
  options: a,
53
- initialOptionsPart: y
53
+ initialOptionsPart: I
54
54
  });
55
- const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [W, U] = Bt(
56
- S,
55
+ const n = o.getState().cogsStateStore[p] || S[p], m = a?.modifyState ? a.modifyState(n) : n, [L, R] = Bt(
56
+ m,
57
57
  {
58
- stateKey: I,
58
+ stateKey: p,
59
59
  syncUpdate: a?.syncUpdate,
60
- componentId: v,
60
+ componentId: y,
61
61
  localStorage: a?.localStorage,
62
62
  middleware: a?.middleware,
63
63
  enabledSync: a?.enabledSync,
@@ -68,10 +68,10 @@ const ce = (t, i) => {
68
68
  serverState: a?.serverState
69
69
  }
70
70
  );
71
- return U;
71
+ return R;
72
72
  };
73
- function w(I, a) {
74
- At({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Ht(I, a), gt(I);
73
+ function w(p, a) {
74
+ At({ stateKey: p, options: a, initialOptionsPart: I }), a.localStorage && Ht(p, a), gt(p);
75
75
  }
76
76
  return { useCogsState: b, setCogsOptions: w };
77
77
  }, {
@@ -80,99 +80,99 @@ const ce = (t, i) => {
80
80
  getInitialOptions: et,
81
81
  getKeyState: Nt,
82
82
  getValidationErrors: Dt,
83
- setStateLog: Lt,
83
+ setStateLog: Wt,
84
84
  updateInitialStateGlobal: It,
85
- addValidationError: Wt,
86
- removeValidationError: J,
85
+ addValidationError: Lt,
86
+ removeValidationError: q,
87
87
  setServerSyncActions: Gt
88
- } = o.getState(), $t = (t, i, m, f, y) => {
89
- m?.log && console.log(
88
+ } = o.getState(), $t = (t, c, h, S, I) => {
89
+ h?.log && console.log(
90
90
  "saving to localstorage",
91
- i,
92
- m.localStorage?.key,
93
- f
91
+ c,
92
+ h.localStorage?.key,
93
+ S
94
94
  );
95
- const b = Y(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
96
- if (b && f) {
97
- const w = `${f}-${i}-${b}`;
98
- let I;
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
+ let p;
99
99
  try {
100
- I = ut(w)?.lastSyncedWithServer;
100
+ p = ut(w)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const a = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
- lastSyncedWithServer: y ?? I
107
- }, v = Ot.serialize(a);
106
+ lastSyncedWithServer: I ?? p
107
+ }, y = Rt.serialize(a);
108
108
  window.localStorage.setItem(
109
109
  w,
110
- JSON.stringify(v.json)
110
+ JSON.stringify(y.json)
111
111
  );
112
112
  }
113
113
  }, ut = (t) => {
114
114
  if (!t) return null;
115
115
  try {
116
- const i = window.localStorage.getItem(t);
117
- return i ? JSON.parse(i) : null;
118
- } catch (i) {
119
- return console.error("Error loading from localStorage:", i), null;
116
+ const c = window.localStorage.getItem(t);
117
+ return c ? JSON.parse(c) : null;
118
+ } catch (c) {
119
+ return console.error("Error loading from localStorage:", c), null;
120
120
  }
121
- }, Ht = (t, i) => {
122
- const m = o.getState().cogsStateStore[t], { sessionId: f } = bt(), y = Y(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
123
- if (y && f) {
121
+ }, Ht = (t, c) => {
122
+ const h = o.getState().cogsStateStore[t], { sessionId: S } = bt(), I = J(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
123
+ if (I && S) {
124
124
  const b = ut(
125
- `${f}-${t}-${y}`
125
+ `${S}-${t}-${I}`
126
126
  );
127
127
  if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
128
128
  return K(t, b.state), gt(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Ct = (t, i, m, f, y, b) => {
131
+ }, Vt = (t, c, h, S, I, b) => {
132
132
  const w = {
133
- initialState: i,
133
+ initialState: c,
134
134
  updaterState: dt(
135
135
  t,
136
- f,
137
- y,
136
+ S,
137
+ I,
138
138
  b
139
139
  ),
140
- state: m
140
+ state: h
141
141
  };
142
142
  It(t, w.initialState), lt(t, w.updaterState), K(t, w.state);
143
143
  }, gt = (t) => {
144
- const i = o.getState().stateComponents.get(t);
145
- if (!i) return;
146
- const m = /* @__PURE__ */ new Set();
147
- i.components.forEach((f) => {
148
- (f ? Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"] : null)?.includes("none") || m.add(() => f.forceUpdate());
144
+ const c = o.getState().stateComponents.get(t);
145
+ if (!c) return;
146
+ const h = /* @__PURE__ */ new Set();
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
- m.forEach((f) => f());
150
+ h.forEach((S) => S());
151
151
  });
152
- }, le = (t, i) => {
153
- const m = o.getState().stateComponents.get(t);
154
- if (m) {
155
- const f = `${t}////${i}`, y = m.components.get(f);
156
- if ((y ? Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"] : null)?.includes("none"))
152
+ }, le = (t, c) => {
153
+ const h = o.getState().stateComponents.get(t);
154
+ if (h) {
155
+ const S = `${t}////${c}`, I = h.components.get(S);
156
+ if ((I ? Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"] : null)?.includes("none"))
157
157
  return;
158
- y && y.forceUpdate();
158
+ I && I.forceUpdate();
159
159
  }
160
- }, zt = (t, i, m, f) => {
160
+ }, zt = (t, c, h, S) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: z(i, f),
165
- newValue: z(m, 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(m, f)
171
+ newValue: z(h, S)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: z(i, f),
175
+ oldValue: z(c, S),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -181,234 +181,234 @@ const ce = (t, i) => {
181
181
  }
182
182
  };
183
183
  function Bt(t, {
184
- stateKey: i,
185
- serverSync: m,
186
- localStorage: f,
187
- formElements: y,
184
+ stateKey: c,
185
+ serverSync: h,
186
+ localStorage: S,
187
+ formElements: I,
188
188
  reactiveDeps: b,
189
189
  reactiveType: w,
190
- componentId: I,
190
+ componentId: p,
191
191
  initialState: a,
192
- syncUpdate: v,
192
+ syncUpdate: y,
193
193
  dependencies: n,
194
- serverState: S
194
+ serverState: m
195
195
  } = {}) {
196
- const [W, U] = Q({}), { sessionId: F } = bt();
197
- let G = !i;
198
- const [h] = Q(i ?? yt()), l = o.getState().stateLog[h], st = Z(/* @__PURE__ */ new Set()), X = Z(I ?? yt()), R = Z(
196
+ const [L, R] = X({}), { sessionId: U } = bt();
197
+ let G = !c;
198
+ const [v] = X(c ?? yt()), l = o.getState().stateLog[v], st = Q(/* @__PURE__ */ new Set()), Y = Q(p ?? yt()), j = Q(
199
199
  null
200
200
  );
201
- R.current = et(h) ?? null, ot(() => {
202
- if (v && v.stateKey === h && v.path?.[0]) {
203
- K(h, (r) => ({
201
+ j.current = et(v) ?? null, nt(() => {
202
+ if (y && y.stateKey === v && y.path?.[0]) {
203
+ K(v, (r) => ({
204
204
  ...r,
205
- [v.path[0]]: v.newValue
205
+ [y.path[0]]: y.newValue
206
206
  }));
207
- const e = `${v.stateKey}:${v.path.join(".")}`;
207
+ const e = `${y.stateKey}:${y.path.join(".")}`;
208
208
  o.getState().setSyncInfo(e, {
209
- timeStamp: v.timeStamp,
210
- userId: v.userId
209
+ timeStamp: y.timeStamp,
210
+ userId: y.userId
211
211
  });
212
212
  }
213
- }, [v]), ot(() => {
213
+ }, [y]), nt(() => {
214
214
  if (a) {
215
- Et(h, {
215
+ Et(v, {
216
216
  initialState: a
217
217
  });
218
- const e = R.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[h];
219
- if (!(c && !H(c, a) || !c) && !s)
218
+ const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[v];
219
+ if (!(i && !H(i, a) || !i) && !s)
220
220
  return;
221
- let u = null;
222
- const E = Y(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
- E && F && (u = ut(`${F}-${h}-${E}`));
224
- let p = a, $ = !1;
225
- const _ = s ? Date.now() : 0, x = u?.lastUpdated || 0, M = u?.lastSyncedWithServer || 0;
226
- s && _ > x ? (p = e.serverState.data, $ = !0) : u && x > M && (p = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), o.getState().initializeShadowState(h, a), Ct(
227
- h,
221
+ let g = null;
222
+ const E = J(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
+ E && U && (g = ut(`${U}-${v}-${E}`));
224
+ let T = a, A = !1;
225
+ const x = s ? Date.now() : 0, V = g?.lastUpdated || 0, k = g?.lastSyncedWithServer || 0;
226
+ s && x > 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
+ v,
228
228
  a,
229
- p,
230
- nt,
231
- X.current,
232
- F
233
- ), $ && E && F && $t(p, h, e, F, Date.now()), gt(h), (Array.isArray(w) ? w : [w || "component"]).includes("none") || U({});
229
+ T,
230
+ rt,
231
+ Y.current,
232
+ U
233
+ ), A && E && U && $t(T, v, e, U, Date.now()), gt(v), (Array.isArray(w) ? w : [w || "component"]).includes("none") || R({});
234
234
  }
235
235
  }, [
236
236
  a,
237
- S?.status,
238
- S?.data,
237
+ m?.status,
238
+ m?.data,
239
239
  ...n || []
240
240
  ]), ct(() => {
241
- G && Et(h, {
242
- serverSync: m,
243
- formElements: y,
241
+ G && Et(v, {
242
+ serverSync: h,
243
+ formElements: I,
244
244
  initialState: a,
245
- localStorage: f,
246
- middleware: R.current?.middleware
245
+ localStorage: S,
246
+ middleware: j.current?.middleware
247
247
  });
248
- const e = `${h}////${X.current}`, r = o.getState().stateComponents.get(h) || {
248
+ const e = `${v}////${Y.current}`, r = o.getState().stateComponents.get(v) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
251
  return r.components.set(e, {
252
- forceUpdate: () => U({}),
252
+ forceUpdate: () => R({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
255
  depsFunction: b || void 0,
256
256
  reactiveType: w ?? ["component", "deps"]
257
- }), o.getState().stateComponents.set(h, r), U({}), () => {
258
- r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
257
+ }), o.getState().stateComponents.set(v, r), R({}), () => {
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, c) => {
261
+ const rt = (e, r, s, i) => {
262
262
  if (Array.isArray(r)) {
263
- const u = `${h}-${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(h, (u) => {
268
- const E = Y(e) ? e(u) : e, p = `${h}-${r.join(".")}`;
269
- if (p) {
270
- let P = !1, N = g.signalDomElements.get(p);
266
+ const u = o.getState();
267
+ K(v, (g) => {
268
+ const E = J(e) ? e(g) : e, T = `${v}-${r.join(".")}`;
269
+ if (T) {
270
+ let M = !1, N = u.signalDomElements.get(T);
271
271
  if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
- const O = r.slice(0, -1), L = z(E, O);
273
- if (Array.isArray(L)) {
274
- P = !0;
275
- const A = `${h}-${O.join(".")}`;
276
- N = g.signalDomElements.get(A);
272
+ const O = r.slice(0, -1), W = z(E, O);
273
+ if (Array.isArray(W)) {
274
+ M = !0;
275
+ const f = `${v}-${O.join(".")}`;
276
+ N = u.signalDomElements.get(f);
277
277
  }
278
278
  }
279
279
  if (N) {
280
- const O = P ? z(E, r.slice(0, -1)) : z(E, r);
281
- N.forEach(({ parentId: L, position: A, effect: T }) => {
282
- const k = document.querySelector(
283
- `[data-parent-id="${L}"]`
280
+ const O = M ? z(E, r.slice(0, -1)) : z(E, r);
281
+ N.forEach(({ parentId: W, position: f, effect: $ }) => {
282
+ const C = document.querySelector(
283
+ `[data-parent-id="${W}"]`
284
284
  );
285
- if (k) {
286
- const j = Array.from(k.childNodes);
287
- if (j[A]) {
288
- const C = T ? new Function("state", `return (${T})(state)`)(O) : O;
289
- j[A].textContent = String(C);
285
+ if (C) {
286
+ const _ = Array.from(C.childNodes);
287
+ if (_[f]) {
288
+ const P = $ ? new Function("state", `return (${$})(state)`)(O) : O;
289
+ _[f].textContent = String(P);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (c || R.current?.validation?.key) && r && J(
296
- (c || R.current?.validation?.key) + "." + r.join(".")
295
+ console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && r && q(
296
+ (i || j.current?.validation?.key) + "." + r.join(".")
297
297
  );
298
- const $ = r.slice(0, r.length - 1);
299
- s.updateType === "cut" && R.current?.validation?.key && J(
300
- R.current?.validation?.key + "." + $.join(".")
301
- ), s.updateType === "insert" && R.current?.validation?.key && Dt(
302
- R.current?.validation?.key + "." + $.join(".")
298
+ const A = r.slice(0, r.length - 1);
299
+ s.updateType === "cut" && j.current?.validation?.key && q(
300
+ j.current?.validation?.key + "." + A.join(".")
301
+ ), s.updateType === "insert" && j.current?.validation?.key && Dt(
302
+ j.current?.validation?.key + "." + A.join(".")
303
303
  ).filter(([N, O]) => {
304
- let L = N?.split(".").length;
305
- if (N == $.join(".") && L == $.length - 1) {
306
- let A = N + "." + $;
307
- J(N), Wt(A, 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 _ = g.stateComponents.get(h);
311
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
312
- const P = vt(u, E), N = new Set(P), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
310
+ const x = u.stateComponents.get(v);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
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
- L,
315
- A
316
- ] of _.components.entries()) {
317
- let T = !1;
318
- const k = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
319
- if (console.log("component", A), !k.includes("none")) {
320
- if (k.includes("all")) {
321
- A.forceUpdate();
314
+ W,
315
+ f
316
+ ] of x.components.entries()) {
317
+ let $ = !1;
318
+ const C = Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"];
319
+ if (console.log("component", f), !C.includes("none")) {
320
+ if (C.includes("all")) {
321
+ f.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (k.includes("component") && ((A.paths.has(O) || A.paths.has("")) && (T = !0), !T))
325
- for (const j of N) {
326
- let C = j;
324
+ if (C.includes("component") && ((f.paths.has(O) || f.paths.has("")) && ($ = !0), !$))
325
+ for (const _ of N) {
326
+ let P = _;
327
327
  for (; ; ) {
328
- if (A.paths.has(C)) {
329
- T = !0;
328
+ if (f.paths.has(P)) {
329
+ $ = !0;
330
330
  break;
331
331
  }
332
- const D = C.lastIndexOf(".");
333
- if (D !== -1) {
334
- const q = C.substring(
332
+ const B = P.lastIndexOf(".");
333
+ if (B !== -1) {
334
+ const Z = P.substring(
335
335
  0,
336
- D
336
+ B
337
337
  );
338
338
  if (!isNaN(
339
- Number(C.substring(D + 1))
340
- ) && A.paths.has(q)) {
341
- T = !0;
339
+ Number(P.substring(B + 1))
340
+ ) && f.paths.has(Z)) {
341
+ $ = !0;
342
342
  break;
343
343
  }
344
- C = q;
344
+ P = Z;
345
345
  } else
346
- C = "";
347
- if (C === "")
346
+ P = "";
347
+ if (P === "")
348
348
  break;
349
349
  }
350
- if (T) break;
350
+ if ($) break;
351
351
  }
352
- if (!T && k.includes("deps") && A.depsFunction) {
353
- const j = A.depsFunction(E);
354
- let C = !1;
355
- typeof j == "boolean" ? j && (C = !0) : H(A.deps, j) || (A.deps = j, C = !0), C && (T = !0);
352
+ if (!$ && C.includes("deps") && f.depsFunction) {
353
+ const _ = f.depsFunction(E);
354
+ let P = !1;
355
+ typeof _ == "boolean" ? _ && (P = !0) : H(f.deps, _) || (f.deps = _, P = !0), P && ($ = !0);
356
356
  }
357
- T && A.forceUpdate();
357
+ $ && f.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const x = Date.now();
362
- r = r.map((P, N) => {
363
- const O = r.slice(0, -1), L = z(E, O);
364
- return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (L.length - 1).toString() : P;
361
+ const V = Date.now();
362
+ r = r.map((M, N) => {
363
+ const O = r.slice(0, -1), W = z(E, O);
364
+ return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : M;
365
365
  });
366
- const { oldValue: M, newValue: V } = zt(
366
+ const { oldValue: k, newValue: D } = zt(
367
367
  s.updateType,
368
- u,
368
+ g,
369
369
  E,
370
370
  r
371
- ), B = {
372
- timeStamp: x,
373
- stateKey: h,
371
+ ), F = {
372
+ timeStamp: V,
373
+ stateKey: v,
374
374
  path: r,
375
375
  updateType: s.updateType,
376
376
  status: "new",
377
- oldValue: M,
378
- newValue: V
377
+ oldValue: k,
378
+ newValue: D
379
379
  };
380
380
  switch (s.updateType) {
381
381
  case "update":
382
- g.updateShadowAtPath(h, r, E);
382
+ u.updateShadowAtPath(v, r, E);
383
383
  break;
384
384
  case "insert":
385
- const P = r.slice(0, -1);
386
- g.insertShadowArrayElement(h, P, V);
385
+ const M = r.slice(0, -1);
386
+ u.insertShadowArrayElement(v, M, D);
387
387
  break;
388
388
  case "cut":
389
389
  const N = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- g.removeShadowArrayElement(h, N, O);
390
+ u.removeShadowArrayElement(v, N, O);
391
391
  break;
392
392
  }
393
- if (Lt(h, (P) => {
394
- const O = [...P ?? [], B].reduce((L, A) => {
395
- const T = `${A.stateKey}:${JSON.stringify(A.path)}`, k = L.get(T);
396
- return k ? (k.timeStamp = Math.max(k.timeStamp, A.timeStamp), k.newValue = A.newValue, k.oldValue = k.oldValue ?? A.oldValue, k.updateType = A.updateType) : L.set(T, { ...A }), L;
393
+ if (Wt(v, (M) => {
394
+ const O = [...M ?? [], F].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(
400
400
  E,
401
- h,
402
- R.current,
403
- F
404
- ), R.current?.middleware && R.current.middleware({
401
+ v,
402
+ j.current,
403
+ U
404
+ ), j.current?.middleware && j.current.middleware({
405
405
  updateLog: l,
406
- update: B
407
- }), R.current?.serverSync) {
408
- const P = g.serverState[h], N = R.current?.serverSync;
409
- Gt(h, {
406
+ update: F
407
+ }), j.current?.serverSync) {
408
+ const M = u.serverState[v], N = j.current?.serverSync;
409
+ Gt(v, {
410
410
  syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
411
- rollBackState: P,
411
+ rollBackState: M,
412
412
  actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
@@ -416,60 +416,60 @@ function Bt(t, {
416
416
  return E;
417
417
  });
418
418
  };
419
- o.getState().updaterState[h] || (lt(
420
- h,
419
+ o.getState().updaterState[v] || (lt(
420
+ v,
421
421
  dt(
422
- h,
423
- nt,
424
- X.current,
425
- F
422
+ v,
423
+ rt,
424
+ Y.current,
425
+ U
426
426
  )
427
- ), o.getState().cogsStateStore[h] || K(h, t), o.getState().initialStateGlobal[h] || It(h, t));
427
+ ), o.getState().cogsStateStore[v] || K(v, t), o.getState().initialStateGlobal[v] || It(v, t));
428
428
  const d = ht(() => dt(
429
- h,
430
- nt,
431
- X.current,
432
- F
433
- ), [h, F]);
434
- return [Nt(h), d];
429
+ v,
430
+ rt,
431
+ Y.current,
432
+ U
433
+ ), [v, U]);
434
+ return [Nt(v), d];
435
435
  }
436
- function dt(t, i, m, f) {
437
- const y = /* @__PURE__ */ new Map();
436
+ function dt(t, c, h, S) {
437
+ const I = /* @__PURE__ */ new Map();
438
438
  let b = 0;
439
- const w = (v) => {
440
- const n = v.join(".");
441
- for (const [S] of y)
442
- (S === n || S.startsWith(n + ".")) && y.delete(S);
439
+ const w = (y) => {
440
+ const n = y.join(".");
441
+ for (const [m] of I)
442
+ (m === n || m.startsWith(n + ".")) && I.delete(m);
443
443
  b++;
444
- }, I = {
445
- removeValidation: (v) => {
446
- v?.validationKey && J(v.validationKey);
444
+ }, p = {
445
+ removeValidation: (y) => {
446
+ y?.validationKey && q(y.validationKey);
447
447
  },
448
- revertToInitialState: (v) => {
448
+ revertToInitialState: (y) => {
449
449
  const n = o.getState().getInitialOptions(t)?.validation;
450
- n?.key && J(n?.key), v?.validationKey && J(v.validationKey);
451
- const S = o.getState().initialStateGlobal[t];
452
- o.getState().clearSelectedIndexesForState(t), y.clear(), b++;
453
- const W = a(S, []), U = et(t), F = Y(U?.localStorage?.key) ? U?.localStorage?.key(S) : U?.localStorage?.key, G = `${f}-${t}-${F}`;
454
- G && localStorage.removeItem(G), lt(t, W), K(t, S);
455
- const h = o.getState().stateComponents.get(t);
456
- return h && h.components.forEach((l) => {
450
+ n?.key && q(n?.key), y?.validationKey && q(y.validationKey);
451
+ const m = o.getState().initialStateGlobal[t];
452
+ o.getState().clearSelectedIndexesForState(t), I.clear(), b++;
453
+ const L = a(m, []), R = et(t), U = J(R?.localStorage?.key) ? R?.localStorage?.key(m) : R?.localStorage?.key, G = `${S}-${t}-${U}`;
454
+ G && localStorage.removeItem(G), lt(t, L), K(t, m);
455
+ const v = o.getState().stateComponents.get(t);
456
+ return v && v.components.forEach((l) => {
457
457
  l.forceUpdate();
458
- }), S;
458
+ }), m;
459
459
  },
460
- updateInitialState: (v) => {
461
- y.clear(), b++;
460
+ updateInitialState: (y) => {
461
+ I.clear(), b++;
462
462
  const n = dt(
463
463
  t,
464
- i,
465
- m,
466
- f
467
- ), S = o.getState().initialStateGlobal[t], W = et(t), U = Y(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, F = `${f}-${t}-${U}`;
468
- return localStorage.getItem(F) && localStorage.removeItem(F), Pt(() => {
469
- It(t, v), o.getState().initializeShadowState(t, v), lt(t, n), K(t, v);
464
+ c,
465
+ h,
466
+ S
467
+ ), m = o.getState().initialStateGlobal[t], L = et(t), R = J(L?.localStorage?.key) ? L?.localStorage?.key(m) : L?.localStorage?.key, U = `${S}-${t}-${R}`;
468
+ return localStorage.getItem(U) && localStorage.removeItem(U), Pt(() => {
469
+ It(t, y), o.getState().initializeShadowState(t, y), lt(t, n), K(t, y);
470
470
  const G = o.getState().stateComponents.get(t);
471
- G && G.components.forEach((h) => {
472
- h.forceUpdate();
471
+ G && G.components.forEach((v) => {
472
+ v.forceUpdate();
473
473
  });
474
474
  }), {
475
475
  fetchId: (G) => n.get()[G]
@@ -479,27 +479,27 @@ function dt(t, i, m, f) {
479
479
  _serverState: o.getState().serverState[t],
480
480
  _isLoading: o.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
- const v = o.getState().serverState[t];
483
- return !!(v && H(v, Nt(t)));
482
+ const y = o.getState().serverState[t];
483
+ return !!(y && H(y, Nt(t)));
484
484
  }
485
485
  };
486
- function a(v, n = [], S) {
487
- const W = n.map(String).join(".");
488
- y.get(W);
489
- const U = function() {
486
+ function a(y, n = [], m) {
487
+ const L = n.map(String).join(".");
488
+ I.get(L);
489
+ const R = function() {
490
490
  return o().getNestedState(t, n);
491
491
  };
492
- Object.keys(I).forEach((h) => {
493
- U[h] = I[h];
492
+ Object.keys(p).forEach((v) => {
493
+ R[v] = p[v];
494
494
  });
495
- const F = {
496
- apply(h, l, st) {
495
+ const U = {
496
+ apply(v, l, st) {
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
- get(h, l) {
502
- S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
501
+ get(v, l) {
502
+ m?.validIndices && !Array.isArray(y) && (m = { ...m, validIndices: void 0 });
503
503
  const st = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
@@ -524,18 +524,18 @@ function dt(t, i, m, f) {
524
524
  "getComponents"
525
525
  ]);
526
526
  if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !st.has(l)) {
527
- const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
527
+ const d = `${t}////${h}`, 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
- let c = !0;
533
- for (const g of r.paths)
534
- if (s.startsWith(g) && (s === g || s[g.length] === ".")) {
535
- c = !1;
532
+ let i = !0;
533
+ for (const u of r.paths)
534
+ if (s.startsWith(u) && (s === u || s[u.length] === ".")) {
535
+ i = !1;
536
536
  break;
537
537
  }
538
- c && r.paths.add(s);
538
+ i && r.paths.add(s);
539
539
  }
540
540
  }
541
541
  }
@@ -551,20 +551,20 @@ function dt(t, i, m, f) {
551
551
  return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
552
552
  const r = o.getState().getNestedState(t, []), s = d?.validation?.key;
553
553
  try {
554
- const c = await e.action(r);
555
- if (c && !c.success && c.errors && s) {
556
- o.getState().removeValidationError(s), c.errors.forEach((u) => {
557
- const E = [s, ...u.path].join(".");
558
- o.getState().addValidationError(E, u.message);
554
+ const i = await e.action(r);
555
+ if (i && !i.success && i.errors && s) {
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
- return c?.success && e.onSuccess ? e.onSuccess(c.data) : !c?.success && e.onError && e.onError(c.error), c;
566
- } catch (c) {
567
- return e.onError && e.onError(c), { success: !1, error: c };
565
+ return i?.success && e.onSuccess ? e.onSuccess(i.data) : !i?.success && e.onError && e.onError(i.error), i;
566
+ } catch (i) {
567
+ return e.onError && e.onError(i), { success: !1, error: i };
568
568
  }
569
569
  };
570
570
  if (l === "_status") {
@@ -581,7 +581,7 @@ function dt(t, i, m, f) {
581
581
  };
582
582
  if (l === "removeStorage")
583
583
  return () => {
584
- const d = o.getState().initialStateGlobal[t], e = et(t), r = Y(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")
@@ -591,10 +591,10 @@ function dt(t, i, m, f) {
591
591
  throw new Error("Validation key not found");
592
592
  return o.getState().getValidationErrors(d.key + "." + n.join("."));
593
593
  };
594
- if (Array.isArray(v)) {
595
- const d = () => S?.validIndices ? v.map((r, s) => ({
594
+ if (Array.isArray(y)) {
595
+ const d = () => m?.validIndices ? y.map((r, s) => ({
596
596
  item: r,
597
- originalIndex: S.validIndices[s]
597
+ originalIndex: m.validIndices[s]
598
598
  })) : o.getState().getNestedState(t, n).map((r, s) => ({
599
599
  item: r,
600
600
  originalIndex: s
@@ -604,9 +604,9 @@ function dt(t, i, m, f) {
604
604
  const e = o.getState().getSelectedIndex(t, n.join("."));
605
605
  if (e !== void 0)
606
606
  return a(
607
- v[e],
607
+ y[e],
608
608
  [...n, e.toString()],
609
- S
609
+ m
610
610
  );
611
611
  };
612
612
  if (l === "clearSelected")
@@ -620,167 +620,171 @@ function dt(t, i, m, f) {
620
620
  const {
621
621
  itemHeight: r = 50,
622
622
  overscan: s = 5,
623
- stickToBottom: c = !1
624
- } = e, g = Z(null), [u, E] = Q({
623
+ stickToBottom: i = !1
624
+ } = e, u = Q(null), [g, E] = X({
625
625
  startIndex: 0,
626
626
  endIndex: 10
627
- }), p = Z(!1), [$, _] = Q(0), x = Z(0);
628
- ot(() => o.getState().subscribeToShadowState(t, () => {
629
- _((k) => k + 1);
627
+ }), T = Q(i), [A, x] = X(0);
628
+ nt(() => o.getState().subscribeToShadowState(t, () => {
629
+ x(($) => $ + 1);
630
630
  }), [t]);
631
- const M = o().getNestedState(
631
+ const V = o().getNestedState(
632
632
  t,
633
633
  n
634
- ), V = M.length, { totalHeight: B, positions: P } = ht(() => {
635
- const T = o.getState().getShadowMetadata(t, n) || [];
636
- let k = 0;
637
- const j = [];
638
- for (let C = 0; C < V; C++) {
639
- j[C] = k;
640
- const D = T[C]?.virtualizer?.itemHeight;
641
- k += D || r;
634
+ ), k = V.length, { totalHeight: D, positions: F } = ht(() => {
635
+ const f = o.getState().getShadowMetadata(t, n) || [];
636
+ let $ = 0;
637
+ const C = [];
638
+ for (let _ = 0; _ < k; _++) {
639
+ C[_] = $;
640
+ const P = f[_]?.virtualizer?.itemHeight;
641
+ $ += P || r;
642
642
  }
643
- return { totalHeight: k, positions: j };
643
+ return { totalHeight: $, positions: C };
644
644
  }, [
645
- V,
645
+ k,
646
646
  t,
647
647
  n.join("."),
648
648
  r,
649
- $
650
- ]), N = ht(() => {
651
- const T = Math.max(0, u.startIndex), k = Math.min(V, u.endIndex), j = Array.from(
652
- { length: k - T },
653
- (D, q) => T + q
654
- ), C = j.map((D) => M[D]);
655
- return a(C, n, {
656
- ...S,
657
- validIndices: j
649
+ A
650
+ ]), M = ht(() => {
651
+ const f = Math.max(0, g.startIndex), $ = Math.min(k, g.endIndex), C = Array.from(
652
+ { length: $ - f },
653
+ (P, B) => f + B
654
+ ), _ = C.map((P) => V[P]);
655
+ return a(_, n, {
656
+ ...m,
657
+ validIndices: C
658
658
  });
659
- }, [u.startIndex, u.endIndex, M, V]);
660
- ct(() => {
661
- const T = g.current;
662
- if (!T) return;
663
- const k = () => {
664
- if (!T) return;
665
- const { scrollTop: C } = T;
666
- let D = 0, q = V - 1;
667
- for (; D <= q; ) {
668
- const ft = Math.floor((D + q) / 2);
669
- P[ft] < C ? D = ft + 1 : q = ft - 1;
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
+ const $ = () => {
679
+ if (!f) return;
680
+ const { scrollTop: _, clientHeight: P } = f;
681
+ let B = 0, Z = k - 1;
682
+ for (; B <= Z; ) {
683
+ const ft = Math.floor((B + Z) / 2);
684
+ F[ft] < _ ? B = ft + 1 : Z = ft - 1;
670
685
  }
671
- const pt = Math.max(0, q - s);
686
+ const pt = Math.max(0, Z - s);
672
687
  let tt = pt;
673
- const Vt = C + T.clientHeight;
674
- for (; tt < V && P[tt] < Vt; )
688
+ const Ct = _ + P;
689
+ for (; tt < k && F[tt] < Ct; )
675
690
  tt++;
676
- tt = Math.min(V, tt + s), E({ startIndex: pt, endIndex: tt });
677
- }, j = () => {
678
- p.current = T.scrollHeight - T.scrollTop - T.clientHeight < 1, k();
691
+ tt = Math.min(k, tt + s), E({ startIndex: pt, endIndex: tt });
692
+ }, C = () => {
693
+ T.current = f.scrollHeight - f.scrollTop - f.clientHeight < 1, $();
679
694
  };
680
- if (T.addEventListener("scroll", j, {
695
+ return f.addEventListener("scroll", C, {
681
696
  passive: !0
682
- }), console.log("totalCount", V), c && V > 0) {
683
- const C = x.current === 0 && V > 0, D = V > x.current;
684
- console.log("isInitialLoad", C), console.log("hasNewItems", D), C ? setTimeout(() => {
685
- T.scrollTop = T.scrollHeight, p.current = !0;
686
- }, 1e3) : D && p.current && setTimeout(() => {
687
- T.scrollTo({
688
- top: T.scrollHeight,
689
- behavior: "smooth"
690
- });
691
- }, 100);
692
- }
693
- return k(), x.current = V, () => {
694
- T.removeEventListener("scroll", j);
697
+ }), i && T.current && (f.scrollTop = f.scrollHeight), $(), () => {
698
+ f.removeEventListener("scroll", C);
695
699
  };
696
- }, [V, P, c]);
697
- const O = wt(
698
- (T = "smooth") => {
699
- g.current && (p.current = !0, g.current.scrollTo({
700
- top: g.current.scrollHeight,
701
- behavior: T
700
+ }, [k, F, D, i]);
701
+ const N = wt(
702
+ (f = "smooth") => {
703
+ u.current && (T.current = !0, u.current.scrollTo({
704
+ top: u.current.scrollHeight,
705
+ behavior: f
702
706
  }));
703
707
  },
704
708
  []
705
- ), L = wt(
706
- (T, k = "smooth") => {
707
- g.current && P[T] !== void 0 && (p.current = !1, g.current.scrollTo({
708
- top: P[T],
709
- behavior: k
709
+ ), O = wt(
710
+ (f, $ = "smooth") => {
711
+ u.current && F[f] !== void 0 && (T.current = !1, u.current.scrollTo({
712
+ top: F[f],
713
+ behavior: $
710
714
  }));
711
715
  },
712
- [P]
713
- ), A = {
716
+ [F]
717
+ ), W = {
714
718
  outer: {
715
- ref: g,
719
+ ref: u,
716
720
  style: { overflowY: "auto", height: "100%" }
717
721
  },
718
722
  inner: {
719
723
  style: {
720
- height: `${B}px`,
724
+ height: `${D}px`,
721
725
  position: "relative"
722
726
  }
723
727
  },
724
728
  list: {
725
729
  style: {
726
- transform: `translateY(${P[u.startIndex] || 0}px)`
730
+ transform: `translateY(${F[g.startIndex] || 0}px)`
727
731
  }
728
732
  }
729
733
  };
730
734
  return {
731
- virtualState: N,
732
- virtualizerProps: A,
733
- scrollToBottom: O,
734
- scrollToIndex: L
735
+ virtualState: M,
736
+ virtualizerProps: W,
737
+ scrollToBottom: N,
738
+ scrollToIndex: O
735
739
  };
736
740
  };
737
741
  if (l === "stateSort")
738
742
  return (e) => {
739
743
  const s = [...d()].sort(
740
- (u, E) => e(u.item, E.item)
741
- ), c = s.map(({ item: u }) => u), g = {
742
- ...S,
744
+ (g, E) => e(g.item, E.item)
745
+ ), i = s.map(({ item: g }) => g), u = {
746
+ ...m,
743
747
  validIndices: s.map(
744
- ({ originalIndex: u }) => u
748
+ ({ originalIndex: g }) => g
745
749
  )
746
750
  };
747
- return a(c, n, g);
751
+ return a(i, n, u);
748
752
  };
749
753
  if (l === "stateFilter")
750
754
  return (e) => {
751
755
  const s = d().filter(
752
- ({ item: u }, E) => e(u, E)
753
- ), c = s.map(({ item: u }) => u), g = {
754
- ...S,
756
+ ({ item: g }, E) => e(g, E)
757
+ ), i = s.map(({ item: g }) => g), u = {
758
+ ...m,
755
759
  validIndices: s.map(
756
- ({ originalIndex: u }) => u
760
+ ({ originalIndex: g }) => g
757
761
  )
758
762
  };
759
- return a(c, n, g);
763
+ return a(i, n, u);
760
764
  };
761
765
  if (l === "stateMap")
762
766
  return (e) => {
763
767
  const r = o.getState().getNestedState(t, n);
764
- return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (c, g) => g)).map((c, g) => {
765
- const u = r[c], E = [...n, c.toString()], p = a(u, E, S);
766
- return e(u, p, {
768
+ return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
769
+ const g = r[i], E = [...n, i.toString()], T = a(g, E, m);
770
+ return e(g, T, {
767
771
  register: () => {
768
- const [, _] = Q({}), x = `${m}-${n.join(".")}-${c}`;
772
+ const [, x] = X({}), V = `${h}-${n.join(".")}-${i}`;
769
773
  ct(() => {
770
- const M = `${t}////${x}`, V = o.getState().stateComponents.get(t) || {
774
+ const k = `${t}////${V}`, D = o.getState().stateComponents.get(t) || {
771
775
  components: /* @__PURE__ */ new Map()
772
776
  };
773
- return V.components.set(M, {
774
- forceUpdate: () => _({}),
777
+ return D.components.set(k, {
778
+ forceUpdate: () => x({}),
775
779
  paths: /* @__PURE__ */ new Set([E.join(".")])
776
- }), o.getState().stateComponents.set(t, V), () => {
777
- const B = o.getState().stateComponents.get(t);
778
- B && B.components.delete(M);
780
+ }), o.getState().stateComponents.set(t, D), () => {
781
+ const F = o.getState().stateComponents.get(t);
782
+ F && F.components.delete(k);
779
783
  };
780
- }, [t, x]);
784
+ }, [t, V]);
781
785
  },
782
- index: g,
783
- originalIndex: c
786
+ index: u,
787
+ originalIndex: i
784
788
  });
785
789
  }) : (console.warn(
786
790
  `stateMap called on a non-array value at path: ${n.join(".")}. The current value is:`,
@@ -788,16 +792,16 @@ function dt(t, i, m, f) {
788
792
  ), null);
789
793
  };
790
794
  if (l === "stateMapNoRender")
791
- return (e) => v.map((s, c) => {
792
- let g;
793
- S?.validIndices && S.validIndices[c] !== void 0 ? g = S.validIndices[c] : g = c;
794
- const u = [...n, g.toString()], E = a(s, u, S);
795
+ return (e) => y.map((s, i) => {
796
+ let u;
797
+ m?.validIndices && m.validIndices[i] !== void 0 ? u = m.validIndices[i] : u = i;
798
+ const g = [...n, u.toString()], E = a(s, g, m);
795
799
  return e(
796
800
  s,
797
801
  E,
798
- c,
799
- v,
800
- a(v, n, S)
802
+ i,
803
+ y,
804
+ a(y, n, m)
801
805
  );
802
806
  });
803
807
  if (l === "$stateMap")
@@ -813,19 +817,19 @@ function dt(t, i, m, f) {
813
817
  if (l === "stateList")
814
818
  return (e) => {
815
819
  const r = o.getState().getNestedState(t, n);
816
- return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (c, g) => g)).map((c, g) => {
817
- const u = r[c], E = [...n, c.toString()], p = a(u, E, S), $ = `${m}-${n.join(".")}-${c}`;
820
+ return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
821
+ const g = r[i], E = [...n, i.toString()], T = a(g, E, m), A = `${h}-${n.join(".")}-${i}`;
818
822
  return at(Yt, {
819
- key: c,
823
+ key: i,
820
824
  stateKey: t,
821
- itemComponentId: $,
825
+ itemComponentId: A,
822
826
  itemPath: E,
823
827
  children: e(
824
- u,
825
- p,
826
828
  g,
829
+ T,
830
+ u,
827
831
  r,
828
- a(r, n, S)
832
+ a(r, n, m)
829
833
  )
830
834
  });
831
835
  }) : (console.warn(
@@ -834,109 +838,109 @@ function dt(t, i, m, f) {
834
838
  };
835
839
  if (l === "stateFlattenOn")
836
840
  return (e) => {
837
- const r = v;
838
- y.clear(), b++;
841
+ const r = y;
842
+ I.clear(), b++;
839
843
  const s = r.flatMap(
840
- (c) => c[e] ?? []
844
+ (i) => i[e] ?? []
841
845
  );
842
846
  return a(
843
847
  s,
844
848
  [...n, "[*]", e],
845
- S
849
+ m
846
850
  );
847
851
  };
848
852
  if (l === "index")
849
853
  return (e) => {
850
- const r = v[e];
854
+ const r = y[e];
851
855
  return a(r, [...n, e.toString()]);
852
856
  };
853
857
  if (l === "last")
854
858
  return () => {
855
859
  const e = o.getState().getNestedState(t, n);
856
860
  if (e.length === 0) return;
857
- const r = e.length - 1, s = e[r], c = [...n, r.toString()];
858
- return a(s, c);
861
+ const r = e.length - 1, s = e[r], i = [...n, r.toString()];
862
+ return a(s, i);
859
863
  };
860
864
  if (l === "insert")
861
- return (e) => (w(n), St(i, e, n, t), a(
865
+ return (e) => (w(n), St(c, e, n, t), a(
862
866
  o.getState().getNestedState(t, n),
863
867
  n
864
868
  ));
865
869
  if (l === "uniqueInsert")
866
870
  return (e, r, s) => {
867
- const c = o.getState().getNestedState(t, n), g = Y(e) ? e(c) : e;
868
- let u = null;
869
- if (!c.some((p) => {
871
+ const i = o.getState().getNestedState(t, n), u = J(e) ? e(i) : e;
872
+ let g = null;
873
+ if (!i.some((T) => {
870
874
  if (r) {
871
- const _ = r.every(
872
- (x) => H(p[x], g[x])
875
+ const x = r.every(
876
+ (V) => H(T[V], u[V])
873
877
  );
874
- return _ && (u = p), _;
878
+ return x && (g = T), x;
875
879
  }
876
- const $ = H(p, g);
877
- return $ && (u = p), $;
880
+ const A = H(T, u);
881
+ return A && (g = T), A;
878
882
  }))
879
- w(n), St(i, g, n, t);
880
- else if (s && u) {
881
- const p = s(u), $ = c.map(
882
- (_) => H(_, u) ? p : _
883
+ w(n), St(c, u, n, t);
884
+ else if (s && g) {
885
+ const T = s(g), A = i.map(
886
+ (x) => H(x, g) ? T : x
883
887
  );
884
- w(n), rt(i, $, n);
888
+ w(n), ot(c, A, n);
885
889
  }
886
890
  };
887
891
  if (l === "cut")
888
892
  return (e, r) => {
889
893
  if (!r?.waitForSync)
890
- return w(n), it(i, n, t, e), a(
894
+ return w(n), it(c, n, t, e), a(
891
895
  o.getState().getNestedState(t, n),
892
896
  n
893
897
  );
894
898
  };
895
899
  if (l === "cutByValue")
896
900
  return (e) => {
897
- for (let r = 0; r < v.length; r++)
898
- v[r] === e && it(i, n, t, r);
901
+ for (let r = 0; r < y.length; r++)
902
+ y[r] === e && it(c, n, t, r);
899
903
  };
900
904
  if (l === "toggleByValue")
901
905
  return (e) => {
902
- const r = v.findIndex((s) => s === e);
903
- r > -1 ? it(i, n, t, r) : St(i, e, n, t);
906
+ const r = y.findIndex((s) => s === e);
907
+ r > -1 ? it(c, n, t, r) : St(c, e, n, t);
904
908
  };
905
909
  if (l === "stateFind")
906
910
  return (e) => {
907
911
  const s = d().find(
908
- ({ item: g }, u) => e(g, u)
912
+ ({ item: u }, g) => e(u, g)
909
913
  );
910
914
  if (!s) return;
911
- const c = [...n, s.originalIndex.toString()];
912
- return a(s.item, c, S);
915
+ const i = [...n, s.originalIndex.toString()];
916
+ return a(s.item, i, m);
913
917
  };
914
918
  if (l === "findWith")
915
919
  return (e, r) => {
916
- const c = d().find(
917
- ({ item: u }) => u[e] === r
920
+ const i = d().find(
921
+ ({ item: g }) => g[e] === r
918
922
  );
919
- if (!c) return;
920
- const g = [...n, c.originalIndex.toString()];
921
- return a(c.item, g, S);
923
+ if (!i) return;
924
+ const u = [...n, i.originalIndex.toString()];
925
+ return a(i.item, u, m);
922
926
  };
923
927
  }
924
- const X = n[n.length - 1];
925
- if (!isNaN(Number(X))) {
928
+ const Y = n[n.length - 1];
929
+ if (!isNaN(Number(Y))) {
926
930
  const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
927
931
  if (Array.isArray(e) && l === "cut")
928
932
  return () => it(
929
- i,
933
+ c,
930
934
  d,
931
935
  t,
932
- Number(X)
936
+ Number(Y)
933
937
  );
934
938
  }
935
939
  if (l === "get")
936
940
  return () => {
937
- if (S?.validIndices && Array.isArray(v)) {
941
+ if (m?.validIndices && Array.isArray(y)) {
938
942
  const d = o.getState().getNestedState(t, n);
939
- return S.validIndices.map((e) => d[e]);
943
+ return m.validIndices.map((e) => d[e]);
940
944
  }
941
945
  return o.getState().getNestedState(t, n);
942
946
  };
@@ -956,7 +960,7 @@ function dt(t, i, m, f) {
956
960
  return o.getState().getSyncInfo(d);
957
961
  }
958
962
  if (l == "getLocalStorage")
959
- return (d) => ut(f + "-" + t + "-" + d);
963
+ return (d) => ut(S + "-" + t + "-" + d);
960
964
  if (l === "_selected") {
961
965
  const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
962
966
  return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
@@ -965,8 +969,8 @@ function dt(t, i, m, f) {
965
969
  return (d) => {
966
970
  const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
967
971
  d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
968
- const c = o.getState().getNestedState(t, [...e]);
969
- rt(i, c, e), w(e);
972
+ const i = o.getState().getNestedState(t, [...e]);
973
+ ot(c, i, e), w(e);
970
974
  };
971
975
  if (l === "toggleSelected")
972
976
  return () => {
@@ -976,74 +980,74 @@ function dt(t, i, m, f) {
976
980
  r,
977
981
  s === e ? void 0 : e
978
982
  );
979
- const c = o.getState().getNestedState(t, [...d]);
980
- rt(i, c, d), w(d);
983
+ const i = o.getState().getNestedState(t, [...d]);
984
+ ot(c, i, d), w(d);
981
985
  };
982
986
  if (n.length == 0) {
983
987
  if (l === "applyJsonPatch")
984
988
  return (d) => {
985
989
  const e = o.getState().cogsStateStore[t], s = Ut(e, d).newDocument;
986
- Ct(
990
+ Vt(
987
991
  t,
988
992
  o.getState().initialStateGlobal[t],
989
993
  s,
990
- i,
991
- m,
992
- f
994
+ c,
995
+ h,
996
+ S
993
997
  );
994
- const c = o.getState().stateComponents.get(t);
995
- if (c) {
996
- const g = vt(e, s), u = new Set(g);
998
+ const i = o.getState().stateComponents.get(t);
999
+ if (i) {
1000
+ const u = vt(e, s), g = new Set(u);
997
1001
  for (const [
998
1002
  E,
999
- p
1000
- ] of c.components.entries()) {
1001
- let $ = !1;
1002
- const _ = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
1003
- if (!_.includes("none")) {
1004
- if (_.includes("all")) {
1005
- p.forceUpdate();
1003
+ T
1004
+ ] of i.components.entries()) {
1005
+ let A = !1;
1006
+ const x = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
1007
+ if (!x.includes("none")) {
1008
+ if (x.includes("all")) {
1009
+ T.forceUpdate();
1006
1010
  continue;
1007
1011
  }
1008
- if (_.includes("component") && (p.paths.has("") && ($ = !0), !$))
1009
- for (const x of u) {
1010
- if (p.paths.has(x)) {
1011
- $ = !0;
1012
+ if (x.includes("component") && (T.paths.has("") && (A = !0), !A))
1013
+ for (const V of g) {
1014
+ if (T.paths.has(V)) {
1015
+ A = !0;
1012
1016
  break;
1013
1017
  }
1014
- let M = x.lastIndexOf(".");
1015
- for (; M !== -1; ) {
1016
- const V = x.substring(0, M);
1017
- if (p.paths.has(V)) {
1018
- $ = !0;
1018
+ let k = V.lastIndexOf(".");
1019
+ for (; k !== -1; ) {
1020
+ const D = V.substring(0, k);
1021
+ if (T.paths.has(D)) {
1022
+ A = !0;
1019
1023
  break;
1020
1024
  }
1021
- const B = x.substring(
1022
- M + 1
1025
+ const F = V.substring(
1026
+ k + 1
1023
1027
  );
1024
- if (!isNaN(Number(B))) {
1025
- const P = V.lastIndexOf(".");
1026
- if (P !== -1) {
1027
- const N = V.substring(
1028
+ if (!isNaN(Number(F))) {
1029
+ const M = D.lastIndexOf(".");
1030
+ if (M !== -1) {
1031
+ const N = D.substring(
1028
1032
  0,
1029
- P
1033
+ M
1030
1034
  );
1031
- if (p.paths.has(N)) {
1032
- $ = !0;
1035
+ if (T.paths.has(N)) {
1036
+ A = !0;
1033
1037
  break;
1034
1038
  }
1035
1039
  }
1036
1040
  }
1037
- M = V.lastIndexOf(".");
1041
+ k = D.lastIndexOf(".");
1038
1042
  }
1039
- if ($) break;
1043
+ if (A) break;
1040
1044
  }
1041
- if (!$ && _.includes("deps") && p.depsFunction) {
1042
- const x = p.depsFunction(s);
1043
- let M = !1;
1044
- typeof x == "boolean" ? x && (M = !0) : H(p.deps, x) || (p.deps = x, M = !0), M && ($ = !0);
1045
+ if (!A && x.includes("deps") && T.depsFunction) {
1046
+ const V = T.depsFunction(s);
1047
+ let k = !1;
1048
+ typeof V == "boolean" ? V && (k = !0) : H(T.deps, V) || (T.deps = V, k = !0), k && (A = !0);
1045
1049
  }
1046
- $ && p.forceUpdate();
1050
+ A && T.forceUpdate();
1047
1051
  }
1048
1052
  }
1049
1053
  }
@@ -1055,23 +1059,23 @@ function dt(t, i, m, f) {
1055
1059
  throw new Error("Zod schema not found");
1056
1060
  if (!d?.key)
1057
1061
  throw new Error("Validation key not found");
1058
- J(d.key);
1062
+ q(d.key);
1059
1063
  const r = o.getState().cogsStateStore[t];
1060
1064
  try {
1061
1065
  const s = o.getState().getValidationErrors(d.key);
1062
- s && s.length > 0 && s.forEach(([g]) => {
1063
- g && g.startsWith(d.key) && J(g);
1066
+ s && s.length > 0 && s.forEach(([u]) => {
1067
+ u && u.startsWith(d.key) && q(u);
1064
1068
  });
1065
- const c = d.zodSchema.safeParse(r);
1066
- return c.success ? !0 : (c.error.errors.forEach((u) => {
1067
- const E = u.path, p = u.message, $ = [d.key, ...E].join(".");
1068
- e($, p);
1069
+ const i = d.zodSchema.safeParse(r);
1070
+ return i.success ? !0 : (i.error.errors.forEach((g) => {
1071
+ const E = g.path, T = g.message, A = [d.key, ...E].join(".");
1072
+ e(A, T);
1069
1073
  }), gt(t), !1);
1070
1074
  } catch (s) {
1071
1075
  return console.error("Zod schema validation failed", s), !1;
1072
1076
  }
1073
1077
  };
1074
- if (l === "_componentId") return m;
1078
+ if (l === "_componentId") return h;
1075
1079
  if (l === "getComponents")
1076
1080
  return () => o().stateComponents.get(t);
1077
1081
  if (l === "getAllFormRefs")
@@ -1083,9 +1087,9 @@ function dt(t, i, m, f) {
1083
1087
  if (l === "_isLoading")
1084
1088
  return o.getState().isLoadingGlobal[t];
1085
1089
  if (l === "revertToInitialState")
1086
- return I.revertToInitialState;
1087
- if (l === "updateInitialState") return I.updateInitialState;
1088
- if (l === "removeValidation") return I.removeValidation;
1090
+ return p.revertToInitialState;
1091
+ if (l === "updateInitialState") return p.updateInitialState;
1092
+ if (l === "removeValidation") return p.removeValidation;
1089
1093
  }
1090
1094
  if (l === "getFormRef")
1091
1095
  return () => Tt.getState().getFormRef(t + "." + n.join("."));
@@ -1100,23 +1104,23 @@ function dt(t, i, m, f) {
1100
1104
  path: n,
1101
1105
  validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
1102
1106
  stateKey: t,
1103
- validIndices: S?.validIndices,
1107
+ validIndices: m?.validIndices,
1104
1108
  children: d
1105
1109
  }
1106
1110
  );
1107
1111
  if (l === "_stateKey") return t;
1108
1112
  if (l === "_path") return n;
1109
- if (l === "_isServerSynced") return I._isServerSynced;
1113
+ if (l === "_isServerSynced") return p._isServerSynced;
1110
1114
  if (l === "update")
1111
1115
  return (d, e) => {
1112
1116
  if (e?.debounce)
1113
1117
  Mt(() => {
1114
- rt(i, d, n, "");
1118
+ ot(c, d, n, "");
1115
1119
  const r = o.getState().getNestedState(t, n);
1116
1120
  e?.afterUpdate && e.afterUpdate(r);
1117
1121
  }, e.debounce);
1118
1122
  else {
1119
- rt(i, d, n, "");
1123
+ ot(c, d, n, "");
1120
1124
  const r = o.getState().getNestedState(t, n);
1121
1125
  e?.afterUpdate && e.afterUpdate(r);
1122
1126
  }
@@ -1124,20 +1128,20 @@ function dt(t, i, m, f) {
1124
1128
  };
1125
1129
  if (l === "formElement")
1126
1130
  return (d, e) => /* @__PURE__ */ mt(
1127
- Rt,
1131
+ Ot,
1128
1132
  {
1129
- setState: i,
1133
+ setState: c,
1130
1134
  stateKey: t,
1131
1135
  path: n,
1132
1136
  child: d,
1133
1137
  formOpts: e
1134
1138
  }
1135
1139
  );
1136
- const R = [...n, l], nt = o.getState().getNestedState(t, R);
1137
- return a(nt, R, S);
1140
+ const j = [...n, l], rt = o.getState().getNestedState(t, j);
1141
+ return a(rt, j, m);
1138
1142
  }
1139
- }, G = new Proxy(U, F);
1140
- return y.set(W, {
1143
+ }, G = new Proxy(R, U);
1144
+ return I.set(L, {
1141
1145
  proxy: G,
1142
1146
  stateVersion: b
1143
1147
  }), G;
@@ -1151,95 +1155,95 @@ function kt(t) {
1151
1155
  }
1152
1156
  function qt({
1153
1157
  proxy: t,
1154
- rebuildStateShape: i
1158
+ rebuildStateShape: c
1155
1159
  }) {
1156
- const m = o().getNestedState(t._stateKey, t._path);
1157
- return Array.isArray(m) ? i(
1158
- m,
1160
+ const h = o().getNestedState(t._stateKey, t._path);
1161
+ return Array.isArray(h) ? c(
1162
+ h,
1159
1163
  t._path
1160
1164
  ).stateMapNoRender(
1161
- (y, b, w, I, a) => t._mapFn(y, b, w, I, a)
1165
+ (I, b, w, p, a) => t._mapFn(I, b, w, p, a)
1162
1166
  ) : null;
1163
1167
  }
1164
1168
  function Jt({
1165
1169
  proxy: t
1166
1170
  }) {
1167
- const i = Z(null), m = `${t._stateKey}-${t._path.join(".")}`;
1168
- return ot(() => {
1169
- const f = i.current;
1170
- if (!f || !f.parentElement) return;
1171
- const y = f.parentElement, w = Array.from(y.childNodes).indexOf(f);
1172
- let I = y.getAttribute("data-parent-id");
1173
- I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I));
1174
- const v = {
1171
+ const c = Q(null), h = `${t._stateKey}-${t._path.join(".")}`;
1172
+ return nt(() => {
1173
+ const S = c.current;
1174
+ if (!S || !S.parentElement) return;
1175
+ const I = S.parentElement, w = Array.from(I.childNodes).indexOf(S);
1176
+ let p = I.getAttribute("data-parent-id");
1177
+ p || (p = `parent-${crypto.randomUUID()}`, I.setAttribute("data-parent-id", p));
1178
+ const y = {
1175
1179
  instanceId: `instance-${crypto.randomUUID()}`,
1176
- parentId: I,
1180
+ parentId: p,
1177
1181
  position: w,
1178
1182
  effect: t._effect
1179
1183
  };
1180
- o.getState().addSignalElement(m, v);
1184
+ o.getState().addSignalElement(h, y);
1181
1185
  const n = o.getState().getNestedState(t._stateKey, t._path);
1182
- let S;
1186
+ let m;
1183
1187
  if (t._effect)
1184
1188
  try {
1185
- S = new Function(
1189
+ m = new Function(
1186
1190
  "state",
1187
1191
  `return (${t._effect})(state)`
1188
1192
  )(n);
1189
- } catch (U) {
1190
- console.error("Error evaluating effect function during mount:", U), S = n;
1193
+ } catch (R) {
1194
+ console.error("Error evaluating effect function during mount:", R), m = n;
1191
1195
  }
1192
1196
  else
1193
- S = n;
1194
- S !== null && typeof S == "object" && (S = JSON.stringify(S));
1195
- const W = document.createTextNode(String(S));
1196
- f.replaceWith(W);
1197
+ m = n;
1198
+ m !== null && typeof m == "object" && (m = JSON.stringify(m));
1199
+ const L = document.createTextNode(String(m));
1200
+ S.replaceWith(L);
1197
1201
  }, [t._stateKey, t._path.join("."), t._effect]), at("span", {
1198
- ref: i,
1202
+ ref: c,
1199
1203
  style: { display: "none" },
1200
- "data-signal-id": m
1204
+ "data-signal-id": h
1201
1205
  });
1202
1206
  }
1203
1207
  function de(t) {
1204
- const i = xt(
1205
- (m) => {
1206
- const f = o.getState().stateComponents.get(t._stateKey) || {
1208
+ const c = xt(
1209
+ (h) => {
1210
+ const S = o.getState().stateComponents.get(t._stateKey) || {
1207
1211
  components: /* @__PURE__ */ new Map()
1208
1212
  };
1209
- return f.components.set(t._stateKey, {
1210
- forceUpdate: m,
1213
+ return S.components.set(t._stateKey, {
1214
+ forceUpdate: h,
1211
1215
  paths: /* @__PURE__ */ new Set([t._path.join(".")])
1212
- }), () => f.components.delete(t._stateKey);
1216
+ }), () => S.components.delete(t._stateKey);
1213
1217
  },
1214
1218
  () => o.getState().getNestedState(t._stateKey, t._path)
1215
1219
  );
1216
- return at("text", {}, String(i));
1220
+ return at("text", {}, String(c));
1217
1221
  }
1218
1222
  function Yt({
1219
1223
  stateKey: t,
1220
- itemComponentId: i,
1221
- itemPath: m,
1222
- children: f
1224
+ itemComponentId: c,
1225
+ itemPath: h,
1226
+ children: S
1223
1227
  }) {
1224
- const [, y] = Q({}), [b, w] = Ft(), I = Z(null);
1225
- return ot(() => {
1226
- w.height > 0 && w.height !== I.current && (I.current = w.height, o.getState().setShadowMetadata(t, m, {
1228
+ const [, I] = X({}), [b, w] = Ft(), p = Q(null);
1229
+ return nt(() => {
1230
+ w.height > 0 && w.height !== p.current && (p.current = w.height, o.getState().setShadowMetadata(t, h, {
1227
1231
  virtualizer: {
1228
1232
  itemHeight: w.height
1229
1233
  }
1230
1234
  }));
1231
- }, [w.height, t, m]), ct(() => {
1232
- const a = `${t}////${i}`, v = o.getState().stateComponents.get(t) || {
1235
+ }, [w.height, t, h]), ct(() => {
1236
+ const a = `${t}////${c}`, y = o.getState().stateComponents.get(t) || {
1233
1237
  components: /* @__PURE__ */ new Map()
1234
1238
  };
1235
- return v.components.set(a, {
1236
- forceUpdate: () => y({}),
1237
- paths: /* @__PURE__ */ new Set([m.join(".")])
1238
- }), o.getState().stateComponents.set(t, v), () => {
1239
+ return y.components.set(a, {
1240
+ forceUpdate: () => I({}),
1241
+ paths: /* @__PURE__ */ new Set([h.join(".")])
1242
+ }), o.getState().stateComponents.set(t, y), () => {
1239
1243
  const n = o.getState().stateComponents.get(t);
1240
1244
  n && n.components.delete(a);
1241
1245
  };
1242
- }, [t, i, m.join(".")]), /* @__PURE__ */ mt("div", { ref: b, children: f });
1246
+ }, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref: b, children: S });
1243
1247
  }
1244
1248
  export {
1245
1249
  kt as $cogsSignal,