@mobsolutions/ngx-dadata
Version:
[](https://badge.fury.io/js/%40kolkov%2Fngx-dadata) [](https://travis-ci.org/kolkov/ngx-dadata) [![Coverage Stat
2 lines • 6.29 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common/http"),require("rxjs"),require("rxjs/operators"),require("@angular/core"),require("@angular/common"),require("@angular/forms")):"function"==typeof define&&define.amd?define("@mobsolutions/ngx-dadata",["exports","@angular/common/http","rxjs","rxjs/operators","@angular/core","@angular/common","@angular/forms"],e):e((t.mobsolutions=t.mobsolutions||{},t.mobsolutions["ngx-dadata"]={}),t.ng.common.http,t.rxjs,t.rxjs.operators,t.ng.core,t.ng.common,t.ng.forms)}(this,function(t,r,o,n,i,e,a){"use strict";var s={fio:"fio",address:"address",party:"party",bank:"bank",email:"email"},u=(p.prototype.setApiKey=function(t){this.apiKey=t},p.prototype.getData=function(t,e,o){void 0===e&&(e=s.address),void 0===o&&(o=10);var n={headers:new r.HttpHeaders({Accept:"application/json","Content-Type":"application/json",Authorization:"Token "+this.apiKey})},i={query:t,count:o};return this.http.post("https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/"+e,i,n)},p.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],p.ctorParameters=function(){return[{type:r.HttpClient}]},p.ngInjectableDef=i.defineInjectable({factory:function(){return new p(i.inject(r.HttpClient))},token:p,providedIn:"root"}),p);function p(t){this.http=t,this.apiKey=""}var c={apiKey:"",type:s.address,delay:500,limit:10,width:"auto",minWidth:"0"},l={provide:a.NG_VALUE_ACCESSOR,useExisting:i.forwardRef(function(){return d}),multi:!0};var d=(Object.defineProperty(h.prototype,"value",{get:function(){return this.v},set:function(t){t!==this.v&&(this.v=t,this.propagateChange(t))},enumerable:!0,configurable:!0}),h.prototype.ngOnInit=function(){var e=this;this.type=this.config.type,this.dataService.setApiKey(this.apiKey?this.apiKey:this.config.apiKey),this.inputString$.pipe(n.debounce(function(){return o.timer(e.config.delay?e.config.delay:500)})).subscribe(function(t){e.dataService.getData(t,e.type,e.limit).subscribe(function(t){e.data=t.suggestions})})},h.prototype.ngOnChanges=function(t){t.value},h.prototype.getData=function(t){this.inputString$.next(t),this.currentFocus=-1},h.prototype.onClick=function(t,e){this.inputValue.nativeElement.value=e.value,this.propagateChange(e.value),this.inputValue.nativeElement.focus(),this.selectedSuggestion=e,this.data=[],this.currentFocus=-1,this.selected.emit(e)},h.prototype.onOutsideClick=function(){this.data=[]},h.prototype.onArrowDown=function(){this.removeFocus(this.currentFocus),this.currentFocus>=this.data.length-1?this.currentFocus=0:this.currentFocus++,this.setFocus(this.currentFocus)},h.prototype.onArrowUp=function(){this.removeFocus(this.currentFocus),0===this.currentFocus?this.currentFocus=this.data.length-1:this.currentFocus--,this.setFocus(this.currentFocus)},h.prototype.onEnter=function(){this.selectedSuggestion=this.data[this.currentFocus],this.inputValue.nativeElement.value=this.selectedSuggestion.value,this.data=[],this.currentFocus=-1,this.propagateChange(this.selectedSuggestion.value),this.selected.emit(this.selectedSuggestion)},h.prototype.setFocus=function(t){var e=document.getElementById(t+"item");this._r.addClass(e,"active")},h.prototype.removeFocus=function(t){if(-1!==t){var e=document.getElementById(t+"item");this._r.removeClass(e,"active")}},h.prototype.writeValue=function(t){t!==undefined&&(this.v=t)},h.prototype.registerOnChange=function(t){this.propagateChange=t},h.prototype.registerOnTouched=function(t){this.onTouched=t},h.prototype.setDisabledState=function(t){alert("disabled!"),this.disabled=t},h.decorators=[{type:i.Component,args:[{selector:"ngx-dadata",template:'<div class="autocomplete">\r\n <label for="address_input"></label>\r\n <input [disabled]="disabled ? true : null" type="text" class="primary-input" #inputValue (input)="getData(inputValue.value)"\r\n [placeholder]="placeholder" (keyup.ArrowDown)="onArrowDown()" (keyup.ArrowUp)="onArrowUp()"\r\n (keyup.Enter)="onEnter()" spellcheck="false" [(ngModel)]="value" autocomplete="new-password" />\r\n <div *ngIf="data.length">\r\n <div class="autocomplete-items">\r\n <div class="autocomplele-item" *ngFor="let item of data;let i = index" (click)="onClick($event, item)" [id]="i+\'item\'">\r\n {{item.value}}\r\n <ng-template [ngIf]="type===\'party\'">\r\n <br/>\r\n <span>{{item.data?.inn}} {{item.data?.address?.value}}</span>\r\n </ng-template>\r\n </div>\r\n </div>\r\n </div>\r\n</div>\r\n',providers:[l],styles:[".autocomplete{position:relative}.autocomplete-items{position:absolute;border:1px solid #d4d4d4;border-bottom:none;border-top:none;z-index:99;top:100%;left:0;right:0}.autocomplete-items .autocomplele-item{padding:5px 10px;cursor:pointer;background-color:#fff;border-bottom:1px solid #d4d4d4}.autocomplete-items .autocomplele-item:hover{background-color:#e9e9e9}.autocomplete-items .autocomplele-item.active{background-color:#1e90ff!important;color:#fff}.autocomplete-items .autocomplele-item span{color:#555;font-size:80%}"]}]}],h.ctorParameters=function(){return[{type:u},{type:i.Renderer2}]},h.propDecorators={config:[{type:i.Input}],apiKey:[{type:i.Input}],disabled:[{type:i.Input}],type:[{type:i.Input}],limit:[{type:i.Input}],placeholder:[{type:i.Input}],selectedSuggestion:[{type:i.Output}],selected:[{type:i.Output}],inputValue:[{type:i.ViewChild,args:["inputValue"]}],onOutsideClick:[{type:i.HostListener,args:["document:click"]}]},h);function h(t,e){this.dataService=t,this._r=e,this.v="",this.currentFocus=-1,this.data=[],this.config=c,this.disabled=null,this.type=s.address,this.limit=c.limit,this.placeholder="",this.selected=new i.EventEmitter,this.inputString$=new o.Subject,this.onTouched=function(){},this.propagateChange=function(){},this.validateFn=function(){}}var g=(m.decorators=[{type:i.NgModule,args:[{imports:[e.CommonModule,a.FormsModule],declarations:[d],exports:[d]}]}],m);function m(){}t.DadataType=s,t.NgxDadataService=u,t.createDaDataValidator=function f(o){return function(t){var e={rangeError:{given:t.value,expected:o}};return t.value!==o?e:null}},t.NgxDadataComponent=d,t.NgxDadataModule=g,t.DadataConfigDefault=c,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=mobsolutions-ngx-dadata.umd.min.js.map