@vaadin/grid 24.2.0-alpha1 → 24.2.0-alpha11

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/grid",
3
- "version": "24.2.0-alpha1",
3
+ "version": "24.2.0-alpha11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -46,18 +46,18 @@
46
46
  "dependencies": {
47
47
  "@open-wc/dedupe-mixin": "^1.3.0",
48
48
  "@polymer/polymer": "^3.0.0",
49
- "@vaadin/a11y-base": "24.2.0-alpha1",
50
- "@vaadin/checkbox": "24.2.0-alpha1",
51
- "@vaadin/component-base": "24.2.0-alpha1",
52
- "@vaadin/lit-renderer": "24.2.0-alpha1",
53
- "@vaadin/text-field": "24.2.0-alpha1",
54
- "@vaadin/vaadin-lumo-styles": "24.2.0-alpha1",
55
- "@vaadin/vaadin-material-styles": "24.2.0-alpha1",
56
- "@vaadin/vaadin-themable-mixin": "24.2.0-alpha1"
49
+ "@vaadin/a11y-base": "24.2.0-alpha11",
50
+ "@vaadin/checkbox": "24.2.0-alpha11",
51
+ "@vaadin/component-base": "24.2.0-alpha11",
52
+ "@vaadin/lit-renderer": "24.2.0-alpha11",
53
+ "@vaadin/text-field": "24.2.0-alpha11",
54
+ "@vaadin/vaadin-lumo-styles": "24.2.0-alpha11",
55
+ "@vaadin/vaadin-material-styles": "24.2.0-alpha11",
56
+ "@vaadin/vaadin-themable-mixin": "24.2.0-alpha11"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@esm-bundle/chai": "^4.3.4",
60
- "@vaadin/testing-helpers": "^0.4.2",
60
+ "@vaadin/testing-helpers": "^0.5.0",
61
61
  "lit": "^2.0.0",
62
62
  "sinon": "^13.0.2"
63
63
  },
@@ -65,5 +65,5 @@
65
65
  "web-types.json",
66
66
  "web-types.lit.json"
67
67
  ],
68
- "gitHead": "0dbb118320203ab6c0c07450a3e718815367589f"
68
+ "gitHead": "a958207d5f6a09ca0e2dcf9f62194b3f92c8766a"
69
69
  }
@@ -4,9 +4,8 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  /* eslint-disable max-classes-per-file */
7
- import type { TemplateResult } from 'lit';
8
7
  import type { DirectiveResult } from 'lit/directive';
9
- import type { LitRenderer } from '@vaadin/lit-renderer';
8
+ import type { LitRenderer, LitRendererResult } from '@vaadin/lit-renderer';
10
9
  import { LitRendererDirective } from '@vaadin/lit-renderer';
11
10
  import type { GridItemModel } from '../vaadin-grid.js';
12
11
  import type { GridColumn } from '../vaadin-grid-column.js';
@@ -15,10 +14,10 @@ export type GridColumnBodyLitRenderer<TItem> = (
15
14
  item: TItem,
16
15
  model: GridItemModel<TItem>,
17
16
  column: GridColumn,
18
- ) => TemplateResult;
17
+ ) => LitRendererResult;
19
18
 
20
- export type GridColumnHeaderLitRenderer = (column: GridColumn) => TemplateResult;
21
- export type GridColumnFooterLitRenderer = (column: GridColumn) => TemplateResult;
19
+ export type GridColumnHeaderLitRenderer = (column: GridColumn) => LitRendererResult;
20
+ export type GridColumnFooterLitRenderer = (column: GridColumn) => LitRendererResult;
22
21
 
23
22
  declare abstract class AbstractGridColumnRendererDirective<R extends LitRenderer> extends LitRendererDirective<
24
23
  GridColumn,
@@ -3,12 +3,16 @@
3
3
  * Copyright (c) 2017 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import type { TemplateResult } from 'lit';
7
6
  import type { DirectiveResult } from 'lit/directive';
7
+ import type { LitRendererResult } from '@vaadin/lit-renderer';
8
8
  import { LitRendererDirective } from '@vaadin/lit-renderer';
9
9
  import type { Grid, GridItemModel } from '../vaadin-grid.js';
10
10
 
11
- export type GridRowDetailsLitRenderer<TItem> = (item: TItem, model: GridItemModel<TItem>, grid: Grid) => TemplateResult;
11
+ export type GridRowDetailsLitRenderer<TItem> = (
12
+ item: TItem,
13
+ model: GridItemModel<TItem>,
14
+ grid: Grid,
15
+ ) => LitRendererResult;
12
16
 
13
17
  export declare class GridRowDetailsRendererDirective<TItem> extends LitRendererDirective<
14
18
  Grid,
@@ -43,6 +43,17 @@ export declare class ColumnBaseMixinClass<TItem> {
43
43
  */
44
44
  frozenToEnd: boolean;
45
45
 
46
+ /**
47
+ * When true, the cells for this column will be rendered with the `role` attribute
48
+ * set as `rowheader`, instead of the `gridcell` role value used by default.
49
+ *
50
+ * When a column is set as row header, its cells will be announced by screen readers
51
+ * while navigating to help user identify the current row as uniquely as possible.
52
+ *
53
+ * @attr {boolean} row-header
54
+ */
55
+ rowHeader: boolean;
56
+
46
57
  /**
47
58
  * When set to true, the cells for this column are hidden.
48
59
  */
@@ -7,6 +7,7 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
7
7
  import { animationFrame } from '@vaadin/component-base/src/async.js';
8
8
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
9
9
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
10
+ import { get } from '@vaadin/component-base/src/path-utils.js';
10
11
  import { processTemplates } from '@vaadin/component-base/src/templates.js';
11
12
  import { updateCellState } from './vaadin-grid-helpers.js';
12
13
 
@@ -61,6 +62,21 @@ export const ColumnBaseMixin = (superClass) =>
61
62
  value: false,
62
63
  },
63
64
 
65
+ /**
66
+ * When true, the cells for this column will be rendered with the `role` attribute
67
+ * set as `rowheader`, instead of the `gridcell` role value used by default.
68
+ *
69
+ * When a column is set as row header, its cells will be announced by screen readers
70
+ * while navigating to help user identify the current row as uniquely as possible.
71
+ *
72
+ * @attr {boolean} row-header
73
+ * @type {boolean}
74
+ */
75
+ rowHeader: {
76
+ type: Boolean,
77
+ value: false,
78
+ },
79
+
64
80
  /**
65
81
  * When set to true, the cells for this column are hidden.
66
82
  */
@@ -222,6 +238,7 @@ export const ColumnBaseMixin = (superClass) =>
222
238
  '_resizableChanged(resizable, _headerCell)',
223
239
  '_reorderStatusChanged(_reorderStatus, _headerCell, _footerCell, _cells.*)',
224
240
  '_hiddenChanged(hidden, _headerCell, _footerCell, _cells.*)',
241
+ '_rowHeaderChanged(rowHeader, _cells.*)',
225
242
  ];
226
243
  }
227
244
 
@@ -407,6 +424,17 @@ export const ColumnBaseMixin = (superClass) =>
407
424
  }
408
425
  }
409
426
 
427
+ /** @private */
428
+ _rowHeaderChanged(rowHeader, cells) {
429
+ if (!cells.value) {
430
+ return;
431
+ }
432
+
433
+ cells.value.forEach((cell) => {
434
+ cell.setAttribute('role', rowHeader ? 'rowheader' : 'gridcell');
435
+ });
436
+ }
437
+
410
438
  /**
411
439
  * @param {string} path
412
440
  * @return {string}
@@ -686,7 +714,7 @@ export const ColumnBaseMixin = (superClass) =>
686
714
  return;
687
715
  }
688
716
 
689
- this.__setTextContent(root, this.get(this.path, item));
717
+ this.__setTextContent(root, get(this.path, item));
690
718
  }
691
719
 
692
720
  /**
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { timeOut } from '@vaadin/component-base/src/async.js';
7
7
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
8
+ import { get } from '@vaadin/component-base/src/path-utils.js';
8
9
  import { getBodyRowCells, updateCellsPart, updateState } from './vaadin-grid-helpers.js';
9
10
 
10
11
  /**
@@ -25,8 +26,8 @@ export const ItemCache = class ItemCache {
25
26
  this.parentItem = parentItem;
26
27
  /** @type {object} */
27
28
  this.itemCaches = {};
28
- /** @type {object} */
29
- this.items = {};
29
+ /** @type {object[]} */
30
+ this.items = [];
30
31
  /** @type {number} */
31
32
  this.effectiveSize = 0;
32
33
  /** @type {number} */
@@ -307,7 +308,7 @@ export const DataProviderMixin = (superClass) =>
307
308
  * @return {!GridItem | !unknown}
308
309
  */
309
310
  getItemId(item) {
310
- return this.itemIdPath ? this.get(this.itemIdPath, item) : item;
311
+ return this.itemIdPath ? get(this.itemIdPath, item) : item;
311
312
  }
312
313
 
313
314
  /**
@@ -6,20 +6,14 @@
6
6
  import { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js';
7
7
 
8
8
  /**
9
+ * Returns the cells of the given row, excluding the details cell.
10
+ *
9
11
  * @param {HTMLTableRowElement} row the table row
10
12
  * @return {HTMLTableCellElement[]} array of cells
11
13
  */
12
14
  export function getBodyRowCells(row) {
13
- if (row.parentElement && row.parentElement.localName === 'tbody') {
14
- // In case dealing with an attached body row, use the cells cached in the
15
- // column to make sure also any physically detached cells
16
- // (due to lazy column rendering) are included
17
- const grid = row.getRootNode().host;
18
- const columns = grid._getColumnsInOrder();
19
- return columns.flatMap((column) => (column._cells && column._cells.find((cell) => cell.__parentRow === row)) || []);
20
- }
21
- // In any other case, query the cells directly from the row
22
- return Array.from(row.querySelectorAll('[part~="cell"]:not([part~="details-cell"])'));
15
+ // If available, return the cached cells. Otherwise, query the cells directly from the row.
16
+ return row.__cells || Array.from(row.querySelectorAll('[part~="cell"]:not([part~="details-cell"])'));
23
17
  }
24
18
 
25
19
  /**
@@ -39,7 +33,10 @@ export function iterateChildren(container, callback) {
39
33
  * @param {Function} callback function to call on each cell
40
34
  */
41
35
  export function iterateRowCells(row, callback) {
42
- [...getBodyRowCells(row), ...row.querySelectorAll('[part~="details-cell"]')].forEach(callback);
36
+ getBodyRowCells(row).forEach(callback);
37
+ if (row.__detailsCell) {
38
+ callback(row.__detailsCell);
39
+ }
43
40
  }
44
41
 
45
42
  /**
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
7
7
  import { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js';
8
+ import { get } from '@vaadin/component-base/src/path-utils.js';
8
9
 
9
10
  /**
10
11
  * @polymerMixin
@@ -266,7 +267,7 @@ export const KeyboardNavigationMixin = (superClass) =>
266
267
  __isRowExpandable(row) {
267
268
  if (this.itemHasChildrenPath) {
268
269
  const item = row._item;
269
- return item && this.get(this.itemHasChildrenPath, item) && !this._isExpanded(item);
270
+ return item && get(this.itemHasChildrenPath, item) && !this._isExpanded(item);
270
271
  }
271
272
  }
272
273
 
@@ -3,6 +3,7 @@
3
3
  * Copyright (c) 2016 - 2023 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';
6
7
  import { animationFrame, microTask, timeOut } from '@vaadin/component-base/src/async.js';
7
8
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
8
9
  import { getNormalizedScrollLeft } from '@vaadin/component-base/src/dir-utils.js';
@@ -136,6 +137,19 @@ export const ScrollMixin = (superClass) =>
136
137
  _onResize() {
137
138
  this._updateOverflow();
138
139
  this.__updateHorizontalScrollPosition();
140
+
141
+ // For Firefox, manually restore last scroll position when grid becomes
142
+ // visible again. This solves an issue where switching visibility of two
143
+ // grids causes Firefox trying to synchronize the scroll positions between
144
+ // the two grid's table elements.
145
+ // See https://github.com/vaadin/web-components/issues/5796
146
+ if (this._firefox) {
147
+ const isVisible = !isElementHidden(this);
148
+ if (isVisible && this.__previousVisible === false) {
149
+ this._scrollTop = this.__memorizedScrollTop || 0;
150
+ }
151
+ this.__previousVisible = isVisible;
152
+ }
139
153
  }
140
154
 
141
155
  /**
@@ -208,6 +222,14 @@ export const ScrollMixin = (superClass) =>
208
222
  }
209
223
  },
210
224
  );
225
+
226
+ // Memorize last scroll position in Firefox
227
+ if (this._firefox) {
228
+ const isVisible = !isElementHidden(this);
229
+ if (isVisible && this.__previousVisible !== false) {
230
+ this.__memorizedScrollTop = this._scrollTop;
231
+ }
232
+ }
211
233
  }
212
234
 
213
235
  /** @private */
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+
8
+ export declare function GridSelectionColumnBaseMixin<TItem, T extends Constructor<HTMLElement>>(
9
+ base: T,
10
+ ): Constructor<GridSelectionColumnBaseMixinClass<TItem>> & T;
11
+
12
+ /**
13
+ * A mixin that provides basic functionality for the
14
+ * `<vaadin-grid-selection-column>`. This includes properties, cell rendering,
15
+ * and overridable methods for handling changes to the selection state.
16
+ *
17
+ * **NOTE**: This mixin is re-used by the Flow component, and as such must not
18
+ * implement any selection state updates for the column element or the grid.
19
+ * Web component-specific selection state updates must be implemented in the
20
+ * `<vaadin-grid-selection-column>` itself, by overriding the protected methods
21
+ * provided by this mixin.
22
+ *
23
+ * @polymerMixin
24
+ */
25
+ export declare class GridSelectionColumnBaseMixinClass<TItem> {
26
+ /**
27
+ * When true, all the items are selected.
28
+ * @attr {boolean} select-all
29
+ */
30
+ selectAll: boolean;
31
+
32
+ /**
33
+ * When true, the active gets automatically selected.
34
+ * @attr {boolean} auto-select
35
+ */
36
+ autoSelect: boolean;
37
+
38
+ /**
39
+ * When true, rows can be selected by dragging over the selection column.
40
+ * @attr {boolean} drag-select
41
+ */
42
+ dragSelect: boolean;
43
+
44
+ /**
45
+ * Override to handle the user selecting all items.
46
+ */
47
+ protected _selectAll(): void;
48
+
49
+ /**
50
+ * Override to handle the user deselecting all items.
51
+ */
52
+ protected _deselectAll(): void;
53
+
54
+ /**
55
+ * Override to handle the user selecting an item.
56
+ */
57
+ protected _selectItem(item: TItem): void;
58
+
59
+ /**
60
+ * Override to handle the user deselecting an item.
61
+ */
62
+ protected _deselectItem(item: TItem): void;
63
+ }