custom-electron-titlebar 4.2.8 → 4.4.1

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