cogsbox-state 0.5.448 → 0.5.450

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