ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
24 lines (22 loc) • 18.7 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ng-zorro-antd/core/logger"),require("@angular/core"),require("rxjs")):"function"==typeof define&&define.amd?define("ng-zorro-antd/core/tree",["exports","ng-zorro-antd/core/logger","@angular/core","rxjs"],t):t(((e=e||self)["ng-zorro-antd"]=e["ng-zorro-antd"]||{},e["ng-zorro-antd"].core=e["ng-zorro-antd"].core||{},e["ng-zorro-antd"].core.tree={}),e["ng-zorro-antd"].core.logger,e.ng.core,e.rxjs)}(this,(function(e,t,i,n){"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.
***************************************************************************** */function r(e){var t="function"==typeof Symbol&&Symbol.iterator,i=t&&e[t],n=0;if(i)return i.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var n,r,o=i.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return s}function s(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e}var c=function(){function e(t,i,n){var r=this;if(void 0===i&&(i=null),void 0===n&&(n=null),this.level=0,t instanceof e)return t;this.service=n||null,this.origin=t,this.key=t.key,this.parentNode=i,this._title=t.title||"---",this._icon=t.icon||"",this._isLeaf=t.isLeaf||!1,this._children=[],this._isChecked=t.checked||!1,this._isSelectable=t.disabled||!1!==t.selectable,this._isDisabled=t.disabled||!1,this._isDisableCheckbox=t.disableCheckbox||!1,this._isExpanded=!t.isLeaf&&(t.expanded||!1),this._isHalfChecked=!1,this._isSelected=!t.disabled&&t.selected||!1,this._isLoading=!1,this.isMatched=!1,this.level=i?i.level+1:0,void 0!==t.children&&null!==t.children&&t.children.forEach((function(i){var n=r.treeService;!n||n.isCheckStrictly||!t.checked||t.disabled||i.disabled||i.disableCheckbox||(i.checked=t.checked),r._children.push(new e(i,r))}))}return Object.defineProperty(e.prototype,"treeService",{get:function(){return this.service||this.parentNode&&this.parentNode.treeService},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},set:function(e){this._title=e,this.update()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"icon",{get:function(){return this._icon},set:function(e){this._icon=e,this.update()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"children",{get:function(){return this._children},set:function(e){this._children=e,this.update()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isLeaf",{get:function(){return this._isLeaf},set:function(e){this._isLeaf=e,this.update()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isChecked",{get:function(){return this._isChecked},set:function(e){this._isChecked=e,this._isAllChecked=e,this.origin.checked=e,this.afterValueChange("isChecked")},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isAllChecked",{get:function(){return this._isAllChecked},set:function(e){t.warnDeprecation("'isAllChecked' is going to be removed in 9.0.0. Please use 'isChecked' instead."),this._isAllChecked=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isHalfChecked",{get:function(){return this._isHalfChecked},set:function(e){this._isHalfChecked=e,this.afterValueChange("isHalfChecked")},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSelectable",{get:function(){return this._isSelectable},set:function(e){this._isSelectable=e,this.update()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDisabled",{get:function(){return this._isDisabled},set:function(e){this._isDisabled=e,this.update()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDisableCheckbox",{get:function(){return this._isDisableCheckbox},set:function(e){this._isDisableCheckbox=e,this.update()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isExpanded",{get:function(){return this._isExpanded},set:function(e){this._isExpanded=e,this.origin.expanded=e,this.afterValueChange("isExpanded"),this.afterValueChange("reRender")},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSelected",{get:function(){return this._isSelected},set:function(e){this._isSelected=e,this.origin.selected=e,this.afterValueChange("isSelected")},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isLoading",{get:function(){return this._isLoading},set:function(e){this._isLoading=e,this.update()},enumerable:!0,configurable:!0}),e.prototype.setSyncChecked=function(e,t){void 0===e&&(e=!1),void 0===t&&(t=!1),this.setChecked(e,t),this.treeService&&!this.treeService.isCheckStrictly&&this.treeService.conduct(this)},e.prototype.setChecked=function(e,i){void 0===e&&(e=!1),void 0===i&&(i=!1),t.warnDeprecation("'setChecked' is going to be removed in 9.0.0. Please use 'isChecked' instead."),this.origin.checked=e,this.isChecked=e,this.isAllChecked=e,this.isHalfChecked=i},e.prototype.setExpanded=function(e){this._isExpanded=e,this.origin.expanded=e,this.afterValueChange("isExpanded")},e.prototype.setSelected=function(e){t.warnDeprecation("'setSelected' is going to be removed in 9.0.0. Please use 'isExpanded' isSelected."),this.isDisabled||(this.isSelected=e)},e.prototype.getParentNode=function(){return this.parentNode},e.prototype.getChildren=function(){return this.children},e.prototype.addChildren=function(t,i){var n=this;void 0===i&&(i=-1),this.isLeaf||(t.forEach((function(t){var r=function(e){e.getChildren().forEach((function(e){e.level=e.getParentNode().level+1,e.origin.level=e.level,r(e)}))},o=t;o instanceof e?o.parentNode=n:o=new e(t,n),o.level=n.level+1,o.origin.level=o.level,r(o);try{-1===i?n.children.push(o):n.children.splice(i,0,o)}catch(e){}})),this.origin.children=this.getChildren().map((function(e){return e.origin})),this.isLoading=!1),this.afterValueChange("addChildren"),this.afterValueChange("reRender")},e.prototype.clearChildren=function(){this.afterValueChange("clearChildren"),this.children=[],this.origin.children=[],this.afterValueChange("reRender")},e.prototype.remove=function(){var e=this,t=this.getParentNode();t&&(t.children=t.getChildren().filter((function(t){return t.key!==e.key})),t.origin.children=t.origin.children.filter((function(t){return t.key!==e.key})),this.afterValueChange("remove"),this.afterValueChange("reRender"))},e.prototype.afterValueChange=function(e){if(this.treeService)switch(e){case"isChecked":this.treeService.setCheckedNodeList(this);break;case"isHalfChecked":this.treeService.setHalfCheckedNodeList(this);break;case"isExpanded":this.treeService.setExpandedNodeList(this);break;case"isSelected":this.treeService.setNodeActive(this);break;case"clearChildren":this.treeService.afterRemove(this.getChildren());break;case"remove":this.treeService.afterRemove([this]);break;case"reRender":this.treeService.flattenTreeData(this.treeService.rootNodes,this.treeService.getExpandedNodeList().map((function(e){return e.key})))}this.update()},e.prototype.update=function(){this.component&&this.component.markForCheck()},e}();
/**
* @license
* Copyright Alibaba.com 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://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
function d(e){var t=e.isDisabled,i=e.isDisableCheckbox;return!(!t&&!i)}function h(e,t){return t.length>0&&t.indexOf(e)>-1}function a(e,t){return e+"-"+t}function l(e,t){return null!=e?e:t}function u(e,t){void 0===e&&(e=[]),void 0===t&&(t=[]);var i=new Set(!0===t?[]:t),n=[];return function e(r,o){return void 0===o&&(o=null),r.map((function(c,d){var h=a(o?o.pos:"0",d),u=l(c.key,h);c.isStart=s(o?o.isStart:[],[0===d]),c.isEnd=s(o?o.isEnd:[],[d===r.length-1]);var f={parent:o,pos:h,children:[],data:c,isStart:s(o?o.isStart:[],[0===d]),isEnd:s(o?o.isEnd:[],[d===r.length-1])};return n.push(f),!0===t||i.has(u)||c.isExpanded?f.children=e(c.children||[],f):f.children=[],f}))}(e),n}var f=function(){function e(){this.DRAG_SIDE_RANGE=.25,this.DRAG_MIN_GAP=2,this.isCheckStrictly=!1,this.isMultiple=!1,this.rootNodes=[],this.flattenNodes$=new n.BehaviorSubject([]),this.selectedNodeList=[],this.expandedNodeList=[],this.checkedNodeList=[],this.halfCheckedNodeList=[],this.matchedNodeList=[]}return e.prototype.initTree=function(e){this.rootNodes=e,this.expandedNodeList=[],this.selectedNodeList=[],this.halfCheckedNodeList=[],this.checkedNodeList=[],this.matchedNodeList=[]},e.prototype.flattenTreeData=function(e,t){void 0===t&&(t=[]),this.flattenNodes$.next(u(e,t).map((function(e){return e.data})))},e.prototype.getSelectedNode=function(){return this.selectedNode},e.prototype.getSelectedNodeList=function(){return this.conductNodeState("select")},e.prototype.getCheckedNodeList=function(){return this.conductNodeState("check")},e.prototype.getHalfCheckedNodeList=function(){return this.conductNodeState("halfCheck")},e.prototype.getExpandedNodeList=function(){return this.conductNodeState("expand")},e.prototype.getMatchedNodeList=function(){return this.conductNodeState("match")},e.prototype.isArrayOfNzTreeNode=function(e){return e.every((function(e){return e instanceof c}))},e.prototype.setSelectedNode=function(e){this.selectedNode=e},e.prototype.setNodeActive=function(e){!this.isMultiple&&e.isSelected&&(this.selectedNodeList.forEach((function(t){e.key!==t.key&&(t.isSelected=!1)})),this.selectedNodeList=[]),this.setSelectedNodeList(e,this.isMultiple)},e.prototype.setSelectedNodeList=function(e,t){void 0===t&&(t=!1);var i=this.getIndexOfArray(this.selectedNodeList,e.key);t?e.isSelected&&-1===i&&this.selectedNodeList.push(e):e.isSelected&&-1===i&&(this.selectedNodeList=[e]),e.isSelected||(this.selectedNodeList=this.selectedNodeList.filter((function(t){return t.key!==e.key})))},e.prototype.setHalfCheckedNodeList=function(e){var t=this.getIndexOfArray(this.halfCheckedNodeList,e.key);e.isHalfChecked&&-1===t?this.halfCheckedNodeList.push(e):!e.isHalfChecked&&t>-1&&(this.halfCheckedNodeList=this.halfCheckedNodeList.filter((function(t){return e.key!==t.key})))},e.prototype.setCheckedNodeList=function(e){var t=this.getIndexOfArray(this.checkedNodeList,e.key);e.isChecked&&-1===t?this.checkedNodeList.push(e):!e.isChecked&&t>-1&&(this.checkedNodeList=this.checkedNodeList.filter((function(t){return e.key!==t.key})))},e.prototype.conductNodeState=function(e){var t=this;void 0===e&&(e="check");var i=[];switch(e){case"select":i=this.selectedNodeList;break;case"expand":i=this.expandedNodeList;break;case"match":i=this.matchedNodeList;break;case"check":i=this.checkedNodeList;var n=function(e){var i=e.getParentNode();return!!i&&(t.checkedNodeList.findIndex((function(e){return e.key===i.key}))>-1||n(i))};this.isCheckStrictly||(i=this.checkedNodeList.filter((function(e){return!n(e)})));break;case"halfCheck":this.isCheckStrictly||(i=this.halfCheckedNodeList)}return i},e.prototype.setExpandedNodeList=function(e){if(!e.isLeaf){var t=this.getIndexOfArray(this.expandedNodeList,e.key);e.isExpanded&&-1===t?this.expandedNodeList.push(e):!e.isExpanded&&t>-1&&this.expandedNodeList.splice(t,1)}},e.prototype.setMatchedNodeList=function(e){var t=this.getIndexOfArray(this.matchedNodeList,e.key);e.isMatched&&-1===t?this.matchedNodeList.push(e):!e.isMatched&&t>-1&&this.matchedNodeList.splice(t,1)},e.prototype.refreshCheckState=function(e){var t=this;void 0===e&&(e=!1),e||this.checkedNodeList.forEach((function(e){t.conduct(e)}))},e.prototype.conduct=function(e){var t=e.isChecked;e&&(this.conductUp(e),this.conductDown(e,t))},e.prototype.conductUp=function(e){var t=e.getParentNode();t&&(d(t)||(t.children.every((function(e){return d(e)||!e.isHalfChecked&&e.isChecked}))?(t.isChecked=!0,t.isHalfChecked=!1):t.children.some((function(e){return e.isHalfChecked||e.isChecked}))?(t.isChecked=!1,t.isHalfChecked=!0):(t.isChecked=!1,t.isHalfChecked=!1)),this.setCheckedNodeList(t),this.setHalfCheckedNodeList(t),this.conductUp(t))},e.prototype.conductDown=function(e,t){var i=this;d(e)||(e.isChecked=t,e.isHalfChecked=!1,this.setCheckedNodeList(e),this.setHalfCheckedNodeList(e),e.children.forEach((function(e){i.conductDown(e,t)})))},e.prototype.afterRemove=function(e){var t=this,i=function(e){t.selectedNodeList=t.selectedNodeList.filter((function(t){return t.key!==e.key})),t.expandedNodeList=t.expandedNodeList.filter((function(t){return t.key!==e.key})),t.checkedNodeList=t.checkedNodeList.filter((function(t){return t.key!==e.key})),e.children&&e.children.forEach((function(e){i(e)}))};e.forEach((function(e){i(e)})),this.refreshCheckState(this.isCheckStrictly)},e.prototype.refreshDragNode=function(e){var t=this;0===e.children.length?this.conductUp(e):e.children.forEach((function(e){t.refreshDragNode(e)}))},e.prototype.resetNodeLevel=function(e){var t,i,n=e.getParentNode();e.level=n?n.level+1:0;try{for(var o=r(e.children),s=o.next();!s.done;s=o.next()){var c=s.value;this.resetNodeLevel(c)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}},e.prototype.calcDropPosition=function(e){var t=e.clientY,i=e.srcElement?e.srcElement.getBoundingClientRect():e.target.getBoundingClientRect(),n=i.top,r=i.bottom,o=i.height,s=Math.max(o*this.DRAG_SIDE_RANGE,this.DRAG_MIN_GAP);return t<=n+s?-1:t>=r-s?1:0},e.prototype.dropAndApply=function(e,t){var i=this;if(void 0===t&&(t=-1),e&&!(t>1)){var n=e.treeService,r=e.getParentNode(),o=this.selectedNode.getParentNode();switch(o?o.children=o.children.filter((function(e){return e.key!==i.selectedNode.key})):this.rootNodes=this.rootNodes.filter((function(e){return e.key!==i.selectedNode.key})),t){case 0:e.addChildren([this.selectedNode]),this.resetNodeLevel(e);break;case-1:case 1:var s=1===t?1:0;if(r){r.addChildren([this.selectedNode],r.children.indexOf(e)+s);var c=this.selectedNode.getParentNode();c&&this.resetNodeLevel(c)}else{var d=this.rootNodes.indexOf(e)+s;this.rootNodes.splice(d,0,this.selectedNode),this.rootNodes[d].parentNode=null,this.resetNodeLevel(this.rootNodes[d])}}this.rootNodes.forEach((function(e){e.treeService||(e.service=n),i.refreshDragNode(e)}))}},e.prototype.formatEvent=function(e,t,i){var n={eventName:e,node:t,event:i};switch(e){case"dragstart":case"dragenter":case"dragover":case"dragleave":case"drop":case"dragend":Object.assign(n,{dragNode:this.getSelectedNode()});break;case"click":case"dblclick":Object.assign(n,{selectedKeys:this.selectedNodeList}),Object.assign(n,{nodes:this.selectedNodeList}),Object.assign(n,{keys:this.selectedNodeList.map((function(e){return e.key}))});break;case"check":var r=this.getCheckedNodeList();Object.assign(n,{checkedKeys:r}),Object.assign(n,{nodes:r}),Object.assign(n,{keys:r.map((function(e){return e.key}))});break;case"search":Object.assign(n,{matchedKeys:this.getMatchedNodeList()}),Object.assign(n,{nodes:this.getMatchedNodeList()}),Object.assign(n,{keys:this.getMatchedNodeList().map((function(e){return e.key}))});break;case"expand":Object.assign(n,{nodes:this.expandedNodeList}),Object.assign(n,{keys:this.expandedNodeList.map((function(e){return e.key}))})}return n},e.prototype.getIndexOfArray=function(e,t){return e.findIndex((function(e){return e.key===t}))},e.prototype.conductCheck=function(e,t){this.checkedNodeList=[],this.halfCheckedNodeList=[];var i=function(t){t.forEach((function(t){h(t.key,e)?(t.isChecked=!0,t.isHalfChecked=!1):(t.isChecked=!1,t.isHalfChecked=!1),t.children.length>0&&i(t.children)}))};i(this.rootNodes),this.refreshCheckState(t)},e.prototype.conductExpandedKeys=function(e){var t=this;void 0===e&&(e=[]);var i=new Set(!0===e?[]:e);this.expandedNodeList=[];var n=function(r){r.forEach((function(r){r.setExpanded(!0===e||i.has(r.key)||!0===r.isExpanded),r.isExpanded&&t.setExpandedNodeList(r),r.children.length>0&&n(r.children)}))};n(this.rootNodes)},e.prototype.conductSelectedKeys=function(e,t){var i=this;this.selectedNodeList=[];var n=function(r){return r.every((function(r){if(h(r.key,e)){if(r.isSelected=!0,i.setSelectedNodeList(r),!t)return!1}else r.isSelected=!1;return!(r.children.length>0)||n(r.children)}))};n(this.rootNodes)},e.prototype.expandNodeAllParentBySearch=function(e){var t=this,i=function(e){if(e&&(e.canHide=!1,e.setExpanded(!0),t.setExpandedNodeList(e),e.getParentNode()))return i(e.getParentNode())};i(e.getParentNode())},e.decorators=[{type:i.Injectable}],e}();var p=new i.InjectionToken("NzTreeHigherOrder"),k=function(){function e(e){this.nzTreeService=e}return e.prototype.coerceTreeNodes=function(e){var t=this;return this.nzTreeService.isArrayOfNzTreeNode(e)?e.map((function(e){return e.service=t.nzTreeService,e})):e.map((function(e){return new c(e,null,t.nzTreeService)}))},e.prototype.getTreeNodes=function(){return this.nzTreeService.rootNodes},e.prototype.getTreeNodeByKey=function(e){var t=[],i=function(e){t.push(e),e.getChildren().forEach((function(e){i(e)}))};return this.getTreeNodes().forEach((function(e){i(e)})),t.find((function(t){return t.key===e}))||null},e.prototype.getCheckedNodeList=function(){return this.nzTreeService.getCheckedNodeList()},e.prototype.getSelectedNodeList=function(){return this.nzTreeService.getSelectedNodeList()},e.prototype.getHalfCheckedNodeList=function(){return this.nzTreeService.getHalfCheckedNodeList()},e.prototype.getExpandedNodeList=function(){return this.nzTreeService.getExpandedNodeList()},e.prototype.getMatchedNodeList=function(){return this.nzTreeService.getMatchedNodeList()},e}();e.NzTreeBase=k,e.NzTreeBaseService=f,e.NzTreeHigherOrderServiceToken=p,e.NzTreeNode=c,e.flattenTreeData=u,e.getKey=l,e.getPosition=a,e.isCheckDisabled=d,e.isInArray=h,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-zorro-antd-core-tree.umd.min.js.map