cogsbox-state 0.5.374 → 0.5.375

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