Skip to content

Commit 02b44ed

Browse files
committed
fix for #81
1 parent aef6fee commit 02b44ed

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

src/components/Dropzone.svelte

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
isIeOrEdge,
1010
isPropagationStopped,
1111
onDocumentDragOver,
12-
TOO_MANY_FILES_REJECTION
12+
TOO_MANY_FILES_REJECTION,
1313
} from "./../utils/index";
1414
import { onMount, onDestroy, createEventDispatcher } from "svelte";
1515
@@ -45,7 +45,7 @@
4545
isDragReject: false,
4646
draggedFiles: [],
4747
acceptedFiles: [],
48-
fileRejections: []
48+
fileRejections: [],
4949
};
5050
5151
let rootRef;
@@ -112,7 +112,7 @@
112112
dragTargetsRef = [...dragTargetsRef, event.target];
113113
114114
if (isEvtWithFiles(event)) {
115-
Promise.resolve(getFilesFromEvent(event)).then(draggedFiles => {
115+
Promise.resolve(getFilesFromEvent(event)).then((draggedFiles) => {
116116
if (isPropagationStopped(event) && !noDragEventsBubbling) {
117117
return;
118118
}
@@ -121,7 +121,7 @@
121121
state.isDragActive = true;
122122
123123
dispatch("dragenter", {
124-
dragEvent: event
124+
dragEvent: event,
125125
});
126126
});
127127
}
@@ -139,7 +139,7 @@
139139
140140
if (isEvtWithFiles(event)) {
141141
dispatch("dragover", {
142-
dragEvent: event
142+
dragEvent: event,
143143
});
144144
}
145145
@@ -152,7 +152,7 @@
152152
153153
// Only deactivate once the dropzone and all children have been left
154154
const targets = dragTargetsRef.filter(
155-
target => rootRef && rootRef.contains(target)
155+
(target) => rootRef && rootRef.contains(target)
156156
);
157157
// Make sure to remove a target present multiple times only once
158158
// (Firefox may fire dragenter/dragleave multiple times on the same element)
@@ -170,7 +170,7 @@
170170
171171
if (isEvtWithFiles(event)) {
172172
dispatch("dragleave", {
173-
dragEvent: event
173+
dragEvent: event,
174174
});
175175
}
176176
}
@@ -182,28 +182,28 @@
182182
dragTargetsRef = [];
183183
184184
if (isEvtWithFiles(event)) {
185-
Promise.resolve(getFilesFromEvent(event)).then(files => {
185+
Promise.resolve(getFilesFromEvent(event)).then((files) => {
186186
if (isPropagationStopped(event) && !noDragEventsBubbling) {
187187
return;
188188
}
189189
190190
const acceptedFiles = [];
191191
const fileRejections = [];
192192
193-
files.forEach(file => {
193+
files.forEach((file) => {
194194
const [accepted, acceptError] = fileAccepted(file, accept);
195195
const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);
196196
if (accepted && sizeMatch) {
197197
acceptedFiles.push(file);
198198
} else {
199-
const errors = [acceptError, sizeError].filter(e => e);
199+
const errors = [acceptError, sizeError].filter((e) => e);
200200
fileRejections.push({ file, errors });
201201
}
202202
});
203203
204204
if (!multiple && acceptedFiles.length > 1) {
205205
// Reject everything and empty accepted files
206-
acceptedFiles.forEach(file => {
206+
acceptedFiles.forEach((file) => {
207207
fileRejections.push({ file, errors: [TOO_MANY_FILES_REJECTION] });
208208
});
209209
acceptedFiles.splice(0);
@@ -215,20 +215,20 @@
215215
dispatch("drop", {
216216
acceptedFiles,
217217
fileRejections,
218-
event
218+
event,
219219
});
220220
221221
if (fileRejections.length > 0) {
222222
dispatch("droprejected", {
223223
fileRejections,
224-
event
224+
event,
225225
});
226226
}
227227
228228
if (acceptedFiles.length > 0) {
229229
dispatch("dropaccepted", {
230230
acceptedFiles,
231-
event
231+
event,
232232
});
233233
}
234234
});
@@ -290,10 +290,10 @@
290290
});
291291
292292
onDestroy(() => {
293-
window.removeEventListener("focus", onWindowFocus, false);
293+
window && window.removeEventListener("focus", onWindowFocus, false);
294294
if (preventDropOnDocument) {
295-
document.removeEventListener("dragover", onDocumentDragOver);
296-
document.removeEventListener("drop", onDocumentDrop);
295+
document && document.removeEventListener("dragover", onDocumentDragOver);
296+
document && document.removeEventListener("drop", onDocumentDrop);
297297
}
298298
});
299299
@@ -302,27 +302,6 @@
302302
}
303303
</script>
304304

305-
<style>
306-
.dropzone {
307-
flex: 1;
308-
display: flex;
309-
flex-direction: column;
310-
align-items: center;
311-
padding: 20px;
312-
border-width: 2px;
313-
border-radius: 2px;
314-
border-color: #eeeeee;
315-
border-style: dashed;
316-
background-color: #fafafa;
317-
color: #bdbdbd;
318-
outline: none;
319-
transition: border 0.24s ease-in-out;
320-
}
321-
.dropzone:focus {
322-
border-color: #2196f3;
323-
}
324-
</style>
325-
326305
<div
327306
bind:this={rootRef}
328307
tabindex="0"
@@ -336,7 +315,8 @@
336315
on:dragenter={composeDragHandler(onDragEnterCb)}
337316
on:dragover={composeDragHandler(onDragOverCb)}
338317
on:dragleave={composeDragHandler(onDragLeaveCb)}
339-
on:drop={composeDragHandler(onDropCb)}>
318+
on:drop={composeDragHandler(onDropCb)}
319+
>
340320
<input
341321
{accept}
342322
{multiple}
@@ -346,8 +326,30 @@
346326
on:change={onDropCb}
347327
on:click={onInputElementClick}
348328
bind:this={inputRef}
349-
style="display: none;" />
329+
style="display: none;"
330+
/>
350331
<slot>
351332
<p>Drag 'n' drop some files here, or click to select files</p>
352333
</slot>
353334
</div>
335+
336+
<style>
337+
.dropzone {
338+
flex: 1;
339+
display: flex;
340+
flex-direction: column;
341+
align-items: center;
342+
padding: 20px;
343+
border-width: 2px;
344+
border-radius: 2px;
345+
border-color: #eeeeee;
346+
border-style: dashed;
347+
background-color: #fafafa;
348+
color: #bdbdbd;
349+
outline: none;
350+
transition: border 0.24s ease-in-out;
351+
}
352+
.dropzone:focus {
353+
border-color: #2196f3;
354+
}
355+
</style>

0 commit comments

Comments
 (0)