/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { addDisposableListener } from './dom.js';6import { Disposable } from '../common/lifecycle.js';7import { Mimes } from '../common/mime.js';89/**10* A helper that will execute a provided function when the provided HTMLElement receives11* dragover event for 800ms. If the drag is aborted before, the callback will not be triggered.12*/13export class DelayedDragHandler extends Disposable {14private timeout: Timeout | undefined = undefined;1516constructor(container: HTMLElement, callback: () => void) {17super();1819this._register(addDisposableListener(container, 'dragover', e => {20e.preventDefault(); // needed so that the drop event fires (https://stackoverflow.com/questions/21339924/drop-event-not-firing-in-chrome)2122if (!this.timeout) {23this.timeout = setTimeout(() => {24callback();2526this.timeout = undefined;27}, 800);28}29}));3031['dragleave', 'drop', 'dragend'].forEach(type => {32this._register(addDisposableListener(container, type, () => {33this.clearDragTimeout();34}));35});36}3738private clearDragTimeout(): void {39if (this.timeout) {40clearTimeout(this.timeout);41this.timeout = undefined;42}43}4445override dispose(): void {46super.dispose();4748this.clearDragTimeout();49}50}5152// Common data transfers53export const DataTransfers = {5455/**56* Application specific resource transfer type57*/58RESOURCES: 'ResourceURLs',5960/**61* Browser specific transfer type to download62*/63DOWNLOAD_URL: 'DownloadURL',6465/**66* Browser specific transfer type for files67*/68FILES: 'Files',6970/**71* Typically transfer type for copy/paste transfers.72*/73TEXT: Mimes.text,7475/**76* Internal type used to pass around text/uri-list data.77*78* This is needed to work around https://bugs.chromium.org/p/chromium/issues/detail?id=239745.79*/80INTERNAL_URI_LIST: 'application/vnd.code.uri-list',81};8283export interface IDragAndDropData {84update(dataTransfer: DataTransfer): void;85getData(): unknown;86}878889