ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
2 lines • 19.5 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/bidi"),require("@angular/cdk/overlay"),require("@angular/common"),require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/core/no-animation"),require("ng-zorro-antd/core/outlet"),require("ng-zorro-antd/input"),require("ng-zorro-antd/core/util"),require("@angular/cdk/keycodes"),require("@angular/cdk/portal"),require("rxjs"),require("rxjs/operators"),require("ng-zorro-antd/core/animation")):"function"==typeof define&&define.amd?define("ng-zorro-antd/auto-complete",["exports","@angular/cdk/bidi","@angular/cdk/overlay","@angular/common","@angular/core","@angular/forms","ng-zorro-antd/core/no-animation","ng-zorro-antd/core/outlet","ng-zorro-antd/input","ng-zorro-antd/core/util","@angular/cdk/keycodes","@angular/cdk/portal","rxjs","rxjs/operators","ng-zorro-antd/core/animation"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"]["auto-complete"]={}),t.ng.cdk.bidi,t.ng.cdk.overlay,t.ng.common,t.ng.core,t.ng.forms,t["ng-zorro-antd"].core["no-animation"],t["ng-zorro-antd"].core.outlet,t["ng-zorro-antd"].input,t["ng-zorro-antd"].core.util,t.ng.cdk.keycodes,t.ng.cdk.portal,t.rxjs,t.rxjs.operators,t["ng-zorro-antd"].core.animation)}(this,(function(t,e,n,o,i,r,s,a,c,l,p,u,h,d,f){"use strict";var m=function(){};m.decorators=[{type:i.Component,args:[{selector:"nz-auto-optgroup",exportAs:"nzAutoOptgroup",preserveWhitespaces:!1,changeDetection:i.ChangeDetectionStrategy.OnPush,encapsulation:i.ViewEncapsulation.None,template:'\n <div class="ant-select-item ant-select-item-group">\n <ng-container *nzStringTemplateOutlet="nzLabel">{{ nzLabel }}</ng-container>\n </div>\n <ng-content select="nz-auto-option"></ng-content>\n '}]}],m.ctorParameters=function(){return[]},m.propDecorators={nzLabel:[{type:i.Input}]};function g(t,e,n,o){var i,r=arguments.length,s=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(r<3?i(s):r>3?i(e,n,s):i(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}function y(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}Object.create;function v(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,i,r=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}function b(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(v(arguments[e]));return t}Object.create;var z=function(t,e){void 0===e&&(e=!1),this.source=t,this.isUserInput=e},O=function(){function t(t,e,n){this.changeDetectorRef=t,this.element=e,this.nzAutocompleteOptgroupComponent=n,this.nzDisabled=!1,this.selectionChange=new i.EventEmitter,this.mouseEntered=new i.EventEmitter,this.active=!1,this.selected=!1}return t.prototype.select=function(t){void 0===t&&(t=!0),this.selected=!0,this.changeDetectorRef.markForCheck(),t&&this.emitSelectionChangeEvent()},t.prototype.onMouseEnter=function(){this.mouseEntered.emit(this)},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(){l.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 z(this,t))},t}();O.decorators=[{type:i.Component,args:[{selector:"nz-auto-option",exportAs:"nzAutoOption",preserveWhitespaces:!1,changeDetection:i.ChangeDetectionStrategy.OnPush,encapsulation:i.ViewEncapsulation.None,template:'\n <div class="ant-select-item-option-content">\n <ng-content></ng-content>\n </div>\n ',host:{role:"menuitem",class:"ant-select-item ant-select-item-option","[class.ant-select-item-option-grouped]":"nzAutocompleteOptgroupComponent","[class.ant-select-item-option-selected]":"selected","[class.ant-select-item-option-active]":"active","[class.ant-select-item-option-disabled]":"nzDisabled","[attr.aria-selected]":"selected.toString()","[attr.aria-disabled]":"nzDisabled.toString()","(click)":"selectViaInteraction()","(mouseenter)":"onMouseEnter()","(mousedown)":"$event.preventDefault()"}}]}],O.ctorParameters=function(){return[{type:i.ChangeDetectorRef},{type:i.ElementRef},{type:m,decorators:[{type:i.Optional}]}]},O.propDecorators={nzValue:[{type:i.Input}],nzLabel:[{type:i.Input}],nzDisabled:[{type:i.Input}],selectionChange:[{type:i.Output}],mouseEntered:[{type:i.Output}]},g([l.InputBoolean(),y("design:type",Object)],O.prototype,"nzDisabled",void 0);var C={provide:r.NG_VALUE_ACCESSOR,useExisting:i.forwardRef((function(){return S})),multi:!0};function A(){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 S=function(){function t(t,e,n,o,i){this.elementRef=t,this.overlay=e,this.viewContainerRef=n,this.nzInputGroupWhitSuffixOrPrefixDirective=o,this.document=i,this.onChange=function(){},this.onTouched=function(){},this.panelOpen=!1,this.destroy$=new h.Subject,this.overlayRef=null,this.portal=null,this.previousValue=null}return Object.defineProperty(t.prototype,"activeOption",{get:function(){if(this.nzAutocomplete&&this.nzAutocomplete.options.length)return this.nzAutocomplete.activeItem},enumerable:!1,configurable:!0}),t.prototype.ngOnDestroy=function(){this.destroyPanel()},t.prototype.writeValue=function(t){var e=this;Promise.resolve(null).then((function(){return e.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(),this.updateStatus()},t.prototype.closePanel=function(){this.panelOpen&&(this.nzAutocomplete.isOpen=this.panelOpen=!1,this.overlayRef&&this.overlayRef.hasAttached()&&(this.selectionChangeSubscription.unsubscribe(),this.overlayOutsideClickSubscription.unsubscribe(),this.optionsChangeSubscription.unsubscribe(),this.overlayRef.dispose(),this.overlayRef=null,this.portal=null))},t.prototype.handleKeydown=function(t){var e=t.keyCode,n=e===p.UP_ARROW||e===p.DOWN_ARROW;e===p.ESCAPE&&t.preventDefault(),!this.panelOpen||e!==p.ESCAPE&&e!==p.TAB?this.panelOpen&&e===p.ENTER?this.nzAutocomplete.showPanel&&this.activeOption&&(t.preventDefault(),this.activeOption.selectViaInteraction()):this.panelOpen&&n&&this.nzAutocomplete.showPanel&&(t.stopPropagation(),t.preventDefault(),e===p.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.onTouched()},t.prototype.subscribeOptionsChange=function(){var t=this;return this.nzAutocomplete.options.changes.pipe(d.tap((function(){return t.positionStrategy.reapplyLastPosition()})),d.delay(0)).subscribe((function(){t.resetActiveItem(),t.panelOpen&&t.overlayRef.updatePosition()}))},t.prototype.subscribeSelectionChange=function(){var t=this;return this.nzAutocomplete.selectionChange.subscribe((function(e){t.setValueAndClose(e)}))},t.prototype.subscribeOverlayOutsideClick=function(){var t=this;return this.overlayRef.outsidePointerEvents().pipe(d.filter((function(e){return!t.elementRef.nativeElement.contains(e.target)}))).subscribe((function(){t.closePanel()}))},t.prototype.attachOverlay=function(){var t=this;if(!this.nzAutocomplete)throw A();!this.portal&&this.nzAutocomplete.template&&(this.portal=new u.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.selectionChangeSubscription=this.subscribeSelectionChange(),this.optionsChangeSubscription=this.subscribeOptionsChange(),this.overlayOutsideClickSubscription=this.subscribeOverlayOutsideClick(),this.overlayRef.detachments().pipe(d.takeUntil(this.destroy$)).subscribe((function(){t.closePanel()}))),this.nzAutocomplete.isOpen=this.panelOpen=!0},t.prototype.updateStatus=function(){this.overlayRef&&this.overlayRef.updateSize({width:this.nzAutocomplete.nzWidth||this.getHostWidth()}),this.nzAutocomplete.setVisibility(),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(),disposeOnNavigation:!0,scrollStrategy:this.overlay.scrollStrategies.reposition(),width:this.nzAutocomplete.nzWidth||this.getHostWidth()})},t.prototype.getConnectedElement=function(){return this.nzInputGroupWhitSuffixOrPrefixDirective?this.nzInputGroupWhitSuffixOrPrefixDirective.elementRef: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()).withFlexibleDimensions(!1).withPush(!1).withPositions(t).withTransformOriginOn(".ant-select-dropdown"),this.positionStrategy},t.prototype.resetActiveItem=function(){var t=this.nzAutocomplete.getOptionIndex(this.previousValue);this.nzAutocomplete.clearSelectedOptions(null,!0),-1!==t?(this.nzAutocomplete.setActiveItem(t),this.nzAutocomplete.activeItem.select(!1)):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){var e=this.nzAutocomplete.getOption(t),n=e?e.getLabel():t;this.elementRef.nativeElement.value=null!=n?n:"",this.nzAutocomplete.nzBackfill||(this.previousValue=n)},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}();S.decorators=[{type:i.Directive,args:[{selector:"input[nzAutocomplete], textarea[nzAutocomplete]",exportAs:"nzAutocompleteTrigger",providers:[C],host:{autocomplete:"off","aria-autocomplete":"list","(focusin)":"handleFocus()","(blur)":"handleBlur()","(input)":"handleInput($event)","(keydown)":"handleKeydown($event)"}}]}],S.ctorParameters=function(){return[{type:i.ElementRef},{type:n.Overlay},{type:i.ViewContainerRef},{type:c.NzInputGroupWhitSuffixOrPrefixDirective,decorators:[{type:i.Optional}]},{type:void 0,decorators:[{type:i.Optional},{type:i.Inject,args:[o.DOCUMENT]}]}]},S.propDecorators={nzAutocomplete:[{type:i.Input}]};var I=function(){function t(t,e,n,o){var r=this;this.changeDetectorRef=t,this.ngZone=e,this.directionality=n,this.noAnimation=o,this.nzOverlayClassName="",this.nzOverlayStyle={},this.nzDefaultActiveFirstOption=!0,this.nzBackfill=!1,this.compareWith=function(t,e){return t===e},this.selectionChange=new i.EventEmitter,this.showPanel=!0,this.isOpen=!1,this.dir="ltr",this.destroy$=new h.Subject,this.activeItemIndex=-1,this.selectionChangeSubscription=h.Subscription.EMPTY,this.optionMouseEnterSubscription=h.Subscription.EMPTY,this.dataSourceChangeSubscription=h.Subscription.EMPTY,this.optionSelectionChanges=h.defer((function(){return r.options?h.merge.apply(void 0,b(r.options.map((function(t){return t.selectionChange})))):r.ngZone.onStable.asObservable().pipe(d.take(1),d.switchMap((function(){return r.optionSelectionChanges})))})),this.optionMouseEnter=h.defer((function(){return r.options?h.merge.apply(void 0,b(r.options.map((function(t){return t.mouseEntered})))):r.ngZone.onStable.asObservable().pipe(d.take(1),d.switchMap((function(){return r.optionMouseEnter})))}))}return Object.defineProperty(t.prototype,"options",{get:function(){return this.nzDataSource?this.fromDataSourceOptions:this.fromContentOptions},enumerable:!1,configurable:!0}),t.prototype.ngOnInit=function(){var t,e=this;null===(t=this.directionality.change)||void 0===t||t.pipe(d.takeUntil(this.destroy$)).subscribe((function(t){e.dir=t,e.changeDetectorRef.detectChanges()})),this.dir=this.directionality.value},t.prototype.ngAfterContentInit=function(){this.nzDataSource||this.optionsInit()},t.prototype.ngAfterViewInit=function(){this.nzDataSource&&this.optionsInit()},t.prototype.ngOnDestroy=function(){this.dataSourceChangeSubscription.unsubscribe(),this.selectionChangeSubscription.unsubscribe(),this.optionMouseEnterSubscription.unsubscribe(),this.destroy$.next(),this.destroy$.complete()},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){var e=this;return this.options.reduce((function(n,o,i){return-1===n?e.compareWith(t,o.nzValue)?i:-1:n}),-1)},t.prototype.getOption=function(t){var e=this;return this.options.find((function(n){return e.compareWith(t,n.nzValue)}))||null},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(d.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.nzValue),t.clearSelectedOptions(e.source,!0),t.selectionChange.emit(e.source)})),this.optionMouseEnterSubscription.unsubscribe(),this.optionMouseEnterSubscription=this.optionMouseEnter.subscribe((function(e){e.setActiveStyles(),t.activeItem=e,t.activeItemIndex=t.getOptionIndex(t.activeItem.nzValue),t.clearSelectedOptions(e)}))},t}();I.decorators=[{type:i.Component,args:[{selector:"nz-autocomplete",exportAs:"nzAutocomplete",preserveWhitespaces:!1,changeDetection:i.ChangeDetectionStrategy.OnPush,encapsulation:i.ViewEncapsulation.None,template:'\n <ng-template>\n <div\n #panel\n class="ant-select-dropdown ant-select-dropdown-placement-bottomLeft"\n [class.ant-select-dropdown-hidden]="!showPanel"\n [class.ant-select-dropdown-rtl]="dir === \'rtl\'"\n [ngClass]="nzOverlayClassName"\n [ngStyle]="nzOverlayStyle"\n [nzNoAnimation]="noAnimation?.nzNoAnimation"\n [@slideMotion]="\'enter\'"\n [@.disabled]="noAnimation?.nzNoAnimation"\n >\n <div style="max-height: 256px; overflow-y: auto; overflow-anchor: none;">\n <div style="display: flex; flex-direction: column;">\n <ng-template *ngTemplateOutlet="nzDataSource ? optionsTemplate : contentTemplate"></ng-template>\n </div>\n </div>\n </div>\n <ng-template #contentTemplate>\n <ng-content></ng-content>\n </ng-template>\n <ng-template #optionsTemplate>\n <nz-auto-option\n *ngFor="let option of nzDataSource!"\n [nzValue]="option"\n [nzLabel]="option && $any(option).label ? $any(option).label : $any(option)"\n >\n {{ option && $any(option).label ? $any(option).label : $any(option) }}\n </nz-auto-option>\n </ng-template>\n </ng-template>\n ',animations:[f.slideMotion]}]}],I.ctorParameters=function(){return[{type:i.ChangeDetectorRef},{type:i.NgZone},{type:e.Directionality,decorators:[{type:i.Optional}]},{type:s.NzNoAnimationDirective,decorators:[{type:i.Host},{type:i.Optional}]}]},I.propDecorators={nzWidth:[{type:i.Input}],nzOverlayClassName:[{type:i.Input}],nzOverlayStyle:[{type:i.Input}],nzDefaultActiveFirstOption:[{type:i.Input}],nzBackfill:[{type:i.Input}],compareWith:[{type:i.Input}],nzDataSource:[{type:i.Input}],selectionChange:[{type:i.Output}],fromContentOptions:[{type:i.ContentChildren,args:[O,{descendants:!0}]}],fromDataSourceOptions:[{type:i.ViewChildren,args:[O]}],template:[{type:i.ViewChild,args:[i.TemplateRef,{static:!1}]}],panel:[{type:i.ViewChild,args:["panel",{static:!1}]}],content:[{type:i.ViewChild,args:["content",{static:!1}]}]},g([l.InputBoolean(),y("design:type",Object)],I.prototype,"nzDefaultActiveFirstOption",void 0),g([l.InputBoolean(),y("design:type",Object)],I.prototype,"nzBackfill",void 0);var D=function(){};D.decorators=[{type:i.NgModule,args:[{declarations:[I,O,S,m],exports:[I,O,S,m],imports:[e.BidiModule,o.CommonModule,n.OverlayModule,r.FormsModule,a.NzOutletModule,s.NzNoAnimationModule,c.NzInputModule]}]}],t.NZ_AUTOCOMPLETE_VALUE_ACCESSOR=C,t.NzAutocompleteComponent=I,t.NzAutocompleteModule=D,t.NzAutocompleteOptgroupComponent=m,t.NzAutocompleteOptionComponent=O,t.NzAutocompleteTriggerDirective=S,t.NzOptionSelectionChange=z,t.getNzAutocompleteMissingPanelError=A,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-zorro-antd-auto-complete.umd.min.js.map