cogsbox-state 0.5.412 → 0.5.414

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