cogsbox-state 0.5.358 → 0.5.360

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