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