@vaadin/grid 25.0.0-alpha7 → 25.0.0-alpha9

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.
@@ -6,15 +6,13 @@
6
6
  import { css } from 'lit';
7
7
 
8
8
  export const gridFilterStyles = css`
9
- @layer base {
10
- :host {
11
- display: inline-flex;
12
- max-width: 100%;
13
- }
9
+ :host {
10
+ display: inline-flex;
11
+ max-width: 100%;
12
+ }
14
13
 
15
- ::slotted(*) {
16
- width: 100%;
17
- box-sizing: border-box;
18
- }
14
+ ::slotted(*) {
15
+ width: 100%;
16
+ box-sizing: border-box;
19
17
  }
20
18
  `;
@@ -7,59 +7,57 @@ import '@vaadin/component-base/src/style-props.js';
7
7
  import { css } from 'lit';
8
8
 
9
9
  export const gridSorterStyles = css`
10
- @layer base {
11
- :host {
12
- display: inline-flex;
13
- align-items: center;
14
- cursor: pointer;
15
- max-width: 100%;
16
- gap: var(--vaadin-gap-container-inline);
17
- -webkit-user-select: none;
18
- user-select: none;
19
- -webkit-tap-highlight-color: transparent;
20
- }
10
+ :host {
11
+ display: inline-flex;
12
+ align-items: center;
13
+ cursor: pointer;
14
+ max-width: 100%;
15
+ gap: var(--vaadin-gap-container-inline);
16
+ -webkit-user-select: none;
17
+ user-select: none;
18
+ -webkit-tap-highlight-color: transparent;
19
+ }
21
20
 
22
- [part='content'] {
23
- flex: 1 1 auto;
24
- overflow: hidden;
25
- text-overflow: ellipsis;
26
- }
21
+ [part='content'] {
22
+ flex: 1 1 auto;
23
+ overflow: hidden;
24
+ text-overflow: ellipsis;
25
+ }
27
26
 
28
- [part='indicators'] {
29
- position: relative;
30
- flex: none;
31
- }
27
+ [part='indicators'] {
28
+ position: relative;
29
+ flex: none;
30
+ }
32
31
 
33
- [part='order'] {
34
- display: inline;
35
- vertical-align: super;
36
- font-size: 0.75em;
37
- line-height: 1;
38
- }
32
+ [part='order'] {
33
+ display: inline;
34
+ vertical-align: super;
35
+ font-size: 0.75em;
36
+ line-height: 1;
37
+ }
39
38
 
40
- [part='indicators']::before {
41
- content: '';
42
- display: inline-block;
43
- height: 12px;
44
- width: 8px;
45
- mask-image: var(--_vaadin-icon-sort);
46
- background: currentColor;
47
- }
39
+ [part='indicators']::before {
40
+ content: '';
41
+ display: inline-block;
42
+ height: 12px;
43
+ width: 8px;
44
+ mask-image: var(--_vaadin-icon-sort);
45
+ background: currentColor;
46
+ }
48
47
 
49
- :host([direction]) [part='indicators']::before {
50
- padding-bottom: 6px;
51
- height: 6px;
52
- mask-clip: content-box;
53
- }
48
+ :host([direction]) [part='indicators']::before {
49
+ padding-bottom: 6px;
50
+ height: 6px;
51
+ mask-clip: content-box;
52
+ }
54
53
 
55
- :host([direction='desc']) [part='indicators']::before {
56
- padding-block: 6px 0;
57
- }
54
+ :host([direction='desc']) [part='indicators']::before {
55
+ padding-block: 6px 0;
56
+ }
58
57
 
59
- @media (forced-colors: active) {
60
- [part='indicators']::before {
61
- background: CanvasText;
62
- }
58
+ @media (forced-colors: active) {
59
+ [part='indicators']::before {
60
+ background: CanvasText;
63
61
  }
64
62
  }
65
63
  `;
@@ -7,72 +7,70 @@ import '@vaadin/component-base/src/style-props.js';
7
7
  import { css } from 'lit';
8
8
 
9
9
  export const gridTreeToggleStyles = css`
10
- @layer base {
11
- :host {
12
- display: flex;
13
- max-width: 100%;
14
- pointer-events: none;
15
- }
10
+ :host {
11
+ display: flex;
12
+ max-width: 100%;
13
+ pointer-events: none;
14
+ }
16
15
 
17
- /* Don't expand/collapse when clicking #level-spacer */
18
- [part] {
19
- pointer-events: auto;
20
- }
16
+ /* Don't expand/collapse when clicking #level-spacer */
17
+ [part] {
18
+ pointer-events: auto;
19
+ }
21
20
 
22
- :host([hidden]) {
23
- display: none !important;
24
- }
21
+ :host([hidden]) {
22
+ display: none !important;
23
+ }
25
24
 
26
- :host(:not([leaf])) {
27
- cursor: var(--vaadin-clickable-cursor);
28
- }
25
+ :host(:not([leaf])) {
26
+ cursor: var(--vaadin-clickable-cursor);
27
+ }
29
28
 
30
- #level-spacer,
31
- [part='toggle'] {
32
- flex: none;
33
- }
29
+ #level-spacer,
30
+ [part='toggle'] {
31
+ flex: none;
32
+ }
34
33
 
35
- #level-spacer {
36
- width: calc(var(--_level, 0) * var(--vaadin-grid-tree-toggle-level-offset, 1em));
37
- }
34
+ #level-spacer {
35
+ width: calc(var(--_level, 0) * var(--vaadin-grid-tree-toggle-level-offset, 16px));
36
+ }
38
37
 
39
- [part='toggle'] {
40
- margin-inline-end: var(--vaadin-gap-container-inline);
41
- }
38
+ [part='toggle'] {
39
+ margin-inline-end: var(--vaadin-gap-container-inline);
40
+ }
42
41
 
43
- [part='toggle']::before {
44
- content: '';
45
- display: block;
46
- width: var(--vaadin-icon-size, 1lh);
47
- height: var(--vaadin-icon-size, 1lh);
48
- background: currentColor;
49
- mask-image: var(--_vaadin-icon-chevron-down);
50
- }
42
+ [part='toggle']::before {
43
+ content: '';
44
+ display: block;
45
+ width: var(--vaadin-icon-size, 1lh);
46
+ height: var(--vaadin-icon-size, 1lh);
47
+ background: currentColor;
48
+ mask-image: var(--_vaadin-icon-chevron-down);
49
+ }
51
50
 
52
- :host(:not([expanded])) [part='toggle']::before {
53
- rotate: -90deg;
54
- }
51
+ :host(:not([expanded])) [part='toggle']::before {
52
+ rotate: -90deg;
53
+ }
55
54
 
56
- @media (prefers-reduced-motion: no-preference) {
57
- [part='toggle']::before {
58
- transition: rotate 120ms;
59
- }
55
+ @media (prefers-reduced-motion: no-preference) {
56
+ [part='toggle']::before {
57
+ transition: rotate 120ms;
60
58
  }
59
+ }
61
60
 
62
- :host([leaf]) [part='toggle'] {
63
- visibility: hidden;
64
- }
61
+ :host([leaf]) [part='toggle'] {
62
+ visibility: hidden;
63
+ }
65
64
 
66
- slot {
67
- display: block;
68
- overflow: hidden;
69
- text-overflow: ellipsis;
70
- }
65
+ slot {
66
+ display: block;
67
+ overflow: hidden;
68
+ text-overflow: ellipsis;
69
+ }
71
70
 
72
- @media (forced-colors: active) {
73
- [part='toggle']::before {
74
- background: CanvasText;
75
- }
71
+ @media (forced-colors: active) {
72
+ [part='toggle']::before {
73
+ background: CanvasText;
76
74
  }
77
75
  }
78
76
  `;
@@ -59,9 +59,15 @@ export const ColumnAutoWidthMixin = (superClass) =>
59
59
  }
60
60
 
61
61
  /** @private */
62
- __flatSizeChangedAutoWidth() {
62
+ __flatSizeChangedAutoWidth(flatSize) {
63
63
  // Flat size changed, recalculate column widths if pending (asynchronously, to allow grid to render row elements first)
64
- requestAnimationFrame(() => this.__tryToRecalculateColumnWidthsIfPending());
64
+ requestAnimationFrame(() => {
65
+ if (!!flatSize && !this.__hasHadRenderedRowsForColumnWidthCalculation) {
66
+ this.recalculateColumnWidths();
67
+ } else {
68
+ this.__tryToRecalculateColumnWidthsIfPending();
69
+ }
70
+ });
65
71
  }
66
72
 
67
73
  /**
@@ -7,7 +7,6 @@ import { microTask, timeOut } from '@vaadin/component-base/src/async.js';
7
7
  import { DataProviderController } from '@vaadin/component-base/src/data-provider-controller/data-provider-controller.js';
8
8
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
9
9
  import { get } from '@vaadin/component-base/src/path-utils.js';
10
- import { getBodyRowCells, updateCellsPart, updateState } from './vaadin-grid-helpers.js';
11
10
 
12
11
  /**
13
12
  * @polymerMixin
@@ -182,46 +181,20 @@ export const DataProviderMixin = (superClass) =>
182
181
  this.requestContentUpdate();
183
182
  }
184
183
 
185
- /**
186
- * @param {number} index
187
- * @param {HTMLElement} el
188
- * @protected
189
- */
190
- _getItem(index, el) {
191
- el.index = index;
192
-
193
- const { item } = this._dataProviderController.getFlatIndexContext(index);
194
- if (item) {
195
- this.__updateLoading(el, false);
196
- this._updateItem(el, item);
197
- if (this._isExpanded(item)) {
198
- this._dataProviderController.ensureFlatIndexHierarchy(index);
199
- }
200
- } else {
201
- this.__updateLoading(el, true);
202
- this._dataProviderController.ensureFlatIndexLoaded(index);
203
- }
184
+ /** @private */
185
+ __getRowItem(row) {
186
+ const { item } = this._dataProviderController.getFlatIndexContext(row.index);
187
+ return item;
204
188
  }
205
189
 
206
- /**
207
- * @param {!HTMLElement} row
208
- * @param {boolean} loading
209
- * @private
210
- */
211
- __updateLoading(row, loading) {
212
- const cells = getBodyRowCells(row);
213
-
214
- // Row state attribute
215
- updateState(row, 'loading', loading);
216
-
217
- // Cells part attribute
218
- updateCellsPart(cells, 'loading-row-cell', loading);
190
+ /** @private */
191
+ __ensureRowItem(row) {
192
+ this._dataProviderController.ensureFlatIndexLoaded(row.index);
193
+ }
219
194
 
220
- if (loading) {
221
- // Run style generators for the loading row to have custom names cleared
222
- this._generateCellClassNames(row);
223
- this._generateCellPartNames(row);
224
- }
195
+ /** @private */
196
+ __ensureRowHierarchy(row) {
197
+ this._dataProviderController.ensureFlatIndexHierarchy(row.index);
225
198
  }
226
199
 
227
200
  /**
@@ -302,7 +275,7 @@ export const DataProviderMixin = (superClass) =>
302
275
  if (this._flatSize !== this._dataProviderController.flatSize) {
303
276
  // Schedule an update of all rendered rows by _debouncerApplyCachedData,
304
277
  // to ensure that all pages associated with the rendered rows are loaded.
305
- this._shouldUpdateAllRenderedRowsAfterPageLoad = true;
278
+ this._shouldLoadAllRenderedRowsAfterPageLoad = true;
306
279
 
307
280
  // TODO: Updating the flat size property can still result in a synchonous virtualizer update
308
281
  // if the size change requires the virtualizer to increase the amount of physical elements
@@ -312,9 +285,7 @@ export const DataProviderMixin = (superClass) =>
312
285
  }
313
286
 
314
287
  // After updating the cache, check if some of the expanded items should have sub-caches loaded
315
- this._getRenderedRows().forEach((row) => {
316
- this._dataProviderController.ensureFlatIndexHierarchy(row.index);
317
- });
288
+ this._getRenderedRows().forEach((row) => this.__ensureRowHierarchy(row));
318
289
 
319
290
  this._hasData = true;
320
291
  }
@@ -325,13 +296,14 @@ export const DataProviderMixin = (superClass) =>
325
296
  this._debouncerApplyCachedData = Debouncer.debounce(this._debouncerApplyCachedData, timeOut.after(0), () => {
326
297
  this._setLoading(false);
327
298
 
328
- const shouldUpdateAllRenderedRowsAfterPageLoad = this._shouldUpdateAllRenderedRowsAfterPageLoad;
329
- this._shouldUpdateAllRenderedRowsAfterPageLoad = false;
299
+ const shouldLoadAllRenderedRowsAfterPageLoad = this._shouldLoadAllRenderedRowsAfterPageLoad;
300
+ this._shouldLoadAllRenderedRowsAfterPageLoad = false;
330
301
 
331
302
  this._getRenderedRows().forEach((row) => {
332
- const { item } = this._dataProviderController.getFlatIndexContext(row.index);
333
- if (item || shouldUpdateAllRenderedRowsAfterPageLoad) {
334
- this._getItem(row.index, row);
303
+ this.__updateRow(row);
304
+
305
+ if (shouldLoadAllRenderedRowsAfterPageLoad) {
306
+ this.__ensureRowItem(row);
335
307
  }
336
308
  });
337
309
 
@@ -41,7 +41,7 @@ import { GridFilterElementMixin } from './vaadin-grid-filter-element-mixin.js';
41
41
  * @extends HTMLElement
42
42
  * @mixes GridFilterElementMixin
43
43
  */
44
- class GridFilter extends GridFilterElementMixin(ThemableMixin(LumoInjectionMixin(PolylitMixin(LitElement)))) {
44
+ class GridFilter extends GridFilterElementMixin(ThemableMixin(PolylitMixin(LumoInjectionMixin(LitElement)))) {
45
45
  static get is() {
46
46
  return 'vaadin-grid-filter';
47
47
  }
@@ -28,6 +28,7 @@ import {
28
28
  iterateRowCells,
29
29
  updateBooleanRowStates,
30
30
  updateCellsPart,
31
+ updateState,
31
32
  } from './vaadin-grid-helpers.js';
32
33
  import { KeyboardNavigationMixin } from './vaadin-grid-keyboard-navigation-mixin.js';
33
34
  import { RowDetailsMixin } from './vaadin-grid-row-details-mixin.js';
@@ -345,7 +346,7 @@ export const GridMixin = (superClass) =>
345
346
  row.setAttribute('role', 'row');
346
347
  row.setAttribute('tabindex', '-1');
347
348
  if (this._columnTree) {
348
- this._updateRow(row, this._columnTree[this._columnTree.length - 1], 'body', false, true);
349
+ this.__initRow(row, this._columnTree[this._columnTree.length - 1], 'body', false, true);
349
350
  }
350
351
  rows.push(row);
351
352
  }
@@ -457,9 +458,9 @@ export const GridMixin = (superClass) =>
457
458
  * @param {?string} section
458
459
  * @param {boolean} isColumnRow
459
460
  * @param {boolean} noNotify
460
- * @protected
461
+ * @private
461
462
  */
462
- _updateRow(row, columns, section = 'body', isColumnRow = false, noNotify = false) {
463
+ __initRow(row, columns, section = 'body', isColumnRow = false, noNotify = false) {
463
464
  const contentsFragment = document.createDocumentFragment();
464
465
 
465
466
  iterateRowCells(row, (cell) => {
@@ -639,10 +640,15 @@ export const GridMixin = (superClass) =>
639
640
  return;
640
641
  }
641
642
 
643
+ row.index = index;
644
+
642
645
  this._updateRowOrderParts(row, index);
643
646
 
644
647
  this._a11yUpdateRowRowindex(row, index);
645
- this._getItem(index, row);
648
+
649
+ this.__ensureRowItem(row);
650
+ this.__ensureRowHierarchy(row);
651
+ this.__updateRow(row);
646
652
  }
647
653
 
648
654
  /** @private */
@@ -683,7 +689,7 @@ export const GridMixin = (superClass) =>
683
689
  */
684
690
  _renderColumnTree(columnTree) {
685
691
  iterateChildren(this.$.items, (row) => {
686
- this._updateRow(row, columnTree[columnTree.length - 1], 'body', false, true);
692
+ this.__initRow(row, columnTree[columnTree.length - 1], 'body', false, true);
687
693
 
688
694
  const model = this.__getRowModel(row);
689
695
  this._updateRowOrderParts(row);
@@ -710,7 +716,7 @@ export const GridMixin = (superClass) =>
710
716
  }
711
717
 
712
718
  iterateChildren(this.$.header, (headerRow, index, rows) => {
713
- this._updateRow(headerRow, columnTree[index], 'header', index === columnTree.length - 1);
719
+ this.__initRow(headerRow, columnTree[index], 'header', index === columnTree.length - 1);
714
720
 
715
721
  const cells = getBodyRowCells(headerRow);
716
722
  updateCellsPart(cells, 'first-header-row-cell', index === 0);
@@ -718,7 +724,7 @@ export const GridMixin = (superClass) =>
718
724
  });
719
725
 
720
726
  iterateChildren(this.$.footer, (footerRow, index, rows) => {
721
- this._updateRow(footerRow, columnTree[columnTree.length - 1 - index], 'footer', index === 0);
727
+ this.__initRow(footerRow, columnTree[columnTree.length - 1 - index], 'footer', index === 0);
722
728
 
723
729
  const cells = getBodyRowCells(footerRow);
724
730
  updateCellsPart(cells, 'first-footer-row-cell', index === 0);
@@ -726,7 +732,7 @@ export const GridMixin = (superClass) =>
726
732
  });
727
733
 
728
734
  // Sizer rows
729
- this._updateRow(this.$.sizer, columnTree[columnTree.length - 1]);
735
+ this.__initRow(this.$.sizer, columnTree[columnTree.length - 1]);
730
736
 
731
737
  this._resizeHandler();
732
738
  this._frozenCellsChanged();
@@ -741,10 +747,38 @@ export const GridMixin = (superClass) =>
741
747
 
742
748
  /**
743
749
  * @param {!HTMLElement} row
744
- * @param {GridItem} item
745
- * @protected
750
+ * @param {boolean} loading
751
+ * @private
746
752
  */
747
- _updateItem(row, item) {
753
+ __updateRowLoading(row, loading) {
754
+ const cells = getBodyRowCells(row);
755
+
756
+ // Row state attribute
757
+ updateState(row, 'loading', loading);
758
+
759
+ // Cells part attribute
760
+ updateCellsPart(cells, 'loading-row-cell', loading);
761
+
762
+ if (loading) {
763
+ // Run style generators for the loading row to have custom names cleared
764
+ this._generateCellClassNames(row);
765
+ this._generateCellPartNames(row);
766
+ }
767
+ }
768
+
769
+ /**
770
+ * @param {!HTMLElement} row
771
+ * @private
772
+ */
773
+ __updateRow(row) {
774
+ const item = this.__getRowItem(row);
775
+ if (item) {
776
+ this.__updateRowLoading(row, false);
777
+ } else {
778
+ this.__updateRowLoading(row, true);
779
+ return;
780
+ }
781
+
748
782
  row._item = item;
749
783
  const model = this.__getRowModel(row);
750
784
 
@@ -85,7 +85,7 @@ export const RowDetailsMixin = (superClass) =>
85
85
  // Only update the rows if the column tree has already been initialized
86
86
  iterateChildren(this.$.items, (row) => {
87
87
  if (!row.querySelector('[part~=details-cell]')) {
88
- this._updateRow(row, this._columnTree[this._columnTree.length - 1]);
88
+ this.__initRow(row, this._columnTree[this._columnTree.length - 1]);
89
89
  const isDetailsOpened = this._isDetailsOpened(row._item);
90
90
  this._toggleDetailsCell(row, isDetailsOpened);
91
91
  }
@@ -98,13 +98,13 @@ export const RowDetailsMixin = (superClass) =>
98
98
  iterateChildren(this.$.items, (row) => {
99
99
  // Re-renders the row to possibly close the previously opened details.
100
100
  if (row.hasAttribute('details-opened')) {
101
- this._updateItem(row, row._item);
101
+ this.__updateRow(row);
102
102
  return;
103
103
  }
104
104
 
105
105
  // Re-renders the row to open the details when a row details renderer is provided.
106
106
  if (rowDetailsRenderer && this._isDetailsOpened(row._item)) {
107
- this._updateItem(row, row._item);
107
+ this.__updateRow(row);
108
108
  }
109
109
  });
110
110
  }
@@ -140,7 +140,7 @@ export const RowDetailsMixin = (superClass) =>
140
140
  }
141
141
 
142
142
  // Assigns a renderer when the details cell is opened.
143
- // The details cell content is rendered later in the `_updateItem` method.
143
+ // The details cell content is rendered later in the `__updateRow` method.
144
144
  if (this.rowDetailsRenderer) {
145
145
  cell._renderer = this.rowDetailsRenderer;
146
146
  }
@@ -57,7 +57,7 @@ import { GridSorterMixin } from './vaadin-grid-sorter-mixin.js';
57
57
  * @mixes ThemableMixin
58
58
  * @mixes DirMixin
59
59
  */
60
- class GridSorter extends GridSorterMixin(ThemableMixin(DirMixin(LumoInjectionMixin(PolylitMixin(LitElement))))) {
60
+ class GridSorter extends GridSorterMixin(ThemableMixin(DirMixin(PolylitMixin(LumoInjectionMixin(LitElement))))) {
61
61
  static get is() {
62
62
  return 'vaadin-grid-sorter';
63
63
  }
@@ -67,7 +67,7 @@ import { GridTreeToggleMixin } from './vaadin-grid-tree-toggle-mixin.js';
67
67
  * @mixes GridTreeToggleMixin
68
68
  */
69
69
  class GridTreeToggle extends GridTreeToggleMixin(
70
- ThemableMixin(DirMixin(LumoInjectionMixin(PolylitMixin(LitElement)))),
70
+ ThemableMixin(DirMixin(PolylitMixin(LumoInjectionMixin(LitElement)))),
71
71
  ) {
72
72
  static get is() {
73
73
  return 'vaadin-grid-tree-toggle';
@@ -262,7 +262,7 @@ import { GridMixin } from './vaadin-grid-mixin.js';
262
262
  * @mixes GridMixin
263
263
  * @mixes ThemableMixin
264
264
  */
265
- class Grid extends GridMixin(ElementMixin(ThemableMixin(LumoInjectionMixin(PolylitMixin(LitElement))))) {
265
+ class Grid extends GridMixin(ElementMixin(ThemableMixin(PolylitMixin(LumoInjectionMixin(LitElement))))) {
266
266
  static get is() {
267
267
  return 'vaadin-grid';
268
268
  }