cogsbox-state 0.5.415 → 0.5.417

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