Mouse/touch event handling improvement

- prefer passive handlers
- fix event moving on touch
- faster selection updates
This commit is contained in:
Leo Vasanko
2025-08-27 08:04:29 -06:00
parent ecae48fd85
commit 5a0d6804bc
6 changed files with 19 additions and 23 deletions

View File

@@ -248,7 +248,7 @@ function onGlobalTouchMove(e) {
if (!isDragging.value) return
const t = e.touches && e.touches[0]
if (!t) return
e.preventDefault()
if (e.cancelable) e.preventDefault()
const dateStr = getDateUnderPoint(t.clientX, t.clientY)
if (dateStr) updateDrag(dateStr)
}
@@ -435,10 +435,11 @@ function buildSearchResults() {
watch(searchQuery, buildSearchResults)
watch(
() => calendarStore.eventsMutation,
() => calendarStore.events,
() => {
if (searchOpen.value && searchQuery.value.trim()) buildSearchResults()
},
{ deep: true },
)
function openSearch(prefill = '') {
@@ -569,19 +570,22 @@ watch(
},
)
// Event changes
// Event changes (optimized): react to mutation counter & targeted range payload
watch(
() => calendarStore.events,
() => {
refreshEvents('events')
},
() => refreshEvents('events'),
{ deep: true },
)
// Reflect selection & events by rebuilding day objects in-place
watch(
() => [selection.value.startDate, selection.value.dayCount],
() => refreshEvents('selection'),
([start, count]) => {
const hasSel = !!start && !!count && count > 0
const end = hasSel ? addDaysStr(start, count, DEFAULT_TZ) : null
for (const w of visibleWeeks.value)
for (const d of w.days) d.isSelected = hasSel && d.date >= start && d.date < end
},
)
// Rebuild if viewport height changes (e.g., resize)

View File

@@ -57,7 +57,7 @@ function shouldRotateMonth(label) {
@mousedown="handleDayMouseDown(day.date)"
@mouseenter="handleDayMouseEnter(day.date)"
@mouseup="handleDayMouseUp(day.date)"
@touchstart="handleDayTouchStart(day.date)"
@touchstart.passive="handleDayTouchStart(day.date)"
/>
<EventOverlay :week="props.week" @event-click="handleEventClick" />
</div>

View File

@@ -278,9 +278,7 @@ function startLocalDrag(init, evt) {
}
}
if (!(evt.pointerType === 'touch')) {
evt.preventDefault()
}
if (evt.cancelable) evt.preventDefault()
window.addEventListener('pointermove', onDragPointerMove, { passive: false })
window.addEventListener('pointerup', onDragPointerUp, { passive: false })
@@ -486,6 +484,8 @@ function applyRangeDuringDrag(st, startDate, endDate) {
user-select: none;
z-index: 1;
text-align: center;
/* Ensure touch pointer events aren't turned into a scroll gesture; needed for reliable drag on mobile */
touch-action: none;
}
/* Inner title wrapper ensures proper ellipsis within flex/grid constraints */
@@ -510,6 +510,7 @@ function applyRangeDuringDrag(st, startDate, endDate) {
background: transparent;
z-index: 2;
cursor: ew-resize;
touch-action: none; /* Allow touch resizing without scroll */
}
.event-span .resize-handle.left {