UNPKG

@taiga-ui/kit

Version:
16 lines (14 loc) 8.64 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms"),require("@taiga-ui/cdk"),require("@taiga-ui/core"),require("@taiga-ui/kit/directives"),require("angular2-text-mask")):"function"==typeof define&&define.amd?define("@taiga-ui/kit/components/input-number",["exports","@angular/core","@angular/forms","@taiga-ui/cdk","@taiga-ui/core","@taiga-ui/kit/directives","angular2-text-mask"],t):t(((e=e||self)["taiga-ui"]=e["taiga-ui"]||{},e["taiga-ui"].kit=e["taiga-ui"].kit||{},e["taiga-ui"].kit.components=e["taiga-ui"].kit.components||{},e["taiga-ui"].kit.components["input-number"]={}),e.ng.core,e.ng.forms,e.cdk,e.core$1,e["taiga-ui"].kit.directives,e.angular2TextMask)}(this,(function(e,t,i,n,o,r,a){"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. ***************************************************************************** */var u=function(e,t){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};function l(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var u=e.length-1;u>=0;u--)(o=e[u])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}function s(e,t){return function(i,n){t(i,n,e)}}var c=function(e){function r(t,i){var n=e.call(this,t,i)||this;return n.min=-1/0,n.max=1/0,n.decimal="not-zero",n.precision=2,n.postfix="",n.mask=function(e,t,i,n){return{mask:o.tuiCreateNumberMask({allowNegative:e,allowDecimal:"never"!==t,decimalLimit:i,requireDecimal:"always"===t}),pipe:o.tuiCreateAutoCorrectedNumberPipe("always"===t?i:0,",",n||void 0),guide:!1}},n}var a;return function(e,t){function i(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}(r,e),a=r,Object.defineProperty(r.prototype,"nativeFocusableElement",{get:function(){return!this.primitiveTextfield||this.computedDisabled?null:this.primitiveTextfield.nativeFocusableElement},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"focused",{get:function(){return!!this.primitiveTextfield&&this.primitiveTextfield.focused},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isNegativeAllowed",{get:function(){return this.min<0},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"inputMode",{get:function(){return"never"===this.decimal?"numeric":"decimal"},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"calculatedMaxLength",{get:function(){return 18+("never"!==this.decimal&&this.nativeValue.includes(",")?this.precision+1:0)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"formattedValue",{get:function(){var e=this.value||0,t=Math.abs(e)%1>0,i="always"===this.decimal||t?this.precision:0,n=t?e.toString().split(".")[1].substr(0,this.precision):"";return this.focused&&"always"!==this.decimal&&(i=n.length),o.formatNumber(e,i)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"computedValue",{get:function(){return this.focused||!this.isNativeValueInLimit?this.nativeValue:null===this.value?o.maskedMoneyValueIsEmpty(this.nativeValue)?this.nativeValue:"":this.formattedValue},enumerable:!0,configurable:!0}),r.prototype.onValue=function(e){if(o.maskedMoneyValueIsEmpty(e))this.updateValue(null);else if(!this.isNativeValueNotFinished){var t=this.absoluteCapInputValue(e);null===t||isNaN(t)||(this.updateValue(t),t!==o.maskedNumberStringToNumber(e)&&(this.nativeValue=this.formattedValue))}},r.prototype.onKeyDown=function(e){","!==e.key&&"."!==e.key||("never"!==this.decimal?this.nativeValue.includes(",")&&(e.preventDefault(),this.setCaretAfterComma()):e.preventDefault())},r.prototype.onFocused=function(e){if(this.updateFocused(e),!e){var t=o.maskedNumberStringToNumber(this.nativeValue);if(isNaN(t))this.clear();else{var i=Math.min(this.max,Math.max(this.min,t));this.updateValue(i),this.nativeValue=this.formattedValue}}},r.prototype.onHovered=function(e){this.updateHovered(e)},r.prototype.onPressed=function(e){this.updatePressed(e)},r.prototype.onZero=function(e){var t=this.nativeValue.split(",")[1]||"",i=this.nativeFocusableElement;t.length<this.precision||!i||!i.selectionStart||"0"!==this.nativeValue[i.selectionStart]||(e.preventDefault(),i.selectionStart++)},Object.defineProperty(r.prototype,"isNativeValueInLimit",{get:function(){if(""===this.nativeValue)return!0;var e=o.maskedNumberStringToNumber(this.nativeValue);return e>=this.min&&e<=this.max},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isNativeValueNotFinished",{get:function(){var e=o.maskedNumberStringToNumber(this.nativeValue);return e<0?e>this.max:e<this.min},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"nativeValue",{get:function(){return this.nativeFocusableElement?this.nativeFocusableElement.value:""},set:function(e){this.primitiveTextfield&&this.nativeFocusableElement&&(this.primitiveTextfield.value=e,this.nativeFocusableElement.value=e)},enumerable:!0,configurable:!0}),r.prototype.clear=function(){this.nativeValue="",this.updateValue(null)},r.prototype.absoluteCapInputValue=function(e){var t=o.maskedNumberStringToNumber(e),i=t<0?Math.max(this.min,t):Math.min(t,this.max);return isNaN(i)||i<this.min||i>this.max?null:i},r.prototype.setCaretAfterComma=function(){if(this.nativeFocusableElement){var e=this.nativeValue.length-this.precision;this.nativeFocusableElement.setSelectionRange(e,e)}},r.ctorParameters=function(){return[{type:i.NgControl,decorators:[{type:t.Optional},{type:t.Self},{type:t.Inject,args:[i.NgControl]}]},{type:t.ChangeDetectorRef,decorators:[{type:t.Inject,args:[t.ChangeDetectorRef]}]}]},l([t.Input(),n.tuiDefaultProp()],r.prototype,"min",void 0),l([t.Input(),n.tuiDefaultProp()],r.prototype,"max",void 0),l([t.Input(),n.tuiDefaultProp()],r.prototype,"decimal",void 0),l([t.Input(),n.tuiDefaultProp()],r.prototype,"precision",void 0),l([t.Input(),n.tuiDefaultProp()],r.prototype,"postfix",void 0),l([t.ViewChild(o.TuiPrimitiveTextfieldComponent)],r.prototype,"primitiveTextfield",void 0),l([t.HostListener("keydown.0",["$event"])],r.prototype,"onZero",null),r=a=l([t.Component({selector:"tui-input-number",template:'<tui-primitive-textfield\n class="textfield"\n tuiValueAccessor\n tuiTextfieldInputMode="decimal"\n [pseudoHovered]="pseudoHovered"\n [pseudoFocused]="computedFocused"\n [invalid]="computedInvalid"\n [tuiTextfieldMaxLength]="calculatedMaxLength"\n [readOnly]="readOnly"\n [disabled]="computedDisabled"\n [textMask]="isNegativeAllowed | tuiMapper: mask:decimal:precision:nativeFocusableElement"\n [value]="computedValue"\n [postfix]="postfix"\n [focusable]="focusable"\n (valueChange)="onValue($event)"\n (hoveredChange)="onHovered($event)"\n (focusedChange)="onFocused($event)"\n (pressedChange)="onPressed($event)"\n (keydown)="onKeyDown($event)"\n>\n <ng-content></ng-content>\n</tui-primitive-textfield>\n',changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[{provide:n.TUI_FOCUSABLE_ITEM_ACCESSOR,useExisting:t.forwardRef((function(){return a}))}],styles:[":host{display:block;border-radius:var(--tui-radius-m)}.textfield{border-radius:inherit}"]}),s(0,t.Optional()),s(0,t.Self()),s(0,t.Inject(i.NgControl)),s(1,t.Inject(t.ChangeDetectorRef))],r)}(n.AbstractTuiNullableControl),p=function(){function e(){}return e=l([t.NgModule({imports:[a.TextMaskModule,n.TuiMapperPipeModule,o.TuiPrimitiveTextfieldModule,o.TuiTextfieldControllerModule,r.TuiValueAccessorModule],declarations:[c],exports:[c]})],e)}();e.TuiInputNumberComponent=c,e.TuiInputNumberModule=p,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=taiga-ui-kit-components-input-number.umd.min.js.map