index-CVTLI1NE.js 6.7 KB

12
  1. import{_ as be,I as Se,f as ze,h as Ie,a6 as Ve,A as $e,ak as Be,$ as b,q as Le,z as Re,al as ee,v as Oe,w as Pe}from"./index-DnTunbJs.js";import{R as xe}from"./resize-observer-DkVUjRMr.js";import{c as Ne,p as Te}from"./index-MBd3sYCs.js";import{d as Ae,l as Ee,r as f,c as v,w as E,u as He,m as H,o as S,a as z,n as k,b as ke,G as F,q as M,B as j,y as ae,e as Fe,A as te,k as Me,I as le}from"./vue-vendor-B2yM2jt_.js";const je=["border-width","box-sizing","font-family","font-weight","font-size","font-variant","letter-spacing","line-height","padding-top","padding-bottom","padding-left","padding-right","text-indent","text-rendering","text-transform","white-space","overflow-wrap","width"],De=e=>{const t={};return je.forEach(u=>{t[u]=e.getPropertyValue(u)}),t};var We=Object.defineProperty,ne=Object.getOwnPropertySymbols,qe=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable,oe=(e,t,u)=>t in e?We(e,t,{enumerable:!0,configurable:!0,writable:!0,value:u}):e[t]=u,re=(e,t)=>{for(var u in t||(t={}))qe.call(t,u)&&oe(e,u,t[u]);if(ne)for(var u of ne(t))Ge.call(t,u)&&oe(e,u,t[u]);return e};const Ue=Ae({name:"Textarea",components:{ResizeObserver:xe,IconHover:Se,IconClose:ze},inheritAttrs:!1,props:{modelValue:String,defaultValue:{type:String,default:""},placeholder:String,disabled:{type:Boolean,default:!1},error:{type:Boolean,default:!1},maxLength:{type:[Number,Object],default:0},showWordLimit:{type:Boolean,default:!1},allowClear:{type:Boolean,default:!1},autoSize:{type:[Boolean,Object],default:!1},wordLength:{type:Function},wordSlice:{type:Function},textareaAttrs:{type:Object}},emits:{"update:modelValue":e=>!0,input:(e,t)=>!0,change:(e,t)=>!0,clear:e=>!0,focus:e=>!0,blur:e=>!0},setup(e,{emit:t,attrs:u}){const{disabled:W,error:q,modelValue:g}=Ee(e),m=Ie("textarea"),{mergedDisabled:c,mergedError:I,eventHandlers:n}=Ve({disabled:W,error:q}),s=f(),G=f(),h=f(),U=f(),V=f(e.defaultValue),d=v(()=>{var a;return(a=g.value)!=null?a:V.value}),[ue,se]=Ne(s);E(g,a=>{($e(a)||Be(a))&&(V.value="")});const w=v(()=>b(e.maxLength)&&!!e.maxLength.errorOnly),i=v(()=>b(e.maxLength)?e.maxLength.length:e.maxLength),C=a=>{var l;return Le(e.wordLength)?e.wordLength(a):(l=a.length)!=null?l:0},_=v(()=>C(d.value)),J=v(()=>I.value||!!(i.value&&w.value&&_.value>i.value)),p=f(!1),$=f(!1),ie=v(()=>e.allowClear&&!c.value&&d.value),B=f(!1),K=f(""),L=()=>{ue(),le(()=>{s.value&&d.value!==s.value.value&&(s.value.value=d.value,se())})},y=(a,l=!0)=>{var o,r;i.value&&!w.value&&C(a)>i.value&&(a=(r=(o=e.wordSlice)==null?void 0:o.call(e,a,i.value))!=null?r:a.slice(0,i.value)),V.value=a,l&&t("update:modelValue",a),L()};let R=d.value;const Q=(a,l)=>{var o,r;a!==R&&(R=a,t("change",a,l),(r=(o=n.value)==null?void 0:o.onChange)==null||r.call(o,l))},de=a=>{var l,o;$.value=!0,R=d.value,t("focus",a),(o=(l=n.value)==null?void 0:l.onFocus)==null||o.call(l,a)},fe=a=>{var l,o;$.value=!1,t("blur",a),(o=(l=n.value)==null?void 0:l.onBlur)==null||o.call(l,a),Q(d.value,a)},ve=a=>{var l,o;const{value:r}=a.target;if(a.type==="compositionend"){if(B.value=!1,K.value="",i.value&&!w.value&&d.value.length>=i.value&&C(r)>i.value){L();return}t("input",r,a),y(r),(o=(l=n.value)==null?void 0:l.onInput)==null||o.call(l,a)}else B.value=!0},me=a=>{var l,o;const{value:r}=a.target;if(B.value)K.value=r;else{if(i.value&&!w.value&&d.value.length>=i.value&&C(r)>i.value&&a.inputType==="insertText"){L();return}t("input",r,a),y(r),(o=(l=n.value)==null?void 0:l.onInput)==null||o.call(l,a)}},ce=a=>{y(""),Q("",a),t("clear",a)};E(g,a=>{a!==d.value&&y(a??"",!1)});const pe=a=>Re(u,ee),X=a=>Te(u,ee),ge=X(),he=v(()=>{const a=re(re({},ge),e.textareaAttrs);return J.value&&(a["aria-invalid"]=!0),a}),we=v(()=>[`${m}-wrapper`,{[`${m}-focus`]:$.value,[`${m}-disabled`]:c.value,[`${m}-error`]:J.value,[`${m}-scroll`]:p.value}]);let Y;const O=f(0),P=f(0),x=v(()=>!b(e.autoSize)||!e.autoSize.minRows?0:e.autoSize.minRows*O.value+P.value),N=v(()=>!b(e.autoSize)||!e.autoSize.maxRows?0:e.autoSize.maxRows*O.value+P.value),T=()=>{const a=De(Y);O.value=Number.parseInt(a["line-height"]||0,10),P.value=Number.parseInt(a["border-width"]||0,10)*2+Number.parseInt(a["padding-top"]||0,10)+Number.parseInt(a["padding-bottom"]||0,10),U.value=a,le(()=>{var l;const o=(l=h.value)==null?void 0:l.offsetHeight;let r=o??0,Z="hidden";x.value&&r<x.value&&(r=x.value),N.value&&r>N.value&&(r=N.value,Z="auto"),G.value={height:`${r}px`,resize:"none",overflow:Z}})};He(()=>{s.value&&(Y=window.getComputedStyle(s.value),e.autoSize&&T()),A()});const Ce=()=>{e.autoSize&&h.value&&T(),A()},ye=a=>{s.value&&a.target!==s.value&&(a.preventDefault(),s.value.focus())},A=()=>{s.value&&(s.value.scrollHeight>s.value.offsetHeight?p.value||(p.value=!0):p.value&&(p.value=!1))};return E(d,()=>{e.autoSize&&h.value&&T(),A()}),{prefixCls:m,wrapperCls:we,textareaRef:s,textareaStyle:G,mirrorRef:h,mirrorStyle:U,computedValue:d,showClearBtn:ie,valueLength:_,computedMaxLength:i,mergedDisabled:c,mergeTextareaAttrs:he,getWrapperAttrs:pe,getTextareaAttrs:X,handleInput:me,handleFocus:de,handleBlur:fe,handleComposition:ve,handleClear:ce,handleResize:Ce,handleMousedown:ye}},methods:{focus(){var e;(e=this.$refs.textareaRef)==null||e.focus()},blur(){var e;(e=this.$refs.textareaRef)==null||e.blur()}}}),_e=["disabled","value","placeholder"];function Je(e,t,u,W,q,g){const m=H("resize-observer"),c=H("icon-close"),I=H("icon-hover");return S(),z("div",te(e.getWrapperAttrs(e.$attrs),{class:e.wrapperCls,onMousedown:t[7]||(t[7]=(...n)=>e.handleMousedown&&e.handleMousedown(...n))}),[e.autoSize?(S(),z("div",{key:0,ref:"mirrorRef",class:k(`${e.prefixCls}-mirror`),style:ke(e.mirrorStyle)},F(`${e.computedValue}
  2. `),7)):M("v-if",!0),j(m,{onResize:e.handleResize},{default:ae(()=>[Fe("textarea",te({ref:"textareaRef"},e.mergeTextareaAttrs,{disabled:e.mergedDisabled,class:e.prefixCls,style:e.textareaStyle,value:e.computedValue,placeholder:e.placeholder,onInput:t[0]||(t[0]=(...n)=>e.handleInput&&e.handleInput(...n)),onFocus:t[1]||(t[1]=(...n)=>e.handleFocus&&e.handleFocus(...n)),onBlur:t[2]||(t[2]=(...n)=>e.handleBlur&&e.handleBlur(...n)),onCompositionstart:t[3]||(t[3]=(...n)=>e.handleComposition&&e.handleComposition(...n)),onCompositionupdate:t[4]||(t[4]=(...n)=>e.handleComposition&&e.handleComposition(...n)),onCompositionend:t[5]||(t[5]=(...n)=>e.handleComposition&&e.handleComposition(...n))}),null,16,_e)]),_:1},8,["onResize"]),Me(e.$slots,"suffix"),e.computedMaxLength&&e.showWordLimit?(S(),z("div",{key:1,class:k(`${e.prefixCls}-word-limit`)},F(e.valueLength)+"/"+F(e.computedMaxLength),3)):M("v-if",!0),e.showClearBtn?(S(),z("div",{key:2,class:k(`${e.prefixCls}-clear-btn`),onClick:t[6]||(t[6]=(...n)=>e.handleClear&&e.handleClear(...n))},[j(I,null,{default:ae(()=>[j(c)]),_:1})],2)):M("v-if",!0)],16)}var D=be(Ue,[["render",Je]]);const Ze=Object.assign(D,{install:(e,t)=>{Oe(e,t);const u=Pe(t);e.component(u+D.name,D)}});export{Ze as T};