ng-virtual-list 19.10.1 → 19.10.2
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 +10 -10
- package/fesm2022/ng-virtual-list.mjs +151 -97
- package/fesm2022/ng-virtual-list.mjs.map +1 -1
- package/lib/components/list-item/ng-virtual-list-item.component.d.ts +3 -0
- package/lib/const/index.d.ts +1 -1
- package/lib/ng-virtual-list.component.d.ts +12 -9
- package/lib/ng-virtual-list.service.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ npm i ng-virtual-list
|
|
|
101
101
|
|
|
102
102
|
## 🚀 Quick Start
|
|
103
103
|
```html
|
|
104
|
-
<ng-virtual-list [items]="items" [bufferSize]="5" [itemRenderer]="itemRenderer" [itemSize]="64"></ng-virtual-list>
|
|
104
|
+
<ng-virtual-list [items]="items" [bufferSize]="5" [itemRenderer]="itemRenderer" [dynamicSize]="false" [itemSize]="64"></ng-virtual-list>
|
|
105
105
|
|
|
106
106
|
<ng-template #itemRenderer let-data="data">
|
|
107
107
|
@if (data) {
|
|
@@ -124,7 +124,7 @@ items = Array.from({ length: 100000 }, (_, i) => ({ id: i, name: `Item #${i}` })
|
|
|
124
124
|
Template:
|
|
125
125
|
```html
|
|
126
126
|
<ng-virtual-list class="list" direction="horizontal" [items]="horizontalItems" [bufferSize]="1" [maxBufferSize]="5"
|
|
127
|
-
[itemRenderer]="horizontalItemRenderer" [itemSize]="64" [methodForSelecting]="'select'"
|
|
127
|
+
[itemRenderer]="horizontalItemRenderer" [dynamicSize]="false" [itemSize]="64" [methodForSelecting]="'select'"
|
|
128
128
|
[selectedIds]="2" (onSelect)="onSelect($event)" (onItemClick)="onItemClick($event)"></ng-virtual-list>
|
|
129
129
|
|
|
130
130
|
<ng-template #horizontalItemRenderer let-data="data" let-config="config">
|
|
@@ -174,7 +174,7 @@ export class AppComponent {
|
|
|
174
174
|
Template:
|
|
175
175
|
```html
|
|
176
176
|
<ng-virtual-list class="list" direction="horizontal" [items]="horizontalGroupItems" [itemRenderer]="horizontalGroupItemRenderer"
|
|
177
|
-
[bufferSize]="1" [maxBufferSize]="5" [itemConfigMap]="horizontalGroupItemConfigMap" [itemSize]="54" [snap]="true"
|
|
177
|
+
[bufferSize]="1" [maxBufferSize]="5" [itemConfigMap]="horizontalGroupItemConfigMap" [dynamicSize]="false" [itemSize]="54" [snap]="true"
|
|
178
178
|
methodForSelecting="multi-select" [selectedIds]="[3,2]" (onSelect)="onSelect($event)" (onItemClick)="onItemClick($event)"></ng-virtual-list>
|
|
179
179
|
|
|
180
180
|
<ng-template #horizontalGroupItemRenderer let-data="data" let-config="config">
|
|
@@ -248,7 +248,7 @@ export class AppComponent {
|
|
|
248
248
|
Template:
|
|
249
249
|
```html
|
|
250
250
|
<ng-virtual-list class="list simple" [items]="items" [bufferSize]="1" [maxBufferSize]="5" [itemRenderer]="itemRenderer"
|
|
251
|
-
[itemSize]="40"></ng-virtual-list>
|
|
251
|
+
[dynamicSize]="false" [itemSize]="40"></ng-virtual-list>
|
|
252
252
|
|
|
253
253
|
<ng-template #itemRenderer let-data="data">
|
|
254
254
|
@if (data) {
|
|
@@ -289,7 +289,7 @@ export class AppComponent {
|
|
|
289
289
|
Template:
|
|
290
290
|
```html
|
|
291
291
|
<ng-virtual-list class="list simple" [items]="groupItems" [bufferSize]="1" [maxBufferSize]="5" [itemRenderer]="groupItemRenderer"
|
|
292
|
-
[itemConfigMap]="groupItemConfigMap" [itemSize]="40" [snap]="false"></ng-virtual-list>
|
|
292
|
+
[itemConfigMap]="groupItemConfigMap" [dynamicSize]="false" [itemSize]="40" [snap]="false"></ng-virtual-list>
|
|
293
293
|
|
|
294
294
|
<ng-template #groupItemRenderer let-data="data">
|
|
295
295
|
@if (data) {
|
|
@@ -316,7 +316,7 @@ Template:
|
|
|
316
316
|
Template (with snapping):
|
|
317
317
|
```html
|
|
318
318
|
<ng-virtual-list class="list simple" [items]="groupItems" [bufferSize]="1" [maxBufferSize]="5" [itemRenderer]="groupItemRenderer"
|
|
319
|
-
[itemConfigMap]="groupItemConfigMap" [itemSize]="40" [snap]="true"></ng-virtual-list>
|
|
319
|
+
[itemConfigMap]="groupItemConfigMap" [dynamicSize]="false" [itemSize]="40" [snap]="true"></ng-virtual-list>
|
|
320
320
|
|
|
321
321
|
<ng-template #groupItemRenderer let-data="data">
|
|
322
322
|
@if (data) {
|
|
@@ -381,7 +381,7 @@ Template
|
|
|
381
381
|
</div>
|
|
382
382
|
|
|
383
383
|
<ng-virtual-list #virtualList class="list" [items]="items" [itemRenderer]="itemRenderer" [bufferSize]="1" [maxBufferSize]="5"
|
|
384
|
-
[itemSize]="40"></ng-virtual-list>
|
|
384
|
+
[dynamicSize]="false" [itemSize]="40"></ng-virtual-list>
|
|
385
385
|
|
|
386
386
|
<ng-template #itemRenderer let-data="data">
|
|
387
387
|
@if (data) {
|
|
@@ -435,7 +435,7 @@ Virtual list with height-adjustable elements.
|
|
|
435
435
|
Template
|
|
436
436
|
```html
|
|
437
437
|
<ng-virtual-list #dynamicList class="list" [items]="groupDynamicItems" [itemRenderer]="groupItemRenderer" [bufferSize]="1" [maxBufferSize]="5"
|
|
438
|
-
[itemConfigMap]="groupDynamicItemConfigMap" [
|
|
438
|
+
[itemConfigMap]="groupDynamicItemConfigMap" [snap]="true"></ng-virtual-list>
|
|
439
439
|
|
|
440
440
|
<ng-template #groupItemRenderer let-data="data">
|
|
441
441
|
@if (data) {
|
|
@@ -649,7 +649,7 @@ Inputs
|
|
|
649
649
|
|---|---|---|
|
|
650
650
|
| id | number | Readonly. Returns the unique identifier of the component. |
|
|
651
651
|
| items | [IVirtualListCollection](https://github.com/DjonnyX/ng-virtual-list/blob/19.x/projects/ng-virtual-list/src/lib/models/collection.model.ts) | Collection of list items. The collection of elements must be immutable. |
|
|
652
|
-
| itemSize | number? = 24 | If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element.
|
|
652
|
+
| itemSize | number? = 24 | If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element. If the dynamicSize property is true, the items in the list can have different sizes, and you must specify the itemSize property to adjust the sizes of the items in the unallocated area. |
|
|
653
653
|
| bufferSize | number? = 2 | Number of elements outside the scope of visibility. Default value is 2. |
|
|
654
654
|
| maxBufferSize | number? = 10 | Maximum number of elements outside the scope of visibility. Default value is 10. If maxBufferSize is set to be greater than bufferSize, then adaptive buffer mode is enabled. The greater the scroll size, the more elements are allocated for rendering. |
|
|
655
655
|
| itemRenderer | TemplateRef | Rendering element template. |
|
|
@@ -661,7 +661,7 @@ Inputs
|
|
|
661
661
|
| snap | boolean? = false | Determines whether elements will snap. Default value is "false". |
|
|
662
662
|
| snappingMethod | [SnappingMethod? = 'normal'](https://github.com/DjonnyX/ng-virtual-list/blob/19.x/projects/ng-virtual-list/src/lib/enums/snapping-method.ts) | Snapping method. 'normal' - Normal group rendering. 'advanced' - The group is rendered on a transparent background. 'chat' - The group is rendered on a background. List items below the group are not rendered. |
|
|
663
663
|
| direction | [Direction? = 'vertical'](https://github.com/DjonnyX/ng-virtual-list/blob/19.x/projects/ng-virtual-list/src/lib/enums/direction.ts) | Determines the direction in which elements are placed. Default value is "vertical". |
|
|
664
|
-
| dynamicSize | boolean? =
|
|
664
|
+
| dynamicSize | boolean? = true | If true, items in the list may have different sizes, and the itemSize property must be specified to adjust the sizes of items in the unallocated area. If false then the items in the list have a fixed size specified by the itemSize property. The default value is true. |
|
|
665
665
|
| enabledBufferOptimization | boolean? = true | Experimental! Enables buffer optimization. Can only be used if items in the collection are not added or updated. |
|
|
666
666
|
| trackBy | string? = 'id' | The name of the property by which tracking is performed. |
|
|
667
667
|
| selectedIds | Array<[Id](https://github.com/DjonnyX/ng-virtual-list/blob/19.x/projects/ng-virtual-list/src/lib/types/id.ts)> \| [Id](https://github.com/DjonnyX/ng-virtual-list/blob/19.x/projects/ng-virtual-list/src/lib/types/id.ts) \| undefined | Sets the selected items. |
|
|
@@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common';
|
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
4
|
import { Injectable, output, inject, ElementRef, DestroyRef, Input, Directive, signal, computed, ChangeDetectionStrategy, Component, viewChild, input, effect, ViewEncapsulation, InjectionToken, ViewChild, NO_ERRORS_SCHEMA, ViewContainerRef } from '@angular/core';
|
|
5
5
|
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
|
|
6
|
-
import { Subject, tap, fromEvent, race, of, combineLatest, map, filter as filter$1,
|
|
6
|
+
import { Subject, tap, fromEvent, race, of, switchMap as switchMap$1, combineLatest, map, filter as filter$1, delay, takeUntil as takeUntil$1, from, debounceTime, BehaviorSubject as BehaviorSubject$1, distinctUntilChanged, take } from 'rxjs';
|
|
7
7
|
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
|
8
8
|
import { switchMap, takeUntil, filter, tap as tap$1 } from 'rxjs/operators';
|
|
9
9
|
import { CdkScrollable } from '@angular/cdk/scrolling';
|
|
@@ -134,7 +134,7 @@ const DEFAULT_SNAP = false;
|
|
|
134
134
|
const DEFAULT_SELECT_BY_CLICK = true;
|
|
135
135
|
const DEFAULT_COLLAPSE_BY_CLICK = true;
|
|
136
136
|
const DEFAULT_ENABLED_BUFFER_OPTIMIZATION = false;
|
|
137
|
-
const DEFAULT_DYNAMIC_SIZE =
|
|
137
|
+
const DEFAULT_DYNAMIC_SIZE = true;
|
|
138
138
|
const DEFAULT_SNAP_TO_END_TRANSITION_INSTANT_OFFSET = 1;
|
|
139
139
|
const DEFAULT_SNAP_SCROLLTO_BOTTOM = false;
|
|
140
140
|
const TRACK_BY_PROPERTY_NAME = 'id';
|
|
@@ -288,6 +288,7 @@ class NgVirtualListService {
|
|
|
288
288
|
$scrollToStart = this._$scrollToStart.asObservable();
|
|
289
289
|
_$scrollToEnd = new Subject();
|
|
290
290
|
$scrollToEnd = this._$scrollToEnd.asObservable();
|
|
291
|
+
lastFocusedItemId = -1;
|
|
291
292
|
scrollStartOffset = 0;
|
|
292
293
|
scrollEndOffset = 0;
|
|
293
294
|
scrollBarSize = 0;
|
|
@@ -634,7 +635,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
|
|
|
634
635
|
args: ['maxClickDistance']
|
|
635
636
|
}] } });
|
|
636
637
|
|
|
637
|
-
const ZEROS_POSITION = -1000, ATTR_AREA_SELECTED = 'area-selected', POSITION = 'position', POSITION_ZERO = '0', ID$1 = 'item-id', KEY_SPACE = ' ', KEY_ARR_LEFT = 'ArrowLeft', KEY_ARR_UP = 'ArrowUp', KEY_ARR_RIGHT = 'ArrowRight', KEY_ARR_DOWN = 'ArrowDown', EVENT_FOCUS_IN = 'focusin', EVENT_FOCUS_OUT = 'focusout', EVENT_KEY_DOWN = 'keydown', CLASS_NAME_SNAPPED = 'snapped', CLASS_NAME_SNAPPED_OUT = 'snapped-out', CLASS_NAME_FOCUS = 'focus';
|
|
638
|
+
const ZEROS_POSITION = -1000, NAVIGATE_TO_ATTEMT = 5, ATTR_AREA_SELECTED = 'area-selected', POSITION = 'position', POSITION_ZERO = '0', ID$1 = 'item-id', KEY_SPACE = ' ', KEY_ARR_LEFT = 'ArrowLeft', KEY_ARR_UP = 'ArrowUp', KEY_ARR_RIGHT = 'ArrowRight', KEY_ARR_DOWN = 'ArrowDown', EVENT_FOCUS_IN = 'focusin', EVENT_FOCUS_OUT = 'focusout', EVENT_KEY_DOWN = 'keydown', CLASS_NAME_SNAPPED = 'snapped', CLASS_NAME_SNAPPED_OUT = 'snapped-out', CLASS_NAME_FOCUS = 'focus';
|
|
638
639
|
/**
|
|
639
640
|
* Virtual list component.
|
|
640
641
|
* Maximum performance for extremely large lists.
|
|
@@ -728,6 +729,7 @@ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
|
|
|
728
729
|
(align = FocusAlignments.CENTER) => {
|
|
729
730
|
this.focus(align);
|
|
730
731
|
};
|
|
732
|
+
_destroyRef = inject(DestroyRef);
|
|
731
733
|
constructor() {
|
|
732
734
|
super();
|
|
733
735
|
this._id = this._service.generateComponentId();
|
|
@@ -765,46 +767,43 @@ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
|
|
|
765
767
|
this.focused.set(false);
|
|
766
768
|
this.updateConfig(this._data);
|
|
767
769
|
this.updatePartStr(this._data, this._isSelected, this._isCollapsed);
|
|
768
|
-
})).subscribe()
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
this._service.select(this._data);
|
|
775
|
-
this._service.collapse(this._data);
|
|
776
|
-
break;
|
|
777
|
-
}
|
|
778
|
-
case KEY_ARR_LEFT:
|
|
779
|
-
if (!this.config().isVertical) {
|
|
780
|
-
e.stopImmediatePropagation();
|
|
781
|
-
e.preventDefault();
|
|
782
|
-
this.focusPrev();
|
|
783
|
-
}
|
|
784
|
-
break;
|
|
785
|
-
case KEY_ARR_UP:
|
|
786
|
-
if (this.config().isVertical) {
|
|
787
|
-
e.stopImmediatePropagation();
|
|
788
|
-
e.preventDefault();
|
|
789
|
-
this.focusPrev();
|
|
790
|
-
}
|
|
791
|
-
break;
|
|
792
|
-
case KEY_ARR_RIGHT:
|
|
793
|
-
if (!this.config().isVertical) {
|
|
794
|
-
e.stopImmediatePropagation();
|
|
795
|
-
e.preventDefault();
|
|
796
|
-
this.focusNext();
|
|
797
|
-
}
|
|
798
|
-
break;
|
|
799
|
-
case KEY_ARR_DOWN:
|
|
800
|
-
if (this.config().isVertical) {
|
|
770
|
+
})).subscribe();
|
|
771
|
+
$focused.pipe(takeUntilDestroyed(), switchMap$1(v => {
|
|
772
|
+
if (v) {
|
|
773
|
+
return fromEvent(this.element, EVENT_KEY_DOWN).pipe(takeUntilDestroyed(this._destroyRef), tap(e => {
|
|
774
|
+
switch (e.key) {
|
|
775
|
+
case KEY_SPACE: {
|
|
801
776
|
e.stopImmediatePropagation();
|
|
802
777
|
e.preventDefault();
|
|
803
|
-
this.
|
|
778
|
+
this._service.select(this._data);
|
|
779
|
+
this._service.collapse(this._data);
|
|
780
|
+
break;
|
|
804
781
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
782
|
+
case KEY_ARR_LEFT:
|
|
783
|
+
if (!this.config().isVertical) {
|
|
784
|
+
this.toPrevItem(e);
|
|
785
|
+
}
|
|
786
|
+
break;
|
|
787
|
+
case KEY_ARR_UP:
|
|
788
|
+
if (this.config().isVertical) {
|
|
789
|
+
this.toPrevItem(e);
|
|
790
|
+
}
|
|
791
|
+
break;
|
|
792
|
+
case KEY_ARR_RIGHT:
|
|
793
|
+
if (!this.config().isVertical) {
|
|
794
|
+
this.toNextItem(e);
|
|
795
|
+
}
|
|
796
|
+
break;
|
|
797
|
+
case KEY_ARR_DOWN:
|
|
798
|
+
if (this.config().isVertical) {
|
|
799
|
+
this.toNextItem(e);
|
|
800
|
+
}
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
}));
|
|
804
|
+
}
|
|
805
|
+
return of(false);
|
|
806
|
+
})).subscribe();
|
|
808
807
|
combineLatest([$data, this._service.$methodOfSelecting, this._service.$selectedIds, this._service.$collapsedIds]).pipe(takeUntilDestroyed(), map(([, m, selectedIds, collapsedIds]) => ({ method: m, selectedIds, collapsedIds })), tap(({ method, selectedIds, collapsedIds }) => {
|
|
809
808
|
switch (method) {
|
|
810
809
|
case MethodsForSelectingTypes.SELECT: {
|
|
@@ -833,19 +832,54 @@ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
|
|
|
833
832
|
this.updateMeasures(this._data);
|
|
834
833
|
})).subscribe();
|
|
835
834
|
}
|
|
835
|
+
toNextItem(e, attempt = NAVIGATE_TO_ATTEMT) {
|
|
836
|
+
const index = this.focusNext();
|
|
837
|
+
if (index > -1) {
|
|
838
|
+
this._service.lastFocusedItemId = index;
|
|
839
|
+
if (!!e && e.cancelable) {
|
|
840
|
+
e.stopImmediatePropagation();
|
|
841
|
+
e.preventDefault();
|
|
842
|
+
}
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (this._service.lastFocusedItemId > -1) {
|
|
846
|
+
this.focus(FocusAlignments.CENTER, this._service.lastFocusedItemId);
|
|
847
|
+
}
|
|
848
|
+
if (attempt > 0) {
|
|
849
|
+
this.toNextItem(e, attempt - 1);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
toPrevItem(e, attempt = NAVIGATE_TO_ATTEMT) {
|
|
853
|
+
const index = this.focusPrev();
|
|
854
|
+
if (index > -1) {
|
|
855
|
+
this._service.lastFocusedItemId = index;
|
|
856
|
+
if (!!e && e.cancelable) {
|
|
857
|
+
e.stopImmediatePropagation();
|
|
858
|
+
e.preventDefault();
|
|
859
|
+
}
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
if (this._service.lastFocusedItemId > -1) {
|
|
863
|
+
this.focus(FocusAlignments.CENTER, this._service.lastFocusedItemId);
|
|
864
|
+
}
|
|
865
|
+
if (attempt > 0) {
|
|
866
|
+
this.toPrevItem(e, attempt - 1);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
836
869
|
focusNext() {
|
|
837
870
|
if (this._service.listElement) {
|
|
838
871
|
const tabIndex = this._data?.config?.tabIndex ?? 0, length = this._service.collection?.length ?? 0;
|
|
839
872
|
let index = tabIndex;
|
|
840
873
|
while (index <= length) {
|
|
841
874
|
index++;
|
|
842
|
-
const
|
|
843
|
-
if (
|
|
844
|
-
this._service.focus(
|
|
845
|
-
|
|
875
|
+
const element = this._service.listElement.querySelector(getListElementByIndex(index));
|
|
876
|
+
if (!!element && element.style.visibility !== VISIBILITY_HIDDEN) {
|
|
877
|
+
this._service.focus(element);
|
|
878
|
+
return index;
|
|
846
879
|
}
|
|
847
880
|
}
|
|
848
881
|
}
|
|
882
|
+
return -1;
|
|
849
883
|
}
|
|
850
884
|
focusPrev() {
|
|
851
885
|
if (this._service.listElement) {
|
|
@@ -853,21 +887,22 @@ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
|
|
|
853
887
|
let index = tabIndex;
|
|
854
888
|
while (index >= 0) {
|
|
855
889
|
index--;
|
|
856
|
-
const
|
|
857
|
-
if (
|
|
858
|
-
this._service.focus(
|
|
859
|
-
|
|
890
|
+
const element = this._service.listElement.querySelector(getListElementByIndex(index));
|
|
891
|
+
if (!!element) {
|
|
892
|
+
this._service.focus(element);
|
|
893
|
+
return index;
|
|
860
894
|
}
|
|
861
895
|
}
|
|
862
896
|
}
|
|
897
|
+
return -1;
|
|
863
898
|
}
|
|
864
|
-
focus(align = FocusAlignments.CENTER) {
|
|
899
|
+
focus(align = FocusAlignments.CENTER, index = -1) {
|
|
865
900
|
if (this._service.listElement) {
|
|
866
|
-
const tabIndex = this._data?.config?.tabIndex ?? 0;
|
|
867
|
-
let
|
|
868
|
-
const
|
|
869
|
-
if (
|
|
870
|
-
this._service.focus(
|
|
901
|
+
const tabIndex = index > -1 ? index : this._data?.config?.tabIndex ?? 0;
|
|
902
|
+
let i = tabIndex;
|
|
903
|
+
const element = this._service.listElement.querySelector(getListElementByIndex(i));
|
|
904
|
+
if (!!element) {
|
|
905
|
+
this._service.focus(element, align);
|
|
871
906
|
}
|
|
872
907
|
}
|
|
873
908
|
}
|
|
@@ -2195,14 +2230,16 @@ class TrackBox extends CacheMap {
|
|
|
2195
2230
|
}
|
|
2196
2231
|
}
|
|
2197
2232
|
changes(immediately = false) {
|
|
2198
|
-
if (this.changesDetected()) {
|
|
2199
|
-
return;
|
|
2200
|
-
}
|
|
2201
|
-
this.bumpVersion();
|
|
2202
2233
|
if (immediately) {
|
|
2203
2234
|
this._previousVersion = this._version;
|
|
2204
2235
|
this.dispatch(CACHE_BOX_CHANGE_EVENT_NAME, this.version);
|
|
2205
2236
|
}
|
|
2237
|
+
else {
|
|
2238
|
+
if (this.changesDetected()) {
|
|
2239
|
+
return;
|
|
2240
|
+
}
|
|
2241
|
+
this.bumpVersion();
|
|
2242
|
+
}
|
|
2206
2243
|
}
|
|
2207
2244
|
generateDisplayCollection(items, itemConfigMap, metrics) {
|
|
2208
2245
|
const { offsetY, offsetX, width, height, normalizedItemWidth, normalizedItemHeight, dynamicSize, itemsOnDisplayLength, itemsFromStartToScrollEnd, isVertical, renderItems: renderItemsLength, scrollSize, sizeProperty, snap, snippedPos, startPosition, totalLength, startIndex, typicalItemSize, } = metrics, displayItems = [];
|
|
@@ -3839,10 +3876,10 @@ class NgScrollerComponent extends NgScrollView {
|
|
|
3839
3876
|
this.prepared = false;
|
|
3840
3877
|
}
|
|
3841
3878
|
refresh(fireUpdate = false, updateScrollbar = true) {
|
|
3842
|
-
this.scrollLimits();
|
|
3843
3879
|
if (updateScrollbar) {
|
|
3844
3880
|
this.stopScrolling();
|
|
3845
3881
|
}
|
|
3882
|
+
this.scrollLimits();
|
|
3846
3883
|
if (this.isVertical()) {
|
|
3847
3884
|
this.refreshY(this._y);
|
|
3848
3885
|
}
|
|
@@ -3850,7 +3887,7 @@ class NgScrollerComponent extends NgScrollView {
|
|
|
3850
3887
|
this.refreshX(this._x);
|
|
3851
3888
|
}
|
|
3852
3889
|
if (updateScrollbar) {
|
|
3853
|
-
this.updateScrollBarHandler(
|
|
3890
|
+
this.updateScrollBarHandler(false);
|
|
3854
3891
|
if (this.cdkScrollable) {
|
|
3855
3892
|
this.cdkScrollable.getElementRef().nativeElement.dispatchEvent(SCROLLBAR_SCROLL_EVENT);
|
|
3856
3893
|
}
|
|
@@ -3913,7 +3950,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
|
|
|
3913
3950
|
args: ['scrollBar', { read: NgScrollBarComponent }]
|
|
3914
3951
|
}] } });
|
|
3915
3952
|
|
|
3916
|
-
const MIN_SCROLL_TO_START_PIXELS = 10, RANGE_DISPLAY_ITEMS_END_OFFSET = 20,
|
|
3953
|
+
const MIN_SCROLL_TO_START_PIXELS = 10, RANGE_DISPLAY_ITEMS_END_OFFSET = 20, MIN_PREPARE_ITERATIONS = 20, EMPTY_SCROLL_STATE_VERSION = '-1', ROLE_LIST = 'list', ROLE_LIST_BOX = 'listbox', ITEM_ID = 'item-id', ITEM_CONTAINER = 'ngvl-item__container', READY_TO_START = 'ready-to-start', WAIT_FOR_PREPARATION = 'wait-for-preparation';
|
|
3954
|
+
const getScrollStateVersion = (scrollSize, cacheVersion) => {
|
|
3955
|
+
return `${scrollSize}_${cacheVersion}`;
|
|
3956
|
+
};
|
|
3917
3957
|
const validateScrollIteration = (value) => {
|
|
3918
3958
|
return Number.isNaN(value) || (value < 0) ? 0 : value > MAX_SCROLL_TO_ITERATIONS ? MAX_SCROLL_TO_ITERATIONS : value;
|
|
3919
3959
|
}, validateId = (id) => {
|
|
@@ -4437,7 +4477,8 @@ class NgVirtualListComponent {
|
|
|
4437
4477
|
};
|
|
4438
4478
|
/**
|
|
4439
4479
|
* If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element.
|
|
4440
|
-
*
|
|
4480
|
+
* If the dynamicSize property is true, the items in the list can have different sizes, and you must specify the itemSize property
|
|
4481
|
+
* to adjust the sizes of the items in the unallocated area.
|
|
4441
4482
|
*/
|
|
4442
4483
|
itemSize = input(DEFAULT_ITEM_SIZE, { ...this._itemSizeOptions });
|
|
4443
4484
|
_dynamicSizeOptions = {
|
|
@@ -4451,8 +4492,9 @@ class NgVirtualListComponent {
|
|
|
4451
4492
|
},
|
|
4452
4493
|
};
|
|
4453
4494
|
/**
|
|
4454
|
-
* If true
|
|
4455
|
-
*
|
|
4495
|
+
* If true, items in the list may have different sizes, and the itemSize property must be specified to adjust
|
|
4496
|
+
* the sizes of items in the unallocated area.
|
|
4497
|
+
* If false then the items in the list have a fixed size specified by the itemSize property. The default value is true.
|
|
4456
4498
|
*/
|
|
4457
4499
|
dynamicSize = input(DEFAULT_DYNAMIC_SIZE, { ...this._dynamicSizeOptions });
|
|
4458
4500
|
_directionOptions = {
|
|
@@ -4739,6 +4781,7 @@ class NgVirtualListComponent {
|
|
|
4739
4781
|
[this._isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: pos, behavior,
|
|
4740
4782
|
fireUpdate: true, blending: true, userAction: true, duration: this.animationParams().navigateToItem,
|
|
4741
4783
|
};
|
|
4784
|
+
scroller.refresh(false);
|
|
4742
4785
|
scroller.scrollTo(params);
|
|
4743
4786
|
}
|
|
4744
4787
|
}
|
|
@@ -4773,8 +4816,10 @@ class NgVirtualListComponent {
|
|
|
4773
4816
|
$scrollTo = this._$scrollTo.asObservable();
|
|
4774
4817
|
_$scroll = new Subject();
|
|
4775
4818
|
$scroll = this._$scroll.asObservable();
|
|
4776
|
-
_$
|
|
4777
|
-
$
|
|
4819
|
+
_$fireUpdate = new Subject();
|
|
4820
|
+
$fireUpdate = this._$fireUpdate.asObservable();
|
|
4821
|
+
_$fireUpdateNextFrame = new Subject();
|
|
4822
|
+
$fireUpdateNextFrame = this._$fireUpdateNextFrame.asObservable();
|
|
4778
4823
|
_onTrackBoxResetHandler = (v) => {
|
|
4779
4824
|
if (v && this._scrollerComponent()?.scrollable) {
|
|
4780
4825
|
this._$isResetedReachStart.next(true);
|
|
@@ -4792,9 +4837,7 @@ class NgVirtualListComponent {
|
|
|
4792
4837
|
}
|
|
4793
4838
|
}
|
|
4794
4839
|
};
|
|
4795
|
-
_$updateIteration = new BehaviorSubject$1(0);
|
|
4796
4840
|
_onPreparedHandler = (v) => {
|
|
4797
|
-
this._$updateIteration.next(0);
|
|
4798
4841
|
this._$prepared.next(v);
|
|
4799
4842
|
};
|
|
4800
4843
|
_destroyRef = inject(DestroyRef);
|
|
@@ -4808,6 +4851,9 @@ class NgVirtualListComponent {
|
|
|
4808
4851
|
this._service.initialize(this._trackBox);
|
|
4809
4852
|
this._service.itemToFocus = this.itemToFocus;
|
|
4810
4853
|
this._trackBox.displayComponents = this._displayComponents;
|
|
4854
|
+
this.$fireUpdateNextFrame.pipe(takeUntilDestroyed(), debounceTime(0), tap(e => {
|
|
4855
|
+
this._$fireUpdate.next(e);
|
|
4856
|
+
})).subscribe();
|
|
4811
4857
|
const $scrollToItem = this.$scrollTo.pipe(takeUntilDestroyed()), $mouseDown = fromEvent(this._elementRef.nativeElement, MOUSE_DOWN).pipe(takeUntilDestroyed()), $touchStart = fromEvent(this._elementRef.nativeElement, TOUCH_START).pipe(takeUntilDestroyed());
|
|
4812
4858
|
fromEvent(document, KEY_DOWN).pipe(takeUntilDestroyed(), switchMap$1(e => {
|
|
4813
4859
|
return fromEvent(this._elementRef.nativeElement, FOCUS).pipe(takeUntilDestroyed(this._destroyRef), delay(0), takeUntil$1($scrollToItem), takeUntil$1($mouseDown), takeUntil$1($touchStart), tap(e => {
|
|
@@ -4835,24 +4881,28 @@ class NgVirtualListComponent {
|
|
|
4835
4881
|
this._service.clickDistance = dist;
|
|
4836
4882
|
});
|
|
4837
4883
|
let prepared = false, readyToStart = false, isUserScrolling = false;
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
const isVerrtical = this._isVertical, actualScrollSize = isVerrtical ? (scroller?.actualScrollHeight ?? 0) : (scroller?.actualScrollWidth ?? 0), params = {
|
|
4845
|
-
[isVerrtical ? TOP_PROP_NAME : LEFT_PROP_NAME]: actualScrollSize,
|
|
4846
|
-
blending: false, fireUpdate: true, userAction: false, behavior: BEHAVIOR_INSTANT,
|
|
4847
|
-
};
|
|
4848
|
-
scroller.stopScrolling();
|
|
4849
|
-
scroller.scrollTo(params);
|
|
4850
|
-
this._service.update();
|
|
4884
|
+
let prevScrollStateVersion = EMPTY_SCROLL_STATE_VERSION, updateIterations = 0;
|
|
4885
|
+
const $updateComplete = this.$update.pipe(takeUntilDestroyed(), debounceTime(0), switchMap$1((v) => {
|
|
4886
|
+
if (((prevScrollStateVersion === EMPTY_SCROLL_STATE_VERSION) || (prevScrollStateVersion !== v)) &&
|
|
4887
|
+
(updateIterations < MIN_PREPARE_ITERATIONS)) {
|
|
4888
|
+
if (v !== EMPTY_SCROLL_STATE_VERSION) {
|
|
4889
|
+
prevScrollStateVersion = v;
|
|
4851
4890
|
}
|
|
4891
|
+
this._trackBox.isScrollEnd = true;
|
|
4892
|
+
this._$fireUpdateNextFrame.next();
|
|
4852
4893
|
return of(false);
|
|
4853
4894
|
}
|
|
4895
|
+
if (prevScrollStateVersion === v) {
|
|
4896
|
+
this._trackBox.isScrollEnd = true;
|
|
4897
|
+
if (updateIterations < MIN_PREPARE_ITERATIONS) {
|
|
4898
|
+
updateIterations++;
|
|
4899
|
+
this._$fireUpdateNextFrame.next();
|
|
4900
|
+
return of(false);
|
|
4901
|
+
}
|
|
4902
|
+
}
|
|
4903
|
+
prevScrollStateVersion = v;
|
|
4854
4904
|
return of(true);
|
|
4855
|
-
}), debounceTime(
|
|
4905
|
+
}), debounceTime(0), filter$1(v => !!v)), $items = toObservable(this.items).pipe(map(i => !i ? [] : i)), $dynamicSize = toObservable(this.dynamicSize);
|
|
4856
4906
|
const $snapScrollToBottom = toObservable(this.snapScrollToBottom), $waitForPreparation = toObservable(this.waitForPreparation);
|
|
4857
4907
|
combineLatest([$dynamicSize, $snapScrollToBottom, $waitForPreparation]).pipe(takeUntilDestroyed(), switchMap$1(([dynamicSize, snapScrollToBottom, waitForPreparation]) => {
|
|
4858
4908
|
if (!dynamicSize || !snapScrollToBottom || !waitForPreparation) {
|
|
@@ -4867,7 +4917,6 @@ class NgVirtualListComponent {
|
|
|
4867
4917
|
return of(false);
|
|
4868
4918
|
}
|
|
4869
4919
|
if (!!dynamicSize && !!snapScrollToBottom && !!waitForPreparation) {
|
|
4870
|
-
this._$updateIteration.next(0);
|
|
4871
4920
|
return this.$prepared.pipe(takeUntilDestroyed(this._destroyRef), distinctUntilChanged(), switchMap$1(v => {
|
|
4872
4921
|
if (!v) {
|
|
4873
4922
|
this._$show.next(false);
|
|
@@ -4879,14 +4928,15 @@ class NgVirtualListComponent {
|
|
|
4879
4928
|
scrollerComponent.stopScrolling();
|
|
4880
4929
|
}
|
|
4881
4930
|
this.classes.set({ prepared: v, [READY_TO_START]: false, [WAIT_FOR_PREPARATION]: false });
|
|
4882
|
-
this._$updateIteration.next(0);
|
|
4883
4931
|
this._service.update(true);
|
|
4884
4932
|
return of(false);
|
|
4885
4933
|
}
|
|
4886
4934
|
return of(true).pipe(takeUntilDestroyed(this._destroyRef), switchMap$1(v => {
|
|
4887
4935
|
const waitForPreparation = this.waitForPreparation();
|
|
4888
4936
|
if (waitForPreparation) {
|
|
4889
|
-
|
|
4937
|
+
prevScrollStateVersion = EMPTY_SCROLL_STATE_VERSION;
|
|
4938
|
+
updateIterations = 0;
|
|
4939
|
+
return $updateComplete.pipe(takeUntilDestroyed(this._destroyRef), take(1), tap(() => {
|
|
4890
4940
|
prepared = readyToStart = true;
|
|
4891
4941
|
const waitForPreparation = this.waitForPreparation(), scrollerComponent = this._scrollerComponent();
|
|
4892
4942
|
if (scrollerComponent) {
|
|
@@ -5065,9 +5115,8 @@ class NgVirtualListComponent {
|
|
|
5065
5115
|
const { snapScrollToBottom, bounds, listBounds, scrollEndOffset, items, itemConfigMap, scrollSize, itemSize, bufferSize, maxBufferSize, snap, isVertical, dynamicSize, enabledBufferOptimization, cacheVersion, } = params;
|
|
5066
5116
|
const scroller = this._scrollerComponent();
|
|
5067
5117
|
if (scroller) {
|
|
5068
|
-
let actualScrollSize =
|
|
5069
|
-
(isVertical ? scroller.
|
|
5070
|
-
(isVertical ? scroller.actualScrollTop ?? 0 : scroller.actualScrollLeft ?? 0), totalSize = 0, displayItems;
|
|
5118
|
+
let actualScrollSize = !prepared && snapScrollToBottom ? (isVertical ? scroller.scrollHeight ?? 0 : scroller.scrollWidth ?? 0) :
|
|
5119
|
+
(isVertical ? scroller.scrollTop ?? 0 : scroller.scrollLeft ?? 0), totalSize = 0, displayItems;
|
|
5071
5120
|
const { width, height, x, y } = bounds, viewportSize = (isVertical ? height : width);
|
|
5072
5121
|
let scrollLength = Math.round(this._totalSize()) ?? 0, actualScrollLength = Math.round(scrollLength === 0 ? 0 : scrollLength > viewportSize ? scrollLength - viewportSize : scrollLength), roundedMaxPosition = Math.round(actualScrollLength), scrollPosition = Math.round(actualScrollSize);
|
|
5073
5122
|
const opts = {
|
|
@@ -5104,7 +5153,8 @@ class NgVirtualListComponent {
|
|
|
5104
5153
|
this._isScrollFinished.set(scrollPosition >= roundedMaxPosition);
|
|
5105
5154
|
}
|
|
5106
5155
|
}
|
|
5107
|
-
actualScrollSize = (isVertical ? scroller.
|
|
5156
|
+
actualScrollSize = !prepared && snapScrollToBottom ? (isVertical ? scroller.scrollHeight ?? 0 : scroller.scrollWidth ?? 0) :
|
|
5157
|
+
(isVertical ? scroller.scrollTop ?? 0 : scroller.scrollLeft ?? 0);
|
|
5108
5158
|
const delta = this._trackBox.delta, roundedActualScrollSize = Math.round(actualScrollSize), scrollPositionAfterUpdate = actualScrollSize + delta, roundedScrollPositionAfterUpdate = Math.round(scrollPositionAfterUpdate), roundedMaxPositionAfterUpdate = Math.round(totalSize - viewportSize);
|
|
5109
5159
|
if (this._isSnappingMethodAdvanced) {
|
|
5110
5160
|
this.updateRegularRenderer();
|
|
@@ -5120,12 +5170,14 @@ class NgVirtualListComponent {
|
|
|
5120
5170
|
}
|
|
5121
5171
|
this._trackBox.isScrollEnd = true;
|
|
5122
5172
|
if (roundedMaxPositionAfterUpdate > 0) {
|
|
5123
|
-
const
|
|
5173
|
+
const params = {
|
|
5124
5174
|
[isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: roundedMaxPositionAfterUpdate,
|
|
5125
|
-
fireUpdate:
|
|
5175
|
+
fireUpdate: false, behavior: BEHAVIOR_INSTANT,
|
|
5126
5176
|
blending: false, duration: this.animationParams().scrollToItem,
|
|
5127
5177
|
};
|
|
5128
5178
|
scroller?.scrollTo?.(params);
|
|
5179
|
+
this._$update.next(getScrollStateVersion(this._isVertical ? scroller.scrollTop : scroller.scrollLeft, cacheVersion));
|
|
5180
|
+
return;
|
|
5129
5181
|
}
|
|
5130
5182
|
}
|
|
5131
5183
|
else if (roundedActualScrollSize !== roundedScrollPositionAfterUpdate && scrollPositionAfterUpdate > 0) {
|
|
@@ -5137,18 +5189,20 @@ class NgVirtualListComponent {
|
|
|
5137
5189
|
if (this._scrollSize() !== scrollPositionAfterUpdate) {
|
|
5138
5190
|
const params = {
|
|
5139
5191
|
[isVertical ? TOP_PROP_NAME : LEFT_PROP_NAME]: scrollPositionAfterUpdate, blending: prepared && readyToStart,
|
|
5140
|
-
fireUpdate:
|
|
5192
|
+
fireUpdate: false, behavior: BEHAVIOR_INSTANT, duration: this.animationParams().scrollToItem,
|
|
5141
5193
|
};
|
|
5142
5194
|
scroller.scrollTo(params);
|
|
5195
|
+
this._$update.next(getScrollStateVersion(this._isVertical ? scroller.scrollTop : scroller.scrollLeft, cacheVersion));
|
|
5196
|
+
return;
|
|
5143
5197
|
}
|
|
5144
5198
|
}
|
|
5145
5199
|
if (!prepared && !readyToStart) {
|
|
5146
|
-
this._$update.next();
|
|
5200
|
+
this._$update.next(getScrollStateVersion(this._isVertical ? scroller.scrollTop : scroller.scrollLeft, cacheVersion));
|
|
5147
5201
|
}
|
|
5148
5202
|
}
|
|
5149
5203
|
};
|
|
5150
5204
|
combineLatest([$snapScrollToBottom, $bounds, $listBounds, $scrollEndOffset, $actualItems, $itemConfigMap, $scrollSize, $itemSize,
|
|
5151
|
-
$bufferSize, $maxBufferSize, $snap, $isVertical, $dynamicSize, $enabledBufferOptimization, $cacheVersion, this.$
|
|
5205
|
+
$bufferSize, $maxBufferSize, $snap, $isVertical, $dynamicSize, $enabledBufferOptimization, $cacheVersion, this.$fireUpdate,
|
|
5152
5206
|
]).pipe(takeUntilDestroyed(), distinctUntilChanged(), tap(([snapScrollToBottom, bounds, listBounds, scrollEndOffset, items, itemConfigMap, scrollSize, itemSize, bufferSize, maxBufferSize, snap, isVertical, dynamicSize, enabledBufferOptimization, cacheVersion,]) => {
|
|
5153
5207
|
update({
|
|
5154
5208
|
snapScrollToBottom, bounds, listBounds, scrollEndOffset, items, itemConfigMap, scrollSize, itemSize,
|
|
@@ -5225,7 +5279,7 @@ class NgVirtualListComponent {
|
|
|
5225
5279
|
this.onScroll.emit(event);
|
|
5226
5280
|
this._$scroll.next(event);
|
|
5227
5281
|
if (userAction && !this.dynamicSize()) {
|
|
5228
|
-
this._$
|
|
5282
|
+
this._$fireUpdate.next(event);
|
|
5229
5283
|
}
|
|
5230
5284
|
}
|
|
5231
5285
|
})).subscribe();
|
|
@@ -5247,7 +5301,7 @@ class NgVirtualListComponent {
|
|
|
5247
5301
|
this.onScrollEnd.emit(event);
|
|
5248
5302
|
this._$scroll.next(event);
|
|
5249
5303
|
if (userAction && !this.dynamicSize()) {
|
|
5250
|
-
this._$
|
|
5304
|
+
this._$fireUpdate.next(event);
|
|
5251
5305
|
}
|
|
5252
5306
|
}
|
|
5253
5307
|
})).subscribe();
|
|
@@ -5415,7 +5469,7 @@ class NgVirtualListComponent {
|
|
|
5415
5469
|
$collapsedIds.pipe(takeUntilDestroyed(), distinctUntilChanged(), tap(v => {
|
|
5416
5470
|
this._service.setCollapsedIds(v);
|
|
5417
5471
|
})).subscribe();
|
|
5418
|
-
this._$
|
|
5472
|
+
this._$fireUpdate.next({
|
|
5419
5473
|
scrollSize: 0,
|
|
5420
5474
|
scrollWeight: 0,
|
|
5421
5475
|
size: 0,
|