ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
2 lines • 16.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("ng-zorro-antd/core"),require("@angular/cdk/keycodes"),require("@angular/cdk/overlay"),require("@angular/cdk/portal"),require("@angular/common"),require("@angular/forms"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ng-zorro-antd/auto-complete",["exports","@angular/core","ng-zorro-antd/core","@angular/cdk/keycodes","@angular/cdk/overlay","@angular/cdk/portal","@angular/common","@angular/forms","rxjs","rxjs/operators"],e):e((t["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"]["auto-complete"]={}),t.ng.core,t["ng-zorro-antd"].core,t.ng.cdk.keycodes,t.ng.cdk.overlay,t.ng.cdk.portal,t.ng.common,t.ng.forms,t.rxjs,t.rxjs.operators)}(this,function(t,i,e,o,n,s,r,a,c,l){"use strict";var p=function(){function t(){}return t.decorators=[{type:i.Component,args:[{selector:"nz-auto-optgroup",exportAs:"nzAutoOptgroup",preserveWhitespaces:!1,changeDetection:i.ChangeDetectionStrategy.OnPush,encapsulation:i.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:i.Input}]},t}();function u(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;0<=a;a--)(i=t[a])&&(r=(s<3?i(r):3<s?i(e,n,r):i(e,n))||r);return 3<s&&r&&Object.defineProperty(e,n,r),r}function h(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function d(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||0<e--)&&!(o=s.next()).done;)r.push(o.value)}catch(a){i={error:a}}finally{try{o&&!o.done&&(n=s["return"])&&n.call(s)}finally{if(i)throw i.error}}return r}var m=function(t,e){void 0===e&&(e=!1),this.source=t,this.isUserInput=e},g=function(){function t(t,e){this.changeDetectorRef=t,this.element=e,this.nzDisabled=!1,this.selectionChange=new i.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(){e.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:i.Component,args:[{selector:"nz-auto-option",exportAs:"nzAutoOption",preserveWhitespaces:!1,changeDetection:i.ChangeDetectionStrategy.OnPush,encapsulation:i.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:i.ChangeDetectorRef},{type:i.ElementRef}]},t.propDecorators={nzValue:[{type:i.Input}],nzLabel:[{type:i.Input}],nzDisabled:[{type:i.Input}],selectionChange:[{type:i.Output}]},u([e.InputBoolean(),h("design:type",Object)],t.prototype,"nzDisabled",void 0),t}(),f={provide:a.NG_VALUE_ACCESSOR,useExisting:i.forwardRef(function(){return v}),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 v=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.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===o.UP_ARROW||e===o.DOWN_ARROW;e===o.ESCAPE&&t.preventDefault(),!this.panelOpen||e!==o.ESCAPE&&e!==o.TAB?this.panelOpen&&e===o.ENTER?this.nzAutocomplete.showPanel&&this.activeOption&&(t.preventDefault(),this.activeOption.selectViaInteraction()):this.panelOpen&&n&&this.nzAutocomplete.showPanel&&(t.stopPropagation(),t.preventDefault(),e===o.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=e.value;"number"===e.type&&(n=""===n?null:parseFloat(n)),this.canOpen()&&document.activeElement===t.target&&this.previousValue!==n&&(this.previousValue=n,this._onChange(n),this.openPanel())},t.prototype.handleFocus=function(){this.canOpen()&&(this.previousValue=this.elementRef.nativeElement.value,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 e=this;return this.nzAutocomplete.selectionChange.subscribe(function(t){e.setValueAndClose(t)})},t.prototype.subscribeOverlayBackdropClick=function(){var n=this;return c.merge(c.fromEvent(this.document,"click"),c.fromEvent(this.document,"touchend")).subscribe(function(t){var e=t.target;e!==n.elementRef.nativeElement&&!n.overlayRef.overlayElement.contains(e)&&n.panelOpen&&n.closePanel()})},t.prototype.subscribeOverlayPositionChange=function(){var e=this;return this.positionStrategy.positionChanges.pipe(l.map(function(t){return t.connectionPair.originY}),l.distinct()).subscribe(function(t){e.nzAutocomplete.dropDownPosition=t})},t.prototype.attachOverlay=function(){var t=this;if(!this.nzAutocomplete)throw y();this.portal||(this.portal=new s.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 n.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 n.ConnectionPositionPair({originX:"start",originY:"bottom"},{overlayX:"start",overlayY:"top"}),new n.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||""},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:i.Directive,args:[{selector:"input[nzAutocomplete], textarea[nzAutocomplete]",exportAs:"nzAutocompleteTrigger",providers:[f],host:{autocomplete:"off","aria-autocomplete":"list","(focusin)":"handleFocus()","(blur)":"handleBlur()","(input)":"handleInput($event)","(keydown)":"handleKeydown($event)"}}]}],t.ctorParameters=function(){return[{type:i.ElementRef},{type:n.Overlay},{type:i.ViewContainerRef},{type:undefined,decorators:[{type:i.Optional},{type:i.Inject,args:[r.DOCUMENT]}]}]},t.propDecorators={nzAutocomplete:[{type:i.Input}]},t}(),b=function(){function t(t,e,n){var o=this;this.changeDetectorRef=t,this.ngZone=e,this.noAnimation=n,this.nzOverlayClassName="",this.nzOverlayStyle={},this.nzDefaultActiveFirstOption=!0,this.nzBackfill=!1,this.selectionChange=new i.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 o.options?c.merge.apply(void 0,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(d(arguments[e]));return t}(o.options.map(function(t){return t.selectionChange}))):o.ngZone.onStable.asObservable().pipe(l.take(1),l.switchMap(function(){return o.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(o){return this.options.reduce(function(t,e,n){return-1===t?o===e?n:-1:t},-1)},t.prototype.optionsInit=function(){var e=this;this.setVisibility(),this.subscribeOptionChanges();var t=this.nzDataSource?this.fromDataSourceOptions.changes:this.fromContentOptions.changes;this.dataSourceChangeSubscription=t.subscribe(function(t){!t.dirty&&e.isOpen&&setTimeout(function(){return e.setVisibility()}),e.subscribeOptionChanges()})},t.prototype.clearSelectedOptions=function(e,n){void 0===n&&(n=!1),this.options.forEach(function(t){t!==e&&(n&&t.deselect(),t.setInactiveStyles())})},t.prototype.subscribeOptionChanges=function(){var e=this;this.selectionChangeSubscription.unsubscribe(),this.selectionChangeSubscription=this.optionSelectionChanges.pipe(l.filter(function(t){return t.isUserInput})).subscribe(function(t){t.source.select(),t.source.setActiveStyles(),e.activeItem=t.source,e.activeItemIndex=e.getOptionIndex(e.activeItem),e.clearSelectedOptions(t.source,!0),e.selectionChange.emit(t.source)})},t.decorators=[{type:i.Component,args:[{selector:"nz-autocomplete",exportAs:"nzAutocomplete",preserveWhitespaces:!1,changeDetection:i.ChangeDetectionStrategy.OnPush,encapsulation:i.ViewEncapsulation.None,template:'<ng-template>\n <div class="ant-select-dropdown ant-select-dropdown--single ant-select-dropdown-placement-bottomLeft"\n #panel\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:[e.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:i.ChangeDetectorRef},{type:i.NgZone},{type:e.NzNoAnimationDirective,decorators:[{type:i.Host},{type:i.Optional}]}]},t.propDecorators={nzWidth:[{type:i.Input}],nzOverlayClassName:[{type:i.Input}],nzOverlayStyle:[{type:i.Input}],nzDefaultActiveFirstOption:[{type:i.Input}],nzBackfill:[{type:i.Input}],nzDataSource:[{type:i.Input}],selectionChange:[{type:i.Output}],fromContentOptions:[{type:i.ContentChildren,args:[g,{descendants:!0}]}],fromDataSourceOptions:[{type:i.ViewChildren,args:[g]}],template:[{type:i.ViewChild,args:[i.TemplateRef]}],panel:[{type:i.ViewChild,args:["panel"]}],content:[{type:i.ViewChild,args:["content"]}]},u([e.InputBoolean(),h("design:type",Object)],t.prototype,"nzDefaultActiveFirstOption",void 0),u([e.InputBoolean(),h("design:type",Object)],t.prototype,"nzBackfill",void 0),t}(),C=function(){function t(){}return t.decorators=[{type:i.NgModule,args:[{declarations:[b,g,v,p],exports:[b,g,v,p],imports:[r.CommonModule,n.OverlayModule,a.FormsModule,e.NzAddOnModule,e.NzNoAnimationModule]}]}],t}();t.NzAutocompleteModule=C,t.NzAutocompleteComponent=b,t.getNzAutocompleteMissingPanelError=y,t.NZ_AUTOCOMPLETE_VALUE_ACCESSOR=f,t.NzAutocompleteTriggerDirective=v,t.NzOptionSelectionChange=m,t.NzAutocompleteOptionComponent=g,t.NzAutocompleteOptgroupComponent=p,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ng-zorro-antd-auto-complete.umd.min.js.map