@vaadin/grid 24.7.0-alpha1 → 24.7.0-alpha10

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.
Files changed (93) hide show
  1. package/package.json +13 -12
  2. package/src/all-imports.js +1 -1
  3. package/src/lit/column-renderer-directives.d.ts +1 -1
  4. package/src/lit/column-renderer-directives.js +1 -1
  5. package/src/lit/renderer-directives.d.ts +1 -1
  6. package/src/lit/renderer-directives.js +1 -1
  7. package/src/lit-all-imports.js +1 -1
  8. package/src/vaadin-grid-a11y-mixin.d.ts +1 -1
  9. package/src/vaadin-grid-a11y-mixin.js +1 -1
  10. package/src/vaadin-grid-active-item-mixin.d.ts +1 -1
  11. package/src/vaadin-grid-active-item-mixin.js +1 -1
  12. package/src/vaadin-grid-array-data-provider-mixin.d.ts +1 -1
  13. package/src/vaadin-grid-array-data-provider-mixin.js +1 -1
  14. package/src/vaadin-grid-column-auto-width-mixin.d.ts +17 -0
  15. package/src/vaadin-grid-column-auto-width-mixin.js +307 -0
  16. package/src/vaadin-grid-column-group-mixin.d.ts +1 -1
  17. package/src/vaadin-grid-column-group-mixin.js +2 -1
  18. package/src/vaadin-grid-column-group.d.ts +1 -1
  19. package/src/vaadin-grid-column-group.js +1 -1
  20. package/src/vaadin-grid-column-mixin.d.ts +1 -1
  21. package/src/vaadin-grid-column-mixin.js +9 -6
  22. package/src/vaadin-grid-column-reordering-mixin.d.ts +1 -1
  23. package/src/vaadin-grid-column-reordering-mixin.js +1 -1
  24. package/src/vaadin-grid-column-resizing-mixin.js +1 -1
  25. package/src/vaadin-grid-column.d.ts +1 -1
  26. package/src/vaadin-grid-column.js +1 -1
  27. package/src/vaadin-grid-data-provider-mixin.d.ts +1 -1
  28. package/src/vaadin-grid-data-provider-mixin.js +2 -2
  29. package/src/vaadin-grid-drag-and-drop-mixin.d.ts +1 -1
  30. package/src/vaadin-grid-drag-and-drop-mixin.js +49 -32
  31. package/src/vaadin-grid-dynamic-columns-mixin.js +5 -11
  32. package/src/vaadin-grid-event-context-mixin.d.ts +1 -1
  33. package/src/vaadin-grid-event-context-mixin.js +1 -1
  34. package/src/vaadin-grid-filter-column-mixin.d.ts +1 -1
  35. package/src/vaadin-grid-filter-column-mixin.js +1 -1
  36. package/src/vaadin-grid-filter-column.d.ts +1 -1
  37. package/src/vaadin-grid-filter-column.js +1 -1
  38. package/src/vaadin-grid-filter-element-mixin.d.ts +1 -1
  39. package/src/vaadin-grid-filter-element-mixin.js +1 -1
  40. package/src/vaadin-grid-filter-mixin.js +1 -1
  41. package/src/vaadin-grid-filter.d.ts +1 -1
  42. package/src/vaadin-grid-filter.js +1 -1
  43. package/src/vaadin-grid-helpers.js +1 -1
  44. package/src/vaadin-grid-keyboard-navigation-mixin.js +1 -1
  45. package/src/vaadin-grid-mixin.d.ts +4 -6
  46. package/src/vaadin-grid-mixin.js +18 -238
  47. package/src/vaadin-grid-row-details-mixin.d.ts +1 -1
  48. package/src/vaadin-grid-row-details-mixin.js +1 -1
  49. package/src/vaadin-grid-scroll-mixin.d.ts +1 -1
  50. package/src/vaadin-grid-scroll-mixin.js +1 -1
  51. package/src/vaadin-grid-selection-column-base-mixin.d.ts +1 -1
  52. package/src/vaadin-grid-selection-column-base-mixin.js +1 -1
  53. package/src/vaadin-grid-selection-column-mixin.d.ts +1 -1
  54. package/src/vaadin-grid-selection-column-mixin.js +1 -1
  55. package/src/vaadin-grid-selection-column.d.ts +1 -1
  56. package/src/vaadin-grid-selection-column.js +1 -1
  57. package/src/vaadin-grid-selection-mixin.d.ts +1 -1
  58. package/src/vaadin-grid-selection-mixin.js +1 -1
  59. package/src/vaadin-grid-sort-column-mixin.d.ts +1 -1
  60. package/src/vaadin-grid-sort-column-mixin.js +1 -1
  61. package/src/vaadin-grid-sort-column.d.ts +1 -1
  62. package/src/vaadin-grid-sort-column.js +1 -1
  63. package/src/vaadin-grid-sort-mixin.d.ts +1 -1
  64. package/src/vaadin-grid-sort-mixin.js +1 -1
  65. package/src/vaadin-grid-sorter-mixin.d.ts +1 -1
  66. package/src/vaadin-grid-sorter-mixin.js +2 -1
  67. package/src/vaadin-grid-sorter.d.ts +1 -1
  68. package/src/vaadin-grid-sorter.js +1 -1
  69. package/src/vaadin-grid-styles.js +2 -1
  70. package/src/vaadin-grid-styling-mixin.d.ts +1 -1
  71. package/src/vaadin-grid-styling-mixin.js +1 -1
  72. package/src/vaadin-grid-tree-column-mixin.d.ts +1 -1
  73. package/src/vaadin-grid-tree-column-mixin.js +1 -5
  74. package/src/vaadin-grid-tree-column.d.ts +1 -1
  75. package/src/vaadin-grid-tree-column.js +1 -1
  76. package/src/vaadin-grid-tree-toggle-mixin.d.ts +1 -1
  77. package/src/vaadin-grid-tree-toggle-mixin.js +1 -1
  78. package/src/vaadin-grid-tree-toggle.d.ts +1 -1
  79. package/src/vaadin-grid-tree-toggle.js +1 -1
  80. package/src/vaadin-grid.d.ts +1 -1
  81. package/src/vaadin-grid.js +1 -1
  82. package/src/vaadin-lit-grid-column-group.js +1 -1
  83. package/src/vaadin-lit-grid-column.js +1 -1
  84. package/src/vaadin-lit-grid-filter-column.js +1 -1
  85. package/src/vaadin-lit-grid-filter.js +1 -1
  86. package/src/vaadin-lit-grid-selection-column.js +1 -1
  87. package/src/vaadin-lit-grid-sort-column.js +1 -1
  88. package/src/vaadin-lit-grid-sorter.js +1 -1
  89. package/src/vaadin-lit-grid-tree-column.js +1 -1
  90. package/src/vaadin-lit-grid-tree-toggle.js +1 -1
  91. package/src/vaadin-lit-grid.js +4 -4
  92. package/web-types.json +4 -4
  93. package/web-types.lit.json +4 -4
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { isChrome, isSafari } from '@vaadin/component-base/src/browser-utils.js';
6
7
  import {
7
8
  iterateChildren,
8
9
  iterateRowCells,
@@ -24,9 +25,6 @@ const DropLocation = {
24
25
  EMPTY: 'empty',
25
26
  };
26
27
 
27
- // Detects if the browser doesn't support HTML5 Drag & Drop API (and falls back to the @vaadin/vaadin-mobile-drag-drop polyfill)
28
- const usesDnDPolyfill = !('draggable' in document.createElement('div'));
29
-
30
28
  /**
31
29
  * @polymerMixin
32
30
  */
@@ -139,10 +137,6 @@ export const DragAndDropMixin = (superClass) =>
139
137
  /** @protected */
140
138
  connectedCallback() {
141
139
  super.connectedCallback();
142
- // Chromium based browsers cannot properly generate drag images for elements
143
- // that have children with massive heights. This workaround prevents crashes
144
- // and performance issues by excluding the items from the drag image.
145
- // https://github.com/vaadin/web-components/issues/7985
146
140
  document.addEventListener('dragstart', this.__onDocumentDragStart, { capture: true });
147
141
  }
148
142
 
@@ -181,13 +175,8 @@ export const DragAndDropMixin = (superClass) =>
181
175
 
182
176
  const rowRect = row.getBoundingClientRect();
183
177
 
184
- if (usesDnDPolyfill) {
185
- // The polyfill drag image is automatically centered so there is no need to adjust the position
186
- e.dataTransfer.setDragImage(row);
187
- } else {
188
- // The native drag image needs to be shifted manually to compensate for the touch position offset
189
- e.dataTransfer.setDragImage(row, e.clientX - rowRect.left, e.clientY - rowRect.top);
190
- }
178
+ // The native drag image needs to be shifted manually to compensate for the touch position offset
179
+ e.dataTransfer.setDragImage(row, e.clientX - rowRect.left, e.clientY - rowRect.top);
191
180
 
192
181
  let rows = [row];
193
182
  if (this._isSelected(row._item)) {
@@ -238,6 +227,9 @@ export const DragAndDropMixin = (superClass) =>
238
227
 
239
228
  /** @private */
240
229
  _onDragLeave(e) {
230
+ if (!this.dropMode) {
231
+ return;
232
+ }
241
233
  e.stopPropagation();
242
234
  this._clearDragStyles();
243
235
  }
@@ -312,25 +304,50 @@ export const DragAndDropMixin = (superClass) =>
312
304
  }
313
305
  }
314
306
 
315
- /** @private */
307
+ /**
308
+ * Webkit-based browsers have issues with generating drag images
309
+ * for elements that have children with massive heights. Chromium
310
+ * browsers crash, while Safari experiences significant performance
311
+ * issues. To mitigate these issues, we hide the scroller element
312
+ * when drag starts to remove it from the drag image.
313
+ *
314
+ * Grids with fewer rows also have issues on Chromium and Safari
315
+ * where the drag image is not properly clipped and may include
316
+ * content outside the grid. Temporary inline styles are applied
317
+ * to mitigate this issue.
318
+ *
319
+ * Related issues:
320
+ * - https://github.com/vaadin/web-components/issues/7985
321
+ * - https://issues.chromium.org/issues/383356871
322
+ * - https://github.com/vaadin/web-components/issues/8386
323
+ *
324
+ * @private
325
+ */
316
326
  __onDocumentDragStart(e) {
317
- // The dragged element can be the element itself or a parent of the element
318
- if (!e.target.contains(this)) {
319
- return;
320
- }
321
- // The threshold value 20000 provides a buffer to both
322
- // - avoid the crash and the performance issues
323
- // - unnecessarily avoid excluding items from the drag image
324
- if (this.$.items.offsetHeight > 20000) {
325
- const initialItemsMaxHeight = this.$.items.style.maxHeight;
326
- const initialTableOverflow = this.$.table.style.overflow;
327
- // Momentarily hides the items until the browser starts generating the
328
- // drag image.
329
- this.$.items.style.maxHeight = '0';
330
- this.$.table.style.overflow = 'hidden';
327
+ if (e.target.contains(this)) {
328
+ // Record the original inline styles to restore them later
329
+ const elements = [e.target, this.$.items, this.$.scroller];
330
+ const originalInlineStyles = elements.map((element) => element.style.cssText);
331
+
332
+ // With a large number of rows, hide the scroller
333
+ if (this.$.table.scrollHeight > 20000) {
334
+ this.$.scroller.style.display = 'none';
335
+ }
336
+
337
+ // Workaround content outside the grid ending up in the drag image on Chromium
338
+ if (isChrome) {
339
+ e.target.style.willChange = 'transform';
340
+ }
341
+
342
+ // Workaround text content outside the grid ending up in the drag image on Safari
343
+ if (isSafari) {
344
+ this.$.items.style.flexShrink = 1;
345
+ }
346
+
331
347
  requestAnimationFrame(() => {
332
- this.$.items.style.maxHeight = initialItemsMaxHeight;
333
- this.$.table.style.overflow = initialTableOverflow;
348
+ elements.forEach((element, index) => {
349
+ element.style.cssText = originalInlineStyles[index];
350
+ });
334
351
  });
335
352
  }
336
353
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { microTask, timeOut } from '@vaadin/component-base/src/async.js';
@@ -36,7 +36,10 @@ export const DynamicColumnsMixin = (superClass) =>
36
36
  /**
37
37
  * @protected
38
38
  */
39
- _columnTree: Object,
39
+ _columnTree: {
40
+ type: Object,
41
+ sync: true,
42
+ },
40
43
  };
41
44
  }
42
45
 
@@ -100,15 +103,6 @@ export const DynamicColumnsMixin = (superClass) =>
100
103
  const columnTree = this._getColumnTree();
101
104
 
102
105
  if (!arrayEquals(columnTree, this._columnTree)) {
103
- // Request a synchronoys update for each column
104
- columnTree.forEach((columnArray) => {
105
- columnArray.forEach((column) => {
106
- if (column.performUpdate) {
107
- column.performUpdate();
108
- }
109
- });
110
- });
111
-
112
106
  this._columnTree = columnTree;
113
107
  }
114
108
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { GridDefaultItem } from './vaadin-grid.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import './vaadin-grid-filter.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { timeOut } from '@vaadin/component-base/src/async.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@vaadin/text-field/src/vaadin-text-field.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { microTask } from '@vaadin/component-base/src/async.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -9,6 +9,7 @@ import type { A11yMixinClass } from './vaadin-grid-a11y-mixin.js';
9
9
  import type { ActiveItemMixinClass } from './vaadin-grid-active-item-mixin.js';
10
10
  import type { ArrayDataProviderMixinClass } from './vaadin-grid-array-data-provider-mixin.js';
11
11
  import type { GridBodyRenderer, GridColumn, GridHeaderFooterRenderer } from './vaadin-grid-column.js';
12
+ import type { ColumnAutoWidthMixinClass } from './vaadin-grid-column-auto-width-mixin.js';
12
13
  import type { ColumnReorderingMixinClass } from './vaadin-grid-column-reordering-mixin.js';
13
14
  import type {
14
15
  DataProviderMixinClass,
@@ -172,6 +173,7 @@ export declare function GridMixin<TItem, T extends Constructor<HTMLElement>>(
172
173
  base: T,
173
174
  ): Constructor<A11yMixinClass> &
174
175
  Constructor<ActiveItemMixinClass<TItem>> &
176
+ Constructor<ColumnAutoWidthMixinClass> &
175
177
  Constructor<ArrayDataProviderMixinClass<TItem>> &
176
178
  Constructor<ColumnReorderingMixinClass> &
177
179
  Constructor<DataProviderMixinClass<TItem>> &
@@ -191,6 +193,7 @@ export interface GridMixinClass<TItem>
191
193
  A11yMixinClass,
192
194
  ActiveItemMixinClass<TItem>,
193
195
  ArrayDataProviderMixinClass<TItem>,
196
+ ColumnAutoWidthMixinClass,
194
197
  DataProviderMixinClass<TItem>,
195
198
  RowDetailsMixinClass<TItem>,
196
199
  ScrollMixinClass,
@@ -209,11 +212,6 @@ export interface GridMixinClass<TItem>
209
212
  */
210
213
  allRowsVisible: boolean;
211
214
 
212
- /**
213
- * Updates the `width` of all columns which have `autoWidth` set to `true`.
214
- */
215
- recalculateColumnWidths(): void;
216
-
217
215
  /**
218
216
  * Requests an update for the content of cells.
219
217
  *
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { isElementHidden } from '@vaadin/a11y-base/src/focus-utils.js';
7
6
  import { TabindexMixin } from '@vaadin/a11y-base/src/tabindex-mixin.js';
8
7
  import { animationFrame, microTask } from '@vaadin/component-base/src/async.js';
9
8
  import {
@@ -24,6 +23,7 @@ import { Virtualizer } from '@vaadin/component-base/src/virtualizer.js';
24
23
  import { A11yMixin } from './vaadin-grid-a11y-mixin.js';
25
24
  import { ActiveItemMixin } from './vaadin-grid-active-item-mixin.js';
26
25
  import { ArrayDataProviderMixin } from './vaadin-grid-array-data-provider-mixin.js';
26
+ import { ColumnAutoWidthMixin } from './vaadin-grid-column-auto-width-mixin.js';
27
27
  import { ColumnReorderingMixin } from './vaadin-grid-column-reordering-mixin.js';
28
28
  import { ColumnResizingMixin } from './vaadin-grid-column-resizing-mixin.js';
29
29
  import { DataProviderMixin } from './vaadin-grid-data-provider-mixin.js';
@@ -67,20 +67,22 @@ import { StylingMixin } from './vaadin-grid-styling-mixin.js';
67
67
  * @mixes DragAndDropMixin
68
68
  */
69
69
  export const GridMixin = (superClass) =>
70
- class extends ArrayDataProviderMixin(
71
- DataProviderMixin(
72
- DynamicColumnsMixin(
73
- ActiveItemMixin(
74
- ScrollMixin(
75
- SelectionMixin(
76
- SortMixin(
77
- RowDetailsMixin(
78
- KeyboardNavigationMixin(
79
- A11yMixin(
80
- FilterMixin(
81
- ColumnReorderingMixin(
82
- ColumnResizingMixin(
83
- EventContextMixin(DragAndDropMixin(StylingMixin(TabindexMixin(superClass)))),
70
+ class extends ColumnAutoWidthMixin(
71
+ ArrayDataProviderMixin(
72
+ DataProviderMixin(
73
+ DynamicColumnsMixin(
74
+ ActiveItemMixin(
75
+ ScrollMixin(
76
+ SelectionMixin(
77
+ SortMixin(
78
+ RowDetailsMixin(
79
+ KeyboardNavigationMixin(
80
+ A11yMixin(
81
+ FilterMixin(
82
+ ColumnReorderingMixin(
83
+ ColumnResizingMixin(
84
+ EventContextMixin(DragAndDropMixin(StylingMixin(TabindexMixin(superClass)))),
85
+ ),
84
86
  ),
85
87
  ),
86
88
  ),
@@ -144,12 +146,6 @@ export const GridMixin = (superClass) =>
144
146
  reflectToAttribute: true,
145
147
  },
146
148
 
147
- /** @private */
148
- __pendingRecalculateColumnWidths: {
149
- type: Boolean,
150
- value: true,
151
- },
152
-
153
149
  /** @private */
154
150
  isAttached: {
155
151
  value: false,
@@ -201,7 +197,6 @@ export const GridMixin = (superClass) =>
201
197
  connectedCallback() {
202
198
  super.connectedCallback();
203
199
  this.isAttached = true;
204
- this.recalculateColumnWidths();
205
200
  }
206
201
 
207
202
  /** @protected */
@@ -273,7 +268,6 @@ export const GridMixin = (superClass) =>
273
268
  new ResizeObserver(() =>
274
269
  setTimeout(() => {
275
270
  this.__updateColumnsBodyContentHidden();
276
- this.__tryToRecalculateColumnWidthsIfPending();
277
271
  }),
278
272
  ).observe(this.$.table);
279
273
 
@@ -352,217 +346,6 @@ export const GridMixin = (superClass) =>
352
346
  }
353
347
  }
354
348
 
355
- /** @private */
356
- __getIntrinsicWidth(col) {
357
- if (!this.__intrinsicWidthCache.has(col)) {
358
- this.__calculateAndCacheIntrinsicWidths([col]);
359
- }
360
- return this.__intrinsicWidthCache.get(col);
361
- }
362
-
363
- /** @private */
364
- __getDistributedWidth(col, innerColumn) {
365
- if (col == null || col === this) {
366
- return 0;
367
- }
368
-
369
- const columnWidth = Math.max(
370
- this.__getIntrinsicWidth(col),
371
- this.__getDistributedWidth((col.assignedSlot || col).parentElement, col),
372
- );
373
-
374
- // We're processing a regular grid-column and not a grid-column-group
375
- if (!innerColumn) {
376
- return columnWidth;
377
- }
378
-
379
- // At the end, the width of each vaadin-grid-column-group is determined by the sum of the width of its children.
380
- // Here we determine how much space the vaadin-grid-column-group actually needs to render properly and then we distribute that space
381
- // to its children, so when we actually do the summation it will be rendered properly.
382
- // Check out vaadin-grid-column-group:_updateFlexAndWidth
383
- const columnGroup = col;
384
- const columnGroupWidth = columnWidth;
385
- const sumOfWidthOfAllChildColumns = columnGroup._visibleChildColumns
386
- .map((col) => this.__getIntrinsicWidth(col))
387
- .reduce((sum, curr) => sum + curr, 0);
388
-
389
- const extraNecessarySpaceForGridColumnGroup = Math.max(0, columnGroupWidth - sumOfWidthOfAllChildColumns);
390
-
391
- // The distribution of the extra necessary space is done according to the intrinsic width of each child column.
392
- // Lets say we need 100 pixels of extra space for the grid-column-group to render properly
393
- // it has two grid-column children, |100px|300px| in total 400px
394
- // the first column gets 25px of the additional space (100/400)*100 = 25
395
- // the second column gets the 75px of the additional space (300/400)*100 = 75
396
- const proportionOfExtraSpace = this.__getIntrinsicWidth(innerColumn) / sumOfWidthOfAllChildColumns;
397
- const shareOfInnerColumnFromNecessaryExtraSpace = proportionOfExtraSpace * extraNecessarySpaceForGridColumnGroup;
398
-
399
- return this.__getIntrinsicWidth(innerColumn) + shareOfInnerColumnFromNecessaryExtraSpace;
400
- }
401
-
402
- /**
403
- * @param {!Array<!GridColumn>} cols the columns to auto size based on their content width
404
- * @private
405
- */
406
- _recalculateColumnWidths(cols) {
407
- // Flush to make sure DOM is up-to-date when measuring the column widths
408
- this.__virtualizer.flush();
409
- [...this.$.header.children, ...this.$.footer.children].forEach((row) => {
410
- if (row.__debounceUpdateHeaderFooterRowVisibility) {
411
- row.__debounceUpdateHeaderFooterRowVisibility.flush();
412
- }
413
- });
414
-
415
- // Flush to account for any changes to the visibility of the columns
416
- if (this._debouncerHiddenChanged) {
417
- this._debouncerHiddenChanged.flush();
418
- }
419
-
420
- this.__intrinsicWidthCache = new Map();
421
- // Cache the viewport rows to avoid unnecessary reflows while measuring the column widths
422
- const fvi = this._firstVisibleIndex;
423
- const lvi = this._lastVisibleIndex;
424
- this.__viewportRowsCache = this._getRenderedRows().filter((row) => row.index >= fvi && row.index <= lvi);
425
-
426
- // Pre-cache the intrinsic width of each column
427
- this.__calculateAndCacheIntrinsicWidths(cols);
428
-
429
- cols.forEach((col) => {
430
- col.width = `${this.__getDistributedWidth(col)}px`;
431
- });
432
- }
433
-
434
- /**
435
- * Toggles the cell content for the given column to use or not use auto width.
436
- *
437
- * While content for all the column cells uses auto width (instead of the default 100%),
438
- * their offsetWidth can be used to calculate the collective intrinsic width of the column.
439
- *
440
- * @private
441
- */
442
- __setVisibleCellContentAutoWidth(col, autoWidth) {
443
- col._allCells
444
- .filter((cell) => {
445
- if (this.$.items.contains(cell)) {
446
- return this.__viewportRowsCache.includes(cell.parentElement);
447
- }
448
- return true;
449
- })
450
- .forEach((cell) => {
451
- cell.__measuringAutoWidth = autoWidth;
452
-
453
- if (cell.__measuringAutoWidth) {
454
- // Store the original inline width of the cell to restore it later
455
- cell.__originalWidth = cell.style.width;
456
- // Prepare the cell for having its intrinsic width measured
457
- cell.style.width = 'auto';
458
- cell.style.position = 'absolute';
459
- } else {
460
- // Restore the original width
461
- cell.style.width = cell.__originalWidth;
462
- delete cell.__originalWidth;
463
- cell.style.position = '';
464
- }
465
- });
466
-
467
- if (autoWidth) {
468
- this.$.scroller.setAttribute('measuring-auto-width', '');
469
- } else {
470
- this.$.scroller.removeAttribute('measuring-auto-width');
471
- }
472
- }
473
-
474
- /**
475
- * Returns the maximum intrinsic width of the cell content in the given column.
476
- * Only cells which are marked for measuring auto width are considered.
477
- *
478
- * @private
479
- */
480
- __getAutoWidthCellsMaxWidth(col) {
481
- // Note: _allCells only contains cells which are currently rendered in DOM
482
- return col._allCells.reduce((width, cell) => {
483
- // Add 1px buffer to the offset width to avoid too narrow columns (sub-pixel rendering)
484
- return cell.__measuringAutoWidth ? Math.max(width, cell.offsetWidth + 1) : width;
485
- }, 0);
486
- }
487
-
488
- /**
489
- * Calculates and caches the intrinsic width of each given column.
490
- *
491
- * @private
492
- */
493
- __calculateAndCacheIntrinsicWidths(cols) {
494
- // Make all the columns use auto width at once before measuring to
495
- // avoid reflows in between the measurements
496
- cols.forEach((col) => this.__setVisibleCellContentAutoWidth(col, true));
497
- // Measure and cache
498
- cols.forEach((col) => {
499
- const width = this.__getAutoWidthCellsMaxWidth(col);
500
- this.__intrinsicWidthCache.set(col, width);
501
- });
502
- // Reset the columns to use 100% width
503
- cols.forEach((col) => this.__setVisibleCellContentAutoWidth(col, false));
504
- }
505
-
506
- /**
507
- * Updates the `width` of all columns which have `autoWidth` set to `true`.
508
- */
509
- recalculateColumnWidths() {
510
- if (!this._columnTree) {
511
- return; // No columns
512
- }
513
- if (isElementHidden(this) || this._dataProviderController.isLoading()) {
514
- this.__pendingRecalculateColumnWidths = true;
515
- return;
516
- }
517
- const cols = this._getColumns().filter((col) => !col.hidden && col.autoWidth);
518
-
519
- const undefinedCols = cols.filter((col) => !customElements.get(col.localName));
520
- if (undefinedCols.length) {
521
- // Some of the columns are not defined yet, wait for them to be defined before measuring
522
- Promise.all(undefinedCols.map((col) => customElements.whenDefined(col.localName))).then(() => {
523
- this._recalculateColumnWidths(cols);
524
- });
525
- } else {
526
- this._recalculateColumnWidths(cols);
527
- }
528
- }
529
-
530
- /** @private */
531
- __tryToRecalculateColumnWidthsIfPending() {
532
- if (!this.__pendingRecalculateColumnWidths || isElementHidden(this) || this._dataProviderController.isLoading()) {
533
- return;
534
- }
535
-
536
- // Delay recalculation if any rows are missing an index.
537
- // This can happen during the grid's initialization if the recalculation is triggered
538
- // as a result of the data provider responding synchronously to a page request created
539
- // in the middle of the virtualizer update loop. In this case, rows after the one that
540
- // triggered the page request may not have an index property yet. The lack of index
541
- // prevents _onDataProviderPageReceived from requesting children for these rows,
542
- // resulting in loading state being set to false and the recalculation beginning
543
- // before all the data is loaded. Note, rows without index get updated in later iterations
544
- // of the virtualizer update loop, ensuring the grid eventually reaches a stable state.
545
- const hasRowsWithUndefinedIndex = [...this.$.items.children].some((row) => row.index === undefined);
546
- if (hasRowsWithUndefinedIndex) {
547
- return;
548
- }
549
-
550
- const hasRowsWithClientHeight = [...this.$.items.children].some((row) => row.clientHeight > 0);
551
- if (hasRowsWithClientHeight) {
552
- this.__pendingRecalculateColumnWidths = false;
553
- this.recalculateColumnWidths();
554
- }
555
- }
556
-
557
- /**
558
- * @protected
559
- * @override
560
- */
561
- _onDataProviderPageLoaded() {
562
- super._onDataProviderPageLoaded();
563
- this.__tryToRecalculateColumnWidthsIfPending();
564
- }
565
-
566
349
  /** @private */
567
350
  _createScrollerRows(count) {
568
351
  const rows = [];
@@ -590,7 +373,6 @@ export const GridMixin = (superClass) =>
590
373
  animationFrame,
591
374
  () => {
592
375
  this._afterScroll();
593
- this.__tryToRecalculateColumnWidthsIfPending();
594
376
  },
595
377
  );
596
378
  return rows;
@@ -876,7 +658,6 @@ export const GridMixin = (superClass) =>
876
658
  /** @private */
877
659
  _columnTreeChanged(columnTree) {
878
660
  this._renderColumnTree(columnTree);
879
- this.recalculateColumnWidths();
880
661
  this.__updateColumnsBodyContentHidden();
881
662
  }
882
663
 
@@ -1015,7 +796,6 @@ export const GridMixin = (superClass) =>
1015
796
  // ShadyCSS applies scoping suffixes to animation names
1016
797
  if (e.animationName.indexOf('vaadin-grid-appear') === 0) {
1017
798
  e.stopPropagation();
1018
- this.__tryToRecalculateColumnWidthsIfPending();
1019
799
 
1020
800
  // Ensure header and footer have tabbable elements
1021
801
  this._resetKeyboardNavigation();
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { iterateChildren } from './vaadin-grid-helpers.js';