@vaadin/vaadin-grid 22.0.0-alpha6 → 22.0.0-beta1

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 (84) hide show
  1. package/package.json +24 -34
  2. package/src/vaadin-grid-column-group.d.ts +14 -57
  3. package/src/vaadin-grid-column-group.js +4 -311
  4. package/src/vaadin-grid-column.d.ts +14 -142
  5. package/src/vaadin-grid-column.js +4 -759
  6. package/src/vaadin-grid-filter-column.d.ts +14 -30
  7. package/src/vaadin-grid-filter-column.js +4 -111
  8. package/src/vaadin-grid-filter.d.ts +11 -60
  9. package/src/vaadin-grid-filter.js +4 -116
  10. package/src/vaadin-grid-selection-column.d.ts +12 -75
  11. package/src/vaadin-grid-selection-column.js +4 -276
  12. package/src/vaadin-grid-sort-column.d.ts +12 -56
  13. package/src/vaadin-grid-sort-column.js +4 -109
  14. package/src/vaadin-grid-sorter.d.ts +11 -82
  15. package/src/vaadin-grid-sorter.js +4 -221
  16. package/src/vaadin-grid-tree-column.d.ts +14 -31
  17. package/src/vaadin-grid-tree-column.js +4 -110
  18. package/src/vaadin-grid-tree-toggle.d.ts +11 -91
  19. package/src/vaadin-grid-tree-toggle.js +4 -196
  20. package/src/vaadin-grid.d.ts +10 -422
  21. package/src/vaadin-grid.js +4 -1026
  22. package/theme/lumo/vaadin-grid-column-group.js +1 -1
  23. package/theme/lumo/vaadin-grid-column.js +1 -1
  24. package/theme/lumo/vaadin-grid-filter-column.js +1 -2
  25. package/theme/lumo/vaadin-grid-filter.js +1 -2
  26. package/theme/lumo/vaadin-grid-selection-column.js +1 -2
  27. package/theme/lumo/vaadin-grid-sort-column.js +1 -2
  28. package/theme/lumo/vaadin-grid-sorter.js +1 -2
  29. package/theme/lumo/vaadin-grid-tree-column.js +1 -2
  30. package/theme/lumo/vaadin-grid-tree-toggle.js +1 -2
  31. package/theme/lumo/vaadin-grid.js +1 -9
  32. package/theme/material/vaadin-grid-column-group.js +1 -1
  33. package/theme/material/vaadin-grid-column.js +1 -1
  34. package/theme/material/vaadin-grid-filter-column.js +1 -2
  35. package/theme/material/vaadin-grid-filter.js +1 -2
  36. package/theme/material/vaadin-grid-selection-column.js +1 -2
  37. package/theme/material/vaadin-grid-sort-column.js +1 -2
  38. package/theme/material/vaadin-grid-sorter.js +1 -2
  39. package/theme/material/vaadin-grid-tree-column.js +1 -2
  40. package/theme/material/vaadin-grid-tree-toggle.js +1 -2
  41. package/theme/material/vaadin-grid.js +1 -2
  42. package/vaadin-grid.d.ts +0 -1
  43. package/src/array-data-provider.js +0 -145
  44. package/src/interfaces.d.ts +0 -78
  45. package/src/vaadin-grid-a11y-mixin.d.ts +0 -27
  46. package/src/vaadin-grid-a11y-mixin.js +0 -158
  47. package/src/vaadin-grid-active-item-mixin.d.ts +0 -28
  48. package/src/vaadin-grid-active-item-mixin.js +0 -117
  49. package/src/vaadin-grid-array-data-provider-mixin.d.ts +0 -20
  50. package/src/vaadin-grid-array-data-provider-mixin.js +0 -75
  51. package/src/vaadin-grid-column-reordering-mixin.d.ts +0 -47
  52. package/src/vaadin-grid-column-reordering-mixin.js +0 -387
  53. package/src/vaadin-grid-column-resizing-mixin.d.ts +0 -11
  54. package/src/vaadin-grid-column-resizing-mixin.js +0 -111
  55. package/src/vaadin-grid-data-provider-mixin.d.ts +0 -126
  56. package/src/vaadin-grid-data-provider-mixin.js +0 -520
  57. package/src/vaadin-grid-drag-and-drop-mixin.d.ts +0 -73
  58. package/src/vaadin-grid-drag-and-drop-mixin.js +0 -435
  59. package/src/vaadin-grid-dynamic-columns-mixin.d.ts +0 -27
  60. package/src/vaadin-grid-dynamic-columns-mixin.js +0 -180
  61. package/src/vaadin-grid-event-context-mixin.d.ts +0 -33
  62. package/src/vaadin-grid-event-context-mixin.js +0 -57
  63. package/src/vaadin-grid-filter-mixin.d.ts +0 -13
  64. package/src/vaadin-grid-filter-mixin.js +0 -76
  65. package/src/vaadin-grid-helpers.js +0 -23
  66. package/src/vaadin-grid-keyboard-navigation-mixin.d.ts +0 -31
  67. package/src/vaadin-grid-keyboard-navigation-mixin.js +0 -891
  68. package/src/vaadin-grid-row-details-mixin.d.ts +0 -54
  69. package/src/vaadin-grid-row-details-mixin.js +0 -200
  70. package/src/vaadin-grid-scroll-mixin.d.ts +0 -22
  71. package/src/vaadin-grid-scroll-mixin.js +0 -202
  72. package/src/vaadin-grid-selection-mixin.d.ts +0 -39
  73. package/src/vaadin-grid-selection-mixin.js +0 -93
  74. package/src/vaadin-grid-sort-mixin.d.ts +0 -21
  75. package/src/vaadin-grid-sort-mixin.js +0 -139
  76. package/src/vaadin-grid-styles.js +0 -297
  77. package/src/vaadin-grid-styling-mixin.d.ts +0 -37
  78. package/src/vaadin-grid-styling-mixin.js +0 -71
  79. package/theme/lumo/vaadin-grid-sorter-styles.js +0 -54
  80. package/theme/lumo/vaadin-grid-styles.js +0 -380
  81. package/theme/lumo/vaadin-grid-tree-toggle-styles.js +0 -112
  82. package/theme/material/vaadin-grid-sorter-styles.js +0 -72
  83. package/theme/material/vaadin-grid-styles.js +0 -252
  84. package/theme/material/vaadin-grid-tree-toggle-styles.js +0 -42
@@ -1 +1 @@
1
- import '../../src/vaadin-grid-column-group.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-column-group.js';
@@ -1 +1 @@
1
- import '../../src/vaadin-grid-column.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-column.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-filter.js';
2
- import '../../src/vaadin-grid-filter-column.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-filter-column.js';
@@ -1,2 +1 @@
1
- import '@vaadin/vaadin-text-field/theme/lumo/vaadin-text-field.js';
2
- import '../../src/vaadin-grid-filter.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-filter.js';
@@ -1,2 +1 @@
1
- import '@vaadin/checkbox/theme/lumo/vaadin-checkbox.js';
2
- import '../../src/vaadin-grid-selection-column.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-selection-column.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-sorter.js';
2
- import '../../src/vaadin-grid-sort-column.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-sort-column.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-sorter-styles.js';
2
- import '../../src/vaadin-grid-sorter.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-sorter.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-tree-toggle.js';
2
- import '../../src/vaadin-grid-tree-column.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-tree-column.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-tree-toggle-styles.js';
2
- import '../../src/vaadin-grid-tree-toggle.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid-tree-toggle.js';
@@ -1,9 +1 @@
1
- import '@vaadin/vaadin-lumo-styles/color.js';
2
- import '@vaadin/vaadin-lumo-styles/font-icons.js';
3
- import '@vaadin/vaadin-lumo-styles/sizing.js';
4
- import '@vaadin/vaadin-lumo-styles/spacing.js';
5
- import '@vaadin/vaadin-lumo-styles/style.js';
6
- import '@vaadin/vaadin-lumo-styles/typography.js';
7
- import '@vaadin/checkbox/theme/lumo/vaadin-checkbox.js';
8
- import './vaadin-grid-styles.js';
9
- import '../../src/vaadin-grid.js';
1
+ import '@vaadin/grid/theme/lumo/vaadin-grid.js';
@@ -1 +1 @@
1
- import '../../src/vaadin-grid-column-group.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-column-group.js';
@@ -1 +1 @@
1
- import '../../src/vaadin-grid-column.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-column.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-filter.js';
2
- import '../../src/vaadin-grid-filter-column.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-filter-column.js';
@@ -1,2 +1 @@
1
- import '@vaadin/vaadin-text-field/theme/material/vaadin-text-field.js';
2
- import '../../src/vaadin-grid-filter.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-filter.js';
@@ -1,2 +1 @@
1
- import '@vaadin/checkbox/theme/material/vaadin-checkbox.js';
2
- import '../../src/vaadin-grid-selection-column.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-selection-column.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-sorter.js';
2
- import '../../src/vaadin-grid-sort-column.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-sort-column.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-sorter-styles.js';
2
- import '../../src/vaadin-grid-sorter.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-sorter.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-tree-toggle.js';
2
- import '../../src/vaadin-grid-tree-column.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-tree-column.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-tree-toggle-styles.js';
2
- import '../../src/vaadin-grid-tree-toggle.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid-tree-toggle.js';
@@ -1,2 +1 @@
1
- import './vaadin-grid-styles.js';
2
- import '../../src/vaadin-grid.js';
1
+ import '@vaadin/grid/theme/material/vaadin-grid.js';
package/vaadin-grid.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './src/vaadin-grid.js';
2
2
  export * from './src/vaadin-grid-column.js';
3
- export * from './src/interfaces';
@@ -1,145 +0,0 @@
1
- /**
2
- * Returns a sub-property of an object
3
- *
4
- * @param {string} path dot-separated path to the sub property
5
- * @param {*} object
6
- * @returns {*}
7
- */
8
- function get(path, object) {
9
- return path.split('.').reduce((obj, property) => obj[property], object);
10
- }
11
-
12
- /**
13
- * Check array of filters/sorters for paths validity, console.warn invalid items
14
- * @param {!Array<!GridFilter | !GridSorter>} arrayToCheck The array of filters/sorters to check
15
- * @param {string} action The name of action to include in warning (filtering, sorting)
16
- * @param {!Array<!GridItem>} items
17
- */
18
- function checkPaths(arrayToCheck, action, items) {
19
- if (items.length === 0) {
20
- return false;
21
- }
22
-
23
- let result = true;
24
-
25
- for (let i in arrayToCheck) {
26
- const path = arrayToCheck[i].path;
27
-
28
- // skip simple paths
29
- if (!path || path.indexOf('.') === -1) {
30
- continue;
31
- }
32
-
33
- const parentProperty = path.replace(/\.[^.]*$/, ''); // a.b.c -> a.b
34
- if (get(parentProperty, items[0]) === undefined) {
35
- console.warn(`Path "${path}" used for ${action} does not exist in all of the items, ${action} is disabled.`);
36
- result = false;
37
- }
38
- }
39
-
40
- return result;
41
- }
42
-
43
- /**
44
- * Sorts the given array of items based on the sorting rules and returns the result.
45
- *
46
- * @param {Array<any>} items
47
- * @param {Array<GridSorter>} items
48
- * @return {Array<any>}
49
- */
50
- function multiSort(items, sortOrders) {
51
- return items.sort((a, b) => {
52
- return sortOrders
53
- .map((sortOrder) => {
54
- if (sortOrder.direction === 'asc') {
55
- return compare(get(sortOrder.path, a), get(sortOrder.path, b));
56
- } else if (sortOrder.direction === 'desc') {
57
- return compare(get(sortOrder.path, b), get(sortOrder.path, a));
58
- }
59
- return 0;
60
- })
61
- .reduce((p, n) => {
62
- return p !== 0 ? p : n;
63
- }, 0);
64
- });
65
- }
66
-
67
- /**
68
- * @param {unknown} value
69
- * @return {string}
70
- */
71
- function normalizeEmptyValue(value) {
72
- if ([undefined, null].indexOf(value) >= 0) {
73
- return '';
74
- } else if (isNaN(value)) {
75
- return value.toString();
76
- } else {
77
- return value;
78
- }
79
- }
80
-
81
- /**
82
- * @param {unknown} a
83
- * @param {unknown} b
84
- * @return {number}
85
- */
86
- function compare(a, b) {
87
- a = normalizeEmptyValue(a);
88
- b = normalizeEmptyValue(b);
89
-
90
- if (a < b) {
91
- return -1;
92
- }
93
- if (a > b) {
94
- return 1;
95
- }
96
- return 0;
97
- }
98
-
99
- /**
100
- * @param {!Array<!GridItem>} items
101
- * @return {!Array<!GridItem>}
102
- */
103
- function filter(items, filters) {
104
- return items.filter((item) => {
105
- return filters.every((filter) => {
106
- const value = normalizeEmptyValue(get(filter.path, item));
107
- const filterValueLowercase = normalizeEmptyValue(filter.value).toString().toLowerCase();
108
- return value.toString().toLowerCase().includes(filterValueLowercase);
109
- });
110
- });
111
- }
112
-
113
- /**
114
- * WARNING: This API is still intended for internal purposes only and
115
- * may change any time.
116
- *
117
- * Creates a new grid compatible data provider that serves the items
118
- * from the given array as data when requested by the grid.
119
- *
120
- * @param {Array<any>} items
121
- * @return {GridDataProvider<any>}
122
- */
123
- export const createArrayDataProvider = (allItems) => {
124
- return (params, callback) => {
125
- let items = allItems ? [...allItems] : [];
126
-
127
- if (params.filters && checkPaths(params.filters, 'filtering', items)) {
128
- items = filter(items, params.filters);
129
- }
130
-
131
- if (
132
- Array.isArray(params.sortOrders) &&
133
- params.sortOrders.length &&
134
- checkPaths(params.sortOrders, 'sorting', items)
135
- ) {
136
- items = multiSort(items, params.sortOrders);
137
- }
138
-
139
- const count = Math.min(items.length, params.pageSize);
140
- const start = params.page * count;
141
- const end = start + count;
142
- const slice = items.slice(start, end);
143
- callback(slice, items.length);
144
- };
145
- };
@@ -1,78 +0,0 @@
1
- import { GridColumnElement } from './vaadin-grid-column.js';
2
- import { GridElement } from './vaadin-grid.js';
3
-
4
- export type GridBodyRenderer<TItem> = (
5
- root: HTMLElement,
6
- column: GridColumnElement<TItem>,
7
- model: GridItemModel<TItem>
8
- ) => void;
9
-
10
- export type GridCellClassNameGenerator<TItem> = (
11
- column: GridColumnElement<TItem>,
12
- model: GridItemModel<TItem>
13
- ) => string;
14
-
15
- export type GridColumnTextAlign = 'start' | 'center' | 'end' | null;
16
-
17
- export type GridDataProviderCallback<TItem> = (items: Array<TItem>, size?: number) => void;
18
-
19
- export type GridDataProviderParams<TItem> = {
20
- page: number;
21
- pageSize: number;
22
- filters: Array<GridFilter>;
23
- sortOrders: Array<GridSorter>;
24
- parentItem?: TItem;
25
- };
26
-
27
- export type GridDataProvider<TItem> = (
28
- params: GridDataProviderParams<TItem>,
29
- callback: GridDataProviderCallback<TItem>
30
- ) => void;
31
-
32
- export type GridDragAndDropFilter<TItem> = (model: GridItemModel<TItem>) => boolean;
33
-
34
- export type GridDropLocation = 'above' | 'on-top' | 'below' | 'empty';
35
-
36
- export type GridDropMode = 'between' | 'on-top' | 'on-top-or-between' | 'on-grid';
37
-
38
- export interface GridFilter {
39
- path: string;
40
- value: string;
41
- }
42
-
43
- export interface GridEventContext<TItem> {
44
- section?: 'body' | 'header' | 'footer' | 'details';
45
- item?: TItem;
46
- column?: GridColumnElement<TItem>;
47
- index?: number;
48
- selected?: boolean;
49
- detailsOpened?: boolean;
50
- expanded?: boolean;
51
- level?: number;
52
- }
53
-
54
- export type GridHeaderFooterRenderer<TItem> = (root: HTMLElement, column: GridColumnElement<TItem>) => void;
55
-
56
- export type GridDefaultItem = any;
57
-
58
- export interface GridItemModel<TItem> {
59
- index: number;
60
- item: TItem;
61
- selected?: boolean;
62
- expanded?: boolean;
63
- level?: number;
64
- detailsOpened?: boolean;
65
- }
66
-
67
- export type GridRowDetailsRenderer<TItem> = (
68
- root: HTMLElement,
69
- grid?: GridElement<TItem>,
70
- model?: GridItemModel<TItem>
71
- ) => void;
72
-
73
- export type GridSorterDirection = 'asc' | 'desc' | null;
74
-
75
- export interface GridSorter {
76
- path: string;
77
- direction: GridSorterDirection;
78
- }
@@ -1,27 +0,0 @@
1
- declare function A11yMixin<T extends new (...args: any[]) => {}>(base: T): T & A11yMixinConstructor;
2
-
3
- interface A11yMixinConstructor {
4
- new (...args: any[]): A11yMixin;
5
- }
6
-
7
- interface A11yMixin {
8
- _a11yUpdateHeaderRows(): void;
9
-
10
- _a11yUpdateFooterRows(): void;
11
-
12
- _a11yUpdateRowRowindex(row: HTMLElement, index: number): void;
13
-
14
- _a11yUpdateRowSelected(row: HTMLElement, selected: boolean): void;
15
-
16
- _a11yUpdateRowLevel(row: HTMLElement, level: number): void;
17
-
18
- _a11yUpdateRowDetailsOpened(row: HTMLElement, detailsOpened: boolean): void;
19
-
20
- _a11ySetRowDetailsCell(row: HTMLElement, detailsCell: HTMLElement): void;
21
-
22
- _a11yUpdateCellColspan(cell: any, colspan: number): void;
23
-
24
- _a11yUpdateSorters(): void;
25
- }
26
-
27
- export { A11yMixin, A11yMixinConstructor };
@@ -1,158 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * @polymerMixin
9
- */
10
- export const A11yMixin = (superClass) =>
11
- class A11yMixin extends superClass {
12
- static get observers() {
13
- return ['_a11yUpdateGridSize(size, _columnTree, _columnTree.*)'];
14
- }
15
-
16
- /** @private */
17
- _a11yGetHeaderRowCount(_columnTree) {
18
- return _columnTree.filter((level) => level.some((col) => col.headerRenderer || col.path || col.header)).length;
19
- }
20
-
21
- /** @private */
22
- _a11yGetFooterRowCount(_columnTree) {
23
- return _columnTree.filter((level) => level.some((col) => col.headerRenderer)).length;
24
- }
25
-
26
- /** @private */
27
- _a11yUpdateGridSize(size, _columnTree) {
28
- if (size === undefined || _columnTree === undefined) {
29
- return;
30
- }
31
-
32
- const bodyColumns = _columnTree[_columnTree.length - 1];
33
- this.$.table.setAttribute(
34
- 'aria-rowcount',
35
- size + this._a11yGetHeaderRowCount(_columnTree) + this._a11yGetFooterRowCount(_columnTree)
36
- );
37
- this.$.table.setAttribute('aria-colcount', (bodyColumns && bodyColumns.length) || 0);
38
-
39
- this._a11yUpdateHeaderRows();
40
- this._a11yUpdateFooterRows();
41
- }
42
-
43
- /** @protected */
44
- _a11yUpdateHeaderRows() {
45
- Array.from(this.$.header.children).forEach((headerRow, index) =>
46
- headerRow.setAttribute('aria-rowindex', index + 1)
47
- );
48
- }
49
-
50
- /** @protected */
51
- _a11yUpdateFooterRows() {
52
- Array.from(this.$.footer.children).forEach((footerRow, index) =>
53
- footerRow.setAttribute('aria-rowindex', this._a11yGetHeaderRowCount(this._columnTree) + this.size + index + 1)
54
- );
55
- }
56
-
57
- /**
58
- * @param {!HTMLElement} row
59
- * @param {number} index
60
- * @protected
61
- */
62
- _a11yUpdateRowRowindex(row, index) {
63
- row.setAttribute('aria-rowindex', index + this._a11yGetHeaderRowCount(this._columnTree) + 1);
64
- }
65
-
66
- /**
67
- * @param {!HTMLElement} row
68
- * @param {boolean} selected
69
- * @protected
70
- */
71
- _a11yUpdateRowSelected(row, selected) {
72
- // Jaws reads selection only for rows, NVDA only for cells
73
- row.setAttribute('aria-selected', Boolean(selected));
74
- Array.from(row.children).forEach((cell) => cell.setAttribute('aria-selected', Boolean(selected)));
75
- }
76
-
77
- /**
78
- * @param {!HTMLElement} row
79
- * @protected
80
- */
81
- _a11yUpdateRowExpanded(row) {
82
- if (this.__isRowExpandable(row)) {
83
- row.setAttribute('aria-expanded', 'false');
84
- } else if (this.__isRowCollapsible(row)) {
85
- row.setAttribute('aria-expanded', 'true');
86
- } else {
87
- row.removeAttribute('aria-expanded');
88
- }
89
- }
90
-
91
- /**
92
- * @param {!HTMLElement} row
93
- * @param {number} level
94
- * @protected
95
- */
96
- _a11yUpdateRowLevel(row, level) {
97
- row.setAttribute('aria-level', level + 1);
98
- }
99
-
100
- /**
101
- * @param {!HTMLElement} row
102
- * @param {boolean} detailsOpened
103
- * @protected
104
- */
105
- _a11yUpdateRowDetailsOpened(row, detailsOpened) {
106
- const detailsCell = row.querySelector('[part~=details-cell]');
107
-
108
- Array.from(row.children).forEach((cell) => {
109
- if (detailsCell) {
110
- cell.setAttribute('aria-expanded', detailsOpened);
111
- } else {
112
- cell.removeAttribute('aria-expanded');
113
- }
114
- });
115
- }
116
-
117
- /**
118
- * @param {!HTMLElement} row
119
- * @param {!HTMLElement} detailsCell
120
- * @protected
121
- */
122
- _a11ySetRowDetailsCell(row, detailsCell) {
123
- Array.from(row.children).forEach((cell) => {
124
- if (cell !== detailsCell) {
125
- cell.setAttribute('aria-controls', detailsCell.id);
126
- }
127
- });
128
- }
129
-
130
- /**
131
- * @param {!HTMLElement} row
132
- * @param {number} colspan
133
- * @protected
134
- */
135
- _a11yUpdateCellColspan(cell, colspan) {
136
- cell.setAttribute('aria-colspan', Number(colspan));
137
- }
138
-
139
- /** @protected */
140
- _a11yUpdateSorters() {
141
- Array.from(this.querySelectorAll('vaadin-grid-sorter')).forEach((sorter) => {
142
- let cellContent = sorter.parentNode;
143
- while (cellContent && cellContent.localName !== 'vaadin-grid-cell-content') {
144
- cellContent = cellContent.parentNode;
145
- }
146
- if (cellContent && cellContent.assignedSlot) {
147
- const cell = cellContent.assignedSlot.parentNode;
148
- cell.setAttribute(
149
- 'aria-sort',
150
- {
151
- asc: 'ascending',
152
- desc: 'descending'
153
- }[String(sorter.direction)] || 'none'
154
- );
155
- }
156
- });
157
- }
158
- };
@@ -1,28 +0,0 @@
1
- declare function ActiveItemMixin<TItem, T extends new (...args: any[]) => {}>(
2
- base: T
3
- ): T & ActiveItemMixinConstructor<TItem>;
4
-
5
- interface ActiveItemMixinConstructor<TItem> {
6
- new (...args: any[]): ActiveItemMixin<TItem>;
7
- }
8
-
9
- interface ActiveItemMixin<TItem> {
10
- /**
11
- * The item user has last interacted with. Turns to `null` after user deactivates
12
- * the item by re-interacting with the currently active item.
13
- */
14
- activeItem: TItem | null;
15
-
16
- /**
17
- * We need to listen to click instead of tap because on mobile safari, the
18
- * document.activeElement has not been updated (focus has not been shifted)
19
- * yet at the point when tap event is being executed.
20
- */
21
- _onClick(e: MouseEvent): void;
22
-
23
- _isFocusable(target: Element): boolean;
24
- }
25
-
26
- declare function isFocusable(target: Element): boolean;
27
-
28
- export { ActiveItemMixin, ActiveItemMixinConstructor, isFocusable };
@@ -1,117 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * @polymerMixin
9
- */
10
- export const ActiveItemMixin = (superClass) =>
11
- class ActiveItemMixin extends superClass {
12
- static get properties() {
13
- return {
14
- /**
15
- * The item user has last interacted with. Turns to `null` after user deactivates
16
- * the item by re-interacting with the currently active item.
17
- * @type {GridItem}
18
- */
19
- activeItem: {
20
- type: Object,
21
- notify: true,
22
- value: null
23
- }
24
- };
25
- }
26
-
27
- ready() {
28
- super.ready();
29
-
30
- this.$.scroller.addEventListener('click', this._onClick.bind(this));
31
- this.addEventListener('cell-activate', this._activateItem.bind(this));
32
- this.addEventListener('row-activate', this._activateItem.bind(this));
33
- }
34
-
35
- /** @private */
36
- _activateItem(e) {
37
- const model = e.detail.model;
38
- const clickedItem = model ? model.item : null;
39
-
40
- if (clickedItem) {
41
- this.activeItem = !this._itemsEqual(this.activeItem, clickedItem) ? clickedItem : null;
42
- }
43
- }
44
-
45
- /**
46
- * We need to listen to click instead of tap because on mobile safari, the
47
- * document.activeElement has not been updated (focus has not been shifted)
48
- * yet at the point when tap event is being executed.
49
- * @param {!MouseEvent} e
50
- * @protected
51
- */
52
- _onClick(e) {
53
- if (e.defaultPrevented) {
54
- // Something has handled this click already, e. g., <vaadin-grid-sorter>
55
- return;
56
- }
57
-
58
- const path = e.composedPath();
59
- const cell = path[path.indexOf(this.$.table) - 3];
60
- if (!cell || cell.getAttribute('part').indexOf('details-cell') > -1) {
61
- return;
62
- }
63
- const cellContent = cell._content;
64
-
65
- const activeElement = this.getRootNode().activeElement;
66
- const cellContentHasFocus = cellContent.contains(activeElement);
67
- if (!cellContentHasFocus && !this._isFocusable(e.target)) {
68
- this.dispatchEvent(
69
- new CustomEvent('cell-activate', {
70
- detail: {
71
- model: this.__getRowModel(cell.parentElement)
72
- }
73
- })
74
- );
75
- }
76
- }
77
-
78
- /**
79
- * @param {!Element} target
80
- * @return {boolean}
81
- * @protected
82
- */
83
- _isFocusable(target) {
84
- return isFocusable(target);
85
- }
86
-
87
- /**
88
- * Fired when the `activeItem` property changes.
89
- *
90
- * @event active-item-changed
91
- */
92
-
93
- /**
94
- * Fired when the cell is activated with click or keyboard.
95
- *
96
- * @event cell-activate
97
- */
98
- };
99
-
100
- /**
101
- * @param {!Element} target
102
- * @return {boolean}
103
- * @protected
104
- */
105
- export const isFocusable = (target) => {
106
- if (!target.parentNode) {
107
- return false;
108
- }
109
- const focusables = Array.from(
110
- target.parentNode.querySelectorAll(
111
- '[tabindex], button, input, select, textarea, object, iframe, label, a[href], area[href]'
112
- )
113
- ).filter((element) => element.getAttribute('part') !== 'cell body-cell');
114
-
115
- const isFocusableElement = focusables.indexOf(target) !== -1;
116
- return !target.disabled && isFocusableElement;
117
- };