vant/v3/assets/index.da0ad0e1.js
2024-04-20 08:49:23 +00:00

2 lines
7.5 KiB
JavaScript

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