@vaadin/vaadin-grid 22.0.0-alpha6 → 22.0.0-beta1
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.
- package/package.json +24 -34
- package/src/vaadin-grid-column-group.d.ts +14 -57
- package/src/vaadin-grid-column-group.js +4 -311
- package/src/vaadin-grid-column.d.ts +14 -142
- package/src/vaadin-grid-column.js +4 -759
- package/src/vaadin-grid-filter-column.d.ts +14 -30
- package/src/vaadin-grid-filter-column.js +4 -111
- package/src/vaadin-grid-filter.d.ts +11 -60
- package/src/vaadin-grid-filter.js +4 -116
- package/src/vaadin-grid-selection-column.d.ts +12 -75
- package/src/vaadin-grid-selection-column.js +4 -276
- package/src/vaadin-grid-sort-column.d.ts +12 -56
- package/src/vaadin-grid-sort-column.js +4 -109
- package/src/vaadin-grid-sorter.d.ts +11 -82
- package/src/vaadin-grid-sorter.js +4 -221
- package/src/vaadin-grid-tree-column.d.ts +14 -31
- package/src/vaadin-grid-tree-column.js +4 -110
- package/src/vaadin-grid-tree-toggle.d.ts +11 -91
- package/src/vaadin-grid-tree-toggle.js +4 -196
- package/src/vaadin-grid.d.ts +10 -422
- package/src/vaadin-grid.js +4 -1026
- package/theme/lumo/vaadin-grid-column-group.js +1 -1
- package/theme/lumo/vaadin-grid-column.js +1 -1
- package/theme/lumo/vaadin-grid-filter-column.js +1 -2
- package/theme/lumo/vaadin-grid-filter.js +1 -2
- package/theme/lumo/vaadin-grid-selection-column.js +1 -2
- package/theme/lumo/vaadin-grid-sort-column.js +1 -2
- package/theme/lumo/vaadin-grid-sorter.js +1 -2
- package/theme/lumo/vaadin-grid-tree-column.js +1 -2
- package/theme/lumo/vaadin-grid-tree-toggle.js +1 -2
- package/theme/lumo/vaadin-grid.js +1 -9
- package/theme/material/vaadin-grid-column-group.js +1 -1
- package/theme/material/vaadin-grid-column.js +1 -1
- package/theme/material/vaadin-grid-filter-column.js +1 -2
- package/theme/material/vaadin-grid-filter.js +1 -2
- package/theme/material/vaadin-grid-selection-column.js +1 -2
- package/theme/material/vaadin-grid-sort-column.js +1 -2
- package/theme/material/vaadin-grid-sorter.js +1 -2
- package/theme/material/vaadin-grid-tree-column.js +1 -2
- package/theme/material/vaadin-grid-tree-toggle.js +1 -2
- package/theme/material/vaadin-grid.js +1 -2
- package/vaadin-grid.d.ts +0 -1
- package/src/array-data-provider.js +0 -145
- package/src/interfaces.d.ts +0 -78
- package/src/vaadin-grid-a11y-mixin.d.ts +0 -27
- package/src/vaadin-grid-a11y-mixin.js +0 -158
- package/src/vaadin-grid-active-item-mixin.d.ts +0 -28
- package/src/vaadin-grid-active-item-mixin.js +0 -117
- package/src/vaadin-grid-array-data-provider-mixin.d.ts +0 -20
- package/src/vaadin-grid-array-data-provider-mixin.js +0 -75
- package/src/vaadin-grid-column-reordering-mixin.d.ts +0 -47
- package/src/vaadin-grid-column-reordering-mixin.js +0 -387
- package/src/vaadin-grid-column-resizing-mixin.d.ts +0 -11
- package/src/vaadin-grid-column-resizing-mixin.js +0 -111
- package/src/vaadin-grid-data-provider-mixin.d.ts +0 -126
- package/src/vaadin-grid-data-provider-mixin.js +0 -520
- package/src/vaadin-grid-drag-and-drop-mixin.d.ts +0 -73
- package/src/vaadin-grid-drag-and-drop-mixin.js +0 -435
- package/src/vaadin-grid-dynamic-columns-mixin.d.ts +0 -27
- package/src/vaadin-grid-dynamic-columns-mixin.js +0 -180
- package/src/vaadin-grid-event-context-mixin.d.ts +0 -33
- package/src/vaadin-grid-event-context-mixin.js +0 -57
- package/src/vaadin-grid-filter-mixin.d.ts +0 -13
- package/src/vaadin-grid-filter-mixin.js +0 -76
- package/src/vaadin-grid-helpers.js +0 -23
- package/src/vaadin-grid-keyboard-navigation-mixin.d.ts +0 -31
- package/src/vaadin-grid-keyboard-navigation-mixin.js +0 -891
- package/src/vaadin-grid-row-details-mixin.d.ts +0 -54
- package/src/vaadin-grid-row-details-mixin.js +0 -200
- package/src/vaadin-grid-scroll-mixin.d.ts +0 -22
- package/src/vaadin-grid-scroll-mixin.js +0 -202
- package/src/vaadin-grid-selection-mixin.d.ts +0 -39
- package/src/vaadin-grid-selection-mixin.js +0 -93
- package/src/vaadin-grid-sort-mixin.d.ts +0 -21
- package/src/vaadin-grid-sort-mixin.js +0 -139
- package/src/vaadin-grid-styles.js +0 -297
- package/src/vaadin-grid-styling-mixin.d.ts +0 -37
- package/src/vaadin-grid-styling-mixin.js +0 -71
- package/theme/lumo/vaadin-grid-sorter-styles.js +0 -54
- package/theme/lumo/vaadin-grid-styles.js +0 -380
- package/theme/lumo/vaadin-grid-tree-toggle-styles.js +0 -112
- package/theme/material/vaadin-grid-sorter-styles.js +0 -72
- package/theme/material/vaadin-grid-styles.js +0 -252
- package/theme/material/vaadin-grid-tree-toggle-styles.js +0 -42
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { GridDataProviderCallback, GridDataProviderParams } from './interfaces';
|
|
2
|
-
|
|
3
|
-
declare function ArrayDataProviderMixin<TItem, T extends new (...args: any[]) => {}>(
|
|
4
|
-
base: T
|
|
5
|
-
): T & ArrayDataProviderMixinConstructor<TItem>;
|
|
6
|
-
|
|
7
|
-
interface ArrayDataProviderMixinConstructor<TItem> {
|
|
8
|
-
new (...args: any[]): ArrayDataProviderMixin<TItem>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare interface ArrayDataProviderMixin<TItem> {
|
|
12
|
-
/**
|
|
13
|
-
* An array containing the items which will be passed to renderer functions.
|
|
14
|
-
*/
|
|
15
|
-
items: TItem[] | null | undefined;
|
|
16
|
-
|
|
17
|
-
_arrayDataProvider(opts: GridDataProviderParams<TItem> | null, cb: GridDataProviderCallback<TItem> | null): void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { ArrayDataProviderMixin, ArrayDataProviderMixinConstructor };
|
|
@@ -1,75 +0,0 @@
|
|
|
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 { createArrayDataProvider } from './array-data-provider.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @polymerMixin
|
|
10
|
-
*/
|
|
11
|
-
export const ArrayDataProviderMixin = (superClass) =>
|
|
12
|
-
class ArrayDataProviderMixin extends superClass {
|
|
13
|
-
static get properties() {
|
|
14
|
-
return {
|
|
15
|
-
/**
|
|
16
|
-
* An array containing the items which will be passed to renderer functions.
|
|
17
|
-
*
|
|
18
|
-
* @type {Array<!GridItem> | undefined}
|
|
19
|
-
*/
|
|
20
|
-
items: Array
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static get observers() {
|
|
25
|
-
return ['__dataProviderOrItemsChanged(dataProvider, items, isAttached, items.*, _filters, _sorters)'];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** @private */
|
|
29
|
-
__setArrayDataProvider(items) {
|
|
30
|
-
const arrayDataProvider = createArrayDataProvider(this.items, {});
|
|
31
|
-
arrayDataProvider.__items = items;
|
|
32
|
-
this.setProperties({
|
|
33
|
-
_arrayDataProvider: arrayDataProvider,
|
|
34
|
-
size: items.length,
|
|
35
|
-
dataProvider: arrayDataProvider
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** @private */
|
|
40
|
-
__dataProviderOrItemsChanged(dataProvider, items, isAttached) {
|
|
41
|
-
if (!isAttached) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (this._arrayDataProvider) {
|
|
46
|
-
// Has an items array data provider beforehand
|
|
47
|
-
|
|
48
|
-
if (dataProvider !== this._arrayDataProvider) {
|
|
49
|
-
// A custom data provider was set externally
|
|
50
|
-
this.setProperties({
|
|
51
|
-
_arrayDataProvider: undefined,
|
|
52
|
-
items: undefined
|
|
53
|
-
});
|
|
54
|
-
} else if (!items) {
|
|
55
|
-
// The items array was unset
|
|
56
|
-
this.setProperties({
|
|
57
|
-
_arrayDataProvider: undefined,
|
|
58
|
-
dataProvider: undefined,
|
|
59
|
-
size: 0
|
|
60
|
-
});
|
|
61
|
-
this.clearCache();
|
|
62
|
-
} else if (this._arrayDataProvider.__items === items) {
|
|
63
|
-
// The items array was modified
|
|
64
|
-
this.clearCache();
|
|
65
|
-
this.size = this._effectiveSize;
|
|
66
|
-
} else {
|
|
67
|
-
// The items array was replaced
|
|
68
|
-
this.__setArrayDataProvider(items);
|
|
69
|
-
}
|
|
70
|
-
} else if (items) {
|
|
71
|
-
// There was no array data provider before items was set
|
|
72
|
-
this.__setArrayDataProvider(items);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { GridColumnElement } from './vaadin-grid-column.js';
|
|
2
|
-
|
|
3
|
-
declare function ColumnReorderingMixin<TItem, T extends new (...args: any[]) => {}>(
|
|
4
|
-
base: T
|
|
5
|
-
): T & ColumnReorderingMixinConstructor<TItem>;
|
|
6
|
-
|
|
7
|
-
interface ColumnReorderingMixinConstructor<TItem> {
|
|
8
|
-
new (...args: any[]): ColumnReorderingMixin<TItem>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { ColumnReorderingMixinConstructor };
|
|
12
|
-
|
|
13
|
-
interface ColumnReorderingMixin<TItem> {
|
|
14
|
-
/**
|
|
15
|
-
* Set to true to allow column reordering.
|
|
16
|
-
* @attr {boolean} column-reordering-allowed
|
|
17
|
-
*/
|
|
18
|
-
columnReorderingAllowed: boolean;
|
|
19
|
-
|
|
20
|
-
_getColumnsInOrder(): GridColumnElement<TItem>[];
|
|
21
|
-
|
|
22
|
-
_cellFromPoint(x: number, y: number): HTMLElement | null | undefined;
|
|
23
|
-
|
|
24
|
-
_updateGhostPosition(eventClientX: number, eventClientY: number): void;
|
|
25
|
-
|
|
26
|
-
_updateGhost(cell: HTMLElement): HTMLElement;
|
|
27
|
-
|
|
28
|
-
_setSiblingsReorderStatus(column: GridColumnElement<TItem>, status: string): void;
|
|
29
|
-
|
|
30
|
-
_autoScroller(): void;
|
|
31
|
-
|
|
32
|
-
_isSwapAllowed(
|
|
33
|
-
column1: GridColumnElement<TItem> | null | undefined,
|
|
34
|
-
column2: GridColumnElement<TItem> | null | undefined
|
|
35
|
-
): boolean | undefined;
|
|
36
|
-
|
|
37
|
-
_isSwappableByPosition(targetColumn: GridColumnElement<TItem>, clientX: number): boolean;
|
|
38
|
-
|
|
39
|
-
_swapColumnOrders(column1: GridColumnElement<TItem>, column2: GridColumnElement<TItem>): void;
|
|
40
|
-
|
|
41
|
-
_getTargetColumn(
|
|
42
|
-
targetCell: HTMLElement | null | undefined,
|
|
43
|
-
draggedColumn: GridColumnElement<TItem> | null
|
|
44
|
-
): GridColumnElement<TItem> | null | undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { ColumnReorderingMixin };
|
|
@@ -1,387 +0,0 @@
|
|
|
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 { GestureEventListeners } from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
|
|
7
|
-
import { addListener } from '@polymer/polymer/lib/utils/gestures.js';
|
|
8
|
-
import { updateColumnOrders } from './vaadin-grid-helpers.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @polymerMixin
|
|
12
|
-
*/
|
|
13
|
-
export const ColumnReorderingMixin = (superClass) =>
|
|
14
|
-
class ColumnReorderingMixin extends GestureEventListeners(superClass) {
|
|
15
|
-
static get properties() {
|
|
16
|
-
return {
|
|
17
|
-
/**
|
|
18
|
-
* Set to true to allow column reordering.
|
|
19
|
-
* @attr {boolean} column-reordering-allowed
|
|
20
|
-
* @type {boolean}
|
|
21
|
-
*/
|
|
22
|
-
columnReorderingAllowed: {
|
|
23
|
-
type: Boolean,
|
|
24
|
-
value: false
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
/** @private */
|
|
28
|
-
_orderBaseScope: {
|
|
29
|
-
type: Number,
|
|
30
|
-
value: 10000000
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static get observers() {
|
|
36
|
-
return ['_updateOrders(_columnTree, _columnTree.*)'];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
ready() {
|
|
40
|
-
super.ready();
|
|
41
|
-
addListener(this, 'track', this._onTrackEvent);
|
|
42
|
-
this._reorderGhost = this.shadowRoot.querySelector('[part="reorder-ghost"]');
|
|
43
|
-
|
|
44
|
-
this.addEventListener('touchstart', this._onTouchStart.bind(this));
|
|
45
|
-
this.addEventListener('touchmove', this._onTouchMove.bind(this));
|
|
46
|
-
this.addEventListener('touchend', this._onTouchEnd.bind(this));
|
|
47
|
-
this.addEventListener('contextmenu', this._onContextMenu.bind(this));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** @private */
|
|
51
|
-
_onContextMenu(e) {
|
|
52
|
-
if (this.hasAttribute('reordering')) {
|
|
53
|
-
e.preventDefault();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** @private */
|
|
58
|
-
_onTouchStart(e) {
|
|
59
|
-
// Touch event, delay activation by 100ms
|
|
60
|
-
this._startTouchReorderTimeout = setTimeout(() => {
|
|
61
|
-
this._onTrackStart({
|
|
62
|
-
detail: {
|
|
63
|
-
x: e.touches[0].clientX,
|
|
64
|
-
y: e.touches[0].clientY
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}, 100);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** @private */
|
|
71
|
-
_onTouchMove(e) {
|
|
72
|
-
if (this._draggedColumn) {
|
|
73
|
-
e.preventDefault();
|
|
74
|
-
}
|
|
75
|
-
clearTimeout(this._startTouchReorderTimeout);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** @private */
|
|
79
|
-
_onTouchEnd() {
|
|
80
|
-
clearTimeout(this._startTouchReorderTimeout);
|
|
81
|
-
this._onTrackEnd();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** @private */
|
|
85
|
-
_onTrackEvent(e) {
|
|
86
|
-
if (e.detail.state === 'start') {
|
|
87
|
-
const path = e.composedPath();
|
|
88
|
-
const headerCell = path[path.indexOf(this.$.header) - 2];
|
|
89
|
-
if (!headerCell || !headerCell._content) {
|
|
90
|
-
// Not a header column
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (headerCell._content.contains(this.getRootNode().activeElement)) {
|
|
95
|
-
// Something was focused inside the cell
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (this.$.scroller.hasAttribute('column-resizing')) {
|
|
100
|
-
// Resizing is in progress
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!this._touchDevice) {
|
|
105
|
-
// Not a touch device
|
|
106
|
-
this._onTrackStart(e);
|
|
107
|
-
}
|
|
108
|
-
} else if (e.detail.state === 'track') {
|
|
109
|
-
this._onTrack(e);
|
|
110
|
-
} else if (e.detail.state === 'end') {
|
|
111
|
-
this._onTrackEnd(e);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** @private */
|
|
116
|
-
_onTrackStart(e) {
|
|
117
|
-
if (!this.columnReorderingAllowed) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Cancel reordering if there are draggable nodes on the event path
|
|
122
|
-
const path = e.composedPath && e.composedPath();
|
|
123
|
-
if (path && path.filter((node) => node.hasAttribute && node.hasAttribute('draggable'))[0]) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const headerCell = this._cellFromPoint(e.detail.x, e.detail.y);
|
|
128
|
-
if (!headerCell || headerCell.getAttribute('part').indexOf('header-cell') === -1) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this._toggleAttribute('reordering', true, this);
|
|
133
|
-
this._draggedColumn = headerCell._column;
|
|
134
|
-
while (this._draggedColumn.parentElement.childElementCount === 1) {
|
|
135
|
-
// This is the only column in the group, drag the whole group instead
|
|
136
|
-
this._draggedColumn = this._draggedColumn.parentElement;
|
|
137
|
-
}
|
|
138
|
-
this._setSiblingsReorderStatus(this._draggedColumn, 'allowed');
|
|
139
|
-
this._draggedColumn._reorderStatus = 'dragging';
|
|
140
|
-
|
|
141
|
-
this._updateGhost(headerCell);
|
|
142
|
-
this._reorderGhost.style.visibility = 'visible';
|
|
143
|
-
this._updateGhostPosition(e.detail.x, this._touchDevice ? e.detail.y - 50 : e.detail.y);
|
|
144
|
-
this._autoScroller();
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/** @private */
|
|
148
|
-
_onTrack(e) {
|
|
149
|
-
if (!this._draggedColumn) {
|
|
150
|
-
// Reordering didn’t start. Skip this event.
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const targetCell = this._cellFromPoint(e.detail.x, e.detail.y);
|
|
155
|
-
if (!targetCell) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const targetColumn = this._getTargetColumn(targetCell, this._draggedColumn);
|
|
160
|
-
if (
|
|
161
|
-
this._isSwapAllowed(this._draggedColumn, targetColumn) &&
|
|
162
|
-
this._isSwappableByPosition(targetColumn, e.detail.x)
|
|
163
|
-
) {
|
|
164
|
-
this._swapColumnOrders(this._draggedColumn, targetColumn);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
this._updateGhostPosition(e.detail.x, this._touchDevice ? e.detail.y - 50 : e.detail.y);
|
|
168
|
-
this._lastDragClientX = e.detail.x;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/** @private */
|
|
172
|
-
_onTrackEnd() {
|
|
173
|
-
if (!this._draggedColumn) {
|
|
174
|
-
// Reordering didn’t start. Skip this event.
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
this._toggleAttribute('reordering', false, this);
|
|
179
|
-
this._draggedColumn._reorderStatus = '';
|
|
180
|
-
this._setSiblingsReorderStatus(this._draggedColumn, '');
|
|
181
|
-
this._draggedColumn = null;
|
|
182
|
-
this._lastDragClientX = null;
|
|
183
|
-
this._reorderGhost.style.visibility = 'hidden';
|
|
184
|
-
|
|
185
|
-
this.dispatchEvent(
|
|
186
|
-
new CustomEvent('column-reorder', {
|
|
187
|
-
detail: {
|
|
188
|
-
columns: this._getColumnsInOrder()
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* @return {!Array<!GridColumnElement>}
|
|
196
|
-
* @protected
|
|
197
|
-
*/
|
|
198
|
-
_getColumnsInOrder() {
|
|
199
|
-
return this._columnTree
|
|
200
|
-
.slice(0)
|
|
201
|
-
.pop()
|
|
202
|
-
.filter((c) => !c.hidden)
|
|
203
|
-
.sort((b, a) => b._order - a._order);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @param {number} x
|
|
208
|
-
* @param {number} y
|
|
209
|
-
* @return {HTMLElement | undefined}
|
|
210
|
-
* @protected
|
|
211
|
-
*/
|
|
212
|
-
_cellFromPoint(x, y) {
|
|
213
|
-
x = x || 0;
|
|
214
|
-
y = y || 0;
|
|
215
|
-
if (!this._draggedColumn) {
|
|
216
|
-
this._toggleAttribute('no-content-pointer-events', true, this.$.scroller);
|
|
217
|
-
}
|
|
218
|
-
const cell = this.shadowRoot.elementFromPoint(x, y);
|
|
219
|
-
this._toggleAttribute('no-content-pointer-events', false, this.$.scroller);
|
|
220
|
-
|
|
221
|
-
// Make sure the element is actually a cell
|
|
222
|
-
if (cell && cell._column) {
|
|
223
|
-
return cell;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* @param {number} eventClientX
|
|
229
|
-
* @param {number} eventClientY
|
|
230
|
-
* @protected
|
|
231
|
-
*/
|
|
232
|
-
_updateGhostPosition(eventClientX, eventClientY) {
|
|
233
|
-
const ghostRect = this._reorderGhost.getBoundingClientRect();
|
|
234
|
-
// // This is where we want to position the ghost
|
|
235
|
-
const targetLeft = eventClientX - ghostRect.width / 2;
|
|
236
|
-
const targetTop = eventClientY - ghostRect.height / 2;
|
|
237
|
-
// Current position
|
|
238
|
-
const _left = parseInt(this._reorderGhost._left || 0);
|
|
239
|
-
const _top = parseInt(this._reorderGhost._top || 0);
|
|
240
|
-
// Reposition the ghost
|
|
241
|
-
this._reorderGhost._left = _left - (ghostRect.left - targetLeft);
|
|
242
|
-
this._reorderGhost._top = _top - (ghostRect.top - targetTop);
|
|
243
|
-
this._reorderGhost.style.transform = `translate(${this._reorderGhost._left}px, ${this._reorderGhost._top}px)`;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* @param {!HTMLElement} cell
|
|
248
|
-
* @return {!HTMLElement}
|
|
249
|
-
* @protected
|
|
250
|
-
*/
|
|
251
|
-
_updateGhost(cell) {
|
|
252
|
-
const ghost = this._reorderGhost;
|
|
253
|
-
ghost.textContent = cell._content.innerText;
|
|
254
|
-
const style = window.getComputedStyle(cell);
|
|
255
|
-
[
|
|
256
|
-
'boxSizing',
|
|
257
|
-
'display',
|
|
258
|
-
'width',
|
|
259
|
-
'height',
|
|
260
|
-
'background',
|
|
261
|
-
'alignItems',
|
|
262
|
-
'padding',
|
|
263
|
-
'border',
|
|
264
|
-
'flex-direction',
|
|
265
|
-
'overflow'
|
|
266
|
-
].forEach((propertyName) => (ghost.style[propertyName] = style[propertyName]));
|
|
267
|
-
return ghost;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/** @private */
|
|
271
|
-
_updateOrders(columnTree, splices) {
|
|
272
|
-
if (columnTree === undefined || splices === undefined) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Reset all column orders
|
|
277
|
-
columnTree[0].forEach((column) => (column._order = 0));
|
|
278
|
-
// Set order numbers to top-level columns
|
|
279
|
-
updateColumnOrders(columnTree[0], this._orderBaseScope, 0);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* @param {!GridColumnElement} column
|
|
284
|
-
* @param {string} status
|
|
285
|
-
* @protected
|
|
286
|
-
*/
|
|
287
|
-
_setSiblingsReorderStatus(column, status) {
|
|
288
|
-
Array.from(column.parentNode.children)
|
|
289
|
-
.filter((child) => /column/.test(child.localName) && this._isSwapAllowed(child, column))
|
|
290
|
-
.forEach((sibling) => (sibling._reorderStatus = status));
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/** @protected */
|
|
294
|
-
_autoScroller() {
|
|
295
|
-
if (this._lastDragClientX) {
|
|
296
|
-
const rightDiff = this._lastDragClientX - this.getBoundingClientRect().right + 50;
|
|
297
|
-
const leftDiff = this.getBoundingClientRect().left - this._lastDragClientX + 50;
|
|
298
|
-
|
|
299
|
-
if (rightDiff > 0) {
|
|
300
|
-
this.$.table.scrollLeft += rightDiff / 10;
|
|
301
|
-
} else if (leftDiff > 0) {
|
|
302
|
-
this.$.table.scrollLeft -= leftDiff / 10;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if (this._draggedColumn) {
|
|
307
|
-
setTimeout(() => this._autoScroller(), 10);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* @param {GridColumnElement | undefined} column1
|
|
313
|
-
* @param {GridColumnElement | undefined} column2
|
|
314
|
-
* @return {boolean | undefined}
|
|
315
|
-
* @protected
|
|
316
|
-
*/
|
|
317
|
-
_isSwapAllowed(column1, column2) {
|
|
318
|
-
if (column1 && column2) {
|
|
319
|
-
const differentColumns = column1 !== column2;
|
|
320
|
-
const sameParent = column1.parentElement === column2.parentElement;
|
|
321
|
-
const sameFrozen = column1.frozen === column2.frozen;
|
|
322
|
-
return differentColumns && sameParent && sameFrozen;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* @param {!GridColumnElement} targetColumn
|
|
328
|
-
* @param {number} clientX
|
|
329
|
-
* @return {boolean}
|
|
330
|
-
* @protected
|
|
331
|
-
*/
|
|
332
|
-
_isSwappableByPosition(targetColumn, clientX) {
|
|
333
|
-
const targetCell = Array.from(this.$.header.querySelectorAll('tr:not([hidden]) [part~="cell"]')).filter((cell) =>
|
|
334
|
-
targetColumn.contains(cell._column)
|
|
335
|
-
)[0];
|
|
336
|
-
const sourceCellRect = this.$.header
|
|
337
|
-
.querySelector('tr:not([hidden]) [reorder-status=dragging]')
|
|
338
|
-
.getBoundingClientRect();
|
|
339
|
-
const targetRect = targetCell.getBoundingClientRect();
|
|
340
|
-
if (targetRect.left > sourceCellRect.left) {
|
|
341
|
-
return clientX > targetRect.right - sourceCellRect.width;
|
|
342
|
-
} else {
|
|
343
|
-
return clientX < targetRect.left + sourceCellRect.width;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* @param {!GridColumnElement} column1
|
|
349
|
-
* @param {!GridColumnElement} column2
|
|
350
|
-
* @protected
|
|
351
|
-
*/
|
|
352
|
-
_swapColumnOrders(column1, column2) {
|
|
353
|
-
const _order = column1._order;
|
|
354
|
-
column1._order = column2._order;
|
|
355
|
-
column2._order = _order;
|
|
356
|
-
this._updateLastFrozen();
|
|
357
|
-
this._updateFirstAndLastColumn();
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* @param {HTMLElement | undefined} targetCell
|
|
362
|
-
* @param {GridColumnElement} draggedColumn
|
|
363
|
-
* @return {GridColumnElement | undefined}
|
|
364
|
-
* @protected
|
|
365
|
-
*/
|
|
366
|
-
_getTargetColumn(targetCell, draggedColumn) {
|
|
367
|
-
if (targetCell && draggedColumn) {
|
|
368
|
-
let candidate = targetCell._column;
|
|
369
|
-
while (candidate.parentElement !== draggedColumn.parentElement && candidate !== this) {
|
|
370
|
-
candidate = candidate.parentElement;
|
|
371
|
-
}
|
|
372
|
-
if (candidate.parentElement === draggedColumn.parentElement) {
|
|
373
|
-
return candidate;
|
|
374
|
-
} else {
|
|
375
|
-
return targetCell._column;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Fired when the columns in the grid are reordered.
|
|
382
|
-
*
|
|
383
|
-
* @event column-reorder
|
|
384
|
-
* @param {Object} detail
|
|
385
|
-
* @param {Object} detail.columns the columns in the new order
|
|
386
|
-
*/
|
|
387
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare function ColumnResizingMixin<T extends new (...args: any[]) => {}>(base: T): T & ColumnResizingMixinConstructor;
|
|
2
|
-
|
|
3
|
-
interface ColumnResizingMixinConstructor {
|
|
4
|
-
new (...args: any[]): ColumnResizingMixin;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export { ColumnResizingMixinConstructor };
|
|
8
|
-
|
|
9
|
-
interface ColumnResizingMixin {}
|
|
10
|
-
|
|
11
|
-
export { ColumnResizingMixin };
|
|
@@ -1,111 +0,0 @@
|
|
|
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 { GestureEventListeners } from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
|
|
7
|
-
import { addListener } from '@polymer/polymer/lib/utils/gestures.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @polymerMixin
|
|
11
|
-
*/
|
|
12
|
-
export const ColumnResizingMixin = (superClass) =>
|
|
13
|
-
class ColumnResizingMixin extends GestureEventListeners(superClass) {
|
|
14
|
-
ready() {
|
|
15
|
-
super.ready();
|
|
16
|
-
const scroller = this.$.scroller;
|
|
17
|
-
addListener(scroller, 'track', this._onHeaderTrack.bind(this));
|
|
18
|
-
|
|
19
|
-
// Disallow scrolling while resizing
|
|
20
|
-
scroller.addEventListener('touchmove', (e) => scroller.hasAttribute('column-resizing') && e.preventDefault());
|
|
21
|
-
|
|
22
|
-
// Disable contextmenu on any resize separator.
|
|
23
|
-
scroller.addEventListener(
|
|
24
|
-
'contextmenu',
|
|
25
|
-
(e) => e.target.getAttribute('part') == 'resize-handle' && e.preventDefault()
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
// Disable native cell focus when resizing
|
|
29
|
-
scroller.addEventListener(
|
|
30
|
-
'mousedown',
|
|
31
|
-
(e) => e.target.getAttribute('part') === 'resize-handle' && e.preventDefault()
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** @private */
|
|
36
|
-
_onHeaderTrack(e) {
|
|
37
|
-
const handle = e.target;
|
|
38
|
-
if (handle.getAttribute('part') === 'resize-handle') {
|
|
39
|
-
const cell = handle.parentElement;
|
|
40
|
-
let column = cell._column;
|
|
41
|
-
|
|
42
|
-
this._toggleAttribute('column-resizing', true, this.$.scroller);
|
|
43
|
-
|
|
44
|
-
// Get the target column to resize
|
|
45
|
-
while (column.localName === 'vaadin-grid-column-group') {
|
|
46
|
-
column = Array.prototype.slice
|
|
47
|
-
.call(column._childColumns, 0)
|
|
48
|
-
.sort(function (a, b) {
|
|
49
|
-
return a._order - b._order;
|
|
50
|
-
})
|
|
51
|
-
.filter(function (column) {
|
|
52
|
-
return !column.hidden;
|
|
53
|
-
})
|
|
54
|
-
.pop();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const columnRowCells = Array.from(this.$.header.querySelectorAll('[part~="row"]:last-child [part~="cell"]'));
|
|
58
|
-
const targetCell = columnRowCells.filter((cell) => cell._column === column)[0];
|
|
59
|
-
// Resize the target column
|
|
60
|
-
if (targetCell.offsetWidth) {
|
|
61
|
-
const style = window.getComputedStyle(targetCell);
|
|
62
|
-
const minWidth =
|
|
63
|
-
10 +
|
|
64
|
-
parseInt(style.paddingLeft) +
|
|
65
|
-
parseInt(style.paddingRight) +
|
|
66
|
-
parseInt(style.borderLeftWidth) +
|
|
67
|
-
parseInt(style.borderRightWidth) +
|
|
68
|
-
parseInt(style.marginLeft) +
|
|
69
|
-
parseInt(style.marginRight);
|
|
70
|
-
const maxWidth =
|
|
71
|
-
targetCell.offsetWidth +
|
|
72
|
-
(this.__isRTL
|
|
73
|
-
? targetCell.getBoundingClientRect().left - e.detail.x
|
|
74
|
-
: e.detail.x - targetCell.getBoundingClientRect().right);
|
|
75
|
-
column.width = Math.max(minWidth, maxWidth) + 'px';
|
|
76
|
-
column.flexGrow = 0;
|
|
77
|
-
}
|
|
78
|
-
// Fix width and flex-grow for all preceding columns
|
|
79
|
-
columnRowCells
|
|
80
|
-
.sort(function (a, b) {
|
|
81
|
-
return a._column._order - b._column._order;
|
|
82
|
-
})
|
|
83
|
-
.forEach(function (cell, index, array) {
|
|
84
|
-
if (index < array.indexOf(targetCell)) {
|
|
85
|
-
cell._column.width = cell.offsetWidth + 'px';
|
|
86
|
-
cell._column.flexGrow = 0;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
if (e.detail.state === 'end') {
|
|
91
|
-
this._toggleAttribute('column-resizing', false, this.$.scroller);
|
|
92
|
-
this.dispatchEvent(
|
|
93
|
-
new CustomEvent('column-resize', {
|
|
94
|
-
detail: { resizedColumn: column }
|
|
95
|
-
})
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Notify resize
|
|
100
|
-
this._resizeHandler();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Fired when a column in the grid is resized by the user.
|
|
106
|
-
*
|
|
107
|
-
* @event column-resize
|
|
108
|
-
* @param {Object} detail
|
|
109
|
-
* @param {Object} detail.resizedColumn the column that was resized
|
|
110
|
-
*/
|
|
111
|
-
};
|