@theia/mini-browser 1.45.1 → 1.46.0-next.72

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 (63) hide show
  1. package/README.md +45 -45
  2. package/lib/browser/environment/mini-browser-environment-module.d.ts +3 -3
  3. package/lib/browser/environment/mini-browser-environment-module.js +24 -24
  4. package/lib/browser/environment/mini-browser-environment.d.ts +25 -25
  5. package/lib/browser/environment/mini-browser-environment.js +95 -95
  6. package/lib/browser/environment/mini-browser-environment.js.map +1 -1
  7. package/lib/browser/location-mapper-service.d.ts +58 -58
  8. package/lib/browser/location-mapper-service.js +140 -140
  9. package/lib/browser/mini-browser-content-style.d.ts +17 -17
  10. package/lib/browser/mini-browser-content-style.js +36 -36
  11. package/lib/browser/mini-browser-content.d.ts +177 -177
  12. package/lib/browser/mini-browser-content.js +554 -554
  13. package/lib/browser/mini-browser-frontend-module.d.ts +4 -4
  14. package/lib/browser/mini-browser-frontend-module.js +70 -70
  15. package/lib/browser/mini-browser-frontend-security-warnings.d.ts +11 -11
  16. package/lib/browser/mini-browser-frontend-security-warnings.js +73 -73
  17. package/lib/browser/mini-browser-open-handler.d.ts +76 -76
  18. package/lib/browser/mini-browser-open-handler.js +292 -292
  19. package/lib/browser/mini-browser.d.ts +25 -25
  20. package/lib/browser/mini-browser.js +118 -118
  21. package/lib/common/mini-browser-endpoint.d.ts +12 -12
  22. package/lib/common/mini-browser-endpoint.js +31 -31
  23. package/lib/common/mini-browser-service.d.ts +14 -14
  24. package/lib/common/mini-browser-service.js +20 -20
  25. package/lib/electron-browser/environment/electron-mini-browser-environment-module.d.ts +3 -3
  26. package/lib/electron-browser/environment/electron-mini-browser-environment-module.js +25 -25
  27. package/lib/electron-browser/environment/electron-mini-browser-environment.d.ts +9 -9
  28. package/lib/electron-browser/environment/electron-mini-browser-environment.js +60 -60
  29. package/lib/electron-main/mini-browser-electron-main-contribution.d.ts +12 -12
  30. package/lib/electron-main/mini-browser-electron-main-contribution.js +54 -54
  31. package/lib/node/mini-browser-backend-module.d.ts +3 -3
  32. package/lib/node/mini-browser-backend-module.js +41 -41
  33. package/lib/node/mini-browser-backend-security-warnings.d.ts +5 -5
  34. package/lib/node/mini-browser-backend-security-warnings.js +51 -51
  35. package/lib/node/mini-browser-endpoint.d.ts +97 -97
  36. package/lib/node/mini-browser-endpoint.js +268 -268
  37. package/lib/node/mini-browser-endpoint.js.map +1 -1
  38. package/lib/node/mini-browser-ws-validator.d.ts +12 -12
  39. package/lib/node/mini-browser-ws-validator.js +69 -69
  40. package/lib/package.spec.js +18 -18
  41. package/package.json +5 -6
  42. package/src/browser/environment/mini-browser-environment-module.ts +24 -24
  43. package/src/browser/environment/mini-browser-environment.ts +87 -87
  44. package/src/browser/location-mapper-service.ts +150 -150
  45. package/src/browser/mini-browser-content-style.ts +32 -32
  46. package/src/browser/mini-browser-content.ts +630 -630
  47. package/src/browser/mini-browser-frontend-module.ts +86 -86
  48. package/src/browser/mini-browser-frontend-security-warnings.ts +59 -59
  49. package/src/browser/mini-browser-open-handler.ts +312 -312
  50. package/src/browser/mini-browser.ts +110 -110
  51. package/src/browser/pdfobject.d.ts +99 -99
  52. package/src/browser/style/index.css +157 -157
  53. package/src/browser/style/mini-browser.svg +17 -17
  54. package/src/common/mini-browser-endpoint.ts +28 -28
  55. package/src/common/mini-browser-service.ts +29 -29
  56. package/src/electron-browser/environment/electron-mini-browser-environment-module.ts +25 -25
  57. package/src/electron-browser/environment/electron-mini-browser-environment.ts +53 -53
  58. package/src/electron-main/mini-browser-electron-main-contribution.ts +42 -42
  59. package/src/node/mini-browser-backend-module.ts +41 -41
  60. package/src/node/mini-browser-backend-security-warnings.ts +45 -45
  61. package/src/node/mini-browser-endpoint.ts +315 -315
  62. package/src/node/mini-browser-ws-validator.ts +56 -56
  63. package/src/package.spec.ts +21 -21
@@ -1,293 +1,293 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2018 TypeFox 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-only 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 MiniBrowserOpenHandler_1;
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.MiniBrowserOpenHandler = exports.MiniBrowserCommands = void 0;
29
- const inversify_1 = require("@theia/core/shared/inversify");
30
- const uri_1 = require("@theia/core/lib/common/uri");
31
- const browser_1 = require("@theia/core/lib/browser");
32
- const command_1 = require("@theia/core/lib/common/command");
33
- const navigatable_1 = require("@theia/core/lib/browser/navigatable");
34
- const opener_service_1 = require("@theia/core/lib/browser/opener-service");
35
- const label_provider_1 = require("@theia/core/lib/browser/label-provider");
36
- const mini_browser_service_1 = require("../common/mini-browser-service");
37
- const mini_browser_1 = require("./mini-browser");
38
- const location_mapper_service_1 = require("./location-mapper-service");
39
- const nls_1 = require("@theia/core/lib/common/nls");
40
- var MiniBrowserCommands;
41
- (function (MiniBrowserCommands) {
42
- MiniBrowserCommands.PREVIEW_CATEGORY = 'Preview';
43
- MiniBrowserCommands.PREVIEW_CATEGORY_KEY = nls_1.nls.getDefaultKey(MiniBrowserCommands.PREVIEW_CATEGORY);
44
- MiniBrowserCommands.PREVIEW = command_1.Command.toLocalizedCommand({
45
- id: 'mini-browser.preview',
46
- label: 'Open Preview',
47
- iconClass: (0, browser_1.codicon)('open-preview')
48
- }, 'vscode.markdown-language-features/package/markdown.preview.title');
49
- MiniBrowserCommands.OPEN_SOURCE = {
50
- id: 'mini-browser.open.source',
51
- iconClass: (0, browser_1.codicon)('go-to-file')
52
- };
53
- MiniBrowserCommands.OPEN_URL = command_1.Command.toDefaultLocalizedCommand({
54
- id: 'mini-browser.openUrl',
55
- category: MiniBrowserCommands.PREVIEW_CATEGORY,
56
- label: 'Open URL'
57
- });
58
- })(MiniBrowserCommands = exports.MiniBrowserCommands || (exports.MiniBrowserCommands = {}));
59
- let MiniBrowserOpenHandler = MiniBrowserOpenHandler_1 = class MiniBrowserOpenHandler extends navigatable_1.NavigatableWidgetOpenHandler {
60
- constructor() {
61
- super(...arguments);
62
- /**
63
- * Instead of going to the backend with each file URI to ask whether it can handle the current file or not,
64
- * we have this map of extension and priority pairs that we populate at application startup.
65
- * The real advantage of this approach is the following: [Phosphor cannot run async code when invoking `isEnabled`/`isVisible`
66
- * for the command handlers](https://github.com/eclipse-theia/theia/issues/1958#issuecomment-392829371)
67
- * so the menu item would be always visible for the user even if the file type cannot be handled eventually.
68
- * Hopefully, we could get rid of this hack once we have migrated the existing Phosphor code to [React](https://github.com/eclipse-theia/theia/issues/1915).
69
- */
70
- this.supportedExtensions = new Map();
71
- this.id = mini_browser_1.MiniBrowser.ID;
72
- this.label = nls_1.nls.localize(MiniBrowserCommands.PREVIEW_CATEGORY_KEY, MiniBrowserCommands.PREVIEW_CATEGORY);
73
- }
74
- onStart() {
75
- this.miniBrowserService.supportedFileExtensions().then(entries => {
76
- entries.forEach(entry => {
77
- const { extension, priority } = entry;
78
- this.supportedExtensions.set(extension, priority);
79
- });
80
- });
81
- }
82
- canHandle(uri, options) {
83
- // It does not guard against directories. For instance, a folder with this name: `Hahahah.html`.
84
- // We could check with the FS, but then, this method would become async again.
85
- const extension = uri.toString().split('.').pop();
86
- if (!extension) {
87
- return 0;
88
- }
89
- if ((options === null || options === void 0 ? void 0 : options.openFor) === 'source') {
90
- return -100;
91
- }
92
- else if ((options === null || options === void 0 ? void 0 : options.openFor) === 'preview') {
93
- return 200; // higher than that of the editor.
94
- }
95
- else {
96
- return this.supportedExtensions.get(extension.toLocaleLowerCase()) || 0;
97
- }
98
- }
99
- async open(uri, options) {
100
- const widget = await super.open(uri, options);
101
- const area = this.shell.getAreaFor(widget);
102
- if (area === 'right' || area === 'left') {
103
- const panelLayout = area === 'right' ? this.shell.getLayoutData().rightPanel : this.shell.getLayoutData().leftPanel;
104
- const minSize = this.shell.mainPanel.node.offsetWidth / 2;
105
- if (panelLayout && panelLayout.size && panelLayout.size <= minSize) {
106
- requestAnimationFrame(() => this.shell.resize(minSize, area));
107
- }
108
- }
109
- return widget;
110
- }
111
- async getOrCreateWidget(uri, options) {
112
- const props = await this.options(uri, options);
113
- const widget = await super.getOrCreateWidget(uri, props);
114
- widget.setProps(props);
115
- return widget;
116
- }
117
- async options(uri, options) {
118
- // Get the default options.
119
- let result = await this.defaultOptions();
120
- if (uri) {
121
- // Decorate it with a few properties inferred from the URI.
122
- const startPage = uri.toString(true);
123
- const name = this.labelProvider.getName(uri);
124
- const iconClass = `${this.labelProvider.getIcon(uri)} file-icon`;
125
- // The background has to be reset to white only for "real" web-pages but not for images, for instance.
126
- const resetBackground = await this.resetBackground(uri);
127
- result = {
128
- ...result,
129
- startPage,
130
- name,
131
- iconClass,
132
- // Make sure the toolbar is not visible. We have the `iframe.src` anyway.
133
- toolbar: 'hide',
134
- resetBackground
135
- };
136
- }
137
- if (options) {
138
- // Explicit options overrule everything.
139
- result = {
140
- ...result,
141
- ...options
142
- };
143
- }
144
- return result;
145
- }
146
- resetBackground(uri) {
147
- const { scheme } = uri;
148
- const uriStr = uri.toString();
149
- return scheme === 'http'
150
- || scheme === 'https'
151
- || (scheme === 'file'
152
- && (uriStr.endsWith('html') || uriStr.endsWith('.htm')));
153
- }
154
- async defaultOptions() {
155
- return {
156
- mode: 'activate',
157
- widgetOptions: { area: 'main' },
158
- sandbox: mini_browser_1.MiniBrowserProps.SandboxOptions.DEFAULT,
159
- toolbar: 'show'
160
- };
161
- }
162
- registerCommands(commands) {
163
- commands.registerCommand(MiniBrowserCommands.PREVIEW, {
164
- execute: widget => this.preview(widget),
165
- isEnabled: widget => this.canPreviewWidget(widget),
166
- isVisible: widget => this.canPreviewWidget(widget)
167
- });
168
- commands.registerCommand(MiniBrowserCommands.OPEN_SOURCE, {
169
- execute: widget => this.openSource(widget),
170
- isEnabled: widget => !!this.getSourceUri(widget),
171
- isVisible: widget => !!this.getSourceUri(widget)
172
- });
173
- commands.registerCommand(MiniBrowserCommands.OPEN_URL, {
174
- execute: (arg) => this.openUrl(arg)
175
- });
176
- }
177
- registerMenus(menus) {
178
- menus.registerMenuAction(['editor_context_menu', 'navigation'], {
179
- commandId: MiniBrowserCommands.PREVIEW.id
180
- });
181
- }
182
- registerToolbarItems(toolbar) {
183
- toolbar.registerItem({
184
- id: MiniBrowserCommands.PREVIEW.id,
185
- command: MiniBrowserCommands.PREVIEW.id,
186
- tooltip: nls_1.nls.localize('vscode.markdown-language-features/package/markdown.previewSide.title', 'Open Preview to the Side')
187
- });
188
- toolbar.registerItem({
189
- id: MiniBrowserCommands.OPEN_SOURCE.id,
190
- command: MiniBrowserCommands.OPEN_SOURCE.id,
191
- tooltip: nls_1.nls.localize('vscode.markdown-language-features/package/markdown.showSource.title', 'Open Source')
192
- });
193
- }
194
- canPreviewWidget(widget) {
195
- const uri = this.getUriToPreview(widget);
196
- return !!uri && !!this.canHandle(uri);
197
- }
198
- getUriToPreview(widget) {
199
- const current = this.getWidgetToPreview(widget);
200
- return current && current.getResourceUri();
201
- }
202
- getWidgetToPreview(widget) {
203
- const current = widget ? widget : this.shell.currentWidget;
204
- // MiniBrowser is NavigatableWidget and should be excluded from widgets to preview
205
- return !(current instanceof mini_browser_1.MiniBrowser) && navigatable_1.NavigatableWidget.is(current) && current || undefined;
206
- }
207
- async preview(widget) {
208
- const ref = this.getWidgetToPreview(widget);
209
- if (!ref) {
210
- return;
211
- }
212
- const uri = ref.getResourceUri();
213
- if (!uri) {
214
- return;
215
- }
216
- await this.open(uri, {
217
- mode: 'reveal',
218
- widgetOptions: { ref, mode: 'open-to-right' },
219
- openFor: 'preview'
220
- });
221
- }
222
- async openSource(ref) {
223
- const uri = this.getSourceUri(ref);
224
- if (uri) {
225
- await (0, opener_service_1.open)(this.openerService, uri, {
226
- widgetOptions: { ref, mode: 'tab-after' },
227
- openFor: 'source'
228
- });
229
- }
230
- }
231
- getSourceUri(ref) {
232
- const uri = ref instanceof mini_browser_1.MiniBrowser && ref.getResourceUri() || undefined;
233
- if (!uri || uri.scheme === 'http' || uri.scheme === 'https' || uri.isEqual(MiniBrowserOpenHandler_1.PREVIEW_URI)) {
234
- return undefined;
235
- }
236
- return uri;
237
- }
238
- async openUrl(arg) {
239
- var _a;
240
- const url = arg ? arg : await ((_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.input({
241
- prompt: nls_1.nls.localizeByDefault('URL to open'),
242
- placeHolder: nls_1.nls.localize('theia/mini-browser/typeUrl', 'Type a URL')
243
- }));
244
- if (url) {
245
- await this.openPreview(url);
246
- }
247
- }
248
- async openPreview(startPage) {
249
- const props = await this.getOpenPreviewProps(await this.locationMapperService.map(startPage));
250
- return this.open(MiniBrowserOpenHandler_1.PREVIEW_URI, props);
251
- }
252
- async getOpenPreviewProps(startPage) {
253
- const resetBackground = await this.resetBackground(new uri_1.default(startPage));
254
- return {
255
- name: nls_1.nls.localize(MiniBrowserCommands.PREVIEW_CATEGORY_KEY, MiniBrowserCommands.PREVIEW_CATEGORY),
256
- startPage,
257
- toolbar: 'read-only',
258
- widgetOptions: {
259
- area: 'right'
260
- },
261
- resetBackground,
262
- iconClass: (0, browser_1.codicon)('preview'),
263
- openFor: 'preview'
264
- };
265
- }
266
- };
267
- MiniBrowserOpenHandler.PREVIEW_URI = new uri_1.default().withScheme('__minibrowser__preview__');
268
- __decorate([
269
- (0, inversify_1.inject)(opener_service_1.OpenerService),
270
- __metadata("design:type", Object)
271
- ], MiniBrowserOpenHandler.prototype, "openerService", void 0);
272
- __decorate([
273
- (0, inversify_1.inject)(label_provider_1.LabelProvider),
274
- __metadata("design:type", label_provider_1.LabelProvider)
275
- ], MiniBrowserOpenHandler.prototype, "labelProvider", void 0);
276
- __decorate([
277
- (0, inversify_1.inject)(browser_1.QuickInputService),
278
- (0, inversify_1.optional)(),
279
- __metadata("design:type", Object)
280
- ], MiniBrowserOpenHandler.prototype, "quickInputService", void 0);
281
- __decorate([
282
- (0, inversify_1.inject)(mini_browser_service_1.MiniBrowserService),
283
- __metadata("design:type", Object)
284
- ], MiniBrowserOpenHandler.prototype, "miniBrowserService", void 0);
285
- __decorate([
286
- (0, inversify_1.inject)(location_mapper_service_1.LocationMapperService),
287
- __metadata("design:type", location_mapper_service_1.LocationMapperService)
288
- ], MiniBrowserOpenHandler.prototype, "locationMapperService", void 0);
289
- MiniBrowserOpenHandler = MiniBrowserOpenHandler_1 = __decorate([
290
- (0, inversify_1.injectable)()
291
- ], MiniBrowserOpenHandler);
292
- exports.MiniBrowserOpenHandler = MiniBrowserOpenHandler;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2018 TypeFox 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-only 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 MiniBrowserOpenHandler_1;
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.MiniBrowserOpenHandler = exports.MiniBrowserCommands = void 0;
29
+ const inversify_1 = require("@theia/core/shared/inversify");
30
+ const uri_1 = require("@theia/core/lib/common/uri");
31
+ const browser_1 = require("@theia/core/lib/browser");
32
+ const command_1 = require("@theia/core/lib/common/command");
33
+ const navigatable_1 = require("@theia/core/lib/browser/navigatable");
34
+ const opener_service_1 = require("@theia/core/lib/browser/opener-service");
35
+ const label_provider_1 = require("@theia/core/lib/browser/label-provider");
36
+ const mini_browser_service_1 = require("../common/mini-browser-service");
37
+ const mini_browser_1 = require("./mini-browser");
38
+ const location_mapper_service_1 = require("./location-mapper-service");
39
+ const nls_1 = require("@theia/core/lib/common/nls");
40
+ var MiniBrowserCommands;
41
+ (function (MiniBrowserCommands) {
42
+ MiniBrowserCommands.PREVIEW_CATEGORY = 'Preview';
43
+ MiniBrowserCommands.PREVIEW_CATEGORY_KEY = nls_1.nls.getDefaultKey(MiniBrowserCommands.PREVIEW_CATEGORY);
44
+ MiniBrowserCommands.PREVIEW = command_1.Command.toLocalizedCommand({
45
+ id: 'mini-browser.preview',
46
+ label: 'Open Preview',
47
+ iconClass: (0, browser_1.codicon)('open-preview')
48
+ }, 'vscode.markdown-language-features/package/markdown.preview.title');
49
+ MiniBrowserCommands.OPEN_SOURCE = {
50
+ id: 'mini-browser.open.source',
51
+ iconClass: (0, browser_1.codicon)('go-to-file')
52
+ };
53
+ MiniBrowserCommands.OPEN_URL = command_1.Command.toDefaultLocalizedCommand({
54
+ id: 'mini-browser.openUrl',
55
+ category: MiniBrowserCommands.PREVIEW_CATEGORY,
56
+ label: 'Open URL'
57
+ });
58
+ })(MiniBrowserCommands = exports.MiniBrowserCommands || (exports.MiniBrowserCommands = {}));
59
+ let MiniBrowserOpenHandler = MiniBrowserOpenHandler_1 = class MiniBrowserOpenHandler extends navigatable_1.NavigatableWidgetOpenHandler {
60
+ constructor() {
61
+ super(...arguments);
62
+ /**
63
+ * Instead of going to the backend with each file URI to ask whether it can handle the current file or not,
64
+ * we have this map of extension and priority pairs that we populate at application startup.
65
+ * The real advantage of this approach is the following: [Phosphor cannot run async code when invoking `isEnabled`/`isVisible`
66
+ * for the command handlers](https://github.com/eclipse-theia/theia/issues/1958#issuecomment-392829371)
67
+ * so the menu item would be always visible for the user even if the file type cannot be handled eventually.
68
+ * Hopefully, we could get rid of this hack once we have migrated the existing Phosphor code to [React](https://github.com/eclipse-theia/theia/issues/1915).
69
+ */
70
+ this.supportedExtensions = new Map();
71
+ this.id = mini_browser_1.MiniBrowser.ID;
72
+ this.label = nls_1.nls.localize(MiniBrowserCommands.PREVIEW_CATEGORY_KEY, MiniBrowserCommands.PREVIEW_CATEGORY);
73
+ }
74
+ onStart() {
75
+ this.miniBrowserService.supportedFileExtensions().then(entries => {
76
+ entries.forEach(entry => {
77
+ const { extension, priority } = entry;
78
+ this.supportedExtensions.set(extension, priority);
79
+ });
80
+ });
81
+ }
82
+ canHandle(uri, options) {
83
+ // It does not guard against directories. For instance, a folder with this name: `Hahahah.html`.
84
+ // We could check with the FS, but then, this method would become async again.
85
+ const extension = uri.toString().split('.').pop();
86
+ if (!extension) {
87
+ return 0;
88
+ }
89
+ if ((options === null || options === void 0 ? void 0 : options.openFor) === 'source') {
90
+ return -100;
91
+ }
92
+ else if ((options === null || options === void 0 ? void 0 : options.openFor) === 'preview') {
93
+ return 200; // higher than that of the editor.
94
+ }
95
+ else {
96
+ return this.supportedExtensions.get(extension.toLocaleLowerCase()) || 0;
97
+ }
98
+ }
99
+ async open(uri, options) {
100
+ const widget = await super.open(uri, options);
101
+ const area = this.shell.getAreaFor(widget);
102
+ if (area === 'right' || area === 'left') {
103
+ const panelLayout = area === 'right' ? this.shell.getLayoutData().rightPanel : this.shell.getLayoutData().leftPanel;
104
+ const minSize = this.shell.mainPanel.node.offsetWidth / 2;
105
+ if (panelLayout && panelLayout.size && panelLayout.size <= minSize) {
106
+ requestAnimationFrame(() => this.shell.resize(minSize, area));
107
+ }
108
+ }
109
+ return widget;
110
+ }
111
+ async getOrCreateWidget(uri, options) {
112
+ const props = await this.options(uri, options);
113
+ const widget = await super.getOrCreateWidget(uri, props);
114
+ widget.setProps(props);
115
+ return widget;
116
+ }
117
+ async options(uri, options) {
118
+ // Get the default options.
119
+ let result = await this.defaultOptions();
120
+ if (uri) {
121
+ // Decorate it with a few properties inferred from the URI.
122
+ const startPage = uri.toString(true);
123
+ const name = this.labelProvider.getName(uri);
124
+ const iconClass = `${this.labelProvider.getIcon(uri)} file-icon`;
125
+ // The background has to be reset to white only for "real" web-pages but not for images, for instance.
126
+ const resetBackground = await this.resetBackground(uri);
127
+ result = {
128
+ ...result,
129
+ startPage,
130
+ name,
131
+ iconClass,
132
+ // Make sure the toolbar is not visible. We have the `iframe.src` anyway.
133
+ toolbar: 'hide',
134
+ resetBackground
135
+ };
136
+ }
137
+ if (options) {
138
+ // Explicit options overrule everything.
139
+ result = {
140
+ ...result,
141
+ ...options
142
+ };
143
+ }
144
+ return result;
145
+ }
146
+ resetBackground(uri) {
147
+ const { scheme } = uri;
148
+ const uriStr = uri.toString();
149
+ return scheme === 'http'
150
+ || scheme === 'https'
151
+ || (scheme === 'file'
152
+ && (uriStr.endsWith('html') || uriStr.endsWith('.htm')));
153
+ }
154
+ async defaultOptions() {
155
+ return {
156
+ mode: 'activate',
157
+ widgetOptions: { area: 'main' },
158
+ sandbox: mini_browser_1.MiniBrowserProps.SandboxOptions.DEFAULT,
159
+ toolbar: 'show'
160
+ };
161
+ }
162
+ registerCommands(commands) {
163
+ commands.registerCommand(MiniBrowserCommands.PREVIEW, {
164
+ execute: widget => this.preview(widget),
165
+ isEnabled: widget => this.canPreviewWidget(widget),
166
+ isVisible: widget => this.canPreviewWidget(widget)
167
+ });
168
+ commands.registerCommand(MiniBrowserCommands.OPEN_SOURCE, {
169
+ execute: widget => this.openSource(widget),
170
+ isEnabled: widget => !!this.getSourceUri(widget),
171
+ isVisible: widget => !!this.getSourceUri(widget)
172
+ });
173
+ commands.registerCommand(MiniBrowserCommands.OPEN_URL, {
174
+ execute: (arg) => this.openUrl(arg)
175
+ });
176
+ }
177
+ registerMenus(menus) {
178
+ menus.registerMenuAction(['editor_context_menu', 'navigation'], {
179
+ commandId: MiniBrowserCommands.PREVIEW.id
180
+ });
181
+ }
182
+ registerToolbarItems(toolbar) {
183
+ toolbar.registerItem({
184
+ id: MiniBrowserCommands.PREVIEW.id,
185
+ command: MiniBrowserCommands.PREVIEW.id,
186
+ tooltip: nls_1.nls.localize('vscode.markdown-language-features/package/markdown.previewSide.title', 'Open Preview to the Side')
187
+ });
188
+ toolbar.registerItem({
189
+ id: MiniBrowserCommands.OPEN_SOURCE.id,
190
+ command: MiniBrowserCommands.OPEN_SOURCE.id,
191
+ tooltip: nls_1.nls.localize('vscode.markdown-language-features/package/markdown.showSource.title', 'Open Source')
192
+ });
193
+ }
194
+ canPreviewWidget(widget) {
195
+ const uri = this.getUriToPreview(widget);
196
+ return !!uri && !!this.canHandle(uri);
197
+ }
198
+ getUriToPreview(widget) {
199
+ const current = this.getWidgetToPreview(widget);
200
+ return current && current.getResourceUri();
201
+ }
202
+ getWidgetToPreview(widget) {
203
+ const current = widget ? widget : this.shell.currentWidget;
204
+ // MiniBrowser is NavigatableWidget and should be excluded from widgets to preview
205
+ return !(current instanceof mini_browser_1.MiniBrowser) && navigatable_1.NavigatableWidget.is(current) && current || undefined;
206
+ }
207
+ async preview(widget) {
208
+ const ref = this.getWidgetToPreview(widget);
209
+ if (!ref) {
210
+ return;
211
+ }
212
+ const uri = ref.getResourceUri();
213
+ if (!uri) {
214
+ return;
215
+ }
216
+ await this.open(uri, {
217
+ mode: 'reveal',
218
+ widgetOptions: { ref, mode: 'open-to-right' },
219
+ openFor: 'preview'
220
+ });
221
+ }
222
+ async openSource(ref) {
223
+ const uri = this.getSourceUri(ref);
224
+ if (uri) {
225
+ await (0, opener_service_1.open)(this.openerService, uri, {
226
+ widgetOptions: { ref, mode: 'tab-after' },
227
+ openFor: 'source'
228
+ });
229
+ }
230
+ }
231
+ getSourceUri(ref) {
232
+ const uri = ref instanceof mini_browser_1.MiniBrowser && ref.getResourceUri() || undefined;
233
+ if (!uri || uri.scheme === 'http' || uri.scheme === 'https' || uri.isEqual(MiniBrowserOpenHandler_1.PREVIEW_URI)) {
234
+ return undefined;
235
+ }
236
+ return uri;
237
+ }
238
+ async openUrl(arg) {
239
+ var _a;
240
+ const url = arg ? arg : await ((_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.input({
241
+ prompt: nls_1.nls.localizeByDefault('URL to open'),
242
+ placeHolder: nls_1.nls.localize('theia/mini-browser/typeUrl', 'Type a URL')
243
+ }));
244
+ if (url) {
245
+ await this.openPreview(url);
246
+ }
247
+ }
248
+ async openPreview(startPage) {
249
+ const props = await this.getOpenPreviewProps(await this.locationMapperService.map(startPage));
250
+ return this.open(MiniBrowserOpenHandler_1.PREVIEW_URI, props);
251
+ }
252
+ async getOpenPreviewProps(startPage) {
253
+ const resetBackground = await this.resetBackground(new uri_1.default(startPage));
254
+ return {
255
+ name: nls_1.nls.localize(MiniBrowserCommands.PREVIEW_CATEGORY_KEY, MiniBrowserCommands.PREVIEW_CATEGORY),
256
+ startPage,
257
+ toolbar: 'read-only',
258
+ widgetOptions: {
259
+ area: 'right'
260
+ },
261
+ resetBackground,
262
+ iconClass: (0, browser_1.codicon)('preview'),
263
+ openFor: 'preview'
264
+ };
265
+ }
266
+ };
267
+ MiniBrowserOpenHandler.PREVIEW_URI = new uri_1.default().withScheme('__minibrowser__preview__');
268
+ __decorate([
269
+ (0, inversify_1.inject)(opener_service_1.OpenerService),
270
+ __metadata("design:type", Object)
271
+ ], MiniBrowserOpenHandler.prototype, "openerService", void 0);
272
+ __decorate([
273
+ (0, inversify_1.inject)(label_provider_1.LabelProvider),
274
+ __metadata("design:type", label_provider_1.LabelProvider)
275
+ ], MiniBrowserOpenHandler.prototype, "labelProvider", void 0);
276
+ __decorate([
277
+ (0, inversify_1.inject)(browser_1.QuickInputService),
278
+ (0, inversify_1.optional)(),
279
+ __metadata("design:type", Object)
280
+ ], MiniBrowserOpenHandler.prototype, "quickInputService", void 0);
281
+ __decorate([
282
+ (0, inversify_1.inject)(mini_browser_service_1.MiniBrowserService),
283
+ __metadata("design:type", Object)
284
+ ], MiniBrowserOpenHandler.prototype, "miniBrowserService", void 0);
285
+ __decorate([
286
+ (0, inversify_1.inject)(location_mapper_service_1.LocationMapperService),
287
+ __metadata("design:type", location_mapper_service_1.LocationMapperService)
288
+ ], MiniBrowserOpenHandler.prototype, "locationMapperService", void 0);
289
+ MiniBrowserOpenHandler = MiniBrowserOpenHandler_1 = __decorate([
290
+ (0, inversify_1.injectable)()
291
+ ], MiniBrowserOpenHandler);
292
+ exports.MiniBrowserOpenHandler = MiniBrowserOpenHandler;
293
293
  //# sourceMappingURL=mini-browser-open-handler.js.map
@@ -1,26 +1,26 @@
1
- import { Message } from '@theia/core/shared/@phosphor/messaging';
2
- import URI from '@theia/core/lib/common/uri';
3
- import { NavigatableWidget, StatefulWidget } from '@theia/core/lib/browser';
4
- import { DisposableCollection } from '@theia/core/lib/common/disposable';
5
- import { BaseWidget } from '@theia/core/lib/browser/widgets/widget';
6
- import { MiniBrowserProps, MiniBrowserContentFactory } from './mini-browser-content';
7
- export { MiniBrowserProps };
8
- export declare class MiniBrowserOptions {
9
- uri: URI;
10
- }
11
- export declare class MiniBrowser extends BaseWidget implements NavigatableWidget, StatefulWidget {
12
- static ID: string;
13
- static ICON: string;
14
- protected readonly options: MiniBrowserOptions;
15
- protected readonly createContent: MiniBrowserContentFactory;
16
- protected init(): void;
17
- getResourceUri(): URI | undefined;
18
- createMoveToUri(resourceUri: URI): URI | undefined;
19
- protected props: MiniBrowserProps | undefined;
20
- protected readonly toDisposeOnProps: DisposableCollection;
21
- setProps(raw: MiniBrowserProps): void;
22
- protected onActivateRequest(msg: Message): void;
23
- storeState(): object;
24
- restoreState(oldState: object): void;
25
- }
1
+ import { Message } from '@theia/core/shared/@phosphor/messaging';
2
+ import URI from '@theia/core/lib/common/uri';
3
+ import { NavigatableWidget, StatefulWidget } from '@theia/core/lib/browser';
4
+ import { DisposableCollection } from '@theia/core/lib/common/disposable';
5
+ import { BaseWidget } from '@theia/core/lib/browser/widgets/widget';
6
+ import { MiniBrowserProps, MiniBrowserContentFactory } from './mini-browser-content';
7
+ export { MiniBrowserProps };
8
+ export declare class MiniBrowserOptions {
9
+ uri: URI;
10
+ }
11
+ export declare class MiniBrowser extends BaseWidget implements NavigatableWidget, StatefulWidget {
12
+ static ID: string;
13
+ static ICON: string;
14
+ protected readonly options: MiniBrowserOptions;
15
+ protected readonly createContent: MiniBrowserContentFactory;
16
+ protected init(): void;
17
+ getResourceUri(): URI | undefined;
18
+ createMoveToUri(resourceUri: URI): URI | undefined;
19
+ protected props: MiniBrowserProps | undefined;
20
+ protected readonly toDisposeOnProps: DisposableCollection;
21
+ setProps(raw: MiniBrowserProps): void;
22
+ protected onActivateRequest(msg: Message): void;
23
+ storeState(): object;
24
+ restoreState(oldState: object): void;
25
+ }
26
26
  //# sourceMappingURL=mini-browser.d.ts.map