refactor: make draggedDocIds a required property in PointerDownOptions and simplify handlePointerDown logic accordingly

This commit is contained in:
2025-11-25 21:04:54 +01:00
parent e0fce40bc3
commit 5accfb4339
2 changed files with 8 additions and 16 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ import React, {
import { resolveDocumentAssetUrl } from '../asset_manager';
import type { GetAsset } from '../asset_manager';
import { formatTransform } from '../utils/math';
import useDocumentDrag from './useDocumentDrag';
import useDocumentDrag, { PointerDownOptions } from './useDocumentDrag';
import PreviewZoomOverlay from '../detail/PreviewZoomOverlay';
import {
WorkspaceEngine,
@@ -894,7 +894,7 @@ function DesktopWorkspaceView({
onDocumentActivate: handleDeskDocumentActivate,
markLayoutDirty,
}) as {
handlePointerDown: React.PointerEventHandler<HTMLElement>;
handlePointerDown: (event: React.PointerEvent<HTMLElement>, docId: Identifier | null, options: PointerDownOptions) => void;
handlePointerMove: React.PointerEventHandler<HTMLElement>;
handlePointerUp: React.PointerEventHandler<HTMLElement>;
handlePointerCancel: React.PointerEventHandler<HTMLElement>;
+6 -14
View File
@@ -82,8 +82,8 @@ interface DragSettings {
debugDrag?: boolean;
}
interface PointerDownOptions {
draggedDocIds?: string[];
export interface PointerDownOptions {
draggedDocIds: string[];
stackSelectionApplied?: boolean;
modifierActive?: boolean;
}
@@ -310,7 +310,7 @@ const useDocumentDrag = (options: UseDocumentDragOptions) => {
);
const handlePointerDown = useCallback(
(event: PointerEventLike, docIdInput?: Identifier | null, options: PointerDownOptions = {}) => {
(event: PointerEventLike, docIdInput: Identifier | null, options: PointerDownOptions) => {
const targetElement = getEventTargetElement(event);
if (targetElement?.closest && targetElement.closest('[data-desk-tag-chip="true"]')) {
return;
@@ -330,22 +330,14 @@ const useDocumentDrag = (options: UseDocumentDragOptions) => {
return;
}
const massGrams = computeDocumentMassGrams(doc);
const draggedDocIds = options?.draggedDocIds;
const draggedDocIds = options.draggedDocIds;
let selectionIds: string[] = [];
if (Array.isArray(draggedDocIds) && draggedDocIds.length > 0) {
// Use explicitly provided IDs for the drag operation
selectionIds = draggedDocIds;
} else {
// Fallback (should ideally not happen if useDeskPointer is correct)
selectionIds = [docKey];
}
let selectionIds: string[] = draggedDocIds;
selectionIds = selectionIds.filter((id, index, array) => array.indexOf(id) === index && documentLookup.has(id));
if (!selectionIds.length) {
selectionIds = [docKey];
return;
}
const isGroupDrag = selectionIds.length > 1;