UNPKG

@taiga-ui/kit

Version:
16 lines (14 loc) 11 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("rxjs"),require("@angular/common"),require("@taiga-ui/kit/providers"),require("rxjs/operators"),require("@taiga-ui/kit/directives"),require("angular2-text-mask")):"function"==typeof define&&define.amd?define("@taiga-ui/kit/components/input-phone",["exports","@angular/core","@angular/forms","@taiga-ui/cdk","@taiga-ui/core","rxjs","@angular/common","@taiga-ui/kit/providers","rxjs/operators","@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-phone"]={}),e.ng.core,e.ng.forms,e.cdk,e.core$1,e.rxjs,e.ng.common,e["taiga-ui"].kit.providers,e.rxjs.operators,e["taiga-ui"].kit.directives,e.angular2TextMask)}(this,(function(e,t,o,n,r,i,a,u,s,c,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. ***************************************************************************** */var p=function(e,t){return(p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(e,t)};function d(e,t,o,n){var r,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,n);else for(var u=e.length-1;u>=0;u--)(r=e[u])&&(a=(i<3?r(a):i>3?r(t,o,a):r(t,o))||a);return i>3&&a&&Object.defineProperty(t,o,a),a}function h(e,t){return function(o,n){t(o,n,e)}}function f(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var n,r,i=o.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}return a}var g=new t.InjectionToken("A stream of selection changes"),y=[n.TuiDestroyService,u.FIXED_DROPDOWN_CONTROLLER_PROVIDER,{provide:g,deps:[n.TuiDestroyService,a.DOCUMENT],useFactory:v}];function v(e,t){return i.fromEvent(t,"selectionchange").pipe(s.windowToggle(i.merge(i.fromEvent(t,"mouseup"),i.fromEvent(t,"keydown")),(function(){return i.fromEvent(t,"mousedown")})),s.flatMap((function(e){return e.pipe(s.startWith(null))})),s.takeUntil(e))}var m=/[ \-_\(\)]/g,b=function(e){function a(o,n,r){var i=e.call(this,o,n)||this;return i.phoneMaskAfterCountryCode="(###) ###-##-##",i.allowText=!1,i.search="",i.searchChange=new t.EventEmitter,i.textMaskOptions={mask:function(e){return!(i.allowText&&!i.value&&C(e)&&"+"!==e)&&function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(f(arguments[t]));return e}(i.countryCode.split(""),[" "],i.phoneMaskAfterCountryCode.replace(/[^#\- \(\)]+/g,"").split("").map((function(e){return"#"===e?/\d/:e})))},pipe:function(e){return i.allowText?e:""===e&&i.focused&&!i.readOnly?i.countryCode+" ":e.replace(/-$/,"")},guide:!1},i.countryCode="+7",i.open=!1,r.subscribe((function(){i.setCaretPosition()})),i}var u;return function(e,t){function o(){this.constructor=e}p(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}(a,e),u=a,Object.defineProperty(a.prototype,"countryCodeSetter",{set:function(e){this.updateValueWithNewContryCode(e),this.countryCode=e},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"nativeFocusableElement",{get:function(){return!this.textfield||this.computedDisabled?null:this.textfield.nativeFocusableElement},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"focused",{get:function(){return n.isNativeFocused(this.nativeFocusableElement)||!!this.dropdown&&this.dropdown.focused},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"nativeValue",{get:function(){return this.value?r.formatPhone(this.value,this.countryCode,this.phoneMaskAfterCountryCode):this.search||""},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"inputMode",{get:function(){return this.allowText?"text":"numeric"},enumerable:!0,configurable:!0}),a.prototype.onHovered=function(e){this.updateHovered(e)},a.prototype.onDrop=function(e){e.dataTransfer&&(this.setValueWithoutPrefix(e.dataTransfer.getData("text")),e.preventDefault())},a.prototype.onPaste=function(e){this.setValueWithoutPrefix(n.getClipboardDataText(e))},a.prototype.onActiveZone=function(e){this.updateFocused(e),!e||this.nativeValue||this.readOnly||this.allowText?(this.nativeValue===this.countryCode||null!==this.search&&isNaN(parseInt(this.search.replace(m,""),10)))&&this.updateSearch(""):this.updateSearch(this.countryCode)},a.prototype.onBackspace=function(e){(e.target.selectionStart||0)<=this.nonRemovableLength&&e.target.selectionStart===e.target.selectionEnd&&e.preventDefault()},a.prototype.onValueChange=function(e){var t=C(e)?e:e.replace(m,"");this.updateSearch(t),this.updateValue(t===this.countryCode||C(t)?"":t),this.open=!0},a.prototype.handleOption=function(e){this.focusInput(),this.updateValue(e),this.updateSearch(""),this.open=!1},a.prototype.setDisabledState=function(){e.prototype.setDisabledState.call(this),this.open=!1},a.prototype.writeValue=function(t){e.prototype.writeValue.call(this,t),this.updateSearch("")},a.prototype.getFallbackValue=function(){return""},Object.defineProperty(a.prototype,"caretIsInForbiddenArea",{get:function(){var e=this.nativeFocusableElement;if(!e)return!1;var t=e.selectionStart,o=e.selectionEnd;return n.isNativeFocused(e)&&null!==t&&t<this.nonRemovableLength&&t===o},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"nonRemovableLength",{get:function(){return this.isTextValue?0:this.countryCode.length+1},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"maxPhoneLength",{get:function(){return this.countryCode.length+this.phoneMaskAfterCountryCode.replace(/[^#]+/g,"").length},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"isTextValue",{get:function(){return!!this.search&&C(this.search)},enumerable:!0,configurable:!0}),a.prototype.setCaretPosition=function(){this.caretIsInForbiddenArea&&this.nativeFocusableElement&&this.nativeFocusableElement.setSelectionRange(this.nonRemovableLength,this.nonRemovableLength)},a.prototype.setValueWithoutPrefix=function(e){this.readOnly||(this.open=!0,this.updateValue(this.cleanValue(e)),this.updateSearch(this.allowText&&C(e)?e:e.replace(m,"")))},a.prototype.cleanValue=function(e){var t="+7"===this.countryCode?/^7|^8/:new RegExp(this.countryCode.substring(1)),o=this.value.length>this.countryCode.length&&this.value.length<this.maxPhoneLength,n=e.replace(m,"").length,r=e.replace(/[^0-9]+/g,""),i=getSelection().toString().length;return o&&0===i?(""+this.value+r).slice(0,this.maxPhoneLength):n<this.maxPhoneLength-1?(""+this.countryCode+r).slice(0,this.maxPhoneLength):(""+this.countryCode+r.replace(t,"")).slice(0,this.maxPhoneLength)},a.prototype.focusInput=function(){this.nativeFocusableElement&&n.setNativeFocused(this.nativeFocusableElement,!0,!0)},a.prototype.updateSearch=function(e){this.search!==e&&(this.search=e,this.searchChange.emit(e))},a.prototype.updateValueWithNewContryCode=function(e){this.isTextValue||this.updateValue(this.value.replace(this.countryCode,e))},a.ctorParameters=function(){return[{type:o.NgControl,decorators:[{type:t.Optional},{type:t.Self},{type:t.Inject,args:[o.NgControl]}]},{type:t.ChangeDetectorRef,decorators:[{type:t.Inject,args:[t.ChangeDetectorRef]}]},{type:i.Observable,decorators:[{type:t.Inject,args:[g]}]}]},d([t.Input("countryCode"),n.tuiRequiredSetter()],a.prototype,"countryCodeSetter",null),d([t.Input(),n.tuiDefaultProp()],a.prototype,"phoneMaskAfterCountryCode",void 0),d([t.Input(),n.tuiDefaultProp()],a.prototype,"allowText",void 0),d([t.Input(),n.tuiDefaultProp()],a.prototype,"search",void 0),d([t.Output()],a.prototype,"searchChange",void 0),d([t.ContentChild(r.TuiDataListDirective,{read:t.TemplateRef})],a.prototype,"datalist",void 0),d([t.ViewChild(r.TuiHostedDropdownComponent)],a.prototype,"dropdown",void 0),d([t.ViewChild(r.TuiPrimitiveTextfieldComponent)],a.prototype,"textfield",void 0),a=u=d([t.Component({selector:"tui-input-phone",template:'<tui-hosted-dropdown\n class="hosted"\n [content]="datalist || \'\'"\n [(open)]="open"\n (tuiActiveZoneChange)="onActiveZone($event)"\n>\n <tui-primitive-textfield\n class="textfield"\n tuiValueAccessor\n tuiTextfieldType="tel"\n [tuiTextfieldInputMode]="inputMode"\n [pseudoHovered]="pseudoHovered"\n [pseudoFocused]="computedFocused"\n [invalid]="computedInvalid"\n [nativeId]="nativeId"\n [readOnly]="readOnly"\n [disabled]="computedDisabled"\n [focusable]="focusable"\n [textMask]="textMaskOptions"\n [value]="nativeValue"\n (valueChange)="onValueChange($event)"\n (hoveredChange)="onHovered($event)"\n (drop)="onDrop($event)"\n (keydown.backspace)="onBackspace($event)"\n (paste.prevent)="onPaste($event)"\n >\n <ng-content></ng-content>\n </tui-primitive-textfield>\n</tui-hosted-dropdown>\n',changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[{provide:n.TUI_FOCUSABLE_ITEM_ACCESSOR,useExisting:t.forwardRef((function(){return u}))},{provide:r.TUI_DATA_LIST_HOST,useExisting:t.forwardRef((function(){return u}))},y],styles:[":host{display:block;border-radius:var(--tui-radius-m)}:host._disabled{pointer-events:none}.hosted{display:block;border-radius:inherit}.textfield{border-radius:inherit}"]}),h(0,t.Optional()),h(0,t.Self()),h(0,t.Inject(o.NgControl)),h(1,t.Inject(t.ChangeDetectorRef)),h(2,t.Inject(g))],a)}(n.AbstractTuiControl);function C(e){return isNaN(parseInt(e.replace(m,""),10))}var x=function(){function e(){}return e=d([t.NgModule({imports:[l.TextMaskModule,r.TuiPrimitiveTextfieldModule,r.TuiHostedDropdownModule,r.TuiTextfieldControllerModule,n.TuiActiveZoneModule,c.TuiValueAccessorModule],declarations:[b],exports:[b]})],e)}();e.INPUT_PHONE_PROVIDERS=y,e.SELECTION_STREAM=g,e.TuiInputPhoneComponent=b,e.TuiInputPhoneModule=x,e.selectionStreamFactory=v,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=taiga-ui-kit-components-input-phone.umd.min.js.map