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