custom-electron-titlebar 4.2.7 → 4.4.0
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/README.md +43 -19
- package/index.d.mts +684 -0
- package/index.d.ts +684 -3
- package/index.js +5225 -175
- package/index.js.map +1 -0
- package/index.mjs +5227 -0
- package/index.mjs.map +1 -0
- package/main/index.d.mts +21 -0
- package/main/index.d.ts +21 -3
- package/main/index.js +793 -175
- package/main/index.js.map +1 -0
- package/main/index.mjs +785 -0
- package/main/index.mjs.map +1 -0
- package/package.json +56 -33
- package/theme/base.css +425 -0
- package/theme/mac.css +0 -0
- package/theme/win.css +0 -0
- package/base/browser/browser.d.ts +0 -26
- package/base/browser/browser.js +0 -317
- package/base/browser/event.d.ts +0 -12
- package/base/browser/event.js +0 -215
- package/base/browser/keyboardEvent.d.ts +0 -38
- package/base/browser/keyboardEvent.js +0 -464
- package/base/browser/mouseEvent.d.ts +0 -61
- package/base/browser/mouseEvent.js +0 -327
- package/base/browser/touch.d.ts +0 -39
- package/base/browser/touch.js +0 -454
- package/base/common/arrays.d.ts +0 -10
- package/base/common/arrays.js +0 -210
- package/base/common/async.d.ts +0 -35
- package/base/common/async.js +0 -280
- package/base/common/charCode.d.ts +0 -405
- package/base/common/charCode.js +0 -9
- package/base/common/color.d.ts +0 -159
- package/base/common/color.js +0 -708
- package/base/common/decorators.d.ts +0 -6
- package/base/common/decorators.js +0 -300
- package/base/common/dom.d.ts +0 -221
- package/base/common/dom.js +0 -1478
- package/base/common/event.d.ts +0 -213
- package/base/common/event.js +0 -804
- package/base/common/iterator.d.ts +0 -69
- package/base/common/iterator.js +0 -381
- package/base/common/keyCodes.d.ts +0 -478
- package/base/common/keyCodes.js +0 -479
- package/base/common/lifecycle.d.ts +0 -17
- package/base/common/lifecycle.js +0 -258
- package/base/common/linkedList.d.ts +0 -17
- package/base/common/linkedList.js +0 -319
- package/base/common/platform.d.ts +0 -36
- package/base/common/platform.js +0 -314
- package/base/common/strings.d.ts +0 -23
- package/base/common/strings.js +0 -273
- package/consts.d.ts +0 -58
- package/consts.js +0 -317
- package/main/attach-titlebar-to-window.d.ts +0 -3
- package/main/attach-titlebar-to-window.js +0 -210
- package/main/setup-titlebar.d.ts +0 -2
- package/main/setup-titlebar.js +0 -255
- package/menubar/index.d.ts +0 -86
- package/menubar/index.js +0 -1121
- package/menubar/menu/index.d.ts +0 -46
- package/menubar/menu/index.js +0 -566
- package/menubar/menu/item.d.ts +0 -67
- package/menubar/menu/item.js +0 -575
- package/menubar/menu/separator.d.ts +0 -11
- package/menubar/menu/separator.js +0 -213
- package/menubar/menu/submenu.d.ts +0 -32
- package/menubar/menu/submenu.js +0 -372
- package/menubar/menubar-options.d.ts +0 -47
- package/menubar/menubar-options.js +0 -9
- package/titlebar/index.d.ts +0 -104
- package/titlebar/index.js +0 -696
- package/titlebar/options.d.ts +0 -84
- package/titlebar/options.js +0 -9
- package/titlebar/themebar.d.ts +0 -20
- package/titlebar/themebar.js +0 -267
package/menubar/index.js
DELETED
|
@@ -1,1121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/* ---------------------------------------------------------------------------------------------
|
|
4
|
-
* Copyright (c) AlexTorresDev. All rights reserved.
|
|
5
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
-
*-------------------------------------------------------------------------------------------- */
|
|
7
|
-
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return m[k];
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
Object.defineProperty(o, k2, desc);
|
|
19
|
-
} : function (o, m, k, k2) {
|
|
20
|
-
if (k2 === undefined) k2 = k;
|
|
21
|
-
o[k2] = m[k];
|
|
22
|
-
});
|
|
23
|
-
var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
|
24
|
-
Object.defineProperty(o, "default", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
value: v
|
|
27
|
-
});
|
|
28
|
-
} : function (o, v) {
|
|
29
|
-
o["default"] = v;
|
|
30
|
-
});
|
|
31
|
-
var __importStar = this && this.__importStar || function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) _get__("__createBinding")(result, mod, k);
|
|
35
|
-
_get__("__setModuleDefault")(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", {
|
|
39
|
-
value: true
|
|
40
|
-
});
|
|
41
|
-
exports.MenuBar = void 0;
|
|
42
|
-
const electron_1 = require("electron");
|
|
43
|
-
const DOM = _get__("__importStar")(require("../base/common/dom"));
|
|
44
|
-
const event_1 = require("../base/common/event");
|
|
45
|
-
const lifecycle_1 = require("../base/common/lifecycle");
|
|
46
|
-
const platform_1 = require("../base/common/platform");
|
|
47
|
-
const keyboardEvent_1 = require("../base/browser/keyboardEvent");
|
|
48
|
-
const keyCodes_1 = require("../base/common/keyCodes");
|
|
49
|
-
const consts_1 = require("../consts");
|
|
50
|
-
const menu_1 = require("./menu");
|
|
51
|
-
const async_1 = require("../base/common/async");
|
|
52
|
-
const mouseEvent_1 = require("../base/browser/mouseEvent");
|
|
53
|
-
const touch_1 = require("../base/browser/touch");
|
|
54
|
-
const strings = _get__("__importStar")(require("../base/common/strings"));
|
|
55
|
-
const $ = _get__("DOM").$;
|
|
56
|
-
var MenubarState;
|
|
57
|
-
(function (MenubarState) {
|
|
58
|
-
MenubarState[MenubarState["HIDDEN"] = 0] = "HIDDEN";
|
|
59
|
-
MenubarState[MenubarState["VISIBLE"] = 1] = "VISIBLE";
|
|
60
|
-
MenubarState[MenubarState["FOCUSED"] = 2] = "FOCUSED";
|
|
61
|
-
MenubarState[MenubarState["OPEN"] = 3] = "OPEN";
|
|
62
|
-
})(_get__("MenubarState") || _assign__("MenubarState", {}));
|
|
63
|
-
class MenuBar extends _get__("lifecycle_1").Disposable {
|
|
64
|
-
constructor(container, menuIcons, currentOptions, options, closeMenu = () => {}) {
|
|
65
|
-
super();
|
|
66
|
-
this.container = container;
|
|
67
|
-
this.menuIcons = menuIcons;
|
|
68
|
-
this.currentOptions = currentOptions;
|
|
69
|
-
this.options = options;
|
|
70
|
-
this.closeMenu = closeMenu;
|
|
71
|
-
// Input-related
|
|
72
|
-
this._mnemonicsInUse = false;
|
|
73
|
-
this.openedViaKeyboard = false;
|
|
74
|
-
this.awaitingAltRelease = false;
|
|
75
|
-
this.ignoreNextMouseUp = false;
|
|
76
|
-
this.updatePending = false;
|
|
77
|
-
this.numMenusShown = 0;
|
|
78
|
-
this.overflowLayoutScheduled = undefined;
|
|
79
|
-
this.menuStyle = {};
|
|
80
|
-
this.container.setAttribute('role', 'menubar');
|
|
81
|
-
if (this.isCompact) {
|
|
82
|
-
this.container.classList.add('compact');
|
|
83
|
-
}
|
|
84
|
-
this.menus = [];
|
|
85
|
-
this.mnemonics = new Map();
|
|
86
|
-
this._focusState = _get__("MenubarState").VISIBLE;
|
|
87
|
-
this._onVisibilityChange = this._register(new (_get__("event_1").Emitter)());
|
|
88
|
-
this._onFocusStateChange = this._register(new (_get__("event_1").Emitter)());
|
|
89
|
-
this.createOverflowMenu();
|
|
90
|
-
this.menuUpdater = this._register(new (_get__("async_1").RunOnceScheduler)(() => this.update(), 200));
|
|
91
|
-
// this.actionRunner = this.options.actionRunner ?? this._register(new ActionRunner());
|
|
92
|
-
this.registerListeners();
|
|
93
|
-
this.setUnfocusedState();
|
|
94
|
-
}
|
|
95
|
-
registerListeners() {
|
|
96
|
-
/* this._register(this.actionRunner.onWillRun(() => {
|
|
97
|
-
this.setUnfocusedState();
|
|
98
|
-
})); */
|
|
99
|
-
if (!_get__("platform_1").isMacintosh) {
|
|
100
|
-
this._register(_get__("DOM").addDisposableListener(window, _get__("DOM").EventType.RESIZE, () => {
|
|
101
|
-
this.blur();
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
this._register(_get__("DOM").ModifierKeyEmitter.getInstance().event(this.onModifierKeyToggled, this));
|
|
105
|
-
this._register(_get__("DOM").addDisposableListener(this.container, _get__("DOM").EventType.KEY_DOWN, e => {
|
|
106
|
-
const event = new (_get__("keyboardEvent_1").StandardKeyboardEvent)(e);
|
|
107
|
-
let eventHandled = true;
|
|
108
|
-
const key = !!e.key ? e.key.toLocaleLowerCase() : '';
|
|
109
|
-
const tabNav = _get__("platform_1").isMacintosh && !this.isCompact;
|
|
110
|
-
if (event.equals(15 /* KeyCode.LeftArrow */) || tabNav && event.equals(2 /* KeyCode.Tab */ | 1024 /* KeyMod.Shift */)) {
|
|
111
|
-
this.focusPrevious();
|
|
112
|
-
} else if (event.equals(17 /* KeyCode.RightArrow */) || tabNav && event.equals(2 /* KeyCode.Tab */)) {
|
|
113
|
-
this.focusNext();
|
|
114
|
-
} else if (event.equals(9 /* KeyCode.Escape */) && this.isFocused && !this.isOpen) {
|
|
115
|
-
this.setUnfocusedState();
|
|
116
|
-
} else if (!this.isOpen && !event.ctrlKey && this.options.enableMnemonics && this.mnemonicsInUse && this.mnemonics.has(key)) {
|
|
117
|
-
const menuIndex = this.mnemonics.get(key);
|
|
118
|
-
this.onMenuTriggered(menuIndex, false);
|
|
119
|
-
} else {
|
|
120
|
-
eventHandled = false;
|
|
121
|
-
}
|
|
122
|
-
// Never allow default tab behavior when not compact
|
|
123
|
-
if (!this.isCompact && (event.equals(2 /* KeyCode.Tab */ | 1024 /* KeyMod.Shift */) || event.equals(2 /* KeyCode.Tab */))) {
|
|
124
|
-
event.preventDefault();
|
|
125
|
-
}
|
|
126
|
-
if (eventHandled) {
|
|
127
|
-
event.preventDefault();
|
|
128
|
-
event.stopPropagation();
|
|
129
|
-
}
|
|
130
|
-
}));
|
|
131
|
-
this._register(_get__("DOM").addDisposableListener(window, _get__("DOM").EventType.MOUSE_DOWN, () => {
|
|
132
|
-
// This mouse event is outside the menubar so it counts as a focus out
|
|
133
|
-
if (this.isFocused) {
|
|
134
|
-
this.setUnfocusedState();
|
|
135
|
-
}
|
|
136
|
-
}));
|
|
137
|
-
this._register(_get__("DOM").addDisposableListener(this.container, _get__("DOM").EventType.FOCUS_IN, e => {
|
|
138
|
-
const event = e;
|
|
139
|
-
if (event.relatedTarget) {
|
|
140
|
-
if (!this.container.contains(event.relatedTarget)) {
|
|
141
|
-
this.focusToReturn = event.relatedTarget;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}));
|
|
145
|
-
this._register(_get__("DOM").addDisposableListener(this.container, _get__("DOM").EventType.FOCUS_OUT, e => {
|
|
146
|
-
const event = e;
|
|
147
|
-
// We are losing focus and there is a target, reset focusToReturn value as not to redirect
|
|
148
|
-
if (event.relatedTarget && !this.container.contains(event.relatedTarget)) {
|
|
149
|
-
this.focusToReturn = undefined;
|
|
150
|
-
this.setUnfocusedState();
|
|
151
|
-
}
|
|
152
|
-
}));
|
|
153
|
-
this._register(_get__("DOM").addDisposableListener(window, _get__("DOM").EventType.KEY_DOWN, e => {
|
|
154
|
-
if (!this.options.enableMnemonics || !e.altKey || e.ctrlKey || e.defaultPrevented) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const key = e.key.toLocaleLowerCase();
|
|
158
|
-
if (!this.mnemonics.has(key)) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
this.mnemonicsInUse = true;
|
|
162
|
-
this.updateMnemonicVisibility(true);
|
|
163
|
-
const menuIndex = this.mnemonics.get(key);
|
|
164
|
-
this.onMenuTriggered(menuIndex, false);
|
|
165
|
-
}));
|
|
166
|
-
}
|
|
167
|
-
push(menu) {
|
|
168
|
-
const topLevelMenus = menu.items;
|
|
169
|
-
topLevelMenus.forEach(menuBarMenu => {
|
|
170
|
-
const menuIndex = this.menus.length;
|
|
171
|
-
const cleanMenuLabel = (0, _get__("consts_1").cleanMnemonic)(menuBarMenu.label);
|
|
172
|
-
const mnemonicMatches = _get__("consts_1").MENU_MNEMONIC_REGEX.exec(menuBarMenu.label);
|
|
173
|
-
// Register mnemonics
|
|
174
|
-
if (mnemonicMatches) {
|
|
175
|
-
const mnemonic = !!mnemonicMatches[1] ? mnemonicMatches[1] : mnemonicMatches[3];
|
|
176
|
-
this.registerMnemonic(this.menus.length, mnemonic);
|
|
177
|
-
}
|
|
178
|
-
if (this.isCompact) {
|
|
179
|
-
this.menus.push({
|
|
180
|
-
label: '',
|
|
181
|
-
actions: menuBarMenu.submenu
|
|
182
|
-
});
|
|
183
|
-
} else {
|
|
184
|
-
const buttonElement = _get__("$")('.cet-menubar-menu-button', {
|
|
185
|
-
role: 'menuitem',
|
|
186
|
-
tabindex: -1,
|
|
187
|
-
'aria-label': cleanMenuLabel,
|
|
188
|
-
'aria-haspopup': true
|
|
189
|
-
});
|
|
190
|
-
const titleElement = _get__("$")('.cet-menubar-menu-title', {
|
|
191
|
-
role: 'none',
|
|
192
|
-
'aria-hidden': true
|
|
193
|
-
});
|
|
194
|
-
buttonElement.appendChild(titleElement);
|
|
195
|
-
this.container.insertBefore(buttonElement, this.overflowMenu.buttonElement);
|
|
196
|
-
this.updateLabels(titleElement, buttonElement, menuBarMenu.label);
|
|
197
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("DOM").EventType.KEY_UP, e => {
|
|
198
|
-
const event = new (_get__("keyboardEvent_1").StandardKeyboardEvent)(e);
|
|
199
|
-
let eventHandled = true;
|
|
200
|
-
if ((event.equals(18 /* KeyCode.DownArrow */) || event.equals(3 /* KeyCode.Enter */)) && !this.isOpen) {
|
|
201
|
-
this.focusedMenu = {
|
|
202
|
-
index: menuIndex
|
|
203
|
-
};
|
|
204
|
-
this.openedViaKeyboard = true;
|
|
205
|
-
this.focusState = _get__("MenubarState").OPEN;
|
|
206
|
-
} else {
|
|
207
|
-
eventHandled = false;
|
|
208
|
-
}
|
|
209
|
-
if (eventHandled) {
|
|
210
|
-
event.preventDefault();
|
|
211
|
-
event.stopPropagation();
|
|
212
|
-
}
|
|
213
|
-
}));
|
|
214
|
-
this._register(_get__("touch_1").Gesture.addTarget(buttonElement));
|
|
215
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("touch_1").EventType.Tap, e => {
|
|
216
|
-
// Ignore this touch if the menu is touched
|
|
217
|
-
if (this.isOpen && this.focusedMenu && this.focusedMenu.holder && _get__("DOM").isAncestor(e.initialTarget, this.focusedMenu.holder)) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
this.ignoreNextMouseUp = false;
|
|
221
|
-
this.onMenuTriggered(menuIndex, true);
|
|
222
|
-
e.preventDefault();
|
|
223
|
-
e.stopPropagation();
|
|
224
|
-
}));
|
|
225
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("DOM").EventType.MOUSE_DOWN, e => {
|
|
226
|
-
// Ignore non-left-click
|
|
227
|
-
const mouseEvent = new (_get__("mouseEvent_1").StandardMouseEvent)(e);
|
|
228
|
-
if (!mouseEvent.leftButton) {
|
|
229
|
-
e.preventDefault();
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (!this.isOpen) {
|
|
233
|
-
// Open the menu with mouse down and ignore the following mouse up event
|
|
234
|
-
this.ignoreNextMouseUp = true;
|
|
235
|
-
this.onMenuTriggered(menuIndex, true);
|
|
236
|
-
} else {
|
|
237
|
-
this.ignoreNextMouseUp = false;
|
|
238
|
-
}
|
|
239
|
-
e.preventDefault();
|
|
240
|
-
e.stopPropagation();
|
|
241
|
-
}));
|
|
242
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("DOM").EventType.MOUSE_UP, e => {
|
|
243
|
-
if (e.defaultPrevented) {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (!this.ignoreNextMouseUp) {
|
|
247
|
-
if (this.isFocused) {
|
|
248
|
-
this.onMenuTriggered(menuIndex, true);
|
|
249
|
-
}
|
|
250
|
-
} else {
|
|
251
|
-
this.ignoreNextMouseUp = false;
|
|
252
|
-
}
|
|
253
|
-
}));
|
|
254
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("DOM").EventType.MOUSE_ENTER, () => {
|
|
255
|
-
if (this.isOpen && !this.isCurrentMenu(menuIndex)) {
|
|
256
|
-
buttonElement.focus();
|
|
257
|
-
this.cleanupMenu();
|
|
258
|
-
this.showMenu(menuIndex, false);
|
|
259
|
-
} else if (this.isFocused && !this.isOpen) {
|
|
260
|
-
this.focusedMenu = {
|
|
261
|
-
index: menuIndex
|
|
262
|
-
};
|
|
263
|
-
buttonElement.focus();
|
|
264
|
-
}
|
|
265
|
-
}));
|
|
266
|
-
this.menus.push({
|
|
267
|
-
label: menuBarMenu.label,
|
|
268
|
-
actions: menuBarMenu.submenu,
|
|
269
|
-
buttonElement,
|
|
270
|
-
titleElement
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
createOverflowMenu() {
|
|
276
|
-
const label = this.isCompact ? 'Compact' : 'More';
|
|
277
|
-
const buttonElement = _get__("$")('.cet-menubar-menu-button', {
|
|
278
|
-
role: 'menuitem',
|
|
279
|
-
tabindex: this.isCompact ? 0 : -1,
|
|
280
|
-
'aria-label': label,
|
|
281
|
-
'aria-haspopup': true
|
|
282
|
-
});
|
|
283
|
-
const titleElement = _get__("$")('.cet-menubar-menu-title.cet-toggle-more', {
|
|
284
|
-
role: 'none',
|
|
285
|
-
'aria-hidden': true
|
|
286
|
-
});
|
|
287
|
-
buttonElement.appendChild(titleElement);
|
|
288
|
-
this.container.appendChild(buttonElement);
|
|
289
|
-
buttonElement.style.visibility = 'hidden';
|
|
290
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("DOM").EventType.KEY_UP, e => {
|
|
291
|
-
const event = new (_get__("keyboardEvent_1").StandardKeyboardEvent)(e);
|
|
292
|
-
let eventHandled = true;
|
|
293
|
-
const triggerKeys = [3 /* KeyCode.Enter */];
|
|
294
|
-
if (!this.isCompact) {
|
|
295
|
-
triggerKeys.push(18 /* KeyCode.DownArrow */);
|
|
296
|
-
} else {
|
|
297
|
-
triggerKeys.push(10 /* KeyCode.Space */);
|
|
298
|
-
if (this.options.compactMode === _get__("menu_1").Direction.Right) {
|
|
299
|
-
triggerKeys.push(17 /* KeyCode.RightArrow */);
|
|
300
|
-
} else if (this.options.compactMode === _get__("menu_1").Direction.Left) {
|
|
301
|
-
triggerKeys.push(15 /* KeyCode.LeftArrow */);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (triggerKeys.some(k => event.equals(k)) && !this.isOpen) {
|
|
306
|
-
this.focusedMenu = {
|
|
307
|
-
index: _get__("MenuBar").OVERFLOW_INDEX
|
|
308
|
-
};
|
|
309
|
-
this.openedViaKeyboard = true;
|
|
310
|
-
this.focusState = _get__("MenubarState").OPEN;
|
|
311
|
-
} else {
|
|
312
|
-
eventHandled = false;
|
|
313
|
-
}
|
|
314
|
-
if (eventHandled) {
|
|
315
|
-
event.preventDefault();
|
|
316
|
-
event.stopPropagation();
|
|
317
|
-
}
|
|
318
|
-
}));
|
|
319
|
-
this._register(_get__("touch_1").Gesture.addTarget(buttonElement));
|
|
320
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("touch_1").EventType.Tap, e => {
|
|
321
|
-
// Ignore this touch if the menu is touched
|
|
322
|
-
if (this.isOpen && this.focusedMenu && this.focusedMenu.holder && _get__("DOM").isAncestor(e.initialTarget, this.focusedMenu.holder)) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
this.ignoreNextMouseUp = false;
|
|
326
|
-
this.onMenuTriggered(_get__("MenuBar").OVERFLOW_INDEX, true);
|
|
327
|
-
e.preventDefault();
|
|
328
|
-
e.stopPropagation();
|
|
329
|
-
}));
|
|
330
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("DOM").EventType.MOUSE_DOWN, e => {
|
|
331
|
-
// Ignore non-left-click
|
|
332
|
-
const mouseEvent = new (_get__("mouseEvent_1").StandardMouseEvent)(e);
|
|
333
|
-
if (!mouseEvent.leftButton) {
|
|
334
|
-
e.preventDefault();
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
if (!this.isOpen) {
|
|
338
|
-
// Open the menu with mouse down and ignore the following mouse up event
|
|
339
|
-
this.ignoreNextMouseUp = true;
|
|
340
|
-
this.onMenuTriggered(_get__("MenuBar").OVERFLOW_INDEX, true);
|
|
341
|
-
} else {
|
|
342
|
-
this.ignoreNextMouseUp = false;
|
|
343
|
-
}
|
|
344
|
-
e.preventDefault();
|
|
345
|
-
e.stopPropagation();
|
|
346
|
-
}));
|
|
347
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("DOM").EventType.MOUSE_UP, e => {
|
|
348
|
-
if (e.defaultPrevented) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
if (!this.ignoreNextMouseUp) {
|
|
352
|
-
if (this.isFocused) {
|
|
353
|
-
this.onMenuTriggered(_get__("MenuBar").OVERFLOW_INDEX, true);
|
|
354
|
-
}
|
|
355
|
-
} else {
|
|
356
|
-
this.ignoreNextMouseUp = false;
|
|
357
|
-
}
|
|
358
|
-
}));
|
|
359
|
-
this._register(_get__("DOM").addDisposableListener(buttonElement, _get__("DOM").EventType.MOUSE_ENTER, () => {
|
|
360
|
-
if (this.isOpen && !this.isCurrentMenu(_get__("MenuBar").OVERFLOW_INDEX)) {
|
|
361
|
-
this.overflowMenu.buttonElement.focus();
|
|
362
|
-
this.cleanupMenu();
|
|
363
|
-
this.showMenu(_get__("MenuBar").OVERFLOW_INDEX, false);
|
|
364
|
-
} else if (this.isFocused && !this.isOpen) {
|
|
365
|
-
this.focusedMenu = {
|
|
366
|
-
index: _get__("MenuBar").OVERFLOW_INDEX
|
|
367
|
-
};
|
|
368
|
-
buttonElement.focus();
|
|
369
|
-
}
|
|
370
|
-
}));
|
|
371
|
-
this.overflowMenu = {
|
|
372
|
-
buttonElement,
|
|
373
|
-
titleElement,
|
|
374
|
-
label: 'More'
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
setStyles(style) {
|
|
378
|
-
this.menuStyle = style;
|
|
379
|
-
}
|
|
380
|
-
updateMenu(menu) {
|
|
381
|
-
const menuToUpdate = this.menus.filter(menuBarMenu => menuBarMenu.label === menu.label);
|
|
382
|
-
if (menuToUpdate && menuToUpdate.length) {
|
|
383
|
-
// menuToUpdate[0].actions = menu.actions;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
dispose() {
|
|
387
|
-
super.dispose();
|
|
388
|
-
this.menus.forEach(menuBarMenu => {
|
|
389
|
-
menuBarMenu.titleElement?.remove();
|
|
390
|
-
menuBarMenu.buttonElement?.remove();
|
|
391
|
-
});
|
|
392
|
-
this.overflowMenu.titleElement.remove();
|
|
393
|
-
this.overflowMenu.buttonElement.remove();
|
|
394
|
-
(0, _get__("lifecycle_1").dispose)(this.overflowLayoutScheduled);
|
|
395
|
-
this.overflowLayoutScheduled = undefined;
|
|
396
|
-
}
|
|
397
|
-
blur() {
|
|
398
|
-
this.setUnfocusedState();
|
|
399
|
-
}
|
|
400
|
-
getWidth() {
|
|
401
|
-
if (!this.isCompact && this.menus) {
|
|
402
|
-
const left = this.menus[0].buttonElement.getBoundingClientRect().left;
|
|
403
|
-
const right = this.hasOverflow ? this.overflowMenu.buttonElement.getBoundingClientRect().right : this.menus[this.menus.length - 1].buttonElement.getBoundingClientRect().right;
|
|
404
|
-
return right - left;
|
|
405
|
-
}
|
|
406
|
-
return 0;
|
|
407
|
-
}
|
|
408
|
-
getHeight() {
|
|
409
|
-
return this.container.clientHeight;
|
|
410
|
-
}
|
|
411
|
-
toggleFocus() {
|
|
412
|
-
if (!this.isFocused && this.options.visibility !== 'hidden') {
|
|
413
|
-
this.mnemonicsInUse = true;
|
|
414
|
-
this.focusedMenu = {
|
|
415
|
-
index: this.numMenusShown > 0 ? 0 : _get__("MenuBar").OVERFLOW_INDEX
|
|
416
|
-
};
|
|
417
|
-
this.focusState = _get__("MenubarState").FOCUSED;
|
|
418
|
-
} else if (!this.isOpen) {
|
|
419
|
-
this.setUnfocusedState();
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
updateOverflowAction() {
|
|
423
|
-
if (!this.menus || !this.menus.length) {
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
const overflowMenuOnlyClass = 'overflow-menu-only';
|
|
427
|
-
// Remove overflow only restriction to allow the most space
|
|
428
|
-
this.container.classList.toggle(overflowMenuOnlyClass, false);
|
|
429
|
-
const sizeAvailable = this.container.offsetWidth;
|
|
430
|
-
let currentSize = 0;
|
|
431
|
-
let full = this.isCompact;
|
|
432
|
-
const prevNumMenusShown = this.numMenusShown;
|
|
433
|
-
this.numMenusShown = 0;
|
|
434
|
-
const showableMenus = this.menus.filter(menu => menu.buttonElement !== undefined && menu.titleElement !== undefined);
|
|
435
|
-
for (const menuBarMenu of showableMenus) {
|
|
436
|
-
if (!full) {
|
|
437
|
-
const size = menuBarMenu.buttonElement.offsetWidth;
|
|
438
|
-
if (currentSize + size > sizeAvailable) {
|
|
439
|
-
full = true;
|
|
440
|
-
} else {
|
|
441
|
-
currentSize += size;
|
|
442
|
-
this.numMenusShown++;
|
|
443
|
-
if (this.numMenusShown > prevNumMenusShown) {
|
|
444
|
-
menuBarMenu.buttonElement.style.visibility = 'visible';
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
if (full) {
|
|
449
|
-
menuBarMenu.buttonElement.style.visibility = 'hidden';
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
// If below minimium menu threshold, show the overflow menu only as hamburger menu
|
|
453
|
-
if (this.numMenusShown - 1 <= showableMenus.length / 2) {
|
|
454
|
-
for (const menuBarMenu of showableMenus) {
|
|
455
|
-
menuBarMenu.buttonElement.style.visibility = 'hidden';
|
|
456
|
-
}
|
|
457
|
-
full = true;
|
|
458
|
-
this.numMenusShown = 0;
|
|
459
|
-
currentSize = 0;
|
|
460
|
-
}
|
|
461
|
-
// Overflow
|
|
462
|
-
if (this.isCompact) {
|
|
463
|
-
// this.overflowMenu.actions = [];
|
|
464
|
-
for (let idx = this.numMenusShown; idx < this.menus.length; idx++) {
|
|
465
|
-
// this.overflowMenu.actions.push(new SubmenuAction(`menubar.submenu.${this.menus[idx].label}`, this.menus[idx].label, this.menus[idx].actions || []));
|
|
466
|
-
}
|
|
467
|
-
/* const compactMenuActions = this.options.getCompactMenuActions?.();
|
|
468
|
-
if (compactMenuActions && compactMenuActions.length) {
|
|
469
|
-
//this.overflowMenu.actions.push(new Separator());
|
|
470
|
-
this.overflowMenu.actions.push(...compactMenuActions);
|
|
471
|
-
} */
|
|
472
|
-
this.overflowMenu.buttonElement.style.visibility = 'visible';
|
|
473
|
-
} else if (full) {
|
|
474
|
-
// Can't fit the more button, need to remove more menus
|
|
475
|
-
while (currentSize + this.overflowMenu.buttonElement.offsetWidth > sizeAvailable && this.numMenusShown > 0) {
|
|
476
|
-
this.numMenusShown--;
|
|
477
|
-
const size = showableMenus[this.numMenusShown].buttonElement.offsetWidth;
|
|
478
|
-
showableMenus[this.numMenusShown].buttonElement.style.visibility = 'hidden';
|
|
479
|
-
currentSize -= size;
|
|
480
|
-
}
|
|
481
|
-
// this.overflowMenu.actions = [];
|
|
482
|
-
for (let idx = this.numMenusShown; idx < showableMenus.length; idx++) {
|
|
483
|
-
// this.overflowMenu.actions.push(new SubmenuAction(`menubar.submenu.${showableMenus[idx].label}`, showableMenus[idx].label, showableMenus[idx].actions || []));
|
|
484
|
-
}
|
|
485
|
-
if (this.overflowMenu.buttonElement.nextElementSibling !== showableMenus[this.numMenusShown].buttonElement) {
|
|
486
|
-
this.overflowMenu.buttonElement.remove();
|
|
487
|
-
this.container.insertBefore(this.overflowMenu.buttonElement, showableMenus[this.numMenusShown].buttonElement);
|
|
488
|
-
}
|
|
489
|
-
this.overflowMenu.buttonElement.style.visibility = 'visible';
|
|
490
|
-
} else {
|
|
491
|
-
this.overflowMenu.buttonElement.remove();
|
|
492
|
-
this.container.appendChild(this.overflowMenu.buttonElement);
|
|
493
|
-
this.overflowMenu.buttonElement.style.visibility = 'hidden';
|
|
494
|
-
}
|
|
495
|
-
// If we are only showing the overflow, add this class to avoid taking up space
|
|
496
|
-
this.container.classList.toggle(overflowMenuOnlyClass, this.numMenusShown === 0);
|
|
497
|
-
}
|
|
498
|
-
updateLabels(titleElement, buttonElement, label) {
|
|
499
|
-
const cleanMenuLabel = (0, _get__("consts_1").cleanMnemonic)(label);
|
|
500
|
-
// Update the button label to reflect mnemonics
|
|
501
|
-
if (this.options.enableMnemonics) {
|
|
502
|
-
const cleanLabel = _get__("strings").escape(label);
|
|
503
|
-
// This is global so reset it
|
|
504
|
-
_get__("consts_1").MENU_ESCAPED_MNEMONIC_REGEX.lastIndex = 0;
|
|
505
|
-
let escMatch = _get__("consts_1").MENU_ESCAPED_MNEMONIC_REGEX.exec(cleanLabel);
|
|
506
|
-
// We can't use negative lookbehind so we match our negative and skip
|
|
507
|
-
while (escMatch && escMatch[1]) {
|
|
508
|
-
escMatch = _get__("consts_1").MENU_ESCAPED_MNEMONIC_REGEX.exec(cleanLabel);
|
|
509
|
-
}
|
|
510
|
-
const replaceDoubleEscapes = str => str.replace(/&&/g, '&');
|
|
511
|
-
if (escMatch) {
|
|
512
|
-
titleElement.innerText = '';
|
|
513
|
-
titleElement.append(_get__("strings").ltrim(replaceDoubleEscapes(cleanLabel.substring(0, escMatch.index)), ' '), _get__("$")('mnemonic', {
|
|
514
|
-
'aria-hidden': 'true'
|
|
515
|
-
}, escMatch[3]), _get__("strings").rtrim(replaceDoubleEscapes(cleanLabel.substring(escMatch.index + escMatch[0].length)), ' '));
|
|
516
|
-
} else {
|
|
517
|
-
titleElement.innerText = replaceDoubleEscapes(cleanLabel).trim();
|
|
518
|
-
}
|
|
519
|
-
} else {
|
|
520
|
-
titleElement.innerText = cleanMenuLabel.replace(/&&/g, '&');
|
|
521
|
-
}
|
|
522
|
-
const mnemonicMatches = _get__("consts_1").MENU_MNEMONIC_REGEX.exec(label);
|
|
523
|
-
// Register mnemonics
|
|
524
|
-
if (mnemonicMatches) {
|
|
525
|
-
const mnemonic = !!mnemonicMatches[1] ? mnemonicMatches[1] : mnemonicMatches[3];
|
|
526
|
-
if (this.options.enableMnemonics) {
|
|
527
|
-
buttonElement.setAttribute('aria-keyshortcuts', 'Alt+' + mnemonic.toLocaleLowerCase());
|
|
528
|
-
} else {
|
|
529
|
-
buttonElement.removeAttribute('aria-keyshortcuts');
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
update(options) {
|
|
534
|
-
if (options) {
|
|
535
|
-
this.options = options;
|
|
536
|
-
}
|
|
537
|
-
// Don't update while using the menu
|
|
538
|
-
if (this.isFocused) {
|
|
539
|
-
this.updatePending = true;
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
this.menus.forEach(menuBarMenu => {
|
|
543
|
-
if (!menuBarMenu.buttonElement || !menuBarMenu.titleElement) {
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
this.updateLabels(menuBarMenu.titleElement, menuBarMenu.buttonElement, menuBarMenu.label);
|
|
547
|
-
});
|
|
548
|
-
if (!this.overflowLayoutScheduled) {
|
|
549
|
-
this.overflowLayoutScheduled = _get__("DOM").scheduleAtNextAnimationFrame(() => {
|
|
550
|
-
this.updateOverflowAction();
|
|
551
|
-
this.overflowLayoutScheduled = undefined;
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
this.setUnfocusedState();
|
|
555
|
-
}
|
|
556
|
-
registerMnemonic(menuIndex, mnemonic) {
|
|
557
|
-
this.mnemonics.set(mnemonic.toLocaleLowerCase(), menuIndex);
|
|
558
|
-
}
|
|
559
|
-
hideMenubar() {
|
|
560
|
-
if (this.container.style.display !== 'none') {
|
|
561
|
-
this.container.style.display = 'none';
|
|
562
|
-
this._onVisibilityChange.fire(false);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
showMenubar() {
|
|
566
|
-
if (this.container.style.display !== 'flex') {
|
|
567
|
-
this.container.style.display = 'flex';
|
|
568
|
-
this._onVisibilityChange.fire(true);
|
|
569
|
-
this.updateOverflowAction();
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
get focusState() {
|
|
573
|
-
return this._focusState;
|
|
574
|
-
}
|
|
575
|
-
set focusState(value) {
|
|
576
|
-
if (this._focusState >= _get__("MenubarState").FOCUSED && value < _get__("MenubarState").FOCUSED) {
|
|
577
|
-
// Losing focus, update the menu if needed
|
|
578
|
-
if (this.updatePending) {
|
|
579
|
-
this.menuUpdater.schedule();
|
|
580
|
-
this.updatePending = false;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
if (value === this._focusState) {
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
const isVisible = this.isVisible;
|
|
587
|
-
const isOpen = this.isOpen;
|
|
588
|
-
const isFocused = this.isFocused;
|
|
589
|
-
this._focusState = value;
|
|
590
|
-
switch (value) {
|
|
591
|
-
case _get__("MenubarState").HIDDEN:
|
|
592
|
-
if (isVisible) {
|
|
593
|
-
this.hideMenubar();
|
|
594
|
-
}
|
|
595
|
-
if (isOpen) {
|
|
596
|
-
this.cleanupMenu();
|
|
597
|
-
}
|
|
598
|
-
if (isFocused) {
|
|
599
|
-
this.focusedMenu = undefined;
|
|
600
|
-
if (this.focusToReturn) {
|
|
601
|
-
this.focusToReturn.focus();
|
|
602
|
-
this.focusToReturn = undefined;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
break;
|
|
606
|
-
case _get__("MenubarState").VISIBLE:
|
|
607
|
-
if (!isVisible) {
|
|
608
|
-
this.showMenubar();
|
|
609
|
-
}
|
|
610
|
-
if (isOpen) {
|
|
611
|
-
this.cleanupMenu();
|
|
612
|
-
}
|
|
613
|
-
if (isFocused) {
|
|
614
|
-
if (this.focusedMenu) {
|
|
615
|
-
if (this.focusedMenu.index === _get__("MenuBar").OVERFLOW_INDEX) {
|
|
616
|
-
this.overflowMenu.buttonElement.blur();
|
|
617
|
-
} else {
|
|
618
|
-
this.menus[this.focusedMenu.index].buttonElement?.blur();
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
this.focusedMenu = undefined;
|
|
622
|
-
if (this.focusToReturn) {
|
|
623
|
-
this.focusToReturn.focus();
|
|
624
|
-
this.focusToReturn = undefined;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
break;
|
|
628
|
-
case _get__("MenubarState").FOCUSED:
|
|
629
|
-
if (!isVisible) {
|
|
630
|
-
this.showMenubar();
|
|
631
|
-
}
|
|
632
|
-
if (isOpen) {
|
|
633
|
-
this.cleanupMenu();
|
|
634
|
-
}
|
|
635
|
-
if (this.focusedMenu) {
|
|
636
|
-
if (this.focusedMenu.index === _get__("MenuBar").OVERFLOW_INDEX) {
|
|
637
|
-
this.overflowMenu.buttonElement.focus();
|
|
638
|
-
} else {
|
|
639
|
-
this.menus[this.focusedMenu.index].buttonElement?.focus();
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
break;
|
|
643
|
-
case _get__("MenubarState").OPEN:
|
|
644
|
-
if (!isVisible) {
|
|
645
|
-
this.showMenubar();
|
|
646
|
-
}
|
|
647
|
-
if (this.focusedMenu) {
|
|
648
|
-
this.showMenu(this.focusedMenu.index, this.openedViaKeyboard);
|
|
649
|
-
}
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
652
|
-
this._focusState = value;
|
|
653
|
-
this._onFocusStateChange.fire(this.focusState >= _get__("MenubarState").FOCUSED);
|
|
654
|
-
}
|
|
655
|
-
get isVisible() {
|
|
656
|
-
return this.focusState >= _get__("MenubarState").VISIBLE;
|
|
657
|
-
}
|
|
658
|
-
get isFocused() {
|
|
659
|
-
return this.focusState >= _get__("MenubarState").FOCUSED;
|
|
660
|
-
}
|
|
661
|
-
get isOpen() {
|
|
662
|
-
return this.focusState >= _get__("MenubarState").OPEN;
|
|
663
|
-
}
|
|
664
|
-
get hasOverflow() {
|
|
665
|
-
return this.isCompact || this.numMenusShown < this.menus.length;
|
|
666
|
-
}
|
|
667
|
-
get isCompact() {
|
|
668
|
-
return this.options.compactMode !== undefined;
|
|
669
|
-
}
|
|
670
|
-
setUnfocusedState() {
|
|
671
|
-
if (this.options.visibility === 'toggle' || this.options.visibility === 'hidden') {
|
|
672
|
-
this.focusState = _get__("MenubarState").HIDDEN;
|
|
673
|
-
} else if (this.options.visibility === 'classic') {
|
|
674
|
-
this.focusState = _get__("MenubarState").HIDDEN;
|
|
675
|
-
} else {
|
|
676
|
-
this.focusState = _get__("MenubarState").VISIBLE;
|
|
677
|
-
}
|
|
678
|
-
this.ignoreNextMouseUp = false;
|
|
679
|
-
this.mnemonicsInUse = false;
|
|
680
|
-
this.updateMnemonicVisibility(false);
|
|
681
|
-
}
|
|
682
|
-
focusPrevious() {
|
|
683
|
-
if (!this.focusedMenu || this.numMenusShown === 0) {
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
let newFocusedIndex = (this.focusedMenu.index - 1 + this.numMenusShown) % this.numMenusShown;
|
|
687
|
-
if (this.focusedMenu.index === _get__("MenuBar").OVERFLOW_INDEX) {
|
|
688
|
-
newFocusedIndex = this.numMenusShown - 1;
|
|
689
|
-
} else if (this.focusedMenu.index === 0 && this.hasOverflow) {
|
|
690
|
-
newFocusedIndex = _get__("MenuBar").OVERFLOW_INDEX;
|
|
691
|
-
}
|
|
692
|
-
if (newFocusedIndex === this.focusedMenu.index) {
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
if (this.isOpen) {
|
|
696
|
-
this.cleanupMenu();
|
|
697
|
-
this.showMenu(newFocusedIndex);
|
|
698
|
-
} else if (this.isFocused) {
|
|
699
|
-
this.focusedMenu.index = newFocusedIndex;
|
|
700
|
-
if (newFocusedIndex === _get__("MenuBar").OVERFLOW_INDEX) {
|
|
701
|
-
this.overflowMenu.buttonElement.focus();
|
|
702
|
-
} else {
|
|
703
|
-
this.menus[newFocusedIndex].buttonElement?.focus();
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
focusNext() {
|
|
708
|
-
if (!this.focusedMenu || this.numMenusShown === 0) {
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
let newFocusedIndex = (this.focusedMenu.index + 1) % this.numMenusShown;
|
|
712
|
-
if (this.focusedMenu.index === _get__("MenuBar").OVERFLOW_INDEX) {
|
|
713
|
-
newFocusedIndex = 0;
|
|
714
|
-
} else if (this.focusedMenu.index === this.numMenusShown - 1) {
|
|
715
|
-
newFocusedIndex = _get__("MenuBar").OVERFLOW_INDEX;
|
|
716
|
-
}
|
|
717
|
-
if (newFocusedIndex === this.focusedMenu.index) {
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
if (this.isOpen) {
|
|
721
|
-
this.cleanupMenu();
|
|
722
|
-
this.showMenu(newFocusedIndex);
|
|
723
|
-
} else if (this.isFocused) {
|
|
724
|
-
this.focusedMenu.index = newFocusedIndex;
|
|
725
|
-
if (newFocusedIndex === _get__("MenuBar").OVERFLOW_INDEX) {
|
|
726
|
-
this.overflowMenu.buttonElement.focus();
|
|
727
|
-
} else {
|
|
728
|
-
this.menus[newFocusedIndex].buttonElement?.focus();
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
updateMnemonicVisibility(visible) {
|
|
733
|
-
if (this.menus) {
|
|
734
|
-
this.menus.forEach(menuBarMenu => {
|
|
735
|
-
if (menuBarMenu.titleElement && menuBarMenu.titleElement.children.length) {
|
|
736
|
-
const child = menuBarMenu.titleElement.children.item(0);
|
|
737
|
-
if (child) {
|
|
738
|
-
child.style.textDecoration = this.options.alwaysOnMnemonics || visible ? 'underline' : '';
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
get mnemonicsInUse() {
|
|
745
|
-
return this._mnemonicsInUse;
|
|
746
|
-
}
|
|
747
|
-
set mnemonicsInUse(value) {
|
|
748
|
-
this._mnemonicsInUse = value;
|
|
749
|
-
}
|
|
750
|
-
get shouldAltKeyFocus() {
|
|
751
|
-
if (_get__("platform_1").isMacintosh) {
|
|
752
|
-
return false;
|
|
753
|
-
}
|
|
754
|
-
if (!this.options.disableAltFocus) {
|
|
755
|
-
return true;
|
|
756
|
-
}
|
|
757
|
-
if (this.options.visibility === 'toggle') {
|
|
758
|
-
return true;
|
|
759
|
-
}
|
|
760
|
-
return false;
|
|
761
|
-
}
|
|
762
|
-
get onVisibilityChange() {
|
|
763
|
-
return this._onVisibilityChange.event;
|
|
764
|
-
}
|
|
765
|
-
get onFocusStateChange() {
|
|
766
|
-
return this._onFocusStateChange.event;
|
|
767
|
-
}
|
|
768
|
-
onMenuTriggered(menuIndex, clicked) {
|
|
769
|
-
if (!this.menus[menuIndex].actions) {
|
|
770
|
-
_get__("electron_1").ipcRenderer.send('menu-event', menuIndex + 1);
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
if (this.isOpen) {
|
|
774
|
-
if (this.isCurrentMenu(menuIndex)) {
|
|
775
|
-
this.setUnfocusedState();
|
|
776
|
-
} else {
|
|
777
|
-
this.cleanupMenu();
|
|
778
|
-
this.showMenu(menuIndex, this.openedViaKeyboard);
|
|
779
|
-
}
|
|
780
|
-
} else {
|
|
781
|
-
this.focusedMenu = {
|
|
782
|
-
index: menuIndex
|
|
783
|
-
};
|
|
784
|
-
this.openedViaKeyboard = !clicked;
|
|
785
|
-
this.focusState = _get__("MenubarState").OPEN;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
onModifierKeyToggled(modifierKeyStatus) {
|
|
789
|
-
const allModifiersReleased = !modifierKeyStatus.altKey && !modifierKeyStatus.ctrlKey && !modifierKeyStatus.shiftKey && !modifierKeyStatus.metaKey;
|
|
790
|
-
if (this.options.visibility === 'hidden') {
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
// Prevent alt-key default if the menu is not hidden and we use alt to focus
|
|
794
|
-
if (modifierKeyStatus.event && this.shouldAltKeyFocus) {
|
|
795
|
-
if (_get__("keyCodes_1").ScanCodeUtils.toEnum(modifierKeyStatus.event.code) === 159 /* ScanCode.AltLeft */) {
|
|
796
|
-
modifierKeyStatus.event.preventDefault();
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
// Alt key pressed while menu is focused. This should return focus away from the menubar
|
|
800
|
-
if (this.isFocused && modifierKeyStatus.lastKeyPressed === 'alt' && modifierKeyStatus.altKey) {
|
|
801
|
-
this.setUnfocusedState();
|
|
802
|
-
this.mnemonicsInUse = false;
|
|
803
|
-
this.awaitingAltRelease = true;
|
|
804
|
-
}
|
|
805
|
-
// Clean alt key press and release
|
|
806
|
-
if (allModifiersReleased && modifierKeyStatus.lastKeyPressed === 'alt' && modifierKeyStatus.lastKeyReleased === 'alt') {
|
|
807
|
-
if (!this.awaitingAltRelease) {
|
|
808
|
-
if (!this.isFocused && this.shouldAltKeyFocus) {
|
|
809
|
-
this.mnemonicsInUse = true;
|
|
810
|
-
this.focusedMenu = {
|
|
811
|
-
index: this.numMenusShown > 0 ? 0 : _get__("MenuBar").OVERFLOW_INDEX
|
|
812
|
-
};
|
|
813
|
-
this.focusState = _get__("MenubarState").FOCUSED;
|
|
814
|
-
} else if (!this.isOpen) {
|
|
815
|
-
this.setUnfocusedState();
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
// Alt key released
|
|
820
|
-
if (!modifierKeyStatus.altKey && modifierKeyStatus.lastKeyReleased === 'alt') {
|
|
821
|
-
this.awaitingAltRelease = false;
|
|
822
|
-
}
|
|
823
|
-
if (this.options.enableMnemonics && this.menus && !this.isOpen) {
|
|
824
|
-
this.updateMnemonicVisibility(!this.awaitingAltRelease && modifierKeyStatus.altKey || this.mnemonicsInUse);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
isCurrentMenu(menuIndex) {
|
|
828
|
-
if (!this.focusedMenu) {
|
|
829
|
-
return false;
|
|
830
|
-
}
|
|
831
|
-
return this.focusedMenu.index === menuIndex;
|
|
832
|
-
}
|
|
833
|
-
cleanupMenu() {
|
|
834
|
-
if (this.focusedMenu) {
|
|
835
|
-
// Remove focus from the menus first
|
|
836
|
-
if (this.focusedMenu.index === _get__("MenuBar").OVERFLOW_INDEX) {
|
|
837
|
-
this.overflowMenu.buttonElement.focus();
|
|
838
|
-
} else {
|
|
839
|
-
this.menus[this.focusedMenu.index].buttonElement?.focus();
|
|
840
|
-
}
|
|
841
|
-
if (this.focusedMenu.holder) {
|
|
842
|
-
this.focusedMenu.holder.parentElement?.classList.remove('open');
|
|
843
|
-
this.focusedMenu.holder.remove();
|
|
844
|
-
}
|
|
845
|
-
this.focusedMenu.widget?.dispose();
|
|
846
|
-
this.focusedMenu = {
|
|
847
|
-
index: this.focusedMenu.index
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
showMenu(menuIndex, selectFirst = true) {
|
|
852
|
-
const actualMenuIndex = menuIndex >= this.numMenusShown ? _get__("MenuBar").OVERFLOW_INDEX : menuIndex;
|
|
853
|
-
const customMenu = actualMenuIndex === _get__("MenuBar").OVERFLOW_INDEX ? this.overflowMenu : this.menus[actualMenuIndex];
|
|
854
|
-
if (!customMenu.actions || !customMenu.buttonElement || !customMenu.titleElement) {
|
|
855
|
-
return;
|
|
856
|
-
}
|
|
857
|
-
const menuHolder = _get__("$")('.cet-menubar-menu-container', {
|
|
858
|
-
title: ''
|
|
859
|
-
});
|
|
860
|
-
customMenu.buttonElement.classList.add('open');
|
|
861
|
-
const titleBoundingRect = customMenu.titleElement.getBoundingClientRect();
|
|
862
|
-
const titleBoundingRectZoom = _get__("DOM").getDomNodeZoomLevel(customMenu.titleElement);
|
|
863
|
-
if (this.options.compactMode === _get__("menu_1").Direction.Right) {
|
|
864
|
-
menuHolder.style.top = `${titleBoundingRect.top}px`;
|
|
865
|
-
menuHolder.style.left = `${titleBoundingRect.left + this.container.clientWidth}px`;
|
|
866
|
-
} else if (this.options.compactMode === _get__("menu_1").Direction.Left) {
|
|
867
|
-
menuHolder.style.top = `${titleBoundingRect.top}px`;
|
|
868
|
-
menuHolder.style.right = `${this.container.clientWidth}px`;
|
|
869
|
-
menuHolder.style.left = 'auto';
|
|
870
|
-
} else {
|
|
871
|
-
menuHolder.style.top = `${titleBoundingRect.bottom * titleBoundingRectZoom}px`;
|
|
872
|
-
menuHolder.style.left = `${titleBoundingRect.left * titleBoundingRectZoom}px`;
|
|
873
|
-
}
|
|
874
|
-
customMenu.buttonElement.appendChild(menuHolder);
|
|
875
|
-
const menuOptions = {
|
|
876
|
-
// getKeyBinding: this.options.getKeybinding,
|
|
877
|
-
// actionRunner: this.actionRunner,
|
|
878
|
-
enableMnemonics: this.options.alwaysOnMnemonics || this.mnemonicsInUse && this.options.enableMnemonics,
|
|
879
|
-
ariaLabel: customMenu.buttonElement.getAttribute('aria-label') ?? undefined
|
|
880
|
-
// expandDirection: this.isCompact ? this.options.compactMode : Direction.Right,
|
|
881
|
-
// useEventAsContext: true
|
|
882
|
-
};
|
|
883
|
-
|
|
884
|
-
const menuWidget = this._register(new (_get__("menu_1").CETMenu)(menuHolder, this.menuIcons, this.currentOptions, menuOptions, this.closeMenu));
|
|
885
|
-
menuWidget.createMenu(customMenu.actions?.items ?? []);
|
|
886
|
-
menuWidget.applyStyle(this.menuStyle);
|
|
887
|
-
this._register(menuWidget.onDidCancel(() => {
|
|
888
|
-
this.focusState = _get__("MenubarState").FOCUSED;
|
|
889
|
-
}));
|
|
890
|
-
if (actualMenuIndex !== menuIndex) {
|
|
891
|
-
menuWidget.trigger(menuIndex - this.numMenusShown);
|
|
892
|
-
} else {
|
|
893
|
-
menuWidget.focus(selectFirst);
|
|
894
|
-
}
|
|
895
|
-
this.focusedMenu = {
|
|
896
|
-
index: actualMenuIndex,
|
|
897
|
-
holder: menuHolder,
|
|
898
|
-
widget: menuWidget
|
|
899
|
-
};
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
exports.MenuBar = _get__("MenuBar");
|
|
903
|
-
_get__("MenuBar").OVERFLOW_INDEX = -1;
|
|
904
|
-
function _getGlobalObject() {
|
|
905
|
-
try {
|
|
906
|
-
if (!!global) {
|
|
907
|
-
return global;
|
|
908
|
-
}
|
|
909
|
-
} catch (e) {
|
|
910
|
-
try {
|
|
911
|
-
if (!!window) {
|
|
912
|
-
return window;
|
|
913
|
-
}
|
|
914
|
-
} catch (e) {
|
|
915
|
-
return this;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
;
|
|
920
|
-
var _RewireModuleId__ = null;
|
|
921
|
-
function _getRewireModuleId__() {
|
|
922
|
-
if (_RewireModuleId__ === null) {
|
|
923
|
-
let globalVariable = _getGlobalObject();
|
|
924
|
-
if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {
|
|
925
|
-
globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;
|
|
926
|
-
}
|
|
927
|
-
_RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;
|
|
928
|
-
}
|
|
929
|
-
return _RewireModuleId__;
|
|
930
|
-
}
|
|
931
|
-
function _getRewireRegistry__() {
|
|
932
|
-
let theGlobalVariable = _getGlobalObject();
|
|
933
|
-
if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {
|
|
934
|
-
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
|
|
935
|
-
}
|
|
936
|
-
return theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__;
|
|
937
|
-
}
|
|
938
|
-
function _getRewiredData__() {
|
|
939
|
-
let moduleId = _getRewireModuleId__();
|
|
940
|
-
let registry = _getRewireRegistry__();
|
|
941
|
-
let rewireData = registry[moduleId];
|
|
942
|
-
if (!rewireData) {
|
|
943
|
-
registry[moduleId] = Object.create(null);
|
|
944
|
-
rewireData = registry[moduleId];
|
|
945
|
-
}
|
|
946
|
-
return rewireData;
|
|
947
|
-
}
|
|
948
|
-
(function registerResetAll() {
|
|
949
|
-
let theGlobalVariable = _getGlobalObject();
|
|
950
|
-
if (!theGlobalVariable['__rewire_reset_all__']) {
|
|
951
|
-
theGlobalVariable['__rewire_reset_all__'] = function () {
|
|
952
|
-
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
})();
|
|
956
|
-
var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';
|
|
957
|
-
let _RewireAPI__ = {};
|
|
958
|
-
(function () {
|
|
959
|
-
function addPropertyToAPIObject(name, value) {
|
|
960
|
-
Object.defineProperty(_RewireAPI__, name, {
|
|
961
|
-
value: value,
|
|
962
|
-
enumerable: false,
|
|
963
|
-
configurable: true
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
addPropertyToAPIObject('__get__', _get__);
|
|
967
|
-
addPropertyToAPIObject('__GetDependency__', _get__);
|
|
968
|
-
addPropertyToAPIObject('__Rewire__', _set__);
|
|
969
|
-
addPropertyToAPIObject('__set__', _set__);
|
|
970
|
-
addPropertyToAPIObject('__reset__', _reset__);
|
|
971
|
-
addPropertyToAPIObject('__ResetDependency__', _reset__);
|
|
972
|
-
addPropertyToAPIObject('__with__', _with__);
|
|
973
|
-
})();
|
|
974
|
-
function _get__(variableName) {
|
|
975
|
-
let rewireData = _getRewiredData__();
|
|
976
|
-
if (rewireData[variableName] === undefined) {
|
|
977
|
-
return _get_original__(variableName);
|
|
978
|
-
} else {
|
|
979
|
-
var value = rewireData[variableName];
|
|
980
|
-
if (value === INTENTIONAL_UNDEFINED) {
|
|
981
|
-
return undefined;
|
|
982
|
-
} else {
|
|
983
|
-
return value;
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
function _get_original__(variableName) {
|
|
988
|
-
switch (variableName) {
|
|
989
|
-
case "__createBinding":
|
|
990
|
-
return __createBinding;
|
|
991
|
-
case "__setModuleDefault":
|
|
992
|
-
return __setModuleDefault;
|
|
993
|
-
case "__importStar":
|
|
994
|
-
return __importStar;
|
|
995
|
-
case "DOM":
|
|
996
|
-
return DOM;
|
|
997
|
-
case "MenubarState":
|
|
998
|
-
return MenubarState;
|
|
999
|
-
case "event_1":
|
|
1000
|
-
return event_1;
|
|
1001
|
-
case "async_1":
|
|
1002
|
-
return async_1;
|
|
1003
|
-
case "platform_1":
|
|
1004
|
-
return platform_1;
|
|
1005
|
-
case "keyboardEvent_1":
|
|
1006
|
-
return keyboardEvent_1;
|
|
1007
|
-
case "consts_1":
|
|
1008
|
-
return consts_1;
|
|
1009
|
-
case "$":
|
|
1010
|
-
return $;
|
|
1011
|
-
case "touch_1":
|
|
1012
|
-
return touch_1;
|
|
1013
|
-
case "mouseEvent_1":
|
|
1014
|
-
return mouseEvent_1;
|
|
1015
|
-
case "menu_1":
|
|
1016
|
-
return menu_1;
|
|
1017
|
-
case "MenuBar":
|
|
1018
|
-
return MenuBar;
|
|
1019
|
-
case "lifecycle_1":
|
|
1020
|
-
return lifecycle_1;
|
|
1021
|
-
case "strings":
|
|
1022
|
-
return strings;
|
|
1023
|
-
case "electron_1":
|
|
1024
|
-
return electron_1;
|
|
1025
|
-
case "keyCodes_1":
|
|
1026
|
-
return keyCodes_1;
|
|
1027
|
-
}
|
|
1028
|
-
return undefined;
|
|
1029
|
-
}
|
|
1030
|
-
function _assign__(variableName, value) {
|
|
1031
|
-
let rewireData = _getRewiredData__();
|
|
1032
|
-
if (rewireData[variableName] === undefined) {
|
|
1033
|
-
return _set_original__(variableName, value);
|
|
1034
|
-
} else {
|
|
1035
|
-
return rewireData[variableName] = value;
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
function _set_original__(variableName, _value) {
|
|
1039
|
-
switch (variableName) {
|
|
1040
|
-
case "MenubarState":
|
|
1041
|
-
return MenubarState = _value;
|
|
1042
|
-
}
|
|
1043
|
-
return undefined;
|
|
1044
|
-
}
|
|
1045
|
-
function _update_operation__(operation, variableName, prefix) {
|
|
1046
|
-
var oldValue = _get__(variableName);
|
|
1047
|
-
var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;
|
|
1048
|
-
_assign__(variableName, newValue);
|
|
1049
|
-
return prefix ? newValue : oldValue;
|
|
1050
|
-
}
|
|
1051
|
-
function _set__(variableName, value) {
|
|
1052
|
-
let rewireData = _getRewiredData__();
|
|
1053
|
-
if (typeof variableName === 'object') {
|
|
1054
|
-
Object.keys(variableName).forEach(function (name) {
|
|
1055
|
-
rewireData[name] = variableName[name];
|
|
1056
|
-
});
|
|
1057
|
-
return function () {
|
|
1058
|
-
Object.keys(variableName).forEach(function (name) {
|
|
1059
|
-
_reset__(variableName);
|
|
1060
|
-
});
|
|
1061
|
-
};
|
|
1062
|
-
} else {
|
|
1063
|
-
if (value === undefined) {
|
|
1064
|
-
rewireData[variableName] = INTENTIONAL_UNDEFINED;
|
|
1065
|
-
} else {
|
|
1066
|
-
rewireData[variableName] = value;
|
|
1067
|
-
}
|
|
1068
|
-
return function () {
|
|
1069
|
-
_reset__(variableName);
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
function _reset__(variableName) {
|
|
1074
|
-
let rewireData = _getRewiredData__();
|
|
1075
|
-
delete rewireData[variableName];
|
|
1076
|
-
if (Object.keys(rewireData).length == 0) {
|
|
1077
|
-
delete _getRewireRegistry__()[_getRewireModuleId__];
|
|
1078
|
-
}
|
|
1079
|
-
;
|
|
1080
|
-
}
|
|
1081
|
-
function _with__(object) {
|
|
1082
|
-
let rewireData = _getRewiredData__();
|
|
1083
|
-
var rewiredVariableNames = Object.keys(object);
|
|
1084
|
-
var previousValues = {};
|
|
1085
|
-
function reset() {
|
|
1086
|
-
rewiredVariableNames.forEach(function (variableName) {
|
|
1087
|
-
rewireData[variableName] = previousValues[variableName];
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1090
|
-
return function (callback) {
|
|
1091
|
-
rewiredVariableNames.forEach(function (variableName) {
|
|
1092
|
-
previousValues[variableName] = rewireData[variableName];
|
|
1093
|
-
rewireData[variableName] = object[variableName];
|
|
1094
|
-
});
|
|
1095
|
-
let result = callback();
|
|
1096
|
-
if (!!result && typeof result.then == 'function') {
|
|
1097
|
-
result.then(reset).catch(reset);
|
|
1098
|
-
} else {
|
|
1099
|
-
reset();
|
|
1100
|
-
}
|
|
1101
|
-
return result;
|
|
1102
|
-
};
|
|
1103
|
-
}
|
|
1104
|
-
let _typeOfOriginalExport = typeof module.exports;
|
|
1105
|
-
function addNonEnumerableProperty(name, value) {
|
|
1106
|
-
Object.defineProperty(module.exports, name, {
|
|
1107
|
-
value: value,
|
|
1108
|
-
enumerable: false,
|
|
1109
|
-
configurable: true
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
if ((_typeOfOriginalExport === 'object' || _typeOfOriginalExport === 'function') && Object.isExtensible(module.exports)) {
|
|
1113
|
-
addNonEnumerableProperty('__get__', _get__);
|
|
1114
|
-
addNonEnumerableProperty('__GetDependency__', _get__);
|
|
1115
|
-
addNonEnumerableProperty('__Rewire__', _set__);
|
|
1116
|
-
addNonEnumerableProperty('__set__', _set__);
|
|
1117
|
-
addNonEnumerableProperty('__reset__', _reset__);
|
|
1118
|
-
addNonEnumerableProperty('__ResetDependency__', _reset__);
|
|
1119
|
-
addNonEnumerableProperty('__with__', _with__);
|
|
1120
|
-
addNonEnumerableProperty('__RewireAPI__', _RewireAPI__);
|
|
1121
|
-
}
|