@itrocks/table 0.2.8 → 0.2.10
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/column-reorder.js +22 -9
- package/package.json +1 -1
package/column-reorder.js
CHANGED
|
@@ -19,8 +19,6 @@ export class TableColumnReorder extends Plugin {
|
|
|
19
19
|
const scrollDirection = this.scroll(drag, time);
|
|
20
20
|
if (scrollDirection)
|
|
21
21
|
this.requestFrame();
|
|
22
|
-
if (drag.remove)
|
|
23
|
-
return;
|
|
24
22
|
const direction = pointerDirection || scrollDirection;
|
|
25
23
|
const target = direction ? this.target(drag, direction) : drag.index;
|
|
26
24
|
if (target !== drag.index)
|
|
@@ -65,8 +63,17 @@ export class TableColumnReorder extends Plugin {
|
|
|
65
63
|
}
|
|
66
64
|
init() {
|
|
67
65
|
const table = this.of;
|
|
66
|
+
const section = table.element.tHead?.rows.length ? 'thead' : 'tbody:first-of-type';
|
|
67
|
+
// Reserve both axes before pointerdown, including vertical drags used to remove a column.
|
|
68
|
+
table.styleSheet.push(`
|
|
69
|
+
${table.selector} > ${section} > tr:first-child > :is(th, td) {
|
|
70
|
+
touch-action: none;
|
|
71
|
+
-webkit-user-select: none;
|
|
72
|
+
user-select: none;
|
|
73
|
+
}
|
|
74
|
+
`);
|
|
68
75
|
table.addEventListener(table.element, 'click', event => {
|
|
69
|
-
if (!this.suppressClick)
|
|
76
|
+
if (!this.suppressClick || (event.detail === 0))
|
|
70
77
|
return;
|
|
71
78
|
this.suppressClick = false;
|
|
72
79
|
event.preventDefault();
|
|
@@ -78,6 +85,10 @@ export class TableColumnReorder extends Plugin {
|
|
|
78
85
|
event.preventDefault();
|
|
79
86
|
this.finish(false);
|
|
80
87
|
}, { capture: true });
|
|
88
|
+
table.addEventListener(table.element, 'lostpointercapture', event => {
|
|
89
|
+
if (event.target === table.element)
|
|
90
|
+
this.onPointer(event);
|
|
91
|
+
});
|
|
81
92
|
table.addEventListener(document, 'pointercancel', event => this.onPointer(event), { capture: true });
|
|
82
93
|
table.addEventListener(table.element, 'pointerdown', event => this.onPointer(event));
|
|
83
94
|
table.addEventListener(document, 'pointermove', event => this.onPointer(event), { capture: true });
|
|
@@ -89,8 +100,9 @@ export class TableColumnReorder extends Plugin {
|
|
|
89
100
|
}
|
|
90
101
|
move(drag, targetIndex) {
|
|
91
102
|
const after = drag.index < targetIndex;
|
|
92
|
-
for (const
|
|
93
|
-
const
|
|
103
|
+
for (const row of this.rows()) {
|
|
104
|
+
const cell = row.cells[drag.index];
|
|
105
|
+
const target = row.cells[targetIndex];
|
|
94
106
|
after ? target.after(cell) : target.before(cell);
|
|
95
107
|
}
|
|
96
108
|
if (drag.col) {
|
|
@@ -102,8 +114,9 @@ export class TableColumnReorder extends Plugin {
|
|
|
102
114
|
}
|
|
103
115
|
onPointer(event) {
|
|
104
116
|
if (event.type === 'pointerdown') {
|
|
105
|
-
if (activeDrag || this.press || (event.button !== 0))
|
|
117
|
+
if (activeDrag || this.press || !event.isPrimary || (event.button !== 0))
|
|
106
118
|
return;
|
|
119
|
+
this.suppressClick = false;
|
|
107
120
|
const header = event.target.closest('th, td');
|
|
108
121
|
if (!header || (header.parentElement !== this.triggerRow()))
|
|
109
122
|
return;
|
|
@@ -113,7 +126,7 @@ export class TableColumnReorder extends Plugin {
|
|
|
113
126
|
const state = this.drag ?? this.press;
|
|
114
127
|
if (!state || (event.pointerId !== state.id))
|
|
115
128
|
return;
|
|
116
|
-
if (event.type === 'pointercancel') {
|
|
129
|
+
if ((event.type === 'pointercancel') || (event.type === 'lostpointercapture')) {
|
|
117
130
|
this.finish(false);
|
|
118
131
|
return;
|
|
119
132
|
}
|
|
@@ -129,8 +142,6 @@ export class TableColumnReorder extends Plugin {
|
|
|
129
142
|
this.frame = undefined;
|
|
130
143
|
this.animate(performance.now());
|
|
131
144
|
}
|
|
132
|
-
this.suppressClick = true;
|
|
133
|
-
setTimeout(() => this.suppressClick = false);
|
|
134
145
|
this.finish(true);
|
|
135
146
|
return;
|
|
136
147
|
}
|
|
@@ -218,6 +229,8 @@ export class TableColumnReorder extends Plugin {
|
|
|
218
229
|
};
|
|
219
230
|
this.drag = drag;
|
|
220
231
|
activeDrag = this;
|
|
232
|
+
// Keep suppression until the compatibility click arrives, even if touch delays it.
|
|
233
|
+
this.suppressClick = true;
|
|
221
234
|
document.documentElement.classList.add('column-reorder');
|
|
222
235
|
for (const cell of drag.cells)
|
|
223
236
|
cell.classList.add('column-reorder');
|
package/package.json
CHANGED