@vaadin/grid 24.3.0-alpha1 → 24.3.0-alpha2

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.
@@ -0,0 +1,198 @@
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 { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
+
8
+ const template = document.createElement('template');
9
+
10
+ template.innerHTML = `
11
+ <style>
12
+ @font-face {
13
+ font-family: 'vaadin-grid-sorter-icons';
14
+ 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');
15
+ font-weight: normal;
16
+ font-style: normal;
17
+ }
18
+ </style>
19
+ `;
20
+
21
+ document.head.appendChild(template.content);
22
+
23
+ registerStyles(
24
+ 'vaadin-grid-sorter',
25
+ css`
26
+ :host {
27
+ display: inline-flex;
28
+ cursor: pointer;
29
+ max-width: 100%;
30
+ }
31
+
32
+ [part='content'] {
33
+ flex: 1 1 auto;
34
+ }
35
+
36
+ [part='indicators'] {
37
+ position: relative;
38
+ align-self: center;
39
+ flex: none;
40
+ }
41
+
42
+ [part='order'] {
43
+ display: inline;
44
+ vertical-align: super;
45
+ }
46
+
47
+ [part='indicators']::before {
48
+ font-family: 'vaadin-grid-sorter-icons';
49
+ display: inline-block;
50
+ }
51
+
52
+ :host(:not([direction])) [part='indicators']::before {
53
+ content: '\\e901';
54
+ }
55
+
56
+ :host([direction='asc']) [part='indicators']::before {
57
+ content: '\\e900';
58
+ }
59
+
60
+ :host([direction='desc']) [part='indicators']::before {
61
+ content: '\\e902';
62
+ }
63
+ `,
64
+ { moduleId: 'vaadin-grid-sorter-styles' },
65
+ );
66
+
67
+ /**
68
+ * A mixin providing common sorter functionality.
69
+ *
70
+ * @polymerMixin
71
+ */
72
+ export const GridSorterMixin = (superClass) =>
73
+ class GridSorterMixinClass extends superClass {
74
+ static get properties() {
75
+ return {
76
+ /**
77
+ * JS Path of the property in the item used for sorting the data.
78
+ */
79
+ path: String,
80
+
81
+ /**
82
+ * How to sort the data.
83
+ * Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
84
+ * descending direction, or `null` for not sorting the data.
85
+ * @type {GridSorterDirection | undefined}
86
+ */
87
+ direction: {
88
+ type: String,
89
+ reflectToAttribute: true,
90
+ notify: true,
91
+ value: null,
92
+ },
93
+
94
+ /**
95
+ * @type {number | null}
96
+ * @protected
97
+ */
98
+ _order: {
99
+ type: Number,
100
+ value: null,
101
+ },
102
+
103
+ /** @private */
104
+ _isConnected: {
105
+ type: Boolean,
106
+ observer: '__isConnectedChanged',
107
+ },
108
+ };
109
+ }
110
+
111
+ static get observers() {
112
+ return ['_pathOrDirectionChanged(path, direction)'];
113
+ }
114
+
115
+ /** @protected */
116
+ ready() {
117
+ super.ready();
118
+ this.addEventListener('click', this._onClick.bind(this));
119
+ }
120
+
121
+ /** @protected */
122
+ connectedCallback() {
123
+ super.connectedCallback();
124
+ this._isConnected = true;
125
+ }
126
+
127
+ /** @protected */
128
+ disconnectedCallback() {
129
+ super.disconnectedCallback();
130
+ this._isConnected = false;
131
+
132
+ if (!this.parentNode && this._grid) {
133
+ this._grid.__removeSorters([this]);
134
+ }
135
+ }
136
+
137
+ /** @private */
138
+ _pathOrDirectionChanged() {
139
+ this.__dispatchSorterChangedEvenIfPossible();
140
+ }
141
+
142
+ /** @private */
143
+ __isConnectedChanged(newValue, oldValue) {
144
+ if (oldValue === false) {
145
+ return;
146
+ }
147
+
148
+ this.__dispatchSorterChangedEvenIfPossible();
149
+ }
150
+
151
+ /** @private */
152
+ __dispatchSorterChangedEvenIfPossible() {
153
+ if (this.path === undefined || this.direction === undefined || !this._isConnected) {
154
+ return;
155
+ }
156
+
157
+ this.dispatchEvent(
158
+ new CustomEvent('sorter-changed', {
159
+ detail: { shiftClick: Boolean(this._shiftClick), fromSorterClick: Boolean(this._fromSorterClick) },
160
+ bubbles: true,
161
+ composed: true,
162
+ }),
163
+ );
164
+ // Cleaning up as a programatically sorting can be done after some user interaction
165
+ this._fromSorterClick = false;
166
+ this._shiftClick = false;
167
+ }
168
+
169
+ /** @private */
170
+ _getDisplayOrder(order) {
171
+ return order === null ? '' : order + 1;
172
+ }
173
+
174
+ /** @private */
175
+ _onClick(e) {
176
+ if (e.defaultPrevented) {
177
+ // Something else has already handled the click event, do nothing.
178
+ return;
179
+ }
180
+
181
+ const activeElement = this.getRootNode().activeElement;
182
+ if (this !== activeElement && this.contains(activeElement)) {
183
+ // Some focusable content inside the sorter was clicked, do nothing.
184
+ return;
185
+ }
186
+
187
+ e.preventDefault();
188
+ this._shiftClick = e.shiftKey;
189
+ this._fromSorterClick = true;
190
+ if (this.direction === 'asc') {
191
+ this.direction = 'desc';
192
+ } else if (this.direction === 'desc') {
193
+ this.direction = null;
194
+ } else {
195
+ this.direction = 'asc';
196
+ }
197
+ }
198
+ };
@@ -5,26 +5,9 @@
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';
8
9
 
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 {}
10
+ export * from './vaadin-grid-sorter-mixin.js';
28
11
 
29
12
  /**
30
13
  * `<vaadin-grid-sorter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
@@ -65,19 +48,7 @@ export interface GridSorterEventMap extends HTMLElementEventMap, GridSorterCusto
65
48
  * @fires {CustomEvent} direction-changed - Fired when the `direction` property changes.
66
49
  * @fires {CustomEvent} sorter-changed - Fired when the `path` or `direction` property changes.
67
50
  */
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
-
51
+ declare class GridSorter extends GridSorterMixin(ThemableMixin(DirMixin(HTMLElement))) {
81
52
  addEventListener<K extends keyof GridSorterEventMap>(
82
53
  type: K,
83
54
  listener: (this: GridSorter, ev: GridSorterEventMap[K]) => void,
@@ -7,21 +7,7 @@ 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
-
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);
10
+ import { GridSorterMixin } from './vaadin-grid-sorter-mixin.js';
25
11
 
26
12
  /**
27
13
  * `<vaadin-grid-sorter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
@@ -64,50 +50,13 @@ document.head.appendChild(template.content);
64
50
  *
65
51
  * @customElement
66
52
  * @extends HTMLElement
53
+ * @mixes GridSorterMixin
54
+ * @mixes ThemableMixin
55
+ * @mixes DirMixin
67
56
  */
68
- class GridSorter extends ThemableMixin(DirMixin(PolymerElement)) {
57
+ class GridSorter extends GridSorterMixin(ThemableMixin(DirMixin(PolymerElement))) {
69
58
  static get template() {
70
59
  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
-
111
60
  <div part="content">
112
61
  <slot></slot>
113
62
  </div>
@@ -120,131 +69,6 @@ class GridSorter extends ThemableMixin(DirMixin(PolymerElement)) {
120
69
  static get is() {
121
70
  return 'vaadin-grid-sorter';
122
71
  }
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
- }
248
72
  }
249
73
 
250
74
  defineCustomElement(GridSorter);
@@ -0,0 +1,19 @@
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
+ import type { Constructor } from '@open-wc/dedupe-mixin';
8
+ import type { GridColumn } from './vaadin-grid-column.js';
9
+
10
+ export declare function GridTreeColumnMixin<TItem, T extends Constructor<GridColumn>>(
11
+ superclass: T,
12
+ ): Constructor<GridTreeColumnMixinClass<TItem>> & T;
13
+
14
+ export declare class GridTreeColumnMixinClass<TItem> {
15
+ /**
16
+ * JS Path of the property in the item used as text content for the tree toggle.
17
+ */
18
+ path: string | null | undefined;
19
+ }
@@ -0,0 +1,92 @@
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 { get } from '@vaadin/component-base/src/path-utils.js';
7
+
8
+ /**
9
+ * @polymerMixin
10
+ */
11
+ export const GridTreeColumnMixin = (superClass) =>
12
+ class extends superClass {
13
+ static get properties() {
14
+ return {
15
+ /**
16
+ * JS Path of the property in the item used as text content for the tree toggle.
17
+ */
18
+ path: String,
19
+ };
20
+ }
21
+
22
+ static get observers() {
23
+ return ['_onRendererOrBindingChanged(_renderer, _cells, _bodyContentHidden, _cells.*, path)'];
24
+ }
25
+
26
+ constructor() {
27
+ super();
28
+
29
+ this.__boundOnExpandedChanged = this.__onExpandedChanged.bind(this);
30
+ }
31
+
32
+ /**
33
+ * Renders the grid tree toggle to the body cell
34
+ *
35
+ * @private
36
+ */
37
+ __defaultRenderer(root, _column, { item, expanded, level }) {
38
+ let toggle = root.firstElementChild;
39
+ if (!toggle) {
40
+ toggle = document.createElement('vaadin-grid-tree-toggle');
41
+ toggle.addEventListener('expanded-changed', this.__boundOnExpandedChanged);
42
+ root.appendChild(toggle);
43
+ }
44
+
45
+ toggle.__item = item;
46
+ toggle.__rendererExpanded = expanded;
47
+ toggle.expanded = expanded;
48
+ toggle.leaf = this.__isLeafItem(item, this._grid.itemHasChildrenPath);
49
+ toggle.textContent = this.__getToggleContent(this.path, item);
50
+ toggle.level = level;
51
+ }
52
+
53
+ /**
54
+ * The tree column doesn't allow to use a custom renderer
55
+ * to override the content of body cells.
56
+ * It always renders the grid tree toggle to body cells.
57
+ *
58
+ * @override
59
+ */
60
+ _computeRenderer() {
61
+ return this.__defaultRenderer;
62
+ }
63
+
64
+ /**
65
+ * Expands or collapses the row once the tree toggle is switched.
66
+ * The listener handles only user-fired events.
67
+ *
68
+ * @private
69
+ */
70
+ __onExpandedChanged(e) {
71
+ // Skip if the state is changed by the renderer.
72
+ if (e.detail.value === e.target.__rendererExpanded) {
73
+ return;
74
+ }
75
+
76
+ if (e.detail.value) {
77
+ this._grid.expandItem(e.target.__item);
78
+ } else {
79
+ this._grid.collapseItem(e.target.__item);
80
+ }
81
+ }
82
+
83
+ /** @private */
84
+ __isLeafItem(item, itemHasChildrenPath) {
85
+ return !item || !item[itemHasChildrenPath];
86
+ }
87
+
88
+ /** @private */
89
+ __getToggleContent(path, item) {
90
+ return path && get(path, item);
91
+ }
92
+ };
@@ -4,7 +4,8 @@
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';
7
+ import type { GridColumn, GridColumnMixin } from './vaadin-grid-column.js';
8
+ import type { GridTreeColumnMixinClass } from './vaadin-grid-tree-column-mixin.js';
8
9
 
9
10
  /**
10
11
  * `<vaadin-grid-tree-column>` is a helper element for the `<vaadin-grid>`
@@ -19,12 +20,13 @@ import { GridColumn } from './vaadin-grid-column.js';
19
20
  * ...
20
21
  * ```
21
22
  */
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
- }
23
+
24
+ declare class GridTreeColumn<TItem = GridDefaultItem> extends HTMLElement {}
25
+
26
+ interface GridTreeColumn<TItem = GridDefaultItem>
27
+ extends GridTreeColumnMixinClass<TItem>,
28
+ GridColumnMixin<TItem, GridTreeColumn<TItem>>,
29
+ GridColumn<TItem> {}
28
30
 
29
31
  declare global {
30
32
  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';
9
8
  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,91 +22,12 @@ import { GridColumn } from './vaadin-grid-column.js';
22
22
  * ```
23
23
  * @customElement
24
24
  * @extends GridColumn
25
+ * @mixes GridTreeColumnMixin
25
26
  */
26
- class GridTreeColumn extends GridColumn {
27
+ class GridTreeColumn extends GridTreeColumnMixin(GridColumn) {
27
28
  static get is() {
28
29
  return 'vaadin-grid-tree-column';
29
30
  }
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
- }
110
31
  }
111
32
 
112
33
  defineCustomElement(GridTreeColumn);