VAutocomplete-14RBtvAN.js 8.1 KB

1
  1. import{c9 as he,ds as ge,dt as ye,cJ as Ve,du as ke,dv as we,cc as be,cy as Ce,ag as I,bG as S,cd as K,aR as p,dw as xe,cL as Se,dx as Ae,dy as Fe,dz as Ie,a$ as P,bw as J,cf as Pe,cg as De,au as $,an as o,aX as D,dA as Re,bn as w,b7 as _e,b9 as q,dB as Me,dC as Te,dD as Ee,aO as W,dE as Le,dF as Oe,ck as Be,at as Ne,dG as Ke,ch as Ue,dH as ze,dI as He,dJ as X}from"./index-D68iA7pN.js";function Ge(e,h,s){if(h==null)return e;if(Array.isArray(h))throw new Error("Multiple matches is not implemented");return typeof h=="number"&&~h?o(D,null,[o("span",{class:"v-autocomplete__unmask"},[e.substr(0,h)]),o("span",{class:"v-autocomplete__mask"},[e.substr(h,s)]),o("span",{class:"v-autocomplete__unmask"},[e.substr(h+s)])]):e}const Je=he({autoSelectFirst:{type:[Boolean,String]},clearOnSelect:Boolean,search:String,...ge({filterKeys:["title"]}),...ye(),...Ve(ke({modelValue:null,role:"combobox"}),["validationValue","dirty","appendInnerIcon"]),...we({transition:!1})},"VAutocomplete"),qe=be()({name:"VAutocomplete",props:Je(),emits:{"update:focused":e=>!0,"update:search":e=>!0,"update:modelValue":e=>!0,"update:menu":e=>!0},setup(e,h){let{slots:s}=h;const{t:R}=Ce(),f=I(),g=S(!1),V=S(!0),_=S(!1),U=I(),M=I(),T=K(e,"menu"),r=p({get:()=>T.value,set:l=>{T.value&&!l&&U.value?.ΨopenChildren.size||(T.value=l)}}),i=S(-1),j=p(()=>f.value?.color),z=p(()=>r.value?e.closeText:e.openText),{items:H,transformIn:Q,transformOut:Y}=xe(e),{textColorClasses:Z,textColorStyles:ee}=Se(j),v=K(e,"search",""),a=K(e,"modelValue",[],l=>Q(l===null?[null]:ze(l)),l=>{const u=Y(l);return e.multiple?u:u[0]??null}),le=p(()=>typeof e.counterValue=="function"?e.counterValue(a.value):typeof e.counterValue=="number"?e.counterValue:a.value.length),G=Ae(),{filteredItems:E,getMatches:te}=Fe(e,H,()=>V.value?"":v.value),y=p(()=>e.hideSelected?E.value.filter(l=>!a.value.some(u=>u.value===l.value)):E.value),A=p(()=>!!(e.chips||s.chip)),b=p(()=>A.value||!!s.selection),ae=p(()=>a.value.map(l=>l.props.value)),L=p(()=>(e.autoSelectFirst===!0||e.autoSelectFirst==="exact"&&v.value===y.value[0]?.title)&&y.value.length>0&&!V.value&&!_.value),O=p(()=>e.hideNoData&&!y.value.length||e.readonly||G?.isReadonly.value),B=I(),ne=Ie(B,f);function ue(l){e.openOnClear&&(r.value=!0),v.value=""}function oe(){O.value||(r.value=!0)}function se(l){O.value||(g.value&&(l.preventDefault(),l.stopPropagation()),r.value=!r.value)}function ie(l){He(l)&&f.value?.focus()}function ce(l){if(e.readonly||G?.isReadonly.value)return;const u=f.value.selectionStart,c=a.value.length;if((i.value>-1||["Enter","ArrowDown","ArrowUp"].includes(l.key))&&l.preventDefault(),["Enter","ArrowDown"].includes(l.key)&&(r.value=!0),["Escape"].includes(l.key)&&(r.value=!1),L.value&&["Enter","Tab"].includes(l.key)&&!a.value.some(t=>{let{value:n}=t;return n===y.value[0].value})&&k(y.value[0]),l.key==="ArrowDown"&&L.value&&B.value?.focus("next"),["Backspace","Delete"].includes(l.key)){if(!e.multiple&&b.value&&a.value.length>0&&!v.value)return k(a.value[0],!1);if(~i.value){const t=i.value;k(a.value[i.value],!1),i.value=t>=c-1?c-2:t}else l.key==="Backspace"&&!v.value&&(i.value=c-1)}if(e.multiple){if(l.key==="ArrowLeft"){if(i.value<0&&u>0)return;const t=i.value>-1?i.value-1:c-1;a.value[t]?i.value=t:(i.value=-1,f.value.setSelectionRange(v.value?.length,v.value?.length))}if(l.key==="ArrowRight"){if(i.value<0)return;const t=i.value+1;a.value[t]?i.value=t:(i.value=-1,f.value.setSelectionRange(0,0))}}}function re(l){if(X(f.value,":autofill")||X(f.value,":-webkit-autofill")){const u=H.value.find(c=>c.title===l.target.value);u&&k(u)}}function ve(){e.eager&&M.value?.calculateVisibleItems()}function de(){g.value&&(V.value=!0,f.value?.focus())}function fe(l){g.value=!0,setTimeout(()=>{_.value=!0})}function me(l){_.value=!1}function pe(l){(l==null||l===""&&!e.multiple&&!b.value)&&(a.value=[])}const N=S(!1);function k(l){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;if(!(!l||l.props.disabled))if(e.multiple){const c=a.value.findIndex(n=>e.valueComparator(n.value,l.value)),t=u??!~c;if(~c){const n=t?[...a.value,l]:[...a.value];n.splice(c,1),a.value=n}else t&&(a.value=[...a.value,l]);e.clearOnSelect&&(v.value="")}else{const c=u!==!1;a.value=c?[l]:[],v.value=c&&!b.value?l.title:"",J(()=>{r.value=!1,V.value=!0})}}return P(g,(l,u)=>{l!==u&&(l?(N.value=!0,v.value=e.multiple||b.value?"":String(a.value.at(-1)?.props.title??""),V.value=!0,J(()=>N.value=!1)):(!e.multiple&&v.value==null&&(a.value=[]),r.value=!1,a.value.some(c=>{let{title:t}=c;return t===v.value})||(v.value=""),i.value=-1))}),P(v,l=>{!g.value||N.value||(l&&(r.value=!0),V.value=!l)}),P(r,()=>{if(!e.hideSelected&&r.value&&a.value.length){const l=y.value.findIndex(u=>a.value.some(c=>u.value===c.value));Pe&&window.requestAnimationFrame(()=>{l>=0&&M.value?.scrollToIndex(l)})}}),P(()=>e.items,(l,u)=>{r.value||g.value&&!u.length&&l.length&&(r.value=!0)}),De(()=>{const l=!!(!e.hideNoData||y.value.length||s["prepend-item"]||s["append-item"]||s["no-data"]),u=a.value.length>0,c=$.filterProps(e);return o($,w({ref:f},c,{modelValue:v.value,"onUpdate:modelValue":[t=>v.value=t,pe],focused:g.value,"onUpdate:focused":t=>g.value=t,validationValue:a.externalValue,counterValue:le.value,dirty:u,onChange:re,class:["v-autocomplete",`v-autocomplete--${e.multiple?"multiple":"single"}`,{"v-autocomplete--active-menu":r.value,"v-autocomplete--chips":!!e.chips,"v-autocomplete--selection-slot":!!b.value,"v-autocomplete--selecting-index":i.value>-1},e.class],style:e.style,readonly:e.readonly,placeholder:u?void 0:e.placeholder,"onClick:clear":ue,"onMousedown:control":oe,onKeydown:ce}),{...s,default:()=>o(D,null,[o(Re,w({ref:U,modelValue:r.value,"onUpdate:modelValue":t=>r.value=t,activator:"parent",contentClass:"v-autocomplete__content",disabled:O.value,eager:e.eager,maxHeight:310,openOnClick:!1,closeOnContentClick:!1,transition:e.transition,onAfterEnter:ve,onAfterLeave:de},e.menuProps),{default:()=>[l&&o(_e,w({ref:B,selected:ae.value,selectStrategy:e.multiple?"independent":"single-independent",onMousedown:t=>t.preventDefault(),onKeydown:ie,onFocusin:fe,onFocusout:me,tabindex:"-1","aria-live":"polite",color:e.itemColor??e.color},ne,e.listProps),{default:()=>[s["prepend-item"]?.(),!y.value.length&&!e.hideNoData&&(s["no-data"]?.()??o(q,{title:R(e.noDataText)},null)),o(Me,{ref:M,renderless:!0,items:y.value},{default:t=>{let{item:n,index:m,itemRef:F}=t;const C=w(n.props,{ref:F,key:m,active:L.value&&m===0?!0:void 0,onClick:()=>k(n,null)});return s.item?.({item:n,index:m,props:C})??o(q,w(C,{role:"option"}),{prepend:x=>{let{isSelected:d}=x;return o(D,null,[e.multiple&&!e.hideSelected?o(Te,{key:n.value,modelValue:d,ripple:!1,tabindex:"-1"},null):void 0,n.props.prependAvatar&&o(Ee,{image:n.props.prependAvatar},null),n.props.prependIcon&&o(W,{icon:n.props.prependIcon},null)])},title:()=>V.value?n.title:Ge(n.title,te(n)?.title,v.value?.length??0)})}}),s["append-item"]?.()]})]}),a.value.map((t,n)=>{function m(d){d.stopPropagation(),d.preventDefault(),k(t,!1)}const F={"onClick:close":m,onKeydown(d){d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),d.stopPropagation(),m(d))},onMousedown(d){d.preventDefault(),d.stopPropagation()},modelValue:!0,"onUpdate:modelValue":void 0},C=A.value?!!s.chip:!!s.selection,x=C?Le(A.value?s.chip({item:t,index:n,props:F}):s.selection({item:t,index:n})):void 0;if(!(C&&!x))return o("div",{key:t.value,class:["v-autocomplete__selection",n===i.value&&["v-autocomplete__selection--selected",Z.value]],style:n===i.value?ee.value:{}},[A.value?s.chip?o(Be,{key:"chip-defaults",defaults:{VChip:{closable:e.closableChips,size:"small",text:t.title}}},{default:()=>[x]}):o(Oe,w({key:"chip",closable:e.closableChips,size:"small",text:t.title,disabled:t.props.disabled},F),null):x??o("span",{class:"v-autocomplete__selection-text"},[t.title,e.multiple&&n<a.value.length-1&&o("span",{class:"v-autocomplete__selection-comma"},[Ne(",")])])])})]),"append-inner":function(){for(var t=arguments.length,n=new Array(t),m=0;m<t;m++)n[m]=arguments[m];return o(D,null,[s["append-inner"]?.(...n),e.menuIcon?o(W,{class:"v-autocomplete__menu-icon",icon:e.menuIcon,onMousedown:se,onClick:Ke,"aria-label":R(z.value),title:R(z.value),tabindex:"-1"},null):void 0])}})}),Ue({isFocused:g,isPristine:V,menu:r,search:v,filteredItems:E,select:k},f)}});export{qe as V};