cogsbox-state 0.5.454 → 0.5.456

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