cogsbox-state 0.5.424 → 0.5.426

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.
@@ -2,17 +2,17 @@
2
2
  import { jsx as pt } from "react/jsx-runtime";
3
3
  import { useState as it, useRef as q, useEffect as rt, useLayoutEffect as Ct, useMemo as Et, createElement as dt, useSyncExternalStore as Ut, startTransition as Ft, useCallback as St } from "react";
4
4
  import { transformStateFunc as Dt, isDeepEqual as Y, isFunction as tt, getNestedValue as Z, getDifferences as Tt, debounce as Lt } from "./utility.js";
5
- import { pushFunc as wt, updateFn as lt, cutFunc as ft, ValidationWrapper as Gt, FormControlComponent as Wt } from "./Functions.jsx";
5
+ import { pushFunc as wt, updateFn as lt, cutFunc as gt, ValidationWrapper as Gt, FormControlComponent as Wt } from "./Functions.jsx";
6
6
  import Ht from "superjson";
7
- import { v4 as kt } from "uuid";
7
+ import { v4 as At } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as o, formRefStore as bt } from "./store.js";
9
+ import { getGlobalStore as r, formRefStore as bt } from "./store.js";
10
10
  import { useCogsConfig as _t } from "./CogsStateClient.jsx";
11
11
  import { applyPatch as zt } from "fast-json-patch";
12
12
  import Bt from "react-use-measure";
13
13
  function Vt(t, i) {
14
- const S = o.getState().getInitialOptions, u = o.getState().setInitialStateOptions, h = S(t) || {};
15
- u(t, {
14
+ const S = r.getState().getInitialOptions, f = r.getState().setInitialStateOptions, h = S(t) || {};
15
+ f(t, {
16
16
  ...h,
17
17
  ...i
18
18
  });
@@ -22,40 +22,40 @@ function $t({
22
22
  options: i,
23
23
  initialOptionsPart: S
24
24
  }) {
25
- const u = st(t) || {}, h = S[t] || {}, x = o.getState().setInitialStateOptions, w = { ...h, ...u };
26
- let I = !1;
25
+ const f = st(t) || {}, h = S[t] || {}, x = r.getState().setInitialStateOptions, p = { ...h, ...f };
26
+ let y = !1;
27
27
  if (i)
28
28
  for (const s in i)
29
- w.hasOwnProperty(s) ? (s == "localStorage" && i[s] && w[s].key !== i[s]?.key && (I = !0, w[s] = i[s]), s == "initialState" && i[s] && w[s] !== i[s] && // Different references
30
- !Y(w[s], i[s]) && (I = !0, w[s] = i[s])) : (I = !0, w[s] = i[s]);
31
- I && x(t, w);
29
+ p.hasOwnProperty(s) ? (s == "localStorage" && i[s] && p[s].key !== i[s]?.key && (y = !0, p[s] = i[s]), s == "initialState" && i[s] && p[s] !== i[s] && // Different references
30
+ !Y(p[s], i[s]) && (y = !0, p[s] = i[s])) : (y = !0, p[s] = i[s]);
31
+ y && x(t, p);
32
32
  }
33
- function fe(t, { formElements: i, validation: S }) {
33
+ function ge(t, { formElements: i, validation: S }) {
34
34
  return { initialState: t, formElements: i, validation: S };
35
35
  }
36
36
  const Se = (t, i) => {
37
37
  let S = t;
38
- const [u, h] = Dt(S);
39
- (Object.keys(h).length > 0 || i && Object.keys(i).length > 0) && Object.keys(h).forEach((I) => {
40
- h[I] = h[I] || {}, h[I].formElements = {
38
+ const [f, h] = Dt(S);
39
+ (Object.keys(h).length > 0 || i && Object.keys(i).length > 0) && Object.keys(h).forEach((y) => {
40
+ h[y] = h[y] || {}, h[y].formElements = {
41
41
  ...i?.formElements,
42
42
  // Global defaults first
43
43
  ...i?.validation,
44
- ...h[I].formElements || {}
44
+ ...h[y].formElements || {}
45
45
  // State-specific overrides
46
- }, st(I) || o.getState().setInitialStateOptions(I, h[I]);
47
- }), o.getState().setInitialStates(u), o.getState().setCreatedState(u);
48
- const x = (I, s) => {
49
- const [m] = it(s?.componentId ?? kt());
46
+ }, st(y) || r.getState().setInitialStateOptions(y, h[y]);
47
+ }), r.getState().setInitialStates(f), r.getState().setCreatedState(f);
48
+ const x = (y, s) => {
49
+ const [m] = it(s?.componentId ?? At());
50
50
  $t({
51
- stateKey: I,
51
+ stateKey: y,
52
52
  options: s,
53
53
  initialOptionsPart: h
54
54
  });
55
- const n = o.getState().cogsStateStore[I] || u[I], g = s?.modifyState ? s.modifyState(n) : n, [L, F] = Qt(
56
- g,
55
+ const n = r.getState().cogsStateStore[y] || f[y], u = s?.modifyState ? s.modifyState(n) : n, [L, R] = Qt(
56
+ u,
57
57
  {
58
- stateKey: I,
58
+ stateKey: y,
59
59
  syncUpdate: s?.syncUpdate,
60
60
  componentId: m,
61
61
  localStorage: s?.localStorage,
@@ -68,12 +68,12 @@ const Se = (t, i) => {
68
68
  serverState: s?.serverState
69
69
  }
70
70
  );
71
- return F;
71
+ return R;
72
72
  };
73
- function w(I, s) {
74
- $t({ stateKey: I, options: s, initialOptionsPart: h }), s.localStorage && Zt(I, s), ut(I);
73
+ function p(y, s) {
74
+ $t({ stateKey: y, options: s, initialOptionsPart: h }), s.localStorage && Zt(y, s), ut(y);
75
75
  }
76
- return { useCogsState: x, setCogsOptions: w };
76
+ return { useCogsState: x, setCogsOptions: p };
77
77
  }, {
78
78
  setUpdaterState: mt,
79
79
  setState: ot,
@@ -81,36 +81,36 @@ const Se = (t, i) => {
81
81
  getKeyState: Rt,
82
82
  getValidationErrors: qt,
83
83
  setStateLog: Jt,
84
- updateInitialStateGlobal: At,
84
+ updateInitialStateGlobal: kt,
85
85
  addValidationError: Mt,
86
86
  removeValidationError: Q,
87
87
  setServerSyncActions: Yt
88
- } = o.getState(), Nt = (t, i, S, u, h) => {
88
+ } = r.getState(), Nt = (t, i, S, f, h) => {
89
89
  S?.log && console.log(
90
90
  "saving to localstorage",
91
91
  i,
92
92
  S.localStorage?.key,
93
- u
93
+ f
94
94
  );
95
95
  const x = tt(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
96
- if (x && u) {
97
- const w = `${u}-${i}-${x}`;
98
- let I;
96
+ if (x && f) {
97
+ const p = `${f}-${i}-${x}`;
98
+ let y;
99
99
  try {
100
- I = vt(w)?.lastSyncedWithServer;
100
+ y = yt(p)?.lastSyncedWithServer;
101
101
  } catch {
102
102
  }
103
103
  const s = {
104
104
  state: t,
105
105
  lastUpdated: Date.now(),
106
- lastSyncedWithServer: h ?? I
106
+ lastSyncedWithServer: h ?? y
107
107
  }, m = Ht.serialize(s);
108
108
  window.localStorage.setItem(
109
- w,
109
+ p,
110
110
  JSON.stringify(m.json)
111
111
  );
112
112
  }
113
- }, vt = (t) => {
113
+ }, yt = (t) => {
114
114
  if (!t) return null;
115
115
  try {
116
116
  const i = window.localStorage.getItem(t);
@@ -119,60 +119,60 @@ const Se = (t, i) => {
119
119
  return console.error("Error loading from localStorage:", i), null;
120
120
  }
121
121
  }, Zt = (t, i) => {
122
- const S = o.getState().cogsStateStore[t], { sessionId: u } = _t(), h = tt(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
123
- if (h && u) {
124
- const x = vt(
125
- `${u}-${t}-${h}`
122
+ const S = r.getState().cogsStateStore[t], { sessionId: f } = _t(), h = tt(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
123
+ if (h && f) {
124
+ const x = yt(
125
+ `${f}-${t}-${h}`
126
126
  );
127
127
  if (x && x.lastUpdated > (x.lastSyncedWithServer || 0))
128
128
  return ot(t, x.state), ut(t), !0;
129
129
  }
130
130
  return !1;
131
- }, Ot = (t, i, S, u, h, x) => {
132
- const w = {
131
+ }, Ot = (t, i, S, f, h, x) => {
132
+ const p = {
133
133
  initialState: i,
134
134
  updaterState: ht(
135
135
  t,
136
- u,
136
+ f,
137
137
  h,
138
138
  x
139
139
  ),
140
140
  state: S
141
141
  };
142
- At(t, w.initialState), mt(t, w.updaterState), ot(t, w.state);
142
+ kt(t, p.initialState), mt(t, p.updaterState), ot(t, p.state);
143
143
  }, ut = (t) => {
144
- const i = o.getState().stateComponents.get(t);
144
+ const i = r.getState().stateComponents.get(t);
145
145
  if (!i) return;
146
146
  const S = /* @__PURE__ */ new Set();
147
- i.components.forEach((u) => {
148
- (u ? Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"] : null)?.includes("none") || S.add(() => u.forceUpdate());
147
+ i.components.forEach((f) => {
148
+ (f ? Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"] : null)?.includes("none") || S.add(() => f.forceUpdate());
149
149
  }), queueMicrotask(() => {
150
- S.forEach((u) => u());
150
+ S.forEach((f) => f());
151
151
  });
152
152
  }, me = (t, i) => {
153
- const S = o.getState().stateComponents.get(t);
153
+ const S = r.getState().stateComponents.get(t);
154
154
  if (S) {
155
- const u = `${t}////${i}`, h = S.components.get(u);
155
+ const f = `${t}////${i}`, h = S.components.get(f);
156
156
  if ((h ? Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"] : null)?.includes("none"))
157
157
  return;
158
158
  h && h.forceUpdate();
159
159
  }
160
- }, Xt = (t, i, S, u) => {
160
+ }, Xt = (t, i, S, f) => {
161
161
  switch (t) {
162
162
  case "update":
163
163
  return {
164
- oldValue: Z(i, u),
165
- newValue: Z(S, u)
164
+ oldValue: Z(i, f),
165
+ newValue: Z(S, f)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: Z(S, u)
171
+ newValue: Z(S, f)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: Z(i, u),
175
+ oldValue: Z(i, f),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -183,150 +183,150 @@ const Se = (t, i) => {
183
183
  function Qt(t, {
184
184
  stateKey: i,
185
185
  serverSync: S,
186
- localStorage: u,
186
+ localStorage: f,
187
187
  formElements: h,
188
188
  reactiveDeps: x,
189
- reactiveType: w,
190
- componentId: I,
189
+ reactiveType: p,
190
+ componentId: y,
191
191
  initialState: s,
192
192
  syncUpdate: m,
193
193
  dependencies: n,
194
- serverState: g
194
+ serverState: u
195
195
  } = {}) {
196
- const [L, F] = it({}), { sessionId: D } = _t();
196
+ const [L, R] = it({}), { sessionId: D } = _t();
197
197
  let H = !i;
198
- const [f] = it(i ?? kt()), l = o.getState().stateLog[f], gt = q(/* @__PURE__ */ new Set()), et = q(I ?? kt()), M = q(
198
+ const [g] = it(i ?? At()), c = r.getState().stateLog[g], ft = q(/* @__PURE__ */ new Set()), et = q(y ?? At()), O = q(
199
199
  null
200
200
  );
201
- M.current = st(f) ?? null, rt(() => {
202
- if (m && m.stateKey === f && m.path?.[0]) {
203
- ot(f, (r) => ({
204
- ...r,
201
+ O.current = st(g) ?? null, rt(() => {
202
+ if (m && m.stateKey === g && m.path?.[0]) {
203
+ ot(g, (o) => ({
204
+ ...o,
205
205
  [m.path[0]]: m.newValue
206
206
  }));
207
207
  const e = `${m.stateKey}:${m.path.join(".")}`;
208
- o.getState().setSyncInfo(e, {
208
+ r.getState().setSyncInfo(e, {
209
209
  timeStamp: m.timeStamp,
210
210
  userId: m.userId
211
211
  });
212
212
  }
213
213
  }, [m]), rt(() => {
214
214
  if (s) {
215
- Vt(f, {
215
+ Vt(g, {
216
216
  initialState: s
217
217
  });
218
- const e = M.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[f];
219
- if (!(c && !Y(c, s) || !c) && !a)
218
+ const e = O.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, d = r.getState().initialStateGlobal[g];
219
+ if (!(d && !Y(d, s) || !d) && !a)
220
220
  return;
221
221
  let v = null;
222
222
  const T = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
223
- T && D && (v = vt(`${D}-${f}-${T}`));
224
- let E = s, A = !1;
225
- const _ = a ? Date.now() : 0, $ = v?.lastUpdated || 0, R = v?.lastSyncedWithServer || 0;
226
- a && _ > $ ? (E = e.serverState.data, A = !0) : v && $ > R && (E = v.state, e?.localStorage?.onChange && e?.localStorage?.onChange(E)), o.getState().initializeShadowState(f, s), Ot(
227
- f,
223
+ T && D && (v = yt(`${D}-${g}-${T}`));
224
+ let E = s, k = !1;
225
+ const C = a ? Date.now() : 0, $ = v?.lastUpdated || 0, M = v?.lastSyncedWithServer || 0;
226
+ a && C > $ ? (E = e.serverState.data, k = !0) : v && $ > M && (E = v.state, e?.localStorage?.onChange && e?.localStorage?.onChange(E)), r.getState().initializeShadowState(g, s), Ot(
227
+ g,
228
228
  s,
229
229
  E,
230
230
  ct,
231
231
  et.current,
232
232
  D
233
- ), A && T && D && Nt(E, f, e, D, Date.now()), ut(f), (Array.isArray(w) ? w : [w || "component"]).includes("none") || F({});
233
+ ), k && T && D && Nt(E, g, e, D, Date.now()), ut(g), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
234
234
  }
235
235
  }, [
236
236
  s,
237
- g?.status,
238
- g?.data,
237
+ u?.status,
238
+ u?.data,
239
239
  ...n || []
240
240
  ]), Ct(() => {
241
- H && Vt(f, {
241
+ H && Vt(g, {
242
242
  serverSync: S,
243
243
  formElements: h,
244
244
  initialState: s,
245
- localStorage: u,
246
- middleware: M.current?.middleware
245
+ localStorage: f,
246
+ middleware: O.current?.middleware
247
247
  });
248
- const e = `${f}////${et.current}`, r = o.getState().stateComponents.get(f) || {
248
+ const e = `${g}////${et.current}`, o = r.getState().stateComponents.get(g) || {
249
249
  components: /* @__PURE__ */ new Map()
250
250
  };
251
- return r.components.set(e, {
252
- forceUpdate: () => F({}),
251
+ return o.components.set(e, {
252
+ forceUpdate: () => R({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
255
  depsFunction: x || void 0,
256
- reactiveType: w ?? ["component", "deps"]
257
- }), o.getState().stateComponents.set(f, r), F({}), () => {
258
- r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(f));
256
+ reactiveType: p ?? ["component", "deps"]
257
+ }), r.getState().stateComponents.set(g, o), R({}), () => {
258
+ o && (o.components.delete(e), o.components.size === 0 && r.getState().stateComponents.delete(g));
259
259
  };
260
260
  }, []);
261
- const ct = (e, r, a, c) => {
262
- if (Array.isArray(r)) {
263
- const v = `${f}-${r.join(".")}`;
264
- gt.current.add(v);
261
+ const ct = (e, o, a, d) => {
262
+ if (Array.isArray(o)) {
263
+ const v = `${g}-${o.join(".")}`;
264
+ ft.current.add(v);
265
265
  }
266
- const p = o.getState();
267
- ot(f, (v) => {
268
- const T = tt(e) ? e(v) : e, E = `${f}-${r.join(".")}`;
266
+ const w = r.getState();
267
+ ot(g, (v) => {
268
+ const T = tt(e) ? e(v) : e, E = `${g}-${o.join(".")}`;
269
269
  if (E) {
270
- let C = !1, y = p.signalDomElements.get(E);
271
- if ((!y || y.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
- const O = r.slice(0, -1), N = Z(T, O);
270
+ let _ = !1, I = w.signalDomElements.get(E);
271
+ if ((!I || I.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
272
+ const j = o.slice(0, -1), N = Z(T, j);
273
273
  if (Array.isArray(N)) {
274
- C = !0;
275
- const k = `${f}-${O.join(".")}`;
276
- y = p.signalDomElements.get(k);
274
+ _ = !0;
275
+ const A = `${g}-${j.join(".")}`;
276
+ I = w.signalDomElements.get(A);
277
277
  }
278
278
  }
279
- if (y) {
280
- const O = C ? Z(T, r.slice(0, -1)) : Z(T, r);
281
- y.forEach(({ parentId: N, position: k, effect: j }) => {
282
- const U = document.querySelector(
279
+ if (I) {
280
+ const j = _ ? Z(T, o.slice(0, -1)) : Z(T, o);
281
+ I.forEach(({ parentId: N, position: A, effect: U }) => {
282
+ const F = document.querySelector(
283
283
  `[data-parent-id="${N}"]`
284
284
  );
285
- if (U) {
286
- const B = Array.from(U.childNodes);
287
- if (B[k]) {
288
- const G = j ? new Function("state", `return (${j})(state)`)(O) : O;
289
- B[k].textContent = String(G);
285
+ if (F) {
286
+ const B = Array.from(F.childNodes);
287
+ if (B[A]) {
288
+ const G = U ? new Function("state", `return (${U})(state)`)(j) : j;
289
+ B[A].textContent = String(G);
290
290
  }
291
291
  }
292
292
  });
293
293
  }
294
294
  }
295
- console.log("shadowState", p.shadowStateStore), a.updateType === "update" && (c || M.current?.validation?.key) && r && Q(
296
- (c || M.current?.validation?.key) + "." + r.join(".")
295
+ console.log("shadowState", w.shadowStateStore), a.updateType === "update" && (d || O.current?.validation?.key) && o && Q(
296
+ (d || O.current?.validation?.key) + "." + o.join(".")
297
297
  );
298
- const A = r.slice(0, r.length - 1);
299
- a.updateType === "cut" && M.current?.validation?.key && Q(
300
- M.current?.validation?.key + "." + A.join(".")
301
- ), a.updateType === "insert" && M.current?.validation?.key && qt(
302
- M.current?.validation?.key + "." + A.join(".")
303
- ).filter(([y, O]) => {
304
- let N = y?.split(".").length;
305
- if (y == A.join(".") && N == A.length - 1) {
306
- let k = y + "." + A;
307
- Q(y), Mt(k, O);
298
+ const k = o.slice(0, o.length - 1);
299
+ a.updateType === "cut" && O.current?.validation?.key && Q(
300
+ O.current?.validation?.key + "." + k.join(".")
301
+ ), a.updateType === "insert" && O.current?.validation?.key && qt(
302
+ O.current?.validation?.key + "." + k.join(".")
303
+ ).filter(([I, j]) => {
304
+ let N = I?.split(".").length;
305
+ if (I == k.join(".") && N == k.length - 1) {
306
+ let A = I + "." + k;
307
+ Q(I), Mt(A, j);
308
308
  }
309
309
  });
310
- const _ = p.stateComponents.get(f);
311
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
312
- const C = Tt(v, T), y = new Set(C), O = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
310
+ const C = w.stateComponents.get(g);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
312
+ const _ = Tt(v, T), I = new Set(_), j = a.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
313
313
  for (const [
314
314
  N,
315
- k
316
- ] of _.components.entries()) {
317
- let j = !1;
318
- const U = Array.isArray(k.reactiveType) ? k.reactiveType : [k.reactiveType || "component"];
319
- if (console.log("component", k), !U.includes("none")) {
320
- if (U.includes("all")) {
321
- k.forceUpdate();
315
+ A
316
+ ] of C.components.entries()) {
317
+ let U = !1;
318
+ const F = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
319
+ if (console.log("component", A), !F.includes("none")) {
320
+ if (F.includes("all")) {
321
+ A.forceUpdate();
322
322
  continue;
323
323
  }
324
- if (U.includes("component") && ((k.paths.has(O) || k.paths.has("")) && (j = !0), !j))
325
- for (const B of y) {
324
+ if (F.includes("component") && ((A.paths.has(j) || A.paths.has("")) && (U = !0), !U))
325
+ for (const B of I) {
326
326
  let G = B;
327
327
  for (; ; ) {
328
- if (k.paths.has(G)) {
329
- j = !0;
328
+ if (A.paths.has(G)) {
329
+ U = !0;
330
330
  break;
331
331
  }
332
332
  const b = G.lastIndexOf(".");
@@ -337,8 +337,8 @@ function Qt(t, {
337
337
  );
338
338
  if (!isNaN(
339
339
  Number(G.substring(b + 1))
340
- ) && k.paths.has(V)) {
341
- j = !0;
340
+ ) && A.paths.has(V)) {
341
+ U = !0;
342
342
  break;
343
343
  }
344
344
  G = V;
@@ -347,115 +347,115 @@ function Qt(t, {
347
347
  if (G === "")
348
348
  break;
349
349
  }
350
- if (j) break;
350
+ if (U) break;
351
351
  }
352
- if (!j && U.includes("deps") && k.depsFunction) {
353
- const B = k.depsFunction(T);
352
+ if (!U && F.includes("deps") && A.depsFunction) {
353
+ const B = A.depsFunction(T);
354
354
  let G = !1;
355
- typeof B == "boolean" ? B && (G = !0) : Y(k.deps, B) || (k.deps = B, G = !0), G && (j = !0);
355
+ typeof B == "boolean" ? B && (G = !0) : Y(A.deps, B) || (A.deps = B, G = !0), G && (U = !0);
356
356
  }
357
- j && k.forceUpdate();
357
+ U && A.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
361
  const $ = Date.now();
362
- r = r.map((C, y) => {
363
- const O = r.slice(0, -1), N = Z(T, O);
364
- return y === r.length - 1 && ["insert", "cut"].includes(a.updateType) ? (N.length - 1).toString() : C;
362
+ o = o.map((_, I) => {
363
+ const j = o.slice(0, -1), N = Z(T, j);
364
+ return I === o.length - 1 && ["insert", "cut"].includes(a.updateType) ? (N.length - 1).toString() : _;
365
365
  });
366
- const { oldValue: R, newValue: z } = Xt(
366
+ const { oldValue: M, newValue: z } = Xt(
367
367
  a.updateType,
368
368
  v,
369
369
  T,
370
- r
370
+ o
371
371
  ), K = {
372
372
  timeStamp: $,
373
- stateKey: f,
374
- path: r,
373
+ stateKey: g,
374
+ path: o,
375
375
  updateType: a.updateType,
376
376
  status: "new",
377
- oldValue: R,
377
+ oldValue: M,
378
378
  newValue: z
379
379
  };
380
380
  switch (a.updateType) {
381
381
  case "update":
382
- p.updateShadowAtPath(f, r, T);
382
+ w.updateShadowAtPath(g, o, T);
383
383
  break;
384
384
  case "insert":
385
- const C = r.slice(0, -1);
386
- p.insertShadowArrayElement(f, C, z);
385
+ const _ = o.slice(0, -1);
386
+ w.insertShadowArrayElement(g, _, z);
387
387
  break;
388
388
  case "cut":
389
- const y = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- p.removeShadowArrayElement(f, y, O);
389
+ const I = o.slice(0, -1), j = parseInt(o[o.length - 1]);
390
+ w.removeShadowArrayElement(g, I, j);
391
391
  break;
392
392
  }
393
- if (Jt(f, (C) => {
394
- const O = [...C ?? [], K].reduce((N, k) => {
395
- const j = `${k.stateKey}:${JSON.stringify(k.path)}`, U = N.get(j);
396
- return U ? (U.timeStamp = Math.max(U.timeStamp, k.timeStamp), U.newValue = k.newValue, U.oldValue = U.oldValue ?? k.oldValue, U.updateType = k.updateType) : N.set(j, { ...k }), N;
393
+ if (Jt(g, (_) => {
394
+ const j = [..._ ?? [], K].reduce((N, A) => {
395
+ const U = `${A.stateKey}:${JSON.stringify(A.path)}`, F = N.get(U);
396
+ return F ? (F.timeStamp = Math.max(F.timeStamp, A.timeStamp), F.newValue = A.newValue, F.oldValue = F.oldValue ?? A.oldValue, F.updateType = A.updateType) : N.set(U, { ...A }), N;
397
397
  }, /* @__PURE__ */ new Map());
398
- return Array.from(O.values());
398
+ return Array.from(j.values());
399
399
  }), Nt(
400
400
  T,
401
- f,
402
- M.current,
401
+ g,
402
+ O.current,
403
403
  D
404
- ), M.current?.middleware && M.current.middleware({
405
- updateLog: l,
404
+ ), O.current?.middleware && O.current.middleware({
405
+ updateLog: c,
406
406
  update: K
407
- }), M.current?.serverSync) {
408
- const C = p.serverState[f], y = M.current?.serverSync;
409
- Yt(f, {
410
- syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: T }),
411
- rollBackState: C,
412
- actionTimeStamp: Date.now() + (y.debounce ?? 3e3),
407
+ }), O.current?.serverSync) {
408
+ const _ = w.serverState[g], I = O.current?.serverSync;
409
+ Yt(g, {
410
+ syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: T }),
411
+ rollBackState: _,
412
+ actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
416
  return T;
417
417
  });
418
418
  };
419
- o.getState().updaterState[f] || (mt(
420
- f,
419
+ r.getState().updaterState[g] || (mt(
420
+ g,
421
421
  ht(
422
- f,
422
+ g,
423
423
  ct,
424
424
  et.current,
425
425
  D
426
426
  )
427
- ), o.getState().cogsStateStore[f] || ot(f, t), o.getState().initialStateGlobal[f] || At(f, t));
428
- const d = Et(() => ht(
429
- f,
427
+ ), r.getState().cogsStateStore[g] || ot(g, t), r.getState().initialStateGlobal[g] || kt(g, t));
428
+ const l = Et(() => ht(
429
+ g,
430
430
  ct,
431
431
  et.current,
432
432
  D
433
- ), [f, D]);
434
- return [Rt(f), d];
433
+ ), [g, D]);
434
+ return [Rt(g), l];
435
435
  }
436
- function ht(t, i, S, u) {
436
+ function ht(t, i, S, f) {
437
437
  const h = /* @__PURE__ */ new Map();
438
438
  let x = 0;
439
- const w = (m) => {
439
+ const p = (m) => {
440
440
  const n = m.join(".");
441
- for (const [g] of h)
442
- (g === n || g.startsWith(n + ".")) && h.delete(g);
441
+ for (const [u] of h)
442
+ (u === n || u.startsWith(n + ".")) && h.delete(u);
443
443
  x++;
444
- }, I = {
444
+ }, y = {
445
445
  removeValidation: (m) => {
446
446
  m?.validationKey && Q(m.validationKey);
447
447
  },
448
448
  revertToInitialState: (m) => {
449
- const n = o.getState().getInitialOptions(t)?.validation;
449
+ const n = r.getState().getInitialOptions(t)?.validation;
450
450
  n?.key && Q(n?.key), m?.validationKey && Q(m.validationKey);
451
- const g = o.getState().initialStateGlobal[t];
452
- o.getState().clearSelectedIndexesForState(t), h.clear(), x++;
453
- const L = s(g, []), F = st(t), D = tt(F?.localStorage?.key) ? F?.localStorage?.key(g) : F?.localStorage?.key, H = `${u}-${t}-${D}`;
454
- H && localStorage.removeItem(H), mt(t, L), ot(t, g);
455
- const f = o.getState().stateComponents.get(t);
456
- return f && f.components.forEach((l) => {
457
- l.forceUpdate();
458
- }), g;
451
+ const u = r.getState().initialStateGlobal[t];
452
+ r.getState().clearSelectedIndexesForState(t), h.clear(), x++;
453
+ const L = s(u, []), R = st(t), D = tt(R?.localStorage?.key) ? R?.localStorage?.key(u) : R?.localStorage?.key, H = `${f}-${t}-${D}`;
454
+ H && localStorage.removeItem(H), mt(t, L), ot(t, u);
455
+ const g = r.getState().stateComponents.get(t);
456
+ return g && g.components.forEach((c) => {
457
+ c.forceUpdate();
458
+ }), u;
459
459
  },
460
460
  updateInitialState: (m) => {
461
461
  h.clear(), x++;
@@ -463,44 +463,44 @@ function ht(t, i, S, u) {
463
463
  t,
464
464
  i,
465
465
  S,
466
- u
467
- ), g = o.getState().initialStateGlobal[t], L = st(t), F = tt(L?.localStorage?.key) ? L?.localStorage?.key(g) : L?.localStorage?.key, D = `${u}-${t}-${F}`;
466
+ f
467
+ ), u = r.getState().initialStateGlobal[t], L = st(t), R = tt(L?.localStorage?.key) ? L?.localStorage?.key(u) : L?.localStorage?.key, D = `${f}-${t}-${R}`;
468
468
  return localStorage.getItem(D) && localStorage.removeItem(D), Ft(() => {
469
- At(t, m), o.getState().initializeShadowState(t, m), mt(t, n), ot(t, m);
470
- const H = o.getState().stateComponents.get(t);
471
- H && H.components.forEach((f) => {
472
- f.forceUpdate();
469
+ kt(t, m), r.getState().initializeShadowState(t, m), mt(t, n), ot(t, m);
470
+ const H = r.getState().stateComponents.get(t);
471
+ H && H.components.forEach((g) => {
472
+ g.forceUpdate();
473
473
  });
474
474
  }), {
475
475
  fetchId: (H) => n.get()[H]
476
476
  };
477
477
  },
478
- _initialState: o.getState().initialStateGlobal[t],
479
- _serverState: o.getState().serverState[t],
480
- _isLoading: o.getState().isLoadingGlobal[t],
478
+ _initialState: r.getState().initialStateGlobal[t],
479
+ _serverState: r.getState().serverState[t],
480
+ _isLoading: r.getState().isLoadingGlobal[t],
481
481
  _isServerSynced: () => {
482
- const m = o.getState().serverState[t];
482
+ const m = r.getState().serverState[t];
483
483
  return !!(m && Y(m, Rt(t)));
484
484
  }
485
485
  };
486
- function s(m, n = [], g) {
486
+ function s(m, n = [], u) {
487
487
  const L = n.map(String).join(".");
488
488
  h.get(L);
489
- const F = function() {
490
- return o().getNestedState(t, n);
489
+ const R = function() {
490
+ return r().getNestedState(t, n);
491
491
  };
492
- Object.keys(I).forEach((f) => {
493
- F[f] = I[f];
492
+ Object.keys(y).forEach((g) => {
493
+ R[g] = y[g];
494
494
  });
495
495
  const D = {
496
- apply(f, l, gt) {
496
+ apply(g, c, ft) {
497
497
  return console.log(
498
498
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
499
- ), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
499
+ ), console.trace("Apply trap stack trace"), r().getNestedState(t, n);
500
500
  },
501
- get(f, l) {
502
- g?.validIndices && !Array.isArray(m) && (g = { ...g, validIndices: void 0 });
503
- const gt = /* @__PURE__ */ new Set([
501
+ get(g, c) {
502
+ u?.validIndices && !Array.isArray(m) && (u = { ...u, validIndices: void 0 });
503
+ const ft = /* @__PURE__ */ new Set([
504
504
  "insert",
505
505
  "cut",
506
506
  "cutByValue",
@@ -523,142 +523,142 @@ function ht(t, i, S, u) {
523
523
  "_stateKey",
524
524
  "getComponents"
525
525
  ]);
526
- if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !gt.has(l)) {
527
- const d = `${t}////${S}`, e = o.getState().stateComponents.get(t);
526
+ if (c !== "then" && !c.startsWith("$") && c !== "stateMapNoRender" && !ft.has(c)) {
527
+ const l = `${t}////${S}`, e = r.getState().stateComponents.get(t);
528
528
  if (e) {
529
- const r = e.components.get(d);
530
- if (r && !r.paths.has("")) {
529
+ const o = e.components.get(l);
530
+ if (o && !o.paths.has("")) {
531
531
  const a = n.join(".");
532
- let c = !0;
533
- for (const p of r.paths)
534
- if (a.startsWith(p) && (a === p || a[p.length] === ".")) {
535
- c = !1;
532
+ let d = !0;
533
+ for (const w of o.paths)
534
+ if (a.startsWith(w) && (a === w || a[w.length] === ".")) {
535
+ d = !1;
536
536
  break;
537
537
  }
538
- c && r.paths.add(a);
538
+ d && o.paths.add(a);
539
539
  }
540
540
  }
541
541
  }
542
- if (l === "getDifferences")
542
+ if (c === "getDifferences")
543
543
  return () => Tt(
544
- o.getState().cogsStateStore[t],
545
- o.getState().initialStateGlobal[t]
544
+ r.getState().cogsStateStore[t],
545
+ r.getState().initialStateGlobal[t]
546
546
  );
547
- if (l === "sync" && n.length === 0)
547
+ if (c === "sync" && n.length === 0)
548
548
  return async function() {
549
- const d = o.getState().getInitialOptions(t), e = d?.sync;
549
+ const l = r.getState().getInitialOptions(t), e = l?.sync;
550
550
  if (!e)
551
551
  return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
552
- const r = o.getState().getNestedState(t, []), a = d?.validation?.key;
552
+ const o = r.getState().getNestedState(t, []), a = l?.validation?.key;
553
553
  try {
554
- const c = await e.action(r);
555
- if (c && !c.success && c.errors && a) {
556
- o.getState().removeValidationError(a), c.errors.forEach((v) => {
554
+ const d = await e.action(o);
555
+ if (d && !d.success && d.errors && a) {
556
+ r.getState().removeValidationError(a), d.errors.forEach((v) => {
557
557
  const T = [a, ...v.path].join(".");
558
- o.getState().addValidationError(T, v.message);
558
+ r.getState().addValidationError(T, v.message);
559
559
  });
560
- const p = o.getState().stateComponents.get(t);
561
- p && p.components.forEach((v) => {
560
+ const w = r.getState().stateComponents.get(t);
561
+ w && w.components.forEach((v) => {
562
562
  v.forceUpdate();
563
563
  });
564
564
  }
565
- return c?.success && e.onSuccess ? e.onSuccess(c.data) : !c?.success && e.onError && e.onError(c.error), c;
566
- } catch (c) {
567
- return e.onError && e.onError(c), { success: !1, error: c };
565
+ return d?.success && e.onSuccess ? e.onSuccess(d.data) : !d?.success && e.onError && e.onError(d.error), d;
566
+ } catch (d) {
567
+ return e.onError && e.onError(d), { success: !1, error: d };
568
568
  }
569
569
  };
570
- if (l === "_status") {
571
- const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = Z(e, n);
572
- return Y(d, r) ? "fresh" : "stale";
570
+ if (c === "_status") {
571
+ const l = r.getState().getNestedState(t, n), e = r.getState().initialStateGlobal[t], o = Z(e, n);
572
+ return Y(l, o) ? "fresh" : "stale";
573
573
  }
574
- if (l === "getStatus")
574
+ if (c === "getStatus")
575
575
  return function() {
576
- const d = o().getNestedState(
576
+ const l = r().getNestedState(
577
577
  t,
578
578
  n
579
- ), e = o.getState().initialStateGlobal[t], r = Z(e, n);
580
- return Y(d, r) ? "fresh" : "stale";
579
+ ), e = r.getState().initialStateGlobal[t], o = Z(e, n);
580
+ return Y(l, o) ? "fresh" : "stale";
581
581
  };
582
- if (l === "removeStorage")
582
+ if (c === "removeStorage")
583
583
  return () => {
584
- const d = o.getState().initialStateGlobal[t], e = st(t), r = tt(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${u}-${t}-${r}`;
584
+ const l = r.getState().initialStateGlobal[t], e = st(t), o = tt(e?.localStorage?.key) ? e?.localStorage?.key(l) : e?.localStorage?.key, a = `${f}-${t}-${o}`;
585
585
  a && localStorage.removeItem(a);
586
586
  };
587
- if (l === "showValidationErrors")
587
+ if (c === "showValidationErrors")
588
588
  return () => {
589
- const d = o.getState().getInitialOptions(t)?.validation;
590
- if (!d?.key)
589
+ const l = r.getState().getInitialOptions(t)?.validation;
590
+ if (!l?.key)
591
591
  throw new Error("Validation key not found");
592
- return o.getState().getValidationErrors(d.key + "." + n.join("."));
592
+ return r.getState().getValidationErrors(l.key + "." + n.join("."));
593
593
  };
594
594
  if (Array.isArray(m)) {
595
- const d = () => g?.validIndices ? m.map((r, a) => ({
596
- item: r,
597
- originalIndex: g.validIndices[a]
598
- })) : o.getState().getNestedState(t, n).map((r, a) => ({
599
- item: r,
595
+ const l = () => u?.validIndices ? m.map((o, a) => ({
596
+ item: o,
597
+ originalIndex: u.validIndices[a]
598
+ })) : r.getState().getNestedState(t, n).map((o, a) => ({
599
+ item: o,
600
600
  originalIndex: a
601
601
  }));
602
- if (l === "getSelected")
602
+ if (c === "getSelected")
603
603
  return () => {
604
- const e = o.getState().getSelectedIndex(t, n.join("."));
604
+ const e = r.getState().getSelectedIndex(t, n.join("."));
605
605
  if (e !== void 0)
606
606
  return s(
607
607
  m[e],
608
608
  [...n, e.toString()],
609
- g
609
+ u
610
610
  );
611
611
  };
612
- if (l === "clearSelected")
612
+ if (c === "clearSelected")
613
613
  return () => {
614
- o.getState().clearSelectedIndex({ stateKey: t, path: n });
614
+ r.getState().clearSelectedIndex({ stateKey: t, path: n });
615
615
  };
616
- if (l === "getSelectedIndex")
617
- return () => o.getState().getSelectedIndex(t, n.join(".")) ?? -1;
618
- if (l === "useVirtualView")
616
+ if (c === "getSelectedIndex")
617
+ return () => r.getState().getSelectedIndex(t, n.join(".")) ?? -1;
618
+ if (c === "useVirtualView")
619
619
  return (e) => {
620
620
  const {
621
- itemHeight: r = 50,
621
+ itemHeight: o = 50,
622
622
  overscan: a = 6,
623
- stickToBottom: c = !1,
624
- dependencies: p = []
623
+ stickToBottom: d = !1,
624
+ dependencies: w = []
625
625
  } = e, v = q(null), [T, E] = it({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
- }), [A, _] = it(0), $ = q(!0), R = q(!1), z = q(0), K = q(T);
629
- rt(() => o.getState().subscribeToShadowState(t, () => {
630
- _((V) => V + 1);
628
+ }), [k, C] = it(0), $ = q(!0), M = q(!1), z = q(0), K = q(T);
629
+ rt(() => r.getState().subscribeToShadowState(t, () => {
630
+ C((V) => V + 1);
631
631
  }), [t]);
632
- const C = o().getNestedState(
632
+ const _ = r().getNestedState(
633
633
  t,
634
634
  n
635
- ), y = C.length, { totalHeight: O, positions: N } = Et(() => {
636
- const b = o.getState().getShadowMetadata(t, n) || [];
635
+ ), I = _.length, { totalHeight: j, positions: N } = Et(() => {
636
+ const b = r.getState().getShadowMetadata(t, n) || [];
637
637
  let V = 0;
638
638
  const P = [];
639
- for (let W = 0; W < y; W++) {
639
+ for (let W = 0; W < I; W++) {
640
640
  P[W] = V;
641
641
  const J = b[W]?.virtualizer?.itemHeight;
642
- V += J || r;
642
+ V += J || o;
643
643
  }
644
644
  return { totalHeight: V, positions: P };
645
645
  }, [
646
- y,
646
+ I,
647
647
  t,
648
648
  n.join("."),
649
- r,
650
- A
651
- ]), k = Et(() => {
652
- const b = Math.max(0, T.startIndex), V = Math.min(y, T.endIndex), P = Array.from(
649
+ o,
650
+ k
651
+ ]), A = Et(() => {
652
+ const b = Math.max(0, T.startIndex), V = Math.min(I, T.endIndex), P = Array.from(
653
653
  { length: V - b },
654
654
  (J, at) => b + at
655
- ), W = P.map((J) => C[J]);
655
+ ), W = P.map((J) => _[J]);
656
656
  return s(W, n, {
657
- ...g,
657
+ ...u,
658
658
  validIndices: P
659
659
  });
660
- }, [T.startIndex, T.endIndex, C, y]), j = St(() => {
661
- const b = o.getState().getShadowMetadata(t, n) || [], V = y - 1;
660
+ }, [T.startIndex, T.endIndex, _, I]), U = St(() => {
661
+ const b = r.getState().getShadowMetadata(t, n) || [], V = I - 1;
662
662
  if (V >= 0) {
663
663
  const P = b[V];
664
664
  if (P?.virtualizer?.domRef) {
@@ -672,79 +672,79 @@ function ht(t, i, S, u) {
672
672
  }
673
673
  }
674
674
  return !1;
675
- }, [t, n, y]);
675
+ }, [t, n, I]);
676
676
  rt(() => {
677
- if (!c || y === 0) return;
678
- const b = y > z.current, V = z.current === 0 && y > 0;
679
- if ((b || V) && $.current && !R.current) {
677
+ if (!d || I === 0) return;
678
+ const b = I > z.current, V = z.current === 0 && I > 0;
679
+ if ((b || V) && $.current && !M.current) {
680
680
  const P = Math.ceil(
681
- (v.current?.clientHeight || 0) / r
681
+ (v.current?.clientHeight || 0) / o
682
682
  ), W = {
683
683
  startIndex: Math.max(
684
684
  0,
685
- y - P - a
685
+ I - P - a
686
686
  ),
687
- endIndex: y
687
+ endIndex: I
688
688
  };
689
689
  E(W);
690
690
  const J = setTimeout(() => {
691
- B(y - 1, "smooth");
691
+ B(I - 1, "smooth");
692
692
  }, 50);
693
693
  return () => clearTimeout(J);
694
694
  }
695
- z.current = y;
696
- }, [y, r, a]), rt(() => {
695
+ z.current = I;
696
+ }, [I, o, a]), rt(() => {
697
697
  const b = v.current;
698
698
  if (!b) return;
699
699
  const V = () => {
700
700
  const { scrollTop: P, scrollHeight: W, clientHeight: J } = b, at = W - P - J;
701
- $.current = at < 5, at > 100 && (R.current = !0), at < 5 && (R.current = !1);
701
+ $.current = at < 5, at > 100 && (M.current = !0), at < 5 && (M.current = !1);
702
702
  let nt = 0;
703
703
  for (let X = 0; X < N.length; X++)
704
- if (N[X] > P - r * a) {
704
+ if (N[X] > P - o * a) {
705
705
  nt = Math.max(0, X - 1);
706
706
  break;
707
707
  }
708
708
  let xt = nt;
709
709
  const jt = P + J;
710
- for (let X = nt; X < N.length && !(N[X] > jt + r * a); X++)
710
+ for (let X = nt; X < N.length && !(N[X] > jt + o * a); X++)
711
711
  xt = X;
712
- const yt = Math.max(0, nt), It = Math.min(
713
- y,
712
+ const vt = Math.max(0, nt), It = Math.min(
713
+ I,
714
714
  xt + 1 + a
715
715
  );
716
- (yt !== K.current.startIndex || It !== K.current.endIndex) && (K.current = {
717
- startIndex: yt,
716
+ (vt !== K.current.startIndex || It !== K.current.endIndex) && (K.current = {
717
+ startIndex: vt,
718
718
  endIndex: It
719
719
  }, E({
720
- startIndex: yt,
720
+ startIndex: vt,
721
721
  endIndex: It
722
722
  }));
723
723
  };
724
724
  if (b.addEventListener("scroll", V, {
725
725
  passive: !0
726
- }), c && y > 0 && !R.current) {
726
+ }), d && I > 0 && !M.current) {
727
727
  const { scrollTop: P } = b;
728
728
  P === 0 && (b.scrollTop = b.scrollHeight, $.current = !0);
729
729
  }
730
730
  return V(), () => {
731
731
  b.removeEventListener("scroll", V);
732
732
  };
733
- }, [N, y, r, a, c]);
734
- const U = St(() => {
735
- $.current = !0, R.current = !1, !j() && v.current && (v.current.scrollTop = v.current.scrollHeight);
736
- }, [j]), B = St(
733
+ }, [N, I, o, a, d]);
734
+ const F = St(() => {
735
+ $.current = !0, M.current = !1, !U() && v.current && (v.current.scrollTop = v.current.scrollHeight);
736
+ }, [U]), B = St(
737
737
  (b, V = "smooth") => {
738
738
  const P = v.current;
739
739
  if (!P) return;
740
- if (b === y - 1) {
740
+ if (b === I - 1) {
741
741
  P.scrollTo({
742
742
  top: P.scrollHeight,
743
743
  behavior: V
744
744
  });
745
745
  return;
746
746
  }
747
- const nt = (o.getState().getShadowMetadata(t, n) || [])[b]?.virtualizer?.domRef;
747
+ const nt = (r.getState().getShadowMetadata(t, n) || [])[b]?.virtualizer?.domRef;
748
748
  nt ? nt.scrollIntoView({
749
749
  behavior: V,
750
750
  block: "center"
@@ -753,7 +753,7 @@ function ht(t, i, S, u) {
753
753
  behavior: V
754
754
  });
755
755
  },
756
- [N, t, n, y]
756
+ [N, t, n, I]
757
757
  // Add totalCount to the dependencies
758
758
  ), G = {
759
759
  outer: {
@@ -762,7 +762,7 @@ function ht(t, i, S, u) {
762
762
  },
763
763
  inner: {
764
764
  style: {
765
- height: `${O}px`,
765
+ height: `${j}px`,
766
766
  position: "relative"
767
767
  }
768
768
  },
@@ -773,26 +773,26 @@ function ht(t, i, S, u) {
773
773
  }
774
774
  };
775
775
  return {
776
- virtualState: k,
776
+ virtualState: A,
777
777
  virtualizerProps: G,
778
- scrollToBottom: U,
778
+ scrollToBottom: F,
779
779
  scrollToIndex: B
780
780
  };
781
781
  };
782
- if (l === "stateMapNoRender")
783
- return (e) => m.map((a, c) => {
784
- let p;
785
- g?.validIndices && g.validIndices[c] !== void 0 ? p = g.validIndices[c] : p = c;
786
- const v = [...n, p.toString()], T = s(a, v, g);
782
+ if (c === "stateMapNoRender")
783
+ return (e) => m.map((a, d) => {
784
+ let w;
785
+ u?.validIndices && u.validIndices[d] !== void 0 ? w = u.validIndices[d] : w = d;
786
+ const v = [...n, w.toString()], T = s(a, v, u);
787
787
  return e(
788
788
  a,
789
789
  T,
790
- c,
790
+ d,
791
791
  m,
792
- s(m, n, g)
792
+ s(m, n, u)
793
793
  );
794
794
  });
795
- if (l === "$stateMap")
795
+ if (c === "$stateMap")
796
796
  return (e) => dt(Kt, {
797
797
  proxy: {
798
798
  _stateKey: t,
@@ -802,350 +802,350 @@ function ht(t, i, S, u) {
802
802
  },
803
803
  rebuildStateShape: s
804
804
  });
805
- if (l === "stateList")
806
- return (e) => {
807
- const r = o.getState().getNestedState(t, n);
808
- return Array.isArray(r) ? (g?.validIndices || Array.from({ length: r.length }, (c, p) => p)).map((c, p) => {
809
- const v = r[c], T = [...n, c.toString()], E = s(v, T, g), A = `${S}-${n.join(".")}-${c}`;
805
+ if (c === "stateList")
806
+ return (e, o) => {
807
+ const a = r.getState().getNestedState(t, n);
808
+ return Array.isArray(a) ? (u?.validIndices || Array.from({ length: a.length }, (w, v) => v)).map((w, v) => {
809
+ const T = a[w], E = [...n, w.toString()], k = s(T, E, u), C = `${S}-${n.join(".")}-${w}`;
810
810
  return dt(ee, {
811
- key: c,
811
+ key: w,
812
812
  stateKey: t,
813
- itemComponentId: A,
814
- itemPath: T,
813
+ itemComponentId: C,
814
+ formOpts: o,
815
+ itemPath: E,
815
816
  children: e(
816
- v,
817
- E,
818
- { localIndex: p, originalIndex: c },
819
- r,
820
- s(r, n, g)
817
+ T,
818
+ k,
819
+ { localIndex: v, originalIndex: w },
820
+ a,
821
+ s(a, n, u)
821
822
  )
822
823
  });
823
824
  }) : (console.warn(
824
825
  `stateList called on a non-array value at path: ${n.join(".")}.`
825
826
  ), null);
826
827
  };
827
- if (l === "stateFlattenOn")
828
+ if (c === "stateFlattenOn")
828
829
  return (e) => {
829
- const r = m;
830
+ const o = m;
830
831
  h.clear(), x++;
831
- const a = r.flatMap(
832
- (c) => c[e] ?? []
832
+ const a = o.flatMap(
833
+ (d) => d[e] ?? []
833
834
  );
834
835
  return s(
835
836
  a,
836
837
  [...n, "[*]", e],
837
- g
838
+ u
838
839
  );
839
840
  };
840
- if (l === "index")
841
+ if (c === "index")
841
842
  return (e) => {
842
- const r = m[e];
843
- return s(r, [...n, e.toString()]);
843
+ const o = m[e];
844
+ return s(o, [...n, e.toString()]);
844
845
  };
845
- if (l === "last")
846
+ if (c === "last")
846
847
  return () => {
847
- const e = o.getState().getNestedState(t, n);
848
+ const e = r.getState().getNestedState(t, n);
848
849
  if (e.length === 0) return;
849
- const r = e.length - 1, a = e[r], c = [...n, r.toString()];
850
- return s(a, c);
850
+ const o = e.length - 1, a = e[o], d = [...n, o.toString()];
851
+ return s(a, d);
851
852
  };
852
- if (l === "insert")
853
- return (e) => (w(n), wt(i, e, n, t), s(
854
- o.getState().getNestedState(t, n),
853
+ if (c === "insert")
854
+ return (e) => (p(n), wt(i, e, n, t), s(
855
+ r.getState().getNestedState(t, n),
855
856
  n
856
857
  ));
857
- if (l === "uniqueInsert")
858
- return (e, r, a) => {
859
- const c = o.getState().getNestedState(t, n), p = tt(e) ? e(c) : e;
858
+ if (c === "uniqueInsert")
859
+ return (e, o, a) => {
860
+ const d = r.getState().getNestedState(t, n), w = tt(e) ? e(d) : e;
860
861
  let v = null;
861
- if (!c.some((E) => {
862
- if (r) {
863
- const _ = r.every(
864
- ($) => Y(E[$], p[$])
862
+ if (!d.some((E) => {
863
+ if (o) {
864
+ const C = o.every(
865
+ ($) => Y(E[$], w[$])
865
866
  );
866
- return _ && (v = E), _;
867
+ return C && (v = E), C;
867
868
  }
868
- const A = Y(E, p);
869
- return A && (v = E), A;
869
+ const k = Y(E, w);
870
+ return k && (v = E), k;
870
871
  }))
871
- w(n), wt(i, p, n, t);
872
+ p(n), wt(i, w, n, t);
872
873
  else if (a && v) {
873
- const E = a(v), A = c.map(
874
- (_) => Y(_, v) ? E : _
874
+ const E = a(v), k = d.map(
875
+ (C) => Y(C, v) ? E : C
875
876
  );
876
- w(n), lt(i, A, n);
877
+ p(n), lt(i, k, n);
877
878
  }
878
879
  };
879
- if (l === "cut")
880
- return (e, r) => {
881
- if (!r?.waitForSync)
882
- return w(n), ft(i, n, t, e), s(
883
- o.getState().getNestedState(t, n),
880
+ if (c === "cut")
881
+ return (e, o) => {
882
+ if (!o?.waitForSync)
883
+ return p(n), gt(i, n, t, e), s(
884
+ r.getState().getNestedState(t, n),
884
885
  n
885
886
  );
886
887
  };
887
- if (l === "cutByValue")
888
+ if (c === "cutByValue")
888
889
  return (e) => {
889
- for (let r = 0; r < m.length; r++)
890
- m[r] === e && ft(i, n, t, r);
890
+ for (let o = 0; o < m.length; o++)
891
+ m[o] === e && gt(i, n, t, o);
891
892
  };
892
- if (l === "toggleByValue")
893
+ if (c === "toggleByValue")
893
894
  return (e) => {
894
- const r = m.findIndex((a) => a === e);
895
- r > -1 ? ft(i, n, t, r) : wt(i, e, n, t);
895
+ const o = m.findIndex((a) => a === e);
896
+ o > -1 ? gt(i, n, t, o) : wt(i, e, n, t);
896
897
  };
897
- if (l === "stateFind")
898
+ if (c === "stateFind")
898
899
  return (e) => {
899
- const a = d().find(
900
- ({ item: p }, v) => e(p, v)
900
+ const a = l().find(
901
+ ({ item: w }, v) => e(w, v)
901
902
  );
902
903
  if (!a) return;
903
- const c = [...n, a.originalIndex.toString()];
904
- return s(a.item, c, g);
904
+ const d = [...n, a.originalIndex.toString()];
905
+ return s(a.item, d, u);
905
906
  };
906
- if (l === "findWith")
907
- return (e, r) => {
908
- const c = d().find(
909
- ({ item: v }) => v[e] === r
907
+ if (c === "findWith")
908
+ return (e, o) => {
909
+ const d = l().find(
910
+ ({ item: v }) => v[e] === o
910
911
  );
911
- if (!c) return;
912
- const p = [...n, c.originalIndex.toString()];
913
- return s(c.item, p, g);
912
+ if (!d) return;
913
+ const w = [...n, d.originalIndex.toString()];
914
+ return s(d.item, w, u);
914
915
  };
915
916
  }
916
917
  const et = n[n.length - 1];
917
918
  if (!isNaN(Number(et))) {
918
- const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
919
- if (Array.isArray(e) && l === "cut")
920
- return () => ft(
919
+ const l = n.slice(0, -1), e = r.getState().getNestedState(t, l);
920
+ if (Array.isArray(e) && c === "cut")
921
+ return () => gt(
921
922
  i,
922
- d,
923
+ l,
923
924
  t,
924
925
  Number(et)
925
926
  );
926
927
  }
927
- if (l === "get")
928
+ if (c === "get")
928
929
  return () => {
929
- if (g?.validIndices && Array.isArray(m)) {
930
- const d = o.getState().getNestedState(t, n);
931
- return g.validIndices.map((e) => d[e]);
930
+ if (u?.validIndices && Array.isArray(m)) {
931
+ const l = r.getState().getNestedState(t, n);
932
+ return u.validIndices.map((e) => l[e]);
932
933
  }
933
- return o.getState().getNestedState(t, n);
934
+ return r.getState().getNestedState(t, n);
934
935
  };
935
- if (l === "$derive")
936
- return (d) => Pt({
936
+ if (c === "$derive")
937
+ return (l) => Pt({
937
938
  _stateKey: t,
938
939
  _path: n,
939
- _effect: d.toString()
940
+ _effect: l.toString()
940
941
  });
941
- if (l === "$get")
942
+ if (c === "$get")
942
943
  return () => Pt({
943
944
  _stateKey: t,
944
945
  _path: n
945
946
  });
946
- if (l === "lastSynced") {
947
- const d = `${t}:${n.join(".")}`;
948
- return o.getState().getSyncInfo(d);
947
+ if (c === "lastSynced") {
948
+ const l = `${t}:${n.join(".")}`;
949
+ return r.getState().getSyncInfo(l);
949
950
  }
950
- if (l == "getLocalStorage")
951
- return (d) => vt(u + "-" + t + "-" + d);
952
- if (l === "_selected") {
953
- const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
954
- return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
951
+ if (c == "getLocalStorage")
952
+ return (l) => yt(f + "-" + t + "-" + l);
953
+ if (c === "_selected") {
954
+ const l = n.slice(0, -1), e = l.join("."), o = r.getState().getNestedState(t, l);
955
+ return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(t, e) : void 0;
955
956
  }
956
- if (l === "setSelected")
957
- return (d) => {
958
- const e = n.slice(0, -1), r = Number(n[n.length - 1]), a = e.join(".");
959
- d ? o.getState().setSelectedIndex(t, a, r) : o.getState().setSelectedIndex(t, a, void 0);
960
- const c = o.getState().getNestedState(t, [...e]);
961
- lt(i, c, e), w(e);
957
+ if (c === "setSelected")
958
+ return (l) => {
959
+ const e = n.slice(0, -1), o = Number(n[n.length - 1]), a = e.join(".");
960
+ l ? r.getState().setSelectedIndex(t, a, o) : r.getState().setSelectedIndex(t, a, void 0);
961
+ const d = r.getState().getNestedState(t, [...e]);
962
+ lt(i, d, e), p(e);
962
963
  };
963
- if (l === "toggleSelected")
964
+ if (c === "toggleSelected")
964
965
  return () => {
965
- const d = n.slice(0, -1), e = Number(n[n.length - 1]), r = d.join("."), a = o.getState().getSelectedIndex(t, r);
966
- o.getState().setSelectedIndex(
966
+ const l = n.slice(0, -1), e = Number(n[n.length - 1]), o = l.join("."), a = r.getState().getSelectedIndex(t, o);
967
+ r.getState().setSelectedIndex(
967
968
  t,
968
- r,
969
+ o,
969
970
  a === e ? void 0 : e
970
971
  );
971
- const c = o.getState().getNestedState(t, [...d]);
972
- lt(i, c, d), w(d);
972
+ const d = r.getState().getNestedState(t, [...l]);
973
+ lt(i, d, l), p(l);
973
974
  };
974
975
  if (n.length == 0) {
975
- if (l === "addValidation")
976
- return (d) => {
977
- const e = o.getState().getInitialOptions(t)?.validation;
976
+ if (c === "addValidation")
977
+ return (l) => {
978
+ const e = r.getState().getInitialOptions(t)?.validation;
978
979
  if (!e?.key)
979
980
  throw new Error("Validation key not found");
980
- Q(e.key), console.log("addValidationError", d), d.forEach((r) => {
981
- const a = [e.key, ...r.path].join(".");
982
- console.log("fullErrorPath", a), Mt(a, r.message);
981
+ Q(e.key), console.log("addValidationError", l), l.forEach((o) => {
982
+ const a = [e.key, ...o.path].join(".");
983
+ console.log("fullErrorPath", a), Mt(a, o.message);
983
984
  }), ut(t);
984
985
  };
985
- if (l === "applyJsonPatch")
986
- return (d) => {
987
- const e = o.getState().cogsStateStore[t], a = zt(e, d).newDocument;
986
+ if (c === "applyJsonPatch")
987
+ return (l) => {
988
+ const e = r.getState().cogsStateStore[t], a = zt(e, l).newDocument;
988
989
  Ot(
989
990
  t,
990
- o.getState().initialStateGlobal[t],
991
+ r.getState().initialStateGlobal[t],
991
992
  a,
992
993
  i,
993
994
  S,
994
- u
995
+ f
995
996
  );
996
- const c = o.getState().stateComponents.get(t);
997
- if (c) {
998
- const p = Tt(e, a), v = new Set(p);
997
+ const d = r.getState().stateComponents.get(t);
998
+ if (d) {
999
+ const w = Tt(e, a), v = new Set(w);
999
1000
  for (const [
1000
1001
  T,
1001
1002
  E
1002
- ] of c.components.entries()) {
1003
- let A = !1;
1004
- const _ = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
1005
- if (!_.includes("none")) {
1006
- if (_.includes("all")) {
1003
+ ] of d.components.entries()) {
1004
+ let k = !1;
1005
+ const C = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
1006
+ if (!C.includes("none")) {
1007
+ if (C.includes("all")) {
1007
1008
  E.forceUpdate();
1008
1009
  continue;
1009
1010
  }
1010
- if (_.includes("component") && (E.paths.has("") && (A = !0), !A))
1011
+ if (C.includes("component") && (E.paths.has("") && (k = !0), !k))
1011
1012
  for (const $ of v) {
1012
1013
  if (E.paths.has($)) {
1013
- A = !0;
1014
+ k = !0;
1014
1015
  break;
1015
1016
  }
1016
- let R = $.lastIndexOf(".");
1017
- for (; R !== -1; ) {
1018
- const z = $.substring(0, R);
1017
+ let M = $.lastIndexOf(".");
1018
+ for (; M !== -1; ) {
1019
+ const z = $.substring(0, M);
1019
1020
  if (E.paths.has(z)) {
1020
- A = !0;
1021
+ k = !0;
1021
1022
  break;
1022
1023
  }
1023
1024
  const K = $.substring(
1024
- R + 1
1025
+ M + 1
1025
1026
  );
1026
1027
  if (!isNaN(Number(K))) {
1027
- const C = z.lastIndexOf(".");
1028
- if (C !== -1) {
1029
- const y = z.substring(
1028
+ const _ = z.lastIndexOf(".");
1029
+ if (_ !== -1) {
1030
+ const I = z.substring(
1030
1031
  0,
1031
- C
1032
+ _
1032
1033
  );
1033
- if (E.paths.has(y)) {
1034
- A = !0;
1034
+ if (E.paths.has(I)) {
1035
+ k = !0;
1035
1036
  break;
1036
1037
  }
1037
1038
  }
1038
1039
  }
1039
- R = z.lastIndexOf(".");
1040
+ M = z.lastIndexOf(".");
1040
1041
  }
1041
- if (A) break;
1042
+ if (k) break;
1042
1043
  }
1043
- if (!A && _.includes("deps") && E.depsFunction) {
1044
+ if (!k && C.includes("deps") && E.depsFunction) {
1044
1045
  const $ = E.depsFunction(a);
1045
- let R = !1;
1046
- typeof $ == "boolean" ? $ && (R = !0) : Y(E.deps, $) || (E.deps = $, R = !0), R && (A = !0);
1046
+ let M = !1;
1047
+ typeof $ == "boolean" ? $ && (M = !0) : Y(E.deps, $) || (E.deps = $, M = !0), M && (k = !0);
1047
1048
  }
1048
- A && E.forceUpdate();
1049
+ k && E.forceUpdate();
1049
1050
  }
1050
1051
  }
1051
1052
  }
1052
1053
  };
1053
- if (l === "validateZodSchema")
1054
+ if (c === "validateZodSchema")
1054
1055
  return () => {
1055
- const d = o.getState().getInitialOptions(t)?.validation, e = o.getState().addValidationError;
1056
- if (!d?.zodSchema)
1056
+ const l = r.getState().getInitialOptions(t)?.validation, e = r.getState().addValidationError;
1057
+ if (!l?.zodSchema)
1057
1058
  throw new Error("Zod schema not found");
1058
- if (!d?.key)
1059
+ if (!l?.key)
1059
1060
  throw new Error("Validation key not found");
1060
- Q(d.key);
1061
- const r = o.getState().cogsStateStore[t];
1061
+ Q(l.key);
1062
+ const o = r.getState().cogsStateStore[t];
1062
1063
  try {
1063
- const a = o.getState().getValidationErrors(d.key);
1064
- a && a.length > 0 && a.forEach(([p]) => {
1065
- p && p.startsWith(d.key) && Q(p);
1064
+ const a = r.getState().getValidationErrors(l.key);
1065
+ a && a.length > 0 && a.forEach(([w]) => {
1066
+ w && w.startsWith(l.key) && Q(w);
1066
1067
  });
1067
- const c = d.zodSchema.safeParse(r);
1068
- return c.success ? !0 : (c.error.errors.forEach((v) => {
1069
- const T = v.path, E = v.message, A = [d.key, ...T].join(".");
1070
- e(A, E);
1068
+ const d = l.zodSchema.safeParse(o);
1069
+ return d.success ? !0 : (d.error.errors.forEach((v) => {
1070
+ const T = v.path, E = v.message, k = [l.key, ...T].join(".");
1071
+ e(k, E);
1071
1072
  }), ut(t), !1);
1072
1073
  } catch (a) {
1073
1074
  return console.error("Zod schema validation failed", a), !1;
1074
1075
  }
1075
1076
  };
1076
- if (l === "_componentId") return S;
1077
- if (l === "getComponents")
1078
- return () => o().stateComponents.get(t);
1079
- if (l === "getAllFormRefs")
1077
+ if (c === "_componentId") return S;
1078
+ if (c === "getComponents")
1079
+ return () => r().stateComponents.get(t);
1080
+ if (c === "getAllFormRefs")
1080
1081
  return () => bt.getState().getFormRefsByStateKey(t);
1081
- if (l === "_initialState")
1082
- return o.getState().initialStateGlobal[t];
1083
- if (l === "_serverState")
1084
- return o.getState().serverState[t];
1085
- if (l === "_isLoading")
1086
- return o.getState().isLoadingGlobal[t];
1087
- if (l === "revertToInitialState")
1088
- return I.revertToInitialState;
1089
- if (l === "updateInitialState") return I.updateInitialState;
1090
- if (l === "removeValidation") return I.removeValidation;
1082
+ if (c === "_initialState")
1083
+ return r.getState().initialStateGlobal[t];
1084
+ if (c === "_serverState")
1085
+ return r.getState().serverState[t];
1086
+ if (c === "_isLoading")
1087
+ return r.getState().isLoadingGlobal[t];
1088
+ if (c === "revertToInitialState")
1089
+ return y.revertToInitialState;
1090
+ if (c === "updateInitialState") return y.updateInitialState;
1091
+ if (c === "removeValidation") return y.removeValidation;
1091
1092
  }
1092
- if (l === "getFormRef")
1093
+ if (c === "getFormRef")
1093
1094
  return () => bt.getState().getFormRef(t + "." + n.join("."));
1094
- if (l === "validationWrapper")
1095
+ if (c === "validationWrapper")
1095
1096
  return ({
1096
- children: d,
1097
+ children: l,
1097
1098
  hideMessage: e
1098
1099
  }) => /* @__PURE__ */ pt(
1099
1100
  Gt,
1100
1101
  {
1101
1102
  formOpts: e ? { validation: { message: "" } } : void 0,
1102
1103
  path: n,
1103
- validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
1104
1104
  stateKey: t,
1105
- validIndices: g?.validIndices,
1106
- children: d
1105
+ validIndices: u?.validIndices,
1106
+ children: l
1107
1107
  }
1108
1108
  );
1109
- if (l === "_stateKey") return t;
1110
- if (l === "_path") return n;
1111
- if (l === "_isServerSynced") return I._isServerSynced;
1112
- if (l === "update")
1113
- return (d, e) => {
1109
+ if (c === "_stateKey") return t;
1110
+ if (c === "_path") return n;
1111
+ if (c === "_isServerSynced") return y._isServerSynced;
1112
+ if (c === "update")
1113
+ return (l, e) => {
1114
1114
  if (e?.debounce)
1115
1115
  Lt(() => {
1116
- lt(i, d, n, "");
1117
- const r = o.getState().getNestedState(t, n);
1118
- e?.afterUpdate && e.afterUpdate(r);
1116
+ lt(i, l, n, "");
1117
+ const o = r.getState().getNestedState(t, n);
1118
+ e?.afterUpdate && e.afterUpdate(o);
1119
1119
  }, e.debounce);
1120
1120
  else {
1121
- lt(i, d, n, "");
1122
- const r = o.getState().getNestedState(t, n);
1123
- e?.afterUpdate && e.afterUpdate(r);
1121
+ lt(i, l, n, "");
1122
+ const o = r.getState().getNestedState(t, n);
1123
+ e?.afterUpdate && e.afterUpdate(o);
1124
1124
  }
1125
- w(n);
1125
+ p(n);
1126
1126
  };
1127
- if (l === "formElement")
1128
- return (d, e) => /* @__PURE__ */ pt(
1127
+ if (c === "formElement")
1128
+ return (l, e) => /* @__PURE__ */ pt(
1129
1129
  Wt,
1130
1130
  {
1131
1131
  setState: i,
1132
1132
  stateKey: t,
1133
1133
  path: n,
1134
- child: d,
1134
+ child: l,
1135
1135
  formOpts: e
1136
1136
  }
1137
1137
  );
1138
- const M = [...n, l], ct = o.getState().getNestedState(t, M);
1139
- return s(ct, M, g);
1138
+ const O = [...n, c], ct = r.getState().getNestedState(t, O);
1139
+ return s(ct, O, u);
1140
1140
  }
1141
- }, H = new Proxy(F, D);
1141
+ }, H = new Proxy(R, D);
1142
1142
  return h.set(L, {
1143
1143
  proxy: H,
1144
1144
  stateVersion: x
1145
1145
  }), H;
1146
1146
  }
1147
1147
  return s(
1148
- o.getState().getNestedState(t, [])
1148
+ r.getState().getNestedState(t, [])
1149
1149
  );
1150
1150
  }
1151
1151
  function Pt(t) {
@@ -1155,12 +1155,12 @@ function Kt({
1155
1155
  proxy: t,
1156
1156
  rebuildStateShape: i
1157
1157
  }) {
1158
- const S = o().getNestedState(t._stateKey, t._path);
1158
+ const S = r().getNestedState(t._stateKey, t._path);
1159
1159
  return Array.isArray(S) ? i(
1160
1160
  S,
1161
1161
  t._path
1162
1162
  ).stateMapNoRender(
1163
- (h, x, w, I, s) => t._mapFn(h, x, w, I, s)
1163
+ (h, x, p, y, s) => t._mapFn(h, x, p, y, s)
1164
1164
  ) : null;
1165
1165
  }
1166
1166
  function te({
@@ -1168,34 +1168,34 @@ function te({
1168
1168
  }) {
1169
1169
  const i = q(null), S = `${t._stateKey}-${t._path.join(".")}`;
1170
1170
  return rt(() => {
1171
- const u = i.current;
1172
- if (!u || !u.parentElement) return;
1173
- const h = u.parentElement, w = Array.from(h.childNodes).indexOf(u);
1174
- let I = h.getAttribute("data-parent-id");
1175
- I || (I = `parent-${crypto.randomUUID()}`, h.setAttribute("data-parent-id", I));
1171
+ const f = i.current;
1172
+ if (!f || !f.parentElement) return;
1173
+ const h = f.parentElement, p = Array.from(h.childNodes).indexOf(f);
1174
+ let y = h.getAttribute("data-parent-id");
1175
+ y || (y = `parent-${crypto.randomUUID()}`, h.setAttribute("data-parent-id", y));
1176
1176
  const m = {
1177
1177
  instanceId: `instance-${crypto.randomUUID()}`,
1178
- parentId: I,
1179
- position: w,
1178
+ parentId: y,
1179
+ position: p,
1180
1180
  effect: t._effect
1181
1181
  };
1182
- o.getState().addSignalElement(S, m);
1183
- const n = o.getState().getNestedState(t._stateKey, t._path);
1184
- let g;
1182
+ r.getState().addSignalElement(S, m);
1183
+ const n = r.getState().getNestedState(t._stateKey, t._path);
1184
+ let u;
1185
1185
  if (t._effect)
1186
1186
  try {
1187
- g = new Function(
1187
+ u = new Function(
1188
1188
  "state",
1189
1189
  `return (${t._effect})(state)`
1190
1190
  )(n);
1191
- } catch (F) {
1192
- console.error("Error evaluating effect function during mount:", F), g = n;
1191
+ } catch (R) {
1192
+ console.error("Error evaluating effect function during mount:", R), u = n;
1193
1193
  }
1194
1194
  else
1195
- g = n;
1196
- g !== null && typeof g == "object" && (g = JSON.stringify(g));
1197
- const L = document.createTextNode(String(g));
1198
- u.replaceWith(L);
1195
+ u = n;
1196
+ u !== null && typeof u == "object" && (u = JSON.stringify(u));
1197
+ const L = document.createTextNode(String(u));
1198
+ f.replaceWith(L);
1199
1199
  }, [t._stateKey, t._path.join("."), t._effect]), dt("span", {
1200
1200
  ref: i,
1201
1201
  style: { display: "none" },
@@ -1205,15 +1205,15 @@ function te({
1205
1205
  function he(t) {
1206
1206
  const i = Ut(
1207
1207
  (S) => {
1208
- const u = o.getState().stateComponents.get(t._stateKey) || {
1208
+ const f = r.getState().stateComponents.get(t._stateKey) || {
1209
1209
  components: /* @__PURE__ */ new Map()
1210
1210
  };
1211
- return u.components.set(t._stateKey, {
1211
+ return f.components.set(t._stateKey, {
1212
1212
  forceUpdate: S,
1213
1213
  paths: /* @__PURE__ */ new Set([t._path.join(".")])
1214
- }), () => u.components.delete(t._stateKey);
1214
+ }), () => f.components.delete(t._stateKey);
1215
1215
  },
1216
- () => o.getState().getNestedState(t._stateKey, t._path)
1216
+ () => r.getState().getNestedState(t._stateKey, t._path)
1217
1217
  );
1218
1218
  return dt("text", {}, String(i));
1219
1219
  }
@@ -1221,39 +1221,40 @@ function ee({
1221
1221
  stateKey: t,
1222
1222
  itemComponentId: i,
1223
1223
  itemPath: S,
1224
- children: u
1224
+ formOpts: f,
1225
+ children: h
1225
1226
  }) {
1226
- const [, h] = it({}), [x, w] = Bt(), I = q(null), s = q(null), m = St(
1227
- (n) => {
1228
- x(n), I.current = n;
1227
+ const [, x] = it({}), [p, y] = Bt(), s = q(null), m = q(null), n = St(
1228
+ (u) => {
1229
+ p(u), s.current = u;
1229
1230
  },
1230
- [x]
1231
+ [p]
1231
1232
  );
1232
1233
  return rt(() => {
1233
- w.height > 0 && w.height !== s.current && (s.current = w.height, o.getState().setShadowMetadata(t, S, {
1234
+ y.height > 0 && y.height !== m.current && (m.current = y.height, r.getState().setShadowMetadata(t, S, {
1234
1235
  virtualizer: {
1235
- itemHeight: w.height,
1236
- domRef: I.current
1236
+ itemHeight: y.height,
1237
+ domRef: s.current
1237
1238
  // Store the actual DOM element reference
1238
1239
  }
1239
1240
  }));
1240
- }, [w.height, t, S]), Ct(() => {
1241
- const n = `${t}////${i}`, g = o.getState().stateComponents.get(t) || {
1241
+ }, [y.height, t, S]), Ct(() => {
1242
+ const u = `${t}////${i}`, L = r.getState().stateComponents.get(t) || {
1242
1243
  components: /* @__PURE__ */ new Map()
1243
1244
  };
1244
- return g.components.set(n, {
1245
- forceUpdate: () => h({}),
1245
+ return L.components.set(u, {
1246
+ forceUpdate: () => x({}),
1246
1247
  paths: /* @__PURE__ */ new Set([S.join(".")])
1247
- }), o.getState().stateComponents.set(t, g), () => {
1248
- const L = o.getState().stateComponents.get(t);
1249
- L && L.components.delete(n);
1248
+ }), r.getState().stateComponents.set(t, L), () => {
1249
+ const R = r.getState().stateComponents.get(t);
1250
+ R && R.components.delete(u);
1250
1251
  };
1251
- }, [t, i, S.join(".")]), /* @__PURE__ */ pt("div", { ref: m, children: u });
1252
+ }, [t, i, S.join(".")]), /* @__PURE__ */ pt("div", { ref: n, children: h });
1252
1253
  }
1253
1254
  export {
1254
1255
  Pt as $cogsSignal,
1255
1256
  he as $cogsSignalStore,
1256
- fe as addStateOptions,
1257
+ ge as addStateOptions,
1257
1258
  Se as createCogsState,
1258
1259
  me as notifyComponent,
1259
1260
  Qt as useCogsStateFn