1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __assign, __extends } from "tslib";
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 | import { Classes, DISPLAYNAME_PREFIX } from "../../common";
|
20 | import { TreeNode } from "./treeNode";
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | var Tree = (function (_super) {
|
28 | __extends(Tree, _super);
|
29 | function Tree() {
|
30 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
31 | _this.nodeRefs = {};
|
32 | _this.handleContentRef = function (node, element) {
|
33 | if (element != null) {
|
34 | _this.nodeRefs[node.id] = element;
|
35 | }
|
36 | else {
|
37 |
|
38 | delete _this.nodeRefs[node.id];
|
39 | }
|
40 | };
|
41 | _this.handleNodeCollapse = function (node, path, e) {
|
42 | var _a, _b;
|
43 | (_b = (_a = _this.props).onNodeCollapse) === null || _b === void 0 ? void 0 : _b.call(_a, node, path, e);
|
44 | };
|
45 | _this.handleNodeClick = function (node, path, e) {
|
46 | var _a, _b;
|
47 | (_b = (_a = _this.props).onNodeClick) === null || _b === void 0 ? void 0 : _b.call(_a, node, path, e);
|
48 | };
|
49 | _this.handleNodeContextMenu = function (node, path, e) {
|
50 | var _a, _b;
|
51 | (_b = (_a = _this.props).onNodeContextMenu) === null || _b === void 0 ? void 0 : _b.call(_a, node, path, e);
|
52 | };
|
53 | _this.handleNodeDoubleClick = function (node, path, e) {
|
54 | var _a, _b;
|
55 | (_b = (_a = _this.props).onNodeDoubleClick) === null || _b === void 0 ? void 0 : _b.call(_a, node, path, e);
|
56 | };
|
57 | _this.handleNodeExpand = function (node, path, e) {
|
58 | var _a, _b;
|
59 | (_b = (_a = _this.props).onNodeExpand) === null || _b === void 0 ? void 0 : _b.call(_a, node, path, e);
|
60 | };
|
61 | _this.handleNodeMouseEnter = function (node, path, e) {
|
62 | var _a, _b;
|
63 | (_b = (_a = _this.props).onNodeMouseEnter) === null || _b === void 0 ? void 0 : _b.call(_a, node, path, e);
|
64 | };
|
65 | _this.handleNodeMouseLeave = function (node, path, e) {
|
66 | var _a, _b;
|
67 | (_b = (_a = _this.props).onNodeMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, node, path, e);
|
68 | };
|
69 | return _this;
|
70 | }
|
71 | Tree.ofType = function () {
|
72 | return Tree;
|
73 | };
|
74 | Tree.nodeFromPath = function (path, treeNodes) {
|
75 | if (path.length === 1) {
|
76 | return treeNodes[path[0]];
|
77 | }
|
78 | else {
|
79 | return Tree.nodeFromPath(path.slice(1), treeNodes[path[0]].childNodes);
|
80 | }
|
81 | };
|
82 | Tree.prototype.render = function () {
|
83 | var _a;
|
84 | return (React.createElement("div", { className: classNames(Classes.TREE, this.props.className, (_a = {},
|
85 | _a[Classes.COMPACT] = this.props.compact,
|
86 | _a)) }, this.renderNodes(this.props.contents, [], Classes.TREE_ROOT)));
|
87 | };
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 | Tree.prototype.getNodeContentElement = function (nodeId) {
|
94 | return this.nodeRefs[nodeId];
|
95 | };
|
96 | Tree.prototype.renderNodes = function (treeNodes, currentPath, className) {
|
97 | var _this = this;
|
98 | if (treeNodes == null) {
|
99 | return null;
|
100 | }
|
101 | var nodeItems = treeNodes.map(function (node, i) {
|
102 | var elementPath = currentPath.concat(i);
|
103 | return (React.createElement(TreeNode, __assign({}, node, { key: node.id, contentRef: _this.handleContentRef, depth: elementPath.length - 1, onClick: _this.handleNodeClick, onContextMenu: _this.handleNodeContextMenu, onCollapse: _this.handleNodeCollapse, onDoubleClick: _this.handleNodeDoubleClick, onExpand: _this.handleNodeExpand, onMouseEnter: _this.handleNodeMouseEnter, onMouseLeave: _this.handleNodeMouseLeave, path: elementPath }), _this.renderNodes(node.childNodes, elementPath)));
|
104 | });
|
105 | return React.createElement("ul", { className: classNames(Classes.TREE_NODE_LIST, className) }, nodeItems);
|
106 | };
|
107 | Tree.displayName = "".concat(DISPLAYNAME_PREFIX, ".Tree");
|
108 | return Tree;
|
109 | }(React.Component));
|
110 | export { Tree };
|
111 |
|
\ | No newline at end of file |