UNPKG

@angular-mdc/web

Version:
22 lines (20 loc) 20.2 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/common"),require("@angular/cdk/coercion"),require("@angular/cdk/platform"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/base"),require("@angular/cdk/keycodes"),require("@material/ripple"),require("@angular-mdc/web/ripple"),require("@angular-mdc/web/dom"),require("@material/list")):"function"==typeof define&&define.amd?define("@angular-mdc/web/list",["exports","@angular/core","@angular/common","@angular/cdk/coercion","@angular/cdk/platform","rxjs","rxjs/operators","@angular-mdc/web/base","@angular/cdk/keycodes","@material/ripple","@angular-mdc/web/ripple","@angular-mdc/web/dom","@material/list"],t):t(((e=e||self).ng=e.ng||{},e.ng.web=e.ng.web||{},e.ng.web.list={}),e.ng.core,e.ng.common,e.ng.cdk.coercion,e.ng.cdk.platform,e.rxjs,e.rxjs.operators,e.ng.web.base,e.ng.cdk.keycodes,e.mdc.ripple,e.ng.web.ripple,e.ng.web.dom,e.mdc.list)}(this,(function(e,t,n,i,r,o,s,c,a,u,l,p,d){"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 m=function(e,t){return(m=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)};var f=function(){return(f=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},h=function(){function e(e){this.elementRef=e,this._inset=!1,this._padded=!1}return Object.defineProperty(e.prototype,"inset",{get:function(){return this._inset},set:function(e){this._inset=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"padded",{get:function(){return this._padded},set:function(e){this._padded=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),e.decorators=[{type:t.Component,args:[{selector:"[mdcListDivider], mdc-list-divider",exportAs:"mdcListDivider",host:{role:"separator",class:"mdc-list-divider","[class.mdc-list-divider--inset]":"inset","[class.mdc-list-divider--padded]":"padded"},template:"",encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={inset:[{type:t.Input}],padded:[{type:t.Input}]},e}(),y=function(e){this.source=e},g=new t.InjectionToken("MDC_LIST_PARENT_COMPONENT"),_=0,b=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcListItemGraphic], mdc-list-item-graphic",exportAs:"mdcListItemGraphic",host:{role:"presentation",class:"mdc-list-item__graphic","[attr.aria-hidden]":"true"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),v=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcListItemMeta], mdc-list-item-meta",exportAs:"mdcListItemMeta",host:{class:"mdc-list-item__meta"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),I=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Component,args:[{selector:"[mdcListItemText], mdc-list-item-text",exportAs:"mdcListItemText",host:{class:"mdc-list-item__text"},template:'\n <ng-container>\n <span class="mdc-list-item__primary-text"><ng-content></ng-content></span>\n <span class="mdc-list-item__secondary-text" *ngIf="secondaryText">{{secondaryText}}</span>\n </ng-container>',encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={secondaryText:[{type:t.Input}]},e}(),E=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcListItemSecondary], mdc-list-item-secondary",exportAs:"mdcListItemSecondary",host:{class:"mdc-list-item__secondary-text"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),L=function(){function e(e,n,i,r){this.ripple=e,this._changeDetectorRef=n,this.elementRef=i,this._parent=r,this._id="mdc-list-item-"+_++,this.tabIndex=-1,this._selected=!1,this._activated=!1,this._disabled=!1,this.selectionChange=new t.EventEmitter,this._root=this.elementRef.nativeElement,this.ripple=this._createRipple(),this.ripple.init()}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"selected",{get:function(){return this._selected},set:function(e){var t=i.coerceBooleanProperty(e);t!==this._selected&&(this._selected=t,this._changeDetectorRef.markForCheck())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"activated",{get:function(){return this._activated},set:function(e){var t=i.coerceBooleanProperty(e);t!==this._activated&&(this._activated=t,this._changeDetectorRef.markForCheck())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){return this._disabled},set:function(e){var t=i.coerceBooleanProperty(e);t!==this._disabled&&(this._disabled=t,this._changeDetectorRef.markForCheck())},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){this.ripple.destroy()},e.prototype._createRipple=function(){var e=this,t=f(f({},l.MdcRipple.createAdapter(this)),{isSurfaceDisabled:function(){return e._disabled||e._parent.disableRipple}});return new l.MdcRipple(this.elementRef,new u.MDCRippleFoundation(t))},e.prototype.focus=function(){this.getListItemElement().focus()},e.prototype.setRole=function(e){this.getListItemElement().setAttribute("role",e)},e.prototype.getListItemElement=function(){return this.elementRef.nativeElement},e.prototype._onKeydown=function(e){e.keyCode!==a.ENTER&&e.keyCode!==a.SPACE||this._emitChangeEvent()},e.prototype._emitChangeEvent=function(){this._disabled||this.selectionChange.emit(new y(this))},e.decorators=[{type:t.Component,args:[{selector:"mdc-list-item, a[mdc-list-item]",exportAs:"mdcListItem",host:{role:"listitem","[id]":"id","[tabIndex]":"tabIndex",class:"mdc-list-item","[attr.data-value]":"value","[class.mdc-list-item--selected]":"selected","[class.mdc-list-item--activated]":"activated","[class.mdc-list-item--disabled]":"disabled","(click)":"_emitChangeEvent()","(keydown)":"_onKeydown($event)"},template:"<ng-content></ng-content>",encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[l.MdcRipple]}]}],e.ctorParameters=function(){return[{type:l.MdcRipple},{type:t.ChangeDetectorRef},{type:t.ElementRef},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[g]}]}]},e.propDecorators={value:[{type:t.Input}],tabIndex:[{type:t.Input}],selected:[{type:t.Input}],activated:[{type:t.Input}],disabled:[{type:t.Input}],selectionChange:[{type:t.Output}]},e}(),C=function(e,t){this.source=e,this.option=t},S=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Component,args:[{selector:"[mdcListGroup], mdc-list-group",exportAs:"mdcListGroup",host:{class:"mdc-list-group"},template:'\n <h3 class="mdc-list-group__subheader" *ngIf="subheader">{{subheader}}</h3>\n <ng-content></ng-content>',encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={subheader:[{type:t.Input}]},e}(),x=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcListGroupSubheader], mdc-list-group-subheader",exportAs:"mdcListGroupSubheader",host:{class:"mdc-list-group__subheader"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),O=function(e){function n(n,i,r){var o=e.call(this,r)||this;return o._platform=n,o._changeDetectorRef=i,o.elementRef=r,o._twoLine=!1,o._dense=!1,o._border=!1,o._avatar=!1,o._interactive=!0,o._disableRipple=!1,o._useActivatedClass=!1,o._useSelectedClass=!1,o._verticalOrientation=!0,o._wrapFocus=!1,o.selectionChange=new t.EventEmitter,o.actionEvent=new t.EventEmitter,o._changeSubscription=null,o.itemSelectionSubscription=null,o}return function(e,t){function n(){this.constructor=e}m(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(n,e),Object.defineProperty(n.prototype,"twoLine",{get:function(){return this._twoLine},set:function(e){this._twoLine=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"dense",{get:function(){return this._dense},set:function(e){this._dense=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"border",{get:function(){return this._border},set:function(e){this._border=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"avatar",{get:function(){return this._avatar},set:function(e){this._avatar=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"interactive",{get:function(){return this._interactive},set:function(e){var t=i.coerceBooleanProperty(e);t!==this._interactive&&(this._interactive=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disableRipple",{get:function(){return this._disableRipple},set:function(e){var t=i.coerceBooleanProperty(e);t!==this._disableRipple&&(this._disableRipple=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"singleSelection",{get:function(){return this._singleSelection},set:function(e){if(void 0!==e){var t=i.coerceBooleanProperty(e);t!==this._singleSelection&&(this._singleSelection=t,this._foundation.setSingleSelection(this._singleSelection),this._changeDetectorRef.markForCheck())}},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"useActivatedClass",{get:function(){return this._useActivatedClass},set:function(e){this._useActivatedClass=i.coerceBooleanProperty(e),this._foundation.setUseActivatedClass(this._useActivatedClass),this._changeDetectorRef.markForCheck()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"useSelectedClass",{get:function(){return this._useSelectedClass},set:function(e){this._useSelectedClass=i.coerceBooleanProperty(e),this._changeDetectorRef.markForCheck()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"verticalOrientation",{get:function(){return this._verticalOrientation},set:function(e){this._verticalOrientation=i.coerceBooleanProperty(e),this._foundation.setVerticalOrientation(this._verticalOrientation),this._changeDetectorRef.markForCheck()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"wrapFocus",{get:function(){return this._wrapFocus},set:function(e){this._wrapFocus=i.coerceBooleanProperty(e),this._foundation.setWrapFocus(this._wrapFocus),this._changeDetectorRef.markForCheck()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"listItemSelections",{get:function(){return o.merge.apply(void 0,this.items.map((function(e){return e.selectionChange})))},enumerable:!0,configurable:!0}),n.prototype.getDefaultFoundation=function(){var e=this,t={getListItemCount:function(){return e.items.length},getFocusedElementIndex:function(){return!e._platform.isBrowser&&document.activeElement?-1:e.items.toArray().findIndex((function(e){return e.getListItemElement()===document.activeElement}))||-1},setAttributeForElementIndex:function(t,n,i){var r,o;null===(o=null===(r=e.getListItemByIndex(t))||void 0===r?void 0:r.getListItemElement())||void 0===o||o.setAttribute(n,i)},addClassForElementIndex:function(t,n){return e.items.toArray()[t].getListItemElement().classList.add(n)},removeClassForElementIndex:function(t,n){var i,r,o;null===(o=null===(r=null===(i=e.getListItemByIndex(t))||void 0===i?void 0:i.getListItemElement())||void 0===r?void 0:r.classList)||void 0===o||o.remove(n)},getAttributeForElementIndex:function(t,n){return e.items.toArray()[t].getListItemElement().getAttribute(n)},focusItemAtIndex:function(t){return e.focusItemAtIndex(t)},setTabIndexForListItemChildren:function(t,n){[].slice.call(e.items.toArray()[t].getListItemElement().querySelectorAll(d.strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX)).forEach((function(e){return e.setAttribute("tabindex",""+n)}))},hasCheckboxAtIndex:function(t){return!!e.items.toArray()[t].getListItemElement().querySelector(d.strings.CHECKBOX_SELECTOR)},hasRadioAtIndex:function(t){return!!e.items.toArray()[t].getListItemElement().querySelector(d.strings.RADIO_SELECTOR)},isCheckboxCheckedAtIndex:function(t){return e.items.toArray()[t].getListItemElement().querySelector(d.strings.CHECKBOX_SELECTOR).checked},setCheckedCheckboxOrRadioAtIndex:function(t,n){var i=e.items.toArray()[t].getListItemElement().querySelector(d.strings.CHECKBOX_RADIO_SELECTOR);if(i.checked=n,e._platform.isBrowser){var r=document.createEvent("Event");r.initEvent("change",!0,!0),i.dispatchEvent(r)}},isFocusInsideList:function(){return!!e._platform.isBrowser&&e.elementRef.nativeElement.contains(document.activeElement)},isRootFocused:function(){return!!e._platform.isBrowser&&document.activeElement===e._getHostElement()},listItemAtIndexHasClass:function(t,n){return e.items.toArray()[t].getListItemElement().classList.contains(n)},notifyAction:function(t){return e.actionEvent.emit({index:t})}};return new d.MDCListFoundation(t)},n.prototype.ngAfterViewInit=function(){var e=this;this._foundation.init(),this._foundation.layout(),this._changeSubscription=this.items.changes.pipe(s.startWith(null)).subscribe((function(){e.items.length&&e._resetListItems()}))},n.prototype.ngOnDestroy=function(){var e;this._dropSubscriptions(),null===(e=this._changeSubscription)||void 0===e||e.unsubscribe(),this._foundation.destroy()},n.prototype.setSelectedIndex=function(e){if(this.reset(),this._foundation.setSelectedIndex(e),-1!==e){var t=this.items.toArray()[e];t&&this._applySelectionState(t)}},n.prototype.setSelectedValue=function(e){if(this.reset(),null!==e){var t=this.getListItemByValue(e);this._foundation.setSelectedIndex(this.getListItemIndexByValue(e)),t&&this._applySelectionState(t)}},n.prototype.getSelectedItem=function(){return this.items.toArray().find((function(e){return e.selected||e.activated}))},n.prototype.getSelectedIndex=function(){return this.items.toArray().findIndex((function(e){return e.selected||e.activated}))},n.prototype.getSelectedValue=function(){var e=this.items?this.items.find((function(e){return e.selected})):null;return e&&e.value?e.value:null},n.prototype.getSelectedText=function(){var e=this.getSelectedItem();return e&&e.getListItemElement().textContent||""},n.prototype.getListItemByValue=function(e){return this.items.toArray().find((function(t){return t.value===e}))},n.prototype.getListItemByIndex=function(e){return this.items.toArray()[e]},n.prototype.getListItemIndexByValue=function(e){return this.items.toArray().findIndex((function(t){return t.value===e}))},n.prototype.focusItemAtIndex=function(e){this.items.toArray()[e].getListItemElement().focus()},n.prototype.focusFirstElement=function(){return this._foundation.focusFirstElement()},n.prototype.focusLastElement=function(){return this._foundation.focusLastElement()},n.prototype.focusNextElement=function(e){return this._foundation.focusNextElement(e)},n.prototype.focusPrevElement=function(e){return this._foundation.focusPrevElement(e)},n.prototype.setRole=function(e){this._getHostElement().setAttribute("role",e)},n.prototype.setTabIndex=function(e){this._getHostElement().tabIndex=e},n.prototype.focus=function(){this._getHostElement().focus()},n.prototype.reset=function(){this.items.forEach((function(e){e.selected=!1,e.activated=!1}))},n.prototype._applySelectionState=function(e){this.useActivatedClass?e.activated=!0:this.useSelectedClass&&(e.selected=!0)},n.prototype._resetListItems=function(){this._dropSubscriptions(),this._listenForListItemSelection()},n.prototype._dropSubscriptions=function(){this.itemSelectionSubscription&&(this.itemSelectionSubscription.unsubscribe(),this.itemSelectionSubscription=null)},n.prototype._listenForListItemSelection=function(){var e=this;this.itemSelectionSubscription=this.listItemSelections.subscribe((function(t){e.singleSelection&&e.items.filter((function(e){return e.id!==t.source.id&&(e.activated||e.selected)})).forEach((function(e){e.selected=!1,e.activated=!1})),e._applySelectionState(t.source),e.singleSelection||t.source.ripple.handleBlur(),e.selectionChange.emit(new C(e,t.source))}))},n.prototype._onFocusIn=function(e){var t=this._getListItemIndexByEvent(e);this._foundation.handleFocusIn(e,t)},n.prototype._onFocusOut=function(e){var t=this._getListItemIndexByEvent(e);t>=0&&this._foundation.handleFocusOut(e,t)},n.prototype._onKeydown=function(e){var t=this._getListItemIndexByEvent(e),n=e.target;t>=0&&this._foundation.handleKeydown(e,n.classList.contains(d.cssClasses.LIST_ITEM_CLASS),t)},n.prototype._handleClickEvent=function(e){var t=this._getListItemIndexByEvent(e),n=e.target,i=this._getListItemByEventTarget(e.target);if(!i||!i.disabled){var r=!p.matches(n,d.strings.CHECKBOX_RADIO_SELECTOR);this._foundation.handleClick(t,r)}},n.prototype._getListItemByEventTarget=function(e){return this.items.toArray().find((function(t){return t.getListItemElement()===e}))},n.prototype._getListItemIndexByEvent=function(e){return this.items.toArray().findIndex((function(t){return t.getListItemElement()===e.target}))},n.prototype._getHostElement=function(){return this.elementRef.nativeElement},n.decorators=[{type:t.Component,args:[{selector:"mdc-list",exportAs:"mdcList",host:{role:"list",class:"mdc-list","[attr.aria-orientation]":'verticalOrientation ? "vertical" : "horizontal"',"[class.mdc-list--dense]":"dense","[class.mdc-list--avatar-list]":"avatar","[class.ngx-mdc-list--border]":"border","[class.mdc-list--non-interactive]":"!interactive","[class.mdc-list--two-line]":"twoLine","(click)":"_handleClickEvent($event)","(keydown)":"_onKeydown($event)","(focusin)":"_onFocusIn($event)","(focusout)":"_onFocusOut($event)"},template:"<ng-content></ng-content>",encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[{provide:g,useExisting:n}]}]}],n.ctorParameters=function(){return[{type:r.Platform},{type:t.ChangeDetectorRef},{type:t.ElementRef}]},n.propDecorators={twoLine:[{type:t.Input}],dense:[{type:t.Input}],border:[{type:t.Input}],avatar:[{type:t.Input}],interactive:[{type:t.Input}],disableRipple:[{type:t.Input}],singleSelection:[{type:t.Input}],useActivatedClass:[{type:t.Input}],useSelectedClass:[{type:t.Input}],verticalOrientation:[{type:t.Input}],wrapFocus:[{type:t.Input}],items:[{type:t.ContentChildren,args:[L,{descendants:!0}]}],selectionChange:[{type:t.Output}],actionEvent:[{type:t.Output}]},n}(c.MDCComponent),R=[O,h,S,x,L,b,v,E,I],A=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],exports:R,declarations:R}]}],e}();e.MDC_LIST_PARENT_COMPONENT=g,e.MdcList=O,e.MdcListDivider=h,e.MdcListGroup=S,e.MdcListGroupSubheader=x,e.MdcListItem=L,e.MdcListItemChange=C,e.MdcListItemGraphic=b,e.MdcListItemMeta=v,e.MdcListItemSecondary=E,e.MdcListItemText=I,e.MdcListModule=A,e.MdcListSelectionChange=y,Object.defineProperty(e,"__esModule",{value:!0})}));