1 |
- import{bg as e,am as t,bh as a,bi as l,b1 as r,t as n,w as o,N as s,x as i,D as u,aq as c,d,ah as g,r as f,Q as p,G as m,c as v,z as h,ag as b,at as y,S as k,V as x,o as S,k as w,a as C,bj as V,ak as M,bk as I,bl as B,aE as A,L as E,bm as z,J as T,m as L,bn as P,C as j}from"./index-232a7449.js";import{c as W,C as q}from"./index-b3c0f2c5.js";function D(e){return Array.isArray(e)?!e.length:0!==e&&!e}function F(e,t){const{message:a}=t;return r(a)?a(e,t):a||""}function H({target:e}){e.composing=!0}function R({target:e}){e.composing&&(e.composing=!1,e.dispatchEvent(new Event("input")))}function O(e){return[...e].length}function G(e,t){return[...e].slice(0,t).join("")}const[J,K]=n("field"),N={id:String,name:String,leftIcon:String,rightIcon:String,autofocus:Boolean,clearable:Boolean,maxlength:o,formatter:Function,clearIcon:s("clear"),modelValue:i(""),inputAlign:String,placeholder:String,autocomplete:String,autocapitalize:String,autocorrect:String,errorMessage:String,enterkeyhint:String,clearTrigger:s("focus"),formatTrigger:s("onChange"),spellcheck:{type:Boolean,"default":null},error:{type:Boolean,"default":null},disabled:{type:Boolean,"default":null},readonly:{type:Boolean,"default":null}},Q=j(d({name:J,props:u({},W,N,{rows:o,type:s("text"),rules:Array,autosize:[Boolean,Object],labelWidth:o,labelClass:c,labelAlign:String,showWordLimit:Boolean,errorMessageAlign:String,colon:{type:Boolean,"default":null}}),emits:["blur","focus","clear","keypress","clickInput","endValidate","startValidate","clickLeftIcon","clickRightIcon","update:modelValue"],setup(r,{emit:n,slots:o}){const s=g(),i=f({status:"unvalidated",focused:!1,validateMessage:""}),u=p(),c=p(),d=p(),{parent:j}=m(V),W=()=>{var e;return String(null!=(e=r.modelValue)?e:"")},J=e=>M(r[e])?r[e]:j&&M(j.props[e])?j.props[e]:void 0,N=v((()=>{const e=J("readonly");if(r.clearable&&!e){const e=""!==W(),t="always"===r.clearTrigger||"focus"===r.clearTrigger&&i.focused;return e&&t}return!1})),Q=v((()=>d.value&&o.input?d.value():r.modelValue)),$=v((()=>{var e;const t=J("required");return"auto"===t?null==(e=r.rules)?void 0:e.some((e=>e.required)):t})),U=()=>{i.status="unvalidated",i.validateMessage=""},X=()=>n("endValidate",{status:i.status,message:i.validateMessage}),Y=(e=r.rules)=>new Promise((t=>{U(),e?(n("startValidate"),(e=>e.reduce(((e,t)=>e.then((()=>{if("failed"===i.status)return;let{value:e}=Q;if(t.formatter&&(e=t.formatter(e,t)),!function(e,t){if(D(e)){if(t.required)return!1;if(!1===t.validateEmpty)return!0}return!(t.pattern&&!t.pattern.test(String(e)))}(e,t))return i.status="failed",void(i.validateMessage=F(e,t));if(t.validator){if(D(e)&&!1===t.validateEmpty)return;return(a=e,r=t,new Promise((e=>{const t=r.validator(a,r);l(t)?t.then(e):e(t)}))).then((a=>{a&&"string"==typeof a?(i.status="failed",i.validateMessage=a):!1===a&&(i.status="failed",i.validateMessage=F(e,t))}))}var a,r}))),Promise.resolve()))(e).then((()=>{"failed"===i.status?(t({name:r.name,message:i.validateMessage}),X()):(i.status="passed",t(),X())}))):t()})),Z=e=>{if(j&&r.rules){const{validateTrigger:t}=j.props,a=I(t).includes(e),l=r.rules.filter((t=>t.trigger?I(t.trigger).includes(e):a));l.length&&Y(l)}},_=(e,t="onChange")=>{const a=e;e=(e=>{var t;const{maxlength:a}=r;if(M(a)&&O(e)>+a){const l=W();if(l&&O(l)===+a)return l;const r=null==(t=u.value)?void 0:t.selectionEnd;if(i.focused&&r){const t=[...e],l=t.length-+a;return t.splice(r-l,l),t.join("")}return G(e,+a)}return e})(e);const l=O(a)-O(e);if("number"===r.type||"digit"===r.type){const t="number"===r.type;e=B(e,t,t)}let o=0;if(r.formatter&&t===r.formatTrigger){const{formatter:t,maxlength:l}=r;if(e=t(e),M(l)&&O(e)>+l&&(e=G(e,+l)),u.value&&i.focused){const{selectionEnd:e}=u.value,l=G(a,e);o=O(t(l))-O(l)}}if(u.value&&u.value.value!==e)if(i.focused){let{selectionStart:t,selectionEnd:a}=u.value;if(u.value.value=e,M(t)&&M(a)){const r=O(e);l?(t-=l,a-=l):o&&(t+=o,a+=o),u.value.setSelectionRange(Math.min(t,r),Math.min(a,r))}}else u.value.value=e;e!==r.modelValue&&n("update:modelValue",e)},ee=e=>{e.target.composing||_(e.target.value)},te=()=>{var e;return null==(e=u.value)?void 0:e.blur()},ae=()=>{var e;return null==(e=u.value)?void 0:e.focus()},le=()=>{const l=u.value;"textarea"===r.type&&r.autosize&&l&&function(l,r){const n=e();l.style.height="auto";let o=l.scrollHeight;if(a(r)){const{maxHeight:e,minHeight:t}=r;void 0!==e&&(o=Math.min(o,e)),void 0!==t&&(o=Math.max(o,t))}o&&(l.style.height="".concat(o,"px"),t(n))}(l,r.autosize)},re=e=>{i.focused=!0,n("focus",e),x(le),J("readonly")&&te()},ne=e=>{i.focused=!1,_(W(),"onBlur"),n("blur",e),J("readonly")||(Z("onBlur"),x(le),P())},oe=e=>n("clickInput",e),se=e=>n("clickLeftIcon",e),ie=e=>n("clickRightIcon",e),ue=v((()=>"boolean"==typeof r.error?r.error:!(!j||!j.props.showError||"failed"!==i.status)||void 0)),ce=v((()=>{const e=J("labelWidth"),t=J("labelAlign");if(e&&"top"!==t)return{width:h(e)}})),de=e=>{13===e.keyCode&&(j&&j.props.submitOnEnter||"textarea"===r.type||A(e),"search"===r.type&&te()),n("keypress",e)},ge=()=>r.id||"".concat(s,"-input"),fe=()=>{const e=K("control",[J("inputAlign"),{error:ue.value,custom:!!o.input,"min-height":"textarea"===r.type&&!r.autosize}]);if(o.input)return C("div",{"class":e,onClick:oe},[o.input()]);const t={id:ge(),ref:u,name:r.name,rows:void 0!==r.rows?+r.rows:void 0,"class":e,disabled:J("disabled"),readonly:J("readonly"),autofocus:r.autofocus,placeholder:r.placeholder,autocomplete:r.autocomplete,autocapitalize:r.autocapitalize,autocorrect:r.autocorrect,enterkeyhint:r.enterkeyhint,spellcheck:r.spellcheck,"aria-labelledby":r.label?"".concat(s,"-label"):void 0,onBlur:ne,onFocus:re,onInput:ee,onClick:oe,onChange:R,onKeypress:de,onCompositionend:R,onCompositionstart:H};return"textarea"===r.type?C("textarea",t,null):C("input",T("number"===(a=r.type)?{type:"text",inputmode:"decimal"}:"digit"===a?{type:"tel",inputmode:"numeric"}:{type:a},t),null);var a},pe=()=>{const e=o["right-icon"];if(r.rightIcon||e)return C("div",{"class":K("right-icon"),onClick:ie},[e?e():C(E,{name:r.rightIcon,classPrefix:r.iconPrefix},null)])},me=()=>{if(r.showWordLimit&&r.maxlength){const e=O(W());return C("div",{"class":K("word-limit")},[C("span",{"class":K("word-num")},[e]),L("/"),r.maxlength])}},ve=()=>{if(j&&!1===j.props.showErrorMessage)return;const e=r.errorMessage||i.validateMessage;if(e){const t=o["error-message"],a=J("errorMessageAlign");return C("div",{"class":K("error-message",a)},[t?t({message:e}):e])}},he=()=>[C("div",{"class":K("body")},[fe(),N.value&&C(E,{ref:c,name:r.clearIcon,"class":K("clear")},null),pe(),o.button&&C("div",{"class":K("button")},[o.button()])]),me(),ve()];return b({blur:te,focus:ae,validate:Y,formValue:Q,resetValidation:U,getValidationStatus:()=>i.status}),y(z,{customValue:d,resetValidation:U,validateWithTrigger:Z}),k((()=>r.modelValue),(()=>{_(W()),U(),Z("onChange"),x(le)})),S((()=>{_(W(),r.formatTrigger),x(le)})),w("touchstart",(e=>{A(e),n("update:modelValue",""),n("clear",e)}),{target:v((()=>{var e;return null==(e=c.value)?void 0:e.$el}))}),()=>{const e=J("disabled"),t=J("labelAlign"),a=(()=>{const e=o["left-icon"];if(r.leftIcon||e)return C("div",{"class":K("left-icon"),onClick:se},[e?e():C(E,{name:r.leftIcon,classPrefix:r.iconPrefix},null)])})();return C(q,{size:r.size,"class":K({error:ue.value,disabled:e,["label-".concat(t)]:t}),center:r.center,border:r.border,isLink:r.isLink,clickable:r.clickable,titleStyle:ce.value,valueClass:K("value"),titleClass:[K("label",[t,{required:$.value}]),r.labelClass],arrowDirection:r.arrowDirection},{icon:a&&"top"!==t?()=>a:null,title:()=>{const e=(()=>{const e=J("labelWidth"),t=J("labelAlign"),a=J("colon")?":":"";return o.label?[o.label(),a]:r.label?C("label",{id:"".concat(s,"-label"),"for":o.input?void 0:ge(),onClick:e=>{A(e),ae()},style:"top"===t&&e?{width:h(e)}:void 0},[r.label+a]):void 0})();return"top"===t?[a,e].filter(Boolean):e||[]},value:he,extra:o.extra})}}}));export{Q as F,N as f};
|