cogsbox-state 0.5.388 → 0.5.390

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