ng-virtual-list 16.2.0 → 16.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.
@@ -82,13 +82,22 @@ const SCROLL_END = 'scrollend';
82
82
  const CLASS_LIST_VERTICAL = 'vertical';
83
83
  const CLASS_LIST_HORIZONTAL = 'horizontal';
84
84
 
85
+ /**
86
+ * Virtual List Item Interface
87
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/16.x/projects/ng-virtual-list/src/lib/models/base-virtual-list-item-component.ts
88
+ * @author Evgenii Grebennikov
89
+ * @email djonnyx@gmail.com
90
+ */
91
+ class BaseVirtualListItemComponent {
92
+ }
93
+
85
94
  /**
86
95
  * Virtual list item component
87
96
  * @link https://github.com/DjonnyX/ng-virtual-list/blob/16.x/projects/ng-virtual-list/src/lib/components/ng-virtual-list-item.component.ts
88
97
  * @author Evgenii Grebennikov
89
98
  * @email djonnyx@gmail.com
90
99
  */
91
- class NgVirtualListItemComponent {
100
+ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
92
101
  _cdr;
93
102
  _elementRef;
94
103
  static __nextId = 0;
@@ -133,6 +142,7 @@ class NgVirtualListItemComponent {
133
142
  return this._elementRef.nativeElement;
134
143
  }
135
144
  constructor(_cdr, _elementRef) {
145
+ super();
136
146
  this._cdr = _cdr;
137
147
  this._elementRef = _elementRef;
138
148
  this._id = NgVirtualListItemComponent.__nextId = NgVirtualListItemComponent.__nextId === Number.MAX_SAFE_INTEGER
@@ -203,7 +213,7 @@ class NgVirtualListItemComponent {
203
213
  styles.zIndex = HIDDEN_ZINDEX;
204
214
  }
205
215
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgVirtualListItemComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
206
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: NgVirtualListItemComponent, selector: "ng-virtual-list-item", host: { classAttribute: "ngvl__item" }, ngImport: i0, template: "<ng-container *ngIf=\"data\">\r\n <li #listItem part=\"item\" class=\"ngvl-item__container\" [ngClass]=\"{'snapped': data.config.snapped,\r\n 'snapped-out': data.config.snappedOut}\">\r\n <ng-container *ngIf=\"itemRenderer\">\r\n <ng-container [ngTemplateOutlet]=\"itemRenderer\"\r\n [ngTemplateOutletContext]=\"{data: data.data || {}, config: data.config}\" />\r\n </ng-container>\r\n </li>\r\n</ng-container>", styles: [":host{display:block;position:absolute;left:0;top:0;box-sizing:border-box;overflow:hidden}.ngvl-item__container{margin:0;padding:0;overflow:hidden;background-color:#fff;width:inherit;height:inherit}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
216
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: NgVirtualListItemComponent, selector: "ng-virtual-list-item", host: { classAttribute: "ngvl__item" }, usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"data\">\r\n <li #listItem part=\"item\" class=\"ngvl-item__container\" [ngClass]=\"{'snapped': data.config.snapped,\r\n 'snapped-out': data.config.snappedOut}\">\r\n <ng-container *ngIf=\"itemRenderer\">\r\n <ng-container [ngTemplateOutlet]=\"itemRenderer\"\r\n [ngTemplateOutletContext]=\"{data: data.data || {}, config: data.config}\" />\r\n </ng-container>\r\n </li>\r\n</ng-container>", styles: [":host{display:block;position:absolute;left:0;top:0;box-sizing:border-box;overflow:hidden}.ngvl-item__container{margin:0;padding:0;overflow:hidden;background-color:#fff;width:inherit;height:inherit}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
207
217
  }
208
218
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgVirtualListItemComponent, decorators: [{
209
219
  type: Component,
@@ -1110,7 +1120,7 @@ class TrackBox extends CacheMap {
1110
1120
  }
1111
1121
  }
1112
1122
  if (deletedItemsMap.hasOwnProperty(i)) {
1113
- const bounds = deletedItemsMap[i], size = bounds[sizeProperty] ?? typicalItemSize;
1123
+ const bounds = deletedItemsMap[i], size = bounds?.[sizeProperty] ?? typicalItemSize;
1114
1124
  if (y < scrollSize - size) {
1115
1125
  leftSizeOfDeletedItems += size;
1116
1126
  }
@@ -1201,6 +1211,9 @@ class TrackBox extends CacheMap {
1201
1211
  let pos = startPosition, renderItems = renderItemsLength, stickyItem, nextSticky, stickyItemIndex = -1, stickyItemSize = 0, endStickyItem, nextEndSticky, endStickyItemIndex = -1, endStickyItemSize = 0;
1202
1212
  if (snap) {
1203
1213
  for (let i = Math.min(itemsFromStartToScrollEnd > 0 ? itemsFromStartToScrollEnd : 0, totalLength - 1); i >= 0; i--) {
1214
+ if (!items[i]) {
1215
+ continue;
1216
+ }
1204
1217
  const id = items[i].id, sticky = stickyMap[id], size = dynamicSize ? this.get(id)?.[sizeProperty] || typicalItemSize : typicalItemSize;
1205
1218
  if (sticky === 1) {
1206
1219
  const measures = {
@@ -1517,6 +1530,7 @@ class NgVirtualListComponent {
1517
1530
  get enabledBufferOptimization() { return this._$enabledBufferOptimization.getValue(); }
1518
1531
  _$itemRenderer = new BehaviorSubject(undefined);
1519
1532
  $itemRenderer = this._$itemRenderer.asObservable();
1533
+ _$renderer = new BehaviorSubject(undefined);
1520
1534
  /**
1521
1535
  * Rendering element template.
1522
1536
  */
@@ -1699,10 +1713,18 @@ class NgVirtualListComponent {
1699
1713
  };
1700
1714
  _$initialized = new BehaviorSubject(false);
1701
1715
  $initialized;
1716
+ /**
1717
+ * Base class of the element component
1718
+ */
1719
+ _itemComponentClass = NgVirtualListItemComponent;
1720
+ /**
1721
+ * Base class trackBox
1722
+ */
1723
+ _trackBoxClass = TrackBox;
1702
1724
  /**
1703
1725
  * Dictionary of element sizes by their id
1704
1726
  */
1705
- _trackBox = new TrackBox(this.trackBy);
1727
+ _trackBox = new this._trackBoxClass(this.trackBy);
1706
1728
  _onTrackBoxChangeHandler = (v) => {
1707
1729
  this._$cacheVersion.next(v);
1708
1730
  };
@@ -1762,12 +1784,19 @@ class NgVirtualListComponent {
1762
1784
  }
1763
1785
  return of(displayItems);
1764
1786
  })).subscribe();
1765
- combineLatest([this.$initialized, this.$itemRenderer]).pipe(takeUntilDestroyed(), distinctUntilChanged(), filter(([initialized]) => !!initialized), tap(([, itemRenderer]) => {
1766
- this.resetRenderers(itemRenderer);
1767
- }));
1787
+ this.setupRenderer();
1788
+ }
1789
+ setupRenderer() {
1790
+ const $itemRenderer = this.$itemRenderer;
1791
+ $itemRenderer.pipe(takeUntilDestroyed(), distinctUntilChanged(), filter(v => !!v), tap(v => {
1792
+ this._$renderer.next(v);
1793
+ })).subscribe();
1768
1794
  }
1769
1795
  /** @internal */
1770
1796
  ngOnInit() {
1797
+ this.onInit();
1798
+ }
1799
+ onInit() {
1771
1800
  this._$initialized.next(true);
1772
1801
  }
1773
1802
  listenCacheChangesIfNeed(value) {
@@ -1800,7 +1829,7 @@ class NgVirtualListComponent {
1800
1829
  }
1801
1830
  if (this._isSnappingMethodAdvanced && this.snap) {
1802
1831
  if (!this._snapedDisplayComponent && this._snapContainerRef) {
1803
- const comp = this._snapContainerRef.createComponent(NgVirtualListItemComponent);
1832
+ const comp = this._snapContainerRef.createComponent(this._itemComponentClass);
1804
1833
  comp.instance.regular = true;
1805
1834
  this._snapedDisplayComponent = comp;
1806
1835
  this._trackBox.snapedDisplayComponent = this._snapedDisplayComponent;
@@ -1813,7 +1842,7 @@ class NgVirtualListComponent {
1813
1842
  const maxLength = displayItems.length, components = this._displayComponents;
1814
1843
  while (components.length < maxLength) {
1815
1844
  if (_listContainerRef) {
1816
- const comp = _listContainerRef.createComponent(NgVirtualListItemComponent);
1845
+ const comp = _listContainerRef.createComponent(this._itemComponentClass);
1817
1846
  components.push(comp);
1818
1847
  this._componentsResizeObserver.observe(comp.instance.element);
1819
1848
  }
@@ -1950,6 +1979,9 @@ class NgVirtualListComponent {
1950
1979
  };
1951
1980
  /** @internal */
1952
1981
  ngAfterViewInit() {
1982
+ this.afterViewInit();
1983
+ }
1984
+ afterViewInit() {
1953
1985
  const containerEl = this._container;
1954
1986
  if (containerEl) {
1955
1987
  // for direction calculation
@@ -1963,6 +1995,9 @@ class NgVirtualListComponent {
1963
1995
  }
1964
1996
  /** @internal */
1965
1997
  ngOnDestroy() {
1998
+ this.dispose();
1999
+ }
2000
+ dispose() {
1966
2001
  this.clearScrollToRepeatExecutionTimeout();
1967
2002
  if (this._trackBox) {
1968
2003
  this._trackBox.dispose();
@@ -2064,5 +2099,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
2064
2099
  * Generated bundle index. Do not edit.
2065
2100
  */
2066
2101
 
2067
- export { Directions, NgVirtualListComponent, NgVirtualListModule, SnappingMethods };
2102
+ export { BaseVirtualListItemComponent, Directions, NgVirtualListComponent, NgVirtualListItemComponent, NgVirtualListModule, SnappingMethods };
2068
2103
  //# sourceMappingURL=ng-virtual-list.mjs.map