ng-virtual-list 20.10.17 → 20.10.19

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.
@@ -7,7 +7,7 @@ import * as i1 from '@angular/common';
7
7
  import { CommonModule } from '@angular/common';
8
8
  import { switchMap, takeUntil, filter, tap as tap$1 } from 'rxjs/operators';
9
9
  import * as i4 from '@angular/cdk/scrolling';
10
- import { CdkScrollable } from '@angular/cdk/scrolling';
10
+ import { CdkScrollable, CdkScrollableModule } from '@angular/cdk/scrolling';
11
11
 
12
12
  /**
13
13
  * Action modes for collection elements.
@@ -4056,7 +4056,8 @@ class NgScrollerComponent extends NgScrollView {
4056
4056
  constructor() {
4057
4057
  super();
4058
4058
  this._service.$langTextDir.pipe(tap(v => {
4059
- this.langTextDir.set(v);
4059
+ takeUntilDestroyed(this._destroyRef),
4060
+ this.langTextDir.set(v);
4060
4061
  })).subscribe();
4061
4062
  const $prepare = toObservable(this.preparedSignal);
4062
4063
  $prepare.pipe(takeUntilDestroyed(), filter$1(v => !!v), tap(() => {
@@ -4222,6 +4223,9 @@ class NgScrollerComponent extends NgScrollView {
4222
4223
  onScrollBarDragHandler(event) {
4223
4224
  const { position, min, max, userAction } = event;
4224
4225
  this._isScrollbarUserAction = userAction;
4226
+ if (!userAction) {
4227
+ return;
4228
+ }
4225
4229
  this._$scrollbarScroll.next(userAction);
4226
4230
  this.stopScrolling();
4227
4231
  const isVertical = this.isVertical(), { position: absolutePosition, } = this._scrollBox.getScrollPositionByScrollBar({
@@ -4236,10 +4240,13 @@ class NgScrollerComponent extends NgScrollView {
4236
4240
  this.fireUpdateIfEdgesDetected(position, min, max, true, true);
4237
4241
  }
4238
4242
  onScrollBarDragEndHandler(event) {
4239
- const { position, min, max } = event;
4243
+ const { position, min, max, userAction } = event;
4240
4244
  this._isScrollbarUserAction = false;
4241
4245
  this._velocities = [0];
4242
4246
  this._velocity = 0;
4247
+ if (!userAction) {
4248
+ return;
4249
+ }
4243
4250
  this.refresh(true, true);
4244
4251
  this.fireUpdateIfEdgesDetected(position, min, max, true, true);
4245
4252
  this._$scrollbarScroll.next(false);
@@ -6082,13 +6089,13 @@ class NgVirtualListComponent {
6082
6089
  this.listenCacheChangesIfNeed(dynamicSize);
6083
6090
  })).subscribe();
6084
6091
  const $preventScrollSnapping = this.$preventScrollSnapping;
6085
- $preventScrollSnapping.pipe(takeUntilDestroyed(), filter$1(v => !!v), tap((v) => {
6092
+ $preventScrollSnapping.pipe(takeUntilDestroyed(), filter$1(v => !!v), tap(() => {
6086
6093
  if (this._readyForShow) {
6087
6094
  this._trackBox.isScrollStart = this._trackBox.isScrollEnd = false;
6088
6095
  this._isScrollStart.set(false);
6089
6096
  this._isScrollEnd.set(false);
6090
6097
  const scroller = this._scrollerComponent();
6091
- if (scroller) {
6098
+ if (!!scroller) {
6092
6099
  this._trackBox.preventScrollSnapping(true);
6093
6100
  }
6094
6101
  }
@@ -6126,19 +6133,19 @@ class NgVirtualListComponent {
6126
6133
  const isVertical = this.isVertical, maxScrollSize = Math.round(isVertical ? scroller.scrollHeight ?? 0 : scroller.scrollWidth ?? 0), scrollSize = isVertical ? scroller.scrollTop ?? 0 : scroller.scrollLeft ?? 0, actualScrollSize = Math.round(scrollSize + delta);
6127
6134
  if (this._readyForShow && !isLoading) {
6128
6135
  if (maxScrollSize >= 0) {
6129
- const isScrollStart = actualScrollSize <= MIN_PIXELS_FOR_PREVENT_SNAPPING;
6136
+ const isScrollStart = (actualScrollSize <= MIN_PIXELS_FOR_PREVENT_SNAPPING);
6130
6137
  if (isScrollStart) {
6131
- this._trackBox.isScrollStart = true;
6132
6138
  this._isScrollStart.set(true);
6133
- this._trackBox.isScrollEnd = false;
6134
6139
  this._isScrollEnd.set(false);
6140
+ this._trackBox.isScrollStart = true;
6141
+ this._trackBox.isScrollEnd = false;
6135
6142
  }
6136
6143
  else {
6137
- const isScrollEnd = actualScrollSize >= (maxScrollSize - MIN_PIXELS_FOR_PREVENT_SNAPPING);
6138
- this._trackBox.isScrollStart = false;
6144
+ const isScrollEnd = (actualScrollSize >= (maxScrollSize - MIN_PIXELS_FOR_PREVENT_SNAPPING));
6139
6145
  this._isScrollStart.set(false);
6140
- this._trackBox.isScrollEnd = isScrollEnd;
6141
6146
  this._isScrollEnd.set(isScrollEnd);
6147
+ this._trackBox.isScrollStart = false;
6148
+ this._trackBox.isScrollEnd = isScrollEnd;
6142
6149
  }
6143
6150
  }
6144
6151
  }
@@ -6199,10 +6206,9 @@ class NgVirtualListComponent {
6199
6206
  }
6200
6207
  return;
6201
6208
  }
6202
- if ((snapScrollToEnd && this._trackBox.isSnappedToEnd) ||
6203
- (snapScrollToEnd && scrollPositionAfterUpdate > 0 &&
6204
- ((roundedScrollPositionAfterUpdate >= scrollPositionAfterUpdate + MIN_PIXELS_FOR_PREVENT_SNAPPING) &&
6205
- (scrollPositionAfterUpdate + MIN_PIXELS_FOR_PREVENT_SNAPPING >= roundedMaxPositionAfterUpdate)))) {
6209
+ if ((snapScrollToEnd && this._trackBox.isSnappedToEnd) || (!snapScrollToStart && snapScrollToEnd && !scroller.scrollable) ||
6210
+ (scrollPositionAfterUpdate + MIN_PIXELS_FOR_PREVENT_SNAPPING >= roundedMaxPositionAfterUpdate) ||
6211
+ (roundedScrollPositionAfterUpdate >= scrollPositionAfterUpdate + MIN_PIXELS_FOR_PREVENT_SNAPPING)) {
6206
6212
  this._trackBox.clearDelta();
6207
6213
  if (!this._trackBox.isSnappedToEnd) {
6208
6214
  this._trackBox.isScrollStart = false;
@@ -6666,17 +6672,13 @@ class NgVirtualListComponent {
6666
6672
  validateIteration(iteration);
6667
6673
  const actualIteration = validateScrollIteration(iteration);
6668
6674
  this._elementRef.nativeElement.focus();
6675
+ if (!this._scrollerComponent()?.scrollable) {
6676
+ this.scrollToFinalize(id, focused, cb);
6677
+ return;
6678
+ }
6669
6679
  this._$scrollTo.next({
6670
6680
  id, behavior, blending, iteration: actualIteration, isLastIteration: actualIteration === MAX_SCROLL_TO_ITERATIONS, cb: () => {
6671
- if (focused) {
6672
- const el = this.getFocusedElementById(id);
6673
- if (!!el) {
6674
- this._service.focus(el, FocusAlignments.NONE);
6675
- }
6676
- }
6677
- if (typeof cb === 'function') {
6678
- cb?.();
6679
- }
6681
+ this.scrollToFinalize(id, focused, cb);
6680
6682
  }
6681
6683
  });
6682
6684
  }
@@ -6691,8 +6693,8 @@ class NgVirtualListComponent {
6691
6693
  const behavior = options?.behavior ?? BEHAVIOR_INSTANT, blending = options?.blending ?? false, focused = options?.focused ?? true, iteration = options?.iteration ?? 0;
6692
6694
  validateScrollBehavior(behavior);
6693
6695
  validateIteration(iteration);
6694
- const trackBy = this.trackBy(), items = this.items(), firsItem = items.length > 0 ? items[0] : undefined, id = firsItem?.[trackBy], actualIteration = validateScrollIteration(iteration);
6695
- if (!!firsItem) {
6696
+ const trackBy = this.trackBy(), items = this.items(), firstItem = items.length > 0 ? items[0] ?? null : null, id = firstItem?.[trackBy] ?? null, actualIteration = validateScrollIteration(iteration);
6697
+ if (!!firstItem) {
6696
6698
  this._elementRef.nativeElement.focus();
6697
6699
  this._$scrollTo.next({
6698
6700
  id, behavior, blending, iteration: actualIteration, isLastIteration: actualIteration === MAX_SCROLL_TO_ITERATIONS, cb: () => {
@@ -6700,15 +6702,7 @@ class NgVirtualListComponent {
6700
6702
  this._trackBox.isScrollStart = true;
6701
6703
  this._trackBox.isScrollEnd = false;
6702
6704
  this._$fireUpdate.next(true);
6703
- if (focused) {
6704
- const el = this.getFocusedElementById(id);
6705
- if (!!el) {
6706
- this._service.focus(el, FocusAlignments.NONE);
6707
- }
6708
- }
6709
- if (typeof cb === 'function') {
6710
- cb?.();
6711
- }
6705
+ this.scrollToFinalize(id, focused, cb);
6712
6706
  }
6713
6707
  });
6714
6708
  }
@@ -6733,24 +6727,31 @@ class NgVirtualListComponent {
6733
6727
  validateIteration(iteration);
6734
6728
  const trackBy = this.trackBy(), items = this.items(), latItem = items[items.length > 0 ? items.length - 1 : 0], id = latItem[trackBy], actualIteration = validateScrollIteration(iteration);
6735
6729
  this._elementRef.nativeElement.focus();
6730
+ if (!this._scrollerComponent()?.scrollable) {
6731
+ this.scrollToFinalize(id, focused, cb);
6732
+ return;
6733
+ }
6736
6734
  this._$scrollTo.next({
6737
6735
  id, behavior, blending, iteration: actualIteration, isLastIteration: actualIteration === MAX_SCROLL_TO_ITERATIONS, cb: () => {
6738
6736
  this._isScrollEnd.set(true);
6739
6737
  this._trackBox.isScrollStart = false;
6740
6738
  this._trackBox.isScrollEnd = true;
6741
6739
  this._$fireUpdate.next(true);
6742
- if (focused) {
6743
- const el = this.getFocusedElementById(id);
6744
- if (!!el) {
6745
- this._service.focus(el, FocusAlignments.NONE);
6746
- }
6747
- }
6748
- if (typeof cb === 'function') {
6749
- cb?.();
6750
- }
6740
+ this.scrollToFinalize(id, focused, cb);
6751
6741
  }
6752
6742
  });
6753
6743
  }
6744
+ scrollToFinalize(id, focused, cb) {
6745
+ if (focused) {
6746
+ const el = this.getFocusedElementById(id);
6747
+ if (!!el) {
6748
+ this._service.focus(el, FocusAlignments.NONE);
6749
+ }
6750
+ }
6751
+ if (typeof cb === 'function') {
6752
+ cb?.();
6753
+ }
6754
+ }
6754
6755
  cleanup() {
6755
6756
  const displayItems = [];
6756
6757
  this._service.collection = displayItems;
@@ -6934,15 +6935,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
6934
6935
 
6935
6936
  class NgScrollerModule {
6936
6937
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: NgScrollerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
6937
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.17", ngImport: i0, type: NgScrollerModule, declarations: [NgScrollerComponent], imports: [CommonModule, NgScrollBarModule, LocaleSensitiveModule, CdkScrollable], exports: [NgScrollerComponent] });
6938
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: NgScrollerModule, imports: [CommonModule, NgScrollBarModule, LocaleSensitiveModule] });
6938
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.17", ngImport: i0, type: NgScrollerModule, declarations: [NgScrollerComponent], imports: [CommonModule, NgScrollBarModule, LocaleSensitiveModule, CdkScrollableModule], exports: [NgScrollerComponent] });
6939
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: NgScrollerModule, imports: [CommonModule, NgScrollBarModule, LocaleSensitiveModule, CdkScrollableModule] });
6939
6940
  }
6940
6941
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: NgScrollerModule, decorators: [{
6941
6942
  type: NgModule,
6942
6943
  args: [{
6943
6944
  declarations: [NgScrollerComponent],
6944
6945
  exports: [NgScrollerComponent],
6945
- imports: [CommonModule, NgScrollBarModule, LocaleSensitiveModule, CdkScrollable],
6946
+ imports: [CommonModule, NgScrollBarModule, LocaleSensitiveModule, CdkScrollableModule],
6946
6947
  schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
6947
6948
  }]
6948
6949
  }] });