@vaadin/vaadin-grid 5.8.1 → 5.9.0

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/README.md CHANGED
@@ -1,18 +1,18 @@
1
- [![npm version](https://badge.fury.io/js/%40vaadin%2Fvaadin-grid.svg)](https://badge.fury.io/js/%40vaadin%2Fvaadin-grid)
2
- [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/vaadin/vaadin-grid)
3
- [![Build Status](https://travis-ci.org/vaadin/vaadin-grid.svg?branch=master)](https://travis-ci.org/vaadin/vaadin-grid)
4
- [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/vaadin/web-components?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
1
+ # <vaadin-grid>
5
2
 
6
- [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/vaadinvaadin-grid)
7
- [![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/vaadinvaadin-grid.svg)](https://vaadin.com/directory/component/vaadinvaadin-grid)
3
+ > ⚠️ Starting from Vaadin 20, the source code and issues for this component are migrated to the [`vaadin/web-components`](https://github.com/vaadin/web-components/tree/master/packages/vaadin-grid) monorepository.
4
+ > This repository contains the source code and releases of `<vaadin-grid>` for the Vaadin versions 10 to 19.
8
5
 
9
- # &lt;vaadin-grid&gt;
6
+ [&lt;vaadin-grid&gt;](https://vaadin.com/components/vaadin-grid) is a free, high quality data grid / data table Web Component, part of the [Vaadin components](https://vaadin.com/components).
10
7
 
11
8
  [Live Demo ↗](https://vaadin.com/components/vaadin-grid/html-examples)
12
9
  |
13
10
  [API documentation ↗](https://vaadin.com/components/vaadin-grid/html-api)
14
11
 
15
- [&lt;vaadin-grid&gt;](https://vaadin.com/components/vaadin-grid) is a free, high quality data grid / data table Web Component, part of the [Vaadin components](https://vaadin.com/components).
12
+ [![npm version](https://badge.fury.io/js/%40vaadin%2Fvaadin-grid.svg)](https://badge.fury.io/js/%40vaadin%2Fvaadin-grid)
13
+ [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/vaadin/vaadin-grid)
14
+ [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/vaadinvaadin-grid)
15
+ [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
16
16
 
17
17
  <!---
18
18
  ```
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "repository": "vaadin/vaadin-grid",
16
16
  "homepage": "https://vaadin.com/components",
17
17
  "name": "@vaadin/vaadin-grid",
18
- "version": "5.8.1",
18
+ "version": "5.9.0",
19
19
  "main": "vaadin-grid.js",
20
20
  "author": "Vaadin Ltd",
21
21
  "license": "Apache-2.0",
package/src/iron-list.js CHANGED
@@ -637,6 +637,16 @@ export const PolymerIronList = Class({
637
637
  * @param {!Array<number>=} itemSet
638
638
  */
639
639
  _updateMetrics: function(itemSet) {
640
+
641
+ // Sometimes the call is schedule before Grid is hidden
642
+ // but it happens when Grid is already hidden.
643
+ // When this happens, there might be some issues as described
644
+ // here https://github.com/vaadin/web-components/issues/2127.
645
+ // Skipping any calculation for a hidden Grid.
646
+ if (!this._isVisible) {
647
+ return;
648
+ }
649
+
640
650
  // Make sure we distributed all the physical items
641
651
  // so we can measure them.
642
652
  flush();
@@ -8,6 +8,7 @@ import '@polymer/polymer/polymer-legacy.js';
8
8
  import { microTask } from '@polymer/polymer/lib/utils/async.js';
9
9
  import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
10
10
  import { ColumnBaseMixin } from './vaadin-grid-column.js';
11
+ import { GridHelper } from './vaadin-grid-helpers.js';
11
12
  import { PolymerElement } from '@polymer/polymer/polymer-element.js';
12
13
  /**
13
14
  * A `<vaadin-grid-column-group>` is used to make groups of columns in `<vaadin-grid>` and
@@ -153,7 +154,7 @@ class GridColumnGroupElement extends ColumnBaseMixin(PolymerElement) {
153
154
 
154
155
  // In an unlikely situation where a group has more than 9 child columns,
155
156
  // the child scope must have 1 digit less...
156
- const childCountDigits = ~~(Math.log(rootColumns.length) / Math.log(Math.LN10)) + 1;
157
+ const childCountDigits = ~~(Math.log(rootColumns.length) / Math.LN10) + 1;
157
158
 
158
159
  // Final scope for the child columns needs to mind both factors.
159
160
  const scope = Math.pow(10, trailingZeros - childCountDigits);
@@ -163,7 +164,7 @@ class GridColumnGroupElement extends ColumnBaseMixin(PolymerElement) {
163
164
  _rootColumns.sort((a, b) => a._order - b._order);
164
165
  }
165
166
 
166
- _rootColumns.forEach((column, index) => column._order = order + ((index + 1) * scope));
167
+ GridHelper._updateColumnOrders(_rootColumns, scope, order);
167
168
  }
168
169
  }
169
170
 
@@ -5,6 +5,7 @@ This program is available under Apache License Version 2.0, available at https:/
5
5
  */
6
6
  import { GestureEventListeners } from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
7
7
 
8
+ import { GridHelper } from './vaadin-grid-helpers.js';
8
9
  import { addListener } from '@polymer/polymer/lib/utils/gestures.js';
9
10
  import { dom } from '@polymer/polymer/lib/legacy/polymer.dom.js';
10
11
  import { useShadow } from '@polymer/polymer/lib/utils/settings.js';
@@ -293,7 +294,7 @@ export const ColumnReorderingMixin = superClass => class ColumnReorderingMixin e
293
294
  // Reset all column orders
294
295
  columnTree[0].forEach((column, index) => column._order = 0);
295
296
  // Set order numbers to top-level columns
296
- columnTree[0].forEach((column, index) => column._order = (index + 1) * this._orderBaseScope);
297
+ GridHelper._updateColumnOrders(columnTree[0], this._orderBaseScope, 0);
297
298
  }
298
299
 
299
300
  /**
@@ -395,7 +395,7 @@ export const DataProviderMixin = superClass => class DataProviderMixin extends s
395
395
  this._debouncerApplyCachedData.flush();
396
396
  }
397
397
 
398
- this.__itemsReceived();
398
+ this.__flushPendingRecalculateColumnWidths();
399
399
  });
400
400
  }
401
401
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ @license
3
+ Copyright (c) 2017 Vaadin Ltd.
4
+ This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ /** @private */
7
+ export const GridHelper = class VaadinGridHelper {
8
+
9
+ /**
10
+ * @param {Array<Object>} columns array of columns to be modified
11
+ * @param {number} scope multiplier added to base order for each column
12
+ * @param {number} baseOrder base number used for order
13
+ */
14
+ static _updateColumnOrders(columns, scope, baseOrder) {
15
+ let c = 1;
16
+ columns.forEach((column) => {
17
+ // avoid multiples of 10 because they introduce and extra zero and
18
+ // causes the underlying calculations for child order goes wrong
19
+ if (c % 10 === 0) {
20
+ c++;
21
+ }
22
+ column._order = baseOrder + c * scope;
23
+ c++;
24
+ });
25
+ }
26
+ };
@@ -532,6 +532,12 @@ export const KeyboardNavigationMixin = superClass => class KeyboardNavigationMix
532
532
  }
533
533
  // Inform cell content of the focus (used in <vaadin-grid-sorter>)
534
534
  cell._content.dispatchEvent(new CustomEvent('cell-focusin', {bubbles: false}));
535
+
536
+ // Fire a public event for cell focus.
537
+ const context = this.getEventContext(e);
538
+ cell.dispatchEvent(
539
+ new CustomEvent('cell-focus', {bubbles: true, composed: true, detail: {context: context}})
540
+ );
535
541
  }
536
542
 
537
543
  this._detectFocusedItemIndex(e);
@@ -738,4 +744,12 @@ export const KeyboardNavigationMixin = superClass => class KeyboardNavigationMix
738
744
  }
739
745
  return null;
740
746
  }
747
+
748
+ /**
749
+ * Fired when a cell is focused with click or keyboard navigation.
750
+ *
751
+ * Use context property of @see {@link GridCellFocusEvent} to get detail information about the event.
752
+ *
753
+ * @event cell-focus
754
+ */
741
755
  };
@@ -209,6 +209,7 @@ class GridScrollerElement extends PolymerIronList {
209
209
  // Ensure the rows are in order after increasing pool
210
210
  this.__reorderChildNodes();
211
211
  }
212
+ this.__flushPendingRecalculateColumnWidths();
212
213
  });
213
214
  }
214
215
  }
@@ -430,6 +431,19 @@ class GridScrollerElement extends PolymerIronList {
430
431
  super._resizeHandler();
431
432
  flush();
432
433
  }
434
+
435
+ __isCreatingRows() {
436
+ // iron-list's _increasePoolIfNeeded function may have scheduled a debouncer
437
+ // that will re-invoke _increasePoolIfNeeded (in vaadin-grid-scroller)
438
+ const schedulingDebounceIncreasePool = this._debouncers
439
+ && this._debouncers._increasePoolIfNeeded
440
+ && this._debouncers._increasePoolIfNeeded.isActive();
441
+ // vaadin-grid-scroller's overridden _increasePoolIfNeeded may have scheduled a _debounceIncreasePool debouncer
442
+ const debouncingIncreasePoolActive = this._debounceIncreasePool && this._debounceIncreasePool.isActive();
443
+
444
+ // If either of the conditions are true, we consider the grid is still in the process of creating new rows
445
+ return schedulingDebounceIncreasePool || debouncingIncreasePoolActive;
446
+ }
433
447
  }
434
448
 
435
449
  customElements.define(GridScrollerElement.is, GridScrollerElement);
@@ -197,7 +197,7 @@ class GridTreeToggleElement extends ThemableMixin(DirMixin(PolymerElement)) {
197
197
  /** @private */
198
198
  _levelChanged(level) {
199
199
  const value = Number(level).toString();
200
- this.style['---level'] = value;
200
+ this.updateStyles({'---level': value});
201
201
  // Async is to make DOM updates applied before evaluating the style
202
202
  // update, required for polyfilled RTL support in MSIE and Edge.
203
203
  this._debouncerUpdateLevel = Debouncer.debounce(
@@ -313,7 +313,7 @@ declare class GridElement extends
313
313
  allRowsVisible: boolean;
314
314
  connectedCallback(): void;
315
315
  attributeChangedCallback(name: string, oldValue: string|null, newValue: string|null): void;
316
- __itemsReceived(): void;
316
+ __flushPendingRecalculateColumnWidths(): void;
317
317
 
318
318
  /**
319
319
  * Updates the `width` of all columns which have `autoWidth` set to `true`.
@@ -322,7 +322,7 @@ class GridElement extends
322
322
  }
323
323
 
324
324
  static get version() {
325
- return '5.8.0';
325
+ return '5.9.0';
326
326
  }
327
327
 
328
328
  static get observers() {
@@ -451,10 +451,11 @@ class GridElement extends
451
451
  }
452
452
 
453
453
  /** @protected */
454
- __itemsReceived() {
454
+ __flushPendingRecalculateColumnWidths() {
455
455
  if (this._recalculateColumnWidthOnceLoadingFinished
456
- && !this._cache.isLoading()
457
- && this.__hasRowsWithClientHeight()) {
456
+ && !this._cache.isLoading()
457
+ && this.__hasRowsWithClientHeight()
458
+ && !this.__isCreatingRows()) {
458
459
  this._recalculateColumnWidthOnceLoadingFinished = false;
459
460
  this.recalculateColumnWidths();
460
461
  }
@@ -501,7 +502,7 @@ class GridElement extends
501
502
  if (!this._columnTree) {
502
503
  return; // No columns
503
504
  }
504
- if (this._cache.isLoading()) {
505
+ if (this._cache.isLoading() || this.__isCreatingRows()) {
505
506
  this._recalculateColumnWidthOnceLoadingFinished = true;
506
507
  } else {
507
508
  const cols = this._getColumns().filter(col => !col.hidden && col.autoWidth);
@@ -862,7 +863,7 @@ class GridElement extends
862
863
  this._render();
863
864
  e.stopPropagation();
864
865
  this.notifyResize();
865
- this.__itemsReceived();
866
+ this.__flushPendingRecalculateColumnWidths();
866
867
 
867
868
  requestAnimationFrame(() => {
868
869
  this.__scrollToPendingIndex();