@theia/preview 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.
- package/README.md +45 -45
- package/lib/browser/index.d.ts +3 -3
- package/lib/browser/index.js +29 -29
- package/lib/browser/markdown/index.d.ts +1 -1
- package/lib/browser/markdown/index.js +28 -28
- package/lib/browser/markdown/markdown-preview-handler.d.ts +28 -28
- package/lib/browser/markdown/markdown-preview-handler.js +301 -301
- package/lib/browser/markdown/markdown-preview-handler.spec.d.ts +1 -1
- package/lib/browser/markdown/markdown-preview-handler.spec.js +193 -193
- package/lib/browser/preview-contribution.d.ts +50 -50
- package/lib/browser/preview-contribution.js +262 -262
- package/lib/browser/preview-frontend-module.d.ts +5 -5
- package/lib/browser/preview-frontend-module.js +52 -52
- package/lib/browser/preview-handler.d.ts +104 -104
- package/lib/browser/preview-handler.js +76 -76
- package/lib/browser/preview-link-normalizer.d.ts +7 -7
- package/lib/browser/preview-link-normalizer.js +54 -54
- package/lib/browser/preview-preferences.d.ts +11 -11
- package/lib/browser/preview-preferences.js +46 -46
- package/lib/browser/preview-uri.d.ts +8 -8
- package/lib/browser/preview-uri.js +47 -47
- package/lib/browser/preview-widget.d.ts +54 -54
- package/lib/browser/preview-widget.js +261 -261
- package/lib/package.spec.js +25 -25
- package/package.json +7 -7
- package/src/browser/index.ts +19 -19
- package/src/browser/markdown/index.ts +17 -17
- package/src/browser/markdown/markdown-preview-handler.spec.ts +228 -228
- package/src/browser/markdown/markdown-preview-handler.ts +309 -309
- package/src/browser/markdown/style/index.css +18 -18
- package/src/browser/markdown/style/markdown.css +203 -203
- package/src/browser/markdown/style/tomorrow.css +105 -105
- package/src/browser/preview-contribution.ts +276 -276
- package/src/browser/preview-frontend-module.ts +57 -57
- package/src/browser/preview-handler.ts +141 -141
- package/src/browser/preview-link-normalizer.ts +40 -40
- package/src/browser/preview-preferences.ts +58 -58
- package/src/browser/preview-uri.ts +43 -43
- package/src/browser/preview-widget.ts +277 -277
- package/src/browser/style/index.css +17 -17
- package/src/browser/style/preview-widget.css +29 -29
- package/src/package.spec.ts +29 -29
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
-
import URI from '@theia/core/lib/common/uri';
|
|
19
|
-
import { CommandContribution, MenuContribution, bindContributionProvider, ResourceProvider } from '@theia/core/lib/common';
|
|
20
|
-
import { OpenHandler, WidgetFactory, FrontendApplicationContribution, NavigatableWidgetOptions } from '@theia/core/lib/browser';
|
|
21
|
-
import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
|
22
|
-
import { PreviewContribution } from './preview-contribution';
|
|
23
|
-
import { PreviewWidget, PreviewWidgetOptions } from './preview-widget';
|
|
24
|
-
import { PreviewHandler, PreviewHandlerProvider } from './preview-handler';
|
|
25
|
-
import { PreviewUri } from './preview-uri';
|
|
26
|
-
import { MarkdownPreviewHandler } from './markdown';
|
|
27
|
-
import { bindPreviewPreferences } from './preview-preferences';
|
|
28
|
-
import { PreviewLinkNormalizer } from './preview-link-normalizer';
|
|
29
|
-
|
|
30
|
-
import '../../src/browser/style/index.css';
|
|
31
|
-
import '../../src/browser/markdown/style/index.css';
|
|
32
|
-
|
|
33
|
-
export default new ContainerModule(bind => {
|
|
34
|
-
bindPreviewPreferences(bind);
|
|
35
|
-
bind(PreviewHandlerProvider).toSelf().inSingletonScope();
|
|
36
|
-
bindContributionProvider(bind, PreviewHandler);
|
|
37
|
-
bind(MarkdownPreviewHandler).toSelf().inSingletonScope();
|
|
38
|
-
bind(PreviewHandler).toService(MarkdownPreviewHandler);
|
|
39
|
-
bind(PreviewLinkNormalizer).toSelf().inSingletonScope();
|
|
40
|
-
|
|
41
|
-
bind(PreviewWidget).toSelf();
|
|
42
|
-
bind<WidgetFactory>(WidgetFactory).toDynamicValue(ctx => ({
|
|
43
|
-
id: PreviewUri.id,
|
|
44
|
-
async createWidget(options: NavigatableWidgetOptions): Promise<PreviewWidget> {
|
|
45
|
-
const { container } = ctx;
|
|
46
|
-
const resource = await container.get<ResourceProvider>(ResourceProvider)(new URI(options.uri));
|
|
47
|
-
const child = container.createChild();
|
|
48
|
-
child.bind<PreviewWidgetOptions>(PreviewWidgetOptions).toConstantValue({ resource });
|
|
49
|
-
return child.get(PreviewWidget);
|
|
50
|
-
}
|
|
51
|
-
})).inSingletonScope();
|
|
52
|
-
|
|
53
|
-
bind(PreviewContribution).toSelf().inSingletonScope();
|
|
54
|
-
[CommandContribution, MenuContribution, OpenHandler, FrontendApplicationContribution, TabBarToolbarContribution].forEach(serviceIdentifier =>
|
|
55
|
-
bind(serviceIdentifier).toService(PreviewContribution)
|
|
56
|
-
);
|
|
57
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import URI from '@theia/core/lib/common/uri';
|
|
19
|
+
import { CommandContribution, MenuContribution, bindContributionProvider, ResourceProvider } from '@theia/core/lib/common';
|
|
20
|
+
import { OpenHandler, WidgetFactory, FrontendApplicationContribution, NavigatableWidgetOptions } from '@theia/core/lib/browser';
|
|
21
|
+
import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
|
22
|
+
import { PreviewContribution } from './preview-contribution';
|
|
23
|
+
import { PreviewWidget, PreviewWidgetOptions } from './preview-widget';
|
|
24
|
+
import { PreviewHandler, PreviewHandlerProvider } from './preview-handler';
|
|
25
|
+
import { PreviewUri } from './preview-uri';
|
|
26
|
+
import { MarkdownPreviewHandler } from './markdown';
|
|
27
|
+
import { bindPreviewPreferences } from './preview-preferences';
|
|
28
|
+
import { PreviewLinkNormalizer } from './preview-link-normalizer';
|
|
29
|
+
|
|
30
|
+
import '../../src/browser/style/index.css';
|
|
31
|
+
import '../../src/browser/markdown/style/index.css';
|
|
32
|
+
|
|
33
|
+
export default new ContainerModule(bind => {
|
|
34
|
+
bindPreviewPreferences(bind);
|
|
35
|
+
bind(PreviewHandlerProvider).toSelf().inSingletonScope();
|
|
36
|
+
bindContributionProvider(bind, PreviewHandler);
|
|
37
|
+
bind(MarkdownPreviewHandler).toSelf().inSingletonScope();
|
|
38
|
+
bind(PreviewHandler).toService(MarkdownPreviewHandler);
|
|
39
|
+
bind(PreviewLinkNormalizer).toSelf().inSingletonScope();
|
|
40
|
+
|
|
41
|
+
bind(PreviewWidget).toSelf();
|
|
42
|
+
bind<WidgetFactory>(WidgetFactory).toDynamicValue(ctx => ({
|
|
43
|
+
id: PreviewUri.id,
|
|
44
|
+
async createWidget(options: NavigatableWidgetOptions): Promise<PreviewWidget> {
|
|
45
|
+
const { container } = ctx;
|
|
46
|
+
const resource = await container.get<ResourceProvider>(ResourceProvider)(new URI(options.uri));
|
|
47
|
+
const child = container.createChild();
|
|
48
|
+
child.bind<PreviewWidgetOptions>(PreviewWidgetOptions).toConstantValue({ resource });
|
|
49
|
+
return child.get(PreviewWidget);
|
|
50
|
+
}
|
|
51
|
+
})).inSingletonScope();
|
|
52
|
+
|
|
53
|
+
bind(PreviewContribution).toSelf().inSingletonScope();
|
|
54
|
+
[CommandContribution, MenuContribution, OpenHandler, FrontendApplicationContribution, TabBarToolbarContribution].forEach(serviceIdentifier =>
|
|
55
|
+
bind(serviceIdentifier).toService(PreviewContribution)
|
|
56
|
+
);
|
|
57
|
+
});
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 TypeFox 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
18
|
-
import URI from '@theia/core/lib/common/uri';
|
|
19
|
-
import { ContributionProvider, isObject, MaybePromise, Prioritizeable } from '@theia/core';
|
|
20
|
-
|
|
21
|
-
export const PreviewHandler = Symbol('PreviewHandler');
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The parameters given to the preview handler to render the preview content.
|
|
25
|
-
*/
|
|
26
|
-
export interface RenderContentParams {
|
|
27
|
-
/**
|
|
28
|
-
* Textual content of the resource.
|
|
29
|
-
*/
|
|
30
|
-
content: string;
|
|
31
|
-
/**
|
|
32
|
-
* URI identifying the source resource.
|
|
33
|
-
*/
|
|
34
|
-
originUri: URI;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export namespace RenderContentParams {
|
|
38
|
-
export function is(params: unknown): params is RenderContentParams {
|
|
39
|
-
return isObject(params) && 'content' in params && 'originUri' in params;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* A PreviewHandler manages the integration of one or more previews.
|
|
45
|
-
*
|
|
46
|
-
* It indicates whether a preview shall be rendered for a given resource URI and, if yes, renders the content.
|
|
47
|
-
* Additionally it optionally provides methods with which the scroll state of the preview and corresponding
|
|
48
|
-
* editor can be managed.
|
|
49
|
-
*
|
|
50
|
-
* See {@link MarkdownPreviewHandler} for an example implementation.
|
|
51
|
-
*/
|
|
52
|
-
export interface PreviewHandler {
|
|
53
|
-
/**
|
|
54
|
-
* One or more classes which specify the preview widget icon.
|
|
55
|
-
*/
|
|
56
|
-
readonly iconClass?: string;
|
|
57
|
-
/**
|
|
58
|
-
* Indicates whether and with which priority (larger is better) this preview handler is responsible for the resource identified by the given URI.
|
|
59
|
-
* If multiple handlers return the same priority it's undefined which one will be used.
|
|
60
|
-
*
|
|
61
|
-
* @param uri the URI identifying a resource.
|
|
62
|
-
*
|
|
63
|
-
* @returns a number larger than 0 if the handler is applicable, 0 or a negative number otherwise.
|
|
64
|
-
*/
|
|
65
|
-
canHandle(uri: URI): number;
|
|
66
|
-
/**
|
|
67
|
-
* Render the preview content by returning appropriate HTML.
|
|
68
|
-
*
|
|
69
|
-
* @param params information for the handler to render its content.
|
|
70
|
-
*
|
|
71
|
-
* @returns the HTMLElement which will be attached to the preview widget.
|
|
72
|
-
*/
|
|
73
|
-
renderContent(params: RenderContentParams): MaybePromise<HTMLElement | undefined>;
|
|
74
|
-
/**
|
|
75
|
-
* Search and return the HTMLElement which corresponds to the given fragment.
|
|
76
|
-
* This is used to initially reveal elements identified via the URI fragment.
|
|
77
|
-
*
|
|
78
|
-
* @param content the preview widget element containing the content previously rendered by {@link PreviewHandler.renderContent}.
|
|
79
|
-
* @param fragment the URI fragment for which the corresponding element shall be returned
|
|
80
|
-
*
|
|
81
|
-
* @returns the HTMLElement which is part of content and corresponds to the given fragment, undefined otherwise.
|
|
82
|
-
*/
|
|
83
|
-
findElementForFragment?(content: HTMLElement, fragment: string): HTMLElement | undefined;
|
|
84
|
-
/**
|
|
85
|
-
* Search and return the HTMLElement which corresponds to the given line number.
|
|
86
|
-
* This is used to scroll the preview when the source editor scrolls.
|
|
87
|
-
*
|
|
88
|
-
* @param content the preview widget element containing the previously rendered by {@link PreviewHandler.renderContent}.
|
|
89
|
-
* @param sourceLine the line number for which the corresponding element shall be returned.
|
|
90
|
-
*
|
|
91
|
-
* @returns the HTMLElement which is part of content and corresponds to the given line number, undefined otherwise.
|
|
92
|
-
*/
|
|
93
|
-
findElementForSourceLine?(content: HTMLElement, sourceLine: number): HTMLElement | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* Returns the line number which corresponds to the preview element at the given offset.
|
|
96
|
-
* This is used to scroll the source editor when the preview scrolls.
|
|
97
|
-
*
|
|
98
|
-
* @param content the preview widget element containing the previously rendered by {@link PreviewHandler.renderContent}.
|
|
99
|
-
* @param offset the total amount by which the preview widget is scrolled.
|
|
100
|
-
*
|
|
101
|
-
* @returns the source line number which corresponds to the preview element at the given offset, undefined otherwise.
|
|
102
|
-
*/
|
|
103
|
-
getSourceLineForOffset?(content: HTMLElement, offset: number): number | undefined;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Provider managing the available PreviewHandlers.
|
|
108
|
-
*/
|
|
109
|
-
@injectable()
|
|
110
|
-
export class PreviewHandlerProvider {
|
|
111
|
-
|
|
112
|
-
constructor(
|
|
113
|
-
@inject(ContributionProvider) @named(PreviewHandler)
|
|
114
|
-
protected readonly previewHandlerContributions: ContributionProvider<PreviewHandler>
|
|
115
|
-
) { }
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Find PreviewHandlers for the given resource identifier.
|
|
119
|
-
*
|
|
120
|
-
* @param uri the URI identifying a resource.
|
|
121
|
-
*
|
|
122
|
-
* @returns the list of all supported `PreviewHandlers` sorted by their priority.
|
|
123
|
-
*/
|
|
124
|
-
findContribution(uri: URI): PreviewHandler[] {
|
|
125
|
-
const prioritized = Prioritizeable.prioritizeAllSync(this.previewHandlerContributions.getContributions(), contrib =>
|
|
126
|
-
contrib.canHandle(uri)
|
|
127
|
-
);
|
|
128
|
-
return prioritized.map(c => c.value);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Indicates whether any PreviewHandler can process the resource identified by the given URI.
|
|
133
|
-
*
|
|
134
|
-
* @param uri the URI identifying a resource.
|
|
135
|
-
*
|
|
136
|
-
* @returns `true` when a PreviewHandler can process the resource, `false` otherwise.
|
|
137
|
-
*/
|
|
138
|
-
canHandle(uri: URI): boolean {
|
|
139
|
-
return this.findContribution(uri).length > 0;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 TypeFox 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
18
|
+
import URI from '@theia/core/lib/common/uri';
|
|
19
|
+
import { ContributionProvider, isObject, MaybePromise, Prioritizeable } from '@theia/core';
|
|
20
|
+
|
|
21
|
+
export const PreviewHandler = Symbol('PreviewHandler');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The parameters given to the preview handler to render the preview content.
|
|
25
|
+
*/
|
|
26
|
+
export interface RenderContentParams {
|
|
27
|
+
/**
|
|
28
|
+
* Textual content of the resource.
|
|
29
|
+
*/
|
|
30
|
+
content: string;
|
|
31
|
+
/**
|
|
32
|
+
* URI identifying the source resource.
|
|
33
|
+
*/
|
|
34
|
+
originUri: URI;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export namespace RenderContentParams {
|
|
38
|
+
export function is(params: unknown): params is RenderContentParams {
|
|
39
|
+
return isObject(params) && 'content' in params && 'originUri' in params;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A PreviewHandler manages the integration of one or more previews.
|
|
45
|
+
*
|
|
46
|
+
* It indicates whether a preview shall be rendered for a given resource URI and, if yes, renders the content.
|
|
47
|
+
* Additionally it optionally provides methods with which the scroll state of the preview and corresponding
|
|
48
|
+
* editor can be managed.
|
|
49
|
+
*
|
|
50
|
+
* See {@link MarkdownPreviewHandler} for an example implementation.
|
|
51
|
+
*/
|
|
52
|
+
export interface PreviewHandler {
|
|
53
|
+
/**
|
|
54
|
+
* One or more classes which specify the preview widget icon.
|
|
55
|
+
*/
|
|
56
|
+
readonly iconClass?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Indicates whether and with which priority (larger is better) this preview handler is responsible for the resource identified by the given URI.
|
|
59
|
+
* If multiple handlers return the same priority it's undefined which one will be used.
|
|
60
|
+
*
|
|
61
|
+
* @param uri the URI identifying a resource.
|
|
62
|
+
*
|
|
63
|
+
* @returns a number larger than 0 if the handler is applicable, 0 or a negative number otherwise.
|
|
64
|
+
*/
|
|
65
|
+
canHandle(uri: URI): number;
|
|
66
|
+
/**
|
|
67
|
+
* Render the preview content by returning appropriate HTML.
|
|
68
|
+
*
|
|
69
|
+
* @param params information for the handler to render its content.
|
|
70
|
+
*
|
|
71
|
+
* @returns the HTMLElement which will be attached to the preview widget.
|
|
72
|
+
*/
|
|
73
|
+
renderContent(params: RenderContentParams): MaybePromise<HTMLElement | undefined>;
|
|
74
|
+
/**
|
|
75
|
+
* Search and return the HTMLElement which corresponds to the given fragment.
|
|
76
|
+
* This is used to initially reveal elements identified via the URI fragment.
|
|
77
|
+
*
|
|
78
|
+
* @param content the preview widget element containing the content previously rendered by {@link PreviewHandler.renderContent}.
|
|
79
|
+
* @param fragment the URI fragment for which the corresponding element shall be returned
|
|
80
|
+
*
|
|
81
|
+
* @returns the HTMLElement which is part of content and corresponds to the given fragment, undefined otherwise.
|
|
82
|
+
*/
|
|
83
|
+
findElementForFragment?(content: HTMLElement, fragment: string): HTMLElement | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Search and return the HTMLElement which corresponds to the given line number.
|
|
86
|
+
* This is used to scroll the preview when the source editor scrolls.
|
|
87
|
+
*
|
|
88
|
+
* @param content the preview widget element containing the previously rendered by {@link PreviewHandler.renderContent}.
|
|
89
|
+
* @param sourceLine the line number for which the corresponding element shall be returned.
|
|
90
|
+
*
|
|
91
|
+
* @returns the HTMLElement which is part of content and corresponds to the given line number, undefined otherwise.
|
|
92
|
+
*/
|
|
93
|
+
findElementForSourceLine?(content: HTMLElement, sourceLine: number): HTMLElement | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the line number which corresponds to the preview element at the given offset.
|
|
96
|
+
* This is used to scroll the source editor when the preview scrolls.
|
|
97
|
+
*
|
|
98
|
+
* @param content the preview widget element containing the previously rendered by {@link PreviewHandler.renderContent}.
|
|
99
|
+
* @param offset the total amount by which the preview widget is scrolled.
|
|
100
|
+
*
|
|
101
|
+
* @returns the source line number which corresponds to the preview element at the given offset, undefined otherwise.
|
|
102
|
+
*/
|
|
103
|
+
getSourceLineForOffset?(content: HTMLElement, offset: number): number | undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Provider managing the available PreviewHandlers.
|
|
108
|
+
*/
|
|
109
|
+
@injectable()
|
|
110
|
+
export class PreviewHandlerProvider {
|
|
111
|
+
|
|
112
|
+
constructor(
|
|
113
|
+
@inject(ContributionProvider) @named(PreviewHandler)
|
|
114
|
+
protected readonly previewHandlerContributions: ContributionProvider<PreviewHandler>
|
|
115
|
+
) { }
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Find PreviewHandlers for the given resource identifier.
|
|
119
|
+
*
|
|
120
|
+
* @param uri the URI identifying a resource.
|
|
121
|
+
*
|
|
122
|
+
* @returns the list of all supported `PreviewHandlers` sorted by their priority.
|
|
123
|
+
*/
|
|
124
|
+
findContribution(uri: URI): PreviewHandler[] {
|
|
125
|
+
const prioritized = Prioritizeable.prioritizeAllSync(this.previewHandlerContributions.getContributions(), contrib =>
|
|
126
|
+
contrib.canHandle(uri)
|
|
127
|
+
);
|
|
128
|
+
return prioritized.map(c => c.value);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Indicates whether any PreviewHandler can process the resource identified by the given URI.
|
|
133
|
+
*
|
|
134
|
+
* @param uri the URI identifying a resource.
|
|
135
|
+
*
|
|
136
|
+
* @returns `true` when a PreviewHandler can process the resource, `false` otherwise.
|
|
137
|
+
*/
|
|
138
|
+
canHandle(uri: URI): boolean {
|
|
139
|
+
return this.findContribution(uri).length > 0;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
18
|
-
import URI from '@theia/core/lib/common/uri';
|
|
19
|
-
import { MiniBrowserEnvironment } from '@theia/mini-browser/lib/browser/environment/mini-browser-environment';
|
|
20
|
-
|
|
21
|
-
@injectable()
|
|
22
|
-
export class PreviewLinkNormalizer {
|
|
23
|
-
|
|
24
|
-
protected urlScheme = new RegExp('^[a-z][a-z|0-9|\+|\-|\.]*:', 'i');
|
|
25
|
-
|
|
26
|
-
@inject(MiniBrowserEnvironment)
|
|
27
|
-
protected readonly miniBrowserEnvironment: MiniBrowserEnvironment;
|
|
28
|
-
|
|
29
|
-
normalizeLink(documentUri: URI, link: string): string {
|
|
30
|
-
try {
|
|
31
|
-
if (!this.urlScheme.test(link)) {
|
|
32
|
-
const location = documentUri.parent.resolve(link).path.toString();
|
|
33
|
-
return this.miniBrowserEnvironment.getEndpoint('normalized-link').getRestUrl().resolve(location).toString();
|
|
34
|
-
}
|
|
35
|
-
} catch {
|
|
36
|
-
// ignore
|
|
37
|
-
}
|
|
38
|
-
return link;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
18
|
+
import URI from '@theia/core/lib/common/uri';
|
|
19
|
+
import { MiniBrowserEnvironment } from '@theia/mini-browser/lib/browser/environment/mini-browser-environment';
|
|
20
|
+
|
|
21
|
+
@injectable()
|
|
22
|
+
export class PreviewLinkNormalizer {
|
|
23
|
+
|
|
24
|
+
protected urlScheme = new RegExp('^[a-z][a-z|0-9|\+|\-|\.]*:', 'i');
|
|
25
|
+
|
|
26
|
+
@inject(MiniBrowserEnvironment)
|
|
27
|
+
protected readonly miniBrowserEnvironment: MiniBrowserEnvironment;
|
|
28
|
+
|
|
29
|
+
normalizeLink(documentUri: URI, link: string): string {
|
|
30
|
+
try {
|
|
31
|
+
if (!this.urlScheme.test(link)) {
|
|
32
|
+
const location = documentUri.parent.resolve(link).path.toString();
|
|
33
|
+
return this.miniBrowserEnvironment.getEndpoint('normalized-link').getRestUrl().resolve(location).toString();
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
// ignore
|
|
37
|
+
}
|
|
38
|
+
return link;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { interfaces } from '@theia/core/shared/inversify';
|
|
18
|
-
import {
|
|
19
|
-
createPreferenceProxy,
|
|
20
|
-
PreferenceProxy,
|
|
21
|
-
PreferenceService,
|
|
22
|
-
PreferenceContribution,
|
|
23
|
-
PreferenceSchema
|
|
24
|
-
} from '@theia/core/lib/browser';
|
|
25
|
-
import { nls } from '@theia/core/lib/common/nls';
|
|
26
|
-
|
|
27
|
-
export const PreviewConfigSchema: PreferenceSchema = {
|
|
28
|
-
type: 'object',
|
|
29
|
-
properties: {
|
|
30
|
-
'preview.openByDefault': {
|
|
31
|
-
type: 'boolean',
|
|
32
|
-
description: nls.localize('theia/preview/openByDefault', 'Open the preview instead of the editor by default.'),
|
|
33
|
-
default: false
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export interface PreviewConfiguration {
|
|
39
|
-
'preview.openByDefault': boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const PreviewPreferenceContribution = Symbol('PreviewPreferenceContribution');
|
|
43
|
-
export const PreviewPreferences = Symbol('PreviewPreferences');
|
|
44
|
-
export type PreviewPreferences = PreferenceProxy<PreviewConfiguration>;
|
|
45
|
-
|
|
46
|
-
export function createPreviewPreferences(preferences: PreferenceService, schema: PreferenceSchema = PreviewConfigSchema): PreviewPreferences {
|
|
47
|
-
return createPreferenceProxy(preferences, schema);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function bindPreviewPreferences(bind: interfaces.Bind): void {
|
|
51
|
-
bind(PreviewPreferences).toDynamicValue(ctx => {
|
|
52
|
-
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
|
|
53
|
-
const contribution = ctx.container.get<PreferenceContribution>(PreviewPreferenceContribution);
|
|
54
|
-
return createPreviewPreferences(preferences, contribution.schema);
|
|
55
|
-
}).inSingletonScope();
|
|
56
|
-
bind(PreviewPreferenceContribution).toConstantValue({ schema: PreviewConfigSchema });
|
|
57
|
-
bind(PreferenceContribution).toService(PreviewPreferenceContribution);
|
|
58
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
18
|
+
import {
|
|
19
|
+
createPreferenceProxy,
|
|
20
|
+
PreferenceProxy,
|
|
21
|
+
PreferenceService,
|
|
22
|
+
PreferenceContribution,
|
|
23
|
+
PreferenceSchema
|
|
24
|
+
} from '@theia/core/lib/browser';
|
|
25
|
+
import { nls } from '@theia/core/lib/common/nls';
|
|
26
|
+
|
|
27
|
+
export const PreviewConfigSchema: PreferenceSchema = {
|
|
28
|
+
type: 'object',
|
|
29
|
+
properties: {
|
|
30
|
+
'preview.openByDefault': {
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
description: nls.localize('theia/preview/openByDefault', 'Open the preview instead of the editor by default.'),
|
|
33
|
+
default: false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export interface PreviewConfiguration {
|
|
39
|
+
'preview.openByDefault': boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const PreviewPreferenceContribution = Symbol('PreviewPreferenceContribution');
|
|
43
|
+
export const PreviewPreferences = Symbol('PreviewPreferences');
|
|
44
|
+
export type PreviewPreferences = PreferenceProxy<PreviewConfiguration>;
|
|
45
|
+
|
|
46
|
+
export function createPreviewPreferences(preferences: PreferenceService, schema: PreferenceSchema = PreviewConfigSchema): PreviewPreferences {
|
|
47
|
+
return createPreferenceProxy(preferences, schema);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function bindPreviewPreferences(bind: interfaces.Bind): void {
|
|
51
|
+
bind(PreviewPreferences).toDynamicValue(ctx => {
|
|
52
|
+
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
|
|
53
|
+
const contribution = ctx.container.get<PreferenceContribution>(PreviewPreferenceContribution);
|
|
54
|
+
return createPreviewPreferences(preferences, contribution.schema);
|
|
55
|
+
}).inSingletonScope();
|
|
56
|
+
bind(PreviewPreferenceContribution).toConstantValue({ schema: PreviewConfigSchema });
|
|
57
|
+
bind(PreferenceContribution).toService(PreviewPreferenceContribution);
|
|
58
|
+
}
|