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