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 { ChevronRight } from "@blueprintjs/icons";
|
20 | import { Classes, DISPLAYNAME_PREFIX } from "../../common";
|
21 | import { Collapse } from "../collapse/collapse";
|
22 | import { Icon } from "../icon/icon";
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var TreeNode = (function (_super) {
|
30 | __extends(TreeNode, _super);
|
31 | function TreeNode() {
|
32 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
33 | _this.handleCaretClick = function (e) {
|
34 | var _a;
|
35 | e.stopPropagation();
|
36 | var _b = _this.props, isExpanded = _b.isExpanded, onCollapse = _b.onCollapse, onExpand = _b.onExpand;
|
37 | (_a = (isExpanded ? onCollapse : onExpand)) === null || _a === void 0 ? void 0 : _a(_this.props, _this.props.path, e);
|
38 | };
|
39 | _this.handleClick = function (e) {
|
40 | var _a, _b;
|
41 | (_b = (_a = _this.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, _this.props, _this.props.path, e);
|
42 | };
|
43 | _this.handleContentRef = function (element) {
|
44 | var _a, _b;
|
45 | (_b = (_a = _this.props).contentRef) === null || _b === void 0 ? void 0 : _b.call(_a, _this.props, element);
|
46 | };
|
47 | _this.handleContextMenu = function (e) {
|
48 | var _a, _b;
|
49 | (_b = (_a = _this.props).onContextMenu) === null || _b === void 0 ? void 0 : _b.call(_a, _this.props, _this.props.path, e);
|
50 | };
|
51 | _this.handleDoubleClick = function (e) {
|
52 | var _a, _b;
|
53 | (_b = (_a = _this.props).onDoubleClick) === null || _b === void 0 ? void 0 : _b.call(_a, _this.props, _this.props.path, e);
|
54 | };
|
55 | _this.handleMouseEnter = function (e) {
|
56 | var _a, _b;
|
57 | (_b = (_a = _this.props).onMouseEnter) === null || _b === void 0 ? void 0 : _b.call(_a, _this.props, _this.props.path, e);
|
58 | };
|
59 | _this.handleMouseLeave = function (e) {
|
60 | var _a, _b;
|
61 | (_b = (_a = _this.props).onMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, _this.props, _this.props.path, e);
|
62 | };
|
63 | return _this;
|
64 | }
|
65 |
|
66 | TreeNode.ofType = function () {
|
67 | return TreeNode;
|
68 | };
|
69 | TreeNode.prototype.render = function () {
|
70 | var _a;
|
71 | var _b = this.props, children = _b.children, className = _b.className, disabled = _b.disabled, icon = _b.icon, isExpanded = _b.isExpanded, isSelected = _b.isSelected, label = _b.label;
|
72 | var classes = classNames(Classes.TREE_NODE, (_a = {},
|
73 | _a[Classes.DISABLED] = disabled,
|
74 | _a[Classes.TREE_NODE_SELECTED] = isSelected,
|
75 | _a[Classes.TREE_NODE_EXPANDED] = isExpanded,
|
76 | _a), className);
|
77 | var contentClasses = classNames(Classes.TREE_NODE_CONTENT, "".concat(Classes.TREE_NODE_CONTENT, "-").concat(this.props.depth));
|
78 | var eventHandlers = disabled === true
|
79 | ? {}
|
80 | : {
|
81 | onClick: this.handleClick,
|
82 | onContextMenu: this.handleContextMenu,
|
83 | onDoubleClick: this.handleDoubleClick,
|
84 | onMouseEnter: this.handleMouseEnter,
|
85 | onMouseLeave: this.handleMouseLeave,
|
86 | };
|
87 | return (React.createElement("li", { className: classes },
|
88 | React.createElement("div", __assign({ className: contentClasses, ref: this.handleContentRef }, eventHandlers),
|
89 | this.maybeRenderCaret(),
|
90 | React.createElement(Icon, { className: Classes.TREE_NODE_ICON, icon: icon, "aria-hidden": true, tabIndex: -1 }),
|
91 | React.createElement("span", { className: Classes.TREE_NODE_LABEL }, label),
|
92 | this.maybeRenderSecondaryLabel()),
|
93 | React.createElement(Collapse, { isOpen: isExpanded }, children)));
|
94 | };
|
95 | TreeNode.prototype.maybeRenderCaret = function () {
|
96 | var _a = this.props, children = _a.children, isExpanded = _a.isExpanded, disabled = _a.disabled, _b = _a.hasCaret, hasCaret = _b === void 0 ? React.Children.count(children) > 0 : _b;
|
97 | if (hasCaret) {
|
98 | var caretClasses = classNames(Classes.TREE_NODE_CARET, isExpanded ? Classes.TREE_NODE_CARET_OPEN : Classes.TREE_NODE_CARET_CLOSED);
|
99 | return (React.createElement(ChevronRight, { title: isExpanded ? "Collapse group" : "Expand group", className: caretClasses, onClick: disabled === true ? undefined : this.handleCaretClick }));
|
100 | }
|
101 | return React.createElement("span", { className: Classes.TREE_NODE_CARET_NONE });
|
102 | };
|
103 | TreeNode.prototype.maybeRenderSecondaryLabel = function () {
|
104 | if (this.props.secondaryLabel != null) {
|
105 | return React.createElement("span", { className: Classes.TREE_NODE_SECONDARY_LABEL }, this.props.secondaryLabel);
|
106 | }
|
107 | else {
|
108 | return undefined;
|
109 | }
|
110 | };
|
111 | TreeNode.displayName = "".concat(DISPLAYNAME_PREFIX, ".TreeNode");
|
112 | return TreeNode;
|
113 | }(React.Component));
|
114 | export { TreeNode };
|
115 |
|
\ | No newline at end of file |