@vaadin/grid 24.3.0-alpha2 → 24.3.0-alpha3

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