@sd-angular/core
Version:
Sd Angular Core Lib
16 lines (14 loc) • 19 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@angular/forms"),require("uuid"),require("object-hash"),require("rxjs"),require("@sd-angular/core/common"),require("@angular/material/form-field"),require("@angular/material/input"),require("@angular/material/button"),require("@angular/material/icon"),require("@angular/material/tooltip"),require("@sd-angular/core/translate")):"function"==typeof define&&define.amd?define("@sd-angular/core/input-number",["exports","@angular/core","@angular/common","@angular/forms","uuid","object-hash","rxjs","@sd-angular/core/common","@angular/material/form-field","@angular/material/input","@angular/material/button","@angular/material/icon","@angular/material/tooltip","@sd-angular/core/translate"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["sd-angular"]=e["sd-angular"]||{},e["sd-angular"].core=e["sd-angular"].core||{},e["sd-angular"].core["input-number"]={}),e.ng.core,e.ng.common,e.ng.forms,e.uuid,e.hash,e.rxjs,e["sd-angular"].core.common,e.ng.material.formField,e.ng.material.input,e.ng.material.button,e.ng.material.icon,e.ng.material.tooltip,e["sd-angular"].core.translate)}(this,(function(e,t,r,n,o,i,a,l,s,u,c,p,d,f){"use strict";function m(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=m(i);
/*! *****************************************************************************
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 g(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function l(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,l)}s((n=n.apply(e,t||[])).next())}))}function b(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}Object.create;var y,v,C,w,E,I,x,M,k,V,O,F,S;Object.create;function q(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)}function j(e,t,r,n,o){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?o.call(e,r):o?o.value=r:t.set(e,r),r}var T=function(){function e(e){this.formControl=e}return e.prototype.isErrorState=function(e,t){var r,n,o,i=t&&t.submitted;return!(!(null===(r=this.formControl)||void 0===r?void 0:r.invalid)||!((null===(n=this.formControl)||void 0===n?void 0:n.dirty)||(null===(o=this.formControl)||void 0===o?void 0:o.touched)||i))},e}(),P=function(){function e(e,r){var i=this;this.ref=e,this.formConfig=r,this.id="I"+o.v4(),y.set(this,o.v4()),v.set(this,void 0),this.disableErrorMessage=!1,C.set(this,!1),w.set(this,void 0),this.modelChange=new t.EventEmitter,this.isRequired=!1,this.precision=3,this.isReadonly=!1,E.set(this,void 0),this.copyable=!1,this.copied=!1,this.sdChange=new t.EventEmitter,this.sdFocus=new t.EventEmitter,this.sdBlur=new t.EventEmitter,this.sdFocusForceBlur=new t.EventEmitter,this.keyupEnter=new t.EventEmitter,this.formControl=new l.SdFormControl,this.inputControl=new l.SdFormControl,I.set(this,new a.Subscription),this.matcher=new T(this.formControl),this.isFocused=!1,x.set(this,(function(e){var t=e.split(",");return t.length>=2?q(i,M).call(i,t[0])+","+t[1]:q(i,M).call(i,e)})),M.set(this,(function(e){return Number.toVNCurrency(((null==e?void 0:e.toString())||"").replace(/\./g,""))})),k.set(this,(function(e){return+((null==e?void 0:e.toString())||"").replace(/\./g,"").replace(/,/g,".")})),this.reValidate=function(){i.formControl.updateValueAndValidity()},V.set(this,(function(){i.formControl.clearValidators(),i.formControl.clearAsyncValidators();var e=[],t=[];i.isRequired&&e.push(n.Validators.required),(i.minNumber||0===i.minNumber)&&e.push(n.Validators.min(i.minNumber)),(i.maxNumber||0===i.maxNumber)&&e.push(n.Validators.max(i.maxNumber)),q(i,E)&&t.push(q(i,S).call(i,q(i,E))),i.inlineError&&e.push(i.customInlineErrorValidator()),i.formControl.setValidators(e),i.formControl.setAsyncValidators(t),i.formControl.updateValueAndValidity()})),O.set(this,(function(e){j(i,w,null!=e?e:null),i.modelChange.emit(q(i,w)),i.sdChange.emit(q(i,w)),i.formControl.setValue(q(i,w))})),this.onKeyupEnter=function(){var e,t=(null!==(e=i.inputControl.value)&&void 0!==e?e:"").toString();t.length>t.trim().length&&i.inputControl.setValue(t.trim()),i.keyupEnter.emit(i.inputControl.value),q(i,C)&&i.blur()},this.onKeydown=function(e){if(e.ctrlKey&&"v"==e.key)q(i,F).call(i,e,"");else{var t=e.keyCode||e.charCode;8!=t&&46!=t&&37!=t&&39!=t&&35!=t&&36!=t&&9!=t&&(!e.ctrlKey||"c"!=e.key&&"x"!=e.key&&"a"!=e.key)&&(e.shiftKey&&9==t||q(i,F).call(i,e,e.key))}},F.set(this,(function(e,t){var r=e.target.value.split("");r.splice(e.target.selectionStart,e.target.selectionEnd-e.target.selectionStart,t);var n=r.join("");if("positive"===i.type||"-"!==n){var o=new RegExp("^"+i.regex,"g");!n||String(n).match(o)||e.preventDefault()}})),this.onFocus=function(){var e;i.isFocused=!0,i.sdFocus.emit(),(null===(e=i.sdFocusForceBlur.observers)||void 0===e?void 0:e.length)>0&&(i.blur(),i.sdFocusForceBlur.emit())},this.onBlur=function(){var e;i.isFocused=!1;var t=(null!==(e=i.inputControl.value)&&void 0!==e?e:"").toString(),r=t.split(",");r.length>=2&&""==r[1]?i.inputControl.setValue(q(i,M).call(i,r[0])):(t.length>t.trim().length&&i.inputControl.setValue(t.trim()),i.sdBlur.emit(i.formControl.value))},this.onClick=function(){var e;(null===(e=i.sdView)||void 0===e?void 0:e.templateRef)&&(i.formControl.disabled||i.isFocused||i.focus())},this.blur=function(){var e,t;i.isFocused=!1,null===(t=null===(e=i.control)||void 0===e?void 0:e.nativeElement)||void 0===t||t.blur()},this.focus=function(){i.isFocused=!0,setTimeout((function(){var e,t;null===(t=null===(e=i.control)||void 0===e?void 0:e.nativeElement)||void 0===t||t.focus()}),100)},S.set(this,(function(e){return function(t){return g(i,void 0,void 0,(function(){var r,n,o,i;return b(this,(function(a){switch(a.label){case 0:return n=null!==(r=t.value)&&void 0!==r?r:null,e&&"function"==typeof e?(o=e(n))instanceof Promise?[4,o]:[3,2]:[3,3];case 1:return(i=a.sent())?[2,{customValidator:i}]:[2,null];case 2:return o?[2,{customValidator:o}]:[2,null];case 3:return[2,null]}}))}))}}))}return Object.defineProperty(e.prototype,"name",{set:function(e){e&&j(this,y,e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"form",{set:function(e){e&&(e instanceof n.NgForm?j(this,v,e.form):j(this,v,e))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_label",{set:function(e){this.label=e,this.qcId=h.default({selector:"sd-input-number",label:e})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_disableErrorMessage",{set:function(e){this.disableErrorMessage=""===e||e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_blurOnEnter",{set:function(e){j(this,C,""===e||e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"model",{set:function(e){if(q(this,w)!==e)if(j(this,w,e),this.formControl.setValue(q(this,w),{emitEvent:!1}),e||0===e){var t=e.toString().replace(/\./g,",");this.inputControl.setValue(q(this,x).call(this,t),{emitEvent:!1})}else this.inputControl.setValue("",{emitEvent:!1})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"required",{set:function(e){this.isRequired=""===e||e,q(this,V).call(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"readonly",{set:function(e){this.isReadonly=""===e||e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"min",{set:function(e){this.minNumber=e,q(this,V).call(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"max",{set:function(e){this.maxNumber=e,q(this,V).call(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"validator",{set:function(e){j(this,E,e),q(this,V).call(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_inlineError",{set:function(e){this.inlineError=e,q(this,V).call(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{set:function(e){(e=""===e||e)?(this.inputControl.disable(),this.formControl.disable()):(this.inputControl.enable(),this.formControl.enable())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_copyable",{set:function(e){this.copyable=""===e||e},enumerable:!1,configurable:!0}),e.prototype.ngOnInit=function(){var e,t=this;this.appearance=this.appearance||(null===(e=this.formConfig)||void 0===e?void 0:e.appearance),q(this,I).add(this.inputControl.touchChanges.subscribe((function(){t.formControl.markAsTouched(),t.ref.markForCheck()}))),q(this,I).add(this.formControl.sdChanges.subscribe((function(){t.ref.markForCheck()}))),q(this,I).add(this.inputControl.sdChanges.subscribe((function(){t.ref.markForCheck()})))},Object.defineProperty(e.prototype,"regex",{get:function(){var e="(([0-9]+(\\.[0-9])?)+(\\,[0-9]{0,"+this.precision+"}){0,1})$";return 0===this.precision&&(e="(([0-9]+(\\.[0-9])?)+)$"),"negative"===this.type&&(e="[-]"+e),this.type||(e="[-]?"+e),e},enumerable:!1,configurable:!0}),e.prototype.ngAfterViewInit=function(){var e,t=this;q(this,I).add(this.inputControl.valueChanges.subscribe((function(){var e=t.inputControl.value;if(e){var r=q(t,k).call(t,e);isNaN(r)||(t.inputControl.setValue(q(t,x).call(t,e),{emitEvent:!1}),q(t,O).call(t,r))}else q(t,O).call(t,void 0)}))),null===(e=q(this,v))||void 0===e||e.addControl(q(this,y),this.formControl),this.ref.detectChanges()},e.prototype.ngOnDestroy=function(){var e;null===(e=q(this,v))||void 0===e||e.removeControl(q(this,y)),q(this,I).unsubscribe()},e.prototype.customInlineErrorValidator=function(){return function(e){return{inlineError:!0}}},e.prototype.onPaste=function(e){var t=e.clipboardData.getData("text");q(this,F).call(this,e,t)},e.prototype.onCopyText=function(){var e=this;SdUtility.copyToClipboard(this.inputControl.value),this.copied=!0,setTimeout((function(){e.copied=!1}),2e3)},e}();y=new WeakMap,v=new WeakMap,C=new WeakMap,w=new WeakMap,E=new WeakMap,I=new WeakMap,x=new WeakMap,M=new WeakMap,k=new WeakMap,V=new WeakMap,O=new WeakMap,F=new WeakMap,S=new WeakMap,P.decorators=[{type:t.Component,args:[{selector:"sd-input-number",template:'<ng-container *ngIf="!appearance && sdLabelDef?.templateRef">\r\n <ng-container *ngTemplateOutlet="sdLabelDef.templateRef">\r\n </ng-container>\r\n</ng-container>\r\n<label *ngIf="!appearance && label && !sdLabelDef?.templateRef" class="d-block mb-0 T14M">{{label}} <span class="text-danger mb-2"\r\n *ngIf="isRequired">*</span></label>\r\n<div class="d-flex align-items-center" [class.sd-view]="sdView?.templateRef" [class.c-focused]="isFocused"\r\n [class.c-disabled]="formControl.disabled" (click)="onClick()">\r\n <ng-container *ngIf="sdView?.templateRef && !isFocused; else default">\r\n <ng-container *ngTemplateOutlet="sdView.templateRef;context: { value: formControl.value }">\r\n </ng-container>\r\n </ng-container>\r\n <ng-template #default>\r\n <mat-form-field class="sd-md" [ngClass]="{ \'sd-sm\': size === \'sm\', \'no-padding-wrapper\': disableErrorMessage}"\r\n [appearance]="appearance || \'outline\'">\r\n <mat-label *ngIf="appearance && label">{{label}}</mat-label>\r\n <input aria-hidden="true" [id]="id" [formControl]="inputControl" #control matInput\r\n [placeholder]="placeholder || (appearance ? label : \'\')" [errorStateMatcher]="matcher"\r\n (keyup.enter)="onKeyupEnter()" (focus)="onFocus()" (blur)="onBlur()" (keydown)="onKeydown($event)"\r\n [required]="isRequired" [readonly]="isReadonly" [autocomplete]="id" (paste)="onPaste($event)" autocorrect="off"\r\n [attr.data-qclabel]="label" [attr.data-qcid]="qcId">\r\n <ng-container *ngIf="sdSuffix?.templateRef" matSuffix>\r\n <ng-container *ngTemplateOutlet="sdSuffix.templateRef">\r\n </ng-container>\r\n </ng-container>\r\n <ng-content select="[sdSuffixIcon]" matSuffix></ng-content>\r\n <svg \r\n #copyTooltip="matTooltip" \r\n *ngIf="copyable" \r\n matSuffix \r\n [matTooltip]="copied ? \'Copied\' : \'Copy\'" \r\n class="icon-copy" \r\n focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" \r\n (click)="onCopyText()">\r\n <path d="M433.941 65.941l-51.882-51.882A48 48 0 0 0 348.118 0H176c-26.51 0-48 21.49-48 48v48H48c-26.51 0-48 21.49-48 48v320c0 26.51 21.49 48 48 48h224c26.51 0 48-21.49 48-48v-48h80c26.51 0 48-21.49 48-48V99.882a48 48 0 0 0-14.059-33.941zM266 464H54a6 6 0 0 1-6-6V150a6 6 0 0 1 6-6h74v224c0 26.51 21.49 48 48 48h96v42a6 6 0 0 1-6 6zm128-96H182a6 6 0 0 1-6-6V54a6 6 0 0 1 6-6h106v88c0 13.255 10.745 24 24 24h88v202a6 6 0 0 1-6 6zm6-256h-64V48h9.632c1.591 0 3.117.632 4.243 1.757l48.368 48.368a6 6 0 0 1 1.757 4.243V112z"></path>\r\n </svg>\r\n <mat-error *ngIf="formControl?.errors?.required">\r\n <ng-container *ngIf="!disableErrorMessage">{{ "This field is required" | sdTranslate }}</ng-container>\r\n </mat-error>\r\n <mat-error *ngIf="formControl.errors?.min"> \r\n <ng-container *ngIf="!disableErrorMessage">{{\'Không nhập bé hơn \'}} <strong>{{minNumber}}</strong></ng-container>\r\n </mat-error>\r\n <mat-error *ngIf="formControl.errors?.max">\r\n <ng-container *ngIf="!disableErrorMessage">{{\'Không nhập lớn hơn \'}} <strong>{{maxNumber}}</strong></ng-container>\r\n </mat-error>\r\n <mat-error *ngIf="formControl.errors?.customValidator">\r\n <ng-container *ngIf="!disableErrorMessage">{{formControl.errors?.customValidator}}</ng-container>\r\n </mat-error>\r\n <mat-error *ngIf="formControl.errors?.inlineError">\r\n <ng-container *ngIf="!disableErrorMessage">{{inlineError}}</ng-container>\r\n </mat-error>\r\n </mat-form-field>\r\n </ng-template>\r\n</div>\r\n\x3c!-- <sd-popover #error="sdPopover" type="danger" width="300px">\r\n <span *ngIf="formControl.errors?.required">\r\n {{ "This field is required" | sdTranslate }}\r\n </span>\r\n <span *ngIf="formControl.errors?.customValidator">\r\n {{formControl.errors?.customValidator}}\r\n </span>\r\n</sd-popover> --\x3e',changeDetection:t.ChangeDetectionStrategy.OnPush,styles:[":host ::ng-deep .mat-form-field.sd-form-tooltip{width:calc(100% - 30px)}:host ::ng-deep .mat-form-field.no-padding-wrapper .mat-form-field-wrapper{padding-bottom:0}:host ::ng-deep .mat-form-field.mat-form-field-appearance-outline.mat-form-field-disabled .mat-form-field-outline{background:#f6f6f6;color:#e9e9e9}:host ::ng-deep .mat-form-field input.mat-input-element:disabled{color:#4d4d4d!important}:host ::ng-deep .mat-form-field .mat-placeholder-required{color:#f82c13}:host ::ng-deep .mat-form-field:hover .icon-copy{opacity:1}:host ::ng-deep .mat-form-field .icon-copy{cursor:pointer;fill:rgba(0,0,0,.5);height:.9em;opacity:0;transition:opacity .2s linear;width:.9em}.sd-view:not(.c-focused):not(.c-disabled):hover{background-color:#ebecf0}.sd-tooltip{display:inline-block;margin:auto;text-align:center;width:30px}:host{display:block;padding-top:5px}.sd-md:hover .btn-copy{visibility:visible}.btn-copy{background:#e9e9e9!important;font-size:12px;line-height:26px!important;margin-bottom:3px;visibility:hidden}"]}]}],P.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:void 0,decorators:[{type:t.Inject,args:[l.FORM_CONFIG]},{type:t.Optional}]}]},P.propDecorators={name:[{type:t.Input}],size:[{type:t.Input}],form:[{type:t.Input}],_label:[{type:t.Input,args:["label"]}],placeholder:[{type:t.Input}],_disableErrorMessage:[{type:t.Input,args:["disableErrorMessage"]}],_blurOnEnter:[{type:t.Input,args:["blurOnEnter"]}],model:[{type:t.Input}],modelChange:[{type:t.Output}],required:[{type:t.Input}],type:[{type:t.Input}],precision:[{type:t.Input}],readonly:[{type:t.Input}],min:[{type:t.Input}],max:[{type:t.Input}],validator:[{type:t.Input}],_inlineError:[{type:t.Input,args:["inlineError"]}],disabled:[{type:t.Input}],appearance:[{type:t.Input}],copyTooltip:[{type:t.ViewChild,args:["copyTooltip"]}],_copyable:[{type:t.Input,args:["copyable"]}],sdChange:[{type:t.Output}],sdFocus:[{type:t.Output}],sdBlur:[{type:t.Output}],sdFocusForceBlur:[{type:t.Output}],keyupEnter:[{type:t.Output}],control:[{type:t.ViewChild,args:["control"]}],sdView:[{type:t.ContentChild,args:[l.SdViewDefDirective]}],sdSuffix:[{type:t.ContentChild,args:[l.SdSuffixDirective]}],sdLabelDef:[{type:t.ContentChild,args:[l.SdLabelDefDirective]}]};var R=function(){};R.decorators=[{type:t.NgModule,args:[{declarations:[P],imports:[r.CommonModule,n.FormsModule,n.ReactiveFormsModule,s.MatFormFieldModule,u.MatInputModule,p.MatIconModule,d.MatTooltipModule,f.SdTranslateModule,l.SdCommonModule,c.MatButtonModule],exports:[P]}]}],e.SdInputNumber=P,e.SdInputNumberModule=R,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=sd-angular-core-input-number.umd.min.js.map