Path: blob/master/src/packages/frontend/components/dnd/config.ts
10799 views
// Shared DnD configuration constants for @dnd-kit.1// Used by both file explorer DnD and frame editor DnD to ensure2// identical activation behavior and visual appearance.34import type { Modifier } from "@dnd-kit/core";56// --- Sensor activation constraints ---78/** Mouse: 300ms hold OR 3px drag distance to activate. */9export const MOUSE_SENSOR_OPTIONS = {10activationConstraint: { distance: 3, delay: 300, tolerance: 5 },11} as const;1213/** Touch: 300ms hold to activate. */14export const TOUCH_SENSOR_OPTIONS = {15activationConstraint: { delay: 300, tolerance: 5 },16} as const;1718// --- Overlay positioning ---1920/** Extract clientX/clientY from mouse, pointer, or touch events. */21export function getEventCoords(event: Event): { x: number; y: number } | null {22if ("clientX" in event && typeof (event as any).clientX === "number") {23return {24x: (event as MouseEvent).clientX,25y: (event as MouseEvent).clientY,26};27}28const te = event as TouchEvent;29const touch = te.touches?.[0] ?? te.changedTouches?.[0];30if (touch) {31return { x: touch.clientX, y: touch.clientY };32}33return null;34}3536/**37* Position DragOverlay at pointer (12px bottom-right offset)38* instead of at the original element's origin.39*/40export const snapToPointerModifier: Modifier = ({41activatorEvent,42activeNodeRect,43transform,44}) => {45if (!activatorEvent || !activeNodeRect) return transform;46const coords = getEventCoords(activatorEvent);47if (!coords) return transform;48return {49...transform,50x: transform.x + (coords.x - activeNodeRect.left) + 12,51y: transform.y + (coords.y - activeNodeRect.top) + 12,52};53};5455export const DRAG_OVERLAY_MODIFIERS: Modifier[] = [snapToPointerModifier];5657// --- Overlay styling ---5859export const DRAG_OVERLAY_STYLE = {60padding: "4px 10px",61borderRadius: 4,62fontSize: "12px",63whiteSpace: "nowrap" as const,64width: "max-content" as const,65pointerEvents: "none" as const,66} as const;676869