cogsbox-state 0.5.377 → 0.5.378

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