Skip to content

Commit 5f653c8

Browse files
author
TutorLatin
committed
support string height in VirtualList
1 parent 7c449a7 commit 5f653c8

File tree

4 files changed

+47
-42
lines changed

4 files changed

+47
-42
lines changed

package-lock.json

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+17-17
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@
3131
"@sveltejs/package": "^2.3.10",
3232
"@sveltejs/vite-plugin-svelte": "^5.0.3",
3333
"@types/eslint": "^9.6.1",
34-
"beercss": "^3.8.0",
35-
"eslint": "^9.17.0",
36-
"eslint-config-prettier": "9.1.0",
37-
"eslint-plugin-svelte": "2.46.0",
38-
"marked": "12.0.2",
34+
"beercss": "^3.9.6",
35+
"eslint": "^9.21.0",
36+
"eslint-config-prettier": "10.0.2",
37+
"eslint-plugin-svelte": "3.0.2",
38+
"marked": "15.0.7",
3939
"marked-base-url": "1.1.6",
40-
"marked-gfm-heading-id": "3.2.0",
41-
"prettier": "3.4.1",
42-
"prettier-plugin-svelte": "3.2.8",
43-
"publint": "0.2.12",
44-
"svelte": "4.2.19",
45-
"svelte-check": "3.8.6",
46-
"svelte-infinite-loading": "1.3.8",
47-
"tslib": "2.6.3",
48-
"typescript": "5.3.3",
49-
"vite": "5.1.8",
50-
"vitest": "1.6.1"
40+
"marked-gfm-heading-id": "4.1.1",
41+
"prettier": "3.5.2",
42+
"prettier-plugin-svelte": "3.3.3",
43+
"publint": "0.3.7",
44+
"svelte": "5.20.5",
45+
"svelte-check": "4.1.4",
46+
"svelte-infinite-loading": "1.4.0",
47+
"tslib": "2.8.1",
48+
"typescript": "5.8.2",
49+
"vite": "6.2.0",
50+
"vitest": "3.0.7"
5151
},
5252
"files": [
5353
"dist",
@@ -66,7 +66,7 @@
6666
"engines": {
6767
"node": ">=18"
6868
},
69-
"packageManager": "pnpm@9.0.6",
69+
"packageManager": "pnpm@10.5.2",
7070
"keywords": [
7171
"svelte",
7272
"virtual",

src/lib/VirtualList.svelte

+8-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
let wrapperStyle = $state.raw('');
3535
let innerStyle = $state.raw('');
3636
37+
let wrapperHeight = $state(400);
38+
let wrapperWidth = $state(400);
39+
3740
let items = $state.raw([]);
3841
3942
const _props = new ListProps(
@@ -66,7 +69,7 @@
6669
6770
// Effect 1: Update props from user provided props
6871
$effect(() => {
69-
_props.listen(scrollToIndex, scrollToAlignment, scrollOffset, itemCount, itemSize, estimatedItemSize, height, width, stickyIndices);
72+
_props.listen(scrollToIndex, scrollToAlignment, scrollOffset, itemCount, itemSize, estimatedItemSize, Number.isFinite(height) ? height : wrapperHeight, Number.isFinite(width) ? width : wrapperWidth, stickyIndices);
7073
7174
untrack(() => {
7275
let doRecomputeSizes = false;
@@ -109,7 +112,7 @@
109112
110113
const refresh = () => {
111114
const { start, stop } = sizeAndPositionManager.getVisibleRange({
112-
containerSize: scrollDirection === DIRECTION.VERTICAL ? height : width,
115+
containerSize: scrollDirection === DIRECTION.VERTICAL ? _props.height : _props.width,
113116
offset: _state.offset,
114117
overscanCount
115118
});
@@ -179,7 +182,7 @@
179182
180183
return sizeAndPositionManager.getUpdatedOffsetForIndex({
181184
align,
182-
containerSize: scrollDirection === DIRECTION.VERTICAL ? height : width,
185+
containerSize: scrollDirection === DIRECTION.VERTICAL ? _props.height : _props.width,
183186
currentOffset: _state.offset || 0,
184187
targetIndex: index
185188
});
@@ -232,6 +235,8 @@
232235

233236
<div
234237
bind:this={wrapper}
238+
bind:offsetHeight={wrapperHeight}
239+
bind:offsetWidth={wrapperWidth}
235240
class="virtual-list-wrapper"
236241
style={wrapperStyle}
237242
>

src/lib/utils/listProps.svelte.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export class ListProps {
1818
itemCount: 0,
1919
itemSize: 0,
2020
estimatedItemSize: 50,
21-
height: 600,
22-
width: "100%",
21+
height: 400,
22+
width: 400,
2323
stickyIndices: []
2424
});
2525

@@ -83,10 +83,10 @@ export class ListProps {
8383
if (typeof estimatedItemSize === "number")
8484
this.estimatedItemSize = estimatedItemSize || this.itemSize || 50;
8585

86-
if (typeof height === "number" || typeof height === "string")
86+
if (typeof height === "number")
8787
this.height = height;
8888

89-
if (typeof width === "number" || typeof width === "string")
89+
if (typeof width === "number")
9090
this.width = width;
9191

9292
if (Array.isArray(stickyIndices))

0 commit comments

Comments
 (0)