UNPKG

ng-zorro-antd

Version:

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

16 lines (14 loc) 10.2 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/util"),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/util","@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.util,t.ng.common,t["ng-zorro-antd"].icon)}(this,(function(t,e,n,i,o,r,s,u){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */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){this.elementRef=t,this.cdr=e,this.focusMonitor=n,this.isFocused=!1,this.disabledUp=!1,this.disabledDown=!1,this.onChange=function(){},this.onTouched=function(){},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.trim().replace(/。/g,".").replace(/[^\w\.-]+/g,"")},this.nzPrecisionMode="toFixed",this.nzPlaceHolder="",this.nzStep=1,this.nzId=null,this.nzDisabled=!1,this.nzAutoFocus=!1,this.nzFormatter=function(t){return t}}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&&r.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(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.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=r.isNotNil(this.nzFormatter(t))?this.nzFormatter(t):"";this.displayValue=e,this.inputElement.nativeElement.value=""+e},t.prototype.onKeyDown=function(t){if(t.keyCode===n.UP_ARROW){var e=this.getRatio(t);this.up(t,e),this.stop()}else if(t.keyCode===n.DOWN_ARROW){e=this.getRatio(t);this.down(t,e),this.stop()}else t.keyCode===n.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=this;this.focusMonitor.monitor(this.elementRef,!0).subscribe((function(e){e?(t.isFocused=!0,t.nzFocus.emit()):(t.isFocused=!1,t.updateDisplayValue(t.value),t.nzBlur.emit(),Promise.resolve().then((function(){return t.onTouched()})))}))},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)},t.decorators=[{type:i.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 (keydown)="onKeyDown($event)"\n (keyup)="stop()"\n [ngModel]="displayValue"\n (ngModelChange)="onModelChange($event)"\n />\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]":"true","[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.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}],nzPrecisionMode:[{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