ng-virtual-list 19.7.16 → 19.7.17
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.
|
@@ -110,6 +110,7 @@ const CLASS_LIST_VERTICAL = 'vertical';
|
|
|
110
110
|
const CLASS_LIST_HORIZONTAL = 'horizontal';
|
|
111
111
|
// styles
|
|
112
112
|
const PART_DEFAULT_ITEM = 'item';
|
|
113
|
+
const PART_ITEM_NEW = ' item-new';
|
|
113
114
|
const PART_ITEM_ODD = ' item-odd';
|
|
114
115
|
const PART_ITEM_EVEN = ' item-even';
|
|
115
116
|
const PART_ITEM_SNAPPED = ' item-snapped';
|
|
@@ -644,6 +645,9 @@ class NgVirtualListItemComponent extends BaseVirtualListItemComponent {
|
|
|
644
645
|
if (isCollapsed) {
|
|
645
646
|
part += PART_ITEM_COLLAPSED;
|
|
646
647
|
}
|
|
648
|
+
if (v ? v.config.new : false) {
|
|
649
|
+
part += PART_ITEM_NEW;
|
|
650
|
+
}
|
|
647
651
|
if (this.focus()) {
|
|
648
652
|
part += PART_ITEM_FOCUSED;
|
|
649
653
|
}
|
|
@@ -1329,6 +1333,7 @@ class TrackBox extends CacheMap {
|
|
|
1329
1333
|
_maxBufferSize = this._defaultBufferSize;
|
|
1330
1334
|
_resetBufferSizeTimeout = DEFAULT_RESET_BUFFER_SIZE_TIMEOUT;
|
|
1331
1335
|
_resetBufferSizeTimer;
|
|
1336
|
+
isInit = true;
|
|
1332
1337
|
lifeCircle() {
|
|
1333
1338
|
this.fireChangeIfNeed();
|
|
1334
1339
|
this.lifeCircleDo();
|
|
@@ -1341,6 +1346,9 @@ class TrackBox extends CacheMap {
|
|
|
1341
1346
|
console.warn('Attention! The collection must be immutable.');
|
|
1342
1347
|
return;
|
|
1343
1348
|
}
|
|
1349
|
+
if (this.isInit && !(!this._previousCollection || this._previousCollection.length === 0)) {
|
|
1350
|
+
this.isInit = false;
|
|
1351
|
+
}
|
|
1344
1352
|
this.updateCache(this._previousCollection, currentCollection, itemSize);
|
|
1345
1353
|
this._previousCollection = currentCollection;
|
|
1346
1354
|
}
|
|
@@ -1564,10 +1572,10 @@ class TrackBox extends CacheMap {
|
|
|
1564
1572
|
else {
|
|
1565
1573
|
leftItemsOffset = rightItemsOffset = bufferSize;
|
|
1566
1574
|
}
|
|
1567
|
-
let itemsFromStartToScrollEnd = -1, itemsFromDisplayEndToOffsetEnd = 0, itemsFromStartToDisplayEnd = -1, leftItemLength = 0, rightItemLength = 0, leftItemsWeight = 0, rightItemsWeight = 0, leftHiddenItemsWeight = 0, totalItemsToDisplayEndWeight = 0, leftSizeOfAddedItems = 0, leftSizeOfUpdatedItems = 0, leftSizeOfDeletedItems = 0, itemById = undefined, itemByIdPos = 0, targetDisplayItemIndex = -1, isTargetInOverscroll = false, actualScrollSize = itemByIdPos, totalSize = 0, startIndex, isFromItemIdFound = false;
|
|
1575
|
+
let itemsFromStartToScrollEnd = -1, itemsFromDisplayEndToOffsetEnd = 0, itemsFromStartToDisplayEnd = -1, leftItemLength = 0, rightItemLength = 0, leftItemsWeight = 0, rightItemsWeight = 0, leftHiddenItemsWeight = 0, totalItemsToDisplayEndWeight = 0, leftSizeOfAddedItems = 0, leftSizeOfUpdatedItems = 0, leftSizeOfDeletedItems = 0, itemById = undefined, itemByIdPos = 0, targetDisplayItemIndex = -1, isTargetInOverscroll = false, actualScrollSize = itemByIdPos, totalSize = 0, startIndex, isFromItemIdFound = false, deltaFromStartCreation = 0;
|
|
1568
1576
|
// If the list is dynamic or there are new elements in the collection, then it switches to the long algorithm.
|
|
1569
1577
|
if (dynamicSize) {
|
|
1570
|
-
let y = 0, stickyCollectionItem = undefined, stickyComponentSize = 0;
|
|
1578
|
+
let y = 0, stickyCollectionItem = undefined, stickyComponentSize = 0, isNew = true;
|
|
1571
1579
|
for (let i = 0, l = collection.length; i < l; i++) {
|
|
1572
1580
|
const ii = i + 1, collectionItem = collection[i], id = collectionItem.id;
|
|
1573
1581
|
let componentSize = 0, componentSizeDelta = 0, itemDisplayMethod = ItemDisplayMethods.NOT_CHANGED;
|
|
@@ -1575,17 +1583,24 @@ class TrackBox extends CacheMap {
|
|
|
1575
1583
|
const bounds = map.get(id) || { width: typicalItemSize, height: typicalItemSize };
|
|
1576
1584
|
componentSize = bounds[sizeProperty];
|
|
1577
1585
|
itemDisplayMethod = bounds?.method ?? ItemDisplayMethods.UPDATE;
|
|
1586
|
+
if (isNew && (this.isInit || itemDisplayMethod !== ItemDisplayMethods.CREATE)) {
|
|
1587
|
+
isNew = false;
|
|
1588
|
+
}
|
|
1578
1589
|
switch (itemDisplayMethod) {
|
|
1579
1590
|
case ItemDisplayMethods.UPDATE: {
|
|
1591
|
+
const isUpdatedNew = bounds.isNew;
|
|
1580
1592
|
const snapshotBounds = snapshot.get(id);
|
|
1581
1593
|
const componentSnapshotSize = componentSize - (snapshotBounds ? snapshotBounds[sizeProperty] : typicalItemSize);
|
|
1582
|
-
componentSizeDelta = componentSnapshotSize;
|
|
1583
|
-
map.set(id, { ...bounds, method: ItemDisplayMethods.NOT_CHANGED });
|
|
1594
|
+
componentSizeDelta = isUpdatedNew ? 0 : componentSnapshotSize;
|
|
1595
|
+
map.set(id, { ...bounds, method: ItemDisplayMethods.NOT_CHANGED, isNew: false });
|
|
1596
|
+
if (isUpdatedNew) {
|
|
1597
|
+
deltaFromStartCreation += componentSize;
|
|
1598
|
+
}
|
|
1584
1599
|
break;
|
|
1585
1600
|
}
|
|
1586
1601
|
case ItemDisplayMethods.CREATE: {
|
|
1587
|
-
componentSizeDelta = typicalItemSize;
|
|
1588
|
-
map.set(id, { ...bounds, method: ItemDisplayMethods.NOT_CHANGED });
|
|
1602
|
+
componentSizeDelta = isNew ? 0 : typicalItemSize;
|
|
1603
|
+
map.set(id, { ...bounds, method: isNew ? ItemDisplayMethods.UPDATE : ItemDisplayMethods.NOT_CHANGED, isNew });
|
|
1589
1604
|
break;
|
|
1590
1605
|
}
|
|
1591
1606
|
}
|
|
@@ -1749,7 +1764,7 @@ class TrackBox extends CacheMap {
|
|
|
1749
1764
|
actualScrollSize = scrollSize * k;
|
|
1750
1765
|
}
|
|
1751
1766
|
startIndex = Math.min(itemsFromStartToScrollEnd - leftItemLength, totalLength > 0 ? totalLength - 1 : 0);
|
|
1752
|
-
const itemsOnDisplayWeight = totalItemsToDisplayEndWeight - leftItemsWeight, itemsOnDisplayLength = itemsFromStartToDisplayEnd - itemsFromStartToScrollEnd, startPosition = leftHiddenItemsWeight - leftItemsWeight, renderItems = itemsOnDisplayLength + leftItemLength + rightItemLength, delta = leftSizeOfUpdatedItems + leftSizeOfAddedItems - leftSizeOfDeletedItems;
|
|
1767
|
+
const itemsOnDisplayWeight = totalItemsToDisplayEndWeight - leftItemsWeight, itemsOnDisplayLength = itemsFromStartToDisplayEnd - itemsFromStartToScrollEnd, startPosition = leftHiddenItemsWeight - leftItemsWeight, renderItems = itemsOnDisplayLength + leftItemLength + rightItemLength, delta = leftSizeOfUpdatedItems + leftSizeOfAddedItems - leftSizeOfDeletedItems + deltaFromStartCreation;
|
|
1753
1768
|
const metrics = {
|
|
1754
1769
|
delta,
|
|
1755
1770
|
normalizedItemWidth: w,
|
|
@@ -1806,7 +1821,7 @@ class TrackBox extends CacheMap {
|
|
|
1806
1821
|
if (!items[i]) {
|
|
1807
1822
|
continue;
|
|
1808
1823
|
}
|
|
1809
|
-
const id = items[i].id, sticky = itemConfigMap[id]?.sticky ?? 0, selectable = itemConfigMap[id]?.selectable ?? true, collapsable = itemConfigMap[id]?.collapsable ?? false, size = dynamicSize ?
|
|
1824
|
+
const id = items[i].id, cache = this.get(id), sticky = itemConfigMap[id]?.sticky ?? 0, selectable = itemConfigMap[id]?.selectable ?? true, collapsable = itemConfigMap[id]?.collapsable ?? false, size = dynamicSize ? cache?.[sizeProperty] || typicalItemSize : typicalItemSize;
|
|
1810
1825
|
if (sticky === 1) {
|
|
1811
1826
|
const isOdd = i % 2 != 0, measures = {
|
|
1812
1827
|
x: isVertical ? 0 : actualSnippedPosition,
|
|
@@ -1815,6 +1830,7 @@ class TrackBox extends CacheMap {
|
|
|
1815
1830
|
height: isVertical ? size : normalizedItemHeight,
|
|
1816
1831
|
delta: 0,
|
|
1817
1832
|
}, config = {
|
|
1833
|
+
new: cache.isNew === true,
|
|
1818
1834
|
odd: isOdd,
|
|
1819
1835
|
even: !isOdd,
|
|
1820
1836
|
isVertical,
|
|
@@ -1845,8 +1861,8 @@ class TrackBox extends CacheMap {
|
|
|
1845
1861
|
if (!items[i]) {
|
|
1846
1862
|
continue;
|
|
1847
1863
|
}
|
|
1848
|
-
const id = items[i].id, sticky = itemConfigMap[id]?.sticky ?? 0, selectable = itemConfigMap[id]?.selectable ?? true, collapsable = itemConfigMap[id]?.collapsable ?? false, size = dynamicSize
|
|
1849
|
-
?
|
|
1864
|
+
const id = items[i].id, cache = this.get(id), sticky = itemConfigMap[id]?.sticky ?? 0, selectable = itemConfigMap[id]?.selectable ?? true, collapsable = itemConfigMap[id]?.collapsable ?? false, size = dynamicSize
|
|
1865
|
+
? cache?.[sizeProperty] || typicalItemSize
|
|
1850
1866
|
: typicalItemSize;
|
|
1851
1867
|
if (sticky === 2) {
|
|
1852
1868
|
const isOdd = i % 2 != 0, w = isVertical ? normalizedItemWidth : size, h = isVertical ? size : normalizedItemHeight, measures = {
|
|
@@ -1856,6 +1872,7 @@ class TrackBox extends CacheMap {
|
|
|
1856
1872
|
height: h,
|
|
1857
1873
|
delta: 0,
|
|
1858
1874
|
}, config = {
|
|
1875
|
+
new: cache.isNew === true,
|
|
1859
1876
|
odd: isOdd,
|
|
1860
1877
|
even: !isOdd,
|
|
1861
1878
|
isVertical,
|
|
@@ -1887,7 +1904,7 @@ class TrackBox extends CacheMap {
|
|
|
1887
1904
|
if (!items[i]) {
|
|
1888
1905
|
continue;
|
|
1889
1906
|
}
|
|
1890
|
-
const id = items[i].id,
|
|
1907
|
+
const id = items[i].id, cache = this.get(id), size = dynamicSize ? cache?.[sizeProperty] || typicalItemSize : typicalItemSize;
|
|
1891
1908
|
if (id !== stickyItem?.id && id !== endStickyItem?.id) {
|
|
1892
1909
|
const isOdd = i % 2 != 0, sticky = itemConfigMap[id]?.sticky ?? 0, selectable = itemConfigMap[id]?.selectable ?? true, collapsable = itemConfigMap[id]?.collapsable ?? false, snapped = snap && (sticky === 1 && pos <= scrollSize || sticky === 2 && pos >= scrollSize + boundsSize - size), measures = {
|
|
1893
1910
|
x: isVertical ? sticky === 1 ? 0 : boundsSize - size : pos,
|
|
@@ -1896,6 +1913,7 @@ class TrackBox extends CacheMap {
|
|
|
1896
1913
|
height: isVertical ? size : normalizedItemHeight,
|
|
1897
1914
|
delta: 0,
|
|
1898
1915
|
}, config = {
|
|
1916
|
+
new: cache.isNew === true,
|
|
1899
1917
|
odd: isOdd,
|
|
1900
1918
|
even: !isOdd,
|
|
1901
1919
|
isVertical,
|
|
@@ -1999,7 +2017,7 @@ class TrackBox extends CacheMap {
|
|
|
1999
2017
|
continue;
|
|
2000
2018
|
}
|
|
2001
2019
|
const bounds = component.instance.getBounds();
|
|
2002
|
-
this.set(itemId, bounds);
|
|
2020
|
+
this.set(itemId, { ...(this.get(itemId) || {}), ...bounds });
|
|
2003
2021
|
}
|
|
2004
2022
|
}
|
|
2005
2023
|
dispose() {
|