ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
2 lines • 16.9 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/overlay"),require("@angular/common"),require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/core"),require("@angular/cdk/keycodes"),require("@angular/cdk/portal"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ng-zorro-antd/auto-complete",["exports","@angular/cdk/overlay","@angular/common","@angular/core","@angular/forms","ng-zorro-antd/core","@angular/cdk/keycodes","@angular/cdk/portal","rxjs","rxjs/operators"],e):e(((t=t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"]["auto-complete"]={}),t.ng.cdk.overlay,t.ng.common,t.ng.core,t.ng.forms,t["ng-zorro-antd"].core,t.ng.cdk.keycodes,t.ng.cdk.portal,t.rxjs,t.rxjs.operators)}(this,function(t,e,n,o,i,s,r,a,c,l){"use strict";function p(t,e,n,o){var i,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(r=(s<3?i(r):s>3?i(e,n,r):i(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}function u(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function h(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,i,s=n.call(t),r=[];try{for(;(void 0===e||e-- >0)&&!(o=s.next()).done;)r.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}return r}var d=function(){function t(){}return t.decorators=[{type:o.Component,args:[{selector:"nz-auto-optgroup",exportAs:"nzAutoOptgroup",preserveWhitespaces:!1,changeDetection:o.ChangeDetectionStrategy.OnPush,encapsulation:o.ViewEncapsulation.None,template:'<div class="ant-select-dropdown-menu-item-group-title">\n <ng-container *nzStringTemplateOutlet="nzLabel">{{nzLabel}}</ng-container>\n</div>\n<ul class="ant-select-dropdown-menu-item-group-list">\n <ng-content select="nz-auto-option"></ng-content>\n</ul>\n',host:{role:"group",class:"ant-select-dropdown-menu-item-group"}}]}],t.ctorParameters=function(){return[]},t.propDecorators={nzLabel:[{type:o.Input}]},t}();var m=function(t,e){void 0===e&&(e=!1),this.source=t,this.isUserInput=e};var g=function(){function t(t,e){this.changeDetectorRef=t,this.element=e,this.nzDisabled=!1,this.selectionChange=new o.EventEmitter,this.active=!1,this.selected=!1}return t.prototype.select=function(){this.selected=!0,this.changeDetectorRef.markForCheck(),this.emitSelectionChangeEvent()},t.prototype.deselect=function(){this.selected=!1,this.changeDetectorRef.markForCheck(),this.emitSelectionChangeEvent()},t.prototype.getLabel=function(){return this.nzLabel||this.nzValue.toString()},t.prototype.setActiveStyles=function(){this.active||(this.active=!0,this.changeDetectorRef.markForCheck())},t.prototype.setInactiveStyles=function(){this.active&&(this.active=!1,this.changeDetectorRef.markForCheck())},t.prototype.scrollIntoViewIfNeeded=function(){s.scrollIntoView(this.element.nativeElement)},t.prototype.selectViaInteraction=function(){this.nzDisabled||(this.selected=!this.selected,this.selected?this.setActiveStyles():this.setInactiveStyles(),this.emitSelectionChangeEvent(!0),this.changeDetectorRef.markForCheck())},t.prototype.emitSelectionChangeEvent=function(t){void 0===t&&(t=!1),this.selectionChange.emit(new m(this,t))},t.decorators=[{type:o.Component,args:[{selector:"nz-auto-option",exportAs:"nzAutoOption",preserveWhitespaces:!1,changeDetection:o.ChangeDetectionStrategy.OnPush,encapsulation:o.ViewEncapsulation.None,template:"<ng-content></ng-content>",host:{role:"menuitem",class:"ant-select-dropdown-menu-item","[class.ant-select-dropdown-menu-item-selected]":"selected","[class.ant-select-dropdown-menu-item-active]":"active","[class.ant-select-dropdown-menu-item-disabled]":"nzDisabled","[attr.aria-selected]":"selected.toString()","[attr.aria-disabled]":"nzDisabled.toString()","(click)":"selectViaInteraction()","(mousedown)":"$event.preventDefault()"}}]}],t.ctorParameters=function(){return[{type:o.ChangeDetectorRef},{type:o.ElementRef}]},t.propDecorators={nzValue:[{type:o.Input}],nzLabel:[{type:o.Input}],nzDisabled:[{type:o.Input}],selectionChange:[{type:o.Output}]},p([s.InputBoolean(),u("design:type",Object)],t.prototype,"nzDisabled",void 0),t}();var f=function(){function t(t,e,n){var i=this;this.changeDetectorRef=t,this.ngZone=e,this.noAnimation=n,this.nzOverlayClassName="",this.nzOverlayStyle={},this.nzDefaultActiveFirstOption=!0,this.nzBackfill=!1,this.selectionChange=new o.EventEmitter,this.showPanel=!1,this.isOpen=!1,this.dropDownPosition="bottom",this.activeItemIndex=-1,this.selectionChangeSubscription=c.Subscription.EMPTY,this.dataSourceChangeSubscription=c.Subscription.EMPTY,this.optionSelectionChanges=c.defer(function(){return i.options?c.merge.apply(void 0,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(h(arguments[e]));return t}(i.options.map(function(t){return t.selectionChange}))):i.ngZone.onStable.asObservable().pipe(l.take(1),l.switchMap(function(){return i.optionSelectionChanges}))})}return Object.defineProperty(t.prototype,"options",{get:function(){return this.nzDataSource?this.fromDataSourceOptions:this.fromContentOptions},enumerable:!0,configurable:!0}),t.prototype.ngAfterViewInit=function(){this.optionsInit()},t.prototype.ngOnDestroy=function(){this.dataSourceChangeSubscription.unsubscribe(),this.selectionChangeSubscription.unsubscribe()},t.prototype.setVisibility=function(){this.showPanel=!!this.options.length,this.changeDetectorRef.markForCheck()},t.prototype.setActiveItem=function(t){var e=this.options.toArray()[t];e&&!e.active&&(this.activeItem=e,this.activeItemIndex=t,this.clearSelectedOptions(this.activeItem),this.activeItem.setActiveStyles(),this.changeDetectorRef.markForCheck())},t.prototype.setNextItemActive=function(){var t=this.activeItemIndex+1<=this.options.length-1?this.activeItemIndex+1:0;this.setActiveItem(t)},t.prototype.setPreviousItemActive=function(){var t=this.activeItemIndex-1<0?this.options.length-1:this.activeItemIndex-1;this.setActiveItem(t)},t.prototype.getOptionIndex=function(t){return this.options.reduce(function(e,n,o){return-1===e?t===n?o:-1:e},-1)},t.prototype.optionsInit=function(){var t=this;this.setVisibility(),this.subscribeOptionChanges();var e=this.nzDataSource?this.fromDataSourceOptions.changes:this.fromContentOptions.changes;this.dataSourceChangeSubscription=e.subscribe(function(e){!e.dirty&&t.isOpen&&setTimeout(function(){return t.setVisibility()}),t.subscribeOptionChanges()})},t.prototype.clearSelectedOptions=function(t,e){void 0===e&&(e=!1),this.options.forEach(function(n){n!==t&&(e&&n.deselect(),n.setInactiveStyles())})},t.prototype.subscribeOptionChanges=function(){var t=this;this.selectionChangeSubscription.unsubscribe(),this.selectionChangeSubscription=this.optionSelectionChanges.pipe(l.filter(function(t){return t.isUserInput})).subscribe(function(e){e.source.select(),e.source.setActiveStyles(),t.activeItem=e.source,t.activeItemIndex=t.getOptionIndex(t.activeItem),t.clearSelectedOptions(e.source,!0),t.selectionChange.emit(e.source)})},t.decorators=[{type:o.Component,args:[{selector:"nz-autocomplete",exportAs:"nzAutocomplete",preserveWhitespaces:!1,changeDetection:o.ChangeDetectionStrategy.OnPush,encapsulation:o.ViewEncapsulation.None,template:'<ng-template>\n <div class="ant-select-dropdown ant-select-dropdown--single ant-select-dropdown-placement-bottomLeft"\n #panel\n [@.disabled]="noAnimation?.nzNoAnimation"\n [nzNoAnimation]="noAnimation?.nzNoAnimation"\n [@slideMotion]="dropDownPosition"\n [class.ant-select-dropdown-hidden]="!showPanel" [ngClass]="nzOverlayClassName" [ngStyle]="nzOverlayStyle">\n <div style="overflow: auto;">\n <ul class="ant-select-dropdown-menu ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical"\n role="menu"\n aria-activedescendant>\n <ng-template *ngTemplateOutlet="nzDataSource ? optionsTemplate : contentTemplate"></ng-template>\n </ul>\n </div>\n </div>\n <ng-template #contentTemplate>\n <ng-content></ng-content>\n </ng-template>\n <ng-template #optionsTemplate>\n <nz-auto-option *ngFor="let option of nzDataSource" [nzValue]="option">{{option}}</nz-auto-option>\n </ng-template>\n</ng-template>',animations:[s.slideMotion],styles:["\n .ant-select-dropdown {\n top: 100%;\n left: 0;\n position: relative;\n width: 100%;\n margin-top: 4px;\n margin-bottom: 4px;\n }\n "]}]}],t.ctorParameters=function(){return[{type:o.ChangeDetectorRef},{type:o.NgZone},{type:s.NzNoAnimationDirective,decorators:[{type:o.Host},{type:o.Optional}]}]},t.propDecorators={nzWidth:[{type:o.Input}],nzOverlayClassName:[{type:o.Input}],nzOverlayStyle:[{type:o.Input}],nzDefaultActiveFirstOption:[{type:o.Input}],nzBackfill:[{type:o.Input}],nzDataSource:[{type:o.Input}],selectionChange:[{type:o.Output}],fromContentOptions:[{type:o.ContentChildren,args:[g,{descendants:!0}]}],fromDataSourceOptions:[{type:o.ViewChildren,args:[g]}],template:[{type:o.ViewChild,args:[o.TemplateRef,{static:!1}]}],panel:[{type:o.ViewChild,args:["panel",{static:!1}]}],content:[{type:o.ViewChild,args:["content",{static:!1}]}]},p([s.InputBoolean(),u("design:type",Object)],t.prototype,"nzDefaultActiveFirstOption",void 0),p([s.InputBoolean(),u("design:type",Object)],t.prototype,"nzBackfill",void 0),t}();var v={provide:i.NG_VALUE_ACCESSOR,useExisting:o.forwardRef(function(){return b}),multi:!0};function y(){return Error("Attempting to open an undefined instance of `nz-autocomplete`. Make sure that the id passed to the `nzAutocomplete` is correct and that you're attempting to open it after the ngAfterContentInit hook.")}var b=function(){function t(t,e,n,o){this.elementRef=t,this._overlay=e,this.viewContainerRef=n,this.document=o,this._onChange=function(){},this._onTouched=function(){},this.panelOpen=!1}return Object.defineProperty(t.prototype,"activeOption",{get:function(){if(this.nzAutocomplete&&this.nzAutocomplete.options.length)return this.nzAutocomplete.activeItem},enumerable:!0,configurable:!0}),t.prototype.ngOnDestroy=function(){this.destroyPanel()},t.prototype.writeValue=function(t){this.setTriggerValue(t)},t.prototype.registerOnChange=function(t){this._onChange=t},t.prototype.registerOnTouched=function(t){this._onTouched=t},t.prototype.setDisabledState=function(t){this.elementRef.nativeElement.disabled=t,this.closePanel()},t.prototype.openPanel=function(){this.previousValue=this.elementRef.nativeElement.value,this.attachOverlay()},t.prototype.closePanel=function(){this.panelOpen&&(this.nzAutocomplete.isOpen=this.panelOpen=!1,this.overlayRef&&this.overlayRef.hasAttached()&&(this.selectionChangeSubscription.unsubscribe(),this.overlayBackdropClickSubscription.unsubscribe(),this.overlayPositionChangeSubscription.unsubscribe(),this.optionsChangeSubscription.unsubscribe(),this.overlayRef.detach(),this.overlayRef=null,this.portal=null))},t.prototype.handleKeydown=function(t){var e=t.keyCode,n=e===r.UP_ARROW||e===r.DOWN_ARROW;e===r.ESCAPE&&t.preventDefault(),!this.panelOpen||e!==r.ESCAPE&&e!==r.TAB?this.panelOpen&&e===r.ENTER?this.nzAutocomplete.showPanel&&this.activeOption&&(t.preventDefault(),this.activeOption.selectViaInteraction()):this.panelOpen&&n&&this.nzAutocomplete.showPanel&&(t.stopPropagation(),t.preventDefault(),e===r.UP_ARROW?this.nzAutocomplete.setPreviousItemActive():this.nzAutocomplete.setNextItemActive(),this.activeOption&&this.activeOption.scrollIntoViewIfNeeded(),this.doBackfill()):(this.activeOption&&this.activeOption.getLabel()!==this.previousValue&&this.setTriggerValue(this.previousValue),this.closePanel())},t.prototype.handleInput=function(t){var e=t.target,n=this.document,o=e.value;"number"===e.type&&(o=""===o?null:parseFloat(o)),this.previousValue!==o&&(this.previousValue=o,this._onChange(o),this.canOpen()&&n.activeElement===t.target&&this.openPanel())},t.prototype.handleFocus=function(){this.canOpen()&&this.openPanel()},t.prototype.handleBlur=function(){this.closePanel(),this._onTouched()},t.prototype.subscribeOptionsChange=function(){var t=this;return this.nzAutocomplete.options.changes.pipe(l.delay(0)).subscribe(function(){t.resetActiveItem()})},t.prototype.subscribeSelectionChange=function(){var t=this;return this.nzAutocomplete.selectionChange.subscribe(function(e){t.setValueAndClose(e)})},t.prototype.subscribeOverlayBackdropClick=function(){var t=this;return c.merge(c.fromEvent(this.document,"click"),c.fromEvent(this.document,"touchend")).subscribe(function(e){var n=e.target;n!==t.elementRef.nativeElement&&!t.overlayRef.overlayElement.contains(n)&&t.panelOpen&&t.closePanel()})},t.prototype.subscribeOverlayPositionChange=function(){var t=this;return this.positionStrategy.positionChanges.pipe(l.map(function(t){return t.connectionPair.originY}),l.distinct()).subscribe(function(e){t.nzAutocomplete.dropDownPosition=e})},t.prototype.attachOverlay=function(){var t=this;if(!this.nzAutocomplete)throw y();this.portal||(this.portal=new a.TemplatePortal(this.nzAutocomplete.template,this.viewContainerRef)),this.overlayRef||(this.overlayRef=this._overlay.create(this.getOverlayConfig())),this.overlayRef&&!this.overlayRef.hasAttached()&&(this.overlayRef.attach(this.portal),this.overlayPositionChangeSubscription=this.subscribeOverlayPositionChange(),this.selectionChangeSubscription=this.subscribeSelectionChange(),this.overlayBackdropClickSubscription=this.subscribeOverlayBackdropClick(),this.optionsChangeSubscription=this.subscribeOptionsChange()),this.nzAutocomplete.isOpen=this.panelOpen=!0,this.nzAutocomplete.setVisibility(),this.overlayRef.updateSize({width:this.nzAutocomplete.nzWidth||this.getHostWidth()}),setTimeout(function(){t.overlayRef&&t.overlayRef.updatePosition()},150),this.resetActiveItem(),this.activeOption&&this.activeOption.scrollIntoViewIfNeeded()},t.prototype.destroyPanel=function(){this.overlayRef&&this.closePanel()},t.prototype.getOverlayConfig=function(){return new e.OverlayConfig({positionStrategy:this.getOverlayPosition(),scrollStrategy:this._overlay.scrollStrategies.reposition(),width:this.nzAutocomplete.nzWidth||this.getHostWidth()})},t.prototype.getConnectedElement=function(){return this.elementRef},t.prototype.getHostWidth=function(){return this.getConnectedElement().nativeElement.getBoundingClientRect().width},t.prototype.getOverlayPosition=function(){var t=[new e.ConnectionPositionPair({originX:"start",originY:"bottom"},{overlayX:"start",overlayY:"top"}),new e.ConnectionPositionPair({originX:"start",originY:"top"},{overlayX:"start",overlayY:"bottom"})];return this.positionStrategy=this._overlay.position().flexibleConnectedTo(this.getConnectedElement()).withPositions(t).withFlexibleDimensions(!1).withPush(!1),this.positionStrategy},t.prototype.resetActiveItem=function(){var t=this.nzAutocomplete.getOptionIndex(this.nzAutocomplete.activeItem);this.nzAutocomplete.activeItem&&-1!==t?this.nzAutocomplete.setActiveItem(t):this.nzAutocomplete.setActiveItem(this.nzAutocomplete.nzDefaultActiveFirstOption?0:-1)},t.prototype.setValueAndClose=function(t){var e=t.nzValue;this.setTriggerValue(t.getLabel()),this._onChange(e),this.elementRef.nativeElement.focus(),this.closePanel()},t.prototype.setTriggerValue=function(t){this.elementRef.nativeElement.value=t||"",this.nzAutocomplete.nzBackfill||(this.previousValue=t)},t.prototype.doBackfill=function(){this.nzAutocomplete.nzBackfill&&this.nzAutocomplete.activeItem&&this.setTriggerValue(this.nzAutocomplete.activeItem.getLabel())},t.prototype.canOpen=function(){var t=this.elementRef.nativeElement;return!t.readOnly&&!t.disabled},t.decorators=[{type:o.Directive,args:[{selector:"input[nzAutocomplete], textarea[nzAutocomplete]",exportAs:"nzAutocompleteTrigger",providers:[v],host:{autocomplete:"off","aria-autocomplete":"list","(focusin)":"handleFocus()","(blur)":"handleBlur()","(input)":"handleInput($event)","(keydown)":"handleKeydown($event)"}}]}],t.ctorParameters=function(){return[{type:o.ElementRef},{type:e.Overlay},{type:o.ViewContainerRef},{type:void 0,decorators:[{type:o.Optional},{type:o.Inject,args:[n.DOCUMENT]}]}]},t.propDecorators={nzAutocomplete:[{type:o.Input}]},t}();var C=function(){function t(){}return t.decorators=[{type:o.NgModule,args:[{declarations:[f,g,b,d],exports:[f,g,b,d],imports:[n.CommonModule,e.OverlayModule,i.FormsModule,s.NzAddOnModule,s.NzNoAnimationModule]}]}],t}();t.NZ_AUTOCOMPLETE_VALUE_ACCESSOR=v,t.NzAutocompleteComponent=f,t.NzAutocompleteModule=C,t.NzAutocompleteOptgroupComponent=d,t.NzAutocompleteOptionComponent=g,t.NzAutocompleteTriggerDirective=b,t.NzOptionSelectionChange=m,t.getNzAutocompleteMissingPanelError=y,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ng-zorro-antd-auto-complete.umd.min.js.map