cogsbox-state 0.5.452 → 0.5.453

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.
@@ -3,11 +3,11 @@ import { jsx as ot, Fragment as Ot } from "react/jsx-runtime";
3
3
  import { memo as Ut, useState as K, useRef as q, useCallback as ct, useEffect as Z, useLayoutEffect as dt, useMemo as gt, createElement as lt, startTransition as Rt } from "react";
4
4
  import { createRoot as At } from "react-dom/client";
5
5
  import { transformStateFunc as Nt, isFunction as at, isArray as Tt, getDifferences as Ct, isDeepEqual as st } from "./utility.js";
6
- import { ValidationWrapper as kt } from "./Functions.jsx";
6
+ import { ValidationWrapper as Pt } from "./Functions.jsx";
7
7
  import Ft from "superjson";
8
8
  import { v4 as rt } from "uuid";
9
9
  import { getGlobalStore as e, formRefStore as vt } from "./store.js";
10
- import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
10
+ import { useCogsConfig as kt } from "./CogsStateClient.jsx";
11
11
  import { useInView as jt } from "react-intersection-observer";
12
12
  function yt(t, n) {
13
13
  const S = e.getState().getInitialOptions, g = e.getState().setInitialStateOptions, y = S(t) || {};
@@ -16,17 +16,17 @@ function yt(t, n) {
16
16
  ...n
17
17
  });
18
18
  }
19
- function Vt({
19
+ function Et({
20
20
  stateKey: t,
21
21
  options: n,
22
22
  initialOptionsPart: S
23
23
  }) {
24
- const g = nt(t) || {}, y = S[t] || {}, w = e.getState().setInitialStateOptions, T = { ...y, ...g };
25
- let u = !1;
24
+ const g = nt(t) || {}, y = S[t] || {}, v = e.getState().setInitialStateOptions, M = { ...y, ...g };
25
+ let c = !1;
26
26
  if (n)
27
27
  for (const f in n)
28
- T.hasOwnProperty(f) ? (f == "localStorage" && n[f] && T[f].key !== n[f]?.key && (u = !0, T[f] = n[f]), f == "defaultState" && n[f] && T[f] !== n[f] && !st(T[f], n[f]) && (u = !0, T[f] = n[f])) : (u = !0, T[f] = n[f]);
29
- u && w(t, T);
28
+ M.hasOwnProperty(f) ? (f == "localStorage" && n[f] && M[f].key !== n[f]?.key && (c = !0, M[f] = n[f]), f == "defaultState" && n[f] && M[f] !== n[f] && !st(M[f], n[f]) && (c = !0, M[f] = n[f])) : (c = !0, M[f] = n[f]);
29
+ c && v(t, M);
30
30
  }
31
31
  function ie(t, { formElements: n, validation: S }) {
32
32
  return { initialState: t, formElements: n, validation: S };
@@ -34,8 +34,8 @@ function ie(t, { formElements: n, validation: S }) {
34
34
  const Lt = (t, n) => {
35
35
  let S = t;
36
36
  const [g, y] = Nt(S);
37
- n?.__fromSyncSchema && n?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", n.__syncNotifications), Object.keys(g).forEach((u) => {
38
- let f = y[u] || {};
37
+ n?.__fromSyncSchema && n?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", n.__syncNotifications), Object.keys(g).forEach((c) => {
38
+ let f = y[c] || {};
39
39
  const A = {
40
40
  ...f
41
41
  };
@@ -45,26 +45,26 @@ const Lt = (t, n) => {
45
45
  }), n?.validation && (A.validation = {
46
46
  ...n.validation,
47
47
  ...f.validation || {}
48
- }, n.validation.key && !f.validation?.key && (A.validation.key = `${n.validation.key}.${u}`)), Object.keys(A).length > 0) {
49
- const I = nt(u);
50
- I ? e.getState().setInitialStateOptions(u, {
48
+ }, n.validation.key && !f.validation?.key && (A.validation.key = `${n.validation.key}.${c}`)), Object.keys(A).length > 0) {
49
+ const I = nt(c);
50
+ I ? e.getState().setInitialStateOptions(c, {
51
51
  ...I,
52
52
  ...A
53
- }) : e.getState().setInitialStateOptions(u, A);
53
+ }) : e.getState().setInitialStateOptions(c, A);
54
54
  }
55
- }), Object.keys(g).forEach((u) => {
56
- e.getState().initializeShadowState(u, g[u]);
55
+ }), Object.keys(g).forEach((c) => {
56
+ e.getState().initializeShadowState(c, g[c]);
57
57
  });
58
- const w = (u, f) => {
58
+ const v = (c, f) => {
59
59
  const [A] = K(f?.componentId ?? rt());
60
- Vt({
61
- stateKey: u,
60
+ Et({
61
+ stateKey: c,
62
62
  options: f,
63
63
  initialOptionsPart: y
64
64
  });
65
- const I = e.getState().getShadowValue(u) || g[u], i = f?.modifyState ? f.modifyState(I) : I;
65
+ const I = e.getState().getShadowValue(c) || g[c], i = f?.modifyState ? f.modifyState(I) : I;
66
66
  return zt(i, {
67
- stateKey: u,
67
+ stateKey: c,
68
68
  syncUpdate: f?.syncUpdate,
69
69
  componentId: A,
70
70
  localStorage: f?.localStorage,
@@ -76,23 +76,33 @@ const Lt = (t, n) => {
76
76
  serverState: f?.serverState
77
77
  });
78
78
  };
79
- function T(u, f) {
80
- Vt({ stateKey: u, options: f, initialOptionsPart: y }), f.localStorage && xt(u, f), it(u);
79
+ function M(c, f) {
80
+ Et({ stateKey: c, options: f, initialOptionsPart: y }), f.localStorage && xt(c, f), it(c);
81
81
  }
82
- return { useCogsState: w, setCogsOptions: T };
82
+ return { useCogsState: v, setCogsOptions: M };
83
83
  };
84
84
  function ce(t) {
85
85
  const n = t.schemas, S = {};
86
- for (const w in n) {
87
- const T = n[w];
88
- S[w] = T?.schemas?.defaultValues || {};
86
+ for (const v in n) {
87
+ const M = n[v];
88
+ S[v] = M?.schemas?.defaultValues || {};
89
89
  }
90
90
  const g = Lt(S, {
91
91
  __fromSyncSchema: !0,
92
92
  __syncNotifications: t.notifications
93
93
  });
94
94
  return {
95
- useCogsState: (w, T) => g.useCogsState(w, T),
95
+ useCogsState: (v, M) => {
96
+ const c = n[v];
97
+ if (c?.apiParamsSchema && M?.apiParams) {
98
+ const f = c.apiParamsSchema.safeParse(M.apiParams);
99
+ if (!f.success)
100
+ throw new Error(
101
+ `Invalid API params for ${String(v)}: ${f.error.message}`
102
+ );
103
+ }
104
+ return g.useCogsState(v, M);
105
+ },
96
106
  setCogsOptions: g.setCogsOptions
97
107
  };
98
108
  }
@@ -110,23 +120,23 @@ const {
110
120
  S.localStorage?.key,
111
121
  g
112
122
  );
113
- const w = at(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
114
- if (w && g) {
115
- const T = `${g}-${n}-${w}`;
116
- let u;
123
+ const v = at(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
124
+ if (v && g) {
125
+ const M = `${g}-${n}-${v}`;
126
+ let c;
117
127
  try {
118
- u = St(T)?.lastSyncedWithServer;
128
+ c = St(M)?.lastSyncedWithServer;
119
129
  } catch {
120
130
  }
121
131
  const f = e.getState().getShadowMetadata(n, []), A = {
122
132
  state: t,
123
133
  lastUpdated: Date.now(),
124
- lastSyncedWithServer: u,
134
+ lastSyncedWithServer: c,
125
135
  stateSource: f?.stateSource,
126
136
  baseServerState: f?.baseServerState
127
137
  }, I = Ft.serialize(A);
128
138
  window.localStorage.setItem(
129
- T,
139
+ M,
130
140
  JSON.stringify(I.json)
131
141
  );
132
142
  }
@@ -139,12 +149,12 @@ const {
139
149
  return console.error("Error loading from localStorage:", n), null;
140
150
  }
141
151
  }, xt = (t, n) => {
142
- const S = e.getState().getShadowValue(t), { sessionId: g } = Pt(), y = at(n?.localStorage?.key) ? n.localStorage.key(S) : n?.localStorage?.key;
152
+ const S = e.getState().getShadowValue(t), { sessionId: g } = kt(), y = at(n?.localStorage?.key) ? n.localStorage.key(S) : n?.localStorage?.key;
143
153
  if (y && g) {
144
- const w = St(
154
+ const v = St(
145
155
  `${g}-${t}-${y}`
146
156
  );
147
- if (w && w.lastUpdated > (w.lastSyncedWithServer || 0))
157
+ if (v && v.lastUpdated > (v.lastSyncedWithServer || 0))
148
158
  return it(t), !0;
149
159
  }
150
160
  return !1;
@@ -167,16 +177,16 @@ const {
167
177
  }
168
178
  };
169
179
  function wt(t, n, S, g) {
170
- const y = e.getState(), w = y.getShadowMetadata(t, n);
180
+ const y = e.getState(), v = y.getShadowMetadata(t, n);
171
181
  if (y.setShadowMetadata(t, n, {
172
- ...w,
182
+ ...v,
173
183
  isDirty: !1,
174
184
  stateSource: "server",
175
185
  lastServerSync: g || Date.now()
176
186
  }), Array.isArray(S)) {
177
- const T = y.getShadowMetadata(t, n);
178
- T?.arrayKeys && T.arrayKeys.forEach((u, f) => {
179
- const A = u.split(".").slice(1), I = S[f];
187
+ const M = y.getShadowMetadata(t, n);
188
+ M?.arrayKeys && M.arrayKeys.forEach((c, f) => {
189
+ const A = c.split(".").slice(1), I = S[f];
180
190
  I !== void 0 && wt(
181
191
  t,
182
192
  A,
@@ -184,9 +194,9 @@ function wt(t, n, S, g) {
184
194
  g
185
195
  );
186
196
  });
187
- } else S && typeof S == "object" && S.constructor === Object && Object.keys(S).forEach((T) => {
188
- const u = [...n, T], f = S[T];
189
- wt(t, u, f, g);
197
+ } else S && typeof S == "object" && S.constructor === Object && Object.keys(S).forEach((M) => {
198
+ const c = [...n, M], f = S[M];
199
+ wt(t, c, f, g);
190
200
  });
191
201
  }
192
202
  function zt(t, {
@@ -194,20 +204,20 @@ function zt(t, {
194
204
  localStorage: S,
195
205
  formElements: g,
196
206
  reactiveDeps: y,
197
- reactiveType: w,
198
- componentId: T,
199
- defaultState: u,
207
+ reactiveType: v,
208
+ componentId: M,
209
+ defaultState: c,
200
210
  syncUpdate: f,
201
211
  dependencies: A,
202
212
  serverState: I
203
213
  } = {}) {
204
- const [i, h] = K({}), { sessionId: M } = Pt();
214
+ const [i, h] = K({}), { sessionId: T } = kt();
205
215
  let z = !n;
206
- const [c] = K(n ?? rt()), B = e.getState().stateLog[c], J = q(/* @__PURE__ */ new Set()), H = q(T ?? rt()), W = q(
216
+ const [l] = K(n ?? rt()), B = e.getState().stateLog[l], J = q(/* @__PURE__ */ new Set()), H = q(M ?? rt()), W = q(
207
217
  null
208
218
  );
209
- W.current = nt(c) ?? null, Z(() => {
210
- if (f && f.stateKey === c && f.path?.[0]) {
219
+ W.current = nt(l) ?? null, Z(() => {
220
+ if (f && f.stateKey === l && f.path?.[0]) {
211
221
  const o = `${f.stateKey}:${f.path.join(".")}`;
212
222
  e.getState().setSyncInfo(o, {
213
223
  timeStamp: f.timeStamp,
@@ -217,22 +227,22 @@ function zt(t, {
217
227
  }, [f]);
218
228
  const m = ct(
219
229
  (o) => {
220
- const a = o ? { ...nt(c), ...o } : nt(c), d = a?.defaultState || u || t;
230
+ const a = o ? { ...nt(l), ...o } : nt(l), d = a?.defaultState || c || t;
221
231
  if (a?.serverState?.status === "success" && a?.serverState?.data !== void 0)
222
232
  return {
223
233
  value: a.serverState.data,
224
234
  source: "server",
225
235
  timestamp: a.serverState.timestamp || Date.now()
226
236
  };
227
- if (a?.localStorage?.key && M) {
228
- const p = at(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key, E = St(
229
- `${M}-${c}-${p}`
237
+ if (a?.localStorage?.key && T) {
238
+ const p = at(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key, V = St(
239
+ `${T}-${l}-${p}`
230
240
  );
231
- if (E && E.lastUpdated > (a?.serverState?.timestamp || 0))
241
+ if (V && V.lastUpdated > (a?.serverState?.timestamp || 0))
232
242
  return {
233
- value: E.state,
243
+ value: V.state,
234
244
  source: "localStorage",
235
- timestamp: E.lastUpdated
245
+ timestamp: V.lastUpdated
236
246
  };
237
247
  }
238
248
  return {
@@ -241,36 +251,36 @@ function zt(t, {
241
251
  timestamp: Date.now()
242
252
  };
243
253
  },
244
- [c, u, t, M]
254
+ [l, c, t, T]
245
255
  );
246
256
  Z(() => {
247
- e.getState().setServerStateUpdate(c, I);
248
- }, [I, c]), Z(() => e.getState().subscribeToPath(c, (r) => {
257
+ e.getState().setServerStateUpdate(l, I);
258
+ }, [I, l]), Z(() => e.getState().subscribeToPath(l, (r) => {
249
259
  if (r?.type === "SERVER_STATE_UPDATE") {
250
260
  const a = r.serverState;
251
261
  if (a?.status === "success" && a.data !== void 0) {
252
- yt(c, { serverState: a });
253
- const l = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, p = e.getState().getShadowValue(c), E = a.data;
254
- if (l && Array.isArray(p) && Array.isArray(E)) {
255
- const O = l.key || "id", C = new Set(
262
+ yt(l, { serverState: a });
263
+ const u = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, p = e.getState().getShadowValue(l), V = a.data;
264
+ if (u && Array.isArray(p) && Array.isArray(V)) {
265
+ const O = u.key || "id", C = new Set(
256
266
  p.map((x) => x[O])
257
- ), F = E.filter((x) => !C.has(x[O]));
267
+ ), F = V.filter((x) => !C.has(x[O]));
258
268
  F.length > 0 && F.forEach((x) => {
259
- e.getState().insertShadowArrayElement(c, [], x);
260
- const N = e.getState().getShadowMetadata(c, []);
269
+ e.getState().insertShadowArrayElement(l, [], x);
270
+ const N = e.getState().getShadowMetadata(l, []);
261
271
  if (N?.arrayKeys) {
262
272
  const j = N.arrayKeys[N.arrayKeys.length - 1];
263
273
  if (j) {
264
274
  const b = j.split(".").slice(1);
265
- e.getState().setShadowMetadata(c, b, {
275
+ e.getState().setShadowMetadata(l, b, {
266
276
  isDirty: !1,
267
277
  stateSource: "server",
268
278
  lastServerSync: a.timestamp || Date.now()
269
279
  });
270
- const k = e.getState().getShadowValue(j);
271
- k && typeof k == "object" && !Array.isArray(k) && Object.keys(k).forEach((P) => {
272
- const U = [...b, P];
273
- e.getState().setShadowMetadata(c, U, {
280
+ const P = e.getState().getShadowValue(j);
281
+ P && typeof P == "object" && !Array.isArray(P) && Object.keys(P).forEach((k) => {
282
+ const U = [...b, k];
283
+ e.getState().setShadowMetadata(l, U, {
274
284
  isDirty: !1,
275
285
  stateSource: "server",
276
286
  lastServerSync: a.timestamp || Date.now()
@@ -280,14 +290,14 @@ function zt(t, {
280
290
  }
281
291
  });
282
292
  } else
283
- e.getState().initializeShadowState(c, E), wt(
284
- c,
293
+ e.getState().initializeShadowState(l, V), wt(
294
+ l,
285
295
  [],
286
- E,
296
+ V,
287
297
  a.timestamp
288
298
  );
289
- const _ = e.getState().getShadowMetadata(c, []);
290
- e.getState().setShadowMetadata(c, [], {
299
+ const _ = e.getState().getShadowMetadata(l, []);
300
+ e.getState().setShadowMetadata(l, [], {
291
301
  ..._,
292
302
  stateSource: "server",
293
303
  lastServerSync: a.timestamp || Date.now(),
@@ -295,95 +305,95 @@ function zt(t, {
295
305
  });
296
306
  }
297
307
  }
298
- }), [c, m]), Z(() => {
299
- const o = e.getState().getShadowMetadata(c, []);
308
+ }), [l, m]), Z(() => {
309
+ const o = e.getState().getShadowMetadata(l, []);
300
310
  if (o && o.stateSource)
301
311
  return;
302
- const r = nt(c);
303
- if (r?.defaultState !== void 0 || u !== void 0) {
304
- const a = r?.defaultState || u;
305
- r?.defaultState || yt(c, {
312
+ const r = nt(l);
313
+ if (r?.defaultState !== void 0 || c !== void 0) {
314
+ const a = r?.defaultState || c;
315
+ r?.defaultState || yt(l, {
306
316
  defaultState: a
307
317
  });
308
- const { value: d, source: l, timestamp: p } = m();
309
- e.getState().initializeShadowState(c, d), e.getState().setShadowMetadata(c, [], {
310
- stateSource: l,
311
- lastServerSync: l === "server" ? p : void 0,
318
+ const { value: d, source: u, timestamp: p } = m();
319
+ e.getState().initializeShadowState(l, d), e.getState().setShadowMetadata(l, [], {
320
+ stateSource: u,
321
+ lastServerSync: u === "server" ? p : void 0,
312
322
  isDirty: !1,
313
- baseServerState: l === "server" ? d : void 0
314
- }), it(c);
323
+ baseServerState: u === "server" ? d : void 0
324
+ }), it(l);
315
325
  }
316
- }, [c, ...A || []]), dt(() => {
317
- z && yt(c, {
326
+ }, [l, ...A || []]), dt(() => {
327
+ z && yt(l, {
318
328
  formElements: g,
319
- defaultState: u,
329
+ defaultState: c,
320
330
  localStorage: S,
321
331
  middleware: W.current?.middleware
322
332
  });
323
- const o = `${c}////${H.current}`, r = e.getState().getShadowMetadata(c, []), a = r?.components || /* @__PURE__ */ new Map();
333
+ const o = `${l}////${H.current}`, r = e.getState().getShadowMetadata(l, []), a = r?.components || /* @__PURE__ */ new Map();
324
334
  return a.set(o, {
325
335
  forceUpdate: () => h({}),
326
- reactiveType: w ?? ["component", "deps"],
336
+ reactiveType: v ?? ["component", "deps"],
327
337
  paths: /* @__PURE__ */ new Set(),
328
338
  depsFunction: y || void 0,
329
- deps: y ? y(e.getState().getShadowValue(c)) : [],
330
- prevDeps: y ? y(e.getState().getShadowValue(c)) : []
331
- }), e.getState().setShadowMetadata(c, [], {
339
+ deps: y ? y(e.getState().getShadowValue(l)) : [],
340
+ prevDeps: y ? y(e.getState().getShadowValue(l)) : []
341
+ }), e.getState().setShadowMetadata(l, [], {
332
342
  ...r,
333
343
  components: a
334
344
  }), h({}), () => {
335
- const d = e.getState().getShadowMetadata(c, []), l = d?.components?.get(o);
336
- l?.paths && l.paths.forEach((p) => {
337
- const _ = p.split(".").slice(1), O = e.getState().getShadowMetadata(c, _);
338
- O?.pathComponents && O.pathComponents.size === 0 && (delete O.pathComponents, e.getState().setShadowMetadata(c, _, O));
339
- }), d?.components && e.getState().setShadowMetadata(c, [], d);
345
+ const d = e.getState().getShadowMetadata(l, []), u = d?.components?.get(o);
346
+ u?.paths && u.paths.forEach((p) => {
347
+ const _ = p.split(".").slice(1), O = e.getState().getShadowMetadata(l, _);
348
+ O?.pathComponents && O.pathComponents.size === 0 && (delete O.pathComponents, e.getState().setShadowMetadata(l, _, O));
349
+ }), d?.components && e.getState().setShadowMetadata(l, [], d);
340
350
  };
341
351
  }, []);
342
352
  const Y = q(null), Q = (o, r, a) => {
343
- const d = [c, ...r].join(".");
353
+ const d = [l, ...r].join(".");
344
354
  if (Array.isArray(r)) {
345
- const b = `${c}-${r.join(".")}`;
355
+ const b = `${l}-${r.join(".")}`;
346
356
  J.current.add(b);
347
357
  }
348
- const l = e.getState(), p = l.getShadowMetadata(c, r), E = l.getShadowValue(d), _ = a.updateType === "insert" && at(o) ? o({ state: E, uuid: rt() }) : at(o) ? o(E) : o, C = {
358
+ const u = e.getState(), p = u.getShadowMetadata(l, r), V = u.getShadowValue(d), _ = a.updateType === "insert" && at(o) ? o({ state: V, uuid: rt() }) : at(o) ? o(V) : o, C = {
349
359
  timeStamp: Date.now(),
350
- stateKey: c,
360
+ stateKey: l,
351
361
  path: r,
352
362
  updateType: a.updateType,
353
363
  status: "new",
354
- oldValue: E,
364
+ oldValue: V,
355
365
  newValue: _
356
366
  };
357
367
  switch (a.updateType) {
358
368
  case "insert": {
359
- l.insertShadowArrayElement(c, r, C.newValue), l.markAsDirty(c, r, { bubble: !0 });
360
- const b = l.getShadowMetadata(c, r);
369
+ u.insertShadowArrayElement(l, r, C.newValue), u.markAsDirty(l, r, { bubble: !0 });
370
+ const b = u.getShadowMetadata(l, r);
361
371
  if (b?.arrayKeys) {
362
- const k = b.arrayKeys[b.arrayKeys.length - 1];
363
- if (k) {
364
- const P = k.split(".").slice(1);
365
- l.markAsDirty(c, P, { bubble: !1 });
372
+ const P = b.arrayKeys[b.arrayKeys.length - 1];
373
+ if (P) {
374
+ const k = P.split(".").slice(1);
375
+ u.markAsDirty(l, k, { bubble: !1 });
366
376
  }
367
377
  }
368
378
  break;
369
379
  }
370
380
  case "cut": {
371
381
  const b = r.slice(0, -1);
372
- l.removeShadowArrayElement(c, r), l.markAsDirty(c, b, { bubble: !0 });
382
+ u.removeShadowArrayElement(l, r), u.markAsDirty(l, b, { bubble: !0 });
373
383
  break;
374
384
  }
375
385
  case "update": {
376
- l.updateShadowAtPath(c, r, C.newValue), l.markAsDirty(c, r, { bubble: !0 });
386
+ u.updateShadowAtPath(l, r, C.newValue), u.markAsDirty(l, r, { bubble: !0 });
377
387
  break;
378
388
  }
379
389
  }
380
390
  if (a.sync !== !1 && Y.current && Y.current.connected && Y.current.updateState({ operation: C }), p?.signals && p.signals.length > 0) {
381
391
  const b = a.updateType === "cut" ? null : _;
382
- p.signals.forEach(({ parentId: k, position: P, effect: U }) => {
383
- const v = document.querySelector(`[data-parent-id="${k}"]`);
384
- if (v) {
385
- const V = Array.from(v.childNodes);
386
- if (V[P]) {
392
+ p.signals.forEach(({ parentId: P, position: k, effect: U }) => {
393
+ const w = document.querySelector(`[data-parent-id="${P}"]`);
394
+ if (w) {
395
+ const E = Array.from(w.childNodes);
396
+ if (E[k]) {
387
397
  let $ = b;
388
398
  if (U && b !== null)
389
399
  try {
@@ -394,107 +404,107 @@ function zt(t, {
394
404
  } catch (D) {
395
405
  console.error("Error evaluating effect function:", D);
396
406
  }
397
- $ != null && typeof $ == "object" && ($ = JSON.stringify($)), V[P].textContent = String($ ?? "");
407
+ $ != null && typeof $ == "object" && ($ = JSON.stringify($)), E[k].textContent = String($ ?? "");
398
408
  }
399
409
  }
400
410
  });
401
411
  }
402
412
  if (a.updateType === "insert" && p?.mapWrappers && p.mapWrappers.length > 0) {
403
- const b = l.getShadowMetadata(c, r)?.arrayKeys || [], k = b[b.length - 1], P = l.getShadowValue(k), U = l.getShadowValue(
404
- [c, ...r].join(".")
413
+ const b = u.getShadowMetadata(l, r)?.arrayKeys || [], P = b[b.length - 1], k = u.getShadowValue(P), U = u.getShadowValue(
414
+ [l, ...r].join(".")
405
415
  );
406
- if (!k || P === void 0) return;
407
- p.mapWrappers.forEach((v) => {
408
- let V = !0, $ = -1;
409
- if (v.meta?.transforms && v.meta.transforms.length > 0) {
410
- for (const D of v.meta.transforms)
411
- if (D.type === "filter" && !D.fn(P, -1)) {
412
- V = !1;
416
+ if (!P || k === void 0) return;
417
+ p.mapWrappers.forEach((w) => {
418
+ let E = !0, $ = -1;
419
+ if (w.meta?.transforms && w.meta.transforms.length > 0) {
420
+ for (const D of w.meta.transforms)
421
+ if (D.type === "filter" && !D.fn(k, -1)) {
422
+ E = !1;
413
423
  break;
414
424
  }
415
- if (V) {
425
+ if (E) {
416
426
  const D = It(
417
- c,
427
+ l,
418
428
  r,
419
- v.meta.transforms
420
- ), R = v.meta.transforms.find(
429
+ w.meta.transforms
430
+ ), R = w.meta.transforms.find(
421
431
  (L) => L.type === "sort"
422
432
  );
423
433
  if (R) {
424
434
  const L = D.map((G) => ({
425
435
  key: G,
426
- value: l.getShadowValue(G)
436
+ value: u.getShadowValue(G)
427
437
  }));
428
- L.push({ key: k, value: P }), L.sort((G, tt) => R.fn(G.value, tt.value)), $ = L.findIndex(
429
- (G) => G.key === k
438
+ L.push({ key: P, value: k }), L.sort((G, tt) => R.fn(G.value, tt.value)), $ = L.findIndex(
439
+ (G) => G.key === P
430
440
  );
431
441
  } else
432
442
  $ = D.length;
433
443
  }
434
444
  } else
435
- V = !0, $ = b.length - 1;
436
- if (V && v.containerRef && v.containerRef.isConnected) {
445
+ E = !0, $ = b.length - 1;
446
+ if (E && w.containerRef && w.containerRef.isConnected) {
437
447
  const D = document.createElement("div");
438
- D.setAttribute("data-item-path", k);
439
- const R = Array.from(v.containerRef.children);
440
- $ >= 0 && $ < R.length ? v.containerRef.insertBefore(
448
+ D.setAttribute("data-item-path", P);
449
+ const R = Array.from(w.containerRef.children);
450
+ $ >= 0 && $ < R.length ? w.containerRef.insertBefore(
441
451
  D,
442
452
  R[$]
443
- ) : v.containerRef.appendChild(D);
444
- const L = At(D), G = rt(), tt = k.split(".").slice(1), et = v.rebuildStateShape({
445
- path: v.path,
453
+ ) : w.containerRef.appendChild(D);
454
+ const L = At(D), G = rt(), tt = P.split(".").slice(1), et = w.rebuildStateShape({
455
+ path: w.path,
446
456
  currentState: U,
447
- componentId: v.componentId,
448
- meta: v.meta
457
+ componentId: w.componentId,
458
+ meta: w.meta
449
459
  });
450
460
  L.render(
451
461
  lt(Mt, {
452
- stateKey: c,
462
+ stateKey: l,
453
463
  itemComponentId: G,
454
464
  itemPath: tt,
455
465
  localIndex: $,
456
466
  arraySetter: et,
457
- rebuildStateShape: v.rebuildStateShape,
458
- renderFn: v.mapFn
467
+ rebuildStateShape: w.rebuildStateShape,
468
+ renderFn: w.mapFn
459
469
  })
460
470
  );
461
471
  }
462
472
  });
463
473
  }
464
474
  if (a.updateType === "cut") {
465
- const b = r.slice(0, -1), k = l.getShadowMetadata(c, b);
466
- k?.mapWrappers && k.mapWrappers.length > 0 && k.mapWrappers.forEach((P) => {
467
- if (P.containerRef && P.containerRef.isConnected) {
468
- const U = P.containerRef.querySelector(
475
+ const b = r.slice(0, -1), P = u.getShadowMetadata(l, b);
476
+ P?.mapWrappers && P.mapWrappers.length > 0 && P.mapWrappers.forEach((k) => {
477
+ if (k.containerRef && k.containerRef.isConnected) {
478
+ const U = k.containerRef.querySelector(
469
479
  `[data-item-path="${d}"]`
470
480
  );
471
481
  U && U.remove();
472
482
  }
473
483
  });
474
484
  }
475
- const x = e.getState().getShadowValue(c), N = e.getState().getShadowMetadata(c, []), j = /* @__PURE__ */ new Set();
485
+ const x = e.getState().getShadowValue(l), N = e.getState().getShadowMetadata(l, []), j = /* @__PURE__ */ new Set();
476
486
  if (console.log(
477
487
  "rootMeta",
478
- c,
488
+ l,
479
489
  e.getState().shadowStateStore
480
490
  ), !N?.components)
481
491
  return x;
482
492
  if (a.updateType === "update") {
483
493
  let b = [...r];
484
494
  for (; ; ) {
485
- const k = l.getShadowMetadata(c, b);
486
- if (k?.pathComponents && k.pathComponents.forEach((P) => {
487
- if (j.has(P))
495
+ const P = u.getShadowMetadata(l, b);
496
+ if (P?.pathComponents && P.pathComponents.forEach((k) => {
497
+ if (j.has(k))
488
498
  return;
489
- const U = N.components?.get(P);
490
- U && ((Array.isArray(U.reactiveType) ? U.reactiveType : [U.reactiveType || "component"]).includes("none") || (U.forceUpdate(), j.add(P)));
499
+ const U = N.components?.get(k);
500
+ U && ((Array.isArray(U.reactiveType) ? U.reactiveType : [U.reactiveType || "component"]).includes("none") || (U.forceUpdate(), j.add(k)));
491
501
  }), b.length === 0)
492
502
  break;
493
503
  b.pop();
494
504
  }
495
- _ && typeof _ == "object" && !Tt(_) && E && typeof E == "object" && !Tt(E) && Ct(_, E).forEach((P) => {
496
- const U = P.split("."), v = [...r, ...U], V = l.getShadowMetadata(c, v);
497
- V?.pathComponents && V.pathComponents.forEach(($) => {
505
+ _ && typeof _ == "object" && !Tt(_) && V && typeof V == "object" && !Tt(V) && Ct(_, V).forEach((k) => {
506
+ const U = k.split("."), w = [...r, ...U], E = u.getShadowMetadata(l, w);
507
+ E?.pathComponents && E.pathComponents.forEach(($) => {
498
508
  if (j.has($))
499
509
  return;
500
510
  const D = N.components?.get($);
@@ -502,16 +512,16 @@ function zt(t, {
502
512
  });
503
513
  });
504
514
  } else if (a.updateType === "insert" || a.updateType === "cut") {
505
- const b = a.updateType === "insert" ? r : r.slice(0, -1), k = l.getShadowMetadata(c, b);
506
- if (k?.signals && k.signals.length > 0) {
507
- const P = [c, ...b].join("."), U = l.getShadowValue(P);
508
- k.signals.forEach(({ parentId: v, position: V, effect: $ }) => {
515
+ const b = a.updateType === "insert" ? r : r.slice(0, -1), P = u.getShadowMetadata(l, b);
516
+ if (P?.signals && P.signals.length > 0) {
517
+ const k = [l, ...b].join("."), U = u.getShadowValue(k);
518
+ P.signals.forEach(({ parentId: w, position: E, effect: $ }) => {
509
519
  const D = document.querySelector(
510
- `[data-parent-id="${v}"]`
520
+ `[data-parent-id="${w}"]`
511
521
  );
512
522
  if (D) {
513
523
  const R = Array.from(D.childNodes);
514
- if (R[V]) {
524
+ if (R[E]) {
515
525
  let L = U;
516
526
  if ($)
517
527
  try {
@@ -522,54 +532,54 @@ function zt(t, {
522
532
  } catch (G) {
523
533
  console.error("Error evaluating effect function:", G), L = U;
524
534
  }
525
- L != null && typeof L == "object" && (L = JSON.stringify(L)), R[V].textContent = String(L ?? "");
535
+ L != null && typeof L == "object" && (L = JSON.stringify(L)), R[E].textContent = String(L ?? "");
526
536
  }
527
537
  }
528
538
  });
529
539
  }
530
- k?.pathComponents && k.pathComponents.forEach((P) => {
531
- if (!j.has(P)) {
532
- const U = N.components?.get(P);
533
- U && (U.forceUpdate(), j.add(P));
540
+ P?.pathComponents && P.pathComponents.forEach((k) => {
541
+ if (!j.has(k)) {
542
+ const U = N.components?.get(k);
543
+ U && (U.forceUpdate(), j.add(k));
534
544
  }
535
545
  });
536
546
  }
537
- return N.components.forEach((b, k) => {
538
- if (j.has(k))
547
+ return N.components.forEach((b, P) => {
548
+ if (j.has(P))
539
549
  return;
540
- const P = Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"];
541
- if (P.includes("all")) {
542
- b.forceUpdate(), j.add(k);
550
+ const k = Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"];
551
+ if (k.includes("all")) {
552
+ b.forceUpdate(), j.add(P);
543
553
  return;
544
554
  }
545
- if (P.includes("deps") && b.depsFunction) {
546
- const U = l.getShadowValue(c), v = b.depsFunction(U);
547
- let V = !1;
548
- v === !0 ? V = !0 : Array.isArray(v) && (st(b.prevDeps, v) || (b.prevDeps = v, V = !0)), V && (b.forceUpdate(), j.add(k));
555
+ if (k.includes("deps") && b.depsFunction) {
556
+ const U = u.getShadowValue(l), w = b.depsFunction(U);
557
+ let E = !1;
558
+ w === !0 ? E = !0 : Array.isArray(w) && (st(b.prevDeps, w) || (b.prevDeps = w, E = !0)), E && (b.forceUpdate(), j.add(P));
549
559
  }
550
- }), j.clear(), Wt(c, (b) => {
551
- const k = [...b ?? [], C], P = /* @__PURE__ */ new Map();
552
- return k.forEach((U) => {
553
- const v = `${U.stateKey}:${JSON.stringify(U.path)}`, V = P.get(v);
554
- V ? (V.timeStamp = Math.max(V.timeStamp, U.timeStamp), V.newValue = U.newValue, V.oldValue = V.oldValue ?? U.oldValue, V.updateType = U.updateType) : P.set(v, { ...U });
555
- }), Array.from(P.values());
560
+ }), j.clear(), Wt(l, (b) => {
561
+ const P = [...b ?? [], C], k = /* @__PURE__ */ new Map();
562
+ return P.forEach((U) => {
563
+ const w = `${U.stateKey}:${JSON.stringify(U.path)}`, E = k.get(w);
564
+ E ? (E.timeStamp = Math.max(E.timeStamp, U.timeStamp), E.newValue = U.newValue, E.oldValue = E.oldValue ?? U.oldValue, E.updateType = U.updateType) : k.set(w, { ...U });
565
+ }), Array.from(k.values());
556
566
  }), Ht(
557
567
  _,
558
- c,
568
+ l,
559
569
  W.current,
560
- M
570
+ T
561
571
  ), W.current?.middleware && W.current.middleware({
562
572
  updateLog: B,
563
573
  update: C
564
574
  }), x;
565
575
  };
566
- e.getState().initialStateGlobal[c] || _t(c, t);
576
+ e.getState().initialStateGlobal[l] || _t(l, t);
567
577
  const X = gt(() => Dt(
568
- c,
578
+ l,
569
579
  Q,
570
580
  H.current,
571
- M
572
- ), [c, M]), s = W.current?.cogsSync;
581
+ T
582
+ ), [l, T]), s = W.current?.cogsSync;
573
583
  return s && (Y.current = s(X)), X;
574
584
  }
575
585
  function Bt(t) {
@@ -584,53 +594,53 @@ const It = (t, n, S) => {
584
594
  let g = e.getState().getShadowMetadata(t, n)?.arrayKeys || [];
585
595
  if (!S || S.length === 0)
586
596
  return g;
587
- let y = g.map((w) => ({
588
- key: w,
589
- value: e.getState().getShadowValue(w)
597
+ let y = g.map((v) => ({
598
+ key: v,
599
+ value: e.getState().getShadowValue(v)
590
600
  }));
591
- for (const w of S)
592
- w.type === "filter" ? y = y.filter(
593
- ({ value: T }, u) => w.fn(T, u)
594
- ) : w.type === "sort" && y.sort((T, u) => w.fn(T.value, u.value));
595
- return y.map(({ key: w }) => w);
596
- }, Et = (t, n, S) => {
597
- const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata: w } = e.getState(), u = w(t, [])?.components?.get(g);
598
- !u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t, S, g);
601
+ for (const v of S)
602
+ v.type === "filter" ? y = y.filter(
603
+ ({ value: M }, c) => v.fn(M, c)
604
+ ) : v.type === "sort" && y.sort((M, c) => v.fn(M.value, c.value));
605
+ return y.map(({ key: v }) => v);
606
+ }, Vt = (t, n, S) => {
607
+ const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata: v } = e.getState(), c = v(t, [])?.components?.get(g);
608
+ !c || c.reactiveType === "none" || !(Array.isArray(c.reactiveType) ? c.reactiveType : [c.reactiveType]).includes("component") || y(t, S, g);
599
609
  }, ft = (t, n, S) => {
600
- const g = e.getState(), y = g.getShadowMetadata(t, []), w = /* @__PURE__ */ new Set();
601
- y?.components && y.components.forEach((u, f) => {
602
- (Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), w.add(f));
603
- }), g.getShadowMetadata(t, [...n, "getSelected"])?.pathComponents?.forEach((u) => {
604
- y?.components?.get(u)?.forceUpdate();
610
+ const g = e.getState(), y = g.getShadowMetadata(t, []), v = /* @__PURE__ */ new Set();
611
+ y?.components && y.components.forEach((c, f) => {
612
+ (Array.isArray(c.reactiveType) ? c.reactiveType : [c.reactiveType || "component"]).includes("all") && (c.forceUpdate(), v.add(f));
613
+ }), g.getShadowMetadata(t, [...n, "getSelected"])?.pathComponents?.forEach((c) => {
614
+ y?.components?.get(c)?.forceUpdate();
605
615
  });
606
- const T = g.getShadowMetadata(t, n);
607
- for (let u of T?.arrayKeys || []) {
608
- const f = u + ".selected", A = g.getShadowMetadata(
616
+ const M = g.getShadowMetadata(t, n);
617
+ for (let c of M?.arrayKeys || []) {
618
+ const f = c + ".selected", A = g.getShadowMetadata(
609
619
  t,
610
620
  f.split(".").slice(1)
611
621
  );
612
- u == S && A?.pathComponents?.forEach((I) => {
622
+ c == S && A?.pathComponents?.forEach((I) => {
613
623
  y?.components?.get(I)?.forceUpdate();
614
624
  });
615
625
  }
616
626
  };
617
627
  function Dt(t, n, S, g) {
618
628
  const y = /* @__PURE__ */ new Map();
619
- let w = 0;
620
- const T = (I) => {
629
+ let v = 0;
630
+ const M = (I) => {
621
631
  const i = I.join(".");
622
632
  for (const [h] of y)
623
633
  (h === i || h.startsWith(i + ".")) && y.delete(h);
624
- w++;
634
+ v++;
625
635
  };
626
- function u({
636
+ function c({
627
637
  currentState: I,
628
638
  path: i = [],
629
639
  meta: h,
630
- componentId: M
640
+ componentId: T
631
641
  }) {
632
- const z = i.map(String).join("."), c = [t, ...i].join(".");
633
- I = e.getState().getShadowValue(c, h?.validIds);
642
+ const z = i.map(String).join("."), l = [t, ...i].join(".");
643
+ I = e.getState().getShadowValue(l, h?.validIds);
634
644
  const B = function() {
635
645
  return e().getShadowValue(t, i);
636
646
  }, J = {
@@ -638,7 +648,7 @@ function Dt(t, n, S, g) {
638
648
  },
639
649
  get(W, m) {
640
650
  if (m === "_rebuildStateShape")
641
- return u;
651
+ return c;
642
652
  if (Object.getOwnPropertyNames(f).includes(m) && i.length === 0)
643
653
  return f[m];
644
654
  if (m === "getDifferences")
@@ -655,13 +665,13 @@ function Dt(t, n, S, g) {
655
665
  const r = e.getState().getShadowValue(t, []), a = s?.validation?.key;
656
666
  try {
657
667
  const d = await o.action(r);
658
- if (d && !d.success && d.errors && a && (e.getState().removeValidationError(a), d.errors.forEach((l) => {
659
- const p = [a, ...l.path].join(".");
660
- e.getState().addValidationError(p, l.message);
668
+ if (d && !d.success && d.errors && a && (e.getState().removeValidationError(a), d.errors.forEach((u) => {
669
+ const p = [a, ...u.path].join(".");
670
+ e.getState().addValidationError(p, u.message);
661
671
  }), it(t)), d?.success) {
662
- const l = e.getState().getShadowMetadata(t, []);
672
+ const u = e.getState().getShadowMetadata(t, []);
663
673
  e.getState().setShadowMetadata(t, [], {
664
- ...l,
674
+ ...u,
665
675
  isDirty: !1,
666
676
  lastServerSync: Date.now(),
667
677
  stateSource: "server",
@@ -676,7 +686,7 @@ function Dt(t, n, S, g) {
676
686
  };
677
687
  if (m === "_status" || m === "getStatus") {
678
688
  const s = () => {
679
- const o = e.getState().getShadowMetadata(t, i), r = e.getState().getShadowValue(c);
689
+ const o = e.getState().getShadowMetadata(t, i), r = e.getState().getShadowValue(l);
680
690
  return o?.isDirty === !0 ? "dirty" : o?.isDirty === !1 || o?.stateSource === "server" ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.stateSource === "default" ? "fresh" : e.getState().getShadowMetadata(t, [])?.stateSource === "server" && !o?.isDirty ? "synced" : r !== void 0 && !o ? "fresh" : "unknown";
681
691
  };
682
692
  return m === "_status" ? s() : s;
@@ -695,7 +705,7 @@ function Dt(t, n, S, g) {
695
705
  if (m === "getSelected")
696
706
  return () => {
697
707
  const s = t + "." + i.join(".");
698
- Et(t, M, [
708
+ Vt(t, T, [
699
709
  ...i,
700
710
  "getSelected"
701
711
  ]);
@@ -707,10 +717,10 @@ function Dt(t, n, S, g) {
707
717
  return;
708
718
  const a = e.getState().getShadowValue(r);
709
719
  if (a)
710
- return u({
720
+ return c({
711
721
  currentState: a,
712
722
  path: r.split(".").slice(1),
713
- componentId: M
723
+ componentId: T
714
724
  });
715
725
  };
716
726
  if (m === "getSelectedIndex")
@@ -731,7 +741,7 @@ function Dt(t, n, S, g) {
731
741
  overscan: r = 6,
732
742
  stickToBottom: a = !1,
733
743
  scrollStickTolerance: d = 75
734
- } = s, l = q(null), [p, E] = K({
744
+ } = s, u = q(null), [p, V] = K({
735
745
  startIndex: 0,
736
746
  endIndex: 10
737
747
  }), [_, O] = K({}), C = q(!0), F = q({
@@ -743,60 +753,60 @@ function Dt(t, n, S, g) {
743
753
  /* @__PURE__ */ new Map()
744
754
  );
745
755
  dt(() => {
746
- if (!a || !l.current || F.current.isUserScrolling)
756
+ if (!a || !u.current || F.current.isUserScrolling)
747
757
  return;
748
- const v = l.current;
749
- v.scrollTo({
750
- top: v.scrollHeight,
758
+ const w = u.current;
759
+ w.scrollTo({
760
+ top: w.scrollHeight,
751
761
  behavior: C.current ? "instant" : "smooth"
752
762
  });
753
763
  }, [_, a]);
754
764
  const N = e.getState().getShadowMetadata(t, i)?.arrayKeys || [], { totalHeight: j, itemOffsets: b } = gt(() => {
755
- let v = 0;
756
- const V = /* @__PURE__ */ new Map();
765
+ let w = 0;
766
+ const E = /* @__PURE__ */ new Map();
757
767
  return (e.getState().getShadowMetadata(t, i)?.arrayKeys || []).forEach((D) => {
758
768
  const R = D.split(".").slice(1), L = e.getState().getShadowMetadata(t, R)?.virtualizer?.itemHeight || o;
759
- V.set(D, {
769
+ E.set(D, {
760
770
  height: L,
761
- offset: v
762
- }), v += L;
763
- }), x.current = V, { totalHeight: v, itemOffsets: V };
771
+ offset: w
772
+ }), w += L;
773
+ }), x.current = E, { totalHeight: w, itemOffsets: E };
764
774
  }, [N.length, o]);
765
775
  dt(() => {
766
- if (a && N.length > 0 && l.current && !F.current.isUserScrolling && C.current) {
767
- const v = l.current, V = () => {
768
- if (v.clientHeight > 0) {
776
+ if (a && N.length > 0 && u.current && !F.current.isUserScrolling && C.current) {
777
+ const w = u.current, E = () => {
778
+ if (w.clientHeight > 0) {
769
779
  const $ = Math.ceil(
770
- v.clientHeight / o
780
+ w.clientHeight / o
771
781
  ), D = N.length - 1, R = Math.max(
772
782
  0,
773
783
  D - $ - r
774
784
  );
775
- E({ startIndex: R, endIndex: D }), requestAnimationFrame(() => {
776
- P("instant"), C.current = !1;
785
+ V({ startIndex: R, endIndex: D }), requestAnimationFrame(() => {
786
+ k("instant"), C.current = !1;
777
787
  });
778
788
  } else
779
- requestAnimationFrame(V);
789
+ requestAnimationFrame(E);
780
790
  };
781
- V();
791
+ E();
782
792
  }
783
793
  }, [N.length, a, o, r]);
784
- const k = ct(() => {
785
- const v = l.current;
786
- if (!v) return;
787
- const V = v.scrollTop, { scrollHeight: $, clientHeight: D } = v, R = F.current, L = $ - (V + D), G = R.isNearBottom;
788
- R.isNearBottom = L <= d, V < R.lastScrollTop ? (R.scrollUpCount++, R.scrollUpCount > 3 && G && (R.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : R.isNearBottom && (R.isUserScrolling = !1, R.scrollUpCount = 0), R.lastScrollTop = V;
794
+ const P = ct(() => {
795
+ const w = u.current;
796
+ if (!w) return;
797
+ const E = w.scrollTop, { scrollHeight: $, clientHeight: D } = w, R = F.current, L = $ - (E + D), G = R.isNearBottom;
798
+ R.isNearBottom = L <= d, E < R.lastScrollTop ? (R.scrollUpCount++, R.scrollUpCount > 3 && G && (R.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : R.isNearBottom && (R.isUserScrolling = !1, R.scrollUpCount = 0), R.lastScrollTop = E;
789
799
  let tt = 0;
790
800
  for (let et = 0; et < N.length; et++) {
791
801
  const ht = N[et], mt = x.current.get(ht);
792
- if (mt && mt.offset + mt.height > V) {
802
+ if (mt && mt.offset + mt.height > E) {
793
803
  tt = et;
794
804
  break;
795
805
  }
796
806
  }
797
807
  if (tt !== p.startIndex) {
798
808
  const et = Math.ceil(D / o);
799
- E({
809
+ V({
800
810
  startIndex: Math.max(0, tt - r),
801
811
  endIndex: Math.min(
802
812
  N.length - 1,
@@ -812,28 +822,28 @@ function Dt(t, n, S, g) {
812
822
  d
813
823
  ]);
814
824
  Z(() => {
815
- const v = l.current;
816
- if (!(!v || !a))
817
- return v.addEventListener("scroll", k, {
825
+ const w = u.current;
826
+ if (!(!w || !a))
827
+ return w.addEventListener("scroll", P, {
818
828
  passive: !0
819
829
  }), () => {
820
- v.removeEventListener("scroll", k);
830
+ w.removeEventListener("scroll", P);
821
831
  };
822
- }, [k, a]);
823
- const P = ct(
824
- (v = "smooth") => {
825
- const V = l.current;
826
- if (!V) return;
832
+ }, [P, a]);
833
+ const k = ct(
834
+ (w = "smooth") => {
835
+ const E = u.current;
836
+ if (!E) return;
827
837
  F.current.isUserScrolling = !1, F.current.isNearBottom = !0, F.current.scrollUpCount = 0;
828
838
  const $ = () => {
829
839
  const D = (R = 0) => {
830
840
  if (R > 5) return;
831
- const L = V.scrollHeight, G = V.scrollTop, tt = V.clientHeight;
832
- G + tt >= L - 1 || (V.scrollTo({
841
+ const L = E.scrollHeight, G = E.scrollTop, tt = E.clientHeight;
842
+ G + tt >= L - 1 || (E.scrollTo({
833
843
  top: L,
834
- behavior: v
844
+ behavior: w
835
845
  }), setTimeout(() => {
836
- const et = V.scrollHeight, ht = V.scrollTop;
846
+ const et = E.scrollHeight, ht = E.scrollTop;
837
847
  (et !== L || ht + tt < et - 1) && D(R + 1);
838
848
  }, 50));
839
849
  };
@@ -846,19 +856,19 @@ function Dt(t, n, S, g) {
846
856
  []
847
857
  );
848
858
  return Z(() => {
849
- if (!a || !l.current) return;
850
- const v = l.current, V = F.current;
859
+ if (!a || !u.current) return;
860
+ const w = u.current, E = F.current;
851
861
  let $;
852
862
  const D = () => {
853
863
  clearTimeout($), $ = setTimeout(() => {
854
- !V.isUserScrolling && V.isNearBottom && P(
864
+ !E.isUserScrolling && E.isNearBottom && k(
855
865
  C.current ? "instant" : "smooth"
856
866
  );
857
867
  }, 100);
858
868
  }, R = new MutationObserver(() => {
859
- V.isUserScrolling || D();
869
+ E.isUserScrolling || D();
860
870
  });
861
- R.observe(v, {
871
+ R.observe(w, {
862
872
  childList: !0,
863
873
  subtree: !0,
864
874
  attributes: !0,
@@ -866,34 +876,34 @@ function Dt(t, n, S, g) {
866
876
  // More specific than just 'height'
867
877
  });
868
878
  const L = (G) => {
869
- G.target instanceof HTMLImageElement && !V.isUserScrolling && D();
879
+ G.target instanceof HTMLImageElement && !E.isUserScrolling && D();
870
880
  };
871
- return v.addEventListener("load", L, !0), C.current ? setTimeout(() => {
872
- P("instant");
881
+ return w.addEventListener("load", L, !0), C.current ? setTimeout(() => {
882
+ k("instant");
873
883
  }, 0) : D(), () => {
874
- clearTimeout($), R.disconnect(), v.removeEventListener("load", L, !0);
884
+ clearTimeout($), R.disconnect(), w.removeEventListener("load", L, !0);
875
885
  };
876
- }, [a, N.length, P]), {
886
+ }, [a, N.length, k]), {
877
887
  virtualState: gt(() => {
878
- const v = e.getState(), V = v.getShadowValue(
888
+ const w = e.getState(), E = w.getShadowValue(
879
889
  [t, ...i].join(".")
880
- ), $ = v.getShadowMetadata(t, i)?.arrayKeys || [], D = V.slice(
890
+ ), $ = w.getShadowMetadata(t, i)?.arrayKeys || [], D = E.slice(
881
891
  p.startIndex,
882
892
  p.endIndex + 1
883
893
  ), R = $.slice(
884
894
  p.startIndex,
885
895
  p.endIndex + 1
886
896
  );
887
- return u({
897
+ return c({
888
898
  currentState: D,
889
899
  path: i,
890
- componentId: M,
900
+ componentId: T,
891
901
  meta: { ...h, validIds: R }
892
902
  });
893
903
  }, [p.startIndex, p.endIndex, N.length]),
894
904
  virtualizerProps: {
895
905
  outer: {
896
- ref: l,
906
+ ref: u,
897
907
  style: {
898
908
  overflowY: "auto",
899
909
  height: "100%",
@@ -914,11 +924,11 @@ function Dt(t, n, S, g) {
914
924
  }
915
925
  }
916
926
  },
917
- scrollToBottom: P,
918
- scrollToIndex: (v, V = "smooth") => {
919
- if (l.current && N[v]) {
920
- const $ = x.current.get(N[v])?.offset || 0;
921
- l.current.scrollTo({ top: $, behavior: V });
927
+ scrollToBottom: k,
928
+ scrollToIndex: (w, E = "smooth") => {
929
+ if (u.current && N[w]) {
930
+ const $ = x.current.get(N[w])?.offset || 0;
931
+ u.current.scrollTo({ top: $, behavior: E });
922
932
  }
923
933
  }
924
934
  };
@@ -927,20 +937,20 @@ function Dt(t, n, S, g) {
927
937
  return (s) => {
928
938
  const [o, r] = K(
929
939
  h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys
930
- ), a = e.getState().getShadowValue(c, h?.validIds);
940
+ ), a = e.getState().getShadowValue(l, h?.validIds);
931
941
  if (!o)
932
942
  throw new Error("No array keys found for mapping");
933
- const d = u({
943
+ const d = c({
934
944
  currentState: a,
935
945
  path: i,
936
- componentId: M,
946
+ componentId: T,
937
947
  meta: h
938
948
  });
939
- return a.map((l, p) => {
940
- const E = o[p]?.split(".").slice(1), _ = u({
941
- currentState: l,
942
- path: E,
943
- componentId: M,
949
+ return a.map((u, p) => {
950
+ const V = o[p]?.split(".").slice(1), _ = c({
951
+ currentState: u,
952
+ path: V,
953
+ componentId: T,
944
954
  meta: h
945
955
  });
946
956
  return s(
@@ -958,7 +968,7 @@ function Dt(t, n, S, g) {
958
968
  _mapFn: s,
959
969
  _meta: h
960
970
  },
961
- rebuildStateShape: u
971
+ rebuildStateShape: c
962
972
  });
963
973
  if (m === "stateFind")
964
974
  return (s) => {
@@ -969,11 +979,11 @@ function Dt(t, n, S, g) {
969
979
  if (!a) continue;
970
980
  const d = e.getState().getShadowValue(a);
971
981
  if (s(d, r)) {
972
- const l = a.split(".").slice(1);
973
- return u({
982
+ const u = a.split(".").slice(1);
983
+ return c({
974
984
  currentState: d,
975
- path: l,
976
- componentId: M,
985
+ path: u,
986
+ componentId: T,
977
987
  meta: h
978
988
  // Pass along meta for potential further chaining
979
989
  });
@@ -986,12 +996,12 @@ function Dt(t, n, S, g) {
986
996
  if (!o)
987
997
  throw new Error("No array keys found for filtering.");
988
998
  const r = [], a = I.filter(
989
- (d, l) => s(d, l) ? (r.push(o[l]), !0) : !1
999
+ (d, u) => s(d, u) ? (r.push(o[u]), !0) : !1
990
1000
  );
991
- return u({
1001
+ return c({
992
1002
  currentState: a,
993
1003
  path: i,
994
- componentId: M,
1004
+ componentId: T,
995
1005
  meta: {
996
1006
  validIds: r,
997
1007
  transforms: [
@@ -1013,10 +1023,10 @@ function Dt(t, n, S, g) {
1013
1023
  item: a,
1014
1024
  key: o[d]
1015
1025
  }));
1016
- return r.sort((a, d) => s(a.item, d.item)).filter(Boolean), u({
1026
+ return r.sort((a, d) => s(a.item, d.item)).filter(Boolean), c({
1017
1027
  currentState: r.map((a) => a.item),
1018
1028
  path: i,
1019
- componentId: M,
1029
+ componentId: T,
1020
1030
  meta: {
1021
1031
  validIds: r.map((a) => a.key),
1022
1032
  transforms: [
@@ -1033,11 +1043,11 @@ function Dt(t, n, S, g) {
1033
1043
  flushInterval: r = 100,
1034
1044
  bufferStrategy: a = "accumulate",
1035
1045
  store: d,
1036
- onFlush: l
1046
+ onFlush: u
1037
1047
  } = s;
1038
- let p = [], E = !1, _ = null;
1048
+ let p = [], V = !1, _ = null;
1039
1049
  const O = (j) => {
1040
- if (!E) {
1050
+ if (!V) {
1041
1051
  if (a === "sliding" && p.length >= o)
1042
1052
  p.shift();
1043
1053
  else if (a === "dropping" && p.length >= o)
@@ -1049,8 +1059,8 @@ function Dt(t, n, S, g) {
1049
1059
  const j = [...p];
1050
1060
  if (p = [], d) {
1051
1061
  const b = d(j);
1052
- b !== void 0 && (Array.isArray(b) ? b : [b]).forEach((P) => {
1053
- n(P, i, {
1062
+ b !== void 0 && (Array.isArray(b) ? b : [b]).forEach((k) => {
1063
+ n(k, i, {
1054
1064
  updateType: "insert"
1055
1065
  });
1056
1066
  });
@@ -1060,7 +1070,7 @@ function Dt(t, n, S, g) {
1060
1070
  updateType: "insert"
1061
1071
  });
1062
1072
  });
1063
- l?.(j);
1073
+ u?.(j);
1064
1074
  };
1065
1075
  r > 0 && (_ = setInterval(C, r));
1066
1076
  const F = rt(), x = e.getState().getShadowMetadata(t, i) || {}, N = x.streams || /* @__PURE__ */ new Map();
@@ -1072,10 +1082,10 @@ function Dt(t, n, S, g) {
1072
1082
  writeMany: (j) => j.forEach(O),
1073
1083
  flush: () => C(),
1074
1084
  pause: () => {
1075
- E = !0;
1085
+ V = !0;
1076
1086
  },
1077
1087
  resume: () => {
1078
- E = !1, p.length > 0 && C();
1088
+ V = !1, p.length > 0 && C();
1079
1089
  },
1080
1090
  close: () => {
1081
1091
  C(), _ && clearInterval(_);
@@ -1086,7 +1096,7 @@ function Dt(t, n, S, g) {
1086
1096
  };
1087
1097
  if (m === "stateList")
1088
1098
  return (s) => /* @__PURE__ */ ot(() => {
1089
- const r = q(/* @__PURE__ */ new Map()), a = h?.transforms && h.transforms.length > 0 ? `${M}-${Bt(h.transforms)}` : `${M}-base`, [d, l] = K({}), { validIds: p, arrayValues: E } = gt(() => {
1099
+ const r = q(/* @__PURE__ */ new Map()), a = h?.transforms && h.transforms.length > 0 ? `${T}-${Bt(h.transforms)}` : `${T}-base`, [d, u] = K({}), { validIds: p, arrayValues: V } = gt(() => {
1090
1100
  const O = e.getState().getShadowMetadata(t, i)?.transformCaches?.get(a);
1091
1101
  let C;
1092
1102
  O && O.validIds ? C = O.validIds : (C = It(
@@ -1098,37 +1108,37 @@ function Dt(t, n, S, g) {
1098
1108
  computedAt: Date.now(),
1099
1109
  transforms: h?.transforms || []
1100
1110
  }));
1101
- const F = e.getState().getShadowValue(c, C);
1111
+ const F = e.getState().getShadowValue(l, C);
1102
1112
  return {
1103
1113
  validIds: C,
1104
1114
  arrayValues: F || []
1105
1115
  };
1106
1116
  }, [a, d]);
1107
1117
  if (Z(() => {
1108
- const O = e.getState().subscribeToPath(c, (C) => {
1118
+ const O = e.getState().subscribeToPath(l, (C) => {
1109
1119
  if (C.type === "GET_SELECTED")
1110
1120
  return;
1111
1121
  const x = e.getState().getShadowMetadata(t, i)?.transformCaches;
1112
1122
  if (x)
1113
1123
  for (const N of x.keys())
1114
- N.startsWith(M) && x.delete(N);
1115
- (C.type === "INSERT" || C.type === "REMOVE" || C.type === "CLEAR_SELECTION") && l({});
1124
+ N.startsWith(T) && x.delete(N);
1125
+ (C.type === "INSERT" || C.type === "REMOVE" || C.type === "CLEAR_SELECTION") && u({});
1116
1126
  });
1117
1127
  return () => {
1118
1128
  O();
1119
1129
  };
1120
- }, [M, c]), !Array.isArray(E))
1130
+ }, [T, l]), !Array.isArray(V))
1121
1131
  return null;
1122
- const _ = u({
1123
- currentState: E,
1132
+ const _ = c({
1133
+ currentState: V,
1124
1134
  path: i,
1125
- componentId: M,
1135
+ componentId: T,
1126
1136
  meta: {
1127
1137
  ...h,
1128
1138
  validIds: p
1129
1139
  }
1130
1140
  });
1131
- return /* @__PURE__ */ ot(Ot, { children: E.map((O, C) => {
1141
+ return /* @__PURE__ */ ot(Ot, { children: V.map((O, C) => {
1132
1142
  const F = p[C];
1133
1143
  if (!F)
1134
1144
  return null;
@@ -1142,7 +1152,7 @@ function Dt(t, n, S, g) {
1142
1152
  itemPath: N,
1143
1153
  localIndex: C,
1144
1154
  arraySetter: _,
1145
- rebuildStateShape: u,
1155
+ rebuildStateShape: c,
1146
1156
  renderFn: s
1147
1157
  });
1148
1158
  }) });
@@ -1150,28 +1160,28 @@ function Dt(t, n, S, g) {
1150
1160
  if (m === "stateFlattenOn")
1151
1161
  return (s) => {
1152
1162
  const o = I;
1153
- y.clear(), w++;
1163
+ y.clear(), v++;
1154
1164
  const r = o.flatMap(
1155
1165
  (a) => a[s] ?? []
1156
1166
  );
1157
- return u({
1167
+ return c({
1158
1168
  currentState: r,
1159
1169
  path: [...i, "[*]", s],
1160
- componentId: M,
1170
+ componentId: T,
1161
1171
  meta: h
1162
1172
  });
1163
1173
  };
1164
1174
  if (m === "index")
1165
1175
  return (s) => {
1166
1176
  const r = e.getState().getShadowMetadata(t, i)?.arrayKeys?.filter(
1167
- (l) => !h?.validIds || h?.validIds && h?.validIds?.includes(l)
1177
+ (u) => !h?.validIds || h?.validIds && h?.validIds?.includes(u)
1168
1178
  )?.[s];
1169
1179
  if (!r) return;
1170
1180
  const a = e.getState().getShadowValue(r, h?.validIds);
1171
- return u({
1181
+ return c({
1172
1182
  currentState: a,
1173
1183
  path: r.split(".").slice(1),
1174
- componentId: M,
1184
+ componentId: T,
1175
1185
  meta: h
1176
1186
  });
1177
1187
  };
@@ -1180,36 +1190,36 @@ function Dt(t, n, S, g) {
1180
1190
  const s = e.getState().getShadowValue(t, i);
1181
1191
  if (s.length === 0) return;
1182
1192
  const o = s.length - 1, r = s[o], a = [...i, o.toString()];
1183
- return u({
1193
+ return c({
1184
1194
  currentState: r,
1185
1195
  path: a,
1186
- componentId: M,
1196
+ componentId: T,
1187
1197
  meta: h
1188
1198
  });
1189
1199
  };
1190
1200
  if (m === "insert")
1191
- return (s, o) => (n(s, i, { updateType: "insert" }), u({
1201
+ return (s, o) => (n(s, i, { updateType: "insert" }), c({
1192
1202
  currentState: e.getState().getShadowValue(t, i),
1193
1203
  path: i,
1194
- componentId: M,
1204
+ componentId: T,
1195
1205
  meta: h
1196
1206
  }));
1197
1207
  if (m === "uniqueInsert")
1198
1208
  return (s, o, r) => {
1199
1209
  const a = e.getState().getShadowValue(t, i), d = at(s) ? s(a) : s;
1200
- let l = null;
1201
- if (!a.some((E) => {
1210
+ let u = null;
1211
+ if (!a.some((V) => {
1202
1212
  const _ = o ? o.every(
1203
- (O) => st(E[O], d[O])
1204
- ) : st(E, d);
1205
- return _ && (l = E), _;
1213
+ (O) => st(V[O], d[O])
1214
+ ) : st(V, d);
1215
+ return _ && (u = V), _;
1206
1216
  }))
1207
- T(i), n(d, i, { updateType: "insert" });
1208
- else if (r && l) {
1209
- const E = r(l), _ = a.map(
1210
- (O) => st(O, l) ? E : O
1217
+ M(i), n(d, i, { updateType: "insert" });
1218
+ else if (r && u) {
1219
+ const V = r(u), _ = a.map(
1220
+ (O) => st(O, u) ? V : O
1211
1221
  );
1212
- T(i), n(_, i, {
1222
+ M(i), n(_, i, {
1213
1223
  updateType: "update"
1214
1224
  });
1215
1225
  }
@@ -1220,8 +1230,8 @@ function Dt(t, n, S, g) {
1220
1230
  if (!r || r.length === 0) return;
1221
1231
  const a = s == -1 ? r.length - 1 : s !== void 0 ? s : r.length - 1, d = r[a];
1222
1232
  if (!d) return;
1223
- const l = d.split(".").slice(1);
1224
- n(I, l, {
1233
+ const u = d.split(".").slice(1);
1234
+ n(I, u, {
1225
1235
  updateType: "cut"
1226
1236
  });
1227
1237
  };
@@ -1233,12 +1243,12 @@ function Dt(t, n, S, g) {
1233
1243
  h?.transforms
1234
1244
  );
1235
1245
  if (!s || s.length === 0) return;
1236
- const o = e.getState().selectedIndicesMap.get(c);
1246
+ const o = e.getState().selectedIndicesMap.get(l);
1237
1247
  let r = s.findIndex(
1238
- (l) => l === o
1248
+ (u) => u === o
1239
1249
  );
1240
1250
  const a = s[r == -1 ? s.length - 1 : r]?.split(".").slice(1);
1241
- e.getState().clearSelectedIndex({ arrayKey: c });
1251
+ e.getState().clearSelectedIndex({ arrayKey: l });
1242
1252
  const d = a?.slice(0, -1);
1243
1253
  ft(t, d), n(I, a, {
1244
1254
  updateType: "cut"
@@ -1265,8 +1275,8 @@ function Dt(t, n, S, g) {
1265
1275
  if (!r) return;
1266
1276
  let a = null;
1267
1277
  for (const d of r) {
1268
- const l = e.getState().getShadowValue(d);
1269
- if (console.log("itemValue sdasdasdasd", l), l === s) {
1278
+ const u = e.getState().getShadowValue(d);
1279
+ if (console.log("itemValue sdasdasdasd", u), u === s) {
1270
1280
  a = d;
1271
1281
  break;
1272
1282
  }
@@ -1285,17 +1295,17 @@ function Dt(t, n, S, g) {
1285
1295
  if (!r)
1286
1296
  throw new Error("No array keys found for sorting");
1287
1297
  let a = null, d = [];
1288
- for (const l of r) {
1289
- let p = e.getState().getShadowValue(l, h?.validIds);
1298
+ for (const u of r) {
1299
+ let p = e.getState().getShadowValue(u, h?.validIds);
1290
1300
  if (p && p[s] === o) {
1291
- a = p, d = l.split(".").slice(1);
1301
+ a = p, d = u.split(".").slice(1);
1292
1302
  break;
1293
1303
  }
1294
1304
  }
1295
- return u({
1305
+ return c({
1296
1306
  currentState: a,
1297
1307
  path: d,
1298
- componentId: M,
1308
+ componentId: T,
1299
1309
  meta: h
1300
1310
  });
1301
1311
  };
@@ -1307,9 +1317,9 @@ function Dt(t, n, S, g) {
1307
1317
  };
1308
1318
  }
1309
1319
  if (m === "get")
1310
- return () => (Et(t, M, i), e.getState().getShadowValue(c, h?.validIds));
1320
+ return () => (Vt(t, T, i), e.getState().getShadowValue(l, h?.validIds));
1311
1321
  if (m === "getState")
1312
- return () => e.getState().getShadowValue(c, h?.validIds);
1322
+ return () => e.getState().getShadowValue(l, h?.validIds);
1313
1323
  if (m === "$derive")
1314
1324
  return (s) => bt({
1315
1325
  _stateKey: t,
@@ -1347,7 +1357,7 @@ function Dt(t, n, S, g) {
1347
1357
  e.getState().selectedIndicesMap.get(o) === r ? e.getState().clearSelectedIndex({ arrayKey: o }) : e.getState().setSelectedIndex(o, r);
1348
1358
  };
1349
1359
  if (m === "_componentId")
1350
- return M;
1360
+ return T;
1351
1361
  if (i.length == 0) {
1352
1362
  if (m === "addValidation")
1353
1363
  return (s) => {
@@ -1362,14 +1372,14 @@ function Dt(t, n, S, g) {
1362
1372
  return (s) => {
1363
1373
  const o = e.getState(), r = o.getShadowMetadata(t, []);
1364
1374
  if (!r?.components) return;
1365
- const a = (l) => !l || l === "/" ? [] : l.split("/").slice(1).map((p) => p.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
1366
- for (const l of s) {
1367
- const p = a(l.path);
1368
- switch (l.op) {
1375
+ const a = (u) => !u || u === "/" ? [] : u.split("/").slice(1).map((p) => p.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
1376
+ for (const u of s) {
1377
+ const p = a(u.path);
1378
+ switch (u.op) {
1369
1379
  case "add":
1370
1380
  case "replace": {
1371
- const { value: E } = l;
1372
- o.updateShadowAtPath(t, p, E), o.markAsDirty(t, p, { bubble: !0 });
1381
+ const { value: V } = u;
1382
+ o.updateShadowAtPath(t, p, V), o.markAsDirty(t, p, { bubble: !0 });
1373
1383
  let _ = [...p];
1374
1384
  for (; ; ) {
1375
1385
  const O = o.getShadowMetadata(
@@ -1387,9 +1397,9 @@ function Dt(t, n, S, g) {
1387
1397
  break;
1388
1398
  }
1389
1399
  case "remove": {
1390
- const E = p.slice(0, -1);
1391
- o.removeShadowArrayElement(t, p), o.markAsDirty(t, E, { bubble: !0 });
1392
- let _ = [...E];
1400
+ const V = p.slice(0, -1);
1401
+ o.removeShadowArrayElement(t, p), o.markAsDirty(t, V, { bubble: !0 });
1402
+ let _ = [...V];
1393
1403
  for (; ; ) {
1394
1404
  const O = o.getShadowMetadata(
1395
1405
  t,
@@ -1418,11 +1428,11 @@ function Dt(t, n, S, g) {
1418
1428
  ut(s.key);
1419
1429
  const r = e.getState().getShadowValue(t), a = o.safeParse(r);
1420
1430
  return a.success ? !0 : ("issues" in a.error ? a.error.issues.forEach((d) => {
1421
- const l = [s.key, ...d.path].join(".");
1422
- pt(l, d.message);
1431
+ const u = [s.key, ...d.path].join(".");
1432
+ pt(u, d.message);
1423
1433
  }) : a.error.errors.forEach((d) => {
1424
- const l = [s.key, ...d.path].join(".");
1425
- pt(l, d.message);
1434
+ const u = [s.key, ...d.path].join(".");
1435
+ pt(u, d.message);
1426
1436
  }), it(t), !1);
1427
1437
  };
1428
1438
  if (m === "getComponents")
@@ -1437,7 +1447,7 @@ function Dt(t, n, S, g) {
1437
1447
  children: s,
1438
1448
  hideMessage: o
1439
1449
  }) => /* @__PURE__ */ ot(
1440
- kt,
1450
+ Pt,
1441
1451
  {
1442
1452
  formOpts: o ? { validation: { message: "" } } : void 0,
1443
1453
  path: i,
@@ -1486,24 +1496,24 @@ function Dt(t, n, S, g) {
1486
1496
  {
1487
1497
  stateKey: t,
1488
1498
  path: i,
1489
- rebuildStateShape: u,
1499
+ rebuildStateShape: c,
1490
1500
  setState: n,
1491
1501
  formOpts: o,
1492
1502
  renderFn: s
1493
1503
  }
1494
1504
  );
1495
1505
  const Q = [...i, m], X = e.getState().getShadowValue(t, Q);
1496
- return u({
1506
+ return c({
1497
1507
  currentState: X,
1498
1508
  path: Q,
1499
- componentId: M,
1509
+ componentId: T,
1500
1510
  meta: h
1501
1511
  });
1502
1512
  }
1503
1513
  }, H = new Proxy(B, J);
1504
1514
  return y.set(z, {
1505
1515
  proxy: H,
1506
- stateVersion: w
1516
+ stateVersion: v
1507
1517
  }), H;
1508
1518
  }
1509
1519
  const f = {
@@ -1515,28 +1525,28 @@ function Dt(t, n, S, g) {
1515
1525
  i?.key && ut(i.key), I?.validationKey && ut(I.validationKey);
1516
1526
  const h = e.getState().getShadowMetadata(t, []);
1517
1527
  h?.stateSource === "server" && h.baseServerState ? h.baseServerState : e.getState().initialStateGlobal[t];
1518
- const M = e.getState().initialStateGlobal[t];
1519
- e.getState().clearSelectedIndexesForState(t), y.clear(), w++, e.getState().initializeShadowState(t, M), u({
1520
- currentState: M,
1528
+ const T = e.getState().initialStateGlobal[t];
1529
+ e.getState().clearSelectedIndexesForState(t), y.clear(), v++, e.getState().initializeShadowState(t, T), c({
1530
+ currentState: T,
1521
1531
  path: [],
1522
1532
  componentId: S
1523
1533
  });
1524
- const z = nt(t), c = at(z?.localStorage?.key) ? z?.localStorage?.key(M) : z?.localStorage?.key, B = `${g}-${t}-${c}`;
1534
+ const z = nt(t), l = at(z?.localStorage?.key) ? z?.localStorage?.key(T) : z?.localStorage?.key, B = `${g}-${t}-${l}`;
1525
1535
  B && localStorage.removeItem(B);
1526
1536
  const J = e.getState().getShadowMetadata(t, []);
1527
1537
  return J && J?.components?.forEach((H) => {
1528
1538
  H.forceUpdate();
1529
- }), M;
1539
+ }), T;
1530
1540
  },
1531
1541
  updateInitialState: (I) => {
1532
- y.clear(), w++;
1542
+ y.clear(), v++;
1533
1543
  const i = Dt(
1534
1544
  t,
1535
1545
  n,
1536
1546
  S,
1537
1547
  g
1538
- ), h = e.getState().initialStateGlobal[t], M = nt(t), z = at(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, c = `${g}-${t}-${z}`;
1539
- return localStorage.getItem(c) && localStorage.removeItem(c), Rt(() => {
1548
+ ), h = e.getState().initialStateGlobal[t], T = nt(t), z = at(T?.localStorage?.key) ? T?.localStorage?.key(h) : T?.localStorage?.key, l = `${g}-${t}-${z}`;
1549
+ return localStorage.getItem(l) && localStorage.removeItem(l), Rt(() => {
1540
1550
  _t(t, I), e.getState().initializeShadowState(t, I);
1541
1551
  const B = e.getState().getShadowMetadata(t, []);
1542
1552
  B && B?.components?.forEach((J) => {
@@ -1547,7 +1557,7 @@ function Dt(t, n, S, g) {
1547
1557
  };
1548
1558
  }
1549
1559
  };
1550
- return u({
1560
+ return c({
1551
1561
  currentState: e.getState().getShadowValue(t, []),
1552
1562
  componentId: S,
1553
1563
  path: []
@@ -1560,16 +1570,16 @@ function qt({
1560
1570
  proxy: t,
1561
1571
  rebuildStateShape: n
1562
1572
  }) {
1563
- const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1), w = q(/* @__PURE__ */ new Map());
1573
+ const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1), v = q(/* @__PURE__ */ new Map());
1564
1574
  Z(() => {
1565
- const u = S.current;
1566
- if (!u || y.current) return;
1575
+ const c = S.current;
1576
+ if (!c || y.current) return;
1567
1577
  const f = setTimeout(() => {
1568
1578
  const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, I = A.mapWrappers || [];
1569
1579
  I.push({
1570
1580
  instanceId: g.current,
1571
1581
  mapFn: t._mapFn,
1572
- containerRef: u,
1582
+ containerRef: c,
1573
1583
  rebuildStateShape: n,
1574
1584
  path: t._path,
1575
1585
  componentId: g.current,
@@ -1577,7 +1587,7 @@ function qt({
1577
1587
  }), e.getState().setShadowMetadata(t._stateKey, t._path, {
1578
1588
  ...A,
1579
1589
  mapWrappers: I
1580
- }), y.current = !0, T();
1590
+ }), y.current = !0, M();
1581
1591
  }, 0);
1582
1592
  return () => {
1583
1593
  if (clearTimeout(f), g.current) {
@@ -1586,12 +1596,12 @@ function qt({
1586
1596
  (I) => I.instanceId !== g.current
1587
1597
  ), e.getState().setShadowMetadata(t._stateKey, t._path, A));
1588
1598
  }
1589
- w.current.forEach((A) => A.unmount());
1599
+ v.current.forEach((A) => A.unmount());
1590
1600
  };
1591
1601
  }, []);
1592
- const T = () => {
1593
- const u = S.current;
1594
- if (!u) return;
1602
+ const M = () => {
1603
+ const c = S.current;
1604
+ if (!c) return;
1595
1605
  const f = e.getState().getShadowValue(
1596
1606
  [t._stateKey, ...t._path].join("."),
1597
1607
  t._meta?.validIds
@@ -1604,13 +1614,13 @@ function qt({
1604
1614
  meta: t._meta
1605
1615
  });
1606
1616
  f.forEach((i, h) => {
1607
- const M = A[h];
1608
- if (!M) return;
1609
- const z = rt(), c = document.createElement("div");
1610
- c.setAttribute("data-item-path", M), u.appendChild(c);
1611
- const B = At(c);
1612
- w.current.set(M, B);
1613
- const J = M.split(".").slice(1);
1617
+ const T = A[h];
1618
+ if (!T) return;
1619
+ const z = rt(), l = document.createElement("div");
1620
+ l.setAttribute("data-item-path", T), c.appendChild(l);
1621
+ const B = At(l);
1622
+ v.current.set(T, B);
1623
+ const J = T.split(".").slice(1);
1614
1624
  B.render(
1615
1625
  lt(Mt, {
1616
1626
  stateKey: t._stateKey,
@@ -1629,47 +1639,47 @@ function qt({
1629
1639
  function Gt({
1630
1640
  proxy: t
1631
1641
  }) {
1632
- const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, w = e.getState().getShadowValue(
1642
+ const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, v = e.getState().getShadowValue(
1633
1643
  [t._stateKey, ...t._path].join("."),
1634
1644
  t._meta?.validIds
1635
1645
  );
1636
1646
  return Z(() => {
1637
- const T = n.current;
1638
- if (!T || g.current) return;
1639
- const u = setTimeout(() => {
1640
- if (!T.parentElement) {
1647
+ const M = n.current;
1648
+ if (!M || g.current) return;
1649
+ const c = setTimeout(() => {
1650
+ if (!M.parentElement) {
1641
1651
  console.warn("Parent element not found for signal", y);
1642
1652
  return;
1643
1653
  }
1644
- const f = T.parentElement, I = Array.from(f.childNodes).indexOf(T);
1654
+ const f = M.parentElement, I = Array.from(f.childNodes).indexOf(M);
1645
1655
  let i = f.getAttribute("data-parent-id");
1646
1656
  i || (i = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", i)), S.current = `instance-${crypto.randomUUID()}`;
1647
- const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, M = h.signals || [];
1648
- M.push({
1657
+ const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, T = h.signals || [];
1658
+ T.push({
1649
1659
  instanceId: S.current,
1650
1660
  parentId: i,
1651
1661
  position: I,
1652
1662
  effect: t._effect
1653
1663
  }), e.getState().setShadowMetadata(t._stateKey, t._path, {
1654
1664
  ...h,
1655
- signals: M
1665
+ signals: T
1656
1666
  });
1657
- let z = w;
1667
+ let z = v;
1658
1668
  if (t._effect)
1659
1669
  try {
1660
1670
  z = new Function(
1661
1671
  "state",
1662
1672
  `return (${t._effect})(state)`
1663
- )(w);
1673
+ )(v);
1664
1674
  } catch (B) {
1665
1675
  console.error("Error evaluating effect function:", B);
1666
1676
  }
1667
1677
  z !== null && typeof z == "object" && (z = JSON.stringify(z));
1668
- const c = document.createTextNode(String(z ?? ""));
1669
- T.replaceWith(c), g.current = !0;
1678
+ const l = document.createTextNode(String(z ?? ""));
1679
+ M.replaceWith(l), g.current = !0;
1670
1680
  }, 0);
1671
1681
  return () => {
1672
- if (clearTimeout(u), S.current) {
1682
+ if (clearTimeout(c), S.current) {
1673
1683
  const f = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
1674
1684
  f.signals && (f.signals = f.signals.filter(
1675
1685
  (A) => A.instanceId !== S.current
@@ -1698,14 +1708,14 @@ const Mt = Ut(
1698
1708
  return;
1699
1709
  }
1700
1710
  let y = 0;
1701
- const w = () => {
1711
+ const v = () => {
1702
1712
  y++, y === g.length && S(!0);
1703
1713
  };
1704
- return g.forEach((T) => {
1705
- T.complete ? w() : (T.addEventListener("load", w), T.addEventListener("error", w));
1714
+ return g.forEach((M) => {
1715
+ M.complete ? v() : (M.addEventListener("load", v), M.addEventListener("error", v));
1706
1716
  }), () => {
1707
- g.forEach((T) => {
1708
- T.removeEventListener("load", w), T.removeEventListener("error", w);
1717
+ g.forEach((M) => {
1718
+ M.removeEventListener("load", v), M.removeEventListener("error", v);
1709
1719
  });
1710
1720
  };
1711
1721
  }, [t.current]), n;
@@ -1716,11 +1726,11 @@ function Yt({
1716
1726
  itemPath: S,
1717
1727
  localIndex: g,
1718
1728
  arraySetter: y,
1719
- rebuildStateShape: w,
1720
- renderFn: T
1729
+ rebuildStateShape: v,
1730
+ renderFn: M
1721
1731
  }) {
1722
- const [, u] = K({}), { ref: f, inView: A } = jt(), I = q(null), i = Jt(I), h = q(!1), M = [t, ...S].join(".");
1723
- $t(t, n, u);
1732
+ const [, c] = K({}), { ref: f, inView: A } = jt(), I = q(null), i = Jt(I), h = q(!1), T = [t, ...S].join(".");
1733
+ $t(t, n, c);
1724
1734
  const z = ct(
1725
1735
  (W) => {
1726
1736
  I.current = W, f(W);
@@ -1728,8 +1738,8 @@ function Yt({
1728
1738
  [f]
1729
1739
  );
1730
1740
  Z(() => {
1731
- e.getState().subscribeToPath(M, (W) => {
1732
- u({});
1741
+ e.getState().subscribeToPath(T, (W) => {
1742
+ c({});
1733
1743
  });
1734
1744
  }, []), Z(() => {
1735
1745
  if (!A || !i || h.current)
@@ -1752,14 +1762,14 @@ function Yt({
1752
1762
  });
1753
1763
  }
1754
1764
  }, [A, i, t, S]);
1755
- const c = [t, ...S].join("."), B = e.getState().getShadowValue(c);
1765
+ const l = [t, ...S].join("."), B = e.getState().getShadowValue(l);
1756
1766
  if (B === void 0)
1757
1767
  return null;
1758
- const J = w({
1768
+ const J = v({
1759
1769
  currentState: B,
1760
1770
  path: S,
1761
1771
  componentId: n
1762
- }), H = T(J, g, y);
1772
+ }), H = M(J, g, y);
1763
1773
  return /* @__PURE__ */ ot("div", { ref: z, children: H });
1764
1774
  }
1765
1775
  function Zt({
@@ -1768,27 +1778,27 @@ function Zt({
1768
1778
  rebuildStateShape: S,
1769
1779
  renderFn: g,
1770
1780
  formOpts: y,
1771
- setState: w
1781
+ setState: v
1772
1782
  }) {
1773
- const [T] = K(() => rt()), [, u] = K({}), f = [t, ...n].join(".");
1774
- $t(t, T, u);
1775
- const A = e.getState().getShadowValue(f), [I, i] = K(A), h = q(!1), M = q(null);
1783
+ const [M] = K(() => rt()), [, c] = K({}), f = [t, ...n].join(".");
1784
+ $t(t, M, c);
1785
+ const A = e.getState().getShadowValue(f), [I, i] = K(A), h = q(!1), T = q(null);
1776
1786
  Z(() => {
1777
1787
  !h.current && !st(A, I) && i(A);
1778
1788
  }, [A]), Z(() => {
1779
1789
  const H = e.getState().subscribeToPath(f, (W) => {
1780
- !h.current && I !== W && u({});
1790
+ !h.current && I !== W && c({});
1781
1791
  });
1782
1792
  return () => {
1783
- H(), M.current && (clearTimeout(M.current), h.current = !1);
1793
+ H(), T.current && (clearTimeout(T.current), h.current = !1);
1784
1794
  };
1785
1795
  }, []);
1786
1796
  const z = ct(
1787
1797
  (H) => {
1788
- typeof A === "number" && typeof H == "string" && (H = H === "" ? 0 : Number(H)), i(H), h.current = !0, M.current && clearTimeout(M.current);
1798
+ typeof A === "number" && typeof H == "string" && (H = H === "" ? 0 : Number(H)), i(H), h.current = !0, T.current && clearTimeout(T.current);
1789
1799
  const m = y?.debounceTime ?? 200;
1790
- M.current = setTimeout(() => {
1791
- h.current = !1, w(H, n, { updateType: "update" });
1800
+ T.current = setTimeout(() => {
1801
+ h.current = !1, v(H, n, { updateType: "update" });
1792
1802
  const { getInitialOptions: Y, setShadowMetadata: Q, getShadowMetadata: X } = e.getState(), s = Y(t)?.validation, o = s?.zodSchemaV4 || s?.zodSchemaV3;
1793
1803
  if (o) {
1794
1804
  const r = e.getState().getShadowValue(t), a = o.safeParse(r), d = X(t, n) || {};
@@ -1802,7 +1812,7 @@ function Zt({
1802
1812
  });
1803
1813
  else {
1804
1814
  const p = ("issues" in a.error ? a.error.issues : a.error.errors).filter(
1805
- (E) => JSON.stringify(E.path) === JSON.stringify(n)
1815
+ (V) => JSON.stringify(V.path) === JSON.stringify(n)
1806
1816
  );
1807
1817
  p.length > 0 ? Q(t, n, {
1808
1818
  ...d,
@@ -1820,11 +1830,11 @@ function Zt({
1820
1830
  });
1821
1831
  }
1822
1832
  }
1823
- }, m), u({});
1833
+ }, m), c({});
1824
1834
  },
1825
- [w, n, y?.debounceTime, t]
1826
- ), c = ct(async () => {
1827
- console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, w(I, n, { updateType: "update" }));
1835
+ [v, n, y?.debounceTime, t]
1836
+ ), l = ct(async () => {
1837
+ console.log("handleBlur triggered"), T.current && (clearTimeout(T.current), T.current = null, h.current = !1, v(I, n, { updateType: "update" }));
1828
1838
  const { getInitialOptions: H } = e.getState(), W = H(t)?.validation, m = W?.zodSchemaV4 || W?.zodSchemaV3;
1829
1839
  if (!m) return;
1830
1840
  const Y = e.getState().getShadowMetadata(t, n);
@@ -1852,11 +1862,11 @@ function Zt({
1852
1862
  console.log("Detected array path with ULID");
1853
1863
  const d = n[0].startsWith("id:") ? [] : n.slice(0, -1);
1854
1864
  console.log("Parent path:", d);
1855
- const l = e.getState().getShadowMetadata(t, d);
1856
- if (console.log("Array metadata:", l), l?.arrayKeys) {
1857
- const p = [t, ...n.slice(0, -1)].join("."), E = l.arrayKeys.indexOf(p);
1858
- console.log("Item key:", p, "Index:", E);
1859
- const _ = [...d, E, ...n.slice(-1)], O = JSON.stringify(r.path) === JSON.stringify(_);
1865
+ const u = e.getState().getShadowMetadata(t, d);
1866
+ if (console.log("Array metadata:", u), u?.arrayKeys) {
1867
+ const p = [t, ...n.slice(0, -1)].join("."), V = u.arrayKeys.indexOf(p);
1868
+ console.log("Item key:", p, "Index:", V);
1869
+ const _ = [...d, V, ...n.slice(-1)], O = JSON.stringify(r.path) === JSON.stringify(_);
1860
1870
  return console.log("Zod path comparison:", {
1861
1871
  zodPath: _,
1862
1872
  errorPath: r.path,
@@ -1880,11 +1890,11 @@ function Zt({
1880
1890
  }
1881
1891
  });
1882
1892
  }
1883
- u({});
1884
- }, [t, n, I, w]), B = S({
1893
+ c({});
1894
+ }, [t, n, I, v]), B = S({
1885
1895
  currentState: A,
1886
1896
  path: n,
1887
- componentId: T
1897
+ componentId: M
1888
1898
  }), J = new Proxy(B, {
1889
1899
  get(H, W) {
1890
1900
  return W === "inputProps" ? {
@@ -1893,23 +1903,23 @@ function Zt({
1893
1903
  z(m.target.value);
1894
1904
  },
1895
1905
  // 5. Wire the new onBlur handler to the input props.
1896
- onBlur: c,
1906
+ onBlur: l,
1897
1907
  ref: vt.getState().getFormRef(t + "." + n.join("."))
1898
1908
  } : H[W];
1899
1909
  }
1900
1910
  });
1901
- return /* @__PURE__ */ ot(kt, { formOpts: y, path: n, stateKey: t, children: g(J) });
1911
+ return /* @__PURE__ */ ot(Pt, { formOpts: y, path: n, stateKey: t, children: g(J) });
1902
1912
  }
1903
1913
  function $t(t, n, S) {
1904
1914
  const g = `${t}////${n}`;
1905
1915
  dt(() => {
1906
- const { registerComponent: y, unregisterComponent: w } = e.getState();
1916
+ const { registerComponent: y, unregisterComponent: v } = e.getState();
1907
1917
  return y(t, g, {
1908
1918
  forceUpdate: () => S({}),
1909
1919
  paths: /* @__PURE__ */ new Set(),
1910
1920
  reactiveType: ["component"]
1911
1921
  }), () => {
1912
- w(t, g);
1922
+ v(t, g);
1913
1923
  };
1914
1924
  }, [t, g]);
1915
1925
  }