cogsbox-state 0.5.322 → 0.5.324

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