@vaadin/grid 24.2.3 → 24.3.0-alpha10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -13
- package/src/vaadin-grid-a11y-mixin.js +1 -1
- package/src/vaadin-grid-active-item-mixin.js +1 -0
- package/src/vaadin-grid-array-data-provider-mixin.js +14 -17
- package/src/vaadin-grid-column-group-mixin.d.ts +20 -0
- package/src/vaadin-grid-column-group-mixin.js +364 -0
- package/src/vaadin-grid-column-group.d.ts +4 -14
- package/src/vaadin-grid-column-group.js +5 -355
- package/src/vaadin-grid-column-mixin.d.ts +170 -0
- package/src/vaadin-grid-column-mixin.js +958 -0
- package/src/vaadin-grid-column.d.ts +11 -138
- package/src/vaadin-grid-column.js +5 -876
- package/src/vaadin-grid-data-provider-mixin.d.ts +6 -30
- package/src/vaadin-grid-data-provider-mixin.js +122 -246
- package/src/vaadin-grid-drag-and-drop-mixin.js +17 -5
- package/src/vaadin-grid-dynamic-columns-mixin.js +22 -17
- package/src/vaadin-grid-filter-column-mixin.d.ts +22 -0
- package/src/vaadin-grid-filter-column-mixin.js +106 -0
- package/src/vaadin-grid-filter-column.d.ts +9 -11
- package/src/vaadin-grid-filter-column.js +3 -90
- package/src/vaadin-grid-filter-element-mixin.d.ts +34 -0
- package/src/vaadin-grid-filter-element-mixin.js +108 -0
- package/src/vaadin-grid-filter-mixin.js +4 -4
- package/src/vaadin-grid-filter.d.ts +4 -21
- package/src/vaadin-grid-filter.js +5 -84
- package/src/vaadin-grid-helpers.js +94 -0
- package/src/vaadin-grid-keyboard-navigation-mixin.js +11 -4
- package/src/vaadin-grid-mixin.js +21 -37
- package/src/vaadin-grid-row-details-mixin.js +7 -8
- package/src/vaadin-grid-scroll-mixin.js +2 -1
- package/src/vaadin-grid-selection-column-base-mixin.js +12 -4
- package/src/vaadin-grid-selection-column-mixin.d.ts +24 -0
- package/src/vaadin-grid-selection-column-mixin.js +194 -0
- package/src/vaadin-grid-selection-column.d.ts +13 -17
- package/src/vaadin-grid-selection-column.js +4 -186
- package/src/vaadin-grid-selection-mixin.js +4 -3
- package/src/vaadin-grid-sort-column-mixin.d.ts +36 -0
- package/src/vaadin-grid-sort-column-mixin.js +101 -0
- package/src/vaadin-grid-sort-column.d.ts +8 -26
- package/src/vaadin-grid-sort-column.js +3 -87
- package/src/vaadin-grid-sorter-mixin.d.ts +44 -0
- package/src/vaadin-grid-sorter-mixin.js +200 -0
- package/src/vaadin-grid-sorter.d.ts +3 -32
- package/src/vaadin-grid-sorter.js +5 -181
- package/src/vaadin-grid-styles.js +341 -345
- package/src/vaadin-grid-styling-mixin.js +8 -2
- package/src/vaadin-grid-tree-column-mixin.d.ts +18 -0
- package/src/vaadin-grid-tree-column-mixin.js +99 -0
- package/src/vaadin-grid-tree-column.d.ts +9 -7
- package/src/vaadin-grid-tree-column.js +3 -82
- package/src/vaadin-grid-tree-toggle-mixin.d.ts +39 -0
- package/src/vaadin-grid-tree-toggle-mixin.js +153 -0
- package/src/vaadin-grid-tree-toggle.d.ts +4 -27
- package/src/vaadin-grid-tree-toggle.js +9 -141
- package/src/vaadin-grid.d.ts +3 -0
- package/src/vaadin-grid.js +7 -2
- package/theme/lumo/vaadin-grid-sorter-styles.js +1 -1
- package/theme/lumo/vaadin-grid-styles.js +15 -14
- package/theme/material/vaadin-grid-styles.js +15 -10
- package/web-types.json +331 -126
- package/web-types.lit.json +114 -58
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
|
|
7
|
-
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
8
6
|
import { microTask, timeOut } from '@vaadin/component-base/src/async.js';
|
|
9
7
|
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
|
|
10
|
-
import { updateCellState } from './vaadin-grid-helpers.js';
|
|
8
|
+
import { ColumnObserver, updateCellState } from './vaadin-grid-helpers.js';
|
|
11
9
|
|
|
12
10
|
function arrayEquals(arr1, arr2) {
|
|
13
11
|
if (!arr1 || !arr2 || arr1.length !== arr2.length) {
|
|
@@ -59,7 +57,7 @@ export const DynamicColumnsMixin = (superClass) =>
|
|
|
59
57
|
* @protected
|
|
60
58
|
*/
|
|
61
59
|
_getChildColumns(el) {
|
|
62
|
-
return
|
|
60
|
+
return ColumnObserver.getColumns(el);
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
/** @private */
|
|
@@ -78,7 +76,7 @@ export const DynamicColumnsMixin = (superClass) =>
|
|
|
78
76
|
|
|
79
77
|
/** @private */
|
|
80
78
|
_getColumnTree() {
|
|
81
|
-
const rootColumns =
|
|
79
|
+
const rootColumns = ColumnObserver.getColumns(this);
|
|
82
80
|
const columnTree = [rootColumns];
|
|
83
81
|
|
|
84
82
|
let c = rootColumns;
|
|
@@ -100,24 +98,31 @@ export const DynamicColumnsMixin = (superClass) =>
|
|
|
100
98
|
/** @protected */
|
|
101
99
|
_updateColumnTree() {
|
|
102
100
|
const columnTree = this._getColumnTree();
|
|
101
|
+
|
|
103
102
|
if (!arrayEquals(columnTree, this._columnTree)) {
|
|
103
|
+
// Request a synchronoys update for each column
|
|
104
|
+
columnTree.forEach((columnArray) => {
|
|
105
|
+
columnArray.forEach((column) => {
|
|
106
|
+
if (column.performUpdate) {
|
|
107
|
+
column.performUpdate();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
104
112
|
this._columnTree = columnTree;
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
/** @private */
|
|
109
117
|
_addNodeObserver() {
|
|
110
|
-
this._observer = new
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.__removeFilters(this._filters.filter(filterNotConnected));
|
|
119
|
-
this._debounceUpdateColumnTree();
|
|
120
|
-
}
|
|
118
|
+
this._observer = new ColumnObserver(this, (_addedColumns, removedColumns) => {
|
|
119
|
+
const allRemovedCells = removedColumns.flatMap((c) => c._allCells);
|
|
120
|
+
const filterNotConnected = (element) =>
|
|
121
|
+
allRemovedCells.filter((cell) => cell && cell._content.contains(element)).length;
|
|
122
|
+
|
|
123
|
+
this.__removeSorters(this._sorters.filter(filterNotConnected));
|
|
124
|
+
this.__removeFilters(this._filters.filter(filterNotConnected));
|
|
125
|
+
this._debounceUpdateColumnTree();
|
|
121
126
|
|
|
122
127
|
this._debouncerCheckImports = Debouncer.debounce(
|
|
123
128
|
this._debouncerCheckImports,
|
|
@@ -141,7 +146,7 @@ export const DynamicColumnsMixin = (superClass) =>
|
|
|
141
146
|
'vaadin-grid-sorter',
|
|
142
147
|
].forEach((elementName) => {
|
|
143
148
|
const element = this.querySelector(elementName);
|
|
144
|
-
if (element && !(
|
|
149
|
+
if (element && !customElements.get(elementName)) {
|
|
145
150
|
console.warn(`Make sure you have imported the required module for <${elementName}> element.`);
|
|
146
151
|
}
|
|
147
152
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
export declare function GridFilterColumnMixin<T extends Constructor<HTMLElement>>(
|
|
9
|
+
superclass: T,
|
|
10
|
+
): Constructor<GridFilterColumnMixinClass> & T;
|
|
11
|
+
|
|
12
|
+
export declare class GridFilterColumnMixinClass {
|
|
13
|
+
/**
|
|
14
|
+
* Text to display as the label of the column filter text-field.
|
|
15
|
+
*/
|
|
16
|
+
header: string | null | undefined;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* JS Path of the property in the item used for filtering the data.
|
|
20
|
+
*/
|
|
21
|
+
path: string | null | undefined;
|
|
22
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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 GridFilterColumnMixin = (superClass) =>
|
|
11
|
+
class extends superClass {
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
/**
|
|
15
|
+
* JS Path of the property in the item used for filtering the data.
|
|
16
|
+
*/
|
|
17
|
+
path: {
|
|
18
|
+
type: String,
|
|
19
|
+
sync: true,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Text to display as the label of the column filter text-field.
|
|
24
|
+
*/
|
|
25
|
+
header: {
|
|
26
|
+
type: String,
|
|
27
|
+
sync: true,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static get observers() {
|
|
33
|
+
return ['_onHeaderRendererOrBindingChanged(_headerRenderer, _headerCell, path, header, _filterValue)'];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
constructor() {
|
|
37
|
+
super();
|
|
38
|
+
|
|
39
|
+
this.__boundOnFilterValueChanged = this.__onFilterValueChanged.bind(this);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Renders the grid filter with the custom text field to the header cell.
|
|
44
|
+
*
|
|
45
|
+
* @override
|
|
46
|
+
*/
|
|
47
|
+
_defaultHeaderRenderer(root, _column) {
|
|
48
|
+
let filter = root.firstElementChild;
|
|
49
|
+
let textField = filter ? filter.firstElementChild : undefined;
|
|
50
|
+
|
|
51
|
+
if (!filter) {
|
|
52
|
+
filter = document.createElement('vaadin-grid-filter');
|
|
53
|
+
textField = document.createElement('vaadin-text-field');
|
|
54
|
+
textField.setAttribute('theme', 'small');
|
|
55
|
+
textField.setAttribute('style', 'max-width: 100%;');
|
|
56
|
+
textField.setAttribute('focus-target', '');
|
|
57
|
+
textField.addEventListener('value-changed', this.__boundOnFilterValueChanged);
|
|
58
|
+
filter.appendChild(textField);
|
|
59
|
+
root.appendChild(filter);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
filter.path = this.path;
|
|
63
|
+
filter.value = this._filterValue;
|
|
64
|
+
|
|
65
|
+
textField.__rendererValue = this._filterValue;
|
|
66
|
+
textField.value = this._filterValue;
|
|
67
|
+
textField.label = this.__getHeader(this.header, this.path);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The filter column doesn't allow to use a custom header renderer
|
|
72
|
+
* to override the header cell content.
|
|
73
|
+
* It always renders the grid filter to the header cell.
|
|
74
|
+
*
|
|
75
|
+
* @override
|
|
76
|
+
*/
|
|
77
|
+
_computeHeaderRenderer() {
|
|
78
|
+
return this._defaultHeaderRenderer;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Updates the internal filter value once the filter text field is changed.
|
|
83
|
+
* The listener handles only user-fired events.
|
|
84
|
+
*
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
__onFilterValueChanged(e) {
|
|
88
|
+
// Skip if the value is changed by the renderer.
|
|
89
|
+
if (e.detail.value === e.target.__rendererValue) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this._filterValue = e.detail.value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** @private */
|
|
97
|
+
__getHeader(header, path) {
|
|
98
|
+
if (header) {
|
|
99
|
+
return header;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (path) {
|
|
103
|
+
return this._generateHeader(path);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
@@ -4,7 +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';
|
|
7
|
+
import type { GridColumn, GridColumnMixin } from './vaadin-grid-column.js';
|
|
8
|
+
import type { GridFilterColumnMixinClass } from './vaadin-grid-filter-column-mixin.js';
|
|
9
|
+
|
|
10
|
+
export * from './vaadin-grid-filter-column-mixin.js';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* `<vaadin-grid-filter-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -19,17 +22,12 @@ import { GridColumn } from './vaadin-grid-column.js';
|
|
|
19
22
|
* ...
|
|
20
23
|
* ```
|
|
21
24
|
*/
|
|
22
|
-
declare class GridFilterColumn<TItem = GridDefaultItem> extends
|
|
23
|
-
/**
|
|
24
|
-
* Text to display as the label of the column filter text-field.
|
|
25
|
-
*/
|
|
26
|
-
header: string | null | undefined;
|
|
25
|
+
declare class GridFilterColumn<TItem = GridDefaultItem> extends HTMLElement {}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
27
|
+
interface GridFilterColumn<TItem = GridDefaultItem>
|
|
28
|
+
extends GridFilterColumnMixinClass,
|
|
29
|
+
GridColumnMixin<TItem, GridColumn<TItem>>,
|
|
30
|
+
GridColumn<TItem> {}
|
|
33
31
|
|
|
34
32
|
declare global {
|
|
35
33
|
interface HTMLElementTagNameMap {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import './vaadin-grid-filter.js';
|
|
7
7
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
8
|
import { GridColumn } from './vaadin-grid-column.js';
|
|
9
|
+
import { GridFilterColumnMixin } from './vaadin-grid-filter-column-mixin.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* `<vaadin-grid-filter-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -22,100 +23,12 @@ import { GridColumn } from './vaadin-grid-column.js';
|
|
|
22
23
|
*
|
|
23
24
|
* @customElement
|
|
24
25
|
* @extends GridColumn
|
|
26
|
+
* @mixes GridFilterColumnMixin
|
|
25
27
|
*/
|
|
26
|
-
class GridFilterColumn extends GridColumn {
|
|
28
|
+
class GridFilterColumn extends GridFilterColumnMixin(GridColumn) {
|
|
27
29
|
static get is() {
|
|
28
30
|
return 'vaadin-grid-filter-column';
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
static get properties() {
|
|
32
|
-
return {
|
|
33
|
-
/**
|
|
34
|
-
* JS Path of the property in the item used for filtering the data.
|
|
35
|
-
*/
|
|
36
|
-
path: String,
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Text to display as the label of the column filter text-field.
|
|
40
|
-
*/
|
|
41
|
-
header: String,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static get observers() {
|
|
46
|
-
return ['_onHeaderRendererOrBindingChanged(_headerRenderer, _headerCell, path, header, _filterValue)'];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
constructor() {
|
|
50
|
-
super();
|
|
51
|
-
|
|
52
|
-
this.__boundOnFilterValueChanged = this.__onFilterValueChanged.bind(this);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Renders the grid filter with the custom text field to the header cell.
|
|
57
|
-
*
|
|
58
|
-
* @override
|
|
59
|
-
*/
|
|
60
|
-
_defaultHeaderRenderer(root, _column) {
|
|
61
|
-
let filter = root.firstElementChild;
|
|
62
|
-
let textField = filter ? filter.firstElementChild : undefined;
|
|
63
|
-
|
|
64
|
-
if (!filter) {
|
|
65
|
-
filter = document.createElement('vaadin-grid-filter');
|
|
66
|
-
textField = document.createElement('vaadin-text-field');
|
|
67
|
-
textField.setAttribute('theme', 'small');
|
|
68
|
-
textField.setAttribute('style', 'max-width: 100%;');
|
|
69
|
-
textField.setAttribute('focus-target', '');
|
|
70
|
-
textField.addEventListener('value-changed', this.__boundOnFilterValueChanged);
|
|
71
|
-
filter.appendChild(textField);
|
|
72
|
-
root.appendChild(filter);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
filter.path = this.path;
|
|
76
|
-
filter.value = this._filterValue;
|
|
77
|
-
|
|
78
|
-
textField.__rendererValue = this._filterValue;
|
|
79
|
-
textField.value = this._filterValue;
|
|
80
|
-
textField.label = this.__getHeader(this.header, this.path);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The filter column doesn't allow to use a custom header renderer
|
|
85
|
-
* to override the header cell content.
|
|
86
|
-
* It always renders the grid filter to the header cell.
|
|
87
|
-
*
|
|
88
|
-
* @override
|
|
89
|
-
*/
|
|
90
|
-
_computeHeaderRenderer() {
|
|
91
|
-
return this._defaultHeaderRenderer;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Updates the internal filter value once the filter text field is changed.
|
|
96
|
-
* The listener handles only user-fired events.
|
|
97
|
-
*
|
|
98
|
-
* @private
|
|
99
|
-
*/
|
|
100
|
-
__onFilterValueChanged(e) {
|
|
101
|
-
// Skip if the value is changed by the renderer.
|
|
102
|
-
if (e.detail.value === e.target.__rendererValue) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
this._filterValue = e.detail.value;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** @private */
|
|
110
|
-
__getHeader(header, path) {
|
|
111
|
-
if (header) {
|
|
112
|
-
return header;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (path) {
|
|
116
|
-
return this._generateHeader(path);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
32
|
}
|
|
120
33
|
|
|
121
34
|
defineCustomElement(GridFilterColumn);
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fired when the `value` property changes.
|
|
11
|
+
*/
|
|
12
|
+
export type GridFilterValueChangedEvent = CustomEvent<{ value: string }>;
|
|
13
|
+
|
|
14
|
+
export interface GridFilterCustomEventMap {
|
|
15
|
+
'value-changed': GridFilterValueChangedEvent;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GridFilterEventMap extends HTMLElementEventMap, GridFilterCustomEventMap {}
|
|
19
|
+
|
|
20
|
+
export declare function GridFilterElementMixin<T extends Constructor<HTMLElement>>(
|
|
21
|
+
base: T,
|
|
22
|
+
): Constructor<ControllerMixinClass> & Constructor<GridFilterElementMixinClass> & T;
|
|
23
|
+
|
|
24
|
+
declare class GridFilterElementMixinClass {
|
|
25
|
+
/**
|
|
26
|
+
* JS Path of the property in the item used for filtering the data.
|
|
27
|
+
*/
|
|
28
|
+
path: string | null | undefined;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Current filter value.
|
|
32
|
+
*/
|
|
33
|
+
value: string | null | undefined;
|
|
34
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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 { timeOut } from '@vaadin/component-base/src/async.js';
|
|
7
|
+
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
8
|
+
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
|
|
9
|
+
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
10
|
+
import { css, registerStyles } from '@vaadin/vaadin-themable-mixin';
|
|
11
|
+
|
|
12
|
+
registerStyles(
|
|
13
|
+
'vaadin-grid-filter',
|
|
14
|
+
css`
|
|
15
|
+
:host {
|
|
16
|
+
display: inline-flex;
|
|
17
|
+
max-width: 100%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
::slotted(*) {
|
|
21
|
+
width: 100%;
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
}
|
|
24
|
+
`,
|
|
25
|
+
{ moduleId: 'vaadin-grid-filter-styles' },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @polymerMixin
|
|
30
|
+
*
|
|
31
|
+
* @mixes ControllerMixin
|
|
32
|
+
*/
|
|
33
|
+
export const GridFilterElementMixin = (superClass) =>
|
|
34
|
+
class extends ControllerMixin(superClass) {
|
|
35
|
+
static get properties() {
|
|
36
|
+
return {
|
|
37
|
+
/**
|
|
38
|
+
* JS Path of the property in the item used for filtering the data.
|
|
39
|
+
*/
|
|
40
|
+
path: {
|
|
41
|
+
type: String,
|
|
42
|
+
sync: true,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Current filter value.
|
|
47
|
+
*/
|
|
48
|
+
value: {
|
|
49
|
+
type: String,
|
|
50
|
+
notify: true,
|
|
51
|
+
sync: true,
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/** @private */
|
|
55
|
+
_textField: {
|
|
56
|
+
type: Object,
|
|
57
|
+
sync: true,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static get observers() {
|
|
63
|
+
return ['_filterChanged(path, value, _textField)'];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @protected */
|
|
67
|
+
ready() {
|
|
68
|
+
super.ready();
|
|
69
|
+
|
|
70
|
+
this._filterController = new SlotController(this, '', 'vaadin-text-field', {
|
|
71
|
+
initializer: (field) => {
|
|
72
|
+
field.addEventListener('value-changed', (e) => {
|
|
73
|
+
if (field.__previousValue === undefined && e.detail.value === '') {
|
|
74
|
+
field.__previousValue = e.detail.value;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.value = e.detail.value;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this._textField = field;
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
this.addController(this._filterController);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @private */
|
|
87
|
+
_filterChanged(path, value, textField) {
|
|
88
|
+
if (path === undefined || value === undefined || !textField) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (this._previousValue === undefined && value === '') {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
textField.value = value;
|
|
96
|
+
this._previousValue = value;
|
|
97
|
+
|
|
98
|
+
this._debouncerFilterChanged = Debouncer.debounce(this._debouncerFilterChanged, timeOut.after(200), () => {
|
|
99
|
+
this.dispatchEvent(new CustomEvent('filter-changed', { bubbles: true }));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
focus() {
|
|
104
|
+
if (this._textField) {
|
|
105
|
+
this._textField.focus();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
@@ -19,10 +19,10 @@ export const FilterMixin = (superClass) =>
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.addEventListener('filter-changed', this._filterChanged
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this._filterChanged = this._filterChanged.bind(this);
|
|
25
|
+
this.addEventListener('filter-changed', this._filterChanged);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/** @private */
|
|
@@ -3,18 +3,11 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export type GridFilterValueChangedEvent = CustomEvent<{ value: string }>;
|
|
12
|
-
|
|
13
|
-
export interface GridFilterCustomEventMap {
|
|
14
|
-
'value-changed': GridFilterValueChangedEvent;
|
|
15
|
-
}
|
|
7
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin';
|
|
8
|
+
import { GridFilterElementMixin, type GridFilterEventMap } from './vaadin-grid-filter-element-mixin.js';
|
|
16
9
|
|
|
17
|
-
export
|
|
10
|
+
export * from './vaadin-grid-filter-element-mixin.js';
|
|
18
11
|
|
|
19
12
|
/**
|
|
20
13
|
* `<vaadin-grid-filter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
|
|
@@ -41,17 +34,7 @@ export interface GridFilterEventMap extends HTMLElementEventMap, GridFilterCusto
|
|
|
41
34
|
*
|
|
42
35
|
* @fires {CustomEvent} value-changed - Fired when the `value` property changes.
|
|
43
36
|
*/
|
|
44
|
-
declare class GridFilter extends
|
|
45
|
-
/**
|
|
46
|
-
* JS Path of the property in the item used for filtering the data.
|
|
47
|
-
*/
|
|
48
|
-
path: string | null | undefined;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Current filter value.
|
|
52
|
-
*/
|
|
53
|
-
value: string | null | undefined;
|
|
54
|
-
|
|
37
|
+
declare class GridFilter extends GridFilterElementMixin(ThemableMixin(HTMLElement)) {
|
|
55
38
|
addEventListener<K extends keyof GridFilterEventMap>(
|
|
56
39
|
type: K,
|
|
57
40
|
listener: (this: GridFilter, ev: GridFilterEventMap[K]) => void,
|
|
@@ -5,11 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import '@vaadin/text-field/src/vaadin-text-field.js';
|
|
7
7
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
8
|
-
import { timeOut } from '@vaadin/component-base/src/async.js';
|
|
9
|
-
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
10
|
-
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
|
|
11
8
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
12
|
-
import {
|
|
9
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin';
|
|
10
|
+
import { GridFilterElementMixin } from './vaadin-grid-filter-element-mixin.js';
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* `<vaadin-grid-filter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
|
|
@@ -38,93 +36,16 @@ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
|
38
36
|
*
|
|
39
37
|
* @customElement
|
|
40
38
|
* @extends HTMLElement
|
|
39
|
+
* @mixes GridFilterElementMixin
|
|
41
40
|
*/
|
|
42
|
-
class GridFilter extends
|
|
41
|
+
class GridFilter extends GridFilterElementMixin(ThemableMixin(PolymerElement)) {
|
|
43
42
|
static get template() {
|
|
44
|
-
return html
|
|
45
|
-
<style>
|
|
46
|
-
:host {
|
|
47
|
-
display: inline-flex;
|
|
48
|
-
max-width: 100%;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
::slotted(*) {
|
|
52
|
-
width: 100%;
|
|
53
|
-
box-sizing: border-box;
|
|
54
|
-
}
|
|
55
|
-
</style>
|
|
56
|
-
<slot></slot>
|
|
57
|
-
`;
|
|
43
|
+
return html`<slot></slot>`;
|
|
58
44
|
}
|
|
59
45
|
|
|
60
46
|
static get is() {
|
|
61
47
|
return 'vaadin-grid-filter';
|
|
62
48
|
}
|
|
63
|
-
|
|
64
|
-
static get properties() {
|
|
65
|
-
return {
|
|
66
|
-
/**
|
|
67
|
-
* JS Path of the property in the item used for filtering the data.
|
|
68
|
-
*/
|
|
69
|
-
path: String,
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Current filter value.
|
|
73
|
-
*/
|
|
74
|
-
value: {
|
|
75
|
-
type: String,
|
|
76
|
-
notify: true,
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
/** @private */
|
|
80
|
-
_textField: {
|
|
81
|
-
type: Object,
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
static get observers() {
|
|
87
|
-
return ['_filterChanged(path, value, _textField)'];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** @protected */
|
|
91
|
-
ready() {
|
|
92
|
-
super.ready();
|
|
93
|
-
|
|
94
|
-
this._filterController = new SlotController(this, '', 'vaadin-text-field', {
|
|
95
|
-
initializer: (field) => {
|
|
96
|
-
field.addEventListener('value-changed', (e) => {
|
|
97
|
-
this.value = e.detail.value;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
this._textField = field;
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
this.addController(this._filterController);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** @private */
|
|
107
|
-
_filterChanged(path, value, textField) {
|
|
108
|
-
if (path === undefined || value === undefined || !textField) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (this._previousValue === undefined && value === '') {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
textField.value = value;
|
|
116
|
-
this._previousValue = value;
|
|
117
|
-
|
|
118
|
-
this._debouncerFilterChanged = Debouncer.debounce(this._debouncerFilterChanged, timeOut.after(200), () => {
|
|
119
|
-
this.dispatchEvent(new CustomEvent('filter-changed', { bubbles: true }));
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
focus() {
|
|
124
|
-
if (this._textField) {
|
|
125
|
-
this._textField.focus();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
49
|
}
|
|
129
50
|
|
|
130
51
|
defineCustomElement(GridFilter);
|