1 line
3.4 KiB
JavaScript
1 line
3.4 KiB
JavaScript
import{Q as B}from"./QChip-f43cc21c.js";import{N as K,aO as U,aW as T,aP as W,Q as X,aR as Y,a as x,aX as G,bV as H,c as i,aY as V,U as s,bf as J,aQ as M,a$ as Z}from"./index-3a2b6cd5.js";import{u as ee,a as te,b as le}from"./use-file-a69aa9db.js";import{h as ae}from"./format-312d1398.js";const oe=K({name:"QFile",inheritAttrs:!1,props:{...U,...T,...ee,modelValue:[File,FileList,Array],append:Boolean,useChips:Boolean,displayValue:[String,Number],tabindex:{type:[String,Number],default:0},counterLabel:Function,inputClass:[Array,String,Object],inputStyle:[Array,String,Object]},emits:[...W,...te],setup(e,{slots:r,emit:S,attrs:p}){const{proxy:v}=X(),u=Y(),o=x(null),g=x(!1),A=G(e),{pickFiles:P,onDragover:j,onDragleave:I,processFiles:Q,getDndNode:N}=le({editable:u.editable,dnd:g,getFileInput:h,addFilesToQueue:C}),O=H(e),l=i(()=>Object(e.modelValue)===e.modelValue?"length"in e.modelValue?Array.from(e.modelValue):[e.modelValue]:[]),b=i(()=>V(l.value)),q=i(()=>l.value.map(t=>t.name).join(", ")),F=i(()=>ae(l.value.reduce((t,a)=>t+a.size,0))),_=i(()=>({totalSize:F.value,filesNumber:l.value.length,maxFiles:e.maxFiles})),k=i(()=>({tabindex:-1,type:"file",title:"",accept:e.accept,capture:e.capture,name:A.value,...p,id:u.targetUid.value,disabled:u.editable.value!==!0})),D=i(()=>"q-file q-field--auto-height"+(g.value===!0?" q-file--dnd":"")),y=i(()=>e.multiple===!0&&e.append===!0);function d(t){const a=l.value.slice();a.splice(t,1),f(a)}function L(t){const a=l.value.findIndex(t);a>-1&&d(a)}function f(t){S("update:modelValue",e.multiple===!0?t:t[0])}function z(t){t.keyCode===13&&Z(t)}function E(t){(t.keyCode===13||t.keyCode===32)&&P(t)}function h(){return o.value}function C(t,a){const n=Q(t,a,l.value,y.value),m=h();m!=null&&(m.value=""),n!==void 0&&((e.multiple===!0?e.modelValue&&n.every(w=>l.value.includes(w)):e.modelValue===n[0])||f(y.value===!0?l.value.concat(n):n))}function c(){return[s("input",{class:[e.inputClass,"q-file__filler"],style:e.inputStyle})]}function R(){if(r.file!==void 0)return l.value.length===0?c():l.value.map((a,n)=>r.file({index:n,file:a,ref:this}));if(r.selected!==void 0)return l.value.length===0?c():r.selected({files:l.value,ref:this});if(e.useChips===!0)return l.value.length===0?c():l.value.map((a,n)=>s(B,{key:"file-"+n,removable:u.editable.value,dense:!0,textColor:e.color,tabindex:e.tabindex,onRemove:()=>{d(n)}},()=>s("span",{class:"ellipsis",textContent:a.name})));const t=e.displayValue!==void 0?e.displayValue:q.value;return t.length>0?[s("div",{class:e.inputClass,style:e.inputStyle,textContent:t})]:c()}function $(){const t={ref:o,...k.value,...O.value,class:"q-field__input fit absolute-full cursor-pointer",onChange:C};return e.multiple===!0&&(t.multiple=!0),s("input",t)}return Object.assign(u,{fieldClass:D,emitValue:f,hasValue:b,inputRef:o,innerValue:l,floatingLabel:i(()=>b.value===!0||V(e.displayValue)),computedCounter:i(()=>{if(e.counterLabel!==void 0)return e.counterLabel(_.value);const t=e.maxFiles;return`${l.value.length}${t!==void 0?" / "+t:""} (${F.value})`}),getControlChild:()=>N("file"),getControl:()=>{const t={ref:u.targetRef,class:"q-field__native row items-center cursor-pointer",tabindex:e.tabindex};return u.editable.value===!0&&Object.assign(t,{onDragover:j,onDragleave:I,onKeydown:z,onKeyup:E}),s("div",t,[$()].concat(R()))}}),Object.assign(v,{removeAtIndex:d,removeFile:L,getNativeElement:()=>o.value}),J(v,"nativeEl",()=>o.value),M(u)}});export{oe as Q};
|