@itrocks/table 0.2.9 → 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 +19 -5
- package/package.json +1 -1
package/column-reorder.js
CHANGED
|
@@ -63,8 +63,17 @@ export class TableColumnReorder extends Plugin {
|
|
|
63
63
|
}
|
|
64
64
|
init() {
|
|
65
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
|
+
`);
|
|
66
75
|
table.addEventListener(table.element, 'click', event => {
|
|
67
|
-
if (!this.suppressClick)
|
|
76
|
+
if (!this.suppressClick || (event.detail === 0))
|
|
68
77
|
return;
|
|
69
78
|
this.suppressClick = false;
|
|
70
79
|
event.preventDefault();
|
|
@@ -76,6 +85,10 @@ export class TableColumnReorder extends Plugin {
|
|
|
76
85
|
event.preventDefault();
|
|
77
86
|
this.finish(false);
|
|
78
87
|
}, { capture: true });
|
|
88
|
+
table.addEventListener(table.element, 'lostpointercapture', event => {
|
|
89
|
+
if (event.target === table.element)
|
|
90
|
+
this.onPointer(event);
|
|
91
|
+
});
|
|
79
92
|
table.addEventListener(document, 'pointercancel', event => this.onPointer(event), { capture: true });
|
|
80
93
|
table.addEventListener(table.element, 'pointerdown', event => this.onPointer(event));
|
|
81
94
|
table.addEventListener(document, 'pointermove', event => this.onPointer(event), { capture: true });
|
|
@@ -101,8 +114,9 @@ export class TableColumnReorder extends Plugin {
|
|
|
101
114
|
}
|
|
102
115
|
onPointer(event) {
|
|
103
116
|
if (event.type === 'pointerdown') {
|
|
104
|
-
if (activeDrag || this.press || (event.button !== 0))
|
|
117
|
+
if (activeDrag || this.press || !event.isPrimary || (event.button !== 0))
|
|
105
118
|
return;
|
|
119
|
+
this.suppressClick = false;
|
|
106
120
|
const header = event.target.closest('th, td');
|
|
107
121
|
if (!header || (header.parentElement !== this.triggerRow()))
|
|
108
122
|
return;
|
|
@@ -112,7 +126,7 @@ export class TableColumnReorder extends Plugin {
|
|
|
112
126
|
const state = this.drag ?? this.press;
|
|
113
127
|
if (!state || (event.pointerId !== state.id))
|
|
114
128
|
return;
|
|
115
|
-
if (event.type === 'pointercancel') {
|
|
129
|
+
if ((event.type === 'pointercancel') || (event.type === 'lostpointercapture')) {
|
|
116
130
|
this.finish(false);
|
|
117
131
|
return;
|
|
118
132
|
}
|
|
@@ -128,8 +142,6 @@ export class TableColumnReorder extends Plugin {
|
|
|
128
142
|
this.frame = undefined;
|
|
129
143
|
this.animate(performance.now());
|
|
130
144
|
}
|
|
131
|
-
this.suppressClick = true;
|
|
132
|
-
setTimeout(() => this.suppressClick = false);
|
|
133
145
|
this.finish(true);
|
|
134
146
|
return;
|
|
135
147
|
}
|
|
@@ -217,6 +229,8 @@ export class TableColumnReorder extends Plugin {
|
|
|
217
229
|
};
|
|
218
230
|
this.drag = drag;
|
|
219
231
|
activeDrag = this;
|
|
232
|
+
// Keep suppression until the compatibility click arrives, even if touch delays it.
|
|
233
|
+
this.suppressClick = true;
|
|
220
234
|
document.documentElement.classList.add('column-reorder');
|
|
221
235
|
for (const cell of drag.cells)
|
|
222
236
|
cell.classList.add('column-reorder');
|
package/package.json
CHANGED