|
8 | 8 | isEvtWithFiles, |
9 | 9 | isIeOrEdge, |
10 | 10 | isPropagationStopped, |
11 | | - onDocumentDragOver, |
12 | 11 | TOO_MANY_FILES_REJECTION |
13 | 12 | } from "./../utils/index"; |
14 | 13 | import { onMount, onDestroy, createEventDispatcher } from "svelte"; |
|
257 | 256 | } |
258 | 257 | } |
259 | 258 |
|
| 259 | + // allow the entire document to be a drag target |
| 260 | + function onDocumentDragOver(event) { |
| 261 | + if (preventDropOnDocument) { |
| 262 | + event.preventDefault(); |
| 263 | + } |
| 264 | + } |
| 265 | +
|
260 | 266 | let dragTargetsRef = []; |
261 | 267 | function onDocumentDrop(event) { |
| 268 | + if (!preventDropOnDocument) { |
| 269 | + return; |
| 270 | + } |
262 | 271 | if (rootRef && rootRef.contains(event.target)) { |
263 | 272 | // If we intercepted an event for our instance, let it propagate down to the instance's onDrop handler |
264 | 273 | return; |
|
284 | 293 | } |
285 | 294 | } |
286 | 295 |
|
287 | | - onMount(() => { |
288 | | - window.addEventListener("focus", onWindowFocus, false); |
289 | | - if (preventDropOnDocument) { |
290 | | - document.addEventListener("dragover", onDocumentDragOver, false); |
291 | | - document.addEventListener("drop", onDocumentDrop, false); |
292 | | - } |
293 | | - }); |
294 | | -
|
295 | 296 | onDestroy(() => { |
296 | | - window.removeEventListener("focus", onWindowFocus, false); |
297 | | - if (preventDropOnDocument) { |
298 | | - document.removeEventListener("dragover", onDocumentDragOver); |
299 | | - document.removeEventListener("drop", onDocumentDrop); |
300 | | - } |
| 297 | + // This is critical for canceling the timeout behaviour on `onWindowFocus()` |
| 298 | + inputRef = null; |
301 | 299 | }); |
302 | 300 |
|
303 | 301 | function onInputElementClick(event) { |
|
326 | 324 | } |
327 | 325 | </style> |
328 | 326 |
|
| 327 | +<svelte:window on:focus={onWindowFocus} on:dragover={onDocumentDragOver} on:drop={onDocumentDrop} /> |
| 328 | + |
329 | 329 | <div |
330 | 330 | bind:this={rootRef} |
331 | 331 | tabindex="0" |
|
0 commit comments