@vaadin/grid 24.3.0-alpha1 → 24.3.0-alpha3

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