@vaadin/component-base 24.1.0-alpha4 → 24.1.0-alpha6

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-alpha4",
3
+ "version": "24.1.0-alpha6",
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": "4494259f3b7532acb604a3048d5b29a4e14b9ca5"
45
+ "gitHead": "823673f238b8d5705d475d0b355864183646ce44"
46
46
  }
@@ -45,7 +45,7 @@ const registered = new Set();
45
45
  export const ElementMixin = (superClass) =>
46
46
  class VaadinElementMixin extends DirMixin(superClass) {
47
47
  static get version() {
48
- return '24.1.0-alpha4';
48
+ return '24.1.0-alpha6';
49
49
  }
50
50
 
51
51
  /** @protected */
@@ -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
- const elementHeight = el.offsetHeight;
208
- if (elementHeight === 0) {
209
- // If the elements have 0 height after update (for example due to lazy rendering),
210
- // it results in iron-list requesting to create an unlimited count of elements.
211
- // Assign a temporary placeholder sizing to elements that would otherwise end up having
212
- // no height.
213
- el.style.paddingTop = `${this.__placeholderHeight}px`;
214
-
215
- // Manually schedule the resize handler to make sure the placeholder padding is
216
- // cleared in case the resize observer never triggers.
217
- requestAnimationFrame(() => this._resizeHandler());
218
- } else {
219
- // Add element height to the queue
220
- this.__elementHeightQueue.push(elementHeight);
221
- this.__elementHeightQueue.shift();
222
-
223
- // Calcualte new placeholder height based on the average of the defined values in the
224
- // element height queue
225
- const filteredHeights = this.__elementHeightQueue.filter((h) => h !== undefined);
226
- this.__placeholderHeight = Math.round(filteredHeights.reduce((a, b) => a + b, 0) / filteredHeights.length);
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