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