@vaadin/grid 24.3.0-alpha1 → 24.3.0-alpha3

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 (46) hide show
  1. package/package.json +10 -10
  2. package/src/vaadin-grid-array-data-provider-mixin.js +1 -1
  3. package/src/vaadin-grid-column-group-mixin.d.ts +20 -0
  4. package/src/vaadin-grid-column-group-mixin.js +369 -0
  5. package/src/vaadin-grid-column-group.d.ts +4 -14
  6. package/src/vaadin-grid-column-group.js +5 -355
  7. package/src/vaadin-grid-column-mixin.d.ts +170 -0
  8. package/src/vaadin-grid-column-mixin.js +922 -0
  9. package/src/vaadin-grid-column.d.ts +11 -138
  10. package/src/vaadin-grid-column.js +3 -876
  11. package/src/vaadin-grid-data-provider-mixin.d.ts +6 -5
  12. package/src/vaadin-grid-data-provider-mixin.js +38 -7
  13. package/src/vaadin-grid-drag-and-drop-mixin.js +1 -1
  14. package/src/vaadin-grid-filter-column-mixin.d.ts +22 -0
  15. package/src/vaadin-grid-filter-column-mixin.js +100 -0
  16. package/src/vaadin-grid-filter-column.d.ts +9 -11
  17. package/src/vaadin-grid-filter-column.js +3 -90
  18. package/src/vaadin-grid-filter-element-mixin.d.ts +34 -0
  19. package/src/vaadin-grid-filter-element-mixin.js +99 -0
  20. package/src/vaadin-grid-filter.d.ts +4 -21
  21. package/src/vaadin-grid-filter.js +5 -84
  22. package/src/vaadin-grid-keyboard-navigation-mixin.js +16 -3
  23. package/src/vaadin-grid-mixin.js +11 -8
  24. package/src/vaadin-grid-scroll-mixin.js +1 -1
  25. package/src/vaadin-grid-selection-column-mixin.d.ts +24 -0
  26. package/src/vaadin-grid-selection-column-mixin.js +194 -0
  27. package/src/vaadin-grid-selection-column.d.ts +13 -17
  28. package/src/vaadin-grid-selection-column.js +4 -186
  29. package/src/vaadin-grid-sort-column-mixin.d.ts +36 -0
  30. package/src/vaadin-grid-sort-column-mixin.js +97 -0
  31. package/src/vaadin-grid-sort-column.d.ts +8 -26
  32. package/src/vaadin-grid-sort-column.js +3 -87
  33. package/src/vaadin-grid-sorter-mixin.d.ts +44 -0
  34. package/src/vaadin-grid-sorter-mixin.js +198 -0
  35. package/src/vaadin-grid-sorter.d.ts +3 -32
  36. package/src/vaadin-grid-sorter.js +5 -181
  37. package/src/vaadin-grid-tree-column-mixin.d.ts +18 -0
  38. package/src/vaadin-grid-tree-column-mixin.js +92 -0
  39. package/src/vaadin-grid-tree-column.d.ts +9 -7
  40. package/src/vaadin-grid-tree-column.js +3 -82
  41. package/src/vaadin-grid-tree-toggle-mixin.d.ts +39 -0
  42. package/src/vaadin-grid-tree-toggle-mixin.js +151 -0
  43. package/src/vaadin-grid-tree-toggle.d.ts +4 -27
  44. package/src/vaadin-grid-tree-toggle.js +9 -141
  45. package/web-types.json +331 -126
  46. package/web-types.lit.json +114 -58
@@ -6,7 +6,7 @@
6
6
  import '@vaadin/checkbox/src/vaadin-checkbox.js';
7
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { GridColumn } from './vaadin-grid-column.js';
9
- import { GridSelectionColumnBaseMixin } from './vaadin-grid-selection-column-base-mixin.js';
9
+ import { GridSelectionColumnMixin } from './vaadin-grid-selection-column-mixin.js';
10
10
 
11
11
  /**
12
12
  * `<vaadin-grid-selection-column>` is a helper element for the `<vaadin-grid>`
@@ -31,196 +31,14 @@ import { GridSelectionColumnBaseMixin } from './vaadin-grid-selection-column-bas
31
31
  * __The default content can also be overridden__
32
32
  *
33
33
  * @customElement
34
- * @extends GridColumn
35
- * @mixes GridSelectionColumnBaseMixin
36
34
  * @fires {CustomEvent} select-all-changed - Fired when the `selectAll` property changes.
35
+ * @extends GridColumn
36
+ * @mixes GridSelectionColumnMixin
37
37
  */
38
- class GridSelectionColumn extends GridSelectionColumnBaseMixin(GridColumn) {
38
+ class GridSelectionColumn extends GridSelectionColumnMixin(GridColumn) {
39
39
  static get is() {
40
40
  return 'vaadin-grid-selection-column';
41
41
  }
42
-
43
- static get properties() {
44
- return {
45
- /**
46
- * The previous state of activeItem. When activeItem turns to `null`,
47
- * previousActiveItem will have an Object with just unselected activeItem
48
- * @private
49
- */
50
- __previousActiveItem: Object,
51
- };
52
- }
53
-
54
- static get observers() {
55
- return ['__onSelectAllChanged(selectAll)'];
56
- }
57
-
58
- constructor() {
59
- super();
60
-
61
- this.__boundOnActiveItemChanged = this.__onActiveItemChanged.bind(this);
62
- this.__boundOnDataProviderChanged = this.__onDataProviderChanged.bind(this);
63
- this.__boundOnSelectedItemsChanged = this.__onSelectedItemsChanged.bind(this);
64
- }
65
-
66
- /** @protected */
67
- disconnectedCallback() {
68
- this._grid.removeEventListener('active-item-changed', this.__boundOnActiveItemChanged);
69
- this._grid.removeEventListener('data-provider-changed', this.__boundOnDataProviderChanged);
70
- this._grid.removeEventListener('filter-changed', this.__boundOnSelectedItemsChanged);
71
- this._grid.removeEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged);
72
-
73
- super.disconnectedCallback();
74
- }
75
-
76
- /** @protected */
77
- connectedCallback() {
78
- super.connectedCallback();
79
- if (this._grid) {
80
- this._grid.addEventListener('active-item-changed', this.__boundOnActiveItemChanged);
81
- this._grid.addEventListener('data-provider-changed', this.__boundOnDataProviderChanged);
82
- this._grid.addEventListener('filter-changed', this.__boundOnSelectedItemsChanged);
83
- this._grid.addEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged);
84
- }
85
- }
86
-
87
- /** @private */
88
- __onSelectAllChanged(selectAll) {
89
- if (selectAll === undefined || !this._grid) {
90
- return;
91
- }
92
-
93
- if (!this.__selectAllInitialized) {
94
- // The initial value for selectAll property was applied, avoid clearing pre-selected items
95
- this.__selectAllInitialized = true;
96
- return;
97
- }
98
-
99
- if (this._selectAllChangeLock) {
100
- return;
101
- }
102
-
103
- if (selectAll && this.__hasArrayDataProvider()) {
104
- this.__withFilteredItemsArray((items) => {
105
- this._grid.selectedItems = items;
106
- });
107
- } else {
108
- this._grid.selectedItems = [];
109
- }
110
- }
111
-
112
- /**
113
- * Return true if array `a` contains all the items in `b`
114
- * We need this when sorting or to preserve selection after filtering.
115
- * @private
116
- */
117
- __arrayContains(a, b) {
118
- return Array.isArray(a) && Array.isArray(b) && b.every((i) => a.includes(i));
119
- }
120
-
121
- /**
122
- * Override a method from `GridSelectionColumnBaseMixin` to handle the user
123
- * selecting all items.
124
- *
125
- * @protected
126
- * @override
127
- */
128
- _selectAll() {
129
- this.selectAll = true;
130
- }
131
-
132
- /**
133
- * Override a method from `GridSelectionColumnBaseMixin` to handle the user
134
- * deselecting all items.
135
- *
136
- * @protected
137
- * @override
138
- */
139
- _deselectAll() {
140
- this.selectAll = false;
141
- }
142
-
143
- /**
144
- * Override a method from `GridSelectionColumnBaseMixin` to handle the user
145
- * selecting an item.
146
- *
147
- * @param {Object} item the item to select
148
- * @protected
149
- * @override
150
- */
151
- _selectItem(item) {
152
- this._grid.selectItem(item);
153
- }
154
-
155
- /**
156
- * Override a method from `GridSelectionColumnBaseMixin` to handle the user
157
- * deselecting an item.
158
- *
159
- * @param {Object} item the item to deselect
160
- * @protected
161
- * @override
162
- */
163
- _deselectItem(item) {
164
- this._grid.deselectItem(item);
165
- }
166
-
167
- /** @private */
168
- __onActiveItemChanged(e) {
169
- const activeItem = e.detail.value;
170
- if (this.autoSelect) {
171
- const item = activeItem || this.__previousActiveItem;
172
- if (item) {
173
- this._grid._toggleItem(item);
174
- }
175
- }
176
- this.__previousActiveItem = activeItem;
177
- }
178
-
179
- /** @private */
180
- __hasArrayDataProvider() {
181
- return Array.isArray(this._grid.items) && !!this._grid.dataProvider;
182
- }
183
-
184
- /** @private */
185
- __onSelectedItemsChanged() {
186
- this._selectAllChangeLock = true;
187
- if (this.__hasArrayDataProvider()) {
188
- this.__withFilteredItemsArray((items) => {
189
- if (!this._grid.selectedItems.length) {
190
- this.selectAll = false;
191
- this._indeterminate = false;
192
- } else if (this.__arrayContains(this._grid.selectedItems, items)) {
193
- this.selectAll = true;
194
- this._indeterminate = false;
195
- } else {
196
- this.selectAll = false;
197
- this._indeterminate = true;
198
- }
199
- });
200
- }
201
- this._selectAllChangeLock = false;
202
- }
203
-
204
- /** @private */
205
- __onDataProviderChanged() {
206
- this._selectAllHidden = !Array.isArray(this._grid.items);
207
- }
208
-
209
- /**
210
- * Assuming the grid uses an items array data provider, fetches all the filtered items
211
- * from the data provider and invokes the callback with the resulting array.
212
- *
213
- * @private
214
- */
215
- __withFilteredItemsArray(callback) {
216
- const params = {
217
- page: 0,
218
- pageSize: Infinity,
219
- sortOrders: [],
220
- filters: this._grid._mapFilters(),
221
- };
222
- this._grid.dataProvider(params, (items) => callback(items));
223
- }
224
42
  }
225
43
 
226
44
  defineCustomElement(GridSelectionColumn);
@@ -0,0 +1,36 @@
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
+ import type { GridSorterDirection } from './vaadin-grid-sorter.js';
8
+
9
+ /**
10
+ * Fired when the `direction` property changes.
11
+ */
12
+ export type GridSortColumnDirectionChangedEvent = CustomEvent<{ value: GridSorterDirection }>;
13
+
14
+ export interface GridSortColumnCustomEventMap {
15
+ 'direction-changed': GridSortColumnDirectionChangedEvent;
16
+ }
17
+
18
+ export interface GridSortColumnEventMap extends HTMLElementEventMap, GridSortColumnCustomEventMap {}
19
+
20
+ export declare function GridSortColumnMixin<T extends Constructor<HTMLElement>>(
21
+ superclass: T,
22
+ ): Constructor<GridSortColumnMixinClass> & T;
23
+
24
+ export declare class GridSortColumnMixinClass {
25
+ /**
26
+ * JS Path of the property in the item used for sorting the data.
27
+ */
28
+ path: string | null | undefined;
29
+
30
+ /**
31
+ * How to sort the data.
32
+ * Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
33
+ * descending direction, or `null` for not sorting the data.
34
+ */
35
+ direction: GridSorterDirection | null | undefined;
36
+ }
@@ -0,0 +1,97 @@
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
+
7
+ /**
8
+ * @polymerMixin
9
+ */
10
+ export const GridSortColumnMixin = (superClass) =>
11
+ class extends superClass {
12
+ static get properties() {
13
+ return {
14
+ /**
15
+ * JS Path of the property in the item used for sorting the data.
16
+ */
17
+ path: String,
18
+
19
+ /**
20
+ * How to sort the data.
21
+ * Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
22
+ * descending direction, or `null` for not sorting the data.
23
+ * @type {GridSorterDirection | undefined}
24
+ */
25
+ direction: {
26
+ type: String,
27
+ notify: true,
28
+ },
29
+ };
30
+ }
31
+
32
+ static get observers() {
33
+ return ['_onHeaderRendererOrBindingChanged(_headerRenderer, _headerCell, path, header, direction)'];
34
+ }
35
+
36
+ constructor() {
37
+ super();
38
+
39
+ this.__boundOnDirectionChanged = this.__onDirectionChanged.bind(this);
40
+ }
41
+
42
+ /**
43
+ * Renders the grid sorter to the header cell.
44
+ *
45
+ * @override
46
+ */
47
+ _defaultHeaderRenderer(root, _column) {
48
+ let sorter = root.firstElementChild;
49
+ if (!sorter) {
50
+ sorter = document.createElement('vaadin-grid-sorter');
51
+ sorter.addEventListener('direction-changed', this.__boundOnDirectionChanged);
52
+ root.appendChild(sorter);
53
+ }
54
+
55
+ sorter.path = this.path;
56
+ sorter.__rendererDirection = this.direction;
57
+ sorter.direction = this.direction;
58
+ sorter.textContent = this.__getHeader(this.header, this.path);
59
+ }
60
+
61
+ /**
62
+ * The sort column doesn't allow to use a custom header renderer
63
+ * to override the header cell content.
64
+ * It always renders the grid sorter to the header cell.
65
+ *
66
+ * @override
67
+ */
68
+ _computeHeaderRenderer() {
69
+ return this._defaultHeaderRenderer;
70
+ }
71
+
72
+ /**
73
+ * Updates the sorting direction once the grid sorter's direction is changed.
74
+ * The listener handles only user-fired events.
75
+ *
76
+ * @private
77
+ */
78
+ __onDirectionChanged(e) {
79
+ // Skip if the direction is changed by the renderer.
80
+ if (e.detail.value === e.target.__rendererDirection) {
81
+ return;
82
+ }
83
+
84
+ this.direction = e.detail.value;
85
+ }
86
+
87
+ /** @private */
88
+ __getHeader(header, path) {
89
+ if (header) {
90
+ return header;
91
+ }
92
+
93
+ if (path) {
94
+ return this._generateHeader(path);
95
+ }
96
+ }
97
+ };
@@ -4,19 +4,10 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { GridDefaultItem } from './vaadin-grid.js';
7
- import { GridColumn } from './vaadin-grid-column.js';
8
- import type { GridSorterDirection } from './vaadin-grid-sorter.js';
7
+ import type { GridColumn, GridColumnMixin } from './vaadin-grid-column.js';
8
+ import type { GridSortColumnEventMap, GridSortColumnMixinClass } from './vaadin-grid-sort-column-mixin.js';
9
9
 
10
- /**
11
- * Fired when the `direction` property changes.
12
- */
13
- export type GridSortColumnDirectionChangedEvent = CustomEvent<{ value: GridSorterDirection }>;
14
-
15
- export interface GridSortColumnCustomEventMap {
16
- 'direction-changed': GridSortColumnDirectionChangedEvent;
17
- }
18
-
19
- export interface GridSortColumnEventMap extends HTMLElementEventMap, GridSortColumnCustomEventMap {}
10
+ export * from './vaadin-grid-sort-column-mixin.js';
20
11
 
21
12
  /**
22
13
  * `<vaadin-grid-sort-column>` is a helper element for the `<vaadin-grid>`
@@ -30,22 +21,13 @@ export interface GridSortColumnEventMap extends HTMLElementEventMap, GridSortCol
30
21
  * <vaadin-grid-column>
31
22
  * ...
32
23
  * ```
33
- *
34
- * @fires {CustomEvent} direction-changed - Fired when the `direction` property changes.
35
24
  */
36
- declare class GridSortColumn<TItem = GridDefaultItem> extends GridColumn<TItem> {
37
- /**
38
- * JS Path of the property in the item used for sorting the data.
39
- */
40
- path: string | null | undefined;
41
-
42
- /**
43
- * How to sort the data.
44
- * Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
45
- * descending direction, or `null` for not sorting the data.
46
- */
47
- direction: GridSorterDirection | null | undefined;
25
+ declare class GridSortColumn<TItem = GridDefaultItem> extends HTMLElement {}
48
26
 
27
+ interface GridSortColumn<TItem = GridDefaultItem>
28
+ extends GridSortColumnMixinClass,
29
+ GridColumnMixin<TItem, GridColumn<TItem>>,
30
+ GridColumn<TItem> {
49
31
  addEventListener<K extends keyof GridSortColumnEventMap>(
50
32
  type: K,
51
33
  listener: (this: GridSortColumn<TItem>, ev: GridSortColumnEventMap[K]) => void,
@@ -6,6 +6,7 @@
6
6
  import './vaadin-grid-sorter.js';
7
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { GridColumn } from './vaadin-grid-column.js';
9
+ import { GridSortColumnMixin } from './vaadin-grid-sort-column-mixin.js';
9
10
 
10
11
  /**
11
12
  * `<vaadin-grid-sort-column>` is a helper element for the `<vaadin-grid>`
@@ -24,97 +25,12 @@ import { GridColumn } from './vaadin-grid-column.js';
24
25
  *
25
26
  * @customElement
26
27
  * @extends GridColumn
28
+ * @mixes GridSortColumnMixin
27
29
  */
28
- class GridSortColumn extends GridColumn {
30
+ class GridSortColumn extends GridSortColumnMixin(GridColumn) {
29
31
  static get is() {
30
32
  return 'vaadin-grid-sort-column';
31
33
  }
32
-
33
- static get properties() {
34
- return {
35
- /**
36
- * JS Path of the property in the item used for sorting the data.
37
- */
38
- path: String,
39
-
40
- /**
41
- * How to sort the data.
42
- * Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
43
- * descending direction, or `null` for not sorting the data.
44
- * @type {GridSorterDirection | undefined}
45
- */
46
- direction: {
47
- type: String,
48
- notify: true,
49
- },
50
- };
51
- }
52
-
53
- static get observers() {
54
- return ['_onHeaderRendererOrBindingChanged(_headerRenderer, _headerCell, path, header, direction)'];
55
- }
56
-
57
- constructor() {
58
- super();
59
-
60
- this.__boundOnDirectionChanged = this.__onDirectionChanged.bind(this);
61
- }
62
-
63
- /**
64
- * Renders the grid sorter to the header cell.
65
- *
66
- * @override
67
- */
68
- _defaultHeaderRenderer(root, _column) {
69
- let sorter = root.firstElementChild;
70
- if (!sorter) {
71
- sorter = document.createElement('vaadin-grid-sorter');
72
- sorter.addEventListener('direction-changed', this.__boundOnDirectionChanged);
73
- root.appendChild(sorter);
74
- }
75
-
76
- sorter.path = this.path;
77
- sorter.__rendererDirection = this.direction;
78
- sorter.direction = this.direction;
79
- sorter.textContent = this.__getHeader(this.header, this.path);
80
- }
81
-
82
- /**
83
- * The sort column doesn't allow to use a custom header renderer
84
- * to override the header cell content.
85
- * It always renders the grid sorter to the header cell.
86
- *
87
- * @override
88
- */
89
- _computeHeaderRenderer() {
90
- return this._defaultHeaderRenderer;
91
- }
92
-
93
- /**
94
- * Updates the sorting direction once the grid sorter's direction is changed.
95
- * The listener handles only user-fired events.
96
- *
97
- * @private
98
- */
99
- __onDirectionChanged(e) {
100
- // Skip if the direction is changed by the renderer.
101
- if (e.detail.value === e.target.__rendererDirection) {
102
- return;
103
- }
104
-
105
- this.direction = e.detail.value;
106
- }
107
-
108
- /** @private */
109
- __getHeader(header, path) {
110
- if (header) {
111
- return header;
112
- }
113
-
114
- if (path) {
115
- return this._generateHeader(path);
116
- }
117
- }
118
34
  }
119
35
 
120
36
  defineCustomElement(GridSortColumn);
@@ -0,0 +1,44 @@
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 type GridSorterDirection = 'asc' | 'desc' | null;
9
+
10
+ /**
11
+ * Fired when the `path` or `direction` property changes.
12
+ */
13
+ export type GridSorterChangedEvent = CustomEvent<{ shiftClick: boolean; fromSorterClick: boolean }>;
14
+
15
+ /**
16
+ * Fired when the `direction` property changes.
17
+ */
18
+ export type GridSorterDirectionChangedEvent = CustomEvent<{ value: GridSorterDirection }>;
19
+
20
+ export interface GridSorterCustomEventMap {
21
+ 'sorter-changed': GridSorterChangedEvent;
22
+
23
+ 'direction-changed': GridSorterDirectionChangedEvent;
24
+ }
25
+
26
+ export interface GridSorterEventMap extends HTMLElementEventMap, GridSorterCustomEventMap {}
27
+
28
+ export declare function GridSorterMixin<T extends Constructor<HTMLElement>>(
29
+ base: T,
30
+ ): Constructor<GridSorterMixinClass> & T;
31
+
32
+ declare class GridSorterMixinClass {
33
+ /**
34
+ * JS Path of the property in the item used for sorting the data.
35
+ */
36
+ path: string | null | undefined;
37
+
38
+ /**
39
+ * How to sort the data.
40
+ * Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
41
+ * descending direction, or `null` for not sorting the data.
42
+ */
43
+ direction: GridSorterDirection | null | undefined;
44
+ }