1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __assign } from "tslib";
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | import classNames from "classnames";
|
23 | import * as React from "react";
|
24 | import * as ReactDOM from "react-dom";
|
25 | import { Classes } from "../common";
|
26 | import { Dialog, Hotkey, Hotkeys } from "../components";
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var DELAY_IN_MS = 10;
|
32 |
|
33 | var HotkeysDialogLegacy = (function () {
|
34 | function HotkeysDialogLegacy() {
|
35 | var _this = this;
|
36 | this.componentProps = {
|
37 | globalHotkeysGroup: "Global hotkeys",
|
38 | };
|
39 | this.container = null;
|
40 | this.hotkeysQueue = [];
|
41 | this.isDialogShowing = false;
|
42 | this.show = function () {
|
43 | _this.isDialogShowing = true;
|
44 | _this.render();
|
45 | };
|
46 | this.hide = function () {
|
47 | _this.isDialogShowing = false;
|
48 | _this.render();
|
49 | };
|
50 | }
|
51 | HotkeysDialogLegacy.prototype.render = function () {
|
52 | if (this.container == null) {
|
53 | this.container = this.getContainer();
|
54 | }
|
55 | ReactDOM.render(this.renderComponent(), this.container);
|
56 | };
|
57 | HotkeysDialogLegacy.prototype.unmount = function () {
|
58 | if (this.container != null) {
|
59 | ReactDOM.unmountComponentAtNode(this.container);
|
60 | this.container.remove();
|
61 | this.container = null;
|
62 | }
|
63 | };
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | HotkeysDialogLegacy.prototype.enqueueHotkeysForDisplay = function (hotkeys) {
|
73 | this.hotkeysQueue.push(hotkeys);
|
74 |
|
75 | window.clearTimeout(this.showTimeoutToken);
|
76 | this.showTimeoutToken = window.setTimeout(this.show, DELAY_IN_MS);
|
77 | };
|
78 | HotkeysDialogLegacy.prototype.hideAfterDelay = function () {
|
79 | window.clearTimeout(this.hideTimeoutToken);
|
80 | this.hideTimeoutToken = window.setTimeout(this.hide, DELAY_IN_MS);
|
81 | };
|
82 | HotkeysDialogLegacy.prototype.isShowing = function () {
|
83 | return this.isDialogShowing;
|
84 | };
|
85 | HotkeysDialogLegacy.prototype.getContainer = function () {
|
86 | if (this.container == null) {
|
87 | this.container = document.createElement("div");
|
88 | this.container.classList.add(Classes.PORTAL);
|
89 | document.body.appendChild(this.container);
|
90 | }
|
91 | return this.container;
|
92 | };
|
93 | HotkeysDialogLegacy.prototype.renderComponent = function () {
|
94 | return (React.createElement(Dialog, __assign({}, this.componentProps, { className: classNames(Classes.HOTKEY_DIALOG, this.componentProps.className), isOpen: this.isDialogShowing, onClose: this.hide }),
|
95 | React.createElement("div", { className: Classes.DIALOG_BODY }, this.renderHotkeys())));
|
96 | };
|
97 | HotkeysDialogLegacy.prototype.renderHotkeys = function () {
|
98 | var _this = this;
|
99 | var hotkeys = this.emptyHotkeyQueue();
|
100 | var elements = hotkeys.map(function (hotkey, index) {
|
101 | var group = hotkey.global === true && hotkey.group == null ? _this.componentProps.globalHotkeysGroup : hotkey.group;
|
102 | return React.createElement(Hotkey, __assign({ key: index }, hotkey, { group: group }));
|
103 | });
|
104 | return React.createElement(Hotkeys, null, elements);
|
105 | };
|
106 | HotkeysDialogLegacy.prototype.emptyHotkeyQueue = function () {
|
107 |
|
108 | var hotkeys = this.hotkeysQueue.reduce(function (arr, queued) { return arr.concat(queued); }, []);
|
109 | this.hotkeysQueue.length = 0;
|
110 | return hotkeys;
|
111 | };
|
112 | return HotkeysDialogLegacy;
|
113 | }());
|
114 |
|
115 | var HOTKEYS_DIALOG = new HotkeysDialogLegacy();
|
116 |
|
117 | export function isHotkeysDialogShowing() {
|
118 | return HOTKEYS_DIALOG.isShowing();
|
119 | }
|
120 |
|
121 | export function setHotkeysDialogProps(props) {
|
122 | for (var key in props) {
|
123 | if (props.hasOwnProperty(key)) {
|
124 | HOTKEYS_DIALOG.componentProps[key] = props[key];
|
125 | }
|
126 | }
|
127 | }
|
128 |
|
129 | export function showHotkeysDialog(hotkeys) {
|
130 | HOTKEYS_DIALOG.enqueueHotkeysForDisplay(hotkeys);
|
131 | }
|
132 |
|
133 | export function hideHotkeysDialog() {
|
134 | HOTKEYS_DIALOG.hide();
|
135 | }
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | export function hideHotkeysDialogAfterDelay() {
|
144 | HOTKEYS_DIALOG.hideAfterDelay();
|
145 | }
|
146 |
|
\ | No newline at end of file |