@angular-mdc/web
Version:
22 lines (20 loc) • 12.3 kB
JavaScript
/**
* @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("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/base"),require("@angular/cdk/coercion"),require("@angular-mdc/web/checkbox"),require("@angular-mdc/web/dom"),require("@material/data-table")):"function"==typeof define&&define.amd?define("@angular-mdc/web/data-table",["exports","@angular/core","@angular/common","rxjs","rxjs/operators","@angular-mdc/web/base","@angular/cdk/coercion","@angular-mdc/web/checkbox","@angular-mdc/web/dom","@material/data-table"],t):t(((e=e||self).ng=e.ng||{},e.ng.web=e.ng.web||{},e.ng.web.dataTable={}),e.ng.core,e.ng.common,e.rxjs,e.rxjs.operators,e.ng.web.base,e.ng.cdk.coercion,e.ng.web.checkbox,e.ng.web.dom,e.mdc.dataTable)}(this,(function(e,t,n,o,r,c,a,i,s,u){"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 l=function(e,t){return(l=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 d(e,t,n,o){return new(n||(n=Promise))((function(r,c){function a(e){try{s(o.next(e))}catch(e){c(e)}}function i(e){try{s(o.throw(e))}catch(e){c(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}s((o=o.apply(e,t||[])).next())}))}function h(e,t){var n,o,r,c,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return c={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c;function i(c){return function(i){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&c[0]?o.return:c[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,c[1])).done)return r;switch(o=0,r&&(c=[2&c[0],r.value]),c[0]){case 0:case 1:r=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,o=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(r=(r=a.trys).length>0&&r[r.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!r||c[1]>r[0]&&c[1]<r[3])){a.label=c[1];break}if(6===c[0]&&a.label<r[1]){a.label=r[1],r=c;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(c);break}r[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],o=0}finally{n=r=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,i])}}}var b=0,p=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcDataTableTable]",exportAs:"mdcDataTableTable",host:{class:"mdc-data-table__table"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),f=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcDataTableHeaderRow]",exportAs:"mdcDataTableHeaderRow",host:{class:"mdc-data-table__header-row"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),m=function(){function e(e){this.elementRef=e,this._numeric=!1}return Object.defineProperty(e.prototype,"numeric",{get:function(){return this._numeric},set:function(e){this._numeric=a.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),e.decorators=[{type:t.Component,args:[{selector:"[mdcDataTableHeaderCell]",exportAs:"mdcDataTableHeaderCell",host:{role:"columnheader",scope:"col",class:"mdc-data-table__header-cell","[class.mdc-data-table__header-cell--checkbox]":"!!_checkbox","[class.mdc-data-table__header-cell--numeric]":"numeric"},template:"<ng-content></ng-content>",encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={numeric:[{type:t.Input}],_checkbox:[{type:t.ContentChild,args:[i.MdcCheckbox,{static:!1}]}]},e}(),g=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcDataTableContent]",exportAs:"mdcDataTableContent",host:{class:"mdc-data-table__content"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),y=function(){function e(e){this.elementRef=e,this._id="mdc-data-table-row-"+b++,this._selected=!1}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){this._selected=a.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),e.prototype.getNativeElement=function(){return this.elementRef.nativeElement},e.decorators=[{type:t.Component,args:[{selector:"[mdcDataTableRow]",exportAs:"mdcDataTableRow",host:{"[attr.data-row-id]":"id",class:"mdc-data-table__row","[class.mdc-data-table__row-checkbox]":"!!_checkbox","[class.mdc-data-table__row--selected]":"selected"},template:"<ng-content></ng-content>",encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={_checkbox:[{type:t.ContentChild,args:[i.MdcCheckbox,{static:!1}]}],selected:[{type:t.Input}]},e}(),_=function(){function e(e){this.elementRef=e,this._checkbox=!1,this._numeric=!1}return Object.defineProperty(e.prototype,"checkbox",{get:function(){return this._checkbox},set:function(e){this._checkbox=a.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"numeric",{get:function(){return this._numeric},set:function(e){this._numeric=a.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),e.decorators=[{type:t.Component,args:[{selector:"[mdcDataTableCell]",exportAs:"mdcDataTableCell",host:{class:"mdc-data-table__cell","[class.mdc-data-table__cell--checkbox]":"checkbox","[class.mdc-data-table__cell--numeric]":"numeric"},template:"<ng-content></ng-content>",encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={checkbox:[{type:t.Input}],numeric:[{type:t.Input}]},e}(),C=function(e){function n(n){var r=e.call(this,n)||this;return r.elementRef=n,r._destroyed=new o.Subject,r._headerCheckboxSubscription=null,r._rowCheckboxesSubscription=null,r.selectedAll=new t.EventEmitter,r.unselectedAll=new t.EventEmitter,r.selectionChanged=new t.EventEmitter,r}return function(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(n,e),Object.defineProperty(n.prototype,"rowCheckboxChanges",{get:function(){return o.merge.apply(void 0,this.rows.map((function(e){return e._checkbox.change})))},enumerable:!0,configurable:!0}),n.prototype.getDefaultFoundation=function(){var e=this,t={addClassAtRowIndex:function(t,n){return e.getRows()[t].getNativeElement().classList.add(n)},getRowCount:function(){return e.getRows().length},getRowElements:function(){return[].slice.call(e.elementRef.nativeElement.querySelectorAll(u.strings.ROW_SELECTOR))},getRowIdAtIndex:function(t){return e.getRows()[t].getNativeElement().getAttribute(u.strings.DATA_ROW_ID_ATTR)},getRowIndexByChildElement:function(t){return e.getRows().findIndex((function(e){return e.getNativeElement()===s.closest(t,u.strings.ROW_SELECTOR)}))},getSelectedRowCount:function(){return e.elementRef.nativeElement.querySelectorAll(u.strings.ROW_SELECTED_SELECTOR).length},isCheckboxAtRowIndexChecked:function(t){return!!(e.rows.length>0&&e.getRows()[t]&&void 0!==e.getRows()[t]._checkbox&&e.getRows()[t]._checkbox.checked)},isHeaderRowCheckboxChecked:function(){return!!e._headerCheckbox&&e._headerCheckbox.checked},isRowsSelectable:function(){return!!e.elementRef.nativeElement.querySelector(u.strings.ROW_CHECKBOX_SELECTOR)},notifyRowSelectionChanged:function(t){return e.selectionChanged.emit({index:t.rowIndex,id:t.rowId,selected:t.selected})},notifySelectedAll:function(){return e.selectedAll.emit()},notifyUnselectedAll:function(){return e.unselectedAll.emit()},registerHeaderRowCheckbox:function(){return e._registerHeaderCheckbox()},registerRowCheckboxes:function(){return e._registerRowCheckboxes()},removeClassAtRowIndex:function(t,n){return e.getRows()[t].getNativeElement().classList.remove(n)},setAttributeAtRowIndex:function(t,n,o){return e.getRows()[t].getNativeElement().setAttribute(n,o)},setHeaderRowCheckboxChecked:function(t){return e._headerCheckbox.checked=t},setHeaderRowCheckboxIndeterminate:function(t){return e._headerCheckbox.indeterminate=t},setRowCheckboxCheckedAtIndex:function(t,n){return e.getRows()[t]._checkbox?e.getRows()[t]._checkbox.toggle(n):null}};return new u.MDCDataTableFoundation(t)},n.prototype.ngAfterViewInit=function(){this._foundation.init(),this.layoutAsync()},n.prototype.ngOnDestroy=function(){this._destroyed.next(),this._destroyed.complete(),this._unsubscribeHeaderCheckbox(),this._unsubscribeRowCheckboxes(),this._foundation&&this._foundation.destroy()},n.prototype.layoutAsync=function(){return d(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this._foundation.layoutAsync()];case 1:return e.sent(),[2]}}))}))},n.prototype.layout=function(){this._foundation.layout()},n.prototype.getSelectedRowIds=function(){return this._foundation.getSelectedRowIds()},n.prototype.setSelectedRowIds=function(e){return this._foundation.setSelectedRowIds(e)},n.prototype.getRows=function(){return this.rows.toArray()},n.prototype.getHeaderCheckbox=function(){return this._headerCheckbox},n.prototype._unsubscribeHeaderCheckbox=function(){this._headerCheckboxSubscription&&this._headerCheckboxSubscription.unsubscribe()},n.prototype._unsubscribeRowCheckboxes=function(){this._rowCheckboxesSubscription&&this._rowCheckboxesSubscription.unsubscribe()},n.prototype._registerHeaderCheckbox=function(){var e=this;this._unsubscribeHeaderCheckbox();var t=this.headerCells.toArray().findIndex((function(e){return void 0!==e._checkbox}));this._headerCheckbox=this.headerCells.toArray()[t]._checkbox,this._headerCheckboxSubscription=this._headerCheckbox.change.pipe(r.takeUntil(this._destroyed)).subscribe((function(t){return e._foundation.handleHeaderRowCheckboxChange()}))},n.prototype._registerRowCheckboxes=function(){var e=this;this._unsubscribeRowCheckboxes(),this._rowCheckboxesSubscription=this.rowCheckboxChanges.subscribe((function(t){e._foundation.handleRowCheckboxChange({target:t.source._inputElement.nativeElement})}))},n.decorators=[{type:t.Component,args:[{selector:"mdc-data-table",exportAs:"mdcDataTable",host:{class:"mdc-data-table"},template:"<ng-content></ng-content>",changeDetection:t.ChangeDetectionStrategy.OnPush,encapsulation:t.ViewEncapsulation.None}]}],n.ctorParameters=function(){return[{type:t.ElementRef}]},n.propDecorators={selectedAll:[{type:t.Output}],unselectedAll:[{type:t.Output}],selectionChanged:[{type:t.Output}],rows:[{type:t.ContentChildren,args:[y,{descendants:!0}]}],headerCells:[{type:t.ContentChildren,args:[m,{descendants:!0}]}]},n}(c.MDCComponent),w=[C,_,g,m,f,y,p],x=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],exports:w,declarations:w}]}],e}();e.MDCDataTable=C,e.MDCDataTableCell=_,e.MDCDataTableContent=g,e.MDCDataTableHeaderCell=m,e.MDCDataTableHeaderRow=f,e.MDCDataTableModule=x,e.MDCDataTableRow=y,e.MDCDataTableTable=p,Object.defineProperty(e,"__esModule",{value:!0})}));