@foxy.io/elements 1.48.0 → 1.48.1-beta.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/dist/cdn/foxy-downloadable-form.js +1 -1
- package/dist/elements/public/DownloadableForm/internal/InternalDownloadableFormUploadControl/InternalDownloadableFormUploadControl.js +1 -3
- package/dist/elements/public/DownloadableForm/internal/InternalDownloadableFormUploadControl/InternalDownloadableFormUploadControl.js.map +1 -1
- package/package.json +1 -1
|
@@ -502,4 +502,4 @@ class x extends(i(s(a))){static get template(){return r`
|
|
|
502
502
|
</slot>
|
|
503
503
|
<slot></slot>
|
|
504
504
|
<input type="file" id="fileInput" on-change="_onFileInputChange" hidden="" accept\$="{{accept}}" multiple\$="[[_isMultiple(maxFiles)]]" capture\$="[[capture]]">
|
|
505
|
-
`}static get is(){return"vaadin-upload"}static get version(){return"4.4.3"}static get properties(){return{nodrop:{type:Boolean,reflectToAttribute:!0,value:function(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}},target:{type:String,value:""},method:{type:String,value:"POST"},headers:{type:Object,value:{}},timeout:{type:Number,value:0},_dragover:{type:Boolean,value:!1,observer:"_dragoverChanged"},files:{type:Array,notify:!0,value:function(){return[]}},maxFiles:{type:Number,value:1/0},maxFilesReached:{type:Boolean,value:!1,notify:!0,readOnly:!0,reflectToAttribute:!0,computed:"_maxFilesAdded(maxFiles, files.length)"},accept:{type:String,value:""},maxFileSize:{type:Number,value:1/0},_dragoverValid:{type:Boolean,value:!1,observer:"_dragoverValidChanged"},formDataName:{type:String,value:"file"},noAuto:{type:Boolean,value:!1},withCredentials:{type:Boolean,value:!1},capture:String,i18n:{type:Object,value:function(){return{dropFiles:{one:"Drop file here",many:"Drop files here"},addFiles:{one:"Upload File...",many:"Upload Files..."},cancel:"Cancel",error:{tooManyFiles:"Too Many Files.",fileIsTooBig:"File is Too Big.",incorrectFileType:"Incorrect File Type."},uploading:{status:{connecting:"Connecting...",stalled:"Stalled.",processing:"Processing File...",held:"Queued"},remainingTime:{prefix:"remaining time: ",unknown:"unknown remaining time"},error:{serverUnavailable:"Server Unavailable",unexpectedServerError:"Unexpected Server Error",forbidden:"Forbidden"}},units:{size:["B","kB","MB","GB","TB","PB","EB","ZB","YB"]}}}}}}ready(){super.ready(),this.addEventListener("dragover",this._onDragover.bind(this)),this.addEventListener("dragleave",this._onDragleave.bind(this)),this.addEventListener("drop",this._onDrop.bind(this)),this.addEventListener("file-retry",this._onFileRetry.bind(this)),this.addEventListener("file-abort",this._onFileAbort.bind(this)),this.addEventListener("file-remove",this._onFileRemove.bind(this)),this.addEventListener("file-start",this._onFileStart.bind(this))}_formatSize(e){if("function"==typeof this.i18n.formatSize)return this.i18n.formatSize(e);const t=this.i18n.units.sizeBase||1e3,r=~~(Math.log(e)/Math.log(t)),a=Math.max(0,Math.min(3,r-1));return parseFloat((e/Math.pow(t,r)).toFixed(a))+" "+this.i18n.units.size[r]}_splitTimeByUnits(e){const t=[60,60,24,1/0],r=[0];for(var a=0;a<t.length&&e>0;a++)r[a]=e%t[a],e=Math.floor(e/t[a]);return r}_formatTime(e,t){if("function"==typeof this.i18n.formatTime)return this.i18n.formatTime(e,t);for(;t.length<3;)t.push(0);return t.reverse().map((e=>(e<10?"0":"")+e)).join(":")}_formatFileProgress(e){return e.totalStr+": "+e.progress+"% ("+(e.loaded>0?this.i18n.uploading.remainingTime.prefix+e.remainingStr:this.i18n.uploading.remainingTime.unknown)+")"}_maxFilesAdded(e,t){return e>=0&&t>=e}_onDragover(e){e.preventDefault(),this.nodrop||this._dragover||(this._dragoverValid=!this.maxFilesReached,this._dragover=!0),e.dataTransfer.dropEffect=!this._dragoverValid||this.nodrop?"none":"copy"}_onDragleave(e){e.preventDefault(),this._dragover&&!this.nodrop&&(this._dragover=this._dragoverValid=!1)}_onDrop(e){this.nodrop||(e.preventDefault(),this._dragover=this._dragoverValid=!1,this._addFiles(e.dataTransfer.files))}_createXhr(){return new XMLHttpRequest}_configureXhr(e){if("string"==typeof this.headers)try{this.headers=JSON.parse(this.headers)}catch(e){this.headers=void 0}for(var t in this.headers)e.setRequestHeader(t,this.headers[t]);this.timeout&&(e.timeout=this.timeout),e.withCredentials=this.withCredentials}_setStatus(e,t,r,a){e.elapsed=a,e.elapsedStr=this._formatTime(e.elapsed,this._splitTimeByUnits(e.elapsed)),e.remaining=Math.ceil(a*(t/r-1)),e.remainingStr=this._formatTime(e.remaining,this._splitTimeByUnits(e.remaining)),e.speed=~~(t/a/1024),e.totalStr=this._formatSize(t),e.loadedStr=this._formatSize(r),e.status=this._formatFileProgress(e)}uploadFiles(e){e&&!Array.isArray(e)&&(e=[e]),e=(e=e||this.files).filter((e=>!e.complete)),Array.prototype.forEach.call(e,this._uploadFile.bind(this))}_uploadFile(e){if(e.uploading)return;const t=Date.now(),r=e.xhr=this._createXhr();let a,o;r.upload.onprogress=i=>{clearTimeout(a),o=Date.now();const s=(o-t)/1e3,l=i.loaded,n=i.total,d=~~(l/n*100);e.loaded=l,e.progress=d,e.indeterminate=l<=0||l>=n,e.error?e.indeterminate=e.status=void 0:e.abort||(d<100?(this._setStatus(e,n,l,s),a=setTimeout((()=>{e.status=this.i18n.uploading.status.stalled,this._notifyFileChanges(e)}),2e3)):(e.loadedStr=e.totalStr,e.status=this.i18n.uploading.status.processing)),this._notifyFileChanges(e),this.dispatchEvent(new CustomEvent("upload-progress",{detail:{file:e,xhr:r}}))},r.onreadystatechange=()=>{if(4==r.readyState){if(clearTimeout(a),e.indeterminate=e.uploading=!1,e.abort)return void this._notifyFileChanges(e);e.status="";if(!this.dispatchEvent(new CustomEvent("upload-response",{detail:{file:e,xhr:r},cancelable:!0})))return;0===r.status?e.error=this.i18n.uploading.error.serverUnavailable:r.status>=500?e.error=this.i18n.uploading.error.unexpectedServerError:r.status>=400&&(e.error=this.i18n.uploading.error.forbidden),e.complete=!e.error,this.dispatchEvent(new CustomEvent("upload-"+(e.error?"error":"success"),{detail:{file:e,xhr:r}})),this._notifyFileChanges(e)}};const i=new FormData;e.uploadTarget=e.uploadTarget||this.target||"",e.formDataName=this.formDataName;if(!this.dispatchEvent(new CustomEvent("upload-before",{detail:{file:e,xhr:r},cancelable:!0})))return;i.append(e.formDataName,e,e.name),r.open(this.method,e.uploadTarget,!0),this._configureXhr(r),e.status=this.i18n.uploading.status.connecting,e.uploading=e.indeterminate=!0,e.complete=e.abort=e.error=e.held=!1,r.upload.onloadstart=()=>{this.dispatchEvent(new CustomEvent("upload-start",{detail:{file:e,xhr:r}})),this._notifyFileChanges(e)};this.dispatchEvent(new CustomEvent("upload-request",{detail:{file:e,xhr:r,formData:i},cancelable:!0}))&&r.send(i)}_retryFileUpload(e){this.dispatchEvent(new CustomEvent("upload-retry",{detail:{file:e,xhr:e.xhr},cancelable:!0}))&&this._uploadFile(e)}_abortFileUpload(e){this.dispatchEvent(new CustomEvent("upload-abort",{detail:{file:e,xhr:e.xhr},cancelable:!0}))&&(e.abort=!0,e.xhr&&e.xhr.abort(),this._notifyFileChanges(e))}_notifyFileChanges(e){var t="files."+this.files.indexOf(e)+".";for(var r in e)e.hasOwnProperty(r)&&this.notifyPath(t+r,e[r])}_addFiles(e){Array.prototype.forEach.call(e,this._addFile.bind(this))}_addFile(e){if(this.maxFilesReached)return void this.dispatchEvent(new CustomEvent("file-reject",{detail:{file:e,error:this.i18n.error.tooManyFiles}}));if(this.maxFileSize>=0&&e.size>this.maxFileSize)return void this.dispatchEvent(new CustomEvent("file-reject",{detail:{file:e,error:this.i18n.error.fileIsTooBig}}));const t=e.name.match(/\.[^\.]*$|$/)[0],r=new RegExp("^("+this.accept.replace(/[, ]+/g,"|").replace(/\/\*/g,"/.*")+")$","i");!this.accept||r.test(e.type)||r.test(t)?(e.loaded=0,e.held=!0,e.status=this.i18n.uploading.status.held,this.unshift("files",e),this.noAuto||this._uploadFile(e)):this.dispatchEvent(new CustomEvent("file-reject",{detail:{file:e,error:this.i18n.error.incorrectFileType}}))}_removeFile(e){this.files.indexOf(e)>-1&&this.splice("files",this.files.indexOf(e),1)}_onAddFilesTouchEnd(e){e.preventDefault(),this.__resetMouseCanceller(),this._onAddFilesClick()}__resetMouseCanceller(){o()}_onAddFilesClick(){this.maxFilesReached||(this.$.fileInput.value="",this.$.fileInput.click())}_onFileInputChange(e){this._addFiles(e.target.files)}_onFileStart(e){this._uploadFile(e.detail.file)}_onFileRetry(e){this._retryFileUpload(e.detail.file)}_onFileAbort(e){this._abortFileUpload(e.detail.file)}_onFileRemove(e){this._removeFile(e.detail.file)}_dragoverChanged(e){e?this.setAttribute("dragover",e):this.removeAttribute("dragover")}_dragoverValidChanged(e){e?this.setAttribute("dragover-valid",e):this.removeAttribute("dragover-valid")}_i18nPlural(e,t){return 1==e?t.one:t.many}_isMultiple(e){return 1!=e}}customElements.define(x.is,x);let E;l("vaadin-upload",d(E||(E=(e=>e)`:host(.foxy-downloadable-form-upload) vaadin-upload-file{padding:var(--lumo-space-xs) 0 0 0;line-height:var(--lumo-line-height-xs)}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(commands){margin-right:-4px}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(progress){margin-right:2px;margin-left:0}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(clear-button),:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(retry-button),:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(start-button){display:none}:host(.foxy-downloadable-form-upload[disabled]) vaadin-upload-file::part(status){color:var(--lumo-disabled-text-color)}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(done-icon),:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(warning-icon){width:0;margin:0;opacity:0}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(info){align-items:flex-start}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(name){font-weight:500}`)));let B,F=e=>e;customElements.define("foxy-internal-downloadable-form-upload-control",class extends e{get uploadElement(){return this.renderRoot.querySelector("vaadin-upload")}renderControl(){return A(B||(B=F` <section class="${0}"> <foxy-i18n infer="" class="font-medium text-s" key="label"></foxy-i18n> <vaadin-upload max-file-size="524288000" max-files="${0}" style="padding:calc((.625em + (var(--lumo-border-radius)/ 4) - 1px) - var(--lumo-space-xs)) calc(.625em + (var(--lumo-border-radius)/ 4) - 1px)" class="${0}" method="PUT" no-auto ?disabled="${0}" ?readonly="${0}" .i18n="${0}" @files-changed="${0}" @upload-request="${0}"> </vaadin-upload> <foxy-i18n infer="" class="text-xs" key="helper_text"></foxy-i18n> </section> `),p({"grid gap-xs group leading-xs transition-colors":!0,"hover-text-body":!this.disabled&&!this.readonly,"text-secondary":!this.disabled,"text-disabled":this.disabled}),u(this.disabled||this.readonly?"0":"2"),p({"rounded-t-l rounded-b-l border transition-colors":!0,"border-dashed border-contrast-30":this.readonly,"border-solid border-contrast-10":!this.readonly,"group-hover-border-contrast-20":!this.disabled&&!this.readonly,"foxy-downloadable-form-upload":!0}),this.disabled,this.readonly,this.__uploadI18n,this.__handleFilesChanged,this.__handleUploadRequest)}updated(e){super.updated(e);const t=this.nucleon,r=this.renderRoot.querySelector("vaadin-upload");r&&t&&(t.in({idle:{snapshot:"clean"}})&&0===r.files.length?r.files=[{complete:!0,progress:100,status:this.t("status_complete"),name:t.data.file_name}]:t.in({idle:{template:"clean"}})&&(r.files=[]))}get __uploadI18n(){return{dropFiles:{one:this.t("drop_label"),many:this.t("drop_label")},addFiles:{one:this.t("select_label"),many:this.t("select_label")},cancel:this.t("cancel"),error:{tooManyFiles:this.t("error_too_many_files"),fileIsTooBig:this.t("error_too_big"),incorrectFileType:""},uploading:{status:{connecting:this.t("status_connecting"),stalled:this.t("status_stalled"),processing:this.t("status_processing"),held:this.t("status_held")},remainingTime:{prefix:this.t("remaining_prefix"),unknown:this.t("remaining_unknown")},error:{serverUnavailable:this.t("error_server_unavailable"),unexpectedServerError:this.t("error_unexpected_server_error"),forbidden:this.t("error_forbidden")}},units:{size:["B","KB","MB","GB"],sizeBase:1024}}}__handleUploadRequest(e){e.preventDefault(),e.detail.xhr.send(e.detail.file)}__handleFilesChanged(e){var t,r,a;const o=e.currentTarget,i=this.nucleon,s=o.files;s.length>1&&(o.files=[o.files[0]]),(null===(t=s[0])||void 0===t?void 0:t.complete)&&!s[0].status&&(s[0].status=this.t("status_complete"));const l=null!==(a=null===(r=o.files[0])||void 0===r?void 0:r.name)&&void 0!==a?a:"";l!==(null==i?void 0:i.form.file_name)&&(null==i||i.edit({file_name:l}))}});let C,k=e=>e;customElements.define("foxy-internal-async-combo-box-control",class extends t{constructor(){var e;super(...arguments),e=this,this.allowCustomValue=!1,this.itemLabelPath=null,this.itemValuePath=null,this.selectedItem=void 0,this.first=null,this.__dataProvider=async function(t,r){if(!e.first)return r([],0);const a=new URL(e.first);a.searchParams.set("offset",String(t.page*t.pageSize)),a.searchParams.set("limit",String(t.pageSize)),t.filter&&e.itemLabelPath&&a.searchParams.set(e.itemLabelPath,`*${t.filter}*`);const o=await new h(e).fetch(a.toString());if(!o.ok)throw new Error(await o.text());const i=await o.json();r(Array.from(Object.values(i._embedded))[0],i.total_items)}}static get properties(){return c(c({},super.properties),{},{allowCustomValue:{type:Boolean,attribute:"allow-custom-value"},itemLabelPath:{type:String,attribute:"item-label-path"},itemValuePath:{type:String,attribute:"item-value-path"},selectedItem:{attribute:!1},first:{type:String}})}renderControl(){var e,t;return A(C||(C=k` <vaadin-combo-box item-value-path="${0}" item-label-path="${0}" error-message="${0}" item-id-path="_links.self.href" helper-text="${0}" placeholder="${0}" label="${0}" class="w-full" ?allow-custom-value="${0}" ?disabled="${0}" ?readonly="${0}" clear-button-visible .checkValidity="${0}" .dataProvider="${0}" .selectedItem="${0}" .value="${0}" @change="${0}"> </vaadin-combo-box> `),u(null!==(e=this.itemValuePath)&&void 0!==e?e:void 0),u(null!==(t=this.itemLabelPath)&&void 0!==t?t:void 0),u(this._errorMessage),this.helperText,this.placeholder,this.label,this.allowCustomValue,this.disabled,this.readonly,this._checkValidity,this.__dataProvider,this.selectedItem,this._value,(e=>{e.stopPropagation();const t=e.currentTarget;this._value=t.value,this._value===t.value?(this.selectedItem=t.selectedItem,this.dispatchEvent(new CustomEvent("selected-item-changed"))):t.value=this._value}))}updated(e){if(super.updated(e),e.has("first")||e.has("itemLabelPath")){const e=this.renderRoot.querySelector("vaadin-combo-box");e&&(e.size=0,e.size=1)}}get _value(){var e;return null!==(e=super._value)&&void 0!==e?e:""}set _value(e){super._value=e}});let j,I=e=>e;const S=n(g,"downloadable-form");class Q extends S{constructor(){super(...arguments),this.downloadableItemCategories=null,this.__downloadableItemCategoryLoaderId="downloadableItemCategoryLoader"}static get properties(){return c(c({},super.properties),{},{downloadableItemCategories:{attribute:"downloadable-item-categories"}})}static get v8n(){return[({item_category_uri:e})=>!!e||"item-category-uri:v8n_required",({file_name:e})=>!!e||"upload:v8n_required",({price:e})=>"number"==typeof e||"price:v8n_required",({price:e})=>!e||e>=0||"price:v8n_negative",({name:e})=>!!e||"name:v8n_required",({name:e})=>!e||e.length<=100||"name:v8n_too_long",({code:e})=>!!e||"code:v8n_required",({code:e})=>!e||e.length<=50||"code:v8n_too_long"]}get disabledSelector(){const e=[],t=this.__downloadableItemCategoryLoader;return(null==t?void 0:t.in("idle"))||e.push("item-category-uri"),new m(`${e.join(" ")}${super.disabledSelector}`)}renderBody(){var e,t;return A(j||(j=I` ${0} <foxy-internal-async-combo-box-control item-label-path="name" item-value-path="_links.self.href" item-id-path="_links.self.href" infer="item-category-uri" first="${0}" .selectedItem="${0}" .setValue="${0}"> </foxy-internal-async-combo-box-control> <foxy-internal-text-control infer="name"></foxy-internal-text-control> <foxy-internal-text-control infer="code"></foxy-internal-text-control> <foxy-internal-number-control infer="price" min="0"></foxy-internal-number-control> <foxy-internal-downloadable-form-upload-control infer="upload"> </foxy-internal-downloadable-form-upload-control> ${0} <foxy-nucleon class="hidden" infer="" href="${0}" id="${0}" @update="${0}"> </foxy-nucleon> `),this.renderHeader(),u(null!==(e=this.downloadableItemCategories)&&void 0!==e?e:void 0),null===(t=this.__downloadableItemCategoryLoader)||void 0===t?void 0:t.data,(e=>{var t;this.edit({item_category_uri:e});const r=parseInt(null!==(t=e.split("/").pop())&&void 0!==t?t:"");isNaN(r)||this.edit({item_category_id:r})}),super.renderBody(),u(this.form.item_category_uri||void 0),this.__downloadableItemCategoryLoaderId,(()=>this.requestUpdate()))}async _sendPatch(e){const t=await super._sendPatch(e),r=t._links["fx:create_upload_url"].href,a=this.renderRoot.querySelector('[infer="upload"]'),o=null==a?void 0:a.uploadElement;if(o&&1===o.files.length){const e=o.files[0],t=await this._fetch(r,{method:"POST",body:JSON.stringify({type:e.type})});o.files[0].uploadTarget=t.upload_url,o.uploadFiles()}return t}async _sendPost(e){const t=await super._sendPost(e),r=t._links["fx:create_upload_url"].href,a=this.renderRoot.querySelector('[infer="upload"]'),o=null==a?void 0:a.uploadElement;if(o&&1===o.files.length){const e=o.files[0],t=await this._fetch(r,{method:"POST",body:JSON.stringify({type:e.type})});o.files[0].uploadTarget=t.upload_url,o.uploadFiles()}return t}get __downloadableItemCategoryLoader(){return this.renderRoot.querySelector(`#${this.__downloadableItemCategoryLoaderId}`)}}customElements.define("foxy-downloadable-form",Q);export{Q as DownloadableForm};
|
|
505
|
+
`}static get is(){return"vaadin-upload"}static get version(){return"4.4.3"}static get properties(){return{nodrop:{type:Boolean,reflectToAttribute:!0,value:function(){try{return!!document.createEvent("TouchEvent")}catch(e){return!1}}},target:{type:String,value:""},method:{type:String,value:"POST"},headers:{type:Object,value:{}},timeout:{type:Number,value:0},_dragover:{type:Boolean,value:!1,observer:"_dragoverChanged"},files:{type:Array,notify:!0,value:function(){return[]}},maxFiles:{type:Number,value:1/0},maxFilesReached:{type:Boolean,value:!1,notify:!0,readOnly:!0,reflectToAttribute:!0,computed:"_maxFilesAdded(maxFiles, files.length)"},accept:{type:String,value:""},maxFileSize:{type:Number,value:1/0},_dragoverValid:{type:Boolean,value:!1,observer:"_dragoverValidChanged"},formDataName:{type:String,value:"file"},noAuto:{type:Boolean,value:!1},withCredentials:{type:Boolean,value:!1},capture:String,i18n:{type:Object,value:function(){return{dropFiles:{one:"Drop file here",many:"Drop files here"},addFiles:{one:"Upload File...",many:"Upload Files..."},cancel:"Cancel",error:{tooManyFiles:"Too Many Files.",fileIsTooBig:"File is Too Big.",incorrectFileType:"Incorrect File Type."},uploading:{status:{connecting:"Connecting...",stalled:"Stalled.",processing:"Processing File...",held:"Queued"},remainingTime:{prefix:"remaining time: ",unknown:"unknown remaining time"},error:{serverUnavailable:"Server Unavailable",unexpectedServerError:"Unexpected Server Error",forbidden:"Forbidden"}},units:{size:["B","kB","MB","GB","TB","PB","EB","ZB","YB"]}}}}}}ready(){super.ready(),this.addEventListener("dragover",this._onDragover.bind(this)),this.addEventListener("dragleave",this._onDragleave.bind(this)),this.addEventListener("drop",this._onDrop.bind(this)),this.addEventListener("file-retry",this._onFileRetry.bind(this)),this.addEventListener("file-abort",this._onFileAbort.bind(this)),this.addEventListener("file-remove",this._onFileRemove.bind(this)),this.addEventListener("file-start",this._onFileStart.bind(this))}_formatSize(e){if("function"==typeof this.i18n.formatSize)return this.i18n.formatSize(e);const t=this.i18n.units.sizeBase||1e3,r=~~(Math.log(e)/Math.log(t)),a=Math.max(0,Math.min(3,r-1));return parseFloat((e/Math.pow(t,r)).toFixed(a))+" "+this.i18n.units.size[r]}_splitTimeByUnits(e){const t=[60,60,24,1/0],r=[0];for(var a=0;a<t.length&&e>0;a++)r[a]=e%t[a],e=Math.floor(e/t[a]);return r}_formatTime(e,t){if("function"==typeof this.i18n.formatTime)return this.i18n.formatTime(e,t);for(;t.length<3;)t.push(0);return t.reverse().map((e=>(e<10?"0":"")+e)).join(":")}_formatFileProgress(e){return e.totalStr+": "+e.progress+"% ("+(e.loaded>0?this.i18n.uploading.remainingTime.prefix+e.remainingStr:this.i18n.uploading.remainingTime.unknown)+")"}_maxFilesAdded(e,t){return e>=0&&t>=e}_onDragover(e){e.preventDefault(),this.nodrop||this._dragover||(this._dragoverValid=!this.maxFilesReached,this._dragover=!0),e.dataTransfer.dropEffect=!this._dragoverValid||this.nodrop?"none":"copy"}_onDragleave(e){e.preventDefault(),this._dragover&&!this.nodrop&&(this._dragover=this._dragoverValid=!1)}_onDrop(e){this.nodrop||(e.preventDefault(),this._dragover=this._dragoverValid=!1,this._addFiles(e.dataTransfer.files))}_createXhr(){return new XMLHttpRequest}_configureXhr(e){if("string"==typeof this.headers)try{this.headers=JSON.parse(this.headers)}catch(e){this.headers=void 0}for(var t in this.headers)e.setRequestHeader(t,this.headers[t]);this.timeout&&(e.timeout=this.timeout),e.withCredentials=this.withCredentials}_setStatus(e,t,r,a){e.elapsed=a,e.elapsedStr=this._formatTime(e.elapsed,this._splitTimeByUnits(e.elapsed)),e.remaining=Math.ceil(a*(t/r-1)),e.remainingStr=this._formatTime(e.remaining,this._splitTimeByUnits(e.remaining)),e.speed=~~(t/a/1024),e.totalStr=this._formatSize(t),e.loadedStr=this._formatSize(r),e.status=this._formatFileProgress(e)}uploadFiles(e){e&&!Array.isArray(e)&&(e=[e]),e=(e=e||this.files).filter((e=>!e.complete)),Array.prototype.forEach.call(e,this._uploadFile.bind(this))}_uploadFile(e){if(e.uploading)return;const t=Date.now(),r=e.xhr=this._createXhr();let a,o;r.upload.onprogress=i=>{clearTimeout(a),o=Date.now();const s=(o-t)/1e3,l=i.loaded,n=i.total,d=~~(l/n*100);e.loaded=l,e.progress=d,e.indeterminate=l<=0||l>=n,e.error?e.indeterminate=e.status=void 0:e.abort||(d<100?(this._setStatus(e,n,l,s),a=setTimeout((()=>{e.status=this.i18n.uploading.status.stalled,this._notifyFileChanges(e)}),2e3)):(e.loadedStr=e.totalStr,e.status=this.i18n.uploading.status.processing)),this._notifyFileChanges(e),this.dispatchEvent(new CustomEvent("upload-progress",{detail:{file:e,xhr:r}}))},r.onreadystatechange=()=>{if(4==r.readyState){if(clearTimeout(a),e.indeterminate=e.uploading=!1,e.abort)return void this._notifyFileChanges(e);e.status="";if(!this.dispatchEvent(new CustomEvent("upload-response",{detail:{file:e,xhr:r},cancelable:!0})))return;0===r.status?e.error=this.i18n.uploading.error.serverUnavailable:r.status>=500?e.error=this.i18n.uploading.error.unexpectedServerError:r.status>=400&&(e.error=this.i18n.uploading.error.forbidden),e.complete=!e.error,this.dispatchEvent(new CustomEvent("upload-"+(e.error?"error":"success"),{detail:{file:e,xhr:r}})),this._notifyFileChanges(e)}};const i=new FormData;e.uploadTarget=e.uploadTarget||this.target||"",e.formDataName=this.formDataName;if(!this.dispatchEvent(new CustomEvent("upload-before",{detail:{file:e,xhr:r},cancelable:!0})))return;i.append(e.formDataName,e,e.name),r.open(this.method,e.uploadTarget,!0),this._configureXhr(r),e.status=this.i18n.uploading.status.connecting,e.uploading=e.indeterminate=!0,e.complete=e.abort=e.error=e.held=!1,r.upload.onloadstart=()=>{this.dispatchEvent(new CustomEvent("upload-start",{detail:{file:e,xhr:r}})),this._notifyFileChanges(e)};this.dispatchEvent(new CustomEvent("upload-request",{detail:{file:e,xhr:r,formData:i},cancelable:!0}))&&r.send(i)}_retryFileUpload(e){this.dispatchEvent(new CustomEvent("upload-retry",{detail:{file:e,xhr:e.xhr},cancelable:!0}))&&this._uploadFile(e)}_abortFileUpload(e){this.dispatchEvent(new CustomEvent("upload-abort",{detail:{file:e,xhr:e.xhr},cancelable:!0}))&&(e.abort=!0,e.xhr&&e.xhr.abort(),this._notifyFileChanges(e))}_notifyFileChanges(e){var t="files."+this.files.indexOf(e)+".";for(var r in e)e.hasOwnProperty(r)&&this.notifyPath(t+r,e[r])}_addFiles(e){Array.prototype.forEach.call(e,this._addFile.bind(this))}_addFile(e){if(this.maxFilesReached)return void this.dispatchEvent(new CustomEvent("file-reject",{detail:{file:e,error:this.i18n.error.tooManyFiles}}));if(this.maxFileSize>=0&&e.size>this.maxFileSize)return void this.dispatchEvent(new CustomEvent("file-reject",{detail:{file:e,error:this.i18n.error.fileIsTooBig}}));const t=e.name.match(/\.[^\.]*$|$/)[0],r=new RegExp("^("+this.accept.replace(/[, ]+/g,"|").replace(/\/\*/g,"/.*")+")$","i");!this.accept||r.test(e.type)||r.test(t)?(e.loaded=0,e.held=!0,e.status=this.i18n.uploading.status.held,this.unshift("files",e),this.noAuto||this._uploadFile(e)):this.dispatchEvent(new CustomEvent("file-reject",{detail:{file:e,error:this.i18n.error.incorrectFileType}}))}_removeFile(e){this.files.indexOf(e)>-1&&this.splice("files",this.files.indexOf(e),1)}_onAddFilesTouchEnd(e){e.preventDefault(),this.__resetMouseCanceller(),this._onAddFilesClick()}__resetMouseCanceller(){o()}_onAddFilesClick(){this.maxFilesReached||(this.$.fileInput.value="",this.$.fileInput.click())}_onFileInputChange(e){this._addFiles(e.target.files)}_onFileStart(e){this._uploadFile(e.detail.file)}_onFileRetry(e){this._retryFileUpload(e.detail.file)}_onFileAbort(e){this._abortFileUpload(e.detail.file)}_onFileRemove(e){this._removeFile(e.detail.file)}_dragoverChanged(e){e?this.setAttribute("dragover",e):this.removeAttribute("dragover")}_dragoverValidChanged(e){e?this.setAttribute("dragover-valid",e):this.removeAttribute("dragover-valid")}_i18nPlural(e,t){return 1==e?t.one:t.many}_isMultiple(e){return 1!=e}}customElements.define(x.is,x);let E;l("vaadin-upload",d(E||(E=(e=>e)`:host(.foxy-downloadable-form-upload) vaadin-upload-file{padding:var(--lumo-space-xs) 0 0 0;line-height:var(--lumo-line-height-xs)}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(commands){margin-right:-4px}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(progress){margin-right:2px;margin-left:0}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(clear-button),:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(retry-button),:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(start-button){display:none}:host(.foxy-downloadable-form-upload[disabled]) vaadin-upload-file::part(status){color:var(--lumo-disabled-text-color)}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(done-icon),:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(warning-icon){width:0;margin:0;opacity:0}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(info){align-items:flex-start}:host(.foxy-downloadable-form-upload) vaadin-upload-file::part(name){font-weight:500}`)));let B,F=e=>e;customElements.define("foxy-internal-downloadable-form-upload-control",class extends e{get uploadElement(){return this.renderRoot.querySelector("vaadin-upload")}renderControl(){return A(B||(B=F` <section class="${0}"> <foxy-i18n infer="" class="font-medium text-s" key="label"></foxy-i18n> <vaadin-upload max-file-size="524288000" max-files="${0}" style="padding:calc((.625em + (var(--lumo-border-radius)/ 4) - 1px) - var(--lumo-space-xs)) calc(.625em + (var(--lumo-border-radius)/ 4) - 1px)" class="${0}" method="PUT" no-auto ?disabled="${0}" ?readonly="${0}" .i18n="${0}" @files-changed="${0}" @upload-request="${0}"> </vaadin-upload> <foxy-i18n infer="" class="text-xs" key="helper_text"></foxy-i18n> </section> `),p({"grid gap-xs group leading-xs transition-colors":!0,"hover-text-body":!this.disabled&&!this.readonly,"text-secondary":!this.disabled,"text-disabled":this.disabled}),u(this.disabled||this.readonly?"0":"2"),p({"rounded-t-l rounded-b-l border transition-colors":!0,"border-dashed border-contrast-30":this.readonly,"border-solid border-contrast-10":!this.readonly,"group-hover-border-contrast-20":!this.disabled&&!this.readonly,"foxy-downloadable-form-upload":!0}),this.disabled,this.readonly,this.__uploadI18n,this.__handleFilesChanged,this.__handleUploadRequest)}updated(e){super.updated(e);const t=this.nucleon,r=this.renderRoot.querySelector("vaadin-upload");r&&t&&(t.in({idle:{snapshot:"clean"}})&&0===r.files.length?r.files=[{complete:!0,progress:100,status:this.t("status_complete"),name:t.data.file_name}]:t.in({idle:{template:"clean"}})&&(r.files=[]))}get __uploadI18n(){return{dropFiles:{one:this.t("drop_label"),many:this.t("drop_label")},addFiles:{one:this.t("select_label"),many:this.t("select_label")},cancel:this.t("cancel"),error:{tooManyFiles:this.t("error_too_many_files"),fileIsTooBig:this.t("error_too_big"),incorrectFileType:""},uploading:{status:{connecting:this.t("status_connecting"),stalled:this.t("status_stalled"),processing:this.t("status_processing"),held:this.t("status_held")},remainingTime:{prefix:this.t("remaining_prefix"),unknown:this.t("remaining_unknown")},error:{serverUnavailable:this.t("error_server_unavailable"),unexpectedServerError:this.t("error_unexpected_server_error"),forbidden:this.t("error_forbidden")}},units:{size:["B","KB","MB","GB"],sizeBase:1024}}}__handleUploadRequest(e){e.preventDefault(),e.detail.xhr.send(e.detail.file)}__handleFilesChanged(e){var t,r,a;const o=e.currentTarget,i=this.nucleon,s=o.files;s.length>1&&(o.files=[o.files[0]]),(null===(t=s[0])||void 0===t?void 0:t.complete)&&!s[0].status&&(s[0].status=this.t("status_complete")),null==i||i.edit({file_name:null!==(a=null===(r=o.files[0])||void 0===r?void 0:r.name)&&void 0!==a?a:""})}});let C,k=e=>e;customElements.define("foxy-internal-async-combo-box-control",class extends t{constructor(){var e;super(...arguments),e=this,this.allowCustomValue=!1,this.itemLabelPath=null,this.itemValuePath=null,this.selectedItem=void 0,this.first=null,this.__dataProvider=async function(t,r){if(!e.first)return r([],0);const a=new URL(e.first);a.searchParams.set("offset",String(t.page*t.pageSize)),a.searchParams.set("limit",String(t.pageSize)),t.filter&&e.itemLabelPath&&a.searchParams.set(e.itemLabelPath,`*${t.filter}*`);const o=await new h(e).fetch(a.toString());if(!o.ok)throw new Error(await o.text());const i=await o.json();r(Array.from(Object.values(i._embedded))[0],i.total_items)}}static get properties(){return c(c({},super.properties),{},{allowCustomValue:{type:Boolean,attribute:"allow-custom-value"},itemLabelPath:{type:String,attribute:"item-label-path"},itemValuePath:{type:String,attribute:"item-value-path"},selectedItem:{attribute:!1},first:{type:String}})}renderControl(){var e,t;return A(C||(C=k` <vaadin-combo-box item-value-path="${0}" item-label-path="${0}" error-message="${0}" item-id-path="_links.self.href" helper-text="${0}" placeholder="${0}" label="${0}" class="w-full" ?allow-custom-value="${0}" ?disabled="${0}" ?readonly="${0}" clear-button-visible .checkValidity="${0}" .dataProvider="${0}" .selectedItem="${0}" .value="${0}" @change="${0}"> </vaadin-combo-box> `),u(null!==(e=this.itemValuePath)&&void 0!==e?e:void 0),u(null!==(t=this.itemLabelPath)&&void 0!==t?t:void 0),u(this._errorMessage),this.helperText,this.placeholder,this.label,this.allowCustomValue,this.disabled,this.readonly,this._checkValidity,this.__dataProvider,this.selectedItem,this._value,(e=>{e.stopPropagation();const t=e.currentTarget;this._value=t.value,this._value===t.value?(this.selectedItem=t.selectedItem,this.dispatchEvent(new CustomEvent("selected-item-changed"))):t.value=this._value}))}updated(e){if(super.updated(e),e.has("first")||e.has("itemLabelPath")){const e=this.renderRoot.querySelector("vaadin-combo-box");e&&(e.size=0,e.size=1)}}get _value(){var e;return null!==(e=super._value)&&void 0!==e?e:""}set _value(e){super._value=e}});let j,I=e=>e;const S=n(g,"downloadable-form");class Q extends S{constructor(){super(...arguments),this.downloadableItemCategories=null,this.__downloadableItemCategoryLoaderId="downloadableItemCategoryLoader"}static get properties(){return c(c({},super.properties),{},{downloadableItemCategories:{attribute:"downloadable-item-categories"}})}static get v8n(){return[({item_category_uri:e})=>!!e||"item-category-uri:v8n_required",({file_name:e})=>!!e||"upload:v8n_required",({price:e})=>"number"==typeof e||"price:v8n_required",({price:e})=>!e||e>=0||"price:v8n_negative",({name:e})=>!!e||"name:v8n_required",({name:e})=>!e||e.length<=100||"name:v8n_too_long",({code:e})=>!!e||"code:v8n_required",({code:e})=>!e||e.length<=50||"code:v8n_too_long"]}get disabledSelector(){const e=[],t=this.__downloadableItemCategoryLoader;return(null==t?void 0:t.in("idle"))||e.push("item-category-uri"),new m(`${e.join(" ")}${super.disabledSelector}`)}renderBody(){var e,t;return A(j||(j=I` ${0} <foxy-internal-async-combo-box-control item-label-path="name" item-value-path="_links.self.href" item-id-path="_links.self.href" infer="item-category-uri" first="${0}" .selectedItem="${0}" .setValue="${0}"> </foxy-internal-async-combo-box-control> <foxy-internal-text-control infer="name"></foxy-internal-text-control> <foxy-internal-text-control infer="code"></foxy-internal-text-control> <foxy-internal-number-control infer="price" min="0"></foxy-internal-number-control> <foxy-internal-downloadable-form-upload-control infer="upload"> </foxy-internal-downloadable-form-upload-control> ${0} <foxy-nucleon class="hidden" infer="" href="${0}" id="${0}" @update="${0}"> </foxy-nucleon> `),this.renderHeader(),u(null!==(e=this.downloadableItemCategories)&&void 0!==e?e:void 0),null===(t=this.__downloadableItemCategoryLoader)||void 0===t?void 0:t.data,(e=>{var t;this.edit({item_category_uri:e});const r=parseInt(null!==(t=e.split("/").pop())&&void 0!==t?t:"");isNaN(r)||this.edit({item_category_id:r})}),super.renderBody(),u(this.form.item_category_uri||void 0),this.__downloadableItemCategoryLoaderId,(()=>this.requestUpdate()))}async _sendPatch(e){const t=await super._sendPatch(e),r=t._links["fx:create_upload_url"].href,a=this.renderRoot.querySelector('[infer="upload"]'),o=null==a?void 0:a.uploadElement;if(o&&1===o.files.length){const e=o.files[0],t=await this._fetch(r,{method:"POST",body:JSON.stringify({type:e.type})});o.files[0].uploadTarget=t.upload_url,o.uploadFiles()}return t}async _sendPost(e){const t=await super._sendPost(e),r=t._links["fx:create_upload_url"].href,a=this.renderRoot.querySelector('[infer="upload"]'),o=null==a?void 0:a.uploadElement;if(o&&1===o.files.length){const e=o.files[0],t=await this._fetch(r,{method:"POST",body:JSON.stringify({type:e.type})});o.files[0].uploadTarget=t.upload_url,o.uploadFiles()}return t}get __downloadableItemCategoryLoader(){return this.renderRoot.querySelector(`#${this.__downloadableItemCategoryLoaderId}`)}}customElements.define("foxy-downloadable-form",Q);export{Q as DownloadableForm};
|
|
@@ -116,9 +116,7 @@ export class InternalDownloadableFormUploadControl extends InternalControl {
|
|
|
116
116
|
upload.files = [upload.files[0]];
|
|
117
117
|
if (((_a = files[0]) === null || _a === void 0 ? void 0 : _a.complete) && !files[0].status)
|
|
118
118
|
files[0].status = this.t('status_complete');
|
|
119
|
-
|
|
120
|
-
if (newName !== (nucleon === null || nucleon === void 0 ? void 0 : nucleon.form.file_name))
|
|
121
|
-
nucleon === null || nucleon === void 0 ? void 0 : nucleon.edit({ file_name: newName });
|
|
119
|
+
nucleon === null || nucleon === void 0 ? void 0 : nucleon.edit({ file_name: (_c = (_b = upload.files[0]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '' });
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
122
|
//# sourceMappingURL=InternalDownloadableFormUploadControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalDownloadableFormUploadControl.js","sourceRoot":"","sources":["../../../../../../src/elements/public/DownloadableForm/internal/InternalDownloadableFormUploadControl/InternalDownloadableFormUploadControl.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAkB,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,gEAA6D;AACvF,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,0CAAuC;AAE1D,MAAM,OAAO,qCAAsC,SAAQ,eAAe;IACxE,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAAgB,eAAe,CAAC,CAAC;IACvE,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAA;;gBAEC,QAAQ,CAAC;YACf,gDAAgD,EAAE,IAAI;YACtD,iBAAiB,EAAE,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ;YACnD,gBAAgB,EAAE,CAAC,IAAI,CAAC,QAAQ;YAChC,eAAe,EAAE,IAAI,CAAC,QAAQ;SAC/B,CAAC;;;;;;sBAMY,SAAS,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;;kBAEzD,QAAQ,CAAC;YACf,kDAAkD,EAAE,IAAI;YACxD,kCAAkC,EAAE,IAAI,CAAC,QAAQ;YACjD,iCAAiC,EAAE,CAAC,IAAI,CAAC,QAAQ;YACjD,gCAAgC,EAAE,CAAC,IAAI,CA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IAAI,CAAC,CAAC;IACvC,CAAC;IAEO,oBAAoB,CAAC,GAAgB;;QAC3C,MAAM,MAAM,GAAG,GAAG,CAAC,aAA8B,CAAC;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAkC,CAAC;QAExD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,IAAI,OAAA,KAAK,CAAC,CAAC,CAAC,0CAAE,QAAQ,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;YAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"InternalDownloadableFormUploadControl.js","sourceRoot":"","sources":["../../../../../../src/elements/public/DownloadableForm/internal/InternalDownloadableFormUploadControl/InternalDownloadableFormUploadControl.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAkB,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,gEAA6D;AACvF,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,0CAAuC;AAE1D,MAAM,OAAO,qCAAsC,SAAQ,eAAe;IACxE,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAAgB,eAAe,CAAC,CAAC;IACvE,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAA;;gBAEC,QAAQ,CAAC;YACf,gDAAgD,EAAE,IAAI;YACtD,iBAAiB,EAAE,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ;YACnD,gBAAgB,EAAE,CAAC,IAAI,CAAC,QAAQ;YAChC,eAAe,EAAE,IAAI,CAAC,QA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AAiB,CAAC;iBACrC;aACF;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;gBAC7B,QAAQ,EAAE,IAAI;aACf;SACF,CAAC;IACJ,CAAC;IAEO,qBAAqB,CAAC,GAAqD;QACjF,GAAG,CAAC,cAAc,EAAE,CAAC;QACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAEO,oBAAoB,CAAC,GAAgB;;QAC3C,MAAM,MAAM,GAAG,GAAG,CAAC,aAA8B,CAAC;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAkC,CAAC;QAExD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,IAAI,OAAA,KAAK,CAAC,CAAC,CAAC,0CAAE,QAAQ,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;YAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;QACxF,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,EAAE,SAAS,cAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,0CAAE,IAAI,mCAAI,EAAE,EAAE,EAAE;IAC5D,CAAC;CACF","sourcesContent":["import type { DownloadableForm } from '../../DownloadableForm';\nimport type { UploadElement } from '@vaadin/vaadin-upload';\n\nimport { html, TemplateResult } from 'lit-html';\nimport { InternalControl } from '../../../../internal/InternalControl/InternalControl';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport { classMap } from '../../../../../utils/class-map';\n\nexport class InternalDownloadableFormUploadControl extends InternalControl {\n get uploadElement(): UploadElement | null {\n return this.renderRoot.querySelector<UploadElement>('vaadin-upload');\n }\n\n renderControl(): TemplateResult {\n return html`\n <section\n class=${classMap({\n 'grid gap-xs group leading-xs transition-colors': true,\n 'hover-text-body': !this.disabled && !this.readonly,\n 'text-secondary': !this.disabled,\n 'text-disabled': this.disabled,\n })}\n >\n <foxy-i18n infer=\"\" class=\"font-medium text-s\" key=\"label\"></foxy-i18n>\n\n <vaadin-upload\n max-file-size=\"524288000\"\n max-files=${ifDefined(this.disabled || this.readonly ? '0' : '2')}\n style=\"padding: calc((0.625em + (var(--lumo-border-radius) / 4) - 1px) - var(--lumo-space-xs)) calc(0.625em + (var(--lumo-border-radius) / 4) - 1px)\"\n class=${classMap({\n 'rounded-t-l rounded-b-l border transition-colors': true,\n 'border-dashed border-contrast-30': this.readonly,\n 'border-solid border-contrast-10': !this.readonly,\n 'group-hover-border-contrast-20': !this.disabled && !this.readonly,\n 'foxy-downloadable-form-upload': true,\n })}\n method=\"PUT\"\n no-auto\n ?disabled=${this.disabled}\n ?readonly=${this.readonly}\n .i18n=${this.__uploadI18n}\n @files-changed=${this.__handleFilesChanged}\n @upload-request=${this.__handleUploadRequest}\n >\n </vaadin-upload>\n\n <foxy-i18n infer=\"\" class=\"text-xs\" key=\"helper_text\"></foxy-i18n>\n </section>\n `;\n }\n\n updated(changes: Map<keyof this, unknown>): void {\n super.updated(changes);\n\n const nucleon = this.nucleon as DownloadableForm | null;\n const upload = this.renderRoot.querySelector<UploadElement>('vaadin-upload');\n\n if (upload && nucleon) {\n if (nucleon.in({ idle: { snapshot: 'clean' } }) && upload.files.length === 0) {\n upload.files = [\n // @ts-expect-error type doesn't match but it's ok because vaadin docs suggest this as a solution\n {\n complete: true,\n progress: 100,\n status: this.t('status_complete'),\n name: nucleon.data.file_name,\n },\n ];\n } else if (nucleon.in({ idle: { template: 'clean' } })) {\n upload.files = [];\n }\n }\n }\n\n private get __uploadI18n() {\n return {\n dropFiles: {\n one: this.t('drop_label'),\n many: this.t('drop_label'),\n },\n addFiles: {\n one: this.t('select_label'),\n many: this.t('select_label'),\n },\n cancel: this.t('cancel'),\n error: {\n tooManyFiles: this.t('error_too_many_files'),\n fileIsTooBig: this.t('error_too_big'),\n incorrectFileType: '',\n },\n uploading: {\n status: {\n connecting: this.t('status_connecting'),\n stalled: this.t('status_stalled'),\n processing: this.t('status_processing'),\n held: this.t('status_held'),\n },\n remainingTime: {\n prefix: this.t('remaining_prefix'),\n unknown: this.t('remaining_unknown'),\n },\n error: {\n serverUnavailable: this.t('error_server_unavailable'),\n unexpectedServerError: this.t('error_unexpected_server_error'),\n forbidden: this.t('error_forbidden'),\n },\n },\n units: {\n size: ['B', 'KB', 'MB', 'GB'],\n sizeBase: 1024,\n },\n };\n }\n\n private __handleUploadRequest(evt: CustomEvent<{ xhr: XMLHttpRequest; file: File }>) {\n evt.preventDefault();\n evt.detail.xhr.send(evt.detail.file);\n }\n\n private __handleFilesChanged(evt: CustomEvent) {\n const upload = evt.currentTarget as UploadElement;\n const nucleon = this.nucleon as DownloadableForm | null;\n\n const files = upload.files;\n if (files.length > 1) upload.files = [upload.files[0]];\n if (files[0]?.complete && !files[0].status) files[0].status = this.t('status_complete');\n nucleon?.edit({ file_name: upload.files[0]?.name ?? '' });\n }\n}\n"]}
|