cogsbox-state 0.5.291 → 0.5.292

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