2 lines
4.5 KiB
JavaScript
2 lines
4.5 KiB
JavaScript
import{p as Z,ae as ee,c3 as te,aj as ae,c as y,r as v,s as ne,am as le,o as oe,w as m,l as ue,ah as ie,a_ as re,G as l,I as R,a1 as S,P as z,c4 as se,cl as ce,a$ as de,A as b,b0 as fe,b as ve,ai as me}from"./index-39ff7cb2.js";/* empty css */import{m as xe,f as ge,V as he,a as we}from"./VField-8880cc37.js";import{m as Ve,u as ye,V as G}from"./VInput-53b0dbfc.js";const Fe=Z({autoGrow:Boolean,autofocus:Boolean,counter:[Boolean,Number,String],counterValue:Function,prefix:String,placeholder:String,persistentPlaceholder:Boolean,persistentCounter:Boolean,noResize:Boolean,rows:{type:[Number,String],default:5,validator:e=>!isNaN(parseFloat(e))},maxRows:{type:[Number,String],validator:e=>!isNaN(parseFloat(e))},suffix:String,modelModifiers:Object,...Ve(),...xe()},"VTextarea"),Re=ee()({name:"VTextarea",directives:{Intersect:te},inheritAttrs:!1,props:Fe(),emits:{"click:control":e=>!0,"mousedown:control":e=>!0,"update:focused":e=>!0,"update:modelValue":e=>!0},setup(e,D){let{attrs:F,emit:M,slots:i}=D;const o=ae(e,"modelValue"),{isFocused:f,focus:E,blur:U}=ye(e),$=y(()=>typeof e.counterValue=="function"?e.counterValue(o.value):(o.value||"").toString().length),O=y(()=>{if(F.maxlength)return F.maxlength;if(!(!e.counter||typeof e.counter!="number"&&typeof e.counter!="string"))return e.counter});function j(t,n){var a,u;!e.autofocus||!t||(u=(a=n[0].target)==null?void 0:a.focus)==null||u.call(a)}const A=v(),x=v(),B=ne(""),g=v(),p=y(()=>e.persistentPlaceholder||f.value||e.active);function P(){var t;g.value!==document.activeElement&&((t=g.value)==null||t.focus()),f.value||E()}function q(t){P(),M("click:control",t)}function J(t){M("mousedown:control",t)}function K(t){t.stopPropagation(),P(),b(()=>{o.value="",fe(e["onClick:clear"],t)})}function L(t){var a;const n=t.target;if(o.value=n.value,(a=e.modelModifiers)!=null&&a.trim){const u=[n.selectionStart,n.selectionEnd];b(()=>{n.selectionStart=u[0],n.selectionEnd=u[1]})}}const c=v(),h=v(+e.rows),C=y(()=>["plain","underlined"].includes(e.variant));le(()=>{e.autoGrow||(h.value=+e.rows)});function d(){e.autoGrow&&b(()=>{if(!c.value||!x.value)return;const t=getComputedStyle(c.value),n=getComputedStyle(x.value.$el),a=parseFloat(t.getPropertyValue("--v-field-padding-top"))+parseFloat(t.getPropertyValue("--v-input-padding-top"))+parseFloat(t.getPropertyValue("--v-field-padding-bottom")),u=c.value.scrollHeight,w=parseFloat(t.lineHeight),I=Math.max(parseFloat(e.rows)*w+a,parseFloat(n.getPropertyValue("--v-input-control-height"))),k=parseFloat(e.maxRows)*w+a||1/0,s=me(u??0,I,k);h.value=Math.floor((s-a)/w),B.value=ve(s)})}oe(d),m(o,d),m(()=>e.rows,d),m(()=>e.maxRows,d),m(()=>e.density,d);let r;return m(c,t=>{t?(r=new ResizeObserver(d),r.observe(c.value)):r==null||r.disconnect()}),ue(()=>{r==null||r.disconnect()}),ie(()=>{const t=!!(i.counter||e.counter||e.counterValue),n=!!(t||i.details),[a,u]=re(F),{modelValue:w,...I}=G.filterProps(e),k=ge(e);return l(G,R({ref:A,modelValue:o.value,"onUpdate:modelValue":s=>o.value=s,class:["v-textarea v-text-field",{"v-textarea--prefixed":e.prefix,"v-textarea--suffixed":e.suffix,"v-text-field--prefixed":e.prefix,"v-text-field--suffixed":e.suffix,"v-textarea--auto-grow":e.autoGrow,"v-textarea--no-resize":e.noResize||e.autoGrow,"v-input--plain-underlined":C.value},e.class],style:e.style},a,I,{centerAffix:h.value===1&&!C.value,focused:f.value}),{...i,default:s=>{let{id:V,isDisabled:H,isDirty:N,isReadonly:Q,isValid:W}=s;return l(he,R({ref:x,style:{"--v-textarea-control-height":B.value},onClick:q,onMousedown:J,"onClick:clear":K,"onClick:prependInner":e["onClick:prependInner"],"onClick:appendInner":e["onClick:appendInner"]},k,{id:V.value,active:p.value||N.value,centerAffix:h.value===1&&!C.value,dirty:N.value||e.dirty,disabled:H.value,focused:f.value,error:W.value===!1}),{...i,default:X=>{let{props:{class:T,..._}}=X;return l(S,null,[e.prefix&&l("span",{class:"v-text-field__prefix"},[e.prefix]),z(l("textarea",R({ref:g,class:T,value:o.value,onInput:L,autofocus:e.autofocus,readonly:Q.value,disabled:H.value,placeholder:e.placeholder,rows:e.rows,name:e.name,onFocus:P,onBlur:U},_,u),null),[[se("intersect"),{handler:j},null,{once:!0}]]),e.autoGrow&&z(l("textarea",{class:[T,"v-textarea__sizer"],id:`${_.id}-sizer`,"onUpdate:modelValue":Y=>o.value=Y,ref:c,readonly:!0,"aria-hidden":"true"},null),[[ce,o.value]]),e.suffix&&l("span",{class:"v-text-field__suffix"},[e.suffix])])}})},details:n?s=>{var V;return l(S,null,[(V=i.details)==null?void 0:V.call(i,s),t&&l(S,null,[l("span",null,null),l(we,{active:e.persistentCounter||f.value,value:$.value,max:O.value},i.counter)])])}:void 0})}),de({},A,x,g)}});export{Re as V};
|