@humanspeak/svelte-virtual-list 0.2.5 โ†’ 0.2.6-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 CHANGED
@@ -28,11 +28,11 @@ A high-performance virtual list component for Svelte 5 applications that efficie
28
28
  - ๐Ÿง  Memory-optimized for 10k+ items
29
29
  - ๐Ÿงช Comprehensive test coverage (vitest and playwright)
30
30
  - ๐Ÿš€ Progressive initialization for large datasets
31
- - ๐Ÿ•น๏ธ Programmatic scrolling with `scrollToIndex`
31
+ - ๐Ÿ•น๏ธ Programmatic scrolling with `scroll`
32
32
 
33
- ## scrollToIndex: Programmatic Scrolling
33
+ ## scroll: Programmatic Scrolling
34
34
 
35
- You can now programmatically scroll to any item in the list using the `scrollToIndex` method. This is useful for chat apps, jump-to-item navigation, and more. Thank you for the feature request.
35
+ You can now programmatically scroll to any item in the list using the `scroll` method. This is useful for chat apps, jump-to-item navigation, and more. You can check the usage in `src/routes/tests/scroll`. Thank you for the feature request!
36
36
 
37
37
  ### Usage Example
38
38
 
@@ -43,8 +43,8 @@ You can now programmatically scroll to any item in the list using the `scrollToI
43
43
  const items = Array.from({ length: 10000 }, (_, i) => ({ id: i, text: `Item ${i}` }))
44
44
 
45
45
  function goToItem5000() {
46
- // Scroll to item 5000 with smooth scrolling
47
- listRef.scrollToIndex(5000, true)
46
+ // Scroll to item 5000 with smooth scrolling and auto alignment
47
+ listRef.scroll({ index: 5000, smoothScroll: true, align: 'auto' })
48
48
  }
49
49
  </script>
50
50
 
@@ -58,10 +58,23 @@ You can now programmatically scroll to any item in the list using the `scrollToI
58
58
 
59
59
  ### API
60
60
 
61
- - `scrollToIndex(index: number, smoothScroll = true, shouldThrowOnBounds = true)`
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:
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
+ ```
65
78
 
66
79
  ## Installation
67
80