virtua 0.50.2 → 0.50.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.
- package/lib/angular/VList.d.ts +7 -7
- package/lib/angular/Virtualizer.d.ts +11 -11
- package/lib/angular/WindowVirtualizer.d.ts +13 -9
- package/lib/angular/index.js +440 -434
- package/lib/angular/index.js.map +1 -1
- package/lib/core/index.cjs +342 -335
- package/lib/core/index.cjs.map +1 -1
- package/lib/core/index.d.ts +5 -2
- package/lib/core/index.js +326 -318
- package/lib/core/index.js.map +1 -1
- package/lib/core/layouts/types.d.ts +1 -0
- package/lib/core/observer.d.ts +1 -0
- package/lib/core/scroll-to.d.ts +1 -0
- package/lib/core/types.d.ts +1 -5
- package/lib/index.cjs +534 -532
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +496 -494
- package/lib/index.js.map +1 -1
- package/lib/solid/VList.d.ts +1 -1
- package/lib/solid/Virtualizer.d.ts +4 -0
- package/lib/solid/WindowVirtualizer.d.ts +4 -0
- package/lib/solid/index.cjs +366 -378
- package/lib/solid/index.cjs.map +1 -1
- package/lib/solid/index.js +373 -386
- package/lib/solid/index.js.map +1 -1
- package/lib/solid/index.jsx +383 -368
- package/lib/solid/index.jsx.map +1 -1
- package/lib/svelte/ListItem.svelte +2 -2
- package/lib/svelte/Virtualizer.svelte +22 -32
- package/lib/svelte/WindowVirtualizer.svelte +22 -21
- package/lib/svelte/WindowVirtualizer.type.d.ts +4 -0
- package/lib/svelte/utils.js.map +1 -1
- package/lib/vue/WindowVirtualizer.d.ts +4 -0
- package/lib/vue/index.cjs +366 -385
- package/lib/vue/index.cjs.map +1 -1
- package/lib/vue/index.js +342 -361
- package/lib/vue/index.js.map +1 -1
- package/package.json +30 -29
- /package/lib/core/{resizer.d.ts → driver.d.ts} +0 -0
- /package/lib/core/{scroller.d.ts → layouts/list.d.ts} +0 -0
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
UPDATE_SCROLL_END_EVENT,
|
|
8
8
|
UPDATE_SCROLL_EVENT,
|
|
9
9
|
UPDATE_VIRTUAL_STATE,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
createContainerDriver,
|
|
11
|
+
scrollTo as _scrollTo,
|
|
12
|
+
scrollBy as _scrollBy,
|
|
13
|
+
scrollToIndex as _scrollToIndex,
|
|
12
14
|
createVirtualStore,
|
|
15
|
+
createListLayout,
|
|
13
16
|
getScrollSize as _getScrollSize,
|
|
14
17
|
sort,
|
|
15
18
|
} from "../core/index.js";
|
|
@@ -42,15 +45,9 @@
|
|
|
42
45
|
onscrollend,
|
|
43
46
|
}: Props = $props();
|
|
44
47
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
ssrCount,
|
|
49
|
-
cache,
|
|
50
|
-
!itemSize,
|
|
51
|
-
);
|
|
52
|
-
const resizer = createResizer(store, horizontal);
|
|
53
|
-
const scroller = createScroller(store, horizontal);
|
|
48
|
+
const layout = createListLayout(data.length, itemSize, cache);
|
|
49
|
+
const store = createVirtualStore(layout, ssrCount);
|
|
50
|
+
const driver = createContainerDriver(store, horizontal);
|
|
54
51
|
store.$subscribe(UPDATE_VIRTUAL_STATE, () => {
|
|
55
52
|
stateVersion = store.$getStateVersion();
|
|
56
53
|
});
|
|
@@ -70,7 +67,7 @@
|
|
|
70
67
|
let range = $derived(stateVersion && store.$getRange(bufferSize));
|
|
71
68
|
let isScrolling = $derived(stateVersion && store.$isScrolling());
|
|
72
69
|
let totalSize = $derived(stateVersion && store.$getTotalSize());
|
|
73
|
-
let negative = $derived(stateVersion &&
|
|
70
|
+
let negative = $derived(stateVersion && driver.$isNegative());
|
|
74
71
|
|
|
75
72
|
let indexes = $derived.by(() => {
|
|
76
73
|
// https://github.com/inokawa/virtua/pull/847
|
|
@@ -107,15 +104,7 @@
|
|
|
107
104
|
tick().then(() => {
|
|
108
105
|
// https://github.com/inokawa/virtua/pull/914
|
|
109
106
|
if (unmounted) return;
|
|
110
|
-
|
|
111
|
-
resizer.$observeRoot(scrollable);
|
|
112
|
-
scroller.$observe(container, scrollable);
|
|
113
|
-
};
|
|
114
|
-
if (scrollRef) {
|
|
115
|
-
assignRef(scrollRef);
|
|
116
|
-
} else {
|
|
117
|
-
assignRef(container.parentElement!);
|
|
118
|
-
}
|
|
107
|
+
driver.$observe(container, scrollRef);
|
|
119
108
|
});
|
|
120
109
|
return () => {
|
|
121
110
|
unmounted = true;
|
|
@@ -123,8 +112,7 @@
|
|
|
123
112
|
});
|
|
124
113
|
onDestroy(() => {
|
|
125
114
|
store.$dispose();
|
|
126
|
-
|
|
127
|
-
scroller.$dispose();
|
|
115
|
+
driver.$dispose();
|
|
128
116
|
});
|
|
129
117
|
|
|
130
118
|
$effect.pre(() => {
|
|
@@ -143,11 +131,11 @@
|
|
|
143
131
|
$effect(() => {
|
|
144
132
|
if (prevStateVersion === stateVersion) return;
|
|
145
133
|
prevStateVersion = stateVersion;
|
|
146
|
-
|
|
134
|
+
driver.$fixScrollJump();
|
|
147
135
|
});
|
|
148
136
|
|
|
149
137
|
export const getCache =
|
|
150
|
-
|
|
138
|
+
layout.$snapshot satisfies VirtualizerHandle["getCache"] as VirtualizerHandle["getCache"];
|
|
151
139
|
export const getScrollOffset =
|
|
152
140
|
store.$getScrollOffset satisfies VirtualizerHandle["getScrollOffset"] as VirtualizerHandle["getScrollOffset"];
|
|
153
141
|
export const getScrollSize = (() =>
|
|
@@ -162,12 +150,14 @@
|
|
|
162
150
|
store.$getItemOffset satisfies VirtualizerHandle["getItemOffset"] as VirtualizerHandle["getItemOffset"];
|
|
163
151
|
export const getItemSize =
|
|
164
152
|
store.$getItemSize satisfies VirtualizerHandle["getItemSize"] as VirtualizerHandle["getItemSize"];
|
|
165
|
-
export const scrollToIndex =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
export const
|
|
170
|
-
|
|
153
|
+
export const scrollToIndex: VirtualizerHandle["scrollToIndex"] = (
|
|
154
|
+
index,
|
|
155
|
+
opts,
|
|
156
|
+
) => _scrollToIndex(driver, store, index, opts);
|
|
157
|
+
export const scrollTo: VirtualizerHandle["scrollTo"] = (offset) =>
|
|
158
|
+
_scrollTo(driver, offset);
|
|
159
|
+
export const scrollBy: VirtualizerHandle["scrollBy"] = (offset) =>
|
|
160
|
+
_scrollBy(driver, store, offset);
|
|
171
161
|
|
|
172
162
|
let containerStyle = $derived(
|
|
173
163
|
styleToString({
|
|
@@ -198,7 +188,7 @@
|
|
|
198
188
|
hide={stateVersion && store.$isUnmeasuredItem(index)}
|
|
199
189
|
{horizontal}
|
|
200
190
|
{isSSR}
|
|
201
|
-
resizer={
|
|
191
|
+
resizer={driver.$observeItem}
|
|
202
192
|
itemProps={itemProps?.({ item, index })}
|
|
203
193
|
/>
|
|
204
194
|
{/each}
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
UPDATE_SCROLL_EVENT,
|
|
8
8
|
UPDATE_VIRTUAL_STATE,
|
|
9
9
|
createVirtualStore,
|
|
10
|
+
createListLayout,
|
|
10
11
|
getScrollSize as _getScrollSize,
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
createWindowDriver,
|
|
13
|
+
scrollToIndex as _scrollToIndex,
|
|
13
14
|
} from "../core/index.js";
|
|
14
15
|
import { defaultGetKey, styleToString } from "./utils.js";
|
|
15
16
|
import ListItem from "./ListItem.svelte";
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
getKey = defaultGetKey,
|
|
26
27
|
bufferSize,
|
|
27
28
|
itemSize,
|
|
29
|
+
ssrCount,
|
|
28
30
|
shift = false,
|
|
29
31
|
horizontal = false,
|
|
30
32
|
cache,
|
|
@@ -33,15 +35,9 @@
|
|
|
33
35
|
onscrollend,
|
|
34
36
|
}: Props = $props();
|
|
35
37
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
undefined,
|
|
40
|
-
cache,
|
|
41
|
-
!itemSize,
|
|
42
|
-
);
|
|
43
|
-
const resizer = createWindowResizer(store, horizontal);
|
|
44
|
-
const scroller = createWindowScroller(store, horizontal);
|
|
38
|
+
const layout = createListLayout(data.length, itemSize, cache);
|
|
39
|
+
const store = createVirtualStore(layout, ssrCount);
|
|
40
|
+
const driver = createWindowDriver(store, horizontal);
|
|
45
41
|
store.$subscribe(UPDATE_VIRTUAL_STATE, () => {
|
|
46
42
|
stateVersion = store.$getStateVersion();
|
|
47
43
|
});
|
|
@@ -53,6 +49,8 @@
|
|
|
53
49
|
onscrollend && onscrollend();
|
|
54
50
|
});
|
|
55
51
|
|
|
52
|
+
let isSSR = $state(!!ssrCount);
|
|
53
|
+
|
|
56
54
|
let containerRef: HTMLDivElement | undefined = $state();
|
|
57
55
|
|
|
58
56
|
let stateVersion: StateVersion = $state(store.$getStateVersion());
|
|
@@ -60,7 +58,7 @@
|
|
|
60
58
|
let range = $derived(stateVersion && store.$getRange(bufferSize));
|
|
61
59
|
let isScrolling = $derived(stateVersion && store.$isScrolling());
|
|
62
60
|
let totalSize = $derived(stateVersion && store.$getTotalSize());
|
|
63
|
-
let negative = $derived(stateVersion &&
|
|
61
|
+
let negative = $derived(stateVersion && driver.$isNegative());
|
|
64
62
|
|
|
65
63
|
let indexes = $derived.by(() => {
|
|
66
64
|
// https://github.com/inokawa/virtua/pull/847
|
|
@@ -77,13 +75,13 @@
|
|
|
77
75
|
});
|
|
78
76
|
|
|
79
77
|
onMount(() => {
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
isSSR = false;
|
|
79
|
+
|
|
80
|
+
driver.$observe(containerRef!);
|
|
82
81
|
});
|
|
83
82
|
onDestroy(() => {
|
|
84
83
|
store.$dispose();
|
|
85
|
-
|
|
86
|
-
scroller.$dispose();
|
|
84
|
+
driver.$dispose();
|
|
87
85
|
});
|
|
88
86
|
|
|
89
87
|
$effect.pre(() => {
|
|
@@ -96,11 +94,11 @@
|
|
|
96
94
|
$effect(() => {
|
|
97
95
|
if (prevStateVersion === stateVersion) return;
|
|
98
96
|
prevStateVersion = stateVersion;
|
|
99
|
-
|
|
97
|
+
driver.$fixScrollJump();
|
|
100
98
|
});
|
|
101
99
|
|
|
102
100
|
export const getCache =
|
|
103
|
-
|
|
101
|
+
layout.$snapshot satisfies WindowVirtualizerHandle["getCache"] as WindowVirtualizerHandle["getCache"];
|
|
104
102
|
export const getScrollOffset =
|
|
105
103
|
store.$getScrollOffset satisfies WindowVirtualizerHandle["getScrollOffset"] as WindowVirtualizerHandle["getScrollOffset"];
|
|
106
104
|
export const getViewportSize =
|
|
@@ -111,8 +109,10 @@
|
|
|
111
109
|
store.$getItemOffset satisfies WindowVirtualizerHandle["getItemOffset"] as WindowVirtualizerHandle["getItemOffset"];
|
|
112
110
|
export const getItemSize =
|
|
113
111
|
store.$getItemSize satisfies WindowVirtualizerHandle["getItemSize"] as WindowVirtualizerHandle["getItemSize"];
|
|
114
|
-
export const scrollToIndex =
|
|
115
|
-
|
|
112
|
+
export const scrollToIndex: WindowVirtualizerHandle["scrollToIndex"] = (
|
|
113
|
+
index,
|
|
114
|
+
opts,
|
|
115
|
+
) => _scrollToIndex(driver, store, index, opts);
|
|
116
116
|
|
|
117
117
|
let containerStyle = $derived(
|
|
118
118
|
styleToString({
|
|
@@ -142,7 +142,8 @@
|
|
|
142
142
|
offset={stateVersion && store.$getItemOffset(index, negative)}
|
|
143
143
|
hide={stateVersion && store.$isUnmeasuredItem(index)}
|
|
144
144
|
{horizontal}
|
|
145
|
-
|
|
145
|
+
{isSSR}
|
|
146
|
+
resizer={driver.$observeItem}
|
|
146
147
|
/>
|
|
147
148
|
{/each}
|
|
148
149
|
</div>
|
|
@@ -29,6 +29,10 @@ export interface WindowVirtualizerProps<T> {
|
|
|
29
29
|
* - If set, you can opt out estimation and use the value as initial item size.
|
|
30
30
|
*/
|
|
31
31
|
itemSize?: number;
|
|
32
|
+
/**
|
|
33
|
+
* A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated. The minimum value is 0.
|
|
34
|
+
*/
|
|
35
|
+
ssrCount?: number;
|
|
32
36
|
/**
|
|
33
37
|
* While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.
|
|
34
38
|
*/
|
package/lib/svelte/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/svelte/utils.ts"],"sourcesContent":["export const styleToString = (\n obj: Record<string, string | undefined>,\n): string => {\n return Object.keys(obj).reduce((acc, k) => {\n const value = obj[k];\n if (value == null) {\n return acc;\n }\n return acc + `${k}:${value};`;\n }, \"\");\n};\n\nexport const defaultGetKey = (_data: unknown, i: number) => \"_\" + i;\n\n/**\n * @internal\n */\nexport type ItemAttrs = {\n [key: string]: any;\n style?: Record<string, string | undefined>;\n class?: string;\n};\n\n/**\n * A function that provides properties/attributes for item element\n */\nexport type ItemProps<T = unknown> = (payload: {\n item: T;\n index: number;\n}) => ItemAttrs | undefined;\n"],"mappings":";AAAA,IAAa,iBACX,QACW;CACX,OAAO,OAAO,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/svelte/utils.ts"],"sourcesContent":["export const styleToString = (\n obj: Record<string, string | undefined>,\n): string => {\n return Object.keys(obj).reduce((acc, k) => {\n const value = obj[k];\n if (value == null) {\n return acc;\n }\n return acc + `${k}:${value};`;\n }, \"\");\n};\n\nexport const defaultGetKey = (_data: unknown, i: number) => \"_\" + i;\n\n/**\n * @internal\n */\nexport type ItemAttrs = {\n [key: string]: any;\n style?: Record<string, string | undefined>;\n class?: string;\n};\n\n/**\n * A function that provides properties/attributes for item element\n */\nexport type ItemProps<T = unknown> = (payload: {\n item: T;\n index: number;\n}) => ItemAttrs | undefined;\n"],"mappings":";AAAA,IAAa,iBACX,QACW;CACX,OAAO,OAAO,KAAK,GAAG,CAAC,CAAC,QAAQ,KAAK,MAAM;EACzC,MAAM,QAAQ,IAAI;EAClB,IAAI,SAAS,MACX,OAAO;EAET,OAAO,MAAM,GAAG,EAAE,GAAG,MAAM;CAC7B,GAAG,EAAE;AACP;AAEA,IAAa,iBAAiB,OAAgB,MAAc,MAAM"}
|
|
@@ -20,6 +20,10 @@ export interface WindowVirtualizerProps<T = unknown> extends PublicProps {
|
|
|
20
20
|
* - If set, you can opt out estimation and use the value as initial item size.
|
|
21
21
|
*/
|
|
22
22
|
itemSize?: number;
|
|
23
|
+
/**
|
|
24
|
+
* A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated. The minimum value is 0.
|
|
25
|
+
*/
|
|
26
|
+
ssrCount?: number;
|
|
23
27
|
/**
|
|
24
28
|
* While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.
|
|
25
29
|
*/
|