index-DzZpZed6.js 6.7 KB

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