@theia/core 1.32.0-next.8 → 1.32.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.
Files changed (113) hide show
  1. package/README.md +6 -6
  2. package/i18n/nls.cs.json +14 -13
  3. package/i18n/nls.de.json +14 -13
  4. package/i18n/nls.es.json +14 -13
  5. package/i18n/nls.fr.json +14 -13
  6. package/i18n/nls.hu.json +14 -13
  7. package/i18n/nls.it.json +14 -13
  8. package/i18n/nls.ja.json +14 -13
  9. package/i18n/nls.json +16 -15
  10. package/i18n/nls.pl.json +14 -13
  11. package/i18n/nls.pt-br.json +14 -13
  12. package/i18n/nls.pt-pt.json +14 -13
  13. package/i18n/nls.ru.json +14 -13
  14. package/i18n/nls.zh-cn.json +23 -22
  15. package/lib/browser/context-key-service.d.ts +20 -8
  16. package/lib/browser/context-key-service.d.ts.map +1 -1
  17. package/lib/browser/context-key-service.js +6 -0
  18. package/lib/browser/context-key-service.js.map +1 -1
  19. package/lib/browser/context-menu-renderer.d.ts +2 -0
  20. package/lib/browser/context-menu-renderer.d.ts.map +1 -1
  21. package/lib/browser/context-menu-renderer.js.map +1 -1
  22. package/lib/browser/core-preferences.d.ts.map +1 -1
  23. package/lib/browser/core-preferences.js +8 -9
  24. package/lib/browser/core-preferences.js.map +1 -1
  25. package/lib/browser/frontend-application-module.d.ts.map +1 -1
  26. package/lib/browser/frontend-application-module.js +4 -1
  27. package/lib/browser/frontend-application-module.js.map +1 -1
  28. package/lib/browser/hover-service.d.ts +41 -0
  29. package/lib/browser/hover-service.d.ts.map +1 -0
  30. package/lib/browser/hover-service.js +191 -0
  31. package/lib/browser/hover-service.js.map +1 -0
  32. package/lib/browser/icon-theme-service.js +1 -1
  33. package/lib/browser/icon-theme-service.js.map +1 -1
  34. package/lib/browser/index.d.ts +1 -0
  35. package/lib/browser/index.d.ts.map +1 -1
  36. package/lib/browser/index.js +1 -0
  37. package/lib/browser/index.js.map +1 -1
  38. package/lib/browser/menu/browser-context-menu-renderer.d.ts +1 -1
  39. package/lib/browser/menu/browser-context-menu-renderer.d.ts.map +1 -1
  40. package/lib/browser/menu/browser-context-menu-renderer.js +2 -2
  41. package/lib/browser/menu/browser-context-menu-renderer.js.map +1 -1
  42. package/lib/browser/menu/browser-menu-plugin.d.ts +4 -3
  43. package/lib/browser/menu/browser-menu-plugin.d.ts.map +1 -1
  44. package/lib/browser/menu/browser-menu-plugin.js +9 -6
  45. package/lib/browser/menu/browser-menu-plugin.js.map +1 -1
  46. package/lib/browser/resource-context-key.d.ts +2 -3
  47. package/lib/browser/resource-context-key.d.ts.map +1 -1
  48. package/lib/browser/resource-context-key.js +2 -4
  49. package/lib/browser/resource-context-key.js.map +1 -1
  50. package/lib/browser/shell/application-shell.d.ts.map +1 -1
  51. package/lib/browser/shell/application-shell.js +7 -0
  52. package/lib/browser/shell/application-shell.js.map +1 -1
  53. package/lib/browser/shell/sidebar-menu-widget.d.ts +3 -0
  54. package/lib/browser/shell/sidebar-menu-widget.d.ts.map +1 -1
  55. package/lib/browser/shell/sidebar-menu-widget.js +15 -1
  56. package/lib/browser/shell/sidebar-menu-widget.js.map +1 -1
  57. package/lib/browser/shell/tab-bars.d.ts +4 -1
  58. package/lib/browser/shell/tab-bars.d.ts.map +1 -1
  59. package/lib/browser/shell/tab-bars.js +25 -12
  60. package/lib/browser/shell/tab-bars.js.map +1 -1
  61. package/lib/browser/status-bar/index.d.ts +0 -1
  62. package/lib/browser/status-bar/index.d.ts.map +1 -1
  63. package/lib/browser/status-bar/index.js +0 -3
  64. package/lib/browser/status-bar/index.js.map +1 -1
  65. package/lib/browser/status-bar/status-bar.d.ts +3 -3
  66. package/lib/browser/status-bar/status-bar.d.ts.map +1 -1
  67. package/lib/browser/status-bar/status-bar.js +10 -6
  68. package/lib/browser/status-bar/status-bar.js.map +1 -1
  69. package/lib/browser/view-container.js +1 -1
  70. package/lib/browser/view-container.js.map +1 -1
  71. package/lib/common/objects.spec.d.ts +2 -0
  72. package/lib/common/objects.spec.d.ts.map +1 -0
  73. package/lib/common/objects.spec.js +102 -0
  74. package/lib/common/objects.spec.js.map +1 -0
  75. package/lib/electron-browser/menu/electron-context-menu-renderer.js +2 -2
  76. package/lib/electron-browser/menu/electron-context-menu-renderer.js.map +1 -1
  77. package/lib/electron-browser/menu/electron-main-menu-factory.d.ts +8 -2
  78. package/lib/electron-browser/menu/electron-main-menu-factory.d.ts.map +1 -1
  79. package/lib/electron-browser/menu/electron-main-menu-factory.js +8 -6
  80. package/lib/electron-browser/menu/electron-main-menu-factory.js.map +1 -1
  81. package/lib/electron-main/messaging/electron-messaging-contribution.d.ts +1 -0
  82. package/lib/electron-main/messaging/electron-messaging-contribution.d.ts.map +1 -1
  83. package/lib/electron-main/messaging/electron-messaging-contribution.js +6 -2
  84. package/lib/electron-main/messaging/electron-messaging-contribution.js.map +1 -1
  85. package/package.json +6 -6
  86. package/src/browser/context-key-service.ts +29 -9
  87. package/src/browser/context-menu-renderer.ts +2 -0
  88. package/src/browser/core-preferences.ts +8 -12
  89. package/src/browser/frontend-application-module.ts +5 -1
  90. package/src/browser/hover-service.ts +189 -0
  91. package/src/browser/icon-theme-service.ts +1 -1
  92. package/src/browser/index.ts +1 -0
  93. package/src/browser/menu/browser-context-menu-renderer.ts +2 -2
  94. package/src/browser/menu/browser-menu-plugin.ts +10 -7
  95. package/src/browser/resource-context-key.ts +5 -7
  96. package/src/browser/shell/application-shell.ts +9 -2
  97. package/src/browser/shell/sidebar-menu-widget.tsx +93 -79
  98. package/src/browser/shell/tab-bars.ts +29 -6
  99. package/src/browser/status-bar/index.ts +0 -3
  100. package/src/browser/status-bar/status-bar.tsx +7 -3
  101. package/src/browser/style/hover-service.css +95 -0
  102. package/src/browser/style/status-bar.css +0 -49
  103. package/src/browser/view-container.ts +1 -1
  104. package/src/common/i18n/nls.metadata.json +7972 -6673
  105. package/src/common/objects.spec.ts +112 -0
  106. package/src/electron-browser/menu/electron-context-menu-renderer.ts +2 -2
  107. package/src/electron-browser/menu/electron-main-menu-factory.ts +14 -6
  108. package/src/electron-main/messaging/electron-messaging-contribution.ts +7 -2
  109. package/lib/browser/status-bar/status-bar-hover-manager.d.ts +0 -25
  110. package/lib/browser/status-bar/status-bar-hover-manager.d.ts.map +0 -1
  111. package/lib/browser/status-bar/status-bar-hover-manager.js +0 -126
  112. package/lib/browser/status-bar/status-bar-hover-manager.js.map +0 -1
  113. package/src/browser/status-bar/status-bar-hover-manager.ts +0 -113
@@ -0,0 +1,112 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { expect } from 'chai';
18
+ import { deepClone, deepFreeze, isEmpty, notEmpty } from './objects';
19
+
20
+ describe('Objects', () => {
21
+
22
+ describe('#deepClone', () => {
23
+
24
+ describe('primitives', () => {
25
+ it('should deep clone numbers', () => {
26
+ expect(1).to.equal(deepClone(1));
27
+ });
28
+ it('should deep clone strings', () => {
29
+ expect('foo').to.equal(deepClone('foo'));
30
+ expect('').to.equal(deepClone(''));
31
+ });
32
+ it('should deep clone booleans', () => {
33
+ expect(true).to.equal(deepClone(true));
34
+ expect(false).to.equal(deepClone(false));
35
+ });
36
+ });
37
+
38
+ describe('undefined', () => {
39
+ it('should deep clone undefined', () => {
40
+ expect(undefined).to.equal(deepClone(undefined));
41
+ });
42
+ });
43
+
44
+ describe('arrays', () => {
45
+ it('should deep clone arrays', () => {
46
+ const a = [1, 2, 3];
47
+ const b = deepClone(a);
48
+ expect(a).to.deep.equal(b);
49
+ expect(Array.isArray(a)).to.equal(true);
50
+ expect(Array.isArray(b)).to.equal(true);
51
+ });
52
+
53
+ it('should deep clone nested arrays', () => {
54
+ const a = [[1], [2]];
55
+ const b = deepClone(a);
56
+ expect(a).to.deep.equal(b);
57
+ expect(Array.isArray(a)).to.equal(true);
58
+ expect(Array.isArray(b)).to.equal(true);
59
+ });
60
+ });
61
+
62
+ describe('objects', () => {
63
+ it('should deep clone objects', () => {
64
+ const a = { 'foo': true, 'bar': 1 };
65
+ const b = deepClone(a);
66
+ expect(a).to.deep.equal(b);
67
+ expect(typeof a).to.equal('object');
68
+ expect(typeof b).to.equal('object');
69
+ });
70
+
71
+ it('should deep clone nested objects', () => {
72
+ const a = { 'foo': true, 'nested': { 'foo': 1 } };
73
+ const b = deepClone(a);
74
+ expect(a).to.deep.equal(b);
75
+ expect(typeof a).to.equal('object');
76
+ expect(typeof b).to.equal('object');
77
+ });
78
+ });
79
+ });
80
+
81
+ describe('#deepFreeze', () => {
82
+ it('should deep freeze an object', () => {
83
+ const e = { a: 10 };
84
+ const d = deepFreeze(e);
85
+ expect(Object.isFrozen(d)).to.equal(true);
86
+ });
87
+ });
88
+
89
+ describe('#notEmpty', () => {
90
+ it('should return "true" when not empty', () => {
91
+ expect(notEmpty({})).to.equal(true);
92
+ expect(notEmpty([])).to.equal(true);
93
+ expect(notEmpty({ a: 1 })).to.equal(true);
94
+ });
95
+ it('should return "false" when empty', () => {
96
+ expect(notEmpty(undefined)).to.equal(false);
97
+ });
98
+ });
99
+
100
+ describe('#isEmpty', () => {
101
+ it('should return "true" when it is empty', () => {
102
+ // eslint-disable-next-line no-null/no-null
103
+ const obj = Object.create(null);
104
+ expect(isEmpty(obj)).to.equal(false);
105
+ });
106
+ it('should return "false" when not empty', () => {
107
+ const z = { d: 5 };
108
+ expect(isEmpty(z)).to.equal(false);
109
+ });
110
+ });
111
+
112
+ });
@@ -101,8 +101,8 @@ export class ElectronContextMenuRenderer extends BrowserContextMenuRenderer {
101
101
 
102
102
  protected override doRender(options: RenderContextMenuOptions): ContextMenuAccess {
103
103
  if (this.useNativeStyle) {
104
- const { menuPath, anchor, args, onHide, context } = options;
105
- const menu = this.electronMenuFactory.createElectronContextMenu(menuPath, args, context);
104
+ const { menuPath, anchor, args, onHide, context, contextKeyService } = options;
105
+ const menu = this.electronMenuFactory.createElectronContextMenu(menuPath, args, context, contextKeyService);
106
106
  const { x, y } = coordinateFromAnchor(anchor);
107
107
  const zoom = electron.webFrame.getZoomFactor();
108
108
  // TODO: Remove the offset once Electron fixes https://github.com/electron/electron/issues/31641
@@ -24,6 +24,7 @@ import { PreferenceService, CommonCommands } from '../../browser';
24
24
  import debounce = require('lodash.debounce');
25
25
  import { MAXIMIZED_CLASS } from '../../browser/shell/theia-dock-panel';
26
26
  import { BrowserMainMenuFactory } from '../../browser/menu/browser-menu-plugin';
27
+ import { ContextMatcher } from 'src/browser/context-key-service';
27
28
 
28
29
  /**
29
30
  * Representation of possible electron menu options.
@@ -39,6 +40,11 @@ export interface ElectronMenuOptions {
39
40
  * of menu items registered for this item.
40
41
  */
41
42
  context?: HTMLElement;
43
+ /**
44
+ * A context key service to use when evaluating any `when` clauses.
45
+ * If none is provided, the global context will be used.
46
+ */
47
+ contextKeyService?: ContextMatcher;
42
48
  /**
43
49
  * The root menu path for which the menu is being built.
44
50
  */
@@ -123,9 +129,9 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
123
129
  return null;
124
130
  }
125
131
 
126
- createElectronContextMenu(menuPath: MenuPath, args?: any[], context?: HTMLElement): Electron.Menu {
132
+ createElectronContextMenu(menuPath: MenuPath, args?: any[], context?: HTMLElement, contextKeyService?: ContextMatcher): Electron.Menu {
127
133
  const menuModel = this.menuProvider.getMenu(menuPath);
128
- const template = this.fillMenuTemplate([], menuModel, args, { showDisabled: false, context, rootMenuPath: menuPath });
134
+ const template = this.fillMenuTemplate([], menuModel, args, { showDisabled: false, context, rootMenuPath: menuPath, contextKeyService });
129
135
  return electronRemote.Menu.buildFromTemplate(template);
130
136
  }
131
137
 
@@ -136,7 +142,7 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
136
142
  ): Electron.MenuItemConstructorOptions[] {
137
143
  const showDisabled = options?.showDisabled !== false;
138
144
 
139
- if (CompoundMenuNode.is(menu) && menu.children.length && this.undefinedOrMatch(menu.when, options.context)) {
145
+ if (CompoundMenuNode.is(menu) && menu.children.length && this.undefinedOrMatch(options.contextKeyService ?? this.contextKeyService, menu.when, options.context)) {
140
146
  const role = CompoundMenuNode.getRole(menu);
141
147
  if (role === CompoundMenuNodeRole.Group && menu.id === 'inline') { return parentItems; }
142
148
  const children = CompoundMenuNode.getFlatChildren(menu.children);
@@ -162,7 +168,9 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
162
168
  return parentItems;
163
169
  }
164
170
 
165
- if (!this.menuCommandExecutor.isVisible(options.rootMenuPath, commandId, ...args) || !this.undefinedOrMatch(node.when, options.context)) {
171
+ if (
172
+ !this.menuCommandExecutor.isVisible(options.rootMenuPath, commandId, ...args)
173
+ || !this.undefinedOrMatch(options.contextKeyService ?? this.contextKeyService, node.when, options.context)) {
166
174
  return parentItems;
167
175
  }
168
176
 
@@ -202,9 +210,9 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
202
210
  return parentItems;
203
211
  }
204
212
 
205
- protected undefinedOrMatch(expression?: string, context?: HTMLElement): boolean {
213
+ protected undefinedOrMatch(contextKeyService: ContextMatcher, expression?: string, context?: HTMLElement): boolean {
206
214
  if (expression) {
207
- return this.contextKeyService.match(expression, context);
215
+ return contextKeyService.match(expression, context);
208
216
  }
209
217
  return true;
210
218
  }
@@ -78,8 +78,8 @@ export class ElectronMessagingContribution implements ElectronMainApplicationCon
78
78
  }
79
79
  });
80
80
 
81
- sender.once('did-navigate', () => multiplexer.onUnderlyingChannelClose({ reason: 'Window was refreshed' })); // When refreshing the browser window.
82
- sender.once('destroyed', () => multiplexer.onUnderlyingChannelClose({ reason: 'Window was closed' })); // When closing the browser window.
81
+ sender.once('did-navigate', () => this.disposeMultiplexer(sender.id, multiplexer, 'Window was refreshed')); // When refreshing the browser window.
82
+ sender.once('destroyed', () => this.disposeMultiplexer(sender.id, multiplexer, 'Window was closed')); // When closing the browser window.
83
83
  const data = { channel: mainChannel, multiplexer };
84
84
  this.windowChannelMultiplexer.set(sender.id, data);
85
85
  return data;
@@ -93,6 +93,11 @@ export class ElectronMessagingContribution implements ElectronMainApplicationCon
93
93
  return new ElectronWebContentChannel(sender);
94
94
  }
95
95
 
96
+ protected disposeMultiplexer(windowId: number, multiplexer: ChannelMultiplexer, reason: string): void {
97
+ multiplexer.onUnderlyingChannelClose({ reason });
98
+ this.windowChannelMultiplexer.delete(windowId);
99
+ }
100
+
96
101
  onStart(): void {
97
102
  for (const contribution of this.messagingContributions.getContributions()) {
98
103
  contribution.configure(this);
@@ -1,25 +0,0 @@
1
- import { Disposable, DisposableCollection } from '../../common';
2
- import { MarkdownString } from '../../common/markdown-rendering/markdown-string';
3
- import { MarkdownRenderer, MarkdownRendererFactory } from '../markdown-rendering/markdown-renderer';
4
- import { PreferenceService } from '../preferences';
5
- export declare class StatusBarHoverManager {
6
- protected static hostClassName: string;
7
- protected static styleSheetId: string;
8
- protected readonly preferences: PreferenceService;
9
- protected readonly markdownRendererFactory: MarkdownRendererFactory;
10
- protected _markdownRenderer: MarkdownRenderer | undefined;
11
- protected get markdownRenderer(): MarkdownRenderer;
12
- protected _hoverHost: HTMLElement | undefined;
13
- protected get hoverHost(): HTMLElement;
14
- protected pendingTimeout: Disposable | undefined;
15
- protected hoverTarget: HTMLElement | undefined;
16
- protected lastHidHover: number;
17
- protected readonly disposeOnHide: DisposableCollection;
18
- requestHover(hover: string | MarkdownString | HTMLElement, target: HTMLElement): void;
19
- protected getHoverDelay(): number;
20
- protected renderHover(hover: string | MarkdownString | HTMLElement, target: HTMLElement): Promise<void>;
21
- protected listenForMouseOut(): void;
22
- cancelHover(): void;
23
- protected unRenderHover(): void;
24
- }
25
- //# sourceMappingURL=status-bar-hover-manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status-bar-hover-manager.d.ts","sourceRoot":"","sources":["../../../src/browser/status-bar/status-bar-hover-manager.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAA4B,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AACpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,qBACa,qBAAqB;IAC9B,SAAS,CAAC,MAAM,CAAC,aAAa,SAA4B;IAC1D,SAAS,CAAC,MAAM,CAAC,YAAY,SAAkC;IACpC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IAC5C,SAAS,CAAC,QAAQ,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;IAErG,SAAS,CAAC,iBAAiB,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC1D,SAAS,KAAK,gBAAgB,IAAI,gBAAgB,CAGjD;IAED,SAAS,CAAC,UAAU,EAAE,WAAW,GAAG,SAAS,CAAC;IAC9C,SAAS,KAAK,SAAS,IAAI,WAAW,CAOrC;IACD,SAAS,CAAC,cAAc,EAAE,UAAU,GAAG,SAAS,CAAC;IACjD,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/C,SAAS,CAAC,YAAY,SAAc;IACpC,SAAS,CAAC,QAAQ,CAAC,aAAa,uBAA8B;IAE9D,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI;IAOrF,SAAS,CAAC,aAAa,IAAI,MAAM;cAMjB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7G,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAUnC,WAAW,IAAI,IAAI;IAOnB,SAAS,CAAC,aAAa,IAAI,IAAI;CAIlC"}
@@ -1,126 +0,0 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2022 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- var StatusBarHoverManager_1;
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.StatusBarHoverManager = void 0;
29
- const inversify_1 = require("inversify");
30
- const common_1 = require("../../common");
31
- const markdown_renderer_1 = require("../markdown-rendering/markdown-renderer");
32
- const preferences_1 = require("../preferences");
33
- let StatusBarHoverManager = StatusBarHoverManager_1 = class StatusBarHoverManager {
34
- constructor() {
35
- this.lastHidHover = Date.now();
36
- this.disposeOnHide = new common_1.DisposableCollection();
37
- }
38
- get markdownRenderer() {
39
- this._markdownRenderer || (this._markdownRenderer = this.markdownRendererFactory());
40
- return this._markdownRenderer;
41
- }
42
- get hoverHost() {
43
- if (!this._hoverHost) {
44
- this._hoverHost = document.createElement('div');
45
- this._hoverHost.classList.add(StatusBarHoverManager_1.hostClassName);
46
- this._hoverHost.style.position = 'absolute';
47
- }
48
- return this._hoverHost;
49
- }
50
- requestHover(hover, target) {
51
- if (target !== this.hoverTarget) {
52
- this.cancelHover();
53
- this.pendingTimeout = (0, common_1.disposableTimeout)(() => this.renderHover(hover, target), this.getHoverDelay());
54
- }
55
- }
56
- getHoverDelay() {
57
- return Date.now() - this.lastHidHover < 200
58
- ? 0
59
- : this.preferences.get('workbench.hover.delay', common_1.isOSX ? 1500 : 500);
60
- }
61
- async renderHover(hover, target) {
62
- const host = this.hoverHost;
63
- this.hoverTarget = target;
64
- if (hover instanceof HTMLElement) {
65
- host.appendChild(hover);
66
- }
67
- else if (typeof hover === 'string') {
68
- host.textContent = hover;
69
- }
70
- else {
71
- const content = this.markdownRenderer.render(hover);
72
- this.disposeOnHide.push(content);
73
- host.appendChild(content.element);
74
- }
75
- this.disposeOnHide.push({ dispose: () => this.lastHidHover = Date.now() });
76
- document.body.append(host);
77
- await new Promise(resolve => requestAnimationFrame(resolve)); // Allow the browser to size the host
78
- const targetDimensions = target.getBoundingClientRect();
79
- const targetMiddle = targetDimensions.left + (targetDimensions.width / 2);
80
- const hostDimensions = host.getBoundingClientRect();
81
- const documentWidth = document.body.getBoundingClientRect().width;
82
- const middleAlignment = targetMiddle - (hostDimensions.width / 2);
83
- const furthestRight = Math.min(documentWidth - hostDimensions.width, middleAlignment);
84
- const left = Math.max(0, furthestRight);
85
- host.style.setProperty('--theia-status-bar-hover-before-left', `${targetMiddle - left - 5}px`); // Centered on the status bar element.
86
- host.style.bottom = `${targetDimensions.height + 5}px`;
87
- host.style.left = `${left}px`;
88
- this.listenForMouseOut();
89
- }
90
- listenForMouseOut() {
91
- const handleMouseMove = (e) => {
92
- var _a;
93
- if (e.target instanceof Node && !this.hoverHost.contains(e.target) && !((_a = this.hoverTarget) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
94
- this.cancelHover();
95
- }
96
- };
97
- document.addEventListener('mousemove', handleMouseMove);
98
- this.disposeOnHide.push({ dispose: () => document.removeEventListener('mousemove', handleMouseMove) });
99
- }
100
- cancelHover() {
101
- var _a;
102
- (_a = this.pendingTimeout) === null || _a === void 0 ? void 0 : _a.dispose();
103
- this.unRenderHover();
104
- this.disposeOnHide.dispose();
105
- this.hoverTarget = undefined;
106
- }
107
- unRenderHover() {
108
- this.hoverHost.remove();
109
- this.hoverHost.replaceChildren();
110
- }
111
- };
112
- StatusBarHoverManager.hostClassName = 'theia-status-bar-hover';
113
- StatusBarHoverManager.styleSheetId = 'theia-status-bar-hover-style';
114
- __decorate([
115
- (0, inversify_1.inject)(preferences_1.PreferenceService),
116
- __metadata("design:type", Object)
117
- ], StatusBarHoverManager.prototype, "preferences", void 0);
118
- __decorate([
119
- (0, inversify_1.inject)(markdown_renderer_1.MarkdownRendererFactory),
120
- __metadata("design:type", Function)
121
- ], StatusBarHoverManager.prototype, "markdownRendererFactory", void 0);
122
- StatusBarHoverManager = StatusBarHoverManager_1 = __decorate([
123
- (0, inversify_1.injectable)()
124
- ], StatusBarHoverManager);
125
- exports.StatusBarHoverManager = StatusBarHoverManager;
126
- //# sourceMappingURL=status-bar-hover-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status-bar-hover-manager.js","sourceRoot":"","sources":["../../../src/browser/status-bar/status-bar-hover-manager.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6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AED,WAAW;;QACP,MAAA,IAAI,CAAC,cAAc,0CAAE,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IACjC,CAAC;IAES,aAAa;QACnB,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AAxFoB,mCAAa,GAAG,wBAAyB,CAAA;AACzC,kCAAY,GAAG,8BAA+B,CAAA;AACpC;IAA1B,IAAA,kBAAM,EAAC,+BAAiB,CAAC;;0DAAmD;AAC5C;IAAhC,IAAA,kBAAM,EAAC,2CAAuB,CAAC;;sEAAqE;AAJ5F,qBAAqB;IADjC,IAAA,sBAAU,GAAE;GACA,qBAAqB,CAyFjC;AAzFY,sDAAqB"}
@@ -1,113 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { inject, injectable } from 'inversify';
18
- import { Disposable, DisposableCollection, disposableTimeout, isOSX } from '../../common';
19
- import { MarkdownString } from '../../common/markdown-rendering/markdown-string';
20
- import { MarkdownRenderer, MarkdownRendererFactory } from '../markdown-rendering/markdown-renderer';
21
- import { PreferenceService } from '../preferences';
22
-
23
- @injectable()
24
- export class StatusBarHoverManager {
25
- protected static hostClassName = 'theia-status-bar-hover';
26
- protected static styleSheetId = 'theia-status-bar-hover-style';
27
- @inject(PreferenceService) protected readonly preferences: PreferenceService;
28
- @inject(MarkdownRendererFactory) protected readonly markdownRendererFactory: MarkdownRendererFactory;
29
-
30
- protected _markdownRenderer: MarkdownRenderer | undefined;
31
- protected get markdownRenderer(): MarkdownRenderer {
32
- this._markdownRenderer ||= this.markdownRendererFactory();
33
- return this._markdownRenderer;
34
- }
35
-
36
- protected _hoverHost: HTMLElement | undefined;
37
- protected get hoverHost(): HTMLElement {
38
- if (!this._hoverHost) {
39
- this._hoverHost = document.createElement('div');
40
- this._hoverHost.classList.add(StatusBarHoverManager.hostClassName);
41
- this._hoverHost.style.position = 'absolute';
42
- }
43
- return this._hoverHost;
44
- }
45
- protected pendingTimeout: Disposable | undefined;
46
- protected hoverTarget: HTMLElement | undefined;
47
- protected lastHidHover = Date.now();
48
- protected readonly disposeOnHide = new DisposableCollection();
49
-
50
- requestHover(hover: string | MarkdownString | HTMLElement, target: HTMLElement): void {
51
- if (target !== this.hoverTarget) {
52
- this.cancelHover();
53
- this.pendingTimeout = disposableTimeout(() => this.renderHover(hover, target), this.getHoverDelay());
54
- }
55
- }
56
-
57
- protected getHoverDelay(): number {
58
- return Date.now() - this.lastHidHover < 200
59
- ? 0
60
- : this.preferences.get('workbench.hover.delay', isOSX ? 1500 : 500);
61
- }
62
-
63
- protected async renderHover(hover: string | MarkdownString | HTMLElement, target: HTMLElement): Promise<void> {
64
- const host = this.hoverHost;
65
- this.hoverTarget = target;
66
- if (hover instanceof HTMLElement) {
67
- host.appendChild(hover);
68
- } else if (typeof hover === 'string') {
69
- host.textContent = hover;
70
- } else {
71
- const content = this.markdownRenderer.render(hover);
72
- this.disposeOnHide.push(content);
73
- host.appendChild(content.element);
74
- }
75
- this.disposeOnHide.push({ dispose: () => this.lastHidHover = Date.now() });
76
- document.body.append(host);
77
- await new Promise(resolve => requestAnimationFrame(resolve)); // Allow the browser to size the host
78
- const targetDimensions = target.getBoundingClientRect();
79
- const targetMiddle = targetDimensions.left + (targetDimensions.width / 2);
80
- const hostDimensions = host.getBoundingClientRect();
81
- const documentWidth = document.body.getBoundingClientRect().width;
82
- const middleAlignment = targetMiddle - (hostDimensions.width / 2);
83
- const furthestRight = Math.min(documentWidth - hostDimensions.width, middleAlignment);
84
- const left = Math.max(0, furthestRight);
85
- host.style.setProperty('--theia-status-bar-hover-before-left', `${targetMiddle - left - 5}px`); // Centered on the status bar element.
86
- host.style.bottom = `${targetDimensions.height + 5}px`;
87
- host.style.left = `${left}px`;
88
-
89
- this.listenForMouseOut();
90
- }
91
-
92
- protected listenForMouseOut(): void {
93
- const handleMouseMove = (e: MouseEvent) => {
94
- if (e.target instanceof Node && !this.hoverHost.contains(e.target) && !this.hoverTarget?.contains(e.target)) {
95
- this.cancelHover();
96
- }
97
- };
98
- document.addEventListener('mousemove', handleMouseMove);
99
- this.disposeOnHide.push({ dispose: () => document.removeEventListener('mousemove', handleMouseMove) });
100
- }
101
-
102
- cancelHover(): void {
103
- this.pendingTimeout?.dispose();
104
- this.unRenderHover();
105
- this.disposeOnHide.dispose();
106
- this.hoverTarget = undefined;
107
- }
108
-
109
- protected unRenderHover(): void {
110
- this.hoverHost.remove();
111
- this.hoverHost.replaceChildren();
112
- }
113
- }