@epoch32/visage 1.3.0 → 1.3.1
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/api/index.js +4 -4
- package/dist/charts/index.js +5 -5
- package/dist/devtools/index.js +7 -7
- package/dist/dom/index.js +3 -3
- package/dist/form/index.js +2 -2
- package/dist/{index-grhdtcb5.js → index-0qat98zs.js} +3 -3
- package/dist/{index-h6tjqk6e.js → index-1jcd8gjf.js} +28 -17
- package/dist/{index-6kfe1nr4.js → index-1yhbg34h.js} +41 -9
- package/dist/{index-9fvarkrx.js → index-3y73zgbk.js} +1 -1
- package/dist/{index-y9bq7h9g.js → index-5jhzwtdz.js} +2 -2
- package/dist/{index-a4xns6cc.js → index-65j7a9et.js} +1 -1
- package/dist/{index-dyvgtp43.js → index-9bez1tmf.js} +2 -2
- package/dist/{index-dvq5f3s8.js → index-aagpn02x.js} +4 -4
- package/dist/{index-df5e614s.js → index-awcrz19g.js} +1 -1
- package/dist/{index-8x8xz80v.js → index-b7emqmej.js} +3 -3
- package/dist/{index-061jf06a.js → index-cgepvvd4.js} +1 -1
- package/dist/{index-1xtrtz1t.js → index-dmhmde2z.js} +2 -2
- package/dist/{index-0madxn60.js → index-enc8cmea.js} +1 -1
- package/dist/{index-js199er4.js → index-g1drdx7k.js} +12 -1
- package/dist/{index-zr6cvset.js → index-ptj8rt6b.js} +5 -5
- package/dist/{index-8czhpea8.js → index-x6whpv54.js} +30 -19
- package/dist/{index-5s255b3w.js → index-xby428n5.js} +23 -22
- package/dist/{index-x2rs3vab.js → index-y3nprgn7.js} +1 -1
- package/dist/index.js +18 -18
- package/dist/jsx-runtime/index.js +4 -4
- package/dist/query/index.js +3 -3
- package/dist/router/index.js +5 -5
- package/dist/rpc/index.js +4 -4
- package/dist/server/index.js +2 -2
- package/dist/signals/index.js +1 -1
- package/dist/signals/system.d.ts +2 -0
- package/dist/style/index.js +6 -6
- package/dist/template/index.js +2 -2
- package/dist/ui/index.js +7 -7
- package/dist/virtual/index.js +5 -5
- package/package.json +1 -1
- package/src/dom/control-flow.ts +31 -21
- package/src/form/form.ts +29 -17
- package/src/signals/effect.ts +2 -2
- package/src/signals/scope.ts +10 -8
- package/src/signals/store.ts +32 -1
- package/src/signals/system.ts +8 -0
- package/src/template/template.ts +12 -1
- package/src/virtual/virtualizer.ts +31 -18
|
@@ -7,12 +7,13 @@ import {
|
|
|
7
7
|
runInScope2,
|
|
8
8
|
getActiveScope2,
|
|
9
9
|
useContext2,
|
|
10
|
-
effect2
|
|
11
|
-
|
|
10
|
+
effect2,
|
|
11
|
+
signal2
|
|
12
|
+
} from "./index-1yhbg34h.js";
|
|
12
13
|
import {
|
|
13
14
|
SuspenseContext2,
|
|
14
15
|
createResource2
|
|
15
|
-
} from "./index-
|
|
16
|
+
} from "./index-65j7a9et.js";
|
|
16
17
|
|
|
17
18
|
// src/dom/lazy.ts
|
|
18
19
|
function lazy2(importer) {
|
|
@@ -176,26 +177,24 @@ function For2(props) {
|
|
|
176
177
|
const newItems = [];
|
|
177
178
|
const prevMap = new Map;
|
|
178
179
|
for (const rec of items) {
|
|
179
|
-
prevMap.
|
|
180
|
+
const group = prevMap.get(rec.item);
|
|
181
|
+
if (group) {
|
|
182
|
+
group.push(rec);
|
|
183
|
+
} else {
|
|
184
|
+
prevMap.set(rec.item, [rec]);
|
|
185
|
+
}
|
|
180
186
|
}
|
|
181
187
|
for (let i = 0;i < list.length; i++) {
|
|
182
188
|
const item = list[i];
|
|
183
|
-
const
|
|
189
|
+
const existingGroup = prevMap.get(item);
|
|
190
|
+
const existing = existingGroup && existingGroup.length > 0 ? existingGroup.shift() : undefined;
|
|
184
191
|
if (existing) {
|
|
185
|
-
|
|
192
|
+
untrack2(() => {
|
|
193
|
+
existing.indexSignal.set(i);
|
|
194
|
+
});
|
|
186
195
|
newItems.push(existing);
|
|
187
|
-
prevMap.delete(item);
|
|
188
196
|
} else {
|
|
189
|
-
|
|
190
|
-
const indexSubscribers = new Set;
|
|
191
|
-
const indexSignal = (...args) => {
|
|
192
|
-
if (args.length > 0 && args[0] !== undefined && args[0] !== indexVal) {
|
|
193
|
-
indexVal = args[0];
|
|
194
|
-
for (const sub of Array.from(indexSubscribers))
|
|
195
|
-
sub();
|
|
196
|
-
}
|
|
197
|
-
return indexVal;
|
|
198
|
-
};
|
|
197
|
+
const indexSignal = signal2(i, { internal: true });
|
|
199
198
|
const itemScope = new Scope2(getActiveScope2());
|
|
200
199
|
let itemNodes = [];
|
|
201
200
|
untrack2(() => {
|
|
@@ -214,11 +213,13 @@ function For2(props) {
|
|
|
214
213
|
});
|
|
215
214
|
}
|
|
216
215
|
}
|
|
217
|
-
for (const [,
|
|
218
|
-
removed
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
node.parentNode
|
|
216
|
+
for (const [, remainingGroup] of prevMap) {
|
|
217
|
+
for (const removed of remainingGroup) {
|
|
218
|
+
removed.scope.dispose();
|
|
219
|
+
for (const node of removed.nodes) {
|
|
220
|
+
if (node.parentNode)
|
|
221
|
+
node.parentNode.removeChild(node);
|
|
222
|
+
}
|
|
222
223
|
}
|
|
223
224
|
}
|
|
224
225
|
if (marker.parentNode) {
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
createStore2,
|
|
41
41
|
mutateStore2,
|
|
42
42
|
unwrapStore2
|
|
43
|
-
} from "./index-
|
|
43
|
+
} from "./index-1yhbg34h.js";
|
|
44
44
|
import {
|
|
45
45
|
createApiClient2,
|
|
46
46
|
buildFileRouter2,
|
|
@@ -49,24 +49,24 @@ import {
|
|
|
49
49
|
defineMiddleware2,
|
|
50
50
|
ProcedureBuilder2,
|
|
51
51
|
procedure2
|
|
52
|
-
} from "./index-
|
|
52
|
+
} from "./index-cgepvvd4.js";
|
|
53
53
|
import {
|
|
54
54
|
lazy2,
|
|
55
55
|
Show2,
|
|
56
56
|
For2,
|
|
57
57
|
Portal2
|
|
58
|
-
} from "./index-
|
|
59
|
-
import"./index-
|
|
58
|
+
} from "./index-xby428n5.js";
|
|
59
|
+
import"./index-3y73zgbk.js";
|
|
60
60
|
import {
|
|
61
61
|
DevToolsHub2,
|
|
62
62
|
devtoolsHub2,
|
|
63
63
|
highlightElement2,
|
|
64
64
|
VisageDevTools2,
|
|
65
65
|
connectDevTools2
|
|
66
|
-
} from "./index-
|
|
66
|
+
} from "./index-ptj8rt6b.js";
|
|
67
67
|
import {
|
|
68
68
|
createForm2
|
|
69
|
-
} from "./index-
|
|
69
|
+
} from "./index-1jcd8gjf.js";
|
|
70
70
|
import"./index-921pn75b.js";
|
|
71
71
|
import {
|
|
72
72
|
Router2,
|
|
@@ -77,7 +77,7 @@ import {
|
|
|
77
77
|
useNavigate2,
|
|
78
78
|
useParams2,
|
|
79
79
|
useSearchParams2
|
|
80
|
-
} from "./index-
|
|
80
|
+
} from "./index-0qat98zs.js";
|
|
81
81
|
import {
|
|
82
82
|
createClient2,
|
|
83
83
|
RouterImpl2,
|
|
@@ -85,17 +85,17 @@ import {
|
|
|
85
85
|
query3,
|
|
86
86
|
mutation3,
|
|
87
87
|
subscription3
|
|
88
|
-
} from "./index-
|
|
88
|
+
} from "./index-awcrz19g.js";
|
|
89
89
|
import {
|
|
90
90
|
hydrate2,
|
|
91
91
|
renderChildToString2,
|
|
92
92
|
renderToString2,
|
|
93
93
|
renderToStream2
|
|
94
|
-
} from "./index-
|
|
94
|
+
} from "./index-y3nprgn7.js";
|
|
95
95
|
import {
|
|
96
96
|
template2,
|
|
97
97
|
html2
|
|
98
|
-
} from "./index-
|
|
98
|
+
} from "./index-g1drdx7k.js";
|
|
99
99
|
import {
|
|
100
100
|
useAccordionContext2,
|
|
101
101
|
useAccordionItemContext2,
|
|
@@ -152,12 +152,12 @@ import {
|
|
|
152
152
|
ToastDescription2,
|
|
153
153
|
ToastClose2,
|
|
154
154
|
Toast2
|
|
155
|
-
} from "./index-
|
|
155
|
+
} from "./index-aagpn02x.js";
|
|
156
156
|
import {
|
|
157
157
|
createVirtualizer2,
|
|
158
158
|
VirtualList2,
|
|
159
159
|
VirtualGrid2
|
|
160
|
-
} from "./index-
|
|
160
|
+
} from "./index-x6whpv54.js";
|
|
161
161
|
import {
|
|
162
162
|
ChartContext2,
|
|
163
163
|
useChartContext2,
|
|
@@ -179,7 +179,7 @@ import {
|
|
|
179
179
|
Line2,
|
|
180
180
|
Pie2,
|
|
181
181
|
ChartTooltip2
|
|
182
|
-
} from "./index-
|
|
182
|
+
} from "./index-9bez1tmf.js";
|
|
183
183
|
import {
|
|
184
184
|
createId2,
|
|
185
185
|
createControllableSignal2,
|
|
@@ -198,7 +198,7 @@ import {
|
|
|
198
198
|
Tooltip3,
|
|
199
199
|
SwitchThumb2,
|
|
200
200
|
Switch2
|
|
201
|
-
} from "./index-
|
|
201
|
+
} from "./index-b7emqmej.js";
|
|
202
202
|
import {
|
|
203
203
|
ERROR_CODE_TO_STATUS2,
|
|
204
204
|
STATUS_TO_ERROR_CODE2,
|
|
@@ -228,7 +228,7 @@ import {
|
|
|
228
228
|
createMutation2,
|
|
229
229
|
createQuery2,
|
|
230
230
|
createInfiniteQuery2
|
|
231
|
-
} from "./index-
|
|
231
|
+
} from "./index-5jhzwtdz.js";
|
|
232
232
|
import {
|
|
233
233
|
hashString2,
|
|
234
234
|
getScopeId2,
|
|
@@ -241,19 +241,19 @@ import {
|
|
|
241
241
|
css2,
|
|
242
242
|
useStyle2,
|
|
243
243
|
Style2
|
|
244
|
-
} from "./index-
|
|
244
|
+
} from "./index-enc8cmea.js";
|
|
245
245
|
import {
|
|
246
246
|
Stack2,
|
|
247
247
|
Row2,
|
|
248
248
|
Center2,
|
|
249
249
|
Grid2,
|
|
250
250
|
Spacer2
|
|
251
|
-
} from "./index-
|
|
251
|
+
} from "./index-dmhmde2z.js";
|
|
252
252
|
import {
|
|
253
253
|
createResource2,
|
|
254
254
|
Suspense2,
|
|
255
255
|
ErrorBoundary2
|
|
256
|
-
} from "./index-
|
|
256
|
+
} from "./index-65j7a9et.js";
|
|
257
257
|
export {
|
|
258
258
|
Accordion2 as Accordion,
|
|
259
259
|
AccordionContent2 as AccordionContent,
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
jsx2,
|
|
4
4
|
jsxs2,
|
|
5
5
|
jsxDEV2
|
|
6
|
-
} from "../index-
|
|
7
|
-
import"../index-
|
|
8
|
-
import"../index-
|
|
9
|
-
import"../index-
|
|
6
|
+
} from "../index-3y73zgbk.js";
|
|
7
|
+
import"../index-xby428n5.js";
|
|
8
|
+
import"../index-65j7a9et.js";
|
|
9
|
+
import"../index-1yhbg34h.js";
|
|
10
10
|
export {
|
|
11
11
|
Fragment2 as Fragment,
|
|
12
12
|
jsx2 as jsx,
|
package/dist/query/index.js
CHANGED
|
@@ -21,9 +21,9 @@ import {
|
|
|
21
21
|
createMutation2,
|
|
22
22
|
createQuery2,
|
|
23
23
|
createInfiniteQuery2
|
|
24
|
-
} from "../index-
|
|
25
|
-
import"../index-
|
|
26
|
-
import"../index-
|
|
24
|
+
} from "../index-5jhzwtdz.js";
|
|
25
|
+
import"../index-65j7a9et.js";
|
|
26
|
+
import"../index-1yhbg34h.js";
|
|
27
27
|
export {
|
|
28
28
|
FocusManager2 as FocusManager,
|
|
29
29
|
Mutation2 as Mutation,
|
package/dist/router/index.js
CHANGED
|
@@ -7,13 +7,13 @@ import {
|
|
|
7
7
|
useNavigate2,
|
|
8
8
|
useParams2,
|
|
9
9
|
useSearchParams2
|
|
10
|
-
} from "../index-
|
|
11
|
-
import"../index-
|
|
10
|
+
} from "../index-0qat98zs.js";
|
|
11
|
+
import"../index-3y73zgbk.js";
|
|
12
12
|
import {
|
|
13
13
|
lazy2
|
|
14
|
-
} from "../index-
|
|
15
|
-
import"../index-
|
|
16
|
-
import"../index-
|
|
14
|
+
} from "../index-xby428n5.js";
|
|
15
|
+
import"../index-65j7a9et.js";
|
|
16
|
+
import"../index-1yhbg34h.js";
|
|
17
17
|
export {
|
|
18
18
|
Link2 as Link,
|
|
19
19
|
Route2 as Route,
|
package/dist/rpc/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
query3,
|
|
6
6
|
mutation3,
|
|
7
7
|
subscription3
|
|
8
|
-
} from "../index-
|
|
8
|
+
} from "../index-awcrz19g.js";
|
|
9
9
|
import {
|
|
10
10
|
ERROR_CODE_TO_STATUS2,
|
|
11
11
|
STATUS_TO_ERROR_CODE2,
|
|
@@ -19,9 +19,9 @@ import {
|
|
|
19
19
|
validateWithSchema2,
|
|
20
20
|
v2
|
|
21
21
|
} from "../index-2zz0g2n2.js";
|
|
22
|
-
import"../index-
|
|
23
|
-
import"../index-
|
|
24
|
-
import"../index-
|
|
22
|
+
import"../index-5jhzwtdz.js";
|
|
23
|
+
import"../index-65j7a9et.js";
|
|
24
|
+
import"../index-1yhbg34h.js";
|
|
25
25
|
export {
|
|
26
26
|
ERROR_CODE_TO_STATUS2 as ERROR_CODE_TO_STATUS,
|
|
27
27
|
RPCError2 as RPCError,
|
package/dist/server/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
renderChildToString2,
|
|
4
4
|
renderToString2,
|
|
5
5
|
renderToStream2
|
|
6
|
-
} from "../index-
|
|
7
|
-
import"../index-
|
|
6
|
+
} from "../index-y3nprgn7.js";
|
|
7
|
+
import"../index-1yhbg34h.js";
|
|
8
8
|
export {
|
|
9
9
|
hydrate2 as hydrate,
|
|
10
10
|
renderChildToString2 as renderChildToString,
|
package/dist/signals/index.js
CHANGED
package/dist/signals/system.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export declare function setCurrentScope(scope: any): void;
|
|
|
14
14
|
export declare function getCurrentScope(): any;
|
|
15
15
|
export declare function addPendingEffect(eff: any): void;
|
|
16
16
|
export declare function removePendingEffect(eff: any): void;
|
|
17
|
+
export declare function getBatchDepth(): number;
|
|
18
|
+
export declare function getIsFlushing(): boolean;
|
|
17
19
|
export declare function flushEffects(): void;
|
|
18
20
|
/**
|
|
19
21
|
* Batch multiple signal mutations so downstreams and effects update synchronously once at completion.
|
package/dist/style/index.js
CHANGED
|
@@ -16,9 +16,9 @@ import {
|
|
|
16
16
|
radius2,
|
|
17
17
|
glass2,
|
|
18
18
|
formatStyleProp2
|
|
19
|
-
} from "../index-
|
|
20
|
-
import"../index-
|
|
21
|
-
import"../index-
|
|
19
|
+
} from "../index-1yhbg34h.js";
|
|
20
|
+
import"../index-xby428n5.js";
|
|
21
|
+
import"../index-3y73zgbk.js";
|
|
22
22
|
import {
|
|
23
23
|
hashString2,
|
|
24
24
|
getScopeId2,
|
|
@@ -32,15 +32,15 @@ import {
|
|
|
32
32
|
css2,
|
|
33
33
|
useStyle2,
|
|
34
34
|
Style2
|
|
35
|
-
} from "../index-
|
|
35
|
+
} from "../index-enc8cmea.js";
|
|
36
36
|
import {
|
|
37
37
|
Stack2,
|
|
38
38
|
Row2,
|
|
39
39
|
Center2,
|
|
40
40
|
Grid2,
|
|
41
41
|
Spacer2
|
|
42
|
-
} from "../index-
|
|
43
|
-
import"../index-
|
|
42
|
+
} from "../index-dmhmde2z.js";
|
|
43
|
+
import"../index-65j7a9et.js";
|
|
44
44
|
export {
|
|
45
45
|
Center2 as Center,
|
|
46
46
|
DIMENSION_KEYWORDS2 as DIMENSION_KEYWORDS,
|
package/dist/template/index.js
CHANGED
package/dist/ui/index.js
CHANGED
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
ToastDescription2,
|
|
55
55
|
ToastClose2,
|
|
56
56
|
Toast2
|
|
57
|
-
} from "../index-
|
|
57
|
+
} from "../index-aagpn02x.js";
|
|
58
58
|
import {
|
|
59
59
|
createId2,
|
|
60
60
|
createControllableSignal2,
|
|
@@ -73,18 +73,18 @@ import {
|
|
|
73
73
|
Tooltip3,
|
|
74
74
|
SwitchThumb2,
|
|
75
75
|
Switch2
|
|
76
|
-
} from "../index-
|
|
76
|
+
} from "../index-b7emqmej.js";
|
|
77
77
|
import {
|
|
78
78
|
Stack2,
|
|
79
79
|
Row2,
|
|
80
80
|
Center2,
|
|
81
81
|
Grid2,
|
|
82
82
|
Spacer2
|
|
83
|
-
} from "../index-
|
|
84
|
-
import"../index-
|
|
85
|
-
import"../index-
|
|
86
|
-
import"../index-
|
|
87
|
-
import"../index-
|
|
83
|
+
} from "../index-dmhmde2z.js";
|
|
84
|
+
import"../index-3y73zgbk.js";
|
|
85
|
+
import"../index-xby428n5.js";
|
|
86
|
+
import"../index-65j7a9et.js";
|
|
87
|
+
import"../index-1yhbg34h.js";
|
|
88
88
|
export {
|
|
89
89
|
Accordion2 as Accordion,
|
|
90
90
|
AccordionContent2 as AccordionContent,
|
package/dist/virtual/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
createVirtualizer2,
|
|
3
3
|
VirtualList2,
|
|
4
4
|
VirtualGrid2
|
|
5
|
-
} from "../index-
|
|
6
|
-
import"../index-
|
|
7
|
-
import"../index-
|
|
8
|
-
import"../index-
|
|
9
|
-
import"../index-
|
|
5
|
+
} from "../index-x6whpv54.js";
|
|
6
|
+
import"../index-3y73zgbk.js";
|
|
7
|
+
import"../index-xby428n5.js";
|
|
8
|
+
import"../index-65j7a9et.js";
|
|
9
|
+
import"../index-1yhbg34h.js";
|
|
10
10
|
export {
|
|
11
11
|
VirtualGrid2 as VirtualGrid,
|
|
12
12
|
VirtualList2 as VirtualList,
|
package/package.json
CHANGED
package/src/dom/control-flow.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
effect,
|
|
3
|
+
getActiveScope,
|
|
4
|
+
onCleanup,
|
|
5
|
+
runInScope,
|
|
6
|
+
Scope,
|
|
7
|
+
signal,
|
|
8
|
+
untrack,
|
|
9
|
+
type WritableSignal
|
|
10
|
+
} from "../signals";
|
|
2
11
|
import { type Child, insertChild, type ReactiveValue, resolveValue } from "./render";
|
|
3
12
|
|
|
4
13
|
export interface ShowProps<T> {
|
|
@@ -120,7 +129,7 @@ interface ItemRecord<T> {
|
|
|
120
129
|
item: T;
|
|
121
130
|
scope: Scope;
|
|
122
131
|
nodes: Node[];
|
|
123
|
-
indexSignal:
|
|
132
|
+
indexSignal: WritableSignal<number>;
|
|
124
133
|
}
|
|
125
134
|
|
|
126
135
|
/**
|
|
@@ -206,32 +215,31 @@ export function For<T>(props: ForProps<T>): any {
|
|
|
206
215
|
if (!parent) return;
|
|
207
216
|
|
|
208
217
|
const newItems: ItemRecord<T>[] = [];
|
|
209
|
-
const prevMap = new Map<T, ItemRecord<T
|
|
218
|
+
const prevMap = new Map<T, ItemRecord<T>[]>();
|
|
210
219
|
|
|
211
220
|
for (const rec of items) {
|
|
212
|
-
prevMap.
|
|
221
|
+
const group = prevMap.get(rec.item);
|
|
222
|
+
if (group) {
|
|
223
|
+
group.push(rec);
|
|
224
|
+
} else {
|
|
225
|
+
prevMap.set(rec.item, [rec]);
|
|
226
|
+
}
|
|
213
227
|
}
|
|
214
228
|
|
|
215
229
|
// Fast-path: map existing or create new item scopes
|
|
216
230
|
for (let i = 0; i < list.length; i++) {
|
|
217
231
|
const item = list[i]!;
|
|
218
|
-
const
|
|
232
|
+
const existingGroup = prevMap.get(item);
|
|
233
|
+
const existing =
|
|
234
|
+
existingGroup && existingGroup.length > 0 ? existingGroup.shift() : undefined;
|
|
219
235
|
|
|
220
236
|
if (existing) {
|
|
221
|
-
|
|
237
|
+
untrack(() => {
|
|
238
|
+
existing.indexSignal.set(i);
|
|
239
|
+
});
|
|
222
240
|
newItems.push(existing);
|
|
223
|
-
prevMap.delete(item);
|
|
224
241
|
} else {
|
|
225
|
-
|
|
226
|
-
const indexSubscribers = new Set<() => void>();
|
|
227
|
-
const indexSignal = (...args: [number?]): number => {
|
|
228
|
-
if (args.length > 0 && args[0] !== undefined && args[0] !== indexVal) {
|
|
229
|
-
indexVal = args[0];
|
|
230
|
-
for (const sub of Array.from(indexSubscribers)) sub();
|
|
231
|
-
}
|
|
232
|
-
return indexVal;
|
|
233
|
-
};
|
|
234
|
-
|
|
242
|
+
const indexSignal = signal(i, { internal: true });
|
|
235
243
|
const itemScope = new Scope(getActiveScope());
|
|
236
244
|
let itemNodes: Node[] = [];
|
|
237
245
|
|
|
@@ -254,10 +262,12 @@ export function For<T>(props: ForProps<T>): any {
|
|
|
254
262
|
}
|
|
255
263
|
|
|
256
264
|
// Clean up removed items
|
|
257
|
-
for (const [,
|
|
258
|
-
removed
|
|
259
|
-
|
|
260
|
-
|
|
265
|
+
for (const [, remainingGroup] of prevMap) {
|
|
266
|
+
for (const removed of remainingGroup) {
|
|
267
|
+
removed.scope.dispose();
|
|
268
|
+
for (const node of removed.nodes) {
|
|
269
|
+
if (node.parentNode) node.parentNode.removeChild(node);
|
|
270
|
+
}
|
|
261
271
|
}
|
|
262
272
|
}
|
|
263
273
|
|
package/src/form/form.ts
CHANGED
|
@@ -54,6 +54,32 @@ export function createForm<T extends Record<string, any> = Record<string, any>>(
|
|
|
54
54
|
const submitCount = signal(0);
|
|
55
55
|
const customErrors = signal<Partial<Record<keyof T, string>>>({});
|
|
56
56
|
|
|
57
|
+
const getValues = (): T => {
|
|
58
|
+
const res: Record<string, any> = {};
|
|
59
|
+
for (const key in fields) {
|
|
60
|
+
res[key] = (fields as any)[key].value();
|
|
61
|
+
}
|
|
62
|
+
return res as T;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const schemaValidation = computed(() => {
|
|
66
|
+
if (!options.schema) {
|
|
67
|
+
return { success: true, issuesMap: new Map<string, string>() };
|
|
68
|
+
}
|
|
69
|
+
const currentValues = getValues();
|
|
70
|
+
const res = validateWithSchema(options.schema, currentValues);
|
|
71
|
+
const issuesMap = new Map<string, string>();
|
|
72
|
+
if (!res.success && res.issues) {
|
|
73
|
+
for (const issue of res.issues) {
|
|
74
|
+
const pathKey = String(issue.path);
|
|
75
|
+
if (!issuesMap.has(pathKey)) {
|
|
76
|
+
issuesMap.set(pathKey, issue.message);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { success: res.success, issuesMap };
|
|
81
|
+
});
|
|
82
|
+
|
|
57
83
|
for (const key in initialValues) {
|
|
58
84
|
const initVal = initialValues[key];
|
|
59
85
|
const valSignal = signal(initVal);
|
|
@@ -74,25 +100,12 @@ export function createForm<T extends Record<string, any> = Record<string, any>>(
|
|
|
74
100
|
|
|
75
101
|
if (!options.schema) return null;
|
|
76
102
|
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
if (!res.success && res.issues) {
|
|
80
|
-
const match = res.issues.find((i) => i.path === key || i.path === `${key}`);
|
|
81
|
-
return match ? match.message : null;
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
103
|
+
const validation = schemaValidation();
|
|
104
|
+
return validation.issuesMap.get(key) ?? validation.issuesMap.get(String(key)) ?? null;
|
|
84
105
|
})
|
|
85
106
|
};
|
|
86
107
|
}
|
|
87
108
|
|
|
88
|
-
const getValues = (): T => {
|
|
89
|
-
const res: Record<string, any> = {};
|
|
90
|
-
for (const key in fields) {
|
|
91
|
-
res[key] = (fields as any)[key].value();
|
|
92
|
-
}
|
|
93
|
-
return res as T;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
109
|
const errors = computed<Partial<Record<keyof T, string>>>(() => {
|
|
97
110
|
const errMap: Partial<Record<keyof T, string>> = {};
|
|
98
111
|
for (const key in fields) {
|
|
@@ -118,8 +131,7 @@ export function createForm<T extends Record<string, any> = Record<string, any>>(
|
|
|
118
131
|
|
|
119
132
|
const validate = (): boolean => {
|
|
120
133
|
if (!options.schema) return true;
|
|
121
|
-
|
|
122
|
-
return res.success;
|
|
134
|
+
return schemaValidation().success;
|
|
123
135
|
};
|
|
124
136
|
|
|
125
137
|
const handleSubmit = async (e?: Event): Promise<boolean> => {
|
package/src/signals/effect.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { Computed } from "./computed";
|
|
|
5
5
|
import type { Scope } from "./scope";
|
|
6
6
|
import {
|
|
7
7
|
addPendingEffect,
|
|
8
|
-
batchDepth,
|
|
9
8
|
flushEffects,
|
|
9
|
+
getBatchDepth,
|
|
10
10
|
getCurrentScope,
|
|
11
11
|
getCurrentSubscriber,
|
|
12
12
|
removePendingEffect,
|
|
@@ -57,7 +57,7 @@ export class Effect implements ISubscriber {
|
|
|
57
57
|
this.state = targetState;
|
|
58
58
|
addPendingEffect(this);
|
|
59
59
|
|
|
60
|
-
if (
|
|
60
|
+
if (getBatchDepth() === 0) {
|
|
61
61
|
flushEffects();
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/signals/scope.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Visage Reactive Scope & Lifecycle Management
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { getCurrentScope, getCurrentSubscriber, setCurrentScope } from "./system";
|
|
5
5
|
import type { CleanupFn, ISubscriber } from "./types";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -14,7 +14,7 @@ export class Scope {
|
|
|
14
14
|
isDisposed = false;
|
|
15
15
|
context?: Map<symbol, any>;
|
|
16
16
|
|
|
17
|
-
constructor(parent: Scope | null =
|
|
17
|
+
constructor(parent: Scope | null = getCurrentScope()) {
|
|
18
18
|
this.parent = parent;
|
|
19
19
|
if (parent && !parent.isDisposed) {
|
|
20
20
|
parent.cleanups.push(() => this.dispose());
|
|
@@ -72,10 +72,12 @@ export class Scope {
|
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
74
|
export function onCleanup(fn: CleanupFn): void {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
const curSub = getCurrentSubscriber();
|
|
76
|
+
const curScope = getCurrentScope();
|
|
77
|
+
if (curSub && "addCleanup" in curSub) {
|
|
78
|
+
(curSub as any).addCleanup(fn);
|
|
79
|
+
} else if (curScope) {
|
|
80
|
+
curScope.addCleanup(fn);
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
|
|
@@ -101,7 +103,7 @@ export function onCleanup(fn: CleanupFn): void {
|
|
|
101
103
|
* @returns The return value of `fn`
|
|
102
104
|
*/
|
|
103
105
|
export function createRoot<T>(fn: (dispose: () => void) => T): T {
|
|
104
|
-
const prevScope =
|
|
106
|
+
const prevScope = getCurrentScope();
|
|
105
107
|
const scope = new Scope(null);
|
|
106
108
|
setCurrentScope(scope);
|
|
107
109
|
try {
|
|
@@ -115,7 +117,7 @@ export function createRoot<T>(fn: (dispose: () => void) => T): T {
|
|
|
115
117
|
* Run a function with a specified reactive scope active.
|
|
116
118
|
*/
|
|
117
119
|
export function runInScope<T>(scope: Scope | null, fn: () => T): T {
|
|
118
|
-
const prevScope =
|
|
120
|
+
const prevScope = getCurrentScope();
|
|
119
121
|
setCurrentScope(scope);
|
|
120
122
|
try {
|
|
121
123
|
return fn();
|