import { ContextTrinity } from "../createTrinity/index.mjs"; import { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef } from "vue"; //#region src/composables/createVirtual/index.d.ts type VirtualDirection = 'forward' | 'reverse'; type VirtualState = 'loading' | 'empty' | 'error' | 'ok'; type VirtualAnchor = 'auto' | 'start' | 'end' | ((items: readonly unknown[]) => number | string); interface ScrollToOptions { /** * The behavior of the scroll animation. */ behavior?: 'auto' | 'smooth' | 'instant'; /** * The alignment of the scroll position. */ block?: 'start' | 'center' | 'end' | 'nearest'; /** * The offset of the scroll position. */ offset?: number; } interface VirtualOptions { /** * The height of the item. */ itemHeight?: number | string | null; /** * The height of the container. */ height?: number | string; /** * The number of extra items to render. */ overscan?: number; /** * The direction of the scrolling. */ direction?: VirtualDirection; /** * The anchor of the scrolling. */ anchor?: VirtualAnchor; /** * Whether to smooth the anchor position. */ anchorSmooth?: boolean; /** * The callback to call when the start is reached. */ onStartReached?: (distance: number) => void | Promise; /** * The callback to call when the end is reached. */ onEndReached?: (distance: number) => void | Promise; /** * The threshold for the start. */ startThreshold?: number; /** * The threshold for the end. */ endThreshold?: number; /** * Whether to enable momentum scrolling. */ momentum?: boolean; /** * Whether to enable elastic scrolling. */ elastic?: boolean; /** * Element at the top of the list inside the scroll parent. * * Its `offsetTop` is removed from the scroll position, so a header or * padding above the list does not shift the window. Omit it when the * list starts at the top of the scroller. * * @example * ```ts * const marker = ref() * const virtual = createVirtual(items, { marker }) * ``` */ marker?: MaybeRefOrGetter; /** * Identity of an item. * * Measured heights follow this key when items are prepended, filtered, * or reordered. Omit it to keep each height on its index. Duplicate keys * keep the latest measurement. * * @example * ```ts * const virtual = createVirtual(items, { * itemKey: item => item.id, * }) * ``` */ itemKey?: (item: T, index: number) => string | number; /** * Write momentum and overscroll styles onto the scroll element. * * Set this to `false` when a parent owns that element. * * @default true * * @example * ```ts * const virtual = createVirtual(items, { ownElement: false }) * ``` */ ownElement?: boolean; } interface VirtualItem { raw: T; index: number; /** `itemKey` result, or the index when no key function was passed. */ key: string | number; } interface VirtualContext { /** * The element that is being virtualized. * * @example * ```vue * * * */ element: Ref; /** * The items that are being virtualized. * * @example * ```vue * * * * ``` */ items: ComputedRef[]>; /** * The offset of the virtualized items. * * @example * ```vue * * * * ``` */ offset: Readonly>; /** * The size of the virtualized items. * * @example * ```vue * * * * ``` */ size: Readonly>; /** * The state of the virtualized items. * * @example * ```vue * * * * ``` */ state: ShallowRef; /** * Scroll to an item by index. * * @example * ```vue * * * * ``` */ scrollTo: (index: number, options?: ScrollToOptions) => void; /** * The scroll event handler. * * @example * ```vue * * * * ``` */ scroll: () => void; /** * The scrollend event handler. * * @example * ```vue * * * * ``` */ scrollend: () => void; /** * Resize an item by index. * * @example * ```vue * * * * ``` */ resize: (index: number, height: number) => void; /** * Reset the virtualized items. * * @example * ```vue * * * * ``` */ reset: () => void; } interface VirtualContextOptions extends VirtualOptions { /** Namespace for dependency injection */ namespace?: string; } declare function createVirtual(items: Ref, _options?: VirtualOptions): VirtualContext; /** * Creates a virtual scrolling context with dependency injection support. * * @param items Reactive array of items to virtualize * @param options Configuration options including namespace * @template T The type of the items * @returns Trinity tuple: [useVirtual, provideVirtual, defaultVirtual] * * @see https://0.vuetifyjs.com/composables/data/create-virtual * * @example * ```ts * // Create injectable context * const [useVirtual, provideVirtual, virtual] = createVirtualContext(items, { * namespace: 'my-virtual', * overscan: 10, * }) * * // In parent component * provideVirtual() * * // In child component * const virtual = useVirtual() * ``` */ declare function createVirtualContext(items: Ref, _options?: VirtualContextOptions): ContextTrinity>; /** * Returns the current virtual context from dependency injection. * * @param namespace The namespace for the virtual context. Defaults to `v0:virtual`. * @template T The type of the items * @returns The current virtual context. * * @throws An error if the virtual context is not found and no default is provided. * * @see https://0.vuetifyjs.com/composables/data/create-virtual * * @example * ```vue * * * * ``` */ declare function useVirtual(namespace?: string): VirtualContext; //#endregion export { ScrollToOptions, VirtualAnchor, VirtualContext, VirtualContextOptions, VirtualDirection, VirtualItem, VirtualOptions, VirtualState, createVirtual, createVirtualContext, useVirtual };