| 12 |
- 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-Ccm7NuMR.js";import{R as xe}from"./resize-observer-BHb_9id6.js";import{c as Ne,p as Te}from"./index-0iFXgJZm.js";import{d as Ae,l as Ee,r as v,c as f,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-B3m6NcsA.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(s=>{t[s]=e.getPropertyValue(s)}),t};var We=Object.defineProperty,oe=Object.getOwnPropertySymbols,qe=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={}))qe.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 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:s}){const{disabled:W,error:q,modelValue:g}=Ee(e),m=Ie("textarea"),{mergedDisabled:c,mergedError:I,eventHandlers:o}=Ve({disabled:W,error:q}),u=v(),G=v(),h=v(),U=v(),V=v(e.defaultValue),d=f(()=>{var a;return(a=g.value)!=null?a:V.value}),[se,ue]=Ne(u);E(g,a=>{($e(a)||Be(a))&&(V.value="")});const w=f(()=>b(e.maxLength)&&!!e.maxLength.errorOnly),i=f(()=>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},_=f(()=>C(d.value)),J=f(()=>I.value||!!(i.value&&w.value&&_.value>i.value)),p=v(!1),$=v(!1),ie=f(()=>e.allowClear&&!c.value&&d.value),B=v(!1),K=v(""),L=()=>{se(),le(()=>{u.value&&d.value!==u.value.value&&(u.value.value=d.value,ue())})},y=(a,l=!0)=>{var n,r;i.value&&!w.value&&C(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),L()};let R=d.value;const Q=(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;$.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;$.value=!1,t("blur",a),(n=(l=o.value)==null?void 0:l.onBlur)==null||n.call(l,a),Q(d.value,a)},fe=a=>{var l,n;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),(n=(l=o.value)==null?void 0:l.onInput)==null||n.call(l,a)}else B.value=!0},me=a=>{var l,n;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),(n=(l=o.value)==null?void 0:l.onInput)==null||n.call(l,a)}},ce=a=>{y(""),Q("",a),t("clear",a)};E(g,a=>{a!==d.value&&y(a??"",!1)});const pe=a=>Re(s,ee),X=a=>Te(s,ee),ge=X(),he=f(()=>{const a=re(re({},ge),e.textareaAttrs);return J.value&&(a["aria-invalid"]=!0),a}),we=f(()=>[`${m}-wrapper`,{[`${m}-focus`]:$.value,[`${m}-disabled`]:c.value,[`${m}-error`]:J.value,[`${m}-scroll`]:p.value}]);let Y;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(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 n=(l=h.value)==null?void 0:l.offsetHeight;let r=n??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(()=>{u.value&&(Y=window.getComputedStyle(u.value),e.autoSize&&T()),A()});const Ce=()=>{e.autoSize&&h.value&&T(),A()},ye=a=>{u.value&&a.target!==u.value&&(a.preventDefault(),u.value.focus())},A=()=>{u.value&&(u.value.scrollHeight>u.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:u,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:ve,handleComposition:fe,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,s,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]=(...o)=>e.handleMousedown&&e.handleMousedown(...o))}),[e.autoSize?(S(),z("div",{key:0,ref:"mirrorRef",class:k(`${e.prefixCls}-mirror`),style:ke(e.mirrorStyle)},F(`${e.computedValue}
- `),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]=(...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,_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]=(...o)=>e.handleClear&&e.handleClear(...o))},[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 s=Pe(t);e.component(s+D.name,D)}});export{Ze as T};
|