@vaadin/grid 22.0.0-alpha7
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/LICENSE +190 -0
- package/README.md +79 -0
- package/all-imports.js +1 -0
- package/package.json +58 -0
- package/src/all-imports.js +14 -0
- package/src/array-data-provider.js +145 -0
- package/src/interfaces.d.ts +75 -0
- package/src/vaadin-grid-a11y-mixin.js +158 -0
- package/src/vaadin-grid-active-item-mixin.d.ts +19 -0
- package/src/vaadin-grid-active-item-mixin.js +117 -0
- package/src/vaadin-grid-array-data-provider-mixin.d.ts +16 -0
- package/src/vaadin-grid-array-data-provider-mixin.js +75 -0
- package/src/vaadin-grid-column-group.d.ts +54 -0
- package/src/vaadin-grid-column-group.js +320 -0
- package/src/vaadin-grid-column-reordering-mixin.d.ts +19 -0
- package/src/vaadin-grid-column-reordering-mixin.js +387 -0
- package/src/vaadin-grid-column-resizing-mixin.js +111 -0
- package/src/vaadin-grid-column.d.ts +133 -0
- package/src/vaadin-grid-column.js +745 -0
- package/src/vaadin-grid-data-provider-mixin.d.ts +108 -0
- package/src/vaadin-grid-data-provider-mixin.js +520 -0
- package/src/vaadin-grid-drag-and-drop-mixin.d.ts +69 -0
- package/src/vaadin-grid-drag-and-drop-mixin.js +433 -0
- package/src/vaadin-grid-dynamic-columns-mixin.js +180 -0
- package/src/vaadin-grid-event-context-mixin.d.ts +33 -0
- package/src/vaadin-grid-event-context-mixin.js +57 -0
- package/src/vaadin-grid-filter-column.d.ts +35 -0
- package/src/vaadin-grid-filter-column.js +120 -0
- package/src/vaadin-grid-filter-mixin.js +76 -0
- package/src/vaadin-grid-filter.d.ts +67 -0
- package/src/vaadin-grid-filter.js +125 -0
- package/src/vaadin-grid-helpers.js +23 -0
- package/src/vaadin-grid-keyboard-navigation-mixin.js +891 -0
- package/src/vaadin-grid-row-details-mixin.d.ts +44 -0
- package/src/vaadin-grid-row-details-mixin.js +200 -0
- package/src/vaadin-grid-scroll-mixin.d.ts +18 -0
- package/src/vaadin-grid-scroll-mixin.js +202 -0
- package/src/vaadin-grid-selection-column.d.ts +71 -0
- package/src/vaadin-grid-selection-column.js +285 -0
- package/src/vaadin-grid-selection-mixin.d.ts +30 -0
- package/src/vaadin-grid-selection-mixin.js +93 -0
- package/src/vaadin-grid-sort-column.d.ts +63 -0
- package/src/vaadin-grid-sort-column.js +118 -0
- package/src/vaadin-grid-sort-mixin.d.ts +15 -0
- package/src/vaadin-grid-sort-mixin.js +139 -0
- package/src/vaadin-grid-sorter.d.ts +94 -0
- package/src/vaadin-grid-sorter.js +230 -0
- package/src/vaadin-grid-styles.js +297 -0
- package/src/vaadin-grid-styling-mixin.d.ts +37 -0
- package/src/vaadin-grid-styling-mixin.js +71 -0
- package/src/vaadin-grid-tree-column.d.ts +36 -0
- package/src/vaadin-grid-tree-column.js +119 -0
- package/src/vaadin-grid-tree-toggle.d.ts +104 -0
- package/src/vaadin-grid-tree-toggle.js +205 -0
- package/src/vaadin-grid.d.ts +397 -0
- package/src/vaadin-grid.js +1004 -0
- package/theme/lumo/all-imports.js +11 -0
- package/theme/lumo/vaadin-grid-column-group.js +1 -0
- package/theme/lumo/vaadin-grid-column.js +1 -0
- package/theme/lumo/vaadin-grid-filter-column.js +2 -0
- package/theme/lumo/vaadin-grid-filter.js +2 -0
- package/theme/lumo/vaadin-grid-selection-column.js +2 -0
- package/theme/lumo/vaadin-grid-sort-column.js +2 -0
- package/theme/lumo/vaadin-grid-sorter-styles.js +53 -0
- package/theme/lumo/vaadin-grid-sorter.js +2 -0
- package/theme/lumo/vaadin-grid-styles.js +378 -0
- package/theme/lumo/vaadin-grid-tree-column.js +2 -0
- package/theme/lumo/vaadin-grid-tree-toggle-styles.js +112 -0
- package/theme/lumo/vaadin-grid-tree-toggle.js +2 -0
- package/theme/lumo/vaadin-grid.js +9 -0
- package/theme/material/all-imports.js +11 -0
- package/theme/material/vaadin-grid-column-group.js +1 -0
- package/theme/material/vaadin-grid-column.js +1 -0
- package/theme/material/vaadin-grid-filter-column.js +2 -0
- package/theme/material/vaadin-grid-filter.js +2 -0
- package/theme/material/vaadin-grid-selection-column.js +2 -0
- package/theme/material/vaadin-grid-sort-column.js +2 -0
- package/theme/material/vaadin-grid-sorter-styles.js +72 -0
- package/theme/material/vaadin-grid-sorter.js +2 -0
- package/theme/material/vaadin-grid-styles.js +252 -0
- package/theme/material/vaadin-grid-tree-column.js +2 -0
- package/theme/material/vaadin-grid-tree-toggle-styles.js +42 -0
- package/theme/material/vaadin-grid-tree-toggle.js +2 -0
- package/theme/material/vaadin-grid.js +2 -0
- package/vaadin-grid-column-group.d.ts +1 -0
- package/vaadin-grid-column-group.js +3 -0
- package/vaadin-grid-column.d.ts +1 -0
- package/vaadin-grid-column.js +3 -0
- package/vaadin-grid-filter-column.d.ts +1 -0
- package/vaadin-grid-filter-column.js +3 -0
- package/vaadin-grid-filter.d.ts +1 -0
- package/vaadin-grid-filter.js +3 -0
- package/vaadin-grid-selection-column.d.ts +1 -0
- package/vaadin-grid-selection-column.js +3 -0
- package/vaadin-grid-sort-column.d.ts +1 -0
- package/vaadin-grid-sort-column.js +3 -0
- package/vaadin-grid-sorter.d.ts +1 -0
- package/vaadin-grid-sorter.js +3 -0
- package/vaadin-grid-tree-column.d.ts +1 -0
- package/vaadin-grid-tree-column.js +3 -0
- package/vaadin-grid-tree-toggle.d.ts +1 -0
- package/vaadin-grid-tree-toggle.js +3 -0
- package/vaadin-grid.d.ts +3 -0
- package/vaadin-grid.js +4 -0
|
@@ -0,0 +1,297 @@
|
|
|
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
|
+
import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
|
|
7
|
+
|
|
8
|
+
registerStyles(
|
|
9
|
+
'vaadin-grid',
|
|
10
|
+
css`
|
|
11
|
+
@keyframes vaadin-grid-appear {
|
|
12
|
+
to {
|
|
13
|
+
opacity: 1;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
:host {
|
|
18
|
+
display: block;
|
|
19
|
+
animation: 1ms vaadin-grid-appear;
|
|
20
|
+
height: 400px;
|
|
21
|
+
flex: 1 1 auto;
|
|
22
|
+
align-self: stretch;
|
|
23
|
+
position: relative;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:host([hidden]) {
|
|
27
|
+
display: none !important;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#scroller {
|
|
31
|
+
display: block;
|
|
32
|
+
transform: translateY(0);
|
|
33
|
+
width: auto;
|
|
34
|
+
height: auto;
|
|
35
|
+
position: absolute;
|
|
36
|
+
top: 0;
|
|
37
|
+
right: 0;
|
|
38
|
+
bottom: 0;
|
|
39
|
+
left: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
:host([all-rows-visible]) {
|
|
43
|
+
height: auto;
|
|
44
|
+
align-self: flex-start;
|
|
45
|
+
flex-grow: 0;
|
|
46
|
+
width: 100%;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
:host([all-rows-visible]) #scroller {
|
|
50
|
+
width: 100%;
|
|
51
|
+
height: 100%;
|
|
52
|
+
position: relative;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
:host([all-rows-visible]) #items {
|
|
56
|
+
min-height: 1px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#table {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: column;
|
|
62
|
+
width: 100%;
|
|
63
|
+
height: 100%;
|
|
64
|
+
overflow: auto;
|
|
65
|
+
position: relative;
|
|
66
|
+
outline: none;
|
|
67
|
+
/* Workaround for a Desktop Safari bug: new stacking context here prevents the scrollbar from getting hidden */
|
|
68
|
+
z-index: 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#header,
|
|
72
|
+
#footer {
|
|
73
|
+
transform: translateX(var(--_grid-horizontal-scroll-position));
|
|
74
|
+
display: block;
|
|
75
|
+
position: -webkit-sticky;
|
|
76
|
+
position: sticky;
|
|
77
|
+
left: 0;
|
|
78
|
+
overflow: visible;
|
|
79
|
+
width: 100%;
|
|
80
|
+
z-index: 1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#header {
|
|
84
|
+
top: 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
th {
|
|
88
|
+
text-align: inherit;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Safari doesn't work with "inherit" */
|
|
92
|
+
[safari] th {
|
|
93
|
+
text-align: initial;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#footer {
|
|
97
|
+
bottom: 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#items {
|
|
101
|
+
transform: translateX(var(--_grid-horizontal-scroll-position));
|
|
102
|
+
flex-grow: 1;
|
|
103
|
+
flex-shrink: 0;
|
|
104
|
+
display: block;
|
|
105
|
+
position: -webkit-sticky;
|
|
106
|
+
position: sticky;
|
|
107
|
+
width: 100%;
|
|
108
|
+
left: 0;
|
|
109
|
+
overflow: visible;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[part~='row'] {
|
|
113
|
+
display: flex;
|
|
114
|
+
width: 100%;
|
|
115
|
+
box-sizing: border-box;
|
|
116
|
+
margin: 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
[part~='row'][loading] [part~='body-cell'] ::slotted(vaadin-grid-cell-content) {
|
|
120
|
+
opacity: 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
#items [part~='row'] {
|
|
124
|
+
position: absolute;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#items [part~='row']:empty {
|
|
128
|
+
height: 100%;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[part~='cell']:not([part~='details-cell']) {
|
|
132
|
+
flex-shrink: 0;
|
|
133
|
+
flex-grow: 1;
|
|
134
|
+
box-sizing: border-box;
|
|
135
|
+
display: flex;
|
|
136
|
+
width: 100%;
|
|
137
|
+
position: relative;
|
|
138
|
+
align-items: center;
|
|
139
|
+
padding: 0;
|
|
140
|
+
white-space: nowrap;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
[part~='details-cell'] {
|
|
144
|
+
position: absolute;
|
|
145
|
+
bottom: 0;
|
|
146
|
+
width: 100%;
|
|
147
|
+
box-sizing: border-box;
|
|
148
|
+
padding: 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
[part~='cell'] ::slotted(vaadin-grid-cell-content) {
|
|
152
|
+
display: block;
|
|
153
|
+
width: 100%;
|
|
154
|
+
box-sizing: border-box;
|
|
155
|
+
overflow: hidden;
|
|
156
|
+
text-overflow: ellipsis;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
[hidden] {
|
|
160
|
+
display: none !important;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
[frozen] {
|
|
164
|
+
z-index: 2;
|
|
165
|
+
transform: translateX(calc(-1 * var(--_grid-horizontal-scroll-position)));
|
|
166
|
+
will-change: transform;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
[no-scrollbars][safari] #table,
|
|
170
|
+
[no-scrollbars][firefox] #table {
|
|
171
|
+
overflow: hidden;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* Reordering styles */
|
|
175
|
+
:host([reordering]) [part~='cell'] ::slotted(vaadin-grid-cell-content),
|
|
176
|
+
:host([reordering]) [part~='resize-handle'],
|
|
177
|
+
#scroller[no-content-pointer-events] [part~='cell'] ::slotted(vaadin-grid-cell-content) {
|
|
178
|
+
pointer-events: none;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
[part~='reorder-ghost'] {
|
|
182
|
+
visibility: hidden;
|
|
183
|
+
position: fixed;
|
|
184
|
+
pointer-events: none;
|
|
185
|
+
opacity: 0.5;
|
|
186
|
+
|
|
187
|
+
/* Prevent overflowing the grid in Firefox */
|
|
188
|
+
top: 0;
|
|
189
|
+
left: 0;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
:host([reordering]) {
|
|
193
|
+
-moz-user-select: none;
|
|
194
|
+
-webkit-user-select: none;
|
|
195
|
+
user-select: none;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* Resizing styles */
|
|
199
|
+
[part~='resize-handle'] {
|
|
200
|
+
position: absolute;
|
|
201
|
+
top: 0;
|
|
202
|
+
right: 0;
|
|
203
|
+
height: 100%;
|
|
204
|
+
cursor: col-resize;
|
|
205
|
+
z-index: 1;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
[part~='resize-handle']::before {
|
|
209
|
+
position: absolute;
|
|
210
|
+
content: '';
|
|
211
|
+
height: 100%;
|
|
212
|
+
width: 35px;
|
|
213
|
+
transform: translateX(-50%);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
[last-column] [part~='resize-handle']::before,
|
|
217
|
+
[last-frozen] [part~='resize-handle']::before {
|
|
218
|
+
width: 18px;
|
|
219
|
+
transform: none;
|
|
220
|
+
right: 0;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#scroller[column-resizing] {
|
|
224
|
+
-ms-user-select: none;
|
|
225
|
+
-moz-user-select: none;
|
|
226
|
+
-webkit-user-select: none;
|
|
227
|
+
user-select: none;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/* Sizer styles */
|
|
231
|
+
#sizer {
|
|
232
|
+
display: flex;
|
|
233
|
+
position: absolute;
|
|
234
|
+
visibility: hidden;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#sizer [part~='details-cell'] {
|
|
238
|
+
display: none !important;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#sizer [part~='cell'][hidden] {
|
|
242
|
+
display: none !important;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
#sizer [part~='cell'] {
|
|
246
|
+
display: block;
|
|
247
|
+
flex-shrink: 0;
|
|
248
|
+
line-height: 0;
|
|
249
|
+
height: 0 !important;
|
|
250
|
+
min-height: 0 !important;
|
|
251
|
+
max-height: 0 !important;
|
|
252
|
+
padding: 0 !important;
|
|
253
|
+
border: none !important;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
#sizer [part~='cell']::before {
|
|
257
|
+
content: '-';
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
#sizer [part~='cell'] ::slotted(vaadin-grid-cell-content) {
|
|
261
|
+
display: none !important;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* RTL specific styles */
|
|
265
|
+
|
|
266
|
+
:host([dir='rtl']) *:is(#items, #header, #footer, [frozen]) {
|
|
267
|
+
transform: none;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
:host([dir='rtl']) #items,
|
|
271
|
+
:host([dir='rtl']) #header,
|
|
272
|
+
:host([dir='rtl']) #footer {
|
|
273
|
+
left: auto;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
:host([dir='rtl']) [part~='reorder-ghost'] {
|
|
277
|
+
left: auto;
|
|
278
|
+
right: 0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
:host([dir='rtl']) [part~='resize-handle'] {
|
|
282
|
+
left: 0;
|
|
283
|
+
right: auto;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
:host([dir='rtl']) [part~='resize-handle']::before {
|
|
287
|
+
transform: translateX(50%);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
:host([dir='rtl']) [last-column] [part~='resize-handle']::before,
|
|
291
|
+
:host([dir='rtl']) [last-frozen] [part~='resize-handle']::before {
|
|
292
|
+
left: 0;
|
|
293
|
+
right: auto;
|
|
294
|
+
}
|
|
295
|
+
`,
|
|
296
|
+
{ moduleId: 'vaadin-grid-styles' }
|
|
297
|
+
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GridCellClassNameGenerator } from './interfaces';
|
|
2
|
+
|
|
3
|
+
declare function StylingMixin<TItem, T extends new (...args: any[]) => {}>(base: T): T & StylingMixinConstructor<TItem>;
|
|
4
|
+
|
|
5
|
+
interface StylingMixinConstructor<TItem> {
|
|
6
|
+
new (...args: any[]): StylingMixin<TItem>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface StylingMixin<TItem> {
|
|
10
|
+
/**
|
|
11
|
+
* A function that allows generating CSS class names for grid cells
|
|
12
|
+
* based on their row and column. The return value should be the generated
|
|
13
|
+
* class name as a string, or multiple class names separated by whitespace
|
|
14
|
+
* characters.
|
|
15
|
+
*
|
|
16
|
+
* Receives two arguments:
|
|
17
|
+
* - `column` The `<vaadin-grid-column>` element (`undefined` for details-cell).
|
|
18
|
+
* - `model` The object with the properties related with
|
|
19
|
+
* the rendered item, contains:
|
|
20
|
+
* - `model.index` The index of the item.
|
|
21
|
+
* - `model.item` The item.
|
|
22
|
+
* - `model.expanded` Sublevel toggle state.
|
|
23
|
+
* - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
|
|
24
|
+
* - `model.selected` Selected state.
|
|
25
|
+
*/
|
|
26
|
+
cellClassNameGenerator: GridCellClassNameGenerator<TItem> | null | undefined;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Runs the `cellClassNameGenerator` for the visible cells.
|
|
30
|
+
* If the generator depends on varying conditions, you need to
|
|
31
|
+
* call this function manually in order to update the styles when
|
|
32
|
+
* the conditions change.
|
|
33
|
+
*/
|
|
34
|
+
generateCellClassNames(): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { StylingMixin, StylingMixinConstructor };
|
|
@@ -0,0 +1,71 @@
|
|
|
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 StylingMixin = (superClass) =>
|
|
11
|
+
class StylingMixin extends superClass {
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
/**
|
|
15
|
+
* A function that allows generating CSS class names for grid cells
|
|
16
|
+
* based on their row and column. The return value should be the generated
|
|
17
|
+
* class name as a string, or multiple class names separated by whitespace
|
|
18
|
+
* characters.
|
|
19
|
+
*
|
|
20
|
+
* Receives two arguments:
|
|
21
|
+
* - `column` The `<vaadin-grid-column>` element (`undefined` for details-cell).
|
|
22
|
+
* - `model` The object with the properties related with
|
|
23
|
+
* the rendered item, contains:
|
|
24
|
+
* - `model.index` The index of the item.
|
|
25
|
+
* - `model.item` The item.
|
|
26
|
+
* - `model.expanded` Sublevel toggle state.
|
|
27
|
+
* - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
|
|
28
|
+
* - `model.selected` Selected state.
|
|
29
|
+
*
|
|
30
|
+
* @type {GridCellClassNameGenerator | null | undefined}
|
|
31
|
+
*/
|
|
32
|
+
cellClassNameGenerator: Function
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static get observers() {
|
|
37
|
+
return ['__cellClassNameGeneratorChanged(cellClassNameGenerator)'];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
__cellClassNameGeneratorChanged() {
|
|
41
|
+
this.generateCellClassNames();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Runs the `cellClassNameGenerator` for the visible cells.
|
|
46
|
+
* If the generator depends on varying conditions, you need to
|
|
47
|
+
* call this function manually in order to update the styles when
|
|
48
|
+
* the conditions change.
|
|
49
|
+
*/
|
|
50
|
+
generateCellClassNames() {
|
|
51
|
+
Array.from(this.$.items.children)
|
|
52
|
+
.filter((row) => !row.hidden)
|
|
53
|
+
.forEach((row) => this._generateCellClassNames(row, this.__getRowModel(row)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @private */
|
|
57
|
+
_generateCellClassNames(row, model) {
|
|
58
|
+
Array.from(row.children).forEach((cell) => {
|
|
59
|
+
if (cell.__generatedClasses) {
|
|
60
|
+
cell.__generatedClasses.forEach((className) => cell.classList.remove(className));
|
|
61
|
+
}
|
|
62
|
+
if (this.cellClassNameGenerator) {
|
|
63
|
+
const result = this.cellClassNameGenerator(cell._column, model);
|
|
64
|
+
cell.__generatedClasses = result && result.split(' ').filter((className) => className.length > 0);
|
|
65
|
+
if (cell.__generatedClasses) {
|
|
66
|
+
cell.__generatedClasses.forEach((className) => cell.classList.add(className));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GridDefaultItem } from './interfaces';
|
|
2
|
+
import { GridColumn } from './vaadin-grid-column.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `<vaadin-grid-tree-column>` is a helper element for the `<vaadin-grid>`
|
|
6
|
+
* that provides default renderer and functionality for toggling tree/hierarchical items.
|
|
7
|
+
*
|
|
8
|
+
* #### Example:
|
|
9
|
+
* ```html
|
|
10
|
+
* <vaadin-grid items="[[items]]">
|
|
11
|
+
* <vaadin-grid-tree-column path="name.first"></vaadin-grid-tree-column>
|
|
12
|
+
*
|
|
13
|
+
* <vaadin-grid-column>
|
|
14
|
+
* ...
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare class GridTreeColumn<TItem = GridDefaultItem> extends GridColumn<TItem> {
|
|
18
|
+
/**
|
|
19
|
+
* JS Path of the property in the item used as text content for the tree toggle.
|
|
20
|
+
*/
|
|
21
|
+
path: string | null | undefined;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* JS Path of the property in the item that indicates whether the item has child items.
|
|
25
|
+
* @attr {string} item-has-children-path
|
|
26
|
+
*/
|
|
27
|
+
itemHasChildrenPath: string | null | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare global {
|
|
31
|
+
interface HTMLElementTagNameMap {
|
|
32
|
+
'vaadin-grid-tree-column': GridTreeColumn<GridDefaultItem>;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { GridTreeColumn };
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
import { GridColumn } from './vaadin-grid-column.js';
|
|
7
|
+
import './vaadin-grid-tree-toggle.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `<vaadin-grid-tree-column>` is a helper element for the `<vaadin-grid>`
|
|
11
|
+
* that provides default renderer and functionality for toggling tree/hierarchical items.
|
|
12
|
+
*
|
|
13
|
+
* #### Example:
|
|
14
|
+
* ```html
|
|
15
|
+
* <vaadin-grid items="[[items]]">
|
|
16
|
+
* <vaadin-grid-tree-column path="name.first"></vaadin-grid-tree-column>
|
|
17
|
+
*
|
|
18
|
+
* <vaadin-grid-column>
|
|
19
|
+
* ...
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
class GridTreeColumn extends GridColumn {
|
|
23
|
+
static get is() {
|
|
24
|
+
return 'vaadin-grid-tree-column';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static get properties() {
|
|
28
|
+
return {
|
|
29
|
+
/**
|
|
30
|
+
* JS Path of the property in the item used as text content for the tree toggle.
|
|
31
|
+
*/
|
|
32
|
+
path: String,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* JS Path of the property in the item that indicates whether the item has child items.
|
|
36
|
+
* @attr {string} item-has-children-path
|
|
37
|
+
*/
|
|
38
|
+
itemHasChildrenPath: {
|
|
39
|
+
type: String,
|
|
40
|
+
value: 'children'
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static get observers() {
|
|
46
|
+
return ['_onRendererOrBindingChanged(_renderer, _cells, _cells.*, path, itemHasChildrenPath)'];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
constructor() {
|
|
50
|
+
super();
|
|
51
|
+
|
|
52
|
+
this.__boundOnExpandedChanged = this.__onExpandedChanged.bind(this);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Renders the grid tree toggle to the body cell
|
|
57
|
+
*
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
__defaultRenderer(root, _column, { item, expanded, level }) {
|
|
61
|
+
let toggle = root.firstElementChild;
|
|
62
|
+
if (!toggle) {
|
|
63
|
+
toggle = document.createElement('vaadin-grid-tree-toggle');
|
|
64
|
+
toggle.addEventListener('expanded-changed', this.__boundOnExpandedChanged);
|
|
65
|
+
root.appendChild(toggle);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
toggle.__item = item;
|
|
69
|
+
toggle.__rendererExpanded = expanded;
|
|
70
|
+
toggle.expanded = expanded;
|
|
71
|
+
toggle.leaf = this.__isLeafItem(item, this.itemHasChildrenPath);
|
|
72
|
+
toggle.textContent = this.__getToggleContent(this.path, item);
|
|
73
|
+
toggle.level = level;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The tree column doesn't allow to use a custom renderer
|
|
78
|
+
* to override the content of body cells.
|
|
79
|
+
* It always renders the grid tree toggle to body cells.
|
|
80
|
+
*
|
|
81
|
+
* @override
|
|
82
|
+
*/
|
|
83
|
+
_computeRenderer() {
|
|
84
|
+
return this.__defaultRenderer;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Expands or collapses the row once the tree toggle is switched.
|
|
89
|
+
* The listener handles only user-fired events.
|
|
90
|
+
*
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
__onExpandedChanged(e) {
|
|
94
|
+
// Skip if the state is changed by the renderer.
|
|
95
|
+
if (e.detail.value === e.target.__rendererExpanded) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (e.detail.value) {
|
|
100
|
+
this._grid.expandItem(e.target.__item);
|
|
101
|
+
} else {
|
|
102
|
+
this._grid.collapseItem(e.target.__item);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @private */
|
|
107
|
+
__isLeafItem(item, itemHasChildrenPath) {
|
|
108
|
+
return !item || !item[itemHasChildrenPath];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @private */
|
|
112
|
+
__getToggleContent(path, item) {
|
|
113
|
+
return path && this.get(path, item);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
customElements.define(GridTreeColumn.is, GridTreeColumn);
|
|
118
|
+
|
|
119
|
+
export { GridTreeColumn };
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
7
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
8
|
+
|
|
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 {}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `<vaadin-grid-tree-toggle>` is a helper element for the `<vaadin-grid>`
|
|
22
|
+
* that provides toggle and level display functionality for the item tree.
|
|
23
|
+
*
|
|
24
|
+
* #### Example:
|
|
25
|
+
* ```html
|
|
26
|
+
* <vaadin-grid-column id="column"></vaadin-grid-column>
|
|
27
|
+
* ```
|
|
28
|
+
* ```js
|
|
29
|
+
* const column = document.querySelector('#column');
|
|
30
|
+
* column.renderer = (root, column, model) => {
|
|
31
|
+
* let treeToggle = root.firstElementChild;
|
|
32
|
+
* if (!treeToggle) {
|
|
33
|
+
* treeToggle = document.createElement('vaadin-grid-tree-toggle');
|
|
34
|
+
* treeToggle.addEventListener('expanded-changed', () => { ... });
|
|
35
|
+
* root.appendChild(treeToggle);
|
|
36
|
+
* }
|
|
37
|
+
* treeToggle.leaf = !model.item.hasChildren;
|
|
38
|
+
* treeToggle.level = level;
|
|
39
|
+
* treeToggle.expanded = expanded;
|
|
40
|
+
* treeToggle.textContent = model.item.name;
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* ### Styling
|
|
45
|
+
*
|
|
46
|
+
* The following shadow DOM parts are available for styling:
|
|
47
|
+
*
|
|
48
|
+
* Part name | Description
|
|
49
|
+
* ---|---
|
|
50
|
+
* `toggle` | The tree toggle icon
|
|
51
|
+
*
|
|
52
|
+
* The following state attributes are available for styling:
|
|
53
|
+
*
|
|
54
|
+
* Attribute | Description | Part name
|
|
55
|
+
* ---|---|---
|
|
56
|
+
* `expanded` | When present, the toggle is expanded | :host
|
|
57
|
+
* `leaf` | When present, the toggle is not expandable, i. e., the current item is a leaf | :host
|
|
58
|
+
*
|
|
59
|
+
* The following custom CSS properties are available on
|
|
60
|
+
* the `<vaadin-grid-tree-toggle>` element:
|
|
61
|
+
*
|
|
62
|
+
* Custom CSS property | Description | Default
|
|
63
|
+
* ---|---|---
|
|
64
|
+
* `--vaadin-grid-tree-toggle-level-offset` | Visual offset step for each tree sublevel | `1em`
|
|
65
|
+
*
|
|
66
|
+
* @fires {CustomEvent} expanded-changed - Fired when the `expanded` property changes.
|
|
67
|
+
*/
|
|
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
|
+
|
|
85
|
+
addEventListener<K extends keyof GridTreeToggleEventMap>(
|
|
86
|
+
type: K,
|
|
87
|
+
listener: (this: GridTreeToggle, ev: GridTreeToggleEventMap[K]) => void,
|
|
88
|
+
options?: boolean | AddEventListenerOptions
|
|
89
|
+
): void;
|
|
90
|
+
|
|
91
|
+
removeEventListener<K extends keyof GridTreeToggleEventMap>(
|
|
92
|
+
type: K,
|
|
93
|
+
listener: (this: GridTreeToggle, ev: GridTreeToggleEventMap[K]) => void,
|
|
94
|
+
options?: boolean | EventListenerOptions
|
|
95
|
+
): void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
declare global {
|
|
99
|
+
interface HTMLElementTagNameMap {
|
|
100
|
+
'vaadin-grid-tree-toggle': GridTreeToggle;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { GridTreeToggle };
|