1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __extends } from "tslib";
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | import * as React from "react";
|
23 | import * as ReactDOM from "react-dom";
|
24 | import { isDarkTheme, isFunction } from "../common/utils";
|
25 | import { show as showLegacyContextMenu } from "./contextMenuLegacy";
|
26 | import { getDisplayName } from "./legacyCommon";
|
27 | export var CONTEXTMENU_WARN_DECORATOR_NO_METHOD = "[Blueprint] @ContextMenuTarget-decorated class should implement renderContextMenu.";
|
28 | export var CONTEXTMENU_WARN_DECORATOR_NEEDS_REACT_ELEMENT = "[Blueprint] \"@ContextMenuTarget-decorated components must return a single JSX.Element or an empty render.";
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | export function ContextMenuTargetLegacy(WrappedComponent) {
|
36 | var _a;
|
37 | if (!isFunction(WrappedComponent.prototype.renderContextMenu)) {
|
38 | console.warn(CONTEXTMENU_WARN_DECORATOR_NO_METHOD);
|
39 | }
|
40 | return _a = (function (_super) {
|
41 | __extends(ContextMenuTargetClass, _super);
|
42 | function ContextMenuTargetClass() {
|
43 | return _super !== null && _super.apply(this, arguments) || this;
|
44 | }
|
45 | ContextMenuTargetClass.prototype.render = function () {
|
46 | var _this = this;
|
47 | var element = _super.prototype.render.call(this);
|
48 | if (element == null) {
|
49 |
|
50 | return element;
|
51 | }
|
52 | if (!React.isValidElement(element)) {
|
53 | console.warn(CONTEXTMENU_WARN_DECORATOR_NEEDS_REACT_ELEMENT);
|
54 | return element;
|
55 | }
|
56 | var oldOnContextMenu = element.props.onContextMenu;
|
57 | var onContextMenu = function (e) {
|
58 |
|
59 | if (e.defaultPrevented) {
|
60 | return;
|
61 | }
|
62 | if (isFunction(_this.renderContextMenu)) {
|
63 | var menu = _this.renderContextMenu(e);
|
64 | if (menu != null) {
|
65 |
|
66 |
|
67 | var darkTheme = isDarkTheme(ReactDOM.findDOMNode(_this));
|
68 | e.preventDefault();
|
69 | showLegacyContextMenu(menu, { left: e.clientX, top: e.clientY }, _this.onContextMenuClose, darkTheme);
|
70 | }
|
71 | }
|
72 | oldOnContextMenu === null || oldOnContextMenu === void 0 ? void 0 : oldOnContextMenu(e);
|
73 | };
|
74 | return React.cloneElement(element, { onContextMenu: onContextMenu });
|
75 | };
|
76 | return ContextMenuTargetClass;
|
77 | }(WrappedComponent)),
|
78 | _a.displayName = "ContextMenuTarget(".concat(getDisplayName(WrappedComponent), ")"),
|
79 | _a;
|
80 | }
|
81 |
|
\ | No newline at end of file |