ng-virtual-list 14.2.0 → 14.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.
@@ -81,14 +81,24 @@ const SCROLL_END = 'scrollend';
81
81
  const CLASS_LIST_VERTICAL = 'vertical';
82
82
  const CLASS_LIST_HORIZONTAL = 'horizontal';
83
83
 
84
+ /**
85
+ * Virtual List Item Interface
86
+ * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/models/base-virtual-list-item-component.ts
87
+ * @author Evgenii Grebennikov
88
+ * @email djonnyx@gmail.com
89
+ */
90
+ class BaseVirtualListItemComponent {
91
+ }
92
+
84
93
  /**
85
94
  * Virtual list item component
86
95
  * @link https://github.com/DjonnyX/ng-virtual-list/blob/14.x/projects/ng-virtual-list/src/lib/components/ng-virtual-list-item.component.ts
87
96
  * @author Evgenii Grebennikov
88
97
  * @email djonnyx@gmail.com
89
98
  */
90
- class NgVirtualListItemComponent {
99
+ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
91
100
  constructor(_cdr, _elementRef) {
101
+ super();
92
102
  this._cdr = _cdr;
93
103
  this._elementRef = _elementRef;
94
104
  this.regular = false;
@@ -200,7 +210,7 @@ class NgVirtualListItemComponent {
200
210
  }
201
211
  NgVirtualListItemComponent.__nextId = 0;
202
212
  NgVirtualListItemComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NgVirtualListItemComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
203
- NgVirtualListItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", 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}\"></ng-container>\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;will-change:scroll-position}.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 });
213
+ NgVirtualListItemComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", 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}\"></ng-container>\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;will-change:scroll-position}.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 });
204
214
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NgVirtualListItemComponent, decorators: [{
205
215
  type: Component,
206
216
  args: [{ selector: 'ng-virtual-list-item', host: {
@@ -1090,7 +1100,7 @@ class TrackBox extends CacheMap {
1090
1100
  }
1091
1101
  }
1092
1102
  if (deletedItemsMap.hasOwnProperty(i)) {
1093
- const bounds = deletedItemsMap[i], size = (_d = bounds[sizeProperty]) !== null && _d !== void 0 ? _d : typicalItemSize;
1103
+ const bounds = deletedItemsMap[i], size = (_d = bounds === null || bounds === void 0 ? void 0 : bounds[sizeProperty]) !== null && _d !== void 0 ? _d : typicalItemSize;
1094
1104
  if (y < scrollSize - size) {
1095
1105
  leftSizeOfDeletedItems += size;
1096
1106
  }
@@ -1182,6 +1192,9 @@ class TrackBox extends CacheMap {
1182
1192
  let pos = startPosition, renderItems = renderItemsLength, stickyItem, nextSticky, stickyItemIndex = -1, stickyItemSize = 0, endStickyItem, nextEndSticky, endStickyItemIndex = -1, endStickyItemSize = 0;
1183
1193
  if (snap) {
1184
1194
  for (let i = Math.min(itemsFromStartToScrollEnd > 0 ? itemsFromStartToScrollEnd : 0, totalLength - 1); i >= 0; i--) {
1195
+ if (!items[i]) {
1196
+ continue;
1197
+ }
1185
1198
  const id = items[i].id, sticky = stickyMap[id], size = dynamicSize ? ((_a = this.get(id)) === null || _a === void 0 ? void 0 : _a[sizeProperty]) || typicalItemSize : typicalItemSize;
1186
1199
  if (sticky === 1) {
1187
1200
  const measures = {
@@ -1476,6 +1489,7 @@ class NgVirtualListComponent extends DisposableComponent {
1476
1489
  this.$enabledBufferOptimization = this._$enabledBufferOptimization.asObservable();
1477
1490
  this._$itemRenderer = new BehaviorSubject(undefined);
1478
1491
  this.$itemRenderer = this._$itemRenderer.asObservable();
1492
+ this._$renderer = new BehaviorSubject(undefined);
1479
1493
  this._$stickyMap = new BehaviorSubject({});
1480
1494
  this.$stickyMap = this._$stickyMap.asObservable();
1481
1495
  this._itemSizeOptions = (v) => {
@@ -1560,10 +1574,18 @@ class NgVirtualListComponent extends DisposableComponent {
1560
1574
  }
1561
1575
  };
1562
1576
  this._$initialized = new BehaviorSubject(false);
1577
+ /**
1578
+ * Base class of the element component
1579
+ */
1580
+ this._itemComponentClass = NgVirtualListItemComponent;
1581
+ /**
1582
+ * Base class trackBox
1583
+ */
1584
+ this._trackBoxClass = TrackBox;
1563
1585
  /**
1564
1586
  * Dictionary of element sizes by their id
1565
1587
  */
1566
- this._trackBox = new TrackBox(this.trackBy);
1588
+ this._trackBox = new this._trackBoxClass(this.trackBy);
1567
1589
  this._onTrackBoxChangeHandler = (v) => {
1568
1590
  this._$cacheVersion.next(v);
1569
1591
  };
@@ -1649,9 +1671,7 @@ class NgVirtualListComponent extends DisposableComponent {
1649
1671
  }
1650
1672
  return of(displayItems);
1651
1673
  })).subscribe();
1652
- combineLatest([this.$initialized, this.$itemRenderer]).pipe(takeUntil(this._$unsubscribe), distinctUntilChanged(), filter(([initialized]) => !!initialized), tap(([, itemRenderer]) => {
1653
- this.resetRenderers(itemRenderer);
1654
- }));
1674
+ this.setupRenderer();
1655
1675
  }
1656
1676
  /**
1657
1677
  * Readonly. Returns the unique identifier of the component.
@@ -1797,8 +1817,17 @@ class NgVirtualListComponent extends DisposableComponent {
1797
1817
  get snappingMethod() { return this._$snappingMethod.getValue(); }
1798
1818
  get isSnappingMethodAdvanced() { return this._isSnappingMethodAdvanced; }
1799
1819
  get $cacheVersion() { return this._$cacheVersion.asObservable(); }
1820
+ setupRenderer() {
1821
+ const $itemRenderer = this.$itemRenderer;
1822
+ $itemRenderer.pipe(takeUntil(this._$unsubscribe), distinctUntilChanged(), filter(v => !!v), tap(v => {
1823
+ this._$renderer.next(v);
1824
+ })).subscribe();
1825
+ }
1800
1826
  /** @internal */
1801
1827
  ngOnInit() {
1828
+ this.onInit();
1829
+ }
1830
+ onInit() {
1802
1831
  this._$initialized.next(true);
1803
1832
  }
1804
1833
  listenCacheChangesIfNeed(value) {
@@ -1828,7 +1857,7 @@ class NgVirtualListComponent extends DisposableComponent {
1828
1857
  }
1829
1858
  if (this._isSnappingMethodAdvanced && this.snap) {
1830
1859
  if (!this._snapedDisplayComponent && this._snapContainerRef) {
1831
- const comp = this._snapContainerRef.createComponent(NgVirtualListItemComponent);
1860
+ const comp = this._snapContainerRef.createComponent(this._itemComponentClass);
1832
1861
  comp.instance.regular = true;
1833
1862
  this._snapedDisplayComponent = comp;
1834
1863
  this._trackBox.snapedDisplayComponent = this._snapedDisplayComponent;
@@ -1841,7 +1870,7 @@ class NgVirtualListComponent extends DisposableComponent {
1841
1870
  const maxLength = displayItems.length, components = this._displayComponents;
1842
1871
  while (components.length < maxLength) {
1843
1872
  if (_listContainerRef) {
1844
- const comp = _listContainerRef.createComponent(NgVirtualListItemComponent);
1873
+ const comp = _listContainerRef.createComponent(this._itemComponentClass);
1845
1874
  components.push(comp);
1846
1875
  this._componentsResizeObserver.observe(comp.instance.element);
1847
1876
  }
@@ -1949,6 +1978,9 @@ class NgVirtualListComponent extends DisposableComponent {
1949
1978
  }
1950
1979
  /** @internal */
1951
1980
  ngAfterViewInit() {
1981
+ this.afterViewInit();
1982
+ }
1983
+ afterViewInit() {
1952
1984
  const containerEl = this._container;
1953
1985
  if (containerEl) {
1954
1986
  // for direction calculation
@@ -1963,6 +1995,9 @@ class NgVirtualListComponent extends DisposableComponent {
1963
1995
  /** @internal */
1964
1996
  ngOnDestroy() {
1965
1997
  super.ngOnDestroy();
1998
+ this.dispose();
1999
+ }
2000
+ dispose() {
1966
2001
  this.clearScrollToRepeatExecutionTimeout();
1967
2002
  if (this._trackBox) {
1968
2003
  this._trackBox.dispose();
@@ -2065,5 +2100,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
2065
2100
  * Generated bundle index. Do not edit.
2066
2101
  */
2067
2102
 
2068
- export { Directions, NgVirtualListComponent, NgVirtualListModule, SnappingMethods };
2103
+ export { BaseVirtualListItemComponent, Directions, NgVirtualListComponent, NgVirtualListItemComponent, NgVirtualListModule, SnappingMethods };
2069
2104
  //# sourceMappingURL=ng-virtual-list.mjs.map