cogsbox-state 0.5.475-canary.2 → 0.5.475-canary.4

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.
@@ -2,8 +2,8 @@
2
2
  import { jsx as Z, Fragment as Me } from "react/jsx-runtime";
3
3
  import { pluginStore as x } from "./pluginStore.js";
4
4
  import { useState as ee, useRef as q, useCallback as Ae, useEffect as J, useLayoutEffect as $e, useMemo as ye, createElement as ue, startTransition as Ee } from "react";
5
- import { transformStateFunc as Te, isFunction as R, isDeepEqual as Y, isArray as Ve, getDifferences as be } from "./utility.js";
6
- import { ValidationWrapper as Ie, IsolatedComponentWrapper as Pe, FormElementWrapper as ke, MemoizedCogsItemWrapper as De } from "./Components.jsx";
5
+ import { transformStateFunc as Ve, isFunction as R, isDeepEqual as Y, isArray as Te, getDifferences as Ie } from "./utility.js";
6
+ import { ValidationWrapper as be, IsolatedComponentWrapper as Pe, FormElementWrapper as ke, MemoizedCogsItemWrapper as De } from "./Components.jsx";
7
7
  import Ce from "superjson";
8
8
  import { v4 as X } from "uuid";
9
9
  import { getGlobalStore as p, updateShadowTypeInfo as fe } from "./store.js";
@@ -13,7 +13,7 @@ const {
13
13
  getInitialOptions: N,
14
14
  updateInitialStateGlobal: he,
15
15
  getShadowMetadata: A,
16
- setShadowMetadata: W,
16
+ setShadowMetadata: L,
17
17
  getShadowValue: D,
18
18
  initializeShadowState: K,
19
19
  initializeAndMergeShadowState: Oe,
@@ -28,8 +28,8 @@ const {
28
28
  clearSelectedIndexesForState: ze,
29
29
  addStateLog: Re,
30
30
  setSyncInfo: wt,
31
- clearSelectedIndex: We,
32
- getSyncInfo: Le,
31
+ clearSelectedIndex: Le,
32
+ getSyncInfo: We,
33
33
  notifyPathSubscribers: Be,
34
34
  getPluginMetaDataMap: Ge,
35
35
  setPluginMetaData: xe,
@@ -98,7 +98,7 @@ function pt(e, a) {
98
98
  }
99
99
  const Mt = (e, a) => {
100
100
  a?.plugins && x.getState().setRegisteredPlugins(a.plugins);
101
- const [l, s] = Te(e);
101
+ const [l, s] = Ve(e);
102
102
  Object.keys(l).forEach((u) => {
103
103
  let t = s[u] || {};
104
104
  const o = {
@@ -135,8 +135,8 @@ const Mt = (e, a) => {
135
135
  initialOptionsPart: s
136
136
  }), $ = q(y);
137
137
  $.current = y;
138
- const E = D(u, []) || l[u], b = ot(
139
- E,
138
+ const V = D(u, []) || l[u], I = ot(
139
+ V,
140
140
  {
141
141
  stateKey: u,
142
142
  syncUpdate: t?.syncUpdate,
@@ -152,9 +152,9 @@ const Mt = (e, a) => {
152
152
  );
153
153
  return J(() => {
154
154
  t && x.getState().setPluginOptionsForState(u, t);
155
- }, [u, t]), J(() => (x.getState().stateHandlers.set(u, b), () => {
155
+ }, [u, t]), J(() => (x.getState().stateHandlers.set(u, I), () => {
156
156
  x.getState().stateHandlers.delete(u);
157
- }), [u, b]), b;
157
+ }), [u, I]), I;
158
158
  };
159
159
  function i(u, t) {
160
160
  if (ce({ stateKey: u, options: t, initialOptionsPart: s }), t.localStorage && Ze(u, t), t.formElements) {
@@ -233,7 +233,7 @@ const Mt = (e, a) => {
233
233
  };
234
234
  function te(e, a, l, s) {
235
235
  const g = A(e, a);
236
- if (W(e, a, {
236
+ if (L(e, a, {
237
237
  ...g,
238
238
  isDirty: !1,
239
239
  stateSource: "server",
@@ -293,11 +293,11 @@ function Xe(e, a, l) {
293
293
  }), i.length === 0) break;
294
294
  i.pop();
295
295
  }
296
- l.newValue && typeof l.newValue == "object" && !Ve(l.newValue) && be(l.newValue, l.oldValue).forEach((u) => {
296
+ l.newValue && typeof l.newValue == "object" && !Te(l.newValue) && Ie(l.newValue, l.oldValue).forEach((u) => {
297
297
  const t = u.split("."), o = [...a, ...t], y = A(e, o);
298
298
  y?.pathComponents && y.pathComponents.forEach(($) => {
299
- const E = s.components?.get($);
300
- E && ((Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"]).includes("none") || g.add(E));
299
+ const V = s.components?.get($);
300
+ V && ((Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"]).includes("none") || g.add(V));
301
301
  });
302
302
  });
303
303
  } else if (l.type === "insert" || l.type === "cut" || l.type === "insert_many") {
@@ -339,7 +339,7 @@ function et(e, a, l) {
339
339
  function tt(e, a, l, s, g) {
340
340
  let i;
341
341
  if (R(l)) {
342
- const { value: o } = L(e, a);
342
+ const { value: o } = W(e, a);
343
343
  i = l({ state: o });
344
344
  } else
345
345
  i = l;
@@ -448,8 +448,8 @@ function ot(e, {
448
448
  dependencies: t,
449
449
  serverState: o
450
450
  } = {}) {
451
- const [y, $] = ee({}), { sessionId: E } = me();
452
- let b = !a;
451
+ const [y, $] = ee({}), { sessionId: V } = me();
452
+ let I = !a;
453
453
  const [v] = ee(a ?? X()), F = q(m ?? X()), C = q(
454
454
  null
455
455
  );
@@ -463,9 +463,9 @@ function ot(e, {
463
463
  source: "server",
464
464
  timestamp: n.serverState.timestamp || Date.now()
465
465
  };
466
- if (n?.localStorage?.key && E) {
467
- const f = R(n.localStorage.key) ? n.localStorage.key(c) : n.localStorage.key, h = ae(
468
- `${E}-${v}-${f}`
466
+ if (n?.localStorage?.key && V) {
467
+ const d = R(n.localStorage.key) ? n.localStorage.key(c) : n.localStorage.key, h = ae(
468
+ `${V}-${v}-${d}`
469
469
  );
470
470
  if (h && h.lastUpdated > (n?.serverState?.timestamp || 0))
471
471
  return {
@@ -480,7 +480,7 @@ function ot(e, {
480
480
  timestamp: Date.now()
481
481
  };
482
482
  },
483
- [v, u, e, E]
483
+ [v, u, e, V]
484
484
  );
485
485
  J(() => {
486
486
  o && o.status === "success" && o.data !== void 0 && ge(v, o);
@@ -490,8 +490,8 @@ function ot(e, {
490
490
  if (n?.status !== "success" || n.data === void 0)
491
491
  return;
492
492
  se(v, { serverState: n });
493
- const c = typeof n.merge == "object" ? n.merge : n.merge === !0 ? { strategy: "append", key: "id" } : null, S = D(v, []), f = n.data;
494
- if (c && c.strategy === "append" && "key" in c && Array.isArray(S) && Array.isArray(f)) {
493
+ const c = typeof n.merge == "object" ? n.merge : n.merge === !0 ? { strategy: "append", key: "id" } : null, S = D(v, []), d = n.data;
494
+ if (c && c.strategy === "append" && "key" in c && Array.isArray(S) && Array.isArray(d)) {
495
495
  const h = c.key;
496
496
  if (!h) {
497
497
  console.error(
@@ -500,23 +500,23 @@ function ot(e, {
500
500
  return;
501
501
  }
502
502
  const w = new Set(
503
- S.map((I) => I[h])
504
- ), M = f.filter(
505
- (I) => !w.has(I[h])
503
+ S.map((b) => b[h])
504
+ ), M = d.filter(
505
+ (b) => !w.has(b[h])
506
506
  );
507
507
  M.length > 0 && ve(v, [], M);
508
- const T = D(v, []);
508
+ const E = D(v, []);
509
509
  te(
510
510
  v,
511
511
  [],
512
- T,
512
+ E,
513
513
  n.timestamp || Date.now()
514
514
  );
515
515
  } else
516
- K(v, f), te(
516
+ K(v, d), te(
517
517
  v,
518
518
  [],
519
- f,
519
+ d,
520
520
  n.timestamp || Date.now()
521
521
  );
522
522
  B(v);
@@ -528,7 +528,7 @@ function ot(e, {
528
528
  const r = N(v), n = {
529
529
  localStorageEnabled: !!r?.localStorage?.key
530
530
  };
531
- if (W(v, [], {
531
+ if (L(v, [], {
532
532
  ...P,
533
533
  features: n
534
534
  }), r?.defaultState !== void 0 || u !== void 0) {
@@ -537,15 +537,15 @@ function ot(e, {
537
537
  defaultState: h
538
538
  });
539
539
  }
540
- const { value: c, source: S, timestamp: f } = G();
541
- K(v, c), W(v, [], {
540
+ const { value: c, source: S, timestamp: d } = G();
541
+ K(v, c), L(v, [], {
542
542
  stateSource: S,
543
- lastServerSync: S === "server" ? f : void 0,
543
+ lastServerSync: S === "server" ? d : void 0,
544
544
  isDirty: S === "server" ? !1 : void 0,
545
545
  baseServerState: S === "server" ? c : void 0
546
546
  }), S === "server" && o && ge(v, o), B(v);
547
547
  }, [v, ...t || []]), $e(() => {
548
- b && se(v, {
548
+ I && se(v, {
549
549
  formElements: s,
550
550
  defaultState: u,
551
551
  localStorage: l,
@@ -559,28 +559,28 @@ function ot(e, {
559
559
  depsFunction: g || void 0,
560
560
  deps: g ? g(D(v, [])) : [],
561
561
  prevDeps: g ? g(D(v, [])) : []
562
- }), W(v, [], {
562
+ }), L(v, [], {
563
563
  ...r,
564
564
  components: n
565
565
  }), $({}), () => {
566
566
  const c = A(v, []), S = c?.components?.get(P);
567
- S?.paths && S.paths.forEach((f) => {
568
- const w = f.split(".").slice(1), M = p.getState().getShadowMetadata(v, w);
567
+ S?.paths && S.paths.forEach((d) => {
568
+ const w = d.split(".").slice(1), M = p.getState().getShadowMetadata(v, w);
569
569
  M?.pathComponents && M.pathComponents.size === 0 && (delete M.pathComponents, p.getState().setShadowMetadata(v, w, M));
570
- }), c?.components && W(v, [], c);
570
+ }), c?.components && L(v, [], c);
571
571
  };
572
572
  }, []);
573
- const d = at(
573
+ const f = at(
574
574
  v,
575
- E,
575
+ V,
576
576
  C
577
577
  );
578
578
  return p.getState().initialStateGlobal[v] || he(v, e), ye(() => we(
579
579
  v,
580
- d,
580
+ f,
581
581
  F.current,
582
- E
583
- ), [v, E]);
582
+ V
583
+ ), [v, V]);
584
584
  }
585
585
  const st = (e, a, l) => {
586
586
  let s = A(e, a)?.arrayKeys || [];
@@ -620,7 +620,7 @@ const st = (e, a, l) => {
620
620
  });
621
621
  }
622
622
  };
623
- function L(e, a, l) {
623
+ function W(e, a, l) {
624
624
  const s = A(e, a), g = a.length > 0 ? a.join(".") : "root", i = l?.arrayViews?.[g];
625
625
  if (Array.isArray(i) && i.length === 0)
626
626
  return {
@@ -642,12 +642,12 @@ function we(e, a, l, s) {
642
642
  meta: o,
643
643
  componentId: y
644
644
  }) {
645
- const $ = o ? JSON.stringify(o.arrayViews || o.transforms) : "", E = t.join(".") + ":" + y + ":" + $;
646
- if (g.has(E))
647
- return g.get(E);
648
- const b = [e, ...t].join("."), v = () => {
645
+ const $ = o ? JSON.stringify(o.arrayViews || o.transforms) : "", V = t.join(".") + ":" + y + ":" + $;
646
+ if (g.has(V))
647
+ return g.get(V);
648
+ const I = [e, ...t].join("."), v = () => {
649
649
  }, F = {
650
- apply(G, d, H) {
650
+ apply(G, f, H) {
651
651
  if (H.length === 0) {
652
652
  const r = t.length > 0 ? t.join(".") : "root", n = o?.arrayViews?.[r];
653
653
  return D(e, t, n);
@@ -655,91 +655,103 @@ function we(e, a, l, s) {
655
655
  const P = H[0];
656
656
  return a(P, t, { updateType: "update" }), !0;
657
657
  },
658
- get(G, d, H) {
659
- if (d === "call" || d === "apply" || d === "bind")
660
- return Reflect.get(G, d, H);
661
- if (typeof d != "string")
662
- return Reflect.get(G, d);
663
- if (t.length === 0 && d in m)
664
- return m[d];
665
- if (typeof d == "string" && !d.startsWith("$")) {
666
- const r = [...t, d];
658
+ get(G, f, H) {
659
+ if (f === "call" || f === "apply" || f === "bind")
660
+ return Reflect.get(G, f, H);
661
+ if (typeof f != "string")
662
+ return Reflect.get(G, f);
663
+ if (t.length === 0 && f in m)
664
+ return m[f];
665
+ if (typeof f == "string" && !f.startsWith("$")) {
666
+ const r = [...t, f];
667
667
  return i({
668
668
  path: r,
669
669
  componentId: y,
670
670
  meta: o
671
671
  });
672
672
  }
673
- if (d === "$_rebuildStateShape")
673
+ if (f === "$_rebuildStateShape")
674
674
  return i;
675
- if (d === "$sync" && t.length === 0)
675
+ if (f === "$sync" && t.length === 0)
676
676
  return async function() {
677
677
  const r = p.getState().getInitialOptions(e), n = r?.sync;
678
678
  if (!n)
679
679
  return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
680
680
  const c = p.getState().getShadowValue(e, []), S = r?.validation?.key;
681
681
  try {
682
- const f = await n.action(c);
683
- if (f && !f.success && f.errors, f?.success) {
682
+ const d = await n.action(c);
683
+ if (d && !d.success && d.errors, d?.success) {
684
684
  const h = p.getState().getShadowMetadata(e, []);
685
- W(e, [], {
685
+ L(e, [], {
686
686
  ...h,
687
687
  isDirty: !1,
688
688
  lastServerSync: Date.now(),
689
689
  stateSource: "server",
690
690
  baseServerState: c
691
691
  // Update base server state
692
- }), n.onSuccess && n.onSuccess(f.data);
693
- } else !f?.success && n.onError && n.onError(f.error);
694
- return f;
695
- } catch (f) {
696
- return n.onError && n.onError(f), { success: !1, error: f };
692
+ }), n.onSuccess && n.onSuccess(d.data);
693
+ } else !d?.success && n.onError && n.onError(d.error);
694
+ return d;
695
+ } catch (d) {
696
+ return n.onError && n.onError(d), { success: !1, error: d };
697
697
  }
698
698
  };
699
- if (d === "$_status" || d === "$getStatus") {
699
+ if (f === "$_status" || f === "$getStatus") {
700
700
  const r = () => {
701
- const { shadowMeta: n, value: c } = L(e, t, o);
701
+ const { shadowMeta: n, value: c } = W(e, t, o);
702
702
  return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" || c !== void 0 ? "fresh" : "unknown";
703
703
  };
704
- return d === "$_status" ? r() : r;
704
+ return f === "$_status" ? r() : r;
705
705
  }
706
- if (d === "$removeStorage")
706
+ if (f === "$removeStorage")
707
707
  return () => {
708
708
  const r = p.getState().initialStateGlobal[e], n = N(e), c = R(n?.localStorage?.key) ? n.localStorage.key(r) : n?.localStorage?.key, S = `${s}-${e}-${c}`;
709
709
  S && localStorage.removeItem(S);
710
710
  };
711
- if (d === "$validate")
711
+ if (f === "$validate")
712
712
  return () => {
713
- const r = p.getState(), { value: n } = L(e, t, o), c = r.getInitialOptions(e), S = c?.validation?.zodSchemaV4 || c?.validation?.zodSchemaV3;
713
+ const r = p.getState(), { value: n } = W(e, t, o), c = r.getInitialOptions(e), S = c?.validation?.zodSchemaV4 || c?.validation?.zodSchemaV3;
714
714
  if (!S)
715
715
  return { success: !0, data: n };
716
- const f = S.safeParse(n);
717
- return f.success || (f.error.errors.forEach((h) => {
718
- const w = [...t, ...h.path.map(String)], M = r.getShadowMetadata(e, w) || {};
719
- r.setShadowMetadata(e, w, {
720
- ...M,
716
+ const d = S.safeParse(n);
717
+ if (d.success) {
718
+ const h = r.getShadowMetadata(e, t) || {};
719
+ r.setShadowMetadata(e, t, {
720
+ ...h,
721
721
  validation: {
722
- status: "INVALID",
723
- errors: [
724
- {
725
- source: "client",
726
- message: h.message,
727
- severity: "error",
728
- code: h.code
729
- }
730
- ],
731
- lastValidated: Date.now(),
732
- validatedValue: D(e, w)
722
+ status: "VALID",
723
+ errors: [],
724
+ lastValidated: Date.now()
733
725
  }
734
726
  });
735
- }), B(e)), f;
727
+ } else
728
+ (d.error?.issues || d.error?.errors || []).forEach((w) => {
729
+ const M = [...t, ...w.path.map(String)], E = r.getShadowMetadata(e, M) || {};
730
+ r.setShadowMetadata(e, M, {
731
+ ...E,
732
+ validation: {
733
+ status: "INVALID",
734
+ errors: [
735
+ {
736
+ source: "client",
737
+ message: w.message,
738
+ severity: "error",
739
+ code: w.code
740
+ }
741
+ ],
742
+ lastValidated: Date.now(),
743
+ validatedValue: r.getShadowValue(e, M)
744
+ }
745
+ });
746
+ });
747
+ return B(e), d;
736
748
  };
737
- if (d === "$showValidationErrors")
749
+ if (f === "$showValidationErrors")
738
750
  return () => {
739
- const { shadowMeta: r } = L(e, t, o);
751
+ const { shadowMeta: r } = W(e, t, o);
740
752
  return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((n) => n.severity === "error").map((n) => n.message) : [];
741
753
  };
742
- if (d === "$getSelected")
754
+ if (f === "$getSelected")
743
755
  return () => {
744
756
  const r = [e, ...t].join(".");
745
757
  ie(e, y, [
@@ -749,8 +761,8 @@ function we(e, a, l, s) {
749
761
  const n = p.getState().selectedIndicesMap.get(r);
750
762
  if (!n)
751
763
  return;
752
- const c = t.join("."), S = o?.arrayViews?.[c], f = n.split(".").pop();
753
- if (!(S && !S.includes(f) || D(
764
+ const c = t.join("."), S = o?.arrayViews?.[c], d = n.split(".").pop();
765
+ if (!(S && !S.includes(d) || D(
754
766
  e,
755
767
  n.split(".").slice(1)
756
768
  ) === void 0))
@@ -760,7 +772,7 @@ function we(e, a, l, s) {
760
772
  meta: o
761
773
  });
762
774
  };
763
- if (d === "$getSelectedIndex")
775
+ if (f === "$getSelectedIndex")
764
776
  return () => {
765
777
  const r = e + "." + t.join(".");
766
778
  t.join(".");
@@ -773,13 +785,13 @@ function we(e, a, l, s) {
773
785
  const S = n.split(".").pop();
774
786
  return c.indexOf(S);
775
787
  };
776
- if (d === "$clearSelected")
788
+ if (f === "$clearSelected")
777
789
  return Q(e, t), () => {
778
- We({
790
+ Le({
779
791
  arrayKey: e + "." + t.join(".")
780
792
  });
781
793
  };
782
- if (d === "$map")
794
+ if (f === "$map")
783
795
  return (r) => {
784
796
  const { value: n, keys: c } = j(
785
797
  e,
@@ -793,19 +805,19 @@ function we(e, a, l, s) {
793
805
  componentId: y,
794
806
  meta: o
795
807
  });
796
- return n.map((f, h) => {
808
+ return n.map((d, h) => {
797
809
  const w = c[h];
798
810
  if (!w) return;
799
- const M = [...t, w], T = i({
811
+ const M = [...t, w], E = i({
800
812
  path: M,
801
813
  // This now correctly points to the item in the shadow store.
802
814
  componentId: y,
803
815
  meta: o
804
816
  });
805
- return r(T, h, S);
817
+ return r(E, h, S);
806
818
  });
807
819
  };
808
- if (d === "$filter")
820
+ if (f === "$filter")
809
821
  return (r) => {
810
822
  const n = t.length > 0 ? t.join(".") : "root", { keys: c, value: S } = j(
811
823
  e,
@@ -814,11 +826,11 @@ function we(e, a, l, s) {
814
826
  );
815
827
  if (!Array.isArray(S))
816
828
  throw new Error("filter can only be used on arrays");
817
- const f = [];
829
+ const d = [];
818
830
  return S.forEach((h, w) => {
819
831
  if (r(h, w)) {
820
832
  const M = c[w];
821
- M && f.push(M);
833
+ M && d.push(M);
822
834
  }
823
835
  }), i({
824
836
  path: t,
@@ -827,7 +839,7 @@ function we(e, a, l, s) {
827
839
  ...o,
828
840
  arrayViews: {
829
841
  ...o?.arrayViews || {},
830
- [n]: f
842
+ [n]: d
831
843
  },
832
844
  transforms: [
833
845
  ...o?.transforms || [],
@@ -836,7 +848,7 @@ function we(e, a, l, s) {
836
848
  }
837
849
  });
838
850
  };
839
- if (d === "$sort")
851
+ if (f === "$sort")
840
852
  return (r) => {
841
853
  const n = t.length > 0 ? t.join(".") : "root", { value: c, keys: S } = j(
842
854
  e,
@@ -845,12 +857,12 @@ function we(e, a, l, s) {
845
857
  );
846
858
  if (!Array.isArray(c) || !S)
847
859
  throw new Error("No array keys found for sorting");
848
- const f = c.map((w, M) => ({
860
+ const d = c.map((w, M) => ({
849
861
  item: w,
850
862
  key: S[M]
851
863
  }));
852
- f.sort((w, M) => r(w.item, M.item));
853
- const h = f.map((w) => w.key);
864
+ d.sort((w, M) => r(w.item, M.item));
865
+ const h = d.map((w) => w.key);
854
866
  return i({
855
867
  path: t,
856
868
  componentId: y,
@@ -867,50 +879,50 @@ function we(e, a, l, s) {
867
879
  }
868
880
  });
869
881
  };
870
- if (d === "$stream")
882
+ if (f === "$stream")
871
883
  return function(r = {}) {
872
884
  const {
873
885
  bufferSize: n = 100,
874
886
  flushInterval: c = 100,
875
887
  bufferStrategy: S = "accumulate",
876
- store: f,
888
+ store: d,
877
889
  onFlush: h
878
890
  } = r;
879
- let w = [], M = !1, T = null;
880
- const I = (V) => {
891
+ let w = [], M = !1, E = null;
892
+ const b = (T) => {
881
893
  if (!M) {
882
894
  if (S === "sliding" && w.length >= n)
883
895
  w.shift();
884
896
  else if (S === "dropping" && w.length >= n)
885
897
  return;
886
- w.push(V), w.length >= n && k();
898
+ w.push(T), w.length >= n && k();
887
899
  }
888
900
  }, k = () => {
889
901
  if (w.length === 0) return;
890
- const V = [...w];
891
- if (w = [], f) {
892
- const U = f(V);
902
+ const T = [...w];
903
+ if (w = [], d) {
904
+ const U = d(T);
893
905
  U !== void 0 && (Array.isArray(U) ? U : [U]).forEach((pe) => {
894
906
  a(pe, t, {
895
907
  updateType: "insert"
896
908
  });
897
909
  });
898
910
  } else
899
- V.forEach((U) => {
911
+ T.forEach((U) => {
900
912
  a(U, t, {
901
913
  updateType: "insert"
902
914
  });
903
915
  });
904
- h?.(V);
916
+ h?.(T);
905
917
  };
906
- c > 0 && (T = setInterval(k, c));
918
+ c > 0 && (E = setInterval(k, c));
907
919
  const O = X(), _ = A(e, t) || {}, z = _.streams || /* @__PURE__ */ new Map();
908
- return z.set(O, { buffer: w, flushTimer: T }), W(e, t, {
920
+ return z.set(O, { buffer: w, flushTimer: E }), L(e, t, {
909
921
  ..._,
910
922
  streams: z
911
923
  }), {
912
- write: (V) => I(V),
913
- writeMany: (V) => V.forEach(I),
924
+ write: (T) => b(T),
925
+ writeMany: (T) => T.forEach(b),
914
926
  flush: () => k(),
915
927
  pause: () => {
916
928
  M = !0;
@@ -919,66 +931,66 @@ function we(e, a, l, s) {
919
931
  M = !1, w.length > 0 && k();
920
932
  },
921
933
  close: () => {
922
- k(), T && clearInterval(T);
923
- const V = p.getState().getShadowMetadata(e, t);
924
- V?.streams && V.streams.delete(O);
934
+ k(), E && clearInterval(E);
935
+ const T = p.getState().getShadowMetadata(e, t);
936
+ T?.streams && T.streams.delete(O);
925
937
  }
926
938
  };
927
939
  };
928
- if (d === "$list")
940
+ if (f === "$list")
929
941
  return (r) => /* @__PURE__ */ Z(() => {
930
- const c = q(/* @__PURE__ */ new Map()), [S, f] = ee({}), h = t.length > 0 ? t.join(".") : "root", w = st(e, t, o), M = ye(() => ({
942
+ const c = q(/* @__PURE__ */ new Map()), [S, d] = ee({}), h = t.length > 0 ? t.join(".") : "root", w = st(e, t, o), M = ye(() => ({
931
943
  ...o,
932
944
  arrayViews: {
933
945
  ...o?.arrayViews || {},
934
946
  [h]: w
935
947
  }
936
- }), [o, h, w]), { value: T } = j(
948
+ }), [o, h, w]), { value: E } = j(
937
949
  e,
938
950
  t,
939
951
  M
940
952
  );
941
953
  if (J(() => {
942
- const O = p.getState().subscribeToPath(b, (_) => {
954
+ const O = p.getState().subscribeToPath(I, (_) => {
943
955
  if (_.type === "GET_SELECTED")
944
956
  return;
945
- const V = p.getState().getShadowMetadata(e, t)?.transformCaches;
946
- if (V)
947
- for (const U of V.keys())
948
- U.startsWith(y) && V.delete(U);
949
- (_.type === "INSERT" || _.type === "INSERT_MANY" || _.type === "REMOVE" || _.type === "CLEAR_SELECTION" || _.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) && f({});
957
+ const T = p.getState().getShadowMetadata(e, t)?.transformCaches;
958
+ if (T)
959
+ for (const U of T.keys())
960
+ U.startsWith(y) && T.delete(U);
961
+ (_.type === "INSERT" || _.type === "INSERT_MANY" || _.type === "REMOVE" || _.type === "CLEAR_SELECTION" || _.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) && d({});
950
962
  });
951
963
  return () => {
952
964
  O();
953
965
  };
954
- }, [y, b]), !Array.isArray(T))
966
+ }, [y, I]), !Array.isArray(E))
955
967
  return null;
956
- const I = i({
968
+ const b = i({
957
969
  path: t,
958
970
  componentId: y,
959
971
  meta: M
960
972
  // Use updated meta here
961
- }), k = T.map((O, _) => {
973
+ }), k = E.map((O, _) => {
962
974
  const z = w[_];
963
975
  if (!z)
964
976
  return null;
965
- let V = c.current.get(z);
966
- V || (V = X(), c.current.set(z, V));
977
+ let T = c.current.get(z);
978
+ T || (T = X(), c.current.set(z, T));
967
979
  const U = [...t, z];
968
980
  return ue(De, {
969
981
  key: z,
970
982
  stateKey: e,
971
- itemComponentId: V,
983
+ itemComponentId: T,
972
984
  itemPath: U,
973
985
  localIndex: _,
974
- arraySetter: I,
986
+ arraySetter: b,
975
987
  rebuildStateShape: i,
976
988
  renderFn: r
977
989
  });
978
990
  });
979
991
  return /* @__PURE__ */ Z(Me, { children: k });
980
992
  }, {});
981
- if (d === "$stateFlattenOn")
993
+ if (f === "$stateFlattenOn")
982
994
  return (r) => {
983
995
  const n = t.length > 0 ? t.join(".") : "root", c = o?.arrayViews?.[n], S = p.getState().getShadowValue(e, t, c);
984
996
  return Array.isArray(S) ? i({
@@ -987,7 +999,7 @@ function we(e, a, l, s) {
987
999
  meta: o
988
1000
  }) : [];
989
1001
  };
990
- if (d === "$index")
1002
+ if (f === "$index")
991
1003
  return (r) => {
992
1004
  const n = t.length > 0 ? t.join(".") : "root", c = o?.arrayViews?.[n];
993
1005
  if (c) {
@@ -1000,15 +1012,15 @@ function we(e, a, l, s) {
1000
1012
  }
1001
1013
  const S = A(e, t);
1002
1014
  if (!S?.arrayKeys) return;
1003
- const f = S.arrayKeys[r];
1004
- if (f)
1015
+ const d = S.arrayKeys[r];
1016
+ if (d)
1005
1017
  return i({
1006
- path: [...t, f],
1018
+ path: [...t, d],
1007
1019
  componentId: y,
1008
1020
  meta: o
1009
1021
  });
1010
1022
  };
1011
- if (d === "$last")
1023
+ if (f === "$last")
1012
1024
  return () => {
1013
1025
  const { keys: r } = j(e, t, o);
1014
1026
  if (!r || r.length === 0)
@@ -1023,56 +1035,56 @@ function we(e, a, l, s) {
1023
1035
  meta: o
1024
1036
  });
1025
1037
  };
1026
- if (d === "$insert")
1038
+ if (f === "$insert")
1027
1039
  return (r, n) => {
1028
1040
  a(r, t, {
1029
1041
  updateType: "insert",
1030
1042
  index: n
1031
1043
  });
1032
1044
  };
1033
- if (d === "$insertMany")
1045
+ if (f === "$insertMany")
1034
1046
  return (r) => {
1035
1047
  a(r, t, {
1036
1048
  updateType: "insert_many"
1037
1049
  });
1038
1050
  };
1039
- if (d === "$uniqueInsert")
1051
+ if (f === "$uniqueInsert")
1040
1052
  return (r, n, c) => {
1041
- const { value: S } = L(
1053
+ const { value: S } = W(
1042
1054
  e,
1043
1055
  t,
1044
1056
  o
1045
- ), f = R(r) ? r(S) : r;
1057
+ ), d = R(r) ? r(S) : r;
1046
1058
  let h = null;
1047
1059
  if (!S.some((M) => {
1048
- const T = n ? n.every(
1049
- (I) => Y(M[I], f[I])
1050
- ) : Y(M, f);
1051
- return T && (h = M), T;
1060
+ const E = n ? n.every(
1061
+ (b) => Y(M[b], d[b])
1062
+ ) : Y(M, d);
1063
+ return E && (h = M), E;
1052
1064
  }))
1053
- a(f, t, { updateType: "insert" });
1065
+ a(d, t, { updateType: "insert" });
1054
1066
  else if (c && h) {
1055
- const M = c(h), T = S.map(
1056
- (I) => Y(I, h) ? M : I
1067
+ const M = c(h), E = S.map(
1068
+ (b) => Y(b, h) ? M : b
1057
1069
  );
1058
- a(T, t, {
1070
+ a(E, t, {
1059
1071
  updateType: "update"
1060
1072
  });
1061
1073
  }
1062
1074
  };
1063
- if (d === "$cut")
1075
+ if (f === "$cut")
1064
1076
  return (r, n) => {
1065
1077
  const c = A(e, t);
1066
1078
  if (console.log("shadowMeta ->>>>>>>>>>>>>>>>", c), !c?.arrayKeys || c.arrayKeys.length === 0)
1067
1079
  return;
1068
1080
  const S = r === -1 ? c.arrayKeys.length - 1 : r !== void 0 ? r : c.arrayKeys.length - 1;
1069
1081
  console.log("indexToCut ->>>>>>>>>>>>>>>>", S);
1070
- const f = c.arrayKeys[S];
1071
- f && (console.log("idToCut ->>>>>>>>>>>>>>>>", f), a(null, [...t, f], {
1082
+ const d = c.arrayKeys[S];
1083
+ d && (console.log("idToCut ->>>>>>>>>>>>>>>>", d), a(null, [...t, d], {
1072
1084
  updateType: "cut"
1073
1085
  }));
1074
1086
  };
1075
- if (d === "$cutSelected")
1087
+ if (f === "$cutSelected")
1076
1088
  return () => {
1077
1089
  const r = [e, ...t].join("."), { keys: n } = j(e, t, o);
1078
1090
  if (!n || n.length === 0)
@@ -1083,14 +1095,14 @@ function we(e, a, l, s) {
1083
1095
  const S = c.split(".").pop();
1084
1096
  if (!n.includes(S))
1085
1097
  return;
1086
- const f = c.split(".").slice(1);
1098
+ const d = c.split(".").slice(1);
1087
1099
  p.getState().clearSelectedIndex({ arrayKey: r });
1088
- const h = f.slice(0, -1);
1089
- Q(e, h), a(null, f, {
1100
+ const h = d.slice(0, -1);
1101
+ Q(e, h), a(null, d, {
1090
1102
  updateType: "cut"
1091
1103
  });
1092
1104
  };
1093
- if (d === "$cutByValue")
1105
+ if (f === "$cutByValue")
1094
1106
  return (r) => {
1095
1107
  const {
1096
1108
  isArray: n,
@@ -1098,12 +1110,12 @@ function we(e, a, l, s) {
1098
1110
  keys: S
1099
1111
  } = j(e, t, o);
1100
1112
  if (!n) return;
1101
- const f = oe(c, S, (h) => h === r);
1102
- f && a(null, [...t, f.key], {
1113
+ const d = oe(c, S, (h) => h === r);
1114
+ d && a(null, [...t, d.key], {
1103
1115
  updateType: "cut"
1104
1116
  });
1105
1117
  };
1106
- if (d === "$toggleByValue")
1118
+ if (f === "$toggleByValue")
1107
1119
  return (r) => {
1108
1120
  const {
1109
1121
  isArray: n,
@@ -1111,23 +1123,23 @@ function we(e, a, l, s) {
1111
1123
  keys: S
1112
1124
  } = j(e, t, o);
1113
1125
  if (!n) return;
1114
- const f = oe(c, S, (h) => h === r);
1115
- if (f) {
1116
- const h = [...t, f.key];
1126
+ const d = oe(c, S, (h) => h === r);
1127
+ if (d) {
1128
+ const h = [...t, d.key];
1117
1129
  a(null, h, {
1118
1130
  updateType: "cut"
1119
1131
  });
1120
1132
  } else
1121
1133
  a(r, t, { updateType: "insert" });
1122
1134
  };
1123
- if (d === "$findWith")
1135
+ if (f === "$findWith")
1124
1136
  return (r, n) => {
1125
- const { isArray: c, value: S, keys: f } = j(e, t, o);
1137
+ const { isArray: c, value: S, keys: d } = j(e, t, o);
1126
1138
  if (!c)
1127
1139
  throw new Error("findWith can only be used on arrays");
1128
1140
  const h = oe(
1129
1141
  S,
1130
- f,
1142
+ d,
1131
1143
  (w) => w?.[r] === n
1132
1144
  );
1133
1145
  return h ? i({
@@ -1136,71 +1148,71 @@ function we(e, a, l, s) {
1136
1148
  meta: o
1137
1149
  }) : null;
1138
1150
  };
1139
- if (d === "$cutThis") {
1140
- const { value: r } = L(e, t, o), n = t.slice(0, -1);
1151
+ if (f === "$cutThis") {
1152
+ const { value: r } = W(e, t, o), n = t.slice(0, -1);
1141
1153
  return Q(e, n), () => {
1142
1154
  a(r, t, { updateType: "cut" });
1143
1155
  };
1144
1156
  }
1145
- if (d === "$get")
1157
+ if (f === "$get")
1146
1158
  return () => {
1147
1159
  ie(e, y, t);
1148
- const { value: r } = L(e, t, o);
1160
+ const { value: r } = W(e, t, o);
1149
1161
  return r;
1150
1162
  };
1151
- if (d === "$$derive")
1163
+ if (f === "$$derive")
1152
1164
  return (r) => Se({
1153
1165
  _stateKey: e,
1154
1166
  _path: t,
1155
1167
  _effect: r.toString(),
1156
1168
  _meta: o
1157
1169
  });
1158
- if (d === "$$get")
1170
+ if (f === "$$get")
1159
1171
  return () => Se({ _stateKey: e, _path: t, _meta: o });
1160
- if (d === "$lastSynced") {
1172
+ if (f === "$lastSynced") {
1161
1173
  const r = `${e}:${t.join(".")}`;
1162
- return Le(r);
1174
+ return We(r);
1163
1175
  }
1164
- if (d == "getLocalStorage")
1176
+ if (f == "getLocalStorage")
1165
1177
  return (r) => ae(s + "-" + e + "-" + r);
1166
- if (d === "$isSelected") {
1178
+ if (f === "$isSelected") {
1167
1179
  const r = t.slice(0, -1);
1168
1180
  if (A(e, r)?.arrayKeys) {
1169
- const c = e + "." + r.join("."), S = p.getState().selectedIndicesMap.get(c), f = e + "." + t.join(".");
1170
- return S === f;
1181
+ const c = e + "." + r.join("."), S = p.getState().selectedIndicesMap.get(c), d = e + "." + t.join(".");
1182
+ return S === d;
1171
1183
  }
1172
1184
  return;
1173
1185
  }
1174
- if (d === "$setSelected")
1186
+ if (f === "$setSelected")
1175
1187
  return (r) => {
1176
1188
  const n = t.slice(0, -1), c = e + "." + n.join("."), S = e + "." + t.join(".");
1177
1189
  Q(e, n, void 0), p.getState().selectedIndicesMap.get(c), r && p.getState().setSelectedIndex(c, S);
1178
1190
  };
1179
- if (d === "$toggleSelected")
1191
+ if (f === "$toggleSelected")
1180
1192
  return () => {
1181
1193
  const r = t.slice(0, -1), n = e + "." + r.join("."), c = e + "." + t.join(".");
1182
1194
  p.getState().selectedIndicesMap.get(n) === c ? p.getState().clearSelectedIndex({ arrayKey: n }) : p.getState().setSelectedIndex(n, c), Q(e, r);
1183
1195
  };
1184
- if (d === "$_componentId")
1196
+ if (f === "$_componentId")
1185
1197
  return y;
1186
1198
  if (t.length == 0) {
1187
- if (d === "$setOptions")
1199
+ if (f === "$setOptions")
1188
1200
  return (r) => {
1189
1201
  ce({ stateKey: e, options: r, initialOptionsPart: {} });
1190
1202
  };
1191
- if (d === "$_applyUpdate")
1203
+ if (f === "$_applyUpdate")
1192
1204
  return (r, n, c = "update") => {
1193
1205
  a(r, n, { updateType: c });
1194
1206
  };
1195
- if (d === "$_getEffectiveSetState")
1207
+ if (f === "$_getEffectiveSetState")
1196
1208
  return a;
1197
- if (d === "$getPluginMetaData")
1209
+ if (f === "$getPluginMetaData")
1198
1210
  return (r) => Ge(e, t)?.get(r);
1199
- if (d === "$addPluginMetaData")
1211
+ if (f === "$addPluginMetaData")
1200
1212
  return console.log("$addPluginMetaDat"), (r, n) => xe(e, t, r, n);
1201
- if (d === "$removePluginMetaData")
1213
+ if (f === "$removePluginMetaData")
1202
1214
  return (r) => qe(e, t, r);
1203
- if (d === "$addZodValidation")
1215
+ if (f === "$addZodValidation")
1204
1216
  return (r, n) => {
1205
1217
  r.forEach((c) => {
1206
1218
  const S = p.getState().getShadowMetadata(e, c.path) || {};
@@ -1222,12 +1234,12 @@ function we(e, a, l, s) {
1222
1234
  });
1223
1235
  });
1224
1236
  };
1225
- if (d === "$clearZodValidation")
1237
+ if (f === "$clearZodValidation")
1226
1238
  return (r) => {
1227
1239
  if (!r)
1228
1240
  throw new Error("clearZodValidation requires a path");
1229
1241
  const n = A(e, r) || {};
1230
- W(e, r, {
1242
+ L(e, r, {
1231
1243
  ...n,
1232
1244
  validation: {
1233
1245
  status: "NOT_VALIDATED",
@@ -1236,7 +1248,7 @@ function we(e, a, l, s) {
1236
1248
  }
1237
1249
  });
1238
1250
  };
1239
- if (d === "$applyOperation")
1251
+ if (f === "$applyOperation")
1240
1252
  return (r, n) => {
1241
1253
  console.log(
1242
1254
  "getGlobalStore",
@@ -1246,10 +1258,10 @@ function we(e, a, l, s) {
1246
1258
  if (r.insertAfterId && r.updateType === "insert") {
1247
1259
  const S = A(e, r.path);
1248
1260
  if (S?.arrayKeys) {
1249
- const f = S.arrayKeys.indexOf(
1261
+ const d = S.arrayKeys.indexOf(
1250
1262
  r.insertAfterId
1251
1263
  );
1252
- f !== -1 && (c = f + 1);
1264
+ d !== -1 && (c = d + 1);
1253
1265
  }
1254
1266
  }
1255
1267
  a(r.newValue, r.path, {
@@ -1260,11 +1272,11 @@ function we(e, a, l, s) {
1260
1272
  metaData: n
1261
1273
  });
1262
1274
  };
1263
- if (d === "$applyJsonPatch")
1275
+ if (f === "$applyJsonPatch")
1264
1276
  return (r) => {
1265
1277
  const n = p.getState(), c = n.getShadowMetadata(e, []);
1266
1278
  if (!c?.components) return;
1267
- const S = (h) => !h || h === "/" ? [] : h.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), f = /* @__PURE__ */ new Set();
1279
+ const S = (h) => !h || h === "/" ? [] : h.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
1268
1280
  for (const h of r) {
1269
1281
  const w = S(h.path);
1270
1282
  switch (h.op) {
@@ -1272,53 +1284,53 @@ function we(e, a, l, s) {
1272
1284
  case "replace": {
1273
1285
  const { value: M } = h;
1274
1286
  n.updateShadowAtPath(e, w, M), n.markAsDirty(e, w, { bubble: !0 });
1275
- let T = [...w];
1287
+ let E = [...w];
1276
1288
  for (; ; ) {
1277
- const I = n.getShadowMetadata(
1289
+ const b = n.getShadowMetadata(
1278
1290
  e,
1279
- T
1291
+ E
1280
1292
  );
1281
- if (I?.pathComponents && I.pathComponents.forEach((k) => {
1282
- if (!f.has(k)) {
1293
+ if (b?.pathComponents && b.pathComponents.forEach((k) => {
1294
+ if (!d.has(k)) {
1283
1295
  const O = c.components?.get(k);
1284
- O && (O.forceUpdate(), f.add(k));
1296
+ O && (O.forceUpdate(), d.add(k));
1285
1297
  }
1286
- }), T.length === 0) break;
1287
- T.pop();
1298
+ }), E.length === 0) break;
1299
+ E.pop();
1288
1300
  }
1289
1301
  break;
1290
1302
  }
1291
1303
  case "remove": {
1292
1304
  const M = w.slice(0, -1);
1293
1305
  n.removeShadowArrayElement(e, w), n.markAsDirty(e, M, { bubble: !0 });
1294
- let T = [...M];
1306
+ let E = [...M];
1295
1307
  for (; ; ) {
1296
- const I = n.getShadowMetadata(
1308
+ const b = n.getShadowMetadata(
1297
1309
  e,
1298
- T
1310
+ E
1299
1311
  );
1300
- if (I?.pathComponents && I.pathComponents.forEach((k) => {
1301
- if (!f.has(k)) {
1312
+ if (b?.pathComponents && b.pathComponents.forEach((k) => {
1313
+ if (!d.has(k)) {
1302
1314
  const O = c.components?.get(k);
1303
- O && (O.forceUpdate(), f.add(k));
1315
+ O && (O.forceUpdate(), d.add(k));
1304
1316
  }
1305
- }), T.length === 0) break;
1306
- T.pop();
1317
+ }), E.length === 0) break;
1318
+ E.pop();
1307
1319
  }
1308
1320
  break;
1309
1321
  }
1310
1322
  }
1311
1323
  }
1312
1324
  };
1313
- if (d === "$getComponents")
1325
+ if (f === "$getComponents")
1314
1326
  return () => A(e, [])?.components;
1315
1327
  }
1316
- if (d === "$validationWrapper")
1328
+ if (f === "$validationWrapper")
1317
1329
  return ({
1318
1330
  children: r,
1319
1331
  hideMessage: n
1320
1332
  }) => /* @__PURE__ */ Z(
1321
- Ie,
1333
+ be,
1322
1334
  {
1323
1335
  formOpts: n ? { validation: { message: "" } } : void 0,
1324
1336
  path: t,
@@ -1326,13 +1338,13 @@ function we(e, a, l, s) {
1326
1338
  children: r
1327
1339
  }
1328
1340
  );
1329
- if (d === "$_stateKey") return e;
1330
- if (d === "$_path") return t;
1331
- if (d === "$update")
1341
+ if (f === "$_stateKey") return e;
1342
+ if (f === "$_path") return t;
1343
+ if (f === "$update")
1332
1344
  return (r) => (a(r, t, { updateType: "update" }), {
1333
1345
  synced: () => {
1334
1346
  const n = p.getState().getShadowMetadata(e, t);
1335
- W(e, t, {
1347
+ L(e, t, {
1336
1348
  ...n,
1337
1349
  isDirty: !1,
1338
1350
  stateSource: "server",
@@ -1345,8 +1357,8 @@ function we(e, a, l, s) {
1345
1357
  });
1346
1358
  }
1347
1359
  });
1348
- if (d === "$toggle") {
1349
- const { value: r } = L(
1360
+ if (f === "$toggle") {
1361
+ const { value: r } = W(
1350
1362
  e,
1351
1363
  t,
1352
1364
  o
@@ -1359,7 +1371,7 @@ function we(e, a, l, s) {
1359
1371
  });
1360
1372
  };
1361
1373
  }
1362
- if (d === "$isolate")
1374
+ if (f === "$isolate")
1363
1375
  return (r) => /* @__PURE__ */ Z(
1364
1376
  Pe,
1365
1377
  {
@@ -1369,7 +1381,7 @@ function we(e, a, l, s) {
1369
1381
  renderFn: r
1370
1382
  }
1371
1383
  );
1372
- if (d === "$formElement")
1384
+ if (f === "$formElement")
1373
1385
  return (r, n) => /* @__PURE__ */ Z(
1374
1386
  ke,
1375
1387
  {
@@ -1381,7 +1393,7 @@ function we(e, a, l, s) {
1381
1393
  renderFn: r
1382
1394
  }
1383
1395
  );
1384
- const P = [...t, d];
1396
+ const P = [...t, f];
1385
1397
  return i({
1386
1398
  path: P,
1387
1399
  componentId: y,
@@ -1389,7 +1401,7 @@ function we(e, a, l, s) {
1389
1401
  });
1390
1402
  }
1391
1403
  }, C = new Proxy(v, F);
1392
- return g.set(E, C), C;
1404
+ return g.set(V, C), C;
1393
1405
  }
1394
1406
  const m = {
1395
1407
  $revertToInitialState: (t) => {
@@ -1399,8 +1411,8 @@ function we(e, a, l, s) {
1399
1411
  path: [],
1400
1412
  componentId: l
1401
1413
  });
1402
- const $ = N(e), E = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, b = `${s}-${e}-${E}`;
1403
- return b && localStorage.removeItem(b), B(e), y;
1414
+ const $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, I = `${s}-${e}-${V}`;
1415
+ return I && localStorage.removeItem(I), B(e), y;
1404
1416
  },
1405
1417
  $initializeAndMergeShadowState: (t) => {
1406
1418
  Oe(e, t), B(e);
@@ -1411,8 +1423,8 @@ function we(e, a, l, s) {
1411
1423
  a,
1412
1424
  l,
1413
1425
  s
1414
- ), y = p.getState().initialStateGlobal[e], $ = N(e), E = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, b = `${s}-${e}-${E}`;
1415
- return localStorage.getItem(b) && localStorage.removeItem(b), Ee(() => {
1426
+ ), y = p.getState().initialStateGlobal[e], $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, I = `${s}-${e}-${V}`;
1427
+ return localStorage.getItem(I) && localStorage.removeItem(I), Ee(() => {
1416
1428
  he(e, t), K(e, t);
1417
1429
  const v = p.getState().getShadowMetadata(e, []);
1418
1430
  v && v?.components?.forEach((F) => {
@@ -1443,14 +1455,14 @@ function it({
1443
1455
  console.warn("Parent element not found for signal", g);
1444
1456
  return;
1445
1457
  }
1446
- const y = t.parentElement, E = Array.from(y.childNodes).indexOf(t);
1447
- let b = y.getAttribute("data-parent-id");
1448
- b || (b = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", b)), l.current = `instance-${crypto.randomUUID()}`;
1458
+ const y = t.parentElement, V = Array.from(y.childNodes).indexOf(t);
1459
+ let I = y.getAttribute("data-parent-id");
1460
+ I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I)), l.current = `instance-${crypto.randomUUID()}`;
1449
1461
  const v = p.getState().getShadowMetadata(e._stateKey, e._path) || {}, F = v.signals || [];
1450
1462
  F.push({
1451
1463
  instanceId: l.current,
1452
- parentId: b,
1453
- position: E,
1464
+ parentId: I,
1465
+ position: V,
1454
1466
  effect: e._effect
1455
1467
  }), p.getState().setShadowMetadata(e._stateKey, e._path, {
1456
1468
  ...v,
@@ -1463,8 +1475,8 @@ function it({
1463
1475
  "state",
1464
1476
  `return (${e._effect})(state)`
1465
1477
  )(u);
1466
- } catch (d) {
1467
- console.error("Error evaluating effect function:", d);
1478
+ } catch (f) {
1479
+ console.error("Error evaluating effect function:", f);
1468
1480
  }
1469
1481
  C !== null && typeof C == "object" && (C = JSON.stringify(C));
1470
1482
  const G = document.createTextNode(String(C ?? ""));