cogsbox-state 0.5.357 → 0.5.358

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