UNPKG

angular-t9n

Version:
55 lines (52 loc) 20.1 kB
import {I as It,a as at,r as rt,_,C as Ct,w as wt,J}from'./chunk-BVUXkDrv.js';import {v as vt$1}from'./chunk-Cfbj5Ou5.js';import {H as ge,I as ce,N as We$1,b4 as Vv,R as Xo,g,as as gd,ah as le,D,i as xv,bs as G,a9 as ye,G as Gd,at as de,bJ as Ud,e as en,bj as aa,b6 as Qm,bK as Rm,b3 as sd,ax as rd,ay as ey,az as ty,b8 as Jm,bL as ie,X,br as $n,ap as R,a4 as Qd,bb as bG,ar as Js,F,bM as Vd,bN as _a,a7 as pD,a6 as Ee,l as ln,K,j as hD,k as Ai,B as Ba,bO as N,a8 as bv,aw as _S,aW as Va,bd as gD,A as At,a3 as H,V as zt,bP as I8,_ as Z,bQ as Ft,ai as xe,aj as Mo,c as Ym,af as Ql,bR as Mt,bS as At$1,bT as ro,av as Ws,be as na,b7 as Xm,bf as ra,aE as Zb,bH as uC,ag as jo,ae as Vm,a2 as Bn}from'./main-XWPOM5LO.js';import {a as X$1}from'./chunk-BaYJwvwh.js';var We=["panel"],He=["*"];function Ye(a,g){if(a&1&&(na(0,"div",1,0),Xm(2),ra()),a&2){let e=g.id,t=Zb();uC(t._classList),jo("mat-mdc-autocomplete-visible",t.showPanel)("mat-mdc-autocomplete-hidden",!t.showPanel)("mat-autocomplete-panel-animations-enabled",!t._animationsDisabled)("mat-primary",t._color==="primary")("mat-accent",t._color==="accent")("mat-warn",t._color==="warn"),Vm("id",t.id),Ql("aria-label",t.ariaLabel||null)("aria-labelledby",t._getPanelAriaLabelledby(e));}}var P=class{source;option;constructor(g,e){this.source=g,this.option=e;}},Fe=new D("mat-autocomplete-default-options",{providedIn:"root",factory:()=>({autoActiveFirstOption:false,autoSelectActiveOption:false,hideSingleSelectionIndicator:false,requireSelection:false,hasBackdrop:false})}),gt=(()=>{class a{_changeDetectorRef=g(gd);_elementRef=g(le);_defaults=g(Fe);_animationsDisabled=xv();_activeOptionChanges=G.EMPTY;_keyManager;showPanel=false;get isOpen(){return this._isOpen&&this.showPanel}_isOpen=false;_latestOpeningTrigger;_setColor(e){this._color=e,this._changeDetectorRef.markForCheck();}_color;template;panel;options;optionGroups;ariaLabel;ariaLabelledby;displayWith=null;autoActiveFirstOption;autoSelectActiveOption;requireSelection;panelWidth;disableRipple=false;optionSelected=new ye;opened=new ye;closed=new ye;optionActivated=new ye;set classList(e){this._classList=e,this._elementRef.nativeElement.className="";}_classList;get hideSingleSelectionIndicator(){return this._hideSingleSelectionIndicator}set hideSingleSelectionIndicator(e){this._hideSingleSelectionIndicator=e,this._syncParentProperties();}_hideSingleSelectionIndicator;_syncParentProperties(){if(this.options)for(let e of this.options)e._changeDetectorRef.markForCheck();}id=g(Gd).getId("mat-autocomplete-");inertGroups;constructor(){let e=g(de);this.inertGroups=e?.SAFARI||false,this.autoActiveFirstOption=!!this._defaults.autoActiveFirstOption,this.autoSelectActiveOption=!!this._defaults.autoSelectActiveOption,this.requireSelection=!!this._defaults.requireSelection,this._hideSingleSelectionIndicator=this._defaults.hideSingleSelectionIndicator??false;}ngAfterContentInit(){this._keyManager=new Ud(this.options).withWrap().skipPredicate(this._skipPredicate),this._activeOptionChanges=this._keyManager.change.subscribe(e=>{this.isOpen&&this.optionActivated.emit({source:this,option:this.options.toArray()[e]||null});}),this._setVisibility();}ngOnDestroy(){this._keyManager?.destroy(),this._activeOptionChanges.unsubscribe();}_setScrollTop(e){this.panel&&(this.panel.nativeElement.scrollTop=e);}_getScrollTop(){return this.panel?this.panel.nativeElement.scrollTop:0}_setVisibility(){this.showPanel=!!this.options?.length,this._changeDetectorRef.markForCheck();}_emitSelectEvent(e){let t=new P(this,e);this.optionSelected.emit(t);}_getPanelAriaLabelledby(e){if(this.ariaLabel)return null;let t=e?e+" ":"";return this.ariaLabelledby?t+this.ariaLabelledby:e}_skipPredicate(){return false}static \u0275fac=function(t){return new(t||a)};static \u0275cmp=en({type:a,selectors:[["mat-autocomplete"]],contentQueries:function(t,i,o){if(t&1&&Jm(o,J,5)(o,rt,5),t&2){let n;ey(n=ty())&&(i.options=n),ey(n=ty())&&(i.optionGroups=n);}},viewQuery:function(t,i){if(t&1&&rd(Bn,7)(We,5),t&2){let o;ey(o=ty())&&(i.template=o.first),ey(o=ty())&&(i.panel=o.first);}},hostAttrs:[1,"mat-mdc-autocomplete"],inputs:{ariaLabel:[0,"aria-label","ariaLabel"],ariaLabelledby:[0,"aria-labelledby","ariaLabelledby"],displayWith:"displayWith",autoActiveFirstOption:[2,"autoActiveFirstOption","autoActiveFirstOption",aa],autoSelectActiveOption:[2,"autoSelectActiveOption","autoSelectActiveOption",aa],requireSelection:[2,"requireSelection","requireSelection",aa],panelWidth:"panelWidth",disableRipple:[2,"disableRipple","disableRipple",aa],classList:[0,"class","classList"],hideSingleSelectionIndicator:[2,"hideSingleSelectionIndicator","hideSingleSelectionIndicator",aa]},outputs:{optionSelected:"optionSelected",opened:"opened",closed:"closed",optionActivated:"optionActivated"},exportAs:["matAutocomplete"],features:[sd([{provide:at,useExisting:a}])],ngContentSelectors:He,decls:1,vars:0,consts:[["panel",""],["role","listbox",1,"mat-mdc-autocomplete-panel","mdc-menu-surface","mdc-menu-surface--open",3,"id"]],template:function(t,i){t&1&&(Qm(),Rm(0,Ye,3,17,"ng-template"));},styles:[`div.mat-mdc-autocomplete-panel { width: 100%; max-height: 256px; visibility: hidden; transform-origin: center top; overflow: auto; padding: 8px 0; box-sizing: border-box; position: relative; border-radius: var(--mat-autocomplete-container-shape, var(--mat-sys-corner-extra-small)); box-shadow: var(--mat-autocomplete-container-elevation-shadow, 0px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12)); background-color: var(--mat-autocomplete-background-color, var(--mat-sys-surface-container)); } @media (forced-colors: active) { div.mat-mdc-autocomplete-panel { outline: solid 1px; } } .cdk-overlay-pane:not(.mat-mdc-autocomplete-panel-above) div.mat-mdc-autocomplete-panel { border-top-left-radius: 0; border-top-right-radius: 0; } .mat-mdc-autocomplete-panel-above div.mat-mdc-autocomplete-panel { border-bottom-left-radius: 0; border-bottom-right-radius: 0; transform-origin: center bottom; } div.mat-mdc-autocomplete-panel.mat-mdc-autocomplete-visible { visibility: visible; } div.mat-mdc-autocomplete-panel.mat-mdc-autocomplete-hidden, .cdk-overlay-pane:has(> .mat-mdc-autocomplete-hidden) { visibility: hidden; pointer-events: none; } @keyframes _mat-autocomplete-enter { from { opacity: 0; transform: scaleY(0.8); } to { opacity: 1; transform: none; } } .mat-autocomplete-panel-animations-enabled { animation: _mat-autocomplete-enter 120ms cubic-bezier(0, 0, 0.2, 1); } mat-autocomplete { display: none; } `],encapsulation:2})}return a})();var Be={provide:X$1,useExisting:ro(()=>Ke),multi:true};var je=new D("mat-autocomplete-scroll-strategy",{providedIn:"root",factory:()=>{let a=g(X);return ()=>At$1(a)}}),Ke=(()=>{class a{_environmentInjector=g(ie);_element=g(le);_injector=g(X);_viewContainerRef=g($n);_zone=g(R);_changeDetectorRef=g(gd);_dir=g(Qd,{optional:true});_formField=g(vt$1,{optional:true,host:true});_viewportRuler=g(bG);_scrollStrategy=g(je);_renderer=g(Js);_animationsDisabled=xv();_defaults=g(Fe,{optional:true});_overlayRef=null;_portal;_componentDestroyed=false;_initialized=new F;_keydownSubscription;_outsideClickSubscription;_cleanupWindowBlur;_previousValue=null;_valueOnAttach=null;_valueOnLastKeydown=null;_positionStrategy;_manuallyFloatingLabel=false;_closingActionsSubscription;_viewportSubscription=G.EMPTY;_breakpointObserver=g(Vd);_handsetLandscapeSubscription=G.EMPTY;_canOpenOnNextFocus=true;_valueBeforeAutoSelection;_pendingAutoselectedOption=null;_closeKeyEventStream=new F;_overlayPanelClass=_a(this._defaults?.overlayPanelClass||[]);_windowBlurHandler=()=>{this._canOpenOnNextFocus=this.panelOpen||!this._hasFocus();};_onChange=()=>{};_onTouched=()=>{};autocomplete;position="auto";connectedTo;autocompleteAttribute="off";autocompleteDisabled=false;_aboveClass="mat-mdc-autocomplete-panel-above";ngAfterViewInit(){this._initialized.next(),this._initialized.complete(),this._cleanupWindowBlur=this._renderer.listen("window","blur",this._windowBlurHandler);}ngOnChanges(e){e.position&&this._positionStrategy&&(this._setStrategyPositions(this._positionStrategy),this.panelOpen&&this._overlayRef.updatePosition());}ngOnDestroy(){this._cleanupWindowBlur?.(),this._handsetLandscapeSubscription.unsubscribe(),this._viewportSubscription.unsubscribe(),this._componentDestroyed=true,this._destroyPanel(),this._closeKeyEventStream.complete();}get panelOpen(){return this._overlayAttached&&this.autocomplete.showPanel}_overlayAttached=false;openPanel(){this._openPanelInternal();}closePanel(){this._resetLabel(),this._overlayAttached&&(this.panelOpen&&this._zone.run(()=>{this.autocomplete.closed.emit();}),this.autocomplete._latestOpeningTrigger===this&&(this.autocomplete._isOpen=false,this.autocomplete._latestOpeningTrigger=null),this._overlayAttached=false,this._pendingAutoselectedOption=null,this._overlayRef&&this._overlayRef.hasAttached()&&(this._overlayRef.detach(),this._closingActionsSubscription.unsubscribe()),this._updatePanelState(),this._componentDestroyed||this._changeDetectorRef.detectChanges());}updatePosition(){this._overlayAttached&&this._overlayRef.updatePosition();}get panelClosingActions(){return pD(this.optionSelections,this.autocomplete._keyManager.tabOut.pipe(Ee(()=>this._overlayAttached)),this._closeKeyEventStream,this._getOutsideClickStream(),this._overlayRef?this._overlayRef.detachments().pipe(Ee(()=>this._overlayAttached)):ln()).pipe(K(e=>e instanceof _?e:null))}optionSelections=hD(()=>{let e=this.autocomplete?this.autocomplete.options:null;return e?e.changes.pipe(Ai(e),Ba(()=>pD(...e.map(t=>t.onSelectionChange)))):this._initialized.pipe(Ba(()=>this.optionSelections))});get activeOption(){return this.autocomplete&&this.autocomplete._keyManager?this.autocomplete._keyManager.activeItem:null}_getOutsideClickStream(){return new N(e=>{let t=o=>{let n=Mt(o),r=this._formField?this._formField.getConnectedOverlayOrigin().nativeElement:null,E=this.connectedTo?this.connectedTo.elementRef.nativeElement:null;this._overlayAttached&&n!==this._element.nativeElement&&!this._hasFocus()&&(!r||!r.contains(n))&&(!E||!E.contains(n))&&this._overlayRef&&!this._overlayRef.overlayElement.contains(n)&&e.next(o);},i=[this._renderer.listen("document","click",t),this._renderer.listen("document","auxclick",t),this._renderer.listen("document","touchend",t)];return ()=>{i.forEach(o=>o());}})}writeValue(e){Promise.resolve(null).then(()=>this._assignOptionValue(e));}registerOnChange(e){this._onChange=e;}registerOnTouched(e){this._onTouched=e;}setDisabledState(e){this._element.nativeElement.disabled=e;}_handleKeydown(e){let t=e,i=t.keyCode,o=bv(t);if(i===27&&!o&&t.preventDefault(),this._valueOnLastKeydown=this._element.nativeElement.value,this.activeOption&&i===13&&this.panelOpen&&!o)this.activeOption._selectViaInteraction(),this._resetActiveItem(),t.preventDefault();else if(this.autocomplete){let n=this.autocomplete._keyManager.activeItem,r=i===38||i===40;i===9||r&&!o&&this.panelOpen?this.autocomplete._keyManager.onKeydown(t):r&&this._canOpen()&&this._openPanelInternal(this._valueOnLastKeydown),(r||this.autocomplete._keyManager.activeItem!==n)&&(this._scrollToOption(this.autocomplete._keyManager.activeItemIndex||0),this.autocomplete.autoSelectActiveOption&&this.activeOption&&(this._pendingAutoselectedOption||(this._valueBeforeAutoSelection=this._valueOnLastKeydown),this._pendingAutoselectedOption=this.activeOption,this._assignOptionValue(this.activeOption.value)));}}_handleInput(e){let t=e.target,i=t.value;if(t.type==="number"&&(i=i==""?null:parseFloat(i)),this._previousValue!==i){if(this._previousValue=i,this._pendingAutoselectedOption=null,(!this.autocomplete||!this.autocomplete.requireSelection)&&this._onChange(i),!i)this._clearPreviousSelectedOption(null,false);else if(this.panelOpen&&!this.autocomplete.requireSelection){let o=this.autocomplete.options?.find(n=>n.selected);if(o){let n=this._getDisplayValue(o.value);i!==n&&o.deselect(false);}}if(this._canOpen()&&this._hasFocus()){let o=this._valueOnLastKeydown??this._element.nativeElement.value;this._valueOnLastKeydown=null,this._openPanelInternal(o);}}}_handleFocus(){this._canOpenOnNextFocus?this._canOpen()&&(this._previousValue=this._element.nativeElement.value,this._attachOverlay(this._previousValue),this._floatLabel(true)):this._canOpenOnNextFocus=true;}_handleClick(){this._canOpen()&&!this.panelOpen&&this._openPanelInternal();}_hasFocus(){return _S()===this._element.nativeElement}_floatLabel(e=false){this._formField&&this._formField.floatLabel==="auto"&&(e?this._formField._animateAndLockLabel():this._formField.floatLabel="always",this._manuallyFloatingLabel=true);}_resetLabel(){this._manuallyFloatingLabel&&(this._formField&&(this._formField.floatLabel="auto"),this._manuallyFloatingLabel=false);}_subscribeToClosingActions(){let e=new N(i=>{Ws(()=>{i.next();},{injector:this._environmentInjector});}),t=this.autocomplete.options?.changes.pipe(Va(()=>this._positionStrategy.reapplyLastPosition()),gD(0))??ln();return pD(e,t).pipe(Ba(()=>this._zone.run(()=>{let i=this.panelOpen;return this._resetActiveItem(),this._updatePanelState(),this._changeDetectorRef.detectChanges(),this.panelOpen&&this._overlayRef.updatePosition(),i!==this.panelOpen&&(this.panelOpen?this._emitOpened():this.autocomplete.closed.emit()),this.panelClosingActions})),At(1)).subscribe(i=>this._setValueAndClose(i))}_emitOpened(){this.autocomplete.opened.emit();}_destroyPanel(){this._overlayRef&&(this.closePanel(),this._overlayRef.dispose(),this._overlayRef=null);}_getDisplayValue(e){let t=this.autocomplete;return t&&t.displayWith?t.displayWith(e):e}_assignOptionValue(e){let t=this._getDisplayValue(e);e==null&&this._clearPreviousSelectedOption(null,false),this._updateNativeInputValue(t??"");}_updateNativeInputValue(e){this._formField?this._formField._control.value=e:this._element.nativeElement.value=e,this._previousValue=e;}_setValueAndClose(e){let t=this.autocomplete,i=e?e.source:this._pendingAutoselectedOption;i?(this._clearPreviousSelectedOption(i),this._assignOptionValue(i.value),this._onChange(i.value),t._emitSelectEvent(i),this._element.nativeElement.focus()):t.requireSelection&&this._element.nativeElement.value!==this._valueOnAttach&&(this._clearPreviousSelectedOption(null),this._assignOptionValue(null),this._onChange(null)),this.closePanel();}_clearPreviousSelectedOption(e,t){this.autocomplete?.options?.forEach(i=>{i!==e&&i.selected&&i.deselect(t);});}_openPanelInternal(e=this._element.nativeElement.value){this._attachOverlay(e),this._floatLabel();}_attachOverlay(e){if(!this.autocomplete)return;let t=this._overlayRef;t?(this._positionStrategy.setOrigin(this._getConnectedElement()),t.updateSize({width:this._getPanelWidth()})):(this._portal=new H(this.autocomplete.template,this._viewContainerRef,{id:this._formField?.getLabelId()}),t=zt(this._injector,this._getOverlayConfig()),this._overlayRef=t,this._viewportSubscription=this._viewportRuler.change().subscribe(()=>{this.panelOpen&&t&&t.updateSize({width:this._getPanelWidth()});}),this._handsetLandscapeSubscription=this._breakpointObserver.observe(I8.HandsetLandscape).subscribe(o=>{o.matches?this._positionStrategy.withFlexibleDimensions(true).withGrowAfterOpen(true).withViewportMargin(8):this._positionStrategy.withFlexibleDimensions(false).withGrowAfterOpen(false).withViewportMargin(0);})),t&&!t.hasAttached()&&(t.attach(this._portal),this._valueOnAttach=e,this._valueOnLastKeydown=null,this._closingActionsSubscription=this._subscribeToClosingActions());let i=this.panelOpen;this.autocomplete._isOpen=this._overlayAttached=true,this.autocomplete._latestOpeningTrigger=this,this.autocomplete._setColor(this._formField?.color),this._updatePanelState(),this.panelOpen&&i!==this.panelOpen&&this._emitOpened();}_handlePanelKeydown=e=>{(e.keyCode===27&&!bv(e)||e.keyCode===38&&bv(e,"altKey"))&&(this._pendingAutoselectedOption&&(this._updateNativeInputValue(this._valueBeforeAutoSelection??""),this._pendingAutoselectedOption=null),this._closeKeyEventStream.next(),this._resetActiveItem(),e.stopPropagation(),e.preventDefault());};_updatePanelState(){if(this.autocomplete._setVisibility(),this.panelOpen){let e=this._overlayRef;this._keydownSubscription||(this._keydownSubscription=e.keydownEvents().subscribe(this._handlePanelKeydown)),this._outsideClickSubscription||(this._outsideClickSubscription=e.outsidePointerEvents().subscribe());}else this._keydownSubscription?.unsubscribe(),this._outsideClickSubscription?.unsubscribe(),this._keydownSubscription=this._outsideClickSubscription=void 0;}_getOverlayConfig(){return new Z({positionStrategy:this._getOverlayPosition(),scrollStrategy:this._scrollStrategy(),width:this._getPanelWidth(),direction:this._dir??void 0,hasBackdrop:this._defaults?.hasBackdrop,backdropClass:this._defaults?.backdropClass||"cdk-overlay-transparent-backdrop",panelClass:this._overlayPanelClass,disableAnimations:this._animationsDisabled})}_getOverlayPosition(){let e=Ft(this._injector,this._getConnectedElement()).withFlexibleDimensions(false).withPush(false).withPopoverLocation("inline");return this._setStrategyPositions(e),this._positionStrategy=e,e}_setStrategyPositions(e){let t=[{originX:"start",originY:"bottom",overlayX:"start",overlayY:"top"},{originX:"end",originY:"bottom",overlayX:"end",overlayY:"top"}],i=this._aboveClass,o=[{originX:"start",originY:"top",overlayX:"start",overlayY:"bottom",panelClass:i},{originX:"end",originY:"top",overlayX:"end",overlayY:"bottom",panelClass:i}],n;this.position==="above"?n=o:this.position==="below"?n=t:n=[...t,...o],e.withPositions(n);}_getConnectedElement(){return this.connectedTo?this.connectedTo.elementRef:this._formField?this._formField.getConnectedOverlayOrigin():this._element}_getPanelWidth(){return this.autocomplete.panelWidth||this._getHostWidth()}_getHostWidth(){return this._getConnectedElement().nativeElement.getBoundingClientRect().width}_resetActiveItem(){let e=this.autocomplete;if(e.autoActiveFirstOption){let t=-1;for(let i=0;i<e.options.length;i++)if(!e.options.get(i).disabled){t=i;break}e._keyManager.setActiveItem(t);}else e._keyManager.setActiveItem(-1);}_canOpen(){let e=this._element.nativeElement;return !e.readOnly&&!e.disabled&&!this.autocompleteDisabled}_scrollToOption(e){let t=this.autocomplete,i=Ct(e,t.options,t.optionGroups);if(e===0&&i===1)t._setScrollTop(0);else if(t.panel){let o=t.options.toArray()[e];if(o){let n=o._getHostElement(),r=wt(n.offsetTop,n.offsetHeight,t._getScrollTop(),t.panel.nativeElement.offsetHeight);t._setScrollTop(r);}}}static \u0275fac=function(t){return new(t||a)};static \u0275dir=xe({type:a,selectors:[["input","matAutocomplete",""],["textarea","matAutocomplete",""]],hostAttrs:[1,"mat-mdc-autocomplete-trigger"],hostVars:7,hostBindings:function(t,i){t&1&&Ym("focusin",function(){return i._handleFocus()})("blur",function(){return i._onTouched()})("input",function(n){return i._handleInput(n)})("keydown",function(n){return i._handleKeydown(n)})("click",function(){return i._handleClick()}),t&2&&Ql("autocomplete",i.autocompleteAttribute)("role",i.autocompleteDisabled?null:"combobox")("aria-autocomplete",i.autocompleteDisabled?null:"list")("aria-activedescendant",i.panelOpen&&i.activeOption?i.activeOption.id:null)("aria-expanded",i.autocompleteDisabled?null:i.panelOpen.toString())("aria-controls",i.autocompleteDisabled||!i.panelOpen?null:i.autocomplete?.id)("aria-haspopup",i.autocompleteDisabled?null:"listbox");},inputs:{autocomplete:[0,"matAutocomplete","autocomplete"],position:[0,"matAutocompletePosition","position"],connectedTo:[0,"matAutocompleteConnectedTo","connectedTo"],autocompleteAttribute:[0,"autocomplete","autocompleteAttribute"],autocompleteDisabled:[2,"matAutocompleteDisabled","autocompleteDisabled",aa]},exportAs:["matAutocompleteTrigger"],features:[sd([Be]),Mo]})}return a})(),vt=(()=>{class a{static \u0275fac=function(t){return new(t||a)};static \u0275mod=ge({type:a});static \u0275inj=ce({imports:[We$1,It,Vv,It,Xo]})}return a})();export{Ke as K,gt as g,vt as v};