1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2025-09-05 01:19:23 +00:00
Classworks/assets/VTextarea-DS5A2eAs.js

2 lines
4.4 KiB
JavaScript

import{g as ae,p as ne,cg as E,R as le,J as y,U as v,W as oe,a1 as ue,a3 as ie,Y as m,bg as re,c as se,aM as ce,d as I,i as r,F as R,E as S,am as G,ch as de,e as fe,aO as ve,a4 as N,K as me,bk as xe,aP as ge}from"./index-BPtvo4Tw.js";import{u as he,a as U,b as D,c as we,j as Ve,d as ye,m as Ce}from"./VTextField-BHDnEf7m.js";const Fe=ne({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,...Ce(),...ye()},"VTextarea"),ke=ae()({name:"VTextarea",directives:{vIntersect:E},inheritAttrs:!1,props:Fe(),emits:{"click:control":e=>!0,"mousedown:control":e=>!0,"update:focused":e=>!0,"update:modelValue":e=>!0},setup(e,O){let{attrs:C,emit:M,slots:l}=O;const a=le(e,"modelValue"),{isFocused:f,focus:j,blur:$}=he(e),{onIntersect:J}=Ve(e),K=y(()=>typeof e.counterValue=="function"?e.counterValue(a.value):(a.value||"").toString().length),W=y(()=>{if(C.maxlength)return C.maxlength;if(!(!e.counter||typeof e.counter!="number"&&typeof e.counter!="string"))return e.counter}),B=v(),x=v(),z=oe(""),g=v(),Y=y(()=>e.persistentPlaceholder||f.value||e.active);function F(){var t;g.value!==document.activeElement&&((t=g.value)==null||t.focus()),f.value||j()}function q(t){F(),M("click:control",t)}function L(t){M("mousedown:control",t)}function Q(t){t.stopPropagation(),F(),N(()=>{a.value="",ge(e["onClick:clear"],t)})}function X(t){var u;const n=t.target;if(a.value=n.value,(u=e.modelModifiers)!=null&&u.trim){const d=[n.selectionStart,n.selectionEnd];N(()=>{n.selectionStart=d[0],n.selectionEnd=d[1]})}}const s=v(),h=v(Number(e.rows)),P=y(()=>["plain","underlined"].includes(e.variant));ue(()=>{e.autoGrow||(h.value=Number(e.rows))});function c(){e.autoGrow&&N(()=>{if(!s.value||!x.value)return;const t=getComputedStyle(s.value),n=getComputedStyle(x.value.$el),u=parseFloat(t.getPropertyValue("--v-field-padding-top"))+parseFloat(t.getPropertyValue("--v-input-padding-top"))+parseFloat(t.getPropertyValue("--v-field-padding-bottom")),d=s.value.scrollHeight,w=parseFloat(t.lineHeight),b=Math.max(parseFloat(e.rows)*w+u,parseFloat(n.getPropertyValue("--v-input-control-height"))),k=parseFloat(e.maxRows)*w+u||1/0,i=xe(d??0,b,k);h.value=Math.floor((i-u)/w),z.value=me(i)})}ie(c),m(a,c),m(()=>e.rows,c),m(()=>e.maxRows,c),m(()=>e.density,c);let o;return m(s,t=>{t?(o=new ResizeObserver(c),o.observe(s.value)):o==null||o.disconnect()}),re(()=>{o==null||o.disconnect()}),se(()=>{const t=!!(l.counter||e.counter||e.counterValue),n=!!(t||l.details),[u,d]=ce(C),{modelValue:w,...b}=U.filterProps(e),k=D.filterProps(e);return I(U,S({ref:B,modelValue:a.value,"onUpdate:modelValue":i=>a.value=i,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":P.value},e.class],style:e.style},u,b,{centerAffix:h.value===1&&!P.value,focused:f.value}),{...l,default:i=>{let{id:V,isDisabled:A,isDirty:H,isReadonly:Z,isValid:p}=i;return I(D,S({ref:x,style:{"--v-textarea-control-height":z.value},onClick:q,onMousedown:L,"onClick:clear":Q,"onClick:prependInner":e["onClick:prependInner"],"onClick:appendInner":e["onClick:appendInner"]},k,{id:V.value,active:Y.value||H.value,centerAffix:h.value===1&&!P.value,dirty:H.value||e.dirty,disabled:A.value,focused:f.value,error:p.value===!1}),{...l,default:ee=>{let{props:{class:T,..._}}=ee;return r(R,null,[e.prefix&&r("span",{class:"v-text-field__prefix"},[e.prefix]),G(r("textarea",S({ref:g,class:T,value:a.value,onInput:X,autofocus:e.autofocus,readonly:Z.value,disabled:A.value,placeholder:e.placeholder,rows:e.rows,name:e.name,onFocus:F,onBlur:$},_,d),null),[[E,{handler:J},null,{once:!0}]]),e.autoGrow&&G(r("textarea",{class:fe([T,"v-textarea__sizer"]),id:`${_.id}-sizer`,"onUpdate:modelValue":te=>a.value=te,ref:s,readonly:!0,"aria-hidden":"true"},null),[[de,a.value]]),e.suffix&&r("span",{class:"v-text-field__suffix"},[e.suffix])])}})},details:n?i=>{var V;return r(R,null,[(V=l.details)==null?void 0:V.call(l,i),t&&r(R,null,[r("span",null,null),I(we,{active:e.persistentCounter||f.value,value:K.value,max:W.value,disabled:e.disabled},l.counter)])])}:void 0})}),ve({},B,x,g)}});export{ke as V};