@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.
Files changed (61) hide show
  1. package/package.json +18 -13
  2. package/src/vaadin-grid-a11y-mixin.js +1 -1
  3. package/src/vaadin-grid-active-item-mixin.js +1 -0
  4. package/src/vaadin-grid-array-data-provider-mixin.js +14 -17
  5. package/src/vaadin-grid-column-group-mixin.d.ts +20 -0
  6. package/src/vaadin-grid-column-group-mixin.js +364 -0
  7. package/src/vaadin-grid-column-group.d.ts +4 -14
  8. package/src/vaadin-grid-column-group.js +5 -355
  9. package/src/vaadin-grid-column-mixin.d.ts +170 -0
  10. package/src/vaadin-grid-column-mixin.js +958 -0
  11. package/src/vaadin-grid-column.d.ts +11 -138
  12. package/src/vaadin-grid-column.js +5 -876
  13. package/src/vaadin-grid-data-provider-mixin.d.ts +6 -30
  14. package/src/vaadin-grid-data-provider-mixin.js +122 -246
  15. package/src/vaadin-grid-drag-and-drop-mixin.js +17 -5
  16. package/src/vaadin-grid-dynamic-columns-mixin.js +22 -17
  17. package/src/vaadin-grid-filter-column-mixin.d.ts +22 -0
  18. package/src/vaadin-grid-filter-column-mixin.js +106 -0
  19. package/src/vaadin-grid-filter-column.d.ts +9 -11
  20. package/src/vaadin-grid-filter-column.js +3 -90
  21. package/src/vaadin-grid-filter-element-mixin.d.ts +34 -0
  22. package/src/vaadin-grid-filter-element-mixin.js +108 -0
  23. package/src/vaadin-grid-filter-mixin.js +4 -4
  24. package/src/vaadin-grid-filter.d.ts +4 -21
  25. package/src/vaadin-grid-filter.js +5 -84
  26. package/src/vaadin-grid-helpers.js +94 -0
  27. package/src/vaadin-grid-keyboard-navigation-mixin.js +11 -4
  28. package/src/vaadin-grid-mixin.js +21 -37
  29. package/src/vaadin-grid-row-details-mixin.js +7 -8
  30. package/src/vaadin-grid-scroll-mixin.js +2 -1
  31. package/src/vaadin-grid-selection-column-base-mixin.js +12 -4
  32. package/src/vaadin-grid-selection-column-mixin.d.ts +24 -0
  33. package/src/vaadin-grid-selection-column-mixin.js +194 -0
  34. package/src/vaadin-grid-selection-column.d.ts +13 -17
  35. package/src/vaadin-grid-selection-column.js +4 -186
  36. package/src/vaadin-grid-selection-mixin.js +4 -3
  37. package/src/vaadin-grid-sort-column-mixin.d.ts +36 -0
  38. package/src/vaadin-grid-sort-column-mixin.js +101 -0
  39. package/src/vaadin-grid-sort-column.d.ts +8 -26
  40. package/src/vaadin-grid-sort-column.js +3 -87
  41. package/src/vaadin-grid-sorter-mixin.d.ts +44 -0
  42. package/src/vaadin-grid-sorter-mixin.js +200 -0
  43. package/src/vaadin-grid-sorter.d.ts +3 -32
  44. package/src/vaadin-grid-sorter.js +5 -181
  45. package/src/vaadin-grid-styles.js +341 -345
  46. package/src/vaadin-grid-styling-mixin.js +8 -2
  47. package/src/vaadin-grid-tree-column-mixin.d.ts +18 -0
  48. package/src/vaadin-grid-tree-column-mixin.js +99 -0
  49. package/src/vaadin-grid-tree-column.d.ts +9 -7
  50. package/src/vaadin-grid-tree-column.js +3 -82
  51. package/src/vaadin-grid-tree-toggle-mixin.d.ts +39 -0
  52. package/src/vaadin-grid-tree-toggle-mixin.js +153 -0
  53. package/src/vaadin-grid-tree-toggle.d.ts +4 -27
  54. package/src/vaadin-grid-tree-toggle.js +9 -141
  55. package/src/vaadin-grid.d.ts +3 -0
  56. package/src/vaadin-grid.js +7 -2
  57. package/theme/lumo/vaadin-grid-sorter-styles.js +1 -1
  58. package/theme/lumo/vaadin-grid-styles.js +15 -14
  59. package/theme/material/vaadin-grid-styles.js +15 -10
  60. package/web-types.json +331 -126
  61. package/web-types.lit.json +114 -58
@@ -4,779 +4,8 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { PolymerElement } from '@polymer/polymer/polymer-element.js';
7
- import { animationFrame } from '@vaadin/component-base/src/async.js';
8
- import { Debouncer } from '@vaadin/component-base/src/debounce.js';
9
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
10
- import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
11
- import { get } from '@vaadin/component-base/src/path-utils.js';
12
- import { processTemplates } from '@vaadin/component-base/src/templates.js';
13
- import { updateCellState } from './vaadin-grid-helpers.js';
14
-
15
- /**
16
- * @polymerMixin
17
- */
18
- export const ColumnBaseMixin = (superClass) =>
19
- class ColumnBaseMixin extends superClass {
20
- static get properties() {
21
- return {
22
- /**
23
- * When set to true, the column is user-resizable.
24
- * @default false
25
- */
26
- resizable: {
27
- type: Boolean,
28
- value() {
29
- if (this.localName === 'vaadin-grid-column-group') {
30
- return;
31
- }
32
-
33
- const parent = this.parentNode;
34
- if (parent && parent.localName === 'vaadin-grid-column-group') {
35
- return parent.resizable || false;
36
- }
37
- return false;
38
- },
39
- },
40
-
41
- /**
42
- * When true, the column is frozen. When a column inside of a column group is frozen,
43
- * all of the sibling columns inside the group will get frozen also.
44
- * @type {boolean}
45
- */
46
- frozen: {
47
- type: Boolean,
48
- value: false,
49
- },
50
-
51
- /**
52
- * When true, the column is frozen to end of grid.
53
- *
54
- * When a column inside of a column group is frozen to end, all of the sibling columns
55
- * inside the group will get frozen to end also.
56
- *
57
- * Column can not be set as `frozen` and `frozenToEnd` at the same time.
58
- * @attr {boolean} frozen-to-end
59
- * @type {boolean}
60
- */
61
- frozenToEnd: {
62
- type: Boolean,
63
- value: false,
64
- },
65
-
66
- /**
67
- * When true, the cells for this column will be rendered with the `role` attribute
68
- * set as `rowheader`, instead of the `gridcell` role value used by default.
69
- *
70
- * When a column is set as row header, its cells will be announced by screen readers
71
- * while navigating to help user identify the current row as uniquely as possible.
72
- *
73
- * @attr {boolean} row-header
74
- * @type {boolean}
75
- */
76
- rowHeader: {
77
- type: Boolean,
78
- value: false,
79
- },
80
-
81
- /**
82
- * When set to true, the cells for this column are hidden.
83
- */
84
- hidden: {
85
- type: Boolean,
86
- value: false,
87
- },
88
-
89
- /**
90
- * Text content to display in the header cell of the column.
91
- */
92
- header: {
93
- type: String,
94
- },
95
-
96
- /**
97
- * Aligns the columns cell content horizontally.
98
- * Supported values: "start", "center" and "end".
99
- * @attr {start|center|end} text-align
100
- * @type {GridColumnTextAlign | null | undefined}
101
- */
102
- textAlign: {
103
- type: String,
104
- },
105
-
106
- /**
107
- * @type {boolean}
108
- * @protected
109
- */
110
- _lastFrozen: {
111
- type: Boolean,
112
- value: false,
113
- },
114
-
115
- /**
116
- * @type {boolean}
117
- * @protected
118
- */
119
- _bodyContentHidden: {
120
- type: Boolean,
121
- value: false,
122
- },
123
-
124
- /**
125
- * @type {boolean}
126
- * @protected
127
- */
128
- _firstFrozenToEnd: {
129
- type: Boolean,
130
- value: false,
131
- },
132
-
133
- /** @protected */
134
- _order: Number,
135
-
136
- /** @private */
137
- _reorderStatus: Boolean,
138
-
139
- /**
140
- * @type {Array<!HTMLElement>}
141
- * @protected
142
- */
143
- _emptyCells: Array,
144
-
145
- /** @private */
146
- _headerCell: Object,
147
-
148
- /** @private */
149
- _footerCell: Object,
150
-
151
- /** @protected */
152
- _grid: Object,
153
-
154
- /**
155
- * By default, the Polymer doesn't invoke the observer
156
- * during initialization if all of its dependencies are `undefined`.
157
- * This internal property can be used to force initial invocation of an observer
158
- * even the other dependencies of the observer are `undefined`.
159
- *
160
- * @private
161
- */
162
- __initialized: {
163
- type: Boolean,
164
- value: true,
165
- },
166
-
167
- /**
168
- * Custom function for rendering the header content.
169
- * Receives two arguments:
170
- *
171
- * - `root` The header cell content DOM element. Append your content to it.
172
- * - `column` The `<vaadin-grid-column>` element.
173
- *
174
- * @type {GridHeaderFooterRenderer | null | undefined}
175
- */
176
- headerRenderer: Function,
177
-
178
- /**
179
- * Represents the final header renderer computed on the set of observable arguments.
180
- * It is supposed to be used internally when rendering the header cell content.
181
- *
182
- * @protected
183
- * @type {GridHeaderFooterRenderer | undefined}
184
- */
185
- _headerRenderer: {
186
- type: Function,
187
- computed: '_computeHeaderRenderer(headerRenderer, header, __initialized)',
188
- },
189
-
190
- /**
191
- * Custom function for rendering the footer content.
192
- * Receives two arguments:
193
- *
194
- * - `root` The footer cell content DOM element. Append your content to it.
195
- * - `column` The `<vaadin-grid-column>` element.
196
- *
197
- * @type {GridHeaderFooterRenderer | null | undefined}
198
- */
199
- footerRenderer: Function,
200
-
201
- /**
202
- * Represents the final footer renderer computed on the set of observable arguments.
203
- * It is supposed to be used internally when rendering the footer cell content.
204
- *
205
- * @protected
206
- * @type {GridHeaderFooterRenderer | undefined}
207
- */
208
- _footerRenderer: {
209
- type: Function,
210
- computed: '_computeFooterRenderer(footerRenderer, __initialized)',
211
- },
212
-
213
- /**
214
- * An internal property that is mainly used by `vaadin-template-renderer`
215
- * to identify grid column elements.
216
- *
217
- * @private
218
- */
219
- __gridColumnElement: {
220
- type: Boolean,
221
- value: true,
222
- },
223
- };
224
- }
225
-
226
- static get observers() {
227
- return [
228
- '_widthChanged(width, _headerCell, _footerCell, _cells.*)',
229
- '_frozenChanged(frozen, _headerCell, _footerCell, _cells.*)',
230
- '_frozenToEndChanged(frozenToEnd, _headerCell, _footerCell, _cells.*)',
231
- '_flexGrowChanged(flexGrow, _headerCell, _footerCell, _cells.*)',
232
- '_textAlignChanged(textAlign, _cells.*, _headerCell, _footerCell)',
233
- '_orderChanged(_order, _headerCell, _footerCell, _cells.*)',
234
- '_lastFrozenChanged(_lastFrozen)',
235
- '_firstFrozenToEndChanged(_firstFrozenToEnd)',
236
- '_onRendererOrBindingChanged(_renderer, _cells, _bodyContentHidden, _cells.*, path)',
237
- '_onHeaderRendererOrBindingChanged(_headerRenderer, _headerCell, path, header)',
238
- '_onFooterRendererOrBindingChanged(_footerRenderer, _footerCell)',
239
- '_resizableChanged(resizable, _headerCell)',
240
- '_reorderStatusChanged(_reorderStatus, _headerCell, _footerCell, _cells.*)',
241
- '_hiddenChanged(hidden, _headerCell, _footerCell, _cells.*)',
242
- '_rowHeaderChanged(rowHeader, _cells.*)',
243
- ];
244
- }
245
-
246
- /**
247
- * @return {!Grid | undefined}
248
- * @protected
249
- */
250
- get _grid() {
251
- if (!this._gridValue) {
252
- this._gridValue = this._findHostGrid();
253
- }
254
- return this._gridValue;
255
- }
256
-
257
- /**
258
- * @return {!Array<!HTMLElement>}
259
- * @protected
260
- */
261
- get _allCells() {
262
- return []
263
- .concat(this._cells || [])
264
- .concat(this._emptyCells || [])
265
- .concat(this._headerCell)
266
- .concat(this._footerCell)
267
- .filter((cell) => cell);
268
- }
269
-
270
- /** @protected */
271
- connectedCallback() {
272
- super.connectedCallback();
273
-
274
- // Adds the column cells to the grid after the column is attached
275
- requestAnimationFrame(() => {
276
- // Skip if the column has been detached
277
- if (!this._grid) {
278
- return;
279
- }
280
-
281
- this._allCells.forEach((cell) => {
282
- if (!cell._content.parentNode) {
283
- this._grid.appendChild(cell._content);
284
- }
285
- });
286
- });
287
- }
288
-
289
- /** @protected */
290
- disconnectedCallback() {
291
- super.disconnectedCallback();
292
-
293
- // Removes the column cells from the grid after the column is detached
294
- requestAnimationFrame(() => {
295
- // Skip if the column has been attached again
296
- if (this._grid) {
297
- return;
298
- }
299
-
300
- this._allCells.forEach((cell) => {
301
- if (cell._content.parentNode) {
302
- cell._content.parentNode.removeChild(cell._content);
303
- }
304
- });
305
- });
306
-
307
- this._gridValue = undefined;
308
- }
309
-
310
- /** @protected */
311
- ready() {
312
- super.ready();
313
-
314
- processTemplates(this);
315
- }
316
-
317
- /**
318
- * @return {!Grid | undefined}
319
- * @protected
320
- */
321
- _findHostGrid() {
322
- // eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
323
- let el = this;
324
- // Custom elements extending grid must have a specific localName
325
- while (el && !/^vaadin.*grid(-pro)?$/u.test(el.localName)) {
326
- el = el.assignedSlot ? el.assignedSlot.parentNode : el.parentNode;
327
- }
328
- return el || undefined;
329
- }
330
-
331
- /** @protected */
332
- _renderHeaderAndFooter() {
333
- this._renderHeaderCellContent(this._headerRenderer, this._headerCell);
334
- this._renderFooterCellContent(this._footerRenderer, this._footerCell);
335
- }
336
-
337
- /** @private */
338
- _flexGrowChanged(flexGrow) {
339
- if (this.parentElement && this.parentElement._columnPropChanged) {
340
- this.parentElement._columnPropChanged('flexGrow');
341
- }
342
-
343
- this._allCells.forEach((cell) => {
344
- cell.style.flexGrow = flexGrow;
345
- });
346
- }
347
-
348
- /** @private */
349
- _orderChanged(order) {
350
- this._allCells.forEach((cell) => {
351
- cell.style.order = order;
352
- });
353
- }
354
-
355
- /** @private */
356
- _widthChanged(width) {
357
- if (this.parentElement && this.parentElement._columnPropChanged) {
358
- this.parentElement._columnPropChanged('width');
359
- }
360
-
361
- this._allCells.forEach((cell) => {
362
- cell.style.width = width;
363
- });
364
- }
365
-
366
- /** @private */
367
- _frozenChanged(frozen) {
368
- if (this.parentElement && this.parentElement._columnPropChanged) {
369
- this.parentElement._columnPropChanged('frozen', frozen);
370
- }
371
-
372
- this._allCells.forEach((cell) => {
373
- updateCellState(cell, 'frozen', frozen);
374
- });
375
-
376
- if (this._grid && this._grid._frozenCellsChanged) {
377
- this._grid._frozenCellsChanged();
378
- }
379
- }
380
-
381
- /** @private */
382
- _frozenToEndChanged(frozenToEnd) {
383
- if (this.parentElement && this.parentElement._columnPropChanged) {
384
- this.parentElement._columnPropChanged('frozenToEnd', frozenToEnd);
385
- }
386
-
387
- this._allCells.forEach((cell) => {
388
- // Skip sizer cells to keep correct scrollWidth.
389
- if (this._grid && cell.parentElement === this._grid.$.sizer) {
390
- return;
391
- }
392
-
393
- updateCellState(cell, 'frozen-to-end', frozenToEnd);
394
- });
395
-
396
- if (this._grid && this._grid._frozenCellsChanged) {
397
- this._grid._frozenCellsChanged();
398
- }
399
- }
400
-
401
- /** @private */
402
- _lastFrozenChanged(lastFrozen) {
403
- this._allCells.forEach((cell) => {
404
- updateCellState(cell, 'last-frozen', lastFrozen);
405
- });
406
-
407
- if (this.parentElement && this.parentElement._columnPropChanged) {
408
- this.parentElement._lastFrozen = lastFrozen;
409
- }
410
- }
411
-
412
- /** @private */
413
- _firstFrozenToEndChanged(firstFrozenToEnd) {
414
- this._allCells.forEach((cell) => {
415
- // Skip sizer cells to keep correct scrollWidth.
416
- if (this._grid && cell.parentElement === this._grid.$.sizer) {
417
- return;
418
- }
419
-
420
- updateCellState(cell, 'first-frozen-to-end', firstFrozenToEnd);
421
- });
422
-
423
- if (this.parentElement && this.parentElement._columnPropChanged) {
424
- this.parentElement._firstFrozenToEnd = firstFrozenToEnd;
425
- }
426
- }
427
-
428
- /** @private */
429
- _rowHeaderChanged(rowHeader, cells) {
430
- if (!cells.value) {
431
- return;
432
- }
433
-
434
- cells.value.forEach((cell) => {
435
- cell.setAttribute('role', rowHeader ? 'rowheader' : 'gridcell');
436
- });
437
- }
438
-
439
- /**
440
- * @param {string} path
441
- * @return {string}
442
- * @protected
443
- */
444
- _generateHeader(path) {
445
- return path
446
- .substr(path.lastIndexOf('.') + 1)
447
- .replace(/([A-Z])/gu, '-$1')
448
- .toLowerCase()
449
- .replace(/-/gu, ' ')
450
- .replace(/^./u, (match) => match.toUpperCase());
451
- }
452
-
453
- /** @private */
454
- _reorderStatusChanged(reorderStatus) {
455
- const prevStatus = this.__previousReorderStatus;
456
- const oldPart = prevStatus ? `reorder-${prevStatus}-cell` : '';
457
- const newPart = `reorder-${reorderStatus}-cell`;
458
-
459
- this._allCells.forEach((cell) => {
460
- updateCellState(cell, 'reorder-status', reorderStatus, newPart, oldPart);
461
- });
462
-
463
- this.__previousReorderStatus = reorderStatus;
464
- }
465
-
466
- /** @private */
467
- _resizableChanged(resizable, headerCell) {
468
- if (resizable === undefined || headerCell === undefined) {
469
- return;
470
- }
471
-
472
- if (headerCell) {
473
- [headerCell].concat(this._emptyCells).forEach((cell) => {
474
- if (cell) {
475
- const existingHandle = cell.querySelector('[part~="resize-handle"]');
476
- if (existingHandle) {
477
- cell.removeChild(existingHandle);
478
- }
479
-
480
- if (resizable) {
481
- const handle = document.createElement('div');
482
- handle.setAttribute('part', 'resize-handle');
483
- cell.appendChild(handle);
484
- }
485
- }
486
- });
487
- }
488
- }
489
-
490
- /** @private */
491
- _textAlignChanged(textAlign) {
492
- if (textAlign === undefined || this._grid === undefined) {
493
- return;
494
- }
495
- if (['start', 'end', 'center'].indexOf(textAlign) === -1) {
496
- console.warn('textAlign can only be set as "start", "end" or "center"');
497
- return;
498
- }
499
-
500
- let textAlignFallback;
501
- if (getComputedStyle(this._grid).direction === 'ltr') {
502
- if (textAlign === 'start') {
503
- textAlignFallback = 'left';
504
- } else if (textAlign === 'end') {
505
- textAlignFallback = 'right';
506
- }
507
- } else if (textAlign === 'start') {
508
- textAlignFallback = 'right';
509
- } else if (textAlign === 'end') {
510
- textAlignFallback = 'left';
511
- }
512
-
513
- this._allCells.forEach((cell) => {
514
- cell._content.style.textAlign = textAlign;
515
- if (getComputedStyle(cell._content).textAlign !== textAlign) {
516
- cell._content.style.textAlign = textAlignFallback;
517
- }
518
- });
519
- }
520
-
521
- /** @private */
522
- _hiddenChanged(hidden) {
523
- if (this.parentElement && this.parentElement._columnPropChanged) {
524
- this.parentElement._columnPropChanged('hidden', hidden);
525
- }
526
-
527
- if (!!hidden !== !!this._previousHidden && this._grid) {
528
- if (hidden === true) {
529
- this._allCells.forEach((cell) => {
530
- if (cell._content.parentNode) {
531
- cell._content.parentNode.removeChild(cell._content);
532
- }
533
- });
534
- }
535
- this._grid._debouncerHiddenChanged = Debouncer.debounce(
536
- this._grid._debouncerHiddenChanged,
537
- animationFrame,
538
- () => {
539
- if (this._grid && this._grid._renderColumnTree) {
540
- this._grid._renderColumnTree(this._grid._columnTree);
541
- }
542
- },
543
- );
544
-
545
- if (this._grid._debounceUpdateFrozenColumn) {
546
- this._grid._debounceUpdateFrozenColumn();
547
- }
548
-
549
- if (this._grid._resetKeyboardNavigation) {
550
- this._grid._resetKeyboardNavigation();
551
- }
552
- }
553
- this._previousHidden = hidden;
554
- }
555
-
556
- /** @protected */
557
- _runRenderer(renderer, cell, model) {
558
- const args = [cell._content, this];
559
- if (model && model.item) {
560
- args.push(model);
561
- }
562
-
563
- renderer.apply(this, args);
564
- }
565
-
566
- /**
567
- * Renders the content to the given cells using a renderer.
568
- *
569
- * @private
570
- */
571
- __renderCellsContent(renderer, cells) {
572
- // Skip if the column is hidden or not attached to a grid.
573
- if (this.hidden || !this._grid) {
574
- return;
575
- }
576
-
577
- cells.forEach((cell) => {
578
- if (!cell.parentElement) {
579
- return;
580
- }
581
-
582
- const model = this._grid.__getRowModel(cell.parentElement);
583
-
584
- if (!renderer) {
585
- return;
586
- }
587
-
588
- if (cell._renderer !== renderer) {
589
- this._clearCellContent(cell);
590
- }
591
-
592
- cell._renderer = renderer;
593
-
594
- if (model.item || renderer === this._headerRenderer || renderer === this._footerRenderer) {
595
- this._runRenderer(renderer, cell, model);
596
- }
597
- });
598
- }
599
-
600
- /**
601
- * Clears the content of a cell.
602
- *
603
- * @protected
604
- */
605
- _clearCellContent(cell) {
606
- cell._content.innerHTML = '';
607
- // Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
608
- // When clearing the rendered content, this part needs to be manually disposed of.
609
- // Otherwise, using a Lit-based renderer on the same node will throw an exception or render nothing afterward.
610
- delete cell._content._$litPart$;
611
- }
612
-
613
- /**
614
- * Renders the header cell content using a renderer,
615
- * and then updates the visibility of the parent row depending on
616
- * whether all its children cells are empty or not.
617
- *
618
- * @protected
619
- */
620
- _renderHeaderCellContent(headerRenderer, headerCell) {
621
- if (!headerCell || !headerRenderer) {
622
- return;
623
- }
624
-
625
- this.__renderCellsContent(headerRenderer, [headerCell]);
626
- if (this._grid && headerCell.parentElement) {
627
- this._grid.__debounceUpdateHeaderFooterRowVisibility(headerCell.parentElement);
628
- }
629
- }
630
-
631
- /** @protected */
632
- _onHeaderRendererOrBindingChanged(headerRenderer, headerCell, ..._bindings) {
633
- this._renderHeaderCellContent(headerRenderer, headerCell);
634
- }
635
-
636
- /**
637
- * Renders the content of body cells using a renderer.
638
- *
639
- * @protected
640
- */
641
- _renderBodyCellsContent(renderer, cells) {
642
- if (!cells || !renderer) {
643
- return;
644
- }
645
-
646
- this.__renderCellsContent(renderer, cells);
647
- }
648
-
649
- /** @protected */
650
- _onRendererOrBindingChanged(renderer, cells, ..._bindings) {
651
- this._renderBodyCellsContent(renderer, cells);
652
- }
653
-
654
- /**
655
- * Renders the footer cell content using a renderer
656
- * and then updates the visibility of the parent row depending on
657
- * whether all its children cells are empty or not.
658
- *
659
- * @protected
660
- */
661
- _renderFooterCellContent(footerRenderer, footerCell) {
662
- if (!footerCell || !footerRenderer) {
663
- return;
664
- }
665
-
666
- this.__renderCellsContent(footerRenderer, [footerCell]);
667
- if (this._grid && footerCell.parentElement) {
668
- this._grid.__debounceUpdateHeaderFooterRowVisibility(footerCell.parentElement);
669
- }
670
- }
671
-
672
- /** @protected */
673
- _onFooterRendererOrBindingChanged(footerRenderer, footerCell) {
674
- this._renderFooterCellContent(footerRenderer, footerCell);
675
- }
676
-
677
- /** @private */
678
- __setTextContent(node, textContent) {
679
- if (node.textContent !== textContent) {
680
- node.textContent = textContent;
681
- }
682
- }
683
-
684
- /**
685
- * Renders the text header to the header cell.
686
- *
687
- * @private
688
- */
689
- __textHeaderRenderer() {
690
- this.__setTextContent(this._headerCell._content, this.header);
691
- }
692
-
693
- /**
694
- * Computes the property name based on the path and renders it to the header cell.
695
- * If the path is not defined, then nothing is rendered.
696
- *
697
- * @protected
698
- */
699
- _defaultHeaderRenderer() {
700
- if (!this.path) {
701
- return;
702
- }
703
-
704
- this.__setTextContent(this._headerCell._content, this._generateHeader(this.path));
705
- }
706
-
707
- /**
708
- * Computes the item property value based on the path and renders it to the body cell.
709
- * If the path is not defined, then nothing is rendered.
710
- *
711
- * @protected
712
- */
713
- _defaultRenderer(root, _owner, { item }) {
714
- if (!this.path) {
715
- return;
716
- }
717
-
718
- this.__setTextContent(root, get(this.path, item));
719
- }
720
-
721
- /**
722
- * By default, nothing is rendered to the footer cell.
723
- *
724
- * @protected
725
- */
726
- _defaultFooterRenderer() {}
727
-
728
- /**
729
- * Computes the final header renderer for the `_headerRenderer` computed property.
730
- * All the arguments are observable by the Polymer, it re-calls the method
731
- * once an argument is changed to update the property value.
732
- *
733
- * @protected
734
- * @return {GridHeaderFooterRenderer | undefined}
735
- */
736
- _computeHeaderRenderer(headerRenderer, header) {
737
- if (headerRenderer) {
738
- return headerRenderer;
739
- }
740
-
741
- if (header !== undefined && header !== null) {
742
- return this.__textHeaderRenderer;
743
- }
744
-
745
- return this._defaultHeaderRenderer;
746
- }
747
-
748
- /**
749
- * Computes the final renderer for the `_renderer` property.
750
- * All the arguments are observable by the Polymer, it re-calls the method
751
- * once an argument is changed to update the property value.
752
- *
753
- * @protected
754
- * @return {GridBodyRenderer | undefined}
755
- */
756
- _computeRenderer(renderer) {
757
- if (renderer) {
758
- return renderer;
759
- }
760
-
761
- return this._defaultRenderer;
762
- }
763
-
764
- /**
765
- * Computes the final footer renderer for the `_footerRenderer` property.
766
- * All the arguments are observable by the Polymer, it re-calls the method
767
- * once an argument is changed to update the property value.
768
- *
769
- * @protected
770
- * @return {GridHeaderFooterRenderer | undefined}
771
- */
772
- _computeFooterRenderer(footerRenderer) {
773
- if (footerRenderer) {
774
- return footerRenderer;
775
- }
776
-
777
- return this._defaultFooterRenderer;
778
- }
779
- };
8
+ import { GridColumnMixin } from './vaadin-grid-column-mixin.js';
780
9
 
781
10
  /**
782
11
  * A `<vaadin-grid-column>` is used to configure how a column in `<vaadin-grid>`
@@ -787,116 +16,16 @@ export const ColumnBaseMixin = (superClass) =>
787
16
  *
788
17
  * @customElement
789
18
  * @extends HTMLElement
790
- * @mixes ColumnBaseMixin
19
+ * @mixes GridColumnMixin
791
20
  */
792
- class GridColumn extends ColumnBaseMixin(DirMixin(PolymerElement)) {
21
+ class GridColumn extends GridColumnMixin(PolymerElement) {
793
22
  static get is() {
794
23
  return 'vaadin-grid-column';
795
24
  }
796
-
797
- static get properties() {
798
- return {
799
- /**
800
- * Width of the cells for this column.
801
- */
802
- width: {
803
- type: String,
804
- value: '100px',
805
- },
806
-
807
- /**
808
- * Flex grow ratio for the cell widths. When set to 0, cell width is fixed.
809
- * @attr {number} flex-grow
810
- * @type {number}
811
- */
812
- flexGrow: {
813
- type: Number,
814
- value: 1,
815
- },
816
-
817
- /**
818
- * Custom function for rendering the cell content.
819
- * Receives three arguments:
820
- *
821
- * - `root` The cell content DOM element. Append your content to it.
822
- * - `column` The `<vaadin-grid-column>` element.
823
- * - `model` The object with the properties related with
824
- * the rendered item, contains:
825
- * - `model.index` The index of the item.
826
- * - `model.item` The item.
827
- * - `model.expanded` Sublevel toggle state.
828
- * - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
829
- * - `model.selected` Selected state.
830
- * - `model.detailsOpened` Details opened state.
831
- *
832
- * @type {GridBodyRenderer | null | undefined}
833
- */
834
- renderer: Function,
835
-
836
- /**
837
- * Represents the final renderer computed on the set of observable arguments.
838
- * It is supposed to be used internally when rendering the content of a body cell.
839
- *
840
- * @protected
841
- * @type {GridBodyRenderer | undefined}
842
- */
843
- _renderer: {
844
- type: Function,
845
- computed: '_computeRenderer(renderer, __initialized)',
846
- },
847
-
848
- /**
849
- * Path to an item sub-property whose value gets displayed in the column body cells.
850
- * The property name is also shown in the column header if an explicit header or renderer isn't defined.
851
- */
852
- path: {
853
- type: String,
854
- },
855
-
856
- /**
857
- * Automatically sets the width of the column based on the column contents when this is set to `true`.
858
- *
859
- * For performance reasons the column width is calculated automatically only once when the grid items
860
- * are rendered for the first time and the calculation only considers the rows which are currently
861
- * rendered in DOM (a bit more than what is currently visible). If the grid is scrolled, or the cell
862
- * content changes, the column width might not match the contents anymore.
863
- *
864
- * Hidden columns are ignored in the calculation and their widths are not automatically updated when
865
- * you show a column that was initially hidden.
866
- *
867
- * You can manually trigger the auto sizing behavior again by calling `grid.recalculateColumnWidths()`.
868
- *
869
- * The column width may still grow larger when `flexGrow` is not 0.
870
- * @attr {boolean} auto-width
871
- * @type {boolean}
872
- */
873
- autoWidth: {
874
- type: Boolean,
875
- value: false,
876
- },
877
-
878
- /**
879
- * When true, wraps the cell's slot into an element with role="button", and sets
880
- * the tabindex attribute on the button element, instead of the cell itself.
881
- * This is needed to keep focus in sync with VoiceOver cursor when navigating
882
- * with Control + Option + arrow keys: focusing the `<td>` element does not fire
883
- * a focus event, but focusing an element with role="button" inside a cell fires it.
884
- * @protected
885
- */
886
- _focusButtonMode: {
887
- type: Boolean,
888
- value: false,
889
- },
890
-
891
- /**
892
- * @type {Array<!HTMLElement>}
893
- * @protected
894
- */
895
- _cells: Array,
896
- };
897
- }
898
25
  }
899
26
 
900
27
  defineCustomElement(GridColumn);
901
28
 
902
29
  export { GridColumn };
30
+
31
+ export { ColumnBaseMixin } from './vaadin-grid-column-mixin.js';