Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/ui/dnd/dnd.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { $ } from '../../dom.js';
7
import './dnd.css';
8
9
export function applyDragImage(event: DragEvent, container: HTMLElement, label: string, extraClasses: string[] = []): void {
10
if (!event.dataTransfer) {
11
return;
12
}
13
14
const dragImage = $('.monaco-drag-image');
15
dragImage.textContent = label;
16
dragImage.classList.add(...extraClasses);
17
18
const getDragImageContainer = (e: HTMLElement | null) => {
19
while (e && !e.classList.contains('monaco-workbench')) {
20
e = e.parentElement;
21
}
22
return e || container.ownerDocument.body;
23
};
24
25
const dragContainer = getDragImageContainer(container);
26
dragContainer.appendChild(dragImage);
27
event.dataTransfer.setDragImage(dragImage, -10, -10);
28
29
// Removes the element when the DND operation is done
30
setTimeout(() => dragImage.remove(), 0);
31
}
32
33