ng-virtual-list
Version:
🚀 High-performance virtual scrolling for Angular apps. Render 100,000+ items in Angular without breaking a sweat. Smooth, customizable, and developer-friendly.
1,260 lines (1,222 loc) • 45 kB
TypeScript
import * as _angular_core from '@angular/core';
import { WritableSignal, TemplateRef, ComponentRef, AfterViewInit, OnInit, OnDestroy } from '@angular/core';
import * as rxjs from 'rxjs';
import { Observable } from 'rxjs';
/**
* Identifier type
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/types/id.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
type Id = string | number;
/**
* Area area Interface
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/types/size.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface ISize {
/**
* Width value.
*/
width: number;
/**
* Height value.
*/
height: number;
}
/**
* Rectangular area interface
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/types/rect.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface IRect extends ISize {
/**
* X coordinate.
*/
x: number;
/**
* Y coordinate.
*/
y: number;
}
/**
* Action modes for collection elements.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/collection-modes.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare enum CollectionModes {
/**
* When adding elements to the beginning of the collection, the scroll remains at the current position.
*/
NORMAL = "normal",
/**
* When adding elements to the beginning of the collection, the scroll is shifted by the sum of the sizes of the new elements.
*/
LAZY = "lazy"
}
/**
* Action modes for collection elements.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/collection-mode.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
type CollectionMode = CollectionModes | 'normal' | 'lazy';
/**
* Axis of the arrangement of virtual list elements.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/directions.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare enum Directions {
/**
* Horizontal axis.
*/
HORIZONTAL = "horizontal",
/**
* Vertical axis.
*/
VERTICAL = "vertical"
}
/**
* Axis of the arrangement of virtual list elements.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/direction.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
type Direction = Directions | 'horizontal' | 'vertical';
/**
* Methods for selecting list items.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/methods-for-selecting.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare enum MethodsForSelecting {
/**
* List items are not selectable.
*/
NONE = "none",
/**
* List items are selected one by one.
*/
SELECT = "select",
/**
* Multiple selection of list items.
*/
MULTI_SELECT = "multi-select"
}
/**
* Methods for selecting list items.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/method-for-selecting.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
type MethodForSelecting = MethodsForSelecting | 'none' | 'select' | 'multi-select';
/**
* Snapping method.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/snapping-method.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare enum SnappingMethods {
/**
* Normal group rendering.
*/
NORMAL = "normal",
/**
* The group is rendered on a transparent background. List items below the group are not rendered.
*/
ADVANCED = "advanced"
}
/**
* Snapping method.
* 'normal' - Normal group rendering.
* 'advanced' - The group is rendered on a transparent background. List items below the group are not rendered.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/snapping-method.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
type SnappingMethod = SnappingMethods | 'normal' | 'advanced';
/**
* Focus Alignments.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/focus-alignments.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare enum FocusAlignments {
NONE = "none",
START = "start",
CENTER = "center",
END = "end"
}
/**
* Focus Alignment
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/types/focus-alignment.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
type FocusAlignment = FocusAlignments | 'none' | 'start' | 'center' | 'end';
/**
* Virtual list element model
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/item.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
type IVirtualListItem<E = Object> = E & {
/**
* Unique identifier of the element.
*/
id: Id;
[x: string]: any;
};
/**
* Object with configuration parameters for IRenderVirtualListItem
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/render-item-config.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*
*/
interface IRenderVirtualListItemConfig {
/**
* Determines whether an element is new in the collection.
*/
new: boolean;
/**
* Indicates that the element is odd.
*/
odd: boolean;
/**
* Indicates that the element is even.
*/
even: boolean;
/**
* Determines whether an element with a `sticky` property greater than zero can collapse and collapse elements in front that do not have a `sticky` property.
* Default value is `false`.
*/
collapsable: boolean;
/**
* If greater than 0, the element will have a sticky position with the given zIndex.
*/
sticky: 0 | 1 | 2;
/**
* Determines whether an element can be selected or not. Default value is `true`.
*/
selectable: boolean;
/**
* Specifies whether the element will snap.
*/
snap: boolean;
/**
* Indicates that the element is snapped.
*/
snapped: boolean;
/**
* Indicates that the element is being shifted by another snap element.
*/
snappedOut: boolean;
/**
* Indicates that the element is a vertical list item.
*/
isVertical: boolean;
/**
* Specifies that the element adapts to the size of its content.
*/
dynamic: boolean;
/**
* Returns true if the snapping method is advanced
*/
isSnappingMethodAdvanced: boolean;
/**
* Tab index.
*/
tabIndex: number;
/**
* z-index
*/
zIndex: string;
}
/**
* List screen element model
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/render-item.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface IRenderVirtualListItem<E = any> {
/**
* Element index.
*/
index: number;
/**
* Unique identifier of the element.
*/
id: Id;
/**
* Element metrics.
*/
measures: IRect & {
/**
* Delta is calculated for Snapping Method.ADVANCED
*/
delta: number;
};
/**
* Element data.
*/
data: IVirtualListItem<E>;
/**
* Object with configuration parameters for IRenderVirtualListItem.
*/
config: IRenderVirtualListItemConfig;
}
/**
* Virtual List Item Interface
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/base-virtual-list-item-component.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare abstract class BaseVirtualListItemComponent {
abstract get id(): number;
abstract data: WritableSignal<IRenderVirtualListItem | undefined>;
abstract regular: boolean;
abstract set regularLength(v: string);
abstract set item(v: IRenderVirtualListItem | null | undefined);
abstract get item(): IRenderVirtualListItem | null | undefined;
abstract get itemId(): Id | undefined;
abstract itemRenderer: WritableSignal<TemplateRef<any> | undefined>;
abstract set renderer(v: TemplateRef<any> | undefined);
abstract get element(): HTMLElement;
abstract getBounds(): ISize;
abstract show(): void;
abstract hide(): void;
}
/**
* Virtual list screen elements collection interface
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/render-collection.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface IRenderVirtualListCollection extends Array<IRenderVirtualListItem> {
}
/**
* A value of -1 indicates the direction is up or left (if the list direction is horizontal).
* A value of 1 indicates the direction is down or right (if the list direction is horizontal).
*/
type ScrollDirection = -1 | 1 | 0;
/**
* Interface IScrollEvent.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/scroll-event.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface IScrollEvent {
/**
* Scroll area offset
*/
scrollSize: number;
/**
* Full size of the scroll area
*/
scrollWeight: number;
/**
* Viewport size
*/
size: number;
/**
* Size of the list of elements
*/
listSize: number;
/**
* Specifies whether the list orientation is vertical.
*/
isVertical: boolean;
/**
* A value of -1 indicates the direction is up or left (if the list direction is horizontal).
* A value of 1 indicates the direction is down or right (if the list direction is horizontal).
*/
direction: ScrollDirection;
/**
* If true then indicates that the list has been scrolled to the end.
*/
isStart: boolean;
/**
* If true then indicates that the list has been scrolled to the end.
*/
isEnd: boolean;
/**
* Delta of marked and unmarked area
*/
delta: number;
/**
* Scroll delta
*/
scrollDelta: number;
}
/**
* Sets `sticky` position, `collapsable` and `selectable` for the list item element. If `sticky` position is greater than `0`, then `sticky` position is applied.
* If the `sticky` value is greater than `0`, then the `sticky` position mode is enabled for the element. `1` - position start, `2` - position end. Default value is `0`.
* `selectable` determines whether an element can be selected or not. Default value is `true`.
* `collapsable` determines whether an element with a `sticky` property greater than zero can collapse and collapse elements in front that do not have a `sticky` property.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/item-config-map.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface IVirtualListItemConfigMap {
[id: string | number]: {
/**
* Sets `sticky` position for the element. If sticky position is greater than `0`, then `sticky` position is applied.
* `1` - position start, `2` - position end.
* Default value is `0`.
*/
sticky?: 0 | 1 | 2;
/**
* Determines whether an element with a `sticky` property greater than zero can collapse and collapse elements in front that do not have a `sticky` property.
* Default value is `false`.
*/
collapsable?: boolean;
/**
* Determines whether an element can be selected or not.
* Default value is `true`.
*/
selectable?: boolean;
};
}
/**
* Virtual list elements collection interface
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/collection.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface IVirtualListCollection<E = Object> extends Array<IVirtualListItem<E>> {
}
/**
* Display object configuration. A set of `select`, `collapse`, and `focus` methods are also provided.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/display-object-config.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface IDisplayObjectConfig extends IRenderVirtualListItemConfig {
/**
* Determines whether the element has focused or not.
*/
focused: boolean;
/**
* Determines whether the element is selected or not.
*/
selected: boolean;
/**
* Determines whether the element is collapsed or not.
*/
collapsed: boolean;
/**
* Focus a list item
*/
focus: () => void;
/**
* Selects a list item
* @param selected - If the value is undefined, then the toggle method is executed, if false or true, then the selection/deselection is performed.
*/
select: (selected: boolean | undefined) => void;
/**
* Collapse list items
* @param collapsed - If the value is undefined, then the toggle method is executed, if false or true, then the collapse/expand is performed.
*/
collapse: (collapsed: boolean | undefined) => void;
}
/**
* Display object metrics.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/display-object-measures.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
interface IDisplayObjectMeasures extends IRect {
/**
* Delta is calculated for Snapping Method.ADVANCED
*/
delta: number;
}
type TEventHandler = (...args: Array<any>) => void;
/**
* Simple event emitter
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/utils/eventEmitter.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare class EventEmitter<E = string, H = TEventHandler> {
private _listeners;
protected _disposed: boolean;
constructor();
/**
* Emits the event
*/
dispatch(event: E, ...args: Array<any>): void;
/**
* Emits the event async
*/
dispatchAsync(event: E, ...args: Array<any>): void;
/**
* Returns true if the event listener is already subscribed.
*/
hasEventListener(eventName: E, handler: H): boolean;
/**
* Add event listener
*/
addEventListener(eventName: E, handler: H): void;
/**
* Remove event listener
*/
removeEventListener(eventName: E, handler: H): void;
/**
* Remove all listeners
*/
removeAllListeners(): void;
/**
* Method of destroying handlers
*/
dispose(): void;
}
declare class CMap<K = string, V = any> {
private _dict;
constructor(dict?: CMap<K, V>);
get(key: K): V;
set(key: K, value: V): this;
has(key: K): boolean;
delete(key: K): void;
clear(): void;
}
interface ICacheMap<I = any, B = any> {
set: (id: I, bounds: B) => CMap<I, B>;
has: (id: I) => boolean;
get: (id: I) => B | undefined;
}
declare const CACHE_BOX_CHANGE_EVENT_NAME = "change";
type CacheMapEvents$1 = typeof CACHE_BOX_CHANGE_EVENT_NAME;
type OnChangeEventListener$1 = (version: number) => void;
type CacheMapListeners$1 = OnChangeEventListener$1;
/**
* Cache map.
* Emits a change event on each mutation.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/utils/cacheMap.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare class CacheMap<I = string | number, B = any, E = CacheMapEvents$1, L = CacheMapListeners$1> extends EventEmitter<E, L> implements ICacheMap {
protected _map: CMap<I, B>;
protected _snapshot: CMap<I, B>;
protected _version: number;
protected _previousVersion: number;
protected _lifeCircleTimeout: any;
protected _delta: number;
get delta(): number;
protected _deltaDirection: ScrollDirection;
set deltaDirection(v: ScrollDirection);
get deltaDirection(): ScrollDirection;
private _scrollDirectionCache;
private _scrollDirection;
get scrollDirection(): ScrollDirection;
get version(): number;
private _clearScrollDirectionDebounce;
constructor();
protected changesDetected(): boolean;
protected stopLifeCircle(): void;
protected nextTick(cb: () => void): any;
protected lifeCircle(): void;
protected lifeCircleDo(): void;
clearScrollDirectionCache(): void;
private calcScrollDirection;
protected bumpVersion(): void;
protected fireChangeIfNeed(): void;
set(id: I, bounds: B): CMap<I, B>;
has(id: I): boolean;
get(id: I): B | undefined;
snapshot(): void;
dispose(): void;
}
type TrackingPropertyId = string | number;
/**
* Tracks display items by property
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/utils/tracker.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare class Tracker<C extends BaseVirtualListItemComponent = any> {
/**
* display objects dictionary of indexes by id
*/
protected _displayObjectIndexMapById: {
[id: number]: number;
};
set displayObjectIndexMapById(v: {
[id: number]: number;
});
get displayObjectIndexMapById(): {
[id: number]: number;
};
/**
* Dictionary displayItems propertyNameId by items propertyNameId
*/
protected _trackMap: CMap<TrackingPropertyId, number>;
get trackMap(): CMap<TrackingPropertyId, number>;
protected _trackingPropertyName: string;
set trackingPropertyName(v: string);
constructor(trackingPropertyName: string);
/**
* tracking by propName
*/
track(items: Array<any>, components: Array<ComponentRef<C>>, snapedComponent: ComponentRef<C> | null | undefined, direction: ScrollDirection): void;
untrackComponentByIdProperty(component?: C): void;
dispose(): void;
}
declare const WIDTH_PROP_NAME = "width";
declare const HEIGHT_PROP_NAME = "height";
declare enum TrackBoxEvents {
CHANGE = "change",
RESET = "reset"
}
interface IMetrics {
delta: number;
normalizedItemWidth: number;
normalizedItemHeight: number;
width: number;
height: number;
dynamicSize: boolean;
itemSize: number;
itemsFromStartToScrollEnd: number;
itemsFromStartToDisplayEnd: number;
itemsOnDisplayWeight: number;
itemsOnDisplayLength: number;
isVertical: boolean;
leftHiddenItemsWeight: number;
leftItemLength: number;
leftItemsWeight: number;
renderItems: number;
rightItemLength: number;
rightItemsWeight: number;
scrollSize: number;
leftSizeOfAddedItems: number;
sizeProperty: typeof HEIGHT_PROP_NAME | typeof WIDTH_PROP_NAME;
snap: boolean;
snippedPos: number;
startIndex: number;
startPosition: number;
totalItemsToDisplayEndWeight: number;
totalLength: number;
totalSize: number;
typicalItemSize: number;
isFromItemIdFound: boolean;
}
interface IRecalculateMetricsOptions<I extends {
id: Id;
}, C extends Array<I>> {
bounds: ISize;
collection: C;
isVertical: boolean;
itemSize: number;
bufferSize: number;
maxBufferSize: number;
dynamicSize: boolean;
scrollSize: number;
snap: boolean;
enabledBufferOptimization: boolean;
fromItemId?: Id;
previousTotalSize: number;
crudDetected: boolean;
deletedItemsMap: {
[index: number]: ISize;
};
}
interface IGetItemPositionOptions<I extends {
id: Id;
}, C extends Array<I>> extends Omit<IRecalculateMetricsOptions<I, C>, 'previousTotalSize' | 'crudDetected' | 'deletedItemsMap'> {
}
interface IUpdateCollectionOptions<I extends {
id: Id;
}, C extends Array<I>> extends Omit<IRecalculateMetricsOptions<I, C>, 'collection' | 'previousTotalSize' | 'crudDetected' | 'deletedItemsMap'> {
}
type CacheMapEvents = TrackBoxEvents.CHANGE | TrackBoxEvents.RESET;
type OnChangeEventListener = (version: number) => void;
type OnResetEventListener = (reseted: boolean) => void;
type CacheMapListeners = OnChangeEventListener | OnResetEventListener;
declare enum ItemDisplayMethods {
CREATE = 0,
UPDATE = 1,
DELETE = 2,
NOT_CHANGED = 3
}
interface IUpdateCollectionReturns {
displayItems: IRenderVirtualListCollection;
totalSize: number;
delta: number;
crudDetected: boolean;
}
type Cache = ISize & {
method?: ItemDisplayMethods;
} & {
[prop: string]: any;
};
/**
* An object that performs tracking, calculations and caching.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/utils/trackBox.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare class TrackBox<C extends BaseVirtualListItemComponent = any> extends CacheMap<Id, Cache, CacheMapEvents, CacheMapListeners> {
protected _tracker: Tracker<C>;
protected _items: IRenderVirtualListCollection | null | undefined;
set items(v: IRenderVirtualListCollection | null | undefined);
protected _displayComponents: Array<ComponentRef<C>> | null | undefined;
set displayComponents(v: Array<ComponentRef<C>> | null | undefined);
protected _snapedDisplayComponent: ComponentRef<C> | null | undefined;
set snapedDisplayComponent(v: ComponentRef<C> | null | undefined);
protected _isSnappingMethodAdvanced: boolean;
set isSnappingMethodAdvanced(v: boolean);
protected _isLazy: boolean;
set isLazy(v: boolean);
/**
* Set the trackBy property
*/
set trackingPropertyName(v: string);
protected _trackingPropertyName: string;
constructor(trackingPropertyName: string);
protected initialize(): void;
set(id: Id, bounds: ISize): CMap<Id, ISize>;
protected _previousCollection: Array<{
id: Id;
}> | null | undefined;
protected _deletedItemsMap: {
[index: number]: ISize;
};
protected _crudDetected: boolean;
get crudDetected(): boolean;
protected fireChangeIfNeed(): void;
protected _previousTotalSize: number;
protected _scrollDelta: number;
get scrollDelta(): number;
isAdaptiveBuffer: boolean;
protected _bufferSequenceExtraThreshold: number;
protected _maxBufferSequenceLength: number;
protected _bufferSizeSequence: Array<number>;
protected _bufferSize: number;
get bufferSize(): number;
protected _defaultBufferSize: number;
protected _maxBufferSize: number;
protected _resetBufferSizeTimeout: number;
protected _resetBufferSizeTimer: number | undefined;
protected isReseted: boolean;
protected lifeCircle(): void;
/**
* Scans the collection for deleted items and flushes the deleted item cache.
*/
resetCollection<I extends {
id: Id;
}, C extends Array<I>>(currentCollection: C | null | undefined, itemSize: number): void;
/**
* Update the cache of items from the list
*/
protected updateCache<I extends {
id: Id;
}, C extends Array<I>>(previousCollection: C | null | undefined, currentCollection: C | null | undefined, itemSize: number): void;
/**
* Finds the position of a collection element by the given Id
*/
getItemPosition<I extends {
id: Id;
}, C extends Array<I>>(id: Id, itemConfigMap: IVirtualListItemConfigMap, options: IGetItemPositionOptions<I, C>): number;
/**
* Updates the collection of display objects
*/
updateCollection<I extends {
id: Id;
}, C extends Array<I>>(items: C, itemConfigMap: IVirtualListItemConfigMap, options: IUpdateCollectionOptions<I, C>): IUpdateCollectionReturns;
/**
* Finds the closest element in the collection by scrollSize
*/
getNearestItem<I extends {
id: Id;
}, C extends Array<I>>(scrollSize: number, items: C, itemSize: number, isVertical: boolean): I | undefined;
protected _previousScrollSize: number;
protected updateAdaptiveBufferParams(metrics: IMetrics, totalItemsLength: number): void;
protected startResetBufferSizeTimer(): void;
protected disposeClearBufferSizeTimer(): void;
/**
* Calculates the position of an element based on the given scrollSize
*/
protected getElementFromStart<I extends {
id: Id;
}, C extends Array<I>>(scrollSize: number, collection: C, map: CMap<Id, ISize>, typicalItemSize: number, isVertical: boolean): I | undefined;
/**
* Calculates the entry into the overscroll area and returns the number of overscroll elements
*/
protected getElementNumToEnd<I extends {
id: Id;
}, C extends Array<I>>(i: number, collection: C, map: CMap<Id, ISize>, typicalItemSize: number, size: number, isVertical: boolean, indexOffset?: number): {
num: number;
offset: number;
};
/**
* Calculates list metrics
*/
protected recalculateMetrics<I extends {
id: Id;
}, C extends Array<I>>(options: IRecalculateMetricsOptions<I, C>): IMetrics;
clearDeltaDirection(): void;
clearDelta(clearDirectionDetector?: boolean): void;
changes(): void;
protected generateDisplayCollection<I extends {
id: Id;
}, C extends Array<I>>(items: C, itemConfigMap: IVirtualListItemConfigMap, metrics: IMetrics): IRenderVirtualListCollection;
/**
* tracking by propName
*/
track(): void;
setDisplayObjectIndexMapById(v: {
[id: number]: number;
}): void;
untrackComponentByIdProperty(component?: C | undefined): void;
getItemBounds(id: Id): ISize | undefined;
protected cacheElements(): void;
dispose(): void;
}
/**
* Methods for selecting list items.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/enums/method-for-selecting-types.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare enum MethodsForSelectingTypes {
/**
* List items are not selectable.
*/
NONE = 0,
/**
* List items are selected one by one.
*/
SELECT = 1,
/**
* Multiple selection of list items.
*/
MULTI_SELECT = 2
}
declare class NgVirtualListService {
private _nextComponentId;
private _$itemClick;
$itemClick: rxjs.Observable<IRenderVirtualListItem<any> | undefined>;
private _$selectedIds;
$selectedIds: rxjs.Observable<Id | Id[] | undefined>;
private _$collapsedIds;
$collapsedIds: rxjs.Observable<Id[]>;
private _$methodOfSelecting;
$methodOfSelecting: rxjs.Observable<MethodsForSelectingTypes>;
set methodOfSelecting(v: MethodsForSelectingTypes);
private _$focusedId;
$focusedId: rxjs.Observable<Id | null>;
get focusedId(): Id | null;
selectByClick: boolean;
collapseByClick: boolean;
private _trackBox;
listElement: HTMLDivElement | null;
private _$displayItems;
readonly $displayItems: rxjs.Observable<IRenderVirtualListCollection>;
private _collection;
set collection(v: IRenderVirtualListCollection);
get collection(): IRenderVirtualListCollection;
constructor();
setSelectedIds(ids: Array<Id> | Id | undefined): void;
setCollapsedIds(ids: Array<Id>): void;
itemClick(data: IRenderVirtualListItem | undefined): void;
update(): void;
/**
* Selects a list item
* @param data
* @param selected - If the value is undefined, then the toggle method is executed, if false or true, then the selection/deselection is performed.
*/
select(data: IRenderVirtualListItem | undefined, selected?: boolean | undefined): void;
/**
* Collapse list items
* @param data
* @param collapsed - If the value is undefined, then the toggle method is executed, if false or true, then the collapse/expand is performed.
*/
collapse(data: IRenderVirtualListItem | undefined, collapsed?: boolean | undefined): void;
itemToFocus: ((element: HTMLElement, position: number, align: FocusAlignment) => void) | undefined;
focus(element: HTMLElement, align?: FocusAlignment): void;
areaFocus(id: Id | null): void;
initialize(trackBox: TrackBox): void;
generateComponentId(): number;
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgVirtualListService, never>;
static ɵprov: _angular_core.ɵɵInjectableDeclaration<NgVirtualListService>;
}
/**
* Virtual list item component
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/components/ng-virtual-list-item.component.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
private _id;
get id(): number;
protected _service: NgVirtualListService;
private _isSelected;
private _isCollapsed;
config: _angular_core.WritableSignal<IDisplayObjectConfig>;
measures: _angular_core.WritableSignal<IDisplayObjectMeasures | undefined>;
focused: _angular_core.WritableSignal<boolean>;
part: _angular_core.WritableSignal<string>;
regular: boolean;
data: _angular_core.WritableSignal<IRenderVirtualListItem<any> | undefined>;
private _data;
set item(v: IRenderVirtualListItem | undefined);
private _regularLength;
set regularLength(v: string);
get item(): IRenderVirtualListItem | undefined;
get itemId(): Id | undefined;
itemRenderer: _angular_core.WritableSignal<TemplateRef<any> | undefined>;
set renderer(v: TemplateRef<any> | undefined);
private _elementRef;
get element(): HTMLElement;
private _selectHandler;
private _collapseHandler;
private _focusHandler;
constructor();
private focusNext;
private focusPrev;
private focus;
private updateMeasures;
private updateConfig;
private update;
private updatePartStr;
getBounds(): ISize;
show(): void;
hide(): void;
onClickHandler(): void;
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgVirtualListItemComponent, never>;
static ɵcmp: _angular_core.ɵɵComponentDeclaration<NgVirtualListItemComponent, "ng-virtual-list-item", never, {}, {}, never, never, true, never>;
}
/**
* Virtual list component.
* Maximum performance for extremely large lists.
* It is based on algorithms for virtualization of screen objects.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/ng-virtual-list.component.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare class NgVirtualListComponent implements AfterViewInit, OnInit, OnDestroy {
private static __nextId;
private _id;
/**
* Readonly. Returns the unique identifier of the component.
*/
get id(): number;
private _service;
private _listContainerRef;
private _snapContainerRef;
private _snappedContainer;
private _container;
private _list;
/**
* Fires when the list has been scrolled.
*/
onScroll: _angular_core.OutputEmitterRef<IScrollEvent>;
/**
* Fires when the list has completed scrolling.
*/
onScrollEnd: _angular_core.OutputEmitterRef<IScrollEvent>;
/**
* Fires when the viewport size is changed.
*/
onViewportChange: _angular_core.OutputEmitterRef<ISize>;
/**
* Fires when an element is clicked.
*/
onItemClick: _angular_core.OutputEmitterRef<IRenderVirtualListItem<any> | undefined>;
/**
* Fires when elements are selected.
*/
onSelect: _angular_core.OutputEmitterRef<Id | Id[] | undefined>;
/**
* Fires when elements are collapsed.
*/
onCollapse: _angular_core.OutputEmitterRef<Id | Id[] | undefined>;
/**
* Fires when the scroll reaches the start.
*/
onScrollReachStart: _angular_core.OutputEmitterRef<void>;
/**
* Fires when the scroll reaches the end.
*/
onScrollReachEnd: _angular_core.OutputEmitterRef<void>;
private _itemsOptions;
/**
* Collection of list items.
*/
items: _angular_core.InputSignal<IVirtualListCollection<Object>>;
private _selectedIdsOptions;
/**
* Sets the selected items.
*/
selectedIds: _angular_core.InputSignal<Id | Id[] | undefined>;
private _collapsedIdsOptions;
/**
* Sets the collapsed items.
*/
collapsedIds: _angular_core.InputSignal<Id[]>;
private _selectByClickOptions;
/**
* If `false`, the element is selected using the config.select method passed to the template;
* if `true`, the element is selected by clicking on it. The default value is `true`.
*/
selectByClick: _angular_core.InputSignal<boolean>;
private _collapseByClickOptions;
/**
* If `false`, the element is collapsed using the config.collapse method passed to the template;
* if `true`, the element is collapsed by clicking on it. The default value is `true`.
*/
collapseByClick: _angular_core.InputSignal<boolean>;
private _snapOptions;
/**
* Determines whether elements will snap. Default value is "true".
*/
snap: _angular_core.InputSignal<boolean>;
private _enabledBufferOptimizationOptions;
/**
* Experimental!
* Enables buffer optimization.
* Can only be used if items in the collection are not added or updated. Otherwise, artifacts in the form of twitching of the scroll area are possible.
* Works only if the property dynamic = true
*/
enabledBufferOptimization: _angular_core.InputSignal<boolean>;
private _itemRendererOptions;
/**
* Rendering element template.
*/
itemRenderer: _angular_core.InputSignal<TemplateRef<any>>;
private _itemRenderer;
private _itemConfigMapOptions;
/**
* Sets `sticky` position, `collapsable` and `selectable` for the list item element. If `sticky` position is greater than `0`, then `sticky` position is applied.
* If the `sticky` value is greater than `0`, then the `sticky` position mode is enabled for the element. `1` - position start, `2` - position end. Default value is `0`.
* `selectable` determines whether an element can be selected or not. Default value is `true`.
* `collapsable` determines whether an element with a `sticky` property greater than zero can collapse and collapse elements in front that do not have a `sticky` property.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/models/item-config-map.model.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
itemConfigMap: _angular_core.InputSignal<IVirtualListItemConfigMap>;
private _itemSizeOptions;
/**
* If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element.
* Ignored if the dynamicSize property is true.
*/
itemSize: _angular_core.InputSignal<number>;
private _dynamicSizeOptions;
/**
* If true then the items in the list can have different sizes and the itemSize property is ignored.
* If false then the items in the list have a fixed size specified by the itemSize property. The default value is false.
*/
dynamicSize: _angular_core.InputSignal<boolean>;
private _directionOptions;
/**
* Determines the direction in which elements are placed. Default value is "vertical".
*/
direction: _angular_core.InputSignal<Direction>;
private _collectionModeOptions;
/**
* Determines the action modes for collection elements. Default value is "normal".
*/
collectionMode: _angular_core.InputSignal<CollectionMode>;
private _bufferSizeOptions;
/**
* Number of elements outside the scope of visibility. Default value is 2.
*/
bufferSize: _angular_core.InputSignal<number>;
private _maxBufferSizeTransform;
/**
* Maximum number of elements outside the scope of visibility. Default value is 100.
* If maxBufferSize is set to be greater than bufferSize, then adaptive buffer mode is enabled.
* The greater the scroll size, the more elements are allocated for rendering.
*/
maxBufferSize: _angular_core.InputSignal<number>;
private _snappingMethodOptions;
/**
* Snapping method.
* 'default' - Normal group rendering.
* 'advanced' - The group is rendered on a transparent background. List items below the group are not rendered.
*/
snappingMethod: _angular_core.InputSignal<SnappingMethod>;
private _methodForSelectingOptions;
/**
* Method for selecting list items. Default value is 'none'.
* 'select' - List items are selected one by one.
* 'multi-select' - Multiple selection of list items.
* 'none' - List items are not selectable.
*/
methodForSelecting: _angular_core.InputSignal<MethodForSelecting>;
private _trackByOptions;
/**
* The name of the property by which tracking is performed
*/
trackBy: _angular_core.InputSignal<string>;
private _screenReaderMessageOptions;
/**
* Message for screen reader.
* The message format is: "some text $1 some text $2",
* where $1 is the number of the first element of the screen collection,
* $2 is the number of the last element of the screen collection.
*/
screenReaderMessage: _angular_core.InputSignal<string>;
readonly screenReaderFormattedMessage: WritableSignal<string>;
private _isNotSelecting;
get isNotSelecting(): boolean;
private _isSingleSelecting;
get isSingleSelecting(): boolean;
private _isMultiSelecting;
get isMultiSelecting(): boolean;
private _isSnappingMethodAdvanced;
get isSnappingMethodAdvanced(): boolean;
private _isLazy;
private _isVertical;
get orientation(): Directions;
readonly focusedElement: WritableSignal<Id | undefined>;
private _actualItems;
private _collapsedItemIds;
private _displayComponents;
private _snapedDisplayComponent;
private _bounds;
private _scrollSize;
private _isScrollStart;
private _isScrollFinished;
private _resizeObserver;
private _resizeSnappedComponentHandler;
private _resizeSnappedObserver;
private _componentsResizeObserver;
private _onResizeHandler;
private _onScrollHandler;
private itemToFocus;
private _elementRef;
private _initialized;
readonly $initialized: Observable<boolean>;
/**
* Base class of the element component
*/
private _itemComponentClass;
/**
* Base class trackBox
*/
private _trackBoxClass;
/**
* Dictionary of element sizes by their id
*/
private _trackBox;
private _onTrackBoxChangeHandler;
private _cacheVersion;
private _isResetedReachStart;
private _onTrackBoxResetHandler;
constructor();
ngOnInit(): void;
private onInit;
private listenCacheChangesIfNeed;
private getIsSnappingMethodAdvanced;
private getIsNotSelecting;
private getIsSingleSelecting;
private getIsMultiSelecting;
private getIsVertical;
private getIsLazy;
private createDisplayComponentsIfNeed;
private updateRegularRenderer;
private resetRenderers;
/**
* Tracking by id
*/
private tracking;
private resetBoundsSize;
/**
* Returns the bounds of an element with a given id
*/
getItemBounds(id: Id): ISize | undefined;
/**
* Focus an list item by a given id.
*/
focus(id: Id, align?: FocusAlignment): void;
/**
* The method scrolls the list to the element with the given id and returns the value of the scrolled area.
* Behavior accepts the values ​​"auto", "instant" and "smooth".
*/
scrollTo(id: Id, behavior?: ScrollBehavior, iteration?: number): void;
private _scrollToRepeatExecutionTimeout;
private clearScrollToRepeatExecutionTimeout;
private scrollToExecutor;
/**
* Scrolls the scroll area to the desired element with the specified ID.
*/
scrollToEnd(behavior?: ScrollBehavior, iteration?: number): void;
private _onContainerScrollHandler;
private _onContainerScrollEndHandler;
ngAfterViewInit(): void;
private afterViewInit;
ngOnDestroy(): void;
private dispose;
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgVirtualListComponent, never>;
static ɵcmp: _angular_core.ɵɵComponentDeclaration<NgVirtualListComponent, "ng-virtual-list", never, { "items": { "alias": "items"; "required": true; "isSignal": true; }; "selectedIds": { "alias": "selectedIds"; "required": false; "isSignal": true; }; "collapsedIds": { "alias": "collapsedIds"; "required": false; "isSignal": true; }; "selectByClick": { "alias": "selectByClick"; "required": false; "isSignal": true; }; "collapseByClick": { "alias": "collapseByClick"; "required": false; "isSignal": true; }; "snap": { "alias": "snap"; "required": false; "isSignal": true; }; "enabledBufferOptimization": { "alias": "enabledBufferOptimization"; "required": false; "isSignal": true; }; "itemRenderer": { "alias": "itemRenderer"; "required": true; "isSignal": true; }; "itemConfigMap": { "alias": "itemConfigMap"; "required": false; "isSignal": true; }; "itemSize": { "alias": "itemSize"; "required": false; "isSignal": true; }; "dynamicSize": { "alias": "dynamicSize"; "required": false; "isSignal": true; }; "direction": { "alias": "direction"; "required": false; "isSignal": true; }; "collectionMode": { "alias": "collectionMode"; "required": false; "isSignal": true; }; "bufferSize": { "alias": "bufferSize"; "required": false; "isSignal": true; }; "maxBufferSize": { "alias": "maxBufferSize"; "required": false; "isSignal": true; }; "snappingMethod": { "alias": "snappingMethod"; "required": false; "isSignal": true; }; "methodForSelecting": { "alias": "methodForSelecting"; "required": false; "isSignal": true; }; "trackBy": { "alias": "trackBy"; "required": false; "isSignal": true; }; "screenReaderMessage": { "alias": "screenReaderMessage"; "required": false; "isSignal": true; }; }, { "onScroll": "onScroll"; "onScrollEnd": "onScrollEnd"; "onViewportChange": "onViewportChange"; "onItemClick": "onItemClick"; "onSelect": "onSelect"; "onCollapse": "onCollapse"; "onScrollReachStart": "onScrollReachStart"; "onScrollReachEnd": "onScrollReachEnd"; }, never, never, true, never>;
}
/**
* Simple debounce function.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/utils/debounce.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare const debounce: (cb: (...args: Array<any>) => void, debounceTime?: number) => {
/**
* Call handling method
*/
execute: (...args: Array<any>) => void;
/**
* Method of destroying handlers
*/
dispose: () => void;
};
/**
* Switch css classes
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/utils/toggleClassName.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare const toggleClassName: (el: HTMLElement, className: string, removeClassName?: string) => void;
interface IScrollEventParams {
direction: ScrollDirection;
container: HTMLElement;
list: HTMLElement;
delta: number;
scrollDelta: number;
isVertical: boolean;
}
/**
* Scroll event.
* @link https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/utils/scrollEvent.ts
* @author Evgenii Grebennikov
* @email djonnyx@gmail.com
*/
declare class ScrollEvent implements IScrollEvent {
private _direction;
get direction(): ScrollDirection;
private _scrollSize;
get scrollSize(): number;
private _scrollWeight;
get scrollWeight(): number;
private _isVertical;
get isVertical(): boolean;
private _listSize;
get listSize(): number;
private _size;
get size(): number;
private _isStart;
get isStart(): boolean;
private _isEnd;
get isEnd(): boolean;
private _delta;
get delta(): number;
private _scrollDelta;
get scrollDelta(): number;
constructor(params: IScrollEventParams);
}
export { CollectionModes, Directions, FocusAlignments, MethodsForSelecting, NgVirtualListComponent, NgVirtualListItemComponent, ScrollEvent, SnappingMethods, debounce, toggleClassName };
export type { CollectionMode, Direction, FocusAlignment, IDisplayObjectConfig, IDisplayObjectMeasures, IMetrics, IRect, IRenderVirtualListItem, IScrollEvent, ISize, IVirtualListCollection, IVirtualListItem, IVirtualListItemConfigMap, Id, MethodForSelecting, ScrollDirection, SnappingMethod };