@humanspeak/svelte-virtual-list 0.2.6 → 0.3.1-beta.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/README.md +50 -13
- package/dist/SvelteVirtualList.svelte +619 -179
- package/dist/SvelteVirtualList.svelte.d.ts +156 -65
- package/dist/reactive-height-manager/INTEGRATION_EXAMPLE.md +136 -0
- package/dist/reactive-height-manager/README.md +324 -0
- package/dist/reactive-height-manager/ReactiveHeightManager.svelte.d.ts +116 -0
- package/dist/reactive-height-manager/ReactiveHeightManager.svelte.js +200 -0
- package/dist/reactive-height-manager/benchmark.d.ts +5 -0
- package/dist/reactive-height-manager/benchmark.js +25 -0
- package/dist/reactive-height-manager/index.d.ts +50 -0
- package/dist/reactive-height-manager/index.js +55 -0
- package/dist/reactive-height-manager/test/TestComponent.svelte +78 -0
- package/dist/reactive-height-manager/test/TestComponent.svelte.d.ts +23 -0
- package/dist/reactive-height-manager/types.d.ts +41 -0
- package/dist/reactive-height-manager/types.js +1 -0
- package/dist/types.d.ts +24 -5
- package/dist/utils/heightCalculation.d.ts +18 -8
- package/dist/utils/heightCalculation.js +18 -11
- package/dist/utils/heightChangeDetection.d.ts +12 -0
- package/dist/utils/heightChangeDetection.js +20 -0
- package/dist/utils/resizeObserver.d.ts +89 -0
- package/dist/utils/resizeObserver.js +119 -0
- package/dist/utils/scrollCalculation.d.ts +47 -0
- package/dist/utils/scrollCalculation.js +167 -0
- package/dist/utils/throttle.d.ts +95 -0
- package/dist/utils/throttle.js +155 -0
- package/dist/utils/types.d.ts +0 -6
- package/dist/utils/virtualList.d.ts +20 -23
- package/dist/utils/virtualList.js +153 -61
- package/dist/utils/virtualListDebug.d.ts +12 -7
- package/dist/utils/virtualListDebug.js +19 -9
- package/package.json +33 -31
package/README.md
CHANGED
|
@@ -58,11 +58,23 @@ You can now programmatically scroll to any item in the list using the `scroll` m
|
|
|
58
58
|
|
|
59
59
|
### API
|
|
60
60
|
|
|
61
|
-
- `scroll(options: { index: number; smoothScroll?: boolean; shouldThrowOnBounds?: boolean; align?: 'auto' | 'top' | 'bottom' })`
|
|
61
|
+
- `scroll(options: { index: number; smoothScroll?: boolean; shouldThrowOnBounds?: boolean; align?: 'auto' | 'top' | 'bottom' | 'nearest' })`
|
|
62
62
|
- `index`: The item index to scroll to (0-based)
|
|
63
63
|
- `smoothScroll`: If true, uses smooth scrolling (default: true)
|
|
64
64
|
- `shouldThrowOnBounds`: If true, throws if index is out of bounds (default: true)
|
|
65
|
-
- `align`: Where to align the item in the viewport
|
|
65
|
+
- `align`: Where to align the item in the viewport:
|
|
66
|
+
- `'auto'` (default): Only scroll if not visible, align to top or bottom as appropriate
|
|
67
|
+
- `'top'`: Always align to the top
|
|
68
|
+
- `'bottom'`: Always align to the bottom
|
|
69
|
+
- `'nearest'`: Scroll as little as possible to bring the item into view (like native scrollIntoView({ block: 'nearest' }))
|
|
70
|
+
|
|
71
|
+
#### Usage Examples
|
|
72
|
+
|
|
73
|
+
```svelte
|
|
74
|
+
<button on:click={() => listRef.scroll({ index: 5000, align: 'nearest' })}>
|
|
75
|
+
Scroll to item 5000 (nearest)
|
|
76
|
+
</button>
|
|
77
|
+
```
|
|
66
78
|
|
|
67
79
|
## Installation
|
|
68
80
|
|
|
@@ -124,19 +136,44 @@ npm install @humanspeak/svelte-virtual-list
|
|
|
124
136
|
</div>
|
|
125
137
|
```
|
|
126
138
|
|
|
139
|
+
### Bottom-to-top mode
|
|
140
|
+
|
|
141
|
+
Use `mode="bottomToTop"` for chat-like lists anchored to the bottom. Programmatic scrolling uses the same API as top-to-bottom lists:
|
|
142
|
+
|
|
143
|
+
```svelte
|
|
144
|
+
<script lang="ts">
|
|
145
|
+
import SvelteVirtualList from '@humanspeak/svelte-virtual-list'
|
|
146
|
+
let listRef
|
|
147
|
+
const messages = Array.from({ length: 2000 }, (_, i) => ({ id: i, text: `Msg ${i}` }))
|
|
148
|
+
</script>
|
|
149
|
+
|
|
150
|
+
<SvelteVirtualList items={messages} mode="bottomToTop" bind:this={listRef} />
|
|
151
|
+
<button on:click={() => listRef.scroll({ index: messages.length - 1, align: 'bottom' })}>
|
|
152
|
+
Jump to latest
|
|
153
|
+
</button>
|
|
154
|
+
```
|
|
155
|
+
|
|
127
156
|
## Props
|
|
128
157
|
|
|
129
|
-
| Prop
|
|
130
|
-
|
|
|
131
|
-
| `items`
|
|
132
|
-
| `
|
|
133
|
-
| `mode`
|
|
134
|
-
| `bufferSize`
|
|
135
|
-
| `debug`
|
|
136
|
-
| `containerClass`
|
|
137
|
-
| `viewportClass`
|
|
138
|
-
| `contentClass`
|
|
139
|
-
| `itemsClass`
|
|
158
|
+
| Prop | Type | Default | Description |
|
|
159
|
+
| ---------------------------- | -------------------------------- | --------------- | ----------------------------------------------------------------------------- |
|
|
160
|
+
| `items` | `T[]` | Required | Array of items to render |
|
|
161
|
+
| `defaultEstimatedItemHeight` | `number` | `40` | Initial height estimate used until items are measured |
|
|
162
|
+
| `mode` | `'topToBottom' \| 'bottomToTop'` | `'topToBottom'` | Scroll direction and anchoring behavior |
|
|
163
|
+
| `bufferSize` | `number` | `20` | Number of items rendered outside the viewport |
|
|
164
|
+
| `debug` | `boolean` | `false` | Enable debug logging and visualizations |
|
|
165
|
+
| `containerClass` | `string` | `''` | Class for outer container |
|
|
166
|
+
| `viewportClass` | `string` | `''` | Class for scrollable viewport |
|
|
167
|
+
| `contentClass` | `string` | `''` | Class for content wrapper |
|
|
168
|
+
| `itemsClass` | `string` | `''` | Class for items container |
|
|
169
|
+
| `testId` | `string` | `''` | Base test id used in internal test hooks (useful for E2E/tests and debugging) |
|
|
170
|
+
|
|
171
|
+
## Testing
|
|
172
|
+
|
|
173
|
+
- Unit tests (Vitest): `npm test`
|
|
174
|
+
- E2E tests (Playwright):
|
|
175
|
+
- One-time: `npx playwright install`
|
|
176
|
+
- Run: `npm run test:e2e`
|
|
140
177
|
|
|
141
178
|
## Performance Considerations
|
|
142
179
|
|