@vaadin/grid 24.2.0-dev.f254716fe → 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.
Files changed (40) hide show
  1. package/package.json +11 -11
  2. package/src/vaadin-grid-array-data-provider-mixin.js +1 -1
  3. package/src/vaadin-grid-column-group-mixin.d.ts +20 -0
  4. package/src/vaadin-grid-column-group-mixin.js +369 -0
  5. package/src/vaadin-grid-column-group.d.ts +4 -14
  6. package/src/vaadin-grid-column-group.js +8 -356
  7. package/src/vaadin-grid-column-mixin.d.ts +156 -0
  8. package/src/vaadin-grid-column-mixin.js +887 -0
  9. package/src/vaadin-grid-column.d.ts +11 -138
  10. package/src/vaadin-grid-column.js +6 -876
  11. package/src/vaadin-grid-data-provider-mixin.d.ts +6 -5
  12. package/src/vaadin-grid-data-provider-mixin.js +51 -20
  13. package/src/vaadin-grid-drag-and-drop-mixin.js +1 -1
  14. package/src/vaadin-grid-dynamic-columns-mixin.js +1 -1
  15. package/src/vaadin-grid-filter-column.js +5 -1
  16. package/src/vaadin-grid-filter-element-mixin.d.ts +34 -0
  17. package/src/vaadin-grid-filter-element-mixin.js +99 -0
  18. package/src/vaadin-grid-filter.d.ts +4 -21
  19. package/src/vaadin-grid-filter.js +8 -85
  20. package/src/vaadin-grid-keyboard-navigation-mixin.js +24 -4
  21. package/src/vaadin-grid-mixin.d.ts +218 -0
  22. package/src/vaadin-grid-mixin.js +1022 -0
  23. package/src/vaadin-grid-scroll-mixin.js +1 -1
  24. package/src/vaadin-grid-selection-column-base-mixin.d.ts +6 -0
  25. package/src/vaadin-grid-selection-column-base-mixin.js +151 -0
  26. package/src/vaadin-grid-selection-column.js +4 -1
  27. package/src/vaadin-grid-sort-column.js +5 -1
  28. package/src/vaadin-grid-sorter-mixin.d.ts +44 -0
  29. package/src/vaadin-grid-sorter-mixin.js +198 -0
  30. package/src/vaadin-grid-sorter.d.ts +3 -32
  31. package/src/vaadin-grid-sorter.js +8 -182
  32. package/src/vaadin-grid-tree-column-mixin.d.ts +19 -0
  33. package/src/vaadin-grid-tree-column-mixin.js +92 -0
  34. package/src/vaadin-grid-tree-column.d.ts +9 -7
  35. package/src/vaadin-grid-tree-column.js +7 -82
  36. package/src/vaadin-grid-tree-toggle.js +3 -1
  37. package/src/vaadin-grid.d.ts +5 -190
  38. package/src/vaadin-grid.js +7 -1018
  39. package/web-types.json +2311 -0
  40. package/web-types.lit.json +1007 -0
@@ -3,12 +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 { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
6
+
7
7
  import { PolymerElement } from '@polymer/polymer/polymer-element.js';
8
- import { animationFrame } from '@vaadin/component-base/src/async.js';
9
- import { Debouncer } from '@vaadin/component-base/src/debounce.js';
10
- import { ColumnBaseMixin } from './vaadin-grid-column.js';
11
- import { updateColumnOrders } from './vaadin-grid-helpers.js';
8
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
9
+ import { GridColumnGroupMixin } from './vaadin-grid-column-group-mixin.js';
10
+ export * from './vaadin-grid-column-group-mixin.js';
12
11
 
13
12
  /**
14
13
  * A `<vaadin-grid-column-group>` is used to make groups of columns in `<vaadin-grid>` and
@@ -39,363 +38,16 @@ import { updateColumnOrders } from './vaadin-grid-helpers.js';
39
38
  * column2.renderer = (root, column, model) => { ... };
40
39
  * ```
41
40
  *
41
+ * @customElement
42
42
  * @extends HTMLElement
43
- * @mixes ColumnBaseMixin
43
+ * @mixes GridColumnGroupMixin
44
44
  */
45
- class GridColumnGroup extends ColumnBaseMixin(PolymerElement) {
45
+ class GridColumnGroup extends GridColumnGroupMixin(PolymerElement) {
46
46
  static get is() {
47
47
  return 'vaadin-grid-column-group';
48
48
  }
49
-
50
- static get properties() {
51
- return {
52
- /** @private */
53
- _childColumns: {
54
- value() {
55
- return this._getChildColumns(this);
56
- },
57
- },
58
-
59
- /**
60
- * Flex grow ratio for the column group as the sum of the ratios of its child columns.
61
- * @attr {number} flex-grow
62
- */
63
- flexGrow: {
64
- type: Number,
65
- readOnly: true,
66
- },
67
-
68
- /**
69
- * Width of the column group as the sum of the widths of its child columns.
70
- */
71
- width: {
72
- type: String,
73
- readOnly: true,
74
- },
75
-
76
- /** @private */
77
- _visibleChildColumns: Array,
78
-
79
- /** @private */
80
- _colSpan: Number,
81
-
82
- /** @private */
83
- _rootColumns: Array,
84
- };
85
- }
86
-
87
- static get observers() {
88
- return [
89
- '_groupFrozenChanged(frozen, _rootColumns)',
90
- '_groupFrozenToEndChanged(frozenToEnd, _rootColumns)',
91
- '_groupHiddenChanged(hidden)',
92
- '_colSpanChanged(_colSpan, _headerCell, _footerCell)',
93
- '_groupOrderChanged(_order, _rootColumns)',
94
- '_groupReorderStatusChanged(_reorderStatus, _rootColumns)',
95
- '_groupResizableChanged(resizable, _rootColumns)',
96
- ];
97
- }
98
-
99
- /** @protected */
100
- connectedCallback() {
101
- super.connectedCallback();
102
- this._addNodeObserver();
103
- this._updateFlexAndWidth();
104
- }
105
-
106
- /** @protected */
107
- disconnectedCallback() {
108
- super.disconnectedCallback();
109
- if (this._observer) {
110
- this._observer.disconnect();
111
- }
112
- }
113
-
114
- /**
115
- * @param {string} path
116
- * @param {unknown=} value
117
- * @protected
118
- */
119
- _columnPropChanged(path, value) {
120
- if (path === 'hidden') {
121
- // Prevent synchronization of the hidden state to child columns.
122
- // If the group is currently auto-hidden, and one column is made visible,
123
- // we don't want the other columns to become visible as well.
124
- this._preventHiddenSynchronization = true;
125
- this._updateVisibleChildColumns(this._childColumns);
126
- this._preventHiddenSynchronization = false;
127
- }
128
-
129
- if (/flexGrow|width|hidden|_childColumns/u.test(path)) {
130
- this._updateFlexAndWidth();
131
- }
132
-
133
- // Don't unfreeze the frozen group because of a non-frozen child
134
- if (path === 'frozen' && !this.frozen) {
135
- this.frozen = value;
136
- }
137
-
138
- // Don't unfreeze the frozen group because of a non-frozen child
139
- if (path === 'lastFrozen' && !this._lastFrozen) {
140
- this._lastFrozen = value;
141
- }
142
-
143
- // Don't unfreeze the frozen group because of a non-frozen child
144
- if (path === 'frozenToEnd' && !this.frozenToEnd) {
145
- this.frozenToEnd = value;
146
- }
147
-
148
- // Don't unfreeze the frozen group because of a non-frozen child
149
- if (path === 'firstFrozenToEnd' && !this._firstFrozenToEnd) {
150
- this._firstFrozenToEnd = value;
151
- }
152
- }
153
-
154
- /** @private */
155
- _groupOrderChanged(order, rootColumns) {
156
- if (rootColumns) {
157
- const _rootColumns = rootColumns.slice(0);
158
-
159
- if (!order) {
160
- _rootColumns.forEach((column) => {
161
- column._order = 0;
162
- });
163
- return;
164
- }
165
- // The parent column order number cascades downwards to it's children
166
- // so that the resulting order numbering constructs as follows:
167
- // [ 1000 ]
168
- // [ 1100 ] | [ 1200 ]
169
- // [1110] | [1120] | [1210] | [1220]
170
-
171
- // Trailing zeros are counted so we know the level on which we're working on.
172
- const trailingZeros = /(0+)$/u.exec(order).pop().length;
173
-
174
- // In an unlikely situation where a group has more than 9 child columns,
175
- // the child scope must have 1 digit less...
176
- // Log^a_b = Ln(a)/Ln(b)
177
- // Number of digits of a number is equal to floor(Log(number)_10) + 1
178
- const childCountDigits = ~~(Math.log(rootColumns.length) / Math.LN10) + 1;
179
-
180
- // Final scope for the child columns needs to mind both factors.
181
- const scope = 10 ** (trailingZeros - childCountDigits);
182
-
183
- if (_rootColumns[0] && _rootColumns[0]._order) {
184
- _rootColumns.sort((a, b) => a._order - b._order);
185
- }
186
- updateColumnOrders(_rootColumns, scope, order);
187
- }
188
- }
189
-
190
- /** @private */
191
- _groupReorderStatusChanged(reorderStatus, rootColumns) {
192
- if (reorderStatus === undefined || rootColumns === undefined) {
193
- return;
194
- }
195
-
196
- rootColumns.forEach((column) => {
197
- column._reorderStatus = reorderStatus;
198
- });
199
- }
200
-
201
- /** @private */
202
- _groupResizableChanged(resizable, rootColumns) {
203
- if (resizable === undefined || rootColumns === undefined) {
204
- return;
205
- }
206
-
207
- rootColumns.forEach((column) => {
208
- column.resizable = resizable;
209
- });
210
- }
211
-
212
- /** @private */
213
- _updateVisibleChildColumns(childColumns) {
214
- this._visibleChildColumns = Array.prototype.filter.call(childColumns, (col) => !col.hidden);
215
- this._colSpan = this._visibleChildColumns.length;
216
- this._updateAutoHidden();
217
- }
218
-
219
- /** @protected */
220
- _updateFlexAndWidth() {
221
- if (!this._visibleChildColumns) {
222
- return;
223
- }
224
-
225
- if (this._visibleChildColumns.length > 0) {
226
- const width = this._visibleChildColumns
227
- .reduce((prev, curr) => {
228
- prev += ` + ${(curr.width || '0px').replace('calc', '')}`;
229
- return prev;
230
- }, '')
231
- .substring(3);
232
- this._setWidth(`calc(${width})`);
233
- } else {
234
- this._setWidth('0px');
235
- }
236
-
237
- this._setFlexGrow(Array.prototype.reduce.call(this._visibleChildColumns, (prev, curr) => prev + curr.flexGrow, 0));
238
- }
239
-
240
- /**
241
- * This method is called before the group's frozen value is being propagated to the child columns.
242
- * In case some of the child columns are frozen, while others are not, the non-frozen ones
243
- * will get automatically frozen as well. As this may sometimes be unintended, this method
244
- * shows a warning in the console in such cases.
245
- * @private
246
- */
247
- __scheduleAutoFreezeWarning(columns, frozenProp) {
248
- if (this._grid) {
249
- // Derive the attribute name from the property name
250
- const frozenAttr = frozenProp.replace(/([A-Z])/gu, '-$1').toLowerCase();
251
-
252
- // Check if all the columns have the same frozen value
253
- const firstColumnFrozen = columns[0][frozenProp] || columns[0].hasAttribute(frozenAttr);
254
- const allSameFrozen = columns.every((column) => {
255
- return (column[frozenProp] || column.hasAttribute(frozenAttr)) === firstColumnFrozen;
256
- });
257
-
258
- if (!allSameFrozen) {
259
- // Some of the child columns are frozen, some are not. Show a warning.
260
- this._grid.__autoFreezeWarningDebouncer = Debouncer.debounce(
261
- this._grid.__autoFreezeWarningDebouncer,
262
- animationFrame,
263
- () => {
264
- console.warn(
265
- `WARNING: Joining ${frozenProp} and non-${frozenProp} Grid columns inside the same column group! ` +
266
- `This will automatically freeze all the joined columns to avoid rendering issues. ` +
267
- `If this was intentional, consider marking each joined column explicitly as ${frozenProp}. ` +
268
- `Otherwise, exclude the ${frozenProp} columns from the joined group.`,
269
- );
270
- },
271
- );
272
- }
273
- }
274
- }
275
-
276
- /** @private */
277
- _groupFrozenChanged(frozen, rootColumns) {
278
- if (rootColumns === undefined || frozen === undefined) {
279
- return;
280
- }
281
-
282
- // Don't propagate the default `false` value.
283
- if (frozen !== false) {
284
- this.__scheduleAutoFreezeWarning(rootColumns, 'frozen');
285
-
286
- Array.from(rootColumns).forEach((col) => {
287
- col.frozen = frozen;
288
- });
289
- }
290
- }
291
-
292
- /** @private */
293
- _groupFrozenToEndChanged(frozenToEnd, rootColumns) {
294
- if (rootColumns === undefined || frozenToEnd === undefined) {
295
- return;
296
- }
297
-
298
- // Don't propagate the default `false` value.
299
- if (frozenToEnd !== false) {
300
- this.__scheduleAutoFreezeWarning(rootColumns, 'frozenToEnd');
301
-
302
- Array.from(rootColumns).forEach((col) => {
303
- col.frozenToEnd = frozenToEnd;
304
- });
305
- }
306
- }
307
-
308
- /** @private */
309
- _groupHiddenChanged(hidden) {
310
- // When initializing the hidden property, only sync hidden state to columns
311
- // if group is actually hidden. Otherwise, we could override a hidden column
312
- // to be visible.
313
- // We always want to run this though if the property is actually changed.
314
- if (hidden || this.__groupHiddenInitialized) {
315
- this._synchronizeHidden();
316
- }
317
- this.__groupHiddenInitialized = true;
318
- }
319
-
320
- /** @private */
321
- _updateAutoHidden() {
322
- const wasAutoHidden = this._autoHidden;
323
- this._autoHidden = (this._visibleChildColumns || []).length === 0;
324
- // Only modify hidden state if group was auto-hidden, or becomes auto-hidden
325
- if (wasAutoHidden || this._autoHidden) {
326
- this.hidden = this._autoHidden;
327
- }
328
- }
329
-
330
- /** @private */
331
- _synchronizeHidden() {
332
- if (this._childColumns && !this._preventHiddenSynchronization) {
333
- this._childColumns.forEach((column) => {
334
- column.hidden = this.hidden;
335
- });
336
- }
337
- }
338
-
339
- /** @private */
340
- _colSpanChanged(colSpan, headerCell, footerCell) {
341
- if (headerCell) {
342
- headerCell.setAttribute('colspan', colSpan);
343
- if (this._grid) {
344
- this._grid._a11yUpdateCellColspan(headerCell, colSpan);
345
- }
346
- }
347
- if (footerCell) {
348
- footerCell.setAttribute('colspan', colSpan);
349
- if (this._grid) {
350
- this._grid._a11yUpdateCellColspan(footerCell, colSpan);
351
- }
352
- }
353
- }
354
-
355
- /**
356
- * @param {!GridColumnGroup} el
357
- * @return {!Array<!GridColumn>}
358
- * @protected
359
- */
360
- _getChildColumns(el) {
361
- return FlattenedNodesObserver.getFlattenedNodes(el).filter(this._isColumnElement);
362
- }
363
-
364
- /** @private */
365
- _addNodeObserver() {
366
- this._observer = new FlattenedNodesObserver(this, (info) => {
367
- if (
368
- info.addedNodes.filter(this._isColumnElement).length > 0 ||
369
- info.removedNodes.filter(this._isColumnElement).length > 0
370
- ) {
371
- // Prevent synchronization of the hidden state to child columns.
372
- // If the group is currently auto-hidden, and a visible column is added,
373
- // we don't want the other columns to become visible as well.
374
- this._preventHiddenSynchronization = true;
375
- this._rootColumns = this._getChildColumns(this);
376
- this._childColumns = this._rootColumns;
377
- this._updateVisibleChildColumns(this._childColumns);
378
- this._preventHiddenSynchronization = false;
379
-
380
- // Update the column tree
381
- if (this._grid && this._grid._debounceUpdateColumnTree) {
382
- this._grid._debounceUpdateColumnTree();
383
- }
384
- }
385
- });
386
- this._observer.flush();
387
- }
388
-
389
- /**
390
- * @param {!Node} node
391
- * @return {boolean}
392
- * @protected
393
- */
394
- _isColumnElement(node) {
395
- return node.nodeType === Node.ELEMENT_NODE && /\bcolumn\b/u.test(node.localName);
396
- }
397
49
  }
398
50
 
399
- customElements.define(GridColumnGroup.is, GridColumnGroup);
51
+ defineCustomElement(GridColumnGroup);
400
52
 
401
53
  export { GridColumnGroup };
@@ -0,0 +1,156 @@
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 { GridItemModel } from './vaadin-grid.js';
8
+
9
+ export type GridBodyRenderer<TItem, Column extends GridColumnMixin<TItem, Column>> = (
10
+ root: HTMLElement,
11
+ column: Column,
12
+ model: GridItemModel<TItem>,
13
+ ) => void;
14
+
15
+ export type GridColumnTextAlign = 'center' | 'end' | 'start' | null;
16
+
17
+ export type GridHeaderFooterRenderer<TItem, Column extends ColumnBaseMixinClass<TItem, Column>> = (
18
+ root: HTMLElement,
19
+ column: Column,
20
+ ) => void;
21
+
22
+ export declare function ColumnBaseMixin<
23
+ TItem,
24
+ Column extends GridColumnMixin<TItem, Column>,
25
+ T extends Constructor<HTMLElement>,
26
+ >(base: T): Constructor<ColumnBaseMixinClass<TItem, Column>> & T;
27
+
28
+ export declare class ColumnBaseMixinClass<TItem, Column extends ColumnBaseMixinClass<TItem, Column>> {
29
+ /**
30
+ * When set to true, the column is user-resizable.
31
+ */
32
+ resizable: boolean | null | undefined;
33
+
34
+ /**
35
+ * When true, the column is frozen. When a column inside of a column group is frozen,
36
+ * all of the sibling columns inside the group will get frozen also.
37
+ */
38
+ frozen: boolean;
39
+
40
+ /**
41
+ * When true, the column is frozen to end of grid.
42
+ *
43
+ * When a column inside of a column group is frozen to end, all of the sibling columns
44
+ * inside the group will get frozen to end also.
45
+ *
46
+ * Column can not be set as `frozen` and `frozenToEnd` at the same time.
47
+ * @attr {boolean} frozen-to-end
48
+ */
49
+ frozenToEnd: boolean;
50
+
51
+ /**
52
+ * When true, the cells for this column will be rendered with the `role` attribute
53
+ * set as `rowheader`, instead of the `gridcell` role value used by default.
54
+ *
55
+ * When a column is set as row header, its cells will be announced by screen readers
56
+ * while navigating to help user identify the current row as uniquely as possible.
57
+ *
58
+ * @attr {boolean} row-header
59
+ */
60
+ rowHeader: boolean;
61
+
62
+ /**
63
+ * When set to true, the cells for this column are hidden.
64
+ */
65
+ hidden: boolean;
66
+
67
+ /**
68
+ * Text content to display in the header cell of the column.
69
+ */
70
+ header: string | null | undefined;
71
+
72
+ /**
73
+ * Aligns the columns cell content horizontally.
74
+ * Supported values: "start", "center" and "end".
75
+ * @attr {start|center|end} text-align
76
+ */
77
+ textAlign: GridColumnTextAlign | null | undefined;
78
+
79
+ /**
80
+ * Custom function for rendering the header content.
81
+ * Receives two arguments:
82
+ *
83
+ * - `root` The header cell content DOM element. Append your content to it.
84
+ * - `column` The `<vaadin-grid-column>` element.
85
+ */
86
+ headerRenderer: GridHeaderFooterRenderer<TItem, Column> | null | undefined;
87
+
88
+ /**
89
+ * Custom function for rendering the footer content.
90
+ * Receives two arguments:
91
+ *
92
+ * - `root` The footer cell content DOM element. Append your content to it.
93
+ * - `column` The `<vaadin-grid-column>` element.
94
+ */
95
+ footerRenderer: GridHeaderFooterRenderer<TItem, Column> | null | undefined;
96
+ }
97
+
98
+ export interface GridColumnMixin<TItem, Column extends GridColumnMixinClass<TItem, Column>>
99
+ extends GridColumnMixinClass<TItem, Column> {}
100
+
101
+ export declare class GridColumnMixinClass<
102
+ TItem,
103
+ Column extends GridColumnMixinClass<TItem, Column>,
104
+ > extends ColumnBaseMixinClass<TItem, Column> {
105
+ /**
106
+ * Width of the cells for this column.
107
+ */
108
+ width: string | null | undefined;
109
+
110
+ /**
111
+ * Flex grow ratio for the cell widths. When set to 0, cell width is fixed.
112
+ * @attr {number} flex-grow
113
+ */
114
+ flexGrow: number;
115
+
116
+ /**
117
+ * Custom function for rendering the cell content.
118
+ * Receives three arguments:
119
+ *
120
+ * - `root` The cell content DOM element. Append your content to it.
121
+ * - `column` The `<vaadin-grid-column>` element.
122
+ * - `model` The object with the properties related with
123
+ * the rendered item, contains:
124
+ * - `model.index` The index of the item.
125
+ * - `model.item` The item.
126
+ * - `model.expanded` Sublevel toggle state.
127
+ * - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
128
+ * - `model.selected` Selected state.
129
+ * - `model.detailsOpened` Details opened state.
130
+ */
131
+ renderer: GridBodyRenderer<TItem, Column> | null | undefined;
132
+
133
+ /**
134
+ * Path to an item sub-property whose value gets displayed in the column body cells.
135
+ * The property name is also shown in the column header if an explicit header or renderer isn't defined.
136
+ */
137
+ path: string | null | undefined;
138
+
139
+ /**
140
+ * Automatically sets the width of the column based on the column contents when this is set to `true`.
141
+ *
142
+ * For performance reasons the column width is calculated automatically only once when the grid items
143
+ * are rendered for the first time and the calculation only considers the rows which are currently
144
+ * rendered in DOM (a bit more than what is currently visible). If the grid is scrolled, or the cell
145
+ * content changes, the column width might not match the contents anymore.
146
+ *
147
+ * Hidden columns are ignored in the calculation and their widths are not automatically updated when
148
+ * you show a column that was initially hidden.
149
+ *
150
+ * You can manually trigger the auto sizing behavior again by calling `grid.recalculateColumnWidths()`.
151
+ *
152
+ * The column width may still grow larger when `flexGrow` is not 0.
153
+ * @attr {boolean} auto-width
154
+ */
155
+ autoWidth: boolean;
156
+ }