cogsbox-state 0.5.444 → 0.5.445

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