|
30 | 30 | })(); |
31 | 31 | </script> |
32 | 32 |
|
33 | | -<script lang="ts"> |
34 | | - import { onMount, onDestroy, type Snippet } from 'svelte'; |
| 33 | +<script lang="ts" generics="ItemType"> |
| 34 | + import { onDestroy, onMount, type Snippet } from 'svelte'; |
35 | 35 | import { |
36 | 36 | ALIGNMENT, |
37 | 37 | SCROLL_BEHAVIOR, |
38 | | - type VLScrollEvent, |
39 | 38 | type SizingCalculatorFn, |
40 | | - type VLSlotSignature, |
41 | | - type VLRangeEvent |
| 39 | + type VLRangeEvent, |
| 40 | + type VLScrollEvent, |
| 41 | + type VLSlotSignature |
42 | 42 | } from '.'; |
43 | 43 |
|
44 | 44 | import clsx from 'clsx'; |
|
103 | 103 | // calculates the size of a given index |
104 | 104 | sizingCalculator |
105 | 105 | }: { |
106 | | - items: any[]; |
| 106 | + items: ItemType[]; |
107 | 107 |
|
108 | 108 | isDisabled?: boolean; |
109 | 109 | isHorizontal?: boolean; |
|
122 | 122 | // snippets |
123 | 123 | header?: Snippet; |
124 | 124 | // size is passed when a sizingCalculator is defined |
125 | | - vl_slot: Snippet<[VLSlotSignature]>; |
| 125 | + vl_slot: Snippet<[VLSlotSignature<ItemType>]>; |
126 | 126 | footer?: Snippet; |
127 | 127 |
|
128 | 128 | // events |
|
201 | 201 | return p; |
202 | 202 | }); |
203 | 203 |
|
204 | | - const visibleItemsInfo: VLSlotSignature[] = $derived.by(() => { |
| 204 | + const visibleItemsInfo: VLSlotSignature<ItemType>[] = $derived.by(() => { |
205 | 205 | if (!items || isDisabled) { |
206 | 206 | return []; |
207 | 207 | } |
208 | | - const r: VLSlotSignature[] = []; |
| 208 | + const r: VLSlotSignature<ItemType>[] = []; |
209 | 209 | for (let index = startIdx; index <= end2; index++) { |
210 | 210 | const item = items[index]; |
211 | 211 | if (item) { |
|
342 | 342 | function onscroll(event: Event): void { |
343 | 343 | const offset = getScroll(listContainer); |
344 | 344 |
|
345 | | - if ( |
346 | | - event.target !== listContainer || |
347 | | - offset < 0 || |
348 | | - curState.offset === offset |
349 | | - ) |
350 | | - return; |
| 345 | + if (event.target !== listContainer || offset < 0 || curState.offset === offset) return; |
351 | 346 |
|
352 | 347 | curState = { |
353 | 348 | offset, |
|
656 | 651 | {/if} |
657 | 652 | <tbody> |
658 | 653 | {#if isDisabled} |
659 | | - {#each items as item} |
660 | | - {@render vl_slot(item)} |
| 654 | + {#each items as item, index} |
| 655 | + {@render vl_slot({ index, item })} |
661 | 656 | {/each} |
662 | 657 | {:else} |
663 | 658 | {#each visibleItemsInfo as item} |
|
675 | 670 | {@render header()} |
676 | 671 | {/if} |
677 | 672 | {#if isDisabled} |
678 | | - {#each items as item} |
679 | | - {@render vl_slot(item)} |
| 673 | + {#each items as item, index} |
| 674 | + {@render vl_slot({ index, item })} |
680 | 675 | {/each} |
681 | 676 | {:else} |
682 | 677 | {#each visibleItemsInfo as item} |
|
0 commit comments