Use nearest-edge distance for symmetrical drag reorder of tall sections

Center-point distance made it harder to drag sections down than up
because tall sections (charts, sankey) have their center far from
the edge. Now uses distance to nearest edge — section height no
longer affects how far you need to drag to trigger a swap.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
juan
2026-03-22 23:51:59 -07:00
parent f37378b2ff
commit 53c5f5759d

View File

@@ -295,10 +295,19 @@ export default class extends Controller {
draggableElements.forEach((child) => {
const rect = child.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
// Use distance to nearest edge instead of center so tall sections
// don't require more finger travel than short ones
const dx = pointerX - centerX;
const dy = pointerY - centerY;
let dy;
if (pointerY < rect.top) {
dy = rect.top - pointerY;
} else if (pointerY > rect.bottom) {
dy = pointerY - rect.bottom;
} else {
dy = 0; // pointer is within this section's vertical bounds
}
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < minDistance) {