cogsbox-state 0.5.462 → 0.5.464

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