@angular/material
Version:
Angular Material
30 lines • 18.6 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("@angular/cdk/a11y"),require("@angular/cdk/coercion"),require("@angular/core"),require("@angular/material/core"),require("@angular/common"),require("@angular/cdk/overlay"),require("@angular/cdk/bidi"),require("@angular/cdk/keycodes"),require("@angular/cdk/platform"),require("@angular/cdk/portal"),require("@angular/cdk/scrolling"),require("@angular/forms"),require("@angular/material/form-field"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@angular/material/autocomplete",["exports","tslib","@angular/cdk/a11y","@angular/cdk/coercion","@angular/core","@angular/material/core","@angular/common","@angular/cdk/overlay","@angular/cdk/bidi","@angular/cdk/keycodes","@angular/cdk/platform","@angular/cdk/portal","@angular/cdk/scrolling","@angular/forms","@angular/material/form-field","rxjs","rxjs/operators"],e):e(((t=t||self).ng=t.ng||{},t.ng.material=t.ng.material||{},t.ng.material.autocomplete={}),t.tslib,t.ng.cdk.a11y,t.ng.cdk.coercion,t.ng.core,t.ng.material.core,t.ng.common,t.ng.cdk.overlay,t.ng.cdk.bidi,t.ng.cdk.keycodes,t.ng.cdk.platform,t.ng.cdk.portal,t.ng.cdk.scrolling,t.ng.forms,t.ng.material.formField,t.rxjs,t.rxjs.operators)}(this,(function(t,e,o,i,n,a,r,s,l,p,c,u,h,d,m,_,y){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var g=0,f=function f(t,e){this.source=t,this.option=e},v=a.mixinDisableRipple((function O(){})),b=new n.InjectionToken("mat-autocomplete-default-options",{providedIn:"root",factory:A});function A(){return{autoActiveFirstOption:!1}}var E=function(t){function r(e,o,i){var a=t.call(this)||this;return a._changeDetectorRef=e,a._elementRef=o,a.showPanel=!1,a._isOpen=!1,a.displayWith=null,a.optionSelected=new n.EventEmitter,a.opened=new n.EventEmitter,a.closed=new n.EventEmitter,a._classList={},a.id="mat-autocomplete-"+g++,a._autoActiveFirstOption=!!i.autoActiveFirstOption,a}return e.__extends(r,t),Object.defineProperty(r.prototype,"isOpen",{get:function(){return this._isOpen&&this.showPanel},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"autoActiveFirstOption",{get:function(){return this._autoActiveFirstOption},set:function(t){this._autoActiveFirstOption=i.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"classList",{set:function(t){this._classList=t&&t.length?t.split(" ").reduce((function(t,e){return t[e.trim()]=!0,t}),{}):{},this._setVisibilityClasses(this._classList),this._elementRef.nativeElement.className=""},enumerable:!0,configurable:!0}),r.prototype.ngAfterContentInit=function(){this._keyManager=new o.ActiveDescendantKeyManager(this.options).withWrap(),this._setVisibility()},r.prototype._setScrollTop=function(t){this.panel&&(this.panel.nativeElement.scrollTop=t)},r.prototype._getScrollTop=function(){return this.panel?this.panel.nativeElement.scrollTop:0},r.prototype._setVisibility=function(){this.showPanel=!!this.options.length,this._setVisibilityClasses(this._classList),this._changeDetectorRef.markForCheck()},r.prototype._emitSelectEvent=function(t){var e=new f(this,t);this.optionSelected.emit(e)},r.prototype._setVisibilityClasses=function(t){t["mat-autocomplete-visible"]=this.showPanel,t["mat-autocomplete-hidden"]=!this.showPanel},r.decorators=[{type:n.Component,args:[{selector:"mat-autocomplete",template:'<ng-template>\n <div class="mat-autocomplete-panel" role="listbox" [id]="id" [ngClass]="_classList" #panel>\n <ng-content></ng-content>\n </div>\n</ng-template>\n',encapsulation:n.ViewEncapsulation.None,changeDetection:n.ChangeDetectionStrategy.OnPush,exportAs:"matAutocomplete",inputs:["disableRipple"],host:{class:"mat-autocomplete"},providers:[{provide:a.MAT_OPTION_PARENT_COMPONENT,useExisting:r}],styles:[".mat-autocomplete-panel{min-width:112px;max-width:280px;overflow:auto;-webkit-overflow-scrolling:touch;visibility:hidden;max-width:none;max-height:256px;position:relative;width:100%;border-bottom-left-radius:4px;border-bottom-right-radius:4px}.mat-autocomplete-panel.mat-autocomplete-visible{visibility:visible}.mat-autocomplete-panel.mat-autocomplete-hidden{visibility:hidden}.mat-autocomplete-panel-above .mat-autocomplete-panel{border-radius:0;border-top-left-radius:4px;border-top-right-radius:4px}.mat-autocomplete-panel .mat-divider-horizontal{margin-top:-1px}.cdk-high-contrast-active .mat-autocomplete-panel{outline:solid 1px}\n"]}]}],r.ctorParameters=function(){return[{type:n.ChangeDetectorRef},{type:n.ElementRef},{type:void 0,decorators:[{type:n.Inject,args:[b]}]}]},r.propDecorators={template:[{type:n.ViewChild,args:[n.TemplateRef,{static:!0}]}],panel:[{type:n.ViewChild,args:["panel"]}],options:[{type:n.ContentChildren,args:[a.MatOption,{descendants:!0}]}],optionGroups:[{type:n.ContentChildren,args:[a.MatOptgroup,{descendants:!0}]}],displayWith:[{type:n.Input}],autoActiveFirstOption:[{type:n.Input}],panelWidth:[{type:n.Input}],optionSelected:[{type:n.Output}],opened:[{type:n.Output}],closed:[{type:n.Output}],classList:[{type:n.Input,args:["class"]}]},r}(v),w=function(){function t(t){this.elementRef=t}return t.decorators=[{type:n.Directive,args:[{selector:"[matAutocompleteOrigin]",exportAs:"matAutocompleteOrigin"}]}],t.ctorParameters=function(){return[{type:n.ElementRef}]},t}(),C=new n.InjectionToken("mat-autocomplete-scroll-strategy");
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/function P(t){return function(){return t.scrollStrategies.reposition()}}var T={provide:C,deps:[s.Overlay],useFactory:P},S={provide:d.NG_VALUE_ACCESSOR,useExisting:n.forwardRef((function(){return k})),multi:!0};function R(){return Error("Attempting to open an undefined instance of `mat-autocomplete`. Make sure that the id passed to the `matAutocomplete` is correct and that you're attempting to open it after the ngAfterContentInit hook.")}var k=function(){function t(t,o,i,n,a,r,s,l,p,c){var u=this;this._element=t,this._overlay=o,this._viewContainerRef=i,this._zone=n,this._changeDetectorRef=a,this._dir=s,this._formField=l,this._document=p,this._viewportRuler=c,this._componentDestroyed=!1,this._autocompleteDisabled=!1,this._manuallyFloatingLabel=!1,this._viewportSubscription=_.Subscription.EMPTY,this._canOpenOnNextFocus=!0,this._closeKeyEventStream=new _.Subject,this._windowBlurHandler=function(){u._canOpenOnNextFocus=u._document.activeElement!==u._element.nativeElement||u.panelOpen},this._onChange=function(){},this._onTouched=function(){},this.position="auto",this.autocompleteAttribute="off",this._overlayAttached=!1,this.optionSelections=_.defer((function(){return u.autocomplete&&u.autocomplete.options?_.merge.apply(void 0,e.__spread(u.autocomplete.options.map((function(t){return t.onSelectionChange})))):u._zone.onStable.asObservable().pipe(y.take(1),y.switchMap((function(){return u.optionSelections})))})),this._scrollStrategy=r}return Object.defineProperty(t.prototype,"autocompleteDisabled",{get:function(){return this._autocompleteDisabled},set:function(t){this._autocompleteDisabled=i.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),t.prototype.ngAfterViewInit=function(){var t=this;if("undefined"!=typeof window&&(this._zone.runOutsideAngular((function(){window.addEventListener("blur",t._windowBlurHandler)})),c._supportsShadowDom())){var e=this._element.nativeElement,o=e.getRootNode?e.getRootNode():null;this._isInsideShadowRoot=o instanceof window.ShadowRoot}},t.prototype.ngOnChanges=function(t){t.position&&this._positionStrategy&&(this._setStrategyPositions(this._positionStrategy),this.panelOpen&&this._overlayRef.updatePosition())},t.prototype.ngOnDestroy=function(){"undefined"!=typeof window&&window.removeEventListener("blur",this._windowBlurHandler),this._viewportSubscription.unsubscribe(),this._componentDestroyed=!0,this._destroyPanel(),this._closeKeyEventStream.complete()},Object.defineProperty(t.prototype,"panelOpen",{get:function(){return this._overlayAttached&&this.autocomplete.showPanel},enumerable:!0,configurable:!0}),t.prototype.openPanel=function(){this._attachOverlay(),this._floatLabel()},t.prototype.closePanel=function(){this._resetLabel(),this._overlayAttached&&(this.panelOpen&&this.autocomplete.closed.emit(),this.autocomplete._isOpen=this._overlayAttached=!1,this._overlayRef&&this._overlayRef.hasAttached()&&(this._overlayRef.detach(),this._closingActionsSubscription.unsubscribe()),this._componentDestroyed||this._changeDetectorRef.detectChanges())},t.prototype.updatePosition=function(){this._overlayAttached&&this._overlayRef.updatePosition()},Object.defineProperty(t.prototype,"panelClosingActions",{get:function(){var t=this;return _.merge(this.optionSelections,this.autocomplete._keyManager.tabOut.pipe(y.filter((function(){return t._overlayAttached}))),this._closeKeyEventStream,this._getOutsideClickStream(),this._overlayRef?this._overlayRef.detachments().pipe(y.filter((function(){return t._overlayAttached}))):_.of()).pipe(y.map((function(t){return t instanceof a.MatOptionSelectionChange?t:null})))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"activeOption",{get:function(){return this.autocomplete&&this.autocomplete._keyManager?this.autocomplete._keyManager.activeItem:null},enumerable:!0,configurable:!0}),t.prototype._getOutsideClickStream=function(){var t=this;return _.merge(_.fromEvent(this._document,"click"),_.fromEvent(this._document,"touchend")).pipe(y.filter((function(e){var o=t._isInsideShadowRoot&&e.composedPath?e.composedPath()[0]:e.target,i=t._formField?t._formField._elementRef.nativeElement:null;return t._overlayAttached&&o!==t._element.nativeElement&&(!i||!i.contains(o))&&!!t._overlayRef&&!t._overlayRef.overlayElement.contains(o)})))},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._element.nativeElement.disabled=t},t.prototype._handleKeydown=function(t){var e=t.keyCode;if(e===p.ESCAPE&&t.preventDefault(),this.activeOption&&e===p.ENTER&&this.panelOpen)this.activeOption._selectViaInteraction(),this._resetActiveItem(),t.preventDefault();else if(this.autocomplete){var o=this.autocomplete._keyManager.activeItem,i=e===p.UP_ARROW||e===p.DOWN_ARROW;this.panelOpen||e===p.TAB?this.autocomplete._keyManager.onKeydown(t):i&&this._canOpen()&&this.openPanel(),(i||this.autocomplete._keyManager.activeItem!==o)&&this._scrollToOption()}},t.prototype._handleInput=function(t){var e=t.target,o=e.value;"number"===e.type&&(o=""==o?null:parseFloat(o)),this._previousValue!==o&&(this._previousValue=o,this._onChange(o),this._canOpen()&&this._document.activeElement===t.target&&this.openPanel())},t.prototype._handleFocus=function(){this._canOpenOnNextFocus?this._canOpen()&&(this._previousValue=this._element.nativeElement.value,this._attachOverlay(),this._floatLabel(!0)):this._canOpenOnNextFocus=!0},t.prototype._floatLabel=function(t){void 0===t&&(t=!1),this._formField&&"auto"===this._formField.floatLabel&&(t?this._formField._animateAndLockLabel():this._formField.floatLabel="always",this._manuallyFloatingLabel=!0)},t.prototype._resetLabel=function(){this._manuallyFloatingLabel&&(this._formField.floatLabel="auto",this._manuallyFloatingLabel=!1)},t.prototype._scrollToOption=function(){var t=this.autocomplete._keyManager.activeItemIndex||0,e=a._countGroupLabelsBeforeOption(t,this.autocomplete.options,this.autocomplete.optionGroups);if(0===t&&1===e)this.autocomplete._setScrollTop(0);else{var o=a._getOptionScrollPosition(t+e,48,this.autocomplete._getScrollTop(),256);this.autocomplete._setScrollTop(o)}},t.prototype._subscribeToClosingActions=function(){var t=this,e=this._zone.onStable.asObservable().pipe(y.take(1)),o=this.autocomplete.options.changes.pipe(y.tap((function(){return t._positionStrategy.reapplyLastPosition()})),y.delay(0));return _.merge(e,o).pipe(y.switchMap((function(){var e=t.panelOpen;return t._resetActiveItem(),t.autocomplete._setVisibility(),t.panelOpen&&(t._overlayRef.updatePosition(),e!==t.panelOpen&&t.autocomplete.opened.emit()),t.panelClosingActions})),y.take(1)).subscribe((function(e){return t._setValueAndClose(e)}))},t.prototype._destroyPanel=function(){this._overlayRef&&(this.closePanel(),this._overlayRef.dispose(),this._overlayRef=null)},t.prototype._setTriggerValue=function(t){var e=this.autocomplete&&this.autocomplete.displayWith?this.autocomplete.displayWith(t):t,o=null!=e?e:"";this._formField?this._formField._control.value=o:this._element.nativeElement.value=o,this._previousValue=o},t.prototype._setValueAndClose=function(t){t&&t.source&&(this._clearPreviousSelectedOption(t.source),this._setTriggerValue(t.source.value),this._onChange(t.source.value),this._element.nativeElement.focus(),this.autocomplete._emitSelectEvent(t.source)),this.closePanel()},t.prototype._clearPreviousSelectedOption=function(t){this.autocomplete.options.forEach((function(e){e!=t&&e.selected&&e.deselect()}))},t.prototype._attachOverlay=function(){var t=this;if(!this.autocomplete)throw R();var e=this._overlayRef;e?(this._positionStrategy.setOrigin(this._getConnectedElement()),e.updateSize({width:this._getPanelWidth()})):(this._portal=new u.TemplatePortal(this.autocomplete.template,this._viewContainerRef),e=this._overlay.create(this._getOverlayConfig()),this._overlayRef=e,e.keydownEvents().subscribe((function(e){(e.keyCode===p.ESCAPE||e.keyCode===p.UP_ARROW&&e.altKey)&&(t._resetActiveItem(),t._closeKeyEventStream.next(),e.stopPropagation(),e.preventDefault())})),this._viewportRuler&&(this._viewportSubscription=this._viewportRuler.change().subscribe((function(){t.panelOpen&&e&&e.updateSize({width:t._getPanelWidth()})})))),e&&!e.hasAttached()&&(e.attach(this._portal),this._closingActionsSubscription=this._subscribeToClosingActions());var o=this.panelOpen;this.autocomplete._setVisibility(),this.autocomplete._isOpen=this._overlayAttached=!0,this.panelOpen&&o!==this.panelOpen&&this.autocomplete.opened.emit()},t.prototype._getOverlayConfig=function(){return new s.OverlayConfig({positionStrategy:this._getOverlayPosition(),scrollStrategy:this._scrollStrategy(),width:this._getPanelWidth(),direction:this._dir})},t.prototype._getOverlayPosition=function(){var t=this._overlay.position().flexibleConnectedTo(this._getConnectedElement()).withFlexibleDimensions(!1).withPush(!1);return this._setStrategyPositions(t),this._positionStrategy=t,t},t.prototype._setStrategyPositions=function(t){var e={originX:"start",originY:"bottom",overlayX:"start",overlayY:"top"},o={originX:"start",originY:"top",overlayX:"start",overlayY:"bottom",panelClass:"mat-autocomplete-panel-above"};t.withPositions("above"===this.position?[o]:"below"===this.position?[e]:[e,o])},t.prototype._getConnectedElement=function(){return this.connectedTo?this.connectedTo.elementRef:this._formField?this._formField.getConnectedOverlayOrigin():this._element},t.prototype._getPanelWidth=function(){return this.autocomplete.panelWidth||this._getHostWidth()},t.prototype._getHostWidth=function(){return this._getConnectedElement().nativeElement.getBoundingClientRect().width},t.prototype._resetActiveItem=function(){this.autocomplete._keyManager.setActiveItem(this.autocomplete.autoActiveFirstOption?0:-1)},t.prototype._canOpen=function(){var t=this._element.nativeElement;return!t.readOnly&&!t.disabled&&!this._autocompleteDisabled},t.decorators=[{type:n.Directive,args:[{selector:"input[matAutocomplete], textarea[matAutocomplete]",host:{class:"mat-autocomplete-trigger","[attr.autocomplete]":"autocompleteAttribute","[attr.role]":'autocompleteDisabled ? null : "combobox"',"[attr.aria-autocomplete]":'autocompleteDisabled ? null : "list"',"[attr.aria-activedescendant]":"(panelOpen && activeOption) ? activeOption.id : null","[attr.aria-expanded]":"autocompleteDisabled ? null : panelOpen.toString()","[attr.aria-owns]":"(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id","[attr.aria-haspopup]":"!autocompleteDisabled","(focusin)":"_handleFocus()","(blur)":"_onTouched()","(input)":"_handleInput($event)","(keydown)":"_handleKeydown($event)"},exportAs:"matAutocompleteTrigger",providers:[S]}]}],t.ctorParameters=function(){return[{type:n.ElementRef},{type:s.Overlay},{type:n.ViewContainerRef},{type:n.NgZone},{type:n.ChangeDetectorRef},{type:void 0,decorators:[{type:n.Inject,args:[C]}]},{type:l.Directionality,decorators:[{type:n.Optional}]},{type:m.MatFormField,decorators:[{type:n.Optional},{type:n.Host}]},{type:void 0,decorators:[{type:n.Optional},{type:n.Inject,args:[r.DOCUMENT]}]},{type:h.ViewportRuler}]},t.propDecorators={autocomplete:[{type:n.Input,args:["matAutocomplete"]}],position:[{type:n.Input,args:["matAutocompletePosition"]}],connectedTo:[{type:n.Input,args:["matAutocompleteConnectedTo"]}],autocompleteAttribute:[{type:n.Input,args:["autocomplete"]}],autocompleteDisabled:[{type:n.Input,args:["matAutocompleteDisabled"]}]},t}(),M=function(){function t(){}return t.decorators=[{type:n.NgModule,args:[{imports:[a.MatOptionModule,s.OverlayModule,a.MatCommonModule,r.CommonModule],exports:[E,a.MatOptionModule,k,w,a.MatCommonModule],declarations:[E,k,w],providers:[T]}]}],t}();
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
t.AUTOCOMPLETE_OPTION_HEIGHT=48,t.AUTOCOMPLETE_PANEL_HEIGHT=256,t.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS=b,t.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY=A,t.MAT_AUTOCOMPLETE_SCROLL_STRATEGY=C,t.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY=P,t.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER=T,t.MAT_AUTOCOMPLETE_VALUE_ACCESSOR=S,t.MatAutocomplete=E,t.MatAutocompleteModule=M,t.MatAutocompleteOrigin=w,t.MatAutocompleteSelectedEvent=f,t.MatAutocompleteTrigger=k,t.getMatAutocompleteMissingPanelError=R,Object.defineProperty(t,"__esModule",{value:!0})}));