import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type $RestProps = SvelteHTMLElements["div"]; type $Props = Record> = { /** * Specify the items to render. * A browser scrolls only so far, about 17.9 million pixels in Firefox and * 33.5 million in Chrome and Safari. A longer list ends at the last item * that fits, so page or filter a list that large. * @default [] */ items?: ReadonlyArray; /** * Specify the height of each item in pixels. * When `measured` is `true`, this is only the estimate for items not yet measured. * @default 40 */ itemHeight?: number; /** * Specify the height of the scrollable viewport in pixels. * When `scrollElement` is set, match this to that element's visible height. * @default 300 */ containerHeight?: number; /** * Specify the number of items to render above and below the viewport * @default 3 */ overscan?: number; /** * Specify the minimum number of items before windowing activates. * Below it, every item renders. * @default 0 */ threshold?: number; /** * Set to `true` to measure each rendered item with `ResizeObserver` * instead of assuming every item is `itemHeight` tall. * @default false */ measured?: boolean; /** * Specify the key for each item. * Defaults to the item's index, which is only stable when items are appended. * @default (_item, index) => index */ getKey?: (item: Item, index: number) => string | number; /** * Set to `true` to keep the rendered items in view during very fast * scrolling, such as a scrollbar drag, instead of showing blank space until * new items render. * The items then follow the scroll a frame behind, and pause while the main * thread is busy. * Ignored when `scrollElement` is set. * @default false */ optimizeFastScroll?: boolean; /** * Specify an ancestor element that scrolls the list, such as the * `scrollElementRef` of a `ScrollGradient`. * When set, the list does not scroll itself. * @default null */ scrollElement?: null | HTMLElement; /** * Specify a tag to render items straight into the parent element, * such as the list of a `ContainedList`, without a container of their own. * Two elements of this tag above and below the items hold the scroll height, * so use one the parent accepts as a child, like `"li"` inside a list. * Requires `scrollElement`. Each item must render exactly one element. * Rest props have no element to land on, so they are dropped. */ spacerTag?: undefined | keyof HTMLElementTagNameMap; /** * Obtain a reference to the list container element. * `null` when `spacerTag` is set. * @default null */ ref?: null | HTMLDivElement; children?: (this: void, ...args: [{ item: Item; index: number; }]) => void; [key: `data-${string}`]: unknown; }; export type VirtualListProps = Record> = Omit<$RestProps, keyof $Props> & $Props; export default class VirtualList = Record> extends SvelteComponentTyped< VirtualListProps, { /** * Dispatched when the list is scrolled near the bottom (load-more signal). * Not the browser's native `scrollend` (scroll stopped). */ scrollend: CustomEvent<{ scrollTop: number; scrollHeight: number; clientHeight: number }>; }, { default: { item: Item; index: number; }; } > {}