@vaadin/component-base 24.4.0-alpha17 → 24.4.0-alpha18
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/package.json +2 -2
- package/src/define.js +1 -1
- package/src/virtualizer-iron-list-adapter.js +39 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "24.4.0-
|
|
3
|
+
"version": "24.4.0-alpha18",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@vaadin/testing-helpers": "^0.6.0",
|
|
43
43
|
"sinon": "^13.0.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "7d675c61eaa32ef50c07de7b2fea19ff437b6b90"
|
|
46
46
|
}
|
package/src/define.js
CHANGED
|
@@ -89,6 +89,10 @@ export class IronListAdapter {
|
|
|
89
89
|
return this.lastVisibleIndex + this._vidxOffset;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
get _maxVirtualIndexOffset() {
|
|
93
|
+
return this.size - this._virtualCount;
|
|
94
|
+
}
|
|
95
|
+
|
|
92
96
|
__hasPlaceholders() {
|
|
93
97
|
return this.__getVisibleElements().some((el) => el.__virtualizerPlaceholder);
|
|
94
98
|
}
|
|
@@ -113,7 +117,7 @@ export class IronListAdapter {
|
|
|
113
117
|
let targetVirtualIndex = Math.floor((index / this.size) * this._virtualCount);
|
|
114
118
|
if (this._virtualCount - targetVirtualIndex < visibleElementCount) {
|
|
115
119
|
targetVirtualIndex = this._virtualCount - (this.size - index);
|
|
116
|
-
this._vidxOffset = this.
|
|
120
|
+
this._vidxOffset = this._maxVirtualIndexOffset;
|
|
117
121
|
} else if (targetVirtualIndex < visibleElementCount) {
|
|
118
122
|
if (index < OFFSET_ADJUST_MIN_THRESHOLD) {
|
|
119
123
|
targetVirtualIndex = index;
|
|
@@ -300,24 +304,41 @@ export class IronListAdapter {
|
|
|
300
304
|
this._debouncers._increasePoolIfNeeded.cancel();
|
|
301
305
|
}
|
|
302
306
|
|
|
307
|
+
// Prevent element update while the scroll position is being restored
|
|
308
|
+
this.__preventElementUpdates = true;
|
|
309
|
+
|
|
310
|
+
// Record the scroll position before changing the size
|
|
311
|
+
let fvi; // First visible index
|
|
312
|
+
let fviOffsetBefore; // Scroll offset of the first visible index
|
|
313
|
+
if (size > 0) {
|
|
314
|
+
fvi = this.adjustedFirstVisibleIndex;
|
|
315
|
+
fviOffsetBefore = this.__getIndexScrollOffset(fvi);
|
|
316
|
+
}
|
|
317
|
+
|
|
303
318
|
// Change the size
|
|
304
319
|
this.__size = size;
|
|
305
320
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
//
|
|
316
|
-
|
|
317
|
-
this.
|
|
318
|
-
|
|
321
|
+
this._itemsChanged({
|
|
322
|
+
path: 'items',
|
|
323
|
+
});
|
|
324
|
+
flush();
|
|
325
|
+
|
|
326
|
+
// Try to restore the scroll position if the new size is larger than 0
|
|
327
|
+
if (size > 0) {
|
|
328
|
+
fvi = Math.min(fvi, size - 1);
|
|
329
|
+
// Note, calling scrollToIndex also updates the virtual index offset,
|
|
330
|
+
// causing the virtualizer to add more items when size is increased,
|
|
331
|
+
// and remove exceeding items when size is decreased.
|
|
332
|
+
this.scrollToIndex(fvi);
|
|
333
|
+
|
|
334
|
+
const fviOffsetAfter = this.__getIndexScrollOffset(fvi);
|
|
335
|
+
if (fviOffsetBefore !== undefined && fviOffsetAfter !== undefined) {
|
|
336
|
+
this._scrollTop += fviOffsetBefore - fviOffsetAfter;
|
|
337
|
+
}
|
|
319
338
|
}
|
|
320
339
|
|
|
340
|
+
this.__preventElementUpdates = false;
|
|
341
|
+
|
|
321
342
|
// When reducing size while invisible, iron-list does not update items, so
|
|
322
343
|
// their hidden state is not updated and their __lastUpdatedIndex is not
|
|
323
344
|
// reset. In that case force an update here.
|
|
@@ -329,8 +350,7 @@ export class IronListAdapter {
|
|
|
329
350
|
requestAnimationFrame(() => this._resizeHandler());
|
|
330
351
|
}
|
|
331
352
|
|
|
332
|
-
// Schedule and flush a resize handler
|
|
333
|
-
// re-render for the elements.
|
|
353
|
+
// Schedule and flush a resize handler
|
|
334
354
|
this._resizeHandler();
|
|
335
355
|
flush();
|
|
336
356
|
}
|
|
@@ -769,6 +789,8 @@ export class IronListAdapter {
|
|
|
769
789
|
|
|
770
790
|
/** @private */
|
|
771
791
|
_adjustVirtualIndexOffset(delta) {
|
|
792
|
+
const maxOffset = this._maxVirtualIndexOffset;
|
|
793
|
+
|
|
772
794
|
if (this._virtualCount >= this.size) {
|
|
773
795
|
this._vidxOffset = 0;
|
|
774
796
|
} else if (this.__skipNextVirtualIndexAdjust) {
|
|
@@ -776,8 +798,7 @@ export class IronListAdapter {
|
|
|
776
798
|
} else if (Math.abs(delta) > 10000) {
|
|
777
799
|
// Process a large scroll position change
|
|
778
800
|
const scale = this._scrollTop / (this.scrollTarget.scrollHeight - this.scrollTarget.offsetHeight);
|
|
779
|
-
|
|
780
|
-
this._vidxOffset = Math.round(offset - scale * this._virtualCount);
|
|
801
|
+
this._vidxOffset = Math.round(scale * maxOffset);
|
|
781
802
|
} else {
|
|
782
803
|
// Make sure user can always swipe/wheel scroll to the start and end
|
|
783
804
|
const oldOffset = this._vidxOffset;
|
|
@@ -796,7 +817,6 @@ export class IronListAdapter {
|
|
|
796
817
|
}
|
|
797
818
|
|
|
798
819
|
// Near end
|
|
799
|
-
const maxOffset = this.size - this._virtualCount;
|
|
800
820
|
if (this._scrollTop >= this._maxScrollTop && this._maxScrollTop > 0) {
|
|
801
821
|
this._vidxOffset = maxOffset;
|
|
802
822
|
if (oldOffset !== this._vidxOffset) {
|