fix: compensate drag offset so drop position matches visual target
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 19s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 19s
This commit is contained in:
parent
67dd7bde3c
commit
883baddd16
1 changed files with 5 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ const START_HOUR = 8;
|
||||||
const END_HOUR = 20;
|
const END_HOUR = 20;
|
||||||
const PIXELS_PER_MINUTE = 0.8;
|
const PIXELS_PER_MINUTE = 0.8;
|
||||||
|
|
||||||
|
let dragOffsetY = 0;
|
||||||
let currentRangeStart = null;
|
let currentRangeStart = null;
|
||||||
let scheduleItems = [];
|
let scheduleItems = [];
|
||||||
let itemIndex = new Map();
|
let itemIndex = new Map();
|
||||||
|
|
@ -275,6 +276,8 @@ function toggleActiveItem(element) {
|
||||||
function handleDragStart(event) {
|
function handleDragStart(event) {
|
||||||
const block = event.currentTarget;
|
const block = event.currentTarget;
|
||||||
block.classList.add('dragging');
|
block.classList.add('dragging');
|
||||||
|
const blockRect = block.getBoundingClientRect();
|
||||||
|
dragOffsetY = event.clientY - blockRect.top;
|
||||||
event.dataTransfer.setData('text/plain', JSON.stringify({
|
event.dataTransfer.setData('text/plain', JSON.stringify({
|
||||||
id: Number(block.dataset.id),
|
id: Number(block.dataset.id),
|
||||||
occurrenceDate: block.dataset.date
|
occurrenceDate: block.dataset.date
|
||||||
|
|
@ -295,7 +298,8 @@ async function handleEventDrop(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const rect = event.currentTarget.getBoundingClientRect();
|
const rect = event.currentTarget.getBoundingClientRect();
|
||||||
const relativeY = Math.max(0, Math.min(rect.height, event.clientY - rect.top));
|
const adjustedY = event.clientY - rect.top - dragOffsetY;
|
||||||
|
const relativeY = Math.max(0, Math.min(rect.height, adjustedY));
|
||||||
const minutesFromStart = Math.round((relativeY / PIXELS_PER_MINUTE) / SLOT_MINUTES) * SLOT_MINUTES;
|
const minutesFromStart = Math.round((relativeY / PIXELS_PER_MINUTE) / SLOT_MINUTES) * SLOT_MINUTES;
|
||||||
const clampedMinutes = Math.min((END_HOUR - START_HOUR) * 60 - item.duration_min, Math.max(0, minutesFromStart));
|
const clampedMinutes = Math.min((END_HOUR - START_HOUR) * 60 - item.duration_min, Math.max(0, minutesFromStart));
|
||||||
const newTime = minutesToTime(START_HOUR * 60 + clampedMinutes);
|
const newTime = minutesToTime(START_HOUR * 60 + clampedMinutes);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue