cogsbox-state 0.5.443 → 0.5.444

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,6 +1,6 @@
1
1
  "use client";
2
- import { jsx as ot, Fragment as Ut } from "react/jsx-runtime";
3
- import { memo as Ot, useState as K, useRef as q, useCallback as ct, useEffect as Z, useLayoutEffect as dt, useMemo as gt, createElement as lt, startTransition as Rt } from "react";
2
+ import { jsx as ot, Fragment as Ot } from "react/jsx-runtime";
3
+ import { memo as Ut, useState as K, useRef as q, useCallback as ct, useEffect as Z, useLayoutEffect as dt, useMemo as gt, createElement as lt, startTransition as Rt } from "react";
4
4
  import { createRoot as At } from "react-dom/client";
5
5
  import { transformStateFunc as Nt, isFunction as at, isArray as Tt, getDifferences as Ct, isDeepEqual as st } from "./utility.js";
6
6
  import { ValidationWrapper as kt } from "./Functions.jsx";
@@ -21,12 +21,12 @@ function Vt({
21
21
  options: n,
22
22
  initialOptionsPart: S
23
23
  }) {
24
- const g = nt(t) || {}, y = S[t] || {}, I = e.getState().setInitialStateOptions, V = { ...y, ...g };
24
+ const g = nt(t) || {}, y = S[t] || {}, w = e.getState().setInitialStateOptions, V = { ...y, ...g };
25
25
  let u = !1;
26
26
  if (n)
27
27
  for (const f in n)
28
28
  V.hasOwnProperty(f) ? (f == "localStorage" && n[f] && V[f].key !== n[f]?.key && (u = !0, V[f] = n[f]), f == "defaultState" && n[f] && V[f] !== n[f] && !st(V[f], n[f]) && (u = !0, V[f] = n[f])) : (u = !0, V[f] = n[f]);
29
- u && I(t, V);
29
+ u && w(t, V);
30
30
  }
31
31
  function ie(t, { formElements: n, validation: S }) {
32
32
  return { initialState: t, formElements: n, validation: S };
@@ -46,23 +46,23 @@ const Lt = (t, n) => {
46
46
  ...n.validation,
47
47
  ...f.validation || {}
48
48
  }, n.validation.key && !f.validation?.key && (A.validation.key = `${n.validation.key}.${u}`)), Object.keys(A).length > 0) {
49
- const w = nt(u);
50
- w ? e.getState().setInitialStateOptions(u, {
51
- ...w,
49
+ const I = nt(u);
50
+ I ? e.getState().setInitialStateOptions(u, {
51
+ ...I,
52
52
  ...A
53
53
  }) : e.getState().setInitialStateOptions(u, A);
54
54
  }
55
55
  }), Object.keys(g).forEach((u) => {
56
56
  e.getState().initializeShadowState(u, g[u]);
57
57
  });
58
- const I = (u, f) => {
58
+ const w = (u, f) => {
59
59
  const [A] = K(f?.componentId ?? rt());
60
60
  Vt({
61
61
  stateKey: u,
62
62
  options: f,
63
63
  initialOptionsPart: y
64
64
  });
65
- const w = e.getState().getShadowValue(u) || g[u], i = f?.modifyState ? f.modifyState(w) : w;
65
+ const I = e.getState().getShadowValue(u) || g[u], i = f?.modifyState ? f.modifyState(I) : I;
66
66
  return zt(i, {
67
67
  stateKey: u,
68
68
  syncUpdate: f?.syncUpdate,
@@ -79,14 +79,18 @@ const Lt = (t, n) => {
79
79
  function V(u, f) {
80
80
  Vt({ stateKey: u, options: f, initialOptionsPart: y }), f.localStorage && xt(u, f), it(u);
81
81
  }
82
- return { useCogsState: I, setCogsOptions: V };
82
+ return { useCogsState: w, setCogsOptions: V };
83
83
  };
84
84
  function ce(t) {
85
85
  t.notifications && e.getState().setInitialStateOptions("__notifications", t.notifications);
86
86
  const n = t.schemas, S = {};
87
- for (const g in n)
88
- S[g] = n[g]?.schemas?.defaultValues || {};
89
- return Lt(S);
87
+ for (const w in n)
88
+ S[w] = n[w]?.schemas?.defaultValues || {};
89
+ const { useCogsState: g, setCogsOptions: y } = Lt(S);
90
+ return {
91
+ useCogsState: g,
92
+ setCogsOptions: y
93
+ };
90
94
  }
91
95
  const {
92
96
  getInitialOptions: nt,
@@ -102,9 +106,9 @@ const {
102
106
  S.localStorage?.key,
103
107
  g
104
108
  );
105
- const I = at(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
106
- if (I && g) {
107
- const V = `${g}-${n}-${I}`;
109
+ const w = at(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
110
+ if (w && g) {
111
+ const V = `${g}-${n}-${w}`;
108
112
  let u;
109
113
  try {
110
114
  u = St(V)?.lastSyncedWithServer;
@@ -116,10 +120,10 @@ const {
116
120
  lastSyncedWithServer: u,
117
121
  stateSource: f?.stateSource,
118
122
  baseServerState: f?.baseServerState
119
- }, w = Ft.serialize(A);
123
+ }, I = Ft.serialize(A);
120
124
  window.localStorage.setItem(
121
125
  V,
122
- JSON.stringify(w.json)
126
+ JSON.stringify(I.json)
123
127
  );
124
128
  }
125
129
  }, St = (t) => {
@@ -133,10 +137,10 @@ const {
133
137
  }, xt = (t, n) => {
134
138
  const S = e.getState().getShadowValue(t), { sessionId: g } = Pt(), y = at(n?.localStorage?.key) ? n.localStorage.key(S) : n?.localStorage?.key;
135
139
  if (y && g) {
136
- const I = St(
140
+ const w = St(
137
141
  `${g}-${t}-${y}`
138
142
  );
139
- if (I && I.lastUpdated > (I.lastSyncedWithServer || 0))
143
+ if (w && w.lastUpdated > (w.lastSyncedWithServer || 0))
140
144
  return it(t), !0;
141
145
  }
142
146
  return !1;
@@ -159,20 +163,20 @@ const {
159
163
  }
160
164
  };
161
165
  function wt(t, n, S, g) {
162
- const y = e.getState(), I = y.getShadowMetadata(t, n);
166
+ const y = e.getState(), w = y.getShadowMetadata(t, n);
163
167
  if (y.setShadowMetadata(t, n, {
164
- ...I,
168
+ ...w,
165
169
  isDirty: !1,
166
170
  stateSource: "server",
167
171
  lastServerSync: g || Date.now()
168
172
  }), Array.isArray(S)) {
169
173
  const V = y.getShadowMetadata(t, n);
170
174
  V?.arrayKeys && V.arrayKeys.forEach((u, f) => {
171
- const A = u.split(".").slice(1), w = S[f];
172
- w !== void 0 && wt(
175
+ const A = u.split(".").slice(1), I = S[f];
176
+ I !== void 0 && wt(
173
177
  t,
174
178
  A,
175
- w,
179
+ I,
176
180
  g
177
181
  );
178
182
  });
@@ -186,12 +190,12 @@ function zt(t, {
186
190
  localStorage: S,
187
191
  formElements: g,
188
192
  reactiveDeps: y,
189
- reactiveType: I,
193
+ reactiveType: w,
190
194
  componentId: V,
191
195
  defaultState: u,
192
196
  syncUpdate: f,
193
197
  dependencies: A,
194
- serverState: w
198
+ serverState: I
195
199
  } = {}) {
196
200
  const [i, h] = K({}), { sessionId: M } = Pt();
197
201
  let z = !n;
@@ -236,17 +240,17 @@ function zt(t, {
236
240
  [c, u, t, M]
237
241
  );
238
242
  Z(() => {
239
- e.getState().setServerStateUpdate(c, w);
240
- }, [w, c]), Z(() => e.getState().subscribeToPath(c, (r) => {
243
+ e.getState().setServerStateUpdate(c, I);
244
+ }, [I, c]), Z(() => e.getState().subscribeToPath(c, (r) => {
241
245
  if (r?.type === "SERVER_STATE_UPDATE") {
242
246
  const a = r.serverState;
243
247
  if (a?.status === "success" && a.data !== void 0) {
244
248
  yt(c, { serverState: a });
245
249
  const l = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, p = e.getState().getShadowValue(c), E = a.data;
246
250
  if (l && Array.isArray(p) && Array.isArray(E)) {
247
- const U = l.key || "id", C = new Set(
248
- p.map((x) => x[U])
249
- ), F = E.filter((x) => !C.has(x[U]));
251
+ const O = l.key || "id", C = new Set(
252
+ p.map((x) => x[O])
253
+ ), F = E.filter((x) => !C.has(x[O]));
250
254
  F.length > 0 && F.forEach((x) => {
251
255
  e.getState().insertShadowArrayElement(c, [], x);
252
256
  const N = e.getState().getShadowMetadata(c, []);
@@ -261,8 +265,8 @@ function zt(t, {
261
265
  });
262
266
  const k = e.getState().getShadowValue(j);
263
267
  k && typeof k == "object" && !Array.isArray(k) && Object.keys(k).forEach((P) => {
264
- const O = [...b, P];
265
- e.getState().setShadowMetadata(c, O, {
268
+ const U = [...b, P];
269
+ e.getState().setShadowMetadata(c, U, {
266
270
  isDirty: !1,
267
271
  stateSource: "server",
268
272
  lastServerSync: a.timestamp || Date.now()
@@ -315,7 +319,7 @@ function zt(t, {
315
319
  const o = `${c}////${H.current}`, r = e.getState().getShadowMetadata(c, []), a = r?.components || /* @__PURE__ */ new Map();
316
320
  return a.set(o, {
317
321
  forceUpdate: () => h({}),
318
- reactiveType: I ?? ["component", "deps"],
322
+ reactiveType: w ?? ["component", "deps"],
319
323
  paths: /* @__PURE__ */ new Set(),
320
324
  depsFunction: y || void 0,
321
325
  deps: y ? y(e.getState().getShadowValue(c)) : [],
@@ -326,8 +330,8 @@ function zt(t, {
326
330
  }), h({}), () => {
327
331
  const d = e.getState().getShadowMetadata(c, []), l = d?.components?.get(o);
328
332
  l?.paths && l.paths.forEach((p) => {
329
- const _ = p.split(".").slice(1), U = e.getState().getShadowMetadata(c, _);
330
- U?.pathComponents && U.pathComponents.size === 0 && (delete U.pathComponents, e.getState().setShadowMetadata(c, _, U));
333
+ const _ = p.split(".").slice(1), O = e.getState().getShadowMetadata(c, _);
334
+ O?.pathComponents && O.pathComponents.size === 0 && (delete O.pathComponents, e.getState().setShadowMetadata(c, _, O));
331
335
  }), d?.components && e.getState().setShadowMetadata(c, [], d);
332
336
  };
333
337
  }, []);
@@ -371,17 +375,17 @@ function zt(t, {
371
375
  }
372
376
  if (a.sync !== !1 && Y.current && Y.current.connected && Y.current.updateState({ operation: C }), p?.signals && p.signals.length > 0) {
373
377
  const b = a.updateType === "cut" ? null : _;
374
- p.signals.forEach(({ parentId: k, position: P, effect: O }) => {
378
+ p.signals.forEach(({ parentId: k, position: P, effect: U }) => {
375
379
  const v = document.querySelector(`[data-parent-id="${k}"]`);
376
380
  if (v) {
377
381
  const T = Array.from(v.childNodes);
378
382
  if (T[P]) {
379
383
  let $ = b;
380
- if (O && b !== null)
384
+ if (U && b !== null)
381
385
  try {
382
386
  $ = new Function(
383
387
  "state",
384
- `return (${O})(state)`
388
+ `return (${U})(state)`
385
389
  )(b);
386
390
  } catch (D) {
387
391
  console.error("Error evaluating effect function:", D);
@@ -392,7 +396,7 @@ function zt(t, {
392
396
  });
393
397
  }
394
398
  if (a.updateType === "insert" && p?.mapWrappers && p.mapWrappers.length > 0) {
395
- const b = l.getShadowMetadata(c, r)?.arrayKeys || [], k = b[b.length - 1], P = l.getShadowValue(k), O = l.getShadowValue(
399
+ const b = l.getShadowMetadata(c, r)?.arrayKeys || [], k = b[b.length - 1], P = l.getShadowValue(k), U = l.getShadowValue(
396
400
  [c, ...r].join(".")
397
401
  );
398
402
  if (!k || P === void 0) return;
@@ -435,7 +439,7 @@ function zt(t, {
435
439
  ) : v.containerRef.appendChild(D);
436
440
  const L = At(D), G = rt(), tt = k.split(".").slice(1), et = v.rebuildStateShape({
437
441
  path: v.path,
438
- currentState: O,
442
+ currentState: U,
439
443
  componentId: v.componentId,
440
444
  meta: v.meta
441
445
  });
@@ -457,10 +461,10 @@ function zt(t, {
457
461
  const b = r.slice(0, -1), k = l.getShadowMetadata(c, b);
458
462
  k?.mapWrappers && k.mapWrappers.length > 0 && k.mapWrappers.forEach((P) => {
459
463
  if (P.containerRef && P.containerRef.isConnected) {
460
- const O = P.containerRef.querySelector(
464
+ const U = P.containerRef.querySelector(
461
465
  `[data-item-path="${d}"]`
462
466
  );
463
- O && O.remove();
467
+ U && U.remove();
464
468
  }
465
469
  });
466
470
  }
@@ -478,14 +482,14 @@ function zt(t, {
478
482
  if (k?.pathComponents && k.pathComponents.forEach((P) => {
479
483
  if (j.has(P))
480
484
  return;
481
- const O = N.components?.get(P);
482
- O && ((Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"]).includes("none") || (O.forceUpdate(), j.add(P)));
485
+ const U = N.components?.get(P);
486
+ U && ((Array.isArray(U.reactiveType) ? U.reactiveType : [U.reactiveType || "component"]).includes("none") || (U.forceUpdate(), j.add(P)));
483
487
  }), b.length === 0)
484
488
  break;
485
489
  b.pop();
486
490
  }
487
491
  _ && typeof _ == "object" && !Tt(_) && E && typeof E == "object" && !Tt(E) && Ct(_, E).forEach((P) => {
488
- const O = P.split("."), v = [...r, ...O], T = l.getShadowMetadata(c, v);
492
+ const U = P.split("."), v = [...r, ...U], T = l.getShadowMetadata(c, v);
489
493
  T?.pathComponents && T.pathComponents.forEach(($) => {
490
494
  if (j.has($))
491
495
  return;
@@ -496,7 +500,7 @@ function zt(t, {
496
500
  } else if (a.updateType === "insert" || a.updateType === "cut") {
497
501
  const b = a.updateType === "insert" ? r : r.slice(0, -1), k = l.getShadowMetadata(c, b);
498
502
  if (k?.signals && k.signals.length > 0) {
499
- const P = [c, ...b].join("."), O = l.getShadowValue(P);
503
+ const P = [c, ...b].join("."), U = l.getShadowValue(P);
500
504
  k.signals.forEach(({ parentId: v, position: T, effect: $ }) => {
501
505
  const D = document.querySelector(
502
506
  `[data-parent-id="${v}"]`
@@ -504,15 +508,15 @@ function zt(t, {
504
508
  if (D) {
505
509
  const R = Array.from(D.childNodes);
506
510
  if (R[T]) {
507
- let L = O;
511
+ let L = U;
508
512
  if ($)
509
513
  try {
510
514
  L = new Function(
511
515
  "state",
512
516
  `return (${$})(state)`
513
- )(O);
517
+ )(U);
514
518
  } catch (G) {
515
- console.error("Error evaluating effect function:", G), L = O;
519
+ console.error("Error evaluating effect function:", G), L = U;
516
520
  }
517
521
  L != null && typeof L == "object" && (L = JSON.stringify(L)), R[T].textContent = String(L ?? "");
518
522
  }
@@ -521,8 +525,8 @@ function zt(t, {
521
525
  }
522
526
  k?.pathComponents && k.pathComponents.forEach((P) => {
523
527
  if (!j.has(P)) {
524
- const O = N.components?.get(P);
525
- O && (O.forceUpdate(), j.add(P));
528
+ const U = N.components?.get(P);
529
+ U && (U.forceUpdate(), j.add(P));
526
530
  }
527
531
  });
528
532
  }
@@ -535,15 +539,15 @@ function zt(t, {
535
539
  return;
536
540
  }
537
541
  if (P.includes("deps") && b.depsFunction) {
538
- const O = l.getShadowValue(c), v = b.depsFunction(O);
542
+ const U = l.getShadowValue(c), v = b.depsFunction(U);
539
543
  let T = !1;
540
544
  v === !0 ? T = !0 : Array.isArray(v) && (st(b.prevDeps, v) || (b.prevDeps = v, T = !0)), T && (b.forceUpdate(), j.add(k));
541
545
  }
542
546
  }), j.clear(), Wt(c, (b) => {
543
547
  const k = [...b ?? [], C], P = /* @__PURE__ */ new Map();
544
- return k.forEach((O) => {
545
- const v = `${O.stateKey}:${JSON.stringify(O.path)}`, T = P.get(v);
546
- T ? (T.timeStamp = Math.max(T.timeStamp, O.timeStamp), T.newValue = O.newValue, T.oldValue = T.oldValue ?? O.oldValue, T.updateType = O.updateType) : P.set(v, { ...O });
548
+ return k.forEach((U) => {
549
+ const v = `${U.stateKey}:${JSON.stringify(U.path)}`, T = P.get(v);
550
+ T ? (T.timeStamp = Math.max(T.timeStamp, U.timeStamp), T.newValue = U.newValue, T.oldValue = T.oldValue ?? U.oldValue, T.updateType = U.updateType) : P.set(v, { ...U });
547
551
  }), Array.from(P.values());
548
552
  }), Ht(
549
553
  _,
@@ -576,22 +580,22 @@ const It = (t, n, S) => {
576
580
  let g = e.getState().getShadowMetadata(t, n)?.arrayKeys || [];
577
581
  if (!S || S.length === 0)
578
582
  return g;
579
- let y = g.map((I) => ({
580
- key: I,
581
- value: e.getState().getShadowValue(I)
583
+ let y = g.map((w) => ({
584
+ key: w,
585
+ value: e.getState().getShadowValue(w)
582
586
  }));
583
- for (const I of S)
584
- I.type === "filter" ? y = y.filter(
585
- ({ value: V }, u) => I.fn(V, u)
586
- ) : I.type === "sort" && y.sort((V, u) => I.fn(V.value, u.value));
587
- return y.map(({ key: I }) => I);
587
+ for (const w of S)
588
+ w.type === "filter" ? y = y.filter(
589
+ ({ value: V }, u) => w.fn(V, u)
590
+ ) : w.type === "sort" && y.sort((V, u) => w.fn(V.value, u.value));
591
+ return y.map(({ key: w }) => w);
588
592
  }, Et = (t, n, S) => {
589
- const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata: I } = e.getState(), u = I(t, [])?.components?.get(g);
593
+ const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata: w } = e.getState(), u = w(t, [])?.components?.get(g);
590
594
  !u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t, S, g);
591
595
  }, ft = (t, n, S) => {
592
- const g = e.getState(), y = g.getShadowMetadata(t, []), I = /* @__PURE__ */ new Set();
596
+ const g = e.getState(), y = g.getShadowMetadata(t, []), w = /* @__PURE__ */ new Set();
593
597
  y?.components && y.components.forEach((u, f) => {
594
- (Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), I.add(f));
598
+ (Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), w.add(f));
595
599
  }), g.getShadowMetadata(t, [...n, "getSelected"])?.pathComponents?.forEach((u) => {
596
600
  y?.components?.get(u)?.forceUpdate();
597
601
  });
@@ -601,28 +605,28 @@ const It = (t, n, S) => {
601
605
  t,
602
606
  f.split(".").slice(1)
603
607
  );
604
- u == S && A?.pathComponents?.forEach((w) => {
605
- y?.components?.get(w)?.forceUpdate();
608
+ u == S && A?.pathComponents?.forEach((I) => {
609
+ y?.components?.get(I)?.forceUpdate();
606
610
  });
607
611
  }
608
612
  };
609
613
  function Dt(t, n, S, g) {
610
614
  const y = /* @__PURE__ */ new Map();
611
- let I = 0;
612
- const V = (w) => {
613
- const i = w.join(".");
615
+ let w = 0;
616
+ const V = (I) => {
617
+ const i = I.join(".");
614
618
  for (const [h] of y)
615
619
  (h === i || h.startsWith(i + ".")) && y.delete(h);
616
- I++;
620
+ w++;
617
621
  };
618
622
  function u({
619
- currentState: w,
623
+ currentState: I,
620
624
  path: i = [],
621
625
  meta: h,
622
626
  componentId: M
623
627
  }) {
624
628
  const z = i.map(String).join("."), c = [t, ...i].join(".");
625
- w = e.getState().getShadowValue(c, h?.validIds);
629
+ I = e.getState().getShadowValue(c, h?.validIds);
626
630
  const B = function() {
627
631
  return e().getShadowValue(t, i);
628
632
  }, J = {
@@ -683,7 +687,7 @@ function Dt(t, n, S, g) {
683
687
  const s = e.getState().getShadowMetadata(t, i);
684
688
  return s?.validation?.status === "VALIDATION_FAILED" && s.validation.message ? [s.validation.message] : [];
685
689
  };
686
- if (Array.isArray(w)) {
690
+ if (Array.isArray(I)) {
687
691
  if (m === "getSelected")
688
692
  return () => {
689
693
  const s = t + "." + i.join(".");
@@ -726,7 +730,7 @@ function Dt(t, n, S, g) {
726
730
  } = s, l = q(null), [p, E] = K({
727
731
  startIndex: 0,
728
732
  endIndex: 10
729
- }), [_, U] = K({}), C = q(!0), F = q({
733
+ }), [_, O] = K({}), C = q(!0), F = q({
730
734
  isUserScrolling: !1,
731
735
  lastScrollTop: 0,
732
736
  scrollUpCount: 0,
@@ -977,7 +981,7 @@ function Dt(t, n, S, g) {
977
981
  const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
978
982
  if (!o)
979
983
  throw new Error("No array keys found for filtering.");
980
- const r = [], a = w.filter(
984
+ const r = [], a = I.filter(
981
985
  (d, l) => s(d, l) ? (r.push(o[l]), !0) : !1
982
986
  );
983
987
  return u({
@@ -1001,7 +1005,7 @@ function Dt(t, n, S, g) {
1001
1005
  const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
1002
1006
  if (!o)
1003
1007
  throw new Error("No array keys found for sorting");
1004
- const r = w.map((a, d) => ({
1008
+ const r = I.map((a, d) => ({
1005
1009
  item: a,
1006
1010
  key: o[d]
1007
1011
  }));
@@ -1028,7 +1032,7 @@ function Dt(t, n, S, g) {
1028
1032
  onFlush: l
1029
1033
  } = s;
1030
1034
  let p = [], E = !1, _ = null;
1031
- const U = (j) => {
1035
+ const O = (j) => {
1032
1036
  if (!E) {
1033
1037
  if (a === "sliding" && p.length >= o)
1034
1038
  p.shift();
@@ -1060,8 +1064,8 @@ function Dt(t, n, S, g) {
1060
1064
  ...x,
1061
1065
  streams: N
1062
1066
  }), {
1063
- write: (j) => U(j),
1064
- writeMany: (j) => j.forEach(U),
1067
+ write: (j) => O(j),
1068
+ writeMany: (j) => j.forEach(O),
1065
1069
  flush: () => C(),
1066
1070
  pause: () => {
1067
1071
  E = !0;
@@ -1079,9 +1083,9 @@ function Dt(t, n, S, g) {
1079
1083
  if (m === "stateList")
1080
1084
  return (s) => /* @__PURE__ */ ot(() => {
1081
1085
  const r = q(/* @__PURE__ */ new Map()), a = h?.transforms && h.transforms.length > 0 ? `${M}-${Bt(h.transforms)}` : `${M}-base`, [d, l] = K({}), { validIds: p, arrayValues: E } = gt(() => {
1082
- const U = e.getState().getShadowMetadata(t, i)?.transformCaches?.get(a);
1086
+ const O = e.getState().getShadowMetadata(t, i)?.transformCaches?.get(a);
1083
1087
  let C;
1084
- U && U.validIds ? C = U.validIds : (C = It(
1088
+ O && O.validIds ? C = O.validIds : (C = It(
1085
1089
  t,
1086
1090
  i,
1087
1091
  h?.transforms
@@ -1097,7 +1101,7 @@ function Dt(t, n, S, g) {
1097
1101
  };
1098
1102
  }, [a, d]);
1099
1103
  if (Z(() => {
1100
- const U = e.getState().subscribeToPath(c, (C) => {
1104
+ const O = e.getState().subscribeToPath(c, (C) => {
1101
1105
  if (C.type === "GET_SELECTED")
1102
1106
  return;
1103
1107
  const x = e.getState().getShadowMetadata(t, i)?.transformCaches;
@@ -1107,7 +1111,7 @@ function Dt(t, n, S, g) {
1107
1111
  (C.type === "INSERT" || C.type === "REMOVE" || C.type === "CLEAR_SELECTION") && l({});
1108
1112
  });
1109
1113
  return () => {
1110
- U();
1114
+ O();
1111
1115
  };
1112
1116
  }, [M, c]), !Array.isArray(E))
1113
1117
  return null;
@@ -1120,7 +1124,7 @@ function Dt(t, n, S, g) {
1120
1124
  validIds: p
1121
1125
  }
1122
1126
  });
1123
- return /* @__PURE__ */ ot(Ut, { children: E.map((U, C) => {
1127
+ return /* @__PURE__ */ ot(Ot, { children: E.map((O, C) => {
1124
1128
  const F = p[C];
1125
1129
  if (!F)
1126
1130
  return null;
@@ -1141,8 +1145,8 @@ function Dt(t, n, S, g) {
1141
1145
  }, {});
1142
1146
  if (m === "stateFlattenOn")
1143
1147
  return (s) => {
1144
- const o = w;
1145
- y.clear(), I++;
1148
+ const o = I;
1149
+ y.clear(), w++;
1146
1150
  const r = o.flatMap(
1147
1151
  (a) => a[s] ?? []
1148
1152
  );
@@ -1192,14 +1196,14 @@ function Dt(t, n, S, g) {
1192
1196
  let l = null;
1193
1197
  if (!a.some((E) => {
1194
1198
  const _ = o ? o.every(
1195
- (U) => st(E[U], d[U])
1199
+ (O) => st(E[O], d[O])
1196
1200
  ) : st(E, d);
1197
1201
  return _ && (l = E), _;
1198
1202
  }))
1199
1203
  V(i), n(d, i, { updateType: "insert" });
1200
1204
  else if (r && l) {
1201
1205
  const E = r(l), _ = a.map(
1202
- (U) => st(U, l) ? E : U
1206
+ (O) => st(O, l) ? E : O
1203
1207
  );
1204
1208
  V(i), n(_, i, {
1205
1209
  updateType: "update"
@@ -1213,7 +1217,7 @@ function Dt(t, n, S, g) {
1213
1217
  const a = s == -1 ? r.length - 1 : s !== void 0 ? s : r.length - 1, d = r[a];
1214
1218
  if (!d) return;
1215
1219
  const l = d.split(".").slice(1);
1216
- n(w, l, {
1220
+ n(I, l, {
1217
1221
  updateType: "cut"
1218
1222
  });
1219
1223
  };
@@ -1232,7 +1236,7 @@ function Dt(t, n, S, g) {
1232
1236
  const a = s[r == -1 ? s.length - 1 : r]?.split(".").slice(1);
1233
1237
  e.getState().clearSelectedIndex({ arrayKey: c });
1234
1238
  const d = a?.slice(0, -1);
1235
- ft(t, d), n(w, a, {
1239
+ ft(t, d), n(I, a, {
1236
1240
  updateType: "cut"
1237
1241
  });
1238
1242
  };
@@ -1364,11 +1368,11 @@ function Dt(t, n, S, g) {
1364
1368
  o.updateShadowAtPath(t, p, E), o.markAsDirty(t, p, { bubble: !0 });
1365
1369
  let _ = [...p];
1366
1370
  for (; ; ) {
1367
- const U = o.getShadowMetadata(
1371
+ const O = o.getShadowMetadata(
1368
1372
  t,
1369
1373
  _
1370
1374
  );
1371
- if (console.log("pathMeta", U), U?.pathComponents && U.pathComponents.forEach((C) => {
1375
+ if (console.log("pathMeta", O), O?.pathComponents && O.pathComponents.forEach((C) => {
1372
1376
  if (!d.has(C)) {
1373
1377
  const F = r.components?.get(C);
1374
1378
  F && (F.forceUpdate(), d.add(C));
@@ -1383,11 +1387,11 @@ function Dt(t, n, S, g) {
1383
1387
  o.removeShadowArrayElement(t, p), o.markAsDirty(t, E, { bubble: !0 });
1384
1388
  let _ = [...E];
1385
1389
  for (; ; ) {
1386
- const U = o.getShadowMetadata(
1390
+ const O = o.getShadowMetadata(
1387
1391
  t,
1388
1392
  _
1389
1393
  );
1390
- if (U?.pathComponents && U.pathComponents.forEach((C) => {
1394
+ if (O?.pathComponents && O.pathComponents.forEach((C) => {
1391
1395
  if (!d.has(C)) {
1392
1396
  const F = r.components?.get(C);
1393
1397
  F && (F.forceUpdate(), d.add(C));
@@ -1464,7 +1468,7 @@ function Dt(t, n, S, g) {
1464
1468
  });
1465
1469
  if (m === "toggle") {
1466
1470
  const s = e.getState().getShadowValue([t, ...i].join("."));
1467
- if (console.log("currentValueAtPath", s), typeof w != "boolean")
1471
+ if (console.log("currentValueAtPath", s), typeof I != "boolean")
1468
1472
  throw new Error("toggle() can only be used on boolean values");
1469
1473
  return () => {
1470
1474
  n(!s, i, {
@@ -1495,20 +1499,20 @@ function Dt(t, n, S, g) {
1495
1499
  }, H = new Proxy(B, J);
1496
1500
  return y.set(z, {
1497
1501
  proxy: H,
1498
- stateVersion: I
1502
+ stateVersion: w
1499
1503
  }), H;
1500
1504
  }
1501
1505
  const f = {
1502
- removeValidation: (w) => {
1503
- w?.validationKey && ut(w.validationKey);
1506
+ removeValidation: (I) => {
1507
+ I?.validationKey && ut(I.validationKey);
1504
1508
  },
1505
- revertToInitialState: (w) => {
1509
+ revertToInitialState: (I) => {
1506
1510
  const i = e.getState().getInitialOptions(t)?.validation;
1507
- i?.key && ut(i.key), w?.validationKey && ut(w.validationKey);
1511
+ i?.key && ut(i.key), I?.validationKey && ut(I.validationKey);
1508
1512
  const h = e.getState().getShadowMetadata(t, []);
1509
1513
  h?.stateSource === "server" && h.baseServerState ? h.baseServerState : e.getState().initialStateGlobal[t];
1510
1514
  const M = e.getState().initialStateGlobal[t];
1511
- e.getState().clearSelectedIndexesForState(t), y.clear(), I++, e.getState().initializeShadowState(t, M), u({
1515
+ e.getState().clearSelectedIndexesForState(t), y.clear(), w++, e.getState().initializeShadowState(t, M), u({
1512
1516
  currentState: M,
1513
1517
  path: [],
1514
1518
  componentId: S
@@ -1520,8 +1524,8 @@ function Dt(t, n, S, g) {
1520
1524
  H.forceUpdate();
1521
1525
  }), M;
1522
1526
  },
1523
- updateInitialState: (w) => {
1524
- y.clear(), I++;
1527
+ updateInitialState: (I) => {
1528
+ y.clear(), w++;
1525
1529
  const i = Dt(
1526
1530
  t,
1527
1531
  n,
@@ -1529,7 +1533,7 @@ function Dt(t, n, S, g) {
1529
1533
  g
1530
1534
  ), h = e.getState().initialStateGlobal[t], M = nt(t), z = at(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, c = `${g}-${t}-${z}`;
1531
1535
  return localStorage.getItem(c) && localStorage.removeItem(c), Rt(() => {
1532
- _t(t, w), e.getState().initializeShadowState(t, w);
1536
+ _t(t, I), e.getState().initializeShadowState(t, I);
1533
1537
  const B = e.getState().getShadowMetadata(t, []);
1534
1538
  B && B?.components?.forEach((J) => {
1535
1539
  J.forceUpdate();
@@ -1552,13 +1556,13 @@ function qt({
1552
1556
  proxy: t,
1553
1557
  rebuildStateShape: n
1554
1558
  }) {
1555
- const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1), I = q(/* @__PURE__ */ new Map());
1559
+ const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1), w = q(/* @__PURE__ */ new Map());
1556
1560
  Z(() => {
1557
1561
  const u = S.current;
1558
1562
  if (!u || y.current) return;
1559
1563
  const f = setTimeout(() => {
1560
- const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, w = A.mapWrappers || [];
1561
- w.push({
1564
+ const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, I = A.mapWrappers || [];
1565
+ I.push({
1562
1566
  instanceId: g.current,
1563
1567
  mapFn: t._mapFn,
1564
1568
  containerRef: u,
@@ -1568,17 +1572,17 @@ function qt({
1568
1572
  meta: t._meta
1569
1573
  }), e.getState().setShadowMetadata(t._stateKey, t._path, {
1570
1574
  ...A,
1571
- mapWrappers: w
1575
+ mapWrappers: I
1572
1576
  }), y.current = !0, V();
1573
1577
  }, 0);
1574
1578
  return () => {
1575
1579
  if (clearTimeout(f), g.current) {
1576
1580
  const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
1577
1581
  A.mapWrappers && (A.mapWrappers = A.mapWrappers.filter(
1578
- (w) => w.instanceId !== g.current
1582
+ (I) => I.instanceId !== g.current
1579
1583
  ), e.getState().setShadowMetadata(t._stateKey, t._path, A));
1580
1584
  }
1581
- I.current.forEach((A) => A.unmount());
1585
+ w.current.forEach((A) => A.unmount());
1582
1586
  };
1583
1587
  }, []);
1584
1588
  const V = () => {
@@ -1589,7 +1593,7 @@ function qt({
1589
1593
  t._meta?.validIds
1590
1594
  );
1591
1595
  if (!Array.isArray(f)) return;
1592
- const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], w = n({
1596
+ const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], I = n({
1593
1597
  currentState: f,
1594
1598
  path: t._path,
1595
1599
  componentId: g.current,
@@ -1601,7 +1605,7 @@ function qt({
1601
1605
  const z = rt(), c = document.createElement("div");
1602
1606
  c.setAttribute("data-item-path", M), u.appendChild(c);
1603
1607
  const B = At(c);
1604
- I.current.set(M, B);
1608
+ w.current.set(M, B);
1605
1609
  const J = M.split(".").slice(1);
1606
1610
  B.render(
1607
1611
  lt(Mt, {
@@ -1609,7 +1613,7 @@ function qt({
1609
1613
  itemComponentId: z,
1610
1614
  itemPath: J,
1611
1615
  localIndex: h,
1612
- arraySetter: w,
1616
+ arraySetter: I,
1613
1617
  rebuildStateShape: n,
1614
1618
  renderFn: t._mapFn
1615
1619
  })
@@ -1621,7 +1625,7 @@ function qt({
1621
1625
  function Gt({
1622
1626
  proxy: t
1623
1627
  }) {
1624
- const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, I = e.getState().getShadowValue(
1628
+ const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, w = e.getState().getShadowValue(
1625
1629
  [t._stateKey, ...t._path].join("."),
1626
1630
  t._meta?.validIds
1627
1631
  );
@@ -1633,26 +1637,26 @@ function Gt({
1633
1637
  console.warn("Parent element not found for signal", y);
1634
1638
  return;
1635
1639
  }
1636
- const f = V.parentElement, w = Array.from(f.childNodes).indexOf(V);
1640
+ const f = V.parentElement, I = Array.from(f.childNodes).indexOf(V);
1637
1641
  let i = f.getAttribute("data-parent-id");
1638
1642
  i || (i = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", i)), S.current = `instance-${crypto.randomUUID()}`;
1639
1643
  const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, M = h.signals || [];
1640
1644
  M.push({
1641
1645
  instanceId: S.current,
1642
1646
  parentId: i,
1643
- position: w,
1647
+ position: I,
1644
1648
  effect: t._effect
1645
1649
  }), e.getState().setShadowMetadata(t._stateKey, t._path, {
1646
1650
  ...h,
1647
1651
  signals: M
1648
1652
  });
1649
- let z = I;
1653
+ let z = w;
1650
1654
  if (t._effect)
1651
1655
  try {
1652
1656
  z = new Function(
1653
1657
  "state",
1654
1658
  `return (${t._effect})(state)`
1655
- )(I);
1659
+ )(w);
1656
1660
  } catch (B) {
1657
1661
  console.error("Error evaluating effect function:", B);
1658
1662
  }
@@ -1674,7 +1678,7 @@ function Gt({
1674
1678
  "data-signal-id": y
1675
1679
  });
1676
1680
  }
1677
- const Mt = Ot(
1681
+ const Mt = Ut(
1678
1682
  Yt,
1679
1683
  (t, n) => t.itemPath.join(".") === n.itemPath.join(".") && t.stateKey === n.stateKey && t.itemComponentId === n.itemComponentId && t.localIndex === n.localIndex
1680
1684
  ), Jt = (t) => {
@@ -1690,14 +1694,14 @@ const Mt = Ot(
1690
1694
  return;
1691
1695
  }
1692
1696
  let y = 0;
1693
- const I = () => {
1697
+ const w = () => {
1694
1698
  y++, y === g.length && S(!0);
1695
1699
  };
1696
1700
  return g.forEach((V) => {
1697
- V.complete ? I() : (V.addEventListener("load", I), V.addEventListener("error", I));
1701
+ V.complete ? w() : (V.addEventListener("load", w), V.addEventListener("error", w));
1698
1702
  }), () => {
1699
1703
  g.forEach((V) => {
1700
- V.removeEventListener("load", I), V.removeEventListener("error", I);
1704
+ V.removeEventListener("load", w), V.removeEventListener("error", w);
1701
1705
  });
1702
1706
  };
1703
1707
  }, [t.current]), n;
@@ -1708,14 +1712,14 @@ function Yt({
1708
1712
  itemPath: S,
1709
1713
  localIndex: g,
1710
1714
  arraySetter: y,
1711
- rebuildStateShape: I,
1715
+ rebuildStateShape: w,
1712
1716
  renderFn: V
1713
1717
  }) {
1714
- const [, u] = K({}), { ref: f, inView: A } = jt(), w = q(null), i = Jt(w), h = q(!1), M = [t, ...S].join(".");
1718
+ const [, u] = K({}), { ref: f, inView: A } = jt(), I = q(null), i = Jt(I), h = q(!1), M = [t, ...S].join(".");
1715
1719
  $t(t, n, u);
1716
1720
  const z = ct(
1717
1721
  (W) => {
1718
- w.current = W, f(W);
1722
+ I.current = W, f(W);
1719
1723
  },
1720
1724
  [f]
1721
1725
  );
@@ -1726,7 +1730,7 @@ function Yt({
1726
1730
  }, []), Z(() => {
1727
1731
  if (!A || !i || h.current)
1728
1732
  return;
1729
- const W = w.current;
1733
+ const W = I.current;
1730
1734
  if (W && W.offsetHeight > 0) {
1731
1735
  h.current = !0;
1732
1736
  const m = W.offsetHeight;
@@ -1740,14 +1744,14 @@ function Yt({
1740
1744
  e.getState().notifyPathSubscribers(Q, {
1741
1745
  type: "ITEMHEIGHT",
1742
1746
  itemKey: S.join("."),
1743
- ref: w.current
1747
+ ref: I.current
1744
1748
  });
1745
1749
  }
1746
1750
  }, [A, i, t, S]);
1747
1751
  const c = [t, ...S].join("."), B = e.getState().getShadowValue(c);
1748
1752
  if (B === void 0)
1749
1753
  return null;
1750
- const J = I({
1754
+ const J = w({
1751
1755
  currentState: B,
1752
1756
  path: S,
1753
1757
  componentId: n
@@ -1760,16 +1764,16 @@ function Zt({
1760
1764
  rebuildStateShape: S,
1761
1765
  renderFn: g,
1762
1766
  formOpts: y,
1763
- setState: I
1767
+ setState: w
1764
1768
  }) {
1765
1769
  const [V] = K(() => rt()), [, u] = K({}), f = [t, ...n].join(".");
1766
1770
  $t(t, V, u);
1767
- const A = e.getState().getShadowValue(f), [w, i] = K(A), h = q(!1), M = q(null);
1771
+ const A = e.getState().getShadowValue(f), [I, i] = K(A), h = q(!1), M = q(null);
1768
1772
  Z(() => {
1769
- !h.current && !st(A, w) && i(A);
1773
+ !h.current && !st(A, I) && i(A);
1770
1774
  }, [A]), Z(() => {
1771
1775
  const H = e.getState().subscribeToPath(f, (W) => {
1772
- !h.current && w !== W && u({});
1776
+ !h.current && I !== W && u({});
1773
1777
  });
1774
1778
  return () => {
1775
1779
  H(), M.current && (clearTimeout(M.current), h.current = !1);
@@ -1780,7 +1784,7 @@ function Zt({
1780
1784
  typeof A === "number" && typeof H == "string" && (H = H === "" ? 0 : Number(H)), i(H), h.current = !0, M.current && clearTimeout(M.current);
1781
1785
  const m = y?.debounceTime ?? 200;
1782
1786
  M.current = setTimeout(() => {
1783
- h.current = !1, I(H, n, { updateType: "update" });
1787
+ h.current = !1, w(H, n, { updateType: "update" });
1784
1788
  const { getInitialOptions: Y, setShadowMetadata: Q, getShadowMetadata: X } = e.getState(), s = Y(t)?.validation, o = s?.zodSchemaV4 || s?.zodSchemaV3;
1785
1789
  if (o) {
1786
1790
  const r = e.getState().getShadowValue(t), a = o.safeParse(r), d = X(t, n) || {};
@@ -1814,9 +1818,9 @@ function Zt({
1814
1818
  }
1815
1819
  }, m), u({});
1816
1820
  },
1817
- [I, n, y?.debounceTime, t]
1821
+ [w, n, y?.debounceTime, t]
1818
1822
  ), c = ct(async () => {
1819
- console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, I(w, n, { updateType: "update" }));
1823
+ console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, w(I, n, { updateType: "update" }));
1820
1824
  const { getInitialOptions: H } = e.getState(), W = H(t)?.validation, m = W?.zodSchemaV4 || W?.zodSchemaV3;
1821
1825
  if (!m) return;
1822
1826
  const Y = e.getState().getShadowMetadata(t, n);
@@ -1824,7 +1828,7 @@ function Zt({
1824
1828
  ...Y,
1825
1829
  validation: {
1826
1830
  status: "DIRTY",
1827
- validatedValue: w
1831
+ validatedValue: I
1828
1832
  }
1829
1833
  });
1830
1834
  const Q = e.getState().getShadowValue(t), X = m.safeParse(Q);
@@ -1833,7 +1837,7 @@ function Zt({
1833
1837
  ...Y,
1834
1838
  validation: {
1835
1839
  status: "VALID_PENDING_SYNC",
1836
- validatedValue: w
1840
+ validatedValue: I
1837
1841
  }
1838
1842
  });
1839
1843
  else {
@@ -1848,12 +1852,12 @@ function Zt({
1848
1852
  if (console.log("Array metadata:", l), l?.arrayKeys) {
1849
1853
  const p = [t, ...n.slice(0, -1)].join("."), E = l.arrayKeys.indexOf(p);
1850
1854
  console.log("Item key:", p, "Index:", E);
1851
- const _ = [...d, E, ...n.slice(-1)], U = JSON.stringify(r.path) === JSON.stringify(_);
1855
+ const _ = [...d, E, ...n.slice(-1)], O = JSON.stringify(r.path) === JSON.stringify(_);
1852
1856
  return console.log("Zod path comparison:", {
1853
1857
  zodPath: _,
1854
1858
  errorPath: r.path,
1855
- match: U
1856
- }), U;
1859
+ match: O
1860
+ }), O;
1857
1861
  }
1858
1862
  }
1859
1863
  const a = JSON.stringify(r.path) === JSON.stringify(n);
@@ -1868,19 +1872,19 @@ function Zt({
1868
1872
  validation: {
1869
1873
  status: "VALIDATION_FAILED",
1870
1874
  message: o[0]?.message,
1871
- validatedValue: w
1875
+ validatedValue: I
1872
1876
  }
1873
1877
  });
1874
1878
  }
1875
1879
  u({});
1876
- }, [t, n, w, I]), B = S({
1880
+ }, [t, n, I, w]), B = S({
1877
1881
  currentState: A,
1878
1882
  path: n,
1879
1883
  componentId: V
1880
1884
  }), J = new Proxy(B, {
1881
1885
  get(H, W) {
1882
1886
  return W === "inputProps" ? {
1883
- value: w ?? "",
1887
+ value: I ?? "",
1884
1888
  onChange: (m) => {
1885
1889
  z(m.target.value);
1886
1890
  },
@@ -1895,13 +1899,13 @@ function Zt({
1895
1899
  function $t(t, n, S) {
1896
1900
  const g = `${t}////${n}`;
1897
1901
  dt(() => {
1898
- const { registerComponent: y, unregisterComponent: I } = e.getState();
1902
+ const { registerComponent: y, unregisterComponent: w } = e.getState();
1899
1903
  return y(t, g, {
1900
1904
  forceUpdate: () => S({}),
1901
1905
  paths: /* @__PURE__ */ new Set(),
1902
1906
  reactiveType: ["component"]
1903
1907
  }), () => {
1904
- I(t, g);
1908
+ w(t, g);
1905
1909
  };
1906
1910
  }, [t, g]);
1907
1911
  }