UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

24 lines 14.8 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),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","tslib","@angular/cdk/collections","rxjs","rxjs/operators","@angular/core","@angular/cdk/bidi","@angular/cdk/coercion","@angular/cdk/a11y","@angular/common"],t):t(((e=e||self).ng=e.ng||{},e.ng.cdk=e.ng.cdk||{},e.ng.cdk.tree={}),e.tslib,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,c){"use strict";var l=function(){function e(){this.expansionModel=new r.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 r,n=[e];n.push.apply(n,t.__spread(this.getDescendants(e))),(r=this.expansionModel).select.apply(r,t.__spread(n))},e.prototype.collapseDescendants=function(e){var r,n=[e];n.push.apply(n,t.__spread(this.getDescendants(e))),(r=this.expansionModel).deselect.apply(r,t.__spread(n))},e}(),u=function(e){function r(t,r){var n=e.call(this)||this;return n.getLevel=t,n.isExpandable=r,n}return t.__extends(r,e),r.prototype.getDescendants=function(e){for(var t=[],r=this.dataNodes.indexOf(e)+1;r<this.dataNodes.length&&this.getLevel(e)<this.getLevel(this.dataNodes[r]);r++)t.push(this.dataNodes[r]);return t},r.prototype.expandAll=function(){var e;(e=this.expansionModel).select.apply(e,t.__spread(this.dataNodes))},r}(l),p=function(e){function r(t){var r=e.call(this)||this;return r.getChildren=t,r}return t.__extends(r,e),r.prototype.expandAll=function(){var e,r=this;this.expansionModel.clear();var n=this.dataNodes.reduce((function(e,n){return t.__spread(e,r.getDescendants(n),[n])}),[]);(e=this.expansionModel).select.apply(e,t.__spread(n))},r.prototype.getDescendants=function(e){var t=[];return this._getDescendants(t,e),t.splice(1)},r.prototype._getDescendants=function(e,r){var i=this;e.push(r);var s=this.getChildren(r);Array.isArray(s)?s.forEach((function(t){return i._getDescendants(e,t)})):s instanceof n.Observable&&s.pipe(o.take(1),o.filter(Boolean)).subscribe((function(r){var n,o;try{for(var s=t.__values(r),a=s.next();!a.done;a=s.next())i._getDescendants(e,a.value)}catch(e){n={error:e}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}}))},r}(l),h=new i.InjectionToken("CDK_TREE_NODE_OUTLET_NODE"),f=function(){function e(e,t){this.viewContainer=e,this._node=t}return e.decorators=[{type:i.Directive,args:[{selector:"[cdkTreeNodeOutlet]"}]}],e.ctorParameters=function(){return[{type:i.ViewContainerRef},{type:void 0,decorators:[{type:i.Inject,args:[h]},{type:i.Optional}]}]},e}(),_=function _(e){this.$implicit=e},g=function(){function e(e){this.template=e}return e.decorators=[{type:i.Directive,args:[{selector:"[cdkTreeNodeDef]",inputs:["when: cdkTreeNodeDefWhen"]}]}],e.ctorParameters=function(){return[{type:i.TemplateRef}]},e}(); /** * @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 */ /** * @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 y(){return Error("A valid data source must be provided.")}function v(){return Error("There can only be one default row without a when predicate function.")}function b(){return Error("Could not find a matching node definition for the provided node data.")}function C(){return Error("Could not find a tree control for the tree.")}function D(){return Error("Could not find functions for nested/flat tree in tree control.")}var m=function(){function e(e,t){this._differs=e,this._changeDetectorRef=t,this._onDestroy=new n.Subject,this._levels=new Map,this.viewChange=new n.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 C()},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 v();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,t=this;if(r.isDataSource(this._dataSource)?e=this._dataSource.connect(this):this._dataSource instanceof n.Observable?e=this._dataSource:Array.isArray(this._dataSource)&&(e=n.of(this._dataSource)),!e)throw y();this._dataSubscription=e.pipe(o.takeUntil(this._onDestroy)).subscribe((function(e){return t.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 b();return r},e.prototype.insertNode=function(e,t,r,n){var o=this._getNodeDef(e,t),i=new _(e);i.level=this.treeControl.getLevel?this.treeControl.getLevel(e):void 0!==n&&this._levels.has(n)?this._levels.get(n)+1:0,this._levels.set(e,i.level),(r||this._nodeOutlet.viewContainer).createEmbeddedView(o.template,i,t),N.mostRecentTreeNode&&(N.mostRecentTreeNode.data=e)},e.decorators=[{type:i.Component,args:[{selector:"cdk-tree",exportAs:"cdkTree",template:"<ng-container cdkTreeNodeOutlet></ng-container>",host:{class:"cdk-tree",role:"tree"},encapsulation:i.ViewEncapsulation.None,changeDetection:i.ChangeDetectionStrategy.Default}]}],e.ctorParameters=function(){return[{type:i.IterableDiffers},{type:i.ChangeDetectorRef}]},e.propDecorators={dataSource:[{type:i.Input}],treeControl:[{type:i.Input}],trackBy:[{type:i.Input}],_nodeOutlet:[{type:i.ViewChild,args:[f,{static:!0}]}],_nodeDefs:[{type:i.ContentChildren,args:[g,{descendants:!0}]}]},e}(),N=function(){function e(t,r){this._elementRef=t,this._tree=r,this._destroyed=new n.Subject,this._dataChanges=new n.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 D();var t=this._tree.treeControl.getChildren(this._data);Array.isArray(t)?this._setRoleFromChildren(t):t instanceof n.Observable&&t.pipe(o.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:i.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:i.ElementRef},{type:m}]},e.propDecorators={role:[{type:i.Input}]},e}(),k=function(e){function r(t,r,n){var o=e.call(this,t,r)||this;return o._elementRef=t,o._tree=r,o._differs=n,o}return t.__extends(r,e),r.prototype.ngAfterContentInit=function(){var e=this;if(this._dataDiffer=this._differs.find([]).create(this._tree.trackBy),!this._tree.treeControl.getChildren)throw D();var t=this._tree.treeControl.getChildren(this.data);Array.isArray(t)?this.updateChildrenNodes(t):t instanceof n.Observable&&t.pipe(o.takeUntil(this._destroyed)).subscribe((function(t){return e.updateChildrenNodes(t)})),this.nodeOutlet.changes.pipe(o.takeUntil(this._destroyed)).subscribe((function(){return e.updateChildrenNodes()}))},r.prototype.ngOnDestroy=function(){this._clear(),e.prototype.ngOnDestroy.call(this)},r.prototype.updateChildrenNodes=function(e){var t=this._getNodeOutlet();e&&(this._children=e),t&&this._children?this._tree.renderNodeChanges(this._children,this._dataDiffer,t.viewContainer,this._data):this._dataDiffer.diff([])},r.prototype._clear=function(){var e=this._getNodeOutlet();e&&(e.viewContainer.clear(),this._dataDiffer.diff([]))},r.prototype._getNodeOutlet=function(){var e=this,t=this.nodeOutlet;return t&&t.find((function(t){return!t._node||t._node===e}))},r.decorators=[{type:i.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:N,useExisting:r},{provide:h,useExisting:r}]}]}],r.ctorParameters=function(){return[{type:i.ElementRef},{type:m},{type:i.IterableDiffers}]},r.propDecorators={nodeOutlet:[{type:i.ContentChildren,args:[f,{descendants:!0}]}]},r}(N),x=/([A-Za-z%]+)$/,T=function(){function e(e,t,r,i,s){var a=this;this._treeNode=e,this._tree=t,this._renderer=r,this._element=i,this._dir=s,this._destroyed=new n.Subject,this.indentUnits="px",this._indent=40,this._setPadding(),s&&s.change.pipe(o.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=a.coerceNumberProperty(e,null),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(x);t=n[0],r=n[1]||r}this.indentUnits=r,this._indent=a.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=null==this._level?e:this._level;return"number"==typeof 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:i.Directive,args:[{selector:"[cdkTreeNodePadding]"}]}],e.ctorParameters=function(){return[{type:N},{type:m},{type:i.Renderer2},{type:i.ElementRef},{type:s.Directionality,decorators:[{type:i.Optional}]}]},e.propDecorators={level:[{type:i.Input,args:["cdkTreeNodePadding"]}],indent:[{type:i.Input,args:["cdkTreeNodePaddingIndent"]}]},e}(),O=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=a.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:i.Directive,args:[{selector:"[cdkTreeNodeToggle]"}]}],e.ctorParameters=function(){return[{type:m},{type:N}]},e.propDecorators={recursive:[{type:i.Input,args:["cdkTreeNodeToggleRecursive"]}],_toggle:[{type:i.HostListener,args:["click",["$event"]]}]},e}(),S=[k,g,T,O,m,N,f],E=function(){function e(){}return e.decorators=[{type:i.NgModule,args:[{imports:[c.CommonModule],exports:S,declarations:S,providers:[d.FocusMonitor,g]}]}],e}(); /** * @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 */ e.BaseTreeControl=l,e.CDK_TREE_NODE_OUTLET_NODE=h,e.CdkNestedTreeNode=k,e.CdkTree=m,e.CdkTreeModule=E,e.CdkTreeNode=N,e.CdkTreeNodeDef=g,e.CdkTreeNodeOutlet=f,e.CdkTreeNodeOutletContext=_,e.CdkTreeNodePadding=T,e.CdkTreeNodeToggle=O,e.FlatTreeControl=u,e.NestedTreeControl=p,e.getTreeControlFunctionsMissingError=D,e.getTreeControlMissingError=C,e.getTreeMissingMatchingNodeDefError=b,e.getTreeMultipleDefaultNodeDefsError=v,e.getTreeNoValidDataSourceError=y,Object.defineProperty(e,"__esModule",{value:!0})}));