@vaadin/grid 24.2.0-beta3 → 24.2.0-beta4
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 +10 -10
- package/src/vaadin-grid-array-data-provider-mixin.js +1 -1
- package/src/vaadin-grid-column-group.d.ts +14 -4
- package/src/vaadin-grid-column-group.js +355 -5
- package/src/vaadin-grid-column.d.ts +138 -11
- package/src/vaadin-grid-column.js +876 -3
- package/src/vaadin-grid-data-provider-mixin.d.ts +30 -6
- package/src/vaadin-grid-data-provider-mixin.js +241 -100
- package/src/vaadin-grid-drag-and-drop-mixin.js +1 -1
- package/src/vaadin-grid-filter.d.ts +21 -4
- package/src/vaadin-grid-filter.js +84 -5
- package/src/vaadin-grid-keyboard-navigation-mixin.js +2 -2
- package/src/vaadin-grid-mixin.js +10 -10
- package/src/vaadin-grid-scroll-mixin.js +1 -1
- package/src/vaadin-grid-sorter.d.ts +32 -3
- package/src/vaadin-grid-sorter.js +181 -5
- package/src/vaadin-grid-tree-column.d.ts +7 -9
- package/src/vaadin-grid-tree-column.js +82 -3
- package/src/vaadin-grid-tree-toggle.d.ts +27 -4
- package/src/vaadin-grid-tree-toggle.js +141 -9
- package/web-types.json +98 -98
- package/web-types.lit.json +42 -42
- package/src/vaadin-grid-column-group-mixin.d.ts +0 -20
- package/src/vaadin-grid-column-group-mixin.js +0 -369
- package/src/vaadin-grid-column-mixin.d.ts +0 -156
- package/src/vaadin-grid-column-mixin.js +0 -887
- package/src/vaadin-grid-filter-element-mixin.d.ts +0 -34
- package/src/vaadin-grid-filter-element-mixin.js +0 -99
- package/src/vaadin-grid-sorter-mixin.d.ts +0 -44
- package/src/vaadin-grid-sorter-mixin.js +0 -198
- package/src/vaadin-grid-tree-column-mixin.d.ts +0 -19
- package/src/vaadin-grid-tree-column-mixin.js +0 -92
- package/src/vaadin-grid-tree-toggle-mixin.d.ts +0 -39
- package/src/vaadin-grid-tree-toggle-mixin.js +0 -151
|
@@ -443,7 +443,7 @@ export const KeyboardNavigationMixin = (superClass) =>
|
|
|
443
443
|
__navigateRows(dy, activeRow, activeCell) {
|
|
444
444
|
const currentRowIndex = this.__getIndexInGroup(activeRow, this._focusedItemIndex);
|
|
445
445
|
const activeRowGroup = activeRow.parentNode;
|
|
446
|
-
const maxRowIndex = (activeRowGroup === this.$.items ? this.
|
|
446
|
+
const maxRowIndex = (activeRowGroup === this.$.items ? this._effectiveSize : activeRowGroup.children.length) - 1;
|
|
447
447
|
|
|
448
448
|
// Index of the destination row
|
|
449
449
|
let dstRowIndex = Math.max(0, Math.min(currentRowIndex + dy, maxRowIndex));
|
|
@@ -476,7 +476,7 @@ export const KeyboardNavigationMixin = (superClass) =>
|
|
|
476
476
|
// Row details navigation logic
|
|
477
477
|
if (activeRowGroup === this.$.items) {
|
|
478
478
|
const item = activeRow._item;
|
|
479
|
-
const
|
|
479
|
+
const dstItem = this._cache.getItemForIndex(dstRowIndex);
|
|
480
480
|
// Should we navigate to row details?
|
|
481
481
|
if (isRowDetails) {
|
|
482
482
|
dstIsRowDetails = dy === 0;
|
package/src/vaadin-grid-mixin.js
CHANGED
|
@@ -58,8 +58,8 @@ import { StylingMixin } from './vaadin-grid-styling-mixin.js';
|
|
|
58
58
|
* @mixes DragAndDropMixin
|
|
59
59
|
*/
|
|
60
60
|
export const GridMixin = (superClass) =>
|
|
61
|
-
class extends
|
|
62
|
-
|
|
61
|
+
class extends DataProviderMixin(
|
|
62
|
+
ArrayDataProviderMixin(
|
|
63
63
|
DynamicColumnsMixin(
|
|
64
64
|
ActiveItemMixin(
|
|
65
65
|
ScrollMixin(
|
|
@@ -88,7 +88,7 @@ export const GridMixin = (superClass) =>
|
|
|
88
88
|
static get observers() {
|
|
89
89
|
return [
|
|
90
90
|
'_columnTreeChanged(_columnTree, _columnTree.*)',
|
|
91
|
-
'
|
|
91
|
+
'_effectiveSizeChanged(_effectiveSize, __virtualizer, _hasData, _columnTree)',
|
|
92
92
|
];
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -294,20 +294,20 @@ export const GridMixin = (superClass) =>
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
/** @private */
|
|
297
|
-
|
|
297
|
+
_effectiveSizeChanged(effectiveSize, virtualizer, hasData, columnTree) {
|
|
298
298
|
if (virtualizer && hasData && columnTree) {
|
|
299
299
|
// Changing the virtualizer size may result in the row with focus getting hidden
|
|
300
300
|
const cell = this.shadowRoot.activeElement;
|
|
301
301
|
const cellCoordinates = this.__getBodyCellCoordinates(cell);
|
|
302
302
|
|
|
303
303
|
const previousSize = virtualizer.size || 0;
|
|
304
|
-
virtualizer.size =
|
|
304
|
+
virtualizer.size = effectiveSize;
|
|
305
305
|
|
|
306
306
|
// Request an update for the previous last row to have the "last" state removed
|
|
307
307
|
virtualizer.update(previousSize - 1, previousSize - 1);
|
|
308
|
-
if (
|
|
308
|
+
if (effectiveSize < previousSize) {
|
|
309
309
|
// Size was decreased, so the new last row requires an explicit update
|
|
310
|
-
virtualizer.update(
|
|
310
|
+
virtualizer.update(effectiveSize - 1, effectiveSize - 1);
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
// If the focused cell's parent row got hidden by the size change, focus the corresponding new cell
|
|
@@ -463,7 +463,7 @@ export const GridMixin = (superClass) =>
|
|
|
463
463
|
if (!this._columnTree) {
|
|
464
464
|
return; // No columns
|
|
465
465
|
}
|
|
466
|
-
if (isElementHidden(this) || this.
|
|
466
|
+
if (isElementHidden(this) || this._cache.isLoading()) {
|
|
467
467
|
this.__pendingRecalculateColumnWidths = true;
|
|
468
468
|
return;
|
|
469
469
|
}
|
|
@@ -476,7 +476,7 @@ export const GridMixin = (superClass) =>
|
|
|
476
476
|
if (
|
|
477
477
|
this.__pendingRecalculateColumnWidths &&
|
|
478
478
|
!isElementHidden(this) &&
|
|
479
|
-
!this.
|
|
479
|
+
!this._cache.isLoading() &&
|
|
480
480
|
this.__hasRowsWithClientHeight()
|
|
481
481
|
) {
|
|
482
482
|
this.__pendingRecalculateColumnWidths = false;
|
|
@@ -801,7 +801,7 @@ export const GridMixin = (superClass) =>
|
|
|
801
801
|
_updateRowOrderParts(row, index = row.index) {
|
|
802
802
|
updateBooleanRowStates(row, {
|
|
803
803
|
first: index === 0,
|
|
804
|
-
last: index === this.
|
|
804
|
+
last: index === this._effectiveSize - 1,
|
|
805
805
|
odd: index % 2 !== 0,
|
|
806
806
|
even: index % 2 === 0,
|
|
807
807
|
});
|
|
@@ -160,7 +160,7 @@ export const ScrollMixin = (superClass) =>
|
|
|
160
160
|
* @protected
|
|
161
161
|
*/
|
|
162
162
|
_scrollToFlatIndex(index) {
|
|
163
|
-
index = Math.min(this.
|
|
163
|
+
index = Math.min(this._effectiveSize - 1, Math.max(0, index));
|
|
164
164
|
this.__virtualizer.scrollToIndex(index);
|
|
165
165
|
this.__scrollIntoViewport(index);
|
|
166
166
|
}
|
|
@@ -5,9 +5,26 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
7
7
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
8
|
-
import { type GridSorterEventMap, GridSorterMixin } from './vaadin-grid-sorter-mixin.js';
|
|
9
8
|
|
|
10
|
-
export
|
|
9
|
+
export type GridSorterDirection = 'asc' | 'desc' | null;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Fired when the `path` or `direction` property changes.
|
|
13
|
+
*/
|
|
14
|
+
export type GridSorterChangedEvent = CustomEvent<{ shiftClick: boolean; fromSorterClick: boolean }>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Fired when the `direction` property changes.
|
|
18
|
+
*/
|
|
19
|
+
export type GridSorterDirectionChangedEvent = CustomEvent<{ value: GridSorterDirection }>;
|
|
20
|
+
|
|
21
|
+
export interface GridSorterCustomEventMap {
|
|
22
|
+
'sorter-changed': GridSorterChangedEvent;
|
|
23
|
+
|
|
24
|
+
'direction-changed': GridSorterDirectionChangedEvent;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface GridSorterEventMap extends HTMLElementEventMap, GridSorterCustomEventMap {}
|
|
11
28
|
|
|
12
29
|
/**
|
|
13
30
|
* `<vaadin-grid-sorter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
|
|
@@ -48,7 +65,19 @@ export * from './vaadin-grid-sorter-mixin.js';
|
|
|
48
65
|
* @fires {CustomEvent} direction-changed - Fired when the `direction` property changes.
|
|
49
66
|
* @fires {CustomEvent} sorter-changed - Fired when the `path` or `direction` property changes.
|
|
50
67
|
*/
|
|
51
|
-
declare class GridSorter extends
|
|
68
|
+
declare class GridSorter extends ThemableMixin(DirMixin(HTMLElement)) {
|
|
69
|
+
/**
|
|
70
|
+
* JS Path of the property in the item used for sorting the data.
|
|
71
|
+
*/
|
|
72
|
+
path: string | null | undefined;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* How to sort the data.
|
|
76
|
+
* Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
|
|
77
|
+
* descending direction, or `null` for not sorting the data.
|
|
78
|
+
*/
|
|
79
|
+
direction: GridSorterDirection | null | undefined;
|
|
80
|
+
|
|
52
81
|
addEventListener<K extends keyof GridSorterEventMap>(
|
|
53
82
|
type: K,
|
|
54
83
|
listener: (this: GridSorter, ev: GridSorterEventMap[K]) => void,
|
|
@@ -7,7 +7,21 @@ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
|
7
7
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
8
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
9
9
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
const template = document.createElement('template');
|
|
12
|
+
|
|
13
|
+
template.innerHTML = `
|
|
14
|
+
<style>
|
|
15
|
+
@font-face {
|
|
16
|
+
font-family: 'vaadin-grid-sorter-icons';
|
|
17
|
+
src: url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAQwAA0AAAAABuwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAAEFAAAABkAAAAcfep+mUdERUYAAAP4AAAAHAAAAB4AJwAOT1MvMgAAAZgAAAA/AAAAYA8TBPpjbWFwAAAB7AAAAFUAAAFeF1fZ4mdhc3AAAAPwAAAACAAAAAgAAAAQZ2x5ZgAAAlgAAABcAAAAnMvguMloZWFkAAABMAAAAC8AAAA2C5Ap72hoZWEAAAFgAAAAHQAAACQGbQPHaG10eAAAAdgAAAAUAAAAHAoAAABsb2NhAAACRAAAABIAAAASAIwAYG1heHAAAAGAAAAAFgAAACAACwAKbmFtZQAAArQAAAECAAACZxWCgKhwb3N0AAADuAAAADUAAABZCrApUXicY2BkYGAA4rDECVrx/DZfGbhZGEDgyqNPOxH0/wNMq5kPALkcDEwgUQBWRA0dAHicY2BkYGA+8P8AAwMLAwgwrWZgZEAFbABY4QM8AAAAeJxjYGRgYOAAQiYGEICQSAAAAi8AFgAAeJxjYGY6yziBgZWBgWkm0xkGBoZ+CM34msGYkZMBFTAKoAkwODAwvmRiPvD/AIMDMxCD1CDJKjAwAgBktQsXAHicY2GAAMZQCM0EwqshbAALxAEKeJxjYGBgZoBgGQZGBhCIAPIYwXwWBhsgzcXAwcAEhIwMCi+Z/v/9/x+sSuElA4T9/4k4K1gHFwMMMILMY2QDYmaoABOQYGJABUA7WBiGNwAAJd4NIQAAAAAAAAAACAAIABAAGAAmAEAATgAAeJyNjLENgDAMBP9tIURJwQCMQccSZgk2i5fIYBDAidJjycXr7x5EPwE2wY8si7jmyBNXGo/bNBerxJNrpxhbO3/fEFpx8ZICpV+ghxJ74fAMe+h7Ox14AbrsHB14nK2QQWrDMBRER4mTkhQK3ZRQKOgCNk7oGQqhhEIX2WSlWEI1BAlkJ5CDdNsj5Ey9Rncdi38ES+jzNJo/HwTgATcoDEthhY3wBHc4CE+pfwsX5F/hGe7Vo/AcK/UhvMSz+mGXKhZU6pww8ISz3oWn1BvhgnwTnuEJf8Jz1OpFeIlX9YULDLdFi4ASHolkSR0iuYdjLak1vAequBhj21D61Nqyi6l3qWybGPjySbPHGScGJl6dP58MYcQRI0bts7mjebBqrFENH7t3qWtj0OuqHnXcW7b0HOTZFnKryRGW2hFX1m0O2vEM3opNMfTau+CS6Z3Vx6veNnEXY6jwDxhsc2gAAHicY2BiwA84GBgYmRiYGJkZmBlZGFkZ2djScyoLMgzZS/MyDQwMwLSrpYEBlIbxjQDrzgsuAAAAAAEAAf//AA94nGNgZGBg4AFiMSBmYmAEQnYgZgHzGAAD6wA2eJxjYGBgZACCKyoz1cD0o087YTQATOcIewAAAA==) format('woff');
|
|
18
|
+
font-weight: normal;
|
|
19
|
+
font-style: normal;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
document.head.appendChild(template.content);
|
|
11
25
|
|
|
12
26
|
/**
|
|
13
27
|
* `<vaadin-grid-sorter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
|
|
@@ -50,13 +64,50 @@ import { GridSorterMixin } from './vaadin-grid-sorter-mixin.js';
|
|
|
50
64
|
*
|
|
51
65
|
* @customElement
|
|
52
66
|
* @extends HTMLElement
|
|
53
|
-
* @mixes GridSorterMixin
|
|
54
|
-
* @mixes ThemableMixin
|
|
55
|
-
* @mixes DirMixin
|
|
56
67
|
*/
|
|
57
|
-
class GridSorter extends
|
|
68
|
+
class GridSorter extends ThemableMixin(DirMixin(PolymerElement)) {
|
|
58
69
|
static get template() {
|
|
59
70
|
return html`
|
|
71
|
+
<style>
|
|
72
|
+
:host {
|
|
73
|
+
display: inline-flex;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
max-width: 100%;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
[part='content'] {
|
|
79
|
+
flex: 1 1 auto;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
[part='indicators'] {
|
|
83
|
+
position: relative;
|
|
84
|
+
align-self: center;
|
|
85
|
+
flex: none;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
[part='order'] {
|
|
89
|
+
display: inline;
|
|
90
|
+
vertical-align: super;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
[part='indicators']::before {
|
|
94
|
+
font-family: 'vaadin-grid-sorter-icons';
|
|
95
|
+
display: inline-block;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
:host(:not([direction])) [part='indicators']::before {
|
|
99
|
+
content: '\\e901';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
:host([direction='asc']) [part='indicators']::before {
|
|
103
|
+
content: '\\e900';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
:host([direction='desc']) [part='indicators']::before {
|
|
107
|
+
content: '\\e902';
|
|
108
|
+
}
|
|
109
|
+
</style>
|
|
110
|
+
|
|
60
111
|
<div part="content">
|
|
61
112
|
<slot></slot>
|
|
62
113
|
</div>
|
|
@@ -69,6 +120,131 @@ class GridSorter extends GridSorterMixin(ThemableMixin(DirMixin(PolymerElement))
|
|
|
69
120
|
static get is() {
|
|
70
121
|
return 'vaadin-grid-sorter';
|
|
71
122
|
}
|
|
123
|
+
|
|
124
|
+
static get properties() {
|
|
125
|
+
return {
|
|
126
|
+
/**
|
|
127
|
+
* JS Path of the property in the item used for sorting the data.
|
|
128
|
+
*/
|
|
129
|
+
path: String,
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* How to sort the data.
|
|
133
|
+
* Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
|
|
134
|
+
* descending direction, or `null` for not sorting the data.
|
|
135
|
+
* @type {GridSorterDirection | undefined}
|
|
136
|
+
*/
|
|
137
|
+
direction: {
|
|
138
|
+
type: String,
|
|
139
|
+
reflectToAttribute: true,
|
|
140
|
+
notify: true,
|
|
141
|
+
value: null,
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @type {number | null}
|
|
146
|
+
* @protected
|
|
147
|
+
*/
|
|
148
|
+
_order: {
|
|
149
|
+
type: Number,
|
|
150
|
+
value: null,
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
/** @private */
|
|
154
|
+
_isConnected: {
|
|
155
|
+
type: Boolean,
|
|
156
|
+
observer: '__isConnectedChanged',
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
static get observers() {
|
|
162
|
+
return ['_pathOrDirectionChanged(path, direction)'];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** @protected */
|
|
166
|
+
ready() {
|
|
167
|
+
super.ready();
|
|
168
|
+
this.addEventListener('click', this._onClick.bind(this));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** @protected */
|
|
172
|
+
connectedCallback() {
|
|
173
|
+
super.connectedCallback();
|
|
174
|
+
this._isConnected = true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** @protected */
|
|
178
|
+
disconnectedCallback() {
|
|
179
|
+
super.disconnectedCallback();
|
|
180
|
+
this._isConnected = false;
|
|
181
|
+
|
|
182
|
+
if (!this.parentNode && this._grid) {
|
|
183
|
+
this._grid.__removeSorters([this]);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** @private */
|
|
188
|
+
_pathOrDirectionChanged() {
|
|
189
|
+
this.__dispatchSorterChangedEvenIfPossible();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** @private */
|
|
193
|
+
__isConnectedChanged(newValue, oldValue) {
|
|
194
|
+
if (oldValue === false) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this.__dispatchSorterChangedEvenIfPossible();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** @private */
|
|
202
|
+
__dispatchSorterChangedEvenIfPossible() {
|
|
203
|
+
if (this.path === undefined || this.direction === undefined || !this._isConnected) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
this.dispatchEvent(
|
|
208
|
+
new CustomEvent('sorter-changed', {
|
|
209
|
+
detail: { shiftClick: Boolean(this._shiftClick), fromSorterClick: Boolean(this._fromSorterClick) },
|
|
210
|
+
bubbles: true,
|
|
211
|
+
composed: true,
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
// Cleaning up as a programatically sorting can be done after some user interaction
|
|
215
|
+
this._fromSorterClick = false;
|
|
216
|
+
this._shiftClick = false;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** @private */
|
|
220
|
+
_getDisplayOrder(order) {
|
|
221
|
+
return order === null ? '' : order + 1;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** @private */
|
|
225
|
+
_onClick(e) {
|
|
226
|
+
if (e.defaultPrevented) {
|
|
227
|
+
// Something else has already handled the click event, do nothing.
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const activeElement = this.getRootNode().activeElement;
|
|
232
|
+
if (this !== activeElement && this.contains(activeElement)) {
|
|
233
|
+
// Some focusable content inside the sorter was clicked, do nothing.
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
this._shiftClick = e.shiftKey;
|
|
239
|
+
this._fromSorterClick = true;
|
|
240
|
+
if (this.direction === 'asc') {
|
|
241
|
+
this.direction = 'desc';
|
|
242
|
+
} else if (this.direction === 'desc') {
|
|
243
|
+
this.direction = null;
|
|
244
|
+
} else {
|
|
245
|
+
this.direction = 'asc';
|
|
246
|
+
}
|
|
247
|
+
}
|
|
72
248
|
}
|
|
73
249
|
|
|
74
250
|
defineCustomElement(GridSorter);
|
|
@@ -4,8 +4,7 @@
|
|
|
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 { GridTreeColumnMixinClass } from './vaadin-grid-tree-column-mixin.js';
|
|
7
|
+
import { GridColumn } from './vaadin-grid-column.js';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* `<vaadin-grid-tree-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -20,13 +19,12 @@ import type { GridTreeColumnMixinClass } from './vaadin-grid-tree-column-mixin.j
|
|
|
20
19
|
* ...
|
|
21
20
|
* ```
|
|
22
21
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
GridColumn<TItem> {}
|
|
22
|
+
declare class GridTreeColumn<TItem = GridDefaultItem> extends GridColumn<TItem> {
|
|
23
|
+
/**
|
|
24
|
+
* JS Path of the property in the item used as text content for the tree toggle.
|
|
25
|
+
*/
|
|
26
|
+
path: string | null | undefined;
|
|
27
|
+
}
|
|
30
28
|
|
|
31
29
|
declare global {
|
|
32
30
|
interface HTMLElementTagNameMap {
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import './vaadin-grid-tree-toggle.js';
|
|
7
7
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
|
+
import { get } from '@vaadin/component-base/src/path-utils.js';
|
|
8
9
|
import { GridColumn } from './vaadin-grid-column.js';
|
|
9
|
-
import { GridTreeColumnMixin } from './vaadin-grid-tree-column-mixin.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* `<vaadin-grid-tree-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -22,12 +22,91 @@ import { GridTreeColumnMixin } from './vaadin-grid-tree-column-mixin.js';
|
|
|
22
22
|
* ```
|
|
23
23
|
* @customElement
|
|
24
24
|
* @extends GridColumn
|
|
25
|
-
* @mixes GridTreeColumnMixin
|
|
26
25
|
*/
|
|
27
|
-
class GridTreeColumn extends
|
|
26
|
+
class GridTreeColumn extends GridColumn {
|
|
28
27
|
static get is() {
|
|
29
28
|
return 'vaadin-grid-tree-column';
|
|
30
29
|
}
|
|
30
|
+
|
|
31
|
+
static get properties() {
|
|
32
|
+
return {
|
|
33
|
+
/**
|
|
34
|
+
* JS Path of the property in the item used as text content for the tree toggle.
|
|
35
|
+
*/
|
|
36
|
+
path: String,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static get observers() {
|
|
41
|
+
return ['_onRendererOrBindingChanged(_renderer, _cells, _bodyContentHidden, _cells.*, path)'];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
|
|
47
|
+
this.__boundOnExpandedChanged = this.__onExpandedChanged.bind(this);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Renders the grid tree toggle to the body cell
|
|
52
|
+
*
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
__defaultRenderer(root, _column, { item, expanded, level }) {
|
|
56
|
+
let toggle = root.firstElementChild;
|
|
57
|
+
if (!toggle) {
|
|
58
|
+
toggle = document.createElement('vaadin-grid-tree-toggle');
|
|
59
|
+
toggle.addEventListener('expanded-changed', this.__boundOnExpandedChanged);
|
|
60
|
+
root.appendChild(toggle);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
toggle.__item = item;
|
|
64
|
+
toggle.__rendererExpanded = expanded;
|
|
65
|
+
toggle.expanded = expanded;
|
|
66
|
+
toggle.leaf = this.__isLeafItem(item, this._grid.itemHasChildrenPath);
|
|
67
|
+
toggle.textContent = this.__getToggleContent(this.path, item);
|
|
68
|
+
toggle.level = level;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The tree column doesn't allow to use a custom renderer
|
|
73
|
+
* to override the content of body cells.
|
|
74
|
+
* It always renders the grid tree toggle to body cells.
|
|
75
|
+
*
|
|
76
|
+
* @override
|
|
77
|
+
*/
|
|
78
|
+
_computeRenderer() {
|
|
79
|
+
return this.__defaultRenderer;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Expands or collapses the row once the tree toggle is switched.
|
|
84
|
+
* The listener handles only user-fired events.
|
|
85
|
+
*
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
__onExpandedChanged(e) {
|
|
89
|
+
// Skip if the state is changed by the renderer.
|
|
90
|
+
if (e.detail.value === e.target.__rendererExpanded) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (e.detail.value) {
|
|
95
|
+
this._grid.expandItem(e.target.__item);
|
|
96
|
+
} else {
|
|
97
|
+
this._grid.collapseItem(e.target.__item);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @private */
|
|
102
|
+
__isLeafItem(item, itemHasChildrenPath) {
|
|
103
|
+
return !item || !item[itemHasChildrenPath];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @private */
|
|
107
|
+
__getToggleContent(path, item) {
|
|
108
|
+
return path && get(path, item);
|
|
109
|
+
}
|
|
31
110
|
}
|
|
32
111
|
|
|
33
112
|
defineCustomElement(GridTreeColumn);
|
|
@@ -5,10 +5,17 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
7
7
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
8
|
-
import type { GridTreeToggleEventMap } from './vaadin-grid-tree-toggle-mixin.js';
|
|
9
|
-
import { GridTreeToggleMixin } from './vaadin-grid-tree-toggle-mixin.js';
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Fired when the `expanded` property changes.
|
|
11
|
+
*/
|
|
12
|
+
export type GridTreeToggleExpandedChangedEvent = CustomEvent<{ value: boolean }>;
|
|
13
|
+
|
|
14
|
+
export interface GridTreeToggleCustomEventMap {
|
|
15
|
+
'expanded-changed': GridTreeToggleExpandedChangedEvent;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GridTreeToggleEventMap extends HTMLElementEventMap, GridTreeToggleCustomEventMap {}
|
|
12
19
|
|
|
13
20
|
/**
|
|
14
21
|
* `<vaadin-grid-tree-toggle>` is a helper element for the `<vaadin-grid>`
|
|
@@ -58,7 +65,23 @@ export * from './vaadin-grid-tree-toggle-mixin.js';
|
|
|
58
65
|
*
|
|
59
66
|
* @fires {CustomEvent} expanded-changed - Fired when the `expanded` property changes.
|
|
60
67
|
*/
|
|
61
|
-
declare class GridTreeToggle extends
|
|
68
|
+
declare class GridTreeToggle extends ThemableMixin(DirMixin(HTMLElement)) {
|
|
69
|
+
/**
|
|
70
|
+
* Current level of the tree represented with a horizontal offset
|
|
71
|
+
* of the toggle button.
|
|
72
|
+
*/
|
|
73
|
+
level: number;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Hides the toggle icon and disables toggling a tree sublevel.
|
|
77
|
+
*/
|
|
78
|
+
leaf: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Sublevel toggle state.
|
|
82
|
+
*/
|
|
83
|
+
expanded: boolean;
|
|
84
|
+
|
|
62
85
|
addEventListener<K extends keyof GridTreeToggleEventMap>(
|
|
63
86
|
type: K,
|
|
64
87
|
listener: (this: GridTreeToggle, ev: GridTreeToggleEventMap[K]) => void,
|