basb-cli
Version:
Blog as Second Brain!
2 lines (1 loc) • 4.33 kB
JavaScript
import{D as t,J as e,d as r,bm as n,bj as o,aM as a,I as i}from"./index.js";import{l as s}from"./linkSeriesData.js";function d(r,n,o){if(r&&t(n,r.type)>=0){var a=o.getData().tree.root,i=r.targetNode;if(e(i)&&(i=a.getNodeById(i)),i&&a.contains(i))return{node:i};var s=r.targetNodeId;if(null!=s&&(i=a.getNodeById(s)))return{node:i}}}function h(t){for(var e=[];t;)(t=t.parentNode)&&e.push(t);return e.reverse()}function u(e,r){var n=h(e);return t(n,r)>=0}function p(t,e){for(var r=[];t;){var n=t.dataIndex;r.push({name:t.name,dataIndex:n,value:e.getRawValue(n)}),t=t.parentNode}return r.reverse(),r}var c=function(){function t(t,e){this.depth=0,this.height=0,this.dataIndex=-1,this.children=[],this.viewChildren=[],this.isExpand=!1,this.name=t||"",this.hostTree=e}return t.prototype.isRemoved=function(){return this.dataIndex<0},t.prototype.eachNode=function(t,r,n){i(t)&&(n=r,r=t,t=null),e(t=t||{})&&(t={order:t});var o,a=t.order||"preorder",s=this[t.attr||"children"];"preorder"===a&&(o=r.call(n,this));for(var d=0;!o&&d<s.length;d++)s[d].eachNode(t,r,n);"postorder"===a&&r.call(n,this)},t.prototype.updateDepthAndHeight=function(t){var e=0;this.depth=t;for(var r=0;r<this.children.length;r++){var n=this.children[r];n.updateDepthAndHeight(t+1),n.height>e&&(e=n.height)}this.height=e+1},t.prototype.getNodeById=function(t){if(this.getId()===t)return this;for(var e=0,r=this.children,n=r.length;e<n;e++){var o=r[e].getNodeById(t);if(o)return o}},t.prototype.contains=function(t){if(t===this)return!0;for(var e=0,r=this.children,n=r.length;e<n;e++){var o=r[e].contains(t);if(o)return o}},t.prototype.getAncestors=function(t){for(var e=[],r=t?this:this.parentNode;r;)e.push(r),r=r.parentNode;return e.reverse(),e},t.prototype.getAncestorsIndices=function(){for(var t=[],e=this;e;)t.push(e.dataIndex),e=e.parentNode;return t.reverse(),t},t.prototype.getDescendantIndices=function(){var t=[];return this.eachNode((function(e){t.push(e.dataIndex)})),t},t.prototype.getValue=function(t){var e=this.hostTree.data;return e.getStore().get(e.getDimensionIndex(t||"value"),this.dataIndex)},t.prototype.setLayout=function(t,e){this.dataIndex>=0&&this.hostTree.data.setItemLayout(this.dataIndex,t,e)},t.prototype.getLayout=function(){return this.hostTree.data.getItemLayout(this.dataIndex)},t.prototype.getModel=function(t){if(!(this.dataIndex<0))return this.hostTree.data.getItemModel(this.dataIndex).getModel(t)},t.prototype.getLevelModel=function(){return(this.hostTree.levelModels||[])[this.depth]},t.prototype.setVisual=function(t,e){this.dataIndex>=0&&this.hostTree.data.setItemVisual(this.dataIndex,t,e)},t.prototype.getVisual=function(t){return this.hostTree.data.getItemVisual(this.dataIndex,t)},t.prototype.getRawIndex=function(){return this.hostTree.data.getRawIndex(this.dataIndex)},t.prototype.getId=function(){return this.hostTree.data.getId(this.dataIndex)},t.prototype.getChildIndex=function(){if(this.parentNode){for(var t=this.parentNode.children,e=0;e<t.length;++e)if(t[e]===this)return e;return-1}return-1},t.prototype.isAncestorOf=function(t){for(var e=t.parentNode;e;){if(e===this)return!0;e=e.parentNode}return!1},t.prototype.isDescendantOf=function(t){return t!==this&&t.isAncestorOf(this)},t}(),f=function(){function t(t){this.type="tree",this._nodes=[],this.hostModel=t}return t.prototype.eachNode=function(t,e,r){this.root.eachNode(t,e,r)},t.prototype.getNodeByDataIndex=function(t){var e=this.data.getRawIndex(t);return this._nodes[e]},t.prototype.getNodeById=function(t){return this.root.getNodeById(t)},t.prototype.update=function(){for(var t=this.data,e=this._nodes,r=0,n=e.length;r<n;r++)e[r].dataIndex=-1;for(r=0,n=t.count();r<n;r++)e[t.getRawIndex(r)].dataIndex=r},t.prototype.clearLayouts=function(){this.data.clearItemLayouts()},t.createTree=function(e,i,d){var h=new t(i),u=[],p=1;!function t(e,o){var a=e.value;p=Math.max(p,r(a)?a.length:1),u.push(e);var i=new c(n(e.name,""),h);o?function(t,e){var r=e.children;if(t.parentNode===e)return;r.push(t),t.parentNode=e}(i,o):h.root=i,h._nodes.push(i);var s=e.children;if(s)for(var d=0;d<s.length;d++)t(s[d],i)}(e),h.root.updateDepthAndHeight(0);var f=o(u,{coordDimensions:["value"],dimensionsCount:p}).dimensions,g=new a(f,i);return g.initData(u),d&&d(g),s({mainData:g,struct:h,structAttr:"tree"}),h.update(),h},t}();export{f as T,u as a,h as g,d as r,p as w};