@vaadin/grid 24.3.0-alpha1 → 24.3.0-alpha10
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 +18 -13
- package/src/vaadin-grid-a11y-mixin.js +1 -1
- package/src/vaadin-grid-active-item-mixin.js +1 -0
- package/src/vaadin-grid-array-data-provider-mixin.js +14 -17
- package/src/vaadin-grid-column-group-mixin.d.ts +20 -0
- package/src/vaadin-grid-column-group-mixin.js +364 -0
- package/src/vaadin-grid-column-group.d.ts +4 -14
- package/src/vaadin-grid-column-group.js +5 -355
- package/src/vaadin-grid-column-mixin.d.ts +170 -0
- package/src/vaadin-grid-column-mixin.js +958 -0
- package/src/vaadin-grid-column.d.ts +11 -138
- package/src/vaadin-grid-column.js +5 -876
- package/src/vaadin-grid-data-provider-mixin.d.ts +6 -5
- package/src/vaadin-grid-data-provider-mixin.js +58 -11
- package/src/vaadin-grid-drag-and-drop-mixin.js +17 -5
- package/src/vaadin-grid-dynamic-columns-mixin.js +22 -17
- package/src/vaadin-grid-filter-column-mixin.d.ts +22 -0
- package/src/vaadin-grid-filter-column-mixin.js +106 -0
- package/src/vaadin-grid-filter-column.d.ts +9 -11
- package/src/vaadin-grid-filter-column.js +3 -90
- package/src/vaadin-grid-filter-element-mixin.d.ts +34 -0
- package/src/vaadin-grid-filter-element-mixin.js +108 -0
- package/src/vaadin-grid-filter-mixin.js +4 -4
- package/src/vaadin-grid-filter.d.ts +4 -21
- package/src/vaadin-grid-filter.js +5 -84
- package/src/vaadin-grid-helpers.js +94 -0
- package/src/vaadin-grid-keyboard-navigation-mixin.js +26 -6
- package/src/vaadin-grid-mixin.js +37 -46
- package/src/vaadin-grid-row-details-mixin.js +14 -8
- package/src/vaadin-grid-scroll-mixin.js +9 -3
- package/src/vaadin-grid-selection-column-base-mixin.js +12 -4
- package/src/vaadin-grid-selection-column-mixin.d.ts +24 -0
- package/src/vaadin-grid-selection-column-mixin.js +194 -0
- package/src/vaadin-grid-selection-column.d.ts +13 -17
- package/src/vaadin-grid-selection-column.js +4 -186
- package/src/vaadin-grid-selection-mixin.js +4 -3
- package/src/vaadin-grid-sort-column-mixin.d.ts +36 -0
- package/src/vaadin-grid-sort-column-mixin.js +101 -0
- package/src/vaadin-grid-sort-column.d.ts +8 -26
- package/src/vaadin-grid-sort-column.js +3 -87
- package/src/vaadin-grid-sorter-mixin.d.ts +44 -0
- package/src/vaadin-grid-sorter-mixin.js +200 -0
- package/src/vaadin-grid-sorter.d.ts +3 -32
- package/src/vaadin-grid-sorter.js +5 -181
- package/src/vaadin-grid-styles.js +341 -345
- package/src/vaadin-grid-styling-mixin.js +8 -2
- package/src/vaadin-grid-tree-column-mixin.d.ts +18 -0
- package/src/vaadin-grid-tree-column-mixin.js +99 -0
- package/src/vaadin-grid-tree-column.d.ts +9 -7
- package/src/vaadin-grid-tree-column.js +3 -82
- package/src/vaadin-grid-tree-toggle-mixin.d.ts +39 -0
- package/src/vaadin-grid-tree-toggle-mixin.js +153 -0
- package/src/vaadin-grid-tree-toggle.d.ts +4 -27
- package/src/vaadin-grid-tree-toggle.js +9 -141
- package/src/vaadin-grid.d.ts +3 -0
- package/src/vaadin-grid.js +7 -2
- package/theme/lumo/vaadin-grid-sorter-styles.js +1 -1
- package/theme/lumo/vaadin-grid-styles.js +15 -14
- package/theme/material/vaadin-grid-styles.js +15 -10
- package/web-types.json +331 -126
- package/web-types.lit.json +114 -58
|
@@ -19,6 +19,7 @@ export const RowDetailsMixin = (superClass) =>
|
|
|
19
19
|
detailsOpenedItems: {
|
|
20
20
|
type: Array,
|
|
21
21
|
value: () => [],
|
|
22
|
+
sync: true,
|
|
22
23
|
},
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -37,7 +38,10 @@ export const RowDetailsMixin = (superClass) =>
|
|
|
37
38
|
*
|
|
38
39
|
* @type {GridRowDetailsRenderer | null | undefined}
|
|
39
40
|
*/
|
|
40
|
-
rowDetailsRenderer:
|
|
41
|
+
rowDetailsRenderer: {
|
|
42
|
+
type: Function,
|
|
43
|
+
sync: true,
|
|
44
|
+
},
|
|
41
45
|
|
|
42
46
|
/**
|
|
43
47
|
* @type {!Array<!HTMLElement> | undefined}
|
|
@@ -51,7 +55,7 @@ export const RowDetailsMixin = (superClass) =>
|
|
|
51
55
|
|
|
52
56
|
static get observers() {
|
|
53
57
|
return [
|
|
54
|
-
'_detailsOpenedItemsChanged(detailsOpenedItems
|
|
58
|
+
'_detailsOpenedItemsChanged(detailsOpenedItems, rowDetailsRenderer)',
|
|
55
59
|
'_rowDetailsRendererChanged(rowDetailsRenderer)',
|
|
56
60
|
];
|
|
57
61
|
}
|
|
@@ -90,12 +94,7 @@ export const RowDetailsMixin = (superClass) =>
|
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
/** @private */
|
|
93
|
-
_detailsOpenedItemsChanged(
|
|
94
|
-
// Skip to avoid duplicate work of both `.splices` and `.length` updates.
|
|
95
|
-
if (changeRecord.path === 'detailsOpenedItems.length' || !changeRecord.value) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
97
|
+
_detailsOpenedItemsChanged(detailsOpenedItems, rowDetailsRenderer) {
|
|
99
98
|
iterateChildren(this.$.items, (row) => {
|
|
100
99
|
// Re-renders the row to possibly close the previously opened details.
|
|
101
100
|
if (row.hasAttribute('details-opened')) {
|
|
@@ -154,6 +153,13 @@ export const RowDetailsMixin = (superClass) =>
|
|
|
154
153
|
return;
|
|
155
154
|
}
|
|
156
155
|
|
|
156
|
+
this.__updateDetailsRowPadding(row, cell);
|
|
157
|
+
// Ensure the row has correct padding after frame (the resize observer might miss it)
|
|
158
|
+
requestAnimationFrame(() => this.__updateDetailsRowPadding(row, cell));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** @private */
|
|
162
|
+
__updateDetailsRowPadding(row, cell) {
|
|
157
163
|
if (cell.hidden) {
|
|
158
164
|
row.style.removeProperty('padding-bottom');
|
|
159
165
|
} else {
|
|
@@ -61,6 +61,7 @@ export const ScrollMixin = (superClass) =>
|
|
|
61
61
|
columnRendering: {
|
|
62
62
|
type: String,
|
|
63
63
|
value: 'eager',
|
|
64
|
+
sync: true,
|
|
64
65
|
},
|
|
65
66
|
|
|
66
67
|
/**
|
|
@@ -160,7 +161,7 @@ export const ScrollMixin = (superClass) =>
|
|
|
160
161
|
* @protected
|
|
161
162
|
*/
|
|
162
163
|
_scrollToFlatIndex(index) {
|
|
163
|
-
index = Math.min(this.
|
|
164
|
+
index = Math.min(this._flatSize - 1, Math.max(0, index));
|
|
164
165
|
this.__virtualizer.scrollToIndex(index);
|
|
165
166
|
this.__scrollIntoViewport(index);
|
|
166
167
|
}
|
|
@@ -320,9 +321,14 @@ export const ScrollMixin = (superClass) =>
|
|
|
320
321
|
}
|
|
321
322
|
|
|
322
323
|
// Check if the column's sizer cell is inside the viewport
|
|
324
|
+
return this.__isHorizontallyInViewport(column._sizerCell);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** @private */
|
|
328
|
+
__isHorizontallyInViewport(element) {
|
|
323
329
|
return (
|
|
324
|
-
|
|
325
|
-
|
|
330
|
+
element.offsetLeft + element.offsetWidth >= this._scrollLeft &&
|
|
331
|
+
element.offsetLeft <= this._scrollLeft + this.clientWidth
|
|
326
332
|
);
|
|
327
333
|
}
|
|
328
334
|
|
|
@@ -28,6 +28,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
|
28
28
|
width: {
|
|
29
29
|
type: String,
|
|
30
30
|
value: '58px',
|
|
31
|
+
sync: true,
|
|
31
32
|
},
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -38,6 +39,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
|
38
39
|
flexGrow: {
|
|
39
40
|
type: Number,
|
|
40
41
|
value: 0,
|
|
42
|
+
sync: true,
|
|
41
43
|
},
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -49,6 +51,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
|
49
51
|
type: Boolean,
|
|
50
52
|
value: false,
|
|
51
53
|
notify: true,
|
|
54
|
+
sync: true,
|
|
52
55
|
},
|
|
53
56
|
|
|
54
57
|
/**
|
|
@@ -59,6 +62,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
|
59
62
|
autoSelect: {
|
|
60
63
|
type: Boolean,
|
|
61
64
|
value: false,
|
|
65
|
+
sync: true,
|
|
62
66
|
},
|
|
63
67
|
|
|
64
68
|
/**
|
|
@@ -69,10 +73,14 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
|
69
73
|
dragSelect: {
|
|
70
74
|
type: Boolean,
|
|
71
75
|
value: false,
|
|
76
|
+
sync: true,
|
|
72
77
|
},
|
|
73
78
|
|
|
74
79
|
/** @protected */
|
|
75
|
-
_indeterminate:
|
|
80
|
+
_indeterminate: {
|
|
81
|
+
type: Boolean,
|
|
82
|
+
sync: true,
|
|
83
|
+
},
|
|
76
84
|
|
|
77
85
|
/** @protected */
|
|
78
86
|
_selectAllHidden: Boolean,
|
|
@@ -181,7 +189,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
|
181
189
|
// Get the row where the drag started
|
|
182
190
|
const dragStartRow = renderedRows.find((row) => row.contains(event.currentTarget.assignedSlot));
|
|
183
191
|
// Whether to select or deselect the items on drag
|
|
184
|
-
this.
|
|
192
|
+
this.__selectOnDrag = !this._grid._isSelected(dragStartRow._item);
|
|
185
193
|
// Store the index of the row where the drag started
|
|
186
194
|
this.__dragStartIndex = dragStartRow.index;
|
|
187
195
|
// Store the item of the row where the drag started
|
|
@@ -191,7 +199,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
|
191
199
|
} else if (event.detail.state === 'end') {
|
|
192
200
|
// if drag start and end stays within the same item, then toggle its state
|
|
193
201
|
if (this.__dragStartItem) {
|
|
194
|
-
if (this.
|
|
202
|
+
if (this.__selectOnDrag) {
|
|
195
203
|
this._selectItem(this.__dragStartItem);
|
|
196
204
|
} else {
|
|
197
205
|
this._deselectItem(this.__dragStartItem);
|
|
@@ -254,7 +262,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
|
254
262
|
(hoveredIndex > this.__dragStartIndex && row.index >= this.__dragStartIndex && row.index <= hoveredIndex) ||
|
|
255
263
|
(hoveredIndex < this.__dragStartIndex && row.index <= this.__dragStartIndex && row.index >= hoveredIndex)
|
|
256
264
|
) {
|
|
257
|
-
if (this.
|
|
265
|
+
if (this.__selectOnDrag) {
|
|
258
266
|
this._selectItem(row._item);
|
|
259
267
|
} else {
|
|
260
268
|
this._deselectItem(row._item);
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { GridSelectionColumnBaseMixinClass } from './vaadin-grid-selection-column-base-mixin.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fired when the `selectAll` property changes.
|
|
11
|
+
*/
|
|
12
|
+
export type GridSelectionColumnSelectAllChangedEvent = CustomEvent<{ value: boolean }>;
|
|
13
|
+
|
|
14
|
+
export interface GridSelectionColumnCustomEventMap {
|
|
15
|
+
'select-all-changed': GridSelectionColumnSelectAllChangedEvent;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GridSelectionColumnEventMap extends HTMLElementEventMap, GridSelectionColumnCustomEventMap {}
|
|
19
|
+
|
|
20
|
+
export declare function GridSelectionColumnMixin<TItem, T extends Constructor<HTMLElement>>(
|
|
21
|
+
superclass: T,
|
|
22
|
+
): Constructor<GridSelectionColumnMixinClass<TItem>> & T;
|
|
23
|
+
|
|
24
|
+
export declare class GridSelectionColumnMixinClass<TItem> extends GridSelectionColumnBaseMixinClass<TItem> {}
|
|
@@ -0,0 +1,194 @@
|
|
|
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 { GridSelectionColumnBaseMixin } from './vaadin-grid-selection-column-base-mixin.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @polymerMixin
|
|
10
|
+
*/
|
|
11
|
+
export const GridSelectionColumnMixin = (superClass) =>
|
|
12
|
+
class extends GridSelectionColumnBaseMixin(superClass) {
|
|
13
|
+
static get properties() {
|
|
14
|
+
return {
|
|
15
|
+
/**
|
|
16
|
+
* The previous state of activeItem. When activeItem turns to `null`,
|
|
17
|
+
* previousActiveItem will have an Object with just unselected activeItem
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
__previousActiveItem: Object,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static get observers() {
|
|
25
|
+
return ['__onSelectAllChanged(selectAll)'];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
|
|
31
|
+
this.__boundOnActiveItemChanged = this.__onActiveItemChanged.bind(this);
|
|
32
|
+
this.__boundOnDataProviderChanged = this.__onDataProviderChanged.bind(this);
|
|
33
|
+
this.__boundOnSelectedItemsChanged = this.__onSelectedItemsChanged.bind(this);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @protected */
|
|
37
|
+
disconnectedCallback() {
|
|
38
|
+
this._grid.removeEventListener('active-item-changed', this.__boundOnActiveItemChanged);
|
|
39
|
+
this._grid.removeEventListener('data-provider-changed', this.__boundOnDataProviderChanged);
|
|
40
|
+
this._grid.removeEventListener('filter-changed', this.__boundOnSelectedItemsChanged);
|
|
41
|
+
this._grid.removeEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged);
|
|
42
|
+
|
|
43
|
+
super.disconnectedCallback();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @protected */
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
if (this._grid) {
|
|
50
|
+
this._grid.addEventListener('active-item-changed', this.__boundOnActiveItemChanged);
|
|
51
|
+
this._grid.addEventListener('data-provider-changed', this.__boundOnDataProviderChanged);
|
|
52
|
+
this._grid.addEventListener('filter-changed', this.__boundOnSelectedItemsChanged);
|
|
53
|
+
this._grid.addEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @private */
|
|
58
|
+
__onSelectAllChanged(selectAll) {
|
|
59
|
+
if (selectAll === undefined || !this._grid) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!this.__selectAllInitialized) {
|
|
64
|
+
// The initial value for selectAll property was applied, avoid clearing pre-selected items
|
|
65
|
+
this.__selectAllInitialized = true;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (this._selectAllChangeLock) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (selectAll && this.__hasArrayDataProvider()) {
|
|
74
|
+
this.__withFilteredItemsArray((items) => {
|
|
75
|
+
this._grid.selectedItems = items;
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
this._grid.selectedItems = [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Return true if array `a` contains all the items in `b`
|
|
84
|
+
* We need this when sorting or to preserve selection after filtering.
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
__arrayContains(a, b) {
|
|
88
|
+
return Array.isArray(a) && Array.isArray(b) && b.every((i) => a.includes(i));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
93
|
+
* selecting all items.
|
|
94
|
+
*
|
|
95
|
+
* @protected
|
|
96
|
+
* @override
|
|
97
|
+
*/
|
|
98
|
+
_selectAll() {
|
|
99
|
+
this.selectAll = true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
104
|
+
* deselecting all items.
|
|
105
|
+
*
|
|
106
|
+
* @protected
|
|
107
|
+
* @override
|
|
108
|
+
*/
|
|
109
|
+
_deselectAll() {
|
|
110
|
+
this.selectAll = false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
115
|
+
* selecting an item.
|
|
116
|
+
*
|
|
117
|
+
* @param {Object} item the item to select
|
|
118
|
+
* @protected
|
|
119
|
+
* @override
|
|
120
|
+
*/
|
|
121
|
+
_selectItem(item) {
|
|
122
|
+
this._grid.selectItem(item);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
127
|
+
* deselecting an item.
|
|
128
|
+
*
|
|
129
|
+
* @param {Object} item the item to deselect
|
|
130
|
+
* @protected
|
|
131
|
+
* @override
|
|
132
|
+
*/
|
|
133
|
+
_deselectItem(item) {
|
|
134
|
+
this._grid.deselectItem(item);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** @private */
|
|
138
|
+
__onActiveItemChanged(e) {
|
|
139
|
+
const activeItem = e.detail.value;
|
|
140
|
+
if (this.autoSelect) {
|
|
141
|
+
const item = activeItem || this.__previousActiveItem;
|
|
142
|
+
if (item) {
|
|
143
|
+
this._grid._toggleItem(item);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
this.__previousActiveItem = activeItem;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** @private */
|
|
150
|
+
__hasArrayDataProvider() {
|
|
151
|
+
return Array.isArray(this._grid.items) && !!this._grid.dataProvider;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** @private */
|
|
155
|
+
__onSelectedItemsChanged() {
|
|
156
|
+
this._selectAllChangeLock = true;
|
|
157
|
+
if (this.__hasArrayDataProvider()) {
|
|
158
|
+
this.__withFilteredItemsArray((items) => {
|
|
159
|
+
if (!this._grid.selectedItems.length) {
|
|
160
|
+
this.selectAll = false;
|
|
161
|
+
this._indeterminate = false;
|
|
162
|
+
} else if (this.__arrayContains(this._grid.selectedItems, items)) {
|
|
163
|
+
this.selectAll = true;
|
|
164
|
+
this._indeterminate = false;
|
|
165
|
+
} else {
|
|
166
|
+
this.selectAll = false;
|
|
167
|
+
this._indeterminate = true;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
this._selectAllChangeLock = false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** @private */
|
|
175
|
+
__onDataProviderChanged() {
|
|
176
|
+
this._selectAllHidden = !Array.isArray(this._grid.items);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Assuming the grid uses an items array data provider, fetches all the filtered items
|
|
181
|
+
* from the data provider and invokes the callback with the resulting array.
|
|
182
|
+
*
|
|
183
|
+
* @private
|
|
184
|
+
*/
|
|
185
|
+
__withFilteredItemsArray(callback) {
|
|
186
|
+
const params = {
|
|
187
|
+
page: 0,
|
|
188
|
+
pageSize: Infinity,
|
|
189
|
+
sortOrders: [],
|
|
190
|
+
filters: this._grid._mapFilters(),
|
|
191
|
+
};
|
|
192
|
+
this._grid.dataProvider(params, (items) => callback(items));
|
|
193
|
+
}
|
|
194
|
+
};
|
|
@@ -4,19 +4,14 @@
|
|
|
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 {
|
|
8
|
-
import type {
|
|
7
|
+
import type { GridColumnMixin } from './vaadin-grid-column.js';
|
|
8
|
+
import type { GridColumn } from './vaadin-grid-column.js';
|
|
9
|
+
import type {
|
|
10
|
+
GridSelectionColumnEventMap,
|
|
11
|
+
GridSelectionColumnMixinClass,
|
|
12
|
+
} from './vaadin-grid-selection-column-mixin.js';
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
* Fired when the `selectAll` property changes.
|
|
12
|
-
*/
|
|
13
|
-
export type GridSelectionColumnSelectAllChangedEvent = CustomEvent<{ value: boolean }>;
|
|
14
|
-
|
|
15
|
-
export interface GridSelectionColumnCustomEventMap {
|
|
16
|
-
'select-all-changed': GridSelectionColumnSelectAllChangedEvent;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface GridSelectionColumnEventMap extends HTMLElementEventMap, GridSelectionColumnCustomEventMap {}
|
|
14
|
+
export * from './vaadin-grid-selection-column-mixin.js';
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
17
|
* `<vaadin-grid-selection-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -39,10 +34,13 @@ export interface GridSelectionColumnEventMap extends HTMLElementEventMap, GridSe
|
|
|
39
34
|
* selection for all the items at once.
|
|
40
35
|
*
|
|
41
36
|
* __The default content can also be overridden__
|
|
42
|
-
*
|
|
43
|
-
* @fires {CustomEvent} select-all-changed - Fired when the `selectAll` property changes.
|
|
44
37
|
*/
|
|
45
|
-
declare class GridSelectionColumn<TItem = GridDefaultItem> extends
|
|
38
|
+
declare class GridSelectionColumn<TItem = GridDefaultItem> extends HTMLElement {}
|
|
39
|
+
|
|
40
|
+
interface GridSelectionColumn<TItem = GridDefaultItem>
|
|
41
|
+
extends GridSelectionColumnMixinClass<TItem>,
|
|
42
|
+
GridColumnMixin<TItem, GridColumn<TItem>>,
|
|
43
|
+
GridColumn<TItem> {
|
|
46
44
|
addEventListener<K extends keyof GridSelectionColumnEventMap>(
|
|
47
45
|
type: K,
|
|
48
46
|
listener: (this: GridSelectionColumn<TItem>, ev: GridSelectionColumnEventMap[K]) => void,
|
|
@@ -56,8 +54,6 @@ declare class GridSelectionColumn<TItem = GridDefaultItem> extends GridColumn<TI
|
|
|
56
54
|
): void;
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
interface GridSelectionColumn<TItem = GridDefaultItem> extends GridSelectionColumnBaseMixinClass<TItem> {}
|
|
60
|
-
|
|
61
57
|
declare global {
|
|
62
58
|
interface HTMLElementTagNameMap {
|
|
63
59
|
'vaadin-grid-selection-column': GridSelectionColumn<GridDefaultItem>;
|
|
@@ -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 {
|
|
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
|
|
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);
|
|
@@ -19,6 +19,7 @@ export const SelectionMixin = (superClass) =>
|
|
|
19
19
|
type: Object,
|
|
20
20
|
notify: true,
|
|
21
21
|
value: () => [],
|
|
22
|
+
sync: true,
|
|
22
23
|
},
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -27,13 +28,13 @@ export const SelectionMixin = (superClass) =>
|
|
|
27
28
|
*/
|
|
28
29
|
__selectedKeys: {
|
|
29
30
|
type: Object,
|
|
30
|
-
computed: '__computeSelectedKeys(itemIdPath, selectedItems
|
|
31
|
+
computed: '__computeSelectedKeys(itemIdPath, selectedItems)',
|
|
31
32
|
},
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
static get observers() {
|
|
36
|
-
return ['__selectedItemsChanged(itemIdPath, selectedItems
|
|
37
|
+
return ['__selectedItemsChanged(itemIdPath, selectedItems)'];
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
@@ -91,7 +92,7 @@ export const SelectionMixin = (superClass) =>
|
|
|
91
92
|
|
|
92
93
|
/** @private */
|
|
93
94
|
__computeSelectedKeys(itemIdPath, selectedItems) {
|
|
94
|
-
const selected = selectedItems
|
|
95
|
+
const selected = selectedItems || [];
|
|
95
96
|
const selectedKeys = new Set();
|
|
96
97
|
selected.forEach((item) => {
|
|
97
98
|
selectedKeys.add(this.getItemId(item));
|