cogsbox-state 0.5.338 → 0.5.340

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