@deephaven/components 0.5.2-beta.0 → 0.6.1-demo.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AutoCompleteInput.js +410 -448
- package/dist/AutoCompleteInput.js.map +1 -1
- package/dist/AutoResizeTextarea.js +17 -46
- package/dist/AutoResizeTextarea.js.map +1 -1
- package/dist/BasicModal.js +18 -19
- package/dist/BasicModal.js.map +1 -1
- package/dist/Button.js +30 -21
- package/dist/Button.js.map +1 -1
- package/dist/ButtonGroup.js +6 -4
- package/dist/ButtonGroup.js.map +1 -1
- package/dist/ButtonOld.js +10 -8
- package/dist/ButtonOld.js.map +1 -1
- package/dist/CardFlip.js +10 -8
- package/dist/CardFlip.js.map +1 -1
- package/dist/Checkbox.js +18 -31
- package/dist/Checkbox.js.map +1 -1
- package/dist/Collapse.js +65 -105
- package/dist/Collapse.js.map +1 -1
- package/dist/ComboBox.js +432 -460
- package/dist/ComboBox.js.map +1 -1
- package/dist/CustomTimeSelect.js +485 -517
- package/dist/CustomTimeSelect.js.map +1 -1
- package/dist/DebouncedSearchInput.js +61 -91
- package/dist/DebouncedSearchInput.js.map +1 -1
- package/dist/DeephavenSpinner.js +6 -6
- package/dist/DeephavenSpinner.js.map +1 -1
- package/dist/DragUtils.js +65 -113
- package/dist/DragUtils.js.map +1 -1
- package/dist/DraggableItemList.d.ts +1 -0
- package/dist/DraggableItemList.d.ts.map +1 -1
- package/dist/DraggableItemList.js +219 -257
- package/dist/DraggableItemList.js.map +1 -1
- package/dist/HierarchicalCheckboxMenu.js +160 -227
- package/dist/HierarchicalCheckboxMenu.js.map +1 -1
- package/dist/ItemList.d.ts +4 -2
- package/dist/ItemList.d.ts.map +1 -1
- package/dist/ItemList.js +595 -598
- package/dist/ItemList.js.map +1 -1
- package/dist/ItemListItem.js +194 -215
- package/dist/ItemListItem.js.map +1 -1
- package/dist/LoadingOverlay.js +9 -10
- package/dist/LoadingOverlay.js.map +1 -1
- package/dist/LoadingSpinner.js +4 -3
- package/dist/LoadingSpinner.js.map +1 -1
- package/dist/MaskedInput.js +59 -70
- package/dist/MaskedInput.js.map +1 -1
- package/dist/Option.js +5 -3
- package/dist/Option.js.map +1 -1
- package/dist/RadioGroup.js +16 -34
- package/dist/RadioGroup.js.map +1 -1
- package/dist/RadioItem.js +14 -33
- package/dist/RadioItem.js.map +1 -1
- package/dist/SearchInput.js +42 -75
- package/dist/SearchInput.js.map +1 -1
- package/dist/Select.js +10 -8
- package/dist/Select.js.map +1 -1
- package/dist/SelectValueList.js +97 -134
- package/dist/SelectValueList.js.map +1 -1
- package/dist/SocketedButton.js +13 -11
- package/dist/SocketedButton.js.map +1 -1
- package/dist/ThemeExport.js.map +1 -1
- package/dist/TimeInput.js +16 -53
- package/dist/TimeInput.js.map +1 -1
- package/dist/TimeSlider.js +62 -88
- package/dist/TimeSlider.js.map +1 -1
- package/dist/ToastNotification.js +14 -13
- package/dist/ToastNotification.js.map +1 -1
- package/dist/UISwitch.js +9 -8
- package/dist/UISwitch.js.map +1 -1
- package/dist/context-actions/ContextActionUtils.js +173 -231
- package/dist/context-actions/ContextActionUtils.js.map +1 -1
- package/dist/context-actions/ContextActions.js +135 -177
- package/dist/context-actions/ContextActions.js.map +1 -1
- package/dist/context-actions/ContextMenu.js +509 -543
- package/dist/context-actions/ContextMenu.js.map +1 -1
- package/dist/context-actions/ContextMenuItem.js +32 -22
- package/dist/context-actions/ContextMenuItem.js.map +1 -1
- package/dist/context-actions/ContextMenuRoot.js +112 -152
- package/dist/context-actions/ContextMenuRoot.js.map +1 -1
- package/dist/context-actions/GlobalContextAction.js +49 -84
- package/dist/context-actions/GlobalContextAction.js.map +1 -1
- package/dist/context-actions/GlobalContextActions.js +25 -57
- package/dist/context-actions/GlobalContextActions.js.map +1 -1
- package/dist/context-actions/index.js +4 -4
- package/dist/context-actions/index.js.map +1 -1
- package/dist/index.js +39 -39
- package/dist/index.js.map +1 -1
- package/dist/menu-actions/DropdownMenu.js +126 -159
- package/dist/menu-actions/DropdownMenu.js.map +1 -1
- package/dist/menu-actions/Menu.js +215 -245
- package/dist/menu-actions/Menu.js.map +1 -1
- package/dist/menu-actions/index.js +1 -1
- package/dist/menu-actions/index.js.map +1 -1
- package/dist/navigation/Menu.js +14 -18
- package/dist/navigation/Menu.js.map +1 -1
- package/dist/navigation/MenuItem.js +15 -14
- package/dist/navigation/MenuItem.js.map +1 -1
- package/dist/navigation/Page.js +7 -5
- package/dist/navigation/Page.js.map +1 -1
- package/dist/navigation/Stack.js +14 -39
- package/dist/navigation/Stack.js.map +1 -1
- package/dist/navigation/index.js +4 -4
- package/dist/navigation/index.js.map +1 -1
- package/dist/popper/Popper.js +209 -235
- package/dist/popper/Popper.js.map +1 -1
- package/dist/popper/Tooltip.js +227 -257
- package/dist/popper/Tooltip.js.map +1 -1
- package/dist/popper/index.js +2 -2
- package/dist/popper/index.js.map +1 -1
- package/dist/shortcuts/GlobalShortcuts.js +2 -2
- package/dist/shortcuts/GlobalShortcuts.js.map +1 -1
- package/dist/shortcuts/Shortcut.js +263 -291
- package/dist/shortcuts/Shortcut.js.map +1 -1
- package/dist/shortcuts/ShortcutRegistry.js +48 -71
- package/dist/shortcuts/ShortcutRegistry.js.map +1 -1
- package/dist/shortcuts/index.js +4 -4
- package/dist/shortcuts/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +30 -54
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
2
|
-
|
|
3
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
-
|
|
5
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
6
|
-
|
|
7
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
8
|
-
|
|
9
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
10
|
-
|
|
11
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
12
|
-
|
|
13
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
14
|
-
|
|
15
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
16
|
-
|
|
17
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
18
|
-
|
|
19
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
-
|
|
21
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
-
|
|
23
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
2
|
|
|
25
3
|
/**
|
|
@@ -27,8 +5,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
27
5
|
*/
|
|
28
6
|
import React, { Component } from 'react';
|
|
29
7
|
import Log from '@deephaven/log';
|
|
30
|
-
import ContextActionUtils from
|
|
31
|
-
import GlobalContextActions from
|
|
8
|
+
import ContextActionUtils from "./ContextActionUtils.js";
|
|
9
|
+
import GlobalContextActions from "./GlobalContextActions.js";
|
|
32
10
|
import "./ContextActions.css";
|
|
33
11
|
var log = Log.module('ContextActions');
|
|
34
12
|
|
|
@@ -58,195 +36,175 @@ var log = Log.module('ContextActions');
|
|
|
58
36
|
* Right clicking the container will then build the context menu, bubbling up until an element with a ContextMenuRoot is on it.
|
|
59
37
|
* You should generally have a ContextMenuRoot on the root node of your document.
|
|
60
38
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
39
|
+
class ContextActions extends Component {
|
|
40
|
+
/**
|
|
41
|
+
* Group you can assign to context menu actions to group them together.
|
|
42
|
+
* Lower group IDs appear at the top of the list.
|
|
43
|
+
* Groups are separated by a separator item.
|
|
44
|
+
* Items within groups are ordered by their order property, then by their title.
|
|
45
|
+
*/
|
|
46
|
+
static triggerMenu(element, clientX, clientY, actions) {
|
|
47
|
+
if (!element || !clientX || !clientY || !actions) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
68
50
|
|
|
69
|
-
|
|
51
|
+
var mouseEvent = new MouseEvent('contextmenu', {
|
|
52
|
+
clientX,
|
|
53
|
+
clientY,
|
|
54
|
+
bubbles: true,
|
|
55
|
+
cancelable: true
|
|
56
|
+
});
|
|
57
|
+
mouseEvent.contextActions = actions;
|
|
58
|
+
element.dispatchEvent(mouseEvent);
|
|
59
|
+
}
|
|
70
60
|
|
|
71
|
-
|
|
61
|
+
constructor(props) {
|
|
62
|
+
super(props);
|
|
72
63
|
|
|
73
|
-
_defineProperty(
|
|
64
|
+
_defineProperty(this, "container", void 0);
|
|
74
65
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
this.handleContextMenu = this.handleContextMenu.bind(this);
|
|
67
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
68
|
+
this.container = /*#__PURE__*/React.createRef();
|
|
69
|
+
this.state = {
|
|
79
70
|
globalActions: [],
|
|
80
71
|
keyboardActions: []
|
|
81
72
|
};
|
|
82
|
-
return _this;
|
|
83
73
|
}
|
|
84
74
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
static getDerivedStateFromProps(props) {
|
|
76
|
+
if (!props.actions || !Array.isArray(props.actions)) {
|
|
77
|
+
return {
|
|
78
|
+
globalActions: [],
|
|
79
|
+
keyboardActions: []
|
|
80
|
+
};
|
|
81
|
+
}
|
|
89
82
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
var globalActions = props.actions.filter(action => action.isGlobal);
|
|
84
|
+
var keyboardActions = props.actions.filter(action => !action.isGlobal && action.shortcut != null);
|
|
85
|
+
return {
|
|
86
|
+
globalActions,
|
|
87
|
+
keyboardActions
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
componentDidMount() {
|
|
92
|
+
var _this$container$curre;
|
|
93
|
+
|
|
94
|
+
if ((_this$container$curre = this.container.current) !== null && _this$container$curre !== void 0 && _this$container$curre.parentElement) {
|
|
95
|
+
this.container.current.parentElement.addEventListener('contextmenu', this.handleContextMenu);
|
|
96
|
+
this.container.current.parentElement.addEventListener('keydown', this.handleKeyDown);
|
|
94
97
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
componentWillUnmount() {
|
|
101
|
+
var _this$container$curre2;
|
|
102
|
+
|
|
103
|
+
if ((_this$container$curre2 = this.container.current) !== null && _this$container$curre2 !== void 0 && _this$container$curre2.parentElement) {
|
|
104
|
+
this.container.current.parentElement.removeEventListener('contextmenu', this.handleContextMenu);
|
|
105
|
+
this.container.current.parentElement.removeEventListener('keydown', this.handleKeyDown);
|
|
104
106
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
el = el.parentElement;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
while (el != null) {
|
|
132
|
-
var _ret = _loop();
|
|
133
|
-
|
|
134
|
-
if (_typeof(_ret) === "object") return _ret.v;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
handleContextMenu(e) {
|
|
110
|
+
var {
|
|
111
|
+
ignoreClassNames = []
|
|
112
|
+
} = this.props;
|
|
113
|
+
|
|
114
|
+
if (ignoreClassNames.length > 0) {
|
|
115
|
+
var el = e.target;
|
|
116
|
+
|
|
117
|
+
var _loop = function _loop() {
|
|
118
|
+
var {
|
|
119
|
+
classList
|
|
120
|
+
} = el;
|
|
121
|
+
var ignoredClassName = ignoreClassNames.find(className => classList.contains(className));
|
|
122
|
+
|
|
123
|
+
if (ignoredClassName !== undefined) {
|
|
124
|
+
log.debug2("Contextmenu event ignored based on the target className \"".concat(ignoredClassName, "\""));
|
|
125
|
+
return {
|
|
126
|
+
v: void 0
|
|
127
|
+
};
|
|
135
128
|
}
|
|
136
|
-
}
|
|
137
129
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
130
|
+
el = el.parentElement;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
while (el != null) {
|
|
134
|
+
var _ret = _loop();
|
|
141
135
|
|
|
142
|
-
|
|
143
|
-
return;
|
|
136
|
+
if (typeof _ret === "object") return _ret.v;
|
|
144
137
|
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!ContextActionUtils.isContextActionEvent(e)) {
|
|
141
|
+
e.contextActions = [];
|
|
142
|
+
}
|
|
145
143
|
|
|
146
|
-
|
|
144
|
+
if (!ContextActionUtils.isContextActionEvent(e)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
var {
|
|
149
|
+
actions
|
|
150
|
+
} = this.props;
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return !action.isGlobal;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
152
|
+
if (actions) {
|
|
153
|
+
var contextActions = actions;
|
|
156
154
|
|
|
157
|
-
|
|
155
|
+
if (Array.isArray(contextActions)) {
|
|
156
|
+
contextActions = contextActions.filter(action => !action.isGlobal);
|
|
158
157
|
}
|
|
159
158
|
|
|
160
|
-
|
|
159
|
+
e.contextActions = e.contextActions.concat(contextActions);
|
|
161
160
|
}
|
|
162
|
-
}, {
|
|
163
|
-
key: "handleKeyDown",
|
|
164
|
-
value: function handleKeyDown(e) {
|
|
165
|
-
var keyboardActions = this.state.keyboardActions;
|
|
166
161
|
|
|
167
|
-
|
|
168
|
-
|
|
162
|
+
log.debug('Received context menu event! Menu items are now: ', e.contextActions);
|
|
163
|
+
}
|
|
169
164
|
|
|
170
|
-
|
|
165
|
+
handleKeyDown(e) {
|
|
166
|
+
var {
|
|
167
|
+
keyboardActions
|
|
168
|
+
} = this.state;
|
|
171
169
|
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
for (var i = 0; i < keyboardActions.length; i += 1) {
|
|
171
|
+
var _keyboardAction$short;
|
|
174
172
|
|
|
175
|
-
|
|
176
|
-
var result = (_keyboardAction$actio = keyboardAction.action) === null || _keyboardAction$actio === void 0 ? void 0 : _keyboardAction$actio.call(keyboardAction, e);
|
|
173
|
+
var keyboardAction = keyboardActions[i];
|
|
177
174
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
e.preventDefault();
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
175
|
+
if (!ContextActionUtils.actionsDisabled && (_keyboardAction$short = keyboardAction.shortcut) !== null && _keyboardAction$short !== void 0 && _keyboardAction$short.matchesEvent(e)) {
|
|
176
|
+
var _keyboardAction$actio;
|
|
183
177
|
|
|
184
|
-
|
|
178
|
+
log.debug('Context hotkey matched!', e);
|
|
179
|
+
var result = (_keyboardAction$actio = keyboardAction.action) === null || _keyboardAction$actio === void 0 ? void 0 : _keyboardAction$actio.call(keyboardAction, e);
|
|
180
|
+
|
|
181
|
+
if (result || result === undefined) {
|
|
182
|
+
e.stopPropagation();
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
return;
|
|
185
185
|
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}, {
|
|
189
|
-
key: "render",
|
|
190
|
-
value: function render() {
|
|
191
|
-
var globalActions = this.state.globalActions;
|
|
192
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
193
|
-
className: "context-actions-listener",
|
|
194
|
-
ref: this.container
|
|
195
|
-
}, /*#__PURE__*/React.createElement(GlobalContextActions, {
|
|
196
|
-
actions: globalActions
|
|
197
|
-
}));
|
|
198
|
-
}
|
|
199
|
-
}], [{
|
|
200
|
-
key: "triggerMenu",
|
|
201
|
-
value:
|
|
202
|
-
/**
|
|
203
|
-
* Group you can assign to context menu actions to group them together.
|
|
204
|
-
* Lower group IDs appear at the top of the list.
|
|
205
|
-
* Groups are separated by a separator item.
|
|
206
|
-
* Items within groups are ordered by their order property, then by their title.
|
|
207
|
-
*/
|
|
208
|
-
function triggerMenu(element, clientX, clientY, actions) {
|
|
209
|
-
if (!element || !clientX || !clientY || !actions) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
186
|
|
|
213
|
-
|
|
214
|
-
clientX: clientX,
|
|
215
|
-
clientY: clientY,
|
|
216
|
-
bubbles: true,
|
|
217
|
-
cancelable: true
|
|
218
|
-
});
|
|
219
|
-
mouseEvent.contextActions = actions;
|
|
220
|
-
element.dispatchEvent(mouseEvent);
|
|
221
|
-
}
|
|
222
|
-
}, {
|
|
223
|
-
key: "getDerivedStateFromProps",
|
|
224
|
-
value: function getDerivedStateFromProps(props) {
|
|
225
|
-
if (!props.actions || !Array.isArray(props.actions)) {
|
|
226
|
-
return {
|
|
227
|
-
globalActions: [],
|
|
228
|
-
keyboardActions: []
|
|
229
|
-
};
|
|
187
|
+
log.debug2('Matched hotkey returned false, key event not consumed');
|
|
230
188
|
}
|
|
231
|
-
|
|
232
|
-
var globalActions = props.actions.filter(function (action) {
|
|
233
|
-
return action.isGlobal;
|
|
234
|
-
});
|
|
235
|
-
var keyboardActions = props.actions.filter(function (action) {
|
|
236
|
-
return !action.isGlobal && action.shortcut != null;
|
|
237
|
-
});
|
|
238
|
-
return {
|
|
239
|
-
globalActions: globalActions,
|
|
240
|
-
keyboardActions: keyboardActions
|
|
241
|
-
};
|
|
242
189
|
}
|
|
243
|
-
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
render() {
|
|
193
|
+
var {
|
|
194
|
+
globalActions
|
|
195
|
+
} = this.state;
|
|
196
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
197
|
+
className: "context-actions-listener",
|
|
198
|
+
ref: this.container
|
|
199
|
+
}, /*#__PURE__*/React.createElement(GlobalContextActions, {
|
|
200
|
+
actions: globalActions
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
244
203
|
|
|
245
|
-
|
|
246
|
-
}(Component);
|
|
204
|
+
}
|
|
247
205
|
|
|
248
206
|
_defineProperty(ContextActions, "groups", {
|
|
249
|
-
|
|
207
|
+
default: null,
|
|
250
208
|
high: 100,
|
|
251
209
|
medium: 5000,
|
|
252
210
|
low: 10000,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context-actions/ContextActions.tsx"],"names":["React","Component","Log","ContextActionUtils","GlobalContextActions","log","module","ContextActions","props","handleContextMenu","bind","handleKeyDown","container","createRef","state","globalActions","keyboardActions","current","parentElement","addEventListener","removeEventListener","e","ignoreClassNames","length","el","target","classList","ignoredClassName","find","className","contains","undefined","debug2","isContextActionEvent","contextActions","actions","Array","isArray","filter","action","isGlobal","concat","debug","i","keyboardAction","actionsDisabled","shortcut","matchesEvent","result","stopPropagation","preventDefault","element","clientX","clientY","mouseEvent","MouseEvent","bubbles","cancelable","dispatchEvent","high","medium","low","global","edit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AACA,OAAOC,GAAP,MAAgB,gBAAhB;AACA,OAAOC,kBAAP,MAA+B,sBAA/B;AAEA,OAAOC,oBAAP,MAAiC,wBAAjC;AACA;AAEA,IAAMC,GAAG,GAAGH,GAAG,CAACI,MAAJ,CAAW,gBAAX,CAAZ;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACMC,c;;;;;AA4CJ,0BAAYC,KAAZ,EAAwC;AAAA;;AAAA;;AACtC,8BAAMA,KAAN;;AADsC;;AAGtC,UAAKC,iBAAL,GAAyB,MAAKA,iBAAL,CAAuBC,IAAvB,+BAAzB;AACA,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UAAI,CAACA,KAAK,CAAC2B,OAAP,IAAkB,CAACC,KAAK,CAACC,OAAN,CAAc7B,KAAK,CAAC2B,OAApB,CAAvB,EAAqD;AACnD,eAAO;AAAEpB,UAAAA,aAAa,EAAE,EAAjB;AAAqBC,UAAAA,eAAe,EAAE;AAAtC,SAAP;AACD;;AACD,UAAMD,aAAa,GAAGP,KAAK,CAAC2B,OAAN,CAAcG,MAAd,CAAqB,UAAAC,MAAM;AAAA,eAAIA,MAAM,CAACC,QAAX;AAAA,OAA3B,CAAtB;AACA,UAAMxB,eAAe,GAAGR,KAAK,CAAC2B,OAAN,CAAcG,MAAd,CACtB,UAAAC,MAAM;AAAA,eAAI,CAACA,MAAM,CAACC,QAAR,IAAoBD,MAAM,CAACO,QAAP,IAAmB,IAA3C;AAAA,OADgB,CAAxB;AAIA,aAAO;AAAE/B,QAAAA,aAAa,EAAbA,aAAF;AAAiBC,QAAAA,eAAe,EAAfA;AAAjB,OAAP;AACD;;;;EAnE0Bf,S;;gBAAvBM,c,YAUY;AACd,aAAS,IADK;AAEdoD,EAAAA,IAAI,EAAE,GAFQ;AAGdC,EAAAA,MAAM,EAAE,IAHM;AAIdC,EAAAA,GAAG,EAAE,KAJS;AAKdC,EAAAA,MAAM,EAAE,MALM;AAOdC,EAAAA,IAAI,EAAE;AAPQ,C;;AAkKlB,eAAexD,cAAf","sourcesContent":["/**\n * Just a simple utility class for displaying a popup menu.\n */\nimport React, { Component } from 'react';\nimport Log from '@deephaven/log';\nimport ContextActionUtils from './ContextActionUtils';\nimport type { ContextAction, ContextActionEvent } from './ContextActionUtils';\nimport GlobalContextActions from './GlobalContextActions';\nimport './ContextActions.scss';\n\nconst log = Log.module('ContextActions');\n\ninterface ContextActionsProps {\n actions: ContextAction[] | (() => ContextAction[]);\n ignoreClassNames?: string[];\n}\n\ninterface ContextActionsState {\n globalActions: ContextAction[];\n keyboardActions: ContextAction[];\n}\n\n/**\n * ContextActions that you add onto any component.\n *\n * Usage:\n * let actions = [{\n * title: 'My Action', // Omit the title to hide it from the context menu\n * action: () => { alert('My Action Clicked!') }\n * actions: [] // Submenu of actions\n * icon: faPrint, // Limited to FontAwesome icons for now.\n * iconColor: '#ff0000, // Color to use for the icon\n * shortcut: Shortcut, // Defaults to null\n * isGlobal: false, // Global context action. Defaults to false.\n * group: ContextActions.groups.default, // What group to group the context action with\n * order: null, // Int where to order within group\n * disabled: true // disable action\n * menuElement: null // Custom menu element for displaying in context menu. When null, creates a default menu item based on title\n * }];\n *\n * <div>\n * Right click in this container\n * <ContextActions actions={actions}/>\n * </div>\n *\n * Right clicking the container will then build the context menu, bubbling up until an element with a ContextMenuRoot is on it.\n * You should generally have a ContextMenuRoot on the root node of your document.\n */\nclass ContextActions extends Component<\n ContextActionsProps,\n ContextActionsState\n> {\n /**\n * Group you can assign to context menu actions to group them together.\n * Lower group IDs appear at the top of the list.\n * Groups are separated by a separator item.\n * Items within groups are ordered by their order property, then by their title.\n */\n static groups = {\n default: null,\n high: 100,\n medium: 5000,\n low: 10000,\n global: 100000,\n\n edit: 100,\n };\n\n static triggerMenu(\n element: Element,\n clientX: number,\n clientY: number,\n actions: ContextAction[]\n ): void {\n if (!element || !clientX || !clientY || !actions) {\n return;\n }\n\n const mouseEvent: Partial<ContextActionEvent> = new MouseEvent(\n 'contextmenu',\n {\n clientX,\n clientY,\n bubbles: true,\n cancelable: true,\n }\n );\n mouseEvent.contextActions = actions;\n\n element.dispatchEvent(mouseEvent as ContextActionEvent);\n }\n\n constructor(props: ContextActionsProps) {\n super(props);\n\n this.handleContextMenu = this.handleContextMenu.bind(this);\n this.handleKeyDown = this.handleKeyDown.bind(this);\n\n this.container = React.createRef();\n\n this.state = { globalActions: [], keyboardActions: [] };\n }\n\n static getDerivedStateFromProps(\n props: ContextActionsProps\n ): ContextActionsState {\n if (!props.actions || !Array.isArray(props.actions)) {\n return { globalActions: [], keyboardActions: [] };\n }\n const globalActions = props.actions.filter(action => action.isGlobal);\n const keyboardActions = props.actions.filter(\n action => !action.isGlobal && action.shortcut != null\n );\n\n return { globalActions, keyboardActions };\n }\n\n componentDidMount(): void {\n if (this.container.current?.parentElement) {\n this.container.current.parentElement.addEventListener(\n 'contextmenu',\n this.handleContextMenu\n );\n this.container.current.parentElement.addEventListener(\n 'keydown',\n this.handleKeyDown\n );\n }\n }\n\n componentWillUnmount(): void {\n if (this.container.current?.parentElement) {\n this.container.current.parentElement.removeEventListener(\n 'contextmenu',\n this.handleContextMenu\n );\n this.container.current.parentElement.removeEventListener(\n 'keydown',\n this.handleKeyDown\n );\n }\n }\n\n container: React.RefObject<HTMLDivElement>;\n\n handleContextMenu(e: MouseEvent): void {\n const { ignoreClassNames = [] } = this.props;\n if (ignoreClassNames.length > 0) {\n let el = e.target as Element | null;\n while (el != null) {\n const { classList } = el;\n const ignoredClassName = ignoreClassNames.find(className =>\n classList.contains(className)\n );\n if (ignoredClassName !== undefined) {\n log.debug2(\n `Contextmenu event ignored based on the target className \"${ignoredClassName}\"`\n );\n return;\n }\n el = el.parentElement;\n }\n }\n if (!ContextActionUtils.isContextActionEvent(e)) {\n (e as ContextActionEvent).contextActions = [];\n }\n\n if (!ContextActionUtils.isContextActionEvent(e)) {\n return;\n }\n\n const { actions } = this.props;\n if (actions) {\n let contextActions = actions;\n if (Array.isArray(contextActions)) {\n contextActions = contextActions.filter(action => !action.isGlobal);\n }\n\n e.contextActions = e.contextActions.concat(contextActions);\n }\n\n log.debug(\n 'Received context menu event! Menu items are now: ',\n e.contextActions\n );\n }\n\n handleKeyDown(e: KeyboardEvent): void {\n const { keyboardActions } = this.state;\n for (let i = 0; i < keyboardActions.length; i += 1) {\n const keyboardAction = keyboardActions[i];\n if (\n !ContextActionUtils.actionsDisabled &&\n keyboardAction.shortcut?.matchesEvent(e)\n ) {\n log.debug('Context hotkey matched!', e);\n\n const result = keyboardAction.action?.(e);\n\n if (result || result === undefined) {\n e.stopPropagation();\n e.preventDefault();\n return;\n }\n\n log.debug2('Matched hotkey returned false, key event not consumed');\n }\n }\n }\n\n render(): JSX.Element {\n const { globalActions } = this.state;\n return (\n <div className=\"context-actions-listener\" ref={this.container}>\n <GlobalContextActions actions={globalActions} />\n </div>\n );\n }\n}\n\nexport default ContextActions;\n"],"file":"ContextActions.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/context-actions/ContextActions.tsx"],"names":["React","Component","Log","ContextActionUtils","GlobalContextActions","log","module","ContextActions","triggerMenu","element","clientX","clientY","actions","mouseEvent","MouseEvent","bubbles","cancelable","contextActions","dispatchEvent","constructor","props","handleContextMenu","bind","handleKeyDown","container","createRef","state","globalActions","keyboardActions","getDerivedStateFromProps","Array","isArray","filter","action","isGlobal","shortcut","componentDidMount","current","parentElement","addEventListener","componentWillUnmount","removeEventListener","e","ignoreClassNames","length","el","target","classList","ignoredClassName","find","className","contains","undefined","debug2","isContextActionEvent","concat","debug","i","keyboardAction","actionsDisabled","matchesEvent","result","stopPropagation","preventDefault","render","default","high","medium","low","global","edit"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AACA,OAAOC,GAAP,MAAgB,gBAAhB;OACOC,kB;OAEAC,oB;;AAGP,IAAMC,GAAG,GAAGH,GAAG,CAACI,MAAJ,CAAW,gBAAX,CAAZ;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,cAAN,SAA6BN,SAA7B,CAGE;AACA;AACF;AACA;AACA;AACA;AACA;AAWoB,SAAXO,WAAW,CAChBC,OADgB,EAEhBC,OAFgB,EAGhBC,OAHgB,EAIhBC,OAJgB,EAKV;AACN,QAAI,CAACH,OAAD,IAAY,CAACC,OAAb,IAAwB,CAACC,OAAzB,IAAoC,CAACC,OAAzC,EAAkD;AAChD;AACD;;AAED,QAAMC,UAAuC,GAAG,IAAIC,UAAJ,CAC9C,aAD8C,EAE9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KT,SAAzB,EAAoC;AAClCV,UAAAA,CAAC,CAACoB,eAAF;AACApB,UAAAA,CAAC,CAACqB,cAAF;AACA;AACD;;AAED1D,QAAAA,GAAG,CAACgD,MAAJ,CAAW,uDAAX;AACD;AACF;AACF;;AAEDW,EAAAA,MAAM,GAAgB;AACpB,QAAM;AAAErC,MAAAA;AAAF,QAAoB,KAAKD,KAA/B;AACA,wBACE;AAAK,MAAA,SAAS,EAAC,0BAAf;AAA0C,MAAA,GAAG,EAAE,KAAKF;AAApD,oBACE,oBAAC,oBAAD;AAAsB,MAAA,OAAO,EAAEG;AAA/B,MADF,CADF;AAKD;;AAtKD;;gBAHIpB,c,YAUY;AACd0D,EAAAA,OAAO,EAAE,IADK;AAEdC,EAAAA,IAAI,EAAE,GAFQ;AAGdC,EAAAA,MAAM,EAAE,IAHM;AAIdC,EAAAA,GAAG,EAAE,KAJS;AAKdC,EAAAA,MAAM,EAAE,MALM;AAOdC,EAAAA,IAAI,EAAE;AAPQ,C;;AAkKlB,eAAe/D,cAAf","sourcesContent":["/**\n * Just a simple utility class for displaying a popup menu.\n */\nimport React, { Component } from 'react';\nimport Log from '@deephaven/log';\nimport ContextActionUtils from './ContextActionUtils';\nimport type { ContextAction, ContextActionEvent } from './ContextActionUtils';\nimport GlobalContextActions from './GlobalContextActions';\nimport './ContextActions.scss';\n\nconst log = Log.module('ContextActions');\n\ninterface ContextActionsProps {\n actions: ContextAction[] | (() => ContextAction[]);\n ignoreClassNames?: string[];\n}\n\ninterface ContextActionsState {\n globalActions: ContextAction[];\n keyboardActions: ContextAction[];\n}\n\n/**\n * ContextActions that you add onto any component.\n *\n * Usage:\n * let actions = [{\n * title: 'My Action', // Omit the title to hide it from the context menu\n * action: () => { alert('My Action Clicked!') }\n * actions: [] // Submenu of actions\n * icon: faPrint, // Limited to FontAwesome icons for now.\n * iconColor: '#ff0000, // Color to use for the icon\n * shortcut: Shortcut, // Defaults to null\n * isGlobal: false, // Global context action. Defaults to false.\n * group: ContextActions.groups.default, // What group to group the context action with\n * order: null, // Int where to order within group\n * disabled: true // disable action\n * menuElement: null // Custom menu element for displaying in context menu. When null, creates a default menu item based on title\n * }];\n *\n * <div>\n * Right click in this container\n * <ContextActions actions={actions}/>\n * </div>\n *\n * Right clicking the container will then build the context menu, bubbling up until an element with a ContextMenuRoot is on it.\n * You should generally have a ContextMenuRoot on the root node of your document.\n */\nclass ContextActions extends Component<\n ContextActionsProps,\n ContextActionsState\n> {\n /**\n * Group you can assign to context menu actions to group them together.\n * Lower group IDs appear at the top of the list.\n * Groups are separated by a separator item.\n * Items within groups are ordered by their order property, then by their title.\n */\n static groups = {\n default: null,\n high: 100,\n medium: 5000,\n low: 10000,\n global: 100000,\n\n edit: 100,\n };\n\n static triggerMenu(\n element: Element,\n clientX: number,\n clientY: number,\n actions: ContextAction[]\n ): void {\n if (!element || !clientX || !clientY || !actions) {\n return;\n }\n\n const mouseEvent: Partial<ContextActionEvent> = new MouseEvent(\n 'contextmenu',\n {\n clientX,\n clientY,\n bubbles: true,\n cancelable: true,\n }\n );\n mouseEvent.contextActions = actions;\n\n element.dispatchEvent(mouseEvent as ContextActionEvent);\n }\n\n constructor(props: ContextActionsProps) {\n super(props);\n\n this.handleContextMenu = this.handleContextMenu.bind(this);\n this.handleKeyDown = this.handleKeyDown.bind(this);\n\n this.container = React.createRef();\n\n this.state = { globalActions: [], keyboardActions: [] };\n }\n\n static getDerivedStateFromProps(\n props: ContextActionsProps\n ): ContextActionsState {\n if (!props.actions || !Array.isArray(props.actions)) {\n return { globalActions: [], keyboardActions: [] };\n }\n const globalActions = props.actions.filter(action => action.isGlobal);\n const keyboardActions = props.actions.filter(\n action => !action.isGlobal && action.shortcut != null\n );\n\n return { globalActions, keyboardActions };\n }\n\n componentDidMount(): void {\n if (this.container.current?.parentElement) {\n this.container.current.parentElement.addEventListener(\n 'contextmenu',\n this.handleContextMenu\n );\n this.container.current.parentElement.addEventListener(\n 'keydown',\n this.handleKeyDown\n );\n }\n }\n\n componentWillUnmount(): void {\n if (this.container.current?.parentElement) {\n this.container.current.parentElement.removeEventListener(\n 'contextmenu',\n this.handleContextMenu\n );\n this.container.current.parentElement.removeEventListener(\n 'keydown',\n this.handleKeyDown\n );\n }\n }\n\n container: React.RefObject<HTMLDivElement>;\n\n handleContextMenu(e: MouseEvent): void {\n const { ignoreClassNames = [] } = this.props;\n if (ignoreClassNames.length > 0) {\n let el = e.target as Element | null;\n while (el != null) {\n const { classList } = el;\n const ignoredClassName = ignoreClassNames.find(className =>\n classList.contains(className)\n );\n if (ignoredClassName !== undefined) {\n log.debug2(\n `Contextmenu event ignored based on the target className \"${ignoredClassName}\"`\n );\n return;\n }\n el = el.parentElement;\n }\n }\n if (!ContextActionUtils.isContextActionEvent(e)) {\n (e as ContextActionEvent).contextActions = [];\n }\n\n if (!ContextActionUtils.isContextActionEvent(e)) {\n return;\n }\n\n const { actions } = this.props;\n if (actions) {\n let contextActions = actions;\n if (Array.isArray(contextActions)) {\n contextActions = contextActions.filter(action => !action.isGlobal);\n }\n\n e.contextActions = e.contextActions.concat(contextActions);\n }\n\n log.debug(\n 'Received context menu event! Menu items are now: ',\n e.contextActions\n );\n }\n\n handleKeyDown(e: KeyboardEvent): void {\n const { keyboardActions } = this.state;\n for (let i = 0; i < keyboardActions.length; i += 1) {\n const keyboardAction = keyboardActions[i];\n if (\n !ContextActionUtils.actionsDisabled &&\n keyboardAction.shortcut?.matchesEvent(e)\n ) {\n log.debug('Context hotkey matched!', e);\n\n const result = keyboardAction.action?.(e);\n\n if (result || result === undefined) {\n e.stopPropagation();\n e.preventDefault();\n return;\n }\n\n log.debug2('Matched hotkey returned false, key event not consumed');\n }\n }\n }\n\n render(): JSX.Element {\n const { globalActions } = this.state;\n return (\n <div className=\"context-actions-listener\" ref={this.container}>\n <GlobalContextActions actions={globalActions} />\n </div>\n );\n }\n}\n\nexport default ContextActions;\n"],"file":"ContextActions.js"}
|