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