buefy
Version:
Lightweight UI components for Vue.js (v3) based on Bulma
3 lines (2 loc) • 6.12 kB
JavaScript
/*! Buefy v3.0.0 | MIT License | github.com/buefy/buefy */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Upload={},e.Vue)}(this,(function(e,t){"use strict";let i,s="mdi",n=!0,a=!0,l=!0;var r=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,d=Object.prototype.propertyIsEnumerable,u=t.defineComponent({inheritAttrs:!1,props:{compatFallthrough:{type:Boolean,default:()=>n}},computed:{rootAttrs(){return this.compatFallthrough?{class:this.$attrs.class,style:this.$attrs.style,id:this.$attrs.id}:{}},fallthroughAttrs(){if(this.compatFallthrough){const e=this.$attrs,{style:t,class:i,id:s}=e;return((e,t)=>{var i={};for(var s in e)o.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&r)for(var s of r(e))t.indexOf(s)<0&&d.call(e,s)&&(i[s]=e[s]);return i})(e,["style","class","id"])}return this.$attrs}}}),p=(e,t)=>{const i=e.__vccOpts||e;for(const[e,s]of t)i[e]=s;return i};const h=t.defineComponent({props:{size:String,expanded:Boolean,loading:Boolean,rounded:Boolean,icon:String,iconPack:String,maxlength:[Number,String],useHtml5Validation:{type:Boolean,default:()=>a},validationMessage:String,locale:{type:[String,Array],default:()=>i},statusIcon:{type:Boolean,default:()=>l}},emits:{blur:e=>!0,focus:e=>!0},data(){return{isValid:!0,isFocused:!1,newIconPack:this.iconPack||s,_elementRef:""}},computed:{parentField(){let e=this.$parent;for(let t=0;t<3;t++)e&&!e.$data._isField&&(e=e.$parent);return e},statusType(){const{newType:e}=this.parentField||{};if(e){if("string"==typeof e)return e;for(const t in e)if(e[t])return t}},statusMessage(){if(this.parentField)return this.parentField.newMessage||this.parentField.$slots.message},iconSize(){switch(this.size){case"is-small":return this.size;case"is-medium":return;case"is-large":return"mdi"===this.newIconPack?"is-medium":""}}},methods:{focus(){const e=this.getElement();void 0!==e&&this.$nextTick((()=>{e&&e.focus()}))},onBlur(e){this.isFocused=!1,this.$emit("blur",e),this.checkHtml5Validity()},onFocus(e){this.isFocused=!0,this.$emit("focus",e)},getElement(){let e=this.$refs[this.$data._elementRef];for(;null!=e&&"object"==typeof e&&"$refs"in e;){const t=e;e=t.$refs[t.$data._elementRef]}return e},setInvalid(){const e=this.validationMessage||this.getElement().validationMessage;this.setValidity("is-danger",e)},setValidity(e,t){this.$nextTick((()=>{this.parentField&&(this.parentField.type||(this.parentField.newType=e),this.parentField.message||(this.parentField.newMessage=t))}))},checkHtml5Validity(){if(!this.useHtml5Validation)return!1;const e=this.getElement();return null!=e&&(e.checkValidity()?(this.setValidity(null,null),this.isValid=!0):(this.setInvalid(),this.isValid=!1),this.isValid)}}}),c="undefined"==typeof window?Object:window.File,f=t.defineComponent({name:"BUpload",mixins:[u,h],props:{modelValue:{type:[Object,Function,c,Array]},multiple:Boolean,disabled:Boolean,accept:String,dragDrop:Boolean,type:{type:String,default:"is-primary"},native:{type:Boolean,default:!1},expanded:{type:Boolean,default:!1},rounded:{type:Boolean,default:!1}},emits:{invalid:()=>!0,"update:modelValue":e=>!0},data(){return{newValue:this.modelValue,dragDropFocus:!1,_elementRef:"input"}},computed:{disabledOrUndefined(){return this.disabled||void 0}},watch:{modelValue(e){this.newValue=e,(!e||Array.isArray(e)&&0===e.length)&&(this.$refs.input.value=""),!this.isValid&&!this.dragDrop&&this.checkHtml5Validity()}},methods:{onFileChange(e){var t,i;if(this.disabled||this.loading)return;this.dragDrop&&this.updateDragDropFocus(!1);const s=null!=(i=null!=(t=e.target.files)?t:e.dataTransfer.files)?i:[];if(0===s.length){if(!this.newValue)return;this.native&&(this.newValue=null)}else if(this.multiple){let e=!1;!this.native&&this.newValue||(this.newValue=[],e=!0);for(let t=0;t<s.length;t++){const i=s[t];this.checkType(i)&&Array.isArray(this.newValue)&&(this.newValue.push(i),e=!0)}if(!e)return}else{if(this.dragDrop&&1!==s.length)return;{const e=s[0];if(this.checkType(e))this.newValue=e;else{if(!this.newValue)return this.clearInput(),void this.checkHtml5Validity();this.newValue=null,this.clearInput()}}}this.$emit("update:modelValue",this.newValue),!this.dragDrop&&this.checkHtml5Validity()},clearInput(){this.$refs.input.value=""},updateDragDropFocus(e){this.disabled||this.loading||(this.dragDropFocus=e)},checkType(e){if(!this.accept)return!0;const t=this.accept.split(",");if(0===t.length)return!0;let i=!1;for(let s=0;s<t.length&&!i;s++){const n=t[s].trim();if(n)if("."===n.substring(0,1)){e.name.toLowerCase().slice(-n.length)===n.toLowerCase()&&(i=!0)}else e.type.match(n)&&(i=!0)}return i||this.$emit("invalid"),i}}}),g=["multiple","accept","disabled"];var m=p(f,[["render",function(e,i,s,n,a,l){return t.openBlock(),t.createElementBlock("label",t.mergeProps({class:"upload control"},e.rootAttrs,{class:[{"is-expanded":e.expanded,"is-rounded":e.rounded}]}),[e.dragDrop?(t.openBlock(),t.createElementBlock("div",{key:1,class:t.normalizeClass(["upload-draggable",[e.type,{"is-loading":e.loading,"is-disabled":e.disabled,"is-hovered":e.dragDropFocus,"is-expanded":e.expanded}]]),onDragover:i[0]||(i[0]=t.withModifiers((t=>e.updateDragDropFocus(!0)),["prevent"])),onDragleave:i[1]||(i[1]=t.withModifiers((t=>e.updateDragDropFocus(!1)),["prevent"])),onDragenter:i[2]||(i[2]=t.withModifiers((t=>e.updateDragDropFocus(!0)),["prevent"])),onDrop:i[3]||(i[3]=t.withModifiers(((...t)=>e.onFileChange&&e.onFileChange(...t)),["prevent"]))},[t.renderSlot(e.$slots,"default")],34)):t.renderSlot(e.$slots,"default",{key:0}),t.createElementVNode("input",t.mergeProps({ref:"input",type:"file"},e.fallthroughAttrs,{multiple:e.multiple,accept:e.accept,disabled:e.disabledOrUndefined,onChange:i[4]||(i[4]=(...t)=>e.onFileChange&&e.onFileChange(...t))}),null,16,g)],16)}]]);const y={install(e){((e,t)=>{const i=t.name;if(null==i)throw new Error("Buefy.registerComponent: missing component name");e.component(i,t)})(e,m)}};e.BUpload=m,e.default=y,Object.defineProperty(e,"__esModule",{value:!0})}));