cogsbox-state 0.5.288 → 0.5.289

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