-
Notifications
You must be signed in to change notification settings - Fork 0
/
p-b5e6face.entry.js
5 lines (5 loc) · 19.4 KB
/
p-b5e6face.entry.js
1
2
3
4
5
/*!
* Built by BASIS
* Copyright BASIS International Ltd.
*/
import{r as t,c as i,h as e,H as s,g as o}from"./p-00e3df8e.js";import{a as r}from"./p-22ab23bc.js";import{a}from"./p-a14ccc92.js";import{h as l}from"./p-3e9fe89f.js";const n={approve:"Upload",cancel:"Cancel",dropFile:"Drop file to upload",dropFiles:"Drop files to upload",addFile:"Select File...",addFiles:"Select Files...",filterAll:"All Files",uploadFile:"Upload",clearFile:"Clear",retryFile:"Retry upload",statusMaxed:"The max amount of allowed files has been reached",statusTooBig:"File is too big.",statusNotAllowedType:"File type is not allowed.",statusConnecting:"Connecting...",statusQueued:"Queued",statusCanceled:"Canceled",errorUnavailable:"Server Unavailable",errorUnexpected:"Unexpected Server Error",errorForbidden:"Forbidden"};let c=0;const d="showOpenFilePicker"in window,h=class{constructor(e){t(this,e),this.listChangedEvent=i(this,"dwc-listbox-changed",7),this.rejectedEvent=i(this,"dwc-rejected",7),this.startedEvent=i(this,"dwc-started",7),this.progressEvent=i(this,"dwc-progress",7),this.respondedEvent=i(this,"dwc-responded",7),this.uploadedEvent=i(this,"dwc-uploaded",7),this.failedEvent=i(this,"dwc-failed",7),this.requestEvent=i(this,"dwc-request",7),this.abortedEvent=i(this,"dwc-aborted",7),this.approvedEvent=i(this,"dwc-approved",7),this.canceledEvent=i(this,"dwc-canceled",7),this.filterChangedEvent=i(this,"dwc-filter-changed",7),this.inputId="upload-"+ ++c,this.__suspendApproveEvent=!1,this.accept="",this.dragOver=!1,this.allFilesFilterEnabled=!0,this.activeFilter="",this.autoUpload=!1,this.autoUploadOnDrop=!1,this.autoClear=!1,this.approveButtonAccesskey=void 0,this.approveButtonLabel=void 0,this.approveButtonVisible=!0,this.cancelButtonAccesskey=void 0,this.cancelButtonLabel=void 0,this.cancelButtonVisible=!0,this.capture=void 0,this.autoClearBehavior="completed",this.credentials=!1,this.disabled=!1,this.drop=!0,this.dropLabel=void 0,this.directory=!1,this.directoryRecursive=void 0,this.files=[],this.filters=void 0,this.filtersVisible=!0,this.formDataName="file",this.fs=d,this.headers=void 0,this.i18n=n,this.label=void 0,this.maxFiles=1/0,this.maxSize=1/0,this.method="POST",this.multiFilterSelection=!1,this.timeout=0,this.theme="default",this.url=""}onFiltersChanged(t,i,e){this.$button&&this.$button.forceUpdate(),this.computeActiveFilterAndAccept("allFilesFilterEnabled"===e)}connectedCallback(){this.handleButtonClick=this.handleButtonClick.bind(this),this.handleFilterSelected=this.handleFilterSelected.bind(this),this.handleApprove=this.handleApprove.bind(this),this.handleCancel=this.handleCancel.bind(this)}componentWillLoad(){this.computeActiveFilterAndAccept(!0)}async componentDidLoad(){try{await this.$button.forceUpdate()}catch(t){}}componentDidRender(){this.$popup&&(this.$button.dropdown=this.$popup)}handleDragOver(t){t.preventDefault();let i="none";this.drop&&!(this.files.length>=this.maxFiles)&&(this.dragOver=!0,i="copy"),t.dataTransfer.dropEffect=i}handleDragLeave(t){t.preventDefault(),this.dragOver=!1}async handleDrop(t){if(!this.drop)return;t.preventDefault();let i=Array.from(t.dataTransfer.files);this.directory&&(i=await this.getFilesFromDataTransformItems(t.dataTransfer.items),this.directoryRecursive||(i=i.filter((t=>2===t.webkitRelativePath.split("/").length)))),await this.applyAutoClearBehaviour(),this.addFiles(i).catch((t=>console.warn("[dwc-upload] Failed:",t))),this.dragOver=!1;const e=this.files.filter((t=>i.indexOf(t)>-1));e.length&&this.listChangedEvent.emit(e)}async addFile(t){if(this.files.indexOf(t)>-1)return;const i=this.getLocalization();if(this.files.length>=this.maxFiles)return t.status=t.error=i.statusMaxed,this.rejectedEvent.emit(t.status),Promise.reject({file:t,request:null,error:t.status});if(this.maxSize>=0&&t.size>this.maxSize)return t.status=t.error=i.statusTooBig,this.rejectedEvent.emit(t.status),Promise.reject({file:t,request:null,error:t.status});let e=this.accept;this.dragOver&&!this.allFilesFilterEnabled&&(e=this.filters.map((t=>t.globs)).join(",")),this.allFilesFilterEnabled&&(e="");const s=t.name.match(/\.[^\.]*$|$/)[0],o=new RegExp("^("+e.replace(/[, ]+/g,"|").replace(/\/\*/g,"/.*")+")$","i");return!e||o.test(t.type)||o.test(s)?(t.complete=!1,t.approved=!1,t.inProgress=!1,t.status=i.statusQueued,t.error="",t.queued=!0,t.request=null,t.id="_"+Math.random().toString(36).substring(2,9),t.autoUpload=this.dragOver?this.autoUploadOnDrop:this.autoUpload,this.files=[t,...this.files],t.autoUpload?this.uploadFile(t):Promise.resolve({file:t,request:null})):(t.status=t.error=i.statusNotAllowedType,this.rejectedEvent.emit(t.status),Promise.reject({file:t,request:null,error:t.status}))}async addFiles(t){return Promise.all(Array.from(t).map((t=>this.addFile(t))))}async uploadFile(t){if(!0===t.inProgress||!0===t.complete)return t.deferred;t.deferred=a();const i=t.request=new XMLHttpRequest;let e=this.headers;if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e=void 0}for(const t in e)i.setRequestHeader(t,e[t]);this.timeout&&(i.timeout=this.timeout),i.withCredentials=this.credentials,i.upload.onloadstart=()=>{this.files=[...this.files],this.startedEvent.emit({file:t,request:i})},i.upload.onprogress=e=>{const s=t.progress=Math.round(e.loaded/e.total*100);t.status=`${((t,i=!0,e=1)=>{const s=i?1e3:1024;if(Math.abs(t)<s)return t+" B";const o=i?["kB","MB","GB","TB","PB","EB","ZB","YB"]:["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"];let r=-1;const a=10**e;do{t/=s,++r}while(Math.round(Math.abs(t)*a)/a>=s&&r<o.length-1);return t.toFixed(e)+" "+o[r]})(t.size)}: ${s}%`,this.files=[...this.files],this.progressEvent.emit({file:t,request:i,progress:s})},i.onreadystatechange=()=>{if(4==i.readyState){if(t.inProgress=!1,this.respondedEvent.emit({file:t,request:i}).defaultPrevented)return;const e=this.getLocalization();if(0===i.status?t.error=t.status=e.errorUnavailable:i.status>=500?t.error=t.status=e.errorUnexpected:i.status>=400&&(t.error=t.status=e.errorForbidden),t.complete=!t.error,t.error){const e={file:t,request:i,error:t.error};t.deferred.reject(e),this.failedEvent.emit(e)}if(t.complete){const e={file:t,request:i};t.deferred.resolve(e),this.uploadedEvent.emit(e),this.__suspendApproveEvent||(this.approvedEvent.emit([t]),t.approved=!0)}this.files=[...this.files]}};const s=this.getLocalization(),o=new FormData;return o.append(this.formDataName,t,t.name),i.open(this.method,this.url,!0),t.inProgress=!0,t.complete=t.abort=t.error=t.queued=t.status=!1,t.status=s.statusConnecting,this.requestEvent.emit({file:t,request:i,form:o}).defaultPrevented||i.send(o),t.deferred}async uploadFiles(t=[]){let i=Array.from(this.files);return Array.isArray(t)&&t.length&&(i=t),this.addFiles(i),this.__suspendApproveEvent=!0,Promise.all(i.map((t=>this.uploadFile(t)))).then((()=>{const t=Array.from(this.files).filter((t=>t.complete&&!t.approved)).map((t=>(t.approved=!0,t)));this.approvedEvent.emit(t),this.__suspendApproveEvent=!1})).catch((()=>{this.__suspendApproveEvent=!1}))}async abortFile(t){if(!t.request||t.complete)return;if(this.abortedEvent.emit({file:t,request:t.request}).defaultPrevented)return;const i=this.getLocalization();t.abort=!0,t.request.abort(),t.status=i.statusCanceled,this.files=[...this.files]}async abortFiles(t=[]){let i=Array.from(this.files);Array.isArray(t)&&t.length&&(i=t),i.forEach((t=>this.abortFile(t)))}async clearFile(t){this.abortFile(t);const i=this.files.indexOf(t);i>-1&&(this.files.splice(i,1),this.files=[...this.files])}async clearFiles(t=[]){let i=Array.from(this.files);Array.isArray(t)&&t.length&&(i=t),i.forEach((t=>this.clearFile(t)))}async approve(){this.uploadFiles()}async cancel(){this.abortFiles();const t=Array.from(this.files).filter((t=>!t.complete));this.canceledEvent.emit(t)}async open(){return this.directory?this.inputDirsOpen():this.fs&&d?this.fsFilesOpen():this.inputFilesOpen()}async fsFilesOpen(){const t=(this.filters||[]).filter((t=>t.globs)).map((t=>{const i=t.name||"";if(t.globs.split(",").filter((t=>".*"!==t)).length)return{description:i,accept:{[`${i.replace(/\s/g,"")}/*`]:t.globs.split(",").map((t=>".*"===t?".":t))}}})).filter(Boolean);let i=this.activeFilter;const e=i.split(",").map((t=>t.trim()));e.length&&(i=e[0]);const s=t.findIndex((t=>t.description===i));s>-1&&r(t,s,0);const o=await window.showOpenFilePicker({id:this.inputId,multiple:1!==this.maxFiles,excludeAcceptAllOption:!this.allFilesFilterEnabled&&this.filters.length,types:t});return await Promise.all(o.map((async t=>{const i=await t.getFile();return i.handle=t,i})))}async inputFilesOpen(){return new Promise((t=>{const i=document.createElement("input");i.id=this.inputId,i.type="file",i.accept=this.accept,i.multiple=1!==this.maxFiles,this.capture&&(i.capture=this.capture),i.addEventListener("change",(i=>{t(Array.from(i.target.files))})),requestAnimationFrame((()=>{i.click()}))}))}async inputDirsOpen(){return new Promise((t=>{const i=document.createElement("input");i.id=this.inputId,i.type="file",i.multiple=!0,i.webkitdirectory=!0,i.addEventListener("change",(i=>{let e=Array.from(i.target.files);this.directoryRecursive||(e=e.filter((t=>2===t.webkitRelativePath.split("/").length))),t(e)})),i.click()}))}async applyAutoClearBehaviour(){if(!this.autoClear)return;const t=this.autoClearBehavior,i=this.files.filter((i=>"completed"===t?i.complete:"in-progress"===t?i.inProgress:"both"===t?i.complete||i.inProgress:void 0)).filter(Boolean);i.length&&await this.clearFiles(i)}computeActiveFilterAndAccept(t=!1){const i=this.filters||[];let e=this.activeFilter.split(",").map((t=>t.trim())).filter(Boolean);if(!e.length&&i.length&&t&&!this.allFilesFilterEnabled){const t=i[0];e=[String(t.id||t.name)]}e.length>1&&!this.multiFilterSelection&&(e=[e[0]]),e=e.filter((t=>i.findIndex((i=>i.id===t||i.name===t))>-1)),this.activeFilter=e.join(","),this.accept=e.map((t=>{const e=i.findIndex((i=>i.id===t||i.name===t));if(e>-1)return i[e].globs})).join(",")}getLocalization(){return Object.assign(n,"string"==typeof this.i18n?JSON.parse(this.i18n):this.i18n)}async getFilesFromDataTransformItems(t){const i=[],e=(t,s="")=>new Promise((o=>{if(t.isFile)t.file((t=>{const e=s?s+"/"+t.name:t.name;Object.defineProperty(t,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e}),i.push(t),o(t)}));else if(t.isDirectory){const i=t.createReader();if("function"!=typeof i.readEntries)return;i.readEntries((i=>{const r=[];for(const o of i)r.push(e(o,`${s?s+"/":""}${t.name}`));o(Promise.all(r))}))}}));return new Promise((s=>{const o=[];for(const i of t)o.push(e(i.webkitGetAsEntry()));Promise.all(o).then((()=>{s(i)}))}))}async handleButtonClick(t){if(this.$popup&&(this.$popup.x=t.clientX,this.$popup.y=t.clientY),!t.defaultPrevented)try{const t=await this.open();await this.applyAutoClearBehaviour(),this.addFiles(t).catch((t=>console.warn("[dwc-upload] Failed:",t)));const i=this.files.filter((i=>t.indexOf(i)>-1));i.length&&this.listChangedEvent.emit(i)}catch(t){console.warn("[dwc-upload] Failed:",t)}}handleApprove(){this.approve()}handleCancel(){this.cancel()}handleFilterSelected(t){const i=t.target,e=i.closest("dwc-menu"),s=e.querySelectorAll("dwc-menuitem");let o=[],r="";if(this.multiFilterSelection){const t=e.querySelector("dwc-menuitem[data-clear]");if(t&&i.isSameNode(t))Array.from(s).forEach((t=>t.checked=!1)),t.checked=!0,o=[],r="";else{const i=Array.from(s).filter((t=>t.checked));o=[],r="",i.length?(t&&(t.checked=!1),i.forEach((t=>{t.hasAttribute("data-clear")||(o.push(t.getAttribute("data-id")),r+=t.getAttribute("data-globs"))}))):t&&(t.checked=!0)}}else Array.from(s).forEach((t=>t.checked=!1)),i.checked=!0,o=[i.getAttribute("data-id")],r=i.getAttribute("data-globs");const a=this.activeFilter,l=o.join(",");this.accept=null,this.accept=r,this.activeFilter=l,a!==l&&this.filterChangedEvent.emit(l)}render(){var t,i,o,r;const a=this.getLocalization(),n=(null===(t=this.label)||void 0===t?void 0:t.length)?this.label:1!==this.maxFiles?a.addFiles:a.addFile,c=(null===(i=this.dropLabel)||void 0===i?void 0:i.length)?this.dropLabel:1!==this.maxFiles?a.dropFiles:a.dropFile,h=(null===(o=this.approveButtonLabel)||void 0===o?void 0:o.length)?this.approveButtonLabel:a.approve,p=(null===(r=this.cancelButtonLabel)||void 0===r?void 0:r.length)?this.cancelButtonLabel:a.cancel,f=this.disabled||0===this.files.filter((t=>!t.complete&&!t.inProgress)).length,u=this.disabled;let b=(!1===this.fs||!d)&&this.filtersVisible;return b=b&&!(!this.allFilesFilterEnabled&&0===(this.filters||[]).length),this.directory&&(b=!1),e(s,{key:"675c463490a5bfb7ab1d3d1e480e721a2fd7ccec",class:l({BBjFileChooser:!0,"bbj-client":!0,"bbj-disabled":this.disabled})},e("div",{key:"a210eae73b9c676b15861c4bf14b9bf210e436b5",part:"control",class:{control:!0,control__disabled:this.disabled,control__dragOver:this.dragOver,control__buttonsVisible:this.approveButtonVisible||this.cancelButtonVisible,control__hasFiles:(this.files||[]).length>0}},b&&e("dwc-popupmenu",{key:"87d02360d07b1468dfb67d0b64acdbbe9df9010b",ref:t=>this.$popup=t},e("dwc-menu",{key:"36d2c3e4cf26c1e86078369587dc08ae494b5da3"},(this.filters||[]).map(((t,i)=>{const s=t.name,o=t.globs,r=String(t.id||s),a=Boolean(this.activeFilter.includes(r));return e("dwc-menuitem",{key:"item-"+i,label:s,checkable:!0,checked:a,"data-id":r,"data-name":s,"data-globs":o,"onDwc-selected":this.handleFilterSelected})})),this.allFilesFilterEnabled&&e("dwc-menuitem",{key:"2e913f916579e2c10829e1561f039f19008a6607",label:a.filterAll,checkable:!0,checked:!this.activeFilter,"data-id":!0,"data-name":!0,"data-globs":!0,"data-clear":!0,"onDwc-selected":this.handleFilterSelected}))),e("div",{key:"5aed8417a60aad76d92d03d986f1be3eb8ffda17",part:"add-files",class:"control__addFiles"},e("dwc-button",{key:"ff0318b4a6fdd2b837d1d7b1e5c4760cca90547b",ref:t=>this.$button=t,part:"button-upload",disabled:this.disabled||this.files.length>=this.maxFiles,onClick:this.handleButtonClick,theme:this.theme},n),e("div",{key:"a403298509415d3e5e3f5faa962f70b05b59f8bc",part:"label-wrapper",class:"control__labelWrapper",hidden:!this.drop},e("dwc-icon",{key:"fe82b769c49935f7740f99bd00eb39d1687bb13c",part:"icon-upload",pool:"dwc",name:"upload"}),e("div",{key:"e31542fca7ca030eac2cdc7f264acd457f194374",part:"label",innerHTML:c}))),e("div",{key:"ff9c4c2a45d434dd9fafa1e3ae66fda587b5f8c3",part:"list-wrapper",class:{control__listWrapper:!0,"control__listWrapper--hidden":!this.files.length}},e("div",{key:"fec886f3d7664c03d7a75109bec41ae2ea250209",part:"list",class:"control__list"},this.files.map((t=>{const i=t.error&&!t.inProgress,s=t.complete,o=t.queued,r=t.webkitRelativePath||t.name;return e("div",{key:t.id,part:"file",class:{control__file:!0,"control__file--errored":i,"control__file--completed":s,"control__file--inProgress":t.inProgress}},e("div",{part:"file-prefix",class:"control__filePrefix"},e("dwc-icon",{part:"icon-failed",pool:"dwc",name:"info",theme:"danger",hidden:!i,title:t.error}),e("dwc-icon",{part:"icon-succeeded",pool:"dwc",name:"check",theme:"primary",hidden:!s}),e("dwc-icon",{part:"icon-file",pool:"dwc",name:"file",theme:"primary",hidden:i||s})),e("div",{part:"file-body",class:"control_fileBody",title:r},e("div",{part:"file-name",class:"control__fileName"},r),e("div",{part:"file-status",class:"control__fileStatus"},t.status)),e("div",{part:"file-suffix",class:"control__fileSuffix"},e("dwc-icon-button",{part:"icon-retry",pool:"dwc",name:"refresh",title:a.retryFile,hidden:!i,onClick:()=>this.uploadFile(t)}),e("dwc-icon-button",{part:"icon-start",pool:"dwc",name:"play",title:a.uploadFile,hidden:!o,onClick:()=>this.uploadFile(t)}),e("dwc-icon-button",{part:"icon-clear",pool:"dwc",name:"icon-x",title:a.clearFile,onClick:()=>this.clearFile(t)})))})))),e("div",{key:"4d1a02bb62d7282724af35f66fc8bbd6f2d5d494",part:"buttons",class:"control__buttons",hidden:!this.approveButtonVisible&&!this.cancelButtonVisible},e("dwc-button",{key:"74f7db505903f52d13995b17f8dc18e1fdfddb9e",part:"button-approve",accessKey:this.approveButtonAccesskey,label:h,hidden:!this.approveButtonVisible,disabled:f,theme:"primary",onClick:this.handleApprove}),e("dwc-button",{key:"aa069bca3718cc0dcd7ccf27adcec6da8a33a331",part:"button-cancel",accessKey:this.cancelButtonAccesskey,label:p,hidden:!this.cancelButtonVisible,disabled:u,onClick:this.handleCancel}))))}get el(){return o(this)}static get watchers(){return{filtersVisible:["onFiltersChanged"],allFilesFilterEnabled:["onFiltersChanged"],activeFilter:["onFiltersChanged"],filters:["onFiltersChanged"],fs:["onFiltersChanged"],directory:["onFiltersChanged"]}}};h.style="@media (prefers-reduced-motion: reduce){*,::before,::after{animation-delay:-1ms !important;animation-duration:1ms !important;animation-iteration-count:1 !important;background-attachment:initial !important;scroll-behavior:auto !important;transition-delay:0s !important;transition-duration:0s !important}}:host{box-sizing:border-box;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;position:relative;-webkit-tap-highlight-color:transparent;text-size-adjust:100%}:host *,:host *::before,:host *::after{box-sizing:inherit}@keyframes dwc-blink{0%,100%{opacity:1}50%{opacity:0.5}}:host{--_dwc-upload-border:var(--dwc-upload-border, var(--dwc-border-width) var(--dwc-border-style) var(--dwc-color-default));--_dwc-upload-padding:var(--dwc-upload-padding, var(--dwc-space));display:block}:host([disabled]){cursor:var(--dwc-cursor-disabled)}.control{border:var(--_dwc-upload-border);border-radius:var(--dwc-border-radius);display:flex;flex-direction:column;height:100%;overflow:hidden;position:relative;transition:var(--dwc-transition) color, var(--dwc-transition) background-color, var(--dwc-transition) border-color;width:100%}.control__dragOver{background-color:var(--dwc-color-primary-alt);border-color:var(--dwc-color-primary);color:var(--dwc-color-on-primary-text-alt)}.control__disabled .control__labelWrapper,.control__disabled .control__listWrapper{cursor:var(--dwc-disabled-cursor);opacity:var(--dwc-disabled-opacity);user-select:none}.control__disabled .control__labelWrapper *,.control__disabled .control__listWrapper *{cursor:var(--dwc-disabled-cursor);user-select:none}.control__addFiles{align-items:center;display:flex;flex-wrap:wrap;gap:var(--dwc-space-m);padding:var(--_dwc-upload-padding)}.control__labelWrapper{align-items:center;display:flex;gap:var(--dwc-space-s)}.control__listWrapper{border-top:var(--_dwc-upload-border);flex:1;overflow:hidden}.control__list{height:100%;overflow:auto;width:100%}.control__file{align-items:stretch;border-bottom:var(--_dwc-upload-border);color:var(--dwc-color-gray-text);display:flex;padding:var(--_dwc-upload-padding)}.control__file:last-of-type{border-bottom:unset}.control__filePrefix,.control__fileSuffix{align-items:center;display:flex}.control__fileSuffix{--dwc-icon-size:1.5rem}.control__filePrefix{--dwc-icon-size:1.8rem;width:var(--dwc-size)}.control__file--inProgress .control__filePrefix{animation:dwc-blink 2s ease-in-out infinite}.control_fileBody{flex:1;flex-basis:50%;min-width:0}.control__fileName{font-size:var(--dwc-font-size-m);font-weight:var(--dwc-font-weight-semibold);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.control__fileStatus{color:var(--dwc-color-gray-text);font-size:var(--dwc-font-size-s);margin-top:var(--dwc-space-xs)}.control__file--errored .control__fileStatus{color:var(--dwc-color-danger-text)}.control__buttons{align-items:center;display:flex;gap:var(--dwc-space-s);justify-content:flex-end;padding:var(--_dwc-upload-padding)}.control__buttonsVisible .control__buttons{border:var(--_dwc-upload-border);border-left:0;border-right:0}[hidden]{display:none}:host([dwc-fs-client]){--dwc-upload-padding:var(--dwc-space-m)}:host([dwc-fs-client]) .control{border:0}:host([dwc-fs-client]) .control__buttons{background-color:var(--dwc-surface-1);border-bottom:0}:host([dwc-fs-client]) .control__listWrapper--hidden{display:none}";export{h as dwc_upload}