cogsbox-state 0.5.455 → 0.5.457

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