@vaadin/component-base 23.1.0-alpha3 → 23.1.0-beta2

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.
@@ -8,7 +8,14 @@ import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
8
8
  const observer = new ResizeObserver((entries) => {
9
9
  setTimeout(() => {
10
10
  entries.forEach((entry) => {
11
- entry.target._onResize(entry.contentRect);
11
+ // Notify child resizables, if any
12
+ if (entry.target.resizables) {
13
+ entry.target.resizables.forEach((resizable) => {
14
+ resizable._onResize(entry.contentRect);
15
+ });
16
+ } else {
17
+ entry.target._onResize(entry.contentRect);
18
+ }
12
19
  });
13
20
  });
14
21
  });
@@ -25,12 +32,49 @@ export const ResizeMixin = dedupingMixin(
25
32
  connectedCallback() {
26
33
  super.connectedCallback();
27
34
  observer.observe(this);
35
+
36
+ if (this._observeParent) {
37
+ const parent = this.parentNode instanceof ShadowRoot ? this.parentNode.host : this.parentNode;
38
+
39
+ if (!parent.resizables) {
40
+ parent.resizables = new Set();
41
+ observer.observe(parent);
42
+ }
43
+
44
+ parent.resizables.add(this);
45
+ this.__parent = parent;
46
+ }
28
47
  }
29
48
 
30
49
  /** @protected */
31
50
  disconnectedCallback() {
32
51
  super.disconnectedCallback();
33
52
  observer.unobserve(this);
53
+
54
+ const parent = this.__parent;
55
+ if (this._observeParent && parent) {
56
+ const resizables = parent.resizables;
57
+
58
+ if (resizables) {
59
+ resizables.delete(this);
60
+
61
+ if (resizables.size === 0) {
62
+ observer.unobserve(parent);
63
+ }
64
+ }
65
+
66
+ this.__parent = null;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * When true, the parent element resize will be also observed.
72
+ * Override this getter and return `true` to enable this.
73
+ *
74
+ * @protected
75
+ */
76
+ get _observeParent() {
77
+ return false;
34
78
  }
35
79
 
36
80
  /**
@@ -49,8 +93,8 @@ export const ResizeMixin = dedupingMixin(
49
93
  */
50
94
  notifyResize() {
51
95
  console.warn(
52
- `WARNING: Since Vaadin 23, notifyResize() is deprecated. The component uses a ResizeObserver internally and doesn't need to be explicitly notified of resizes.`
96
+ `WARNING: Since Vaadin 23, notifyResize() is deprecated. The component uses a ResizeObserver internally and doesn't need to be explicitly notified of resizes.`,
53
97
  );
54
98
  }
55
- }
99
+ },
56
100
  );
@@ -10,7 +10,7 @@ export class SlotController extends EventTarget implements ReactiveController {
10
10
  host: HTMLElement,
11
11
  slotName: string,
12
12
  slotFactory?: () => HTMLElement,
13
- slotInitializer?: (host: HTMLElement, node: HTMLElement) => void
13
+ slotInitializer?: (host: HTMLElement, node: HTMLElement) => void,
14
14
  );
15
15
 
16
16
  hostConnected(): void;
package/src/slot-mixin.js CHANGED
@@ -56,5 +56,5 @@ export const SlotMixin = dedupingMixin(
56
56
  );
57
57
  });
58
58
  }
59
- }
59
+ },
60
60
  );
@@ -13,7 +13,7 @@ import { DisabledMixinClass } from './disabled-mixin.js';
13
13
  * and restored with the last known value once the element is enabled.
14
14
  */
15
15
  export declare function TabindexMixin<T extends Constructor<HTMLElement>>(
16
- base: T
16
+ base: T,
17
17
  ): T & Constructor<DisabledMixinClass> & Constructor<TabindexMixinClass>;
18
18
 
19
19
  export declare class TabindexMixinClass {
@@ -26,7 +26,7 @@ export const TabindexMixin = (superclass) =>
26
26
  tabindex: {
27
27
  type: Number,
28
28
  reflectToAttribute: true,
29
- observer: '_tabindexChanged'
29
+ observer: '_tabindexChanged',
30
30
  },
31
31
 
32
32
  /**
@@ -35,8 +35,8 @@ export const TabindexMixin = (superclass) =>
35
35
  * @protected
36
36
  */
37
37
  _lastTabIndex: {
38
- type: Number
39
- }
38
+ type: Number,
39
+ },
40
40
  };
41
41
  }
42
42
 
package/src/templates.js CHANGED
@@ -18,7 +18,7 @@ export function processTemplates(component) {
18
18
 
19
19
  if (component.querySelector('template')) {
20
20
  console.warn(
21
- `WARNING: <template> inside <${component.localName}> is no longer supported. Import @vaadin/polymer-legacy-adapter/template-renderer.js to enable compatibility.`
21
+ `WARNING: <template> inside <${component.localName}> is no longer supported. Import @vaadin/polymer-legacy-adapter/template-renderer.js to enable compatibility.`,
22
22
  );
23
23
  }
24
24
  }
@@ -8,7 +8,7 @@ import { isSafari } from './browser-utils.js';
8
8
  import { Debouncer, flush } from './debounce.js';
9
9
  import { ironList } from './iron-list-core.js';
10
10
 
11
- // iron-list can by default handle sizes up to around 100000.
11
+ // Iron-list can by default handle sizes up to around 100000.
12
12
  // When the size is larger than MAX_VIRTUAL_COUNT _vidxOffset is used
13
13
  const MAX_VIRTUAL_COUNT = 100000;
14
14
  const OFFSET_ADJUST_MIN_THRESHOLD = 1000;
@@ -28,7 +28,7 @@ export class IronListAdapter {
28
28
 
29
29
  this.timeouts = {
30
30
  SCROLL_REORDER: 500,
31
- IGNORE_WHEEL: 500
31
+ IGNORE_WHEEL: 500,
32
32
  };
33
33
 
34
34
  this.__resizeObserver = new ResizeObserver(() => this._resizeHandler());
@@ -118,8 +118,12 @@ export class IronListAdapter {
118
118
  this._resizeHandler();
119
119
  flush();
120
120
  this._scrollHandler();
121
- this.__scrollReorderDebouncer && this.__scrollReorderDebouncer.flush();
122
- this.__debouncerWheelAnimationFrame && this.__debouncerWheelAnimationFrame.flush();
121
+ if (this.__scrollReorderDebouncer) {
122
+ this.__scrollReorderDebouncer.flush();
123
+ }
124
+ if (this.__debouncerWheelAnimationFrame) {
125
+ this.__debouncerWheelAnimationFrame.flush();
126
+ }
123
127
  }
124
128
 
125
129
  update(startIndex = 0, endIndex = this.size - 1) {
@@ -168,8 +172,8 @@ export class IronListAdapter {
168
172
  this.__preventElementUpdates = true;
169
173
 
170
174
  // Record the scroll position before changing the size
171
- let fvi; // first visible index
172
- let fviOffsetBefore; // scroll offset of the first visible index
175
+ let fvi; // First visible index
176
+ let fviOffsetBefore; // Scroll offset of the first visible index
173
177
  if (size > 0) {
174
178
  fvi = this.adjustedFirstVisibleIndex;
175
179
  fviOffsetBefore = this.__getIndexScrollOffset(fvi);
@@ -183,7 +187,7 @@ export class IronListAdapter {
183
187
  flush();
184
188
 
185
189
  this._itemsChanged({
186
- path: 'items'
190
+ path: 'items',
187
191
  });
188
192
  flush();
189
193
 
@@ -221,7 +225,7 @@ export class IronListAdapter {
221
225
  /** @private */
222
226
  get items() {
223
227
  return {
224
- length: Math.min(this.size, MAX_VIRTUAL_COUNT)
228
+ length: Math.min(this.size, MAX_VIRTUAL_COUNT),
225
229
  };
226
230
  }
227
231
 
@@ -233,7 +237,7 @@ export class IronListAdapter {
233
237
  /** @private */
234
238
  get $() {
235
239
  return {
236
- items: this.scrollContainer
240
+ items: this.scrollContainer,
237
241
  };
238
242
  }
239
243
 
@@ -245,7 +249,9 @@ export class IronListAdapter {
245
249
  this._viewportWidth = this.elementsContainer.offsetWidth;
246
250
  this._viewportHeight = this.scrollTarget.offsetHeight;
247
251
  this._scrollPageHeight = this._viewportHeight - this._scrollLineHeight;
248
- this.grid && this._updateGridMetrics();
252
+ if (this.grid) {
253
+ this._updateGridMetrics();
254
+ }
249
255
  }
250
256
 
251
257
  /** @private */
@@ -298,11 +304,20 @@ export class IronListAdapter {
298
304
 
299
305
  super._scrollHandler();
300
306
 
307
+ if (this._physicalCount !== 0) {
308
+ // After running super._scrollHandler, fix _virtualStart to workaround an iron-list issue.
309
+ // See https://github.com/vaadin/web-components/issues/1691
310
+ const reusables = this._getReusables(true);
311
+ this._physicalTop = reusables.physicalTop;
312
+ this._virtualStart += reusables.indexes.length;
313
+ this._physicalStart += reusables.indexes.length;
314
+ }
315
+
301
316
  if (this.reorderElements) {
302
317
  this.__scrollReorderDebouncer = Debouncer.debounce(
303
318
  this.__scrollReorderDebouncer,
304
319
  timeOut.after(this.timeouts.SCROLL_REORDER),
305
- () => this.__reorderElements()
320
+ () => this.__reorderElements(),
306
321
  );
307
322
  }
308
323
 
@@ -340,7 +355,7 @@ export class IronListAdapter {
340
355
  this.__debouncerWheelAnimationFrame = Debouncer.debounce(
341
356
  this.__debouncerWheelAnimationFrame,
342
357
  animationFrame,
343
- () => (this._wheelAnimationFrame = false)
358
+ () => (this._wheelAnimationFrame = false),
344
359
  );
345
360
 
346
361
  const momentum = Math.abs(e.deltaX) + Math.abs(deltaY);
@@ -356,7 +371,7 @@ export class IronListAdapter {
356
371
  this._debouncerIgnoreNewWheel = Debouncer.debounce(
357
372
  this._debouncerIgnoreNewWheel,
358
373
  timeOut.after(this.timeouts.IGNORE_WHEEL),
359
- () => (this._ignoreNewWheel = false)
374
+ () => (this._ignoreNewWheel = false),
360
375
  );
361
376
  } else if ((this._hasResidualMomentum && momentum <= this._previousMomentum) || this._ignoreNewWheel) {
362
377
  e.preventDefault();
@@ -427,7 +442,7 @@ export class IronListAdapter {
427
442
  const elementWithFocus = visibleElements.find(
428
443
  (element) =>
429
444
  element.contains(this.elementsContainer.getRootNode().activeElement) ||
430
- element.contains(this.scrollTarget.getRootNode().activeElement)
445
+ element.contains(this.scrollTarget.getRootNode().activeElement),
431
446
  );
432
447
  const targetElement = elementWithFocus || visibleElements[0];
433
448
  if (!targetElement) {