@vaadin/component-base 23.6.2 → 23.6.4

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": "23.6.2",
3
+ "version": "23.6.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,5 +42,5 @@
42
42
  "@vaadin/testing-helpers": "^0.3.2",
43
43
  "sinon": "^13.0.2"
44
44
  },
45
- "gitHead": "2db3b5416b9ba6ee342720970150e2d31cd634cd"
45
+ "gitHead": "5b6742f8777f6ad4e8ad833d4023a84cc55b7be7"
46
46
  }
@@ -44,7 +44,7 @@ const registered = new Set();
44
44
  export const ElementMixin = (superClass) =>
45
45
  class VaadinElementMixin extends DirMixin(superClass) {
46
46
  static get version() {
47
- return '23.6.2';
47
+ return '23.6.4';
48
48
  }
49
49
 
50
50
  /** @protected */
@@ -139,11 +139,15 @@ export class IronListAdapter {
139
139
  }
140
140
 
141
141
  update(startIndex = 0, endIndex = this.size - 1) {
142
+ const updatedElements = [];
142
143
  this.__getVisibleElements().forEach((el) => {
143
144
  if (el.__virtualIndex >= startIndex && el.__virtualIndex <= endIndex) {
144
145
  this.__updateElement(el, el.__virtualIndex, true);
146
+ updatedElements.push(el);
145
147
  }
146
148
  });
149
+
150
+ this.__afterElementsUpdated(updatedElements);
147
151
  }
148
152
 
149
153
  /**
@@ -206,28 +210,40 @@ export class IronListAdapter {
206
210
  this.updateElement(el, index);
207
211
  el.__lastUpdatedIndex = index;
208
212
  }
213
+ }
209
214
 
210
- const elementHeight = el.offsetHeight;
211
- if (elementHeight === 0) {
212
- // If the elements have 0 height after update (for example due to lazy rendering),
213
- // it results in iron-list requesting to create an unlimited count of elements.
214
- // Assign a temporary placeholder sizing to elements that would otherwise end up having
215
- // no height.
216
- el.style.paddingTop = `${this.__placeholderHeight}px`;
217
-
218
- // Manually schedule the resize handler to make sure the placeholder padding is
219
- // cleared in case the resize observer never triggers.
220
- requestAnimationFrame(() => this._resizeHandler());
221
- } else {
222
- // Add element height to the queue
223
- this.__elementHeightQueue.push(elementHeight);
224
- this.__elementHeightQueue.shift();
225
-
226
- // Calcualte new placeholder height based on the average of the defined values in the
227
- // element height queue
228
- const filteredHeights = this.__elementHeightQueue.filter((h) => h !== undefined);
229
- this.__placeholderHeight = Math.round(filteredHeights.reduce((a, b) => a + b, 0) / filteredHeights.length);
230
- }
215
+ /**
216
+ * Called synchronously right after elements have been updated.
217
+ * This is a good place to do any post-update work.
218
+ *
219
+ * @param {!Array<!HTMLElement>} updatedElements
220
+ */
221
+ __afterElementsUpdated(updatedElements) {
222
+ updatedElements.forEach((el) => {
223
+ const elementHeight = el.offsetHeight;
224
+ if (elementHeight === 0) {
225
+ // If the elements have 0 height after update (for example due to lazy rendering),
226
+ // it results in iron-list requesting to create an unlimited count of elements.
227
+ // Assign a temporary placeholder sizing to elements that would otherwise end up having
228
+ // no height.
229
+ el.style.paddingTop = `${this.__placeholderHeight}px`;
230
+
231
+ // Manually schedule the resize handler to make sure the placeholder padding is
232
+ // cleared in case the resize observer never triggers.
233
+ this.__placeholderClearDebouncer = Debouncer.debounce(this.__placeholderClearDebouncer, animationFrame, () =>
234
+ this._resizeHandler(),
235
+ );
236
+ } else {
237
+ // Add element height to the queue
238
+ this.__elementHeightQueue.push(elementHeight);
239
+ this.__elementHeightQueue.shift();
240
+
241
+ // Calculate new placeholder height based on the average of the defined values in the
242
+ // element height queue
243
+ const filteredHeights = this.__elementHeightQueue.filter((h) => h !== undefined);
244
+ this.__placeholderHeight = Math.round(filteredHeights.reduce((a, b) => a + b, 0) / filteredHeights.length);
245
+ }
246
+ });
231
247
  }
232
248
 
233
249
  __getIndexScrollOffset(index) {
@@ -352,16 +368,20 @@ export class IronListAdapter {
352
368
 
353
369
  /** @private */
354
370
  _assignModels(itemSet) {
371
+ const updatedElements = [];
355
372
  this._iterateItems((pidx, vidx) => {
356
373
  const el = this._physicalItems[pidx];
357
374
  el.hidden = vidx >= this.size;
358
375
  if (!el.hidden) {
359
376
  el.__virtualIndex = vidx + (this._vidxOffset || 0);
360
377
  this.__updateElement(el, el.__virtualIndex);
378
+ updatedElements.push(el);
361
379
  } else {
362
380
  delete el.__lastUpdatedIndex;
363
381
  }
364
382
  }, itemSet);
383
+
384
+ this.__afterElementsUpdated(updatedElements);
365
385
  }
366
386
 
367
387
  /** @private */