cogsbox-state 0.5.436 → 0.5.437

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