cogsbox-state 0.5.275 → 0.5.277

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