cogsbox-state 0.5.403 → 0.5.404

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