UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

2 lines 9.23 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/a11y"),require("@angular/cdk/keycodes"),require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/core"),require("@angular/common"),require("ng-zorro-antd/icon")):"function"==typeof define&&define.amd?define("ng-zorro-antd/input-number",["exports","@angular/cdk/a11y","@angular/cdk/keycodes","@angular/core","@angular/forms","ng-zorro-antd/core","@angular/common","ng-zorro-antd/icon"],e):e(((t=t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"]["input-number"]={}),t.ng.cdk.a11y,t.ng.cdk.keycodes,t.ng.core,t.ng.forms,t["ng-zorro-antd"].core,t.ng.common,t["ng-zorro-antd"].icon)}(this,function(t,e,n,i,o,r,s,u){"use strict";function a(t,e,n,i){var o,r=arguments.length,s=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var u=t.length-1;u>=0;u--)(o=t[u])&&(s=(r<3?o(s):r>3?o(e,n,s):o(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}function p(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var l=function(){function t(t,e,n,o){this.elementRef=t,this.renderer=e,this.cdr=n,this.focusMonitor=o,this.isFocused=!1,this.disabledUp=!1,this.disabledDown=!1,this.onChange=function(){return null},this.onTouched=function(){return null},this.nzBlur=new i.EventEmitter,this.nzFocus=new i.EventEmitter,this.nzSize="default",this.nzMin=-1/0,this.nzMax=1/0,this.nzParser=function(t){return t},this.nzPlaceHolder="",this.nzStep=1,this.nzDisabled=!1,this.nzAutoFocus=!1,this.nzFormatter=function(t){return t},e.addClass(t.nativeElement,"ant-input-number")}return t.prototype.updateAutoFocus=function(){this.nzAutoFocus?this.renderer.setAttribute(this.inputElement.nativeElement,"autofocus","autofocus"):this.renderer.removeAttribute(this.inputElement.nativeElement,"autofocus")},t.prototype.onModelChange=function(t){this.actualValue=this.nzParser(t.trim().replace(/。/g,".").replace(/[^\w\.-]+/g,"")),this.inputElement.nativeElement.value=""+this.actualValue},t.prototype.getCurrentValidValue=function(t){var e=t;return e=""===e?"":this.isNotCompleteNumber(e)?this.value:this.getValidValue(e),this.toNumber(e)},t.prototype.isNotCompleteNumber=function(t){return isNaN(t)||""===t||null===t||!(!t||t.toString().indexOf(".")!==t.toString().length-1)},t.prototype.getValidValue=function(t){var e=parseFloat(t);return isNaN(e)?t:(e<this.nzMin&&(e=this.nzMin),e>this.nzMax&&(e=this.nzMax),e)},t.prototype.toNumber=function(t){return this.isNotCompleteNumber(t)?t:r.isNotNil(this.nzPrecision)?Number(Number(t).toFixed(this.nzPrecision)):Number(t)},t.prototype.setValidateValue=function(){var t=this.getCurrentValidValue(this.actualValue);this.setValue(t,""+this.value!=""+t)},t.prototype.onBlur=function(){this.isFocused=!1,this.setValidateValue()},t.prototype.onFocus=function(){this.isFocused=!0},t.prototype.getRatio=function(t){var e=1;return t.metaKey||t.ctrlKey?e=.1:t.shiftKey&&(e=10),e},t.prototype.down=function(t,e){this.isFocused||this.focus(),this.step("down",t,e)},t.prototype.up=function(t,e){this.isFocused||this.focus(),this.step("up",t,e)},t.prototype.getPrecision=function(t){var e=t.toString();if(e.indexOf("e-")>=0)return parseInt(e.slice(e.indexOf("e-")+2),10);var n=0;return e.indexOf(".")>=0&&(n=e.length-e.indexOf(".")-1),n},t.prototype.getMaxPrecision=function(t,e){if(r.isNotNil(this.nzPrecision))return this.nzPrecision;var n=this.getPrecision(e),i=this.getPrecision(this.nzStep),o=this.getPrecision(t);return t?Math.max(o,n+i):n+i},t.prototype.getPrecisionFactor=function(t,e){var n=this.getMaxPrecision(t,e);return Math.pow(10,n)},t.prototype.upStep=function(t,e){var n,i=this.getPrecisionFactor(t,e),o=Math.abs(this.getMaxPrecision(t,e));return n="number"==typeof t?((i*t+i*this.nzStep*e)/i).toFixed(o):this.nzMin===-1/0?this.nzStep:this.nzMin,this.toNumber(n)},t.prototype.downStep=function(t,e){var n,i=this.getPrecisionFactor(t,e),o=Math.abs(this.getMaxPrecision(t,e));return n="number"==typeof t?((i*t-i*this.nzStep*e)/i).toFixed(o):this.nzMin===-1/0?-this.nzStep:this.nzMin,this.toNumber(n)},t.prototype.step=function(t,e,n){var i=this;if(void 0===n&&(n=1),this.stop(),e.preventDefault(),!this.nzDisabled){var o=this.getCurrentValidValue(this.actualValue)||0,r=0;"up"===t?r=this.upStep(o,n):"down"===t&&(r=this.downStep(o,n));var s=r>this.nzMax||r<this.nzMin;r>this.nzMax?r=this.nzMax:r<this.nzMin&&(r=this.nzMin),this.setValue(r,!0),this.isFocused=!0,s||(this.autoStepTimer=setTimeout(function(){i[t](e,n,!0)},600))}},t.prototype.stop=function(){this.autoStepTimer&&clearTimeout(this.autoStepTimer)},t.prototype.setValue=function(t,e){e&&""+this.value!=""+t&&this.onChange(t),this.value=t,this.actualValue=t;var n=r.isNotNil(this.nzFormatter(this.value))?this.nzFormatter(this.value):"";if(this.displayValue=n,this.inputElement.nativeElement.value=""+n,this.disabledUp=this.disabledDown=!1,t||0===t){var i=Number(t);i>=this.nzMax&&(this.disabledUp=!0),i<=this.nzMin&&(this.disabledDown=!0)}},t.prototype.onKeyDown=function(t){if("ArrowUp"===t.code||t.keyCode===n.UP_ARROW){var e=this.getRatio(t);this.up(t,e),this.stop()}else if("ArrowDown"===t.code||t.keyCode===n.DOWN_ARROW){e=this.getRatio(t);this.down(t,e),this.stop()}else t.keyCode===n.ENTER&&this.setValidateValue()},t.prototype.onKeyUp=function(){this.stop()},t.prototype.writeValue=function(t){this.setValue(t,!1),this.cdr.markForCheck()},t.prototype.registerOnChange=function(t){this.onChange=t},t.prototype.registerOnTouched=function(t){this.onTouched=t},t.prototype.setDisabledState=function(t){this.nzDisabled=t,this.cdr.markForCheck()},t.prototype.focus=function(){this.focusMonitor.focusVia(this.inputElement,"keyboard")},t.prototype.blur=function(){this.inputElement.nativeElement.blur()},t.prototype.ngOnInit=function(){var t=this;this.focusMonitor.monitor(this.elementRef,!0).subscribe(function(e){e?(t.onFocus(),t.nzFocus.emit()):(t.onBlur(),t.nzBlur.emit(),Promise.resolve().then(function(){return t.onTouched()}))})},t.prototype.ngOnChanges=function(t){if(t.nzAutoFocus&&this.updateAutoFocus(),t.nzFormatter){var e=this.getCurrentValidValue(this.actualValue);this.setValue(e,!0)}},t.prototype.ngAfterViewInit=function(){this.nzAutoFocus&&this.focus()},t.prototype.ngOnDestroy=function(){this.focusMonitor.stopMonitoring(this.elementRef)},t.decorators=[{type:i.Component,args:[{selector:"nz-input-number",exportAs:"nzInputNumber",template:'<div class="ant-input-number-handler-wrap">\n <span unselectable="unselectable"\n class="ant-input-number-handler ant-input-number-handler-up"\n (mousedown)="up($event)"\n (mouseup)="stop()"\n (mouseleave)="stop()"\n [class.ant-input-number-handler-up-disabled]="disabledUp">\n <i nz-icon nzType="up" class="ant-input-number-handler-up-inner"></i>\n </span>\n <span unselectable="unselectable"\n class="ant-input-number-handler ant-input-number-handler-down"\n (mousedown)="down($event)"\n (mouseup)="stop()"\n (mouseleave)="stop()"\n [class.ant-input-number-handler-down-disabled]="disabledDown">\n <i nz-icon nzType="down" class="ant-input-number-handler-down-inner"></i>\n </span>\n</div>\n<div class="ant-input-number-input-wrap">\n <input #inputElement\n autocomplete="off"\n class="ant-input-number-input"\n [attr.id]="nzId"\n [disabled]="nzDisabled"\n [attr.min]="nzMin"\n [attr.max]="nzMax"\n [placeholder]="nzPlaceHolder"\n [attr.step]="nzStep"\n (keydown)="onKeyDown($event)"\n (keyup)="onKeyUp()"\n [ngModel]="displayValue"\n (ngModelChange)="onModelChange($event)">\n</div>\n',providers:[{provide:o.NG_VALUE_ACCESSOR,useExisting:i.forwardRef(function(){return t}),multi:!0}],changeDetection:i.ChangeDetectionStrategy.OnPush,encapsulation:i.ViewEncapsulation.None,host:{"[class.ant-input-number-focused]":"isFocused","[class.ant-input-number-lg]":"nzSize === 'large'","[class.ant-input-number-sm]":"nzSize === 'small'","[class.ant-input-number-disabled]":"nzDisabled"}}]}],t.ctorParameters=function(){return[{type:i.ElementRef},{type:i.Renderer2},{type:i.ChangeDetectorRef},{type:e.FocusMonitor}]},t.propDecorators={nzBlur:[{type:i.Output}],nzFocus:[{type:i.Output}],inputElement:[{type:i.ViewChild,args:["inputElement",{static:!0}]}],nzSize:[{type:i.Input}],nzMin:[{type:i.Input}],nzMax:[{type:i.Input}],nzParser:[{type:i.Input}],nzPrecision:[{type:i.Input}],nzPlaceHolder:[{type:i.Input}],nzStep:[{type:i.Input}],nzId:[{type:i.Input}],nzDisabled:[{type:i.Input}],nzAutoFocus:[{type:i.Input}],nzFormatter:[{type:i.Input}]},a([r.InputBoolean(),p("design:type",Object)],t.prototype,"nzDisabled",void 0),a([r.InputBoolean(),p("design:type",Object)],t.prototype,"nzAutoFocus",void 0),t}();var c=function(){function t(){}return t.decorators=[{type:i.NgModule,args:[{imports:[s.CommonModule,o.FormsModule,u.NzIconModule],declarations:[l],exports:[l]}]}],t}();t.NzInputNumberComponent=l,t.NzInputNumberModule=c,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ng-zorro-antd-input-number.umd.min.js.map