blob: 319bdb08a8611f4c67bf6cab3b506addf9d5dfe2 [file] [log] [blame]
/**
* @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(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/cdk/collections"),require("rxjs"),require("rxjs/operators"),require("@angular/core"),require("@angular/cdk/bidi"),require("@angular/cdk/coercion"),require("@angular/cdk/a11y"),require("@angular/common")):"function"==typeof define&&define.amd?define("@angular/cdk/tree",["exports","@angular/cdk/collections","rxjs","rxjs/operators","@angular/core","@angular/cdk/bidi","@angular/cdk/coercion","@angular/cdk/a11y","@angular/common"],t):t((e.ng=e.ng||{},e.ng.cdk=e.ng.cdk||{},e.ng.cdk.tree={}),e.ng.cdk.collections,e.rxjs,e.rxjs.operators,e.ng.core,e.ng.cdk.bidi,e.ng.cdk.coercion,e.ng.cdk.a11y,e.ng.common)}(this,function(e,t,r,n,o,i,s,a,d){"use strict";function c(e,t){function r(){this.constructor=e}_(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function l(){return Error("A valid data source must be provided.")}function u(){return Error("There can only be one default row without a when predicate function.")}function p(){return Error("Could not find a matching node definition for the provided node data.")}function h(){return Error("Could not find a tree control for the tree.")}function f(){return Error("Could not find functions for nested/flat tree in tree control.")}var _=function(e,t){return(_=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},g=function(){function e(){this.expansionModel=new t.SelectionModel(!0)}return e.prototype.toggle=function(e){this.expansionModel.toggle(e)},e.prototype.expand=function(e){this.expansionModel.select(e)},e.prototype.collapse=function(e){this.expansionModel.deselect(e)},e.prototype.isExpanded=function(e){return this.expansionModel.isSelected(e)},e.prototype.toggleDescendants=function(e){this.expansionModel.isSelected(e)?this.collapseDescendants(e):this.expandDescendants(e)},e.prototype.collapseAll=function(){this.expansionModel.clear()},e.prototype.expandDescendants=function(e){var t,r=[e];r.push.apply(r,this.getDescendants(e)),(t=this.expansionModel).select.apply(t,r)},e.prototype.collapseDescendants=function(e){var t,r=[e];r.push.apply(r,this.getDescendants(e)),(t=this.expansionModel).deselect.apply(t,r)},e}(),y=function(e){function t(t,r){var n=e.call(this)||this;return n.getLevel=t,n.isExpandable=r,n}return c(t,e),t.prototype.getDescendants=function(e){for(var t=this.dataNodes.indexOf(e),r=[],n=t+1;n<this.dataNodes.length&&this.getLevel(e)<this.getLevel(this.dataNodes[n]);n++)r.push(this.dataNodes[n]);return r},t.prototype.expandAll=function(){var e;(e=this.expansionModel).select.apply(e,this.dataNodes)},t}(g),v=function(e){function t(t){var r=e.call(this)||this;return r.getChildren=t,r}return c(t,e),t.prototype.expandAll=function(){var e,t=this;this.expansionModel.clear();var r=this.dataNodes.reduce(function(e,r){return e.concat(t.getDescendants(r),[r])},[]);(e=this.expansionModel).select.apply(e,r)},t.prototype.getDescendants=function(e){var t=[];return this._getDescendants(t,e),t.splice(1)},t.prototype._getDescendants=function(e,t){var o=this;e.push(t);var i=this.getChildren(t);Array.isArray(i)?i.forEach(function(t){return o._getDescendants(e,t)}):i instanceof r.Observable&&i.pipe(n.take(1),n.filter(Boolean)).subscribe(function(t){for(var r=0,n=t;r<n.length;r++){var i=n[r];o._getDescendants(e,i)}})},t}(g),C=new o.InjectionToken("CDK_TREE_NODE_OUTLET_NODE"),b=function(){function e(e,t){this.viewContainer=e,this._node=t}return e.decorators=[{type:o.Directive,args:[{selector:"[cdkTreeNodeOutlet]"}]}],e.ctorParameters=function(){return[{type:o.ViewContainerRef},{type:void 0,decorators:[{type:o.Inject,args:[C]},{type:o.Optional}]}]},e}(),D=function(){function e(e){this.$implicit=e}return e}(),m=function(){function e(e){this.template=e}return e.decorators=[{type:o.Directive,args:[{selector:"[cdkTreeNodeDef]",inputs:["when: cdkTreeNodeDefWhen"]}]}],e.ctorParameters=function(){return[{type:o.TemplateRef}]},e}(),N=function(){function e(e,t){this._differs=e,this._changeDetectorRef=t,this._onDestroy=new r.Subject,this._levels=new Map,this.viewChange=new r.BehaviorSubject({start:0,end:Number.MAX_VALUE})}return Object.defineProperty(e.prototype,"dataSource",{get:function(){return this._dataSource},set:function(e){this._dataSource!==e&&this._switchDataSource(e)},enumerable:!0,configurable:!0}),e.prototype.ngOnInit=function(){if(this._dataDiffer=this._differs.find([]).create(this.trackBy),!this.treeControl)throw h()},e.prototype.ngOnDestroy=function(){this._nodeOutlet.viewContainer.clear(),this._onDestroy.next(),this._onDestroy.complete(),this._dataSource&&"function"==typeof this._dataSource.disconnect&&this.dataSource.disconnect(this),this._dataSubscription&&(this._dataSubscription.unsubscribe(),this._dataSubscription=null)},e.prototype.ngAfterContentChecked=function(){var e=this._nodeDefs.filter(function(e){return!e.when});if(e.length>1)throw u();this._defaultNodeDef=e[0],this.dataSource&&this._nodeDefs&&!this._dataSubscription&&this._observeRenderChanges()},e.prototype._switchDataSource=function(e){this._dataSource&&"function"==typeof this._dataSource.disconnect&&this.dataSource.disconnect(this),this._dataSubscription&&(this._dataSubscription.unsubscribe(),this._dataSubscription=null),e||this._nodeOutlet.viewContainer.clear(),this._dataSource=e,this._nodeDefs&&this._observeRenderChanges()},e.prototype._observeRenderChanges=function(){var e,o=this;if(t.isDataSource(this._dataSource)?e=this._dataSource.connect(this):this._dataSource instanceof r.Observable?e=this._dataSource:Array.isArray(this._dataSource)&&(e=r.of(this._dataSource)),!e)throw l();this._dataSubscription=e.pipe(n.takeUntil(this._onDestroy)).subscribe(function(e){return o.renderNodeChanges(e)})},e.prototype.renderNodeChanges=function(e,t,r,n){var o=this;void 0===t&&(t=this._dataDiffer),void 0===r&&(r=this._nodeOutlet.viewContainer);var i=t.diff(e);i&&(i.forEachOperation(function(t,i,s){if(null==t.previousIndex)o.insertNode(e[s],s,r,n);else if(null==s)r.remove(i),o._levels.delete(t.item);else{var a=r.get(i);r.move(a,s)}}),this._changeDetectorRef.detectChanges())},e.prototype._getNodeDef=function(e,t){if(1===this._nodeDefs.length)return this._nodeDefs.first;var r=this._nodeDefs.find(function(r){return r.when&&r.when(t,e)})||this._defaultNodeDef;if(!r)throw p();return r},e.prototype.insertNode=function(e,t,r,n){var o=this._getNodeDef(e,t),i=new D(e);this.treeControl.getLevel?i.level=this.treeControl.getLevel(e):void 0!==n&&this._levels.has(n)?i.level=this._levels.get(n)+1:i.level=0,this._levels.set(e,i.level),(r||this._nodeOutlet.viewContainer).createEmbeddedView(o.template,i,t),k.mostRecentTreeNode&&(k.mostRecentTreeNode.data=e)},e.decorators=[{type:o.Component,args:[{selector:"cdk-tree",exportAs:"cdkTree",template:"<ng-container cdkTreeNodeOutlet></ng-container>",host:{class:"cdk-tree",role:"tree"},encapsulation:o.ViewEncapsulation.None,changeDetection:o.ChangeDetectionStrategy.Default}]}],e.ctorParameters=function(){return[{type:o.IterableDiffers},{type:o.ChangeDetectorRef}]},e.propDecorators={dataSource:[{type:o.Input}],treeControl:[{type:o.Input}],trackBy:[{type:o.Input}],_nodeOutlet:[{type:o.ViewChild,args:[b,{static:!0}]}],_nodeDefs:[{type:o.ContentChildren,args:[m]}]},e}(),k=function(){function e(t,n){this._elementRef=t,this._tree=n,this._destroyed=new r.Subject,this._dataChanges=new r.Subject,this.role="treeitem",e.mostRecentTreeNode=this}return Object.defineProperty(e.prototype,"data",{get:function(){return this._data},set:function(e){e!==this._data&&(this._data=e,this._setRoleFromData(),this._dataChanges.next())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isExpanded",{get:function(){return this._tree.treeControl.isExpanded(this._data)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"level",{get:function(){return this._tree.treeControl.getLevel?this._tree.treeControl.getLevel(this._data):0},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){e.mostRecentTreeNode===this&&(e.mostRecentTreeNode=null),this._dataChanges.complete(),this._destroyed.next(),this._destroyed.complete()},e.prototype.focus=function(){this._elementRef.nativeElement.focus()},e.prototype._setRoleFromData=function(){var e=this;if(this._tree.treeControl.isExpandable)this.role=this._tree.treeControl.isExpandable(this._data)?"group":"treeitem";else{if(!this._tree.treeControl.getChildren)throw f();var t=this._tree.treeControl.getChildren(this._data);Array.isArray(t)?this._setRoleFromChildren(t):t instanceof r.Observable&&t.pipe(n.takeUntil(this._destroyed)).subscribe(function(t){return e._setRoleFromChildren(t)})}},e.prototype._setRoleFromChildren=function(e){this.role=e&&e.length?"group":"treeitem"},e.mostRecentTreeNode=null,e.decorators=[{type:o.Directive,args:[{selector:"cdk-tree-node",exportAs:"cdkTreeNode",host:{"[attr.aria-expanded]":"isExpanded","[attr.aria-level]":'role === "treeitem" ? level : null',"[attr.role]":"role",class:"cdk-tree-node"}}]}],e.ctorParameters=function(){return[{type:o.ElementRef},{type:N}]},e.propDecorators={role:[{type:o.Input}]},e}(),x=function(e){function t(t,r,n){var o=e.call(this,t,r)||this;return o._elementRef=t,o._tree=r,o._differs=n,o}return c(t,e),t.prototype.ngAfterContentInit=function(){var e=this;if(this._dataDiffer=this._differs.find([]).create(this._tree.trackBy),!this._tree.treeControl.getChildren)throw f();var t=this._tree.treeControl.getChildren(this.data);Array.isArray(t)?this.updateChildrenNodes(t):t instanceof r.Observable&&t.pipe(n.takeUntil(this._destroyed)).subscribe(function(t){return e.updateChildrenNodes(t)}),this.nodeOutlet.changes.pipe(n.takeUntil(this._destroyed)).subscribe(function(){return e.updateChildrenNodes()})},t.prototype.ngOnDestroy=function(){this._clear(),e.prototype.ngOnDestroy.call(this)},t.prototype.updateChildrenNodes=function(e){var t=this._getNodeOutlet();if(e&&(this._children=e),t&&this._children){var r=t.viewContainer;this._tree.renderNodeChanges(this._children,this._dataDiffer,r,this._data)}else this._dataDiffer.diff([])},t.prototype._clear=function(){var e=this._getNodeOutlet();e&&(e.viewContainer.clear(),this._dataDiffer.diff([]))},t.prototype._getNodeOutlet=function(){var e=this,t=this.nodeOutlet;if(t)return t.find(function(t){return!t._node||t._node===e})},t.decorators=[{type:o.Directive,args:[{selector:"cdk-nested-tree-node",exportAs:"cdkNestedTreeNode",host:{"[attr.aria-expanded]":"isExpanded","[attr.role]":"role",class:"cdk-tree-node cdk-nested-tree-node"},providers:[{provide:k,useExisting:t},{provide:C,useExisting:t}]}]}],t.ctorParameters=function(){return[{type:o.ElementRef},{type:N},{type:o.IterableDiffers}]},t.propDecorators={nodeOutlet:[{type:o.ContentChildren,args:[b,{descendants:!0}]}]},t}(k),O=/([A-Za-z%]+)$/,T=function(){function e(e,t,o,i,s){var a=this;this._treeNode=e,this._tree=t,this._renderer=o,this._element=i,this._dir=s,this._destroyed=new r.Subject,this.indentUnits="px",this._indent=40,this._setPadding(),s&&s.change.pipe(n.takeUntil(this._destroyed)).subscribe(function(){return a._setPadding(!0)}),e._dataChanges.subscribe(function(){return a._setPadding()})}return Object.defineProperty(e.prototype,"level",{get:function(){return this._level},set:function(e){this._level=s.coerceNumberProperty(e),this._setPadding()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"indent",{get:function(){return this._indent},set:function(e){var t=e,r="px";if("string"==typeof e){var n=e.split(O);t=n[0],r=n[1]||r}this.indentUnits=r,this._indent=s.coerceNumberProperty(t),this._setPadding()},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){this._destroyed.next(),this._destroyed.complete()},e.prototype._paddingIndent=function(){var e=this._treeNode.data&&this._tree.treeControl.getLevel?this._tree.treeControl.getLevel(this._treeNode.data):null,t=this._level||e;return t?""+t*this._indent+this.indentUnits:null},e.prototype._setPadding=function(e){void 0===e&&(e=!1);var t=this._paddingIndent();if(t!==this._currentPadding||e){var r=this._element.nativeElement,n=this._dir&&"rtl"===this._dir.value?"paddingRight":"paddingLeft",o="paddingLeft"===n?"paddingRight":"paddingLeft";this._renderer.setStyle(r,n,t),this._renderer.setStyle(r,o,null),this._currentPadding=t}},e.decorators=[{type:o.Directive,args:[{selector:"[cdkTreeNodePadding]"}]}],e.ctorParameters=function(){return[{type:k},{type:N},{type:o.Renderer2},{type:o.ElementRef},{type:i.Directionality,decorators:[{type:o.Optional}]}]},e.propDecorators={level:[{type:o.Input,args:["cdkTreeNodePadding"]}],indent:[{type:o.Input,args:["cdkTreeNodePaddingIndent"]}]},e}(),S=function(){function e(e,t){this._tree=e,this._treeNode=t,this._recursive=!1}return Object.defineProperty(e.prototype,"recursive",{get:function(){return this._recursive},set:function(e){this._recursive=s.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),e.prototype._toggle=function(e){this.recursive?this._tree.treeControl.toggleDescendants(this._treeNode.data):this._tree.treeControl.toggle(this._treeNode.data),e.stopPropagation()},e.decorators=[{type:o.Directive,args:[{selector:"[cdkTreeNodeToggle]"}]}],e.ctorParameters=function(){return[{type:N},{type:k}]},e.propDecorators={recursive:[{type:o.Input,args:["cdkTreeNodeToggleRecursive"]}],_toggle:[{type:o.HostListener,args:["click",["$event"]]}]},e}(),E=[x,m,T,S,N,k,b],w=function(){function e(){}return e.decorators=[{type:o.NgModule,args:[{imports:[d.CommonModule],exports:E,declarations:E,providers:[a.FocusMonitor,m]}]}],e}();e.BaseTreeControl=g,e.FlatTreeControl=y,e.NestedTreeControl=v,e.CdkNestedTreeNode=x,e.CdkTreeNodeOutletContext=D,e.CdkTreeNodeDef=m,e.CdkTreeNodePadding=T,e.CDK_TREE_NODE_OUTLET_NODE=C,e.CdkTreeNodeOutlet=b,e.CdkTree=N,e.CdkTreeNode=k,e.getTreeNoValidDataSourceError=l,e.getTreeMultipleDefaultNodeDefsError=u,e.getTreeMissingMatchingNodeDefError=p,e.getTreeControlMissingError=h,e.getTreeControlFunctionsMissingError=f,e.CdkTreeModule=w,e.CdkTreeNodeToggle=S,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=cdk-tree.umd.min.js.map