Skip to content

Commit 3b01d44

Browse files
committed
feat: store the model inside the component, rename @Row @slot
1 parent 8d710c3 commit 3b01d44

File tree

15 files changed

+246
-179
lines changed

15 files changed

+246
-179
lines changed

README.md

+16-13
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,26 @@
2121

2222
Keep your page efficient and fast: only shows the visible items, instead of displaying all your data in large lists.
2323

24-
This package is a copy-cat of [svelte-tiny-virtual-list](https://github.com/jonasgeiler/svelte-tiny-virtual-list) with svelte 5, better suroundings, types, bug fixes and enhacements to the functionality and APIs. Credits must go to its original [author](https://github.com/jonasgeiler).
24+
This package originated from [svelte-tiny-virtual-list](https://github.com/jonasgeiler/svelte-tiny-virtual-list) and was modified to support Svelte 5, improved model handling, types, bug fixes, and overall project enhancement. Many thanks to the original [author](https://github.com/jonasgeiler).
2525

2626
## Features
2727

28-
- 🔄 **Svelte 5+**
28+
- ❺➎⓹ **Svelte 5+ only**
2929
Build for Svelte 5+ in Typescript.
3030

31-
- **Performant**
31+
- 🚀 **Performant**
3232
Render millions of items, without breaking a sweat.
3333

3434
- 🛠 **Configurable**
3535
Customize width, heigh, position, style, content.
36-
- 💡 **Layout Control**
36+
37+
- 💠 **Layout Control**
3738
Support fixed and variables sizing, dynamic loading along with vertical and horizontal lists.
3839

39-
- 🧠 **Programming Interface**
40+
- 🧩 **Programming Interface**
4041
Set list positions and properties, and respond promptly to events.
4142

42-
- 🤏 **Small**
43+
- 💼 **Small**
4344
Compact and dependency free – Only ~5kb when compressed.
4445

4546
## Usage
@@ -48,7 +49,7 @@ This component can be used two different ways:
4849

4950
- 🤖 As a scrollable listover a large number of items, optionally read incrementally.
5051

51-
- 🧩 As a fondation for more complex components - TreeViews and DataGrids.
52+
- 🧠 As a fondation for more complex components - TreeViews and DataGrids.
5253

5354
## Browser Support
5455

@@ -97,12 +98,13 @@ The component accepts the following properties
9798
| ----------------- | ----------- | :-------: | ------------ |
9899
| width | `number` or `string`\* || Width of List. This property will determine the number of rendered items when scrollDirection is `'horizontal'`. |
99100
| height | `number` or `string`\* || Height of List. This property will determine the number of rendered items when scrollDirection is `'vertical'`. |
100-
| itemCount | `number` || The number of items you want to render |
101+
| items | any[] || the model, the data for the items to display in the list. |
102+
| itemCount | `number` || The number of items you want to render. |
101103
| itemSize | `number | number[] | (index: number) => number` || Either a fixed height/width (depending on the scrollDirection), an array containing the heights of all the items in your list, or a function that returns the height of an item given its index: `(index: number): number` |
102104
| row | (r:RowAttributes) => SnippetResult || Snippet called to render every item, see description below. |
103105
| scrollDirection | `string` | | Whether the list should scroll vertically or horizontally. One of `'vertical'` (default) or `'horizontal'`. |
104-
| scrollOffset | `number` | | Can be used to control the scroll offset; Also useful for setting an initial scroll offset |
105-
| scrollToIndex | `number` | | Item index to scroll to (by forcefully scrolling if necessary) |
106+
| scrollOffset | `number` | | Can be used to control the scroll offset; Also useful for setting an initial scroll offset. |
107+
| scrollToIndex | `number` | | Item index to scroll to (by forcefully scrolling if necessary). |
106108
| scrollToAlignment | `string` | | Used in combination with `scrollToIndex`, this prop controls the alignment of the scrolled to item. One of: `'start'`, `'center'`, `'end'` or `'auto'`. Use `'start'` to always align items to the top of the container and `'end'` to align them bottom. Use `'center`' to align them in the middle of the container. `'auto'` scrolls the least amount possible to ensure that the specified `scrollToIndex` item is fully visible. |
107109
| scrollToBehaviour | `string` | | Used in combination with `scrollToIndex`, this prop controls the behaviour of the scrolling. One of: `'auto'`, `'smooth'` or `'instant'` (default). |
108110
| windowOverPadding | `number` | | Number of extra buffer items to render above/below the visible items. Tweaking this can help reduce scroll flickering on certain browsers/devices. |
@@ -115,10 +117,11 @@ _\* `height` must be a number when `scrollDirection` is `'vertical'`. Similarly,
115117

116118
- `header` - a snippet for the elements that should appear at the top of the list
117119
- `footer` - a snippet for the elements that should appear at the bottom of the list (e.g. `InfiniteLoading` component from `svelte-infinite-loading`)
118-
- `row` - a required snipper property called to render each row of the list with the signature `row(r:RowAttributes)`
120+
- `slot` - a required snipper property called to render each row of the list with the signature `slot(r:RowAttributes)`
119121

120122
```typescript
121123
export interface RowAttributes {
124+
item: any // the element from the items array at index
122125
index: number; // Item index
123126
style: string; // Item style, must be applied to the slot (look above for example)
124127
}
@@ -128,9 +131,9 @@ for instance,
128131

129132
```svelte
130133
<VirtualList ...>
131-
{#snippet row({ style, index }:RowAttributes)}
134+
{#snippet slot({ item, style, index }:RowAttributes)}
132135
<div class="row" {style}>
133-
Item: {data[index]}, Row: #{index}
136+
Item: {item}, Row: #{index}
134137
</div>
135138
{/snippet}
136139
</VirtualList>

TODO.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[ ] Add a <PartialLoader/> to fetch the model on demand
2+
[ ] Add class and style attributes
3+
[x] store the model inside the component
4+
[x] Rename the row snippet to something else -> slot
5+
[ ] add disabled
6+
[ ] move the css style logic out of the component row({ item, style, index })

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"@sveltejs/package": "2.3.0",
6161
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.3",
6262
"@types/eslint": "^8.56.10",
63-
"@types/node": "^20.14.5",
63+
"@types/node": "^20.14.6",
6464
"@typescript-eslint/eslint-plugin": "^7.13.1",
6565
"@typescript-eslint/parser": "^7.13.1",
6666
"badge-maker": "^3.3.1",
@@ -88,6 +88,6 @@
8888
"vite": "^5.3.1"
8989
},
9090
"peerDependencies": {
91-
"svelte": "5.0.0-next.158"
91+
"svelte": "5.0.0-next.160"
9292
}
9393
}

0 commit comments

Comments
 (0)