@georapbox/files-dropzone-element 2.0.1 → 2.1.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/README.md +12 -3
- package/dist/files-dropzone-defined.js +13 -9
- package/dist/files-dropzone-defined.js.map +3 -3
- package/dist/files-dropzone.d.ts +42 -1
- package/dist/files-dropzone.d.ts.map +1 -1
- package/dist/files-dropzone.js +13 -9
- package/dist/files-dropzone.js.map +3 -3
- package/dist/utils/is-valid-file.d.ts +1 -1
- package/dist/utils/is-valid-file.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/files-dropzone.js +123 -81
package/README.md
CHANGED
|
@@ -108,17 +108,26 @@ By default, the component comes with basic styling. However, you can customise t
|
|
|
108
108
|
|
|
109
109
|
<sup>1</sup> Instance methods are only available after the component has been defined. To ensure the component is defined, you can use `whenDefined` method of the `CustomElementRegistry` interface, eg `customElements.whenDefined('files-dropzone').then(() => { /* call methods here */ });`
|
|
110
110
|
|
|
111
|
+
### Static Properties
|
|
112
|
+
|
|
113
|
+
Below are static properties exposed on the `FilesDropzone` class for consumer reference.
|
|
114
|
+
|
|
115
|
+
| Name | Type | Description |
|
|
116
|
+
| ---- | ---- | ----------- |
|
|
117
|
+
| `ERROR_CODES` | Object | Static object of stable identifiers used in drop error event. Properties: `FILE_DIALOG_OPEN_FAILED`, `FILE_INPUT_CHANGE_FAILED`, `DROP_EVENT_PROCESSING_FAILED`, `UNKNOWN_ERROR`. |
|
|
118
|
+
| `REJECTION_CODES` | Object | Static object of stable identifiers used for file rejection reasons. Properties : `TOO_MANY_FILES`, `FILE_TOO_LARGE`, `FILE_TOO_SMALL`, `INVALID_MIME_TYPE`. |
|
|
119
|
+
|
|
111
120
|
### Events
|
|
112
121
|
|
|
113
122
|
| Name | Description | Event Detail |
|
|
114
123
|
| ---- | ----------- | ------------ |
|
|
115
|
-
| `files-dropzone-drop` | Emitted when one or more files are selected, either by using the native file dialog or dropping files in the dropzone area. The event is emitted regardless if the dropped files are accepted or rejected. Files are accepted or rejected based on the `accept`, `max-files`, `max-size`, `min-size` and `multiple` attributes. | `{acceptedFiles: Array<File>, rejectedFiles: Array<{file: File, errors: Array<{code:
|
|
124
|
+
| `files-dropzone-drop` | Emitted when one or more files are selected, either by using the native file dialog or dropping files in the dropzone area. The event is emitted regardless if the dropped files are accepted or rejected. Files are accepted or rejected based on the `accept`, `max-files`, `max-size`, `min-size` and `multiple` attributes. | `{acceptedFiles: Array<File>, rejectedFiles: Array<{file: File, errors: Array<{code: FilesDropzoneRejectionCode, message: string}>}>}` |
|
|
116
125
|
| `files-dropzone-drop-accepted` | Emitted when one or more dropped files are accepted. If no files are accepted, the event is not emitted at all. | `{acceptedFiles: Array<File>}` |
|
|
117
|
-
| `files-dropzone-drop-rejected` | Emitted when one or more dropped files are rejected. If no files are rejected, the event is not emitted at all. | `{rejectedFiles: Array<{file: File, errors: Array<{code:
|
|
126
|
+
| `files-dropzone-drop-rejected` | Emitted when one or more dropped files are rejected. If no files are rejected, the event is not emitted at all. | `{rejectedFiles: Array<{file: File, errors: Array<{code: FilesDropzoneRejectionCode, message: string}>}>}` |
|
|
118
127
|
| `files-dropzone-dragenter` | Emitted on `dragenter` event. The event is not emitted if `disabled` attribute is set. | - |
|
|
119
128
|
| `files-dropzone-dragover` | Emitted on `dragover` event. The event is not emitted if `disabled` attribute is set. | - |
|
|
120
129
|
| `files-dropzone-dragleave` | Emitted on `dragleave` event. The event is not emitted if `disabled` attribute is set. | - |
|
|
121
|
-
| `files-dropzone-error` | Emitted if there is any error in the process of reading dropped files or directories. | `{error:
|
|
130
|
+
| `files-dropzone-error` | Emitted if there is any error in the process of reading dropped files or directories. | `{error: unknown, code: FilesDropzoneErrorCode}` |
|
|
122
131
|
|
|
123
132
|
## Usage example
|
|
124
133
|
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* @georapbox/files-dropzone-element
|
|
3
3
|
* A custom element that creates a drag and drop zone for files
|
|
4
4
|
*
|
|
5
|
-
* @version 2.
|
|
5
|
+
* @version 2.1.1
|
|
6
6
|
* @homepage https://github.com/georapbox/files-dropzone-element#readme
|
|
7
7
|
* @author George Raptis <georapbox@gmail.com>
|
|
8
8
|
* @license MIT
|
|
9
9
|
*/
|
|
10
|
-
function
|
|
10
|
+
function h(o,e=""){if(!e)return!0;let t=[...new Set(e.split(",").map(r=>r.trim()).filter(Boolean))],i=o.type,s=i.replace(/\/.*$/,"");for(let r of t)if(r.charAt(0)==="."){if(o.name.toLowerCase().indexOf(r.toLowerCase(),o.name.length-r.length)!==-1)return!0}else if(/\/\*$/.test(r)){if(s===r.replace(/\/.*$/,""))return!0}else if(i===r)return!0;return!1}var E=new Map([["aac","audio/aac"],["abw","application/x-abiword"],["arc","application/x-freearc"],["avif","image/avif"],["avi","video/x-msvideo"],["azw","application/vnd.amazon.ebook"],["bin","application/octet-stream"],["bmp","image/bmp"],["bz","application/x-bzip"],["bz2","application/x-bzip2"],["cda","application/x-cdf"],["csh","application/x-csh"],["css","text/css"],["csv","text/csv"],["doc","application/msword"],["docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],["eot","application/vnd.ms-fontobject"],["epub","application/epub+zip"],["gz","application/gzip"],["gif","image/gif"],["heic","image/heic"],["heif","image/heif"],["htm","text/html"],["html","text/html"],["ico","image/vnd.microsoft.icon"],["ics","text/calendar"],["jar","application/java-archive"],["jpeg","image/jpeg"],["jpg","image/jpeg"],["jxl","image/jxl"],["js","text/javascript"],["json","application/json"],["jsonld","application/ld+json"],["markdown","text/markdown"],["md","text/markdown"],["mid","audio/midi"],["midi","audio/midi"],["mjs","text/javascript"],["mp3","audio/mpeg"],["mp4","video/mp4"],["mpeg","video/mpeg"],["mpkg","application/vnd.apple.installer+xml"],["odp","application/vnd.oasis.opendocument.presentation"],["ods","application/vnd.oasis.opendocument.spreadsheet"],["odt","application/vnd.oasis.opendocument.text"],["oga","audio/ogg"],["ogv","video/ogg"],["ogx","application/ogg"],["opus","audio/opus"],["otf","font/otf"],["png","image/png"],["pdf","application/pdf"],["php","application/x-httpd-php"],["ppt","application/vnd.ms-powerpoint"],["pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation"],["rar","application/vnd.rar"],["rtf","application/rtf"],["sh","application/x-sh"],["svg","image/svg+xml"],["swf","application/x-shockwave-flash"],["tar","application/x-tar"],["tif","image/tiff"],["tiff","image/tiff"],["ts","video/mp2t"],["ttf","font/ttf"],["txt","text/plain"],["vsd","application/vnd.visio"],["wav","audio/wav"],["weba","audio/webm"],["webm","video/webm"],["webp","image/webp"],["woff","font/woff"],["woff2","font/woff2"],["xhtml","application/xhtml+xml"],["xls","application/vnd.ms-excel"],["xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],["xml","application/xml"],["xul","application/vnd.mozilla.xul+xml"],["zip","application/zip"],["7z","application/x-7z-compressed"],["mkv","video/x-matroska"],["mov","video/quicktime"],["msg","application/vnd.ms-outlook"]]),f=[".DS_Store","Thumbs.db"],z=o=>{let{name:e}=o;if(e&&e.lastIndexOf(".")!==-1&&!o.type){let i=(e.split(".").pop()||"").toLowerCase(),s=E.get(i);s&&Object.defineProperty(o,"type",{value:s,writable:!1,configurable:!1,enumerable:!0})}return o},g=(o,e)=>{let t=z(o);if(typeof t.path!="string"){let{webkitRelativePath:i}=o;Object.defineProperty(t,"path",{value:typeof e=="string"?e:i||o.name,writable:!1,configurable:!1,enumerable:!0})}return t},u=async o=>await new Promise((e,t)=>{o.readEntries(e,t)}),x=async o=>{let e=[],t=await u(o);for(;t.length>0;)e.push(...t),t=await u(o);return e},y=o=>new Promise((e,t)=>{o.file(i=>e(g(i,o.fullPath)),t)}),w=async o=>{let e=[],t=[];for(let i of o){if(i.kind!=="file")continue;let s=i.getAsEntry?i.getAsEntry():i.webkitGetAsEntry();t.push(s)}for(;t.length>0;){let i=t.shift();if(i)if(i.isFile){let s=await y(i);f.indexOf(s.name)===-1&&e.push(s)}else i.isDirectory&&t.push(...await x(i.createReader()));else continue}return e},m=async o=>{let e=[];for(let t of o)f.indexOf(t.name)===-1&&e.push(g(t));return e},d=async o=>o.dataTransfer?o.dataTransfer.items?await w(o.dataTransfer.items):await m(o.dataTransfer.files):await m(o.target.files);var O=String.raw,L=String.raw,b="files-dropzone",v=document.createElement("template"),F=O`
|
|
11
11
|
*,
|
|
12
12
|
*::before,
|
|
13
13
|
*::after {
|
|
@@ -32,7 +32,7 @@ function u(o,e=""){if(!e)return!0;let t=[...new Set(e.split(",").map(r=>r.trim()
|
|
|
32
32
|
--dropzone-body-color: #3f3f46;
|
|
33
33
|
--dropzone-body-color-dragover: var(--dropzone-body-color);
|
|
34
34
|
--dropzone-body-color-hover: var(--dropzone-body-color-dragover);
|
|
35
|
-
--dropzone-focus-shadow-rgb: 49,132,253;
|
|
35
|
+
--dropzone-focus-shadow-rgb: 49, 132, 253;
|
|
36
36
|
--dropzone-focus-box-shadow: 0 0 0 0.25rem rgba(var(--dropzone-focus-shadow-rgb), 0.5);
|
|
37
37
|
--transition-duration: 0.2s; /* for backwards compatibility */
|
|
38
38
|
--dropzone-transition-duration: var(--transition-duration);
|
|
@@ -49,7 +49,11 @@ function u(o,e=""){if(!e)return!0;let t=[...new Set(e.split(",").map(r=>r.trim()
|
|
|
49
49
|
color: var(--dropzone-body-color);
|
|
50
50
|
text-align: center;
|
|
51
51
|
cursor: pointer;
|
|
52
|
-
transition:
|
|
52
|
+
transition:
|
|
53
|
+
border var(--dropzone-transition-duration) ease-in-out,
|
|
54
|
+
background-color var(--dropzone-transition-duration) ease-in-out,
|
|
55
|
+
color var(--dropzone-transition-duration) ease-in-out,
|
|
56
|
+
box-shadow var(--dropzone-transition-duration) ease-in-out;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
:host(:not([no-style])[disabled]) .dropzone {
|
|
@@ -76,15 +80,15 @@ function u(o,e=""){if(!e)return!0;let t=[...new Set(e.split(",").map(r=>r.trim()
|
|
|
76
80
|
color: var(--dropzone-body-color-hover);
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
|
-
`;
|
|
83
|
+
`;v.innerHTML=L`
|
|
80
84
|
<style>
|
|
81
|
-
${
|
|
85
|
+
${F}
|
|
82
86
|
</style>
|
|
83
87
|
|
|
84
|
-
<input type="file" id="file-input" hidden
|
|
88
|
+
<input type="file" id="file-input" hidden />
|
|
85
89
|
|
|
86
90
|
<div part="dropzone" class="dropzone" id="dropzone" tabindex="0" role="button" aria-disabled="false">
|
|
87
|
-
<slot>Drag 'n' drop files here, or click to select files</slot>
|
|
91
|
+
<slot><span>Drag 'n' drop files here, or click to select files</span></slot>
|
|
88
92
|
</div>
|
|
89
|
-
`;var
|
|
93
|
+
`;var a=class o extends HTMLElement{static ERROR_CODES={FILE_DIALOG_OPEN_FAILED:"FILE_DIALOG_OPEN_FAILED",FILE_INPUT_CHANGE_FAILED:"FILE_INPUT_CHANGE_FAILED",DROP_EVENT_PROCESSING_FAILED:"DROP_EVENT_PROCESSING_FAILED",UNKNOWN_ERROR:"UNKNOWN_ERROR"};static REJECTION_CODES={TOO_MANY_FILES:"TOO_MANY_FILES",FILE_TOO_LARGE:"FILE_TOO_LARGE",FILE_TOO_SMALL:"FILE_TOO_SMALL",INVALID_MIME_TYPE:"INVALID_MIME_TYPE"};#t=null;#e=null;constructor(){super(),this.shadowRoot||this.attachShadow({mode:"open",delegatesFocus:!0}).appendChild(v.content.cloneNode(!0)),this.shadowRoot&&(this.#t=this.shadowRoot.getElementById("file-input"),this.#e=this.shadowRoot.getElementById("dropzone"))}static get observedAttributes(){return["accept","disabled","multiple"]}attributeChangedCallback(e,t,i){e==="accept"&&t!==i&&this.#t&&(this.#t.accept=this.accept),e==="disabled"&&t!==i&&this.#t&&(this.#t.disabled=this.disabled,this.disabled?(this.#e?.removeAttribute("tabindex"),this.#e?.setAttribute("aria-disabled","true")):(this.#e?.setAttribute("tabindex","0"),this.#e?.setAttribute("aria-disabled","false"))),e==="multiple"&&t!==i&&this.#t&&(this.#t.multiple=this.multiple)}connectedCallback(){this.#o("accept"),this.#o("disabled"),this.#o("maxFiles"),this.#o("maxSize"),this.#o("minSize"),this.#o("multiple"),this.#o("autoFocus"),this.#o("noStyle"),this.#t?.addEventListener("change",this.#s),this.#e?.addEventListener("dragenter",this.#n),this.#e?.addEventListener("dragover",this.#a),this.#e?.addEventListener("dragleave",this.#d),this.#e?.addEventListener("drop",this.#l),this.#e?.addEventListener("click",this.#c),this.#e?.addEventListener("keyup",this.#p),this.autoFocus&&this.#e?.focus()}disconnectedCallback(){this.#t?.removeEventListener("change",this.#s),this.#e?.removeEventListener("dragenter",this.#n),this.#e?.removeEventListener("dragover",this.#a),this.#e?.removeEventListener("dragleave",this.#d),this.#e?.removeEventListener("drop",this.#l),this.#e?.removeEventListener("click",this.#c),this.#e?.removeEventListener("keyup",this.#p)}get accept(){return this.getAttribute("accept")||""}set accept(e){this.setAttribute("accept",e!=null?e.toString():e)}get disabled(){return this.hasAttribute("disabled")}set disabled(e){this.toggleAttribute("disabled",!!e)}get maxFiles(){let e=Number(this.getAttribute("max-files"))||0;return e<=0?1/0:Math.floor(Math.abs(e))}set maxFiles(e){this.setAttribute("max-files",e!=null?e.toString():e)}get maxSize(){let e=this.getAttribute("max-size");if(e===null)return 1/0;let t=Number(e);return Number.isNaN(t)?1/0:t}set maxSize(e){this.setAttribute("max-size",e!=null?e.toString():e)}get minSize(){let e=this.getAttribute("min-size");if(e===null)return 0;let t=Number(e);return Number.isNaN(t)?0:t}set minSize(e){this.setAttribute("min-size",e!=null?e.toString():e)}get multiple(){return this.hasAttribute("multiple")}set multiple(e){this.toggleAttribute("multiple",!!e)}get autoFocus(){return this.hasAttribute("auto-focus")}set autoFocus(e){this.toggleAttribute("auto-focus",!!e)}get noStyle(){return this.hasAttribute("no-style")}set noStyle(e){this.toggleAttribute("no-style",!!e)}#i(e,t,i){let s={bubbles:!0,composed:!0,cancelable:!1,...i,detail:t},r=new CustomEvent(`${b}-${e}`,s);return this.dispatchEvent(r)}#r(e,t){let i={code:e,error:t};this.#i("error",i)}#s=async e=>{try{this.#h(await d(e))}catch(t){this.#r(o.ERROR_CODES.FILE_INPUT_CHANGE_FAILED,t)}};#n=()=>{this.disabled||this.#i("dragenter")};#a=e=>{if(e.preventDefault(),this.disabled){e.dataTransfer.dropEffect="none";return}e.dataTransfer.dropEffect="copy",this.#e&&(this.#e.classList.add("dropzone--dragover"),this.#e.part.add("dropzone--dragover")),this.#i("dragover")};#d=()=>{this.disabled||(this.#e&&(this.#e.classList.remove("dropzone--dragover"),this.#e.part.remove("dropzone--dragover")),this.#i("dragleave"))};#l=async e=>{if(!this.disabled){e.preventDefault(),this.#e&&(this.#e.classList.remove("dropzone--dragover"),this.#e.part.remove("dropzone--dragover"));try{this.#h(await d(e))}catch(t){this.#r(o.ERROR_CODES.DROP_EVENT_PROCESSING_FAILED,t)}}};#c=()=>{this.disabled||this.openFileDialog()};#p=e=>{this.disabled||(e.key===" "||e.key==="Enter")&&this.openFileDialog()};#h(e){if(!Array.isArray(e)||!e.length)return;let t=[],i=[],s=e.length;if(!this.multiple&&s>1)for(let r of e)i.push({file:r,errors:[{code:o.REJECTION_CODES.TOO_MANY_FILES,message:"Too many files selected. Only 1 file is allowed."}]});else if(this.multiple&&s>this.maxFiles)for(let r of e)i.push({file:r,errors:[{code:o.REJECTION_CODES.TOO_MANY_FILES,message:`Too many files selected. Only ${this.maxFiles} ${this.maxFiles>1?"files are":"file is"} allowed.`}]});else for(let r of e){let l=h(r,this.accept),c=r.size>this.maxSize,p=r.size<this.minSize;if(l&&!c&&!p)t.push(r);else{let n=[];l||n.push({code:o.REJECTION_CODES.INVALID_MIME_TYPE,message:`File type "${r.type}" is not accepted.`}),c&&n.push({code:o.REJECTION_CODES.FILE_TOO_LARGE,message:`File size ${r.size} exceeds the maximum size of ${this.maxSize}.`}),p&&n.push({code:o.REJECTION_CODES.FILE_TOO_SMALL,message:`File size ${r.size} is smaller than the minimum size of ${this.minSize}.`}),i.push({file:r,errors:n})}}this.#i("drop",{acceptedFiles:t,rejectedFiles:i}),t.length>0&&this.#i("drop-accepted",{acceptedFiles:t}),i.length>0&&this.#i("drop-rejected",{rejectedFiles:i}),this.#t&&(this.#t.value=this.#t.defaultValue)}openFileDialog(){if(!(this.disabled||!this.#t)){if("showPicker"in HTMLInputElement.prototype&&typeof this.#t.showPicker=="function"){try{this.#t.showPicker()}catch(e){this.#r(o.ERROR_CODES.FILE_DIALOG_OPEN_FAILED,e)}return}this.#t.click()}}#o(e){let t=this;if(Object.prototype.hasOwnProperty.call(t,e)){let i=t[e];delete t[e],t[e]=i}}static defineCustomElement(e=b){typeof window<"u"&&!window.customElements.get(e)&&window.customElements.define(e,o)}};a.defineCustomElement();export{a as FilesDropzone};
|
|
90
94
|
//# sourceMappingURL=files-dropzone-defined.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils/is-valid-file.js", "../src/utils/files-selector.js", "../src/files-dropzone.js", "../src/files-dropzone-defined.js"],
|
|
4
|
-
"sourcesContent": ["// @ts-check\n\n/**\n * Checks if a file is valid based on the accepted file type specifiers.\n *\n * @param {File} file - The File object to validate.\n * @param {string} [acceptedTypeSpecifiers=''] - The accepted file type specifiers.\n * @returns {boolean} - True if the file is valid, false otherwise.\n */\nexport function isValidFile(file, acceptedTypeSpecifiers = '') {\n if (!acceptedTypeSpecifiers) {\n return true;\n }\n\n const acceptedMimeTypesList = [\n ...new Set(\n acceptedTypeSpecifiers\n .split(',')\n .map(v => v.trim())\n .filter(Boolean)\n )\n ];\n\n const fileMimeType = file.type;\n const baseMimeType = fileMimeType.replace(/\\/.*$/, '');\n\n for (const validType of acceptedMimeTypesList) {\n if (validType.charAt(0) === '.') {\n if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) {\n return true;\n }\n } else if (/\\/\\*$/.test(validType)) {\n // Check for mime type that looks like \"image/*\" or similar.\n if (baseMimeType === validType.replace(/\\/.*$/, '')) {\n return true;\n }\n } else {\n if (fileMimeType === validType) {\n return true;\n }\n }\n }\n\n return false;\n}\n", "// @ts-check\n\n/**\n * A map of common file extensions and their associated MIME types.\n */\nconst COMMON_MIME_TYPES = new Map([\n // https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\n ['aac', 'audio/aac'],\n ['abw', 'application/x-abiword'],\n ['arc', 'application/x-freearc'],\n ['avif', 'image/avif'],\n ['avi', 'video/x-msvideo'],\n ['azw', 'application/vnd.amazon.ebook'],\n ['bin', 'application/octet-stream'],\n ['bmp', 'image/bmp'],\n ['bz', 'application/x-bzip'],\n ['bz2', 'application/x-bzip2'],\n ['cda', 'application/x-cdf'],\n ['csh', 'application/x-csh'],\n ['css', 'text/css'],\n ['csv', 'text/csv'],\n ['doc', 'application/msword'],\n ['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],\n ['eot', 'application/vnd.ms-fontobject'],\n ['epub', 'application/epub+zip'],\n ['gz', 'application/gzip'],\n ['gif', 'image/gif'],\n ['heic', 'image/heic'],\n ['heif', 'image/heif'],\n ['htm', 'text/html'],\n ['html', 'text/html'],\n ['ico', 'image/vnd.microsoft.icon'],\n ['ics', 'text/calendar'],\n ['jar', 'application/java-archive'],\n ['jpeg', 'image/jpeg'],\n ['jpg', 'image/jpeg'],\n ['jxl', 'image/jxl'],\n ['js', 'text/javascript'],\n ['json', 'application/json'],\n ['jsonld', 'application/ld+json'],\n ['markdown', 'text/markdown'],\n ['md', 'text/markdown'],\n ['mid', 'audio/midi'],\n ['midi', 'audio/midi'],\n ['mjs', 'text/javascript'],\n ['mp3', 'audio/mpeg'],\n ['mp4', 'video/mp4'],\n ['mpeg', 'video/mpeg'],\n ['mpkg', 'application/vnd.apple.installer+xml'],\n ['odp', 'application/vnd.oasis.opendocument.presentation'],\n ['ods', 'application/vnd.oasis.opendocument.spreadsheet'],\n ['odt', 'application/vnd.oasis.opendocument.text'],\n ['oga', 'audio/ogg'],\n ['ogv', 'video/ogg'],\n ['ogx', 'application/ogg'],\n ['opus', 'audio/opus'],\n ['otf', 'font/otf'],\n ['png', 'image/png'],\n ['pdf', 'application/pdf'],\n ['php', 'application/x-httpd-php'],\n ['ppt', 'application/vnd.ms-powerpoint'],\n ['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],\n ['rar', 'application/vnd.rar'],\n ['rtf', 'application/rtf'],\n ['sh', 'application/x-sh'],\n ['svg', 'image/svg+xml'],\n ['swf', 'application/x-shockwave-flash'],\n ['tar', 'application/x-tar'],\n ['tif', 'image/tiff'],\n ['tiff', 'image/tiff'],\n ['ts', 'video/mp2t'],\n ['ttf', 'font/ttf'],\n ['txt', 'text/plain'],\n ['vsd', 'application/vnd.visio'],\n ['wav', 'audio/wav'],\n ['weba', 'audio/webm'],\n ['webm', 'video/webm'],\n ['webp', 'image/webp'],\n ['woff', 'font/woff'],\n ['woff2', 'font/woff2'],\n ['xhtml', 'application/xhtml+xml'],\n ['xls', 'application/vnd.ms-excel'],\n ['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],\n ['xml', 'application/xml'],\n ['xul', 'application/vnd.mozilla.xul+xml'],\n ['zip', 'application/zip'],\n ['7z', 'application/x-7z-compressed'],\n\n // Others\n ['mkv', 'video/x-matroska'],\n ['mov', 'video/quicktime'],\n ['msg', 'application/vnd.ms-outlook']\n]);\n\nconst FILES_TO_IGNORE = [\n // Thumbnail cache files for macOS and Windows\n '.DS_Store', // macOs\n 'Thumbs.db' // Windows\n];\n\n/**\n * Adds a `type` property to the file object if it doesn't have one and the file has an extension.\n * This is needed because Firefox doesn't add a type property to files dragged from the desktop.\n * @bug https://bugzilla.mozilla.org/show_bug.cgi?id=1424689\n *\n * @param {File} file - The file object to add the type property to.\n * @returns {File} - The file object with the type property added.\n */\nconst toFileWithMimeType = file => {\n const { name } = file;\n const hasExtension = name && name.lastIndexOf('.') !== -1;\n\n if (hasExtension && !file.type) {\n const extension = (name.split('.').pop() || '').toLowerCase();\n const type = COMMON_MIME_TYPES.get(extension);\n\n if (type) {\n Object.defineProperty(file, 'type', {\n value: type,\n writable: false,\n configurable: false,\n enumerable: true\n });\n }\n }\n\n return file;\n};\n\n/**\n * Adds a `path` property to the file object if it doesn't have one.\n * If `path` is not provided, the `webkitRelativePath` property of the file will be used\n * or the file's name if `webkitRelativePath` is not available.\n *\n * @param {File} file - The file object to add the path property to.\n * @param {string} [path] - The path to set on the file object.\n * @returns {File} - The file object with the path property added.\n */\nconst toFileWithPath = (file, path) => {\n const fileWithMimeType = toFileWithMimeType(file);\n\n // @ts-ignore\n if (typeof fileWithMimeType.path !== 'string') {\n const { webkitRelativePath } = file;\n\n Object.defineProperty(fileWithMimeType, 'path', {\n value: typeof path === 'string' ? path : webkitRelativePath || file.name,\n writable: false,\n configurable: false,\n enumerable: true\n });\n }\n\n return fileWithMimeType;\n};\n\n/**\n * Wrap `FileSystemDirectoryReader.readEntries` in a promise to make working with read entries easier.\n * https://developer.mozilla.org/docs/Web/API/FileSystemDirectoryReader/readEntries\n *\n * @param {FileSystemDirectoryReader} directoryReader - The directory reader to read entries from.\n * @returns {Promise<FileSystemEntry[]>} - A promise that resolves with an array of `FileSystemEntry` objects.\n */\nconst readEntriesPromise = async directoryReader => {\n return await new Promise((resolve, reject) => {\n directoryReader.readEntries(resolve, reject);\n });\n};\n\n/**\n * Read all entries in a directory or sub-directory\n * by calling `readEntries` until it returns an empty array.\n *\n * @param {FileSystemDirectoryReader} directoryReader - The directory reader to read entries from.\n * @returns {Promise<FileSystemEntry[]>} - A promise that resolves with an array of `FileSystemEntry` objects.\n */\nconst readAllDirectoryEntries = async directoryReader => {\n const entries = [];\n let readEntries = await readEntriesPromise(directoryReader);\n\n while (readEntries.length > 0) {\n entries.push(...readEntries);\n readEntries = await readEntriesPromise(directoryReader);\n }\n\n return entries;\n};\n\n/**\n * Get a `File` object from a `FileSystemFileEntry` object.\n *\n * @param {FileSystemFileEntry} fileEntry - The file entry to get a `File` object from.\n * @returns {Promise<File>} - A promise that resolves with a `File` object.\n */\nconst getFileFromFileEntry = fileEntry => {\n return new Promise((resolve, reject) => {\n fileEntry.file(file => resolve(toFileWithPath(file, fileEntry.fullPath)), reject);\n });\n};\n\n/**\n * Get an array of `File` objects from a `DataTransferItemList` object.\n *\n * @param {DataTransferItemList} dataTransferItemList - The item list to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nconst getFilesFromDataTransferItemList = async dataTransferItemList => {\n const files = [];\n\n // Chromium browsers read only 100 files at a time as per the spec, so we need to use\n // BFS (Breadth-first search) to traverse the entire directory/file structure.\n // https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#javascript_content\n const queue = [];\n\n for (const item of dataTransferItemList) {\n if (item.kind !== 'file') {\n // Ignore non-file items, such as links.\n continue;\n }\n\n // https://developer.mozilla.org/docs/Web/API/DataTransferItem/webkitGetAsEntry\n // This function is implemented as `webkitGetAsEntry()` in non-WebKit browsers\n // including Firefox at this time but it may be renamed to `getAsEntry()` in the future.\n // @ts-ignore\n const entry = item.getAsEntry ? item.getAsEntry() : item.webkitGetAsEntry();\n\n queue.push(entry);\n }\n\n while (queue.length > 0) {\n const entry = queue.shift();\n\n if (!entry) {\n continue;\n } else if (entry.isFile) {\n const file = await getFileFromFileEntry(entry);\n\n if (FILES_TO_IGNORE.indexOf(file.name) === -1) {\n files.push(file);\n }\n } else if (entry.isDirectory) {\n queue.push(...(await readAllDirectoryEntries(entry.createReader())));\n }\n }\n\n return files;\n};\n\n/**\n * Get an array of `File` objects from a `FileList` object.\n *\n * @param {FileList} fileList - The file list to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nconst getFilesFromFileList = async fileList => {\n const files = [];\n\n for (const file of fileList) {\n if (FILES_TO_IGNORE.indexOf(file.name) === -1) {\n files.push(toFileWithPath(file));\n }\n }\n\n return files;\n};\n\n/**\n * Get an array of `File` objects from an event.\n * This function supports both `drop` and `change` events.\n *\n * @param {*} evt - The event to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nexport const getFilesFromEvent = async evt => {\n if (evt.dataTransfer) {\n return evt.dataTransfer.items\n ? await getFilesFromDataTransferItemList(evt.dataTransfer.items)\n : await getFilesFromFileList(evt.dataTransfer.files);\n }\n\n return await getFilesFromFileList(evt.target.files);\n};\n", "// @ts-check\n\n/**\n * Represents a value that may be of type T, or null.\n *\n * @template T\n * @typedef {T | null} Nullable\n */\n\nimport { isValidFile } from './utils/is-valid-file.js';\nimport { getFilesFromEvent } from './utils/files-selector.js';\n\nconst COMPONENT_NAME = 'files-dropzone';\nconst TOO_MANY_FILES = 'TOO_MANY_FILES';\nconst FILE_TOO_LARGE = 'FILE_TOO_LARGE';\nconst FILE_TOO_SMALL = 'FILE_TOO_SMALL';\nconst INVALID_MIME_TYPE = 'INVALID_MIME_TYPE';\nconst template = document.createElement('template');\n\nconst styles = /* css */ `\n *,\n *::before,\n *::after {\n box-sizing: border-box;\n }\n\n :host([hidden]),\n [hidden] {\n display: none !important;\n }\n\n :host {\n --dropzone-border-width: 2px;\n --dropzone-border-style: dashed;\n --dropzone-border-radius: 0.25rem;\n --dropzone-border-color: #6c757d;\n --dropzone-border-color-dragover: #0d6efd;\n --dropzone-border-color-hover: var(--dropzone-border-color-dragover);\n --dropzone-background-color: #ffffff;\n --dropzone-background-color-dragover: #f4f4f5;\n --dropzone-background-color-hover: var(--dropzone-background-color-dragover);\n --dropzone-body-color: #3f3f46;\n --dropzone-body-color-dragover: var(--dropzone-body-color);\n --dropzone-body-color-hover: var(--dropzone-body-color-dragover);\n --dropzone-focus-shadow-rgb: 49,132,253;\n --dropzone-focus-box-shadow: 0 0 0 0.25rem rgba(var(--dropzone-focus-shadow-rgb), 0.5);\n --transition-duration: 0.2s; /* for backwards compatibility */\n --dropzone-transition-duration: var(--transition-duration);\n\n display: block;\n }\n\n :host(:not([no-style])) .dropzone {\n border: var(--dropzone-border-width) var(--dropzone-border-style) var(--dropzone-border-color);\n border-radius: var(--dropzone-border-radius);\n padding: 3rem 1rem;\n overflow: hidden;\n background-color: var(--dropzone-background-color);\n color: var(--dropzone-body-color);\n text-align: center;\n cursor: pointer;\n transition: border var(--dropzone-transition-duration) ease-in-out, background-color var(--dropzone-transition-duration) ease-in-out, color var(--dropzone-transition-duration) ease-in-out, box-shadow var(--dropzone-transition-duration) ease-in-out;\n }\n\n :host(:not([no-style])[disabled]) .dropzone {\n opacity: 0.8;\n cursor: not-allowed;\n user-select: none;\n }\n\n :host(:not([no-style]):not([disabled])) .dropzone--dragover {\n border-color: var(--dropzone-border-color-dragover);\n background-color: var(--dropzone-background-color-dragover);\n color: var(--dropzone-body-color-dragover);\n }\n\n :host(:not([no-style]):not([disabled])) .dropzone:focus-visible {\n outline: none;\n box-shadow: var(--dropzone-focus-box-shadow);\n }\n\n @media (hover: hover) {\n :host(:not([no-style]):not([disabled])) .dropzone:not(.dropzone--dragover):hover {\n border-color: var(--dropzone-border-color-hover);\n background-color: var(--dropzone-background-color-hover);\n color: var(--dropzone-body-color-hover);\n }\n }\n`;\n\ntemplate.innerHTML = /* html */ `\n <style>\n ${styles}\n </style>\n\n <input type=\"file\" id=\"file-input\" hidden>\n\n <div part=\"dropzone\" class=\"dropzone\" id=\"dropzone\" tabindex=\"0\" role=\"button\" aria-disabled=\"false\">\n <slot>Drag 'n' drop files here, or click to select files</slot>\n </div>\n`;\n\n/**\n * @summary A custom element that allows users to drag and drop files into it.\n * @documentation https://github.com/georapbox/files-dropzone-element\n *\n * @tagname files-dropzone - This is the default tag name, unless overridden by the `defineCustomElement` method.\n *\n * @property {string} accept - A comma-separated list of unique file type specifiers describing file types to allow.\n * @property {boolean} disabled - Determines whether the dropzone is disabled.\n * @property {number} maxFiles - The maximum number of files allowed to be dropped.\n * @property {number} maxSize - The maximum file size allowed in bytes.\n * @property {number} minSize - The minimum file size allowed in bytes.\n * @property {boolean} multiple - Allows multiple files to be dropped.\n * @property {boolean} autoFocus - Automatically focuses the dropzone when it's connected to the DOM.\n * @property {boolean} noStyle - Prevents the dropzone from applying any styling.\n *\n * @attribute {string} accept - Reflects the accept property.\n * @attribute {boolean} disabled - Reflects the disabled property.\n * @attribute {number} max-files - Reflects the maxFiles property.\n * @attribute {number} max-size - Reflects the maxSize property.\n * @attribute {number} min-size - Reflects the minSize property.\n * @attribute {boolean} multiple - Reflects the multiple property.\n * @attribute {boolean} auto-focus - Reflects the autoFocus property.\n * @attribute {boolean} no-style - Reflects the noStyle property.\n *\n * @slot - The default slot content of the dropzone.\n *\n * @csspart dropzone - The dropzone element.\n * @csspart dropzone--dragover - The state of the dropzone when dragging over it.\n *\n * @cssproperty --dropzone-border-width - The border width of the dropzone.\n * @cssproperty --dropzone-border-style - The border style of the dropzone.\n * @cssproperty --dropzone-border-radius - The border radius of the dropzone.\n * @cssproperty --dropzone-border-color - The border color of the dropzone.\n * @cssproperty --dropzone-border-color-dragover - The border color of the dropzone when dragging over it.\n * @cssproperty --dropzone-border-color-hover - The border color of the dropzone when hovering over it.\n * @cssproperty --dropzone-background-color - The background color of the dropzone.\n * @cssproperty --dropzone-background-color-dragover - The background color of the dropzone when dragging over it.\n * @cssproperty --dropzone-background-color-hover - The background color of the dropzone when hovering over it.\n * @cssproperty --dropzone-body-color - The text color of the dropzone.\n * @cssproperty --dropzone-body-color-dragover - The text color of the dropzone when dragging over it.\n * @cssproperty --dropzone-body-color-hover - The text color of the dropzone when hovering over it.\n * @cssproperty --dropzone-focus-shadow-rgb - The RGB value of the dropzone's focus shadow.\n * @cssproperty --dropzone-focus-box-shadow - The box shadow of the dropzone when focused.\n * @cssproperty --dropzone-transition-duration - The transition's duration for the dropzone area.\n *\n * @event files-dropzone-drop - Fired when files are dropped.\n * @event files-dropzone-drop-accepted - Fired when files dropped files are accepted.\n * @event files-dropzone-drop-rejected - Fired when files dropped files are rejected.\n * @event files-dropzone-dragenter - Fired when files are dragged into the dropzone.\n * @event files-dropzone-dragover - Fired when files are dragged over the dropzone.\n * @event files-dropzone-dragleave - Fired when files are dragged out of the dropzone.\n * @event files-dropzone-error - Fired when there is any error in the process of reading dropped files or directories.\n *\n * @method defineCustomElement - Static method. Defines a custom element with the given name.\n * @method openFileDialog - Instance method. Opens the file dialog programmatically.\n */\nclass FilesDropzone extends HTMLElement {\n /** @type {Nullable<HTMLInputElement>} */\n #fileInput = null;\n\n /** @type {Nullable<HTMLElement>} */\n #dropzoneEl = null;\n\n constructor() {\n super();\n\n if (!this.shadowRoot) {\n const shadowRoot = this.attachShadow({ mode: 'open', delegatesFocus: true });\n shadowRoot.appendChild(template.content.cloneNode(true));\n }\n\n if (this.shadowRoot) {\n this.#fileInput = /** @type {Nullable<HTMLInputElement>} */ (this.shadowRoot.getElementById('file-input'));\n this.#dropzoneEl = this.shadowRoot.getElementById('dropzone');\n }\n }\n\n static get observedAttributes() {\n return ['accept', 'disabled', 'multiple'];\n }\n\n /**\n * Lifecycle method that is called when attributes are changed, added, removed, or replaced.\n *\n * @param {string} name - The name of the attribute.\n * @param {string} oldValue - The old value of the attribute.\n * @param {string} newValue - The new value of the attribute.\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (name === 'accept' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.accept = this.accept;\n }\n\n if (name === 'disabled' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.disabled = this.disabled;\n\n if (this.disabled) {\n this.#dropzoneEl?.removeAttribute('tabindex');\n this.#dropzoneEl?.setAttribute('aria-disabled', 'true');\n } else {\n this.#dropzoneEl?.setAttribute('tabindex', '0');\n this.#dropzoneEl?.setAttribute('aria-disabled', 'false');\n }\n }\n\n if (name === 'multiple' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.multiple = this.multiple;\n }\n }\n\n /**\n * Lifecycle method that is called when the element is added to the DOM.\n */\n connectedCallback() {\n this.#upgradeProperty('accept');\n this.#upgradeProperty('disabled');\n this.#upgradeProperty('maxFiles');\n this.#upgradeProperty('maxSize');\n this.#upgradeProperty('minSize');\n this.#upgradeProperty('multiple');\n this.#upgradeProperty('autoFocus');\n this.#upgradeProperty('noStyle');\n\n this.#fileInput?.addEventListener('change', this.#handleFileInputChange);\n this.#dropzoneEl?.addEventListener('dragenter', this.#handleDragEnter);\n this.#dropzoneEl?.addEventListener('dragover', this.#handleDragOver);\n this.#dropzoneEl?.addEventListener('dragleave', this.#handleDragLeave);\n this.#dropzoneEl?.addEventListener('drop', this.#handleDrop);\n this.#dropzoneEl?.addEventListener('click', this.#handleClick);\n this.#dropzoneEl?.addEventListener('keyup', this.#handleKeyUp);\n\n this.autoFocus && this.#dropzoneEl?.focus();\n }\n\n /**\n * Lifecycle method that is called when the element is removed from the DOM.\n */\n disconnectedCallback() {\n this.#fileInput?.removeEventListener('change', this.#handleFileInputChange);\n this.#dropzoneEl?.removeEventListener('dragenter', this.#handleDragEnter);\n this.#dropzoneEl?.removeEventListener('dragover', this.#handleDragOver);\n this.#dropzoneEl?.removeEventListener('dragleave', this.#handleDragLeave);\n this.#dropzoneEl?.removeEventListener('drop', this.#handleDrop);\n this.#dropzoneEl?.removeEventListener('click', this.#handleClick);\n this.#dropzoneEl?.removeEventListener('keyup', this.#handleKeyUp);\n }\n\n /**\n * @type {string} - A comma-separated list of unique file type specifiers describing file types to allow.\n * @attribute accept - Reflects the accept property.\n */\n get accept() {\n return this.getAttribute('accept') || '';\n }\n\n set accept(value) {\n this.setAttribute('accept', value != null ? value.toString() : value);\n }\n\n /**\n * @type {boolean} - Determines whether the dropzone is disabled.\n * @default false\n * @attribute disabled - Reflects the disabled property.\n */\n get disabled() {\n return this.hasAttribute('disabled');\n }\n\n set disabled(value) {\n this.toggleAttribute('disabled', !!value);\n }\n\n /**\n * @type {number} - The maximum number of files allowed to be dropped.\n * @default Infinity\n * @attribute max-files - Reflects the maxFiles property.\n */\n get maxFiles() {\n const num = Number(this.getAttribute('max-files')) || 0;\n\n if (num <= 0) {\n return Infinity;\n }\n\n return Math.floor(Math.abs(num));\n }\n\n set maxFiles(value) {\n this.setAttribute('max-files', value != null ? value.toString() : value);\n }\n\n /**\n * @type {number} - The maximum file size allowed in bytes.\n * @default Infinity\n * @attribute max-size - Reflects the maxSize property.\n */\n get maxSize() {\n const value = this.getAttribute('max-size');\n\n if (value === null) {\n return Infinity;\n }\n\n const num = Number(value);\n\n return Number.isNaN(num) ? Infinity : num;\n }\n\n set maxSize(value) {\n this.setAttribute('max-size', value != null ? value.toString() : value);\n }\n\n /**\n * @type {number} - The minimum file size allowed in bytes.\n * @default 0\n * @attribute min-size - Reflects the minSize property.\n */\n get minSize() {\n const value = this.getAttribute('min-size');\n\n if (value === null) {\n return 0;\n }\n\n const num = Number(value);\n\n return Number.isNaN(num) ? 0 : num;\n }\n\n set minSize(value) {\n this.setAttribute('min-size', value != null ? value.toString() : value);\n }\n\n /**\n * @type {boolean} - Allows multiple files to be dropped.\n * @default false\n * @attribute multiple - Reflects the multiple property.\n */\n get multiple() {\n return this.hasAttribute('multiple');\n }\n\n set multiple(value) {\n this.toggleAttribute('multiple', !!value);\n }\n\n /**\n * @type {boolean} - Automatically focuses the dropzone when it's connected to the DOM.\n * @default false\n * @attribute auto-focus - Reflects the autoFocus property.\n */\n get autoFocus() {\n return this.hasAttribute('auto-focus');\n }\n\n set autoFocus(value) {\n this.toggleAttribute('auto-focus', !!value);\n }\n\n /**\n * @type {boolean} - Prevents the dropzone from applying any styling.\n * @default false\n * @attribute no-style - Reflects the noStyle property.\n */\n get noStyle() {\n return this.hasAttribute('no-style');\n }\n\n set noStyle(value) {\n this.toggleAttribute('no-style', !!value);\n }\n\n /**\n * Handles the change event of the file input.\n *\n * @param {*} evt - The event object.\n */\n #handleFileInputChange = async evt => {\n try {\n this.#handleFilesSelect(await getFilesFromEvent(evt));\n } catch (error) {\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-error`, {\n bubbles: true,\n composed: true,\n detail: { error }\n })\n );\n }\n };\n\n /**\n * Handles the dragenter event of the dropzone.\n */\n #handleDragEnter = () => {\n if (this.disabled) {\n return;\n }\n\n this.dispatchEvent(\n new Event(`${COMPONENT_NAME}-dragenter`, {\n bubbles: true,\n composed: true\n })\n );\n };\n\n /**\n * Handles the dragover event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleDragOver = evt => {\n evt.preventDefault();\n\n if (this.disabled) {\n evt.dataTransfer.dropEffect = 'none';\n return;\n }\n\n evt.dataTransfer.dropEffect = 'copy';\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.add('dropzone--dragover');\n this.#dropzoneEl.part.add('dropzone--dragover');\n }\n\n this.dispatchEvent(\n new Event(`${COMPONENT_NAME}-dragover`, {\n bubbles: true,\n composed: true\n })\n );\n };\n\n /**\n * Handles the dragleave event of the dropzone.\n */\n #handleDragLeave = () => {\n if (this.disabled) {\n return;\n }\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.remove('dropzone--dragover');\n this.#dropzoneEl.part.remove('dropzone--dragover');\n }\n\n this.dispatchEvent(\n new Event(`${COMPONENT_NAME}-dragleave`, {\n bubbles: true,\n composed: true\n })\n );\n };\n\n /**\n * Handles the drop event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleDrop = async evt => {\n if (this.disabled) {\n return;\n }\n\n evt.preventDefault();\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.remove('dropzone--dragover');\n this.#dropzoneEl.part.remove('dropzone--dragover');\n }\n\n try {\n this.#handleFilesSelect(await getFilesFromEvent(evt));\n } catch (error) {\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-error`, {\n bubbles: true,\n composed: true,\n detail: { error }\n })\n );\n }\n };\n\n /**\n * Handles the click event of the dropzone.\n */\n #handleClick = () => {\n if (this.disabled) {\n return;\n }\n\n this.#fileInput?.click();\n };\n\n /**\n * Handles the keyup event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleKeyUp = evt => {\n if (this.disabled) {\n return;\n }\n\n if (evt.key === ' ' || evt.key === 'Enter') {\n this.#fileInput?.click();\n }\n };\n\n /**\n * Handles the selection of files.\n *\n * @param {File[]} files - The files to handle.\n */\n #handleFilesSelect(files) {\n if (!Array.isArray(files) || !files.length) {\n return;\n }\n\n const acceptedFiles = [];\n const rejectedFiles = [];\n const filesLength = files.length;\n\n // If the component is not in multiple mode, reject all files.\n if (!this.multiple && filesLength > 1) {\n for (const file of files) {\n rejectedFiles.push({\n file,\n errors: [\n {\n code: TOO_MANY_FILES,\n message: `Too many files selected. Only 1 file is allowed.`\n }\n ]\n });\n }\n } else if (this.multiple && filesLength > this.maxFiles) {\n // If the component is in multiple mode, but the number of files exceeds\n // the maxFiles attribute, reject all files.\n for (const file of files) {\n rejectedFiles.push({\n file,\n errors: [\n {\n code: TOO_MANY_FILES,\n message: `Too many files selected. Only ${this.maxFiles} ${this.maxFiles > 1 ? 'files are' : 'file is'} allowed.`\n }\n ]\n });\n }\n } else {\n // Validate each file. If it's valid, add it to the accepted files array,\n // otherwise add it to the rejected files array.\n for (const file of files) {\n const fileHasValidType = isValidFile(file, this.accept);\n const fileExceedsMaxSize = file.size > this.maxSize;\n const fileIsSmallerThanMinSize = file.size < this.minSize;\n\n if (fileHasValidType && !fileExceedsMaxSize && !fileIsSmallerThanMinSize) {\n acceptedFiles.push(file);\n } else {\n const errors = [];\n\n if (!fileHasValidType) {\n errors.push({\n code: INVALID_MIME_TYPE,\n message: `File type \"${file.type}\" is not accepted.`\n });\n }\n\n if (fileExceedsMaxSize) {\n errors.push({\n code: FILE_TOO_LARGE,\n message: `File size ${file.size} exceeds the maximum size of ${this.maxSize}.`\n });\n }\n\n if (fileIsSmallerThanMinSize) {\n errors.push({\n code: FILE_TOO_SMALL,\n message: `File size ${file.size} is smaller than the minimum size of ${this.minSize}.`\n });\n }\n\n rejectedFiles.push({ file, errors });\n }\n }\n }\n\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-drop`, {\n bubbles: true,\n composed: true,\n detail: {\n acceptedFiles,\n rejectedFiles\n }\n })\n );\n\n if (acceptedFiles.length > 0) {\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-drop-accepted`, {\n bubbles: true,\n composed: true,\n detail: {\n acceptedFiles\n }\n })\n );\n }\n\n if (rejectedFiles.length > 0) {\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-drop-rejected`, {\n bubbles: true,\n composed: true,\n detail: {\n rejectedFiles\n }\n })\n );\n }\n\n if (this.#fileInput) {\n this.#fileInput.value = this.#fileInput.defaultValue;\n }\n }\n\n /**\n * Opens the file dialog programmatically.\n */\n openFileDialog() {\n if (this.disabled) {\n return;\n }\n\n this.#fileInput?.click();\n }\n\n /**\n * This is to safe guard against cases where, for instance, a framework may have added the element to the page and set a\n * value on one of its properties, but lazy loaded its definition. Without this guard, the upgraded element would miss that\n * property and the instance property would prevent the class property setter from ever being called.\n *\n * https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties\n *\n * @param {'accept' | 'disabled' | 'maxFiles' | 'maxSize' | 'minSize' | 'multiple' | 'autoFocus' | 'noStyle'} prop - The property name to upgrade.\n */\n #upgradeProperty(prop) {\n /** @type {any} */\n const instance = this;\n\n if (Object.prototype.hasOwnProperty.call(instance, prop)) {\n const value = instance[prop];\n delete instance[prop];\n instance[prop] = value;\n }\n }\n\n /**\n * Defines a custom element with the given name.\n * The name must contain a dash (-).\n *\n * @param {string} [elementName='files-dropzone'] - The name of the custom element.\n * @example\n *\n * FilesDropzone.defineCustomElement('my-dropzone');\n */\n static defineCustomElement(elementName = COMPONENT_NAME) {\n if (typeof window !== 'undefined' && !window.customElements.get(elementName)) {\n window.customElements.define(elementName, FilesDropzone);\n }\n }\n}\n\nexport { FilesDropzone };\n", "import { FilesDropzone } from './files-dropzone.js';\n\nFilesDropzone.defineCustomElement();\n\nexport { FilesDropzone };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AASO,SAASA,EAAYC,EAAMC,EAAyB,GAAI,CAC7D,GAAI,CAAC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B,EAAK,IAAI,wCAAwC,KAAK,OAAO,GACrF,CAAC,EAGHF,EAAc,KAAK,CAAE,KAAAE,EAAM,OAAAK,CAAO,CAAC,CACrC,CACF,CAGF,KAAK,cACH,IAAI,YAAY,GAAGrC,CAAc,QAAS,CACxC,QAAS,GACT,SAAU,GACV,OAAQ,CACN,cAAA6B,EACA,cAAAC,CACF,CACF,CAAC,CACH,EAEID,EAAc,OAAS,GACzB,KAAK,cACH,IAAI,YAAY,GAAG7B,CAAc,iBAAkB,CACjD,QAAS,GACT,SAAU,GACV,OAAQ,CACN,cAAA6B,CACF,CACF,CAAC,CACH,EAGEC,EAAc,OAAS,GACzB,KAAK,cACH,IAAI,YAAY,GAAG9B,CAAc,iBAAkB,CACjD,QAAS,GACT,SAAU,GACV,OAAQ,CACN,cAAA8B,CACF,CACF,CAAC,CACH,EAGE,KAAKrB,KACP,KAAKA,GAAW,MAAQ,KAAKA,GAAW,aAE5C,CAKA,gBAAiB,CACX,KAAK,UAIT,KAAKA,IAAY,MAAM,CACzB,CAWAK,GAAiBwB,EAAM,CAErB,IAAMC,EAAW,KAEjB,GAAI,OAAO,UAAU,eAAe,KAAKA,EAAUD,CAAI,EAAG,CACxD,IAAMhB,EAAQiB,EAASD,CAAI,EAC3B,OAAOC,EAASD,CAAI,EACpBC,EAASD,CAAI,EAAIhB,CACnB,CACF,CAWA,OAAO,oBAAoBkB,EAAcxC,EAAgB,CACnD,OAAO,OAAW,KAAe,CAAC,OAAO,eAAe,IAAIwC,CAAW,GACzE,OAAO,eAAe,OAAOA,EAAahC,CAAa,CAE3D,CACF,ECrqBAiC,EAAc,oBAAoB",
|
|
6
|
-
"names": ["isValidFile", "file", "acceptedTypeSpecifiers", "acceptedMimeTypesList", "v", "fileMimeType", "baseMimeType", "validType", "COMMON_MIME_TYPES", "FILES_TO_IGNORE", "toFileWithMimeType", "file", "name", "extension", "type", "toFileWithPath", "path", "fileWithMimeType", "webkitRelativePath", "readEntriesPromise", "directoryReader", "resolve", "reject", "readAllDirectoryEntries", "entries", "readEntries", "getFileFromFileEntry", "fileEntry", "getFilesFromDataTransferItemList", "dataTransferItemList", "files", "queue", "item", "entry", "getFilesFromFileList", "fileList", "getFilesFromEvent", "evt", "
|
|
4
|
+
"sourcesContent": ["// @ts-check\n\n/**\n * Checks if a file is valid based on the accepted file type specifiers.\n *\n * @param {File} file - The File object to validate.\n * @param {string} [acceptedTypeSpecifiers=''] - The accepted file type specifiers.\n * @returns {boolean} - True if the file is valid, false otherwise.\n */\nexport function isValidFile(file, acceptedTypeSpecifiers = '') {\n if (!acceptedTypeSpecifiers) {\n return true;\n }\n\n const acceptedMimeTypesList = [\n ...new Set(\n acceptedTypeSpecifiers\n .split(',')\n .map(v => v.trim())\n .filter(Boolean)\n )\n ];\n\n const fileMimeType = file.type;\n const baseMimeType = fileMimeType.replace(/\\/.*$/, '');\n\n for (const validType of acceptedMimeTypesList) {\n if (validType.charAt(0) === '.') {\n if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) {\n return true;\n }\n } else if (/\\/\\*$/.test(validType)) {\n // Check for mime type that looks like \"image/*\" or similar.\n if (baseMimeType === validType.replace(/\\/.*$/, '')) {\n return true;\n }\n } else {\n if (fileMimeType === validType) {\n return true;\n }\n }\n }\n\n return false;\n}\n", "// @ts-check\n\n/**\n * A map of common file extensions and their associated MIME types.\n */\nconst COMMON_MIME_TYPES = new Map([\n // https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\n ['aac', 'audio/aac'],\n ['abw', 'application/x-abiword'],\n ['arc', 'application/x-freearc'],\n ['avif', 'image/avif'],\n ['avi', 'video/x-msvideo'],\n ['azw', 'application/vnd.amazon.ebook'],\n ['bin', 'application/octet-stream'],\n ['bmp', 'image/bmp'],\n ['bz', 'application/x-bzip'],\n ['bz2', 'application/x-bzip2'],\n ['cda', 'application/x-cdf'],\n ['csh', 'application/x-csh'],\n ['css', 'text/css'],\n ['csv', 'text/csv'],\n ['doc', 'application/msword'],\n ['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],\n ['eot', 'application/vnd.ms-fontobject'],\n ['epub', 'application/epub+zip'],\n ['gz', 'application/gzip'],\n ['gif', 'image/gif'],\n ['heic', 'image/heic'],\n ['heif', 'image/heif'],\n ['htm', 'text/html'],\n ['html', 'text/html'],\n ['ico', 'image/vnd.microsoft.icon'],\n ['ics', 'text/calendar'],\n ['jar', 'application/java-archive'],\n ['jpeg', 'image/jpeg'],\n ['jpg', 'image/jpeg'],\n ['jxl', 'image/jxl'],\n ['js', 'text/javascript'],\n ['json', 'application/json'],\n ['jsonld', 'application/ld+json'],\n ['markdown', 'text/markdown'],\n ['md', 'text/markdown'],\n ['mid', 'audio/midi'],\n ['midi', 'audio/midi'],\n ['mjs', 'text/javascript'],\n ['mp3', 'audio/mpeg'],\n ['mp4', 'video/mp4'],\n ['mpeg', 'video/mpeg'],\n ['mpkg', 'application/vnd.apple.installer+xml'],\n ['odp', 'application/vnd.oasis.opendocument.presentation'],\n ['ods', 'application/vnd.oasis.opendocument.spreadsheet'],\n ['odt', 'application/vnd.oasis.opendocument.text'],\n ['oga', 'audio/ogg'],\n ['ogv', 'video/ogg'],\n ['ogx', 'application/ogg'],\n ['opus', 'audio/opus'],\n ['otf', 'font/otf'],\n ['png', 'image/png'],\n ['pdf', 'application/pdf'],\n ['php', 'application/x-httpd-php'],\n ['ppt', 'application/vnd.ms-powerpoint'],\n ['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],\n ['rar', 'application/vnd.rar'],\n ['rtf', 'application/rtf'],\n ['sh', 'application/x-sh'],\n ['svg', 'image/svg+xml'],\n ['swf', 'application/x-shockwave-flash'],\n ['tar', 'application/x-tar'],\n ['tif', 'image/tiff'],\n ['tiff', 'image/tiff'],\n ['ts', 'video/mp2t'],\n ['ttf', 'font/ttf'],\n ['txt', 'text/plain'],\n ['vsd', 'application/vnd.visio'],\n ['wav', 'audio/wav'],\n ['weba', 'audio/webm'],\n ['webm', 'video/webm'],\n ['webp', 'image/webp'],\n ['woff', 'font/woff'],\n ['woff2', 'font/woff2'],\n ['xhtml', 'application/xhtml+xml'],\n ['xls', 'application/vnd.ms-excel'],\n ['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],\n ['xml', 'application/xml'],\n ['xul', 'application/vnd.mozilla.xul+xml'],\n ['zip', 'application/zip'],\n ['7z', 'application/x-7z-compressed'],\n\n // Others\n ['mkv', 'video/x-matroska'],\n ['mov', 'video/quicktime'],\n ['msg', 'application/vnd.ms-outlook']\n]);\n\nconst FILES_TO_IGNORE = [\n // Thumbnail cache files for macOS and Windows\n '.DS_Store', // macOs\n 'Thumbs.db' // Windows\n];\n\n/**\n * Adds a `type` property to the file object if it doesn't have one and the file has an extension.\n * This is needed because Firefox doesn't add a type property to files dragged from the desktop.\n * @bug https://bugzilla.mozilla.org/show_bug.cgi?id=1424689\n *\n * @param {File} file - The file object to add the type property to.\n * @returns {File} - The file object with the type property added.\n */\nconst toFileWithMimeType = file => {\n const { name } = file;\n const hasExtension = name && name.lastIndexOf('.') !== -1;\n\n if (hasExtension && !file.type) {\n const extension = (name.split('.').pop() || '').toLowerCase();\n const type = COMMON_MIME_TYPES.get(extension);\n\n if (type) {\n Object.defineProperty(file, 'type', {\n value: type,\n writable: false,\n configurable: false,\n enumerable: true\n });\n }\n }\n\n return file;\n};\n\n/**\n * Adds a `path` property to the file object if it doesn't have one.\n * If `path` is not provided, the `webkitRelativePath` property of the file will be used\n * or the file's name if `webkitRelativePath` is not available.\n *\n * @param {File} file - The file object to add the path property to.\n * @param {string} [path] - The path to set on the file object.\n * @returns {File} - The file object with the path property added.\n */\nconst toFileWithPath = (file, path) => {\n const fileWithMimeType = toFileWithMimeType(file);\n\n // @ts-ignore\n if (typeof fileWithMimeType.path !== 'string') {\n const { webkitRelativePath } = file;\n\n Object.defineProperty(fileWithMimeType, 'path', {\n value: typeof path === 'string' ? path : webkitRelativePath || file.name,\n writable: false,\n configurable: false,\n enumerable: true\n });\n }\n\n return fileWithMimeType;\n};\n\n/**\n * Wrap `FileSystemDirectoryReader.readEntries` in a promise to make working with read entries easier.\n * https://developer.mozilla.org/docs/Web/API/FileSystemDirectoryReader/readEntries\n *\n * @param {FileSystemDirectoryReader} directoryReader - The directory reader to read entries from.\n * @returns {Promise<FileSystemEntry[]>} - A promise that resolves with an array of `FileSystemEntry` objects.\n */\nconst readEntriesPromise = async directoryReader => {\n return await new Promise((resolve, reject) => {\n directoryReader.readEntries(resolve, reject);\n });\n};\n\n/**\n * Read all entries in a directory or sub-directory\n * by calling `readEntries` until it returns an empty array.\n *\n * @param {FileSystemDirectoryReader} directoryReader - The directory reader to read entries from.\n * @returns {Promise<FileSystemEntry[]>} - A promise that resolves with an array of `FileSystemEntry` objects.\n */\nconst readAllDirectoryEntries = async directoryReader => {\n const entries = [];\n let readEntries = await readEntriesPromise(directoryReader);\n\n while (readEntries.length > 0) {\n entries.push(...readEntries);\n readEntries = await readEntriesPromise(directoryReader);\n }\n\n return entries;\n};\n\n/**\n * Get a `File` object from a `FileSystemFileEntry` object.\n *\n * @param {FileSystemFileEntry} fileEntry - The file entry to get a `File` object from.\n * @returns {Promise<File>} - A promise that resolves with a `File` object.\n */\nconst getFileFromFileEntry = fileEntry => {\n return new Promise((resolve, reject) => {\n fileEntry.file(file => resolve(toFileWithPath(file, fileEntry.fullPath)), reject);\n });\n};\n\n/**\n * Get an array of `File` objects from a `DataTransferItemList` object.\n *\n * @param {DataTransferItemList} dataTransferItemList - The item list to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nconst getFilesFromDataTransferItemList = async dataTransferItemList => {\n const files = [];\n\n // Chromium browsers read only 100 files at a time as per the spec, so we need to use\n // BFS (Breadth-first search) to traverse the entire directory/file structure.\n // https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#javascript_content\n const queue = [];\n\n for (const item of dataTransferItemList) {\n if (item.kind !== 'file') {\n // Ignore non-file items, such as links.\n continue;\n }\n\n // https://developer.mozilla.org/docs/Web/API/DataTransferItem/webkitGetAsEntry\n // This function is implemented as `webkitGetAsEntry()` in non-WebKit browsers\n // including Firefox at this time but it may be renamed to `getAsEntry()` in the future.\n // @ts-ignore\n const entry = item.getAsEntry ? item.getAsEntry() : item.webkitGetAsEntry();\n\n queue.push(entry);\n }\n\n while (queue.length > 0) {\n const entry = queue.shift();\n\n if (!entry) {\n continue;\n } else if (entry.isFile) {\n const file = await getFileFromFileEntry(entry);\n\n if (FILES_TO_IGNORE.indexOf(file.name) === -1) {\n files.push(file);\n }\n } else if (entry.isDirectory) {\n queue.push(...(await readAllDirectoryEntries(entry.createReader())));\n }\n }\n\n return files;\n};\n\n/**\n * Get an array of `File` objects from a `FileList` object.\n *\n * @param {FileList} fileList - The file list to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nconst getFilesFromFileList = async fileList => {\n const files = [];\n\n for (const file of fileList) {\n if (FILES_TO_IGNORE.indexOf(file.name) === -1) {\n files.push(toFileWithPath(file));\n }\n }\n\n return files;\n};\n\n/**\n * Get an array of `File` objects from an event.\n * This function supports both `drop` and `change` events.\n *\n * @param {*} evt - The event to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nexport const getFilesFromEvent = async evt => {\n if (evt.dataTransfer) {\n return evt.dataTransfer.items\n ? await getFilesFromDataTransferItemList(evt.dataTransfer.items)\n : await getFilesFromFileList(evt.dataTransfer.files);\n }\n\n return await getFilesFromFileList(evt.target.files);\n};\n", "// @ts-check\n\n/**\n * Represents a value that may be of type T, or null.\n *\n * @template T\n * @typedef {T | null} Nullable\n */\n\n/**\n * Stable identifier for error codes used in the `files-dropzone-error` event.\n *\n * @typedef {typeof FilesDropzone.ERROR_CODES[keyof typeof FilesDropzone.ERROR_CODES]} FilesDropzoneErrorCode\n */\n\n/**\n * The detail payload for the `files-dropzone-error` event.\n *\n * @typedef {Object} FilesDropzoneErrorDetail\n * @property {FilesDropzoneErrorCode} code - Stable identifier for the type of error that occurred.\n * @property {unknown} error - The underlying error object or value that triggered the event.\n */\n\n/**\n * Stable identifier for rejection codes used in the various drop-related events.\n *\n * @typedef {typeof FilesDropzone.REJECTION_CODES[keyof typeof FilesDropzone.REJECTION_CODES]} FilesDropzoneRejectionCode\n */\n\nimport { isValidFile } from './utils/is-valid-file.js';\nimport { getFilesFromEvent } from './utils/files-selector.js';\n\nconst css = String.raw;\nconst html = String.raw;\nconst COMPONENT_NAME = 'files-dropzone';\nconst template = document.createElement('template');\n\nconst styles = css`\n *,\n *::before,\n *::after {\n box-sizing: border-box;\n }\n\n :host([hidden]),\n [hidden] {\n display: none !important;\n }\n\n :host {\n --dropzone-border-width: 2px;\n --dropzone-border-style: dashed;\n --dropzone-border-radius: 0.25rem;\n --dropzone-border-color: #6c757d;\n --dropzone-border-color-dragover: #0d6efd;\n --dropzone-border-color-hover: var(--dropzone-border-color-dragover);\n --dropzone-background-color: #ffffff;\n --dropzone-background-color-dragover: #f4f4f5;\n --dropzone-background-color-hover: var(--dropzone-background-color-dragover);\n --dropzone-body-color: #3f3f46;\n --dropzone-body-color-dragover: var(--dropzone-body-color);\n --dropzone-body-color-hover: var(--dropzone-body-color-dragover);\n --dropzone-focus-shadow-rgb: 49, 132, 253;\n --dropzone-focus-box-shadow: 0 0 0 0.25rem rgba(var(--dropzone-focus-shadow-rgb), 0.5);\n --transition-duration: 0.2s; /* for backwards compatibility */\n --dropzone-transition-duration: var(--transition-duration);\n\n display: block;\n }\n\n :host(:not([no-style])) .dropzone {\n border: var(--dropzone-border-width) var(--dropzone-border-style) var(--dropzone-border-color);\n border-radius: var(--dropzone-border-radius);\n padding: 3rem 1rem;\n overflow: hidden;\n background-color: var(--dropzone-background-color);\n color: var(--dropzone-body-color);\n text-align: center;\n cursor: pointer;\n transition:\n border var(--dropzone-transition-duration) ease-in-out,\n background-color var(--dropzone-transition-duration) ease-in-out,\n color var(--dropzone-transition-duration) ease-in-out,\n box-shadow var(--dropzone-transition-duration) ease-in-out;\n }\n\n :host(:not([no-style])[disabled]) .dropzone {\n opacity: 0.8;\n cursor: not-allowed;\n user-select: none;\n }\n\n :host(:not([no-style]):not([disabled])) .dropzone--dragover {\n border-color: var(--dropzone-border-color-dragover);\n background-color: var(--dropzone-background-color-dragover);\n color: var(--dropzone-body-color-dragover);\n }\n\n :host(:not([no-style]):not([disabled])) .dropzone:focus-visible {\n outline: none;\n box-shadow: var(--dropzone-focus-box-shadow);\n }\n\n @media (hover: hover) {\n :host(:not([no-style]):not([disabled])) .dropzone:not(.dropzone--dragover):hover {\n border-color: var(--dropzone-border-color-hover);\n background-color: var(--dropzone-background-color-hover);\n color: var(--dropzone-body-color-hover);\n }\n }\n`;\n\ntemplate.innerHTML = html`\n <style>\n ${styles}\n </style>\n\n <input type=\"file\" id=\"file-input\" hidden />\n\n <div part=\"dropzone\" class=\"dropzone\" id=\"dropzone\" tabindex=\"0\" role=\"button\" aria-disabled=\"false\">\n <slot><span>Drag 'n' drop files here, or click to select files</span></slot>\n </div>\n`;\n\n/**\n * @summary A custom element that allows users to drag and drop files into it.\n * @documentation https://github.com/georapbox/files-dropzone-element\n *\n * @tagname files-dropzone - This is the default tag name, unless overridden by the `defineCustomElement` method.\n *\n * @property {string} accept - A comma-separated list of unique file type specifiers describing file types to allow.\n * @property {boolean} disabled - Determines whether the dropzone is disabled.\n * @property {number} maxFiles - The maximum number of files allowed to be dropped.\n * @property {number} maxSize - The maximum file size allowed in bytes.\n * @property {number} minSize - The minimum file size allowed in bytes.\n * @property {boolean} multiple - Allows multiple files to be dropped.\n * @property {boolean} autoFocus - Automatically focuses the dropzone when it's connected to the DOM.\n * @property {boolean} noStyle - Prevents the dropzone from applying any styling.\n *\n * @attribute {string} accept - Reflects the accept property.\n * @attribute {boolean} disabled - Reflects the disabled property.\n * @attribute {number} max-files - Reflects the maxFiles property.\n * @attribute {number} max-size - Reflects the maxSize property.\n * @attribute {number} min-size - Reflects the minSize property.\n * @attribute {boolean} multiple - Reflects the multiple property.\n * @attribute {boolean} auto-focus - Reflects the autoFocus property.\n * @attribute {boolean} no-style - Reflects the noStyle property.\n *\n * @slot - The default slot content of the dropzone.\n *\n * @csspart dropzone - The dropzone element.\n * @csspart dropzone--dragover - The state of the dropzone when dragging over it.\n *\n * @cssproperty --dropzone-border-width - The border width of the dropzone.\n * @cssproperty --dropzone-border-style - The border style of the dropzone.\n * @cssproperty --dropzone-border-radius - The border radius of the dropzone.\n * @cssproperty --dropzone-border-color - The border color of the dropzone.\n * @cssproperty --dropzone-border-color-dragover - The border color of the dropzone when dragging over it.\n * @cssproperty --dropzone-border-color-hover - The border color of the dropzone when hovering over it.\n * @cssproperty --dropzone-background-color - The background color of the dropzone.\n * @cssproperty --dropzone-background-color-dragover - The background color of the dropzone when dragging over it.\n * @cssproperty --dropzone-background-color-hover - The background color of the dropzone when hovering over it.\n * @cssproperty --dropzone-body-color - The text color of the dropzone.\n * @cssproperty --dropzone-body-color-dragover - The text color of the dropzone when dragging over it.\n * @cssproperty --dropzone-body-color-hover - The text color of the dropzone when hovering over it.\n * @cssproperty --dropzone-focus-shadow-rgb - The RGB value of the dropzone's focus shadow.\n * @cssproperty --dropzone-focus-box-shadow - The box shadow of the dropzone when focused.\n * @cssproperty --dropzone-transition-duration - The transition's duration for the dropzone area.\n *\n * @event files-dropzone-drop - Fired when files are dropped.\n * @event files-dropzone-drop-accepted - Fired when files dropped files are accepted.\n * @event files-dropzone-drop-rejected - Fired when files dropped files are rejected.\n * @event files-dropzone-dragenter - Fired when files are dragged into the dropzone.\n * @event files-dropzone-dragover - Fired when files are dragged over the dropzone.\n * @event files-dropzone-dragleave - Fired when files are dragged out of the dropzone.\n * @event files-dropzone-error - Fired when there is any error in the process of reading dropped files or directories.\n *\n * @method defineCustomElement - Static method. Defines a custom element with the given name.\n * @method openFileDialog - Instance method. Opens the file dialog programmatically.\n */\nclass FilesDropzone extends HTMLElement {\n /**\n * Central list of error codes used in drop error event.\n * @readonly\n */\n static ERROR_CODES = /** @type {const} */ ({\n FILE_DIALOG_OPEN_FAILED: 'FILE_DIALOG_OPEN_FAILED',\n FILE_INPUT_CHANGE_FAILED: 'FILE_INPUT_CHANGE_FAILED',\n DROP_EVENT_PROCESSING_FAILED: 'DROP_EVENT_PROCESSING_FAILED',\n UNKNOWN_ERROR: 'UNKNOWN_ERROR'\n });\n\n /**\n * Central list of rejection codes for files that are rejected during the drop process.\n * @readonly\n */\n static REJECTION_CODES = /** @type {const} */ ({\n TOO_MANY_FILES: 'TOO_MANY_FILES',\n FILE_TOO_LARGE: 'FILE_TOO_LARGE',\n FILE_TOO_SMALL: 'FILE_TOO_SMALL',\n INVALID_MIME_TYPE: 'INVALID_MIME_TYPE'\n });\n\n /** @type {Nullable<HTMLInputElement>} */\n #fileInput = null;\n\n /** @type {Nullable<HTMLElement>} */\n #dropzoneEl = null;\n\n constructor() {\n super();\n\n if (!this.shadowRoot) {\n const shadowRoot = this.attachShadow({ mode: 'open', delegatesFocus: true });\n shadowRoot.appendChild(template.content.cloneNode(true));\n }\n\n if (this.shadowRoot) {\n this.#fileInput = /** @type {Nullable<HTMLInputElement>} */ (this.shadowRoot.getElementById('file-input'));\n this.#dropzoneEl = this.shadowRoot.getElementById('dropzone');\n }\n }\n\n static get observedAttributes() {\n return ['accept', 'disabled', 'multiple'];\n }\n\n /**\n * Lifecycle method that is called when attributes are changed, added, removed, or replaced.\n *\n * @param {string} name - The name of the attribute.\n * @param {string} oldValue - The old value of the attribute.\n * @param {string} newValue - The new value of the attribute.\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (name === 'accept' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.accept = this.accept;\n }\n\n if (name === 'disabled' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.disabled = this.disabled;\n\n if (this.disabled) {\n this.#dropzoneEl?.removeAttribute('tabindex');\n this.#dropzoneEl?.setAttribute('aria-disabled', 'true');\n } else {\n this.#dropzoneEl?.setAttribute('tabindex', '0');\n this.#dropzoneEl?.setAttribute('aria-disabled', 'false');\n }\n }\n\n if (name === 'multiple' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.multiple = this.multiple;\n }\n }\n\n /**\n * Lifecycle method that is called when the element is added to the DOM.\n */\n connectedCallback() {\n this.#upgradeProperty('accept');\n this.#upgradeProperty('disabled');\n this.#upgradeProperty('maxFiles');\n this.#upgradeProperty('maxSize');\n this.#upgradeProperty('minSize');\n this.#upgradeProperty('multiple');\n this.#upgradeProperty('autoFocus');\n this.#upgradeProperty('noStyle');\n\n this.#fileInput?.addEventListener('change', this.#handleFileInputChange);\n this.#dropzoneEl?.addEventListener('dragenter', this.#handleDragEnter);\n this.#dropzoneEl?.addEventListener('dragover', this.#handleDragOver);\n this.#dropzoneEl?.addEventListener('dragleave', this.#handleDragLeave);\n this.#dropzoneEl?.addEventListener('drop', this.#handleDrop);\n this.#dropzoneEl?.addEventListener('click', this.#handleClick);\n this.#dropzoneEl?.addEventListener('keyup', this.#handleKeyUp);\n\n this.autoFocus && this.#dropzoneEl?.focus();\n }\n\n /**\n * Lifecycle method that is called when the element is removed from the DOM.\n */\n disconnectedCallback() {\n this.#fileInput?.removeEventListener('change', this.#handleFileInputChange);\n this.#dropzoneEl?.removeEventListener('dragenter', this.#handleDragEnter);\n this.#dropzoneEl?.removeEventListener('dragover', this.#handleDragOver);\n this.#dropzoneEl?.removeEventListener('dragleave', this.#handleDragLeave);\n this.#dropzoneEl?.removeEventListener('drop', this.#handleDrop);\n this.#dropzoneEl?.removeEventListener('click', this.#handleClick);\n this.#dropzoneEl?.removeEventListener('keyup', this.#handleKeyUp);\n }\n\n /**\n * @type {string} - A comma-separated list of unique file type specifiers describing file types to allow.\n * @attribute accept - Reflects the accept property.\n */\n get accept() {\n return this.getAttribute('accept') || '';\n }\n\n set accept(value) {\n this.setAttribute('accept', value != null ? value.toString() : value);\n }\n\n /**\n * @type {boolean} - Determines whether the dropzone is disabled.\n * @default false\n * @attribute disabled - Reflects the disabled property.\n */\n get disabled() {\n return this.hasAttribute('disabled');\n }\n\n set disabled(value) {\n this.toggleAttribute('disabled', !!value);\n }\n\n /**\n * @type {number} - The maximum number of files allowed to be dropped.\n * @default Infinity\n * @attribute max-files - Reflects the maxFiles property.\n */\n get maxFiles() {\n const num = Number(this.getAttribute('max-files')) || 0;\n\n if (num <= 0) {\n return Infinity;\n }\n\n return Math.floor(Math.abs(num));\n }\n\n set maxFiles(value) {\n this.setAttribute('max-files', value != null ? value.toString() : value);\n }\n\n /**\n * @type {number} - The maximum file size allowed in bytes.\n * @default Infinity\n * @attribute max-size - Reflects the maxSize property.\n */\n get maxSize() {\n const value = this.getAttribute('max-size');\n\n if (value === null) {\n return Infinity;\n }\n\n const num = Number(value);\n\n return Number.isNaN(num) ? Infinity : num;\n }\n\n set maxSize(value) {\n this.setAttribute('max-size', value != null ? value.toString() : value);\n }\n\n /**\n * @type {number} - The minimum file size allowed in bytes.\n * @default 0\n * @attribute min-size - Reflects the minSize property.\n */\n get minSize() {\n const value = this.getAttribute('min-size');\n\n if (value === null) {\n return 0;\n }\n\n const num = Number(value);\n\n return Number.isNaN(num) ? 0 : num;\n }\n\n set minSize(value) {\n this.setAttribute('min-size', value != null ? value.toString() : value);\n }\n\n /**\n * @type {boolean} - Allows multiple files to be dropped.\n * @default false\n * @attribute multiple - Reflects the multiple property.\n */\n get multiple() {\n return this.hasAttribute('multiple');\n }\n\n set multiple(value) {\n this.toggleAttribute('multiple', !!value);\n }\n\n /**\n * @type {boolean} - Automatically focuses the dropzone when it's connected to the DOM.\n * @default false\n * @attribute auto-focus - Reflects the autoFocus property.\n */\n get autoFocus() {\n return this.hasAttribute('auto-focus');\n }\n\n set autoFocus(value) {\n this.toggleAttribute('auto-focus', !!value);\n }\n\n /**\n * @type {boolean} - Prevents the dropzone from applying any styling.\n * @default false\n * @attribute no-style - Reflects the noStyle property.\n */\n get noStyle() {\n return this.hasAttribute('no-style');\n }\n\n set noStyle(value) {\n this.toggleAttribute('no-style', !!value);\n }\n\n /**\n * Emit a custom event with the given name and detail.\n *\n * @template D\n * @param {string} name - The name of the event.\n * @param {D} [detail] - The detail payload of the event.\n * @param {CustomEventInit<D>} [init] - Override the default event initialization options.\n * @returns {boolean} - Returns false if at least one event listener called `preventDefault()`, otherwise true.\n */\n #emitEvent(name, detail, init) {\n const options = {\n bubbles: true,\n composed: true,\n cancelable: false,\n ...init,\n detail\n };\n const evt = new CustomEvent(`${COMPONENT_NAME}-${name}`, options);\n return this.dispatchEvent(evt);\n }\n\n /**\n * Emit a standardized error event with typed detail.\n *\n * @param {FilesDropzoneErrorCode} code - Stable identifier for the type of error that occurred.\n * @param {unknown} error - The underlying error that triggered the event.\n */\n #emitErrorEvent(code, error) {\n /** @type {FilesDropzoneErrorDetail} */\n const detail = { code, error };\n\n this.#emitEvent('error', detail);\n }\n\n /**\n * Handles the change event of the file input.\n *\n * @param {*} evt - The event object.\n */\n #handleFileInputChange = async evt => {\n try {\n this.#handleFilesSelect(await getFilesFromEvent(evt));\n } catch (err) {\n this.#emitErrorEvent(FilesDropzone.ERROR_CODES.FILE_INPUT_CHANGE_FAILED, err);\n }\n };\n\n /**\n * Handles the dragenter event of the dropzone.\n */\n #handleDragEnter = () => {\n if (this.disabled) {\n return;\n }\n\n this.#emitEvent('dragenter');\n };\n\n /**\n * Handles the dragover event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleDragOver = evt => {\n evt.preventDefault();\n\n if (this.disabled) {\n evt.dataTransfer.dropEffect = 'none';\n return;\n }\n\n evt.dataTransfer.dropEffect = 'copy';\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.add('dropzone--dragover');\n this.#dropzoneEl.part.add('dropzone--dragover');\n }\n\n this.#emitEvent('dragover');\n };\n\n /**\n * Handles the dragleave event of the dropzone.\n */\n #handleDragLeave = () => {\n if (this.disabled) {\n return;\n }\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.remove('dropzone--dragover');\n this.#dropzoneEl.part.remove('dropzone--dragover');\n }\n\n this.#emitEvent('dragleave');\n };\n\n /**\n * Handles the drop event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleDrop = async evt => {\n if (this.disabled) {\n return;\n }\n\n evt.preventDefault();\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.remove('dropzone--dragover');\n this.#dropzoneEl.part.remove('dropzone--dragover');\n }\n\n try {\n this.#handleFilesSelect(await getFilesFromEvent(evt));\n } catch (err) {\n this.#emitErrorEvent(FilesDropzone.ERROR_CODES.DROP_EVENT_PROCESSING_FAILED, err);\n }\n };\n\n /**\n * Handles the click event of the dropzone.\n */\n #handleClick = () => {\n if (this.disabled) {\n return;\n }\n\n this.openFileDialog();\n };\n\n /**\n * Handles the keyup event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleKeyUp = evt => {\n if (this.disabled) {\n return;\n }\n\n if (evt.key === ' ' || evt.key === 'Enter') {\n this.openFileDialog();\n }\n };\n\n /**\n * Handles the selection of files.\n *\n * @param {File[]} files - The files to handle.\n */\n #handleFilesSelect(files) {\n if (!Array.isArray(files) || !files.length) {\n return;\n }\n\n const acceptedFiles = [];\n const rejectedFiles = [];\n const filesLength = files.length;\n\n // If the component is not in multiple mode, reject all files.\n if (!this.multiple && filesLength > 1) {\n for (const file of files) {\n rejectedFiles.push({\n file,\n errors: [\n {\n code: FilesDropzone.REJECTION_CODES.TOO_MANY_FILES,\n message: `Too many files selected. Only 1 file is allowed.`\n }\n ]\n });\n }\n } else if (this.multiple && filesLength > this.maxFiles) {\n // If the component is in multiple mode, but the number of files exceeds\n // the maxFiles attribute, reject all files.\n for (const file of files) {\n rejectedFiles.push({\n file,\n errors: [\n {\n code: FilesDropzone.REJECTION_CODES.TOO_MANY_FILES,\n message: `Too many files selected. Only ${this.maxFiles} ${this.maxFiles > 1 ? 'files are' : 'file is'} allowed.`\n }\n ]\n });\n }\n } else {\n // Validate each file. If it's valid, add it to the accepted files array,\n // otherwise add it to the rejected files array.\n for (const file of files) {\n const fileHasValidType = isValidFile(file, this.accept);\n const fileExceedsMaxSize = file.size > this.maxSize;\n const fileIsSmallerThanMinSize = file.size < this.minSize;\n\n if (fileHasValidType && !fileExceedsMaxSize && !fileIsSmallerThanMinSize) {\n acceptedFiles.push(file);\n } else {\n const errors = [];\n\n if (!fileHasValidType) {\n errors.push({\n code: FilesDropzone.REJECTION_CODES.INVALID_MIME_TYPE,\n message: `File type \"${file.type}\" is not accepted.`\n });\n }\n\n if (fileExceedsMaxSize) {\n errors.push({\n code: FilesDropzone.REJECTION_CODES.FILE_TOO_LARGE,\n message: `File size ${file.size} exceeds the maximum size of ${this.maxSize}.`\n });\n }\n\n if (fileIsSmallerThanMinSize) {\n errors.push({\n code: FilesDropzone.REJECTION_CODES.FILE_TOO_SMALL,\n message: `File size ${file.size} is smaller than the minimum size of ${this.minSize}.`\n });\n }\n\n rejectedFiles.push({ file, errors });\n }\n }\n }\n\n this.#emitEvent('drop', { acceptedFiles, rejectedFiles });\n\n if (acceptedFiles.length > 0) {\n this.#emitEvent('drop-accepted', { acceptedFiles });\n }\n\n if (rejectedFiles.length > 0) {\n this.#emitEvent('drop-rejected', { rejectedFiles });\n }\n\n if (this.#fileInput) {\n this.#fileInput.value = this.#fileInput.defaultValue;\n }\n }\n\n /**\n * Opens the file dialog programmatically.\n */\n openFileDialog() {\n if (this.disabled || !this.#fileInput) {\n return;\n }\n\n // In modern browsers, use the showPicker() method if available.\n // This way we are able to detect if the file dialog was blocked by the browser\n // (e.g. if the method was called outside a user gesture event).\n if ('showPicker' in HTMLInputElement.prototype && typeof this.#fileInput.showPicker === 'function') {\n try {\n this.#fileInput.showPicker();\n } catch (err) {\n this.#emitErrorEvent(FilesDropzone.ERROR_CODES.FILE_DIALOG_OPEN_FAILED, err);\n }\n return;\n }\n\n // Fallback for browsers that do not support showPicker().\n // This may not work if the method is called outside a user gesture event.\n // In such cases, the browser may block the file dialog from opening but\n // most likely it won't throw an error rather just a warning in the console.\n this.#fileInput.click();\n }\n\n /**\n * This is to safe guard against cases where, for instance, a framework may have added the element to the page and set a\n * value on one of its properties, but lazy loaded its definition. Without this guard, the upgraded element would miss that\n * property and the instance property would prevent the class property setter from ever being called.\n *\n * https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties\n *\n * @param {'accept' | 'disabled' | 'maxFiles' | 'maxSize' | 'minSize' | 'multiple' | 'autoFocus' | 'noStyle'} prop - The property name to upgrade.\n */\n #upgradeProperty(prop) {\n /** @type {any} */\n const instance = this;\n\n if (Object.prototype.hasOwnProperty.call(instance, prop)) {\n const value = instance[prop];\n delete instance[prop];\n instance[prop] = value;\n }\n }\n\n /**\n * Defines a custom element with the given name.\n * The name must contain a dash (-).\n *\n * @param {string} [elementName='files-dropzone'] - The name of the custom element.\n * @example\n *\n * FilesDropzone.defineCustomElement('my-dropzone');\n */\n static defineCustomElement(elementName = COMPONENT_NAME) {\n if (typeof window !== 'undefined' && !window.customElements.get(elementName)) {\n window.customElements.define(elementName, FilesDropzone);\n }\n }\n}\n\nexport { FilesDropzone };\n", "import { FilesDropzone } from './files-dropzone.js';\n\nFilesDropzone.defineCustomElement();\n\nexport { FilesDropzone };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AASO,SAASA,EAAYC,EAAMC,EAAyB,GAAI,CAC7D,GAAI,CAACA,EACH,MAAO,GAGT,IAAMC,EAAwB,CAC5B,GAAG,IAAI,IACLD,EACG,MAAM,GAAG,EACT,IAAIE,GAAKA,EAAE,KAAK,CAAC,EACjB,OAAO,OAAO,CACnB,CACF,EAEMC,EAAeJ,EAAK,KACpBK,EAAeD,EAAa,QAAQ,QAAS,EAAE,EAErD,QAAWE,KAAaJ,EACtB,GAAII,EAAU,OAAO,CAAC,IAAM,KAC1B,GAAIN,EAAK,KAAK,YAAY,EAAE,QAAQM,EAAU,YAAY,EAAGN,EAAK,KAAK,OAASM,EAAU,MAAM,IAAM,GACpG,MAAO,WAE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AGF,KAAKpB,GAAW,OAAQ,CAAE,cAAAY,EAAe,cAAAC,CAAc,CAAC,EAEpDD,EAAc,OAAS,GACzB,KAAKZ,GAAW,gBAAiB,CAAE,cAAAY,CAAc,CAAC,EAGhDC,EAAc,OAAS,GACzB,KAAKb,GAAW,gBAAiB,CAAE,cAAAa,CAAc,CAAC,EAGhD,KAAK5B,KACP,KAAKA,GAAW,MAAQ,KAAKA,GAAW,aAE5C,CAKA,gBAAiB,CACf,GAAI,OAAK,UAAY,CAAC,KAAKA,IAO3B,IAAI,eAAgB,iBAAiB,WAAa,OAAO,KAAKA,GAAW,YAAe,WAAY,CAClG,GAAI,CACF,KAAKA,GAAW,WAAW,CAC7B,OAASyB,EAAK,CACZ,KAAKL,GAAgBrB,EAAc,YAAY,wBAAyB0B,CAAG,CAC7E,CACA,MACF,CAMA,KAAKzB,GAAW,MAAM,EACxB,CAWAK,GAAiB+B,EAAM,CAErB,IAAMC,EAAW,KAEjB,GAAI,OAAO,UAAU,eAAe,KAAKA,EAAUD,CAAI,EAAG,CACxD,IAAMvB,EAAQwB,EAASD,CAAI,EAC3B,OAAOC,EAASD,CAAI,EACpBC,EAASD,CAAI,EAAIvB,CACnB,CACF,CAWA,OAAO,oBAAoByB,EAAc3C,EAAgB,CACnD,OAAO,OAAW,KAAe,CAAC,OAAO,eAAe,IAAI2C,CAAW,GACzE,OAAO,eAAe,OAAOA,EAAavC,CAAa,CAE3D,CACF,EC/sBAwC,EAAc,oBAAoB",
|
|
6
|
+
"names": ["isValidFile", "file", "acceptedTypeSpecifiers", "acceptedMimeTypesList", "v", "fileMimeType", "baseMimeType", "validType", "COMMON_MIME_TYPES", "FILES_TO_IGNORE", "toFileWithMimeType", "file", "name", "extension", "type", "toFileWithPath", "path", "fileWithMimeType", "webkitRelativePath", "readEntriesPromise", "directoryReader", "resolve", "reject", "readAllDirectoryEntries", "entries", "readEntries", "getFileFromFileEntry", "fileEntry", "getFilesFromDataTransferItemList", "dataTransferItemList", "files", "queue", "item", "entry", "getFilesFromFileList", "fileList", "getFilesFromEvent", "evt", "css", "html", "COMPONENT_NAME", "template", "styles", "FilesDropzone", "_FilesDropzone", "#fileInput", "#dropzoneEl", "name", "oldValue", "newValue", "#upgradeProperty", "#handleFileInputChange", "#handleDragEnter", "#handleDragOver", "#handleDragLeave", "#handleDrop", "#handleClick", "#handleKeyUp", "value", "num", "#emitEvent", "detail", "init", "options", "evt", "#emitErrorEvent", "code", "error", "#handleFilesSelect", "getFilesFromEvent", "err", "files", "acceptedFiles", "rejectedFiles", "filesLength", "file", "fileHasValidType", "isValidFile", "fileExceedsMaxSize", "fileIsSmallerThanMinSize", "errors", "prop", "instance", "elementName", "FilesDropzone"]
|
|
7
7
|
}
|
package/dist/files-dropzone.d.ts
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
* Represents a value that may be of type T, or null.
|
|
3
3
|
*/
|
|
4
4
|
export type Nullable<T> = T | null;
|
|
5
|
+
/**
|
|
6
|
+
* Stable identifier for error codes used in the `files-dropzone-error` event.
|
|
7
|
+
*/
|
|
8
|
+
export type FilesDropzoneErrorCode = (typeof FilesDropzone.ERROR_CODES)[keyof typeof FilesDropzone.ERROR_CODES];
|
|
9
|
+
/**
|
|
10
|
+
* The detail payload for the `files-dropzone-error` event.
|
|
11
|
+
*/
|
|
12
|
+
export type FilesDropzoneErrorDetail = {
|
|
13
|
+
/**
|
|
14
|
+
* - Stable identifier for the type of error that occurred.
|
|
15
|
+
*/
|
|
16
|
+
code: FilesDropzoneErrorCode;
|
|
17
|
+
/**
|
|
18
|
+
* - The underlying error object or value that triggered the event.
|
|
19
|
+
*/
|
|
20
|
+
error: unknown;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Stable identifier for rejection codes used in the various drop-related events.
|
|
24
|
+
*/
|
|
25
|
+
export type FilesDropzoneRejectionCode = (typeof FilesDropzone.REJECTION_CODES)[keyof typeof FilesDropzone.REJECTION_CODES];
|
|
5
26
|
/**
|
|
6
27
|
* @summary A custom element that allows users to drag and drop files into it.
|
|
7
28
|
* @documentation https://github.com/georapbox/files-dropzone-element
|
|
@@ -59,6 +80,26 @@ export type Nullable<T> = T | null;
|
|
|
59
80
|
* @method openFileDialog - Instance method. Opens the file dialog programmatically.
|
|
60
81
|
*/
|
|
61
82
|
export class FilesDropzone extends HTMLElement {
|
|
83
|
+
/**
|
|
84
|
+
* Central list of error codes used in drop error event.
|
|
85
|
+
* @readonly
|
|
86
|
+
*/
|
|
87
|
+
static readonly ERROR_CODES: {
|
|
88
|
+
readonly FILE_DIALOG_OPEN_FAILED: "FILE_DIALOG_OPEN_FAILED";
|
|
89
|
+
readonly FILE_INPUT_CHANGE_FAILED: "FILE_INPUT_CHANGE_FAILED";
|
|
90
|
+
readonly DROP_EVENT_PROCESSING_FAILED: "DROP_EVENT_PROCESSING_FAILED";
|
|
91
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Central list of rejection codes for files that are rejected during the drop process.
|
|
95
|
+
* @readonly
|
|
96
|
+
*/
|
|
97
|
+
static readonly REJECTION_CODES: {
|
|
98
|
+
readonly TOO_MANY_FILES: "TOO_MANY_FILES";
|
|
99
|
+
readonly FILE_TOO_LARGE: "FILE_TOO_LARGE";
|
|
100
|
+
readonly FILE_TOO_SMALL: "FILE_TOO_SMALL";
|
|
101
|
+
readonly INVALID_MIME_TYPE: "INVALID_MIME_TYPE";
|
|
102
|
+
};
|
|
62
103
|
static get observedAttributes(): string[];
|
|
63
104
|
/**
|
|
64
105
|
* Defines a custom element with the given name.
|
|
@@ -69,7 +110,7 @@ export class FilesDropzone extends HTMLElement {
|
|
|
69
110
|
*
|
|
70
111
|
* FilesDropzone.defineCustomElement('my-dropzone');
|
|
71
112
|
*/
|
|
72
|
-
static defineCustomElement(elementName?: string
|
|
113
|
+
static defineCustomElement(elementName?: string): void;
|
|
73
114
|
/**
|
|
74
115
|
* Lifecycle method that is called when attributes are changed, added, removed, or replaced.
|
|
75
116
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files-dropzone.d.ts","sourceRoot":"","sources":["../src/files-dropzone.js"],"names":[],"mappings":";;;qBAKa,CAAC,IACD,CAAC,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"files-dropzone.d.ts","sourceRoot":"","sources":["../src/files-dropzone.js"],"names":[],"mappings":";;;qBAKa,CAAC,IACD,CAAC,GAAG,IAAI;;;;qCAMR,CAAA,OAAO,aAAa,CAAC,WAAW,EAAC,MAAM,OAAO,aAAa,CAAC,WAAW,CAAC;;;;;;;;UAOvE,sBAAsB;;;;WACtB,OAAO;;;;;yCAMR,CAAA,OAAO,aAAa,CAAC,eAAe,EAAC,MAAM,OAAO,aAAa,CAAC,eAAe,CAAC;AAkG7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH;IACE;;;OAGG;IACH;;;;;MAKG;IAEH;;;OAGG;IACH;;;;;MAKG;IAsBH,0CAEC;IAkeD;;;;;;;;OAQG;IACH,yCALW,MAAM,QAShB;IA7eD;;;;;;OAMG;IACH,+BAJW,MAAM,YACN,MAAM,YACN,MAAM,QAsBhB;IAED;;OAEG;IACH,0BAmBC;IAED;;OAEG;IACH,6BAQC;IAUD,kBAPU,MAAM,EASf;IAVD;;;OAGG;IACH,cAHU,MAAM,CAKf;IAeD,oBARU,OAAO,EAUhB;IAXD;;;;OAIG;IACH,gBAJU,OAAO,CAMhB;IAqBD,oBAdU,MAAM,EAgBf;IAjBD;;;;OAIG;IACH,gBAJU,MAAM,CAYf;IAuBD,mBAhBU,MAAM,EAkBf;IAnBD;;;;OAIG;IACH,eAJU,MAAM,CAcf;IAuBD,mBAhBU,MAAM,EAkBf;IAnBD;;;;OAIG;IACH,eAJU,MAAM,CAcf;IAeD,oBARU,OAAO,EAUhB;IAXD;;;;OAIG;IACH,gBAJU,OAAO,CAMhB;IAeD,qBARU,OAAO,EAUhB;IAXD;;;;OAIG;IACH,iBAJU,OAAO,CAMhB;IAeD,mBARU,OAAO,EAUhB;IAXD;;;;OAIG;IACH,eAJU,OAAO,CAMhB;IAwPD;;OAEG;IACH,uBAsBC;;CAoCF"}
|
package/dist/files-dropzone.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* @georapbox/files-dropzone-element
|
|
3
3
|
* A custom element that creates a drag and drop zone for files
|
|
4
4
|
*
|
|
5
|
-
* @version 2.
|
|
5
|
+
* @version 2.1.1
|
|
6
6
|
* @homepage https://github.com/georapbox/files-dropzone-element#readme
|
|
7
7
|
* @author George Raptis <georapbox@gmail.com>
|
|
8
8
|
* @license MIT
|
|
9
9
|
*/
|
|
10
|
-
function
|
|
10
|
+
function p(o,e=""){if(!e)return!0;let t=[...new Set(e.split(",").map(r=>r.trim()).filter(Boolean))],i=o.type,s=i.replace(/\/.*$/,"");for(let r of t)if(r.charAt(0)==="."){if(o.name.toLowerCase().indexOf(r.toLowerCase(),o.name.length-r.length)!==-1)return!0}else if(/\/\*$/.test(r)){if(s===r.replace(/\/.*$/,""))return!0}else if(i===r)return!0;return!1}var E=new Map([["aac","audio/aac"],["abw","application/x-abiword"],["arc","application/x-freearc"],["avif","image/avif"],["avi","video/x-msvideo"],["azw","application/vnd.amazon.ebook"],["bin","application/octet-stream"],["bmp","image/bmp"],["bz","application/x-bzip"],["bz2","application/x-bzip2"],["cda","application/x-cdf"],["csh","application/x-csh"],["css","text/css"],["csv","text/csv"],["doc","application/msword"],["docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],["eot","application/vnd.ms-fontobject"],["epub","application/epub+zip"],["gz","application/gzip"],["gif","image/gif"],["heic","image/heic"],["heif","image/heif"],["htm","text/html"],["html","text/html"],["ico","image/vnd.microsoft.icon"],["ics","text/calendar"],["jar","application/java-archive"],["jpeg","image/jpeg"],["jpg","image/jpeg"],["jxl","image/jxl"],["js","text/javascript"],["json","application/json"],["jsonld","application/ld+json"],["markdown","text/markdown"],["md","text/markdown"],["mid","audio/midi"],["midi","audio/midi"],["mjs","text/javascript"],["mp3","audio/mpeg"],["mp4","video/mp4"],["mpeg","video/mpeg"],["mpkg","application/vnd.apple.installer+xml"],["odp","application/vnd.oasis.opendocument.presentation"],["ods","application/vnd.oasis.opendocument.spreadsheet"],["odt","application/vnd.oasis.opendocument.text"],["oga","audio/ogg"],["ogv","video/ogg"],["ogx","application/ogg"],["opus","audio/opus"],["otf","font/otf"],["png","image/png"],["pdf","application/pdf"],["php","application/x-httpd-php"],["ppt","application/vnd.ms-powerpoint"],["pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation"],["rar","application/vnd.rar"],["rtf","application/rtf"],["sh","application/x-sh"],["svg","image/svg+xml"],["swf","application/x-shockwave-flash"],["tar","application/x-tar"],["tif","image/tiff"],["tiff","image/tiff"],["ts","video/mp2t"],["ttf","font/ttf"],["txt","text/plain"],["vsd","application/vnd.visio"],["wav","audio/wav"],["weba","audio/webm"],["webm","video/webm"],["webp","image/webp"],["woff","font/woff"],["woff2","font/woff2"],["xhtml","application/xhtml+xml"],["xls","application/vnd.ms-excel"],["xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],["xml","application/xml"],["xul","application/vnd.mozilla.xul+xml"],["zip","application/zip"],["7z","application/x-7z-compressed"],["mkv","video/x-matroska"],["mov","video/quicktime"],["msg","application/vnd.ms-outlook"]]),m=[".DS_Store","Thumbs.db"],z=o=>{let{name:e}=o;if(e&&e.lastIndexOf(".")!==-1&&!o.type){let i=(e.split(".").pop()||"").toLowerCase(),s=E.get(i);s&&Object.defineProperty(o,"type",{value:s,writable:!1,configurable:!1,enumerable:!0})}return o},f=(o,e)=>{let t=z(o);if(typeof t.path!="string"){let{webkitRelativePath:i}=o;Object.defineProperty(t,"path",{value:typeof e=="string"?e:i||o.name,writable:!1,configurable:!1,enumerable:!0})}return t},h=async o=>await new Promise((e,t)=>{o.readEntries(e,t)}),x=async o=>{let e=[],t=await h(o);for(;t.length>0;)e.push(...t),t=await h(o);return e},y=o=>new Promise((e,t)=>{o.file(i=>e(f(i,o.fullPath)),t)}),w=async o=>{let e=[],t=[];for(let i of o){if(i.kind!=="file")continue;let s=i.getAsEntry?i.getAsEntry():i.webkitGetAsEntry();t.push(s)}for(;t.length>0;){let i=t.shift();if(i)if(i.isFile){let s=await y(i);m.indexOf(s.name)===-1&&e.push(s)}else i.isDirectory&&t.push(...await x(i.createReader()));else continue}return e},u=async o=>{let e=[];for(let t of o)m.indexOf(t.name)===-1&&e.push(f(t));return e},a=async o=>o.dataTransfer?o.dataTransfer.items?await w(o.dataTransfer.items):await u(o.dataTransfer.files):await u(o.target.files);var O=String.raw,L=String.raw,g="files-dropzone",v=document.createElement("template"),F=O`
|
|
11
11
|
*,
|
|
12
12
|
*::before,
|
|
13
13
|
*::after {
|
|
@@ -32,7 +32,7 @@ function h(o,e=""){if(!e)return!0;let t=[...new Set(e.split(",").map(r=>r.trim()
|
|
|
32
32
|
--dropzone-body-color: #3f3f46;
|
|
33
33
|
--dropzone-body-color-dragover: var(--dropzone-body-color);
|
|
34
34
|
--dropzone-body-color-hover: var(--dropzone-body-color-dragover);
|
|
35
|
-
--dropzone-focus-shadow-rgb: 49,132,253;
|
|
35
|
+
--dropzone-focus-shadow-rgb: 49, 132, 253;
|
|
36
36
|
--dropzone-focus-box-shadow: 0 0 0 0.25rem rgba(var(--dropzone-focus-shadow-rgb), 0.5);
|
|
37
37
|
--transition-duration: 0.2s; /* for backwards compatibility */
|
|
38
38
|
--dropzone-transition-duration: var(--transition-duration);
|
|
@@ -49,7 +49,11 @@ function h(o,e=""){if(!e)return!0;let t=[...new Set(e.split(",").map(r=>r.trim()
|
|
|
49
49
|
color: var(--dropzone-body-color);
|
|
50
50
|
text-align: center;
|
|
51
51
|
cursor: pointer;
|
|
52
|
-
transition:
|
|
52
|
+
transition:
|
|
53
|
+
border var(--dropzone-transition-duration) ease-in-out,
|
|
54
|
+
background-color var(--dropzone-transition-duration) ease-in-out,
|
|
55
|
+
color var(--dropzone-transition-duration) ease-in-out,
|
|
56
|
+
box-shadow var(--dropzone-transition-duration) ease-in-out;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
:host(:not([no-style])[disabled]) .dropzone {
|
|
@@ -76,15 +80,15 @@ function h(o,e=""){if(!e)return!0;let t=[...new Set(e.split(",").map(r=>r.trim()
|
|
|
76
80
|
color: var(--dropzone-body-color-hover);
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
|
-
`;
|
|
83
|
+
`;v.innerHTML=L`
|
|
80
84
|
<style>
|
|
81
|
-
${
|
|
85
|
+
${F}
|
|
82
86
|
</style>
|
|
83
87
|
|
|
84
|
-
<input type="file" id="file-input" hidden
|
|
88
|
+
<input type="file" id="file-input" hidden />
|
|
85
89
|
|
|
86
90
|
<div part="dropzone" class="dropzone" id="dropzone" tabindex="0" role="button" aria-disabled="false">
|
|
87
|
-
<slot>Drag 'n' drop files here, or click to select files</slot>
|
|
91
|
+
<slot><span>Drag 'n' drop files here, or click to select files</span></slot>
|
|
88
92
|
</div>
|
|
89
|
-
`;var
|
|
93
|
+
`;var b=class o extends HTMLElement{static ERROR_CODES={FILE_DIALOG_OPEN_FAILED:"FILE_DIALOG_OPEN_FAILED",FILE_INPUT_CHANGE_FAILED:"FILE_INPUT_CHANGE_FAILED",DROP_EVENT_PROCESSING_FAILED:"DROP_EVENT_PROCESSING_FAILED",UNKNOWN_ERROR:"UNKNOWN_ERROR"};static REJECTION_CODES={TOO_MANY_FILES:"TOO_MANY_FILES",FILE_TOO_LARGE:"FILE_TOO_LARGE",FILE_TOO_SMALL:"FILE_TOO_SMALL",INVALID_MIME_TYPE:"INVALID_MIME_TYPE"};#t=null;#e=null;constructor(){super(),this.shadowRoot||this.attachShadow({mode:"open",delegatesFocus:!0}).appendChild(v.content.cloneNode(!0)),this.shadowRoot&&(this.#t=this.shadowRoot.getElementById("file-input"),this.#e=this.shadowRoot.getElementById("dropzone"))}static get observedAttributes(){return["accept","disabled","multiple"]}attributeChangedCallback(e,t,i){e==="accept"&&t!==i&&this.#t&&(this.#t.accept=this.accept),e==="disabled"&&t!==i&&this.#t&&(this.#t.disabled=this.disabled,this.disabled?(this.#e?.removeAttribute("tabindex"),this.#e?.setAttribute("aria-disabled","true")):(this.#e?.setAttribute("tabindex","0"),this.#e?.setAttribute("aria-disabled","false"))),e==="multiple"&&t!==i&&this.#t&&(this.#t.multiple=this.multiple)}connectedCallback(){this.#o("accept"),this.#o("disabled"),this.#o("maxFiles"),this.#o("maxSize"),this.#o("minSize"),this.#o("multiple"),this.#o("autoFocus"),this.#o("noStyle"),this.#t?.addEventListener("change",this.#s),this.#e?.addEventListener("dragenter",this.#n),this.#e?.addEventListener("dragover",this.#a),this.#e?.addEventListener("dragleave",this.#d),this.#e?.addEventListener("drop",this.#l),this.#e?.addEventListener("click",this.#c),this.#e?.addEventListener("keyup",this.#p),this.autoFocus&&this.#e?.focus()}disconnectedCallback(){this.#t?.removeEventListener("change",this.#s),this.#e?.removeEventListener("dragenter",this.#n),this.#e?.removeEventListener("dragover",this.#a),this.#e?.removeEventListener("dragleave",this.#d),this.#e?.removeEventListener("drop",this.#l),this.#e?.removeEventListener("click",this.#c),this.#e?.removeEventListener("keyup",this.#p)}get accept(){return this.getAttribute("accept")||""}set accept(e){this.setAttribute("accept",e!=null?e.toString():e)}get disabled(){return this.hasAttribute("disabled")}set disabled(e){this.toggleAttribute("disabled",!!e)}get maxFiles(){let e=Number(this.getAttribute("max-files"))||0;return e<=0?1/0:Math.floor(Math.abs(e))}set maxFiles(e){this.setAttribute("max-files",e!=null?e.toString():e)}get maxSize(){let e=this.getAttribute("max-size");if(e===null)return 1/0;let t=Number(e);return Number.isNaN(t)?1/0:t}set maxSize(e){this.setAttribute("max-size",e!=null?e.toString():e)}get minSize(){let e=this.getAttribute("min-size");if(e===null)return 0;let t=Number(e);return Number.isNaN(t)?0:t}set minSize(e){this.setAttribute("min-size",e!=null?e.toString():e)}get multiple(){return this.hasAttribute("multiple")}set multiple(e){this.toggleAttribute("multiple",!!e)}get autoFocus(){return this.hasAttribute("auto-focus")}set autoFocus(e){this.toggleAttribute("auto-focus",!!e)}get noStyle(){return this.hasAttribute("no-style")}set noStyle(e){this.toggleAttribute("no-style",!!e)}#i(e,t,i){let s={bubbles:!0,composed:!0,cancelable:!1,...i,detail:t},r=new CustomEvent(`${g}-${e}`,s);return this.dispatchEvent(r)}#r(e,t){let i={code:e,error:t};this.#i("error",i)}#s=async e=>{try{this.#h(await a(e))}catch(t){this.#r(o.ERROR_CODES.FILE_INPUT_CHANGE_FAILED,t)}};#n=()=>{this.disabled||this.#i("dragenter")};#a=e=>{if(e.preventDefault(),this.disabled){e.dataTransfer.dropEffect="none";return}e.dataTransfer.dropEffect="copy",this.#e&&(this.#e.classList.add("dropzone--dragover"),this.#e.part.add("dropzone--dragover")),this.#i("dragover")};#d=()=>{this.disabled||(this.#e&&(this.#e.classList.remove("dropzone--dragover"),this.#e.part.remove("dropzone--dragover")),this.#i("dragleave"))};#l=async e=>{if(!this.disabled){e.preventDefault(),this.#e&&(this.#e.classList.remove("dropzone--dragover"),this.#e.part.remove("dropzone--dragover"));try{this.#h(await a(e))}catch(t){this.#r(o.ERROR_CODES.DROP_EVENT_PROCESSING_FAILED,t)}}};#c=()=>{this.disabled||this.openFileDialog()};#p=e=>{this.disabled||(e.key===" "||e.key==="Enter")&&this.openFileDialog()};#h(e){if(!Array.isArray(e)||!e.length)return;let t=[],i=[],s=e.length;if(!this.multiple&&s>1)for(let r of e)i.push({file:r,errors:[{code:o.REJECTION_CODES.TOO_MANY_FILES,message:"Too many files selected. Only 1 file is allowed."}]});else if(this.multiple&&s>this.maxFiles)for(let r of e)i.push({file:r,errors:[{code:o.REJECTION_CODES.TOO_MANY_FILES,message:`Too many files selected. Only ${this.maxFiles} ${this.maxFiles>1?"files are":"file is"} allowed.`}]});else for(let r of e){let d=p(r,this.accept),l=r.size>this.maxSize,c=r.size<this.minSize;if(d&&!l&&!c)t.push(r);else{let n=[];d||n.push({code:o.REJECTION_CODES.INVALID_MIME_TYPE,message:`File type "${r.type}" is not accepted.`}),l&&n.push({code:o.REJECTION_CODES.FILE_TOO_LARGE,message:`File size ${r.size} exceeds the maximum size of ${this.maxSize}.`}),c&&n.push({code:o.REJECTION_CODES.FILE_TOO_SMALL,message:`File size ${r.size} is smaller than the minimum size of ${this.minSize}.`}),i.push({file:r,errors:n})}}this.#i("drop",{acceptedFiles:t,rejectedFiles:i}),t.length>0&&this.#i("drop-accepted",{acceptedFiles:t}),i.length>0&&this.#i("drop-rejected",{rejectedFiles:i}),this.#t&&(this.#t.value=this.#t.defaultValue)}openFileDialog(){if(!(this.disabled||!this.#t)){if("showPicker"in HTMLInputElement.prototype&&typeof this.#t.showPicker=="function"){try{this.#t.showPicker()}catch(e){this.#r(o.ERROR_CODES.FILE_DIALOG_OPEN_FAILED,e)}return}this.#t.click()}}#o(e){let t=this;if(Object.prototype.hasOwnProperty.call(t,e)){let i=t[e];delete t[e],t[e]=i}}static defineCustomElement(e=g){typeof window<"u"&&!window.customElements.get(e)&&window.customElements.define(e,o)}};export{b as FilesDropzone};
|
|
90
94
|
//# sourceMappingURL=files-dropzone.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils/is-valid-file.js", "../src/utils/files-selector.js", "../src/files-dropzone.js"],
|
|
4
|
-
"sourcesContent": ["// @ts-check\n\n/**\n * Checks if a file is valid based on the accepted file type specifiers.\n *\n * @param {File} file - The File object to validate.\n * @param {string} [acceptedTypeSpecifiers=''] - The accepted file type specifiers.\n * @returns {boolean} - True if the file is valid, false otherwise.\n */\nexport function isValidFile(file, acceptedTypeSpecifiers = '') {\n if (!acceptedTypeSpecifiers) {\n return true;\n }\n\n const acceptedMimeTypesList = [\n ...new Set(\n acceptedTypeSpecifiers\n .split(',')\n .map(v => v.trim())\n .filter(Boolean)\n )\n ];\n\n const fileMimeType = file.type;\n const baseMimeType = fileMimeType.replace(/\\/.*$/, '');\n\n for (const validType of acceptedMimeTypesList) {\n if (validType.charAt(0) === '.') {\n if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) {\n return true;\n }\n } else if (/\\/\\*$/.test(validType)) {\n // Check for mime type that looks like \"image/*\" or similar.\n if (baseMimeType === validType.replace(/\\/.*$/, '')) {\n return true;\n }\n } else {\n if (fileMimeType === validType) {\n return true;\n }\n }\n }\n\n return false;\n}\n", "// @ts-check\n\n/**\n * A map of common file extensions and their associated MIME types.\n */\nconst COMMON_MIME_TYPES = new Map([\n // https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\n ['aac', 'audio/aac'],\n ['abw', 'application/x-abiword'],\n ['arc', 'application/x-freearc'],\n ['avif', 'image/avif'],\n ['avi', 'video/x-msvideo'],\n ['azw', 'application/vnd.amazon.ebook'],\n ['bin', 'application/octet-stream'],\n ['bmp', 'image/bmp'],\n ['bz', 'application/x-bzip'],\n ['bz2', 'application/x-bzip2'],\n ['cda', 'application/x-cdf'],\n ['csh', 'application/x-csh'],\n ['css', 'text/css'],\n ['csv', 'text/csv'],\n ['doc', 'application/msword'],\n ['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],\n ['eot', 'application/vnd.ms-fontobject'],\n ['epub', 'application/epub+zip'],\n ['gz', 'application/gzip'],\n ['gif', 'image/gif'],\n ['heic', 'image/heic'],\n ['heif', 'image/heif'],\n ['htm', 'text/html'],\n ['html', 'text/html'],\n ['ico', 'image/vnd.microsoft.icon'],\n ['ics', 'text/calendar'],\n ['jar', 'application/java-archive'],\n ['jpeg', 'image/jpeg'],\n ['jpg', 'image/jpeg'],\n ['jxl', 'image/jxl'],\n ['js', 'text/javascript'],\n ['json', 'application/json'],\n ['jsonld', 'application/ld+json'],\n ['markdown', 'text/markdown'],\n ['md', 'text/markdown'],\n ['mid', 'audio/midi'],\n ['midi', 'audio/midi'],\n ['mjs', 'text/javascript'],\n ['mp3', 'audio/mpeg'],\n ['mp4', 'video/mp4'],\n ['mpeg', 'video/mpeg'],\n ['mpkg', 'application/vnd.apple.installer+xml'],\n ['odp', 'application/vnd.oasis.opendocument.presentation'],\n ['ods', 'application/vnd.oasis.opendocument.spreadsheet'],\n ['odt', 'application/vnd.oasis.opendocument.text'],\n ['oga', 'audio/ogg'],\n ['ogv', 'video/ogg'],\n ['ogx', 'application/ogg'],\n ['opus', 'audio/opus'],\n ['otf', 'font/otf'],\n ['png', 'image/png'],\n ['pdf', 'application/pdf'],\n ['php', 'application/x-httpd-php'],\n ['ppt', 'application/vnd.ms-powerpoint'],\n ['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],\n ['rar', 'application/vnd.rar'],\n ['rtf', 'application/rtf'],\n ['sh', 'application/x-sh'],\n ['svg', 'image/svg+xml'],\n ['swf', 'application/x-shockwave-flash'],\n ['tar', 'application/x-tar'],\n ['tif', 'image/tiff'],\n ['tiff', 'image/tiff'],\n ['ts', 'video/mp2t'],\n ['ttf', 'font/ttf'],\n ['txt', 'text/plain'],\n ['vsd', 'application/vnd.visio'],\n ['wav', 'audio/wav'],\n ['weba', 'audio/webm'],\n ['webm', 'video/webm'],\n ['webp', 'image/webp'],\n ['woff', 'font/woff'],\n ['woff2', 'font/woff2'],\n ['xhtml', 'application/xhtml+xml'],\n ['xls', 'application/vnd.ms-excel'],\n ['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],\n ['xml', 'application/xml'],\n ['xul', 'application/vnd.mozilla.xul+xml'],\n ['zip', 'application/zip'],\n ['7z', 'application/x-7z-compressed'],\n\n // Others\n ['mkv', 'video/x-matroska'],\n ['mov', 'video/quicktime'],\n ['msg', 'application/vnd.ms-outlook']\n]);\n\nconst FILES_TO_IGNORE = [\n // Thumbnail cache files for macOS and Windows\n '.DS_Store', // macOs\n 'Thumbs.db' // Windows\n];\n\n/**\n * Adds a `type` property to the file object if it doesn't have one and the file has an extension.\n * This is needed because Firefox doesn't add a type property to files dragged from the desktop.\n * @bug https://bugzilla.mozilla.org/show_bug.cgi?id=1424689\n *\n * @param {File} file - The file object to add the type property to.\n * @returns {File} - The file object with the type property added.\n */\nconst toFileWithMimeType = file => {\n const { name } = file;\n const hasExtension = name && name.lastIndexOf('.') !== -1;\n\n if (hasExtension && !file.type) {\n const extension = (name.split('.').pop() || '').toLowerCase();\n const type = COMMON_MIME_TYPES.get(extension);\n\n if (type) {\n Object.defineProperty(file, 'type', {\n value: type,\n writable: false,\n configurable: false,\n enumerable: true\n });\n }\n }\n\n return file;\n};\n\n/**\n * Adds a `path` property to the file object if it doesn't have one.\n * If `path` is not provided, the `webkitRelativePath` property of the file will be used\n * or the file's name if `webkitRelativePath` is not available.\n *\n * @param {File} file - The file object to add the path property to.\n * @param {string} [path] - The path to set on the file object.\n * @returns {File} - The file object with the path property added.\n */\nconst toFileWithPath = (file, path) => {\n const fileWithMimeType = toFileWithMimeType(file);\n\n // @ts-ignore\n if (typeof fileWithMimeType.path !== 'string') {\n const { webkitRelativePath } = file;\n\n Object.defineProperty(fileWithMimeType, 'path', {\n value: typeof path === 'string' ? path : webkitRelativePath || file.name,\n writable: false,\n configurable: false,\n enumerable: true\n });\n }\n\n return fileWithMimeType;\n};\n\n/**\n * Wrap `FileSystemDirectoryReader.readEntries` in a promise to make working with read entries easier.\n * https://developer.mozilla.org/docs/Web/API/FileSystemDirectoryReader/readEntries\n *\n * @param {FileSystemDirectoryReader} directoryReader - The directory reader to read entries from.\n * @returns {Promise<FileSystemEntry[]>} - A promise that resolves with an array of `FileSystemEntry` objects.\n */\nconst readEntriesPromise = async directoryReader => {\n return await new Promise((resolve, reject) => {\n directoryReader.readEntries(resolve, reject);\n });\n};\n\n/**\n * Read all entries in a directory or sub-directory\n * by calling `readEntries` until it returns an empty array.\n *\n * @param {FileSystemDirectoryReader} directoryReader - The directory reader to read entries from.\n * @returns {Promise<FileSystemEntry[]>} - A promise that resolves with an array of `FileSystemEntry` objects.\n */\nconst readAllDirectoryEntries = async directoryReader => {\n const entries = [];\n let readEntries = await readEntriesPromise(directoryReader);\n\n while (readEntries.length > 0) {\n entries.push(...readEntries);\n readEntries = await readEntriesPromise(directoryReader);\n }\n\n return entries;\n};\n\n/**\n * Get a `File` object from a `FileSystemFileEntry` object.\n *\n * @param {FileSystemFileEntry} fileEntry - The file entry to get a `File` object from.\n * @returns {Promise<File>} - A promise that resolves with a `File` object.\n */\nconst getFileFromFileEntry = fileEntry => {\n return new Promise((resolve, reject) => {\n fileEntry.file(file => resolve(toFileWithPath(file, fileEntry.fullPath)), reject);\n });\n};\n\n/**\n * Get an array of `File` objects from a `DataTransferItemList` object.\n *\n * @param {DataTransferItemList} dataTransferItemList - The item list to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nconst getFilesFromDataTransferItemList = async dataTransferItemList => {\n const files = [];\n\n // Chromium browsers read only 100 files at a time as per the spec, so we need to use\n // BFS (Breadth-first search) to traverse the entire directory/file structure.\n // https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#javascript_content\n const queue = [];\n\n for (const item of dataTransferItemList) {\n if (item.kind !== 'file') {\n // Ignore non-file items, such as links.\n continue;\n }\n\n // https://developer.mozilla.org/docs/Web/API/DataTransferItem/webkitGetAsEntry\n // This function is implemented as `webkitGetAsEntry()` in non-WebKit browsers\n // including Firefox at this time but it may be renamed to `getAsEntry()` in the future.\n // @ts-ignore\n const entry = item.getAsEntry ? item.getAsEntry() : item.webkitGetAsEntry();\n\n queue.push(entry);\n }\n\n while (queue.length > 0) {\n const entry = queue.shift();\n\n if (!entry) {\n continue;\n } else if (entry.isFile) {\n const file = await getFileFromFileEntry(entry);\n\n if (FILES_TO_IGNORE.indexOf(file.name) === -1) {\n files.push(file);\n }\n } else if (entry.isDirectory) {\n queue.push(...(await readAllDirectoryEntries(entry.createReader())));\n }\n }\n\n return files;\n};\n\n/**\n * Get an array of `File` objects from a `FileList` object.\n *\n * @param {FileList} fileList - The file list to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nconst getFilesFromFileList = async fileList => {\n const files = [];\n\n for (const file of fileList) {\n if (FILES_TO_IGNORE.indexOf(file.name) === -1) {\n files.push(toFileWithPath(file));\n }\n }\n\n return files;\n};\n\n/**\n * Get an array of `File` objects from an event.\n * This function supports both `drop` and `change` events.\n *\n * @param {*} evt - The event to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nexport const getFilesFromEvent = async evt => {\n if (evt.dataTransfer) {\n return evt.dataTransfer.items\n ? await getFilesFromDataTransferItemList(evt.dataTransfer.items)\n : await getFilesFromFileList(evt.dataTransfer.files);\n }\n\n return await getFilesFromFileList(evt.target.files);\n};\n", "// @ts-check\n\n/**\n * Represents a value that may be of type T, or null.\n *\n * @template T\n * @typedef {T | null} Nullable\n */\n\nimport { isValidFile } from './utils/is-valid-file.js';\nimport { getFilesFromEvent } from './utils/files-selector.js';\n\nconst COMPONENT_NAME = 'files-dropzone';\nconst TOO_MANY_FILES = 'TOO_MANY_FILES';\nconst FILE_TOO_LARGE = 'FILE_TOO_LARGE';\nconst FILE_TOO_SMALL = 'FILE_TOO_SMALL';\nconst INVALID_MIME_TYPE = 'INVALID_MIME_TYPE';\nconst template = document.createElement('template');\n\nconst styles = /* css */ `\n *,\n *::before,\n *::after {\n box-sizing: border-box;\n }\n\n :host([hidden]),\n [hidden] {\n display: none !important;\n }\n\n :host {\n --dropzone-border-width: 2px;\n --dropzone-border-style: dashed;\n --dropzone-border-radius: 0.25rem;\n --dropzone-border-color: #6c757d;\n --dropzone-border-color-dragover: #0d6efd;\n --dropzone-border-color-hover: var(--dropzone-border-color-dragover);\n --dropzone-background-color: #ffffff;\n --dropzone-background-color-dragover: #f4f4f5;\n --dropzone-background-color-hover: var(--dropzone-background-color-dragover);\n --dropzone-body-color: #3f3f46;\n --dropzone-body-color-dragover: var(--dropzone-body-color);\n --dropzone-body-color-hover: var(--dropzone-body-color-dragover);\n --dropzone-focus-shadow-rgb: 49,132,253;\n --dropzone-focus-box-shadow: 0 0 0 0.25rem rgba(var(--dropzone-focus-shadow-rgb), 0.5);\n --transition-duration: 0.2s; /* for backwards compatibility */\n --dropzone-transition-duration: var(--transition-duration);\n\n display: block;\n }\n\n :host(:not([no-style])) .dropzone {\n border: var(--dropzone-border-width) var(--dropzone-border-style) var(--dropzone-border-color);\n border-radius: var(--dropzone-border-radius);\n padding: 3rem 1rem;\n overflow: hidden;\n background-color: var(--dropzone-background-color);\n color: var(--dropzone-body-color);\n text-align: center;\n cursor: pointer;\n transition: border var(--dropzone-transition-duration) ease-in-out, background-color var(--dropzone-transition-duration) ease-in-out, color var(--dropzone-transition-duration) ease-in-out, box-shadow var(--dropzone-transition-duration) ease-in-out;\n }\n\n :host(:not([no-style])[disabled]) .dropzone {\n opacity: 0.8;\n cursor: not-allowed;\n user-select: none;\n }\n\n :host(:not([no-style]):not([disabled])) .dropzone--dragover {\n border-color: var(--dropzone-border-color-dragover);\n background-color: var(--dropzone-background-color-dragover);\n color: var(--dropzone-body-color-dragover);\n }\n\n :host(:not([no-style]):not([disabled])) .dropzone:focus-visible {\n outline: none;\n box-shadow: var(--dropzone-focus-box-shadow);\n }\n\n @media (hover: hover) {\n :host(:not([no-style]):not([disabled])) .dropzone:not(.dropzone--dragover):hover {\n border-color: var(--dropzone-border-color-hover);\n background-color: var(--dropzone-background-color-hover);\n color: var(--dropzone-body-color-hover);\n }\n }\n`;\n\ntemplate.innerHTML = /* html */ `\n <style>\n ${styles}\n </style>\n\n <input type=\"file\" id=\"file-input\" hidden>\n\n <div part=\"dropzone\" class=\"dropzone\" id=\"dropzone\" tabindex=\"0\" role=\"button\" aria-disabled=\"false\">\n <slot>Drag 'n' drop files here, or click to select files</slot>\n </div>\n`;\n\n/**\n * @summary A custom element that allows users to drag and drop files into it.\n * @documentation https://github.com/georapbox/files-dropzone-element\n *\n * @tagname files-dropzone - This is the default tag name, unless overridden by the `defineCustomElement` method.\n *\n * @property {string} accept - A comma-separated list of unique file type specifiers describing file types to allow.\n * @property {boolean} disabled - Determines whether the dropzone is disabled.\n * @property {number} maxFiles - The maximum number of files allowed to be dropped.\n * @property {number} maxSize - The maximum file size allowed in bytes.\n * @property {number} minSize - The minimum file size allowed in bytes.\n * @property {boolean} multiple - Allows multiple files to be dropped.\n * @property {boolean} autoFocus - Automatically focuses the dropzone when it's connected to the DOM.\n * @property {boolean} noStyle - Prevents the dropzone from applying any styling.\n *\n * @attribute {string} accept - Reflects the accept property.\n * @attribute {boolean} disabled - Reflects the disabled property.\n * @attribute {number} max-files - Reflects the maxFiles property.\n * @attribute {number} max-size - Reflects the maxSize property.\n * @attribute {number} min-size - Reflects the minSize property.\n * @attribute {boolean} multiple - Reflects the multiple property.\n * @attribute {boolean} auto-focus - Reflects the autoFocus property.\n * @attribute {boolean} no-style - Reflects the noStyle property.\n *\n * @slot - The default slot content of the dropzone.\n *\n * @csspart dropzone - The dropzone element.\n * @csspart dropzone--dragover - The state of the dropzone when dragging over it.\n *\n * @cssproperty --dropzone-border-width - The border width of the dropzone.\n * @cssproperty --dropzone-border-style - The border style of the dropzone.\n * @cssproperty --dropzone-border-radius - The border radius of the dropzone.\n * @cssproperty --dropzone-border-color - The border color of the dropzone.\n * @cssproperty --dropzone-border-color-dragover - The border color of the dropzone when dragging over it.\n * @cssproperty --dropzone-border-color-hover - The border color of the dropzone when hovering over it.\n * @cssproperty --dropzone-background-color - The background color of the dropzone.\n * @cssproperty --dropzone-background-color-dragover - The background color of the dropzone when dragging over it.\n * @cssproperty --dropzone-background-color-hover - The background color of the dropzone when hovering over it.\n * @cssproperty --dropzone-body-color - The text color of the dropzone.\n * @cssproperty --dropzone-body-color-dragover - The text color of the dropzone when dragging over it.\n * @cssproperty --dropzone-body-color-hover - The text color of the dropzone when hovering over it.\n * @cssproperty --dropzone-focus-shadow-rgb - The RGB value of the dropzone's focus shadow.\n * @cssproperty --dropzone-focus-box-shadow - The box shadow of the dropzone when focused.\n * @cssproperty --dropzone-transition-duration - The transition's duration for the dropzone area.\n *\n * @event files-dropzone-drop - Fired when files are dropped.\n * @event files-dropzone-drop-accepted - Fired when files dropped files are accepted.\n * @event files-dropzone-drop-rejected - Fired when files dropped files are rejected.\n * @event files-dropzone-dragenter - Fired when files are dragged into the dropzone.\n * @event files-dropzone-dragover - Fired when files are dragged over the dropzone.\n * @event files-dropzone-dragleave - Fired when files are dragged out of the dropzone.\n * @event files-dropzone-error - Fired when there is any error in the process of reading dropped files or directories.\n *\n * @method defineCustomElement - Static method. Defines a custom element with the given name.\n * @method openFileDialog - Instance method. Opens the file dialog programmatically.\n */\nclass FilesDropzone extends HTMLElement {\n /** @type {Nullable<HTMLInputElement>} */\n #fileInput = null;\n\n /** @type {Nullable<HTMLElement>} */\n #dropzoneEl = null;\n\n constructor() {\n super();\n\n if (!this.shadowRoot) {\n const shadowRoot = this.attachShadow({ mode: 'open', delegatesFocus: true });\n shadowRoot.appendChild(template.content.cloneNode(true));\n }\n\n if (this.shadowRoot) {\n this.#fileInput = /** @type {Nullable<HTMLInputElement>} */ (this.shadowRoot.getElementById('file-input'));\n this.#dropzoneEl = this.shadowRoot.getElementById('dropzone');\n }\n }\n\n static get observedAttributes() {\n return ['accept', 'disabled', 'multiple'];\n }\n\n /**\n * Lifecycle method that is called when attributes are changed, added, removed, or replaced.\n *\n * @param {string} name - The name of the attribute.\n * @param {string} oldValue - The old value of the attribute.\n * @param {string} newValue - The new value of the attribute.\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (name === 'accept' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.accept = this.accept;\n }\n\n if (name === 'disabled' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.disabled = this.disabled;\n\n if (this.disabled) {\n this.#dropzoneEl?.removeAttribute('tabindex');\n this.#dropzoneEl?.setAttribute('aria-disabled', 'true');\n } else {\n this.#dropzoneEl?.setAttribute('tabindex', '0');\n this.#dropzoneEl?.setAttribute('aria-disabled', 'false');\n }\n }\n\n if (name === 'multiple' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.multiple = this.multiple;\n }\n }\n\n /**\n * Lifecycle method that is called when the element is added to the DOM.\n */\n connectedCallback() {\n this.#upgradeProperty('accept');\n this.#upgradeProperty('disabled');\n this.#upgradeProperty('maxFiles');\n this.#upgradeProperty('maxSize');\n this.#upgradeProperty('minSize');\n this.#upgradeProperty('multiple');\n this.#upgradeProperty('autoFocus');\n this.#upgradeProperty('noStyle');\n\n this.#fileInput?.addEventListener('change', this.#handleFileInputChange);\n this.#dropzoneEl?.addEventListener('dragenter', this.#handleDragEnter);\n this.#dropzoneEl?.addEventListener('dragover', this.#handleDragOver);\n this.#dropzoneEl?.addEventListener('dragleave', this.#handleDragLeave);\n this.#dropzoneEl?.addEventListener('drop', this.#handleDrop);\n this.#dropzoneEl?.addEventListener('click', this.#handleClick);\n this.#dropzoneEl?.addEventListener('keyup', this.#handleKeyUp);\n\n this.autoFocus && this.#dropzoneEl?.focus();\n }\n\n /**\n * Lifecycle method that is called when the element is removed from the DOM.\n */\n disconnectedCallback() {\n this.#fileInput?.removeEventListener('change', this.#handleFileInputChange);\n this.#dropzoneEl?.removeEventListener('dragenter', this.#handleDragEnter);\n this.#dropzoneEl?.removeEventListener('dragover', this.#handleDragOver);\n this.#dropzoneEl?.removeEventListener('dragleave', this.#handleDragLeave);\n this.#dropzoneEl?.removeEventListener('drop', this.#handleDrop);\n this.#dropzoneEl?.removeEventListener('click', this.#handleClick);\n this.#dropzoneEl?.removeEventListener('keyup', this.#handleKeyUp);\n }\n\n /**\n * @type {string} - A comma-separated list of unique file type specifiers describing file types to allow.\n * @attribute accept - Reflects the accept property.\n */\n get accept() {\n return this.getAttribute('accept') || '';\n }\n\n set accept(value) {\n this.setAttribute('accept', value != null ? value.toString() : value);\n }\n\n /**\n * @type {boolean} - Determines whether the dropzone is disabled.\n * @default false\n * @attribute disabled - Reflects the disabled property.\n */\n get disabled() {\n return this.hasAttribute('disabled');\n }\n\n set disabled(value) {\n this.toggleAttribute('disabled', !!value);\n }\n\n /**\n * @type {number} - The maximum number of files allowed to be dropped.\n * @default Infinity\n * @attribute max-files - Reflects the maxFiles property.\n */\n get maxFiles() {\n const num = Number(this.getAttribute('max-files')) || 0;\n\n if (num <= 0) {\n return Infinity;\n }\n\n return Math.floor(Math.abs(num));\n }\n\n set maxFiles(value) {\n this.setAttribute('max-files', value != null ? value.toString() : value);\n }\n\n /**\n * @type {number} - The maximum file size allowed in bytes.\n * @default Infinity\n * @attribute max-size - Reflects the maxSize property.\n */\n get maxSize() {\n const value = this.getAttribute('max-size');\n\n if (value === null) {\n return Infinity;\n }\n\n const num = Number(value);\n\n return Number.isNaN(num) ? Infinity : num;\n }\n\n set maxSize(value) {\n this.setAttribute('max-size', value != null ? value.toString() : value);\n }\n\n /**\n * @type {number} - The minimum file size allowed in bytes.\n * @default 0\n * @attribute min-size - Reflects the minSize property.\n */\n get minSize() {\n const value = this.getAttribute('min-size');\n\n if (value === null) {\n return 0;\n }\n\n const num = Number(value);\n\n return Number.isNaN(num) ? 0 : num;\n }\n\n set minSize(value) {\n this.setAttribute('min-size', value != null ? value.toString() : value);\n }\n\n /**\n * @type {boolean} - Allows multiple files to be dropped.\n * @default false\n * @attribute multiple - Reflects the multiple property.\n */\n get multiple() {\n return this.hasAttribute('multiple');\n }\n\n set multiple(value) {\n this.toggleAttribute('multiple', !!value);\n }\n\n /**\n * @type {boolean} - Automatically focuses the dropzone when it's connected to the DOM.\n * @default false\n * @attribute auto-focus - Reflects the autoFocus property.\n */\n get autoFocus() {\n return this.hasAttribute('auto-focus');\n }\n\n set autoFocus(value) {\n this.toggleAttribute('auto-focus', !!value);\n }\n\n /**\n * @type {boolean} - Prevents the dropzone from applying any styling.\n * @default false\n * @attribute no-style - Reflects the noStyle property.\n */\n get noStyle() {\n return this.hasAttribute('no-style');\n }\n\n set noStyle(value) {\n this.toggleAttribute('no-style', !!value);\n }\n\n /**\n * Handles the change event of the file input.\n *\n * @param {*} evt - The event object.\n */\n #handleFileInputChange = async evt => {\n try {\n this.#handleFilesSelect(await getFilesFromEvent(evt));\n } catch (error) {\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-error`, {\n bubbles: true,\n composed: true,\n detail: { error }\n })\n );\n }\n };\n\n /**\n * Handles the dragenter event of the dropzone.\n */\n #handleDragEnter = () => {\n if (this.disabled) {\n return;\n }\n\n this.dispatchEvent(\n new Event(`${COMPONENT_NAME}-dragenter`, {\n bubbles: true,\n composed: true\n })\n );\n };\n\n /**\n * Handles the dragover event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleDragOver = evt => {\n evt.preventDefault();\n\n if (this.disabled) {\n evt.dataTransfer.dropEffect = 'none';\n return;\n }\n\n evt.dataTransfer.dropEffect = 'copy';\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.add('dropzone--dragover');\n this.#dropzoneEl.part.add('dropzone--dragover');\n }\n\n this.dispatchEvent(\n new Event(`${COMPONENT_NAME}-dragover`, {\n bubbles: true,\n composed: true\n })\n );\n };\n\n /**\n * Handles the dragleave event of the dropzone.\n */\n #handleDragLeave = () => {\n if (this.disabled) {\n return;\n }\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.remove('dropzone--dragover');\n this.#dropzoneEl.part.remove('dropzone--dragover');\n }\n\n this.dispatchEvent(\n new Event(`${COMPONENT_NAME}-dragleave`, {\n bubbles: true,\n composed: true\n })\n );\n };\n\n /**\n * Handles the drop event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleDrop = async evt => {\n if (this.disabled) {\n return;\n }\n\n evt.preventDefault();\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.remove('dropzone--dragover');\n this.#dropzoneEl.part.remove('dropzone--dragover');\n }\n\n try {\n this.#handleFilesSelect(await getFilesFromEvent(evt));\n } catch (error) {\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-error`, {\n bubbles: true,\n composed: true,\n detail: { error }\n })\n );\n }\n };\n\n /**\n * Handles the click event of the dropzone.\n */\n #handleClick = () => {\n if (this.disabled) {\n return;\n }\n\n this.#fileInput?.click();\n };\n\n /**\n * Handles the keyup event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleKeyUp = evt => {\n if (this.disabled) {\n return;\n }\n\n if (evt.key === ' ' || evt.key === 'Enter') {\n this.#fileInput?.click();\n }\n };\n\n /**\n * Handles the selection of files.\n *\n * @param {File[]} files - The files to handle.\n */\n #handleFilesSelect(files) {\n if (!Array.isArray(files) || !files.length) {\n return;\n }\n\n const acceptedFiles = [];\n const rejectedFiles = [];\n const filesLength = files.length;\n\n // If the component is not in multiple mode, reject all files.\n if (!this.multiple && filesLength > 1) {\n for (const file of files) {\n rejectedFiles.push({\n file,\n errors: [\n {\n code: TOO_MANY_FILES,\n message: `Too many files selected. Only 1 file is allowed.`\n }\n ]\n });\n }\n } else if (this.multiple && filesLength > this.maxFiles) {\n // If the component is in multiple mode, but the number of files exceeds\n // the maxFiles attribute, reject all files.\n for (const file of files) {\n rejectedFiles.push({\n file,\n errors: [\n {\n code: TOO_MANY_FILES,\n message: `Too many files selected. Only ${this.maxFiles} ${this.maxFiles > 1 ? 'files are' : 'file is'} allowed.`\n }\n ]\n });\n }\n } else {\n // Validate each file. If it's valid, add it to the accepted files array,\n // otherwise add it to the rejected files array.\n for (const file of files) {\n const fileHasValidType = isValidFile(file, this.accept);\n const fileExceedsMaxSize = file.size > this.maxSize;\n const fileIsSmallerThanMinSize = file.size < this.minSize;\n\n if (fileHasValidType && !fileExceedsMaxSize && !fileIsSmallerThanMinSize) {\n acceptedFiles.push(file);\n } else {\n const errors = [];\n\n if (!fileHasValidType) {\n errors.push({\n code: INVALID_MIME_TYPE,\n message: `File type \"${file.type}\" is not accepted.`\n });\n }\n\n if (fileExceedsMaxSize) {\n errors.push({\n code: FILE_TOO_LARGE,\n message: `File size ${file.size} exceeds the maximum size of ${this.maxSize}.`\n });\n }\n\n if (fileIsSmallerThanMinSize) {\n errors.push({\n code: FILE_TOO_SMALL,\n message: `File size ${file.size} is smaller than the minimum size of ${this.minSize}.`\n });\n }\n\n rejectedFiles.push({ file, errors });\n }\n }\n }\n\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-drop`, {\n bubbles: true,\n composed: true,\n detail: {\n acceptedFiles,\n rejectedFiles\n }\n })\n );\n\n if (acceptedFiles.length > 0) {\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-drop-accepted`, {\n bubbles: true,\n composed: true,\n detail: {\n acceptedFiles\n }\n })\n );\n }\n\n if (rejectedFiles.length > 0) {\n this.dispatchEvent(\n new CustomEvent(`${COMPONENT_NAME}-drop-rejected`, {\n bubbles: true,\n composed: true,\n detail: {\n rejectedFiles\n }\n })\n );\n }\n\n if (this.#fileInput) {\n this.#fileInput.value = this.#fileInput.defaultValue;\n }\n }\n\n /**\n * Opens the file dialog programmatically.\n */\n openFileDialog() {\n if (this.disabled) {\n return;\n }\n\n this.#fileInput?.click();\n }\n\n /**\n * This is to safe guard against cases where, for instance, a framework may have added the element to the page and set a\n * value on one of its properties, but lazy loaded its definition. Without this guard, the upgraded element would miss that\n * property and the instance property would prevent the class property setter from ever being called.\n *\n * https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties\n *\n * @param {'accept' | 'disabled' | 'maxFiles' | 'maxSize' | 'minSize' | 'multiple' | 'autoFocus' | 'noStyle'} prop - The property name to upgrade.\n */\n #upgradeProperty(prop) {\n /** @type {any} */\n const instance = this;\n\n if (Object.prototype.hasOwnProperty.call(instance, prop)) {\n const value = instance[prop];\n delete instance[prop];\n instance[prop] = value;\n }\n }\n\n /**\n * Defines a custom element with the given name.\n * The name must contain a dash (-).\n *\n * @param {string} [elementName='files-dropzone'] - The name of the custom element.\n * @example\n *\n * FilesDropzone.defineCustomElement('my-dropzone');\n */\n static defineCustomElement(elementName = COMPONENT_NAME) {\n if (typeof window !== 'undefined' && !window.customElements.get(elementName)) {\n window.customElements.define(elementName, FilesDropzone);\n }\n }\n}\n\nexport { FilesDropzone };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AASO,SAASA,EAAYC,EAAMC,EAAyB,GAAI,CAC7D,GAAI,CAACA,EACH,MAAO,GAGT,IAAMC,EAAwB,CAC5B,GAAG,IAAI,IACLD,EACG,MAAM,GAAG,EACT,IAAIE,GAAKA,EAAE,KAAK,CAAC,EACjB,OAAO,OAAO,CACnB,CACF,EAEMC,EAAeJ,EAAK,KACpBK,EAAeD,EAAa,QAAQ,QAAS,EAAE,EAErD,QAAWE,KAAaJ,EACtB,GAAII,EAAU,OAAO,CAAC,IAAM,KAC1B,GAAIN,EAAK,KAAK,YAAY,EAAE,QAAQM,EAAU,YAAY,EAAGN,EAAK,KAAK,OAASM,EAAU,MAAM,IAAM,GACpG,MAAO,WAEA,QAAQ,KAAKA,CAAS,GAE/B,GAAID,IAAiBC,EAAU,QAAQ,QAAS,EAAE,EAChD,MAAO,WAGLF,IAAiBE,EACnB,MAAO,GAKb,MAAO,EACT,CCvCA,IAAMC,EAAoB,IAAI,IAAI,CAEhC,CAAC,MAAO,WAAW,EACnB,CAAC,MAAO,uBAAuB,EAC/B,CAAC,MAAO,uBAAuB,EAC/B,CAAC,OAAQ,YAAY,EACrB,CAAC,MAAO,iBAAiB,EACzB,CAAC,MAAO,8BAA8B,EACtC,CAAC,MAAO,0BAA0B,EAClC,CAAC,MAAO,WAAW,EACnB,CAAC,KAAM,oBAAoB,EAC3B,CAAC,MAAO,qBAAqB,EAC7B,CAAC,MAAO,mBAAmB,EAC3B,CAAC,MAAO,mBAAmB,EAC3B,CAAC,MAAO,UAAU,EAClB,CAAC,MAAO,UAAU,EAClB,CAAC,MAAO,oBAAoB,EAC5B,CAAC,OAAQ,yEAAyE,EAClF,CAAC,MAAO,+BAA+B,EACvC,CAAC,OAAQ,sBAAsB,EAC/B,CAAC,KAAM,kBAAk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imeTypesList", "v", "fileMimeType", "baseMimeType", "validType", "COMMON_MIME_TYPES", "FILES_TO_IGNORE", "toFileWithMimeType", "file", "name", "extension", "type", "toFileWithPath", "path", "fileWithMimeType", "webkitRelativePath", "readEntriesPromise", "directoryReader", "resolve", "reject", "readAllDirectoryEntries", "entries", "readEntries", "getFileFromFileEntry", "fileEntry", "getFilesFromDataTransferItemList", "dataTransferItemList", "files", "queue", "item", "entry", "getFilesFromFileList", "fileList", "getFilesFromEvent", "evt", "
|
|
4
|
+
"sourcesContent": ["// @ts-check\n\n/**\n * Checks if a file is valid based on the accepted file type specifiers.\n *\n * @param {File} file - The File object to validate.\n * @param {string} [acceptedTypeSpecifiers=''] - The accepted file type specifiers.\n * @returns {boolean} - True if the file is valid, false otherwise.\n */\nexport function isValidFile(file, acceptedTypeSpecifiers = '') {\n if (!acceptedTypeSpecifiers) {\n return true;\n }\n\n const acceptedMimeTypesList = [\n ...new Set(\n acceptedTypeSpecifiers\n .split(',')\n .map(v => v.trim())\n .filter(Boolean)\n )\n ];\n\n const fileMimeType = file.type;\n const baseMimeType = fileMimeType.replace(/\\/.*$/, '');\n\n for (const validType of acceptedMimeTypesList) {\n if (validType.charAt(0) === '.') {\n if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) {\n return true;\n }\n } else if (/\\/\\*$/.test(validType)) {\n // Check for mime type that looks like \"image/*\" or similar.\n if (baseMimeType === validType.replace(/\\/.*$/, '')) {\n return true;\n }\n } else {\n if (fileMimeType === validType) {\n return true;\n }\n }\n }\n\n return false;\n}\n", "// @ts-check\n\n/**\n * A map of common file extensions and their associated MIME types.\n */\nconst COMMON_MIME_TYPES = new Map([\n // https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\n ['aac', 'audio/aac'],\n ['abw', 'application/x-abiword'],\n ['arc', 'application/x-freearc'],\n ['avif', 'image/avif'],\n ['avi', 'video/x-msvideo'],\n ['azw', 'application/vnd.amazon.ebook'],\n ['bin', 'application/octet-stream'],\n ['bmp', 'image/bmp'],\n ['bz', 'application/x-bzip'],\n ['bz2', 'application/x-bzip2'],\n ['cda', 'application/x-cdf'],\n ['csh', 'application/x-csh'],\n ['css', 'text/css'],\n ['csv', 'text/csv'],\n ['doc', 'application/msword'],\n ['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],\n ['eot', 'application/vnd.ms-fontobject'],\n ['epub', 'application/epub+zip'],\n ['gz', 'application/gzip'],\n ['gif', 'image/gif'],\n ['heic', 'image/heic'],\n ['heif', 'image/heif'],\n ['htm', 'text/html'],\n ['html', 'text/html'],\n ['ico', 'image/vnd.microsoft.icon'],\n ['ics', 'text/calendar'],\n ['jar', 'application/java-archive'],\n ['jpeg', 'image/jpeg'],\n ['jpg', 'image/jpeg'],\n ['jxl', 'image/jxl'],\n ['js', 'text/javascript'],\n ['json', 'application/json'],\n ['jsonld', 'application/ld+json'],\n ['markdown', 'text/markdown'],\n ['md', 'text/markdown'],\n ['mid', 'audio/midi'],\n ['midi', 'audio/midi'],\n ['mjs', 'text/javascript'],\n ['mp3', 'audio/mpeg'],\n ['mp4', 'video/mp4'],\n ['mpeg', 'video/mpeg'],\n ['mpkg', 'application/vnd.apple.installer+xml'],\n ['odp', 'application/vnd.oasis.opendocument.presentation'],\n ['ods', 'application/vnd.oasis.opendocument.spreadsheet'],\n ['odt', 'application/vnd.oasis.opendocument.text'],\n ['oga', 'audio/ogg'],\n ['ogv', 'video/ogg'],\n ['ogx', 'application/ogg'],\n ['opus', 'audio/opus'],\n ['otf', 'font/otf'],\n ['png', 'image/png'],\n ['pdf', 'application/pdf'],\n ['php', 'application/x-httpd-php'],\n ['ppt', 'application/vnd.ms-powerpoint'],\n ['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],\n ['rar', 'application/vnd.rar'],\n ['rtf', 'application/rtf'],\n ['sh', 'application/x-sh'],\n ['svg', 'image/svg+xml'],\n ['swf', 'application/x-shockwave-flash'],\n ['tar', 'application/x-tar'],\n ['tif', 'image/tiff'],\n ['tiff', 'image/tiff'],\n ['ts', 'video/mp2t'],\n ['ttf', 'font/ttf'],\n ['txt', 'text/plain'],\n ['vsd', 'application/vnd.visio'],\n ['wav', 'audio/wav'],\n ['weba', 'audio/webm'],\n ['webm', 'video/webm'],\n ['webp', 'image/webp'],\n ['woff', 'font/woff'],\n ['woff2', 'font/woff2'],\n ['xhtml', 'application/xhtml+xml'],\n ['xls', 'application/vnd.ms-excel'],\n ['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],\n ['xml', 'application/xml'],\n ['xul', 'application/vnd.mozilla.xul+xml'],\n ['zip', 'application/zip'],\n ['7z', 'application/x-7z-compressed'],\n\n // Others\n ['mkv', 'video/x-matroska'],\n ['mov', 'video/quicktime'],\n ['msg', 'application/vnd.ms-outlook']\n]);\n\nconst FILES_TO_IGNORE = [\n // Thumbnail cache files for macOS and Windows\n '.DS_Store', // macOs\n 'Thumbs.db' // Windows\n];\n\n/**\n * Adds a `type` property to the file object if it doesn't have one and the file has an extension.\n * This is needed because Firefox doesn't add a type property to files dragged from the desktop.\n * @bug https://bugzilla.mozilla.org/show_bug.cgi?id=1424689\n *\n * @param {File} file - The file object to add the type property to.\n * @returns {File} - The file object with the type property added.\n */\nconst toFileWithMimeType = file => {\n const { name } = file;\n const hasExtension = name && name.lastIndexOf('.') !== -1;\n\n if (hasExtension && !file.type) {\n const extension = (name.split('.').pop() || '').toLowerCase();\n const type = COMMON_MIME_TYPES.get(extension);\n\n if (type) {\n Object.defineProperty(file, 'type', {\n value: type,\n writable: false,\n configurable: false,\n enumerable: true\n });\n }\n }\n\n return file;\n};\n\n/**\n * Adds a `path` property to the file object if it doesn't have one.\n * If `path` is not provided, the `webkitRelativePath` property of the file will be used\n * or the file's name if `webkitRelativePath` is not available.\n *\n * @param {File} file - The file object to add the path property to.\n * @param {string} [path] - The path to set on the file object.\n * @returns {File} - The file object with the path property added.\n */\nconst toFileWithPath = (file, path) => {\n const fileWithMimeType = toFileWithMimeType(file);\n\n // @ts-ignore\n if (typeof fileWithMimeType.path !== 'string') {\n const { webkitRelativePath } = file;\n\n Object.defineProperty(fileWithMimeType, 'path', {\n value: typeof path === 'string' ? path : webkitRelativePath || file.name,\n writable: false,\n configurable: false,\n enumerable: true\n });\n }\n\n return fileWithMimeType;\n};\n\n/**\n * Wrap `FileSystemDirectoryReader.readEntries` in a promise to make working with read entries easier.\n * https://developer.mozilla.org/docs/Web/API/FileSystemDirectoryReader/readEntries\n *\n * @param {FileSystemDirectoryReader} directoryReader - The directory reader to read entries from.\n * @returns {Promise<FileSystemEntry[]>} - A promise that resolves with an array of `FileSystemEntry` objects.\n */\nconst readEntriesPromise = async directoryReader => {\n return await new Promise((resolve, reject) => {\n directoryReader.readEntries(resolve, reject);\n });\n};\n\n/**\n * Read all entries in a directory or sub-directory\n * by calling `readEntries` until it returns an empty array.\n *\n * @param {FileSystemDirectoryReader} directoryReader - The directory reader to read entries from.\n * @returns {Promise<FileSystemEntry[]>} - A promise that resolves with an array of `FileSystemEntry` objects.\n */\nconst readAllDirectoryEntries = async directoryReader => {\n const entries = [];\n let readEntries = await readEntriesPromise(directoryReader);\n\n while (readEntries.length > 0) {\n entries.push(...readEntries);\n readEntries = await readEntriesPromise(directoryReader);\n }\n\n return entries;\n};\n\n/**\n * Get a `File` object from a `FileSystemFileEntry` object.\n *\n * @param {FileSystemFileEntry} fileEntry - The file entry to get a `File` object from.\n * @returns {Promise<File>} - A promise that resolves with a `File` object.\n */\nconst getFileFromFileEntry = fileEntry => {\n return new Promise((resolve, reject) => {\n fileEntry.file(file => resolve(toFileWithPath(file, fileEntry.fullPath)), reject);\n });\n};\n\n/**\n * Get an array of `File` objects from a `DataTransferItemList` object.\n *\n * @param {DataTransferItemList} dataTransferItemList - The item list to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nconst getFilesFromDataTransferItemList = async dataTransferItemList => {\n const files = [];\n\n // Chromium browsers read only 100 files at a time as per the spec, so we need to use\n // BFS (Breadth-first search) to traverse the entire directory/file structure.\n // https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#javascript_content\n const queue = [];\n\n for (const item of dataTransferItemList) {\n if (item.kind !== 'file') {\n // Ignore non-file items, such as links.\n continue;\n }\n\n // https://developer.mozilla.org/docs/Web/API/DataTransferItem/webkitGetAsEntry\n // This function is implemented as `webkitGetAsEntry()` in non-WebKit browsers\n // including Firefox at this time but it may be renamed to `getAsEntry()` in the future.\n // @ts-ignore\n const entry = item.getAsEntry ? item.getAsEntry() : item.webkitGetAsEntry();\n\n queue.push(entry);\n }\n\n while (queue.length > 0) {\n const entry = queue.shift();\n\n if (!entry) {\n continue;\n } else if (entry.isFile) {\n const file = await getFileFromFileEntry(entry);\n\n if (FILES_TO_IGNORE.indexOf(file.name) === -1) {\n files.push(file);\n }\n } else if (entry.isDirectory) {\n queue.push(...(await readAllDirectoryEntries(entry.createReader())));\n }\n }\n\n return files;\n};\n\n/**\n * Get an array of `File` objects from a `FileList` object.\n *\n * @param {FileList} fileList - The file list to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nconst getFilesFromFileList = async fileList => {\n const files = [];\n\n for (const file of fileList) {\n if (FILES_TO_IGNORE.indexOf(file.name) === -1) {\n files.push(toFileWithPath(file));\n }\n }\n\n return files;\n};\n\n/**\n * Get an array of `File` objects from an event.\n * This function supports both `drop` and `change` events.\n *\n * @param {*} evt - The event to get an array of `File` objects from.\n * @returns {Promise<File[]>} - A promise that resolves with an array of `File` objects.\n */\nexport const getFilesFromEvent = async evt => {\n if (evt.dataTransfer) {\n return evt.dataTransfer.items\n ? await getFilesFromDataTransferItemList(evt.dataTransfer.items)\n : await getFilesFromFileList(evt.dataTransfer.files);\n }\n\n return await getFilesFromFileList(evt.target.files);\n};\n", "// @ts-check\n\n/**\n * Represents a value that may be of type T, or null.\n *\n * @template T\n * @typedef {T | null} Nullable\n */\n\n/**\n * Stable identifier for error codes used in the `files-dropzone-error` event.\n *\n * @typedef {typeof FilesDropzone.ERROR_CODES[keyof typeof FilesDropzone.ERROR_CODES]} FilesDropzoneErrorCode\n */\n\n/**\n * The detail payload for the `files-dropzone-error` event.\n *\n * @typedef {Object} FilesDropzoneErrorDetail\n * @property {FilesDropzoneErrorCode} code - Stable identifier for the type of error that occurred.\n * @property {unknown} error - The underlying error object or value that triggered the event.\n */\n\n/**\n * Stable identifier for rejection codes used in the various drop-related events.\n *\n * @typedef {typeof FilesDropzone.REJECTION_CODES[keyof typeof FilesDropzone.REJECTION_CODES]} FilesDropzoneRejectionCode\n */\n\nimport { isValidFile } from './utils/is-valid-file.js';\nimport { getFilesFromEvent } from './utils/files-selector.js';\n\nconst css = String.raw;\nconst html = String.raw;\nconst COMPONENT_NAME = 'files-dropzone';\nconst template = document.createElement('template');\n\nconst styles = css`\n *,\n *::before,\n *::after {\n box-sizing: border-box;\n }\n\n :host([hidden]),\n [hidden] {\n display: none !important;\n }\n\n :host {\n --dropzone-border-width: 2px;\n --dropzone-border-style: dashed;\n --dropzone-border-radius: 0.25rem;\n --dropzone-border-color: #6c757d;\n --dropzone-border-color-dragover: #0d6efd;\n --dropzone-border-color-hover: var(--dropzone-border-color-dragover);\n --dropzone-background-color: #ffffff;\n --dropzone-background-color-dragover: #f4f4f5;\n --dropzone-background-color-hover: var(--dropzone-background-color-dragover);\n --dropzone-body-color: #3f3f46;\n --dropzone-body-color-dragover: var(--dropzone-body-color);\n --dropzone-body-color-hover: var(--dropzone-body-color-dragover);\n --dropzone-focus-shadow-rgb: 49, 132, 253;\n --dropzone-focus-box-shadow: 0 0 0 0.25rem rgba(var(--dropzone-focus-shadow-rgb), 0.5);\n --transition-duration: 0.2s; /* for backwards compatibility */\n --dropzone-transition-duration: var(--transition-duration);\n\n display: block;\n }\n\n :host(:not([no-style])) .dropzone {\n border: var(--dropzone-border-width) var(--dropzone-border-style) var(--dropzone-border-color);\n border-radius: var(--dropzone-border-radius);\n padding: 3rem 1rem;\n overflow: hidden;\n background-color: var(--dropzone-background-color);\n color: var(--dropzone-body-color);\n text-align: center;\n cursor: pointer;\n transition:\n border var(--dropzone-transition-duration) ease-in-out,\n background-color var(--dropzone-transition-duration) ease-in-out,\n color var(--dropzone-transition-duration) ease-in-out,\n box-shadow var(--dropzone-transition-duration) ease-in-out;\n }\n\n :host(:not([no-style])[disabled]) .dropzone {\n opacity: 0.8;\n cursor: not-allowed;\n user-select: none;\n }\n\n :host(:not([no-style]):not([disabled])) .dropzone--dragover {\n border-color: var(--dropzone-border-color-dragover);\n background-color: var(--dropzone-background-color-dragover);\n color: var(--dropzone-body-color-dragover);\n }\n\n :host(:not([no-style]):not([disabled])) .dropzone:focus-visible {\n outline: none;\n box-shadow: var(--dropzone-focus-box-shadow);\n }\n\n @media (hover: hover) {\n :host(:not([no-style]):not([disabled])) .dropzone:not(.dropzone--dragover):hover {\n border-color: var(--dropzone-border-color-hover);\n background-color: var(--dropzone-background-color-hover);\n color: var(--dropzone-body-color-hover);\n }\n }\n`;\n\ntemplate.innerHTML = html`\n <style>\n ${styles}\n </style>\n\n <input type=\"file\" id=\"file-input\" hidden />\n\n <div part=\"dropzone\" class=\"dropzone\" id=\"dropzone\" tabindex=\"0\" role=\"button\" aria-disabled=\"false\">\n <slot><span>Drag 'n' drop files here, or click to select files</span></slot>\n </div>\n`;\n\n/**\n * @summary A custom element that allows users to drag and drop files into it.\n * @documentation https://github.com/georapbox/files-dropzone-element\n *\n * @tagname files-dropzone - This is the default tag name, unless overridden by the `defineCustomElement` method.\n *\n * @property {string} accept - A comma-separated list of unique file type specifiers describing file types to allow.\n * @property {boolean} disabled - Determines whether the dropzone is disabled.\n * @property {number} maxFiles - The maximum number of files allowed to be dropped.\n * @property {number} maxSize - The maximum file size allowed in bytes.\n * @property {number} minSize - The minimum file size allowed in bytes.\n * @property {boolean} multiple - Allows multiple files to be dropped.\n * @property {boolean} autoFocus - Automatically focuses the dropzone when it's connected to the DOM.\n * @property {boolean} noStyle - Prevents the dropzone from applying any styling.\n *\n * @attribute {string} accept - Reflects the accept property.\n * @attribute {boolean} disabled - Reflects the disabled property.\n * @attribute {number} max-files - Reflects the maxFiles property.\n * @attribute {number} max-size - Reflects the maxSize property.\n * @attribute {number} min-size - Reflects the minSize property.\n * @attribute {boolean} multiple - Reflects the multiple property.\n * @attribute {boolean} auto-focus - Reflects the autoFocus property.\n * @attribute {boolean} no-style - Reflects the noStyle property.\n *\n * @slot - The default slot content of the dropzone.\n *\n * @csspart dropzone - The dropzone element.\n * @csspart dropzone--dragover - The state of the dropzone when dragging over it.\n *\n * @cssproperty --dropzone-border-width - The border width of the dropzone.\n * @cssproperty --dropzone-border-style - The border style of the dropzone.\n * @cssproperty --dropzone-border-radius - The border radius of the dropzone.\n * @cssproperty --dropzone-border-color - The border color of the dropzone.\n * @cssproperty --dropzone-border-color-dragover - The border color of the dropzone when dragging over it.\n * @cssproperty --dropzone-border-color-hover - The border color of the dropzone when hovering over it.\n * @cssproperty --dropzone-background-color - The background color of the dropzone.\n * @cssproperty --dropzone-background-color-dragover - The background color of the dropzone when dragging over it.\n * @cssproperty --dropzone-background-color-hover - The background color of the dropzone when hovering over it.\n * @cssproperty --dropzone-body-color - The text color of the dropzone.\n * @cssproperty --dropzone-body-color-dragover - The text color of the dropzone when dragging over it.\n * @cssproperty --dropzone-body-color-hover - The text color of the dropzone when hovering over it.\n * @cssproperty --dropzone-focus-shadow-rgb - The RGB value of the dropzone's focus shadow.\n * @cssproperty --dropzone-focus-box-shadow - The box shadow of the dropzone when focused.\n * @cssproperty --dropzone-transition-duration - The transition's duration for the dropzone area.\n *\n * @event files-dropzone-drop - Fired when files are dropped.\n * @event files-dropzone-drop-accepted - Fired when files dropped files are accepted.\n * @event files-dropzone-drop-rejected - Fired when files dropped files are rejected.\n * @event files-dropzone-dragenter - Fired when files are dragged into the dropzone.\n * @event files-dropzone-dragover - Fired when files are dragged over the dropzone.\n * @event files-dropzone-dragleave - Fired when files are dragged out of the dropzone.\n * @event files-dropzone-error - Fired when there is any error in the process of reading dropped files or directories.\n *\n * @method defineCustomElement - Static method. Defines a custom element with the given name.\n * @method openFileDialog - Instance method. Opens the file dialog programmatically.\n */\nclass FilesDropzone extends HTMLElement {\n /**\n * Central list of error codes used in drop error event.\n * @readonly\n */\n static ERROR_CODES = /** @type {const} */ ({\n FILE_DIALOG_OPEN_FAILED: 'FILE_DIALOG_OPEN_FAILED',\n FILE_INPUT_CHANGE_FAILED: 'FILE_INPUT_CHANGE_FAILED',\n DROP_EVENT_PROCESSING_FAILED: 'DROP_EVENT_PROCESSING_FAILED',\n UNKNOWN_ERROR: 'UNKNOWN_ERROR'\n });\n\n /**\n * Central list of rejection codes for files that are rejected during the drop process.\n * @readonly\n */\n static REJECTION_CODES = /** @type {const} */ ({\n TOO_MANY_FILES: 'TOO_MANY_FILES',\n FILE_TOO_LARGE: 'FILE_TOO_LARGE',\n FILE_TOO_SMALL: 'FILE_TOO_SMALL',\n INVALID_MIME_TYPE: 'INVALID_MIME_TYPE'\n });\n\n /** @type {Nullable<HTMLInputElement>} */\n #fileInput = null;\n\n /** @type {Nullable<HTMLElement>} */\n #dropzoneEl = null;\n\n constructor() {\n super();\n\n if (!this.shadowRoot) {\n const shadowRoot = this.attachShadow({ mode: 'open', delegatesFocus: true });\n shadowRoot.appendChild(template.content.cloneNode(true));\n }\n\n if (this.shadowRoot) {\n this.#fileInput = /** @type {Nullable<HTMLInputElement>} */ (this.shadowRoot.getElementById('file-input'));\n this.#dropzoneEl = this.shadowRoot.getElementById('dropzone');\n }\n }\n\n static get observedAttributes() {\n return ['accept', 'disabled', 'multiple'];\n }\n\n /**\n * Lifecycle method that is called when attributes are changed, added, removed, or replaced.\n *\n * @param {string} name - The name of the attribute.\n * @param {string} oldValue - The old value of the attribute.\n * @param {string} newValue - The new value of the attribute.\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (name === 'accept' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.accept = this.accept;\n }\n\n if (name === 'disabled' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.disabled = this.disabled;\n\n if (this.disabled) {\n this.#dropzoneEl?.removeAttribute('tabindex');\n this.#dropzoneEl?.setAttribute('aria-disabled', 'true');\n } else {\n this.#dropzoneEl?.setAttribute('tabindex', '0');\n this.#dropzoneEl?.setAttribute('aria-disabled', 'false');\n }\n }\n\n if (name === 'multiple' && oldValue !== newValue && this.#fileInput) {\n this.#fileInput.multiple = this.multiple;\n }\n }\n\n /**\n * Lifecycle method that is called when the element is added to the DOM.\n */\n connectedCallback() {\n this.#upgradeProperty('accept');\n this.#upgradeProperty('disabled');\n this.#upgradeProperty('maxFiles');\n this.#upgradeProperty('maxSize');\n this.#upgradeProperty('minSize');\n this.#upgradeProperty('multiple');\n this.#upgradeProperty('autoFocus');\n this.#upgradeProperty('noStyle');\n\n this.#fileInput?.addEventListener('change', this.#handleFileInputChange);\n this.#dropzoneEl?.addEventListener('dragenter', this.#handleDragEnter);\n this.#dropzoneEl?.addEventListener('dragover', this.#handleDragOver);\n this.#dropzoneEl?.addEventListener('dragleave', this.#handleDragLeave);\n this.#dropzoneEl?.addEventListener('drop', this.#handleDrop);\n this.#dropzoneEl?.addEventListener('click', this.#handleClick);\n this.#dropzoneEl?.addEventListener('keyup', this.#handleKeyUp);\n\n this.autoFocus && this.#dropzoneEl?.focus();\n }\n\n /**\n * Lifecycle method that is called when the element is removed from the DOM.\n */\n disconnectedCallback() {\n this.#fileInput?.removeEventListener('change', this.#handleFileInputChange);\n this.#dropzoneEl?.removeEventListener('dragenter', this.#handleDragEnter);\n this.#dropzoneEl?.removeEventListener('dragover', this.#handleDragOver);\n this.#dropzoneEl?.removeEventListener('dragleave', this.#handleDragLeave);\n this.#dropzoneEl?.removeEventListener('drop', this.#handleDrop);\n this.#dropzoneEl?.removeEventListener('click', this.#handleClick);\n this.#dropzoneEl?.removeEventListener('keyup', this.#handleKeyUp);\n }\n\n /**\n * @type {string} - A comma-separated list of unique file type specifiers describing file types to allow.\n * @attribute accept - Reflects the accept property.\n */\n get accept() {\n return this.getAttribute('accept') || '';\n }\n\n set accept(value) {\n this.setAttribute('accept', value != null ? value.toString() : value);\n }\n\n /**\n * @type {boolean} - Determines whether the dropzone is disabled.\n * @default false\n * @attribute disabled - Reflects the disabled property.\n */\n get disabled() {\n return this.hasAttribute('disabled');\n }\n\n set disabled(value) {\n this.toggleAttribute('disabled', !!value);\n }\n\n /**\n * @type {number} - The maximum number of files allowed to be dropped.\n * @default Infinity\n * @attribute max-files - Reflects the maxFiles property.\n */\n get maxFiles() {\n const num = Number(this.getAttribute('max-files')) || 0;\n\n if (num <= 0) {\n return Infinity;\n }\n\n return Math.floor(Math.abs(num));\n }\n\n set maxFiles(value) {\n this.setAttribute('max-files', value != null ? value.toString() : value);\n }\n\n /**\n * @type {number} - The maximum file size allowed in bytes.\n * @default Infinity\n * @attribute max-size - Reflects the maxSize property.\n */\n get maxSize() {\n const value = this.getAttribute('max-size');\n\n if (value === null) {\n return Infinity;\n }\n\n const num = Number(value);\n\n return Number.isNaN(num) ? Infinity : num;\n }\n\n set maxSize(value) {\n this.setAttribute('max-size', value != null ? value.toString() : value);\n }\n\n /**\n * @type {number} - The minimum file size allowed in bytes.\n * @default 0\n * @attribute min-size - Reflects the minSize property.\n */\n get minSize() {\n const value = this.getAttribute('min-size');\n\n if (value === null) {\n return 0;\n }\n\n const num = Number(value);\n\n return Number.isNaN(num) ? 0 : num;\n }\n\n set minSize(value) {\n this.setAttribute('min-size', value != null ? value.toString() : value);\n }\n\n /**\n * @type {boolean} - Allows multiple files to be dropped.\n * @default false\n * @attribute multiple - Reflects the multiple property.\n */\n get multiple() {\n return this.hasAttribute('multiple');\n }\n\n set multiple(value) {\n this.toggleAttribute('multiple', !!value);\n }\n\n /**\n * @type {boolean} - Automatically focuses the dropzone when it's connected to the DOM.\n * @default false\n * @attribute auto-focus - Reflects the autoFocus property.\n */\n get autoFocus() {\n return this.hasAttribute('auto-focus');\n }\n\n set autoFocus(value) {\n this.toggleAttribute('auto-focus', !!value);\n }\n\n /**\n * @type {boolean} - Prevents the dropzone from applying any styling.\n * @default false\n * @attribute no-style - Reflects the noStyle property.\n */\n get noStyle() {\n return this.hasAttribute('no-style');\n }\n\n set noStyle(value) {\n this.toggleAttribute('no-style', !!value);\n }\n\n /**\n * Emit a custom event with the given name and detail.\n *\n * @template D\n * @param {string} name - The name of the event.\n * @param {D} [detail] - The detail payload of the event.\n * @param {CustomEventInit<D>} [init] - Override the default event initialization options.\n * @returns {boolean} - Returns false if at least one event listener called `preventDefault()`, otherwise true.\n */\n #emitEvent(name, detail, init) {\n const options = {\n bubbles: true,\n composed: true,\n cancelable: false,\n ...init,\n detail\n };\n const evt = new CustomEvent(`${COMPONENT_NAME}-${name}`, options);\n return this.dispatchEvent(evt);\n }\n\n /**\n * Emit a standardized error event with typed detail.\n *\n * @param {FilesDropzoneErrorCode} code - Stable identifier for the type of error that occurred.\n * @param {unknown} error - The underlying error that triggered the event.\n */\n #emitErrorEvent(code, error) {\n /** @type {FilesDropzoneErrorDetail} */\n const detail = { code, error };\n\n this.#emitEvent('error', detail);\n }\n\n /**\n * Handles the change event of the file input.\n *\n * @param {*} evt - The event object.\n */\n #handleFileInputChange = async evt => {\n try {\n this.#handleFilesSelect(await getFilesFromEvent(evt));\n } catch (err) {\n this.#emitErrorEvent(FilesDropzone.ERROR_CODES.FILE_INPUT_CHANGE_FAILED, err);\n }\n };\n\n /**\n * Handles the dragenter event of the dropzone.\n */\n #handleDragEnter = () => {\n if (this.disabled) {\n return;\n }\n\n this.#emitEvent('dragenter');\n };\n\n /**\n * Handles the dragover event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleDragOver = evt => {\n evt.preventDefault();\n\n if (this.disabled) {\n evt.dataTransfer.dropEffect = 'none';\n return;\n }\n\n evt.dataTransfer.dropEffect = 'copy';\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.add('dropzone--dragover');\n this.#dropzoneEl.part.add('dropzone--dragover');\n }\n\n this.#emitEvent('dragover');\n };\n\n /**\n * Handles the dragleave event of the dropzone.\n */\n #handleDragLeave = () => {\n if (this.disabled) {\n return;\n }\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.remove('dropzone--dragover');\n this.#dropzoneEl.part.remove('dropzone--dragover');\n }\n\n this.#emitEvent('dragleave');\n };\n\n /**\n * Handles the drop event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleDrop = async evt => {\n if (this.disabled) {\n return;\n }\n\n evt.preventDefault();\n\n if (this.#dropzoneEl) {\n this.#dropzoneEl.classList.remove('dropzone--dragover');\n this.#dropzoneEl.part.remove('dropzone--dragover');\n }\n\n try {\n this.#handleFilesSelect(await getFilesFromEvent(evt));\n } catch (err) {\n this.#emitErrorEvent(FilesDropzone.ERROR_CODES.DROP_EVENT_PROCESSING_FAILED, err);\n }\n };\n\n /**\n * Handles the click event of the dropzone.\n */\n #handleClick = () => {\n if (this.disabled) {\n return;\n }\n\n this.openFileDialog();\n };\n\n /**\n * Handles the keyup event of the dropzone.\n *\n * @param {*} evt - The event object.\n */\n #handleKeyUp = evt => {\n if (this.disabled) {\n return;\n }\n\n if (evt.key === ' ' || evt.key === 'Enter') {\n this.openFileDialog();\n }\n };\n\n /**\n * Handles the selection of files.\n *\n * @param {File[]} files - The files to handle.\n */\n #handleFilesSelect(files) {\n if (!Array.isArray(files) || !files.length) {\n return;\n }\n\n const acceptedFiles = [];\n const rejectedFiles = [];\n const filesLength = files.length;\n\n // If the component is not in multiple mode, reject all files.\n if (!this.multiple && filesLength > 1) {\n for (const file of files) {\n rejectedFiles.push({\n file,\n errors: [\n {\n code: FilesDropzone.REJECTION_CODES.TOO_MANY_FILES,\n message: `Too many files selected. Only 1 file is allowed.`\n }\n ]\n });\n }\n } else if (this.multiple && filesLength > this.maxFiles) {\n // If the component is in multiple mode, but the number of files exceeds\n // the maxFiles attribute, reject all files.\n for (const file of files) {\n rejectedFiles.push({\n file,\n errors: [\n {\n code: FilesDropzone.REJECTION_CODES.TOO_MANY_FILES,\n message: `Too many files selected. Only ${this.maxFiles} ${this.maxFiles > 1 ? 'files are' : 'file is'} allowed.`\n }\n ]\n });\n }\n } else {\n // Validate each file. If it's valid, add it to the accepted files array,\n // otherwise add it to the rejected files array.\n for (const file of files) {\n const fileHasValidType = isValidFile(file, this.accept);\n const fileExceedsMaxSize = file.size > this.maxSize;\n const fileIsSmallerThanMinSize = file.size < this.minSize;\n\n if (fileHasValidType && !fileExceedsMaxSize && !fileIsSmallerThanMinSize) {\n acceptedFiles.push(file);\n } else {\n const errors = [];\n\n if (!fileHasValidType) {\n errors.push({\n code: FilesDropzone.REJECTION_CODES.INVALID_MIME_TYPE,\n message: `File type \"${file.type}\" is not accepted.`\n });\n }\n\n if (fileExceedsMaxSize) {\n errors.push({\n code: FilesDropzone.REJECTION_CODES.FILE_TOO_LARGE,\n message: `File size ${file.size} exceeds the maximum size of ${this.maxSize}.`\n });\n }\n\n if (fileIsSmallerThanMinSize) {\n errors.push({\n code: FilesDropzone.REJECTION_CODES.FILE_TOO_SMALL,\n message: `File size ${file.size} is smaller than the minimum size of ${this.minSize}.`\n });\n }\n\n rejectedFiles.push({ file, errors });\n }\n }\n }\n\n this.#emitEvent('drop', { acceptedFiles, rejectedFiles });\n\n if (acceptedFiles.length > 0) {\n this.#emitEvent('drop-accepted', { acceptedFiles });\n }\n\n if (rejectedFiles.length > 0) {\n this.#emitEvent('drop-rejected', { rejectedFiles });\n }\n\n if (this.#fileInput) {\n this.#fileInput.value = this.#fileInput.defaultValue;\n }\n }\n\n /**\n * Opens the file dialog programmatically.\n */\n openFileDialog() {\n if (this.disabled || !this.#fileInput) {\n return;\n }\n\n // In modern browsers, use the showPicker() method if available.\n // This way we are able to detect if the file dialog was blocked by the browser\n // (e.g. if the method was called outside a user gesture event).\n if ('showPicker' in HTMLInputElement.prototype && typeof this.#fileInput.showPicker === 'function') {\n try {\n this.#fileInput.showPicker();\n } catch (err) {\n this.#emitErrorEvent(FilesDropzone.ERROR_CODES.FILE_DIALOG_OPEN_FAILED, err);\n }\n return;\n }\n\n // Fallback for browsers that do not support showPicker().\n // This may not work if the method is called outside a user gesture event.\n // In such cases, the browser may block the file dialog from opening but\n // most likely it won't throw an error rather just a warning in the console.\n this.#fileInput.click();\n }\n\n /**\n * This is to safe guard against cases where, for instance, a framework may have added the element to the page and set a\n * value on one of its properties, but lazy loaded its definition. Without this guard, the upgraded element would miss that\n * property and the instance property would prevent the class property setter from ever being called.\n *\n * https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties\n *\n * @param {'accept' | 'disabled' | 'maxFiles' | 'maxSize' | 'minSize' | 'multiple' | 'autoFocus' | 'noStyle'} prop - The property name to upgrade.\n */\n #upgradeProperty(prop) {\n /** @type {any} */\n const instance = this;\n\n if (Object.prototype.hasOwnProperty.call(instance, prop)) {\n const value = instance[prop];\n delete instance[prop];\n instance[prop] = value;\n }\n }\n\n /**\n * Defines a custom element with the given name.\n * The name must contain a dash (-).\n *\n * @param {string} [elementName='files-dropzone'] - The name of the custom element.\n * @example\n *\n * FilesDropzone.defineCustomElement('my-dropzone');\n */\n static defineCustomElement(elementName = COMPONENT_NAME) {\n if (typeof window !== 'undefined' && !window.customElements.get(elementName)) {\n window.customElements.define(elementName, FilesDropzone);\n }\n }\n}\n\nexport { FilesDropzone };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AASO,SAASA,EAAYC,EAAMC,EAAyB,GAAI,CAC7D,GAAI,CAACA,EACH,MAAO,GAGT,IAAMC,EAAwB,CAC5B,GAAG,IAAI,IACLD,EACG,MAAM,GAAG,EACT,IAAIE,GAAKA,EAAE,KAAK,CAAC,EACjB,OAAO,OAAO,CACnB,CACF,EAEMC,EAAeJ,EAAK,KACpBK,EAAeD,EAAa,QAAQ,QAAS,EAAE,EAErD,QAAWE,KAAaJ,EACtB,GAAII,EAAU,OAAO,CAAC,IAAM,KAC1B,GAAIN,EAAK,KA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KAAK,OAAO,GACrF,CAAC,EAGHF,EAAc,KAAK,CAAE,KAAAE,EAAM,OAAAK,CAAO,CAAC,CACrC,CACF,CAGF,KAAKpB,GAAW,OAAQ,CAAE,cAAAY,EAAe,cAAAC,CAAc,CAAC,EAEpDD,EAAc,OAAS,GACzB,KAAKZ,GAAW,gBAAiB,CAAE,cAAAY,CAAc,CAAC,EAGhDC,EAAc,OAAS,GACzB,KAAKb,GAAW,gBAAiB,CAAE,cAAAa,CAAc,CAAC,EAGhD,KAAK5B,KACP,KAAKA,GAAW,MAAQ,KAAKA,GAAW,aAE5C,CAKA,gBAAiB,CACf,GAAI,OAAK,UAAY,CAAC,KAAKA,IAO3B,IAAI,eAAgB,iBAAiB,WAAa,OAAO,KAAKA,GAAW,YAAe,WAAY,CAClG,GAAI,CACF,KAAKA,GAAW,WAAW,CAC7B,OAASyB,EAAK,CACZ,KAAKL,GAAgBrB,EAAc,YAAY,wBAAyB0B,CAAG,CAC7E,CACA,MACF,CAMA,KAAKzB,GAAW,MAAM,EACxB,CAWAK,GAAiB+B,EAAM,CAErB,IAAMC,EAAW,KAEjB,GAAI,OAAO,UAAU,eAAe,KAAKA,EAAUD,CAAI,EAAG,CACxD,IAAMvB,EAAQwB,EAASD,CAAI,EAC3B,OAAOC,EAASD,CAAI,EACpBC,EAASD,CAAI,EAAIvB,CACnB,CACF,CAWA,OAAO,oBAAoByB,EAAc3C,EAAgB,CACnD,OAAO,OAAW,KAAe,CAAC,OAAO,eAAe,IAAI2C,CAAW,GACzE,OAAO,eAAe,OAAOA,EAAavC,CAAa,CAE3D,CACF",
|
|
6
|
+
"names": ["isValidFile", "file", "acceptedTypeSpecifiers", "acceptedMimeTypesList", "v", "fileMimeType", "baseMimeType", "validType", "COMMON_MIME_TYPES", "FILES_TO_IGNORE", "toFileWithMimeType", "file", "name", "extension", "type", "toFileWithPath", "path", "fileWithMimeType", "webkitRelativePath", "readEntriesPromise", "directoryReader", "resolve", "reject", "readAllDirectoryEntries", "entries", "readEntries", "getFileFromFileEntry", "fileEntry", "getFilesFromDataTransferItemList", "dataTransferItemList", "files", "queue", "item", "entry", "getFilesFromFileList", "fileList", "getFilesFromEvent", "evt", "css", "html", "COMPONENT_NAME", "template", "styles", "FilesDropzone", "_FilesDropzone", "#fileInput", "#dropzoneEl", "name", "oldValue", "newValue", "#upgradeProperty", "#handleFileInputChange", "#handleDragEnter", "#handleDragOver", "#handleDragLeave", "#handleDrop", "#handleClick", "#handleKeyUp", "value", "num", "#emitEvent", "detail", "init", "options", "evt", "#emitErrorEvent", "code", "error", "#handleFilesSelect", "getFilesFromEvent", "err", "files", "acceptedFiles", "rejectedFiles", "filesLength", "file", "fileHasValidType", "isValidFile", "fileExceedsMaxSize", "fileIsSmallerThanMinSize", "errors", "prop", "instance", "elementName"]
|
|
7
7
|
}
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* @param {string} [acceptedTypeSpecifiers=''] - The accepted file type specifiers.
|
|
6
6
|
* @returns {boolean} - True if the file is valid, false otherwise.
|
|
7
7
|
*/
|
|
8
|
-
export function isValidFile(file: File, acceptedTypeSpecifiers?: string
|
|
8
|
+
export function isValidFile(file: File, acceptedTypeSpecifiers?: string): boolean;
|
|
9
9
|
//# sourceMappingURL=is-valid-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-valid-file.d.ts","sourceRoot":"","sources":["../../src/utils/is-valid-file.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,kCAJW,IAAI,
|
|
1
|
+
{"version":3,"file":"is-valid-file.d.ts","sourceRoot":"","sources":["../../src/utils/is-valid-file.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,kCAJW,IAAI,2BACJ,MAAM,GACJ,OAAO,CAqCnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@georapbox/files-dropzone-element",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "A custom element that creates a drag and drop zone for files",
|
|
5
5
|
"main": "dist/files-dropzone.js",
|
|
6
6
|
"module": "dist/files-dropzone.js",
|
|
@@ -46,23 +46,23 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://github.com/georapbox/files-dropzone-element#readme",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@eslint/js": "~9.
|
|
50
|
-
"@esm-bundle/chai": "~4.3.4
|
|
49
|
+
"@eslint/js": "~9.34.0",
|
|
50
|
+
"@esm-bundle/chai": "~4.3.4",
|
|
51
51
|
"@open-wc/testing": "~4.0.0",
|
|
52
52
|
"@web/dev-server": "~0.4.6",
|
|
53
|
-
"@web/test-runner": "~0.
|
|
53
|
+
"@web/test-runner": "~0.20.2",
|
|
54
54
|
"@web/test-runner-playwright": "~0.11.0",
|
|
55
|
-
"esbuild": "~0.
|
|
56
|
-
"eslint": "~9.
|
|
57
|
-
"eslint-plugin-wc": "~
|
|
58
|
-
"globals": "~
|
|
55
|
+
"esbuild": "~0.25.9",
|
|
56
|
+
"eslint": "~9.34.0",
|
|
57
|
+
"eslint-plugin-wc": "~3.0.1",
|
|
58
|
+
"globals": "~16.3.0",
|
|
59
59
|
"npm-run-all": "~4.1.5",
|
|
60
|
-
"prettier": "~3.
|
|
60
|
+
"prettier": "~3.6.2",
|
|
61
61
|
"rimraf": "~6.0.1",
|
|
62
|
-
"sinon": "~
|
|
63
|
-
"typescript": "~5.
|
|
62
|
+
"sinon": "~21.0.0",
|
|
63
|
+
"typescript": "~5.9.2"
|
|
64
64
|
},
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|
package/src/files-dropzone.js
CHANGED
|
@@ -7,17 +7,35 @@
|
|
|
7
7
|
* @typedef {T | null} Nullable
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Stable identifier for error codes used in the `files-dropzone-error` event.
|
|
12
|
+
*
|
|
13
|
+
* @typedef {typeof FilesDropzone.ERROR_CODES[keyof typeof FilesDropzone.ERROR_CODES]} FilesDropzoneErrorCode
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The detail payload for the `files-dropzone-error` event.
|
|
18
|
+
*
|
|
19
|
+
* @typedef {Object} FilesDropzoneErrorDetail
|
|
20
|
+
* @property {FilesDropzoneErrorCode} code - Stable identifier for the type of error that occurred.
|
|
21
|
+
* @property {unknown} error - The underlying error object or value that triggered the event.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Stable identifier for rejection codes used in the various drop-related events.
|
|
26
|
+
*
|
|
27
|
+
* @typedef {typeof FilesDropzone.REJECTION_CODES[keyof typeof FilesDropzone.REJECTION_CODES]} FilesDropzoneRejectionCode
|
|
28
|
+
*/
|
|
29
|
+
|
|
10
30
|
import { isValidFile } from './utils/is-valid-file.js';
|
|
11
31
|
import { getFilesFromEvent } from './utils/files-selector.js';
|
|
12
32
|
|
|
33
|
+
const css = String.raw;
|
|
34
|
+
const html = String.raw;
|
|
13
35
|
const COMPONENT_NAME = 'files-dropzone';
|
|
14
|
-
const TOO_MANY_FILES = 'TOO_MANY_FILES';
|
|
15
|
-
const FILE_TOO_LARGE = 'FILE_TOO_LARGE';
|
|
16
|
-
const FILE_TOO_SMALL = 'FILE_TOO_SMALL';
|
|
17
|
-
const INVALID_MIME_TYPE = 'INVALID_MIME_TYPE';
|
|
18
36
|
const template = document.createElement('template');
|
|
19
37
|
|
|
20
|
-
const styles =
|
|
38
|
+
const styles = css`
|
|
21
39
|
*,
|
|
22
40
|
*::before,
|
|
23
41
|
*::after {
|
|
@@ -42,7 +60,7 @@ const styles = /* css */ `
|
|
|
42
60
|
--dropzone-body-color: #3f3f46;
|
|
43
61
|
--dropzone-body-color-dragover: var(--dropzone-body-color);
|
|
44
62
|
--dropzone-body-color-hover: var(--dropzone-body-color-dragover);
|
|
45
|
-
--dropzone-focus-shadow-rgb: 49,132,253;
|
|
63
|
+
--dropzone-focus-shadow-rgb: 49, 132, 253;
|
|
46
64
|
--dropzone-focus-box-shadow: 0 0 0 0.25rem rgba(var(--dropzone-focus-shadow-rgb), 0.5);
|
|
47
65
|
--transition-duration: 0.2s; /* for backwards compatibility */
|
|
48
66
|
--dropzone-transition-duration: var(--transition-duration);
|
|
@@ -59,7 +77,11 @@ const styles = /* css */ `
|
|
|
59
77
|
color: var(--dropzone-body-color);
|
|
60
78
|
text-align: center;
|
|
61
79
|
cursor: pointer;
|
|
62
|
-
transition:
|
|
80
|
+
transition:
|
|
81
|
+
border var(--dropzone-transition-duration) ease-in-out,
|
|
82
|
+
background-color var(--dropzone-transition-duration) ease-in-out,
|
|
83
|
+
color var(--dropzone-transition-duration) ease-in-out,
|
|
84
|
+
box-shadow var(--dropzone-transition-duration) ease-in-out;
|
|
63
85
|
}
|
|
64
86
|
|
|
65
87
|
:host(:not([no-style])[disabled]) .dropzone {
|
|
@@ -88,15 +110,15 @@ const styles = /* css */ `
|
|
|
88
110
|
}
|
|
89
111
|
`;
|
|
90
112
|
|
|
91
|
-
template.innerHTML =
|
|
113
|
+
template.innerHTML = html`
|
|
92
114
|
<style>
|
|
93
115
|
${styles}
|
|
94
116
|
</style>
|
|
95
117
|
|
|
96
|
-
<input type="file" id="file-input" hidden
|
|
118
|
+
<input type="file" id="file-input" hidden />
|
|
97
119
|
|
|
98
120
|
<div part="dropzone" class="dropzone" id="dropzone" tabindex="0" role="button" aria-disabled="false">
|
|
99
|
-
<slot>Drag 'n' drop files here, or click to select files</slot>
|
|
121
|
+
<slot><span>Drag 'n' drop files here, or click to select files</span></slot>
|
|
100
122
|
</div>
|
|
101
123
|
`;
|
|
102
124
|
|
|
@@ -157,6 +179,28 @@ template.innerHTML = /* html */ `
|
|
|
157
179
|
* @method openFileDialog - Instance method. Opens the file dialog programmatically.
|
|
158
180
|
*/
|
|
159
181
|
class FilesDropzone extends HTMLElement {
|
|
182
|
+
/**
|
|
183
|
+
* Central list of error codes used in drop error event.
|
|
184
|
+
* @readonly
|
|
185
|
+
*/
|
|
186
|
+
static ERROR_CODES = /** @type {const} */ ({
|
|
187
|
+
FILE_DIALOG_OPEN_FAILED: 'FILE_DIALOG_OPEN_FAILED',
|
|
188
|
+
FILE_INPUT_CHANGE_FAILED: 'FILE_INPUT_CHANGE_FAILED',
|
|
189
|
+
DROP_EVENT_PROCESSING_FAILED: 'DROP_EVENT_PROCESSING_FAILED',
|
|
190
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR'
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Central list of rejection codes for files that are rejected during the drop process.
|
|
195
|
+
* @readonly
|
|
196
|
+
*/
|
|
197
|
+
static REJECTION_CODES = /** @type {const} */ ({
|
|
198
|
+
TOO_MANY_FILES: 'TOO_MANY_FILES',
|
|
199
|
+
FILE_TOO_LARGE: 'FILE_TOO_LARGE',
|
|
200
|
+
FILE_TOO_SMALL: 'FILE_TOO_SMALL',
|
|
201
|
+
INVALID_MIME_TYPE: 'INVALID_MIME_TYPE'
|
|
202
|
+
});
|
|
203
|
+
|
|
160
204
|
/** @type {Nullable<HTMLInputElement>} */
|
|
161
205
|
#fileInput = null;
|
|
162
206
|
|
|
@@ -372,6 +416,40 @@ class FilesDropzone extends HTMLElement {
|
|
|
372
416
|
this.toggleAttribute('no-style', !!value);
|
|
373
417
|
}
|
|
374
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Emit a custom event with the given name and detail.
|
|
421
|
+
*
|
|
422
|
+
* @template D
|
|
423
|
+
* @param {string} name - The name of the event.
|
|
424
|
+
* @param {D} [detail] - The detail payload of the event.
|
|
425
|
+
* @param {CustomEventInit<D>} [init] - Override the default event initialization options.
|
|
426
|
+
* @returns {boolean} - Returns false if at least one event listener called `preventDefault()`, otherwise true.
|
|
427
|
+
*/
|
|
428
|
+
#emitEvent(name, detail, init) {
|
|
429
|
+
const options = {
|
|
430
|
+
bubbles: true,
|
|
431
|
+
composed: true,
|
|
432
|
+
cancelable: false,
|
|
433
|
+
...init,
|
|
434
|
+
detail
|
|
435
|
+
};
|
|
436
|
+
const evt = new CustomEvent(`${COMPONENT_NAME}-${name}`, options);
|
|
437
|
+
return this.dispatchEvent(evt);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Emit a standardized error event with typed detail.
|
|
442
|
+
*
|
|
443
|
+
* @param {FilesDropzoneErrorCode} code - Stable identifier for the type of error that occurred.
|
|
444
|
+
* @param {unknown} error - The underlying error that triggered the event.
|
|
445
|
+
*/
|
|
446
|
+
#emitErrorEvent(code, error) {
|
|
447
|
+
/** @type {FilesDropzoneErrorDetail} */
|
|
448
|
+
const detail = { code, error };
|
|
449
|
+
|
|
450
|
+
this.#emitEvent('error', detail);
|
|
451
|
+
}
|
|
452
|
+
|
|
375
453
|
/**
|
|
376
454
|
* Handles the change event of the file input.
|
|
377
455
|
*
|
|
@@ -380,14 +458,8 @@ class FilesDropzone extends HTMLElement {
|
|
|
380
458
|
#handleFileInputChange = async evt => {
|
|
381
459
|
try {
|
|
382
460
|
this.#handleFilesSelect(await getFilesFromEvent(evt));
|
|
383
|
-
} catch (
|
|
384
|
-
this.
|
|
385
|
-
new CustomEvent(`${COMPONENT_NAME}-error`, {
|
|
386
|
-
bubbles: true,
|
|
387
|
-
composed: true,
|
|
388
|
-
detail: { error }
|
|
389
|
-
})
|
|
390
|
-
);
|
|
461
|
+
} catch (err) {
|
|
462
|
+
this.#emitErrorEvent(FilesDropzone.ERROR_CODES.FILE_INPUT_CHANGE_FAILED, err);
|
|
391
463
|
}
|
|
392
464
|
};
|
|
393
465
|
|
|
@@ -399,12 +471,7 @@ class FilesDropzone extends HTMLElement {
|
|
|
399
471
|
return;
|
|
400
472
|
}
|
|
401
473
|
|
|
402
|
-
this
|
|
403
|
-
new Event(`${COMPONENT_NAME}-dragenter`, {
|
|
404
|
-
bubbles: true,
|
|
405
|
-
composed: true
|
|
406
|
-
})
|
|
407
|
-
);
|
|
474
|
+
this.#emitEvent('dragenter');
|
|
408
475
|
};
|
|
409
476
|
|
|
410
477
|
/**
|
|
@@ -427,12 +494,7 @@ class FilesDropzone extends HTMLElement {
|
|
|
427
494
|
this.#dropzoneEl.part.add('dropzone--dragover');
|
|
428
495
|
}
|
|
429
496
|
|
|
430
|
-
this
|
|
431
|
-
new Event(`${COMPONENT_NAME}-dragover`, {
|
|
432
|
-
bubbles: true,
|
|
433
|
-
composed: true
|
|
434
|
-
})
|
|
435
|
-
);
|
|
497
|
+
this.#emitEvent('dragover');
|
|
436
498
|
};
|
|
437
499
|
|
|
438
500
|
/**
|
|
@@ -448,12 +510,7 @@ class FilesDropzone extends HTMLElement {
|
|
|
448
510
|
this.#dropzoneEl.part.remove('dropzone--dragover');
|
|
449
511
|
}
|
|
450
512
|
|
|
451
|
-
this
|
|
452
|
-
new Event(`${COMPONENT_NAME}-dragleave`, {
|
|
453
|
-
bubbles: true,
|
|
454
|
-
composed: true
|
|
455
|
-
})
|
|
456
|
-
);
|
|
513
|
+
this.#emitEvent('dragleave');
|
|
457
514
|
};
|
|
458
515
|
|
|
459
516
|
/**
|
|
@@ -475,14 +532,8 @@ class FilesDropzone extends HTMLElement {
|
|
|
475
532
|
|
|
476
533
|
try {
|
|
477
534
|
this.#handleFilesSelect(await getFilesFromEvent(evt));
|
|
478
|
-
} catch (
|
|
479
|
-
this.
|
|
480
|
-
new CustomEvent(`${COMPONENT_NAME}-error`, {
|
|
481
|
-
bubbles: true,
|
|
482
|
-
composed: true,
|
|
483
|
-
detail: { error }
|
|
484
|
-
})
|
|
485
|
-
);
|
|
535
|
+
} catch (err) {
|
|
536
|
+
this.#emitErrorEvent(FilesDropzone.ERROR_CODES.DROP_EVENT_PROCESSING_FAILED, err);
|
|
486
537
|
}
|
|
487
538
|
};
|
|
488
539
|
|
|
@@ -494,7 +545,7 @@ class FilesDropzone extends HTMLElement {
|
|
|
494
545
|
return;
|
|
495
546
|
}
|
|
496
547
|
|
|
497
|
-
this
|
|
548
|
+
this.openFileDialog();
|
|
498
549
|
};
|
|
499
550
|
|
|
500
551
|
/**
|
|
@@ -508,7 +559,7 @@ class FilesDropzone extends HTMLElement {
|
|
|
508
559
|
}
|
|
509
560
|
|
|
510
561
|
if (evt.key === ' ' || evt.key === 'Enter') {
|
|
511
|
-
this
|
|
562
|
+
this.openFileDialog();
|
|
512
563
|
}
|
|
513
564
|
};
|
|
514
565
|
|
|
@@ -533,7 +584,7 @@ class FilesDropzone extends HTMLElement {
|
|
|
533
584
|
file,
|
|
534
585
|
errors: [
|
|
535
586
|
{
|
|
536
|
-
code: TOO_MANY_FILES,
|
|
587
|
+
code: FilesDropzone.REJECTION_CODES.TOO_MANY_FILES,
|
|
537
588
|
message: `Too many files selected. Only 1 file is allowed.`
|
|
538
589
|
}
|
|
539
590
|
]
|
|
@@ -547,7 +598,7 @@ class FilesDropzone extends HTMLElement {
|
|
|
547
598
|
file,
|
|
548
599
|
errors: [
|
|
549
600
|
{
|
|
550
|
-
code: TOO_MANY_FILES,
|
|
601
|
+
code: FilesDropzone.REJECTION_CODES.TOO_MANY_FILES,
|
|
551
602
|
message: `Too many files selected. Only ${this.maxFiles} ${this.maxFiles > 1 ? 'files are' : 'file is'} allowed.`
|
|
552
603
|
}
|
|
553
604
|
]
|
|
@@ -568,21 +619,21 @@ class FilesDropzone extends HTMLElement {
|
|
|
568
619
|
|
|
569
620
|
if (!fileHasValidType) {
|
|
570
621
|
errors.push({
|
|
571
|
-
code: INVALID_MIME_TYPE,
|
|
622
|
+
code: FilesDropzone.REJECTION_CODES.INVALID_MIME_TYPE,
|
|
572
623
|
message: `File type "${file.type}" is not accepted.`
|
|
573
624
|
});
|
|
574
625
|
}
|
|
575
626
|
|
|
576
627
|
if (fileExceedsMaxSize) {
|
|
577
628
|
errors.push({
|
|
578
|
-
code: FILE_TOO_LARGE,
|
|
629
|
+
code: FilesDropzone.REJECTION_CODES.FILE_TOO_LARGE,
|
|
579
630
|
message: `File size ${file.size} exceeds the maximum size of ${this.maxSize}.`
|
|
580
631
|
});
|
|
581
632
|
}
|
|
582
633
|
|
|
583
634
|
if (fileIsSmallerThanMinSize) {
|
|
584
635
|
errors.push({
|
|
585
|
-
code: FILE_TOO_SMALL,
|
|
636
|
+
code: FilesDropzone.REJECTION_CODES.FILE_TOO_SMALL,
|
|
586
637
|
message: `File size ${file.size} is smaller than the minimum size of ${this.minSize}.`
|
|
587
638
|
});
|
|
588
639
|
}
|
|
@@ -592,39 +643,14 @@ class FilesDropzone extends HTMLElement {
|
|
|
592
643
|
}
|
|
593
644
|
}
|
|
594
645
|
|
|
595
|
-
this
|
|
596
|
-
new CustomEvent(`${COMPONENT_NAME}-drop`, {
|
|
597
|
-
bubbles: true,
|
|
598
|
-
composed: true,
|
|
599
|
-
detail: {
|
|
600
|
-
acceptedFiles,
|
|
601
|
-
rejectedFiles
|
|
602
|
-
}
|
|
603
|
-
})
|
|
604
|
-
);
|
|
646
|
+
this.#emitEvent('drop', { acceptedFiles, rejectedFiles });
|
|
605
647
|
|
|
606
648
|
if (acceptedFiles.length > 0) {
|
|
607
|
-
this
|
|
608
|
-
new CustomEvent(`${COMPONENT_NAME}-drop-accepted`, {
|
|
609
|
-
bubbles: true,
|
|
610
|
-
composed: true,
|
|
611
|
-
detail: {
|
|
612
|
-
acceptedFiles
|
|
613
|
-
}
|
|
614
|
-
})
|
|
615
|
-
);
|
|
649
|
+
this.#emitEvent('drop-accepted', { acceptedFiles });
|
|
616
650
|
}
|
|
617
651
|
|
|
618
652
|
if (rejectedFiles.length > 0) {
|
|
619
|
-
this
|
|
620
|
-
new CustomEvent(`${COMPONENT_NAME}-drop-rejected`, {
|
|
621
|
-
bubbles: true,
|
|
622
|
-
composed: true,
|
|
623
|
-
detail: {
|
|
624
|
-
rejectedFiles
|
|
625
|
-
}
|
|
626
|
-
})
|
|
627
|
-
);
|
|
653
|
+
this.#emitEvent('drop-rejected', { rejectedFiles });
|
|
628
654
|
}
|
|
629
655
|
|
|
630
656
|
if (this.#fileInput) {
|
|
@@ -636,11 +662,27 @@ class FilesDropzone extends HTMLElement {
|
|
|
636
662
|
* Opens the file dialog programmatically.
|
|
637
663
|
*/
|
|
638
664
|
openFileDialog() {
|
|
639
|
-
if (this.disabled) {
|
|
665
|
+
if (this.disabled || !this.#fileInput) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// In modern browsers, use the showPicker() method if available.
|
|
670
|
+
// This way we are able to detect if the file dialog was blocked by the browser
|
|
671
|
+
// (e.g. if the method was called outside a user gesture event).
|
|
672
|
+
if ('showPicker' in HTMLInputElement.prototype && typeof this.#fileInput.showPicker === 'function') {
|
|
673
|
+
try {
|
|
674
|
+
this.#fileInput.showPicker();
|
|
675
|
+
} catch (err) {
|
|
676
|
+
this.#emitErrorEvent(FilesDropzone.ERROR_CODES.FILE_DIALOG_OPEN_FAILED, err);
|
|
677
|
+
}
|
|
640
678
|
return;
|
|
641
679
|
}
|
|
642
680
|
|
|
643
|
-
|
|
681
|
+
// Fallback for browsers that do not support showPicker().
|
|
682
|
+
// This may not work if the method is called outside a user gesture event.
|
|
683
|
+
// In such cases, the browser may block the file dialog from opening but
|
|
684
|
+
// most likely it won't throw an error rather just a warning in the console.
|
|
685
|
+
this.#fileInput.click();
|
|
644
686
|
}
|
|
645
687
|
|
|
646
688
|
/**
|