cogsbox-state 0.5.446 → 0.5.448
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.
- package/dist/CogsState.d.ts +6 -5
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +126 -123
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +13 -6
package/dist/CogsState.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
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
|
|
3
|
+
import { memo as Ot, useState as K, useRef as q, useCallback as ct, useEffect as Z, useLayoutEffect as dt, useMemo as St, 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";
|
|
@@ -10,8 +10,8 @@ import { getGlobalStore as e, formRefStore as vt } from "./store.js";
|
|
|
10
10
|
import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
|
|
11
11
|
import { useInView as jt } from "react-intersection-observer";
|
|
12
12
|
function yt(t, n) {
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const g = e.getState().getInitialOptions, S = e.getState().setInitialStateOptions, y = g(t) || {};
|
|
14
|
+
S(t, {
|
|
15
15
|
...y,
|
|
16
16
|
...n
|
|
17
17
|
});
|
|
@@ -19,22 +19,22 @@ function yt(t, n) {
|
|
|
19
19
|
function Vt({
|
|
20
20
|
stateKey: t,
|
|
21
21
|
options: n,
|
|
22
|
-
initialOptionsPart:
|
|
22
|
+
initialOptionsPart: g
|
|
23
23
|
}) {
|
|
24
|
-
const
|
|
24
|
+
const S = nt(t) || {}, y = g[t] || {}, I = e.getState().setInitialStateOptions, V = { ...y, ...S };
|
|
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
29
|
u && I(t, V);
|
|
30
30
|
}
|
|
31
|
-
function ie(t, { formElements: n, validation:
|
|
32
|
-
return { initialState: t, formElements: n, validation:
|
|
31
|
+
function ie(t, { formElements: n, validation: g }) {
|
|
32
|
+
return { initialState: t, formElements: n, validation: g };
|
|
33
33
|
}
|
|
34
34
|
const Lt = (t, n) => {
|
|
35
|
-
let
|
|
36
|
-
const [
|
|
37
|
-
n?.__fromSyncSchema && n?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", n.__syncNotifications), Object.keys(
|
|
35
|
+
let g = t;
|
|
36
|
+
const [S, y] = Nt(g);
|
|
37
|
+
n?.__fromSyncSchema && n?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", n.__syncNotifications), Object.keys(S).forEach((u) => {
|
|
38
38
|
let f = y[u] || {};
|
|
39
39
|
const A = {
|
|
40
40
|
...f
|
|
@@ -52,8 +52,8 @@ const Lt = (t, n) => {
|
|
|
52
52
|
...A
|
|
53
53
|
}) : e.getState().setInitialStateOptions(u, A);
|
|
54
54
|
}
|
|
55
|
-
}), Object.keys(
|
|
56
|
-
e.getState().initializeShadowState(u,
|
|
55
|
+
}), Object.keys(S).forEach((u) => {
|
|
56
|
+
e.getState().initializeShadowState(u, S[u]);
|
|
57
57
|
});
|
|
58
58
|
const I = (u, f) => {
|
|
59
59
|
const [A] = K(f?.componentId ?? rt());
|
|
@@ -62,7 +62,7 @@ const Lt = (t, n) => {
|
|
|
62
62
|
options: f,
|
|
63
63
|
initialOptionsPart: y
|
|
64
64
|
});
|
|
65
|
-
const w = e.getState().getShadowValue(u) ||
|
|
65
|
+
const w = e.getState().getShadowValue(u) || S[u], i = f?.modifyState ? f.modifyState(w) : w;
|
|
66
66
|
return zt(i, {
|
|
67
67
|
stateKey: u,
|
|
68
68
|
syncUpdate: f?.syncUpdate,
|
|
@@ -82,12 +82,15 @@ const Lt = (t, n) => {
|
|
|
82
82
|
return { useCogsState: I, setCogsOptions: V };
|
|
83
83
|
};
|
|
84
84
|
function ce(t) {
|
|
85
|
-
const n = t.schemas,
|
|
86
|
-
for (const
|
|
87
|
-
const y = n[
|
|
88
|
-
S
|
|
85
|
+
const n = t.schemas, g = {};
|
|
86
|
+
for (const S in n) {
|
|
87
|
+
const y = n[S];
|
|
88
|
+
g[S] = y?.schemas?.defaultValues || {};
|
|
89
89
|
}
|
|
90
|
-
return Lt(
|
|
90
|
+
return Lt(g, {
|
|
91
|
+
__fromSyncSchema: !0,
|
|
92
|
+
__syncNotifications: t.notifications
|
|
93
|
+
});
|
|
91
94
|
}
|
|
92
95
|
const {
|
|
93
96
|
getInitialOptions: nt,
|
|
@@ -96,19 +99,19 @@ const {
|
|
|
96
99
|
updateInitialStateGlobal: _t,
|
|
97
100
|
addValidationError: pt,
|
|
98
101
|
removeValidationError: ut
|
|
99
|
-
} = e.getState(), Ht = (t, n,
|
|
100
|
-
|
|
102
|
+
} = e.getState(), Ht = (t, n, g, S, y) => {
|
|
103
|
+
g?.log && console.log(
|
|
101
104
|
"saving to localstorage",
|
|
102
105
|
n,
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
g.localStorage?.key,
|
|
107
|
+
S
|
|
105
108
|
);
|
|
106
|
-
const I = at(
|
|
107
|
-
if (I &&
|
|
108
|
-
const V = `${
|
|
109
|
+
const I = at(g?.localStorage?.key) ? g.localStorage?.key(t) : g?.localStorage?.key;
|
|
110
|
+
if (I && S) {
|
|
111
|
+
const V = `${S}-${n}-${I}`;
|
|
109
112
|
let u;
|
|
110
113
|
try {
|
|
111
|
-
u =
|
|
114
|
+
u = gt(V)?.lastSyncedWithServer;
|
|
112
115
|
} catch {
|
|
113
116
|
}
|
|
114
117
|
const f = e.getState().getShadowMetadata(n, []), A = {
|
|
@@ -123,7 +126,7 @@ const {
|
|
|
123
126
|
JSON.stringify(w.json)
|
|
124
127
|
);
|
|
125
128
|
}
|
|
126
|
-
},
|
|
129
|
+
}, gt = (t) => {
|
|
127
130
|
if (!t) return null;
|
|
128
131
|
try {
|
|
129
132
|
const n = window.localStorage.getItem(t);
|
|
@@ -132,10 +135,10 @@ const {
|
|
|
132
135
|
return console.error("Error loading from localStorage:", n), null;
|
|
133
136
|
}
|
|
134
137
|
}, xt = (t, n) => {
|
|
135
|
-
const
|
|
136
|
-
if (y &&
|
|
137
|
-
const I =
|
|
138
|
-
`${
|
|
138
|
+
const g = e.getState().getShadowValue(t), { sessionId: S } = Pt(), y = at(n?.localStorage?.key) ? n.localStorage.key(g) : n?.localStorage?.key;
|
|
139
|
+
if (y && S) {
|
|
140
|
+
const I = gt(
|
|
141
|
+
`${S}-${t}-${y}`
|
|
139
142
|
);
|
|
140
143
|
if (I && I.lastUpdated > (I.lastSyncedWithServer || 0))
|
|
141
144
|
return it(t), !0;
|
|
@@ -144,48 +147,48 @@ const {
|
|
|
144
147
|
}, it = (t) => {
|
|
145
148
|
const n = e.getState().getShadowMetadata(t, []);
|
|
146
149
|
if (!n) return;
|
|
147
|
-
const
|
|
148
|
-
n?.components?.forEach((
|
|
149
|
-
(
|
|
150
|
+
const g = /* @__PURE__ */ new Set();
|
|
151
|
+
n?.components?.forEach((S) => {
|
|
152
|
+
(S ? Array.isArray(S.reactiveType) ? S.reactiveType : [S.reactiveType || "component"] : null)?.includes("none") || g.add(() => S.forceUpdate());
|
|
150
153
|
}), queueMicrotask(() => {
|
|
151
|
-
|
|
154
|
+
g.forEach((S) => S());
|
|
152
155
|
});
|
|
153
156
|
}, ue = (t, n) => {
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
156
|
-
const
|
|
157
|
+
const g = e.getState().getShadowMetadata(t, []);
|
|
158
|
+
if (g) {
|
|
159
|
+
const S = `${t}////${n}`, y = g?.components?.get(S);
|
|
157
160
|
if ((y ? Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"] : null)?.includes("none"))
|
|
158
161
|
return;
|
|
159
162
|
y && y.forceUpdate();
|
|
160
163
|
}
|
|
161
164
|
};
|
|
162
|
-
function wt(t, n,
|
|
165
|
+
function wt(t, n, g, S) {
|
|
163
166
|
const y = e.getState(), I = y.getShadowMetadata(t, n);
|
|
164
167
|
if (y.setShadowMetadata(t, n, {
|
|
165
168
|
...I,
|
|
166
169
|
isDirty: !1,
|
|
167
170
|
stateSource: "server",
|
|
168
|
-
lastServerSync:
|
|
169
|
-
}), Array.isArray(
|
|
171
|
+
lastServerSync: S || Date.now()
|
|
172
|
+
}), Array.isArray(g)) {
|
|
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 =
|
|
175
|
+
const A = u.split(".").slice(1), w = g[f];
|
|
173
176
|
w !== void 0 && wt(
|
|
174
177
|
t,
|
|
175
178
|
A,
|
|
176
179
|
w,
|
|
177
|
-
|
|
180
|
+
S
|
|
178
181
|
);
|
|
179
182
|
});
|
|
180
|
-
} else
|
|
181
|
-
const u = [...n, V], f =
|
|
182
|
-
wt(t, u, f,
|
|
183
|
+
} else g && typeof g == "object" && g.constructor === Object && Object.keys(g).forEach((V) => {
|
|
184
|
+
const u = [...n, V], f = g[V];
|
|
185
|
+
wt(t, u, f, S);
|
|
183
186
|
});
|
|
184
187
|
}
|
|
185
188
|
function zt(t, {
|
|
186
189
|
stateKey: n,
|
|
187
|
-
localStorage:
|
|
188
|
-
formElements:
|
|
190
|
+
localStorage: g,
|
|
191
|
+
formElements: S,
|
|
189
192
|
reactiveDeps: y,
|
|
190
193
|
reactiveType: I,
|
|
191
194
|
componentId: V,
|
|
@@ -218,7 +221,7 @@ function zt(t, {
|
|
|
218
221
|
timestamp: a.serverState.timestamp || Date.now()
|
|
219
222
|
};
|
|
220
223
|
if (a?.localStorage?.key && M) {
|
|
221
|
-
const p = at(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key, E =
|
|
224
|
+
const p = at(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key, E = gt(
|
|
222
225
|
`${M}-${c}-${p}`
|
|
223
226
|
);
|
|
224
227
|
if (E && E.lastUpdated > (a?.serverState?.timestamp || 0))
|
|
@@ -308,9 +311,9 @@ function zt(t, {
|
|
|
308
311
|
}
|
|
309
312
|
}, [c, ...A || []]), dt(() => {
|
|
310
313
|
z && yt(c, {
|
|
311
|
-
formElements:
|
|
314
|
+
formElements: S,
|
|
312
315
|
defaultState: u,
|
|
313
|
-
localStorage:
|
|
316
|
+
localStorage: g,
|
|
314
317
|
middleware: W.current?.middleware
|
|
315
318
|
});
|
|
316
319
|
const o = `${c}////${H.current}`, r = e.getState().getShadowMetadata(c, []), a = r?.components || /* @__PURE__ */ new Map();
|
|
@@ -557,7 +560,7 @@ function zt(t, {
|
|
|
557
560
|
}), x;
|
|
558
561
|
};
|
|
559
562
|
e.getState().initialStateGlobal[c] || _t(c, t);
|
|
560
|
-
const X =
|
|
563
|
+
const X = St(() => Dt(
|
|
561
564
|
c,
|
|
562
565
|
Q,
|
|
563
566
|
H.current,
|
|
@@ -573,41 +576,41 @@ function Bt(t) {
|
|
|
573
576
|
)
|
|
574
577
|
).join("");
|
|
575
578
|
}
|
|
576
|
-
const It = (t, n,
|
|
577
|
-
let
|
|
578
|
-
if (!
|
|
579
|
-
return
|
|
580
|
-
let y =
|
|
579
|
+
const It = (t, n, g) => {
|
|
580
|
+
let S = e.getState().getShadowMetadata(t, n)?.arrayKeys || [];
|
|
581
|
+
if (!g || g.length === 0)
|
|
582
|
+
return S;
|
|
583
|
+
let y = S.map((I) => ({
|
|
581
584
|
key: I,
|
|
582
585
|
value: e.getState().getShadowValue(I)
|
|
583
586
|
}));
|
|
584
|
-
for (const I of
|
|
587
|
+
for (const I of g)
|
|
585
588
|
I.type === "filter" ? y = y.filter(
|
|
586
589
|
({ value: V }, u) => I.fn(V, u)
|
|
587
590
|
) : I.type === "sort" && y.sort((V, u) => I.fn(V.value, u.value));
|
|
588
591
|
return y.map(({ key: I }) => I);
|
|
589
|
-
}, Et = (t, n,
|
|
590
|
-
const
|
|
591
|
-
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t,
|
|
592
|
-
}, ft = (t, n,
|
|
593
|
-
const
|
|
592
|
+
}, Et = (t, n, g) => {
|
|
593
|
+
const S = `${t}////${n}`, { addPathComponent: y, getShadowMetadata: I } = e.getState(), u = I(t, [])?.components?.get(S);
|
|
594
|
+
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t, g, S);
|
|
595
|
+
}, ft = (t, n, g) => {
|
|
596
|
+
const S = e.getState(), y = S.getShadowMetadata(t, []), I = /* @__PURE__ */ new Set();
|
|
594
597
|
y?.components && y.components.forEach((u, f) => {
|
|
595
598
|
(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), I.add(f));
|
|
596
|
-
}),
|
|
599
|
+
}), S.getShadowMetadata(t, [...n, "getSelected"])?.pathComponents?.forEach((u) => {
|
|
597
600
|
y?.components?.get(u)?.forceUpdate();
|
|
598
601
|
});
|
|
599
|
-
const V =
|
|
602
|
+
const V = S.getShadowMetadata(t, n);
|
|
600
603
|
for (let u of V?.arrayKeys || []) {
|
|
601
|
-
const f = u + ".selected", A =
|
|
604
|
+
const f = u + ".selected", A = S.getShadowMetadata(
|
|
602
605
|
t,
|
|
603
606
|
f.split(".").slice(1)
|
|
604
607
|
);
|
|
605
|
-
u ==
|
|
608
|
+
u == g && A?.pathComponents?.forEach((w) => {
|
|
606
609
|
y?.components?.get(w)?.forceUpdate();
|
|
607
610
|
});
|
|
608
611
|
}
|
|
609
612
|
};
|
|
610
|
-
function Dt(t, n,
|
|
613
|
+
function Dt(t, n, g, S) {
|
|
611
614
|
const y = /* @__PURE__ */ new Map();
|
|
612
615
|
let I = 0;
|
|
613
616
|
const V = (w) => {
|
|
@@ -676,7 +679,7 @@ function Dt(t, n, S, g) {
|
|
|
676
679
|
}
|
|
677
680
|
if (m === "removeStorage")
|
|
678
681
|
return () => {
|
|
679
|
-
const s = e.getState().initialStateGlobal[t], o = nt(t), r = at(o?.localStorage?.key) ? o.localStorage.key(s) : o?.localStorage?.key, a = `${
|
|
682
|
+
const s = e.getState().initialStateGlobal[t], o = nt(t), r = at(o?.localStorage?.key) ? o.localStorage.key(s) : o?.localStorage?.key, a = `${S}-${t}-${r}`;
|
|
680
683
|
a && localStorage.removeItem(a);
|
|
681
684
|
};
|
|
682
685
|
if (m === "showValidationErrors")
|
|
@@ -744,7 +747,7 @@ function Dt(t, n, S, g) {
|
|
|
744
747
|
behavior: C.current ? "instant" : "smooth"
|
|
745
748
|
});
|
|
746
749
|
}, [_, a]);
|
|
747
|
-
const N = e.getState().getShadowMetadata(t, i)?.arrayKeys || [], { totalHeight: j, itemOffsets: b } =
|
|
750
|
+
const N = e.getState().getShadowMetadata(t, i)?.arrayKeys || [], { totalHeight: j, itemOffsets: b } = St(() => {
|
|
748
751
|
let v = 0;
|
|
749
752
|
const T = /* @__PURE__ */ new Map();
|
|
750
753
|
return (e.getState().getShadowMetadata(t, i)?.arrayKeys || []).forEach((D) => {
|
|
@@ -867,7 +870,7 @@ function Dt(t, n, S, g) {
|
|
|
867
870
|
clearTimeout($), R.disconnect(), v.removeEventListener("load", L, !0);
|
|
868
871
|
};
|
|
869
872
|
}, [a, N.length, P]), {
|
|
870
|
-
virtualState:
|
|
873
|
+
virtualState: St(() => {
|
|
871
874
|
const v = e.getState(), T = v.getShadowValue(
|
|
872
875
|
[t, ...i].join(".")
|
|
873
876
|
), $ = v.getShadowMetadata(t, i)?.arrayKeys || [], D = T.slice(
|
|
@@ -1079,7 +1082,7 @@ function Dt(t, n, S, g) {
|
|
|
1079
1082
|
};
|
|
1080
1083
|
if (m === "stateList")
|
|
1081
1084
|
return (s) => /* @__PURE__ */ ot(() => {
|
|
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 } =
|
|
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 } = St(() => {
|
|
1083
1086
|
const U = e.getState().getShadowMetadata(t, i)?.transformCaches?.get(a);
|
|
1084
1087
|
let C;
|
|
1085
1088
|
U && U.validIds ? C = U.validIds : (C = It(
|
|
@@ -1317,7 +1320,7 @@ function Dt(t, n, S, g) {
|
|
|
1317
1320
|
return e.getState().getSyncInfo(s);
|
|
1318
1321
|
}
|
|
1319
1322
|
if (m == "getLocalStorage")
|
|
1320
|
-
return (s) =>
|
|
1323
|
+
return (s) => gt(S + "-" + t + "-" + s);
|
|
1321
1324
|
if (m === "isSelected") {
|
|
1322
1325
|
const s = [t, ...i].slice(0, -1);
|
|
1323
1326
|
if (ft(t, i, void 0), Array.isArray(
|
|
@@ -1512,9 +1515,9 @@ function Dt(t, n, S, g) {
|
|
|
1512
1515
|
e.getState().clearSelectedIndexesForState(t), y.clear(), I++, e.getState().initializeShadowState(t, M), u({
|
|
1513
1516
|
currentState: M,
|
|
1514
1517
|
path: [],
|
|
1515
|
-
componentId:
|
|
1518
|
+
componentId: g
|
|
1516
1519
|
});
|
|
1517
|
-
const z = nt(t), c = at(z?.localStorage?.key) ? z?.localStorage?.key(M) : z?.localStorage?.key, B = `${
|
|
1520
|
+
const z = nt(t), c = at(z?.localStorage?.key) ? z?.localStorage?.key(M) : z?.localStorage?.key, B = `${S}-${t}-${c}`;
|
|
1518
1521
|
B && localStorage.removeItem(B);
|
|
1519
1522
|
const J = e.getState().getShadowMetadata(t, []);
|
|
1520
1523
|
return J && J?.components?.forEach((H) => {
|
|
@@ -1526,9 +1529,9 @@ function Dt(t, n, S, g) {
|
|
|
1526
1529
|
const i = Dt(
|
|
1527
1530
|
t,
|
|
1528
1531
|
n,
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
), h = e.getState().initialStateGlobal[t], M = nt(t), z = at(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, c = `${
|
|
1532
|
+
g,
|
|
1533
|
+
S
|
|
1534
|
+
), h = e.getState().initialStateGlobal[t], M = nt(t), z = at(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, c = `${S}-${t}-${z}`;
|
|
1532
1535
|
return localStorage.getItem(c) && localStorage.removeItem(c), Rt(() => {
|
|
1533
1536
|
_t(t, w), e.getState().initializeShadowState(t, w);
|
|
1534
1537
|
const B = e.getState().getShadowMetadata(t, []);
|
|
@@ -1542,7 +1545,7 @@ function Dt(t, n, S, g) {
|
|
|
1542
1545
|
};
|
|
1543
1546
|
return u({
|
|
1544
1547
|
currentState: e.getState().getShadowValue(t, []),
|
|
1545
|
-
componentId:
|
|
1548
|
+
componentId: g,
|
|
1546
1549
|
path: []
|
|
1547
1550
|
});
|
|
1548
1551
|
}
|
|
@@ -1553,19 +1556,19 @@ function qt({
|
|
|
1553
1556
|
proxy: t,
|
|
1554
1557
|
rebuildStateShape: n
|
|
1555
1558
|
}) {
|
|
1556
|
-
const
|
|
1559
|
+
const g = q(null), S = q(`map-${crypto.randomUUID()}`), y = q(!1), I = q(/* @__PURE__ */ new Map());
|
|
1557
1560
|
Z(() => {
|
|
1558
|
-
const u =
|
|
1561
|
+
const u = g.current;
|
|
1559
1562
|
if (!u || y.current) return;
|
|
1560
1563
|
const f = setTimeout(() => {
|
|
1561
1564
|
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, w = A.mapWrappers || [];
|
|
1562
1565
|
w.push({
|
|
1563
|
-
instanceId:
|
|
1566
|
+
instanceId: S.current,
|
|
1564
1567
|
mapFn: t._mapFn,
|
|
1565
1568
|
containerRef: u,
|
|
1566
1569
|
rebuildStateShape: n,
|
|
1567
1570
|
path: t._path,
|
|
1568
|
-
componentId:
|
|
1571
|
+
componentId: S.current,
|
|
1569
1572
|
meta: t._meta
|
|
1570
1573
|
}), e.getState().setShadowMetadata(t._stateKey, t._path, {
|
|
1571
1574
|
...A,
|
|
@@ -1573,17 +1576,17 @@ function qt({
|
|
|
1573
1576
|
}), y.current = !0, V();
|
|
1574
1577
|
}, 0);
|
|
1575
1578
|
return () => {
|
|
1576
|
-
if (clearTimeout(f),
|
|
1579
|
+
if (clearTimeout(f), S.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 !==
|
|
1582
|
+
(w) => w.instanceId !== S.current
|
|
1580
1583
|
), e.getState().setShadowMetadata(t._stateKey, t._path, A));
|
|
1581
1584
|
}
|
|
1582
1585
|
I.current.forEach((A) => A.unmount());
|
|
1583
1586
|
};
|
|
1584
1587
|
}, []);
|
|
1585
1588
|
const V = () => {
|
|
1586
|
-
const u =
|
|
1589
|
+
const u = g.current;
|
|
1587
1590
|
if (!u) return;
|
|
1588
1591
|
const f = e.getState().getShadowValue(
|
|
1589
1592
|
[t._stateKey, ...t._path].join("."),
|
|
@@ -1593,7 +1596,7 @@ function qt({
|
|
|
1593
1596
|
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], w = n({
|
|
1594
1597
|
currentState: f,
|
|
1595
1598
|
path: t._path,
|
|
1596
|
-
componentId:
|
|
1599
|
+
componentId: S.current,
|
|
1597
1600
|
meta: t._meta
|
|
1598
1601
|
});
|
|
1599
1602
|
f.forEach((i, h) => {
|
|
@@ -1617,18 +1620,18 @@ function qt({
|
|
|
1617
1620
|
);
|
|
1618
1621
|
});
|
|
1619
1622
|
};
|
|
1620
|
-
return /* @__PURE__ */ ot("div", { ref:
|
|
1623
|
+
return /* @__PURE__ */ ot("div", { ref: g, "data-map-container": S.current });
|
|
1621
1624
|
}
|
|
1622
1625
|
function Gt({
|
|
1623
1626
|
proxy: t
|
|
1624
1627
|
}) {
|
|
1625
|
-
const n = q(null),
|
|
1628
|
+
const n = q(null), g = q(null), S = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, I = e.getState().getShadowValue(
|
|
1626
1629
|
[t._stateKey, ...t._path].join("."),
|
|
1627
1630
|
t._meta?.validIds
|
|
1628
1631
|
);
|
|
1629
1632
|
return Z(() => {
|
|
1630
1633
|
const V = n.current;
|
|
1631
|
-
if (!V ||
|
|
1634
|
+
if (!V || S.current) return;
|
|
1632
1635
|
const u = setTimeout(() => {
|
|
1633
1636
|
if (!V.parentElement) {
|
|
1634
1637
|
console.warn("Parent element not found for signal", y);
|
|
@@ -1636,10 +1639,10 @@ function Gt({
|
|
|
1636
1639
|
}
|
|
1637
1640
|
const f = V.parentElement, w = Array.from(f.childNodes).indexOf(V);
|
|
1638
1641
|
let i = f.getAttribute("data-parent-id");
|
|
1639
|
-
i || (i = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", i)),
|
|
1642
|
+
i || (i = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", i)), g.current = `instance-${crypto.randomUUID()}`;
|
|
1640
1643
|
const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, M = h.signals || [];
|
|
1641
1644
|
M.push({
|
|
1642
|
-
instanceId:
|
|
1645
|
+
instanceId: g.current,
|
|
1643
1646
|
parentId: i,
|
|
1644
1647
|
position: w,
|
|
1645
1648
|
effect: t._effect
|
|
@@ -1659,13 +1662,13 @@ function Gt({
|
|
|
1659
1662
|
}
|
|
1660
1663
|
z !== null && typeof z == "object" && (z = JSON.stringify(z));
|
|
1661
1664
|
const c = document.createTextNode(String(z ?? ""));
|
|
1662
|
-
V.replaceWith(c),
|
|
1665
|
+
V.replaceWith(c), S.current = !0;
|
|
1663
1666
|
}, 0);
|
|
1664
1667
|
return () => {
|
|
1665
|
-
if (clearTimeout(u),
|
|
1668
|
+
if (clearTimeout(u), g.current) {
|
|
1666
1669
|
const f = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
|
|
1667
1670
|
f.signals && (f.signals = f.signals.filter(
|
|
1668
|
-
(A) => A.instanceId !==
|
|
1671
|
+
(A) => A.instanceId !== g.current
|
|
1669
1672
|
), e.getState().setShadowMetadata(t._stateKey, t._path, f));
|
|
1670
1673
|
}
|
|
1671
1674
|
};
|
|
@@ -1679,25 +1682,25 @@ const Mt = Ot(
|
|
|
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) => {
|
|
1682
|
-
const [n,
|
|
1685
|
+
const [n, g] = K(!1);
|
|
1683
1686
|
return dt(() => {
|
|
1684
1687
|
if (!t.current) {
|
|
1685
|
-
|
|
1688
|
+
g(!0);
|
|
1686
1689
|
return;
|
|
1687
1690
|
}
|
|
1688
|
-
const
|
|
1689
|
-
if (
|
|
1690
|
-
|
|
1691
|
+
const S = Array.from(t.current.querySelectorAll("img"));
|
|
1692
|
+
if (S.length === 0) {
|
|
1693
|
+
g(!0);
|
|
1691
1694
|
return;
|
|
1692
1695
|
}
|
|
1693
1696
|
let y = 0;
|
|
1694
1697
|
const I = () => {
|
|
1695
|
-
y++, y ===
|
|
1698
|
+
y++, y === S.length && g(!0);
|
|
1696
1699
|
};
|
|
1697
|
-
return
|
|
1700
|
+
return S.forEach((V) => {
|
|
1698
1701
|
V.complete ? I() : (V.addEventListener("load", I), V.addEventListener("error", I));
|
|
1699
1702
|
}), () => {
|
|
1700
|
-
|
|
1703
|
+
S.forEach((V) => {
|
|
1701
1704
|
V.removeEventListener("load", I), V.removeEventListener("error", I);
|
|
1702
1705
|
});
|
|
1703
1706
|
};
|
|
@@ -1706,13 +1709,13 @@ const Mt = Ot(
|
|
|
1706
1709
|
function Yt({
|
|
1707
1710
|
stateKey: t,
|
|
1708
1711
|
itemComponentId: n,
|
|
1709
|
-
itemPath:
|
|
1710
|
-
localIndex:
|
|
1712
|
+
itemPath: g,
|
|
1713
|
+
localIndex: S,
|
|
1711
1714
|
arraySetter: y,
|
|
1712
1715
|
rebuildStateShape: I,
|
|
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, ...
|
|
1718
|
+
const [, u] = K({}), { ref: f, inView: A } = jt(), w = q(null), i = Jt(w), h = q(!1), M = [t, ...g].join(".");
|
|
1716
1719
|
$t(t, n, u);
|
|
1717
1720
|
const z = ct(
|
|
1718
1721
|
(W) => {
|
|
@@ -1731,35 +1734,35 @@ function Yt({
|
|
|
1731
1734
|
if (W && W.offsetHeight > 0) {
|
|
1732
1735
|
h.current = !0;
|
|
1733
1736
|
const m = W.offsetHeight;
|
|
1734
|
-
e.getState().setShadowMetadata(t,
|
|
1737
|
+
e.getState().setShadowMetadata(t, g, {
|
|
1735
1738
|
virtualizer: {
|
|
1736
1739
|
itemHeight: m,
|
|
1737
1740
|
domRef: W
|
|
1738
1741
|
}
|
|
1739
1742
|
});
|
|
1740
|
-
const Y =
|
|
1743
|
+
const Y = g.slice(0, -1), Q = [t, ...Y].join(".");
|
|
1741
1744
|
e.getState().notifyPathSubscribers(Q, {
|
|
1742
1745
|
type: "ITEMHEIGHT",
|
|
1743
|
-
itemKey:
|
|
1746
|
+
itemKey: g.join("."),
|
|
1744
1747
|
ref: w.current
|
|
1745
1748
|
});
|
|
1746
1749
|
}
|
|
1747
|
-
}, [A, i, t,
|
|
1748
|
-
const c = [t, ...
|
|
1750
|
+
}, [A, i, t, g]);
|
|
1751
|
+
const c = [t, ...g].join("."), B = e.getState().getShadowValue(c);
|
|
1749
1752
|
if (B === void 0)
|
|
1750
1753
|
return null;
|
|
1751
1754
|
const J = I({
|
|
1752
1755
|
currentState: B,
|
|
1753
|
-
path:
|
|
1756
|
+
path: g,
|
|
1754
1757
|
componentId: n
|
|
1755
|
-
}), H = V(J,
|
|
1758
|
+
}), H = V(J, S, y);
|
|
1756
1759
|
return /* @__PURE__ */ ot("div", { ref: z, children: H });
|
|
1757
1760
|
}
|
|
1758
1761
|
function Zt({
|
|
1759
1762
|
stateKey: t,
|
|
1760
1763
|
path: n,
|
|
1761
|
-
rebuildStateShape:
|
|
1762
|
-
renderFn:
|
|
1764
|
+
rebuildStateShape: g,
|
|
1765
|
+
renderFn: S,
|
|
1763
1766
|
formOpts: y,
|
|
1764
1767
|
setState: I
|
|
1765
1768
|
}) {
|
|
@@ -1874,7 +1877,7 @@ function Zt({
|
|
|
1874
1877
|
});
|
|
1875
1878
|
}
|
|
1876
1879
|
u({});
|
|
1877
|
-
}, [t, n, w, I]), B =
|
|
1880
|
+
}, [t, n, w, I]), B = g({
|
|
1878
1881
|
currentState: A,
|
|
1879
1882
|
path: n,
|
|
1880
1883
|
componentId: V
|
|
@@ -1891,20 +1894,20 @@ function Zt({
|
|
|
1891
1894
|
} : H[W];
|
|
1892
1895
|
}
|
|
1893
1896
|
});
|
|
1894
|
-
return /* @__PURE__ */ ot(kt, { formOpts: y, path: n, stateKey: t, children:
|
|
1897
|
+
return /* @__PURE__ */ ot(kt, { formOpts: y, path: n, stateKey: t, children: S(J) });
|
|
1895
1898
|
}
|
|
1896
|
-
function $t(t, n,
|
|
1897
|
-
const
|
|
1899
|
+
function $t(t, n, g) {
|
|
1900
|
+
const S = `${t}////${n}`;
|
|
1898
1901
|
dt(() => {
|
|
1899
1902
|
const { registerComponent: y, unregisterComponent: I } = e.getState();
|
|
1900
|
-
return y(t,
|
|
1901
|
-
forceUpdate: () =>
|
|
1903
|
+
return y(t, S, {
|
|
1904
|
+
forceUpdate: () => g({}),
|
|
1902
1905
|
paths: /* @__PURE__ */ new Set(),
|
|
1903
1906
|
reactiveType: ["component"]
|
|
1904
1907
|
}), () => {
|
|
1905
|
-
I(t,
|
|
1908
|
+
I(t, S);
|
|
1906
1909
|
};
|
|
1907
|
-
}, [t,
|
|
1910
|
+
}, [t, S]);
|
|
1908
1911
|
}
|
|
1909
1912
|
export {
|
|
1910
1913
|
bt as $cogsSignal,
|