fix
This commit is contained in:
@@ -124,7 +124,6 @@ interface DesktopWorkspaceProps {
|
|||||||
onDocumentStackSelect?: (docIds: Identifier[]) => void;
|
onDocumentStackSelect?: (docIds: Identifier[]) => void;
|
||||||
onPromoteSelection?: (...args: unknown[]) => void;
|
onPromoteSelection?: (...args: unknown[]) => void;
|
||||||
onAssignTagToDocument?: (...args: unknown[]) => void;
|
onAssignTagToDocument?: (...args: unknown[]) => void;
|
||||||
onRemoveTagFromDocument?: (...args: unknown[]) => void;
|
|
||||||
ensureAssetUrl?: (...args: unknown[]) => Promise<unknown> | unknown;
|
ensureAssetUrl?: (...args: unknown[]) => Promise<unknown> | unknown;
|
||||||
getDocumentAsset?: (...args: unknown[]) => unknown;
|
getDocumentAsset?: (...args: unknown[]) => unknown;
|
||||||
activeTagIds?: Array<Identifier | null | undefined>;
|
activeTagIds?: Array<Identifier | null | undefined>;
|
||||||
@@ -202,7 +201,6 @@ const DesktopWorkspace: React.FC<DesktopWorkspaceProps> = ({
|
|||||||
onDocumentStackSelect = null,
|
onDocumentStackSelect = null,
|
||||||
onPromoteSelection = null,
|
onPromoteSelection = null,
|
||||||
onAssignTagToDocument = null,
|
onAssignTagToDocument = null,
|
||||||
onRemoveTagFromDocument = null,
|
|
||||||
ensureAssetUrl = null,
|
ensureAssetUrl = null,
|
||||||
getDocumentAsset = () => null,
|
getDocumentAsset = () => null,
|
||||||
activeTagIds = [],
|
activeTagIds = [],
|
||||||
@@ -489,7 +487,6 @@ const DesktopWorkspace: React.FC<DesktopWorkspaceProps> = ({
|
|||||||
const tagInteractions = useDeskTagInteractions({
|
const tagInteractions = useDeskTagInteractions({
|
||||||
engine,
|
engine,
|
||||||
onAssignTagToDocument,
|
onAssignTagToDocument,
|
||||||
onRemoveTagFromDocument,
|
|
||||||
requestCanvasFocus,
|
requestCanvasFocus,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
} from '../../documents/tagTransfer';
|
} from '../../documents/tagTransfer';
|
||||||
|
|
||||||
const TAG_REMOVE_DISTANCE = 160;
|
const TAG_REMOVE_DISTANCE = 160;
|
||||||
const DEBUG_DROP = false;
|
|
||||||
|
|
||||||
const createDragPreview = (node, clientX, clientY) => {
|
const createDragPreview = (node, clientX, clientY) => {
|
||||||
if (!(node instanceof HTMLElement)) {
|
if (!(node instanceof HTMLElement)) {
|
||||||
@@ -42,145 +41,22 @@ const cleanupPreview = (previewNode) => {
|
|||||||
export const useDeskTagInteractions = ({
|
export const useDeskTagInteractions = ({
|
||||||
engine,
|
engine,
|
||||||
onAssignTagToDocument,
|
onAssignTagToDocument,
|
||||||
onRemoveTagFromDocument,
|
|
||||||
requestCanvasFocus,
|
requestCanvasFocus,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const draggingTagRef = useRef(null);
|
const draggingTagRef = useRef(null);
|
||||||
const pendingDocTagDragRef = useRef(null);
|
|
||||||
const removalCursorActiveRef = useRef(false);
|
|
||||||
|
|
||||||
const updateRemovalCursor = useCallback((active) => {
|
|
||||||
if (removalCursorActiveRef.current === active) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const body = document.body;
|
|
||||||
if (!body) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
removalCursorActiveRef.current = active;
|
|
||||||
if (active) {
|
|
||||||
body.classList.add('desk-cursor-remove');
|
|
||||||
} else {
|
|
||||||
body.classList.remove('desk-cursor-remove');
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(
|
|
||||||
() => () => {
|
|
||||||
updateRemovalCursor(false);
|
|
||||||
},
|
|
||||||
[updateRemovalCursor],
|
|
||||||
);
|
|
||||||
|
|
||||||
const isTagTransfer = useCallback((event) => isTagTransferEvent(event), []);
|
const isTagTransfer = useCallback((event) => isTagTransferEvent(event), []);
|
||||||
|
|
||||||
const handleTagDragEnd = useCallback(() => {
|
const handleDocTagPointerDown = useCallback(() => {
|
||||||
updateRemovalCursor(false);
|
engine.setPendingRemovalTag(null);
|
||||||
engine.setTagDropTargetId(null);
|
}, [engine]);
|
||||||
}, [engine, updateRemovalCursor]);
|
|
||||||
|
|
||||||
const finalizeTagDrag = useCallback(
|
|
||||||
(dropEffect = 'none') => {
|
|
||||||
const state = draggingTagRef.current;
|
|
||||||
if (!state) {
|
|
||||||
updateRemovalCursor(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
draggingTagRef.current = null;
|
|
||||||
|
|
||||||
const node = state.element;
|
|
||||||
const showNode = () => {
|
|
||||||
if (node instanceof HTMLElement) {
|
|
||||||
node.classList.remove('is-drag-hidden');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const scheduleShowNode = () => {
|
|
||||||
const raf = window.requestAnimationFrame;
|
|
||||||
if (raf) {
|
|
||||||
raf(showNode);
|
|
||||||
} else {
|
|
||||||
setTimeout(showNode, 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
cleanupPreview(state.previewClone);
|
|
||||||
|
|
||||||
const shouldRemove =
|
|
||||||
!state.dropHandled
|
|
||||||
&& dropEffect === 'none'
|
|
||||||
&& state.sourceDocId
|
|
||||||
&& (state.distance || 0) >= TAG_REMOVE_DISTANCE;
|
|
||||||
|
|
||||||
if (!shouldRemove) {
|
|
||||||
scheduleShowNode();
|
|
||||||
updateRemovalCursor(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateRemovalCursor(false);
|
|
||||||
engine.setPendingRemovalTag({ docId: state.sourceDocId, tagId: state.tagId });
|
|
||||||
const removePromise = safeInvoke(onRemoveTagFromDocument, state.sourceDocId, state.tagId);
|
|
||||||
if (!removePromise || typeof removePromise.then !== 'function') {
|
|
||||||
scheduleShowNode();
|
|
||||||
engine.setPendingRemovalTag(null);
|
|
||||||
updateRemovalCursor(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
void (async () => {
|
|
||||||
try {
|
|
||||||
await removePromise;
|
|
||||||
void DEBUG_DROP;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to remove tag after drag', error);
|
|
||||||
scheduleShowNode();
|
|
||||||
} finally {
|
|
||||||
engine.setPendingRemovalTag(null);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
},
|
|
||||||
[engine, onRemoveTagFromDocument, updateRemovalCursor],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDocTagPointerDown = useCallback((event, doc, tag) => {
|
|
||||||
if (!doc || !tag) {
|
|
||||||
pendingDocTagDragRef.current = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { x: startX, y: startY } = getPointerPosition(event);
|
|
||||||
pendingDocTagDragRef.current = {
|
|
||||||
docId: doc.id,
|
|
||||||
tagId: tag.id,
|
|
||||||
startX,
|
|
||||||
startY,
|
|
||||||
};
|
|
||||||
updateRemovalCursor(false);
|
|
||||||
}, [updateRemovalCursor]);
|
|
||||||
|
|
||||||
const markActiveTagDropHandled = useCallback((tagId, sourceDocId = null) => {
|
|
||||||
const state = draggingTagRef.current;
|
|
||||||
if (!state) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (state.tagId !== tagId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (sourceDocId && state.sourceDocId !== sourceDocId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
state.dropHandled = true;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const runTagHoverTransition = useCallback(
|
const runTagHoverTransition = useCallback(
|
||||||
(event, docId, { applyTarget = false, applyPending = false, updateCursor = true } = {}) => {
|
(event, docId, { applyTarget = false, applyPending = false } = {}) => {
|
||||||
if (!isTagTransfer(event)) {
|
if (!isTagTransfer(event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
preventAll(event);
|
preventAll(event);
|
||||||
if (updateCursor) {
|
|
||||||
updateRemovalCursor(false);
|
|
||||||
}
|
|
||||||
const stringId = docId != null ? String(docId) : null;
|
const stringId = docId != null ? String(docId) : null;
|
||||||
if (applyTarget) {
|
if (applyTarget) {
|
||||||
engine.setTagDropTargetId(stringId);
|
engine.setTagDropTargetId(stringId);
|
||||||
@@ -189,7 +65,7 @@ export const useDeskTagInteractions = ({
|
|||||||
engine.setPendingTagDocId(stringId);
|
engine.setPendingTagDocId(stringId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[engine, isTagTransfer, updateRemovalCursor],
|
[engine, isTagTransfer],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleTagDragEnterDoc = useCallback(
|
const handleTagDragEnterDoc = useCallback(
|
||||||
@@ -238,7 +114,7 @@ export const useDeskTagInteractions = ({
|
|||||||
if (!payload || !payload.id) {
|
if (!payload || !payload.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
markActiveTagDropHandled(payload.id, payload.sourceDocId);
|
engine.setPendingRemovalTag(null);
|
||||||
|
|
||||||
if (payload.sourceDocId === doc.id) {
|
if (payload.sourceDocId === doc.id) {
|
||||||
return;
|
return;
|
||||||
@@ -252,7 +128,7 @@ export const useDeskTagInteractions = ({
|
|||||||
sourceDocId: payload.sourceDocId ?? null,
|
sourceDocId: payload.sourceDocId ?? null,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[engine, isTagTransfer, markActiveTagDropHandled, onAssignTagToDocument, requestCanvasFocus],
|
[engine, isTagTransfer, onAssignTagToDocument, requestCanvasFocus],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDocTagDragStart = useCallback(
|
const handleDocTagDragStart = useCallback(
|
||||||
@@ -282,12 +158,11 @@ export const useDeskTagInteractions = ({
|
|||||||
initialX: pointerX,
|
initialX: pointerX,
|
||||||
initialY: pointerY,
|
initialY: pointerY,
|
||||||
distance: 0,
|
distance: 0,
|
||||||
dropHandled: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updateRemovalCursor(false);
|
engine.setPendingRemovalTag(null);
|
||||||
},
|
},
|
||||||
[updateRemovalCursor],
|
[engine],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDocTagDrag = useCallback((event) => {
|
const handleDocTagDrag = useCallback((event) => {
|
||||||
@@ -300,35 +175,36 @@ export const useDeskTagInteractions = ({
|
|||||||
const dy = y - (state.initialY || 0);
|
const dy = y - (state.initialY || 0);
|
||||||
state.distance = Math.sqrt(dx * dx + dy * dy);
|
state.distance = Math.sqrt(dx * dx + dy * dy);
|
||||||
if (state.distance >= TAG_REMOVE_DISTANCE) {
|
if (state.distance >= TAG_REMOVE_DISTANCE) {
|
||||||
updateRemovalCursor(true);
|
engine.setPendingRemovalTag({ docId: state.sourceDocId, tagId: state.tagId });
|
||||||
} else {
|
} else {
|
||||||
updateRemovalCursor(false);
|
engine.setPendingRemovalTag(null);
|
||||||
}
|
}
|
||||||
}, [updateRemovalCursor]);
|
}, [engine]);
|
||||||
|
|
||||||
const handleDocTagDragEnd = useCallback(
|
const handleDocTagDragEnd = useCallback(
|
||||||
(event) => {
|
() => {
|
||||||
finalizeTagDrag(event?.dataTransfer?.dropEffect || 'none');
|
|
||||||
const state = draggingTagRef.current;
|
const state = draggingTagRef.current;
|
||||||
if (!state) {
|
if (state) {
|
||||||
return;
|
const element = state.element;
|
||||||
|
if (element) {
|
||||||
|
element.classList.remove('is-drag-hidden');
|
||||||
|
}
|
||||||
|
cleanupPreview(state.previewClone);
|
||||||
}
|
}
|
||||||
const element = state.element;
|
|
||||||
if (element) {
|
|
||||||
element.classList.remove('is-drag-hidden');
|
|
||||||
}
|
|
||||||
cleanupPreview(state.previewClone);
|
|
||||||
draggingTagRef.current = null;
|
draggingTagRef.current = null;
|
||||||
|
engine.setPendingRemovalTag(null);
|
||||||
|
engine.setTagDropTargetId(null);
|
||||||
|
engine.setPendingTagDocId(null);
|
||||||
},
|
},
|
||||||
[finalizeTagDrag],
|
[engine],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
draggingTagRef.current = null;
|
draggingTagRef.current = null;
|
||||||
pendingDocTagDragRef.current = null;
|
engine.setPendingRemovalTag(null);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [engine]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handleTagDragEnterDoc,
|
handleTagDragEnterDoc,
|
||||||
@@ -339,8 +215,6 @@ export const useDeskTagInteractions = ({
|
|||||||
handleDocTagDragStart,
|
handleDocTagDragStart,
|
||||||
handleDocTagDrag,
|
handleDocTagDrag,
|
||||||
handleDocTagDragEnd,
|
handleDocTagDragEnd,
|
||||||
handleTagDragEnd,
|
|
||||||
markActiveTagDropHandled,
|
|
||||||
handleCanvasDragOver,
|
handleCanvasDragOver,
|
||||||
handleCanvasDragLeave,
|
handleCanvasDragLeave,
|
||||||
handleCanvasDrop,
|
handleCanvasDrop,
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ interface UseDeskWorkspacePropsArgs {
|
|||||||
handleDetailPanelClose?: () => void;
|
handleDetailPanelClose?: () => void;
|
||||||
resolveThumbnailUrlForDoc?: (doc: DocumentEntry) => string | null;
|
resolveThumbnailUrlForDoc?: (doc: DocumentEntry) => string | null;
|
||||||
handleDocumentTagDrop?: (...args: unknown[]) => void;
|
handleDocumentTagDrop?: (...args: unknown[]) => void;
|
||||||
handleTagRemove?: (...args: unknown[]) => void;
|
|
||||||
ensureAssetUrl?: (...args: unknown[]) => void;
|
ensureAssetUrl?: (...args: unknown[]) => void;
|
||||||
getDocumentAsset?: (...args: unknown[]) => unknown;
|
getDocumentAsset?: (...args: unknown[]) => unknown;
|
||||||
activeTagFilters?: Identifier[];
|
activeTagFilters?: Identifier[];
|
||||||
@@ -84,7 +83,6 @@ const useDeskWorkspaceProps = ({
|
|||||||
handleDetailPanelClose,
|
handleDetailPanelClose,
|
||||||
resolveThumbnailUrlForDoc,
|
resolveThumbnailUrlForDoc,
|
||||||
handleDocumentTagDrop,
|
handleDocumentTagDrop,
|
||||||
handleTagRemove,
|
|
||||||
ensureAssetUrl,
|
ensureAssetUrl,
|
||||||
getDocumentAsset,
|
getDocumentAsset,
|
||||||
activeTagFilters = [],
|
activeTagFilters = [],
|
||||||
@@ -185,7 +183,6 @@ const useDeskWorkspaceProps = ({
|
|||||||
onCloseDetailPanel: handleDetailPanelClose,
|
onCloseDetailPanel: handleDetailPanelClose,
|
||||||
resolveThumbnailUrl: resolveThumbnailUrlForDoc,
|
resolveThumbnailUrl: resolveThumbnailUrlForDoc,
|
||||||
onAssignTagToDocument: handleDocumentTagDrop,
|
onAssignTagToDocument: handleDocumentTagDrop,
|
||||||
onRemoveTagFromDocument: handleTagRemove,
|
|
||||||
ensureAssetUrl,
|
ensureAssetUrl,
|
||||||
getDocumentAsset,
|
getDocumentAsset,
|
||||||
activeTagIds: activeTagFilters,
|
activeTagIds: activeTagFilters,
|
||||||
@@ -226,7 +223,6 @@ const useDeskWorkspaceProps = ({
|
|||||||
handleDetailPanelClose,
|
handleDetailPanelClose,
|
||||||
resolveThumbnailUrlForDoc,
|
resolveThumbnailUrlForDoc,
|
||||||
handleDocumentTagDrop,
|
handleDocumentTagDrop,
|
||||||
handleTagRemove,
|
|
||||||
ensureAssetUrl,
|
ensureAssetUrl,
|
||||||
getDocumentAsset,
|
getDocumentAsset,
|
||||||
activeTagFilters,
|
activeTagFilters,
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
max-width: min(640px, calc(100% - 2rem));
|
max-width: min(640px, calc(100% - 2rem));
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
overflow: hidden;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-floating__buttons {
|
.panel-floating__buttons {
|
||||||
@@ -153,7 +153,7 @@
|
|||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
overflow: hidden;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-floating-actions--assignments {
|
.panel-floating-actions--assignments {
|
||||||
@@ -163,7 +163,7 @@
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
overflow: hidden;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-floating-actions .quick-add {
|
.panel-floating-actions .quick-add {
|
||||||
|
|||||||
Reference in New Issue
Block a user