ng-virtual-list 18.2.0 → 18.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
- import { TemplateRef } from '@angular/core';
1
+ import { ChangeDetectorRef, ElementRef, TemplateRef } from '@angular/core';
2
2
  import { IRenderVirtualListItem } from '../models/render-item.model';
3
3
  import { ISize } from '../types';
4
+ import { BaseVirtualListItemComponent } from '../models';
4
5
  import * as i0 from "@angular/core";
5
6
  /**
6
7
  * Virtual list item component
@@ -8,22 +9,22 @@ import * as i0 from "@angular/core";
8
9
  * @author Evgenii Grebennikov
9
10
  * @email djonnyx@gmail.com
10
11
  */
11
- export declare class NgVirtualListItemComponent {
12
- private static __nextId;
13
- private _id;
12
+ export declare class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
13
+ protected static __nextId: number;
14
+ protected _id: number;
14
15
  get id(): number;
15
- private _cdr;
16
+ protected _cdr: ChangeDetectorRef;
16
17
  regular: boolean;
17
18
  data: import("@angular/core").WritableSignal<IRenderVirtualListItem | undefined>;
18
- private _data;
19
+ protected _data: IRenderVirtualListItem | undefined;
19
20
  set item(v: IRenderVirtualListItem | undefined);
20
- private _regularLength;
21
+ protected _regularLength: string;
21
22
  set regularLength(v: string);
22
23
  get item(): IRenderVirtualListItem | undefined;
23
24
  get itemId(): import("../types").Id | undefined;
24
25
  itemRenderer: import("@angular/core").WritableSignal<TemplateRef<any> | undefined>;
25
26
  set renderer(v: TemplateRef<any> | undefined);
26
- private _elementRef;
27
+ protected _elementRef: ElementRef<HTMLElement>;
27
28
  get element(): HTMLElement;
28
29
  constructor();
29
30
  protected update(): void;
@@ -5,4 +5,4 @@ import { Directions } from "./directions";
5
5
  * @author Evgenii Grebennikov
6
6
  * @email djonnyx@gmail.com
7
7
  */
8
- export type Direction = Directions | 'hotizontal' | 'vertical';
8
+ export type Direction = Directions | 'horizontal' | 'vertical';
@@ -0,0 +1,25 @@
1
+ import { TemplateRef, WritableSignal } from '@angular/core';
2
+ import { Id, ISize } from '../types';
3
+ import { IRenderVirtualListItem } from './render-item.model';
4
+ /**
5
+ * Virtual List Item Interface
6
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/18.x/projects/ng-virtual-list/src/lib/models/base-virtual-list-item-component.ts
7
+ * @author Evgenii Grebennikov
8
+ * @email djonnyx@gmail.com
9
+ */
10
+ export declare abstract class BaseVirtualListItemComponent {
11
+ abstract get id(): number;
12
+ abstract data: WritableSignal<IRenderVirtualListItem | undefined>;
13
+ abstract regular: boolean;
14
+ abstract set regularLength(v: string);
15
+ abstract set item(v: IRenderVirtualListItem | null | undefined);
16
+ abstract get item(): IRenderVirtualListItem | null | undefined;
17
+ abstract get itemId(): Id | undefined;
18
+ abstract itemRenderer: WritableSignal<TemplateRef<any> | undefined>;
19
+ abstract set renderer(v: TemplateRef<any> | undefined);
20
+ abstract get element(): HTMLElement;
21
+ protected abstract update(): void;
22
+ abstract getBounds(): ISize;
23
+ abstract show(): void;
24
+ abstract hide(): void;
25
+ }
@@ -5,5 +5,5 @@ import { IVirtualListItem } from "./item.model";
5
5
  * @author Evgenii Grebennikov
6
6
  * @email djonnyx@gmail.com
7
7
  */
8
- export interface IVirtualListCollection extends Array<IVirtualListItem> {
8
+ export interface IVirtualListCollection<E = Object> extends Array<IVirtualListItem<E>> {
9
9
  }
@@ -0,0 +1,3 @@
1
+ export interface Component$1<T> extends Function {
2
+ new (...args: any[]): T;
3
+ }
@@ -3,4 +3,7 @@ import { IScrollEvent } from './scroll-event.model';
3
3
  import { IVirtualListItem } from './item.model';
4
4
  import { IVirtualListStickyMap } from './sticky-map.model';
5
5
  import { IVirtualListCollection } from './collection.model';
6
- export type { ScrollDirection, IScrollEvent, IVirtualListItem, IVirtualListStickyMap, IVirtualListCollection, };
6
+ import { BaseVirtualListItemComponent } from './base-virtual-list-item-component';
7
+ import { Component$1 } from './component.model';
8
+ export type { ScrollDirection, IScrollEvent, IVirtualListItem, IVirtualListStickyMap, IVirtualListCollection, Component$1, };
9
+ export { BaseVirtualListItemComponent, };
@@ -5,10 +5,10 @@ import { Id } from "../types/id";
5
5
  * @author Evgenii Grebennikov
6
6
  * @email djonnyx@gmail.com
7
7
  */
8
- export interface IVirtualListItem {
8
+ export type IVirtualListItem<E = Object> = E & {
9
9
  /**
10
10
  * Unique identifier of the element.
11
11
  */
12
12
  id: Id;
13
13
  [x: string]: any;
14
- }
14
+ };
@@ -1,9 +1,10 @@
1
1
  import { AfterViewInit, ComponentRef, ElementRef, OnDestroy, OnInit, TemplateRef, ViewContainerRef, WritableSignal } from '@angular/core';
2
2
  import { Observable } from 'rxjs';
3
- import { NgVirtualListItemComponent } from './components/ng-virtual-list-item.component';
4
- import { IScrollEvent, IVirtualListCollection, IVirtualListStickyMap } from './models';
3
+ import { BaseVirtualListItemComponent, Component$1, IScrollEvent, IVirtualListCollection, IVirtualListStickyMap } from './models';
5
4
  import { Id, ISize } from './types';
5
+ import { IRenderVirtualListCollection } from './models/render-collection.model';
6
6
  import { Direction, SnappingMethod } from './enums';
7
+ import { TrackBox } from './utils';
7
8
  import * as i0 from "@angular/core";
8
9
  /**
9
10
  * Virtual list component.
@@ -14,8 +15,8 @@ import * as i0 from "@angular/core";
14
15
  * @email djonnyx@gmail.com
15
16
  */
16
17
  export declare class NgVirtualListComponent implements AfterViewInit, OnInit, OnDestroy {
17
- private static __nextId;
18
- private _id;
18
+ protected static __nextId: number;
19
+ protected _id: number;
19
20
  /**
20
21
  * Readonly. Returns the unique identifier of the component.
21
22
  */
@@ -33,11 +34,11 @@ export declare class NgVirtualListComponent implements AfterViewInit, OnInit, On
33
34
  * Fires when the list has completed scrolling.
34
35
  */
35
36
  onScrollEnd: import("@angular/core").OutputEmitterRef<IScrollEvent>;
36
- private _itemsOptions;
37
+ protected _itemsOptions: any;
37
38
  /**
38
39
  * Collection of list items.
39
40
  */
40
- items: import("@angular/core").InputSignal<IVirtualListCollection>;
41
+ items: import("@angular/core").InputSignal<IVirtualListCollection<Object>>;
41
42
  /**
42
43
  * Determines whether elements will snap. Default value is "true".
43
44
  */
@@ -53,12 +54,13 @@ export declare class NgVirtualListComponent implements AfterViewInit, OnInit, On
53
54
  * Rendering element template.
54
55
  */
55
56
  itemRenderer: import("@angular/core").InputSignal<TemplateRef<any>>;
57
+ protected _itemRenderer: WritableSignal<TemplateRef<any> | undefined>;
56
58
  /**
57
59
  * Dictionary zIndex by id of the list element. If the value is not set or equal to 0,
58
60
  * then a simple element is displayed, if the value is greater than 0, then the sticky position mode is enabled for the element.
59
61
  */
60
62
  stickyMap: import("@angular/core").InputSignal<IVirtualListStickyMap>;
61
- private _itemSizeOptions;
63
+ protected _itemSizeOptions: any;
62
64
  /**
63
65
  * If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element.
64
66
  * Ignored if the dynamicSize property is true.
@@ -86,41 +88,51 @@ export declare class NgVirtualListComponent implements AfterViewInit, OnInit, On
86
88
  protected _isSnappingMethodAdvanced: boolean;
87
89
  get isSnappingMethodAdvanced(): boolean;
88
90
  protected _isVertical: boolean;
89
- protected _displayComponents: Array<ComponentRef<NgVirtualListItemComponent>>;
90
- protected _snapedDisplayComponent: ComponentRef<NgVirtualListItemComponent> | undefined;
91
+ protected _displayComponents: Array<ComponentRef<BaseVirtualListItemComponent>>;
92
+ protected _snapedDisplayComponent: ComponentRef<BaseVirtualListItemComponent> | undefined;
91
93
  protected _bounds: WritableSignal<ISize | null>;
92
94
  protected _scrollSize: WritableSignal<number>;
93
- private _resizeObserver;
94
- private _resizeSnappedComponentHandler;
95
- private _resizeSnappedObserver;
96
- private _componentsResizeObserver;
97
- private _onResizeHandler;
98
- private _onScrollHandler;
99
- private _elementRef;
100
- private _initialized;
95
+ protected _resizeObserver: ResizeObserver | null;
96
+ protected _resizeSnappedComponentHandler: () => void;
97
+ protected _resizeSnappedObserver: ResizeObserver | null;
98
+ protected _componentsResizeObserver: ResizeObserver;
99
+ protected _onResizeHandler: () => void;
100
+ protected _onScrollHandler: (e?: Event) => void;
101
+ protected _elementRef: ElementRef<any>;
102
+ protected _initialized: WritableSignal<boolean>;
101
103
  readonly $initialized: Observable<boolean>;
102
104
  /**
103
105
  * The name of the property by which tracking is performed
104
106
  */
105
107
  trackBy: import("@angular/core").InputSignal<string>;
108
+ /**
109
+ * Base class of the element component
110
+ */
111
+ protected _itemComponentClass: Component$1<BaseVirtualListItemComponent>;
112
+ /**
113
+ * Base class trackBox
114
+ */
115
+ protected _trackBoxClass: Component$1<TrackBox>;
106
116
  /**
107
117
  * Dictionary of element sizes by their id
108
118
  */
109
- private _trackBox;
110
- private _onTrackBoxChangeHandler;
119
+ protected _trackBox: TrackBox;
120
+ protected _onTrackBoxChangeHandler: (v: number) => void;
111
121
  protected _cacheVersion: WritableSignal<number>;
112
122
  constructor();
113
- private listenCacheChangesIfNeed;
114
- private getIsSnappingMethodAdvanced;
115
- private getIsVertical;
116
- private createDisplayComponentsIfNeed;
117
- private updateRegularRenderer;
118
- private resetRenderers;
123
+ protected setupRenderer(): void;
124
+ protected onInit(): void;
125
+ protected listenCacheChangesIfNeed(value: boolean): void;
126
+ protected getIsSnappingMethodAdvanced(m?: SnappingMethod): boolean;
127
+ protected getIsVertical(d?: Direction): boolean;
128
+ protected createDisplayComponentsIfNeed(displayItems: IRenderVirtualListCollection | null): void;
129
+ protected updateRegularRenderer(): void;
130
+ protected resetRenderers(itemRenderer?: TemplateRef<HTMLElement>): void;
119
131
  /**
120
132
  * Tracking by id
121
133
  */
122
134
  protected tracking(): void;
123
- private resetBoundsSize;
135
+ protected resetBoundsSize(isVertical: boolean, totalSize: number): void;
124
136
  /**
125
137
  * Returns the bounds of an element with a given id
126
138
  */
@@ -130,15 +142,17 @@ export declare class NgVirtualListComponent implements AfterViewInit, OnInit, On
130
142
  * Behavior accepts the values ​​"auto", "instant" and "smooth".
131
143
  */
132
144
  scrollTo(id: Id, behavior?: ScrollBehavior): void;
133
- private _scrollToRepeatExecutionTimeout;
134
- private clearScrollToRepeatExecutionTimeout;
145
+ protected _scrollToRepeatExecutionTimeout: number | undefined;
146
+ protected clearScrollToRepeatExecutionTimeout(): void;
135
147
  protected scrollToExecutor(id: Id, behavior: ScrollBehavior, iteration?: number, isLastIteration?: boolean): void;
136
148
  /**
137
149
  * Scrolls the scroll area to the desired element with the specified ID.
138
150
  */
139
151
  scrollToEnd(behavior?: ScrollBehavior): void;
140
- private _onContainerScrollHandler;
141
- private _onContainerScrollEndHandler;
152
+ protected _onContainerScrollHandler: (e: Event) => void;
153
+ protected _onContainerScrollEndHandler: (e: Event) => void;
154
+ protected afterViewInit(): void;
155
+ protected dispose(): void;
142
156
  static ɵfac: i0.ɵɵFactoryDeclaration<NgVirtualListComponent, never>;
143
157
  static ɵcmp: i0.ɵɵComponentDeclaration<NgVirtualListComponent, "ng-virtual-list", never, { "items": { "alias": "items"; "required": true; "isSignal": true; }; "snap": { "alias": "snap"; "required": false; "isSignal": true; }; "enabledBufferOptimization": { "alias": "enabledBufferOptimization"; "required": false; "isSignal": true; }; "itemRenderer": { "alias": "itemRenderer"; "required": true; "isSignal": true; }; "stickyMap": { "alias": "stickyMap"; "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; }; "itemsOffset": { "alias": "itemsOffset"; "required": false; "isSignal": true; }; "snappingMethod": { "alias": "snappingMethod"; "required": false; "isSignal": true; }; "trackBy": { "alias": "trackBy"; "required": false; "isSignal": true; }; }, { "onScroll": "onScroll"; "onScrollEnd": "onScrollEnd"; }, never, never, false, never>;
144
158
  }
@@ -2,6 +2,8 @@ import { isDirection } from "./isDirection";
2
2
  import { debounce } from "./debounce";
3
3
  import { toggleClassName } from './toggleClassName';
4
4
  import { Tracker } from "./tracker";
5
- import { TrackBox } from "./trackBox";
5
+ import { TrackBox, IUpdateCollectionReturns, TRACK_BOX_CHANGE_EVENT_NAME, IMetrics, IRecalculateMetricsOptions, IGetItemPositionOptions, IUpdateCollectionOptions, CacheMapEvents, OnChangeEventListener, CacheMapListeners, ItemDisplayMethods } from "./trackBox";
6
+ import { CMap, ICacheMap, CACHE_BOX_CHANGE_EVENT_NAME } from './cacheMap';
6
7
  import { ScrollEvent } from "./scrollEvent";
7
- export { isDirection, debounce, toggleClassName, ScrollEvent, TrackBox, Tracker, };
8
+ export { isDirection, debounce, toggleClassName, ScrollEvent, TrackBox, Tracker, TRACK_BOX_CHANGE_EVENT_NAME, CMap, CACHE_BOX_CHANGE_EVENT_NAME, };
9
+ export type { ICacheMap, IUpdateCollectionReturns, IMetrics, IRecalculateMetricsOptions, IGetItemPositionOptions, IUpdateCollectionOptions, CacheMapEvents, OnChangeEventListener, CacheMapListeners, ItemDisplayMethods, };
@@ -1,13 +1,11 @@
1
1
  import { ComponentRef } from "@angular/core";
2
- import { NgVirtualListItemComponent } from "../components/ng-virtual-list-item.component";
3
2
  import { IRenderVirtualListCollection } from "../models/render-collection.model";
4
- import { IRenderVirtualListItem } from "../models/render-item.model";
5
3
  import { Id } from "../types/id";
6
4
  import { CacheMap, CMap } from "./cacheMap";
7
5
  import { Tracker } from "./tracker";
8
6
  import { ISize } from "../types";
9
7
  import { HEIGHT_PROP_NAME, WIDTH_PROP_NAME } from "../const";
10
- import { IVirtualListStickyMap } from "../models";
8
+ import { BaseVirtualListItemComponent, IVirtualListStickyMap } from "../models";
11
9
  export declare const TRACK_BOX_CHANGE_EVENT_NAME = "change";
12
10
  export interface IMetrics {
13
11
  delta: number;
@@ -67,16 +65,16 @@ export interface IUpdateCollectionOptions<I extends {
67
65
  id: Id;
68
66
  }, C extends Array<I>> extends Omit<IRecalculateMetricsOptions<I, C>, 'collection' | 'previousTotalSize' | 'crudDetected' | 'deletedItemsMap'> {
69
67
  }
70
- type CacheMapEvents = typeof TRACK_BOX_CHANGE_EVENT_NAME;
71
- type OnChangeEventListener = (version: number) => void;
72
- type CacheMapListeners = OnChangeEventListener;
73
- declare enum ItemDisplayMethods {
68
+ export type CacheMapEvents = typeof TRACK_BOX_CHANGE_EVENT_NAME;
69
+ export type OnChangeEventListener = (version: number) => void;
70
+ export type CacheMapListeners = OnChangeEventListener;
71
+ export declare enum ItemDisplayMethods {
74
72
  CREATE = 0,
75
73
  UPDATE = 1,
76
74
  DELETE = 2,
77
75
  NOT_CHANGED = 3
78
76
  }
79
- interface IUpdateCollectionReturns {
77
+ export interface IUpdateCollectionReturns {
80
78
  displayItems: IRenderVirtualListCollection;
81
79
  totalSize: number;
82
80
  delta: number;
@@ -88,16 +86,16 @@ interface IUpdateCollectionReturns {
88
86
  * @author Evgenii Grebennikov
89
87
  * @email djonnyx@gmail.com
90
88
  */
91
- export declare class TrackBox extends CacheMap<Id, ISize & {
89
+ export declare class TrackBox<C extends BaseVirtualListItemComponent = any> extends CacheMap<Id, ISize & {
92
90
  method?: ItemDisplayMethods;
93
91
  }, CacheMapEvents, CacheMapListeners> {
94
- protected _tracker: Tracker<IRenderVirtualListItem, NgVirtualListItemComponent>;
92
+ protected _tracker: Tracker<C>;
95
93
  protected _items: IRenderVirtualListCollection | null | undefined;
96
94
  set items(v: IRenderVirtualListCollection | null | undefined);
97
- protected _displayComponents: Array<ComponentRef<NgVirtualListItemComponent>> | null | undefined;
98
- set displayComponents(v: Array<ComponentRef<NgVirtualListItemComponent>> | null | undefined);
99
- protected _snapedDisplayComponent: ComponentRef<NgVirtualListItemComponent> | null | undefined;
100
- set snapedDisplayComponent(v: ComponentRef<NgVirtualListItemComponent> | null | undefined);
95
+ protected _displayComponents: Array<ComponentRef<C>> | null | undefined;
96
+ set displayComponents(v: Array<ComponentRef<C>> | null | undefined);
97
+ protected _snapedDisplayComponent: ComponentRef<C> | null | undefined;
98
+ set snapedDisplayComponent(v: ComponentRef<C> | null | undefined);
101
99
  protected _isSnappingMethodAdvanced: boolean;
102
100
  set isSnappingMethodAdvanced(v: boolean);
103
101
  /**
@@ -106,12 +104,16 @@ export declare class TrackBox extends CacheMap<Id, ISize & {
106
104
  set trackingPropertyName(v: string);
107
105
  constructor(trackingPropertyName: string);
108
106
  set(id: Id, bounds: ISize): CMap<Id, ISize>;
109
- private _previousCollection;
110
- private _deletedItemsMap;
111
- private _crudDetected;
107
+ protected _previousCollection: Array<{
108
+ id: Id;
109
+ }> | null | undefined;
110
+ protected _deletedItemsMap: {
111
+ [index: number]: ISize;
112
+ };
113
+ protected _crudDetected: boolean;
112
114
  get crudDetected(): boolean;
113
115
  protected fireChangeIfNeed(): void;
114
- private _previousTotalSize;
116
+ protected _previousTotalSize: number;
115
117
  protected _scrollDelta: number;
116
118
  get scrollDelta(): number;
117
119
  protected lifeCircle(): void;
@@ -148,11 +150,18 @@ export declare class TrackBox extends CacheMap<Id, ISize & {
148
150
  /**
149
151
  * Calculates the position of an element based on the given scrollSize
150
152
  */
151
- private getElementFromStart;
153
+ protected getElementFromStart<I extends {
154
+ id: Id;
155
+ }, C extends Array<I>>(scrollSize: number, collection: C, map: CMap<Id, ISize>, typicalItemSize: number, isVertical: boolean): I | undefined;
152
156
  /**
153
157
  * Calculates the entry into the overscroll area and returns the number of overscroll elements
154
158
  */
155
- private getElementNumToEnd;
159
+ protected getElementNumToEnd<I extends {
160
+ id: Id;
161
+ }, C extends Array<I>>(i: number, collection: C, map: CMap<Id, ISize>, typicalItemSize: number, size: number, isVertical: boolean, indexOffset?: number): {
162
+ num: number;
163
+ offset: number;
164
+ };
156
165
  /**
157
166
  * Calculates list metrics
158
167
  */
@@ -172,9 +181,8 @@ export declare class TrackBox extends CacheMap<Id, ISize & {
172
181
  setDisplayObjectIndexMapById(v: {
173
182
  [id: number]: number;
174
183
  }): void;
175
- untrackComponentByIdProperty(component?: NgVirtualListItemComponent | undefined): void;
184
+ untrackComponentByIdProperty(component?: C | undefined): void;
176
185
  getItemBounds(id: Id): ISize | undefined;
177
186
  protected cacheElements(): void;
178
187
  dispose(): void;
179
188
  }
180
- export {};
@@ -1,8 +1,11 @@
1
1
  import { ComponentRef } from "@angular/core";
2
- import { ScrollDirection } from "../models";
3
- interface IVirtualListItemComponent<I = any> {
2
+ import { BaseVirtualListItemComponent, ScrollDirection } from "../models";
3
+ import { Id, ISize } from "../types";
4
+ export interface IVirtualListItemComponent<I = any> {
5
+ getBounds(): ISize;
6
+ itemId: Id;
4
7
  id: number;
5
- item: I;
8
+ item: I | null;
6
9
  show: () => void;
7
10
  hide: () => void;
8
11
  }
@@ -12,7 +15,7 @@ interface IVirtualListItemComponent<I = any> {
12
15
  * @author Evgenii Grebennikov
13
16
  * @email djonnyx@gmail.com
14
17
  */
15
- export declare class Tracker<I = any, C extends IVirtualListItemComponent = any> {
18
+ export declare class Tracker<C extends BaseVirtualListItemComponent = any> {
16
19
  /**
17
20
  * display objects dictionary of indexes by id
18
21
  */
@@ -41,4 +44,3 @@ export declare class Tracker<I = any, C extends IVirtualListItemComponent = any>
41
44
  untrackComponentByIdProperty(component?: C): void;
42
45
  dispose(): void;
43
46
  }
44
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-virtual-list",
3
- "version": "18.2.0",
3
+ "version": "18.3.1",
4
4
  "author": {
5
5
  "name": "Evgenii Grebennikov",
6
6
  "email": "djonnyx@gmail.com"
package/public-api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './lib/components/ng-virtual-list-item.component';
1
2
  export * from './lib/ng-virtual-list.module';
2
3
  export * from './lib/ng-virtual-list.component';
3
4
  export * from './lib/enums';