@georapbox/files-dropzone-element 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +48 -1
- package/dist/files-dropzone-defined.js +13 -4
- package/dist/files-dropzone-defined.js.map +7 -1
- package/dist/files-dropzone.d.ts.map +1 -1
- package/dist/files-dropzone.js +13 -4
- package/dist/files-dropzone.js.map +7 -1
- package/dist/utils/files-selector.d.ts.map +1 -1
- package/dist/utils/is-valid-file.d.ts.map +1 -1
- package/package.json +22 -39
- package/src/files-dropzone.js +73 -53
- package/src/utils/files-selector.js +1 -1
- package/src/utils/is-valid-file.js +6 -1
package/src/files-dropzone.js
CHANGED
|
@@ -17,7 +17,7 @@ const FILE_TOO_SMALL = 'FILE_TOO_SMALL';
|
|
|
17
17
|
const INVALID_MIME_TYPE = 'INVALID_MIME_TYPE';
|
|
18
18
|
const template = document.createElement('template');
|
|
19
19
|
|
|
20
|
-
const styles = /* css
|
|
20
|
+
const styles = /* css */ `
|
|
21
21
|
*,
|
|
22
22
|
*::before,
|
|
23
23
|
*::after {
|
|
@@ -88,7 +88,7 @@ const styles = /* css */`
|
|
|
88
88
|
}
|
|
89
89
|
`;
|
|
90
90
|
|
|
91
|
-
template.innerHTML = /* html
|
|
91
|
+
template.innerHTML = /* html */ `
|
|
92
92
|
<style>
|
|
93
93
|
${styles}
|
|
94
94
|
</style>
|
|
@@ -172,7 +172,7 @@ class FilesDropzone extends HTMLElement {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
if (this.shadowRoot) {
|
|
175
|
-
this.#fileInput = /** @type {Nullable<HTMLInputElement>} */(this.shadowRoot.getElementById('file-input'));
|
|
175
|
+
this.#fileInput = /** @type {Nullable<HTMLInputElement>} */ (this.shadowRoot.getElementById('file-input'));
|
|
176
176
|
this.#dropzoneEl = this.shadowRoot.getElementById('dropzone');
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -381,11 +381,13 @@ class FilesDropzone extends HTMLElement {
|
|
|
381
381
|
try {
|
|
382
382
|
this.#handleFilesSelect(await getFilesFromEvent(evt));
|
|
383
383
|
} catch (error) {
|
|
384
|
-
this.dispatchEvent(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
384
|
+
this.dispatchEvent(
|
|
385
|
+
new CustomEvent(`${COMPONENT_NAME}-error`, {
|
|
386
|
+
bubbles: true,
|
|
387
|
+
composed: true,
|
|
388
|
+
detail: { error }
|
|
389
|
+
})
|
|
390
|
+
);
|
|
389
391
|
}
|
|
390
392
|
};
|
|
391
393
|
|
|
@@ -397,10 +399,12 @@ class FilesDropzone extends HTMLElement {
|
|
|
397
399
|
return;
|
|
398
400
|
}
|
|
399
401
|
|
|
400
|
-
this.dispatchEvent(
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
402
|
+
this.dispatchEvent(
|
|
403
|
+
new Event(`${COMPONENT_NAME}-dragenter`, {
|
|
404
|
+
bubbles: true,
|
|
405
|
+
composed: true
|
|
406
|
+
})
|
|
407
|
+
);
|
|
404
408
|
};
|
|
405
409
|
|
|
406
410
|
/**
|
|
@@ -423,10 +427,12 @@ class FilesDropzone extends HTMLElement {
|
|
|
423
427
|
this.#dropzoneEl.part.add('dropzone--dragover');
|
|
424
428
|
}
|
|
425
429
|
|
|
426
|
-
this.dispatchEvent(
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
+
this.dispatchEvent(
|
|
431
|
+
new Event(`${COMPONENT_NAME}-dragover`, {
|
|
432
|
+
bubbles: true,
|
|
433
|
+
composed: true
|
|
434
|
+
})
|
|
435
|
+
);
|
|
430
436
|
};
|
|
431
437
|
|
|
432
438
|
/**
|
|
@@ -442,10 +448,12 @@ class FilesDropzone extends HTMLElement {
|
|
|
442
448
|
this.#dropzoneEl.part.remove('dropzone--dragover');
|
|
443
449
|
}
|
|
444
450
|
|
|
445
|
-
this.dispatchEvent(
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
451
|
+
this.dispatchEvent(
|
|
452
|
+
new Event(`${COMPONENT_NAME}-dragleave`, {
|
|
453
|
+
bubbles: true,
|
|
454
|
+
composed: true
|
|
455
|
+
})
|
|
456
|
+
);
|
|
449
457
|
};
|
|
450
458
|
|
|
451
459
|
/**
|
|
@@ -468,11 +476,13 @@ class FilesDropzone extends HTMLElement {
|
|
|
468
476
|
try {
|
|
469
477
|
this.#handleFilesSelect(await getFilesFromEvent(evt));
|
|
470
478
|
} catch (error) {
|
|
471
|
-
this.dispatchEvent(
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
479
|
+
this.dispatchEvent(
|
|
480
|
+
new CustomEvent(`${COMPONENT_NAME}-error`, {
|
|
481
|
+
bubbles: true,
|
|
482
|
+
composed: true,
|
|
483
|
+
detail: { error }
|
|
484
|
+
})
|
|
485
|
+
);
|
|
476
486
|
}
|
|
477
487
|
};
|
|
478
488
|
|
|
@@ -521,10 +531,12 @@ class FilesDropzone extends HTMLElement {
|
|
|
521
531
|
for (const file of files) {
|
|
522
532
|
rejectedFiles.push({
|
|
523
533
|
file,
|
|
524
|
-
errors: [
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
534
|
+
errors: [
|
|
535
|
+
{
|
|
536
|
+
code: TOO_MANY_FILES,
|
|
537
|
+
message: `Too many files selected. Only 1 file is allowed.`
|
|
538
|
+
}
|
|
539
|
+
]
|
|
528
540
|
});
|
|
529
541
|
}
|
|
530
542
|
} else if (this.multiple && filesLength > this.maxFiles) {
|
|
@@ -533,10 +545,12 @@ class FilesDropzone extends HTMLElement {
|
|
|
533
545
|
for (const file of files) {
|
|
534
546
|
rejectedFiles.push({
|
|
535
547
|
file,
|
|
536
|
-
errors: [
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
548
|
+
errors: [
|
|
549
|
+
{
|
|
550
|
+
code: TOO_MANY_FILES,
|
|
551
|
+
message: `Too many files selected. Only ${this.maxFiles} ${this.maxFiles > 1 ? 'files are' : 'file is'} allowed.`
|
|
552
|
+
}
|
|
553
|
+
]
|
|
540
554
|
});
|
|
541
555
|
}
|
|
542
556
|
} else {
|
|
@@ -578,33 +592,39 @@ class FilesDropzone extends HTMLElement {
|
|
|
578
592
|
}
|
|
579
593
|
}
|
|
580
594
|
|
|
581
|
-
this.dispatchEvent(
|
|
582
|
-
|
|
583
|
-
composed: true,
|
|
584
|
-
detail: {
|
|
585
|
-
acceptedFiles,
|
|
586
|
-
rejectedFiles
|
|
587
|
-
}
|
|
588
|
-
}));
|
|
589
|
-
|
|
590
|
-
if (acceptedFiles.length > 0) {
|
|
591
|
-
this.dispatchEvent(new CustomEvent(`${COMPONENT_NAME}-drop-accepted`, {
|
|
595
|
+
this.dispatchEvent(
|
|
596
|
+
new CustomEvent(`${COMPONENT_NAME}-drop`, {
|
|
592
597
|
bubbles: true,
|
|
593
598
|
composed: true,
|
|
594
599
|
detail: {
|
|
595
|
-
acceptedFiles
|
|
600
|
+
acceptedFiles,
|
|
601
|
+
rejectedFiles
|
|
596
602
|
}
|
|
597
|
-
})
|
|
603
|
+
})
|
|
604
|
+
);
|
|
605
|
+
|
|
606
|
+
if (acceptedFiles.length > 0) {
|
|
607
|
+
this.dispatchEvent(
|
|
608
|
+
new CustomEvent(`${COMPONENT_NAME}-drop-accepted`, {
|
|
609
|
+
bubbles: true,
|
|
610
|
+
composed: true,
|
|
611
|
+
detail: {
|
|
612
|
+
acceptedFiles
|
|
613
|
+
}
|
|
614
|
+
})
|
|
615
|
+
);
|
|
598
616
|
}
|
|
599
617
|
|
|
600
618
|
if (rejectedFiles.length > 0) {
|
|
601
|
-
this.dispatchEvent(
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
619
|
+
this.dispatchEvent(
|
|
620
|
+
new CustomEvent(`${COMPONENT_NAME}-drop-rejected`, {
|
|
621
|
+
bubbles: true,
|
|
622
|
+
composed: true,
|
|
623
|
+
detail: {
|
|
624
|
+
rejectedFiles
|
|
625
|
+
}
|
|
626
|
+
})
|
|
627
|
+
);
|
|
608
628
|
}
|
|
609
629
|
|
|
610
630
|
if (this.#fileInput) {
|
|
@@ -239,7 +239,7 @@ const getFilesFromDataTransferItemList = async dataTransferItemList => {
|
|
|
239
239
|
files.push(file);
|
|
240
240
|
}
|
|
241
241
|
} else if (entry.isDirectory) {
|
|
242
|
-
queue.push(...await readAllDirectoryEntries(entry.createReader()));
|
|
242
|
+
queue.push(...(await readAllDirectoryEntries(entry.createReader())));
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
|
|
@@ -13,7 +13,12 @@ export function isValidFile(file, acceptedTypeSpecifiers = '') {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
const acceptedMimeTypesList = [
|
|
16
|
-
...new Set(
|
|
16
|
+
...new Set(
|
|
17
|
+
acceptedTypeSpecifiers
|
|
18
|
+
.split(',')
|
|
19
|
+
.map(v => v.trim())
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
)
|
|
17
22
|
];
|
|
18
23
|
|
|
19
24
|
const fileMimeType = file.type;
|