1 |
- import{H as se,I as ce,J as ue,K as de,M as fe,t as ge,z as P,u as C,w as me,N as he,O as be,d as ye,Q as ve,r as Ie,R as k,C as Se,S as Ce,y as b,U as xe,W as Ve,X as Ee,Y as ke,Z as we,_ as S,$ as Me,a0 as Te,c as s,a1 as w,a2 as z,a3 as Pe,a4 as D,a5 as M,E as Re,q as Le,a6 as Ae,D as Be}from"./index.332c7f08.js";import{c as _e,C as Ne}from"./index.91135ff9.js";function $(e){return Array.isArray(e)?!e.length:e===0?!1:!e}function Oe(e,r){if($(e)){if(r.required)return!1;if(r.validateEmpty===!1)return!0}return!(r.pattern&&!r.pattern.test(String(e)))}function ze(e,r){return new Promise(l=>{const c=r.validator(e,r);if(de(c)){c.then(l);return}l(c)})}function F(e,r){const{message:l}=r;return fe(l)?l(e,r):l||""}function De({target:e}){e.composing=!0}function W({target:e}){e.composing&&(e.composing=!1,e.dispatchEvent(new Event("input")))}function Fe(e,r){const l=se();e.style.height="auto";let c=e.scrollHeight;if(ue(r)){const{maxHeight:i,minHeight:u}=r;i!==void 0&&(c=Math.min(c,i)),u!==void 0&&(c=Math.max(c,u))}c&&(e.style.height=`${c}px`,ce(l))}function We(e){return e==="number"?{type:"text",inputmode:"decimal"}:e==="digit"?{type:"tel",inputmode:"numeric"}:{type:e}}function T(e){return[...e].length}function $e(e,r){return[...e].slice(0,r).join("")}const[je,d]=ge("field"),qe={id:String,name:String,leftIcon:String,rightIcon:String,autofocus:Boolean,clearable:Boolean,maxlength:P,formatter:Function,clearIcon:C("clear"),modelValue:me(""),inputAlign:String,placeholder:String,autocomplete:String,errorMessage:String,enterkeyhint:String,clearTrigger:C("focus"),formatTrigger:C("onChange"),error:{type:Boolean,default:null},disabled:{type:Boolean,default:null},readonly:{type:Boolean,default:null}},He=he({},_e,qe,{rows:P,type:C("text"),rules:Array,autosize:[Boolean,Object],labelWidth:P,labelClass:be,labelAlign:String,showWordLimit:Boolean,errorMessageAlign:String,colon:{type:Boolean,default:null}});var Ke=ye({name:je,props:He,emits:["blur","focus","clear","keypress","clickInput","endValidate","startValidate","clickLeftIcon","clickRightIcon","update:modelValue"],setup(e,{emit:r,slots:l}){const c=ve(),i=Ie({status:"unvalidated",focused:!1,validateMessage:""}),u=k(),R=k(),x=k(),{parent:f}=Se(Ce),h=()=>{var t;return String((t=e.modelValue)!=null?t:"")},g=t=>{if(w(e[t]))return e[t];if(f&&w(f.props[t]))return f.props[t]},j=b(()=>{const t=g("readonly");if(e.clearable&&!t){const n=h()!=="",a=e.clearTrigger==="always"||e.clearTrigger==="focus"&&i.focused;return n&&a}return!1}),L=b(()=>x.value&&l.input?x.value():e.modelValue),q=t=>t.reduce((n,a)=>n.then(()=>{if(i.status==="failed")return;let{value:o}=L;if(a.formatter&&(o=a.formatter(o,a)),!Oe(o,a)){i.status="failed",i.validateMessage=F(o,a);return}if(a.validator)return $(o)&&a.validateEmpty===!1?void 0:ze(o,a).then(m=>{m&&typeof m=="string"?(i.status="failed",i.validateMessage=m):m===!1&&(i.status="failed",i.validateMessage=F(o,a))})}),Promise.resolve()),y=()=>{i.status="unvalidated",i.validateMessage=""},A=()=>r("endValidate",{status:i.status,message:i.validateMessage}),B=(t=e.rules)=>new Promise(n=>{y(),t?(r("startValidate"),q(t).then(()=>{i.status==="failed"?(n({name:e.name,message:i.validateMessage}),A()):(i.status="passed",n(),A())})):n()}),V=t=>{if(f&&e.rules){const{validateTrigger:n}=f.props,a=z(n).includes(t),o=e.rules.filter(m=>m.trigger?z(m.trigger).includes(t):a);o.length&&B(o)}},H=t=>{const{maxlength:n}=e;if(w(n)&&T(t)>n){const a=h();return a&&T(a)===+n?a:$e(t,+n)}return t},v=(t,n="onChange")=>{if(t=H(t),e.type==="number"||e.type==="digit"){const a=e.type==="number";t=Pe(t,a,a)}if(e.formatter&&n===e.formatTrigger&&(t=e.formatter(t)),u.value&&u.value.value!==t){const{selectionStart:a,selectionEnd:o}=u.value;u.value.value=t,u.value.setSelectionRange(a,o)}t!==e.modelValue&&r("update:modelValue",t)},K=t=>{t.target.composing||v(t.target.value)},E=()=>{var t;return(t=u.value)==null?void 0:t.blur()},U=()=>{var t;return(t=u.value)==null?void 0:t.focus()},I=()=>{const t=u.value;e.type==="textarea"&&e.autosize&&t&&Fe(t,e.autosize)},Y=t=>{i.focused=!0,r("focus",t),S(I),g("readonly")&&E()},J=t=>{g("readonly")||(i.focused=!1,v(h(),"onBlur"),r("blur",t),V("onBlur"),S(I),Ae())},_=t=>r("clickInput",t),Q=t=>r("clickLeftIcon",t),X=t=>r("clickRightIcon",t),Z=t=>{D(t),r("update:modelValue",""),r("clear",t)},N=b(()=>{if(typeof e.error=="boolean")return e.error;if(f&&f.props.showError&&i.status==="failed")return!0}),G=b(()=>{const t=g("labelWidth");if(t)return{width:xe(t)}}),p=t=>{t.keyCode===13&&(!(f&&f.props.submitOnEnter)&&e.type!=="textarea"&&D(t),e.type==="search"&&E()),r("keypress",t)},O=()=>e.id||`${c}-input`,ee=()=>i.status,te=()=>{const t=d("control",[g("inputAlign"),{error:N.value,custom:!!l.input,"min-height":e.type==="textarea"&&!e.autosize}]);if(l.input)return s("div",{class:t,onClick:_},[l.input()]);const n={id:O(),ref:u,name:e.name,rows:e.rows!==void 0?+e.rows:void 0,class:t,disabled:g("disabled"),readonly:g("readonly"),autofocus:e.autofocus,placeholder:e.placeholder,autocomplete:e.autocomplete,enterkeyhint:e.enterkeyhint,"aria-labelledby":e.label?`${c}-label`:void 0,onBlur:J,onFocus:Y,onInput:K,onClick:_,onChange:W,onKeypress:p,onCompositionend:W,onCompositionstart:De};return e.type==="textarea"?s("textarea",n,null):s("input",Re(We(e.type),n),null)},ne=()=>{const t=l["left-icon"];if(e.leftIcon||t)return s("div",{class:d("left-icon"),onClick:Q},[t?t():s(M,{name:e.leftIcon,classPrefix:e.iconPrefix},null)])},ae=()=>{const t=l["right-icon"];if(e.rightIcon||t)return s("div",{class:d("right-icon"),onClick:X},[t?t():s(M,{name:e.rightIcon,classPrefix:e.iconPrefix},null)])},re=()=>{if(e.showWordLimit&&e.maxlength){const t=T(h());return s("div",{class:d("word-limit")},[s("span",{class:d("word-num")},[t]),Le("/"),e.maxlength])}},ie=()=>{if(f&&f.props.showErrorMessage===!1)return;const t=e.errorMessage||i.validateMessage;if(t){const n=l["error-message"],a=g("errorMessageAlign");return s("div",{class:d("error-message",a)},[n?n({message:t}):t])}},le=()=>{const t=g("colon")?":":"";if(l.label)return[l.label(),t];if(e.label)return s("label",{id:`${c}-label`,for:O()},[e.label+t])},oe=()=>[s("div",{class:d("body")},[te(),j.value&&s(M,{ref:R,name:e.clearIcon,class:d("clear")},null),ae(),l.button&&s("div",{class:d("button")},[l.button()])]),re(),ie()];return Ve({blur:E,focus:U,validate:B,formValue:L,resetValidation:y,getValidationStatus:ee}),Ee(ke,{customValue:x,resetValidation:y,validateWithTrigger:V}),we(()=>e.modelValue,()=>{v(h()),y(),V("onChange"),S(I)}),Me(()=>{v(h(),e.formatTrigger),S(I)}),Te("touchstart",Z,{target:b(()=>{var t;return(t=R.value)==null?void 0:t.$el})}),()=>{const t=g("disabled"),n=g("labelAlign"),a=le(),o=ne(),m=()=>n==="top"?[o,a]:a;return s(Ne,{size:e.size,class:d({error:N.value,disabled:t,[`label-${n}`]:n}),center:e.center,border:e.border,isLink:e.isLink,clickable:e.clickable,titleStyle:G.value,valueClass:d("value"),titleClass:[d("label",[n,{required:e.required}]),e.labelClass],arrowDirection:e.arrowDirection},{icon:o&&n!=="top"?()=>o:null,title:a||n==="top"?m:null,value:oe,extra:l.extra})}}});const Je=Be(Ke);export{Je as F,qe as f};
|