Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/dnd.ts
3292 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 { addDisposableListener } from './dom.js';
7
import { Disposable } from '../common/lifecycle.js';
8
import { Mimes } from '../common/mime.js';
9
10
/**
11
* A helper that will execute a provided function when the provided HTMLElement receives
12
* dragover event for 800ms. If the drag is aborted before, the callback will not be triggered.
13
*/
14
export class DelayedDragHandler extends Disposable {
15
private timeout: Timeout | undefined = undefined;
16
17
constructor(container: HTMLElement, callback: () => void) {
18
super();
19
20
this._register(addDisposableListener(container, 'dragover', e => {
21
e.preventDefault(); // needed so that the drop event fires (https://stackoverflow.com/questions/21339924/drop-event-not-firing-in-chrome)
22
23
if (!this.timeout) {
24
this.timeout = setTimeout(() => {
25
callback();
26
27
this.timeout = undefined;
28
}, 800);
29
}
30
}));
31
32
['dragleave', 'drop', 'dragend'].forEach(type => {
33
this._register(addDisposableListener(container, type, () => {
34
this.clearDragTimeout();
35
}));
36
});
37
}
38
39
private clearDragTimeout(): void {
40
if (this.timeout) {
41
clearTimeout(this.timeout);
42
this.timeout = undefined;
43
}
44
}
45
46
override dispose(): void {
47
super.dispose();
48
49
this.clearDragTimeout();
50
}
51
}
52
53
// Common data transfers
54
export const DataTransfers = {
55
56
/**
57
* Application specific resource transfer type
58
*/
59
RESOURCES: 'ResourceURLs',
60
61
/**
62
* Browser specific transfer type to download
63
*/
64
DOWNLOAD_URL: 'DownloadURL',
65
66
/**
67
* Browser specific transfer type for files
68
*/
69
FILES: 'Files',
70
71
/**
72
* Typically transfer type for copy/paste transfers.
73
*/
74
TEXT: Mimes.text,
75
76
/**
77
* Internal type used to pass around text/uri-list data.
78
*
79
* This is needed to work around https://bugs.chromium.org/p/chromium/issues/detail?id=239745.
80
*/
81
INTERNAL_URI_LIST: 'application/vnd.code.uri-list',
82
};
83
84
export interface IDragAndDropData {
85
update(dataTransfer: DataTransfer): void;
86
getData(): unknown;
87
}
88
89