mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
## Summary Extract duplicated click-vs-drag detection logic into a shared `useClickDragGuard` composable and `exceedsClickThreshold` pure utility function. ## Changes - **What**: New `useClickDragGuard(threshold)` composable in `src/composables/useClickDragGuard.ts` that stores pointer start position and checks squared distance against a threshold. Also exports `exceedsClickThreshold` for non-Vue contexts. - Migrated `DropZone.vue`, `useNodePointerInteractions.ts`, and `Load3d.ts` to use the shared utility - `CanvasPointer.ts` left as-is (LiteGraph internal) - All consumers now use squared-distance comparison (no `Math.sqrt` or per-axis `Math.abs`) ## Review Focus - The composable uses plain `let` state instead of `ref` since reactivity is not needed for the start position - `Load3d.ts` uses the pure `exceedsClickThreshold` function directly since it is a class, not a Vue component - Threshold values preserved per-consumer: DropZone=5, useNodePointerInteractions=3, Load3d=5 Fixes #10356 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10357-refactor-extract-shared-click-vs-drag-guard-utility-32a6d73d3650816e83f5cb89872fb184) by [Unito](https://www.unito.io) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Alexander Brown <drjkl@comfy.org>
42 lines
931 B
TypeScript
42 lines
931 B
TypeScript
interface PointerPosition {
|
|
readonly x: number
|
|
readonly y: number
|
|
}
|
|
|
|
function squaredDistance(a: PointerPosition, b: PointerPosition): number {
|
|
const dx = a.x - b.x
|
|
const dy = a.y - b.y
|
|
return dx * dx + dy * dy
|
|
}
|
|
|
|
export function exceedsClickThreshold(
|
|
start: PointerPosition,
|
|
end: PointerPosition,
|
|
threshold: number
|
|
): boolean {
|
|
return squaredDistance(start, end) > threshold * threshold
|
|
}
|
|
|
|
export function useClickDragGuard(threshold: number = 5) {
|
|
let start: PointerPosition | null = null
|
|
|
|
function recordStart(e: { clientX: number; clientY: number }) {
|
|
start = { x: e.clientX, y: e.clientY }
|
|
}
|
|
|
|
function wasDragged(e: { clientX: number; clientY: number }): boolean {
|
|
if (!start) return false
|
|
return exceedsClickThreshold(
|
|
start,
|
|
{ x: e.clientX, y: e.clientY },
|
|
threshold
|
|
)
|
|
}
|
|
|
|
function reset() {
|
|
start = null
|
|
}
|
|
|
|
return { recordStart, wasDragged, reset }
|
|
}
|