@deephaven/components 0.5.2-beta.0 → 0.6.1-demo.8
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
|
@@ -2,271 +2,213 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
2
2
|
|
|
3
3
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
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); } }
|
|
5
|
+
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; }
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
class ContextActionUtils {
|
|
8
|
+
static disableAllActions() {
|
|
9
|
+
ContextActionUtils.actionsDisabled = true;
|
|
10
|
+
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
static enableAllActions() {
|
|
13
|
+
ContextActionUtils.actionsDisabled = false;
|
|
14
|
+
}
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_classCallCheck(this, ContextActionUtils);
|
|
16
|
+
static isContextActionEvent(e) {
|
|
17
|
+
return Array.isArray(e.contextActions);
|
|
16
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Compare two action items. Useful in Array.sort
|
|
21
|
+
* @param a First context action to compare
|
|
22
|
+
* @param b Second context action to compare
|
|
23
|
+
*/
|
|
24
|
+
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
ContextActionUtils.actionsDisabled = true;
|
|
26
|
+
static compareActions(a, b) {
|
|
27
|
+
if (a.group !== b.group) {
|
|
28
|
+
return (a.group || 0) > (b.group || 0) ? 1 : -1;
|
|
22
29
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
ContextActionUtils.actionsDisabled = false;
|
|
30
|
+
|
|
31
|
+
if (a.order !== b.order) {
|
|
32
|
+
return (a.order || 0) > (b.order || 0) ? 1 : -1;
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return Array.isArray(e.contextActions);
|
|
34
|
+
|
|
35
|
+
if (a.title !== b.title) {
|
|
36
|
+
return (a.title || '') > (b.title || '') ? 1 : -1;
|
|
32
37
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Compare two action items. Useful in Array.sort
|
|
35
|
-
* @param a First context action to compare
|
|
36
|
-
* @param b Second context action to compare
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
}, {
|
|
40
|
-
key: "compareActions",
|
|
41
|
-
value: function compareActions(a, b) {
|
|
42
|
-
if (a.group !== b.group) {
|
|
43
|
-
return (a.group || 0) > (b.group || 0) ? 1 : -1;
|
|
44
|
-
}
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
if (a !== b) {
|
|
40
|
+
return a > b ? 1 : -1;
|
|
41
|
+
}
|
|
49
42
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param actions The array of actions to sort
|
|
48
|
+
*/
|
|
53
49
|
|
|
54
|
-
if (a !== b) {
|
|
55
|
-
return a > b ? 1 : -1;
|
|
56
|
-
}
|
|
57
50
|
|
|
58
|
-
|
|
51
|
+
static sortActions(actions) {
|
|
52
|
+
if (!actions || !Array.isArray(actions)) {
|
|
53
|
+
return [];
|
|
59
54
|
}
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* @param actions The array of actions to sort
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
}, {
|
|
66
|
-
key: "sortActions",
|
|
67
|
-
value: function sortActions(actions) {
|
|
68
|
-
if (!actions || !Array.isArray(actions)) {
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
55
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
56
|
+
var sortedActions = actions.slice();
|
|
57
|
+
sortedActions.sort(ContextActionUtils.compareActions);
|
|
58
|
+
return sortedActions;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static isMacPlatform() {
|
|
62
|
+
var {
|
|
63
|
+
platform
|
|
64
|
+
} = window.navigator;
|
|
65
|
+
return platform.startsWith('Mac');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Retrieve the preferred modifier key based on the current platform
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
static getModifierKey() {
|
|
73
|
+
if (ContextActionUtils.isMacPlatform()) {
|
|
74
|
+
return 'metaKey';
|
|
81
75
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
|
|
77
|
+
return 'ctrlKey';
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns true if the modifier key for the current platform is down for the event (Ctrl for windows/linux, Command (meta) for mac)
|
|
81
|
+
* @param event The event to get the meta key status from
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
static isModifierKeyDown(event) {
|
|
86
|
+
var modifierKey = ContextActionUtils.getModifierKey();
|
|
87
|
+
return event[modifierKey];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Copy the passed in text to the clipboard.
|
|
91
|
+
* @param text The text to copy
|
|
92
|
+
* @returns Promise Resolved on success, rejected on failure
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
static copyToClipboard(text) {
|
|
97
|
+
return _asyncToGenerator(function* () {
|
|
98
|
+
try {
|
|
99
|
+
var permissions = yield navigator.permissions.query({
|
|
100
|
+
name: 'clipboard-write'
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (permissions.state !== 'granted' && permissions.state !== 'prompt') {
|
|
104
|
+
throw new Error('Invalid permissions for clipboard-write');
|
|
105
|
+
}
|
|
106
|
+
} catch (e) {
|
|
107
|
+
// Fallback if we can't get permissions for some reason
|
|
108
|
+
ContextActionUtils.copyToClipboardExecCommand(text);
|
|
109
|
+
return;
|
|
91
110
|
}
|
|
92
111
|
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
yield navigator.clipboard.writeText(text);
|
|
113
|
+
})();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Copy the passed in text to the clipboard using the `execCommand` functionality
|
|
117
|
+
* Throws on error/failure
|
|
118
|
+
* @param text The text to copy
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
static copyToClipboardExecCommand(text) {
|
|
123
|
+
var oldFocus = document.activeElement;
|
|
124
|
+
var textArea = document.createElement('textarea');
|
|
125
|
+
textArea.value = text;
|
|
126
|
+
document.body.appendChild(textArea);
|
|
127
|
+
textArea.focus();
|
|
128
|
+
textArea.select();
|
|
129
|
+
|
|
130
|
+
if (!document.execCommand('copy')) {
|
|
131
|
+
throw new Error('Unable to execute copy command');
|
|
105
132
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Copy the passed in text to the clipboard.
|
|
108
|
-
* @param text The text to copy
|
|
109
|
-
* @returns Promise Resolved on success, rejected on failure
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
}, {
|
|
113
|
-
key: "copyToClipboard",
|
|
114
|
-
value: function () {
|
|
115
|
-
var _copyToClipboard = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(text) {
|
|
116
|
-
var permissions;
|
|
117
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
118
|
-
while (1) {
|
|
119
|
-
switch (_context.prev = _context.next) {
|
|
120
|
-
case 0:
|
|
121
|
-
_context.prev = 0;
|
|
122
|
-
_context.next = 3;
|
|
123
|
-
return navigator.permissions.query({
|
|
124
|
-
name: 'clipboard-write'
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
case 3:
|
|
128
|
-
permissions = _context.sent;
|
|
129
|
-
|
|
130
|
-
if (!(permissions.state !== 'granted' && permissions.state !== 'prompt')) {
|
|
131
|
-
_context.next = 6;
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
throw new Error('Invalid permissions for clipboard-write');
|
|
136
|
-
|
|
137
|
-
case 6:
|
|
138
|
-
_context.next = 12;
|
|
139
|
-
break;
|
|
140
|
-
|
|
141
|
-
case 8:
|
|
142
|
-
_context.prev = 8;
|
|
143
|
-
_context.t0 = _context["catch"](0);
|
|
144
|
-
// Fallback if we can't get permissions for some reason
|
|
145
|
-
ContextActionUtils.copyToClipboardExecCommand(text);
|
|
146
|
-
return _context.abrupt("return");
|
|
147
|
-
|
|
148
|
-
case 12:
|
|
149
|
-
_context.next = 14;
|
|
150
|
-
return navigator.clipboard.writeText(text);
|
|
151
|
-
|
|
152
|
-
case 14:
|
|
153
|
-
case "end":
|
|
154
|
-
return _context.stop();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}, _callee, null, [[0, 8]]);
|
|
158
|
-
}));
|
|
159
133
|
|
|
160
|
-
|
|
161
|
-
return _copyToClipboard.apply(this, arguments);
|
|
162
|
-
}
|
|
134
|
+
document.body.removeChild(textArea);
|
|
163
135
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
key: "copyToClipboardExecCommand",
|
|
174
|
-
value: function copyToClipboardExecCommand(text) {
|
|
175
|
-
var oldFocus = document.activeElement;
|
|
176
|
-
var textArea = document.createElement('textarea');
|
|
177
|
-
textArea.value = text;
|
|
178
|
-
document.body.appendChild(textArea);
|
|
179
|
-
textArea.focus();
|
|
180
|
-
textArea.select();
|
|
181
|
-
|
|
182
|
-
if (!document.execCommand('copy')) {
|
|
183
|
-
throw new Error('Unable to execute copy command');
|
|
184
|
-
}
|
|
136
|
+
if (oldFocus instanceof HTMLElement) {
|
|
137
|
+
oldFocus.focus();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns the menu items for the provided context actions, or empty array if none found.
|
|
142
|
+
* @param actionsParam The actions to get menu items for
|
|
143
|
+
* @param includePromises Whether or not to include promises in the returned menu items
|
|
144
|
+
*/
|
|
185
145
|
|
|
186
|
-
document.body.removeChild(textArea);
|
|
187
146
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
147
|
+
static getMenuItems(actionsParam) {
|
|
148
|
+
var includePromises = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
149
|
+
var menuItems = [];
|
|
150
|
+
var actions = actionsParam;
|
|
151
|
+
|
|
152
|
+
if (!Array.isArray(actions)) {
|
|
153
|
+
actions = [actions];
|
|
191
154
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Returns the menu items for the provided context actions, or empty array if none found.
|
|
194
|
-
* @param actionsParam The actions to get menu items for
|
|
195
|
-
* @param includePromises Whether or not to include promises in the returned menu items
|
|
196
|
-
*/
|
|
197
|
-
|
|
198
|
-
}, {
|
|
199
|
-
key: "getMenuItems",
|
|
200
|
-
value: function getMenuItems(actionsParam) {
|
|
201
|
-
var includePromises = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
202
|
-
var menuItems = [];
|
|
203
|
-
var actions = actionsParam;
|
|
204
|
-
|
|
205
|
-
if (!Array.isArray(actions)) {
|
|
206
|
-
actions = [actions];
|
|
207
|
-
}
|
|
208
155
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
156
|
+
for (var i = 0; i < actions.length; i += 1) {
|
|
157
|
+
var _action = actions[i];
|
|
158
|
+
var newMenuItems = void 0;
|
|
212
159
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
160
|
+
if (typeof _action === 'function') {
|
|
161
|
+
newMenuItems = _action();
|
|
162
|
+
} else {
|
|
163
|
+
newMenuItems = _action;
|
|
164
|
+
}
|
|
218
165
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
menuItems.push(newMenuItems);
|
|
223
|
-
}
|
|
224
|
-
} else if (Array.isArray(newMenuItems)) {
|
|
225
|
-
menuItems = menuItems.concat(newMenuItems);
|
|
226
|
-
} else {
|
|
166
|
+
if (newMenuItems != null) {
|
|
167
|
+
if (newMenuItems instanceof Promise) {
|
|
168
|
+
if (includePromises) {
|
|
227
169
|
menuItems.push(newMenuItems);
|
|
228
170
|
}
|
|
171
|
+
} else if (Array.isArray(newMenuItems)) {
|
|
172
|
+
menuItems = menuItems.concat(newMenuItems);
|
|
173
|
+
} else {
|
|
174
|
+
menuItems.push(newMenuItems);
|
|
229
175
|
}
|
|
230
176
|
}
|
|
231
|
-
|
|
232
|
-
menuItems = menuItems.filter(function (action) {
|
|
233
|
-
return action.title || action.then || action.menuElement;
|
|
234
|
-
});
|
|
235
|
-
return menuItems;
|
|
236
177
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Returns the index of the next menu item in a list that doesn't have a disabled=true prop
|
|
239
|
-
* @param startIndex the starting position for the iteration
|
|
240
|
-
* @param delta the direction of travel, -1 or 1
|
|
241
|
-
* @param menuItems an array of menuItems
|
|
242
|
-
*/
|
|
243
|
-
|
|
244
|
-
}, {
|
|
245
|
-
key: "getNextMenuItem",
|
|
246
|
-
value: function getNextMenuItem(startIndex, delta, menuItems) {
|
|
247
|
-
var firstIndex = startIndex;
|
|
248
|
-
|
|
249
|
-
if (firstIndex < 0 && delta < 0) {
|
|
250
|
-
// if menu index is -1 and delta -1 manually set start point
|
|
251
|
-
firstIndex = menuItems.length;
|
|
252
|
-
} // find the next non disabled menu option, iterating the list only once
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
for (var i = 1; i < menuItems.length + 1; i += 1) {
|
|
256
|
-
var menuIndex = (firstIndex + delta * i + menuItems.length) % menuItems.length;
|
|
257
|
-
var item = menuItems[menuIndex];
|
|
258
|
-
|
|
259
|
-
if (!(item instanceof Promise) && item.disabled !== true) {
|
|
260
|
-
return menuIndex;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
178
|
|
|
264
|
-
|
|
179
|
+
menuItems = menuItems.filter(action => action.title || action.then || action.menuElement);
|
|
180
|
+
return menuItems;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Returns the index of the next menu item in a list that doesn't have a disabled=true prop
|
|
184
|
+
* @param startIndex the starting position for the iteration
|
|
185
|
+
* @param delta the direction of travel, -1 or 1
|
|
186
|
+
* @param menuItems an array of menuItems
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
static getNextMenuItem(startIndex, delta, menuItems) {
|
|
191
|
+
var firstIndex = startIndex;
|
|
192
|
+
|
|
193
|
+
if (firstIndex < 0 && delta < 0) {
|
|
194
|
+
// if menu index is -1 and delta -1 manually set start point
|
|
195
|
+
firstIndex = menuItems.length;
|
|
196
|
+
} // find the next non disabled menu option, iterating the list only once
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
for (var i = 1; i < menuItems.length + 1; i += 1) {
|
|
200
|
+
var menuIndex = (firstIndex + delta * i + menuItems.length) % menuItems.length;
|
|
201
|
+
var item = menuItems[menuIndex];
|
|
202
|
+
|
|
203
|
+
if (!(item instanceof Promise) && item.disabled !== true) {
|
|
204
|
+
return menuIndex;
|
|
205
|
+
}
|
|
265
206
|
}
|
|
266
|
-
}]);
|
|
267
207
|
|
|
268
|
-
|
|
269
|
-
}
|
|
208
|
+
return startIndex;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
}
|
|
270
212
|
|
|
271
213
|
_defineProperty(ContextActionUtils, "actionsDisabled", false);
|
|
272
214
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context-actions/ContextActionUtils.ts"],"names":["ContextActionUtils","actionsDisabled","e","Array","isArray","contextActions","a","b","group","order","title","actions","sortedActions","slice","sort","compareActions","platform","window","navigator","startsWith","isMacPlatform","event","modifierKey","getModifierKey","text","permissions","query","name","state","Error","copyToClipboardExecCommand","clipboard","writeText","oldFocus","document","activeElement","textArea","createElement","value","body","appendChild","focus","select","execCommand","removeChild","HTMLElement","actionsParam","includePromises","menuItems","i","length","action","newMenuItems","Promise","push","concat","filter","then","menuElement","startIndex","delta","firstIndex","menuIndex","item","disabled"],"mappings":";;;;;;;;;;;;IA+BMA,kB;;;;;;;WAGJ,6BAAiC;AAC/BA,MAAAA,kBAAkB,CAACC,eAAnB,GAAqC,IAArC;AACD;;;WAED,4BAAgC;AAC9BD,MAAAA,kBAAkB,CAACC,eAAnB,GAAqC,KAArC;AACD;;;WAED,8BAA4BC,CAA5B,EAAoE;AAClE,aAAOC,KAAK,CAACC,OAAN,CAAeF,CAAD,CAA0BG,cAAxC,CAAP;AACD;AAED;AACF;AACA;AACA;AACA;;;;WACE,wBAAsBC,CAAtB,EAAwCC,CAAxC,EAAkE;AAChE,UAAID,CAAC,CAACE,KAAF,KAAYD,CAAC,CAACC,KAAlB,EAAyB;AACvB,eAAO,CAACF,CAAC,CAACE,KAAF,IAAW,CAAZ,KAAkBD,CAAC,CAACC,KAAF,IAAW,CAA7B,IAAkC,CAAlC,GAAsC,CAAC,CAA9C;AACD;;AAED,UAAIF,CAAC,CAACG,KAAF,KAAYF,CAAC,CAACE,KAAlB,EAAyB;AACvB,eAAO,CAACH,CAAC,CAACG,KAAF,IAAW,CAAZ,KAAkBF,CAAC,CAACE,KAAF,IAAW,CAA7B,IAAkC,CAAlC,GAAsC,CAAC,CAA9C;AACD;;AAED,UAAIH,CAAC,CAACI,KAAF,KAAYH,CAAC,CAACG,KAAlB,EAAyB;AACvB,eAAO,CAACJ,CAAC,CAACI,KAAF,IAAW,EAAZ,KAAmBH,CAAC,CAACG,KAAF,IAAW,EAA9B,IAAoC,CAApC,GAAwC,CAAC,CAAhD;AACD;;AAED,UAAIJ,CAAC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AApC,IAA8CF,SAAS,CAACE,MAD1D;AAEA,YAAMa,IAAI,GAAGf,SAAS,CAACc,SAAD,CAAtB;;AACA,YAAI,EAAEC,IAAI,YAAYV,OAAlB,KAA8BU,IAAI,CAACC,QAAL,KAAkB,IAApD,EAA0D;AACxD,iBAAOF,SAAP;AACD;AACF;;AACD,aAAOH,UAAP;AACD;;;;;;gBAtNG3D,kB,qBACqB,K;;AAwN3B,eAAeA,kBAAf","sourcesContent":["import { IconDefinition } from '@deephaven/icons';\nimport React from 'react';\nimport type { Shortcut } from '../shortcuts';\n\nexport type ResolvableContextAction =\n | ContextAction\n | Promise<ContextAction[]>\n | (() => Promise<ContextAction[]> | ContextAction[] | ContextAction);\n\nexport type MenuItem = ContextAction | Promise<ContextAction[]>;\n\nexport interface ContextAction {\n title?: string;\n description?: string;\n action?(event?: KeyboardEvent): void;\n actions?: ResolvableContextAction[];\n icon?: IconDefinition | React.ReactElement;\n iconColor?: string;\n shortcut?: Shortcut;\n isGlobal?: boolean;\n group?: number;\n order?: number;\n disabled?: boolean;\n menuElement?: React.ReactElement;\n iconOutline?: boolean;\n}\n\nexport interface ContextActionEvent extends MouseEvent {\n contextActions: ResolvableContextAction[];\n}\n\nclass ContextActionUtils {\n static actionsDisabled = false;\n\n static disableAllActions(): void {\n ContextActionUtils.actionsDisabled = true;\n }\n\n static enableAllActions(): void {\n ContextActionUtils.actionsDisabled = false;\n }\n\n static isContextActionEvent(e: MouseEvent): e is ContextActionEvent {\n return Array.isArray((e as ContextActionEvent).contextActions);\n }\n\n /**\n * Compare two action items. Useful in Array.sort\n * @param a First context action to compare\n * @param b Second context action to compare\n */\n static compareActions(a: ContextAction, b: ContextAction): number {\n if (a.group !== b.group) {\n return (a.group || 0) > (b.group || 0) ? 1 : -1;\n }\n\n if (a.order !== b.order) {\n return (a.order || 0) > (b.order || 0) ? 1 : -1;\n }\n\n if (a.title !== b.title) {\n return (a.title || '') > (b.title || '') ? 1 : -1;\n }\n\n if (a !== b) {\n return a > b ? 1 : -1;\n }\n\n return 0;\n }\n\n /**\n *\n * @param actions The array of actions to sort\n */\n static sortActions(actions: ContextAction[]): ContextAction[] {\n if (!actions || !Array.isArray(actions)) {\n return [];\n }\n\n const sortedActions = actions.slice();\n sortedActions.sort(ContextActionUtils.compareActions);\n return sortedActions;\n }\n\n static isMacPlatform(): boolean {\n const { platform } = window.navigator;\n return platform.startsWith('Mac');\n }\n\n /**\n * Retrieve the preferred modifier key based on the current platform\n */\n static getModifierKey(): 'metaKey' | 'ctrlKey' {\n if (ContextActionUtils.isMacPlatform()) {\n return 'metaKey';\n }\n\n return 'ctrlKey';\n }\n\n /**\n * Returns true if the modifier key for the current platform is down for the event (Ctrl for windows/linux, Command (meta) for mac)\n * @param event The event to get the meta key status from\n */\n static isModifierKeyDown(\n event: KeyboardEvent | MouseEvent | React.KeyboardEvent | React.MouseEvent\n ): boolean {\n const modifierKey = ContextActionUtils.getModifierKey();\n return event[modifierKey];\n }\n\n /**\n * Copy the passed in text to the clipboard.\n * @param text The text to copy\n * @returns Promise Resolved on success, rejected on failure\n */\n static async copyToClipboard(text: string): Promise<void> {\n try {\n const permissions = await navigator.permissions.query({\n name: 'clipboard-write',\n });\n if (permissions.state !== 'granted' && permissions.state !== 'prompt') {\n throw new Error('Invalid permissions for clipboard-write');\n }\n } catch (e) {\n // Fallback if we can't get permissions for some reason\n ContextActionUtils.copyToClipboardExecCommand(text);\n return;\n }\n\n await navigator.clipboard.writeText(text);\n }\n\n /**\n * Copy the passed in text to the clipboard using the `execCommand` functionality\n * Throws on error/failure\n * @param text The text to copy\n */\n static copyToClipboardExecCommand(text: string): void {\n const oldFocus = document.activeElement;\n const textArea = document.createElement('textarea');\n textArea.value = text;\n document.body.appendChild(textArea);\n textArea.focus();\n textArea.select();\n\n if (!document.execCommand('copy')) {\n throw new Error('Unable to execute copy command');\n }\n\n document.body.removeChild(textArea);\n\n if (oldFocus instanceof HTMLElement) {\n oldFocus.focus();\n }\n }\n\n /**\n * Returns the menu items for the provided context actions, or empty array if none found.\n * @param actionsParam The actions to get menu items for\n * @param includePromises Whether or not to include promises in the returned menu items\n */\n static getMenuItems(\n actionsParam: ResolvableContextAction | ResolvableContextAction[],\n includePromises?: true\n ): MenuItem[];\n\n // If ignoring promises, then the return type is narrowed\n static getMenuItems(\n actionsParam: ResolvableContextAction | ResolvableContextAction[],\n includePromises: false\n ): ContextAction[];\n\n static getMenuItems(\n actionsParam: ResolvableContextAction | ResolvableContextAction[],\n includePromises = true\n ): MenuItem[] {\n let menuItems: MenuItem[] = [];\n let actions = actionsParam;\n if (!Array.isArray(actions)) {\n actions = [actions];\n }\n\n for (let i = 0; i < actions.length; i += 1) {\n const action = actions[i];\n let newMenuItems:\n | ContextAction\n | ContextAction[]\n | Promise<ContextAction[]>;\n if (typeof action === 'function') {\n newMenuItems = action();\n } else {\n newMenuItems = action;\n }\n\n if (newMenuItems != null) {\n if (newMenuItems instanceof Promise) {\n if (includePromises) {\n menuItems.push(newMenuItems);\n }\n } else if (Array.isArray(newMenuItems)) {\n menuItems = menuItems.concat(newMenuItems);\n } else {\n menuItems.push(newMenuItems);\n }\n }\n }\n\n menuItems = menuItems.filter(\n action =>\n (action as ContextAction).title ||\n (action as Promise<ContextAction[]>).then ||\n (action as ContextAction).menuElement\n );\n\n return menuItems;\n }\n\n /**\n * Returns the index of the next menu item in a list that doesn't have a disabled=true prop\n * @param startIndex the starting position for the iteration\n * @param delta the direction of travel, -1 or 1\n * @param menuItems an array of menuItems\n */\n static getNextMenuItem(\n startIndex: number,\n delta: -1 | 1,\n menuItems: MenuItem[]\n ): number {\n let firstIndex = startIndex;\n if (firstIndex < 0 && delta < 0) {\n // if menu index is -1 and delta -1 manually set start point\n firstIndex = menuItems.length;\n }\n // find the next non disabled menu option, iterating the list only once\n for (let i = 1; i < menuItems.length + 1; i += 1) {\n const menuIndex =\n (firstIndex + delta * i + menuItems.length) % menuItems.length;\n const item = menuItems[menuIndex];\n if (!(item instanceof Promise) && item.disabled !== true) {\n return menuIndex;\n }\n }\n return startIndex;\n }\n}\n\nexport default ContextActionUtils;\n"],"file":"ContextActionUtils.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/context-actions/ContextActionUtils.ts"],"names":["ContextActionUtils","disableAllActions","actionsDisabled","enableAllActions","isContextActionEvent","e","Array","isArray","contextActions","compareActions","a","b","group","order","title","sortActions","actions","sortedActions","slice","sort","isMacPlatform","platform","window","navigator","startsWith","getModifierKey","isModifierKeyDown","event","modifierKey","copyToClipboard","text","permissions","query","name","state","Error","copyToClipboardExecCommand","clipboard","writeText","oldFocus","document","activeElement","textArea","createElement","value","body","appendChild","focus","select","execCommand","removeChild","HTMLElement","getMenuItems","actionsParam","includePromises","menuItems","i","length","action","newMenuItems","Promise","push","concat","filter","then","menuElement","getNextMenuItem","startIndex","delta","firstIndex","menuIndex","item","disabled"],"mappings":";;;;;;AA+BA,MAAMA,kBAAN,CAAyB;AAGC,SAAjBC,iBAAiB,GAAS;AAC/BD,IAAAA,kBAAkB,CAACE,eAAnB,GAAqC,IAArC;AACD;;AAEsB,SAAhBC,gBAAgB,GAAS;AAC9BH,IAAAA,kBAAkB,CAACE,eAAnB,GAAqC,KAArC;AACD;;AAE0B,SAApBE,oBAAoB,CAACC,CAAD,EAAyC;AAClE,WAAOC,KAAK,CAACC,OAAN,CAAeF,CAAD,CAA0BG,cAAxC,CAAP;AACD;AAED;AACF;AACA;AACA;AACA;;;AACuB,SAAdC,cAAc,CAACC,CAAD,EAAmBC,CAAnB,EAA6C;AAChE,QAAID,CAAC,CAACE,KAAF,KAAYD,CAAC,CAACC,KAAlB,EAAyB;AACvB,aAAO,CAACF,CAAC,CAACE,KAAF,IAAW,CAAZ,KAAkBD,CAAC,CAACC,KAAF,IAAW,CAA7B,IAAkC,CAAlC,GAAsC,CAAC,CAA9C;AACD;;AAED,QAAIF,CAAC,CAACG,KAAF,KAAYF,CAAC,CAACE,KAAlB,EAAyB;AACvB,aAAO,CAACH,CAAC,CAACG,KAAF,IAA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AAC/B;AACAC,MAAAA,UAAU,GAAGd,SAAS,CAACE,MAAvB;AACD,KALO,CAMR;;;AACA,SAAK,IAAID,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,SAAS,CAACE,MAAV,GAAmB,CAAvC,EAA0CD,CAAC,IAAI,CAA/C,EAAkD;AAChD,UAAMc,SAAS,GACb,CAACD,UAAU,GAAGD,KAAK,GAAGZ,CAArB,GAAyBD,SAAS,CAACE,MAApC,IAA8CF,SAAS,CAACE,MAD1D;AAEA,UAAMc,IAAI,GAAGhB,SAAS,CAACe,SAAD,CAAtB;;AACA,UAAI,EAAEC,IAAI,YAAYX,OAAlB,KAA8BW,IAAI,CAACC,QAAL,KAAkB,IAApD,EAA0D;AACxD,eAAOF,SAAP;AACD;AACF;;AACD,WAAOH,UAAP;AACD;;AAtNsB;;gBAAnBnE,kB,qBACqB,K;;AAwN3B,eAAeA,kBAAf","sourcesContent":["import { IconDefinition } from '@deephaven/icons';\nimport React from 'react';\nimport type { Shortcut } from '../shortcuts';\n\nexport type ResolvableContextAction =\n | ContextAction\n | Promise<ContextAction[]>\n | (() => Promise<ContextAction[]> | ContextAction[] | ContextAction);\n\nexport type MenuItem = ContextAction | Promise<ContextAction[]>;\n\nexport interface ContextAction {\n title?: string;\n description?: string;\n action?(event?: KeyboardEvent): void;\n actions?: ResolvableContextAction[];\n icon?: IconDefinition | React.ReactElement;\n iconColor?: string;\n shortcut?: Shortcut;\n isGlobal?: boolean;\n group?: number;\n order?: number;\n disabled?: boolean;\n menuElement?: React.ReactElement;\n iconOutline?: boolean;\n}\n\nexport interface ContextActionEvent extends MouseEvent {\n contextActions: ResolvableContextAction[];\n}\n\nclass ContextActionUtils {\n static actionsDisabled = false;\n\n static disableAllActions(): void {\n ContextActionUtils.actionsDisabled = true;\n }\n\n static enableAllActions(): void {\n ContextActionUtils.actionsDisabled = false;\n }\n\n static isContextActionEvent(e: MouseEvent): e is ContextActionEvent {\n return Array.isArray((e as ContextActionEvent).contextActions);\n }\n\n /**\n * Compare two action items. Useful in Array.sort\n * @param a First context action to compare\n * @param b Second context action to compare\n */\n static compareActions(a: ContextAction, b: ContextAction): number {\n if (a.group !== b.group) {\n return (a.group || 0) > (b.group || 0) ? 1 : -1;\n }\n\n if (a.order !== b.order) {\n return (a.order || 0) > (b.order || 0) ? 1 : -1;\n }\n\n if (a.title !== b.title) {\n return (a.title || '') > (b.title || '') ? 1 : -1;\n }\n\n if (a !== b) {\n return a > b ? 1 : -1;\n }\n\n return 0;\n }\n\n /**\n *\n * @param actions The array of actions to sort\n */\n static sortActions(actions: ContextAction[]): ContextAction[] {\n if (!actions || !Array.isArray(actions)) {\n return [];\n }\n\n const sortedActions = actions.slice();\n sortedActions.sort(ContextActionUtils.compareActions);\n return sortedActions;\n }\n\n static isMacPlatform(): boolean {\n const { platform } = window.navigator;\n return platform.startsWith('Mac');\n }\n\n /**\n * Retrieve the preferred modifier key based on the current platform\n */\n static getModifierKey(): 'metaKey' | 'ctrlKey' {\n if (ContextActionUtils.isMacPlatform()) {\n return 'metaKey';\n }\n\n return 'ctrlKey';\n }\n\n /**\n * Returns true if the modifier key for the current platform is down for the event (Ctrl for windows/linux, Command (meta) for mac)\n * @param event The event to get the meta key status from\n */\n static isModifierKeyDown(\n event: KeyboardEvent | MouseEvent | React.KeyboardEvent | React.MouseEvent\n ): boolean {\n const modifierKey = ContextActionUtils.getModifierKey();\n return event[modifierKey];\n }\n\n /**\n * Copy the passed in text to the clipboard.\n * @param text The text to copy\n * @returns Promise Resolved on success, rejected on failure\n */\n static async copyToClipboard(text: string): Promise<void> {\n try {\n const permissions = await navigator.permissions.query({\n name: 'clipboard-write',\n });\n if (permissions.state !== 'granted' && permissions.state !== 'prompt') {\n throw new Error('Invalid permissions for clipboard-write');\n }\n } catch (e) {\n // Fallback if we can't get permissions for some reason\n ContextActionUtils.copyToClipboardExecCommand(text);\n return;\n }\n\n await navigator.clipboard.writeText(text);\n }\n\n /**\n * Copy the passed in text to the clipboard using the `execCommand` functionality\n * Throws on error/failure\n * @param text The text to copy\n */\n static copyToClipboardExecCommand(text: string): void {\n const oldFocus = document.activeElement;\n const textArea = document.createElement('textarea');\n textArea.value = text;\n document.body.appendChild(textArea);\n textArea.focus();\n textArea.select();\n\n if (!document.execCommand('copy')) {\n throw new Error('Unable to execute copy command');\n }\n\n document.body.removeChild(textArea);\n\n if (oldFocus instanceof HTMLElement) {\n oldFocus.focus();\n }\n }\n\n /**\n * Returns the menu items for the provided context actions, or empty array if none found.\n * @param actionsParam The actions to get menu items for\n * @param includePromises Whether or not to include promises in the returned menu items\n */\n static getMenuItems(\n actionsParam: ResolvableContextAction | ResolvableContextAction[],\n includePromises?: true\n ): MenuItem[];\n\n // If ignoring promises, then the return type is narrowed\n static getMenuItems(\n actionsParam: ResolvableContextAction | ResolvableContextAction[],\n includePromises: false\n ): ContextAction[];\n\n static getMenuItems(\n actionsParam: ResolvableContextAction | ResolvableContextAction[],\n includePromises = true\n ): MenuItem[] {\n let menuItems: MenuItem[] = [];\n let actions = actionsParam;\n if (!Array.isArray(actions)) {\n actions = [actions];\n }\n\n for (let i = 0; i < actions.length; i += 1) {\n const action = actions[i];\n let newMenuItems:\n | ContextAction\n | ContextAction[]\n | Promise<ContextAction[]>;\n if (typeof action === 'function') {\n newMenuItems = action();\n } else {\n newMenuItems = action;\n }\n\n if (newMenuItems != null) {\n if (newMenuItems instanceof Promise) {\n if (includePromises) {\n menuItems.push(newMenuItems);\n }\n } else if (Array.isArray(newMenuItems)) {\n menuItems = menuItems.concat(newMenuItems);\n } else {\n menuItems.push(newMenuItems);\n }\n }\n }\n\n menuItems = menuItems.filter(\n action =>\n (action as ContextAction).title ||\n (action as Promise<ContextAction[]>).then ||\n (action as ContextAction).menuElement\n );\n\n return menuItems;\n }\n\n /**\n * Returns the index of the next menu item in a list that doesn't have a disabled=true prop\n * @param startIndex the starting position for the iteration\n * @param delta the direction of travel, -1 or 1\n * @param menuItems an array of menuItems\n */\n static getNextMenuItem(\n startIndex: number,\n delta: -1 | 1,\n menuItems: MenuItem[]\n ): number {\n let firstIndex = startIndex;\n if (firstIndex < 0 && delta < 0) {\n // if menu index is -1 and delta -1 manually set start point\n firstIndex = menuItems.length;\n }\n // find the next non disabled menu option, iterating the list only once\n for (let i = 1; i < menuItems.length + 1; i += 1) {\n const menuIndex =\n (firstIndex + delta * i + menuItems.length) % menuItems.length;\n const item = menuItems[menuIndex];\n if (!(item instanceof Promise) && item.disabled !== true) {\n return menuIndex;\n }\n }\n return startIndex;\n }\n}\n\nexport default ContextActionUtils;\n"],"file":"ContextActionUtils.js"}
|