mirror of
https://github.com/schroinerxy/cloud-mail.git
synced 2026-06-21 19:35:50 +08:00
2 lines
6.3 KiB
JavaScript
2 lines
6.3 KiB
JavaScript
import{aQ as p,X as y,b as oe,d as de,aS as ce,_ as me,a as Z,aK as pe,u as fe,z as be,D as ve,k as h,C as w,F as Ne,I as Ve,aX as he,c as $,o as b,N as Q,e as j,ab as z,g as r,aP as _,n as K,r as S,p as A,m as F,A as ye,bu as Ee,L as q,bv as Ie,bw as ge,aD as we,a7 as L,M as _e,w as Se}from"./index-BtzXKQwE.js";import{E as Ae}from"./vnode-D7e7dmSq.js";import{u as Fe,d as J,t as Pe}from"./index-DeJUs09x.js";import{U as N,I as P,C as ee}from"./event-BB_Ol6Sd.js";import{v as Y}from"./index-DauRvaKi.js";import{b as Ce,a as Me,d as ke}from"./index-CBgbCWze.js";const De=oe({id:{type:String,default:void 0},step:{type:Number,default:1},stepStrictly:Boolean,max:{type:Number,default:Number.MAX_SAFE_INTEGER},min:{type:Number,default:Number.MIN_SAFE_INTEGER},modelValue:{type:[Number,null]},readonly:Boolean,disabled:Boolean,size:ce,controls:{type:Boolean,default:!0},controlsPosition:{type:String,default:"",values:["","right"]},valueOnClear:{type:[String,Number,null],validator:u=>u===null||p(u)||["min","max"].includes(u),default:null},name:String,placeholder:String,precision:{type:Number,validator:u=>u>=0&&u===Number.parseInt(`${u}`,10)},validateEvent:{type:Boolean,default:!0},...Fe(["ariaLabel"]),inputmode:{type:de(String),default:void 0}}),Te={[ee]:(u,C)=>C!==u,blur:u=>u instanceof FocusEvent,focus:u=>u instanceof FocusEvent,[P]:u=>p(u)||y(u),[N]:u=>p(u)||y(u)},xe=Z({name:"ElInputNumber"}),Be=Z({...xe,props:De,emits:Te,setup(u,{expose:C,emit:d}){const a=u,{t:R}=pe(),c=fe("input-number"),f=be(),l=ve({currentValue:a.modelValue,userInput:null}),{formItem:v}=Ce(),G=h(()=>p(a.modelValue)&&a.modelValue<=a.min),O=h(()=>p(a.modelValue)&&a.modelValue>=a.max),ne=h(()=>{const e=X(a.step);return w(a.precision)?Math.max(X(a.modelValue),e):(e>a.precision,a.precision)}),M=h(()=>a.controls&&a.controlsPosition==="right"),U=Me(),V=ke(),k=h(()=>{if(l.userInput!==null)return l.userInput;let e=l.currentValue;if(y(e))return"";if(p(e)){if(Number.isNaN(e))return"";w(a.precision)||(e=e.toFixed(a.precision))}return e}),D=(e,n)=>{if(w(n)&&(n=ne.value),n===0)return Math.round(e);let t=String(e);const s=t.indexOf(".");if(s===-1||!t.replace(".","").split("")[s+n])return e;const I=t.length;return t.charAt(I-1)==="5"&&(t=`${t.slice(0,Math.max(0,I-1))}6`),Number.parseFloat(Number(t).toFixed(n))},X=e=>{if(y(e))return 0;const n=e.toString(),t=n.indexOf(".");let s=0;return t!==-1&&(s=n.length-t-1),s},W=(e,n=1)=>p(e)?e>=Number.MAX_SAFE_INTEGER&&n===1||e<=Number.MIN_SAFE_INTEGER&&n===-1?e:D(e+a.step*n):l.currentValue,T=()=>{if(a.readonly||V.value||O.value)return;const e=Number(k.value)||0,n=W(e);E(n),d(P,l.currentValue),B()},x=()=>{if(a.readonly||V.value||G.value)return;const e=Number(k.value)||0,n=W(e,-1);E(n),d(P,l.currentValue),B()},H=(e,n)=>{const{max:t,min:s,step:i,precision:m,stepStrictly:I,valueOnClear:g}=a;t<s&&Pe("InputNumber","min should not be greater than max.");let o=Number(e);if(y(e)||Number.isNaN(o))return null;if(e===""){if(g===null)return null;o=_e(g)?{min:s,max:t}[g]:g}return I&&(o=D(Math.round(o/i)*i,m),o!==e&&n&&d(N,o)),w(m)||(o=D(o,m)),(o>t||o<s)&&(o=o>t?t:s,n&&d(N,o)),o},E=(e,n=!0)=>{var t;const s=l.currentValue,i=H(e);if(!n){d(N,i);return}s===i&&e||(l.userInput=null,d(N,i),s!==i&&d(ee,i,s),a.validateEvent&&((t=v?.validate)==null||t.call(v,"change").catch(m=>J())),l.currentValue=i)},te=e=>{l.userInput=e;const n=e===""?null:Number(e);d(P,n),E(n,!1)},re=e=>{const n=e!==""?Number(e):"";(p(n)&&!Number.isNaN(n)||e==="")&&E(n),B(),l.userInput=null},ae=()=>{var e,n;(n=(e=f.value)==null?void 0:e.focus)==null||n.call(e)},ue=()=>{var e,n;(n=(e=f.value)==null?void 0:e.blur)==null||n.call(e)},le=e=>{d("focus",e)},se=e=>{var n,t;l.userInput=null,l.currentValue===null&&((n=f.value)!=null&&n.input)&&(f.value.input.value=""),d("blur",e),a.validateEvent&&((t=v?.validate)==null||t.call(v,"blur").catch(s=>J()))},B=()=>{l.currentValue!==a.modelValue&&(l.currentValue=a.modelValue)},ie=e=>{document.activeElement===e.target&&e.preventDefault()};return Ne(()=>a.modelValue,(e,n)=>{const t=H(e,!0);l.userInput===null&&t!==n&&(l.currentValue=t)},{immediate:!0}),Ve(()=>{var e;const{min:n,max:t,modelValue:s}=a,i=(e=f.value)==null?void 0:e.input;if(i.setAttribute("role","spinbutton"),Number.isFinite(t)?i.setAttribute("aria-valuemax",String(t)):i.removeAttribute("aria-valuemax"),Number.isFinite(n)?i.setAttribute("aria-valuemin",String(n)):i.removeAttribute("aria-valuemin"),i.setAttribute("aria-valuenow",l.currentValue||l.currentValue===0?String(l.currentValue):""),i.setAttribute("aria-disabled",String(V.value)),!p(s)&&s!=null){let m=Number(s);Number.isNaN(m)&&(m=null),d(N,m)}i.addEventListener("wheel",ie,{passive:!1})}),he(()=>{var e,n;const t=(e=f.value)==null?void 0:e.input;t?.setAttribute("aria-valuenow",`${(n=l.currentValue)!=null?n:""}`)}),C({focus:ae,blur:ue}),(e,n)=>(b(),$("div",{class:K([r(c).b(),r(c).m(r(U)),r(c).is("disabled",r(V)),r(c).is("without-controls",!e.controls),r(c).is("controls-right",r(M))]),onDragstart:L(()=>{},["prevent"])},[e.controls?Q((b(),$("span",{key:0,role:"button","aria-label":r(R)("el.inputNumber.decrease"),class:K([r(c).e("decrease"),r(c).is("disabled",r(G))]),onKeydown:_(x,["enter"])},[S(e.$slots,"decrease-icon",{},()=>[z(r(q),null,{default:A(()=>[r(M)?(b(),F(r(ye),{key:0})):(b(),F(r(Ee),{key:1}))]),_:1})])],42,["aria-label","onKeydown"])),[[r(Y),x]]):j("v-if",!0),e.controls?Q((b(),$("span",{key:1,role:"button","aria-label":r(R)("el.inputNumber.increase"),class:K([r(c).e("increase"),r(c).is("disabled",r(O))]),onKeydown:_(T,["enter"])},[S(e.$slots,"increase-icon",{},()=>[z(r(q),null,{default:A(()=>[r(M)?(b(),F(r(Ie),{key:0})):(b(),F(r(ge),{key:1}))]),_:1})])],42,["aria-label","onKeydown"])),[[r(Y),T]]):j("v-if",!0),z(r(Ae),{id:e.id,ref_key:"input",ref:f,type:"number",step:e.step,"model-value":r(k),placeholder:e.placeholder,readonly:e.readonly,disabled:r(V),size:r(U),max:e.max,min:e.min,name:e.name,"aria-label":e.ariaLabel,"validate-event":!1,inputmode:e.inputmode,onKeydown:[_(L(T,["prevent"]),["up"]),_(L(x,["prevent"]),["down"])],onBlur:se,onFocus:le,onInput:te,onChange:re},we({_:2},[e.$slots.prefix?{name:"prefix",fn:A(()=>[S(e.$slots,"prefix")])}:void 0,e.$slots.suffix?{name:"suffix",fn:A(()=>[S(e.$slots,"suffix")])}:void 0]),1032,["id","step","model-value","placeholder","readonly","disabled","size","max","min","name","aria-label","inputmode","onKeydown"])],42,["onDragstart"]))}});var $e=me(Be,[["__file","input-number.vue"]]);const Ue=Se($e);export{Ue as E};
|