cogsbox-state 0.5.346 → 0.5.347

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