@vaadin/vaadin-grid 21.0.1 → 21.0.5

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/vaadin-grid",
3
- "version": "21.0.1",
3
+ "version": "21.0.5",
4
4
  "description": "A free, flexible and high-quality Web Component for showing large amounts of tabular data",
5
5
  "main": "vaadin-grid.js",
6
6
  "module": "vaadin-grid.js",
@@ -32,23 +32,23 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "@polymer/polymer": "^3.0.0",
35
- "@vaadin/vaadin-checkbox": "^21.0.1",
36
- "@vaadin/vaadin-element-mixin": "^21.0.1",
37
- "@vaadin/vaadin-lumo-styles": "^21.0.1",
38
- "@vaadin/vaadin-material-styles": "^21.0.1",
39
- "@vaadin/vaadin-text-field": "^21.0.1",
40
- "@vaadin/vaadin-themable-mixin": "^21.0.1",
41
- "@vaadin/vaadin-virtual-list": "^21.0.1"
35
+ "@vaadin/vaadin-checkbox": "^21.0.5",
36
+ "@vaadin/vaadin-element-mixin": "^21.0.5",
37
+ "@vaadin/vaadin-lumo-styles": "^21.0.5",
38
+ "@vaadin/vaadin-material-styles": "^21.0.5",
39
+ "@vaadin/vaadin-text-field": "^21.0.5",
40
+ "@vaadin/vaadin-themable-mixin": "^21.0.5",
41
+ "@vaadin/vaadin-virtual-list": "^21.0.5"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@esm-bundle/chai": "^4.1.5",
45
45
  "@vaadin/testing-helpers": "^0.2.1",
46
- "@vaadin/vaadin-template-renderer": "^21.0.1",
47
- "lit": "^2.0.0-rc.1",
46
+ "@vaadin/vaadin-template-renderer": "^21.0.5",
47
+ "lit": "^2.0.0",
48
48
  "sinon": "^9.2.0"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "91e44dcfa63dc5e30e1e8d18be499b3e1e17b1c4"
53
+ "gitHead": "c79135f420e560fa566afc1377db9585757bc4c3"
54
54
  }
@@ -85,7 +85,7 @@ export const DragAndDropMixin = (superClass) =>
85
85
  }
86
86
 
87
87
  static get observers() {
88
- return ['_dragDropAccessChanged(rowsDraggable, dropMode, dragFilter, dropFilter)'];
88
+ return ['_dragDropAccessChanged(rowsDraggable, dropMode, dragFilter, dropFilter, loading)'];
89
89
  }
90
90
 
91
91
  /** @protected */
@@ -376,8 +376,9 @@ export const DragAndDropMixin = (superClass) =>
376
376
  * @protected
377
377
  */
378
378
  _filterDragAndDrop(row, model) {
379
- const dragDisabled = !this.rowsDraggable || (this.dragFilter && !this.dragFilter(model));
380
- const dropDisabled = !this.dropMode || (this.dropFilter && !this.dropFilter(model));
379
+ const loading = this.loading || row.hasAttribute('loading');
380
+ const dragDisabled = !this.rowsDraggable || loading || (this.dragFilter && !this.dragFilter(model));
381
+ const dropDisabled = !this.dropMode || loading || (this.dropFilter && !this.dropFilter(model));
381
382
 
382
383
  const draggableElements = Array.from(row.children).map((cell) => cell._content);
383
384
 
@@ -184,7 +184,11 @@ class GridSelectionColumnElement extends GridColumnElement {
184
184
  return;
185
185
  }
186
186
 
187
- this._grid.selectedItems = selectAll && Array.isArray(this._grid.items) ? this.__getRootLevelItems() : [];
187
+ if (selectAll && Array.isArray(this._grid.items)) {
188
+ this.__withFilteredItemsArray((items) => (this._grid.selectedItems = items));
189
+ } else {
190
+ this._grid.selectedItems = [];
191
+ }
188
192
  }
189
193
 
190
194
  /**
@@ -251,26 +255,22 @@ class GridSelectionColumnElement extends GridColumnElement {
251
255
  this.__previousActiveItem = activeItem;
252
256
  }
253
257
 
254
- /** @private */
255
- __getRootLevelItems() {
256
- const rootCache = this._grid._cache;
257
- return [...Array(rootCache.size)].map((_, idx) => rootCache.items[idx]);
258
- }
259
-
260
258
  /** @private */
261
259
  __onSelectedItemsChanged() {
262
260
  this._selectAllChangeLock = true;
263
261
  if (Array.isArray(this._grid.items)) {
264
- if (!this._grid.selectedItems.length) {
265
- this.selectAll = false;
266
- this.__indeterminate = false;
267
- } else if (this.__arrayContains(this._grid.selectedItems, this.__getRootLevelItems())) {
268
- this.selectAll = true;
269
- this.__indeterminate = false;
270
- } else {
271
- this.selectAll = false;
272
- this.__indeterminate = true;
273
- }
262
+ this.__withFilteredItemsArray((items) => {
263
+ if (!this._grid.selectedItems.length) {
264
+ this.selectAll = false;
265
+ this.__indeterminate = false;
266
+ } else if (this.__arrayContains(this._grid.selectedItems, items)) {
267
+ this.selectAll = true;
268
+ this.__indeterminate = false;
269
+ } else {
270
+ this.selectAll = false;
271
+ this.__indeterminate = true;
272
+ }
273
+ });
274
274
  }
275
275
  this._selectAllChangeLock = false;
276
276
  }
@@ -279,6 +279,22 @@ class GridSelectionColumnElement extends GridColumnElement {
279
279
  __onDataProviderChanged() {
280
280
  this.__selectAllHidden = !Array.isArray(this._grid.items);
281
281
  }
282
+
283
+ /**
284
+ * Assuming the grid uses an items array data provider, fetches all the filtered items
285
+ * from the data provider and invokes the callback with the resulting array.
286
+ *
287
+ * @private
288
+ */
289
+ __withFilteredItemsArray(callback) {
290
+ const params = {
291
+ page: 0,
292
+ pageSize: Infinity,
293
+ sortOrders: [],
294
+ filters: this._grid._mapFilters()
295
+ };
296
+ this._grid.dataProvider(params, (items) => callback(items));
297
+ }
282
298
  }
283
299
 
284
300
  customElements.define(GridSelectionColumnElement.is, GridSelectionColumnElement);
@@ -317,7 +317,7 @@ class GridElement extends ElementMixin(
317
317
  }
318
318
 
319
319
  static get version() {
320
- return '21.0.1';
320
+ return '21.0.5';
321
321
  }
322
322
 
323
323
  static get observers() {
@@ -540,42 +540,72 @@ class GridElement extends ElementMixin(
540
540
  }
541
541
  }
542
542
 
543
+ /** @private */
544
+ __getIntrinsicWidth(col) {
545
+ const initialWidth = col.width;
546
+ const initialFlexGrow = col.flexGrow;
547
+
548
+ col.width = 'auto';
549
+ col.flexGrow = 0;
550
+
551
+ // Note: _allCells only contains cells which are currently rendered in DOM
552
+ const width = col._allCells
553
+ .filter((cell) => {
554
+ // Exclude body cells that are out of the visible viewport
555
+ return !this.$.items.contains(cell) || this._isInViewport(cell.parentElement);
556
+ })
557
+ .reduce((width, cell) => {
558
+ // Add 1px buffer to the offset width to avoid too narrow columns (sub-pixel rendering)
559
+ return Math.max(width, cell.offsetWidth + 1);
560
+ }, 0);
561
+
562
+ col.flexGrow = initialFlexGrow;
563
+ col.width = initialWidth;
564
+
565
+ return width;
566
+ }
567
+
568
+ /** @private */
569
+ __getDistributedWidth(col, innerColumn) {
570
+ if (col == null || col === this) return 0;
571
+
572
+ const columnWidth = Math.max(this.__getIntrinsicWidth(col), this.__getDistributedWidth(col.parentElement, col));
573
+
574
+ // we're processing a regular grid-column and not a grid-column-group
575
+ if (!innerColumn) {
576
+ return columnWidth;
577
+ }
578
+
579
+ // At the end, the width of each vaadin-grid-column-group is determined by the sum of the width of its children.
580
+ // Here we determine how much space the vaadin-grid-column-group actually needs to render properly and then we distribute that space
581
+ // to its children, so when we actually do the summation it will be rendered properly.
582
+ // Check out vaadin-grid-column-group:_updateFlexAndWidth
583
+ const columnGroup = col;
584
+ const columnGroupWidth = columnWidth;
585
+ const sumOfWidthOfAllChildColumns = columnGroup._visibleChildColumns
586
+ .map((col) => this.__getIntrinsicWidth(col))
587
+ .reduce((sum, curr) => sum + curr, 0);
588
+
589
+ const extraNecessarySpaceForGridColumnGroup = Math.max(0, columnGroupWidth - sumOfWidthOfAllChildColumns);
590
+
591
+ // The distribution of the extra necessary space is done according to the intrinsic width of each child column.
592
+ // Lets say we need 100 pixels of extra space for the grid-column-group to render properly
593
+ // it has two grid-column children, |100px|300px| in total 400px
594
+ // the first column gets 25px of the additional space (100/400)*100 = 25
595
+ // the second column gets the 75px of the additional space (300/400)*100 = 75
596
+ const proportionOfExtraSpace = this.__getIntrinsicWidth(innerColumn) / sumOfWidthOfAllChildColumns;
597
+ const shareOfInnerColumnFromNecessaryExtraSpace = proportionOfExtraSpace * extraNecessarySpaceForGridColumnGroup;
598
+
599
+ return this.__getIntrinsicWidth(innerColumn) + shareOfInnerColumnFromNecessaryExtraSpace;
600
+ }
601
+
543
602
  /**
544
603
  * @param {!Array<!GridColumnElement>} cols the columns to auto size based on their content width
545
604
  * @private
546
605
  */
547
606
  _recalculateColumnWidths(cols) {
548
- // Note: The `cols.forEach()` loops below could be implemented as a single loop but this has been
549
- // split for performance reasons to batch these similar actions [write/read] together to avoid
550
- // unnecessary layout trashing.
551
-
552
- // [write] Set automatic width for all cells (breaks column alignment)
553
- cols.forEach((col) => {
554
- col.width = 'auto';
555
- col._origFlexGrow = col.flexGrow;
556
- col.flexGrow = 0;
557
- });
558
- // [read] Measure max cell width in each column
559
- cols.forEach((col) => {
560
- col._currentWidth = 0;
561
- // Note: _allCells only contains cells which are currently rendered in DOM
562
- col._allCells
563
- .filter((c) => {
564
- // Exclude body cells that are out of the visible viewport
565
- return !this.$.items.contains(c) || this._isInViewport(c.parentElement);
566
- })
567
- .forEach((c) => {
568
- // Add 1px buffer to the offset width to avoid too narrow columns (sub-pixel rendering)
569
- const cellWidth = c.offsetWidth + 1;
570
- col._currentWidth = Math.max(col._currentWidth, cellWidth);
571
- });
572
- });
573
- // [write] Set column widths to fit widest measured content
574
607
  cols.forEach((col) => {
575
- col.width = `${col._currentWidth}px`;
576
- col.flexGrow = col._origFlexGrow;
577
- col._currentWidth = undefined;
578
- col._origFlexGrow = undefined;
608
+ col.width = `${this.__getDistributedWidth(col)}px`;
579
609
  });
580
610
  }
581
611
 
@@ -864,6 +894,7 @@ class GridElement extends ElementMixin(
864
894
  this._a11yUpdateHeaderRows();
865
895
  this._a11yUpdateFooterRows();
866
896
  this.__updateFooterPositioning();
897
+ this.generateCellClassNames();
867
898
  }
868
899
 
869
900
  __updateFooterPositioning() {