cogsbox-state 0.5.422 → 0.5.423

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