cogsbox-state 0.5.317 → 0.5.319

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