预览拖动阈值抽成公共常量模块

- 新增 previewDragThreshold.ts,导出 DRAG_THRESHOLD_SCREEN_PX 与屏幕坐标阈值判定 passedDragThresholdScreen
- useNodeTransformInteraction 删除本地阈值常量,改为复用该模块,左键拖动/缩放行为不变

验证:npx vitest run useNodeTransformInteraction.test.tsx previewWorkspaceZoom.test.tsx(18 passed)
This commit is contained in:
2026-09-22 15:26:11 +08:00
parent 65e06c4808
commit 96e7ba7808
2 changed files with 25 additions and 7 deletions
@@ -0,0 +1,21 @@
/** 屏幕像素坐标点。 */
export type ScreenPoint = {
x: number;
y: number;
};
/**
* 指针拖动阈值(屏幕像素)。左键拖动/缩放与右键拖拽平移共用同一判据,
* 保证同一张画布上"多小的移动算点击"只有一个答案。
*/
export const DRAG_THRESHOLD_SCREEN_PX = 2;
export function passedDragThresholdScreen(
start: ScreenPoint,
current: ScreenPoint,
): boolean {
return (
Math.hypot(current.x - start.x, current.y - start.y) >=
DRAG_THRESHOLD_SCREEN_PX
);
}
@@ -21,6 +21,7 @@ import {
import type { Node as UiNode } from '../../../../features/ui-editor/types/Node';
import type { UITree } from '../../../../features/ui-editor/types/UITree';
import type { UiEditorCanvasProjection } from '../../useUiEditorPage';
import { passedDragThresholdScreen } from './previewDragThreshold';
type ViewportScale = { scale: number };
type GestureBase = {
@@ -47,17 +48,13 @@ type ActiveGesture =
ratioAxis: ResizeAxis | null;
});
const DRAG_THRESHOLD_SCREEN_PX = 2;
function passedDragThreshold(
gesture: GestureBase,
event: ReactPointerEvent<HTMLDivElement>,
) {
return (
Math.hypot(
event.clientX - gesture.startClientX,
event.clientY - gesture.startClientY,
) >= DRAG_THRESHOLD_SCREEN_PX
return passedDragThresholdScreen(
{ x: gesture.startClientX, y: gesture.startClientY },
{ x: event.clientX, y: event.clientY },
);
}