cogsbox-state 0.5.295 → 0.5.296

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