@digital-realty/ix-file-uploader 1.1.8 → 1.1.10
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.
|
@@ -17,7 +17,7 @@ export const processFiles = (config) => {
|
|
|
17
17
|
for (let file of filesToProcess) {
|
|
18
18
|
// check file extension
|
|
19
19
|
const fileExtension = file.name.split('.').pop() || '';
|
|
20
|
-
const isAllowedExtension = extensions.includes(fileExtension);
|
|
20
|
+
const isAllowedExtension = extensions.includes(fileExtension.toLocaleLowerCase());
|
|
21
21
|
file = mapBrowserContentTypes(fileExtension, file);
|
|
22
22
|
if (!isAllowedExtension) {
|
|
23
23
|
const message = `File extension for "${file.name}" is not allowed`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-files.js","sourceRoot":"","sources":["../../src/internal/process-files.ts"],"names":[],"mappings":"AAYA,gEAAgE;AAChE,MAAM,WAAW,GAA8B;IAC7C,8BAA8B,EAAE,UAAU;CAC3C,CAAC;AAEF,SAAS,sBAAsB,CAAC,aAAqB,EAAE,IAAU;IAC/D,IAAI,WAAW,CAAC,GAAG,aAAa,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;QAChD,OAAO,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE;YACjC,IAAI,EAAE,WAAW,CAAC,GAAG,aAAa,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;SACnD,CAAC,CAAC;KACJ;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAA2B,EAAE;IACtE,MAAM,EACJ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,GAChB,GAAG,MAAM,CAAC;IAEX,MAAM,OAAO,GAA4B,EAAE,CAAC;IAE5C,IAAI,kBAAkB,GAAG,CAAC,CAAC,CAAC,4HAA4H;IAEx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,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI;oBACJ,OAAO;oBACP,QAAQ,EAAE,KAAK;oBACf,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE;iBACxB,CAAC,CAAC;gBACH,SAAS;aACV;SACF;QAED,kDAAkD;QAClD,OAAO,CAAC,IAAI,CAAC;YACX,IAAI;YACJ,OAAO,EAAE,eAAe;YACxB,QAAQ,EAAE,IAAI;YACd,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE;SACxB,CAAC,CAAC;QACH,kBAAkB,IAAI,CAAC,CAAC;KACzB;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import FileUploadResult from './file-upload-result.js';\nimport UploaderFile from './uploader-file.js';\n\nexport interface Config {\n currentFiles: Array<UploaderFile>;\n extensions: Array<string>;\n filesToProcess: Array<File>;\n maxFileCount: number;\n maxFileSizeInBytes: number;\n allowDuplicates: boolean;\n}\n\n// key is source file extension and browser infered content type\nconst mimeTypeMap: { [key: string]: string } = {\n 'csv-application/vnd.ms-excel': 'text/csv',\n};\n\nfunction mapBrowserContentTypes(fileExtension: string, file: File) {\n if (mimeTypeMap[`${fileExtension}-${file.type}`]) {\n return new File([file], file.name, {\n type: mimeTypeMap[`${fileExtension}-${file.type}`],\n });\n }\n return file;\n}\n\nexport const processFiles = (config: Config): Array<FileUploadResult> => {\n const {\n currentFiles,\n extensions,\n filesToProcess,\n maxFileCount,\n maxFileSizeInBytes,\n allowDuplicates,\n } = config;\n\n const results: Array<FileUploadResult> = [];\n\n let filesToUploadCount = 0; // counter for how many files we add in the \"for\" loop below; used to know when we reach the maximum number of files allowed\n\n for (let file of filesToProcess) {\n // check file extension\n const fileExtension = file.name.split('.').pop() || '';\n const isAllowedExtension = extensions.includes(fileExtension.toLocaleLowerCase());\n file = mapBrowserContentTypes(fileExtension, file);\n if (!isAllowedExtension) {\n const message = `File extension for \"${file.name}\" is not allowed`;\n results.push({ file, message, uploaded: false, id: crypto.randomUUID() });\n continue;\n }\n\n // check for max file size\n if (file.size > maxFileSizeInBytes) {\n const message = `File size ${file.size} bytes is too large; maximum allowed size is ${maxFileSizeInBytes} bytes`;\n results.push({ file, message, uploaded: false, id: crypto.randomUUID() });\n continue;\n }\n\n // check for max file count\n const noMoreFilesAllowed =\n currentFiles.length + filesToUploadCount >= maxFileCount;\n if (noMoreFilesAllowed) {\n const message = `File not uploaded; it would exceed the maximum number of files (${maxFileCount})`;\n results.push({ file, message, uploaded: false, id: crypto.randomUUID() });\n continue;\n }\n\n // check for duplicate file names\n if (!allowDuplicates) {\n const isDuplicate = currentFiles.some(\n (f: UploaderFile) => f.name === file.name\n );\n if (isDuplicate) {\n const message = `File not uploaded; there is already a file named ${file.name}`;\n results.push({\n file,\n message,\n uploaded: false,\n id: crypto.randomUUID(),\n });\n continue;\n }\n }\n\n // The file passes all validation and can be added\n results.push({\n file,\n message: 'File uploaded',\n uploaded: true,\n id: crypto.randomUUID(),\n });\n filesToUploadCount += 1;\n }\n\n return results;\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate}from"tslib";import{css,svg,LitElement,html
|
|
1
|
+
import{__decorate}from"tslib";import{css,svg,LitElement,nothing,html}from"lit";import{property,state}from"lit/decorators.js";import{createRef,ref}from"lit/directives/ref.js";import{classMap}from"lit/directives/class-map.js";import"@digital-realty/ix-icon-button/ix-icon-button.js";let IxFileChipStyles=css`.file-chip{align-items:center;background:#f5f7ff;cursor:pointer;display:flex;flex:auto;padding:4px 8px;height:40px}.file-chip span{margin-right:10px}.delete-icon{color:var(--md-sys-color-error)}`,trash=svg`<svg viewBox="0 0 24 24"><path d="M15.5 4H19V6H5V4H8.5L9.5 3H14.5L15.5 4ZM8 21C6.9 21 6 20.1 6 19V7H18V19C18 20.1 17.1 21 16 21H8Z"/></svg>`;class IxFileChip extends LitElement{constructor(){super(...arguments),this.deletable=!0}onClick(){var e=new CustomEvent("on-file-click",{detail:{file:this.file}});this.dispatchEvent(e)}onDelete(){var e;this.deletable&&(e=new CustomEvent("on-file-delete",{detail:{file:this.file}}),this.dispatchEvent(e))}render(){var e;return html`<li class="file-chip"><span @click="${this.onClick}">${null==(e=this.file)?void 0:e.name} </span>${this.deletable?html`<ix-icon-button @click="${this.onDelete}" name="delete-button"><ix-icon slot="default" class="delete-icon">${trash}</ix-icon></ix-icon-button>`:nothing}</li>`}}IxFileChip.styles=[IxFileChipStyles],__decorate([property({type:Object})],IxFileChip.prototype,"file",void 0),__decorate([property({type:Boolean})],IxFileChip.prototype,"deletable",void 0),customElements.define("ix-file-chip",IxFileChip),(e=>{e.B="B",e.KB="KB",e.MB="MB",e.GB="GB",e.TB="TB",e.PB="PB",e.EB="EB",e.ZB="ZB",e.YB="YB"})(DataStorageUnit=DataStorageUnit||{});var DataStorageUnit,DataStorageUnit$1=DataStorageUnit;let KB=1024,MB=1024*KB,GB=1024*MB,TB=1024*GB,PB=1024*TB,EB=1024*PB,ZB=1024*EB,YB=1024*ZB,getTotalBytes=e=>{switch(e){case DataStorageUnit$1.KB:return KB;case DataStorageUnit$1.MB:return MB;case DataStorageUnit$1.GB:return GB;case DataStorageUnit$1.TB:return TB;case DataStorageUnit$1.PB:return PB;case DataStorageUnit$1.EB:return EB;case DataStorageUnit$1.ZB:return ZB;case DataStorageUnit$1.YB:return YB;default:return 0}},mimeTypeMap={"csv-application/vnd.ms-excel":"text/csv"};function mapBrowserContentTypes(e,t){return mimeTypeMap[e+"-"+t.type]?new File([t],t.name,{type:mimeTypeMap[e+"-"+t.type]}):t}let processFiles=e=>{var{currentFiles:i,extensions:l,filesToProcess:e,maxFileCount:a,maxFileSizeInBytes:o,allowDuplicates:r}=e,s=[];let n=0;for(let t of e){var p=t.name.split(".").pop()||"",d=l.includes(p.toLocaleLowerCase());if(t=mapBrowserContentTypes(p,t),d)if(t.size>o){p=`File size ${t.size} bytes is too large; maximum allowed size is ${o} bytes`;s.push({file:t,message:p,uploaded:!1,id:crypto.randomUUID()})}else if(i.length+n>=a)s.push({file:t,message:`File not uploaded; it would exceed the maximum number of files (${a})`,uploaded:!1,id:crypto.randomUUID()});else{if(!r)if(i.some(e=>e.name===t.name)){d="File not uploaded; there is already a file named "+t.name;s.push({file:t,message:d,uploaded:!1,id:crypto.randomUUID()});continue}s.push({file:t,message:"File uploaded",uploaded:!0,id:crypto.randomUUID()}),n+=1}else{p=`File extension for "${t.name}" is not allowed`;s.push({file:t,message:p,uploaded:!1,id:crypto.randomUUID()})}}return s},sortFilesAscending=(e=[])=>e.sort((e,t)=>{e=e.name.toLocaleLowerCase(),t=t.name.toLocaleLowerCase();return e<t?-1:0}),IxFileUploaderStyles=css`.ix-file-uploader{display:flex;flex-direction:column;justify-content:center;min-width:320px}.dropzone{background:var(--clr-surface,#f5f7ff);border:1px dashed var(--clr-info,#2196f3);border-radius:3px;cursor:pointer;display:flex;flex-direction:column;gap:4px;padding:16px}.ix-file-uploader__label{color:var(
|
|
2
2
|
--ix-file-uploader-label-color,
|
|
3
3
|
var(--clr-on-surface, 'inherit')
|
|
4
4
|
);font-family:var(
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Webcomponent ix-file-uploader following open-wc recommendations",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Digital Realty",
|
|
6
|
-
"version": "1.1.
|
|
6
|
+
"version": "1.1.10",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"module": "dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@digital-realty/ix-button": "^3.3.7",
|
|
33
|
-
"@digital-realty/ix-icon-button": "^1.1.
|
|
33
|
+
"@digital-realty/ix-icon-button": "^1.1.7",
|
|
34
34
|
"@lit-labs/react": "^2.1.0",
|
|
35
35
|
"@lit/react": "^1.0.2",
|
|
36
36
|
"@material/web": "1.2.0",
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"README.md",
|
|
114
114
|
"LICENSE"
|
|
115
115
|
],
|
|
116
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "88d71dc777dfb338bb137b04f0ec54489600ee26"
|
|
117
117
|
}
|