cogsbox-state 0.5.453 → 0.5.454

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