cogsbox-state 0.5.330 → 0.5.332

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