UNPKG

@angular-mdc/web

Version:
22 lines (20 loc) 7.46 kB
/** * @license * Copyright (c) Dominic Carretto * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular-mdc/web/menu-surface"),require("@angular/cdk/coercion"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/list"),require("@angular-mdc/web/dom"),require("@material/menu")):"function"==typeof define&&define.amd?define("@angular-mdc/web/menu",["exports","@angular/core","@angular-mdc/web/menu-surface","@angular/cdk/coercion","rxjs","rxjs/operators","@angular-mdc/web/list","@angular-mdc/web/dom","@material/menu"],t):t(((e=e||self).ng=e.ng||{},e.ng.web=e.ng.web||{},e.ng.web.menu={}),e.ng.core,e.ng.web.menuSurface,e.ng.cdk.coercion,e.rxjs,e.rxjs.operators,e.ng.web.list,e.ng.web.dom,e.mdc.menu)}(this,(function(e,t,n,r,o,i,s,u,c){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function l(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],s=0,u=i.length;s<u;s++,o++)r[o]=i[s];return r}var d=function(e,t){this.index=e,this.source=t},m=0,f=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n._destroyed=new o.Subject,n._uniqueId=c.cssClasses.ROOT+"-"+ ++m,n.id=n._uniqueId,n._wrapFocus=!1,n._closeSurfaceOnSelection=!0,n.selected=new t.EventEmitter,n._menuFoundation=new c.MDCMenuFoundation(n._createAdapter()),n}return function(e,t){function n(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(n,e),Object.defineProperty(n.prototype,"wrapFocus",{get:function(){return this._wrapFocus},set:function(e){var t=r.coerceBooleanProperty(e);t!==this._wrapFocus&&(this._wrapFocus=t,this._list.wrapFocus=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"closeSurfaceOnSelection",{get:function(){return this._closeSurfaceOnSelection},set:function(e){var t=r.coerceBooleanProperty(e);t!==this._closeSurfaceOnSelection&&(this._closeSurfaceOnSelection=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"defaultFocusState",{get:function(){return this._defaultFocusState},set:function(e){e!==this._defaultFocusState&&(this._defaultFocusState=r.coerceNumberProperty(e,0),this._menuFoundation.setDefaultFocusState(this._defaultFocusState))},enumerable:!0,configurable:!0}),n.prototype._createAdapter=function(){var e=this;return Object.assign({addClassToElementAtIndex:function(t,n){return e._list.items.toArray()[t].getListItemElement().classList.add(n)},removeClassFromElementAtIndex:function(t,n){return e._list.items.toArray()[t].getListItemElement().classList.remove(n)},addAttributeToElementAtIndex:function(t,n,r){return e._list.items.toArray()[t].getListItemElement().setAttribute(n,r)},removeAttributeFromElementAtIndex:function(t,n){return e._list.items.toArray()[t].getListItemElement().removeAttribute(n)},elementContainsClass:function(e,t){return e.classList.contains(t)},closeSurface:function(t){e.closeSurfaceOnSelection&&e._foundation.close(t)},getElementIndex:function(t){return e._list.items.toArray().findIndex((function(e){return e.getListItemElement()===t}))},notifySelected:function(t){return e.selected.emit(new d(t.index,e._list.items.toArray()[t.index]))},getMenuItemCount:function(){return e._list.items.toArray().length},focusItemAtIndex:function(t){return e._list.items.toArray()[t].focus()},focusListRoot:function(){return e._list.focus()},isSelectableItemAtIndex:function(t){return!!u.closest(e._list.items.toArray()[t].getListItemElement(),"."+c.cssClasses.MENU_SELECTION_GROUP)},getSelectedSiblingOfItemAtIndex:function(t){var n=u.closest(e._list.items.toArray()[t].getListItemElement(),"."+c.cssClasses.MENU_SELECTION_GROUP).querySelector("."+c.cssClasses.MENU_SELECTED_LIST_ITEM);return n?e._list.items.toArray().findIndex((function(e){return e.elementRef.nativeElement===n})):-1}})},n.prototype.ngAfterContentInit=function(){var e=this;this.initMenuSurface(),this._initList(),this.opened.pipe(i.takeUntil(this._destroyed)).subscribe((function(){return e._menuFoundation.handleMenuSurfaceOpened()}))},n.prototype.ngOnDestroy=function(){this._destroyed.next(),this._destroyed.complete(),this.destroyMenuSurface(),this._menuFoundation.destroy()},n.prototype._handleKeydown=function(e){this._menuFoundation.handleKeydown(e)},n.prototype._initList=function(){var e=this;this._list&&(this._list.setRole("menu"),this._list.wrapFocus=this._wrapFocus,this._list.setTabIndex(-1),this._list.items.changes.pipe(i.takeUntil(this._destroyed)).subscribe((function(){return e._list.items.forEach((function(e){return e.setRole("menuitem")}))})),this._list.actionEvent.pipe(i.takeUntil(this._destroyed)).subscribe((function(t){return e._menuFoundation.handleItemAction(e._list.items.toArray()[t.index].getListItemElement())})))},n.decorators=[{type:t.Component,args:[{selector:"mdc-menu",exportAs:"mdcMenu",host:{"[id]":"id",class:"mdc-menu mdc-menu-surface","(keydown)":"_handleKeydown($event)"},template:"<ng-content></ng-content>",encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],n.propDecorators={id:[{type:t.Input}],wrapFocus:[{type:t.Input}],closeSurfaceOnSelection:[{type:t.Input}],defaultFocusState:[{type:t.Input}],selected:[{type:t.Output}],_list:[{type:t.ContentChild,args:[s.MdcList,{static:!1}]}]},n}(n.MdcMenuSurfaceBase),p=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcMenuSelectionGroup], mdc-menu-selection-group",host:{class:"mdc-menu__selection-group"},exportAs:"mdcMenuSelectionGroup"}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),_=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcMenuSelectionGroupIcon], mdc-menu-selection-group-icon",host:{class:"mdc-menu__selection-group-icon"},exportAs:"mdcMenuSelectionGroupIcon"}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),y=[f,p,_],g=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.MdcMenuSurfaceModule],exports:l(y,[n.MdcMenuSurfaceModule]),declarations:[y]}]}],e}();e.MdcMenu=f,e.MdcMenuModule=g,e.MdcMenuSelectedEvent=d,e.MdcMenuSelectionGroup=p,e.MdcMenuSelectionGroupIcon=_,Object.defineProperty(e,"__esModule",{value:!0})}));