primevue 3.12.5 → 3.12.6
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/core/core.js +22 -6
- package/core/core.min.js +2 -2
- package/fileupload/FileUpload.d.ts +12 -0
- package/fileupload/FileUpload.vue +21 -7
- package/fileupload/fileupload.cjs.js +41 -26
- package/fileupload/fileupload.cjs.min.js +1 -1
- package/fileupload/fileupload.esm.js +41 -26
- package/fileupload/fileupload.esm.min.js +1 -1
- package/fileupload/fileupload.js +41 -26
- package/fileupload/fileupload.min.js +1 -1
- package/inputnumber/InputNumber.d.ts +4 -0
- package/inputnumber/InputNumber.vue +20 -2
- package/inputnumber/inputnumber.cjs.js +21 -2
- package/inputnumber/inputnumber.cjs.min.js +1 -1
- package/inputnumber/inputnumber.esm.js +21 -2
- package/inputnumber/inputnumber.esm.min.js +1 -1
- package/inputnumber/inputnumber.js +21 -2
- package/inputnumber/inputnumber.min.js +1 -1
- package/package.json +1 -1
- package/password/Password.vue +1 -1
- package/password/password.cjs.js +1 -1
- package/password/password.cjs.min.js +1 -1
- package/password/password.esm.js +1 -1
- package/password/password.esm.min.js +1 -1
- package/password/password.js +1 -1
- package/password/password.min.js +1 -1
- package/resources/primevue.css +0 -4
- package/resources/primevue.min.css +1 -1
- package/resources/themes/arya-blue/theme.css +10 -0
- package/resources/themes/arya-green/theme.css +10 -0
- package/resources/themes/arya-orange/theme.css +10 -0
- package/resources/themes/arya-purple/theme.css +10 -0
- package/resources/themes/bootstrap4-dark-blue/theme.css +10 -0
- package/resources/themes/bootstrap4-dark-purple/theme.css +10 -0
- package/resources/themes/bootstrap4-light-blue/theme.css +10 -0
- package/resources/themes/bootstrap4-light-purple/theme.css +10 -0
- package/resources/themes/fluent-light/theme.css +10 -0
- package/resources/themes/lara-dark-blue/theme.css +10 -0
- package/resources/themes/lara-dark-indigo/theme.css +10 -0
- package/resources/themes/lara-dark-purple/theme.css +10 -0
- package/resources/themes/lara-dark-teal/theme.css +10 -0
- package/resources/themes/lara-light-blue/theme.css +10 -0
- package/resources/themes/lara-light-indigo/theme.css +10 -0
- package/resources/themes/lara-light-purple/theme.css +10 -0
- package/resources/themes/lara-light-teal/theme.css +10 -0
- package/resources/themes/luna-amber/theme.css +10 -0
- package/resources/themes/luna-blue/theme.css +10 -0
- package/resources/themes/luna-green/theme.css +10 -0
- package/resources/themes/luna-pink/theme.css +10 -0
- package/resources/themes/md-dark-deeppurple/theme.css +11 -3
- package/resources/themes/md-dark-indigo/theme.css +11 -3
- package/resources/themes/md-light-deeppurple/theme.css +11 -3
- package/resources/themes/md-light-indigo/theme.css +11 -3
- package/resources/themes/mdc-dark-deeppurple/theme.css +11 -3
- package/resources/themes/mdc-dark-indigo/theme.css +11 -3
- package/resources/themes/mdc-light-deeppurple/theme.css +11 -3
- package/resources/themes/mdc-light-indigo/theme.css +11 -3
- package/resources/themes/nova/theme.css +10 -0
- package/resources/themes/nova-accent/theme.css +10 -0
- package/resources/themes/nova-alt/theme.css +10 -0
- package/resources/themes/nova-vue/theme.css +10 -0
- package/resources/themes/rhea/theme.css +10 -0
- package/resources/themes/saga-blue/theme.css +10 -0
- package/resources/themes/saga-green/theme.css +10 -0
- package/resources/themes/saga-orange/theme.css +10 -0
- package/resources/themes/saga-purple/theme.css +10 -0
- package/resources/themes/tailwind-light/theme.css +10 -0
- package/resources/themes/vela-blue/theme.css +10 -0
- package/resources/themes/vela-green/theme.css +10 -0
- package/resources/themes/vela-orange/theme.css +10 -0
- package/resources/themes/vela-purple/theme.css +10 -0
- package/sidebar/Sidebar.d.ts +4 -0
- package/sidebar/Sidebar.vue +3 -0
- package/sidebar/sidebar.cjs.js +17 -8
- package/sidebar/sidebar.cjs.min.js +1 -1
- package/sidebar/sidebar.esm.js +18 -9
- package/sidebar/sidebar.esm.min.js +1 -1
- package/sidebar/sidebar.js +17 -8
- package/sidebar/sidebar.min.js +1 -1
- package/tree/TreeNode.vue +1 -4
- package/tree/tree.cjs.js +1 -4
- package/tree/tree.cjs.min.js +1 -1
- package/tree/tree.esm.js +1 -4
- package/tree/tree.esm.min.js +1 -1
- package/tree/tree.js +1 -4
- package/tree/tree.min.js +1 -1
- package/vetur-attributes.json +17 -1
- package/vetur-tags.json +4 -0
- package/web-types.json +49 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("primevue/button"),t=require("primevue/progressbar"),l=require("primevue/message"),i=require("primevue/utils"),s=require("primevue/ripple"),o=require("vue");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=a(e),r=a(t),p=a(l),d=a(s),c={name:"FileUpload",emits:["select","uploader","before-upload","progress","upload","error","before-send","clear","remove"],props:{name:{type:String,default:null},url:{type:String,default:null},mode:{type:String,default:"advanced"},multiple:{type:Boolean,default:!1},accept:{type:String,default:null},disabled:{type:Boolean,default:!1},auto:{type:Boolean,default:!1},maxFileSize:{type:Number,default:null},invalidFileSizeMessage:{type:String,default:"{0}: Invalid file size, file size should be smaller than {1}."},invalidFileTypeMessage:{type:String,default:"{0}: Invalid file type, allowed file types: {1}."},fileLimit:{type:Number,default:null},invalidFileLimitMessage:{type:String,default:"Maximum number of files exceeded, limit is {0} at most."},withCredentials:{type:Boolean,default:!1},previewWidth:{type:Number,default:50},chooseLabel:{type:String,default:null},uploadLabel:{type:String,default:null},cancelLabel:{type:String,default:null},customUpload:{type:Boolean,default:!1},showUploadButton:{type:Boolean,default:!0},showCancelButton:{type:Boolean,default:!0},style:null,class:null},duplicateIEEvent:!1,data:()=>({uploadedFileCount:0,files:[],messages:[],focused:!1,progress:null}),methods:{onFileSelect(e){if("drop"!==e.type&&this.isIE11()&&this.duplicateIEEvent)return void(this.duplicateIEEvent=!1);this.messages=[],this.files=this.files||[];let t=e.dataTransfer?e.dataTransfer.files:e.target.files;for(let e of t)this.isFileSelected(e)||this.validate(e)&&(this.isImage(e)&&(e.objectURL=window.URL.createObjectURL(e)),this.files.push(e));this.$emit("select",{originalEvent:e,files:this.files}),this.fileLimit&&this.checkFileLimit(),this.auto&&this.hasFiles&&!this.isFileLimitExceeded()&&this.upload(),"drop"!==e.type&&this.isIE11()?this.clearIEInput():this.clearInputElement()},choose(){this.$refs.fileInput.click()},upload(){if(this.customUpload)this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("uploader",{files:this.files}),this.clear();else{let e=new XMLHttpRequest,t=new FormData;this.$emit("before-upload",{xhr:e,formData:t});for(let e of this.files)t.append(this.name,e,e.name);e.upload.addEventListener("progress",(e=>{e.lengthComputable&&(this.progress=Math.round(100*e.loaded/e.total)),this.$emit("progress",{originalEvent:e,progress:this.progress})})),e.onreadystatechange=()=>{4===e.readyState&&(this.progress=0,e.status>=200&&e.status<300?(this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("upload",{xhr:e,files:this.files})):this.$emit("error",{xhr:e,files:this.files}),this.clear())},e.open("POST",this.url,!0),this.$emit("before-send",{xhr:e,formData:t}),e.withCredentials=this.withCredentials,e.send(t)}},clear(){this.files=[],this.messages=null,this.$emit("clear"),this.isAdvanced&&this.clearInputElement()},onFocus(){this.focused=!0},onBlur(){this.focused=!1},isFileSelected(e){if(this.files&&this.files.length)for(let t of this.files)if(t.name+t.type+t.size===e.name+e.type+e.size)return!0;return!1},isIE11:()=>!!window.MSInputMethodContext&&!!document.documentMode,validate(e){return this.accept&&!this.isFileTypeValid(e)?(this.messages.push(this.invalidFileTypeMessage.replace("{0}",e.name).replace("{1}",this.accept)),!1):!(this.maxFileSize&&e.size>this.maxFileSize)||(this.messages.push(this.invalidFileSizeMessage.replace("{0}",e.name).replace("{1}",this.formatSize(this.maxFileSize))),!1)},isFileTypeValid(e){let t=this.accept.split(",").map((e=>e.trim()));for(let l of t){if(this.isWildcard(l)?this.getTypeClass(e.type)===this.getTypeClass(l):e.type==l||this.getFileExtension(e).toLowerCase()===l.toLowerCase())return!0}return!1},getTypeClass:e=>e.substring(0,e.indexOf("/")),isWildcard:e=>-1!==e.indexOf("*"),getFileExtension:e=>"."+e.name.split(".").pop(),isImage:e=>/^image\//.test(e.type),onDragEnter(e){this.disabled||(e.stopPropagation(),e.preventDefault())},onDragOver(e){this.disabled||(i.DomHandler.addClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault())},onDragLeave(){this.disabled||i.DomHandler.removeClass(this.$refs.content,"p-fileupload-highlight")},onDrop(e){if(!this.disabled){i.DomHandler.removeClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault();const t=e.dataTransfer?e.dataTransfer.files:e.target.files;(this.multiple||t&&1===t.length)&&this.onFileSelect(e)}},onBasicUploaderClick(){this.hasFiles?this.upload():this.$refs.fileInput.click()},remove(e){this.clearInputElement();let t=this.files.splice(e,1)[0];this.files=[...this.files],this.$emit("remove",{file:t,files:this.files})},clearInputElement(){this.$refs.fileInput.value=""},clearIEInput(){this.$refs.fileInput&&(this.duplicateIEEvent=!0,this.$refs.fileInput.value="")},formatSize(e){if(0===e)return"0 B";let t=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,t)).toFixed(3))+" "+["B","KB","MB","GB","TB","PB","EB","ZB","YB"][t]},isFileLimitExceeded(){return this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount&&this.focused&&(this.focused=!1),this.fileLimit&&this.fileLimit<this.files.length+this.uploadedFileCount},checkFileLimit(){this.isFileLimitExceeded()&&this.messages.push(this.invalidFileLimitMessage.replace("{0}",this.fileLimit.toString()))},onMessageClose(){this.messages=null}},computed:{isAdvanced(){return"advanced"===this.mode},isBasic(){return"basic"===this.mode},advancedChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-fileupload-choose-selected":this.hasFiles,"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonIconClass(){return["p-button-icon p-button-icon-left pi",{"pi-plus":!this.hasFiles||this.auto,"pi-upload":this.hasFiles&&!this.auto}]},basicChooseButtonLabel(){return this.auto?this.chooseButtonLabel:this.hasFiles?this.files.map((e=>e.name)).join(", "):this.chooseButtonLabel},hasFiles(){return this.files&&this.files.length>0},chooseDisabled(){return this.disabled||this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount},uploadDisabled(){return this.disabled||!this.hasFiles||this.fileLimit&&this.fileLimit<this.files.length},cancelDisabled(){return this.disabled||!this.hasFiles},chooseButtonLabel(){return this.chooseLabel||this.$primevue.config.locale.choose},uploadButtonLabel(){return this.uploadLabel||this.$primevue.config.locale.upload},cancelButtonLabel(){return this.cancelLabel||this.$primevue.config.locale.cancel}},components:{FileUploadButton:n.default,FileUploadProgressBar:r.default,FileUploadMessage:p.default},directives:{ripple:d.default}};const u={key:0,class:"p-fileupload p-fileupload-advanced p-component"},h={class:"p-fileupload-buttonbar"},f=["multiple","accept","disabled"],m=o.createElementVNode("span",{class:"p-button-icon p-button-icon-left pi pi-fw pi-plus"},null,-1),g={class:"p-button-label"},b={key:1,class:"p-fileupload-files"},B=["alt","src","width"],y={class:"p-fileupload-filename"},v={key:2,class:"p-fileupload-empty"},C={key:1,class:"p-fileupload p-fileupload-basic p-component"},F={class:"p-button-label"},k=["accept","disabled","multiple"];!function(e,t){void 0===t&&(t={});var l=t.insertAt;if(e&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===l&&i.firstChild?i.insertBefore(s,i.firstChild):i.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}("\n.p-fileupload-content {\n position: relative;\n}\n.p-fileupload-row {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n}\n.p-fileupload-row > div {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n width: 25%;\n}\n.p-fileupload-row > div:last-child {\n text-align: right;\n}\n.p-fileupload-content .p-progressbar {\n width: 100%;\n position: absolute;\n top: 0;\n left: 0;\n}\n.p-button.p-fileupload-choose {\n position: relative;\n overflow: hidden;\n}\n.p-button.p-fileupload-choose input[type=file] {\n display: none;\n}\n.p-fileupload-choose.p-fileupload-choose-selected input[type=file] {\n display: none;\n}\n.p-fileupload-filename {\n word-break: break-all;\n}\n.p-fluid .p-fileupload .p-button {\n width: auto;\n}\n"),c.render=function(e,t,l,i,s,a){const n=o.resolveComponent("FileUploadButton"),r=o.resolveComponent("FileUploadProgressBar"),p=o.resolveComponent("FileUploadMessage"),d=o.resolveDirective("ripple");return a.isAdvanced?(o.openBlock(),o.createElementBlock("div",u,[o.createElementVNode("div",h,[o.withDirectives((o.openBlock(),o.createElementBlock("span",{class:o.normalizeClass(a.advancedChooseButtonClass),style:o.normalizeStyle(l.style),onClick:t[1]||(t[1]=(...e)=>a.choose&&a.choose(...e)),onKeydown:t[2]||(t[2]=o.withKeys(((...e)=>a.choose&&a.choose(...e)),["enter"])),onFocus:t[3]||(t[3]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[4]||(t[4]=(...e)=>a.onBlur&&a.onBlur(...e)),tabindex:"0"},[o.createElementVNode("input",{ref:"fileInput",type:"file",onChange:t[0]||(t[0]=(...e)=>a.onFileSelect&&a.onFileSelect(...e)),multiple:l.multiple,accept:l.accept,disabled:a.chooseDisabled},null,40,f),m,o.createElementVNode("span",g,o.toDisplayString(a.chooseButtonLabel),1)],38)),[[d]]),l.showUploadButton?(o.openBlock(),o.createBlock(n,{key:0,label:a.uploadButtonLabel,icon:"pi pi-upload",onClick:a.upload,disabled:a.uploadDisabled},null,8,["label","onClick","disabled"])):o.createCommentVNode("",!0),l.showCancelButton?(o.openBlock(),o.createBlock(n,{key:1,label:a.cancelButtonLabel,icon:"pi pi-times",onClick:a.clear,disabled:a.cancelDisabled},null,8,["label","onClick","disabled"])):o.createCommentVNode("",!0)]),o.createElementVNode("div",{ref:"content",class:"p-fileupload-content",onDragenter:t[5]||(t[5]=(...e)=>a.onDragEnter&&a.onDragEnter(...e)),onDragover:t[6]||(t[6]=(...e)=>a.onDragOver&&a.onDragOver(...e)),onDragleave:t[7]||(t[7]=(...e)=>a.onDragLeave&&a.onDragLeave(...e)),onDrop:t[8]||(t[8]=(...e)=>a.onDrop&&a.onDrop(...e))},[a.hasFiles?(o.openBlock(),o.createBlock(r,{key:0,value:s.progress},null,8,["value"])):o.createCommentVNode("",!0),(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.messages,(e=>(o.openBlock(),o.createBlock(p,{severity:"error",key:e,onClose:a.onMessageClose},{default:o.withCtx((()=>[o.createTextVNode(o.toDisplayString(e),1)])),_:2},1032,["onClose"])))),128)),a.hasFiles?(o.openBlock(),o.createElementBlock("div",b,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.files,((e,t)=>(o.openBlock(),o.createElementBlock("div",{class:"p-fileupload-row",key:e.name+e.type+e.size},[o.createElementVNode("div",null,[a.isImage(e)?(o.openBlock(),o.createElementBlock("img",{key:0,role:"presentation",alt:e.name,src:e.objectURL,width:l.previewWidth},null,8,B)):o.createCommentVNode("",!0)]),o.createElementVNode("div",y,o.toDisplayString(e.name),1),o.createElementVNode("div",null,o.toDisplayString(a.formatSize(e.size)),1),o.createElementVNode("div",null,[o.createVNode(n,{type:"button",icon:"pi pi-times",onClick:e=>a.remove(t)},null,8,["onClick"])])])))),128))])):o.createCommentVNode("",!0),e.$slots.empty&&!a.hasFiles?(o.openBlock(),o.createElementBlock("div",v,[o.renderSlot(e.$slots,"empty")])):o.createCommentVNode("",!0)],544)])):a.isBasic?(o.openBlock(),o.createElementBlock("div",C,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.messages,(e=>(o.openBlock(),o.createBlock(p,{severity:"error",key:e,onClose:a.onMessageClose},{default:o.withCtx((()=>[o.createTextVNode(o.toDisplayString(e),1)])),_:2},1032,["onClose"])))),128)),o.withDirectives((o.openBlock(),o.createElementBlock("span",{class:o.normalizeClass(a.basicChooseButtonClass),style:o.normalizeStyle(l.style),onMouseup:t[12]||(t[12]=(...e)=>a.onBasicUploaderClick&&a.onBasicUploaderClick(...e)),onKeydown:t[13]||(t[13]=o.withKeys(((...e)=>a.choose&&a.choose(...e)),["enter"])),onFocus:t[14]||(t[14]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[15]||(t[15]=(...e)=>a.onBlur&&a.onBlur(...e)),tabindex:"0"},[o.createElementVNode("span",{class:o.normalizeClass(a.basicChooseButtonIconClass)},null,2),o.createElementVNode("span",F,o.toDisplayString(a.basicChooseButtonLabel),1),a.hasFiles?o.createCommentVNode("",!0):(o.openBlock(),o.createElementBlock("input",{key:0,ref:"fileInput",type:"file",accept:l.accept,disabled:l.disabled,multiple:l.multiple,onChange:t[9]||(t[9]=(...e)=>a.onFileSelect&&a.onFileSelect(...e)),onFocus:t[10]||(t[10]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[11]||(t[11]=(...e)=>a.onBlur&&a.onBlur(...e))},null,40,k))],38)),[[d]])])):o.createCommentVNode("",!0)},module.exports=c;
|
|
1
|
+
"use strict";var e=require("primevue/button"),t=require("primevue/progressbar"),l=require("primevue/message"),i=require("primevue/utils"),s=require("primevue/ripple"),o=require("vue");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=a(e),r=a(t),p=a(l),d=a(s),c={name:"FileUpload",emits:["select","uploader","before-upload","progress","upload","error","before-send","clear","remove"],props:{name:{type:String,default:null},url:{type:String,default:null},mode:{type:String,default:"advanced"},multiple:{type:Boolean,default:!1},accept:{type:String,default:null},disabled:{type:Boolean,default:!1},auto:{type:Boolean,default:!1},maxFileSize:{type:Number,default:null},invalidFileSizeMessage:{type:String,default:"{0}: Invalid file size, file size should be smaller than {1}."},invalidFileTypeMessage:{type:String,default:"{0}: Invalid file type, allowed file types: {1}."},fileLimit:{type:Number,default:null},invalidFileLimitMessage:{type:String,default:"Maximum number of files exceeded, limit is {0} at most."},withCredentials:{type:Boolean,default:!1},previewWidth:{type:Number,default:50},chooseLabel:{type:String,default:null},uploadLabel:{type:String,default:null},cancelLabel:{type:String,default:null},customUpload:{type:Boolean,default:!1},showUploadButton:{type:Boolean,default:!0},showCancelButton:{type:Boolean,default:!0},chooseIcon:{type:String,default:"pi pi-plus"},uploadIcon:{type:String,default:"pi pi-upload"},cancelIcon:{type:String,default:"pi pi-times"},style:null,class:null},duplicateIEEvent:!1,data:()=>({uploadedFileCount:0,files:[],messages:[],focused:!1,progress:null}),methods:{onFileSelect(e){if("drop"!==e.type&&this.isIE11()&&this.duplicateIEEvent)return void(this.duplicateIEEvent=!1);this.messages=[],this.files=this.files||[];let t=e.dataTransfer?e.dataTransfer.files:e.target.files;for(let e of t)this.isFileSelected(e)||this.validate(e)&&(this.isImage(e)&&(e.objectURL=window.URL.createObjectURL(e)),this.files.push(e));this.$emit("select",{originalEvent:e,files:this.files}),this.fileLimit&&this.checkFileLimit(),this.auto&&this.hasFiles&&!this.isFileLimitExceeded()&&this.upload(),"drop"!==e.type&&this.isIE11()?this.clearIEInput():this.clearInputElement()},choose(){this.$refs.fileInput.click()},upload(){if(this.customUpload)this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("uploader",{files:this.files}),this.clear();else{let e=new XMLHttpRequest,t=new FormData;this.$emit("before-upload",{xhr:e,formData:t});for(let e of this.files)t.append(this.name,e,e.name);e.upload.addEventListener("progress",(e=>{e.lengthComputable&&(this.progress=Math.round(100*e.loaded/e.total)),this.$emit("progress",{originalEvent:e,progress:this.progress})})),e.onreadystatechange=()=>{4===e.readyState&&(this.progress=0,e.status>=200&&e.status<300?(this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("upload",{xhr:e,files:this.files})):this.$emit("error",{xhr:e,files:this.files}),this.clear())},e.open("POST",this.url,!0),this.$emit("before-send",{xhr:e,formData:t}),e.withCredentials=this.withCredentials,e.send(t)}},clear(){this.files=[],this.messages=null,this.$emit("clear"),this.isAdvanced&&this.clearInputElement()},onFocus(){this.focused=!0},onBlur(){this.focused=!1},isFileSelected(e){if(this.files&&this.files.length)for(let t of this.files)if(t.name+t.type+t.size===e.name+e.type+e.size)return!0;return!1},isIE11:()=>!!window.MSInputMethodContext&&!!document.documentMode,validate(e){return this.accept&&!this.isFileTypeValid(e)?(this.messages.push(this.invalidFileTypeMessage.replace("{0}",e.name).replace("{1}",this.accept)),!1):!(this.maxFileSize&&e.size>this.maxFileSize)||(this.messages.push(this.invalidFileSizeMessage.replace("{0}",e.name).replace("{1}",this.formatSize(this.maxFileSize))),!1)},isFileTypeValid(e){let t=this.accept.split(",").map((e=>e.trim()));for(let l of t){if(this.isWildcard(l)?this.getTypeClass(e.type)===this.getTypeClass(l):e.type==l||this.getFileExtension(e).toLowerCase()===l.toLowerCase())return!0}return!1},getTypeClass:e=>e.substring(0,e.indexOf("/")),isWildcard:e=>-1!==e.indexOf("*"),getFileExtension:e=>"."+e.name.split(".").pop(),isImage:e=>/^image\//.test(e.type),onDragEnter(e){this.disabled||(e.stopPropagation(),e.preventDefault())},onDragOver(e){this.disabled||(i.DomHandler.addClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault())},onDragLeave(){this.disabled||i.DomHandler.removeClass(this.$refs.content,"p-fileupload-highlight")},onDrop(e){if(!this.disabled){i.DomHandler.removeClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault();const t=e.dataTransfer?e.dataTransfer.files:e.target.files;(this.multiple||t&&1===t.length)&&this.onFileSelect(e)}},onBasicUploaderClick(){this.hasFiles?this.upload():this.$refs.fileInput.click()},remove(e){this.clearInputElement();let t=this.files.splice(e,1)[0];this.files=[...this.files],this.$emit("remove",{file:t,files:this.files})},clearInputElement(){this.$refs.fileInput.value=""},clearIEInput(){this.$refs.fileInput&&(this.duplicateIEEvent=!0,this.$refs.fileInput.value="")},formatSize(e){if(0===e)return"0 B";let t=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,t)).toFixed(3))+" "+["B","KB","MB","GB","TB","PB","EB","ZB","YB"][t]},isFileLimitExceeded(){return this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount&&this.focused&&(this.focused=!1),this.fileLimit&&this.fileLimit<this.files.length+this.uploadedFileCount},checkFileLimit(){this.isFileLimitExceeded()&&this.messages.push(this.invalidFileLimitMessage.replace("{0}",this.fileLimit.toString()))},onMessageClose(){this.messages=null}},computed:{isAdvanced(){return"advanced"===this.mode},isBasic(){return"basic"===this.mode},advancedChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-fileupload-choose-selected":this.hasFiles,"p-disabled":this.disabled,"p-focus":this.focused}]},advancedChooseIconClass(){return["p-button-icon p-button-icon-left pi-fw",this.chooseIcon]},basicChooseButtonIconClass(){return["p-button-icon p-button-icon-left",!this.hasFiles||this.auto?this.uploadIcon:this.chooseIcon]},basicChooseButtonLabel(){return this.auto?this.chooseButtonLabel:this.hasFiles?this.files.map((e=>e.name)).join(", "):this.chooseButtonLabel},hasFiles(){return this.files&&this.files.length>0},chooseDisabled(){return this.disabled||this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount},uploadDisabled(){return this.disabled||!this.hasFiles||this.fileLimit&&this.fileLimit<this.files.length},cancelDisabled(){return this.disabled||!this.hasFiles},chooseButtonLabel(){return this.chooseLabel||this.$primevue.config.locale.choose},uploadButtonLabel(){return this.uploadLabel||this.$primevue.config.locale.upload},cancelButtonLabel(){return this.cancelLabel||this.$primevue.config.locale.cancel}},components:{FileUploadButton:n.default,FileUploadProgressBar:r.default,FileUploadMessage:p.default},directives:{ripple:d.default}};const u={key:0,class:"p-fileupload p-fileupload-advanced p-component"},h={class:"p-fileupload-buttonbar"},f=["multiple","accept","disabled"],m={class:"p-button-label"},g={key:1,class:"p-fileupload-files"},b=["alt","src","width"],y={class:"p-fileupload-filename"},B={key:2,class:"p-fileupload-empty"},v={key:1,class:"p-fileupload p-fileupload-basic p-component"},C={class:"p-button-label"},F=["accept","disabled","multiple"];!function(e,t){void 0===t&&(t={});var l=t.insertAt;if(e&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===l&&i.firstChild?i.insertBefore(s,i.firstChild):i.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}("\n.p-fileupload-content {\n position: relative;\n}\n.p-fileupload-row {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n}\n.p-fileupload-row > div {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n width: 25%;\n}\n.p-fileupload-row > div:last-child {\n text-align: right;\n}\n.p-fileupload-content .p-progressbar {\n width: 100%;\n position: absolute;\n top: 0;\n left: 0;\n}\n.p-button.p-fileupload-choose {\n position: relative;\n overflow: hidden;\n}\n.p-button.p-fileupload-choose input[type=file] {\n display: none;\n}\n.p-fileupload-choose.p-fileupload-choose-selected input[type=file] {\n display: none;\n}\n.p-fileupload-filename {\n word-break: break-all;\n}\n.p-fluid .p-fileupload .p-button {\n width: auto;\n}\n"),c.render=function(e,t,l,i,s,a){const n=o.resolveComponent("FileUploadButton"),r=o.resolveComponent("FileUploadProgressBar"),p=o.resolveComponent("FileUploadMessage"),d=o.resolveDirective("ripple");return a.isAdvanced?(o.openBlock(),o.createElementBlock("div",u,[o.createElementVNode("div",h,[o.withDirectives((o.openBlock(),o.createElementBlock("span",{class:o.normalizeClass(a.advancedChooseButtonClass),style:o.normalizeStyle(l.style),onClick:t[1]||(t[1]=(...e)=>a.choose&&a.choose(...e)),onKeydown:t[2]||(t[2]=o.withKeys(((...e)=>a.choose&&a.choose(...e)),["enter"])),onFocus:t[3]||(t[3]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[4]||(t[4]=(...e)=>a.onBlur&&a.onBlur(...e)),tabindex:"0"},[o.createElementVNode("input",{ref:"fileInput",type:"file",onChange:t[0]||(t[0]=(...e)=>a.onFileSelect&&a.onFileSelect(...e)),multiple:l.multiple,accept:l.accept,disabled:a.chooseDisabled},null,40,f),o.createElementVNode("span",{class:o.normalizeClass(a.advancedChooseIconClass)},null,2),o.createElementVNode("span",m,o.toDisplayString(a.chooseButtonLabel),1)],38)),[[d]]),l.showUploadButton?(o.openBlock(),o.createBlock(n,{key:0,label:a.uploadButtonLabel,icon:l.uploadIcon,onClick:a.upload,disabled:a.uploadDisabled},null,8,["label","icon","onClick","disabled"])):o.createCommentVNode("",!0),l.showCancelButton?(o.openBlock(),o.createBlock(n,{key:1,label:a.cancelButtonLabel,icon:l.cancelIcon,onClick:a.clear,disabled:a.cancelDisabled},null,8,["label","icon","onClick","disabled"])):o.createCommentVNode("",!0)]),o.createElementVNode("div",{ref:"content",class:"p-fileupload-content",onDragenter:t[5]||(t[5]=(...e)=>a.onDragEnter&&a.onDragEnter(...e)),onDragover:t[6]||(t[6]=(...e)=>a.onDragOver&&a.onDragOver(...e)),onDragleave:t[7]||(t[7]=(...e)=>a.onDragLeave&&a.onDragLeave(...e)),onDrop:t[8]||(t[8]=(...e)=>a.onDrop&&a.onDrop(...e))},[a.hasFiles?(o.openBlock(),o.createBlock(r,{key:0,value:s.progress},null,8,["value"])):o.createCommentVNode("",!0),(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.messages,(e=>(o.openBlock(),o.createBlock(p,{severity:"error",key:e,onClose:a.onMessageClose},{default:o.withCtx((()=>[o.createTextVNode(o.toDisplayString(e),1)])),_:2},1032,["onClose"])))),128)),a.hasFiles?(o.openBlock(),o.createElementBlock("div",g,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.files,((e,t)=>(o.openBlock(),o.createElementBlock("div",{class:"p-fileupload-row",key:e.name+e.type+e.size},[o.createElementVNode("div",null,[a.isImage(e)?(o.openBlock(),o.createElementBlock("img",{key:0,role:"presentation",alt:e.name,src:e.objectURL,width:l.previewWidth},null,8,b)):o.createCommentVNode("",!0)]),o.createElementVNode("div",y,o.toDisplayString(e.name),1),o.createElementVNode("div",null,o.toDisplayString(a.formatSize(e.size)),1),o.createElementVNode("div",null,[o.createVNode(n,{type:"button",icon:"pi pi-times",onClick:e=>a.remove(t)},null,8,["onClick"])])])))),128))])):o.createCommentVNode("",!0),e.$slots.empty&&!a.hasFiles?(o.openBlock(),o.createElementBlock("div",B,[o.renderSlot(e.$slots,"empty")])):o.createCommentVNode("",!0)],544)])):a.isBasic?(o.openBlock(),o.createElementBlock("div",v,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.messages,(e=>(o.openBlock(),o.createBlock(p,{severity:"error",key:e,onClose:a.onMessageClose},{default:o.withCtx((()=>[o.createTextVNode(o.toDisplayString(e),1)])),_:2},1032,["onClose"])))),128)),o.withDirectives((o.openBlock(),o.createElementBlock("span",{class:o.normalizeClass(a.basicChooseButtonClass),style:o.normalizeStyle(l.style),onMouseup:t[12]||(t[12]=(...e)=>a.onBasicUploaderClick&&a.onBasicUploaderClick(...e)),onKeydown:t[13]||(t[13]=o.withKeys(((...e)=>a.choose&&a.choose(...e)),["enter"])),onFocus:t[14]||(t[14]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[15]||(t[15]=(...e)=>a.onBlur&&a.onBlur(...e)),tabindex:"0"},[o.createElementVNode("span",{class:o.normalizeClass(a.basicChooseButtonIconClass)},null,2),o.createElementVNode("span",C,o.toDisplayString(a.basicChooseButtonLabel),1),a.hasFiles?o.createCommentVNode("",!0):(o.openBlock(),o.createElementBlock("input",{key:0,ref:"fileInput",type:"file",accept:l.accept,disabled:l.disabled,multiple:l.multiple,onChange:t[9]||(t[9]=(...e)=>a.onFileSelect&&a.onFileSelect(...e)),onFocus:t[10]||(t[10]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[11]||(t[11]=(...e)=>a.onBlur&&a.onBlur(...e))},null,40,F))],38)),[[d]])])):o.createCommentVNode("",!0)},module.exports=c;
|
|
@@ -89,6 +89,18 @@ var script = {
|
|
|
89
89
|
type: Boolean,
|
|
90
90
|
default: true
|
|
91
91
|
},
|
|
92
|
+
chooseIcon: {
|
|
93
|
+
type: String,
|
|
94
|
+
default: 'pi pi-plus'
|
|
95
|
+
},
|
|
96
|
+
uploadIcon: {
|
|
97
|
+
type: String,
|
|
98
|
+
default: 'pi pi-upload'
|
|
99
|
+
},
|
|
100
|
+
cancelIcon: {
|
|
101
|
+
type: String,
|
|
102
|
+
default: 'pi pi-times'
|
|
103
|
+
},
|
|
92
104
|
style: null,
|
|
93
105
|
class: null
|
|
94
106
|
},
|
|
@@ -383,11 +395,13 @@ var script = {
|
|
|
383
395
|
'p-focus': this.focused
|
|
384
396
|
}];
|
|
385
397
|
},
|
|
398
|
+
advancedChooseIconClass() {
|
|
399
|
+
return ['p-button-icon p-button-icon-left pi-fw', this.chooseIcon];
|
|
400
|
+
},
|
|
386
401
|
basicChooseButtonIconClass() {
|
|
387
|
-
return ['p-button-icon p-button-icon-left
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}];
|
|
402
|
+
return ['p-button-icon p-button-icon-left',
|
|
403
|
+
!this.hasFiles || this.auto ? this.uploadIcon : this.chooseIcon
|
|
404
|
+
];
|
|
391
405
|
},
|
|
392
406
|
basicChooseButtonLabel() {
|
|
393
407
|
return this.auto ? this.chooseButtonLabel : (this.hasFiles ? this.files.map(f => f.name).join(', ') : this.chooseButtonLabel);
|
|
@@ -430,24 +444,23 @@ const _hoisted_1 = {
|
|
|
430
444
|
};
|
|
431
445
|
const _hoisted_2 = { class: "p-fileupload-buttonbar" };
|
|
432
446
|
const _hoisted_3 = ["multiple", "accept", "disabled"];
|
|
433
|
-
const _hoisted_4 =
|
|
434
|
-
const _hoisted_5 = {
|
|
435
|
-
const _hoisted_6 = {
|
|
447
|
+
const _hoisted_4 = { class: "p-button-label" };
|
|
448
|
+
const _hoisted_5 = {
|
|
436
449
|
key: 1,
|
|
437
450
|
class: "p-fileupload-files"
|
|
438
451
|
};
|
|
439
|
-
const
|
|
440
|
-
const
|
|
441
|
-
const
|
|
452
|
+
const _hoisted_6 = ["alt", "src", "width"];
|
|
453
|
+
const _hoisted_7 = { class: "p-fileupload-filename" };
|
|
454
|
+
const _hoisted_8 = {
|
|
442
455
|
key: 2,
|
|
443
456
|
class: "p-fileupload-empty"
|
|
444
457
|
};
|
|
445
|
-
const
|
|
458
|
+
const _hoisted_9 = {
|
|
446
459
|
key: 1,
|
|
447
460
|
class: "p-fileupload p-fileupload-basic p-component"
|
|
448
461
|
};
|
|
449
|
-
const
|
|
450
|
-
const
|
|
462
|
+
const _hoisted_10 = { class: "p-button-label" };
|
|
463
|
+
const _hoisted_11 = ["accept", "disabled", "multiple"];
|
|
451
464
|
|
|
452
465
|
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
453
466
|
const _component_FileUploadButton = resolveComponent("FileUploadButton");
|
|
@@ -475,8 +488,10 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
475
488
|
accept: $props.accept,
|
|
476
489
|
disabled: $options.chooseDisabled
|
|
477
490
|
}, null, 40, _hoisted_3),
|
|
478
|
-
|
|
479
|
-
|
|
491
|
+
createElementVNode("span", {
|
|
492
|
+
class: normalizeClass($options.advancedChooseIconClass)
|
|
493
|
+
}, null, 2),
|
|
494
|
+
createElementVNode("span", _hoisted_4, toDisplayString($options.chooseButtonLabel), 1)
|
|
480
495
|
], 38)), [
|
|
481
496
|
[_directive_ripple]
|
|
482
497
|
]),
|
|
@@ -484,19 +499,19 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
484
499
|
? (openBlock(), createBlock(_component_FileUploadButton, {
|
|
485
500
|
key: 0,
|
|
486
501
|
label: $options.uploadButtonLabel,
|
|
487
|
-
icon:
|
|
502
|
+
icon: $props.uploadIcon,
|
|
488
503
|
onClick: $options.upload,
|
|
489
504
|
disabled: $options.uploadDisabled
|
|
490
|
-
}, null, 8, ["label", "onClick", "disabled"]))
|
|
505
|
+
}, null, 8, ["label", "icon", "onClick", "disabled"]))
|
|
491
506
|
: createCommentVNode("", true),
|
|
492
507
|
($props.showCancelButton)
|
|
493
508
|
? (openBlock(), createBlock(_component_FileUploadButton, {
|
|
494
509
|
key: 1,
|
|
495
510
|
label: $options.cancelButtonLabel,
|
|
496
|
-
icon:
|
|
511
|
+
icon: $props.cancelIcon,
|
|
497
512
|
onClick: $options.clear,
|
|
498
513
|
disabled: $options.cancelDisabled
|
|
499
|
-
}, null, 8, ["label", "onClick", "disabled"]))
|
|
514
|
+
}, null, 8, ["label", "icon", "onClick", "disabled"]))
|
|
500
515
|
: createCommentVNode("", true)
|
|
501
516
|
]),
|
|
502
517
|
createElementVNode("div", {
|
|
@@ -526,7 +541,7 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
526
541
|
}, 1032, ["onClose"]))
|
|
527
542
|
}), 128)),
|
|
528
543
|
($options.hasFiles)
|
|
529
|
-
? (openBlock(), createElementBlock("div",
|
|
544
|
+
? (openBlock(), createElementBlock("div", _hoisted_5, [
|
|
530
545
|
(openBlock(true), createElementBlock(Fragment, null, renderList($data.files, (file, index) => {
|
|
531
546
|
return (openBlock(), createElementBlock("div", {
|
|
532
547
|
class: "p-fileupload-row",
|
|
@@ -540,10 +555,10 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
540
555
|
alt: file.name,
|
|
541
556
|
src: file.objectURL,
|
|
542
557
|
width: $props.previewWidth
|
|
543
|
-
}, null, 8,
|
|
558
|
+
}, null, 8, _hoisted_6))
|
|
544
559
|
: createCommentVNode("", true)
|
|
545
560
|
]),
|
|
546
|
-
createElementVNode("div",
|
|
561
|
+
createElementVNode("div", _hoisted_7, toDisplayString(file.name), 1),
|
|
547
562
|
createElementVNode("div", null, toDisplayString($options.formatSize(file.size)), 1),
|
|
548
563
|
createElementVNode("div", null, [
|
|
549
564
|
createVNode(_component_FileUploadButton, {
|
|
@@ -557,14 +572,14 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
557
572
|
]))
|
|
558
573
|
: createCommentVNode("", true),
|
|
559
574
|
(_ctx.$slots.empty && !$options.hasFiles)
|
|
560
|
-
? (openBlock(), createElementBlock("div",
|
|
575
|
+
? (openBlock(), createElementBlock("div", _hoisted_8, [
|
|
561
576
|
renderSlot(_ctx.$slots, "empty")
|
|
562
577
|
]))
|
|
563
578
|
: createCommentVNode("", true)
|
|
564
579
|
], 544)
|
|
565
580
|
]))
|
|
566
581
|
: ($options.isBasic)
|
|
567
|
-
? (openBlock(), createElementBlock("div",
|
|
582
|
+
? (openBlock(), createElementBlock("div", _hoisted_9, [
|
|
568
583
|
(openBlock(true), createElementBlock(Fragment, null, renderList($data.messages, (msg) => {
|
|
569
584
|
return (openBlock(), createBlock(_component_FileUploadMessage, {
|
|
570
585
|
severity: "error",
|
|
@@ -589,7 +604,7 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
589
604
|
createElementVNode("span", {
|
|
590
605
|
class: normalizeClass($options.basicChooseButtonIconClass)
|
|
591
606
|
}, null, 2),
|
|
592
|
-
createElementVNode("span",
|
|
607
|
+
createElementVNode("span", _hoisted_10, toDisplayString($options.basicChooseButtonLabel), 1),
|
|
593
608
|
(!$options.hasFiles)
|
|
594
609
|
? (openBlock(), createElementBlock("input", {
|
|
595
610
|
key: 0,
|
|
@@ -601,7 +616,7 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
601
616
|
onChange: _cache[9] || (_cache[9] = (...args) => ($options.onFileSelect && $options.onFileSelect(...args))),
|
|
602
617
|
onFocus: _cache[10] || (_cache[10] = (...args) => ($options.onFocus && $options.onFocus(...args))),
|
|
603
618
|
onBlur: _cache[11] || (_cache[11] = (...args) => ($options.onBlur && $options.onBlur(...args)))
|
|
604
|
-
}, null, 40,
|
|
619
|
+
}, null, 40, _hoisted_11))
|
|
605
620
|
: createCommentVNode("", true)
|
|
606
621
|
], 38)), [
|
|
607
622
|
[_directive_ripple]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"primevue/button";import t from"primevue/progressbar";import i from"primevue/message";import{DomHandler as l}from"primevue/utils";import s from"primevue/ripple";import{resolveComponent as o,resolveDirective as a,openBlock as n,createElementBlock as p,createElementVNode as r,withDirectives as d,normalizeClass as u,normalizeStyle as h,withKeys as c,toDisplayString as f,createBlock as m,createCommentVNode as g,Fragment as b,renderList as v,withCtx as y,createTextVNode as F,createVNode as B,renderSlot as C}from"vue";var L={name:"FileUpload",emits:["select","uploader","before-upload","progress","upload","error","before-send","clear","remove"],props:{name:{type:String,default:null},url:{type:String,default:null},mode:{type:String,default:"advanced"},multiple:{type:Boolean,default:!1},accept:{type:String,default:null},disabled:{type:Boolean,default:!1},auto:{type:Boolean,default:!1},maxFileSize:{type:Number,default:null},invalidFileSizeMessage:{type:String,default:"{0}: Invalid file size, file size should be smaller than {1}."},invalidFileTypeMessage:{type:String,default:"{0}: Invalid file type, allowed file types: {1}."},fileLimit:{type:Number,default:null},invalidFileLimitMessage:{type:String,default:"Maximum number of files exceeded, limit is {0} at most."},withCredentials:{type:Boolean,default:!1},previewWidth:{type:Number,default:50},chooseLabel:{type:String,default:null},uploadLabel:{type:String,default:null},cancelLabel:{type:String,default:null},customUpload:{type:Boolean,default:!1},showUploadButton:{type:Boolean,default:!0},showCancelButton:{type:Boolean,default:!0},style:null,class:null},duplicateIEEvent:!1,data:()=>({uploadedFileCount:0,files:[],messages:[],focused:!1,progress:null}),methods:{onFileSelect(e){if("drop"!==e.type&&this.isIE11()&&this.duplicateIEEvent)return void(this.duplicateIEEvent=!1);this.messages=[],this.files=this.files||[];let t=e.dataTransfer?e.dataTransfer.files:e.target.files;for(let e of t)this.isFileSelected(e)||this.validate(e)&&(this.isImage(e)&&(e.objectURL=window.URL.createObjectURL(e)),this.files.push(e));this.$emit("select",{originalEvent:e,files:this.files}),this.fileLimit&&this.checkFileLimit(),this.auto&&this.hasFiles&&!this.isFileLimitExceeded()&&this.upload(),"drop"!==e.type&&this.isIE11()?this.clearIEInput():this.clearInputElement()},choose(){this.$refs.fileInput.click()},upload(){if(this.customUpload)this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("uploader",{files:this.files}),this.clear();else{let e=new XMLHttpRequest,t=new FormData;this.$emit("before-upload",{xhr:e,formData:t});for(let e of this.files)t.append(this.name,e,e.name);e.upload.addEventListener("progress",(e=>{e.lengthComputable&&(this.progress=Math.round(100*e.loaded/e.total)),this.$emit("progress",{originalEvent:e,progress:this.progress})})),e.onreadystatechange=()=>{4===e.readyState&&(this.progress=0,e.status>=200&&e.status<300?(this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("upload",{xhr:e,files:this.files})):this.$emit("error",{xhr:e,files:this.files}),this.clear())},e.open("POST",this.url,!0),this.$emit("before-send",{xhr:e,formData:t}),e.withCredentials=this.withCredentials,e.send(t)}},clear(){this.files=[],this.messages=null,this.$emit("clear"),this.isAdvanced&&this.clearInputElement()},onFocus(){this.focused=!0},onBlur(){this.focused=!1},isFileSelected(e){if(this.files&&this.files.length)for(let t of this.files)if(t.name+t.type+t.size===e.name+e.type+e.size)return!0;return!1},isIE11:()=>!!window.MSInputMethodContext&&!!document.documentMode,validate(e){return this.accept&&!this.isFileTypeValid(e)?(this.messages.push(this.invalidFileTypeMessage.replace("{0}",e.name).replace("{1}",this.accept)),!1):!(this.maxFileSize&&e.size>this.maxFileSize)||(this.messages.push(this.invalidFileSizeMessage.replace("{0}",e.name).replace("{1}",this.formatSize(this.maxFileSize))),!1)},isFileTypeValid(e){let t=this.accept.split(",").map((e=>e.trim()));for(let i of t){if(this.isWildcard(i)?this.getTypeClass(e.type)===this.getTypeClass(i):e.type==i||this.getFileExtension(e).toLowerCase()===i.toLowerCase())return!0}return!1},getTypeClass:e=>e.substring(0,e.indexOf("/")),isWildcard:e=>-1!==e.indexOf("*"),getFileExtension:e=>"."+e.name.split(".").pop(),isImage:e=>/^image\//.test(e.type),onDragEnter(e){this.disabled||(e.stopPropagation(),e.preventDefault())},onDragOver(e){this.disabled||(l.addClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault())},onDragLeave(){this.disabled||l.removeClass(this.$refs.content,"p-fileupload-highlight")},onDrop(e){if(!this.disabled){l.removeClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault();const t=e.dataTransfer?e.dataTransfer.files:e.target.files;(this.multiple||t&&1===t.length)&&this.onFileSelect(e)}},onBasicUploaderClick(){this.hasFiles?this.upload():this.$refs.fileInput.click()},remove(e){this.clearInputElement();let t=this.files.splice(e,1)[0];this.files=[...this.files],this.$emit("remove",{file:t,files:this.files})},clearInputElement(){this.$refs.fileInput.value=""},clearIEInput(){this.$refs.fileInput&&(this.duplicateIEEvent=!0,this.$refs.fileInput.value="")},formatSize(e){if(0===e)return"0 B";let t=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,t)).toFixed(3))+" "+["B","KB","MB","GB","TB","PB","EB","ZB","YB"][t]},isFileLimitExceeded(){return this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount&&this.focused&&(this.focused=!1),this.fileLimit&&this.fileLimit<this.files.length+this.uploadedFileCount},checkFileLimit(){this.isFileLimitExceeded()&&this.messages.push(this.invalidFileLimitMessage.replace("{0}",this.fileLimit.toString()))},onMessageClose(){this.messages=null}},computed:{isAdvanced(){return"advanced"===this.mode},isBasic(){return"basic"===this.mode},advancedChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-fileupload-choose-selected":this.hasFiles,"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonIconClass(){return["p-button-icon p-button-icon-left pi",{"pi-plus":!this.hasFiles||this.auto,"pi-upload":this.hasFiles&&!this.auto}]},basicChooseButtonLabel(){return this.auto?this.chooseButtonLabel:this.hasFiles?this.files.map((e=>e.name)).join(", "):this.chooseButtonLabel},hasFiles(){return this.files&&this.files.length>0},chooseDisabled(){return this.disabled||this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount},uploadDisabled(){return this.disabled||!this.hasFiles||this.fileLimit&&this.fileLimit<this.files.length},cancelDisabled(){return this.disabled||!this.hasFiles},chooseButtonLabel(){return this.chooseLabel||this.$primevue.config.locale.choose},uploadButtonLabel(){return this.uploadLabel||this.$primevue.config.locale.upload},cancelButtonLabel(){return this.cancelLabel||this.$primevue.config.locale.cancel}},components:{FileUploadButton:e,FileUploadProgressBar:t,FileUploadMessage:i},directives:{ripple:s}};const w={key:0,class:"p-fileupload p-fileupload-advanced p-component"},x={class:"p-fileupload-buttonbar"},S=["multiple","accept","disabled"],k=r("span",{class:"p-button-icon p-button-icon-left pi pi-fw pi-plus"},null,-1),E={class:"p-button-label"},I={key:1,class:"p-fileupload-files"},D=["alt","src","width"],M={class:"p-fileupload-filename"},$={key:2,class:"p-fileupload-empty"},U={key:1,class:"p-fileupload p-fileupload-basic p-component"},z={class:"p-button-label"},T=["accept","disabled","multiple"];!function(e,t){void 0===t&&(t={});var i=t.insertAt;if(e&&"undefined"!=typeof document){var l=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===i&&l.firstChild?l.insertBefore(s,l.firstChild):l.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}("\n.p-fileupload-content {\n position: relative;\n}\n.p-fileupload-row {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n}\n.p-fileupload-row > div {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n width: 25%;\n}\n.p-fileupload-row > div:last-child {\n text-align: right;\n}\n.p-fileupload-content .p-progressbar {\n width: 100%;\n position: absolute;\n top: 0;\n left: 0;\n}\n.p-button.p-fileupload-choose {\n position: relative;\n overflow: hidden;\n}\n.p-button.p-fileupload-choose input[type=file] {\n display: none;\n}\n.p-fileupload-choose.p-fileupload-choose-selected input[type=file] {\n display: none;\n}\n.p-fileupload-filename {\n word-break: break-all;\n}\n.p-fluid .p-fileupload .p-button {\n width: auto;\n}\n"),L.render=function(e,t,i,l,s,L){const O=o("FileUploadButton"),P=o("FileUploadProgressBar"),N=o("FileUploadMessage"),R=a("ripple");return L.isAdvanced?(n(),p("div",w,[r("div",x,[d((n(),p("span",{class:u(L.advancedChooseButtonClass),style:h(i.style),onClick:t[1]||(t[1]=(...e)=>L.choose&&L.choose(...e)),onKeydown:t[2]||(t[2]=c(((...e)=>L.choose&&L.choose(...e)),["enter"])),onFocus:t[3]||(t[3]=(...e)=>L.onFocus&&L.onFocus(...e)),onBlur:t[4]||(t[4]=(...e)=>L.onBlur&&L.onBlur(...e)),tabindex:"0"},[r("input",{ref:"fileInput",type:"file",onChange:t[0]||(t[0]=(...e)=>L.onFileSelect&&L.onFileSelect(...e)),multiple:i.multiple,accept:i.accept,disabled:L.chooseDisabled},null,40,S),k,r("span",E,f(L.chooseButtonLabel),1)],38)),[[R]]),i.showUploadButton?(n(),m(O,{key:0,label:L.uploadButtonLabel,icon:"pi pi-upload",onClick:L.upload,disabled:L.uploadDisabled},null,8,["label","onClick","disabled"])):g("",!0),i.showCancelButton?(n(),m(O,{key:1,label:L.cancelButtonLabel,icon:"pi pi-times",onClick:L.clear,disabled:L.cancelDisabled},null,8,["label","onClick","disabled"])):g("",!0)]),r("div",{ref:"content",class:"p-fileupload-content",onDragenter:t[5]||(t[5]=(...e)=>L.onDragEnter&&L.onDragEnter(...e)),onDragover:t[6]||(t[6]=(...e)=>L.onDragOver&&L.onDragOver(...e)),onDragleave:t[7]||(t[7]=(...e)=>L.onDragLeave&&L.onDragLeave(...e)),onDrop:t[8]||(t[8]=(...e)=>L.onDrop&&L.onDrop(...e))},[L.hasFiles?(n(),m(P,{key:0,value:s.progress},null,8,["value"])):g("",!0),(n(!0),p(b,null,v(s.messages,(e=>(n(),m(N,{severity:"error",key:e,onClose:L.onMessageClose},{default:y((()=>[F(f(e),1)])),_:2},1032,["onClose"])))),128)),L.hasFiles?(n(),p("div",I,[(n(!0),p(b,null,v(s.files,((e,t)=>(n(),p("div",{class:"p-fileupload-row",key:e.name+e.type+e.size},[r("div",null,[L.isImage(e)?(n(),p("img",{key:0,role:"presentation",alt:e.name,src:e.objectURL,width:i.previewWidth},null,8,D)):g("",!0)]),r("div",M,f(e.name),1),r("div",null,f(L.formatSize(e.size)),1),r("div",null,[B(O,{type:"button",icon:"pi pi-times",onClick:e=>L.remove(t)},null,8,["onClick"])])])))),128))])):g("",!0),e.$slots.empty&&!L.hasFiles?(n(),p("div",$,[C(e.$slots,"empty")])):g("",!0)],544)])):L.isBasic?(n(),p("div",U,[(n(!0),p(b,null,v(s.messages,(e=>(n(),m(N,{severity:"error",key:e,onClose:L.onMessageClose},{default:y((()=>[F(f(e),1)])),_:2},1032,["onClose"])))),128)),d((n(),p("span",{class:u(L.basicChooseButtonClass),style:h(i.style),onMouseup:t[12]||(t[12]=(...e)=>L.onBasicUploaderClick&&L.onBasicUploaderClick(...e)),onKeydown:t[13]||(t[13]=c(((...e)=>L.choose&&L.choose(...e)),["enter"])),onFocus:t[14]||(t[14]=(...e)=>L.onFocus&&L.onFocus(...e)),onBlur:t[15]||(t[15]=(...e)=>L.onBlur&&L.onBlur(...e)),tabindex:"0"},[r("span",{class:u(L.basicChooseButtonIconClass)},null,2),r("span",z,f(L.basicChooseButtonLabel),1),L.hasFiles?g("",!0):(n(),p("input",{key:0,ref:"fileInput",type:"file",accept:i.accept,disabled:i.disabled,multiple:i.multiple,onChange:t[9]||(t[9]=(...e)=>L.onFileSelect&&L.onFileSelect(...e)),onFocus:t[10]||(t[10]=(...e)=>L.onFocus&&L.onFocus(...e)),onBlur:t[11]||(t[11]=(...e)=>L.onBlur&&L.onBlur(...e))},null,40,T))],38)),[[R]])])):g("",!0)};export{L as default};
|
|
1
|
+
import e from"primevue/button";import t from"primevue/progressbar";import i from"primevue/message";import{DomHandler as l}from"primevue/utils";import s from"primevue/ripple";import{resolveComponent as o,resolveDirective as a,openBlock as n,createElementBlock as p,createElementVNode as d,withDirectives as r,normalizeClass as u,normalizeStyle as h,withKeys as c,toDisplayString as f,createBlock as m,createCommentVNode as g,Fragment as b,renderList as v,withCtx as y,createTextVNode as F,createVNode as C,renderSlot as B}from"vue";var L={name:"FileUpload",emits:["select","uploader","before-upload","progress","upload","error","before-send","clear","remove"],props:{name:{type:String,default:null},url:{type:String,default:null},mode:{type:String,default:"advanced"},multiple:{type:Boolean,default:!1},accept:{type:String,default:null},disabled:{type:Boolean,default:!1},auto:{type:Boolean,default:!1},maxFileSize:{type:Number,default:null},invalidFileSizeMessage:{type:String,default:"{0}: Invalid file size, file size should be smaller than {1}."},invalidFileTypeMessage:{type:String,default:"{0}: Invalid file type, allowed file types: {1}."},fileLimit:{type:Number,default:null},invalidFileLimitMessage:{type:String,default:"Maximum number of files exceeded, limit is {0} at most."},withCredentials:{type:Boolean,default:!1},previewWidth:{type:Number,default:50},chooseLabel:{type:String,default:null},uploadLabel:{type:String,default:null},cancelLabel:{type:String,default:null},customUpload:{type:Boolean,default:!1},showUploadButton:{type:Boolean,default:!0},showCancelButton:{type:Boolean,default:!0},chooseIcon:{type:String,default:"pi pi-plus"},uploadIcon:{type:String,default:"pi pi-upload"},cancelIcon:{type:String,default:"pi pi-times"},style:null,class:null},duplicateIEEvent:!1,data:()=>({uploadedFileCount:0,files:[],messages:[],focused:!1,progress:null}),methods:{onFileSelect(e){if("drop"!==e.type&&this.isIE11()&&this.duplicateIEEvent)return void(this.duplicateIEEvent=!1);this.messages=[],this.files=this.files||[];let t=e.dataTransfer?e.dataTransfer.files:e.target.files;for(let e of t)this.isFileSelected(e)||this.validate(e)&&(this.isImage(e)&&(e.objectURL=window.URL.createObjectURL(e)),this.files.push(e));this.$emit("select",{originalEvent:e,files:this.files}),this.fileLimit&&this.checkFileLimit(),this.auto&&this.hasFiles&&!this.isFileLimitExceeded()&&this.upload(),"drop"!==e.type&&this.isIE11()?this.clearIEInput():this.clearInputElement()},choose(){this.$refs.fileInput.click()},upload(){if(this.customUpload)this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("uploader",{files:this.files}),this.clear();else{let e=new XMLHttpRequest,t=new FormData;this.$emit("before-upload",{xhr:e,formData:t});for(let e of this.files)t.append(this.name,e,e.name);e.upload.addEventListener("progress",(e=>{e.lengthComputable&&(this.progress=Math.round(100*e.loaded/e.total)),this.$emit("progress",{originalEvent:e,progress:this.progress})})),e.onreadystatechange=()=>{4===e.readyState&&(this.progress=0,e.status>=200&&e.status<300?(this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("upload",{xhr:e,files:this.files})):this.$emit("error",{xhr:e,files:this.files}),this.clear())},e.open("POST",this.url,!0),this.$emit("before-send",{xhr:e,formData:t}),e.withCredentials=this.withCredentials,e.send(t)}},clear(){this.files=[],this.messages=null,this.$emit("clear"),this.isAdvanced&&this.clearInputElement()},onFocus(){this.focused=!0},onBlur(){this.focused=!1},isFileSelected(e){if(this.files&&this.files.length)for(let t of this.files)if(t.name+t.type+t.size===e.name+e.type+e.size)return!0;return!1},isIE11:()=>!!window.MSInputMethodContext&&!!document.documentMode,validate(e){return this.accept&&!this.isFileTypeValid(e)?(this.messages.push(this.invalidFileTypeMessage.replace("{0}",e.name).replace("{1}",this.accept)),!1):!(this.maxFileSize&&e.size>this.maxFileSize)||(this.messages.push(this.invalidFileSizeMessage.replace("{0}",e.name).replace("{1}",this.formatSize(this.maxFileSize))),!1)},isFileTypeValid(e){let t=this.accept.split(",").map((e=>e.trim()));for(let i of t){if(this.isWildcard(i)?this.getTypeClass(e.type)===this.getTypeClass(i):e.type==i||this.getFileExtension(e).toLowerCase()===i.toLowerCase())return!0}return!1},getTypeClass:e=>e.substring(0,e.indexOf("/")),isWildcard:e=>-1!==e.indexOf("*"),getFileExtension:e=>"."+e.name.split(".").pop(),isImage:e=>/^image\//.test(e.type),onDragEnter(e){this.disabled||(e.stopPropagation(),e.preventDefault())},onDragOver(e){this.disabled||(l.addClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault())},onDragLeave(){this.disabled||l.removeClass(this.$refs.content,"p-fileupload-highlight")},onDrop(e){if(!this.disabled){l.removeClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault();const t=e.dataTransfer?e.dataTransfer.files:e.target.files;(this.multiple||t&&1===t.length)&&this.onFileSelect(e)}},onBasicUploaderClick(){this.hasFiles?this.upload():this.$refs.fileInput.click()},remove(e){this.clearInputElement();let t=this.files.splice(e,1)[0];this.files=[...this.files],this.$emit("remove",{file:t,files:this.files})},clearInputElement(){this.$refs.fileInput.value=""},clearIEInput(){this.$refs.fileInput&&(this.duplicateIEEvent=!0,this.$refs.fileInput.value="")},formatSize(e){if(0===e)return"0 B";let t=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,t)).toFixed(3))+" "+["B","KB","MB","GB","TB","PB","EB","ZB","YB"][t]},isFileLimitExceeded(){return this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount&&this.focused&&(this.focused=!1),this.fileLimit&&this.fileLimit<this.files.length+this.uploadedFileCount},checkFileLimit(){this.isFileLimitExceeded()&&this.messages.push(this.invalidFileLimitMessage.replace("{0}",this.fileLimit.toString()))},onMessageClose(){this.messages=null}},computed:{isAdvanced(){return"advanced"===this.mode},isBasic(){return"basic"===this.mode},advancedChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-fileupload-choose-selected":this.hasFiles,"p-disabled":this.disabled,"p-focus":this.focused}]},advancedChooseIconClass(){return["p-button-icon p-button-icon-left pi-fw",this.chooseIcon]},basicChooseButtonIconClass(){return["p-button-icon p-button-icon-left",!this.hasFiles||this.auto?this.uploadIcon:this.chooseIcon]},basicChooseButtonLabel(){return this.auto?this.chooseButtonLabel:this.hasFiles?this.files.map((e=>e.name)).join(", "):this.chooseButtonLabel},hasFiles(){return this.files&&this.files.length>0},chooseDisabled(){return this.disabled||this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount},uploadDisabled(){return this.disabled||!this.hasFiles||this.fileLimit&&this.fileLimit<this.files.length},cancelDisabled(){return this.disabled||!this.hasFiles},chooseButtonLabel(){return this.chooseLabel||this.$primevue.config.locale.choose},uploadButtonLabel(){return this.uploadLabel||this.$primevue.config.locale.upload},cancelButtonLabel(){return this.cancelLabel||this.$primevue.config.locale.cancel}},components:{FileUploadButton:e,FileUploadProgressBar:t,FileUploadMessage:i},directives:{ripple:s}};const I={key:0,class:"p-fileupload p-fileupload-advanced p-component"},w={class:"p-fileupload-buttonbar"},x=["multiple","accept","disabled"],S={class:"p-button-label"},k={key:1,class:"p-fileupload-files"},E=["alt","src","width"],D={class:"p-fileupload-filename"},M={key:2,class:"p-fileupload-empty"},$={key:1,class:"p-fileupload p-fileupload-basic p-component"},U={class:"p-button-label"},z=["accept","disabled","multiple"];!function(e,t){void 0===t&&(t={});var i=t.insertAt;if(e&&"undefined"!=typeof document){var l=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===i&&l.firstChild?l.insertBefore(s,l.firstChild):l.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}("\n.p-fileupload-content {\n position: relative;\n}\n.p-fileupload-row {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n}\n.p-fileupload-row > div {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n width: 25%;\n}\n.p-fileupload-row > div:last-child {\n text-align: right;\n}\n.p-fileupload-content .p-progressbar {\n width: 100%;\n position: absolute;\n top: 0;\n left: 0;\n}\n.p-button.p-fileupload-choose {\n position: relative;\n overflow: hidden;\n}\n.p-button.p-fileupload-choose input[type=file] {\n display: none;\n}\n.p-fileupload-choose.p-fileupload-choose-selected input[type=file] {\n display: none;\n}\n.p-fileupload-filename {\n word-break: break-all;\n}\n.p-fluid .p-fileupload .p-button {\n width: auto;\n}\n"),L.render=function(e,t,i,l,s,L){const T=o("FileUploadButton"),O=o("FileUploadProgressBar"),P=o("FileUploadMessage"),N=a("ripple");return L.isAdvanced?(n(),p("div",I,[d("div",w,[r((n(),p("span",{class:u(L.advancedChooseButtonClass),style:h(i.style),onClick:t[1]||(t[1]=(...e)=>L.choose&&L.choose(...e)),onKeydown:t[2]||(t[2]=c(((...e)=>L.choose&&L.choose(...e)),["enter"])),onFocus:t[3]||(t[3]=(...e)=>L.onFocus&&L.onFocus(...e)),onBlur:t[4]||(t[4]=(...e)=>L.onBlur&&L.onBlur(...e)),tabindex:"0"},[d("input",{ref:"fileInput",type:"file",onChange:t[0]||(t[0]=(...e)=>L.onFileSelect&&L.onFileSelect(...e)),multiple:i.multiple,accept:i.accept,disabled:L.chooseDisabled},null,40,x),d("span",{class:u(L.advancedChooseIconClass)},null,2),d("span",S,f(L.chooseButtonLabel),1)],38)),[[N]]),i.showUploadButton?(n(),m(T,{key:0,label:L.uploadButtonLabel,icon:i.uploadIcon,onClick:L.upload,disabled:L.uploadDisabled},null,8,["label","icon","onClick","disabled"])):g("",!0),i.showCancelButton?(n(),m(T,{key:1,label:L.cancelButtonLabel,icon:i.cancelIcon,onClick:L.clear,disabled:L.cancelDisabled},null,8,["label","icon","onClick","disabled"])):g("",!0)]),d("div",{ref:"content",class:"p-fileupload-content",onDragenter:t[5]||(t[5]=(...e)=>L.onDragEnter&&L.onDragEnter(...e)),onDragover:t[6]||(t[6]=(...e)=>L.onDragOver&&L.onDragOver(...e)),onDragleave:t[7]||(t[7]=(...e)=>L.onDragLeave&&L.onDragLeave(...e)),onDrop:t[8]||(t[8]=(...e)=>L.onDrop&&L.onDrop(...e))},[L.hasFiles?(n(),m(O,{key:0,value:s.progress},null,8,["value"])):g("",!0),(n(!0),p(b,null,v(s.messages,(e=>(n(),m(P,{severity:"error",key:e,onClose:L.onMessageClose},{default:y((()=>[F(f(e),1)])),_:2},1032,["onClose"])))),128)),L.hasFiles?(n(),p("div",k,[(n(!0),p(b,null,v(s.files,((e,t)=>(n(),p("div",{class:"p-fileupload-row",key:e.name+e.type+e.size},[d("div",null,[L.isImage(e)?(n(),p("img",{key:0,role:"presentation",alt:e.name,src:e.objectURL,width:i.previewWidth},null,8,E)):g("",!0)]),d("div",D,f(e.name),1),d("div",null,f(L.formatSize(e.size)),1),d("div",null,[C(T,{type:"button",icon:"pi pi-times",onClick:e=>L.remove(t)},null,8,["onClick"])])])))),128))])):g("",!0),e.$slots.empty&&!L.hasFiles?(n(),p("div",M,[B(e.$slots,"empty")])):g("",!0)],544)])):L.isBasic?(n(),p("div",$,[(n(!0),p(b,null,v(s.messages,(e=>(n(),m(P,{severity:"error",key:e,onClose:L.onMessageClose},{default:y((()=>[F(f(e),1)])),_:2},1032,["onClose"])))),128)),r((n(),p("span",{class:u(L.basicChooseButtonClass),style:h(i.style),onMouseup:t[12]||(t[12]=(...e)=>L.onBasicUploaderClick&&L.onBasicUploaderClick(...e)),onKeydown:t[13]||(t[13]=c(((...e)=>L.choose&&L.choose(...e)),["enter"])),onFocus:t[14]||(t[14]=(...e)=>L.onFocus&&L.onFocus(...e)),onBlur:t[15]||(t[15]=(...e)=>L.onBlur&&L.onBlur(...e)),tabindex:"0"},[d("span",{class:u(L.basicChooseButtonIconClass)},null,2),d("span",U,f(L.basicChooseButtonLabel),1),L.hasFiles?g("",!0):(n(),p("input",{key:0,ref:"fileInput",type:"file",accept:i.accept,disabled:i.disabled,multiple:i.multiple,onChange:t[9]||(t[9]=(...e)=>L.onFileSelect&&L.onFileSelect(...e)),onFocus:t[10]||(t[10]=(...e)=>L.onFocus&&L.onFocus(...e)),onBlur:t[11]||(t[11]=(...e)=>L.onBlur&&L.onBlur(...e))},null,40,z))],38)),[[N]])])):g("",!0)};export{L as default};
|
package/fileupload/fileupload.js
CHANGED
|
@@ -93,6 +93,18 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
93
93
|
type: Boolean,
|
|
94
94
|
default: true
|
|
95
95
|
},
|
|
96
|
+
chooseIcon: {
|
|
97
|
+
type: String,
|
|
98
|
+
default: 'pi pi-plus'
|
|
99
|
+
},
|
|
100
|
+
uploadIcon: {
|
|
101
|
+
type: String,
|
|
102
|
+
default: 'pi pi-upload'
|
|
103
|
+
},
|
|
104
|
+
cancelIcon: {
|
|
105
|
+
type: String,
|
|
106
|
+
default: 'pi pi-times'
|
|
107
|
+
},
|
|
96
108
|
style: null,
|
|
97
109
|
class: null
|
|
98
110
|
},
|
|
@@ -387,11 +399,13 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
387
399
|
'p-focus': this.focused
|
|
388
400
|
}];
|
|
389
401
|
},
|
|
402
|
+
advancedChooseIconClass() {
|
|
403
|
+
return ['p-button-icon p-button-icon-left pi-fw', this.chooseIcon];
|
|
404
|
+
},
|
|
390
405
|
basicChooseButtonIconClass() {
|
|
391
|
-
return ['p-button-icon p-button-icon-left
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}];
|
|
406
|
+
return ['p-button-icon p-button-icon-left',
|
|
407
|
+
!this.hasFiles || this.auto ? this.uploadIcon : this.chooseIcon
|
|
408
|
+
];
|
|
395
409
|
},
|
|
396
410
|
basicChooseButtonLabel() {
|
|
397
411
|
return this.auto ? this.chooseButtonLabel : (this.hasFiles ? this.files.map(f => f.name).join(', ') : this.chooseButtonLabel);
|
|
@@ -434,24 +448,23 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
434
448
|
};
|
|
435
449
|
const _hoisted_2 = { class: "p-fileupload-buttonbar" };
|
|
436
450
|
const _hoisted_3 = ["multiple", "accept", "disabled"];
|
|
437
|
-
const _hoisted_4 =
|
|
438
|
-
const _hoisted_5 = {
|
|
439
|
-
const _hoisted_6 = {
|
|
451
|
+
const _hoisted_4 = { class: "p-button-label" };
|
|
452
|
+
const _hoisted_5 = {
|
|
440
453
|
key: 1,
|
|
441
454
|
class: "p-fileupload-files"
|
|
442
455
|
};
|
|
443
|
-
const
|
|
444
|
-
const
|
|
445
|
-
const
|
|
456
|
+
const _hoisted_6 = ["alt", "src", "width"];
|
|
457
|
+
const _hoisted_7 = { class: "p-fileupload-filename" };
|
|
458
|
+
const _hoisted_8 = {
|
|
446
459
|
key: 2,
|
|
447
460
|
class: "p-fileupload-empty"
|
|
448
461
|
};
|
|
449
|
-
const
|
|
462
|
+
const _hoisted_9 = {
|
|
450
463
|
key: 1,
|
|
451
464
|
class: "p-fileupload p-fileupload-basic p-component"
|
|
452
465
|
};
|
|
453
|
-
const
|
|
454
|
-
const
|
|
466
|
+
const _hoisted_10 = { class: "p-button-label" };
|
|
467
|
+
const _hoisted_11 = ["accept", "disabled", "multiple"];
|
|
455
468
|
|
|
456
469
|
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
457
470
|
const _component_FileUploadButton = vue.resolveComponent("FileUploadButton");
|
|
@@ -479,8 +492,10 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
479
492
|
accept: $props.accept,
|
|
480
493
|
disabled: $options.chooseDisabled
|
|
481
494
|
}, null, 40, _hoisted_3),
|
|
482
|
-
|
|
483
|
-
|
|
495
|
+
vue.createElementVNode("span", {
|
|
496
|
+
class: vue.normalizeClass($options.advancedChooseIconClass)
|
|
497
|
+
}, null, 2),
|
|
498
|
+
vue.createElementVNode("span", _hoisted_4, vue.toDisplayString($options.chooseButtonLabel), 1)
|
|
484
499
|
], 38)), [
|
|
485
500
|
[_directive_ripple]
|
|
486
501
|
]),
|
|
@@ -488,19 +503,19 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
488
503
|
? (vue.openBlock(), vue.createBlock(_component_FileUploadButton, {
|
|
489
504
|
key: 0,
|
|
490
505
|
label: $options.uploadButtonLabel,
|
|
491
|
-
icon:
|
|
506
|
+
icon: $props.uploadIcon,
|
|
492
507
|
onClick: $options.upload,
|
|
493
508
|
disabled: $options.uploadDisabled
|
|
494
|
-
}, null, 8, ["label", "onClick", "disabled"]))
|
|
509
|
+
}, null, 8, ["label", "icon", "onClick", "disabled"]))
|
|
495
510
|
: vue.createCommentVNode("", true),
|
|
496
511
|
($props.showCancelButton)
|
|
497
512
|
? (vue.openBlock(), vue.createBlock(_component_FileUploadButton, {
|
|
498
513
|
key: 1,
|
|
499
514
|
label: $options.cancelButtonLabel,
|
|
500
|
-
icon:
|
|
515
|
+
icon: $props.cancelIcon,
|
|
501
516
|
onClick: $options.clear,
|
|
502
517
|
disabled: $options.cancelDisabled
|
|
503
|
-
}, null, 8, ["label", "onClick", "disabled"]))
|
|
518
|
+
}, null, 8, ["label", "icon", "onClick", "disabled"]))
|
|
504
519
|
: vue.createCommentVNode("", true)
|
|
505
520
|
]),
|
|
506
521
|
vue.createElementVNode("div", {
|
|
@@ -530,7 +545,7 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
530
545
|
}, 1032, ["onClose"]))
|
|
531
546
|
}), 128)),
|
|
532
547
|
($options.hasFiles)
|
|
533
|
-
? (vue.openBlock(), vue.createElementBlock("div",
|
|
548
|
+
? (vue.openBlock(), vue.createElementBlock("div", _hoisted_5, [
|
|
534
549
|
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList($data.files, (file, index) => {
|
|
535
550
|
return (vue.openBlock(), vue.createElementBlock("div", {
|
|
536
551
|
class: "p-fileupload-row",
|
|
@@ -544,10 +559,10 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
544
559
|
alt: file.name,
|
|
545
560
|
src: file.objectURL,
|
|
546
561
|
width: $props.previewWidth
|
|
547
|
-
}, null, 8,
|
|
562
|
+
}, null, 8, _hoisted_6))
|
|
548
563
|
: vue.createCommentVNode("", true)
|
|
549
564
|
]),
|
|
550
|
-
vue.createElementVNode("div",
|
|
565
|
+
vue.createElementVNode("div", _hoisted_7, vue.toDisplayString(file.name), 1),
|
|
551
566
|
vue.createElementVNode("div", null, vue.toDisplayString($options.formatSize(file.size)), 1),
|
|
552
567
|
vue.createElementVNode("div", null, [
|
|
553
568
|
vue.createVNode(_component_FileUploadButton, {
|
|
@@ -561,14 +576,14 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
561
576
|
]))
|
|
562
577
|
: vue.createCommentVNode("", true),
|
|
563
578
|
(_ctx.$slots.empty && !$options.hasFiles)
|
|
564
|
-
? (vue.openBlock(), vue.createElementBlock("div",
|
|
579
|
+
? (vue.openBlock(), vue.createElementBlock("div", _hoisted_8, [
|
|
565
580
|
vue.renderSlot(_ctx.$slots, "empty")
|
|
566
581
|
]))
|
|
567
582
|
: vue.createCommentVNode("", true)
|
|
568
583
|
], 544)
|
|
569
584
|
]))
|
|
570
585
|
: ($options.isBasic)
|
|
571
|
-
? (vue.openBlock(), vue.createElementBlock("div",
|
|
586
|
+
? (vue.openBlock(), vue.createElementBlock("div", _hoisted_9, [
|
|
572
587
|
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList($data.messages, (msg) => {
|
|
573
588
|
return (vue.openBlock(), vue.createBlock(_component_FileUploadMessage, {
|
|
574
589
|
severity: "error",
|
|
@@ -593,7 +608,7 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
593
608
|
vue.createElementVNode("span", {
|
|
594
609
|
class: vue.normalizeClass($options.basicChooseButtonIconClass)
|
|
595
610
|
}, null, 2),
|
|
596
|
-
vue.createElementVNode("span",
|
|
611
|
+
vue.createElementVNode("span", _hoisted_10, vue.toDisplayString($options.basicChooseButtonLabel), 1),
|
|
597
612
|
(!$options.hasFiles)
|
|
598
613
|
? (vue.openBlock(), vue.createElementBlock("input", {
|
|
599
614
|
key: 0,
|
|
@@ -605,7 +620,7 @@ this.primevue.fileupload = (function (Button, ProgressBar, Message, utils, Rippl
|
|
|
605
620
|
onChange: _cache[9] || (_cache[9] = (...args) => ($options.onFileSelect && $options.onFileSelect(...args))),
|
|
606
621
|
onFocus: _cache[10] || (_cache[10] = (...args) => ($options.onFocus && $options.onFocus(...args))),
|
|
607
622
|
onBlur: _cache[11] || (_cache[11] = (...args) => ($options.onBlur && $options.onBlur(...args)))
|
|
608
|
-
}, null, 40,
|
|
623
|
+
}, null, 40, _hoisted_11))
|
|
609
624
|
: vue.createCommentVNode("", true)
|
|
610
625
|
], 38)), [
|
|
611
626
|
[_directive_ripple]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
this.primevue=this.primevue||{},this.primevue.fileupload=function(e,t,l,i,s,o){"use strict";function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=a(e),r=a(t),p=a(l),d=a(s),c={name:"FileUpload",emits:["select","uploader","before-upload","progress","upload","error","before-send","clear","remove"],props:{name:{type:String,default:null},url:{type:String,default:null},mode:{type:String,default:"advanced"},multiple:{type:Boolean,default:!1},accept:{type:String,default:null},disabled:{type:Boolean,default:!1},auto:{type:Boolean,default:!1},maxFileSize:{type:Number,default:null},invalidFileSizeMessage:{type:String,default:"{0}: Invalid file size, file size should be smaller than {1}."},invalidFileTypeMessage:{type:String,default:"{0}: Invalid file type, allowed file types: {1}."},fileLimit:{type:Number,default:null},invalidFileLimitMessage:{type:String,default:"Maximum number of files exceeded, limit is {0} at most."},withCredentials:{type:Boolean,default:!1},previewWidth:{type:Number,default:50},chooseLabel:{type:String,default:null},uploadLabel:{type:String,default:null},cancelLabel:{type:String,default:null},customUpload:{type:Boolean,default:!1},showUploadButton:{type:Boolean,default:!0},showCancelButton:{type:Boolean,default:!0},style:null,class:null},duplicateIEEvent:!1,data:()=>({uploadedFileCount:0,files:[],messages:[],focused:!1,progress:null}),methods:{onFileSelect(e){if("drop"!==e.type&&this.isIE11()&&this.duplicateIEEvent)return void(this.duplicateIEEvent=!1);this.messages=[],this.files=this.files||[];let t=e.dataTransfer?e.dataTransfer.files:e.target.files;for(let e of t)this.isFileSelected(e)||this.validate(e)&&(this.isImage(e)&&(e.objectURL=window.URL.createObjectURL(e)),this.files.push(e));this.$emit("select",{originalEvent:e,files:this.files}),this.fileLimit&&this.checkFileLimit(),this.auto&&this.hasFiles&&!this.isFileLimitExceeded()&&this.upload(),"drop"!==e.type&&this.isIE11()?this.clearIEInput():this.clearInputElement()},choose(){this.$refs.fileInput.click()},upload(){if(this.customUpload)this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("uploader",{files:this.files}),this.clear();else{let e=new XMLHttpRequest,t=new FormData;this.$emit("before-upload",{xhr:e,formData:t});for(let e of this.files)t.append(this.name,e,e.name);e.upload.addEventListener("progress",(e=>{e.lengthComputable&&(this.progress=Math.round(100*e.loaded/e.total)),this.$emit("progress",{originalEvent:e,progress:this.progress})})),e.onreadystatechange=()=>{4===e.readyState&&(this.progress=0,e.status>=200&&e.status<300?(this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("upload",{xhr:e,files:this.files})):this.$emit("error",{xhr:e,files:this.files}),this.clear())},e.open("POST",this.url,!0),this.$emit("before-send",{xhr:e,formData:t}),e.withCredentials=this.withCredentials,e.send(t)}},clear(){this.files=[],this.messages=null,this.$emit("clear"),this.isAdvanced&&this.clearInputElement()},onFocus(){this.focused=!0},onBlur(){this.focused=!1},isFileSelected(e){if(this.files&&this.files.length)for(let t of this.files)if(t.name+t.type+t.size===e.name+e.type+e.size)return!0;return!1},isIE11:()=>!!window.MSInputMethodContext&&!!document.documentMode,validate(e){return this.accept&&!this.isFileTypeValid(e)?(this.messages.push(this.invalidFileTypeMessage.replace("{0}",e.name).replace("{1}",this.accept)),!1):!(this.maxFileSize&&e.size>this.maxFileSize)||(this.messages.push(this.invalidFileSizeMessage.replace("{0}",e.name).replace("{1}",this.formatSize(this.maxFileSize))),!1)},isFileTypeValid(e){let t=this.accept.split(",").map((e=>e.trim()));for(let l of t){if(this.isWildcard(l)?this.getTypeClass(e.type)===this.getTypeClass(l):e.type==l||this.getFileExtension(e).toLowerCase()===l.toLowerCase())return!0}return!1},getTypeClass:e=>e.substring(0,e.indexOf("/")),isWildcard:e=>-1!==e.indexOf("*"),getFileExtension:e=>"."+e.name.split(".").pop(),isImage:e=>/^image\//.test(e.type),onDragEnter(e){this.disabled||(e.stopPropagation(),e.preventDefault())},onDragOver(e){this.disabled||(i.DomHandler.addClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault())},onDragLeave(){this.disabled||i.DomHandler.removeClass(this.$refs.content,"p-fileupload-highlight")},onDrop(e){if(!this.disabled){i.DomHandler.removeClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault();const t=e.dataTransfer?e.dataTransfer.files:e.target.files;(this.multiple||t&&1===t.length)&&this.onFileSelect(e)}},onBasicUploaderClick(){this.hasFiles?this.upload():this.$refs.fileInput.click()},remove(e){this.clearInputElement();let t=this.files.splice(e,1)[0];this.files=[...this.files],this.$emit("remove",{file:t,files:this.files})},clearInputElement(){this.$refs.fileInput.value=""},clearIEInput(){this.$refs.fileInput&&(this.duplicateIEEvent=!0,this.$refs.fileInput.value="")},formatSize(e){if(0===e)return"0 B";let t=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,t)).toFixed(3))+" "+["B","KB","MB","GB","TB","PB","EB","ZB","YB"][t]},isFileLimitExceeded(){return this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount&&this.focused&&(this.focused=!1),this.fileLimit&&this.fileLimit<this.files.length+this.uploadedFileCount},checkFileLimit(){this.isFileLimitExceeded()&&this.messages.push(this.invalidFileLimitMessage.replace("{0}",this.fileLimit.toString()))},onMessageClose(){this.messages=null}},computed:{isAdvanced(){return"advanced"===this.mode},isBasic(){return"basic"===this.mode},advancedChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-fileupload-choose-selected":this.hasFiles,"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonIconClass(){return["p-button-icon p-button-icon-left pi",{"pi-plus":!this.hasFiles||this.auto,"pi-upload":this.hasFiles&&!this.auto}]},basicChooseButtonLabel(){return this.auto?this.chooseButtonLabel:this.hasFiles?this.files.map((e=>e.name)).join(", "):this.chooseButtonLabel},hasFiles(){return this.files&&this.files.length>0},chooseDisabled(){return this.disabled||this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount},uploadDisabled(){return this.disabled||!this.hasFiles||this.fileLimit&&this.fileLimit<this.files.length},cancelDisabled(){return this.disabled||!this.hasFiles},chooseButtonLabel(){return this.chooseLabel||this.$primevue.config.locale.choose},uploadButtonLabel(){return this.uploadLabel||this.$primevue.config.locale.upload},cancelButtonLabel(){return this.cancelLabel||this.$primevue.config.locale.cancel}},components:{FileUploadButton:n.default,FileUploadProgressBar:r.default,FileUploadMessage:p.default},directives:{ripple:d.default}};const u={key:0,class:"p-fileupload p-fileupload-advanced p-component"},h={class:"p-fileupload-buttonbar"},f=["multiple","accept","disabled"],m=o.createElementVNode("span",{class:"p-button-icon p-button-icon-left pi pi-fw pi-plus"},null,-1),g={class:"p-button-label"},b={key:1,class:"p-fileupload-files"},B=["alt","src","width"],v={class:"p-fileupload-filename"},y={key:2,class:"p-fileupload-empty"},C={key:1,class:"p-fileupload p-fileupload-basic p-component"},F={class:"p-button-label"},k=["accept","disabled","multiple"];return function(e,t){void 0===t&&(t={});var l=t.insertAt;if(e&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===l&&i.firstChild?i.insertBefore(s,i.firstChild):i.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}("\n.p-fileupload-content {\n position: relative;\n}\n.p-fileupload-row {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n}\n.p-fileupload-row > div {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n width: 25%;\n}\n.p-fileupload-row > div:last-child {\n text-align: right;\n}\n.p-fileupload-content .p-progressbar {\n width: 100%;\n position: absolute;\n top: 0;\n left: 0;\n}\n.p-button.p-fileupload-choose {\n position: relative;\n overflow: hidden;\n}\n.p-button.p-fileupload-choose input[type=file] {\n display: none;\n}\n.p-fileupload-choose.p-fileupload-choose-selected input[type=file] {\n display: none;\n}\n.p-fileupload-filename {\n word-break: break-all;\n}\n.p-fluid .p-fileupload .p-button {\n width: auto;\n}\n"),c.render=function(e,t,l,i,s,a){const n=o.resolveComponent("FileUploadButton"),r=o.resolveComponent("FileUploadProgressBar"),p=o.resolveComponent("FileUploadMessage"),d=o.resolveDirective("ripple");return a.isAdvanced?(o.openBlock(),o.createElementBlock("div",u,[o.createElementVNode("div",h,[o.withDirectives((o.openBlock(),o.createElementBlock("span",{class:o.normalizeClass(a.advancedChooseButtonClass),style:o.normalizeStyle(l.style),onClick:t[1]||(t[1]=(...e)=>a.choose&&a.choose(...e)),onKeydown:t[2]||(t[2]=o.withKeys(((...e)=>a.choose&&a.choose(...e)),["enter"])),onFocus:t[3]||(t[3]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[4]||(t[4]=(...e)=>a.onBlur&&a.onBlur(...e)),tabindex:"0"},[o.createElementVNode("input",{ref:"fileInput",type:"file",onChange:t[0]||(t[0]=(...e)=>a.onFileSelect&&a.onFileSelect(...e)),multiple:l.multiple,accept:l.accept,disabled:a.chooseDisabled},null,40,f),m,o.createElementVNode("span",g,o.toDisplayString(a.chooseButtonLabel),1)],38)),[[d]]),l.showUploadButton?(o.openBlock(),o.createBlock(n,{key:0,label:a.uploadButtonLabel,icon:"pi pi-upload",onClick:a.upload,disabled:a.uploadDisabled},null,8,["label","onClick","disabled"])):o.createCommentVNode("",!0),l.showCancelButton?(o.openBlock(),o.createBlock(n,{key:1,label:a.cancelButtonLabel,icon:"pi pi-times",onClick:a.clear,disabled:a.cancelDisabled},null,8,["label","onClick","disabled"])):o.createCommentVNode("",!0)]),o.createElementVNode("div",{ref:"content",class:"p-fileupload-content",onDragenter:t[5]||(t[5]=(...e)=>a.onDragEnter&&a.onDragEnter(...e)),onDragover:t[6]||(t[6]=(...e)=>a.onDragOver&&a.onDragOver(...e)),onDragleave:t[7]||(t[7]=(...e)=>a.onDragLeave&&a.onDragLeave(...e)),onDrop:t[8]||(t[8]=(...e)=>a.onDrop&&a.onDrop(...e))},[a.hasFiles?(o.openBlock(),o.createBlock(r,{key:0,value:s.progress},null,8,["value"])):o.createCommentVNode("",!0),(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.messages,(e=>(o.openBlock(),o.createBlock(p,{severity:"error",key:e,onClose:a.onMessageClose},{default:o.withCtx((()=>[o.createTextVNode(o.toDisplayString(e),1)])),_:2},1032,["onClose"])))),128)),a.hasFiles?(o.openBlock(),o.createElementBlock("div",b,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.files,((e,t)=>(o.openBlock(),o.createElementBlock("div",{class:"p-fileupload-row",key:e.name+e.type+e.size},[o.createElementVNode("div",null,[a.isImage(e)?(o.openBlock(),o.createElementBlock("img",{key:0,role:"presentation",alt:e.name,src:e.objectURL,width:l.previewWidth},null,8,B)):o.createCommentVNode("",!0)]),o.createElementVNode("div",v,o.toDisplayString(e.name),1),o.createElementVNode("div",null,o.toDisplayString(a.formatSize(e.size)),1),o.createElementVNode("div",null,[o.createVNode(n,{type:"button",icon:"pi pi-times",onClick:e=>a.remove(t)},null,8,["onClick"])])])))),128))])):o.createCommentVNode("",!0),e.$slots.empty&&!a.hasFiles?(o.openBlock(),o.createElementBlock("div",y,[o.renderSlot(e.$slots,"empty")])):o.createCommentVNode("",!0)],544)])):a.isBasic?(o.openBlock(),o.createElementBlock("div",C,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.messages,(e=>(o.openBlock(),o.createBlock(p,{severity:"error",key:e,onClose:a.onMessageClose},{default:o.withCtx((()=>[o.createTextVNode(o.toDisplayString(e),1)])),_:2},1032,["onClose"])))),128)),o.withDirectives((o.openBlock(),o.createElementBlock("span",{class:o.normalizeClass(a.basicChooseButtonClass),style:o.normalizeStyle(l.style),onMouseup:t[12]||(t[12]=(...e)=>a.onBasicUploaderClick&&a.onBasicUploaderClick(...e)),onKeydown:t[13]||(t[13]=o.withKeys(((...e)=>a.choose&&a.choose(...e)),["enter"])),onFocus:t[14]||(t[14]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[15]||(t[15]=(...e)=>a.onBlur&&a.onBlur(...e)),tabindex:"0"},[o.createElementVNode("span",{class:o.normalizeClass(a.basicChooseButtonIconClass)},null,2),o.createElementVNode("span",F,o.toDisplayString(a.basicChooseButtonLabel),1),a.hasFiles?o.createCommentVNode("",!0):(o.openBlock(),o.createElementBlock("input",{key:0,ref:"fileInput",type:"file",accept:l.accept,disabled:l.disabled,multiple:l.multiple,onChange:t[9]||(t[9]=(...e)=>a.onFileSelect&&a.onFileSelect(...e)),onFocus:t[10]||(t[10]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[11]||(t[11]=(...e)=>a.onBlur&&a.onBlur(...e))},null,40,k))],38)),[[d]])])):o.createCommentVNode("",!0)},c}(primevue.button,primevue.progressbar,primevue.message,primevue.utils,primevue.ripple,Vue);
|
|
1
|
+
this.primevue=this.primevue||{},this.primevue.fileupload=function(e,t,l,i,s,o){"use strict";function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=a(e),r=a(t),p=a(l),d=a(s),c={name:"FileUpload",emits:["select","uploader","before-upload","progress","upload","error","before-send","clear","remove"],props:{name:{type:String,default:null},url:{type:String,default:null},mode:{type:String,default:"advanced"},multiple:{type:Boolean,default:!1},accept:{type:String,default:null},disabled:{type:Boolean,default:!1},auto:{type:Boolean,default:!1},maxFileSize:{type:Number,default:null},invalidFileSizeMessage:{type:String,default:"{0}: Invalid file size, file size should be smaller than {1}."},invalidFileTypeMessage:{type:String,default:"{0}: Invalid file type, allowed file types: {1}."},fileLimit:{type:Number,default:null},invalidFileLimitMessage:{type:String,default:"Maximum number of files exceeded, limit is {0} at most."},withCredentials:{type:Boolean,default:!1},previewWidth:{type:Number,default:50},chooseLabel:{type:String,default:null},uploadLabel:{type:String,default:null},cancelLabel:{type:String,default:null},customUpload:{type:Boolean,default:!1},showUploadButton:{type:Boolean,default:!0},showCancelButton:{type:Boolean,default:!0},chooseIcon:{type:String,default:"pi pi-plus"},uploadIcon:{type:String,default:"pi pi-upload"},cancelIcon:{type:String,default:"pi pi-times"},style:null,class:null},duplicateIEEvent:!1,data:()=>({uploadedFileCount:0,files:[],messages:[],focused:!1,progress:null}),methods:{onFileSelect(e){if("drop"!==e.type&&this.isIE11()&&this.duplicateIEEvent)return void(this.duplicateIEEvent=!1);this.messages=[],this.files=this.files||[];let t=e.dataTransfer?e.dataTransfer.files:e.target.files;for(let e of t)this.isFileSelected(e)||this.validate(e)&&(this.isImage(e)&&(e.objectURL=window.URL.createObjectURL(e)),this.files.push(e));this.$emit("select",{originalEvent:e,files:this.files}),this.fileLimit&&this.checkFileLimit(),this.auto&&this.hasFiles&&!this.isFileLimitExceeded()&&this.upload(),"drop"!==e.type&&this.isIE11()?this.clearIEInput():this.clearInputElement()},choose(){this.$refs.fileInput.click()},upload(){if(this.customUpload)this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("uploader",{files:this.files}),this.clear();else{let e=new XMLHttpRequest,t=new FormData;this.$emit("before-upload",{xhr:e,formData:t});for(let e of this.files)t.append(this.name,e,e.name);e.upload.addEventListener("progress",(e=>{e.lengthComputable&&(this.progress=Math.round(100*e.loaded/e.total)),this.$emit("progress",{originalEvent:e,progress:this.progress})})),e.onreadystatechange=()=>{4===e.readyState&&(this.progress=0,e.status>=200&&e.status<300?(this.fileLimit&&(this.uploadedFileCount+=this.files.length),this.$emit("upload",{xhr:e,files:this.files})):this.$emit("error",{xhr:e,files:this.files}),this.clear())},e.open("POST",this.url,!0),this.$emit("before-send",{xhr:e,formData:t}),e.withCredentials=this.withCredentials,e.send(t)}},clear(){this.files=[],this.messages=null,this.$emit("clear"),this.isAdvanced&&this.clearInputElement()},onFocus(){this.focused=!0},onBlur(){this.focused=!1},isFileSelected(e){if(this.files&&this.files.length)for(let t of this.files)if(t.name+t.type+t.size===e.name+e.type+e.size)return!0;return!1},isIE11:()=>!!window.MSInputMethodContext&&!!document.documentMode,validate(e){return this.accept&&!this.isFileTypeValid(e)?(this.messages.push(this.invalidFileTypeMessage.replace("{0}",e.name).replace("{1}",this.accept)),!1):!(this.maxFileSize&&e.size>this.maxFileSize)||(this.messages.push(this.invalidFileSizeMessage.replace("{0}",e.name).replace("{1}",this.formatSize(this.maxFileSize))),!1)},isFileTypeValid(e){let t=this.accept.split(",").map((e=>e.trim()));for(let l of t){if(this.isWildcard(l)?this.getTypeClass(e.type)===this.getTypeClass(l):e.type==l||this.getFileExtension(e).toLowerCase()===l.toLowerCase())return!0}return!1},getTypeClass:e=>e.substring(0,e.indexOf("/")),isWildcard:e=>-1!==e.indexOf("*"),getFileExtension:e=>"."+e.name.split(".").pop(),isImage:e=>/^image\//.test(e.type),onDragEnter(e){this.disabled||(e.stopPropagation(),e.preventDefault())},onDragOver(e){this.disabled||(i.DomHandler.addClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault())},onDragLeave(){this.disabled||i.DomHandler.removeClass(this.$refs.content,"p-fileupload-highlight")},onDrop(e){if(!this.disabled){i.DomHandler.removeClass(this.$refs.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault();const t=e.dataTransfer?e.dataTransfer.files:e.target.files;(this.multiple||t&&1===t.length)&&this.onFileSelect(e)}},onBasicUploaderClick(){this.hasFiles?this.upload():this.$refs.fileInput.click()},remove(e){this.clearInputElement();let t=this.files.splice(e,1)[0];this.files=[...this.files],this.$emit("remove",{file:t,files:this.files})},clearInputElement(){this.$refs.fileInput.value=""},clearIEInput(){this.$refs.fileInput&&(this.duplicateIEEvent=!0,this.$refs.fileInput.value="")},formatSize(e){if(0===e)return"0 B";let t=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,t)).toFixed(3))+" "+["B","KB","MB","GB","TB","PB","EB","ZB","YB"][t]},isFileLimitExceeded(){return this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount&&this.focused&&(this.focused=!1),this.fileLimit&&this.fileLimit<this.files.length+this.uploadedFileCount},checkFileLimit(){this.isFileLimitExceeded()&&this.messages.push(this.invalidFileLimitMessage.replace("{0}",this.fileLimit.toString()))},onMessageClose(){this.messages=null}},computed:{isAdvanced(){return"advanced"===this.mode},isBasic(){return"basic"===this.mode},advancedChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-disabled":this.disabled,"p-focus":this.focused}]},basicChooseButtonClass(){return["p-button p-component p-fileupload-choose",this.class,{"p-fileupload-choose-selected":this.hasFiles,"p-disabled":this.disabled,"p-focus":this.focused}]},advancedChooseIconClass(){return["p-button-icon p-button-icon-left pi-fw",this.chooseIcon]},basicChooseButtonIconClass(){return["p-button-icon p-button-icon-left",!this.hasFiles||this.auto?this.uploadIcon:this.chooseIcon]},basicChooseButtonLabel(){return this.auto?this.chooseButtonLabel:this.hasFiles?this.files.map((e=>e.name)).join(", "):this.chooseButtonLabel},hasFiles(){return this.files&&this.files.length>0},chooseDisabled(){return this.disabled||this.fileLimit&&this.fileLimit<=this.files.length+this.uploadedFileCount},uploadDisabled(){return this.disabled||!this.hasFiles||this.fileLimit&&this.fileLimit<this.files.length},cancelDisabled(){return this.disabled||!this.hasFiles},chooseButtonLabel(){return this.chooseLabel||this.$primevue.config.locale.choose},uploadButtonLabel(){return this.uploadLabel||this.$primevue.config.locale.upload},cancelButtonLabel(){return this.cancelLabel||this.$primevue.config.locale.cancel}},components:{FileUploadButton:n.default,FileUploadProgressBar:r.default,FileUploadMessage:p.default},directives:{ripple:d.default}};const u={key:0,class:"p-fileupload p-fileupload-advanced p-component"},h={class:"p-fileupload-buttonbar"},f=["multiple","accept","disabled"],m={class:"p-button-label"},g={key:1,class:"p-fileupload-files"},b=["alt","src","width"],y={class:"p-fileupload-filename"},v={key:2,class:"p-fileupload-empty"},B={key:1,class:"p-fileupload p-fileupload-basic p-component"},C={class:"p-button-label"},F=["accept","disabled","multiple"];return function(e,t){void 0===t&&(t={});var l=t.insertAt;if(e&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===l&&i.firstChild?i.insertBefore(s,i.firstChild):i.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}("\n.p-fileupload-content {\n position: relative;\n}\n.p-fileupload-row {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n}\n.p-fileupload-row > div {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n width: 25%;\n}\n.p-fileupload-row > div:last-child {\n text-align: right;\n}\n.p-fileupload-content .p-progressbar {\n width: 100%;\n position: absolute;\n top: 0;\n left: 0;\n}\n.p-button.p-fileupload-choose {\n position: relative;\n overflow: hidden;\n}\n.p-button.p-fileupload-choose input[type=file] {\n display: none;\n}\n.p-fileupload-choose.p-fileupload-choose-selected input[type=file] {\n display: none;\n}\n.p-fileupload-filename {\n word-break: break-all;\n}\n.p-fluid .p-fileupload .p-button {\n width: auto;\n}\n"),c.render=function(e,t,l,i,s,a){const n=o.resolveComponent("FileUploadButton"),r=o.resolveComponent("FileUploadProgressBar"),p=o.resolveComponent("FileUploadMessage"),d=o.resolveDirective("ripple");return a.isAdvanced?(o.openBlock(),o.createElementBlock("div",u,[o.createElementVNode("div",h,[o.withDirectives((o.openBlock(),o.createElementBlock("span",{class:o.normalizeClass(a.advancedChooseButtonClass),style:o.normalizeStyle(l.style),onClick:t[1]||(t[1]=(...e)=>a.choose&&a.choose(...e)),onKeydown:t[2]||(t[2]=o.withKeys(((...e)=>a.choose&&a.choose(...e)),["enter"])),onFocus:t[3]||(t[3]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[4]||(t[4]=(...e)=>a.onBlur&&a.onBlur(...e)),tabindex:"0"},[o.createElementVNode("input",{ref:"fileInput",type:"file",onChange:t[0]||(t[0]=(...e)=>a.onFileSelect&&a.onFileSelect(...e)),multiple:l.multiple,accept:l.accept,disabled:a.chooseDisabled},null,40,f),o.createElementVNode("span",{class:o.normalizeClass(a.advancedChooseIconClass)},null,2),o.createElementVNode("span",m,o.toDisplayString(a.chooseButtonLabel),1)],38)),[[d]]),l.showUploadButton?(o.openBlock(),o.createBlock(n,{key:0,label:a.uploadButtonLabel,icon:l.uploadIcon,onClick:a.upload,disabled:a.uploadDisabled},null,8,["label","icon","onClick","disabled"])):o.createCommentVNode("",!0),l.showCancelButton?(o.openBlock(),o.createBlock(n,{key:1,label:a.cancelButtonLabel,icon:l.cancelIcon,onClick:a.clear,disabled:a.cancelDisabled},null,8,["label","icon","onClick","disabled"])):o.createCommentVNode("",!0)]),o.createElementVNode("div",{ref:"content",class:"p-fileupload-content",onDragenter:t[5]||(t[5]=(...e)=>a.onDragEnter&&a.onDragEnter(...e)),onDragover:t[6]||(t[6]=(...e)=>a.onDragOver&&a.onDragOver(...e)),onDragleave:t[7]||(t[7]=(...e)=>a.onDragLeave&&a.onDragLeave(...e)),onDrop:t[8]||(t[8]=(...e)=>a.onDrop&&a.onDrop(...e))},[a.hasFiles?(o.openBlock(),o.createBlock(r,{key:0,value:s.progress},null,8,["value"])):o.createCommentVNode("",!0),(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.messages,(e=>(o.openBlock(),o.createBlock(p,{severity:"error",key:e,onClose:a.onMessageClose},{default:o.withCtx((()=>[o.createTextVNode(o.toDisplayString(e),1)])),_:2},1032,["onClose"])))),128)),a.hasFiles?(o.openBlock(),o.createElementBlock("div",g,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.files,((e,t)=>(o.openBlock(),o.createElementBlock("div",{class:"p-fileupload-row",key:e.name+e.type+e.size},[o.createElementVNode("div",null,[a.isImage(e)?(o.openBlock(),o.createElementBlock("img",{key:0,role:"presentation",alt:e.name,src:e.objectURL,width:l.previewWidth},null,8,b)):o.createCommentVNode("",!0)]),o.createElementVNode("div",y,o.toDisplayString(e.name),1),o.createElementVNode("div",null,o.toDisplayString(a.formatSize(e.size)),1),o.createElementVNode("div",null,[o.createVNode(n,{type:"button",icon:"pi pi-times",onClick:e=>a.remove(t)},null,8,["onClick"])])])))),128))])):o.createCommentVNode("",!0),e.$slots.empty&&!a.hasFiles?(o.openBlock(),o.createElementBlock("div",v,[o.renderSlot(e.$slots,"empty")])):o.createCommentVNode("",!0)],544)])):a.isBasic?(o.openBlock(),o.createElementBlock("div",B,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.messages,(e=>(o.openBlock(),o.createBlock(p,{severity:"error",key:e,onClose:a.onMessageClose},{default:o.withCtx((()=>[o.createTextVNode(o.toDisplayString(e),1)])),_:2},1032,["onClose"])))),128)),o.withDirectives((o.openBlock(),o.createElementBlock("span",{class:o.normalizeClass(a.basicChooseButtonClass),style:o.normalizeStyle(l.style),onMouseup:t[12]||(t[12]=(...e)=>a.onBasicUploaderClick&&a.onBasicUploaderClick(...e)),onKeydown:t[13]||(t[13]=o.withKeys(((...e)=>a.choose&&a.choose(...e)),["enter"])),onFocus:t[14]||(t[14]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[15]||(t[15]=(...e)=>a.onBlur&&a.onBlur(...e)),tabindex:"0"},[o.createElementVNode("span",{class:o.normalizeClass(a.basicChooseButtonIconClass)},null,2),o.createElementVNode("span",C,o.toDisplayString(a.basicChooseButtonLabel),1),a.hasFiles?o.createCommentVNode("",!0):(o.openBlock(),o.createElementBlock("input",{key:0,ref:"fileInput",type:"file",accept:l.accept,disabled:l.disabled,multiple:l.multiple,onChange:t[9]||(t[9]=(...e)=>a.onFileSelect&&a.onFileSelect(...e)),onFocus:t[10]||(t[10]=(...e)=>a.onFocus&&a.onFocus(...e)),onBlur:t[11]||(t[11]=(...e)=>a.onBlur&&a.onBlur(...e))},null,40,F))],38)),[[d]])])):o.createCommentVNode("",!0)},c}(primevue.button,primevue.progressbar,primevue.message,primevue.utils,primevue.ripple,Vue);
|
|
@@ -133,6 +133,10 @@ export interface InputNumberProps {
|
|
|
133
133
|
* Default value is true.
|
|
134
134
|
*/
|
|
135
135
|
allowEmpty?: boolean | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* When present, it specifies that an input field is read-only.
|
|
138
|
+
*/
|
|
139
|
+
readonly?: boolean | undefined;
|
|
136
140
|
/**
|
|
137
141
|
* Inline style of the input field.
|
|
138
142
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<span :class="containerClass" :style="style">
|
|
3
|
-
<INInputText ref="input" :class="['p-inputnumber-input', inputClass]" :style="inputStyle" :value="formattedValue" v-bind="$attrs" :aria-valumin="min" :aria-valuemax="max"
|
|
3
|
+
<INInputText ref="input" :class="['p-inputnumber-input', inputClass]" :style="inputStyle" :value="formattedValue" v-bind="$attrs" :aria-valumin="min" :aria-valuemax="max" :readonly="readonly"
|
|
4
4
|
@input="onUserInput" @keydown="onInputKeyDown" @keypress="onInputKeyPress" @paste="onPaste" @click="onInputClick" @focus="onInputFocus" @blur="onInputBlur"/>
|
|
5
5
|
<span class="p-inputnumber-button-group" v-if="showButtons && buttonLayout === 'stacked'">
|
|
6
6
|
<INButton :class="upButtonClass" :icon="incrementButtonIcon" v-on="upButtonListeners" :disabled="$attrs.disabled" />
|
|
@@ -108,6 +108,10 @@ export default {
|
|
|
108
108
|
type: Boolean,
|
|
109
109
|
default: true
|
|
110
110
|
},
|
|
111
|
+
readonly: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
default: false
|
|
114
|
+
},
|
|
111
115
|
style: null,
|
|
112
116
|
class: null,
|
|
113
117
|
inputStyle: null,
|
|
@@ -297,6 +301,10 @@ export default {
|
|
|
297
301
|
return null;
|
|
298
302
|
},
|
|
299
303
|
repeat(event, interval, dir) {
|
|
304
|
+
if (this.readonly) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
300
308
|
let i = interval || 500;
|
|
301
309
|
|
|
302
310
|
this.clearTimer();
|
|
@@ -379,6 +387,10 @@ export default {
|
|
|
379
387
|
this.isSpecialChar = false;
|
|
380
388
|
},
|
|
381
389
|
onInputKeyDown(event) {
|
|
390
|
+
if (this.readonly) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
382
394
|
this.lastValue = event.target.value;
|
|
383
395
|
if (event.shiftKey || event.altKey) {
|
|
384
396
|
this.isSpecialChar = true;
|
|
@@ -528,6 +540,10 @@ export default {
|
|
|
528
540
|
}
|
|
529
541
|
},
|
|
530
542
|
onInputKeyPress(event) {
|
|
543
|
+
if (this.readonly) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
|
|
531
547
|
event.preventDefault();
|
|
532
548
|
let code = event.which || event.keyCode;
|
|
533
549
|
let char = String.fromCharCode(code);
|
|
@@ -734,7 +750,9 @@ export default {
|
|
|
734
750
|
return index || 0;
|
|
735
751
|
},
|
|
736
752
|
onInputClick() {
|
|
737
|
-
this.
|
|
753
|
+
if (!this.readonly) {
|
|
754
|
+
this.initCursor();
|
|
755
|
+
}
|
|
738
756
|
},
|
|
739
757
|
isNumeralChar(char) {
|
|
740
758
|
if (char.length === 1 && (this._numeral.test(char) || this._decimal.test(char) || this._group.test(char) || this._minusSign.test(char))) {
|