Skip to content

Commit a06dc20

Browse files
sc1ftexodus
authored andcommitted
#257: flickering stop-gap fix, move drag-drop from row.js to utils.js
1 parent ba6e1f3 commit a06dc20

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

packages/perspective-viewer/src/js/computed_column.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ class ComputedColumn extends HTMLElement {
142142
for (let i = 0; i < computation.num_params; i++) {
143143
this._input_columns.innerHTML += `<div class="psp-cc-computation__input-column"
144144
data-index="${i}"
145-
drop-target
146-
ondragenter="dragEnter(event)">
145+
drop-target>
147146
<span class="psp-label__requiredType ${input_type}"></span>
148147
<span class="psp-label__placeholder">Param ${i + 1}</span>
149148
<div class="psp-cc-computation__drop-target-hover"></div>
@@ -181,13 +180,11 @@ class ComputedColumn extends HTMLElement {
181180
}
182181

183182
_hover_column(event) {
184-
console.log("hover");
185183
event.preventDefault();
186184
event.dataTransfer.dropEffect = "move";
187185

188186
const drop_target = event.currentTarget;
189187
const drop_target_hover = drop_target.querySelector(".psp-cc-computation__drop-target-hover");
190-
191188
if (drop_target.className !== "dropping") {
192189
//event.currentTarget.classList.remove('dropped');
193190
drop_target.classList.add("dropping");
@@ -238,16 +235,19 @@ class ComputedColumn extends HTMLElement {
238235

239236
// Called when a column is dragged out of the computed column UI
240237
_remove_column(event) {
241-
console.log("remove");
242238
event.currentTarget.classList.remove("dropping");
243239
}
244240

245241
// Called when the column passes over and then leaves the drop target
246242
_pass_column(event) {
247-
if (event.pageX === 0 || event.pageY === 0) {
243+
const src = event.currentTarget;
244+
// are we inside the column? if we are, prevent further calls which cause flickering
245+
const bounds = src.getBoundingClientRect();
246+
const inside_x = event.pageX >= bounds.left && event.pageX <= bounds.right - 2;
247+
const inside_y = event.pageY >= bounds.top && event.pageY <= bounds.bottom - 2;
248+
if (inside_x && inside_y) {
248249
return;
249250
}
250-
const src = event.currentTarget;
251251
if (src !== null && src.nodeName !== "SPAN") {
252252
src.classList.remove("dropping");
253253
const drop_target_hover = src.querySelector(".psp-cc-computation__drop-target-hover");

packages/perspective-viewer/src/js/row.js

-27
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,6 @@ import template from "../html/row.html";
1919

2020
import style from "../less/row.less";
2121

22-
/******************************************************************************
23-
*
24-
* Drag & Drop Utils
25-
*
26-
*/
27-
28-
global.dragEnter = function dragEnter(ev) {
29-
ev.stopPropagation();
30-
ev.preventDefault();
31-
ev.currentTarget.classList.add("dropping");
32-
};
33-
34-
global.allowDrop = function allowDrop(ev) {
35-
ev.stopPropagation();
36-
ev.preventDefault();
37-
ev.currentTarget.classList.add("dropping");
38-
ev.dataTransfer.dropEffect = "move";
39-
};
40-
41-
global.disallowDrop = function disallowDrop(ev) {
42-
if (ev.currentTarget == ev.target) {
43-
ev.stopPropagation();
44-
ev.preventDefault();
45-
ev.currentTarget.classList.remove("dropping");
46-
}
47-
};
48-
4922
function get_text_width(text, max = 0) {
5023
let span = document.createElement("span");
5124
// FIXME get these values form the stylesheet

packages/perspective-viewer/src/js/utils.js

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@
77
*
88
*/
99

10+
/******************************************************************************
11+
*
12+
* Drag & Drop Utils
13+
*
14+
*/
15+
16+
global.dragEnter = function dragEnter(ev) {
17+
ev.stopPropagation();
18+
ev.preventDefault();
19+
ev.currentTarget.classList.add("dropping");
20+
};
21+
22+
global.allowDrop = function allowDrop(ev) {
23+
ev.stopPropagation();
24+
ev.preventDefault();
25+
ev.currentTarget.classList.add("dropping");
26+
ev.dataTransfer.dropEffect = "move";
27+
};
28+
29+
global.disallowDrop = function disallowDrop(ev) {
30+
if (ev.currentTarget == ev.target) {
31+
ev.stopPropagation();
32+
ev.preventDefault();
33+
ev.currentTarget.classList.remove("dropping");
34+
}
35+
};
36+
1037
/**
1138
* Instantiate a Template DOM object from an HTML text string.
1239
*

packages/perspective-viewer/src/less/computed_column.less

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203

204204
perspective-row {
205205
display: none !important;
206+
pointer-events: none;
206207
}
207208
}
208209

0 commit comments

Comments
 (0)