@vaadin/component-base 24.1.0-alpha5 → 24.1.0-alpha7
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "24.1.0-
|
|
3
|
+
"version": "24.1.0-alpha7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@vaadin/testing-helpers": "^0.4.0",
|
|
43
43
|
"sinon": "^13.0.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "6711b6ac7b49e2ddc0990c34de9718b58c2d16b3"
|
|
46
46
|
}
|
package/src/element-mixin.js
CHANGED
|
@@ -136,11 +136,15 @@ export class IronListAdapter {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
update(startIndex = 0, endIndex = this.size - 1) {
|
|
139
|
+
const updatedElements = [];
|
|
139
140
|
this.__getVisibleElements().forEach((el) => {
|
|
140
141
|
if (el.__virtualIndex >= startIndex && el.__virtualIndex <= endIndex) {
|
|
141
142
|
this.__updateElement(el, el.__virtualIndex, true);
|
|
143
|
+
updatedElements.push(el);
|
|
142
144
|
}
|
|
143
145
|
});
|
|
146
|
+
|
|
147
|
+
this.__afterElementsUpdated(updatedElements);
|
|
144
148
|
}
|
|
145
149
|
|
|
146
150
|
/**
|
|
@@ -203,28 +207,40 @@ export class IronListAdapter {
|
|
|
203
207
|
this.updateElement(el, index);
|
|
204
208
|
el.__lastUpdatedIndex = index;
|
|
205
209
|
}
|
|
210
|
+
}
|
|
206
211
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Called synchronously right after elements have been updated.
|
|
214
|
+
* This is a good place to do any post-update work.
|
|
215
|
+
*
|
|
216
|
+
* @param {!Array<!HTMLElement>} updatedElements
|
|
217
|
+
*/
|
|
218
|
+
__afterElementsUpdated(updatedElements) {
|
|
219
|
+
updatedElements.forEach((el) => {
|
|
220
|
+
const elementHeight = el.offsetHeight;
|
|
221
|
+
if (elementHeight === 0) {
|
|
222
|
+
// If the elements have 0 height after update (for example due to lazy rendering),
|
|
223
|
+
// it results in iron-list requesting to create an unlimited count of elements.
|
|
224
|
+
// Assign a temporary placeholder sizing to elements that would otherwise end up having
|
|
225
|
+
// no height.
|
|
226
|
+
el.style.paddingTop = `${this.__placeholderHeight}px`;
|
|
227
|
+
|
|
228
|
+
// Manually schedule the resize handler to make sure the placeholder padding is
|
|
229
|
+
// cleared in case the resize observer never triggers.
|
|
230
|
+
this.__placeholderClearDebouncer = Debouncer.debounce(this.__placeholderClearDebouncer, animationFrame, () =>
|
|
231
|
+
this._resizeHandler(),
|
|
232
|
+
);
|
|
233
|
+
} else {
|
|
234
|
+
// Add element height to the queue
|
|
235
|
+
this.__elementHeightQueue.push(elementHeight);
|
|
236
|
+
this.__elementHeightQueue.shift();
|
|
237
|
+
|
|
238
|
+
// Calculate new placeholder height based on the average of the defined values in the
|
|
239
|
+
// element height queue
|
|
240
|
+
const filteredHeights = this.__elementHeightQueue.filter((h) => h !== undefined);
|
|
241
|
+
this.__placeholderHeight = Math.round(filteredHeights.reduce((a, b) => a + b, 0) / filteredHeights.length);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
228
244
|
}
|
|
229
245
|
|
|
230
246
|
__getIndexScrollOffset(index) {
|
|
@@ -335,16 +351,20 @@ export class IronListAdapter {
|
|
|
335
351
|
|
|
336
352
|
/** @private */
|
|
337
353
|
_assignModels(itemSet) {
|
|
354
|
+
const updatedElements = [];
|
|
338
355
|
this._iterateItems((pidx, vidx) => {
|
|
339
356
|
const el = this._physicalItems[pidx];
|
|
340
357
|
el.hidden = vidx >= this.size;
|
|
341
358
|
if (!el.hidden) {
|
|
342
359
|
el.__virtualIndex = vidx + (this._vidxOffset || 0);
|
|
343
360
|
this.__updateElement(el, el.__virtualIndex);
|
|
361
|
+
updatedElements.push(el);
|
|
344
362
|
} else {
|
|
345
363
|
delete el.__lastUpdatedIndex;
|
|
346
364
|
}
|
|
347
365
|
}, itemSet);
|
|
366
|
+
|
|
367
|
+
this.__afterElementsUpdated(updatedElements);
|
|
348
368
|
}
|
|
349
369
|
|
|
350
370
|
/** @private */
|
|
@@ -543,6 +563,29 @@ export class IronListAdapter {
|
|
|
543
563
|
);
|
|
544
564
|
}
|
|
545
565
|
|
|
566
|
+
/**
|
|
567
|
+
* Increases the pool size.
|
|
568
|
+
* @override
|
|
569
|
+
*/
|
|
570
|
+
_increasePoolIfNeeded(count) {
|
|
571
|
+
if (this._physicalCount > 2 && count) {
|
|
572
|
+
// The iron-list logic has already created some physical items and
|
|
573
|
+
// has decided to create more. Since each item creation round is
|
|
574
|
+
// expensive, let's try to create the remaining items in one go.
|
|
575
|
+
|
|
576
|
+
// Calculate the total item count that would be needed to fill the viewport
|
|
577
|
+
// plus the buffer assuming rest of the items to be of the average size
|
|
578
|
+
// of the items already created.
|
|
579
|
+
const totalItemCount = Math.ceil(this._optPhysicalSize / this._physicalAverage);
|
|
580
|
+
const missingItemCount = totalItemCount - this._physicalCount;
|
|
581
|
+
// Create the remaining items in one go. Use a maximum of 100 items
|
|
582
|
+
// as a safety measure.
|
|
583
|
+
super._increasePoolIfNeeded(Math.max(count, Math.min(100, missingItemCount)));
|
|
584
|
+
} else {
|
|
585
|
+
super._increasePoolIfNeeded(count);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
546
589
|
/**
|
|
547
590
|
* @returns {Number|undefined} - The browser's default font-size in pixels
|
|
548
591
|
* @private
|