@tanstack/lit-virtual 3.8.3 → 3.8.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/README.md +68 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @tanstack/lit-virtual
|
|
2
|
+
|
|
3
|
+
Efficiently virtualize only the visible DOM nodes within massive scrollable elements using Lit, while maintaining complete control over markup and styles.
|
|
4
|
+
|
|
5
|
+
## `VirtualizerController`
|
|
6
|
+
|
|
7
|
+
`@tanstack/lit-virtual` utilizes [Reactive Controllers](https://lit.dev/docs/composition/controllers/) to create the virtualizer and integrate it with the element lifecycle:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { LitElement } from 'lit'
|
|
11
|
+
import { VirtualizerController } from '@tanstack/lit-virtual'
|
|
12
|
+
import { Ref, createRef } from 'lit/directives/ref.js'
|
|
13
|
+
|
|
14
|
+
class MyVirtualElement extends LitElement {
|
|
15
|
+
private virtualizerController: VirtualizerController<HTMLDivElement, Element>
|
|
16
|
+
private scrollElementRef: Ref<HTMLDivElement> = createRef()
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
super()
|
|
20
|
+
this.virtualizerController = new VirtualizerController(this, {
|
|
21
|
+
getScrollElement: () => this.scrollElementRef.value,
|
|
22
|
+
count: 10000,
|
|
23
|
+
estimateSize: () => 35,
|
|
24
|
+
overscan: 5,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
render() {
|
|
29
|
+
const virtualizer = this.virtualizerController.getVirtualizer()
|
|
30
|
+
const virtualItems = virtualizer.getVirtualItems()
|
|
31
|
+
|
|
32
|
+
return html`
|
|
33
|
+
<div class="list scroll-container" ${ref(this.scrollElementRef)}>
|
|
34
|
+
${virtualItems.map(
|
|
35
|
+
(item) => html`<div class="item">${item.index}</div>`,
|
|
36
|
+
)}
|
|
37
|
+
</div>
|
|
38
|
+
`
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Note that a [Ref](https://lit.dev/docs/templates/directives/#ref) is attached to the scrolling container to allow the virtualizer to interact with it.
|
|
44
|
+
|
|
45
|
+
## `WindowVirtualizerController`
|
|
46
|
+
|
|
47
|
+
You can also create a virtualizer controller that attaches to the Window:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { WindowVirtualizerController } from '@tanstack/lit-virtual'
|
|
51
|
+
|
|
52
|
+
class MyWindowVirtualElement extends LitElement {
|
|
53
|
+
private windowVirtualizerController: WindowVirtualizerController
|
|
54
|
+
|
|
55
|
+
constructor() {
|
|
56
|
+
super()
|
|
57
|
+
this.windowVirtualizerController = new WindowVirtualizerController(this, {
|
|
58
|
+
count: this.data.length,
|
|
59
|
+
estimateSize: () => 350,
|
|
60
|
+
overscan: 5,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Implement render and other lifecycle methods as needed
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
For more examples and detailed usage, visit the [official documentation](https://tanstack.com/virtual/latest).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/lit-virtual",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.4",
|
|
4
4
|
"description": "Headless UI for virtualizing scrollable elements in Lit",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"src"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@tanstack/virtual-core": "3.8.
|
|
46
|
+
"@tanstack/virtual-core": "3.8.4"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@open-wc/testing": "^4.0.0",
|