@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,320 @@
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 { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
8
+ import { microTask } from '@vaadin/component-base/src/async.js';
9
+ import { ColumnBaseMixin } from './vaadin-grid-column.js';
10
+ import { updateColumnOrders } from './vaadin-grid-helpers.js';
11
+
12
+ /**
13
+ * A `<vaadin-grid-column-group>` is used to make groups of columns in `<vaadin-grid>` and
14
+ * to configure additional headers and footers.
15
+ *
16
+ * Groups can be nested to create complex header and footer configurations.
17
+ *
18
+ * #### Example:
19
+ * ```html
20
+ * <vaadin-grid-column-group resizable id="columnGroup">
21
+ * <vaadin-grid-column id="column1"></vaadin-grid-column>
22
+ * <vaadin-grid-column id="column2"></vaadin-grid-column>
23
+ * </vaadin-grid-column-group>
24
+ * ```
25
+ *
26
+ * ```js
27
+ * const columnGroup = document.querySelector('#columnGroup');
28
+ * columnGroup.headerRenderer = (root, columnGroup) => {
29
+ * root.textContent = 'header';
30
+ * }
31
+ *
32
+ * const column1 = document.querySelector('#column1');
33
+ * column1.headerRenderer = (root, column) => { ... };
34
+ * column1.renderer = (root, column, model) => { ... };
35
+ *
36
+ * const column2 = document.querySelector('#column2');
37
+ * column2.headerRenderer = (root, column) => { ... };
38
+ * column2.renderer = (root, column, model) => { ... };
39
+ * ```
40
+ *
41
+ * @extends HTMLElement
42
+ * @mixes ColumnBaseMixin
43
+ */
44
+ class GridColumnGroup extends ColumnBaseMixin(PolymerElement) {
45
+ static get is() {
46
+ return 'vaadin-grid-column-group';
47
+ }
48
+
49
+ static get properties() {
50
+ return {
51
+ /** @private */
52
+ _childColumns: {
53
+ value: function () {
54
+ return this._getChildColumns(this);
55
+ }
56
+ },
57
+
58
+ /**
59
+ * Flex grow ratio for the column group as the sum of the ratios of its child columns.
60
+ * @attr {number} flex-grow
61
+ */
62
+ flexGrow: {
63
+ type: Number,
64
+ readOnly: true
65
+ },
66
+
67
+ /**
68
+ * Width of the column group as the sum of the widths of its child columns.
69
+ */
70
+ width: {
71
+ type: String,
72
+ readOnly: true
73
+ },
74
+
75
+ /** @private */
76
+ _visibleChildColumns: Array,
77
+
78
+ /** @private */
79
+ _colSpan: Number,
80
+
81
+ /** @private */
82
+ _rootColumns: Array
83
+ };
84
+ }
85
+
86
+ static get observers() {
87
+ return [
88
+ '_updateVisibleChildColumns(_childColumns)',
89
+ '_childColumnsChanged(_childColumns)',
90
+ '_groupFrozenChanged(frozen, _rootColumns)',
91
+ '_groupHiddenChanged(hidden, _rootColumns)',
92
+ '_visibleChildColumnsChanged(_visibleChildColumns)',
93
+ '_colSpanChanged(_colSpan, _headerCell, _footerCell)',
94
+ '_groupOrderChanged(_order, _rootColumns)',
95
+ '_groupReorderStatusChanged(_reorderStatus, _rootColumns)',
96
+ '_groupResizableChanged(resizable, _rootColumns)'
97
+ ];
98
+ }
99
+
100
+ /** @protected */
101
+ connectedCallback() {
102
+ super.connectedCallback();
103
+ this._addNodeObserver();
104
+ this._updateFlexAndWidth();
105
+ }
106
+
107
+ /** @protected */
108
+ disconnectedCallback() {
109
+ super.disconnectedCallback();
110
+ this._observer && this._observer.disconnect();
111
+ }
112
+
113
+ /**
114
+ * @param {string} path
115
+ * @param {unknown=} value
116
+ * @protected
117
+ */
118
+ _columnPropChanged(path, value) {
119
+ if (path === 'hidden') {
120
+ this._preventHiddenCascade = true;
121
+ this._updateVisibleChildColumns(this._childColumns);
122
+ this._preventHiddenCascade = false;
123
+ }
124
+
125
+ if (/flexGrow|width|hidden|_childColumns/.test(path)) {
126
+ this._updateFlexAndWidth();
127
+ }
128
+
129
+ if (path === 'frozen') {
130
+ // Don’t unfreeze the frozen group because of a non-frozen child
131
+ this.frozen = this.frozen || value;
132
+ }
133
+
134
+ if (path === 'lastFrozen') {
135
+ // Don’t unfreeze the frozen group because of a non-frozen child
136
+ this._lastFrozen = this._lastFrozen || value;
137
+ }
138
+ }
139
+
140
+ /** @private */
141
+ _groupOrderChanged(order, rootColumns) {
142
+ if (rootColumns) {
143
+ const _rootColumns = rootColumns.slice(0);
144
+
145
+ if (!order) {
146
+ _rootColumns.forEach((column) => (column._order = 0));
147
+ return;
148
+ }
149
+ // The parent column order number cascades downwards to it's children
150
+ // so that the resulting order numbering constructs as follows:
151
+ // [ 1000 ]
152
+ // [ 1100 ] | [ 1200 ]
153
+ // [1110] | [1120] | [1210] | [1220]
154
+
155
+ // Trailing zeros are counted so we know the level on which we're working on.
156
+ const trailingZeros = /(0+)$/.exec(order).pop().length;
157
+
158
+ // In an unlikely situation where a group has more than 9 child columns,
159
+ // the child scope must have 1 digit less...
160
+ // Log^a_b = Ln(a)/Ln(b)
161
+ // Number of digits of a number is equal to floor(Log(number)_10) + 1
162
+ const childCountDigits = ~~(Math.log(rootColumns.length) / Math.LN10) + 1;
163
+
164
+ // Final scope for the child columns needs to mind both factors.
165
+ const scope = Math.pow(10, trailingZeros - childCountDigits);
166
+
167
+ if (_rootColumns[0] && _rootColumns[0]._order) {
168
+ _rootColumns.sort((a, b) => a._order - b._order);
169
+ }
170
+ updateColumnOrders(_rootColumns, scope, order);
171
+ }
172
+ }
173
+
174
+ /** @private */
175
+ _groupReorderStatusChanged(reorderStatus, rootColumns) {
176
+ if (reorderStatus === undefined || rootColumns === undefined) {
177
+ return;
178
+ }
179
+
180
+ rootColumns.forEach((column) => (column._reorderStatus = reorderStatus));
181
+ }
182
+
183
+ /** @private */
184
+ _groupResizableChanged(resizable, rootColumns) {
185
+ if (resizable === undefined || rootColumns === undefined) {
186
+ return;
187
+ }
188
+
189
+ rootColumns.forEach((column) => (column.resizable = resizable));
190
+ }
191
+
192
+ /** @private */
193
+ _updateVisibleChildColumns(childColumns) {
194
+ this._visibleChildColumns = Array.prototype.filter.call(childColumns, (col) => !col.hidden);
195
+ }
196
+
197
+ /** @private */
198
+ _childColumnsChanged(childColumns) {
199
+ if (!this._autoHidden && this.hidden) {
200
+ Array.prototype.forEach.call(childColumns, (column) => (column.hidden = true));
201
+ this._updateVisibleChildColumns(childColumns);
202
+ }
203
+ }
204
+
205
+ /** @protected */
206
+ _updateFlexAndWidth() {
207
+ if (!this._visibleChildColumns) {
208
+ return;
209
+ }
210
+
211
+ if (this._visibleChildColumns.length) {
212
+ this._setWidth(
213
+ 'calc(' +
214
+ Array.prototype.reduce
215
+ .call(
216
+ this._visibleChildColumns,
217
+ (prev, curr) => (prev += ' + ' + (curr.width || '0px').replace('calc', '')),
218
+ ''
219
+ )
220
+ .substring(3) +
221
+ ')'
222
+ );
223
+ } else {
224
+ this._setWidth('0px');
225
+ }
226
+
227
+ this._setFlexGrow(Array.prototype.reduce.call(this._visibleChildColumns, (prev, curr) => prev + curr.flexGrow, 0));
228
+ }
229
+
230
+ /** @private */
231
+ _groupFrozenChanged(frozen, rootColumns) {
232
+ if (rootColumns === undefined || frozen === undefined) {
233
+ return;
234
+ }
235
+
236
+ // Don’t propagate the default `false` value.
237
+ if (frozen !== false) {
238
+ Array.from(rootColumns).forEach((col) => (col.frozen = frozen));
239
+ }
240
+ }
241
+
242
+ /** @private */
243
+ _groupHiddenChanged(hidden, rootColumns) {
244
+ if (rootColumns && !this._preventHiddenCascade) {
245
+ this._ignoreVisibleChildColumns = true;
246
+ rootColumns.forEach((column) => (column.hidden = hidden));
247
+ this._ignoreVisibleChildColumns = false;
248
+ }
249
+
250
+ this._columnPropChanged('hidden');
251
+ }
252
+
253
+ /** @private */
254
+ _visibleChildColumnsChanged(visibleChildColumns) {
255
+ this._colSpan = visibleChildColumns.length;
256
+
257
+ if (!this._ignoreVisibleChildColumns) {
258
+ if (visibleChildColumns.length === 0) {
259
+ this._autoHidden = this.hidden = true;
260
+ } else if (this.hidden && this._autoHidden) {
261
+ this._autoHidden = this.hidden = false;
262
+ }
263
+ }
264
+ }
265
+
266
+ /** @private */
267
+ _colSpanChanged(colSpan, headerCell, footerCell) {
268
+ if (headerCell) {
269
+ headerCell.setAttribute('colspan', colSpan);
270
+ this._grid && this._grid._a11yUpdateCellColspan(headerCell, colSpan);
271
+ }
272
+ if (footerCell) {
273
+ footerCell.setAttribute('colspan', colSpan);
274
+ this._grid && this._grid._a11yUpdateCellColspan(footerCell, colSpan);
275
+ }
276
+ }
277
+
278
+ /**
279
+ * @param {!GridColumnGroup} el
280
+ * @return {!Array<!GridColumn>}
281
+ * @protected
282
+ */
283
+ _getChildColumns(el) {
284
+ return FlattenedNodesObserver.getFlattenedNodes(el).filter(this._isColumnElement);
285
+ }
286
+
287
+ /** @private */
288
+ _addNodeObserver() {
289
+ this._observer = new FlattenedNodesObserver(this, (info) => {
290
+ if (
291
+ info.addedNodes.filter(this._isColumnElement).length > 0 ||
292
+ info.removedNodes.filter(this._isColumnElement).length > 0
293
+ ) {
294
+ this._preventHiddenCascade = true;
295
+ this._rootColumns = this._getChildColumns(this);
296
+ this._childColumns = this._rootColumns;
297
+ this._preventHiddenCascade = false;
298
+
299
+ // Update the column tree with microtask timing to avoid shady style scope issues
300
+ microTask.run(() => {
301
+ this._grid && this._grid._updateColumnTree && this._grid._updateColumnTree();
302
+ });
303
+ }
304
+ });
305
+ this._observer.flush();
306
+ }
307
+
308
+ /**
309
+ * @param {!Node} node
310
+ * @return {boolean}
311
+ * @protected
312
+ */
313
+ _isColumnElement(node) {
314
+ return node.nodeType === Node.ELEMENT_NODE && /\bcolumn\b/.test(node.localName);
315
+ }
316
+ }
317
+
318
+ customElements.define(GridColumnGroup.is, GridColumnGroup);
319
+
320
+ export { GridColumnGroup };
@@ -0,0 +1,19 @@
1
+ declare function ColumnReorderingMixin<T extends new (...args: any[]) => {}>(
2
+ base: T
3
+ ): T & ColumnReorderingMixinConstructor;
4
+
5
+ interface ColumnReorderingMixinConstructor {
6
+ new (...args: any[]): ColumnReorderingMixin;
7
+ }
8
+
9
+ export { ColumnReorderingMixinConstructor };
10
+
11
+ interface ColumnReorderingMixin {
12
+ /**
13
+ * Set to true to allow column reordering.
14
+ * @attr {boolean} column-reordering-allowed
15
+ */
16
+ columnReorderingAllowed: boolean;
17
+ }
18
+
19
+ export { ColumnReorderingMixin };