返回 DeepSeek-Reasonix
workspaceDrag.ts
根目录 / desktop / frontend / src / lib / workspaceDrag.ts
1 export const WORKSPACE_REF_DRAG_TYPE = "application/x-reasonix-workspace-ref";
2
3 export interface WorkspaceRefDragPayload {
4 path: string;
5 isDir?: boolean;
6 }
7
8 export function formatWorkspaceReference(path: string, isDir?: boolean): string {
9 const clean = isDir && !path.endsWith("/") ? path + "/" : path;
10 return `@${clean}`;
11 }
12
13 export function parseWorkspaceReference(text: string): WorkspaceRefDragPayload | null {
14 const trimmed = text.trim();
15 const match = /^@(\S+)$/.exec(trimmed);
16 if (!match) return null;
17 const path = match[1];
18 if (!path) return null;
19 return { path, isDir: path.endsWith("/") };
20 }
21
22 export function readWorkspaceReferenceDrag(dataTransfer: DataTransfer): WorkspaceRefDragPayload | null {
23 if (!Array.from(dataTransfer.types).includes(WORKSPACE_REF_DRAG_TYPE)) return null;
24 try {
25 const payload = JSON.parse(dataTransfer.getData(WORKSPACE_REF_DRAG_TYPE)) as WorkspaceRefDragPayload;
26 if (!payload.path) return null;
27 return { path: payload.path, isDir: payload.isDir };
28 } catch {
29 return null;
30 }
31 }
32
32 lines TYPESCRIPT