ng-virtual-list 20.10.13 → 20.10.14

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.
@@ -142,7 +142,7 @@ const TRACK_BY_PROPERTY_NAME = 'id';
142
142
  const DEFAULT_DIRECTION = Directions.VERTICAL;
143
143
  const DEFAULT_COLLECTION_MODE = CollectionModes.NORMAL;
144
144
  const DISPLAY_OBJECTS_LENGTH_MESUREMENT_ERROR = 1;
145
- const MAX_SCROLL_TO_ITERATIONS = 5;
145
+ const MAX_SCROLL_TO_ITERATIONS = 7;
146
146
  const DEFAULT_SNAPPING_METHOD = SnappingMethods.NORMAL;
147
147
  const DEFAULT_SELECT_METHOD = MethodsForSelecting.NONE;
148
148
  const DEFAULT_SCREEN_READER_MESSAGE = 'Showing items $1 to $2';
@@ -3829,10 +3829,10 @@ class NgScrollerComponent extends NgScrollView {
3829
3829
  if (update) {
3830
3830
  this.scrollBar?.scroll({
3831
3831
  [isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: thumbPosition, fireUpdate: false, behavior: BEHAVIOR_INSTANT,
3832
- userAction: false, blending: false,
3832
+ userAction: false, blending: true,
3833
3833
  });
3834
3834
  }
3835
- this.scrollbarShow.set(isVertical ? this.scrollHeight > 0 : this.scrollWidth > 0);
3835
+ this.scrollbarShow.set(this.scrollable);
3836
3836
  }
3837
3837
  ;
3838
3838
  ngAfterViewInit() {
@@ -3843,18 +3843,14 @@ class NgScrollerComponent extends NgScrollView {
3843
3843
  }
3844
3844
  onDragStart() {
3845
3845
  super.onDragStart();
3846
- if (!!this.scrollBar) {
3847
- this.scrollBar.stopScrolling();
3848
- }
3846
+ this.stopScrollbar();
3849
3847
  this._isScrollbarUserAction = false;
3850
3848
  this.updateScrollBar();
3851
3849
  }
3852
3850
  reset() {
3853
3851
  super.reset(this.startOffset());
3854
3852
  this.totalSize = 0;
3855
- if (this.scrollBar) {
3856
- this.scrollBar.stopScrolling();
3857
- }
3853
+ this.stopScrollbar();
3858
3854
  this.refresh(true, true);
3859
3855
  this.prepared = false;
3860
3856
  }
@@ -3880,13 +3876,16 @@ class NgScrollerComponent extends NgScrollView {
3880
3876
  scrollTo(params) {
3881
3877
  const userAction = params.userAction ?? true, blending = params.blending ?? true, fireUpdate = params.fireUpdate ?? false;
3882
3878
  if (userAction && (!blending && !this._isMoving) && !fireUpdate) {
3883
- if (this.scrollBar) {
3884
- this.scrollBar.stopScrolling();
3885
- }
3879
+ this.stopScrollbar();
3886
3880
  this._isScrollbarUserAction = false;
3887
3881
  }
3888
3882
  this.scroll(params);
3889
3883
  }
3884
+ stopScrollbar() {
3885
+ if (!!this.scrollBar) {
3886
+ this.scrollBar.stopScrolling();
3887
+ }
3888
+ }
3890
3889
  onScrollBarDragHandler(event) {
3891
3890
  const { animation, position, min, max, userAction } = event;
3892
3891
  this._isScrollbarUserAction = userAction;
@@ -4858,7 +4857,6 @@ class NgVirtualListComponent {
4858
4857
  this._trackBox.isScrollEnd = true;
4859
4858
  if (this._updateIterations < PREPARATION_REUPDATE_LENGTH) {
4860
4859
  this._updateIterations++;
4861
- this._trackBox.isScrollEnd = true;
4862
4860
  this._$fireUpdate.next();
4863
4861
  return of(false);
4864
4862
  }
@@ -4868,19 +4866,7 @@ class NgVirtualListComponent {
4868
4866
  return of(true);
4869
4867
  }), filter$1(v => !!v), distinctUntilChanged()), $items = toObservable(this.items), $dynamicSize = toObservable(this.dynamicSize);
4870
4868
  const $viewInit = this.$viewInit, $snapScrollToBottom = toObservable(this.snapScrollToBottom), $waitForPreparation = toObservable(this.waitForPreparation);
4871
- combineLatest([$dynamicSize, $snapScrollToBottom, $waitForPreparation]).pipe(takeUntilDestroyed(this._destroyRef), distinctUntilChanged(), switchMap$1(([dynamicSize, snapScrollToBottom, waitForPreparation]) => {
4872
- if (!dynamicSize || !snapScrollToBottom || !waitForPreparation) {
4873
- this._readyToShow = true;
4874
- this.refreshActualItemSize(true);
4875
- const scrollerComponent = this._scrollerComponent();
4876
- if (scrollerComponent) {
4877
- scrollerComponent.prepared = true;
4878
- }
4879
- this.classes.set({ prepared: true, [READY_TO_START]: true, [WAIT_FOR_PREPARATION]: false });
4880
- this._service.update();
4881
- this._$show.next(true);
4882
- return of(false);
4883
- }
4869
+ combineLatest([$viewInit, $dynamicSize, $snapScrollToBottom, $waitForPreparation]).pipe(takeUntilDestroyed(this._destroyRef), distinctUntilChanged(), filter$1(([init]) => !!init), switchMap$1(([, dynamicSize, snapScrollToBottom, waitForPreparation]) => {
4884
4870
  if (!!dynamicSize && !!snapScrollToBottom && !!waitForPreparation) {
4885
4871
  this._$show.next(false);
4886
4872
  this.cacheClean();
@@ -4892,14 +4878,13 @@ class NgVirtualListComponent {
4892
4878
  }
4893
4879
  this.classes.set({ prepared: false, [READY_TO_START]: false, [WAIT_FOR_PREPARATION]: false });
4894
4880
  return $items.pipe(takeUntilDestroyed(this._destroyRef), debounceTime(0), tap(items => {
4895
- if (items && items.length > 0)
4896
- this._trackBox.resetCollection(items, this.actualItemSize());
4897
- }), map(i => (i ?? []).length > 0), distinctUntilChanged(), switchMap$1(v => {
4898
- if (!v) {
4881
+ if (!items || items.length === 0) {
4899
4882
  this.cacheClean();
4900
4883
  this._readyToShow = this._isUserScrolling = false;
4901
4884
  this.refreshActualItemSize(false);
4902
- this._trackBox.isScrollEnd = true;
4885
+ if (this.snapScrollToBottom()) {
4886
+ this._trackBox.isScrollEnd = true;
4887
+ }
4903
4888
  this._updateIterations = 0;
4904
4889
  this._prevScrollStateVersion = EMPTY_SCROLL_STATE_VERSION;
4905
4890
  const scrollerComponent = this._scrollerComponent();
@@ -4909,6 +4894,10 @@ class NgVirtualListComponent {
4909
4894
  }
4910
4895
  this.classes.set({ prepared: false, [READY_TO_START]: false, [WAIT_FOR_PREPARATION]: false });
4911
4896
  this._$show.next(false);
4897
+ }
4898
+ this._trackBox.resetCollection(items, this.itemSize());
4899
+ }), map(i => (i ?? []).length > 0), distinctUntilChanged(), switchMap$1(v => {
4900
+ if (!v) {
4912
4901
  return of(false);
4913
4902
  }
4914
4903
  return of(true).pipe(takeUntilDestroyed(this._destroyRef), switchMap$1(() => {
@@ -4953,7 +4942,17 @@ class NgVirtualListComponent {
4953
4942
  this._service.update(true);
4954
4943
  this._$show.next(true);
4955
4944
  this._scrollerComponent()?.refresh(true, true);
4956
- return of(false);
4945
+ return $items.pipe(takeUntilDestroyed(this._destroyRef), debounceTime(0), tap(items => {
4946
+ if (!items || items.length === 0) {
4947
+ this.cacheClean();
4948
+ }
4949
+ this._trackBox.resetCollection(items, this.itemSize());
4950
+ const scrollerComponent = this._scrollerComponent();
4951
+ if (scrollerComponent) {
4952
+ scrollerComponent.prepared = true;
4953
+ }
4954
+ }));
4955
+ ;
4957
4956
  }
4958
4957
  })).subscribe();
4959
4958
  this._service.$focusedId.pipe(takeUntilDestroyed(), tap(v => {
@@ -5135,7 +5134,8 @@ class NgVirtualListComponent {
5135
5134
  this._isScrollFinished.set(scrollPosition >= roundedMaxPosition);
5136
5135
  }
5137
5136
  }
5138
- actualScrollSize = !this._readyToShow && snapScrollToBottom ? (isVertical ? scroller.scrollHeight ?? 0 : scroller.scrollWidth ?? 0) :
5137
+ actualScrollSize = ((!this._readyToShow && snapScrollToBottom) || this._trackBox.isSnappedToEnd) ?
5138
+ (isVertical ? scroller.scrollHeight ?? 0 : scroller.scrollWidth ?? 0) :
5139
5139
  (isVertical ? scroller.scrollTop ?? 0 : scroller.scrollLeft ?? 0);
5140
5140
  const delta = this._trackBox.delta, roundedActualScrollSize = Math.round(actualScrollSize), scrollPositionAfterUpdate = actualScrollSize + delta, roundedScrollPositionAfterUpdate = Math.round(scrollPositionAfterUpdate), roundedMaxPositionAfterUpdate = Math.round(totalSize - viewportSize);
5141
5141
  if (this._isSnappingMethodAdvanced) {
@@ -5155,10 +5155,11 @@ class NgVirtualListComponent {
5155
5155
  if (emitable && this._readyToShow) {
5156
5156
  this.emitScrollEvent(true, false);
5157
5157
  }
5158
- if (roundedMaxPositionAfterUpdate >= 0 && this._scrollSize() !== roundedMaxPositionAfterUpdate) {
5158
+ if ((this._readyToShow && roundedMaxPositionAfterUpdate > 0) ||
5159
+ (roundedMaxPositionAfterUpdate >= 0 && this._scrollSize() !== roundedMaxPositionAfterUpdate)) {
5159
5160
  const params = {
5160
5161
  [isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: roundedMaxPositionAfterUpdate,
5161
- fireUpdate: this._readyToShow, behavior: BEHAVIOR_INSTANT,
5162
+ fireUpdate: !this._readyToShow, behavior: BEHAVIOR_INSTANT,
5162
5163
  blending: false, duration: this.animationParams().scrollToItem,
5163
5164
  };
5164
5165
  scroller?.scrollTo?.(params);
@@ -5177,7 +5178,7 @@ class NgVirtualListComponent {
5177
5178
  if (this._scrollSize() !== scrollPositionAfterUpdate) {
5178
5179
  const params = {
5179
5180
  [isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollPositionAfterUpdate, blending: true,
5180
- fireUpdate: this._readyToShow, behavior: BEHAVIOR_INSTANT, duration: this.animationParams().scrollToItem,
5181
+ fireUpdate: !this._readyToShow, behavior: BEHAVIOR_INSTANT, duration: this.animationParams().scrollToItem,
5181
5182
  };
5182
5183
  scroller.scrollTo(params);
5183
5184
  if (emitable && !this._readyToShow) {
@@ -5186,7 +5187,7 @@ class NgVirtualListComponent {
5186
5187
  return;
5187
5188
  }
5188
5189
  }
5189
- if (emitable || !this._readyToShow) {
5190
+ if (emitable && !this._readyToShow) {
5190
5191
  this._$update.next(this.getScrollStateVersion(totalSize, this._isVertical ? scroller.scrollTop : scroller.scrollLeft, cacheVersion));
5191
5192
  }
5192
5193
  }
@@ -5201,9 +5202,6 @@ class NgVirtualListComponent {
5201
5202
  });
5202
5203
  }));
5203
5204
  })).subscribe();
5204
- combineLatest([$items, $dynamicSize]).pipe(takeUntilDestroyed(), debounceTime(0), filter$1(([, dynamic]) => !dynamic), delay(0), takeUntilDestroyed(), tap(() => {
5205
- this._scrollerComponent()?.refresh(true);
5206
- })).subscribe();
5207
5205
  const $scroller = toObservable(this._scroller).pipe(takeUntilDestroyed(), filter$1(v => !!v), map(v => v.nativeElement), take(1)), $scrollerScroll = toObservable(this._scrollerComponent).pipe(takeUntilDestroyed(), filter$1(v => !!v), take(1), switchMap$1(scroller => scroller.$scroll)), $scrollerScrollEnd = toObservable(this._scrollerComponent).pipe(takeUntilDestroyed(), filter$1(v => !!v), take(1), switchMap$1(scroller => scroller.$scrollEnd)), $list = toObservable(this._list).pipe(takeUntilDestroyed(), filter$1(v => !!v), map(v => v.nativeElement), take(1));
5208
5206
  $scroller.pipe(takeUntilDestroyed(), distinctUntilChanged(), switchMap$1(scroller => {
5209
5207
  return fromEvent(scroller, SCROLLER_WHEEL, { passive: true }).pipe(takeUntilDestroyed(this._destroyRef), filter$1(() => {
@@ -5374,7 +5372,7 @@ class NgVirtualListComponent {
5374
5372
  return of([false, {
5375
5373
  id, scroller: scrollerComponent, iteration: iteration + 1, blending,
5376
5374
  isLastIteration: notChanged, scrollCalled: true, cb
5377
- }]).pipe(delay(1));
5375
+ }]).pipe(delay(0));
5378
5376
  }
5379
5377
  else {
5380
5378
  this._scrollSize.set(actualScrollSize);