refactor(web): extract touch event forwarding

This commit is contained in:
2026-04-01 11:39:39 +02:00
parent 37c6e03d23
commit 463caedcfd
5 changed files with 210 additions and 50 deletions
+33 -33
View File
@@ -26,6 +26,11 @@ import { resolveAllocationDragPosition, resolveProjectDragPosition } from "./tim
import { attachDocumentMouseDrag } from "./timelineDocumentDrag.js";
import { buildProjectShiftMutationInput, createProjectDragState } from "./timelineProjectDrag.js";
import { beginProjectDragSession } from "./timelineProjectDragSession.js";
import {
forwardCanvasTouchEnd,
forwardCanvasTouchMove,
forwardTouchStartAsMouseDown,
} from "./timelineTouchEvents.js";
import {
completeMultiSelectDraft,
createMultiSelectState,
@@ -34,16 +39,7 @@ import {
import { beginCanvasMultiSelectSession } from "./timelineMultiSelectSession.js";
import { reconcileOptimisticEntries } from "./timelineOptimisticAllocations.js";
import { createRangeSelectionState, finalizeRangeSelection, updateRangeSelectionDraft } from "./timelineRangeSelection.js";
import {
createTouchCanvasPointerEvent,
createTouchMouseDownEvent,
type TouchCanvasPointerEvent,
type TouchMouseDownEvent,
} from "./timelineTouchAdapters.js";
import {
getTouchPoint,
resolveTouchDragDecision,
} from "./timelineTouch.js";
import { type TouchCanvasPointerEvent, type TouchMouseDownEvent } from "./timelineTouchAdapters.js";
const DRAG_CLICK_THRESHOLD_PX = 5;
@@ -796,10 +792,13 @@ export function useTimelineDrag({
endDate: Date;
},
) => {
e.preventDefault();
const point = getTouchPoint(e);
touchStartRef.current = { x: point.clientX, y: point.clientY, decided: true };
onProjectBarMouseDown(createTouchMouseDownEvent(point, e.currentTarget), opts);
forwardTouchStartAsMouseDown({
event: e,
touchStartRef,
decided: true,
onMouseDown: onProjectBarMouseDown,
opts,
});
},
[onProjectBarMouseDown],
);
@@ -821,10 +820,13 @@ export function useTimelineDrag({
scope?: AllocDragScope;
},
) => {
e.preventDefault();
const point = getTouchPoint(e);
touchStartRef.current = { x: point.clientX, y: point.clientY, decided: true };
onAllocMouseDown(createTouchMouseDownEvent(point, e.currentTarget), opts);
forwardTouchStartAsMouseDown({
event: e,
touchStartRef,
decided: true,
onMouseDown: onAllocMouseDown,
opts,
});
},
[onAllocMouseDown],
);
@@ -838,33 +840,31 @@ export function useTimelineDrag({
suggestedProjectId?: string;
},
) => {
e.preventDefault();
const point = getTouchPoint(e);
touchStartRef.current = { x: point.clientX, y: point.clientY, decided: false };
onRowMouseDown(createTouchMouseDownEvent(point, e.currentTarget), opts);
forwardTouchStartAsMouseDown({
event: e,
touchStartRef,
decided: false,
onMouseDown: onRowMouseDown,
opts,
});
},
[onRowMouseDown],
);
const onCanvasTouchMove = useCallback(
(e: React.TouchEvent) => {
const point = getTouchPoint(e);
// Scroll vs drag disambiguation: once decided, stick with the decision
const decision = resolveTouchDragDecision(touchStartRef.current, point);
touchStartRef.current = decision.nextState;
if (!decision.shouldHandleDrag) {
return;
}
onCanvasMouseMove(createTouchCanvasPointerEvent(point));
forwardCanvasTouchMove({
event: e,
touchStartRef,
onCanvasMouseMove,
});
},
[onCanvasMouseMove],
);
const onCanvasTouchEnd = useCallback(
async (e: React.TouchEvent) => {
await onCanvasMouseUp(createTouchCanvasPointerEvent(getTouchPoint(e)));
await forwardCanvasTouchEnd({ event: e, onCanvasMouseUp });
},
[onCanvasMouseUp],
);