UNPKG

dk-plus

Version:
2 lines (1 loc) 7.35 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),Y=require("./index3.js"),Z=require("./index4.js"),r=require("../../_hooks/get-input/index.js"),ee=require("../../_hooks/public/get-return/index.js");require("../../_icon/index.js");const te={key:1},ne={key:0,class:"dk-input_label-text"},oe={key:1,class:"dk-input_prefix"},le=["type","onKeydown"],ae={key:2,class:"dk-input_length"},se={key:3,class:"dk-input_length"},re={key:4,class:"dk-input_suffix"},ie={key:1},ce=["type"],pe={key:0,class:"dk-input_textarea_length"},ue={key:1,class:"dk-input_length"},de=e.defineComponent({__name:"input",props:Y.dkInputProps,emits:Z.inputEmits,setup($,{emit:i}){const l=$,g=e.useSlots(),P=e.shallowRef(),C=e.shallowRef(),d=e.computed(()=>P.value||C.value),{classList:w,styleList:B,wrapperClassList:_,innerClassList:j,pendStyleList:b}=r.getInput(l),m=e.ref(l.modelValue),V=e.ref(!1),I=e.ref(!1),n=r.setPropData(l),u=e.ref(l.modelValue);let c=!1,p=e.ref(r.verifyInputType(n.typeProp,c));const q=(t="")=>{let o="";return n.maxlengthProp&&n.minlengthProp?o=`${n.minlengthProp}/${n.maxlengthProp}`:n.maxlengthProp?o=`${t.toString().length}/${n.maxlengthProp}`:n.minlengthProp&&(o=`${n.minlengthProp}`),o},a=r.setData(n,g,p.value),R=e.computed(()=>r.getNull(u.value));let y=q();const S=e.reactive({isPrependText:r.getBooleanAnd([!g.prepend,r.getNull(n.prependText),!a.isPrependIcon]),isAppendText:r.getBooleanAnd([r.getNull(n.appendText),!g.append,!a.isAppendIcon])}),K=["dk-input_prepend","dk-input_pend"],M=["dk-input_append","dk-input_pend"],x=e.ref(0);e.watch(()=>l.modelValue,()=>{u.value=r.getValue(l.modelValue,n.prependText,n.prependIcon,n.appendText,n.appendIcon),m.value=u.value}),e.watch(()=>u.value,t=>{const o=t.toString().length;if(n.maxlengthProp&&(y=`${o}/${n.maxlengthProp}`),D().autosize){const s=d.value;s.style.height="auto",s.style.height=`${s.scrollHeight+2}px`}a.showLength&&(x.value=o),n.typeProp==="number"?i("update:modelValue",Number(t)):i("update:modelValue",r.getPendValue(t,n.prependText,n.prependIcon,n.appendText,n.appendIcon))});const N=t=>{const o=t.target;u.value=o.value},H=()=>["dk-input_prefix-icon",typeof n.prefixIcon=="boolean"?"dk-icon-search":n.prefixIcon],O=()=>["dk-input_suffix-icon",typeof n.suffixIcon=="boolean"?"dk-icon-search":n.suffixIcon],F=()=>{m.value="",i("update:modelValue",""),E()},E=async()=>{var t;await e.nextTick(),(t=d.value)==null||t.focus()};let T=e.ref("IconPasswordSee");const U=()=>{var t,o;c=!c,T.value=c?"IconPasswordShow":"IconPasswordSee",p.value=c?"text":"password",c?(t=d.value)==null||t.setAttribute("type","text"):(o=d.value)==null||o.setAttribute("type","password"),E()},G=()=>["dk-input_password-icon"],z=t=>{V.value=!0,i("focus",t)},L=t=>{V.value=!1,i("blur",t)},{getRun:v}=ee.getReturn(),J=t=>{v(l.onAppendClick,t)},Q=t=>{v(l.onPrependClick,t)},W=t=>{if(t.which===13){const o=t.target;v(l.onEnter,o.value)}},D=()=>{let t=1;const o=p.value==="textarea",s=n.autosizeProp,h=+n.rowsProp,X=h>0;return o&&X&&(t=h),{row:t,autosize:o&&s}},A=t=>{const o=t.target;i("change",o.value)},f=e.reactive({class:j.value,placeholder:n.placeholder,oninput:N,disabled:n.disabledProp,inputmode:a.inputmode,onfocus:z,onblur:L,onChange:A,maxlength:n.maxlengthProp,minlength:n.minlengthProp,readonly:n.readonlyProp,id:l.id||void 0,name:l.name||void 0,tabindex:l.tabindex,"aria-label":l.ariaLabel||void 0}),k=e.reactive({class:_.value,type:p.value,placeholder:n.placeholder,onInput:N,onfocus:z,onblur:L,onChange:A,disabled:n.disabledProp,maxlength:n.maxlengthProp,minlength:n.minlengthProp,autosize:n.autosizeProp,rows:D().row,readonly:n.readonlyProp,id:l.id||void 0,name:l.name||void 0,tabindex:l.tabindex,"aria-label":l.ariaLabel||void 0});return e.watch(()=>l.placeholder,t=>{n.placeholder=t,f.placeholder=t,k.placeholder=t},{immediate:!0}),e.watch(()=>l.tabindex,t=>{f.tabindex=t,k.tabindex=t},{immediate:!0}),e.watch(()=>l.ariaLabel,t=>{f["aria-label"]=t||void 0,k["aria-label"]=t||void 0},{immediate:!0}),(t,o)=>{const s=e.resolveComponent("dk-icon");return t.type!=="textarea"?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass([e.unref(w),"dk-input"]),style:e.normalizeStyle(e.unref(B))},[!I.value&&e.unref(a).isPrepend?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(K),style:e.normalizeStyle(e.unref(b))},[e.renderSlot(t.$slots,"prepend"),e.unref(a).isPrependIcon?(e.openBlock(),e.createBlock(s,{key:0,icon:t.prependIcon,onClick:Q},null,8,["icon"])):e.createCommentVNode("",!0),S.isPrependText?(e.openBlock(),e.createElementBlock("span",te,e.toDisplayString(t.prependText),1)):e.createCommentVNode("",!0)],4)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(e.unref(_))},[e.unref(a).labelText?(e.openBlock(),e.createElementBlock("div",ne,[e.createElementVNode("span",null,e.toDisplayString(e.unref(a).labelText),1)])):e.createCommentVNode("",!0),e.unref(a).isPrefix?(e.openBlock(),e.createElementBlock("span",oe,[e.renderSlot(t.$slots,"prefix"),e.unref(a).isPrefixIcon?(e.openBlock(),e.createBlock(s,{key:0,class:e.normalizeClass(H),icon:t.prefixIcon,size:"19px"},null,8,["icon"])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("input",e.mergeProps({ref_key:"input",ref:P,"onUpdate:modelValue":o[0]||(o[0]=h=>m.value=h),type:e.unref(p)},f,{onKeydown:e.withKeys(W,["enter"])}),null,16,le),[[e.vModelDynamic,m.value]]),e.unref(a).isLength?(e.openBlock(),e.createElementBlock("span",ae,e.toDisplayString(e.unref(y)),1)):e.createCommentVNode("",!0),t.showLength?(e.openBlock(),e.createElementBlock("span",se,e.toDisplayString(x.value),1)):e.createCommentVNode("",!0),e.unref(a).isSuffix?(e.openBlock(),e.createElementBlock("div",re,[e.renderSlot(t.$slots,"suffix"),e.unref(a).isSuffixIcon?(e.openBlock(),e.createBlock(s,{key:0,class:e.normalizeClass(O),icon:t.suffixIcon},null,8,["icon"])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.unref(a).isClear?e.withDirectives((e.openBlock(),e.createBlock(s,{key:5,class:"dk-input-clearable",icon:l.clearIcon||"IconShanchu1",onClick:F},null,8,["icon"])),[[e.vShow,R.value]]):e.createCommentVNode("",!0),e.unref(a).isShowPassword?(e.openBlock(),e.createBlock(s,{key:6,class:e.normalizeClass(G),icon:e.unref(T),onClick:U},null,8,["icon"])):e.createCommentVNode("",!0)],2),!I.value&&e.unref(a).isAppend?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(M),style:e.normalizeStyle(e.unref(b))},[e.renderSlot(t.$slots,"append"),e.unref(a).isAppendIcon?(e.openBlock(),e.createBlock(s,{key:0,icon:t.appendIcon,onClick:J},null,8,["icon"])):e.createCommentVNode("",!0),S.isAppendText?(e.openBlock(),e.createElementBlock("span",ie,e.toDisplayString(t.appendText),1)):e.createCommentVNode("",!0)],4)):e.createCommentVNode("",!0)],6)):(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(e.unref(w)),style:e.normalizeStyle(e.unref(B))},[e.createElementVNode("textarea",e.mergeProps({ref_key:"textarea",ref:C,type:e.unref(p)},k),null,16,ce),e.unref(a).isLength?(e.openBlock(),e.createElementBlock("span",pe,e.toDisplayString(e.unref(y)),1)):e.createCommentVNode("",!0),t.showLength?(e.openBlock(),e.createElementBlock("span",ue,e.toDisplayString(x.value),1)):e.createCommentVNode("",!0)],6))}}});exports.default=de;