primevue-mirror/components/lib/virtualscroller/VirtualScroller.d.ts

521 lines
14 KiB
TypeScript
Raw Normal View History

2023-03-01 12:46:56 +00:00
/**
*
* VirtualScroller is a performant approach to handle huge data efficiently.
*
* [Live Demo](https://www.primevue.org/virtualscroller/)
*
* @module virtualscroller
*
*/
2022-09-06 12:03:37 +00:00
import { VNode } from 'vue';
2023-07-06 11:17:08 +00:00
import { ComponentHooks } from '../basecomponent';
2023-09-05 08:50:46 +00:00
import { PassThroughOptions } from '../passthrough';
import { ClassComponent, GlobalComponentConstructor, PassThrough } from '../ts-helpers';
2022-09-06 12:03:37 +00:00
export declare type VirtualScrollerPassThroughOptionType = VirtualScrollerPassThroughAttributes | ((options: VirtualScrollerPassThroughMethodOptions) => VirtualScrollerPassThroughAttributes | string) | string | null | undefined;
2023-05-05 06:37:18 +00:00
/**
* Custom passthrough(pt) option method.
*/
export interface VirtualScrollerPassThroughMethodOptions {
/**
* Defines instance.
*/
2023-07-06 12:01:33 +00:00
instance: any;
/**
* Defines valid properties.
*/
2023-05-05 06:37:18 +00:00
props: VirtualScrollerProps;
/**
* Defines current inline state.
*/
2023-05-05 06:37:18 +00:00
state: VirtualScrollerState;
2023-09-05 08:50:46 +00:00
/**
* Defines passthrough(pt) options in global config.
*/
global: object | undefined;
2023-05-05 06:37:18 +00:00
}
2023-03-01 12:46:56 +00:00
/**
* Custom scroll index change event.
2023-03-06 20:35:39 +00:00
* @see {@link VirtualScrollerEmits['scroll-index-change']}
2023-03-01 12:46:56 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface VirtualScrollerScrollIndexChangeEvent {
/**
* First index of the new data range to be loaded.
*/
first: number;
/**
* Last index of the new data range to be loaded.
*/
last: number;
}
/**
2023-03-01 12:46:56 +00:00
* Custom lazy event.
2023-03-06 20:35:39 +00:00
* @see {@link VirtualScrollerEmits['scroll-index-change']}
2022-09-06 12:03:37 +00:00
* @extends VirtualScrollerScrollIndexChangeEvent
*/
2022-09-14 11:26:01 +00:00
export interface VirtualScrollerLazyEvent extends VirtualScrollerScrollIndexChangeEvent {}
2022-09-06 12:03:37 +00:00
/**
2023-03-01 12:46:56 +00:00
* Custom virtualscroller viewport metadata.
2023-03-06 20:35:39 +00:00
* @see {@link VirtualScrollerEmits['scroll-index-change']}
2022-09-06 12:03:37 +00:00
* @extends VirtualScrollerScrollIndexChangeEvent
*/
2022-09-14 11:26:01 +00:00
export interface VirtualScrollerViewport extends VirtualScrollerScrollIndexChangeEvent {}
2022-09-06 12:03:37 +00:00
2023-03-01 12:46:56 +00:00
/**
* Virtual scroller rendered range.
*/
2022-09-06 12:03:37 +00:00
export interface VirtualScrollerRangeMethod {
/**
* Whether the item is first.
*/
first: number;
/**
* Whether the item is last.
*/
last: number;
/**
* Viewport info.
* @see VirtualScrollerViewport
*/
viewport: VirtualScrollerViewport;
}
2023-03-01 12:46:56 +00:00
/**
* Custom item options.
*/
2022-09-06 12:03:37 +00:00
export interface VirtualScrollerItemOptions {
/**
* Item index
*/
index: number;
/**
* Items count
*/
count: number;
/**
* Whether the item is first.
*/
first: boolean;
/**
* Whether the item is last.
*/
last: boolean;
/**
* Whether the item is even.
*/
even: boolean;
/**
* Whether the item is odd.
*/
odd: boolean;
/**
* Optional
*/
[key: string]: any;
}
2023-05-05 06:37:18 +00:00
/**
* Custom passthrough(pt) options.
* @see {@link VirtualScrollerProps.pt}
*/
export interface VirtualScrollerPassThroughOptions {
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the root's DOM element.
2023-05-05 06:37:18 +00:00
*/
root?: VirtualScrollerPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the content's DOM element.
2023-05-05 06:37:18 +00:00
*/
content?: VirtualScrollerPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the loader's DOM element.
2023-05-05 06:37:18 +00:00
*/
loader?: VirtualScrollerPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the loading icon's DOM element.
2023-05-05 06:37:18 +00:00
*/
loadingIcon?: VirtualScrollerPassThroughOptionType;
2023-06-20 09:51:09 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the spacer's DOM element.
2023-06-20 09:51:09 +00:00
*/
spacer?: VirtualScrollerPassThroughOptionType;
2023-07-06 11:09:01 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to manage all lifecycle hooks
2023-07-06 11:09:01 +00:00
* @see {@link BaseComponent.ComponentHooks}
*/
hooks?: ComponentHooks;
2023-05-05 06:37:18 +00:00
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface VirtualScrollerPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in VirtualScroller component.
*/
export interface VirtualScrollerState {
/**
* First index of the new data range to be loaded as a number.
*/
first: number;
/**
* Last index of the new data range to be loaded as a number.
*/
last: number;
/**
* Index of the first item as a number.
*/
page: number;
/**
* Visible item count in the viewport as a number.
*/
numItemsInViewport: number;
/**
* Lastest scroll position as a number.
*/
lastScrollPos: number;
/**
* Additional elements to add to the DOM outside of the view as a number.
*/
d_numToleratedItems: number;
/**
* Current loading state as a boolean.
* @defaultValue false
*/
d_loading: number;
/**
* Loadable items array.
*/
loaderArr: any[];
/**
* The style of spacer element.
*/
spacerStyle: any;
/**
* The style of content element.
*/
contentStyle: any;
}
2022-09-06 12:03:37 +00:00
/**
2023-03-01 12:46:56 +00:00
* Custom virtualscroller loader options
* @see VirtualScrollerItemOptions
2022-09-06 12:03:37 +00:00
* @extends VirtualScrollerItemOptions
*/
2022-09-14 11:26:01 +00:00
export interface VirtualScrollerLoaderOptions extends VirtualScrollerItemOptions {}
2022-09-06 12:03:37 +00:00
2023-03-01 12:46:56 +00:00
/**
* Defines valid properties in VirtualScroller component.
*/
2022-09-06 12:03:37 +00:00
export interface VirtualScrollerProps {
/**
* Unique identifier of the element.
*/
id?: string | undefined;
/**
* Inline style of the component.
*/
style?: any;
/**
* Style class of the component.
*/
class?: any;
/**
* An array of objects to display.
*/
2023-03-01 12:46:56 +00:00
items?: any[] | any[][] | undefined | null;
2022-09-06 12:03:37 +00:00
/**
* The height/width of item according to orientation.
*/
2023-03-01 12:46:56 +00:00
itemSize?: number | number[] | undefined;
2022-09-06 12:03:37 +00:00
/**
* Height of the scroll viewport.
*/
scrollHeight?: string | undefined;
/**
* Width of the scroll viewport.
*/
scrollWidth?: string | undefined;
/**
* The orientation of scrollbar.
2023-03-01 12:46:56 +00:00
* @defaultValue vertical
2022-09-06 12:03:37 +00:00
*/
2023-03-01 12:46:56 +00:00
orientation?: 'vertical' | 'horizontal' | 'both' | undefined;
2022-09-06 12:03:37 +00:00
/**
* Determines how many additional elements to add to the DOM outside of the view.
* According to the scrolls made up and down, extra items are added in a certain algorithm in the form of multiples of this number.
2023-03-01 12:46:56 +00:00
* @defaultValue half the number of items shown in the view.
2022-09-06 12:03:37 +00:00
*/
numToleratedItems?: number | undefined;
/**
* Delay in scroll before new data is loaded.
2023-03-01 12:46:56 +00:00
* @defaultValue 0
2022-09-06 12:03:37 +00:00
*/
delay?: number | undefined;
/**
* Delay after window's resize finishes.
* @defaultValue 10
*/
resizeDelay?: number | undefined;
2022-09-06 12:03:37 +00:00
/**
* Defines if data is loaded and interacted with in lazy manner.
2023-03-01 12:46:56 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
lazy?: boolean | undefined;
/**
* If disabled, the VirtualScroller feature is eliminated and the content is displayed directly.
2023-03-01 12:46:56 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
disabled?: boolean | undefined;
/**
* Used to implement a custom loader instead of using the loader feature in the VirtualScroller.
2023-03-01 12:46:56 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
loaderDisabled?: boolean | undefined;
/**
* Whether to show loader.
2023-05-05 06:37:18 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
showLoader?: boolean | undefined;
/**
* Used to implement a custom spacer instead of using the spacer feature in the VirtualScroller.
2023-03-01 12:46:56 +00:00
* @defaultValue true
2022-09-06 12:03:37 +00:00
*/
showSpacer?: boolean | undefined;
/**
* Whether to load items.
2023-03-01 12:46:56 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
loading?: boolean | undefined;
/**
* Callback to invoke in lazy mode to load new data.
* @param {VirtualScrollerLazyEvent} event - Custom lazy event.
*/
2023-03-01 12:46:56 +00:00
onLazyLoad?(event: VirtualScrollerLazyEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Index of the element in tabbing order.
2023-03-08 10:51:52 +00:00
* @defaultValue 0
2022-09-06 12:03:37 +00:00
*/
tabindex?: number | string | undefined;
/**
* When enabled, positions the content as inline.
* @defaultValue false
*/
inline?: boolean | undefined;
/**
* Used to specify how many items to load in each load method in lazy mode.
* @defaultValue 0
*/
step?: number | undefined;
/**
* Used to append each loaded item to top without removing any items from the DOM. Using very large data may cause the browser to crash.
* @defaultValue false
*/
appendOnly?: boolean | undefined;
/**
* Whether to dynamically change the height or width of scrollable container.
* @defaultValue false
*/
autoSize?: boolean | undefined;
2023-05-05 06:37:18 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to DOM elements inside the component.
2023-05-05 06:37:18 +00:00
* @type {VirtualScrollerPassThroughOptions}
*/
pt?: PassThrough<VirtualScrollerPassThroughOptions>;
2023-09-05 08:50:46 +00:00
/**
* Used to configure passthrough(pt) options of the component.
* @type {PassThroughOptions}
*/
ptOptions?: PassThroughOptions;
2023-06-06 11:38:49 +00:00
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
2022-09-06 12:03:37 +00:00
}
2023-03-01 12:46:56 +00:00
/**
* Defines valid slots in VirtualScroller component.
*/
2022-09-06 12:03:37 +00:00
export interface VirtualScrollerSlots {
/**
* Custom content template.
* @param {Object} scope - content slot's params.
*/
2023-03-01 12:46:56 +00:00
content(scope: {
2022-09-06 12:03:37 +00:00
/**
* An array of objects to display for virtualscroller
*/
items: any;
/**
* Style class of the content
*/
styleClass: string;
/**
* Referance of the content
* @param {HTMLElement} el - Element of 'ref' property
*/
2023-08-17 07:16:25 +00:00
contentRef: (el: any) => void;
2022-09-06 12:03:37 +00:00
/**
* Options of the items
* @param {number} index - Rendered index
2023-08-17 07:16:25 +00:00
* @return {@link VirtualScrollerItemOptions}
2022-09-06 12:03:37 +00:00
*/
2023-08-17 07:16:25 +00:00
getItemOptions: (index: number) => VirtualScrollerItemOptions;
2022-09-06 12:03:37 +00:00
/**
* Whether the data is loaded.
*/
loading: boolean;
/**
* Loader options of the items while the data is loading.
* @param {number} index - Rendered index
* @param {*} [ext] - Extra options
2023-08-17 07:16:25 +00:00
* @return {@link VirtualScrollerItemOptions}
2022-09-06 12:03:37 +00:00
*/
2023-08-17 07:16:25 +00:00
getLoaderOptions: (index: number, ext?: any) => VirtualScrollerLoaderOptions;
2022-09-06 12:03:37 +00:00
/**
* The height/width of item according to orientation.
*/
2023-03-01 12:46:56 +00:00
itemSize: number | number[] | undefined;
2022-09-06 12:03:37 +00:00
/**
* The number of the rendered rows.
*/
rows: number | undefined;
/**
* The number of the rendered columns.
*/
columns: number | undefined;
/**
* The style of spacer element.
*/
spacerStyle: any;
/**
* The style of content element.
*/
contentStyle: any;
/**
* Whether the orientation is vertical.
*/
vertical: boolean;
/**
* Whether the orientation is horizontal.
*/
horizontal: boolean;
/**
* Whether the orientation is both.
*/
both: boolean;
2023-03-01 12:46:56 +00:00
}): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom item template.
* @param {Object} scope - item slot's params.
*/
2023-03-01 12:46:56 +00:00
item(scope: {
2022-09-06 12:03:37 +00:00
/**
* Item data.
*/
item: any;
/**
* Item options.
*/
options: VirtualScrollerItemOptions;
2023-03-01 12:46:56 +00:00
}): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom loader template.
* @param {Object} scope - header slot's params.
*/
2023-03-01 12:46:56 +00:00
loader(scope: {
2022-09-06 12:03:37 +00:00
/**
* Loader options.
*/
options: VirtualScrollerLoaderOptions;
2023-03-01 12:46:56 +00:00
}): VNode[];
/**
* Custom loading icon template.
2023-08-17 07:16:25 +00:00
* @param {Object} scope - loadingicon slot's params.
*/
2023-06-06 11:38:49 +00:00
loadingicon(scope: {
/**
* Style class of the icon.
*/
class: string;
}): VNode[];
2022-09-06 12:03:37 +00:00
}
2023-03-01 12:46:56 +00:00
/**
* Defines valid emits in VirtualScroller component.
*/
export interface VirtualScrollerEmits {
2022-09-06 12:03:37 +00:00
/**
* Emitted when the numToleratedItems changes.
* @param {number} value - New number tolerated items
*/
2023-03-01 12:46:56 +00:00
'update:numToleratedItems'(value: number): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when scroll position changes.
* @param {Event} event - Browser event.
2022-09-14 11:26:01 +00:00
*/
2023-03-01 12:46:56 +00:00
scroll(event: Event): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when scroll position and item's range in view changes.
2023-03-01 12:46:56 +00:00
* @param {VirtualScrollerScrollIndexChangeEvent} event - Custom tab open event.
2022-09-14 11:26:01 +00:00
*/
2023-03-01 12:46:56 +00:00
'scroll-index-change'(event: VirtualScrollerScrollIndexChangeEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke in lazy mode to load new data.
* @param {VirtualScrollerLazyEvent} event - Custom lazy event.
*/
2023-03-01 12:46:56 +00:00
'lazy-load'(event: VirtualScrollerLazyEvent): void;
}
2022-09-06 12:03:37 +00:00
2023-03-01 12:46:56 +00:00
/**
* **PrimeVue - VirtualScroller**
*
* _VirtualScroller is a performant approach to handle huge data efficiently._
*
* [Live Demo](https://www.primevue.org/virtualscroller/)
* --- ---
* ![PrimeVue](https://primefaces.org/cdn/primevue/images/logo-100.png)
*
* @group Component
*/
2022-09-06 12:03:37 +00:00
declare class VirtualScroller extends ClassComponent<VirtualScrollerProps, VirtualScrollerSlots, VirtualScrollerEmits> {
/**
* Scroll to move to a specific position.
* @param {ScrollToOptions} [options] - scoll options.
*/
scrollTo(options?: ScrollToOptions): void;
/**
* Scroll to move to a specific item.
* @param {number} index - Index of item according to orientation mode.
* @param {ScrollBehavior} [behavior] - Behavior of scroll.
*/
scrollToIndex(index: number, behavior?: ScrollBehavior): void;
/**
* It is used to move the specified index into the view. It is a method that will usually be needed when keyboard support is added to the virtualScroller component.
* @param {number} index - Index of item according to orientation mode.
2023-03-01 12:46:56 +00:00
* @param {'to-start' | 'to-end' } to - Defines the location of the item in view,
2022-09-06 12:03:37 +00:00
* @param {ScrollBehavior} [behavior] Behavior of scroll
*/
2023-03-01 12:46:56 +00:00
scrollInView(index: number, to: 'to-start' | 'to-end', behavior?: ScrollBehavior): void;
2022-09-06 12:03:37 +00:00
/**
* Returns the range of items added to the DOM.
*/
getRenderedRange(): VirtualScrollerRangeMethod;
}
declare module '@vue/runtime-core' {
interface GlobalComponents {
2022-09-14 11:26:01 +00:00
VirtualScroller: GlobalComponentConstructor<VirtualScroller>;
2022-09-06 12:03:37 +00:00
}
}
export default VirtualScroller;