ng-virtual-list 20.11.8 → 20.11.9

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.
package/README.md CHANGED
@@ -638,7 +638,7 @@ Inputs
638
638
  | scrollbarThumbRenderer | TemplateRef<any> \| null = null | Scrollbar customization template. |
639
639
  | scrollbarThumbParams | {[propName: string]: any;} \| null | Additional options for the scrollbar. |
640
640
  | scrollBehavior | ScrollBehavior? = 'smooth' | Defines the scrolling behavior for any element on the page. The default value is "smooth". |
641
- | scrollingSettings | [IScrollingSettings](https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/interfaces/scrolling-settings.ts) = {frictionalForce: 0.035, mass: 0.005, maxDistance: 12500, maxDuration: 4000, speedScale: 15} | Scrolling settings. |
641
+ | scrollingSettings | [IScrollingSettings](https://github.com/DjonnyX/ng-virtual-list/blob/20.x/projects/ng-virtual-list/src/lib/interfaces/scrolling-settings.ts) = {frictionalForce: 0.035, mass: 0.005, maxDistance: 12500, maxDuration: 4000, speedScale: 15, optimization: true} | Scrolling settings. |
642
642
  | trackBy | string? = 'id' | The name of the property by which tracking is performed. |
643
643
 
644
644
  <br/>
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, inject, signal, ElementRef, DestroyRef, computed, output, Input, Directive, Injector, ChangeDetectionStrategy, Component, InjectionToken, viewChild, input, ViewChild, effect, ViewContainerRef, ViewEncapsulation, NO_ERRORS_SCHEMA, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
2
+ import { Injectable, inject, signal, ElementRef, DestroyRef, computed, output, Input, Directive, Injector, ChangeDetectionStrategy, Component, InjectionToken, viewChild, input, ViewChild, effect, ViewContainerRef, ViewEncapsulation, NO_ERRORS_SCHEMA, NgModule } from '@angular/core';
3
3
  import { Subject, BehaviorSubject, tap, fromEvent, race, of, debounceTime, switchMap as switchMap$1, combineLatest, map, filter as filter$1, takeUntil as takeUntil$1, startWith, from, take, delay, distinctUntilChanged, skip } from 'rxjs';
4
4
  import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
5
5
  import { BehaviorSubject as BehaviorSubject$1 } from 'rxjs/internal/BehaviorSubject';
@@ -196,6 +196,7 @@ const DEFAULT_SCROLLING_SETTINGS = {
196
196
  mass: 0.005,
197
197
  maxDistance: 12500,
198
198
  speedScale: 15,
199
+ optimization: true,
199
200
  };
200
201
  const DEFAULT_OVERSCROLL_ENABLED = true;
201
202
  const DEFAULT_SNAP = false;
@@ -2479,6 +2480,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
2479
2480
  */
2480
2481
  class BaseVirtualListItemComponent {
2481
2482
  _apiService = inject(NgVirtualListPublicService);
2483
+ _service = inject(NgVirtualListService);
2482
2484
  _id;
2483
2485
  get id() {
2484
2486
  return this._id;
@@ -2544,6 +2546,9 @@ class BaseVirtualListItemComponent {
2544
2546
  }
2545
2547
  _destroyRef = inject(DestroyRef);
2546
2548
  constructor() {
2549
+ this._id = this._service.generateComponentId();
2550
+ this._listId = this._service.id;
2551
+ this._displayId = createDisplayId(this._listId, this._id);
2547
2552
  this.classes = computed(() => {
2548
2553
  const data = this.data(), focused = this.focused();
2549
2554
  return {
@@ -2725,14 +2730,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
2725
2730
  * @email djonnyx@gmail.com
2726
2731
  */
2727
2732
  class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
2728
- _service = inject(NgVirtualListService);
2729
2733
  maxClickDistance = signal(DEFAULT_CLICK_DISTANCE, ...(ngDevMode ? [{ debugName: "maxClickDistance" }] : []));
2730
2734
  _injector = inject(Injector);
2731
2735
  constructor() {
2732
2736
  super();
2733
- this._id = this._service.generateComponentId();
2734
- this._listId = this._service.id;
2735
- this._displayId = createDisplayId(this._listId, this._id);
2736
2737
  }
2737
2738
  ngOnInit() {
2738
2739
  this._service.$clickDistance.pipe(takeUntilDestroyed(this._destroyRef), tap(v => {
@@ -5188,7 +5189,7 @@ class NgVirtualListComponent {
5188
5189
  transform: (v) => {
5189
5190
  let valid = validateObject(v, true, true);
5190
5191
  if (valid && !!v) {
5191
- const { frictionalForce, mass, maxDistance, maxDuration, speedScale } = v;
5192
+ const { frictionalForce, mass, maxDistance, maxDuration, speedScale, optimization } = v;
5192
5193
  valid = validateFloat(frictionalForce, true);
5193
5194
  if (!valid) {
5194
5195
  console.error('The "frictionalForce" parameter must be of type `number` or `undefined`.');
@@ -5214,6 +5215,11 @@ class NgVirtualListComponent {
5214
5215
  console.error('The "speedScale" parameter must be of type `number` or `undefined`.');
5215
5216
  return DEFAULT_SCROLLING_SETTINGS;
5216
5217
  }
5218
+ valid = validateBoolean(optimization, true);
5219
+ if (!valid) {
5220
+ console.error('The "optimization" parameter must be of type `boolean` or `undefined`.');
5221
+ return DEFAULT_SCROLLING_SETTINGS;
5222
+ }
5217
5223
  }
5218
5224
  if (!valid) {
5219
5225
  console.error('The "scrollingSettings" parameter must be of type `object` or null.');
@@ -5225,6 +5231,7 @@ class NgVirtualListComponent {
5225
5231
  maxDistance: v.maxDistance !== undefined && v.maxDistance > 0 ? v.maxDistance : DEFAULT_SCROLLING_SETTINGS.maxDistance,
5226
5232
  maxDuration: v.maxDuration !== undefined && v.maxDuration > 0 ? v.maxDuration : DEFAULT_SCROLLING_SETTINGS.maxDuration,
5227
5233
  speedScale: v.speedScale !== undefined && v.speedScale > 0 ? v.speedScale : DEFAULT_SCROLLING_SETTINGS.speedScale,
5234
+ optimization: v.optimization ?? DEFAULT_SCROLLING_SETTINGS.optimization,
5228
5235
  };
5229
5236
  },
5230
5237
  };
@@ -5235,6 +5242,7 @@ class NgVirtualListComponent {
5235
5242
  * - maxDistance - Maximum scrolling distance. Default value is 12500.
5236
5243
  * - maxDuration - Maximum animation duration. Default value is 4000.
5237
5244
  * - speedScale - Speed scale. Default value is 15.
5245
+ * - optimization - Enables scrolling performance optimization. Default value is `true`.
5238
5246
  */
5239
5247
  scrollingSettings = input(DEFAULT_SCROLLING_SETTINGS, ...(ngDevMode ? [{ debugName: "scrollingSettings", ...this._scrollingSettingsOptions }] : [{ ...this._scrollingSettingsOptions }]));
5240
5248
  _animationParamsOptions = {
@@ -6254,16 +6262,18 @@ class NgVirtualListComponent {
6254
6262
  itemsChanged = true;
6255
6263
  prevItems = items;
6256
6264
  }
6257
- const scroller = this._scrollerComponent(), velocity = this._scrollerComponent()?.averageVelocity ?? 0, maxScrollSize = isVertical ? (scroller?.scrollHeight || 0) : (scroller?.scrollWidth ?? 0), isEdges = scrollSize === 0 || scrollSize === maxScrollSize, isScrolling = this._$scrollingTo.getValue(), useDebouncedUpdate = dynamicSize && !itemsChanged && hasUserAction && !isScrolling && (velocity > 0 && velocity < MAX_VELOCITY_FOR_SCROLL_QUALITY_OPTIMIZATION_LVL1), rerenderOptimization = dynamicSize && !itemsChanged && (hasUserAction || hasScrollbarUserAction) && !isEdges && velocity > 0 &&
6265
+ const enabledOptimization = this.scrollingSettings()?.optimization ?? DEFAULT_SCROLLING_SETTINGS.optimization, scroller = this._scrollerComponent(), velocity = this._scrollerComponent()?.averageVelocity ?? 0, maxScrollSize = isVertical ? (scroller?.scrollHeight || 0) : (scroller?.scrollWidth ?? 0), isEdges = scrollSize === 0 || scrollSize === maxScrollSize, isScrolling = this._$scrollingTo.getValue(), useDebouncedUpdate = dynamicSize && !itemsChanged && hasUserAction && !isScrolling && (velocity > 0 && velocity < MAX_VELOCITY_FOR_SCROLL_QUALITY_OPTIMIZATION_LVL1), rerenderOptimization = enabledOptimization && dynamicSize && !itemsChanged && (hasUserAction || hasScrollbarUserAction) && !isEdges && velocity > 0 &&
6258
6266
  (velocity > MAX_VELOCITY_FOR_SCROLL_QUALITY_OPTIMIZATION_LVL2 || hasUserAction);
6259
- if (useDebouncedUpdate) {
6260
- debouncedUpdate.execute({
6261
- snapScrollToStart, snapScrollToEnd, bounds, listBounds, scrollEndOffset, items, itemConfigMap, scrollSize, itemSize, collapsedIds,
6262
- bufferSize, maxBufferSize, snap, isVertical, dynamicSize, enabledBufferOptimization, cacheVersion, userAction: hasUserAction,
6263
- }, rerenderOptimization, itemsChanged);
6264
- return;
6267
+ if (enabledOptimization) {
6268
+ if (useDebouncedUpdate) {
6269
+ debouncedUpdate.execute({
6270
+ snapScrollToStart, snapScrollToEnd, bounds, listBounds, scrollEndOffset, items, itemConfigMap, scrollSize, itemSize, collapsedIds,
6271
+ bufferSize, maxBufferSize, snap, isVertical, dynamicSize, enabledBufferOptimization, cacheVersion, userAction: hasUserAction,
6272
+ }, rerenderOptimization, itemsChanged);
6273
+ return;
6274
+ }
6275
+ debouncedUpdate.dispose();
6265
6276
  }
6266
- debouncedUpdate.dispose();
6267
6277
  if (!isScrolling) {
6268
6278
  update({
6269
6279
  snapScrollToStart, snapScrollToEnd, bounds, listBounds, scrollEndOffset, items, itemConfigMap, scrollSize, itemSize, collapsedIds,
@@ -6902,7 +6912,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
6902
6912
  declarations: [NgVirtualListItemComponent],
6903
6913
  exports: [NgVirtualListItemComponent],
6904
6914
  imports: [CommonModule, ItemClickModule],
6905
- schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
6915
+ schemas: [NO_ERRORS_SCHEMA],
6906
6916
  }]
6907
6917
  }] });
6908
6918
 
@@ -6917,7 +6927,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
6917
6927
  declarations: [NgScrollBarComponent],
6918
6928
  exports: [NgScrollBarComponent],
6919
6929
  imports: [CommonModule],
6920
- schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
6930
+ schemas: [NO_ERRORS_SCHEMA],
6921
6931
  }]
6922
6932
  }] });
6923
6933
 
@@ -6932,7 +6942,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
6932
6942
  declarations: [NgScrollerComponent],
6933
6943
  exports: [NgScrollerComponent],
6934
6944
  imports: [CommonModule, NgScrollBarModule, LocaleSensitiveModule, CdkScrollableModule],
6935
- schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
6945
+ schemas: [NO_ERRORS_SCHEMA],
6936
6946
  }]
6937
6947
  }] });
6938
6948
 
@@ -6947,7 +6957,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
6947
6957
  declarations: [NgPrerenderVirtualListItemComponent],
6948
6958
  exports: [NgPrerenderVirtualListItemComponent],
6949
6959
  imports: [CommonModule, ItemClickModule],
6950
- schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
6960
+ schemas: [NO_ERRORS_SCHEMA],
6951
6961
  }]
6952
6962
  }] });
6953
6963
 
@@ -6962,7 +6972,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
6962
6972
  declarations: [NgPrerenderScrollerComponent],
6963
6973
  exports: [NgPrerenderScrollerComponent],
6964
6974
  imports: [CommonModule, LocaleSensitiveModule],
6965
- schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
6975
+ schemas: [NO_ERRORS_SCHEMA],
6966
6976
  }]
6967
6977
  }] });
6968
6978