@vaadin/component-base 25.0.0-alpha18 → 25.0.0-alpha19

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": "25.0.0-alpha18",
3
+ "version": "25.0.0-alpha19",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,15 +33,15 @@
33
33
  "dependencies": {
34
34
  "@open-wc/dedupe-mixin": "^1.3.0",
35
35
  "@vaadin/vaadin-development-mode-detector": "^2.0.0",
36
- "@vaadin/vaadin-themable-mixin": "25.0.0-alpha18",
36
+ "@vaadin/vaadin-themable-mixin": "25.0.0-alpha19",
37
37
  "@vaadin/vaadin-usage-statistics": "^2.1.0",
38
38
  "lit": "^3.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@vaadin/chai-plugins": "25.0.0-alpha18",
42
- "@vaadin/test-runner-commands": "25.0.0-alpha18",
41
+ "@vaadin/chai-plugins": "25.0.0-alpha19",
42
+ "@vaadin/test-runner-commands": "25.0.0-alpha19",
43
43
  "@vaadin/testing-helpers": "^2.0.0",
44
44
  "sinon": "^21.0.0"
45
45
  },
46
- "gitHead": "cb5cafb5687a117ebead1b81e2116991cec13abe"
46
+ "gitHead": "1f9af1ce5f0bae8daff044176c8a8df697763881"
47
47
  }
package/src/define.js CHANGED
@@ -13,7 +13,7 @@ function dashToCamelCase(dash) {
13
13
 
14
14
  const experimentalMap = {};
15
15
 
16
- export function defineCustomElement(CustomElement, version = '25.0.0-alpha18') {
16
+ export function defineCustomElement(CustomElement, version = '25.0.0-alpha19') {
17
17
  Object.defineProperty(CustomElement, 'version', {
18
18
  get() {
19
19
  return version;
@@ -14,15 +14,29 @@ const MAX_VIRTUAL_COUNT = 100000;
14
14
  const OFFSET_ADJUST_MIN_THRESHOLD = 1000;
15
15
 
16
16
  export class IronListAdapter {
17
- constructor({ createElements, updateElement, scrollTarget, scrollContainer, elementsContainer, reorderElements }) {
17
+ constructor({
18
+ createElements,
19
+ updateElement,
20
+ scrollTarget,
21
+ scrollContainer,
22
+ reorderElements,
23
+ elementsContainer,
24
+ __disableHeightPlaceholder,
25
+ }) {
18
26
  this.isAttached = true;
19
27
  this._vidxOffset = 0;
20
28
  this.createElements = createElements;
21
29
  this.updateElement = updateElement;
22
30
  this.scrollTarget = scrollTarget;
23
31
  this.scrollContainer = scrollContainer;
24
- this.elementsContainer = elementsContainer || scrollContainer;
25
32
  this.reorderElements = reorderElements;
33
+ this.elementsContainer = elementsContainer || scrollContainer;
34
+
35
+ // Internal option that disables the heavy height placeholder calculation
36
+ // (see __afterElementsUpdated) for components that always render virtual
37
+ // elements with a non-zero height. Not for public use.
38
+ this.__disableHeightPlaceholder = __disableHeightPlaceholder ?? false;
39
+
26
40
  // Iron-list uses this value to determine how many pages of elements to render
27
41
  this._maxPages = 1.3;
28
42
 
@@ -270,33 +284,35 @@ export class IronListAdapter {
270
284
  * @param {!Array<!HTMLElement>} updatedElements
271
285
  */
272
286
  __afterElementsUpdated(updatedElements) {
273
- updatedElements.forEach((el) => {
274
- const elementHeight = el.offsetHeight;
275
- if (elementHeight === 0) {
276
- // If the elements have 0 height after update (for example due to lazy rendering),
277
- // it results in iron-list requesting to create an unlimited count of elements.
278
- // Assign a temporary placeholder sizing to elements that would otherwise end up having
279
- // no height.
280
- el.style.paddingTop = `${this.__placeholderHeight}px`;
281
- el.style.opacity = '0';
282
- el.__virtualizerPlaceholder = true;
283
-
284
- // Manually schedule the resize handler to make sure the placeholder padding is
285
- // cleared in case the resize observer never triggers.
286
- this.__placeholderClearDebouncer = Debouncer.debounce(this.__placeholderClearDebouncer, animationFrame, () =>
287
- this._resizeHandler(),
288
- );
289
- } else {
290
- // Add element height to the queue
291
- this.__elementHeightQueue.push(elementHeight);
292
- this.__elementHeightQueue.shift();
293
-
294
- // Calculate new placeholder height based on the average of the defined values in the
295
- // element height queue
296
- const filteredHeights = this.__elementHeightQueue.filter((h) => h !== undefined);
297
- this.__placeholderHeight = Math.round(filteredHeights.reduce((a, b) => a + b, 0) / filteredHeights.length);
298
- }
299
- });
287
+ if (!this.__disableHeightPlaceholder) {
288
+ updatedElements.forEach((el) => {
289
+ const elementHeight = el.offsetHeight;
290
+ if (elementHeight === 0) {
291
+ // If the elements have 0 height after update (for example due to lazy rendering),
292
+ // it results in iron-list requesting to create an unlimited count of elements.
293
+ // Assign a temporary placeholder sizing to elements that would otherwise end up having
294
+ // no height.
295
+ el.style.paddingTop = `${this.__placeholderHeight}px`;
296
+ el.style.opacity = '0';
297
+ el.__virtualizerPlaceholder = true;
298
+
299
+ // Manually schedule the resize handler to make sure the placeholder padding is
300
+ // cleared in case the resize observer never triggers.
301
+ this.__placeholderClearDebouncer = Debouncer.debounce(this.__placeholderClearDebouncer, animationFrame, () =>
302
+ this._resizeHandler(),
303
+ );
304
+ } else {
305
+ // Add element height to the queue
306
+ this.__elementHeightQueue.push(elementHeight);
307
+ this.__elementHeightQueue.shift();
308
+
309
+ // Calculate new placeholder height based on the average of the defined values in the
310
+ // element height queue
311
+ const filteredHeights = this.__elementHeightQueue.filter((h) => h !== undefined);
312
+ this.__placeholderHeight = Math.round(filteredHeights.reduce((a, b) => a + b, 0) / filteredHeights.length);
313
+ }
314
+ });
315
+ }
300
316
 
301
317
  if (this.__pendingScrollToIndex !== undefined && !this.__hasPlaceholders()) {
302
318
  this.scrollToIndex(this.__pendingScrollToIndex);
@@ -547,8 +563,8 @@ export class IronListAdapter {
547
563
  return;
548
564
  }
549
565
 
550
- this._adjustVirtualIndexOffset(this._scrollTop - (this.__previousScrollTop || 0));
551
- const delta = this.scrollTarget.scrollTop - this._scrollPosition;
566
+ this._adjustVirtualIndexOffset(this._scrollTop - this._scrollPosition);
567
+ const delta = this._scrollTop - this._scrollPosition;
552
568
 
553
569
  super._scrollHandler();
554
570
 
@@ -601,11 +617,9 @@ export class IronListAdapter {
601
617
  );
602
618
  }
603
619
 
604
- this.__previousScrollTop = this._scrollTop;
605
-
606
620
  // If the first visible index is not 0 when scrolled to the top,
607
621
  // scroll to index 0 to fix the issue.
608
- if (this._scrollTop === 0 && this.firstVisibleIndex !== 0 && Math.abs(delta) > 0) {
622
+ if (this._scrollPosition === 0 && this.firstVisibleIndex !== 0 && Math.abs(delta) > 0) {
609
623
  this.scrollToIndex(0);
610
624
  }
611
625
  }