@vaadin/grid 24.3.0-alpha1 → 24.3.0-alpha11

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.
Files changed (114) hide show
  1. package/package.json +12 -12
  2. package/src/lit-all-imports.js +14 -0
  3. package/src/vaadin-grid-a11y-mixin.js +1 -1
  4. package/src/vaadin-grid-active-item-mixin.js +1 -0
  5. package/src/vaadin-grid-array-data-provider-mixin.js +14 -17
  6. package/src/vaadin-grid-column-group-mixin.d.ts +20 -0
  7. package/src/vaadin-grid-column-group-mixin.js +364 -0
  8. package/src/vaadin-grid-column-group.d.ts +4 -14
  9. package/src/vaadin-grid-column-group.js +5 -355
  10. package/src/vaadin-grid-column-mixin.d.ts +170 -0
  11. package/src/vaadin-grid-column-mixin.js +958 -0
  12. package/src/vaadin-grid-column.d.ts +11 -138
  13. package/src/vaadin-grid-column.js +5 -876
  14. package/src/vaadin-grid-data-provider-mixin.d.ts +6 -5
  15. package/src/vaadin-grid-data-provider-mixin.js +62 -12
  16. package/src/vaadin-grid-drag-and-drop-mixin.js +17 -5
  17. package/src/vaadin-grid-dynamic-columns-mixin.js +22 -17
  18. package/src/vaadin-grid-filter-column-mixin.d.ts +22 -0
  19. package/src/vaadin-grid-filter-column-mixin.js +106 -0
  20. package/src/vaadin-grid-filter-column.d.ts +9 -11
  21. package/src/vaadin-grid-filter-column.js +3 -90
  22. package/src/vaadin-grid-filter-element-mixin.d.ts +34 -0
  23. package/src/vaadin-grid-filter-element-mixin.js +108 -0
  24. package/src/vaadin-grid-filter-mixin.js +4 -4
  25. package/src/vaadin-grid-filter.d.ts +4 -21
  26. package/src/vaadin-grid-filter.js +5 -84
  27. package/src/vaadin-grid-helpers.js +94 -0
  28. package/src/vaadin-grid-keyboard-navigation-mixin.js +26 -6
  29. package/src/vaadin-grid-mixin.js +37 -46
  30. package/src/vaadin-grid-row-details-mixin.js +14 -8
  31. package/src/vaadin-grid-scroll-mixin.js +9 -3
  32. package/src/vaadin-grid-selection-column-base-mixin.js +12 -4
  33. package/src/vaadin-grid-selection-column-mixin.d.ts +24 -0
  34. package/src/vaadin-grid-selection-column-mixin.js +194 -0
  35. package/src/vaadin-grid-selection-column.d.ts +13 -17
  36. package/src/vaadin-grid-selection-column.js +4 -186
  37. package/src/vaadin-grid-selection-mixin.js +4 -3
  38. package/src/vaadin-grid-sort-column-mixin.d.ts +36 -0
  39. package/src/vaadin-grid-sort-column-mixin.js +101 -0
  40. package/src/vaadin-grid-sort-column.d.ts +8 -26
  41. package/src/vaadin-grid-sort-column.js +3 -87
  42. package/src/vaadin-grid-sorter-mixin.d.ts +44 -0
  43. package/src/vaadin-grid-sorter-mixin.js +200 -0
  44. package/src/vaadin-grid-sorter.d.ts +3 -32
  45. package/src/vaadin-grid-sorter.js +5 -181
  46. package/src/vaadin-grid-styles.js +341 -345
  47. package/src/vaadin-grid-styling-mixin.js +8 -2
  48. package/src/vaadin-grid-tree-column-mixin.d.ts +18 -0
  49. package/src/vaadin-grid-tree-column-mixin.js +99 -0
  50. package/src/vaadin-grid-tree-column.d.ts +9 -7
  51. package/src/vaadin-grid-tree-column.js +3 -82
  52. package/src/vaadin-grid-tree-toggle-mixin.d.ts +39 -0
  53. package/src/vaadin-grid-tree-toggle-mixin.js +153 -0
  54. package/src/vaadin-grid-tree-toggle.d.ts +4 -27
  55. package/src/vaadin-grid-tree-toggle.js +9 -141
  56. package/src/vaadin-grid.d.ts +3 -0
  57. package/src/vaadin-grid.js +7 -2
  58. package/src/vaadin-lit-grid-column-group.js +28 -0
  59. package/src/vaadin-lit-grid-column.js +30 -0
  60. package/src/vaadin-lit-grid-filter-column.js +28 -0
  61. package/src/vaadin-lit-grid-filter.js +35 -0
  62. package/src/vaadin-lit-grid-selection-column.js +28 -0
  63. package/src/vaadin-lit-grid-sort-column.js +28 -0
  64. package/src/vaadin-lit-grid-sorter.js +42 -0
  65. package/src/vaadin-lit-grid-tree-column.js +28 -0
  66. package/src/vaadin-lit-grid-tree-toggle.js +39 -0
  67. package/src/vaadin-lit-grid.js +63 -0
  68. package/theme/lumo/lit-all-imports.js +11 -0
  69. package/theme/lumo/vaadin-grid-sorter-styles.js +1 -1
  70. package/theme/lumo/vaadin-grid-styles.js +15 -14
  71. package/theme/lumo/vaadin-lit-grid-column-group.js +1 -0
  72. package/theme/lumo/vaadin-lit-grid-column.js +1 -0
  73. package/theme/lumo/vaadin-lit-grid-filter-column.js +2 -0
  74. package/theme/lumo/vaadin-lit-grid-filter.js +3 -0
  75. package/theme/lumo/vaadin-lit-grid-selection-column.js +2 -0
  76. package/theme/lumo/vaadin-lit-grid-sort-column.js +2 -0
  77. package/theme/lumo/vaadin-lit-grid-sorter.js +2 -0
  78. package/theme/lumo/vaadin-lit-grid-tree-column.js +2 -0
  79. package/theme/lumo/vaadin-lit-grid-tree-toggle.js +2 -0
  80. package/theme/lumo/vaadin-lit-grid.js +2 -0
  81. package/theme/material/lit-all-imports.js +11 -0
  82. package/theme/material/vaadin-grid-styles.js +15 -10
  83. package/theme/material/vaadin-lit-grid-column-group.js +1 -0
  84. package/theme/material/vaadin-lit-grid-column.js +1 -0
  85. package/theme/material/vaadin-lit-grid-filter-column.js +2 -0
  86. package/theme/material/vaadin-lit-grid-filter.js +3 -0
  87. package/theme/material/vaadin-lit-grid-selection-column.js +2 -0
  88. package/theme/material/vaadin-lit-grid-sort-column.js +2 -0
  89. package/theme/material/vaadin-lit-grid-sorter.js +2 -0
  90. package/theme/material/vaadin-lit-grid-tree-column.js +2 -0
  91. package/theme/material/vaadin-lit-grid-tree-toggle.js +2 -0
  92. package/theme/material/vaadin-lit-grid.js +2 -0
  93. package/vaadin-lit-grid-column-group.d.ts +1 -0
  94. package/vaadin-lit-grid-column-group.js +3 -0
  95. package/vaadin-lit-grid-column.d.ts +1 -0
  96. package/vaadin-lit-grid-column.js +3 -0
  97. package/vaadin-lit-grid-filter-column.d.ts +1 -0
  98. package/vaadin-lit-grid-filter-column.js +3 -0
  99. package/vaadin-lit-grid-filter.d.ts +1 -0
  100. package/vaadin-lit-grid-filter.js +3 -0
  101. package/vaadin-lit-grid-selection-column.d.ts +1 -0
  102. package/vaadin-lit-grid-selection-column.js +3 -0
  103. package/vaadin-lit-grid-sort-column.d.ts +1 -0
  104. package/vaadin-lit-grid-sort-column.js +3 -0
  105. package/vaadin-lit-grid-sorter.d.ts +1 -0
  106. package/vaadin-lit-grid-sorter.js +3 -0
  107. package/vaadin-lit-grid-tree-column.d.ts +1 -0
  108. package/vaadin-lit-grid-tree-column.js +3 -0
  109. package/vaadin-lit-grid-tree-toggle.d.ts +1 -0
  110. package/vaadin-lit-grid-tree-toggle.js +3 -0
  111. package/vaadin-lit-grid.d.ts +2 -0
  112. package/vaadin-lit-grid.js +4 -0
  113. package/web-types.json +331 -126
  114. package/web-types.lit.json +114 -58
@@ -4,6 +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 { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type {
8
+ DataProvider,
9
+ DataProviderCallback,
10
+ } from '@vaadin/component-base/src/data-provider-controller/data-provider-controller.js';
7
11
  import { GridSorterDirection } from './vaadin-grid-sorter.js';
8
12
 
9
13
  export { GridSorterDirection };
@@ -18,7 +22,7 @@ export interface GridSorterDefinition {
18
22
  direction: GridSorterDirection;
19
23
  }
20
24
 
21
- export type GridDataProviderCallback<TItem> = (items: TItem[], size?: number) => void;
25
+ export type GridDataProviderCallback<TItem> = DataProviderCallback<TItem>;
22
26
 
23
27
  export type GridDataProviderParams<TItem> = {
24
28
  page: number;
@@ -28,10 +32,7 @@ export type GridDataProviderParams<TItem> = {
28
32
  parentItem?: TItem;
29
33
  };
30
34
 
31
- export type GridDataProvider<TItem> = (
32
- params: GridDataProviderParams<TItem>,
33
- callback: GridDataProviderCallback<TItem>,
34
- ) => void;
35
+ export type GridDataProvider<TItem> = DataProvider<TItem, GridDataProviderParams<TItem>>;
35
36
 
36
37
  export declare function DataProviderMixin<TItem, T extends Constructor<HTMLElement>>(
37
38
  base: T,
@@ -24,6 +24,16 @@ export const DataProviderMixin = (superClass) =>
24
24
  size: {
25
25
  type: Number,
26
26
  notify: true,
27
+ sync: true,
28
+ },
29
+
30
+ /**
31
+ * @type {number}
32
+ * @protected
33
+ */
34
+ _flatSize: {
35
+ type: Number,
36
+ sync: true,
27
37
  },
28
38
 
29
39
  /**
@@ -35,6 +45,7 @@ export const DataProviderMixin = (superClass) =>
35
45
  type: Number,
36
46
  value: 50,
37
47
  observer: '_pageSizeChanged',
48
+ sync: true,
38
49
  },
39
50
 
40
51
  /**
@@ -64,6 +75,7 @@ export const DataProviderMixin = (superClass) =>
64
75
  type: Object,
65
76
  notify: true,
66
77
  observer: '_dataProviderChanged',
78
+ sync: true,
67
79
  },
68
80
 
69
81
  /**
@@ -82,6 +94,7 @@ export const DataProviderMixin = (superClass) =>
82
94
  _hasData: {
83
95
  type: Boolean,
84
96
  value: false,
97
+ sync: true,
85
98
  },
86
99
 
87
100
  /**
@@ -92,6 +105,7 @@ export const DataProviderMixin = (superClass) =>
92
105
  type: String,
93
106
  value: 'children',
94
107
  observer: '__itemHasChildrenPathChanged',
108
+ sync: true,
95
109
  },
96
110
 
97
111
  /**
@@ -101,6 +115,7 @@ export const DataProviderMixin = (superClass) =>
101
115
  itemIdPath: {
102
116
  type: String,
103
117
  value: null,
118
+ sync: true,
104
119
  },
105
120
 
106
121
  /**
@@ -111,6 +126,7 @@ export const DataProviderMixin = (superClass) =>
111
126
  type: Object,
112
127
  notify: true,
113
128
  value: () => [],
129
+ sync: true,
114
130
  },
115
131
 
116
132
  /**
@@ -118,13 +134,13 @@ export const DataProviderMixin = (superClass) =>
118
134
  */
119
135
  __expandedKeys: {
120
136
  type: Object,
121
- computed: '__computeExpandedKeys(itemIdPath, expandedItems.*)',
137
+ computed: '__computeExpandedKeys(itemIdPath, expandedItems)',
122
138
  },
123
139
  };
124
140
  }
125
141
 
126
142
  static get observers() {
127
- return ['_sizeChanged(size)', '_expandedItemsChanged(expandedItems.*)'];
143
+ return ['_sizeChanged(size)', '_expandedItemsChanged(expandedItems)'];
128
144
  }
129
145
 
130
146
  constructor() {
@@ -134,6 +150,7 @@ export const DataProviderMixin = (superClass) =>
134
150
  this._dataProviderController = new DataProviderController(this, {
135
151
  size: this.size,
136
152
  pageSize: this.pageSize,
153
+ getItemId: this.getItemId.bind(this),
137
154
  isExpanded: this._isExpanded.bind(this),
138
155
  dataProvider: this.dataProvider ? this.dataProvider.bind(this) : null,
139
156
  dataProviderParams: () => {
@@ -149,10 +166,29 @@ export const DataProviderMixin = (superClass) =>
149
166
  this._dataProviderController.addEventListener('page-loaded', this._onDataProviderPageLoaded.bind(this));
150
167
  }
151
168
 
169
+ /**
170
+ * @protected
171
+ * @deprecated since 24.3 and will be removed in Vaadin 25.
172
+ */
173
+ get _cache() {
174
+ console.warn('<vaadin-grid> The `_cache` property is deprecated and will be removed in Vaadin 25.');
175
+ return this._dataProviderController.rootCache;
176
+ }
177
+
178
+ /**
179
+ * @protected
180
+ * @deprecated since 24.3 and will be removed in Vaadin 25.
181
+ */
182
+ get _effectiveSize() {
183
+ console.warn('<vaadin-grid> The `_effectiveSize` property is deprecated and will be removed in Vaadin 25.');
184
+ return this._flatSize;
185
+ }
186
+
152
187
  /** @private */
153
188
  _sizeChanged(size) {
154
- this._dataProviderController.setSize(size);
155
- this._effectiveSize = this._dataProviderController.effectiveSize;
189
+ this._dataProviderController.rootCache.size = size;
190
+ this._dataProviderController.recalculateFlatSize();
191
+ this._flatSize = this._dataProviderController.flatSize;
156
192
  }
157
193
 
158
194
  /** @private */
@@ -170,7 +206,7 @@ export const DataProviderMixin = (superClass) =>
170
206
  * @protected
171
207
  */
172
208
  _getItem(index, el) {
173
- if (index >= this._effectiveSize) {
209
+ if (index >= this._flatSize) {
174
210
  return;
175
211
  }
176
212
 
@@ -220,19 +256,19 @@ export const DataProviderMixin = (superClass) =>
220
256
  * @protected
221
257
  */
222
258
  _isExpanded(item) {
223
- return this.__expandedKeys.has(this.getItemId(item));
259
+ return this.__expandedKeys && this.__expandedKeys.has(this.getItemId(item));
224
260
  }
225
261
 
226
262
  /** @private */
227
263
  _expandedItemsChanged() {
228
- this._dataProviderController.recalculateEffectiveSize();
229
- this._effectiveSize = this._dataProviderController.effectiveSize;
264
+ this._dataProviderController.recalculateFlatSize();
265
+ this._flatSize = this._dataProviderController.flatSize;
230
266
  this.__updateVisibleRows();
231
267
  }
232
268
 
233
269
  /** @private */
234
270
  __computeExpandedKeys(itemIdPath, expandedItems) {
235
- const expanded = expandedItems.base || [];
271
+ const expanded = expandedItems || [];
236
272
  const expandedKeys = new Set();
237
273
  expanded.forEach((item) => {
238
274
  expandedKeys.add(this.getItemId(item));
@@ -271,6 +307,17 @@ export const DataProviderMixin = (superClass) =>
271
307
  return level;
272
308
  }
273
309
 
310
+ /**
311
+ * @param {number} page
312
+ * @param {ItemCache} cache
313
+ * @protected
314
+ * @deprecated since 24.3 and will be removed in Vaadin 25.
315
+ */
316
+ _loadPage(page, cache) {
317
+ console.warn('<vaadin-grid> The `_loadPage` method is deprecated and will be removed in Vaadin 25.');
318
+ this._dataProviderController.__loadCachePage(cache, page);
319
+ }
320
+
274
321
  /** @protected */
275
322
  _onDataProviderPageRequested() {
276
323
  this._setLoading(true);
@@ -279,7 +326,7 @@ export const DataProviderMixin = (superClass) =>
279
326
  /** @protected */
280
327
  _onDataProviderPageReceived() {
281
328
  // With the new items added, update the cache size and the grid's effective size
282
- this._effectiveSize = this._dataProviderController.effectiveSize;
329
+ this._flatSize = this._dataProviderController.flatSize;
283
330
 
284
331
  // After updating the cache, check if some of the expanded items should have sub-caches loaded
285
332
  this._getRenderedRows().forEach((row) => {
@@ -303,6 +350,7 @@ export const DataProviderMixin = (superClass) =>
303
350
  });
304
351
 
305
352
  this.__scrollToPendingIndexes();
353
+ this.__dispatchPendingBodyCellFocus();
306
354
  });
307
355
 
308
356
  // If the grid is not loading anything, flush the debouncer immediately
@@ -316,10 +364,12 @@ export const DataProviderMixin = (superClass) =>
316
364
  */
317
365
  clearCache() {
318
366
  this._dataProviderController.clearCache();
367
+ this._dataProviderController.rootCache.size = this.size;
368
+ this._dataProviderController.recalculateFlatSize();
319
369
  this._hasData = false;
320
370
  this.__updateVisibleRows();
321
371
 
322
- if (!this._effectiveSize) {
372
+ if (!this._flatSize) {
323
373
  this._dataProviderController.loadFirstPage();
324
374
  }
325
375
  }
@@ -335,7 +385,7 @@ export const DataProviderMixin = (superClass) =>
335
385
 
336
386
  /** @protected */
337
387
  _checkSize() {
338
- if (this.size === undefined && this._effectiveSize === 0) {
388
+ if (this.size === undefined && this._flatSize === 0) {
339
389
  console.warn(
340
390
  'The <vaadin-grid> needs the total number of items in' +
341
391
  ' order to display rows, which you can specify either by setting' +
@@ -45,13 +45,19 @@ export const DragAndDropMixin = (superClass) =>
45
45
  * @attr {between|on-top|on-top-or-between|on-grid} drop-mode
46
46
  * @type {GridDropMode | null | undefined}
47
47
  */
48
- dropMode: String,
48
+ dropMode: {
49
+ type: String,
50
+ sync: true,
51
+ },
49
52
 
50
53
  /**
51
54
  * Marks the grid's rows to be available for dragging.
52
55
  * @attr {boolean} rows-draggable
53
56
  */
54
- rowsDraggable: Boolean,
57
+ rowsDraggable: {
58
+ type: Boolean,
59
+ sync: true,
60
+ },
55
61
 
56
62
  /**
57
63
  * A function that filters dragging of specific grid rows. The return value should be false
@@ -68,7 +74,10 @@ export const DragAndDropMixin = (superClass) =>
68
74
  *
69
75
  * @type {GridDragAndDropFilter | null | undefined}
70
76
  */
71
- dragFilter: Function,
77
+ dragFilter: {
78
+ type: Function,
79
+ sync: true,
80
+ },
72
81
 
73
82
  /**
74
83
  * A function that filters dropping on specific grid rows. The return value should be false
@@ -85,7 +94,10 @@ export const DragAndDropMixin = (superClass) =>
85
94
  *
86
95
  * @type {GridDragAndDropFilter | null | undefined}
87
96
  */
88
- dropFilter: Function,
97
+ dropFilter: {
98
+ type: Function,
99
+ sync: true,
100
+ },
89
101
 
90
102
  /** @private */
91
103
  __dndAutoScrollThreshold: {
@@ -211,7 +223,7 @@ export const DragAndDropMixin = (superClass) =>
211
223
 
212
224
  let row = e.composedPath().find((node) => node.localName === 'tr');
213
225
 
214
- if (!this._effectiveSize || this.dropMode === DropMode.ON_GRID) {
226
+ if (!this._flatSize || this.dropMode === DropMode.ON_GRID) {
215
227
  // The grid is empty or "on-grid" drop mode was used, always default to "empty"
216
228
  this._dropLocation = DropLocation.EMPTY;
217
229
  } else if (!row || row.parentNode !== this.$.items) {
@@ -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 FlattenedNodesObserver.getFlattenedNodes(el).filter(this._isColumnElement);
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 = FlattenedNodesObserver.getFlattenedNodes(this).filter(this._isColumnElement);
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 FlattenedNodesObserver(this, (info) => {
111
- const hasColumnElements = (nodeCollection) => nodeCollection.filter(this._isColumnElement).length > 0;
112
- if (hasColumnElements(info.addedNodes) || hasColumnElements(info.removedNodes)) {
113
- const allRemovedCells = info.removedNodes.flatMap((c) => c._allCells);
114
- const filterNotConnected = (element) =>
115
- allRemovedCells.filter((cell) => cell && cell._content.contains(element)).length;
116
-
117
- this.__removeSorters(this._sorters.filter(filterNotConnected));
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 && !(element instanceof PolymerElement)) {
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 GridColumn<TItem> {
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
- * JS Path of the property in the item used for filtering the data.
30
- */
31
- path: string | null | undefined;
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
+ }