cogsbox-state 0.5.373 → 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 ye } from "react/jsx-runtime";
3
- import { useState as Q, useRef as Z, useEffect as oe, useLayoutEffect as ce, useMemo as pe, createElement as le, useSyncExternalStore as Ge, startTransition as Le, useCallback as Ae } from "react";
4
- import { transformStateFunc as Re, isDeepEqual as q, isFunction as K, getNestedValue as J, getDifferences as Ee, debounce as De } from "./utility.js";
5
- import { pushFunc as ve, updateFn as ie, cutFunc as fe, ValidationWrapper as Ue, FormControlComponent as je } from "./Functions.jsx";
6
- import He from "superjson";
7
- import { v4 as we } 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 Ne } from "./store.js";
10
- import { useCogsConfig as xe } from "./CogsStateClient.jsx";
11
- import { applyPatch as Fe } from "fast-json-patch";
12
- import Be from "react-use-measure";
13
- function Ce(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 $e({
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] || {}, C = 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 && C(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 gt(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 ft = (e, i) => {
36
+ const Tt = (e, i) => {
37
37
  let m = e;
38
- const [g, T] = Re(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 C = (v, a) => {
49
- const [h] = Q(a?.componentId ?? we());
50
- $e({
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, G] = Xe(
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,49 +68,49 @@ const ft = (e, i) => {
68
68
  serverState: a?.serverState
69
69
  }
70
70
  );
71
- return G;
71
+ return L;
72
72
  };
73
- function p(v, a) {
74
- $e({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && Ye(v, a), he(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: C, setCogsOptions: p };
76
+ return { useCogsState: A, setCogsOptions: O };
77
77
  }, {
78
- setUpdaterState: Se,
79
- setState: ne,
78
+ setUpdaterState: me,
79
+ setState: te,
80
80
  getInitialOptions: re,
81
- getKeyState: Me,
82
- getValidationErrors: We,
83
- setStateLog: ze,
84
- updateInitialStateGlobal: _e,
85
- addValidationError: qe,
81
+ getKeyState: Le,
82
+ getValidationErrors: Je,
83
+ setStateLog: Ye,
84
+ updateInitialStateGlobal: Ne,
85
+ addValidationError: Ze,
86
86
  removeValidationError: X,
87
- setServerSyncActions: Je
88
- } = r.getState(), ke = (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 C = K(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
96
- if (C && g) {
97
- const p = `${g}-${i}-${C}`;
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 = Ie(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 = He.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
  }
113
- }, Ie = (e) => {
113
+ }, he = (e) => {
114
114
  if (!e) return null;
115
115
  try {
116
116
  const i = window.localStorage.getItem(e);
@@ -118,30 +118,30 @@ const ft = (e, i) => {
118
118
  } catch (i) {
119
119
  return console.error("Error loading from localStorage:", i), null;
120
120
  }
121
- }, Ye = (e, i) => {
122
- const m = r.getState().cogsStateStore[e], { sessionId: g } = xe(), T = K(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
123
- if (T && g) {
124
- const C = Ie(
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 (C && C.lastUpdated > (C.lastSyncedWithServer || 0))
128
- return ne(e, C.state), he(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
- }, Pe = (e, i, m, g, T, C) => {
132
- const p = {
131
+ }, Ge = (e, i, m, g, I, A) => {
132
+ const O = {
133
133
  initialState: i,
134
- updaterState: me(
134
+ updaterState: Te(
135
135
  e,
136
136
  g,
137
- T,
138
- C
137
+ I,
138
+ A
139
139
  ),
140
140
  state: m
141
141
  };
142
- _e(e, p.initialState), Se(e, p.updaterState), ne(e, p.state);
143
- }, he = (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,30 +149,30 @@ const ft = (e, i) => {
149
149
  }), queueMicrotask(() => {
150
150
  m.forEach((g) => g());
151
151
  });
152
- }, St = (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
- }, Ze = (e, i, m, g) => {
160
+ }, Ke = (e, i, m, g) => {
161
161
  switch (e) {
162
162
  case "update":
163
163
  return {
164
- oldValue: J(i, g),
165
- newValue: J(m, g)
164
+ oldValue: Z(i, g),
165
+ newValue: Z(m, g)
166
166
  };
167
167
  case "insert":
168
168
  return {
169
169
  oldValue: null,
170
170
  // or undefined
171
- newValue: J(m, g)
171
+ newValue: Z(m, g)
172
172
  };
173
173
  case "cut":
174
174
  return {
175
- oldValue: J(i, g),
175
+ oldValue: Z(i, g),
176
176
  newValue: null
177
177
  // or undefined
178
178
  };
@@ -180,57 +180,57 @@ const ft = (e, i) => {
180
180
  return { oldValue: null, newValue: null };
181
181
  }
182
182
  };
183
- function Xe(e, {
183
+ function et(e, {
184
184
  stateKey: i,
185
185
  serverSync: m,
186
186
  localStorage: g,
187
- formElements: T,
188
- reactiveDeps: C,
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, G] = Q({}), { sessionId: L } = xe();
197
- let F = !i;
198
- const [I] = Q(i ?? we()), l = r.getState().stateLog[I], de = Z(/* @__PURE__ */ new Set()), ee = Z(v ?? we()), P = Z(
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
- P.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
- Ce(I, {
215
+ ke(T, {
216
216
  initialState: a
217
217
  });
218
- const t = P.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 && L && (u = Ie(`${L}-${I}-${E}`));
224
- let y = a, O = !1;
225
- const k = s ? Date.now() : 0, A = u?.lastUpdated || 0, x = u?.lastSyncedWithServer || 0;
226
- s && k > A ? (y = t.serverState.data, O = !0) : u && A > x && (y = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(y)), r.getState().initializeShadowState(I, a), Pe(
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
- L
233
- ), O && E && L && ke(y, I, t, L, Date.now()), he(I), (Array.isArray(p) ? p : [p || "component"]).includes("none") || G({});
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,
@@ -238,267 +238,267 @@ function Xe(e, {
238
238
  S?.data,
239
239
  ...n || []
240
240
  ]), ce(() => {
241
- F && Ce(I, {
241
+ W && ke(T, {
242
242
  serverSync: m,
243
- formElements: T,
243
+ formElements: I,
244
244
  initialState: a,
245
245
  localStorage: g,
246
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: () => G({}),
251
+ return r.components.set(t, {
252
+ forceUpdate: () => L({}),
253
253
  paths: /* @__PURE__ */ new Set(),
254
254
  deps: [],
255
- depsFunction: C || void 0,
256
- reactiveType: p ?? ["component", "deps"]
257
- }), r.getState().stateComponents.set(I, o), G({}), () => {
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(".")}`;
261
+ const ae = (t, r, s, c) => {
262
+ if (Array.isArray(r)) {
263
+ const u = `${T}-${r.join(".")}`;
264
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 M = !1, N = f.signalDomElements.get(y);
271
- if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
- const _ = o.slice(0, -1), j = J(E, _);
273
- if (Array.isArray(j)) {
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
+ if ((!C || C.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
272
+ const V = r.slice(0, -1), R = Z(E, V);
273
+ if (Array.isArray(R)) {
274
274
  M = !0;
275
- const w = `${I}-${_.join(".")}`;
276
- N = f.signalDomElements.get(w);
275
+ const v = `${T}-${V.join(".")}`;
276
+ C = f.signalDomElements.get(v);
277
277
  }
278
278
  }
279
- if (N) {
280
- const _ = M ? J(E, o.slice(0, -1)) : J(E, o);
281
- N.forEach(({ parentId: j, position: w, effect: R }) => {
282
- const V = document.querySelector(
283
- `[data-parent-id="${j}"]`
279
+ if (C) {
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 (V) {
286
- const W = Array.from(V.childNodes);
287
- if (W[w]) {
288
- const D = R ? new Function("state", `return (${R})(state)`)(_) : _;
289
- W[w].textContent = String(D);
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 || P.current?.validation?.key) && o && X(
296
- (c || P.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 O = o.slice(0, o.length - 1);
298
+ const _ = r.slice(0, r.length - 1);
299
299
  s.updateType === "cut" && P.current?.validation?.key && X(
300
- P.current?.validation?.key + "." + O.join(".")
301
- ), s.updateType === "insert" && P.current?.validation?.key && We(
302
- P.current?.validation?.key + "." + O.join(".")
303
- ).filter(([N, _]) => {
304
- let j = N?.split(".").length;
305
- if (N == O.join(".") && j == O.length - 1) {
306
- let w = N + "." + O;
307
- X(N), qe(w, _);
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 k = f.stateComponents.get(I);
311
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", k), k) {
312
- const M = Ee(u, E), N = new Set(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
- j,
315
- w
316
- ] of k.components.entries()) {
317
- let R = !1;
318
- const V = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
319
- if (console.log("component", w), !V.includes("none")) {
320
- if (V.includes("all")) {
321
- w.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 (V.includes("component") && ((w.paths.has(_) || w.paths.has("")) && (R = !0), !R))
325
- for (const W of N) {
326
- let D = 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 (w.paths.has(D)) {
329
- R = !0;
328
+ if (v.paths.has(j)) {
329
+ D = !0;
330
330
  break;
331
331
  }
332
- const $ = D.lastIndexOf(".");
333
- if ($ !== -1) {
334
- const b = D.substring(
332
+ const se = j.lastIndexOf(".");
333
+ if (se !== -1) {
334
+ const ue = j.substring(
335
335
  0,
336
- $
336
+ se
337
337
  );
338
338
  if (!isNaN(
339
- Number(D.substring($ + 1))
340
- ) && w.paths.has(b)) {
341
- R = !0;
339
+ Number(j.substring(se + 1))
340
+ ) && v.paths.has(ue)) {
341
+ D = !0;
342
342
  break;
343
343
  }
344
- D = b;
344
+ j = ue;
345
345
  } else
346
- D = "";
347
- if (D === "")
346
+ j = "";
347
+ if (j === "")
348
348
  break;
349
349
  }
350
- if (R) break;
350
+ if (D) break;
351
351
  }
352
- if (!R && V.includes("deps") && w.depsFunction) {
353
- const W = w.depsFunction(E);
354
- let D = !1;
355
- typeof W == "boolean" ? W && (D = !0) : q(w.deps, W) || (w.deps = W, D = !0), D && (R = !0);
352
+ if (!D && $.includes("deps") && v.depsFunction) {
353
+ const z = v.depsFunction(E);
354
+ let j = !1;
355
+ typeof z == "boolean" ? z && (j = !0) : q(v.deps, z) || (v.deps = z, j = !0), j && (D = !0);
356
356
  }
357
- R && w.forceUpdate();
357
+ D && v.forceUpdate();
358
358
  }
359
359
  }
360
360
  }
361
- const A = Date.now();
362
- o = o.map((M, N) => {
363
- const _ = o.slice(0, -1), j = J(E, _);
364
- return N === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (j.length - 1).toString() : M;
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 } = Ze(
366
+ const { oldValue: k, newValue: U } = Ke(
367
367
  s.updateType,
368
368
  u,
369
369
  E,
370
- o
370
+ r
371
371
  ), Y = {
372
- timeStamp: A,
373
- stateKey: I,
374
- path: o,
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 M = o.slice(0, -1);
386
- f.insertShadowArrayElement(I, M, U);
385
+ const M = r.slice(0, -1);
386
+ f.insertShadowArrayElement(T, M, U);
387
387
  break;
388
388
  case "cut":
389
- const N = o.slice(0, -1), _ = parseInt(o[o.length - 1]);
390
- f.removeShadowArrayElement(I, N, _);
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 (ze(I, (M) => {
394
- const _ = [...M ?? [], Y].reduce((j, w) => {
395
- const R = `${w.stateKey}:${JSON.stringify(w.path)}`, V = j.get(R);
396
- return V ? (V.timeStamp = Math.max(V.timeStamp, w.timeStamp), V.newValue = w.newValue, V.oldValue = V.oldValue ?? w.oldValue, V.updateType = w.updateType) : j.set(R, { ...w }), j;
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(_.values());
399
- }), ke(
398
+ return Array.from(V.values());
399
+ }), xe(
400
400
  E,
401
- I,
401
+ T,
402
402
  P.current,
403
- L
403
+ G
404
404
  ), P.current?.middleware && P.current.middleware({
405
405
  updateLog: l,
406
406
  update: Y
407
407
  }), P.current?.serverSync) {
408
- const M = f.serverState[I], N = P.current?.serverSync;
409
- Je(I, {
410
- syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
408
+ const M = f.serverState[T], C = P.current?.serverSync;
409
+ Xe(T, {
410
+ syncKey: typeof C.syncKey == "string" ? C.syncKey : C.syncKey({ state: E }),
411
411
  rollBackState: M,
412
- actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
412
+ actionTimeStamp: Date.now() + (C.debounce ?? 3e3),
413
413
  status: "waiting"
414
414
  });
415
415
  }
416
416
  return E;
417
417
  });
418
418
  };
419
- r.getState().updaterState[I] || (Se(
420
- I,
421
- me(
422
- I,
419
+ o.getState().updaterState[T] || (me(
420
+ T,
421
+ Te(
422
+ T,
423
423
  ae,
424
424
  ee.current,
425
- L
425
+ G
426
426
  )
427
- ), r.getState().cogsStateStore[I] || ne(I, e), r.getState().initialStateGlobal[I] || _e(I, e));
428
- const d = pe(() => me(
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
- L
433
- ), [I, L]);
434
- return [Me(I), d];
432
+ G
433
+ ), [T, G]);
434
+ return [Le(T), d];
435
435
  }
436
- function me(e, i, m, g) {
437
- const T = /* @__PURE__ */ new Map();
438
- let C = 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
- C++;
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(), C++;
453
- const H = a(S, []), G = re(e), L = K(G?.localStorage?.key) ? G?.localStorage?.key(S) : G?.localStorage?.key, F = `${g}-${e}-${L}`;
454
- F && localStorage.removeItem(F), Se(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(), C++;
462
- const n = me(
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), G = K(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, L = `${g}-${e}-${G}`;
468
- return localStorage.getItem(L) && localStorage.removeItem(L), Le(() => {
469
- _e(e, h), r.getState().initializeShadowState(e, h), Se(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, Me(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 G = 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
- G[I] = v[I];
492
+ Object.keys(y).forEach((T) => {
493
+ L[T] = y[T];
494
494
  });
495
- const L = {
496
- apply(I, l, de) {
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
503
  const de = /* @__PURE__ */ new Set([
504
504
  "insert",
@@ -524,40 +524,40 @@ function me(e, i, m, g) {
524
524
  "getComponents"
525
525
  ]);
526
526
  if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !de.has(l)) {
527
- const d = `${e}////${m}`, t = r.getState().stateComponents.get(e);
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
- return () => Ee(
544
- r.getState().cogsStateStore[e],
545
- r.getState().initialStateGlobal[e]
543
+ return () => we(
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 me(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 = J(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 = J(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,168 +611,175 @@ function me(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 = Z(!1), E = Z(null), [y, O] = Q({
625
+ } = t, u = J(!1), E = J(null), [p, _] = Q({
626
626
  startIndex: 0,
627
627
  endIndex: 10
628
- }), [k, A] = Q("IDLE_AT_TOP"), x = Z(0), U = Z(f), [Y, M] = Q(0);
629
- oe(() => r.getState().subscribeToShadowState(e, () => {
630
- M((b) => b + 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 N = r().getNestedState(
632
+ const R = o().getNestedState(
633
633
  e,
634
634
  n
635
- ), _ = N.length, { totalHeight: j, positions: w } = pe(() => {
636
- const $ = r.getState().getShadowMetadata(e, n) || [];
637
- let b = 0;
638
- const z = [];
639
- for (let B = 0; B < _; B++) {
640
- z[B] = b;
641
- const te = $[B]?.virtualizer?.itemHeight;
642
- b += 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: b, positions: z };
644
+ return { totalHeight: x, positions: B };
645
645
  }, [
646
- _,
646
+ v,
647
647
  e,
648
648
  n.join("."),
649
- o,
650
- Y
651
- ]), R = pe(() => {
652
- const $ = Math.max(0, y.startIndex), b = Math.min(_, y.endIndex), z = Array.from(
653
- { length: b - $ },
654
- (te, se) => $ + se
655
- ), B = z.map((te) => N[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, N, _]);
660
+ }, [p.startIndex, p.endIndex, R, v]);
661
661
  ce(() => {
662
- const $ = !q(
662
+ const b = !q(
663
663
  f,
664
- U.current
665
- ), b = _ > x.current;
666
- if ($) {
667
- console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), A("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
- b && k === "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
- ), A("GETTING_HEIGHTS")), x.current = _, U.current = f;
673
- }, [_, ...f]), ce(() => {
674
- const $ = E.current;
675
- if (!$) return;
676
- let b;
677
- if (k === "IDLE_AT_TOP" && c && _ > 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
- ), A("GETTING_HEIGHTS");
681
- else if (k === "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
- ), O({
685
- startIndex: Math.max(0, _ - 10 - s),
686
- endIndex: _
687
- }), b = setInterval(() => {
688
- const z = _ - 1;
689
- ((r.getState().getShadowMetadata(e, n) || [])[z]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(b), 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
- ), A("SCROLLING_TO_BOTTOM")));
691
+ ), w("SCROLLING_TO_BOTTOM")));
692
692
  }, 100);
693
- else if (k === "SCROLLING_TO_BOTTOM") {
693
+ else if (N === "SCROLLING_TO_BOTTOM") {
694
694
  console.log(
695
695
  "ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
696
- );
697
- const z = x.current === 0 ? "auto" : "smooth";
698
- $.scrollTo({
699
- top: $.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
- ), u.current = !1, A("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
- b && clearInterval(b);
713
+ x && clearInterval(x);
714
714
  };
715
- }, [k, _, w]), oe(() => {
716
- const $ = E.current;
717
- if (!$) return;
718
- const b = () => {
719
- $.scrollHeight - $.scrollTop - $.clientHeight < 1 ? u.current = !1 : (console.log(
715
+ }, [N, v, $]), oe(() => {
716
+ const b = E.current;
717
+ if (!b) return;
718
+ const x = r / 2, B = () => {
719
+ if (k.current)
720
+ return;
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(
720
725
  "USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
721
- ), u.current = !0, A("IDLE_NOT_AT_BOTTOM"));
722
- const { scrollTop: B, clientHeight: te } = $;
723
- let se = 0, ue = _ - 1;
724
- for (; se <= ue; ) {
725
- const Te = Math.floor((se + ue) / 2);
726
- w[Te] < B ? se = Te + 1 : ue = Te - 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;
727
734
  }
728
- const Oe = Math.max(0, ue - s);
729
- let ge = Oe;
730
- const Ve = B + te;
731
- for (; ge < _ && w[ge] < Ve; )
732
- ge++;
733
- O({
734
- startIndex: Oe,
735
- endIndex: Math.min(_, ge + s)
735
+ const Ce = Math.max(0, ge - s);
736
+ let fe = Ce;
737
+ const Re = H + ve;
738
+ for (; fe < v && $[fe] < Re; )
739
+ fe++;
740
+ _({
741
+ startIndex: Ce,
742
+ endIndex: Math.min(v, fe + s)
736
743
  });
737
744
  };
738
- return $.addEventListener("scroll", b, {
745
+ return b.addEventListener("scroll", B, {
739
746
  passive: !0
740
- }), () => $.removeEventListener("scroll", b);
741
- }, [_, w, k]);
742
- const V = Ae(() => {
747
+ }), () => b.removeEventListener("scroll", B);
748
+ }, [v, $, N, r]);
749
+ const j = $e(() => {
743
750
  console.log(
744
751
  "USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
745
- ), A("SCROLLING_TO_BOTTOM");
746
- }, []), W = Ae(
747
- ($, b = "smooth") => {
748
- E.current && w[$] !== void 0 && (A("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
749
- top: w[$],
750
- behavior: b
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
751
758
  }));
752
759
  },
753
- [w]
754
- ), D = {
760
+ [$]
761
+ ), ue = {
755
762
  outer: {
756
763
  ref: E,
757
764
  style: { overflowY: "auto", height: "100%" }
758
765
  },
759
766
  inner: {
760
767
  style: {
761
- height: `${j}px`,
768
+ height: `${D}px`,
762
769
  position: "relative"
763
770
  }
764
771
  },
765
772
  list: {
766
773
  style: {
767
- transform: `translateY(${w[y.startIndex] || 0}px)`
774
+ transform: `translateY(${$[p.startIndex] || 0}px)`
768
775
  }
769
776
  }
770
777
  };
771
778
  return {
772
- virtualState: R,
773
- virtualizerProps: D,
774
- scrollToBottom: V,
775
- scrollToIndex: W
779
+ virtualState: z,
780
+ virtualizerProps: ue,
781
+ scrollToBottom: j,
782
+ scrollToIndex: se
776
783
  };
777
784
  };
778
785
  if (l === "stateSort")
@@ -801,31 +808,31 @@ function me(e, i, m, g) {
801
808
  };
802
809
  if (l === "stateMap")
803
810
  return (t) => {
804
- const o = r.getState().getNestedState(e, n);
805
- return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
806
- const u = o[c], E = [...n, c.toString()], y = a(u, E, S);
807
- 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, {
808
815
  register: () => {
809
- const [, k] = Q({}), A = `${m}-${n.join(".")}-${c}`;
816
+ const [, N] = Q({}), w = `${m}-${n.join(".")}-${c}`;
810
817
  ce(() => {
811
- const x = `${e}////${A}`, U = r.getState().stateComponents.get(e) || {
818
+ const k = `${e}////${w}`, U = o.getState().stateComponents.get(e) || {
812
819
  components: /* @__PURE__ */ new Map()
813
820
  };
814
- return U.components.set(x, {
815
- forceUpdate: () => k({}),
821
+ return U.components.set(k, {
822
+ forceUpdate: () => N({}),
816
823
  paths: /* @__PURE__ */ new Set([E.join(".")])
817
- }), r.getState().stateComponents.set(e, U), () => {
818
- const Y = r.getState().stateComponents.get(e);
819
- Y && Y.components.delete(x);
824
+ }), o.getState().stateComponents.set(e, U), () => {
825
+ const Y = o.getState().stateComponents.get(e);
826
+ Y && Y.components.delete(k);
820
827
  };
821
- }, [e, A]);
828
+ }, [e, w]);
822
829
  },
823
830
  index: f,
824
831
  originalIndex: c
825
832
  });
826
833
  }) : (console.warn(
827
834
  `stateMap called on a non-array value at path: ${n.join(".")}. The current value is:`,
828
- o
835
+ r
829
836
  ), null);
830
837
  };
831
838
  if (l === "stateMapNoRender")
@@ -842,7 +849,7 @@ function me(e, i, m, g) {
842
849
  );
843
850
  });
844
851
  if (l === "$stateMap")
845
- return (t) => le(Qe, {
852
+ return (t) => le(tt, {
846
853
  proxy: {
847
854
  _stateKey: e,
848
855
  _path: n,
@@ -853,20 +860,20 @@ function me(e, i, m, g) {
853
860
  });
854
861
  if (l === "stateList")
855
862
  return (t) => {
856
- const o = r.getState().getNestedState(e, n);
857
- return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
858
- const u = o[c], E = [...n, c.toString()], y = a(u, E, S), O = `${m}-${n.join(".")}-${c}`;
859
- return le(et, {
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, {
860
867
  key: c,
861
868
  stateKey: e,
862
- itemComponentId: O,
869
+ itemComponentId: _,
863
870
  itemPath: E,
864
871
  children: t(
865
872
  u,
866
- y,
873
+ p,
867
874
  f,
868
- o,
869
- a(o, n, S)
875
+ r,
876
+ a(r, n, S)
870
877
  )
871
878
  });
872
879
  }) : (console.warn(
@@ -875,9 +882,9 @@ function me(e, i, m, g) {
875
882
  };
876
883
  if (l === "stateFlattenOn")
877
884
  return (t) => {
878
- const o = h;
879
- T.clear(), C++;
880
- const s = o.flatMap(
885
+ const r = h;
886
+ I.clear(), A++;
887
+ const s = r.flatMap(
881
888
  (c) => c[t] ?? []
882
889
  );
883
890
  return a(
@@ -888,60 +895,60 @@ function me(e, i, m, g) {
888
895
  };
889
896
  if (l === "index")
890
897
  return (t) => {
891
- const o = h[t];
892
- return a(o, [...n, t.toString()]);
898
+ const r = h[t];
899
+ return a(r, [...n, t.toString()]);
893
900
  };
894
901
  if (l === "last")
895
902
  return () => {
896
- const t = r.getState().getNestedState(e, n);
903
+ const t = o.getState().getNestedState(e, n);
897
904
  if (t.length === 0) return;
898
- 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()];
899
906
  return a(s, c);
900
907
  };
901
908
  if (l === "insert")
902
- return (t) => (p(n), ve(i, t, n, e), a(
903
- r.getState().getNestedState(e, n),
909
+ return (t) => (O(n), Oe(i, t, n, e), a(
910
+ o.getState().getNestedState(e, n),
904
911
  n
905
912
  ));
906
913
  if (l === "uniqueInsert")
907
- return (t, o, s) => {
908
- 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;
909
916
  let u = null;
910
- if (!c.some((y) => {
911
- if (o) {
912
- const k = o.every(
913
- (A) => q(y[A], f[A])
917
+ if (!c.some((p) => {
918
+ if (r) {
919
+ const N = r.every(
920
+ (w) => q(p[w], f[w])
914
921
  );
915
- return k && (u = y), k;
922
+ return N && (u = p), N;
916
923
  }
917
- const O = q(y, f);
918
- return O && (u = y), O;
924
+ const _ = q(p, f);
925
+ return _ && (u = p), _;
919
926
  }))
920
- p(n), ve(i, f, n, e);
927
+ O(n), Oe(i, f, n, e);
921
928
  else if (s && u) {
922
- const y = s(u), O = c.map(
923
- (k) => q(k, u) ? y : k
929
+ const p = s(u), _ = c.map(
930
+ (N) => q(N, u) ? p : N
924
931
  );
925
- p(n), ie(i, O, n);
932
+ O(n), ie(i, _, n);
926
933
  }
927
934
  };
928
935
  if (l === "cut")
929
- return (t, o) => {
930
- if (!o?.waitForSync)
931
- return p(n), fe(i, n, e, t), a(
932
- 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),
933
940
  n
934
941
  );
935
942
  };
936
943
  if (l === "cutByValue")
937
944
  return (t) => {
938
- for (let o = 0; o < h.length; o++)
939
- h[o] === t && fe(i, n, e, o);
945
+ for (let r = 0; r < h.length; r++)
946
+ h[r] === t && Se(i, n, e, r);
940
947
  };
941
948
  if (l === "toggleByValue")
942
949
  return (t) => {
943
- const o = h.findIndex((s) => s === t);
944
- o > -1 ? fe(i, n, e, o) : ve(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);
945
952
  };
946
953
  if (l === "stateFind")
947
954
  return (t) => {
@@ -953,9 +960,9 @@ function me(e, i, m, g) {
953
960
  return a(s.item, c, S);
954
961
  };
955
962
  if (l === "findWith")
956
- return (t, o) => {
963
+ return (t, r) => {
957
964
  const c = d().find(
958
- ({ item: u }) => u[t] === o
965
+ ({ item: u }) => u[t] === r
959
966
  );
960
967
  if (!c) return;
961
968
  const f = [...n, c.originalIndex.toString()];
@@ -964,9 +971,9 @@ function me(e, i, m, g) {
964
971
  }
965
972
  const ee = n[n.length - 1];
966
973
  if (!isNaN(Number(ee))) {
967
- 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);
968
975
  if (Array.isArray(t) && l === "cut")
969
- return () => fe(
976
+ return () => Se(
970
977
  i,
971
978
  d,
972
979
  e,
@@ -976,170 +983,170 @@ function me(e, i, m, g) {
976
983
  if (l === "get")
977
984
  return () => {
978
985
  if (S?.validIndices && Array.isArray(h)) {
979
- const d = r.getState().getNestedState(e, n);
986
+ const d = o.getState().getNestedState(e, n);
980
987
  return S.validIndices.map((t) => d[t]);
981
988
  }
982
- return r.getState().getNestedState(e, n);
989
+ return o.getState().getNestedState(e, n);
983
990
  };
984
991
  if (l === "$derive")
985
- return (d) => be({
992
+ return (d) => Pe({
986
993
  _stateKey: e,
987
994
  _path: n,
988
995
  _effect: d.toString()
989
996
  });
990
997
  if (l === "$get")
991
- return () => be({
998
+ return () => Pe({
992
999
  _stateKey: e,
993
1000
  _path: n
994
1001
  });
995
1002
  if (l === "lastSynced") {
996
1003
  const d = `${e}:${n.join(".")}`;
997
- return r.getState().getSyncInfo(d);
1004
+ return o.getState().getSyncInfo(d);
998
1005
  }
999
1006
  if (l == "getLocalStorage")
1000
- return (d) => Ie(g + "-" + e + "-" + d);
1007
+ return (d) => he(g + "-" + e + "-" + d);
1001
1008
  if (l === "_selected") {
1002
- const d = n.slice(0, -1), t = d.join("."), o = r.getState().getNestedState(e, d);
1003
- 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;
1004
1011
  }
1005
1012
  if (l === "setSelected")
1006
1013
  return (d) => {
1007
- const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
1008
- d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
1009
- const c = r.getState().getNestedState(e, [...t]);
1010
- ie(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);
1011
1018
  };
1012
1019
  if (l === "toggleSelected")
1013
1020
  return () => {
1014
- const d = n.slice(0, -1), t = Number(n[n.length - 1]), o = d.join("."), s = r.getState().getSelectedIndex(e, o);
1015
- 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(
1016
1023
  e,
1017
- o,
1024
+ r,
1018
1025
  s === t ? void 0 : t
1019
1026
  );
1020
- const c = r.getState().getNestedState(e, [...d]);
1021
- ie(i, c, d), p(d);
1027
+ const c = o.getState().getNestedState(e, [...d]);
1028
+ ie(i, c, d), O(d);
1022
1029
  };
1023
1030
  if (n.length == 0) {
1024
1031
  if (l === "applyJsonPatch")
1025
1032
  return (d) => {
1026
- const t = r.getState().cogsStateStore[e], s = Fe(t, d).newDocument;
1027
- Pe(
1033
+ const t = o.getState().cogsStateStore[e], s = ze(t, d).newDocument;
1034
+ Ge(
1028
1035
  e,
1029
- r.getState().initialStateGlobal[e],
1036
+ o.getState().initialStateGlobal[e],
1030
1037
  s,
1031
1038
  i,
1032
1039
  m,
1033
1040
  g
1034
1041
  );
1035
- const c = r.getState().stateComponents.get(e);
1042
+ const c = o.getState().stateComponents.get(e);
1036
1043
  if (c) {
1037
- const f = Ee(t, s), u = new Set(f);
1044
+ const f = we(t, s), u = new Set(f);
1038
1045
  for (const [
1039
1046
  E,
1040
- y
1047
+ p
1041
1048
  ] of c.components.entries()) {
1042
- let O = !1;
1043
- const k = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
1044
- if (!k.includes("none")) {
1045
- if (k.includes("all")) {
1046
- 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();
1047
1054
  continue;
1048
1055
  }
1049
- if (k.includes("component") && (y.paths.has("") && (O = !0), !O))
1050
- for (const A of u) {
1051
- if (y.paths.has(A)) {
1052
- O = !0;
1056
+ if (N.includes("component") && (p.paths.has("") && (_ = !0), !_))
1057
+ for (const w of u) {
1058
+ if (p.paths.has(w)) {
1059
+ _ = !0;
1053
1060
  break;
1054
1061
  }
1055
- let x = A.lastIndexOf(".");
1056
- for (; x !== -1; ) {
1057
- const U = A.substring(0, x);
1058
- if (y.paths.has(U)) {
1059
- O = !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;
1060
1067
  break;
1061
1068
  }
1062
- const Y = A.substring(
1063
- x + 1
1069
+ const Y = w.substring(
1070
+ k + 1
1064
1071
  );
1065
1072
  if (!isNaN(Number(Y))) {
1066
1073
  const M = U.lastIndexOf(".");
1067
1074
  if (M !== -1) {
1068
- const N = U.substring(
1075
+ const C = U.substring(
1069
1076
  0,
1070
1077
  M
1071
1078
  );
1072
- if (y.paths.has(N)) {
1073
- O = !0;
1079
+ if (p.paths.has(C)) {
1080
+ _ = !0;
1074
1081
  break;
1075
1082
  }
1076
1083
  }
1077
1084
  }
1078
- x = U.lastIndexOf(".");
1085
+ k = U.lastIndexOf(".");
1079
1086
  }
1080
- if (O) break;
1087
+ if (_) break;
1081
1088
  }
1082
- if (!O && k.includes("deps") && y.depsFunction) {
1083
- const A = y.depsFunction(s);
1084
- let x = !1;
1085
- typeof A == "boolean" ? A && (x = !0) : q(y.deps, A) || (y.deps = A, x = !0), x && (O = !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);
1086
1093
  }
1087
- O && y.forceUpdate();
1094
+ _ && p.forceUpdate();
1088
1095
  }
1089
1096
  }
1090
1097
  }
1091
1098
  };
1092
1099
  if (l === "validateZodSchema")
1093
1100
  return () => {
1094
- const d = r.getState().getInitialOptions(e)?.validation, t = r.getState().addValidationError;
1101
+ const d = o.getState().getInitialOptions(e)?.validation, t = o.getState().addValidationError;
1095
1102
  if (!d?.zodSchema)
1096
1103
  throw new Error("Zod schema not found");
1097
1104
  if (!d?.key)
1098
1105
  throw new Error("Validation key not found");
1099
1106
  X(d.key);
1100
- const o = r.getState().cogsStateStore[e];
1107
+ const r = o.getState().cogsStateStore[e];
1101
1108
  try {
1102
- const s = r.getState().getValidationErrors(d.key);
1109
+ const s = o.getState().getValidationErrors(d.key);
1103
1110
  s && s.length > 0 && s.forEach(([f]) => {
1104
1111
  f && f.startsWith(d.key) && X(f);
1105
1112
  });
1106
- const c = d.zodSchema.safeParse(o);
1113
+ const c = d.zodSchema.safeParse(r);
1107
1114
  return c.success ? !0 : (c.error.errors.forEach((u) => {
1108
- const E = u.path, y = u.message, O = [d.key, ...E].join(".");
1109
- t(O, y);
1110
- }), he(e), !1);
1115
+ const E = u.path, p = u.message, _ = [d.key, ...E].join(".");
1116
+ t(_, p);
1117
+ }), Ie(e), !1);
1111
1118
  } catch (s) {
1112
1119
  return console.error("Zod schema validation failed", s), !1;
1113
1120
  }
1114
1121
  };
1115
1122
  if (l === "_componentId") return m;
1116
1123
  if (l === "getComponents")
1117
- return () => r().stateComponents.get(e);
1124
+ return () => o().stateComponents.get(e);
1118
1125
  if (l === "getAllFormRefs")
1119
- return () => Ne.getState().getFormRefsByStateKey(e);
1126
+ return () => be.getState().getFormRefsByStateKey(e);
1120
1127
  if (l === "_initialState")
1121
- return r.getState().initialStateGlobal[e];
1128
+ return o.getState().initialStateGlobal[e];
1122
1129
  if (l === "_serverState")
1123
- return r.getState().serverState[e];
1130
+ return o.getState().serverState[e];
1124
1131
  if (l === "_isLoading")
1125
- return r.getState().isLoadingGlobal[e];
1132
+ return o.getState().isLoadingGlobal[e];
1126
1133
  if (l === "revertToInitialState")
1127
- return v.revertToInitialState;
1128
- if (l === "updateInitialState") return v.updateInitialState;
1129
- if (l === "removeValidation") return v.removeValidation;
1134
+ return y.revertToInitialState;
1135
+ if (l === "updateInitialState") return y.updateInitialState;
1136
+ if (l === "removeValidation") return y.removeValidation;
1130
1137
  }
1131
1138
  if (l === "getFormRef")
1132
- return () => Ne.getState().getFormRef(e + "." + n.join("."));
1139
+ return () => be.getState().getFormRef(e + "." + n.join("."));
1133
1140
  if (l === "validationWrapper")
1134
1141
  return ({
1135
1142
  children: d,
1136
1143
  hideMessage: t
1137
- }) => /* @__PURE__ */ ye(
1138
- Ue,
1144
+ }) => /* @__PURE__ */ Ee(
1145
+ Be,
1139
1146
  {
1140
1147
  formOpts: t ? { validation: { message: "" } } : void 0,
1141
1148
  path: n,
1142
- validationKey: r.getState().getInitialOptions(e)?.validation?.key || "",
1149
+ validationKey: o.getState().getInitialOptions(e)?.validation?.key || "",
1143
1150
  stateKey: e,
1144
1151
  validIndices: S?.validIndices,
1145
1152
  children: d
@@ -1147,25 +1154,25 @@ function me(e, i, m, g) {
1147
1154
  );
1148
1155
  if (l === "_stateKey") return e;
1149
1156
  if (l === "_path") return n;
1150
- if (l === "_isServerSynced") return v._isServerSynced;
1157
+ if (l === "_isServerSynced") return y._isServerSynced;
1151
1158
  if (l === "update")
1152
1159
  return (d, t) => {
1153
1160
  if (t?.debounce)
1154
- De(() => {
1161
+ He(() => {
1155
1162
  ie(i, d, n, "");
1156
- const o = r.getState().getNestedState(e, n);
1157
- t?.afterUpdate && t.afterUpdate(o);
1163
+ const r = o.getState().getNestedState(e, n);
1164
+ t?.afterUpdate && t.afterUpdate(r);
1158
1165
  }, t.debounce);
1159
1166
  else {
1160
1167
  ie(i, d, n, "");
1161
- const o = r.getState().getNestedState(e, n);
1162
- t?.afterUpdate && t.afterUpdate(o);
1168
+ const r = o.getState().getNestedState(e, n);
1169
+ t?.afterUpdate && t.afterUpdate(r);
1163
1170
  }
1164
- p(n);
1171
+ O(n);
1165
1172
  };
1166
1173
  if (l === "formElement")
1167
- return (d, t) => /* @__PURE__ */ ye(
1168
- je,
1174
+ return (d, t) => /* @__PURE__ */ Ee(
1175
+ Fe,
1169
1176
  {
1170
1177
  setState: i,
1171
1178
  stateKey: e,
@@ -1174,52 +1181,52 @@ function me(e, i, m, g) {
1174
1181
  formOpts: t
1175
1182
  }
1176
1183
  );
1177
- const P = [...n, l], ae = r.getState().getNestedState(e, P);
1184
+ const P = [...n, l], ae = o.getState().getNestedState(e, P);
1178
1185
  return a(ae, P, S);
1179
1186
  }
1180
- }, F = new Proxy(G, L);
1181
- return T.set(H, {
1182
- proxy: F,
1183
- stateVersion: C
1184
- }), F;
1187
+ }, W = new Proxy(L, G);
1188
+ return I.set(F, {
1189
+ proxy: W,
1190
+ stateVersion: A
1191
+ }), W;
1185
1192
  }
1186
1193
  return a(
1187
- r.getState().getNestedState(e, [])
1194
+ o.getState().getNestedState(e, [])
1188
1195
  );
1189
1196
  }
1190
- function be(e) {
1191
- return le(Ke, { proxy: e });
1197
+ function Pe(e) {
1198
+ return le(nt, { proxy: e });
1192
1199
  }
1193
- function Qe({
1200
+ function tt({
1194
1201
  proxy: e,
1195
1202
  rebuildStateShape: i
1196
1203
  }) {
1197
- const m = r().getNestedState(e._stateKey, e._path);
1204
+ const m = o().getNestedState(e._stateKey, e._path);
1198
1205
  return Array.isArray(m) ? i(
1199
1206
  m,
1200
1207
  e._path
1201
1208
  ).stateMapNoRender(
1202
- (T, C, p, v, a) => e._mapFn(T, C, p, v, a)
1209
+ (I, A, O, y, a) => e._mapFn(I, A, O, y, a)
1203
1210
  ) : null;
1204
1211
  }
1205
- function Ke({
1212
+ function nt({
1206
1213
  proxy: e
1207
1214
  }) {
1208
- const i = Z(null), m = `${e._stateKey}-${e._path.join(".")}`;
1215
+ const i = J(null), m = `${e._stateKey}-${e._path.join(".")}`;
1209
1216
  return oe(() => {
1210
1217
  const g = i.current;
1211
1218
  if (!g || !g.parentElement) return;
1212
- const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
1213
- let v = T.getAttribute("data-parent-id");
1214
- 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));
1215
1222
  const h = {
1216
1223
  instanceId: `instance-${crypto.randomUUID()}`,
1217
- parentId: v,
1218
- position: p,
1224
+ parentId: y,
1225
+ position: O,
1219
1226
  effect: e._effect
1220
1227
  };
1221
- r.getState().addSignalElement(m, h);
1222
- 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);
1223
1230
  let S;
1224
1231
  if (e._effect)
1225
1232
  try {
@@ -1227,24 +1234,24 @@ function Ke({
1227
1234
  "state",
1228
1235
  `return (${e._effect})(state)`
1229
1236
  )(n);
1230
- } catch (G) {
1231
- console.error("Error evaluating effect function during mount:", G), S = n;
1237
+ } catch (L) {
1238
+ console.error("Error evaluating effect function during mount:", L), S = n;
1232
1239
  }
1233
1240
  else
1234
1241
  S = n;
1235
1242
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1236
- const H = document.createTextNode(String(S));
1237
- g.replaceWith(H);
1243
+ const F = document.createTextNode(String(S));
1244
+ g.replaceWith(F);
1238
1245
  }, [e._stateKey, e._path.join("."), e._effect]), le("span", {
1239
1246
  ref: i,
1240
1247
  style: { display: "none" },
1241
1248
  "data-signal-id": m
1242
1249
  });
1243
1250
  }
1244
- function mt(e) {
1245
- const i = Ge(
1251
+ function It(e) {
1252
+ const i = De(
1246
1253
  (m) => {
1247
- const g = r.getState().stateComponents.get(e._stateKey) || {
1254
+ const g = o.getState().stateComponents.get(e._stateKey) || {
1248
1255
  components: /* @__PURE__ */ new Map()
1249
1256
  };
1250
1257
  return g.components.set(e._stateKey, {
@@ -1252,42 +1259,42 @@ function mt(e) {
1252
1259
  paths: /* @__PURE__ */ new Set([e._path.join(".")])
1253
1260
  }), () => g.components.delete(e._stateKey);
1254
1261
  },
1255
- () => r.getState().getNestedState(e._stateKey, e._path)
1262
+ () => o.getState().getNestedState(e._stateKey, e._path)
1256
1263
  );
1257
1264
  return le("text", {}, String(i));
1258
1265
  }
1259
- function et({
1266
+ function rt({
1260
1267
  stateKey: e,
1261
1268
  itemComponentId: i,
1262
1269
  itemPath: m,
1263
1270
  children: g
1264
1271
  }) {
1265
- const [, T] = Q({}), [C, p] = Be(), v = Z(null);
1272
+ const [, I] = Q({}), [A, O] = qe(), y = J(null);
1266
1273
  return oe(() => {
1267
- 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, {
1268
1275
  virtualizer: {
1269
- itemHeight: p.height
1276
+ itemHeight: O.height
1270
1277
  }
1271
1278
  }));
1272
- }, [p.height, e, m]), ce(() => {
1273
- 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) || {
1274
1281
  components: /* @__PURE__ */ new Map()
1275
1282
  };
1276
1283
  return h.components.set(a, {
1277
- forceUpdate: () => T({}),
1284
+ forceUpdate: () => I({}),
1278
1285
  paths: /* @__PURE__ */ new Set([m.join(".")])
1279
- }), r.getState().stateComponents.set(e, h), () => {
1280
- const n = r.getState().stateComponents.get(e);
1286
+ }), o.getState().stateComponents.set(e, h), () => {
1287
+ const n = o.getState().stateComponents.get(e);
1281
1288
  n && n.components.delete(a);
1282
1289
  };
1283
- }, [e, i, m.join(".")]), /* @__PURE__ */ ye("div", { ref: C, children: g });
1290
+ }, [e, i, m.join(".")]), /* @__PURE__ */ Ee("div", { ref: A, children: g });
1284
1291
  }
1285
1292
  export {
1286
- be as $cogsSignal,
1287
- mt as $cogsSignalStore,
1288
- gt as addStateOptions,
1289
- ft as createCogsState,
1290
- St as notifyComponent,
1291
- Xe as useCogsStateFn
1293
+ Pe as $cogsSignal,
1294
+ It as $cogsSignalStore,
1295
+ mt as addStateOptions,
1296
+ Tt as createCogsState,
1297
+ ht as notifyComponent,
1298
+ et as useCogsStateFn
1292
1299
  };
1293
1300
  //# sourceMappingURL=CogsState.jsx.map