@vaadin/grid 22.0.0-alpha9 → 22.0.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.
Files changed (42) hide show
  1. package/README.md +45 -26
  2. package/package.json +11 -11
  3. package/src/vaadin-grid-active-item-mixin.d.ts +5 -10
  4. package/src/vaadin-grid-array-data-provider-mixin.d.ts +4 -9
  5. package/src/vaadin-grid-column-group.d.ts +2 -2
  6. package/src/vaadin-grid-column-group.js +1 -1
  7. package/src/vaadin-grid-column-reordering-mixin.d.ts +4 -11
  8. package/src/vaadin-grid-column.d.ts +6 -9
  9. package/src/vaadin-grid-column.js +2 -2
  10. package/src/vaadin-grid-data-provider-mixin.d.ts +5 -10
  11. package/src/vaadin-grid-data-provider-mixin.js +1 -1
  12. package/src/vaadin-grid-drag-and-drop-mixin.d.ts +4 -9
  13. package/src/vaadin-grid-drag-and-drop-mixin.js +4 -3
  14. package/src/vaadin-grid-dynamic-columns-mixin.js +2 -2
  15. package/src/vaadin-grid-event-context-mixin.d.ts +4 -9
  16. package/src/vaadin-grid-filter-column.d.ts +1 -1
  17. package/src/vaadin-grid-filter-column.js +1 -1
  18. package/src/vaadin-grid-filter.js +3 -3
  19. package/src/vaadin-grid-keyboard-navigation-mixin.js +28 -15
  20. package/src/vaadin-grid-row-details-mixin.d.ts +4 -9
  21. package/src/vaadin-grid-scroll-mixin.d.ts +3 -8
  22. package/src/vaadin-grid-scroll-mixin.js +1 -1
  23. package/src/vaadin-grid-selection-column.d.ts +1 -1
  24. package/src/vaadin-grid-selection-column.js +34 -18
  25. package/src/vaadin-grid-selection-mixin.d.ts +4 -9
  26. package/src/vaadin-grid-sort-column.d.ts +1 -1
  27. package/src/vaadin-grid-sort-column.js +1 -1
  28. package/src/vaadin-grid-sort-mixin.d.ts +3 -8
  29. package/src/vaadin-grid-sorter.js +1 -1
  30. package/src/vaadin-grid-styles.js +1 -1
  31. package/src/vaadin-grid-styling-mixin.d.ts +6 -9
  32. package/src/vaadin-grid-tree-column.d.ts +1 -1
  33. package/src/vaadin-grid-tree-column.js +1 -1
  34. package/src/vaadin-grid-tree-toggle.js +1 -1
  35. package/src/vaadin-grid.d.ts +43 -52
  36. package/src/vaadin-grid.js +98 -79
  37. package/theme/lumo/vaadin-grid-sorter-styles.js +1 -1
  38. package/theme/lumo/vaadin-grid-styles.js +5 -1
  39. package/theme/lumo/vaadin-grid-tree-toggle-styles.js +1 -1
  40. package/theme/material/vaadin-grid-sorter-styles.js +1 -1
  41. package/theme/material/vaadin-grid-styles.js +5 -1
  42. package/theme/material/vaadin-grid-tree-toggle-styles.js +1 -1
@@ -3,14 +3,11 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { Constructor } from '@open-wc/dedupe-mixin';
6
7
 
7
- declare function ScrollMixin<T extends new (...args: any[]) => {}>(base: T): T & ScrollMixinConstructor;
8
+ export declare function ScrollMixin<T extends Constructor<HTMLElement>>(base: T): T & Constructor<ScrollMixinClass>;
8
9
 
9
- interface ScrollMixinConstructor {
10
- new (...args: any[]): ScrollMixin;
11
- }
12
-
13
- interface ScrollMixin {
10
+ export declare class ScrollMixinClass {
14
11
  /**
15
12
  * Scroll to a specific row index in the virtual list. Note that the row index is
16
13
  * not always the same for any particular item. For example, sorting/filtering/expanding
@@ -20,5 +17,3 @@ interface ScrollMixin {
20
17
  */
21
18
  scrollToIndex(index: number): void;
22
19
  }
23
-
24
- export { ScrollMixin, ScrollMixinConstructor };
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { animationFrame, microTask, timeOut } from '@vaadin/component-base/src/async.js';
6
7
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
7
- import { animationFrame, timeOut, microTask } from '@vaadin/component-base/src/async.js';
8
8
 
9
9
  const timeouts = {
10
10
  SCROLLING: 500
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { GridColumn } from './vaadin-grid-column.js';
7
6
  import { GridDefaultItem } from './vaadin-grid.js';
7
+ import { GridColumn } from './vaadin-grid-column.js';
8
8
 
9
9
  /**
10
10
  * Fired when the `selectAll` property changes.
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { GridColumn } from './vaadin-grid-column.js';
7
6
  import '@vaadin/checkbox/src/vaadin-checkbox.js';
7
+ import { GridColumn } from './vaadin-grid-column.js';
8
8
 
9
9
  /**
10
10
  * `<vaadin-grid-selection-column>` is a helper element for the `<vaadin-grid>`
@@ -184,7 +184,11 @@ class GridSelectionColumn extends GridColumn {
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
  /**
@@ -250,26 +254,22 @@ class GridSelectionColumn extends GridColumn {
250
254
  this.__previousActiveItem = activeItem;
251
255
  }
252
256
 
253
- /** @private */
254
- __getRootLevelItems() {
255
- const rootCache = this._grid._cache;
256
- return [...Array(rootCache.size)].map((_, idx) => rootCache.items[idx]);
257
- }
258
-
259
257
  /** @private */
260
258
  __onSelectedItemsChanged() {
261
259
  this._selectAllChangeLock = true;
262
260
  if (Array.isArray(this._grid.items)) {
263
- if (!this._grid.selectedItems.length) {
264
- this.selectAll = false;
265
- this.__indeterminate = false;
266
- } else if (this.__arrayContains(this._grid.selectedItems, this.__getRootLevelItems())) {
267
- this.selectAll = true;
268
- this.__indeterminate = false;
269
- } else {
270
- this.selectAll = false;
271
- this.__indeterminate = true;
272
- }
261
+ this.__withFilteredItemsArray((items) => {
262
+ if (!this._grid.selectedItems.length) {
263
+ this.selectAll = false;
264
+ this.__indeterminate = false;
265
+ } else if (this.__arrayContains(this._grid.selectedItems, items)) {
266
+ this.selectAll = true;
267
+ this.__indeterminate = false;
268
+ } else {
269
+ this.selectAll = false;
270
+ this.__indeterminate = true;
271
+ }
272
+ });
273
273
  }
274
274
  this._selectAllChangeLock = false;
275
275
  }
@@ -278,6 +278,22 @@ class GridSelectionColumn extends GridColumn {
278
278
  __onDataProviderChanged() {
279
279
  this.__selectAllHidden = !Array.isArray(this._grid.items);
280
280
  }
281
+
282
+ /**
283
+ * Assuming the grid uses an items array data provider, fetches all the filtered items
284
+ * from the data provider and invokes the callback with the resulting array.
285
+ *
286
+ * @private
287
+ */
288
+ __withFilteredItemsArray(callback) {
289
+ const params = {
290
+ page: 0,
291
+ pageSize: Infinity,
292
+ sortOrders: [],
293
+ filters: this._grid._mapFilters()
294
+ };
295
+ this._grid.dataProvider(params, (items) => callback(items));
296
+ }
281
297
  }
282
298
 
283
299
  customElements.define(GridSelectionColumn.is, GridSelectionColumn);
@@ -3,16 +3,13 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { Constructor } from '@open-wc/dedupe-mixin';
6
7
 
7
- declare function SelectionMixin<TItem, T extends new (...args: any[]) => {}>(
8
+ export declare function SelectionMixin<TItem, T extends Constructor<HTMLElement>>(
8
9
  base: T
9
- ): T & SelectionMixinConstructor<TItem>;
10
+ ): T & Constructor<SelectionMixinClass<TItem>>;
10
11
 
11
- interface SelectionMixinConstructor<TItem> {
12
- new (...args: any[]): SelectionMixin<TItem>;
13
- }
14
-
15
- interface SelectionMixin<TItem> {
12
+ export declare class SelectionMixinClass<TItem> {
16
13
  /**
17
14
  * An array that contains the selected items.
18
15
  */
@@ -32,5 +29,3 @@ interface SelectionMixin<TItem> {
32
29
  */
33
30
  deselectItem(item: TItem): void;
34
31
  }
35
-
36
- export { SelectionMixin, SelectionMixinConstructor };
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { GridColumn } from './vaadin-grid-column.js';
7
6
  import { GridDefaultItem } from './vaadin-grid.js';
7
+ import { GridColumn } from './vaadin-grid-column.js';
8
8
  import { GridSorterDirection } from './vaadin-grid-sorter.js';
9
9
 
10
10
  /**
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { GridColumn } from './vaadin-grid-column.js';
7
6
  import './vaadin-grid-sorter.js';
7
+ import { GridColumn } from './vaadin-grid-column.js';
8
8
 
9
9
  /**
10
10
  * `<vaadin-grid-sort-column>` is a helper element for the `<vaadin-grid>`
@@ -3,19 +3,14 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { Constructor } from '@open-wc/dedupe-mixin';
6
7
 
7
- declare function SortMixin<T extends new (...args: any[]) => {}>(base: T): T & SortMixinConstructor;
8
+ export declare function SortMixin<T extends Constructor<HTMLElement>>(base: T): T & Constructor<SortMixinClass>;
8
9
 
9
- interface SortMixinConstructor {
10
- new (...args: any[]): SortMixin;
11
- }
12
-
13
- interface SortMixin {
10
+ export declare class SortMixinClass {
14
11
  /**
15
12
  * When `true`, all `<vaadin-grid-sorter>` are applied for sorting.
16
13
  * @attr {boolean} multi-sort
17
14
  */
18
15
  multiSort: boolean;
19
16
  }
20
-
21
- export { SortMixin, SortMixinConstructor };
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
6
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
7
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
8
8
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
9
 
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
6
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
7
 
8
8
  registerStyles(
9
9
  'vaadin-grid',
@@ -3,18 +3,17 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { GridColumn } from './vaadin-grid-column.js';
6
+ import { Constructor } from '@open-wc/dedupe-mixin';
7
7
  import { GridItemModel } from './vaadin-grid.js';
8
+ import { GridColumn } from './vaadin-grid-column.js';
8
9
 
9
10
  export type GridCellClassNameGenerator<TItem> = (column: GridColumn<TItem>, model: GridItemModel<TItem>) => string;
10
11
 
11
- declare function StylingMixin<TItem, T extends new (...args: any[]) => {}>(base: T): T & StylingMixinConstructor<TItem>;
12
+ export declare function StylingMixin<TItem, T extends Constructor<HTMLElement>>(
13
+ base: T
14
+ ): T & Constructor<StylingMixinClass<TItem>>;
12
15
 
13
- interface StylingMixinConstructor<TItem> {
14
- new (...args: any[]): StylingMixin<TItem>;
15
- }
16
-
17
- interface StylingMixin<TItem> {
16
+ export declare class StylingMixinClass<TItem> {
18
17
  /**
19
18
  * A function that allows generating CSS class names for grid cells
20
19
  * based on their row and column. The return value should be the generated
@@ -41,5 +40,3 @@ interface StylingMixin<TItem> {
41
40
  */
42
41
  generateCellClassNames(): void;
43
42
  }
44
-
45
- export { StylingMixin, StylingMixinConstructor };
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { GridColumn } from './vaadin-grid-column.js';
7
6
  import { GridDefaultItem } from './vaadin-grid.js';
7
+ import { GridColumn } from './vaadin-grid-column.js';
8
8
 
9
9
  /**
10
10
  * `<vaadin-grid-tree-column>` is a helper element for the `<vaadin-grid>`
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { GridColumn } from './vaadin-grid-column.js';
7
6
  import './vaadin-grid-tree-toggle.js';
7
+ import { GridColumn } from './vaadin-grid-column.js';
8
8
 
9
9
  /**
10
10
  * `<vaadin-grid-tree-column>` is a helper element for the `<vaadin-grid>`
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
6
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
7
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
8
8
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
9
  import { isFocusable } from './vaadin-grid-active-item-mixin.js';
@@ -3,14 +3,14 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
- import { ActiveItemMixin } from './vaadin-grid-active-item-mixin.js';
9
- import { ArrayDataProviderMixin } from './vaadin-grid-array-data-provider-mixin.js';
10
- import { GridColumn, GridBodyRenderer, GridHeaderFooterRenderer } from './vaadin-grid-column.js';
11
- import { ColumnReorderingMixin } from './vaadin-grid-column-reordering-mixin.js';
6
+ import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js';
7
+ import { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
+ import { ActiveItemMixinClass } from './vaadin-grid-active-item-mixin.js';
9
+ import { ArrayDataProviderMixinClass } from './vaadin-grid-array-data-provider-mixin.js';
10
+ import { GridBodyRenderer, GridColumn, GridHeaderFooterRenderer } from './vaadin-grid-column.js';
11
+ import { ColumnReorderingMixinClass } from './vaadin-grid-column-reordering-mixin.js';
12
12
  import {
13
- DataProviderMixin,
13
+ DataProviderMixinClass,
14
14
  GridDataProvider,
15
15
  GridDataProviderCallback,
16
16
  GridDataProviderParams,
@@ -19,17 +19,17 @@ import {
19
19
  GridSorterDirection
20
20
  } from './vaadin-grid-data-provider-mixin.js';
21
21
  import {
22
- DragAndDropMixin,
22
+ DragAndDropMixinClass,
23
23
  GridDragAndDropFilter,
24
24
  GridDropLocation,
25
25
  GridDropMode
26
26
  } from './vaadin-grid-drag-and-drop-mixin.js';
27
- import { EventContextMixin, GridEventContext } from './vaadin-grid-event-context-mixin.js';
28
- import { RowDetailsMixin, GridRowDetailsRenderer } from './vaadin-grid-row-details-mixin.js';
29
- import { ScrollMixin } from './vaadin-grid-scroll-mixin.js';
30
- import { SelectionMixin } from './vaadin-grid-selection-mixin.js';
31
- import { SortMixin } from './vaadin-grid-sort-mixin.js';
32
- import { StylingMixin, GridCellClassNameGenerator } from './vaadin-grid-styling-mixin.js';
27
+ import { EventContextMixinClass, GridEventContext } from './vaadin-grid-event-context-mixin.js';
28
+ import { GridRowDetailsRenderer, RowDetailsMixinClass } from './vaadin-grid-row-details-mixin.js';
29
+ import { ScrollMixinClass } from './vaadin-grid-scroll-mixin.js';
30
+ import { SelectionMixinClass } from './vaadin-grid-selection-mixin.js';
31
+ import { SortMixinClass } from './vaadin-grid-sort-mixin.js';
32
+ import { GridCellClassNameGenerator, StylingMixinClass } from './vaadin-grid-styling-mixin.js';
33
33
 
34
34
  export {
35
35
  GridBodyRenderer,
@@ -253,20 +253,16 @@ export interface GridEventMap<TItem> extends HTMLElementEventMap, GridCustomEven
253
253
  * in the second argument of the data provider callback:__
254
254
  *
255
255
  * ```javascript
256
- * grid.dataProvider = function(params, callback) {
257
- * const url = 'https://api.example/data' +
258
- * '?page=' + params.page + // the requested page index
259
- * '&per_page=' + params.pageSize; // number of items on the page
260
- * const xhr = new XMLHttpRequest();
261
- * xhr.onload = function() {
262
- * const response = JSON.parse(xhr.responseText);
263
- * callback(
264
- * response.employees, // requested page of items
265
- * response.totalSize // total number of items
266
- * );
267
- * };
268
- * xhr.open('GET', url, true);
269
- * xhr.send();
256
+ * grid.dataProvider = ({page, pageSize}, callback) => {
257
+ * // page: the requested page index
258
+ * // pageSize: number of items on one page
259
+ * const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
260
+ *
261
+ * fetch(url)
262
+ * .then((res) => res.json())
263
+ * .then(({ employees, totalSize }) => {
264
+ * callback(employees, totalSize);
265
+ * });
270
266
  * };
271
267
  * ```
272
268
  *
@@ -274,17 +270,12 @@ export interface GridEventMap<TItem> extends HTMLElementEventMap, GridCustomEven
274
270
  *
275
271
  * ```javascript
276
272
  * grid.size = 200; // The total number of items
277
- * grid.dataProvider = function(params, callback) {
278
- * const url = 'https://api.example/data' +
279
- * '?page=' + params.page + // the requested page index
280
- * '&per_page=' + params.pageSize; // number of items on the page
281
- * const xhr = new XMLHttpRequest();
282
- * xhr.onload = function() {
283
- * const response = JSON.parse(xhr.responseText);
284
- * callback(response.employees);
285
- * };
286
- * xhr.open('GET', url, true);
287
- * xhr.send();
273
+ * grid.dataProvider = ({page, pageSize}, callback) => {
274
+ * const url = `https://api.example/data?page=${page}&per_page=${pageSize}`;
275
+ *
276
+ * fetch(url)
277
+ * .then((res) => res.json())
278
+ * .then((resJson) => callback(resJson.employees));
288
279
  * };
289
280
  * ```
290
281
  *
@@ -397,19 +388,19 @@ declare class Grid<TItem = GridDefaultItem> extends HTMLElement {
397
388
  }
398
389
 
399
390
  interface Grid<TItem = GridDefaultItem>
400
- extends ElementMixin,
401
- ThemableMixin,
402
- ActiveItemMixin<TItem>,
403
- ArrayDataProviderMixin<TItem>,
404
- DataProviderMixin<TItem>,
405
- RowDetailsMixin<TItem>,
406
- ScrollMixin,
407
- SelectionMixin<TItem>,
408
- SortMixin,
409
- ColumnReorderingMixin,
410
- EventContextMixin<TItem>,
411
- StylingMixin<TItem>,
412
- DragAndDropMixin<TItem> {}
391
+ extends ElementMixinClass,
392
+ ThemableMixinClass,
393
+ ActiveItemMixinClass<TItem>,
394
+ ArrayDataProviderMixinClass<TItem>,
395
+ DataProviderMixinClass<TItem>,
396
+ RowDetailsMixinClass<TItem>,
397
+ ScrollMixinClass,
398
+ SelectionMixinClass<TItem>,
399
+ SortMixinClass,
400
+ ColumnReorderingMixinClass,
401
+ EventContextMixinClass<TItem>,
402
+ StylingMixinClass<TItem>,
403
+ DragAndDropMixinClass<TItem> {}
413
404
 
414
405
  declare global {
415
406
  interface HTMLElementTagNameMap {