UNPKG

@ux-aspects/ux-aspects

Version:

Open source user interface framework for building modern, responsive, mobile big data applications

221 lines (220 loc) 7.22 kB
import { AfterContentInit, ElementRef, EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core'; import * as i0 from "@angular/core"; export declare class InfiniteScrollDirective<T = unknown> implements OnInit, AfterContentInit, OnChanges, OnDestroy { private readonly _element; load: InfiniteScrollLoadFunction<T>; _collection: T[]; get collection(): T[]; set collection(value: T[]); set scrollElement(element: ElementRef | HTMLElement); enabled: boolean; filter: any; loadOnInit: boolean; loadOnScroll: boolean; pageSize: number; collectionChange: EventEmitter<T[]>; loadingEvent: EventEmitter<InfiniteScrollLoadingEvent<any>>; loadedEvent: EventEmitter<InfiniteScrollLoadedEvent<any, any>>; loadErrorEvent: EventEmitter<InfiniteScrollLoadErrorEvent<any>>; private readonly _loadButtonQuery; private readonly _loadingIndicatorQuery; private _pages; private _nextPageNum; private _domObserver; private _scrollEventSub; private readonly _updateRequests; private readonly _isLoading; private readonly _isExhausted; private readonly _loadButtonEnabled; private readonly _canLoadManually; private _scrollElement; private _subscriptions; private _loadButtonSubscriptions; private readonly _onDestroy; constructor(); ngOnInit(): void; ngAfterContentInit(): void; ngOnChanges(changes: SimpleChanges): void; ngOnDestroy(): void; /** * Request an additional page of data. */ loadNextPage(): void; /** * Request a check for whether an additional page of data is required. This is throttled. */ check(): void; /** * Clear the collection. Future requests will load from page 0. */ reset(clearSubscriptions?: boolean): void; /** * Reload the data without clearing the view. */ reload(): void; /** * Reload the data in a specific page without clearing the view. * @param pageNum Page number */ reloadPage(pageNum: number): void; /** A filter value of null or undefined should be considered the same as an empty string */ private coerceFilter; /** * Attach scroll event handler and DOM observer. */ private attachEventHandlers; /** * Detach scroll event handler and DOM observer. */ private detachEventHandlers; /** * Remove any existing event subscriptions for the load button `loading` event, then attach * subscriptions * for any in the query. */ private attachLoadButtonEvents; /** * Conditionally loads a page into the collection based on directive state and request parameters. */ private doRequest; /** * Returns true if the request should be fulfilled. */ private needsData; /** * Updates state for the beginning of a load. Returns false if the `loading` event was cancelled. */ private beginLoading; private setPageItems; /** * Updates state from a successful load. Raises the `loaded` event. */ private endLoading; /** * Updates state from a failed load. Raises the `loadError` event. */ private endLoadingWithError; static ɵfac: i0.ɵɵFactoryDeclaration<InfiniteScrollDirective<any>, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<InfiniteScrollDirective<any>, "[uxInfiniteScroll]", ["uxInfiniteScroll"], { "load": { "alias": "uxInfiniteScroll"; "required": false; }; "_collection": { "alias": "collection"; "required": false; }; "scrollElement": { "alias": "scrollElement"; "required": false; }; "enabled": { "alias": "enabled"; "required": false; }; "filter": { "alias": "filter"; "required": false; }; "loadOnInit": { "alias": "loadOnInit"; "required": false; }; "loadOnScroll": { "alias": "loadOnScroll"; "required": false; }; "pageSize": { "alias": "pageSize"; "required": false; }; }, { "collectionChange": "collectionChange"; "loadingEvent": "loading"; "loadedEvent": "loaded"; "loadErrorEvent": "loadError"; }, ["_loadButtonQuery", "_loadingIndicatorQuery"], never, false, never>; } export type InfiniteScrollLoadFunction<T = any, S = any> = (pageNum: number, pageSize: number, filter: S) => T[] | Promise<T[]>; /** * Event raised before the `loading` function is called. */ export declare class InfiniteScrollLoadingEvent<S = any> { /** * The index of the requested page, starting from 0. */ pageNumber: number; /** * The number of items requested. */ pageSize: number; /** * The filter details as provided via the `filter` binding. */ filter: S; private _defaultPrevented; constructor( /** * The index of the requested page, starting from 0. */ pageNumber: number, /** * The number of items requested. */ pageSize: number, /** * The filter details as provided via the `filter` binding. */ filter: S); /** * Prevents the default behaviour of the `loading` event (loading function will not be called). */ preventDefault(): void; defaultPrevented(): boolean; } /** * Event raised when the loading function result has been resolved and added to the collection. */ export declare class InfiniteScrollLoadedEvent<T = any, S = any> { /** * The index of the requested page, starting from 0. */ pageNumber: number; /** * The number of items requested. */ pageSize: number; /** * The filter details as provided via the `filter` binding. */ filter: S; /** * The result of the promise returned from the loading function. */ data: T[]; /** * True if the data is considered exhausted (number of items returned less than `pageSize`). */ exhausted: boolean; constructor( /** * The index of the requested page, starting from 0. */ pageNumber: number, /** * The number of items requested. */ pageSize: number, /** * The filter details as provided via the `filter` binding. */ filter: S, /** * The result of the promise returned from the loading function. */ data: T[], /** * True if the data is considered exhausted (number of items returned less than `pageSize`). */ exhausted: boolean); } /** * Event raised if the loading function returns a rejected promise. */ export declare class InfiniteScrollLoadErrorEvent<S = any> { /** * The index of the requested page, starting from 0. */ pageNumber: number; /** * The number of items requested. */ pageSize: number; /** * The filter details as provided via the `filter` binding. */ filter: S; /** * The object provided when rejecting the promise. */ error: any; constructor( /** * The index of the requested page, starting from 0. */ pageNumber: number, /** * The number of items requested. */ pageSize: number, /** * The filter details as provided via the `filter` binding. */ filter: S, /** * The object provided when rejecting the promise. */ error: any); }