Skip to content

resolveCloudDiskFolderDropTargetAtPoint

根据指针坐标解析云盘/桌面文件夹拖拽落点,按 specificity 与 z-index 择优。

前置依赖

依赖参数

参数名类型说明
deps.queryFolderWindows() => ArrayLike<CloudDiskFolderDropTargetElement>查询未最小化的文件夹窗口壳
deps.readComputedZIndex(el) => string可选,读取 computed z-index

DOM 约定

  • 窗口壳:.folder-window:not([data-minimized])
  • 面板落点:[data-folder-drop-target]
  • 资源管理器文件夹磁贴:[data-explorer-folder-id]
  • 桌面文件夹槽:[data-desktop-folder-id]

函数签名

typescript
function resolveCloudDiskFolderDropTargetAtPoint(
  options: {
    clientX: number
    clientY: number
    dragIds: readonly string[]
    iconsLayer: CloudDiskFolderDropTargetElement | null
    isFolderId?: (folderId: string) => boolean
  },
  deps: {
    queryFolderWindows: () => ArrayLike<CloudDiskFolderDropTargetElement>
    readComputedZIndex?: (el: CloudDiskFolderDropTargetElement) => string
  },
): string | null

参数

参数名类型必填说明
options.clientX / clientYnumber指针客户端坐标
options.dragIdsreadonly string[]正在拖拽的节点 id,排除自落点
options.iconsLayerelement | null桌面图标层根元素
options.isFolderIdfunction过滤桌面槽是否有效文件夹
deps.queryFolderWindowsfunction注入窗口查询(通常 document.querySelectorAll

返回值

类型说明
string | null命中的文件夹 id,无命中返回 null

工作原理

  1. 遍历每个打开的文件夹窗口,收集面板落点(specificity=1)与 explorer 磁贴(specificity=2)的矩形命中。
  2. iconsLayer 内扫描桌面文件夹槽,同样 specificity=2,并可用 isFolderId 过滤。
  3. 排除 dragIds 中的 id,避免拖到自己。
  4. specificity 降序、再按 zIndex 降序排序,返回最优 hit 的 id。