UNPKG

ng-zorro-antd

Version:

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

16 lines (14 loc) 10.9 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/a11y"),require("@angular/cdk/bidi"),require("@angular/cdk/keycodes"),require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/core/util"),require("rxjs"),require("rxjs/operators"),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/bidi","@angular/cdk/keycodes","@angular/core","@angular/forms","ng-zorro-antd/core/util","rxjs","rxjs/operators","@angular/common","ng-zorro-antd/icon"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"]["input-number"]={}),t.ng.cdk.a11y,t.ng.cdk.bidi,t.ng.cdk.keycodes,t.ng.core,t.ng.forms,t["ng-zorro-antd"].core.util,t.rxjs,t.rxjs.operators,t.ng.common,t["ng-zorro-antd"].icon)}(this,(function(t,e,n,i,o,r,s,u,a,p,l){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */function c(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 d(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}Object.create;Object.create;var h=function(){function t(t,e,n,i){this.elementRef=t,this.cdr=e,this.focusMonitor=n,this.directionality=i,this.destroy$=new u.Subject,this.isFocused=!1,this.disabledUp=!1,this.disabledDown=!1,this.dir="ltr",this.onChange=function(){},this.onTouched=function(){},this.nzBlur=new o.EventEmitter,this.nzFocus=new o.EventEmitter,this.nzSize="default",this.nzMin=-1/0,this.nzMax=1/0,this.nzParser=function(t){return t.trim().replace(/。/g,".").replace(/[^\w\.-]+/g,"")},this.nzPrecisionMode="toFixed",this.nzPlaceHolder="",this.nzStep=1,this.nzInputMode="decimal",this.nzId=null,this.nzDisabled=!1,this.nzAutoFocus=!1,this.nzFormatter=function(t){return t},this.elementRef.nativeElement.classList.add("ant-input-number")}return t.prototype.onModelChange=function(t){this.parsedValue=this.nzParser(t),this.inputElement.nativeElement.value=""+this.parsedValue;var e=this.getCurrentValidValue(this.parsedValue);this.setValue(e)},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){if(this.isNotCompleteNumber(t))return t;var e=String(t);if(e.indexOf(".")>=0&&s.isNotNil(this.nzPrecision)){if("function"==typeof this.nzPrecisionMode)return this.nzPrecisionMode(t,this.nzPrecision);if("cut"===this.nzPrecisionMode){var n=e.split(".");return n[1]=n[1].slice(0,this.nzPrecision),Number(n.join("."))}return Number(Number(t).toFixed(this.nzPrecision))}return Number(t)},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(s.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.parsedValue)||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),this.updateDisplayValue(r),this.isFocused=!0,s||(this.autoStepTimer=setTimeout((function(){i[t](e,n)}),300))}},t.prototype.stop=function(){this.autoStepTimer&&clearTimeout(this.autoStepTimer)},t.prototype.setValue=function(t){if(""+this.value!=""+t&&this.onChange(t),this.value=t,this.parsedValue=t,this.disabledUp=this.disabledDown=!1,t||0===t){var e=Number(t);e>=this.nzMax&&(this.disabledUp=!0),e<=this.nzMin&&(this.disabledDown=!0)}},t.prototype.updateDisplayValue=function(t){var e=s.isNotNil(this.nzFormatter(t))?this.nzFormatter(t):"";this.displayValue=e,this.inputElement.nativeElement.value=""+e},t.prototype.onKeyDown=function(t){if(t.keyCode===i.UP_ARROW){var e=this.getRatio(t);this.up(t,e),this.stop()}else if(t.keyCode===i.DOWN_ARROW){e=this.getRatio(t);this.down(t,e),this.stop()}else t.keyCode===i.ENTER&&this.updateDisplayValue(this.value)},t.prototype.writeValue=function(t){this.value=t,this.setValue(t),this.updateDisplayValue(t),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,e=this;this.focusMonitor.monitor(this.elementRef,!0).subscribe((function(t){t?(e.isFocused=!0,e.nzFocus.emit()):(e.isFocused=!1,e.updateDisplayValue(e.value),e.nzBlur.emit(),Promise.resolve().then((function(){return e.onTouched()})))})),this.dir=this.directionality.value,null===(t=this.directionality.change)||void 0===t||t.pipe(a.takeUntil(this.destroy$)).subscribe((function(t){e.dir=t}))},t.prototype.ngOnChanges=function(t){if(t.nzFormatter&&!t.nzFormatter.isFirstChange()){var e=this.getCurrentValidValue(this.parsedValue);this.setValue(e),this.updateDisplayValue(e)}},t.prototype.ngAfterViewInit=function(){this.nzAutoFocus&&this.focus()},t.prototype.ngOnDestroy=function(){this.focusMonitor.stopMonitoring(this.elementRef),this.destroy$.next(),this.destroy$.complete()},t}();h.decorators=[{type:o.Component,args:[{selector:"nz-input-number",exportAs:"nzInputNumber",template:'\n <div class="ant-input-number-handler-wrap">\n <span\n 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 >\n <i nz-icon nzType="up" class="ant-input-number-handler-up-inner"></i>\n </span>\n <span\n 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 >\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\n #inputElement\n autocomplete="off"\n class="ant-input-number-input"\n [attr.id]="nzId"\n [attr.autofocus]="nzAutoFocus ? \'autofocus\' : null"\n [disabled]="nzDisabled"\n [attr.min]="nzMin"\n [attr.max]="nzMax"\n [placeholder]="nzPlaceHolder"\n [attr.step]="nzStep"\n [attr.inputmode]="nzInputMode"\n (keydown)="onKeyDown($event)"\n (keyup)="stop()"\n [ngModel]="displayValue"\n (ngModelChange)="onModelChange($event)"\n />\n </div>\n ',providers:[{provide:r.NG_VALUE_ACCESSOR,useExisting:o.forwardRef((function(){return h})),multi:!0}],changeDetection:o.ChangeDetectionStrategy.OnPush,encapsulation:o.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","[class.ant-input-number-rtl]":"dir === 'rtl'"}}]}],h.ctorParameters=function(){return[{type:o.ElementRef},{type:o.ChangeDetectorRef},{type:e.FocusMonitor},{type:n.Directionality,decorators:[{type:o.Optional}]}]},h.propDecorators={nzBlur:[{type:o.Output}],nzFocus:[{type:o.Output}],inputElement:[{type:o.ViewChild,args:["inputElement",{static:!0}]}],nzSize:[{type:o.Input}],nzMin:[{type:o.Input}],nzMax:[{type:o.Input}],nzParser:[{type:o.Input}],nzPrecision:[{type:o.Input}],nzPrecisionMode:[{type:o.Input}],nzPlaceHolder:[{type:o.Input}],nzStep:[{type:o.Input}],nzInputMode:[{type:o.Input}],nzId:[{type:o.Input}],nzDisabled:[{type:o.Input}],nzAutoFocus:[{type:o.Input}],nzFormatter:[{type:o.Input}]},c([s.InputBoolean(),d("design:type",Object)],h.prototype,"nzDisabled",void 0),c([s.InputBoolean(),d("design:type",Object)],h.prototype,"nzAutoFocus",void 0);var f=function(){};f.decorators=[{type:o.NgModule,args:[{imports:[n.BidiModule,p.CommonModule,r.FormsModule,l.NzIconModule],declarations:[h],exports:[h]}]}],t.NzInputNumberComponent=h,t.NzInputNumberModule=f,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=ng-zorro-antd-input-number.umd.min.js.map