@vaadin/grid 22.0.0-alpha7

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