cogsbox-state 0.5.287 → 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 Y, 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 Z, 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, R] = 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 R;
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: J,
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 = Z(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 = Z(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, R] = rt({}), { sessionId: F } = 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 = Y(/* @__PURE__ */ new Set()), X = Y(I ?? pt()), j = Y(
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
- j.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 = j.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 = Z(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
223
- A && F && (u = ft(`${F}-${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 P = s ? Date.now() : 0, x = u?.lastUpdated || 0, b = u?.lastSyncedWithServer || 0;
226
- s && P > x ? (w = e.serverState.data, T = !0) : u && x > b && (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
- X.current,
232
- F
233
- ), T && A && F && $t(w, h, e, F, Date.now()), St(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
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,
245
+ localStorage: g,
246
246
  middleware: j.current?.middleware
247
247
  });
248
- const e = `${h}////${X.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: () => R({}),
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), R({}), () => {
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 = Z(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 C = !1, N = g.signalDomElements.get(w);
270
+ let _ = !1, N = f.signalDomElements.get(w);
271
271
  if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
- const O = r.slice(0, -1), D = z(A, O);
273
- if (Array.isArray(D)) {
274
- C = !0;
275
- const $ = `${h}-${O.join(".")}`;
276
- N = g.signalDomElements.get($);
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
279
  if (N) {
280
- const O = C ? z(A, r.slice(0, -1)) : z(A, r);
281
- N.forEach(({ parentId: D, position: $, effect: E }) => {
282
- const V = document.querySelector(
283
- `[data-parent-id="${D}"]`
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 (V) {
286
- const _ = Array.from(V.childNodes);
287
- if (_[$]) {
288
- const M = E ? new Function("state", `return (${E})(state)`)(O) : O;
289
- _[$].textContent = String(M);
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 || j.current?.validation?.key) && r && J(
296
- (i || j.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" && j.current?.validation?.key && J(
298
+ const T = n.slice(0, n.length - 1);
299
+ s.updateType === "cut" && j.current?.validation?.key && q(
300
300
  j.current?.validation?.key + "." + T.join(".")
301
- ), s.updateType === "insert" && j.current?.validation?.key && Dt(
301
+ ), s.updateType === "insert" && j.current?.validation?.key && Rt(
302
302
  j.current?.validation?.key + "." + T.join(".")
303
- ).filter(([N, O]) => {
304
- let D = N?.split(".").length;
305
- if (N == T.join(".") && D == T.length - 1) {
306
- let $ = N + "." + T;
307
- J(N), Gt($, O);
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 P = g.stateComponents.get(h);
311
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", P), P) {
312
- const C = It(u, A), N = new Set(C), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
310
+ const x = f.stateComponents.get(m);
311
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
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
- $
316
- ] of P.components.entries()) {
317
- let E = !1;
318
- const V = Array.isArray($.reactiveType) ? $.reactiveType : [$.reactiveType || "component"];
319
- if (console.log("component", $), !V.includes("none")) {
320
- if (V.includes("all")) {
321
- $.forceUpdate();
314
+ M,
315
+ A
316
+ ] of x.components.entries()) {
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 (V.includes("component") && (($.paths.has(O) || $.paths.has("")) && (E = !0), !E))
325
- for (const _ of N) {
326
- let 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(M)) {
329
- E = !0;
328
+ if (A.paths.has(F)) {
329
+ P = !0;
330
330
  break;
331
331
  }
332
- const L = M.lastIndexOf(".");
333
- if (L !== -1) {
334
- const Q = M.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(M.substring(L + 1))
340
- ) && $.paths.has(Q)) {
341
- E = !0;
339
+ Number(F.substring(X + 1))
340
+ ) && A.paths.has(et)) {
341
+ P = !0;
342
342
  break;
343
343
  }
344
- M = Q;
344
+ F = et;
345
345
  } else
346
- M = "";
347
- if (M === "")
346
+ F = "";
347
+ if (F === "")
348
348
  break;
349
349
  }
350
- if (E) break;
350
+ if (P) break;
351
351
  }
352
- if (!E && V.includes("deps") && $.depsFunction) {
353
- const _ = $.depsFunction(A);
354
- let M = !1;
355
- typeof _ == "boolean" ? _ && (M = !0) : H($.deps, _) || ($.deps = _, M = !0), M && (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 x = Date.now();
362
- r = r.map((C, N) => {
363
- const O = r.slice(0, -1), D = z(A, O);
364
- return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : C;
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: b, newValue: U } = 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: x,
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: b,
378
- newValue: U
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 C = r.slice(0, -1);
386
- g.insertShadowArrayElement(h, C, U);
385
+ const _ = n.slice(0, -1);
386
+ f.insertShadowArrayElement(m, _, D);
387
387
  break;
388
388
  case "cut":
389
- const N = r.slice(0, -1), O = parseInt(r[r.length - 1]);
390
- g.removeShadowArrayElement(h, N, O);
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, (C) => {
394
- const O = [...C ?? [], B].reduce((D, $) => {
395
- const E = `${$.stateKey}:${JSON.stringify($.path)}`, V = D.get(E);
396
- return V ? (V.timeStamp = Math.max(V.timeStamp, $.timeStamp), V.newValue = $.newValue, V.oldValue = V.oldValue ?? $.oldValue, V.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(O.values());
399
- }), $t(
400
- A,
401
- h,
398
+ return Array.from($.values());
399
+ }), Et(
400
+ E,
401
+ m,
402
402
  j.current,
403
- F
403
+ R
404
404
  ), j.current?.middleware && j.current.middleware({
405
405
  updateLog: l,
406
406
  update: B
407
407
  }), j.current?.serverSync) {
408
- const C = g.serverState[h], N = j.current?.serverSync;
409
- Lt(h, {
410
- syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: A }),
411
- rollBackState: C,
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
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
- X.current,
425
- F
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
- X.current,
432
- F
433
- ), [h, F]);
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 && J(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 && J(n?.key), m?.validationKey && J(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, []), R = nt(t), F = Z(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, G = `${f}-${t}-${F}`;
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), R = Z(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, F = `${f}-${t}-${R}`;
468
- return localStorage.getItem(F) && localStorage.removeItem(F), 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 R = 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
- R[h] = I[h];
492
+ Object.keys(I).forEach((m) => {
493
+ O[m] = I[m];
494
494
  });
495
- const F = {
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 = Z(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,207 +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
- // Default height for unmeasured items
621
+ itemHeight: n,
623
622
  overscan: s = 5,
624
623
  stickToBottom: i = !1
625
- } = e, g = Y(null), [u, A] = rt({
624
+ } = e, f = H(null), [u, E] = K({
626
625
  startIndex: 0,
627
626
  endIndex: 10
628
- }), w = Y(i), T = Y(0), P = Y(!0), x = o().getNestedState(
627
+ }), w = H(i), T = H(0), x = H(!0), C = o().getNestedState(
629
628
  t,
630
- n
631
- ), b = x.length, U = mt(
632
- (E) => o.getState().getShadowMetadata(t, [...n, E.toString()])?.virtualizer?.itemHeight || r,
633
- [r, t, n]
634
- ), { totalHeight: B, positions: C } = yt(() => {
635
- let E = 0;
636
- const V = [];
637
- for (let _ = 0; _ < b; _++)
638
- V[_] = E, E += U(_);
639
- return { totalHeight: E, positions: V };
640
- }, [b, U]), N = yt(() => {
641
- const E = Math.max(0, u.startIndex), V = Math.min(b, u.endIndex), _ = Array.from(
642
- { length: V - E },
643
- (L, Q) => E + Q
644
- ), M = _.map((L) => x[L]);
645
- return a(M, 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: _
637
+ validIndices: A
648
638
  });
649
- }, [u.startIndex, u.endIndex, x, b]);
650
- dt(() => {
651
- const E = g.current;
652
- if (!E) return;
653
- const V = w.current, _ = b > T.current;
654
- T.current = b;
655
- const M = () => {
656
- const { scrollTop: L, clientHeight: Q, scrollHeight: Vt } = E;
657
- w.current = Vt - L - Q < 10;
658
- let et = 0;
659
- for (let q = 0; q < C.length; q++)
660
- if (C[q] >= L) {
661
- et = q;
662
- break;
663
- }
664
- let K = et;
665
- for (; K < b && C[K] < L + Q; )
666
- K++;
667
- et = Math.max(0, et - s), K = Math.min(b, K + s), A((q) => q.startIndex !== et || q.endIndex !== K ? { startIndex: et, endIndex: K } : q);
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", M, {
657
+ return $.addEventListener("scroll", P, {
670
658
  passive: !0
671
- }), i && (P.current ? E.scrollTo({
672
- top: E.scrollHeight,
659
+ }), i && (x.current ? $.scrollTo({
660
+ top: $.scrollHeight,
673
661
  behavior: "auto"
674
- }) : V && _ && requestAnimationFrame(() => {
675
- E.scrollTo({
676
- top: E.scrollHeight,
662
+ }) : M && A && requestAnimationFrame(() => {
663
+ $.scrollTo({
664
+ top: $.scrollHeight,
677
665
  behavior: "smooth"
678
666
  });
679
- })), P.current = !1, M(), () => E.removeEventListener("scroll", M);
680
- }, [b, s, i, C]);
681
- const O = 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, V = "smooth") => {
691
- g.current && C[E] !== void 0 && g.current.scrollTo({
692
- top: C[E],
693
- behavior: V
677
+ ), _ = vt(
678
+ ($, M = "smooth") => {
679
+ f.current && f.current.scrollTo({
680
+ top: $ * n,
681
+ behavior: M
694
682
  });
695
683
  },
696
- [C]
697
- // Depends on the calculated positions
698
- ), $ = {
684
+ [n]
685
+ ), N = {
699
686
  outer: {
700
- ref: g,
687
+ ref: f,
701
688
  style: { overflowY: "auto", height: "100%" }
702
689
  },
703
690
  inner: {
704
691
  style: {
705
- height: `${B}px`,
692
+ height: `${V * n}px`,
706
693
  position: "relative"
707
694
  }
708
695
  },
709
696
  list: {
710
697
  style: {
711
- transform: `translateY(${C[u.startIndex] || 0}px)`
698
+ transform: `translateY(${u.startIndex * n}px)`
712
699
  }
713
700
  }
714
701
  };
715
702
  return {
716
- virtualState: N,
717
- virtualizerProps: $,
718
- scrollToBottom: O,
719
- scrollToIndex: D
703
+ virtualState: D,
704
+ virtualizerProps: N,
705
+ scrollToBottom: B,
706
+ scrollToIndex: _
720
707
  };
721
708
  };
722
709
  if (l === "stateSort")
723
710
  return (e) => {
724
711
  const s = [...d()].sort(
725
- (u, A) => e(u.item, A.item)
726
- ), i = s.map(({ item: u }) => u), g = {
712
+ (u, E) => e(u.item, E.item)
713
+ ), i = s.map(({ item: u }) => u), f = {
727
714
  ...S,
728
715
  validIndices: s.map(
729
716
  ({ originalIndex: u }) => u
730
717
  )
731
718
  };
732
- return a(i, n, g);
719
+ return a(i, r, f);
733
720
  };
734
721
  if (l === "stateFilter")
735
722
  return (e) => {
736
723
  const s = d().filter(
737
- ({ item: u }, A) => e(u, A)
738
- ), i = s.map(({ item: u }) => u), g = {
724
+ ({ item: u }, E) => e(u, E)
725
+ ), i = s.map(({ item: u }) => u), f = {
739
726
  ...S,
740
727
  validIndices: s.map(
741
728
  ({ originalIndex: u }) => u
742
729
  )
743
730
  };
744
- return a(i, n, g);
731
+ return a(i, r, f);
745
732
  };
746
733
  if (l === "stateMap")
747
734
  return (e) => {
748
- const r = o.getState().getNestedState(t, n);
749
- return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
750
- 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);
751
738
  return e(u, w, {
752
739
  register: () => {
753
- const [, P] = rt({}), x = `${v}-${n.join(".")}-${i}`;
754
- dt(() => {
755
- const b = `${t}////${x}`, U = 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) || {
756
743
  components: /* @__PURE__ */ new Map()
757
744
  };
758
- return U.components.set(b, {
759
- forceUpdate: () => P({}),
760
- paths: /* @__PURE__ */ new Set([A.join(".")])
761
- }), o.getState().stateComponents.set(t, U), () => {
745
+ return D.components.set(V, {
746
+ forceUpdate: () => x({}),
747
+ paths: /* @__PURE__ */ new Set([E.join(".")])
748
+ }), o.getState().stateComponents.set(t, D), () => {
762
749
  const B = o.getState().stateComponents.get(t);
763
- B && B.components.delete(b);
750
+ B && B.components.delete(V);
764
751
  };
765
- }, [t, x]);
752
+ }, [t, C]);
766
753
  },
767
- index: g,
754
+ index: f,
768
755
  originalIndex: i
769
756
  });
770
757
  }) : (console.warn(
771
- `stateMap called on a non-array value at path: ${n.join(".")}. The current value is:`,
772
- r
758
+ `stateMap called on a non-array value at path: ${r.join(".")}. The current value is:`,
759
+ n
773
760
  ), null);
774
761
  };
775
762
  if (l === "stateMapNoRender")
776
- return (e) => m.map((s, i) => {
777
- let g;
778
- S?.validIndices && S.validIndices[i] !== void 0 ? g = S.validIndices[i] : g = i;
779
- 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);
780
767
  return e(
781
768
  s,
782
- A,
769
+ E,
783
770
  i,
784
- m,
785
- a(m, n, S)
771
+ y,
772
+ a(y, r, S)
786
773
  );
787
774
  });
788
775
  if (l === "$stateMap")
789
- return (e) => st(qt, {
776
+ return (e) => rt(zt, {
790
777
  proxy: {
791
778
  _stateKey: t,
792
- _path: n,
779
+ _path: r,
793
780
  _mapFn: e
794
781
  // Pass the actual function, not string
795
782
  },
@@ -797,221 +784,221 @@ function gt(t, c, v, f) {
797
784
  });
798
785
  if (l === "stateList")
799
786
  return (e) => {
800
- const r = o.getState().getNestedState(t, n);
801
- return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
802
- const u = r[i], A = [...n, i.toString()], w = a(u, A, S), T = `${v}-${n.join(".")}-${i}`;
803
- 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, {
804
791
  key: i,
805
792
  stateKey: t,
806
793
  itemComponentId: T,
807
- itemPath: A,
794
+ itemPath: E,
808
795
  children: e(
809
796
  u,
810
797
  w,
811
- g,
812
- r,
813
- a(r, n, S)
798
+ f,
799
+ n,
800
+ a(n, r, S)
814
801
  )
815
802
  });
816
803
  }) : (console.warn(
817
- `stateList called on a non-array value at path: ${n.join(".")}.`
804
+ `stateList called on a non-array value at path: ${r.join(".")}.`
818
805
  ), null);
819
806
  };
820
807
  if (l === "stateFlattenOn")
821
808
  return (e) => {
822
- const r = m;
823
- y.clear(), k++;
824
- const s = r.flatMap(
809
+ const n = y;
810
+ v.clear(), k++;
811
+ const s = n.flatMap(
825
812
  (i) => i[e] ?? []
826
813
  );
827
814
  return a(
828
815
  s,
829
- [...n, "[*]", e],
816
+ [...r, "[*]", e],
830
817
  S
831
818
  );
832
819
  };
833
820
  if (l === "index")
834
821
  return (e) => {
835
- const r = m[e];
836
- return a(r, [...n, e.toString()]);
822
+ const n = y[e];
823
+ return a(n, [...r, e.toString()]);
837
824
  };
838
825
  if (l === "last")
839
826
  return () => {
840
- const e = o.getState().getNestedState(t, n);
827
+ const e = o.getState().getNestedState(t, r);
841
828
  if (e.length === 0) return;
842
- 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()];
843
830
  return a(s, i);
844
831
  };
845
832
  if (l === "insert")
846
- return (e) => (p(n), ht(c, e, n, t), a(
847
- o.getState().getNestedState(t, n),
848
- n
833
+ return (e) => (p(r), gt(c, e, r, t), a(
834
+ o.getState().getNestedState(t, r),
835
+ r
849
836
  ));
850
837
  if (l === "uniqueInsert")
851
- return (e, r, s) => {
852
- const i = o.getState().getNestedState(t, n), g = Z(e) ? e(i) : e;
838
+ return (e, n, s) => {
839
+ const i = o.getState().getNestedState(t, r), f = J(e) ? e(i) : e;
853
840
  let u = null;
854
841
  if (!i.some((w) => {
855
- if (r) {
856
- const P = r.every(
857
- (x) => H(w[x], g[x])
842
+ if (n) {
843
+ const x = n.every(
844
+ (C) => L(w[C], f[C])
858
845
  );
859
- return P && (u = w), P;
846
+ return x && (u = w), x;
860
847
  }
861
- const T = H(w, g);
848
+ const T = L(w, f);
862
849
  return T && (u = w), T;
863
850
  }))
864
- p(n), ht(c, g, n, t);
851
+ p(r), gt(c, f, r, t);
865
852
  else if (s && u) {
866
853
  const w = s(u), T = i.map(
867
- (P) => H(P, u) ? w : P
854
+ (x) => L(x, u) ? w : x
868
855
  );
869
- p(n), at(c, T, n);
856
+ p(r), nt(c, T, r);
870
857
  }
871
858
  };
872
859
  if (l === "cut")
873
- return (e, r) => {
874
- if (!r?.waitForSync)
875
- return p(n), ct(c, n, t, e), a(
876
- o.getState().getNestedState(t, n),
877
- 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
878
865
  );
879
866
  };
880
867
  if (l === "cutByValue")
881
868
  return (e) => {
882
- for (let r = 0; r < m.length; r++)
883
- 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);
884
871
  };
885
872
  if (l === "toggleByValue")
886
873
  return (e) => {
887
- const r = m.findIndex((s) => s === e);
888
- 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);
889
876
  };
890
877
  if (l === "stateFind")
891
878
  return (e) => {
892
879
  const s = d().find(
893
- ({ item: g }, u) => e(g, u)
880
+ ({ item: f }, u) => e(f, u)
894
881
  );
895
882
  if (!s) return;
896
- const i = [...n, s.originalIndex.toString()];
883
+ const i = [...r, s.originalIndex.toString()];
897
884
  return a(s.item, i, S);
898
885
  };
899
886
  if (l === "findWith")
900
- return (e, r) => {
887
+ return (e, n) => {
901
888
  const i = d().find(
902
- ({ item: u }) => u[e] === r
889
+ ({ item: u }) => u[e] === n
903
890
  );
904
891
  if (!i) return;
905
- const g = [...n, i.originalIndex.toString()];
906
- return a(i.item, g, S);
892
+ const f = [...r, i.originalIndex.toString()];
893
+ return a(i.item, f, S);
907
894
  };
908
895
  }
909
- const X = n[n.length - 1];
910
- if (!isNaN(Number(X))) {
911
- 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);
912
899
  if (Array.isArray(e) && l === "cut")
913
- return () => ct(
900
+ return () => at(
914
901
  c,
915
902
  d,
916
903
  t,
917
- Number(X)
904
+ Number(Y)
918
905
  );
919
906
  }
920
907
  if (l === "get")
921
908
  return () => {
922
- if (S?.validIndices && Array.isArray(m)) {
923
- const d = o.getState().getNestedState(t, n);
909
+ if (S?.validIndices && Array.isArray(y)) {
910
+ const d = o.getState().getNestedState(t, r);
924
911
  return S.validIndices.map((e) => d[e]);
925
912
  }
926
- return o.getState().getNestedState(t, n);
913
+ return o.getState().getNestedState(t, r);
927
914
  };
928
915
  if (l === "$derive")
929
- return (d) => kt({
916
+ return (d) => At({
930
917
  _stateKey: t,
931
- _path: n,
918
+ _path: r,
932
919
  _effect: d.toString()
933
920
  });
934
921
  if (l === "$get")
935
- return () => kt({
922
+ return () => At({
936
923
  _stateKey: t,
937
- _path: n
924
+ _path: r
938
925
  });
939
926
  if (l === "lastSynced") {
940
- const d = `${t}:${n.join(".")}`;
927
+ const d = `${t}:${r.join(".")}`;
941
928
  return o.getState().getSyncInfo(d);
942
929
  }
943
930
  if (l == "getLocalStorage")
944
- return (d) => ft(f + "-" + t + "-" + d);
931
+ return (d) => dt(g + "-" + t + "-" + d);
945
932
  if (l === "_selected") {
946
- const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
947
- 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;
948
935
  }
949
936
  if (l === "setSelected")
950
937
  return (d) => {
951
- const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
952
- 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);
953
940
  const i = o.getState().getNestedState(t, [...e]);
954
- at(c, i, e), p(e);
941
+ nt(c, i, e), p(e);
955
942
  };
956
943
  if (l === "toggleSelected")
957
944
  return () => {
958
- 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);
959
946
  o.getState().setSelectedIndex(
960
947
  t,
961
- r,
948
+ n,
962
949
  s === e ? void 0 : e
963
950
  );
964
951
  const i = o.getState().getNestedState(t, [...d]);
965
- at(c, i, d), p(d);
952
+ nt(c, i, d), p(d);
966
953
  };
967
- if (n.length == 0) {
954
+ if (r.length == 0) {
968
955
  if (l === "applyJsonPatch")
969
956
  return (d) => {
970
- const e = o.getState().cogsStateStore[t], s = Ft(e, d).newDocument;
971
- Ct(
957
+ const e = o.getState().cogsStateStore[t], s = jt(e, d).newDocument;
958
+ Nt(
972
959
  t,
973
960
  o.getState().initialStateGlobal[t],
974
961
  s,
975
962
  c,
976
- v,
977
- f
963
+ h,
964
+ g
978
965
  );
979
966
  const i = o.getState().stateComponents.get(t);
980
967
  if (i) {
981
- const g = It(e, s), u = new Set(g);
968
+ const f = mt(e, s), u = new Set(f);
982
969
  for (const [
983
- A,
970
+ E,
984
971
  w
985
972
  ] of i.components.entries()) {
986
973
  let T = !1;
987
- const P = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
988
- if (!P.includes("none")) {
989
- if (P.includes("all")) {
974
+ const x = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
975
+ if (!x.includes("none")) {
976
+ if (x.includes("all")) {
990
977
  w.forceUpdate();
991
978
  continue;
992
979
  }
993
- if (P.includes("component") && (w.paths.has("") && (T = !0), !T))
994
- for (const x of u) {
995
- if (w.paths.has(x)) {
980
+ if (x.includes("component") && (w.paths.has("") && (T = !0), !T))
981
+ for (const C of u) {
982
+ if (w.paths.has(C)) {
996
983
  T = !0;
997
984
  break;
998
985
  }
999
- let b = x.lastIndexOf(".");
1000
- for (; b !== -1; ) {
1001
- const U = x.substring(0, b);
1002
- if (w.paths.has(U)) {
986
+ let V = C.lastIndexOf(".");
987
+ for (; V !== -1; ) {
988
+ const D = C.substring(0, V);
989
+ if (w.paths.has(D)) {
1003
990
  T = !0;
1004
991
  break;
1005
992
  }
1006
- const B = x.substring(
1007
- b + 1
993
+ const B = C.substring(
994
+ V + 1
1008
995
  );
1009
996
  if (!isNaN(Number(B))) {
1010
- const C = U.lastIndexOf(".");
1011
- if (C !== -1) {
1012
- const N = U.substring(
997
+ const _ = D.lastIndexOf(".");
998
+ if (_ !== -1) {
999
+ const N = D.substring(
1013
1000
  0,
1014
- C
1001
+ _
1015
1002
  );
1016
1003
  if (w.paths.has(N)) {
1017
1004
  T = !0;
@@ -1019,14 +1006,14 @@ function gt(t, c, v, f) {
1019
1006
  }
1020
1007
  }
1021
1008
  }
1022
- b = U.lastIndexOf(".");
1009
+ V = D.lastIndexOf(".");
1023
1010
  }
1024
1011
  if (T) break;
1025
1012
  }
1026
- if (!T && P.includes("deps") && w.depsFunction) {
1027
- const x = w.depsFunction(s);
1028
- let b = !1;
1029
- typeof x == "boolean" ? x && (b = !0) : H(w.deps, x) || (w.deps = x, b = !0), b && (T = !0);
1013
+ if (!T && x.includes("deps") && w.depsFunction) {
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);
1030
1017
  }
1031
1018
  T && w.forceUpdate();
1032
1019
  }
@@ -1040,27 +1027,27 @@ function gt(t, c, v, f) {
1040
1027
  throw new Error("Zod schema not found");
1041
1028
  if (!d?.key)
1042
1029
  throw new Error("Validation key not found");
1043
- J(d.key);
1044
- const r = o.getState().cogsStateStore[t];
1030
+ q(d.key);
1031
+ const n = o.getState().cogsStateStore[t];
1045
1032
  try {
1046
1033
  const s = o.getState().getValidationErrors(d.key);
1047
- s && s.length > 0 && s.forEach(([g]) => {
1048
- g && g.startsWith(d.key) && J(g);
1034
+ s && s.length > 0 && s.forEach(([f]) => {
1035
+ f && f.startsWith(d.key) && q(f);
1049
1036
  });
1050
- const i = d.zodSchema.safeParse(r);
1037
+ const i = d.zodSchema.safeParse(n);
1051
1038
  return i.success ? !0 : (i.error.errors.forEach((u) => {
1052
- 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(".");
1053
1040
  e(T, w);
1054
- }), St(t), !1);
1041
+ }), ut(t), !1);
1055
1042
  } catch (s) {
1056
1043
  return console.error("Zod schema validation failed", s), !1;
1057
1044
  }
1058
1045
  };
1059
- if (l === "_componentId") return v;
1046
+ if (l === "_componentId") return h;
1060
1047
  if (l === "getComponents")
1061
1048
  return () => o().stateComponents.get(t);
1062
1049
  if (l === "getAllFormRefs")
1063
- return () => Et.getState().getFormRefsByStateKey(t);
1050
+ return () => It.getState().getFormRefsByStateKey(t);
1064
1051
  if (l === "_initialState")
1065
1052
  return o.getState().initialStateGlobal[t];
1066
1053
  if (l === "_serverState")
@@ -1073,16 +1060,16 @@ function gt(t, c, v, f) {
1073
1060
  if (l === "removeValidation") return I.removeValidation;
1074
1061
  }
1075
1062
  if (l === "getFormRef")
1076
- return () => Et.getState().getFormRef(t + "." + n.join("."));
1063
+ return () => It.getState().getFormRef(t + "." + r.join("."));
1077
1064
  if (l === "validationWrapper")
1078
1065
  return ({
1079
1066
  children: d,
1080
1067
  hideMessage: e
1081
- }) => /* @__PURE__ */ vt(
1082
- jt,
1068
+ }) => /* @__PURE__ */ St(
1069
+ Pt,
1083
1070
  {
1084
1071
  formOpts: e ? { validation: { message: "" } } : void 0,
1085
- path: n,
1072
+ path: r,
1086
1073
  validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
1087
1074
  stateKey: t,
1088
1075
  validIndices: S?.validIndices,
@@ -1090,39 +1077,39 @@ function gt(t, c, v, f) {
1090
1077
  }
1091
1078
  );
1092
1079
  if (l === "_stateKey") return t;
1093
- if (l === "_path") return n;
1080
+ if (l === "_path") return r;
1094
1081
  if (l === "_isServerSynced") return I._isServerSynced;
1095
1082
  if (l === "update")
1096
1083
  return (d, e) => {
1097
1084
  if (e?.debounce)
1098
- Mt(() => {
1099
- at(c, d, n, "");
1100
- const r = o.getState().getNestedState(t, n);
1101
- 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);
1102
1089
  }, e.debounce);
1103
1090
  else {
1104
- at(c, d, n, "");
1105
- const r = o.getState().getNestedState(t, n);
1106
- e?.afterUpdate && e.afterUpdate(r);
1091
+ nt(c, d, r, "");
1092
+ const n = o.getState().getNestedState(t, r);
1093
+ e?.afterUpdate && e.afterUpdate(n);
1107
1094
  }
1108
- p(n);
1095
+ p(r);
1109
1096
  };
1110
1097
  if (l === "formElement")
1111
- return (d, e) => /* @__PURE__ */ vt(
1112
- Ot,
1098
+ return (d, e) => /* @__PURE__ */ St(
1099
+ _t,
1113
1100
  {
1114
1101
  setState: c,
1115
1102
  stateKey: t,
1116
- path: n,
1103
+ path: r,
1117
1104
  child: d,
1118
1105
  formOpts: e
1119
1106
  }
1120
1107
  );
1121
- const j = [...n, l], ot = o.getState().getNestedState(t, j);
1122
- return a(ot, j, S);
1108
+ const j = [...r, l], tt = o.getState().getNestedState(t, j);
1109
+ return a(tt, j, S);
1123
1110
  }
1124
- }, G = new Proxy(R, F);
1125
- return y.set(W, {
1111
+ }, G = new Proxy(O, R);
1112
+ return v.set(W, {
1126
1113
  proxy: G,
1127
1114
  stateVersion: k
1128
1115
  }), G;
@@ -1131,107 +1118,107 @@ function gt(t, c, v, f) {
1131
1118
  o.getState().getNestedState(t, [])
1132
1119
  );
1133
1120
  }
1134
- function kt(t) {
1135
- return st(Jt, { proxy: t });
1121
+ function At(t) {
1122
+ return rt(Bt, { proxy: t });
1136
1123
  }
1137
- function qt({
1124
+ function zt({
1138
1125
  proxy: t,
1139
1126
  rebuildStateShape: c
1140
1127
  }) {
1141
- const v = o().getNestedState(t._stateKey, t._path);
1142
- return Array.isArray(v) ? c(
1143
- v,
1128
+ const h = o().getNestedState(t._stateKey, t._path);
1129
+ return Array.isArray(h) ? c(
1130
+ h,
1144
1131
  t._path
1145
1132
  ).stateMapNoRender(
1146
- (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)
1147
1134
  ) : null;
1148
1135
  }
1149
- function Jt({
1136
+ function Bt({
1150
1137
  proxy: t
1151
1138
  }) {
1152
- const c = Y(null), v = `${t._stateKey}-${t._path.join(".")}`;
1153
- return lt(() => {
1154
- const f = c.current;
1155
- if (!f || !f.parentElement) return;
1156
- const y = f.parentElement, p = Array.from(y.childNodes).indexOf(f);
1157
- let I = y.getAttribute("data-parent-id");
1158
- I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I));
1159
- 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 = {
1160
1147
  instanceId: `instance-${crypto.randomUUID()}`,
1161
1148
  parentId: I,
1162
1149
  position: p,
1163
1150
  effect: t._effect
1164
1151
  };
1165
- o.getState().addSignalElement(v, m);
1166
- 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);
1167
1154
  let S;
1168
1155
  if (t._effect)
1169
1156
  try {
1170
1157
  S = new Function(
1171
1158
  "state",
1172
1159
  `return (${t._effect})(state)`
1173
- )(n);
1174
- } catch (R) {
1175
- console.error("Error evaluating effect function during mount:", R), S = n;
1160
+ )(r);
1161
+ } catch (O) {
1162
+ console.error("Error evaluating effect function during mount:", O), S = r;
1176
1163
  }
1177
1164
  else
1178
- S = n;
1165
+ S = r;
1179
1166
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1180
1167
  const W = document.createTextNode(String(S));
1181
- f.replaceWith(W);
1182
- }, [t._stateKey, t._path.join("."), t._effect]), st("span", {
1168
+ g.replaceWith(W);
1169
+ }, [t._stateKey, t._path.join("."), t._effect]), rt("span", {
1183
1170
  ref: c,
1184
1171
  style: { display: "none" },
1185
- "data-signal-id": v
1172
+ "data-signal-id": h
1186
1173
  });
1187
1174
  }
1188
- function de(t) {
1189
- const c = xt(
1190
- (v) => {
1191
- 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) || {
1192
1179
  components: /* @__PURE__ */ new Map()
1193
1180
  };
1194
- return f.components.set(t._stateKey, {
1195
- forceUpdate: v,
1181
+ return g.components.set(t._stateKey, {
1182
+ forceUpdate: h,
1196
1183
  paths: /* @__PURE__ */ new Set([t._path.join(".")])
1197
- }), () => f.components.delete(t._stateKey);
1184
+ }), () => g.components.delete(t._stateKey);
1198
1185
  },
1199
1186
  () => o.getState().getNestedState(t._stateKey, t._path)
1200
1187
  );
1201
- return st("text", {}, String(c));
1188
+ return rt("text", {}, String(c));
1202
1189
  }
1203
- function Yt({
1190
+ function qt({
1204
1191
  stateKey: t,
1205
1192
  itemComponentId: c,
1206
- itemPath: v,
1207
- children: f
1193
+ itemPath: h,
1194
+ children: g
1208
1195
  }) {
1209
- const [, y] = rt({}), [k, p] = Ut();
1210
- return lt(() => {
1211
- 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, {
1212
1199
  virtualizer: {
1213
1200
  itemHeight: p.height
1214
1201
  }
1215
1202
  });
1216
- }, [p.height]), dt(() => {
1203
+ }, [p.height]), it(() => {
1217
1204
  const I = `${t}////${c}`, a = o.getState().stateComponents.get(t) || {
1218
1205
  components: /* @__PURE__ */ new Map()
1219
1206
  };
1220
1207
  return a.components.set(I, {
1221
- forceUpdate: () => y({}),
1222
- paths: /* @__PURE__ */ new Set([v.join(".")])
1208
+ forceUpdate: () => v({}),
1209
+ paths: /* @__PURE__ */ new Set([h.join(".")])
1223
1210
  }), o.getState().stateComponents.set(t, a), () => {
1224
- const m = o.getState().stateComponents.get(t);
1225
- m && m.components.delete(I);
1211
+ const y = o.getState().stateComponents.get(t);
1212
+ y && y.components.delete(I);
1226
1213
  };
1227
- }, [t, c, v.join(".")]), /* @__PURE__ */ vt("div", { ref: k, children: f });
1214
+ }, [t, c, h.join(".")]), /* @__PURE__ */ St("div", { ref: k, children: g });
1228
1215
  }
1229
1216
  export {
1230
- kt as $cogsSignal,
1231
- de as $cogsSignalStore,
1232
- ie as addStateOptions,
1233
- ce as createCogsState,
1234
- le as notifyComponent,
1235
- 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
1236
1223
  };
1237
1224
  //# sourceMappingURL=CogsState.jsx.map