@theia/notebook 1.53.0-next.4 → 1.53.0-next.55

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 (99) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/contributions/cell-operations.d.ts.map +1 -1
  3. package/lib/browser/contributions/cell-operations.js +8 -1
  4. package/lib/browser/contributions/cell-operations.js.map +1 -1
  5. package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
  6. package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
  7. package/lib/browser/contributions/notebook-actions-contribution.js +31 -6
  8. package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
  9. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +4 -0
  10. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
  11. package/lib/browser/contributions/notebook-cell-actions-contribution.js +49 -12
  12. package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
  13. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts +14 -0
  14. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -0
  15. package/lib/browser/contributions/notebook-status-bar-contribution.js +75 -0
  16. package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -0
  17. package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
  18. package/lib/browser/notebook-editor-widget.js +3 -5
  19. package/lib/browser/notebook-editor-widget.js.map +1 -1
  20. package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
  21. package/lib/browser/notebook-frontend-module.js +3 -0
  22. package/lib/browser/notebook-frontend-module.js.map +1 -1
  23. package/lib/browser/notebook-open-handler.d.ts +3 -2
  24. package/lib/browser/notebook-open-handler.d.ts.map +1 -1
  25. package/lib/browser/notebook-open-handler.js +12 -5
  26. package/lib/browser/notebook-open-handler.js.map +1 -1
  27. package/lib/browser/service/notebook-options.d.ts +1 -0
  28. package/lib/browser/service/notebook-options.d.ts.map +1 -1
  29. package/lib/browser/service/notebook-options.js +1 -0
  30. package/lib/browser/service/notebook-options.js.map +1 -1
  31. package/lib/browser/service/notebook-service.d.ts +1 -0
  32. package/lib/browser/service/notebook-service.d.ts.map +1 -1
  33. package/lib/browser/service/notebook-service.js +7 -0
  34. package/lib/browser/service/notebook-service.js.map +1 -1
  35. package/lib/browser/view/notebook-cell-editor.d.ts +1 -0
  36. package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
  37. package/lib/browser/view/notebook-cell-editor.js +30 -16
  38. package/lib/browser/view/notebook-cell-editor.js.map +1 -1
  39. package/lib/browser/view/notebook-cell-list-view.d.ts +7 -4
  40. package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
  41. package/lib/browser/view/notebook-cell-list-view.js +39 -29
  42. package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
  43. package/lib/browser/view-model/notebook-cell-model.d.ts +3 -0
  44. package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
  45. package/lib/browser/view-model/notebook-cell-model.js +5 -0
  46. package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
  47. package/package.json +8 -8
  48. package/src/browser/contributions/cell-operations.ts +44 -39
  49. package/src/browser/contributions/notebook-actions-contribution.ts +379 -351
  50. package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -485
  51. package/src/browser/contributions/notebook-color-contribution.ts +268 -268
  52. package/src/browser/contributions/notebook-context-keys.ts +113 -113
  53. package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
  54. package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
  55. package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
  56. package/src/browser/contributions/notebook-preferences.ts +92 -92
  57. package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -0
  58. package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
  59. package/src/browser/index.ts +27 -27
  60. package/src/browser/notebook-cell-resource-resolver.ts +130 -130
  61. package/src/browser/notebook-editor-widget-factory.ts +82 -82
  62. package/src/browser/notebook-editor-widget.tsx +330 -331
  63. package/src/browser/notebook-frontend-module.ts +119 -115
  64. package/src/browser/notebook-open-handler.ts +120 -114
  65. package/src/browser/notebook-output-utils.ts +119 -119
  66. package/src/browser/notebook-renderer-registry.ts +85 -85
  67. package/src/browser/notebook-type-registry.ts +54 -54
  68. package/src/browser/notebook-types.ts +186 -186
  69. package/src/browser/renderers/cell-output-webview.ts +33 -33
  70. package/src/browser/service/notebook-clipboard-service.ts +43 -43
  71. package/src/browser/service/notebook-context-manager.ts +162 -162
  72. package/src/browser/service/notebook-editor-widget-service.ts +101 -101
  73. package/src/browser/service/notebook-execution-service.ts +139 -139
  74. package/src/browser/service/notebook-execution-state-service.ts +311 -311
  75. package/src/browser/service/notebook-kernel-history-service.ts +124 -124
  76. package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
  77. package/src/browser/service/notebook-kernel-service.ts +357 -357
  78. package/src/browser/service/notebook-model-resolver-service.ts +160 -160
  79. package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
  80. package/src/browser/service/notebook-options.ts +155 -154
  81. package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
  82. package/src/browser/service/notebook-service.ts +215 -209
  83. package/src/browser/style/index.css +483 -467
  84. package/src/browser/view/notebook-cell-editor.tsx +263 -247
  85. package/src/browser/view/notebook-cell-list-view.tsx +279 -259
  86. package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
  87. package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
  88. package/src/browser/view/notebook-code-cell-view.tsx +350 -350
  89. package/src/browser/view/notebook-find-widget.tsx +335 -335
  90. package/src/browser/view/notebook-main-toolbar.tsx +235 -235
  91. package/src/browser/view/notebook-markdown-cell-view.tsx +208 -208
  92. package/src/browser/view/notebook-viewport-service.ts +61 -61
  93. package/src/browser/view-model/notebook-cell-model.ts +473 -466
  94. package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
  95. package/src/browser/view-model/notebook-model.ts +550 -550
  96. package/src/common/index.ts +18 -18
  97. package/src/common/notebook-common.ts +337 -337
  98. package/src/common/notebook-protocol.ts +35 -35
  99. package/src/common/notebook-range.ts +30 -30
@@ -1,115 +1,119 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 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
- import '../../src/browser/style/index.css';
17
-
18
- import { ContainerModule } from '@theia/core/shared/inversify';
19
- import { FrontendApplicationContribution, KeybindingContribution, LabelProviderContribution, OpenHandler, UndoRedoHandler, WidgetFactory } from '@theia/core/lib/browser';
20
- import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
21
- import { NotebookOpenHandler } from './notebook-open-handler';
22
- import { CommandContribution, MenuContribution, ResourceResolver, } from '@theia/core';
23
- import { NotebookTypeRegistry } from './notebook-type-registry';
24
- import { NotebookRendererRegistry } from './notebook-renderer-registry';
25
- import { NotebookService } from './service/notebook-service';
26
- import { NotebookEditorWidgetFactory } from './notebook-editor-widget-factory';
27
- import { NotebookCellResourceResolver, NotebookOutputResourceResolver } from './notebook-cell-resource-resolver';
28
- import { NotebookModelResolverService } from './service/notebook-model-resolver-service';
29
- import { NotebookCellActionContribution } from './contributions/notebook-cell-actions-contribution';
30
- import { createNotebookModelContainer, NotebookModel, NotebookModelFactory, NotebookModelProps, NotebookModelResolverServiceProxy } from './view-model/notebook-model';
31
- import { createNotebookCellModelContainer, NotebookCellModel, NotebookCellModelFactory, NotebookCellModelProps } from './view-model/notebook-cell-model';
32
- import { createNotebookEditorWidgetContainer, NotebookEditorWidgetContainerFactory, NotebookEditorProps, NotebookEditorWidget } from './notebook-editor-widget';
33
- import { NotebookActionsContribution } from './contributions/notebook-actions-contribution';
34
- import { NotebookExecutionService } from './service/notebook-execution-service';
35
- import { NotebookExecutionStateService } from './service/notebook-execution-state-service';
36
- import { NotebookKernelService } from './service/notebook-kernel-service';
37
- import { NotebookKernelQuickPickService } from './service/notebook-kernel-quick-pick-service';
38
- import { NotebookKernelHistoryService } from './service/notebook-kernel-history-service';
39
- import { NotebookEditorWidgetService } from './service/notebook-editor-widget-service';
40
- import { NotebookRendererMessagingService } from './service/notebook-renderer-messaging-service';
41
- import { NotebookColorContribution } from './contributions/notebook-color-contribution';
42
- import { NotebookMonacoTextModelService } from './service/notebook-monaco-text-model-service';
43
- import { NotebookOutlineContribution } from './contributions/notebook-outline-contribution';
44
- import { NotebookLabelProviderContribution } from './contributions/notebook-label-provider-contribution';
45
- import { NotebookOutputActionContribution } from './contributions/notebook-output-action-contribution';
46
- import { NotebookClipboardService } from './service/notebook-clipboard-service';
47
- import { bindNotebookPreferences } from './contributions/notebook-preferences';
48
- import { NotebookOptionsService } from './service/notebook-options';
49
- import { NotebookUndoRedoHandler } from './contributions/notebook-undo-redo-handler';
50
-
51
- export default new ContainerModule((bind, unbind, isBound, rebind) => {
52
- bind(NotebookColorContribution).toSelf().inSingletonScope();
53
- bind(ColorContribution).toService(NotebookColorContribution);
54
-
55
- bind(NotebookOpenHandler).toSelf().inSingletonScope();
56
- bind(OpenHandler).toService(NotebookOpenHandler);
57
-
58
- bind(NotebookTypeRegistry).toSelf().inSingletonScope();
59
- bind(NotebookRendererRegistry).toSelf().inSingletonScope();
60
-
61
- bind(WidgetFactory).to(NotebookEditorWidgetFactory).inSingletonScope();
62
-
63
- bind(NotebookService).toSelf().inSingletonScope();
64
- bind(NotebookEditorWidgetService).toSelf().inSingletonScope();
65
- bind(NotebookExecutionService).toSelf().inSingletonScope();
66
- bind(NotebookExecutionStateService).toSelf().inSingletonScope();
67
- bind(NotebookKernelService).toSelf().inSingletonScope();
68
- bind(NotebookRendererMessagingService).toSelf().inSingletonScope();
69
- bind(NotebookKernelHistoryService).toSelf().inSingletonScope();
70
- bind(NotebookKernelQuickPickService).toSelf().inSingletonScope();
71
- bind(NotebookClipboardService).toSelf().inSingletonScope();
72
-
73
- bind(NotebookCellResourceResolver).toSelf().inSingletonScope();
74
- bind(ResourceResolver).toService(NotebookCellResourceResolver);
75
- bind(NotebookModelResolverService).toSelf().inSingletonScope();
76
- bind(NotebookModelResolverServiceProxy).toService(NotebookModelResolverService);
77
- bind(NotebookOutputResourceResolver).toSelf().inSingletonScope();
78
- bind(ResourceResolver).toService(NotebookOutputResourceResolver);
79
-
80
- bind(NotebookCellActionContribution).toSelf().inSingletonScope();
81
- bind(MenuContribution).toService(NotebookCellActionContribution);
82
- bind(CommandContribution).toService(NotebookCellActionContribution);
83
- bind(KeybindingContribution).toService(NotebookCellActionContribution);
84
-
85
- bind(NotebookActionsContribution).toSelf().inSingletonScope();
86
- bind(CommandContribution).toService(NotebookActionsContribution);
87
- bind(MenuContribution).toService(NotebookActionsContribution);
88
- bind(KeybindingContribution).toService(NotebookActionsContribution);
89
-
90
- bind(NotebookOutputActionContribution).toSelf().inSingletonScope();
91
- bind(CommandContribution).toService(NotebookOutputActionContribution);
92
-
93
- bind(NotebookEditorWidgetContainerFactory).toFactory(ctx => (props: NotebookEditorProps) =>
94
- createNotebookEditorWidgetContainer(ctx.container, props).get(NotebookEditorWidget)
95
- );
96
- bind(NotebookModelFactory).toFactory(ctx => (props: NotebookModelProps) =>
97
- createNotebookModelContainer(ctx.container, props).get(NotebookModel)
98
- );
99
- bind(NotebookCellModelFactory).toFactory(ctx => (props: NotebookCellModelProps) =>
100
- createNotebookCellModelContainer(ctx.container, props).get(NotebookCellModel)
101
- );
102
-
103
- bind(NotebookMonacoTextModelService).toSelf().inSingletonScope();
104
-
105
- bind(NotebookOutlineContribution).toSelf().inSingletonScope();
106
- bind(FrontendApplicationContribution).toService(NotebookOutlineContribution);
107
- bind(NotebookLabelProviderContribution).toSelf().inSingletonScope();
108
- bind(LabelProviderContribution).toService(NotebookLabelProviderContribution);
109
-
110
- bindNotebookPreferences(bind);
111
- bind(NotebookOptionsService).toSelf().inSingletonScope();
112
-
113
- bind(NotebookUndoRedoHandler).toSelf().inSingletonScope();
114
- bind(UndoRedoHandler).toService(NotebookUndoRedoHandler);
115
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 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
+ import '../../src/browser/style/index.css';
17
+
18
+ import { ContainerModule } from '@theia/core/shared/inversify';
19
+ import { FrontendApplicationContribution, KeybindingContribution, LabelProviderContribution, OpenHandler, UndoRedoHandler, WidgetFactory } from '@theia/core/lib/browser';
20
+ import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
21
+ import { NotebookOpenHandler } from './notebook-open-handler';
22
+ import { CommandContribution, MenuContribution, ResourceResolver, } from '@theia/core';
23
+ import { NotebookTypeRegistry } from './notebook-type-registry';
24
+ import { NotebookRendererRegistry } from './notebook-renderer-registry';
25
+ import { NotebookService } from './service/notebook-service';
26
+ import { NotebookEditorWidgetFactory } from './notebook-editor-widget-factory';
27
+ import { NotebookCellResourceResolver, NotebookOutputResourceResolver } from './notebook-cell-resource-resolver';
28
+ import { NotebookModelResolverService } from './service/notebook-model-resolver-service';
29
+ import { NotebookCellActionContribution } from './contributions/notebook-cell-actions-contribution';
30
+ import { createNotebookModelContainer, NotebookModel, NotebookModelFactory, NotebookModelProps, NotebookModelResolverServiceProxy } from './view-model/notebook-model';
31
+ import { createNotebookCellModelContainer, NotebookCellModel, NotebookCellModelFactory, NotebookCellModelProps } from './view-model/notebook-cell-model';
32
+ import { createNotebookEditorWidgetContainer, NotebookEditorWidgetContainerFactory, NotebookEditorProps, NotebookEditorWidget } from './notebook-editor-widget';
33
+ import { NotebookActionsContribution } from './contributions/notebook-actions-contribution';
34
+ import { NotebookExecutionService } from './service/notebook-execution-service';
35
+ import { NotebookExecutionStateService } from './service/notebook-execution-state-service';
36
+ import { NotebookKernelService } from './service/notebook-kernel-service';
37
+ import { NotebookKernelQuickPickService } from './service/notebook-kernel-quick-pick-service';
38
+ import { NotebookKernelHistoryService } from './service/notebook-kernel-history-service';
39
+ import { NotebookEditorWidgetService } from './service/notebook-editor-widget-service';
40
+ import { NotebookRendererMessagingService } from './service/notebook-renderer-messaging-service';
41
+ import { NotebookColorContribution } from './contributions/notebook-color-contribution';
42
+ import { NotebookMonacoTextModelService } from './service/notebook-monaco-text-model-service';
43
+ import { NotebookOutlineContribution } from './contributions/notebook-outline-contribution';
44
+ import { NotebookLabelProviderContribution } from './contributions/notebook-label-provider-contribution';
45
+ import { NotebookOutputActionContribution } from './contributions/notebook-output-action-contribution';
46
+ import { NotebookClipboardService } from './service/notebook-clipboard-service';
47
+ import { bindNotebookPreferences } from './contributions/notebook-preferences';
48
+ import { NotebookOptionsService } from './service/notebook-options';
49
+ import { NotebookUndoRedoHandler } from './contributions/notebook-undo-redo-handler';
50
+ import { NotebookStatusBarContribution } from './contributions/notebook-status-bar-contribution';
51
+
52
+ export default new ContainerModule((bind, unbind, isBound, rebind) => {
53
+ bind(NotebookColorContribution).toSelf().inSingletonScope();
54
+ bind(ColorContribution).toService(NotebookColorContribution);
55
+
56
+ bind(NotebookOpenHandler).toSelf().inSingletonScope();
57
+ bind(OpenHandler).toService(NotebookOpenHandler);
58
+
59
+ bind(NotebookTypeRegistry).toSelf().inSingletonScope();
60
+ bind(NotebookRendererRegistry).toSelf().inSingletonScope();
61
+
62
+ bind(WidgetFactory).to(NotebookEditorWidgetFactory).inSingletonScope();
63
+
64
+ bind(NotebookService).toSelf().inSingletonScope();
65
+ bind(NotebookEditorWidgetService).toSelf().inSingletonScope();
66
+ bind(NotebookExecutionService).toSelf().inSingletonScope();
67
+ bind(NotebookExecutionStateService).toSelf().inSingletonScope();
68
+ bind(NotebookKernelService).toSelf().inSingletonScope();
69
+ bind(NotebookRendererMessagingService).toSelf().inSingletonScope();
70
+ bind(NotebookKernelHistoryService).toSelf().inSingletonScope();
71
+ bind(NotebookKernelQuickPickService).toSelf().inSingletonScope();
72
+ bind(NotebookClipboardService).toSelf().inSingletonScope();
73
+
74
+ bind(NotebookCellResourceResolver).toSelf().inSingletonScope();
75
+ bind(ResourceResolver).toService(NotebookCellResourceResolver);
76
+ bind(NotebookModelResolverService).toSelf().inSingletonScope();
77
+ bind(NotebookModelResolverServiceProxy).toService(NotebookModelResolverService);
78
+ bind(NotebookOutputResourceResolver).toSelf().inSingletonScope();
79
+ bind(ResourceResolver).toService(NotebookOutputResourceResolver);
80
+
81
+ bind(NotebookCellActionContribution).toSelf().inSingletonScope();
82
+ bind(MenuContribution).toService(NotebookCellActionContribution);
83
+ bind(CommandContribution).toService(NotebookCellActionContribution);
84
+ bind(KeybindingContribution).toService(NotebookCellActionContribution);
85
+
86
+ bind(NotebookActionsContribution).toSelf().inSingletonScope();
87
+ bind(CommandContribution).toService(NotebookActionsContribution);
88
+ bind(MenuContribution).toService(NotebookActionsContribution);
89
+ bind(KeybindingContribution).toService(NotebookActionsContribution);
90
+
91
+ bind(NotebookOutputActionContribution).toSelf().inSingletonScope();
92
+ bind(CommandContribution).toService(NotebookOutputActionContribution);
93
+
94
+ bind(NotebookEditorWidgetContainerFactory).toFactory(ctx => (props: NotebookEditorProps) =>
95
+ createNotebookEditorWidgetContainer(ctx.container, props).get(NotebookEditorWidget)
96
+ );
97
+ bind(NotebookModelFactory).toFactory(ctx => (props: NotebookModelProps) =>
98
+ createNotebookModelContainer(ctx.container, props).get(NotebookModel)
99
+ );
100
+ bind(NotebookCellModelFactory).toFactory(ctx => (props: NotebookCellModelProps) =>
101
+ createNotebookCellModelContainer(ctx.container, props).get(NotebookCellModel)
102
+ );
103
+
104
+ bind(NotebookMonacoTextModelService).toSelf().inSingletonScope();
105
+
106
+ bind(NotebookOutlineContribution).toSelf().inSingletonScope();
107
+ bind(FrontendApplicationContribution).toService(NotebookOutlineContribution);
108
+ bind(NotebookLabelProviderContribution).toSelf().inSingletonScope();
109
+ bind(LabelProviderContribution).toService(NotebookLabelProviderContribution);
110
+
111
+ bindNotebookPreferences(bind);
112
+ bind(NotebookOptionsService).toSelf().inSingletonScope();
113
+
114
+ bind(NotebookUndoRedoHandler).toSelf().inSingletonScope();
115
+ bind(UndoRedoHandler).toService(NotebookUndoRedoHandler);
116
+
117
+ bind(NotebookStatusBarContribution).toSelf().inSingletonScope();
118
+ bind(FrontendApplicationContribution).toService(NotebookStatusBarContribution);
119
+ });
@@ -1,114 +1,120 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 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 { URI, MaybePromise, Disposable } from '@theia/core';
18
- import { NavigatableWidgetOpenHandler, WidgetOpenerOptions } from '@theia/core/lib/browser';
19
- import { injectable } from '@theia/core/shared/inversify';
20
- import { NotebookFileSelector, NotebookTypeDescriptor } from '../common/notebook-protocol';
21
- import { NotebookEditorWidget } from './notebook-editor-widget';
22
- import { match } from '@theia/core/lib/common/glob';
23
- import { NotebookEditorWidgetOptions } from './notebook-editor-widget-factory';
24
-
25
- export interface NotebookWidgetOpenerOptions extends WidgetOpenerOptions {
26
- notebookType?: string;
27
- }
28
-
29
- @injectable()
30
- export class NotebookOpenHandler extends NavigatableWidgetOpenHandler<NotebookEditorWidget> {
31
-
32
- readonly id = NotebookEditorWidget.ID;
33
-
34
- protected notebookTypes: NotebookTypeDescriptor[] = [];
35
-
36
- registerNotebookType(notebookType: NotebookTypeDescriptor): Disposable {
37
- this.notebookTypes.push(notebookType);
38
- return Disposable.create(() => {
39
- this.notebookTypes.splice(this.notebookTypes.indexOf(notebookType), 1);
40
- });
41
- }
42
-
43
- canHandle(uri: URI, options?: NotebookWidgetOpenerOptions): MaybePromise<number> {
44
- if (options?.notebookType) {
45
- return this.canHandleType(uri, this.notebookTypes.find(type => type.type === options.notebookType));
46
- }
47
- return Math.max(...this.notebookTypes.map(type => this.canHandleType(uri, type)));
48
- }
49
-
50
- canHandleType(uri: URI, notebookType?: NotebookTypeDescriptor): number {
51
- if (notebookType?.selector && this.matches(notebookType.selector, uri)) {
52
- return this.calculatePriority(notebookType);
53
- } else {
54
- return 0;
55
- }
56
- }
57
-
58
- protected calculatePriority(notebookType: NotebookTypeDescriptor | undefined): number {
59
- if (!notebookType) {
60
- return 0;
61
- }
62
- return notebookType.priority === 'option' ? 100 : 200;
63
- }
64
-
65
- protected findHighestPriorityType(uri: URI): NotebookTypeDescriptor | undefined {
66
- const matchingTypes = this.notebookTypes
67
- .filter(notebookType => notebookType.selector && this.matches(notebookType.selector, uri))
68
- .map(notebookType => ({ descriptor: notebookType, priority: this.calculatePriority(notebookType) }));
69
-
70
- if (matchingTypes.length === 0) {
71
- return undefined;
72
- }
73
- let type = matchingTypes[0];
74
- for (let i = 1; i < matchingTypes.length; i++) {
75
- const notebookType = matchingTypes[i];
76
- if (notebookType.priority > type.priority) {
77
- type = notebookType;
78
- }
79
- }
80
- return type.descriptor;
81
- }
82
-
83
- // Override for better options typing
84
- override open(uri: URI, options?: NotebookWidgetOpenerOptions): Promise<NotebookEditorWidget> {
85
- return super.open(uri, options);
86
- }
87
-
88
- protected override createWidgetOptions(uri: URI, options?: NotebookWidgetOpenerOptions): NotebookEditorWidgetOptions {
89
- const widgetOptions = super.createWidgetOptions(uri, options);
90
- if (options?.notebookType) {
91
- return {
92
- notebookType: options.notebookType,
93
- ...widgetOptions
94
- };
95
- }
96
- const notebookType = this.findHighestPriorityType(uri);
97
- if (!notebookType) {
98
- throw new Error('No notebook types registered for uri: ' + uri.toString());
99
- }
100
- return {
101
- notebookType: notebookType.type,
102
- ...widgetOptions
103
- };
104
- }
105
-
106
- protected matches(selectors: readonly NotebookFileSelector[], resource: URI): boolean {
107
- return selectors.some(selector => this.selectorMatches(selector, resource));
108
- }
109
-
110
- protected selectorMatches(selector: NotebookFileSelector, resource: URI): boolean {
111
- return !!selector.filenamePattern
112
- && match(selector.filenamePattern, resource.path.name + resource.path.ext);
113
- }
114
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 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 { URI, MaybePromise, Disposable } from '@theia/core';
18
+ import { NavigatableWidgetOpenHandler, PreferenceService, WidgetOpenerOptions, getDefaultHandler, defaultHandlerPriority } from '@theia/core/lib/browser';
19
+ import { inject, injectable } from '@theia/core/shared/inversify';
20
+ import { NotebookFileSelector, NotebookTypeDescriptor } from '../common/notebook-protocol';
21
+ import { NotebookEditorWidget } from './notebook-editor-widget';
22
+ import { match } from '@theia/core/lib/common/glob';
23
+ import { NotebookEditorWidgetOptions } from './notebook-editor-widget-factory';
24
+
25
+ export interface NotebookWidgetOpenerOptions extends WidgetOpenerOptions {
26
+ notebookType?: string;
27
+ }
28
+
29
+ @injectable()
30
+ export class NotebookOpenHandler extends NavigatableWidgetOpenHandler<NotebookEditorWidget> {
31
+
32
+ readonly id = NotebookEditorWidget.ID;
33
+
34
+ protected notebookTypes: NotebookTypeDescriptor[] = [];
35
+
36
+ @inject(PreferenceService)
37
+ protected readonly preferenceService: PreferenceService;
38
+
39
+ registerNotebookType(notebookType: NotebookTypeDescriptor): Disposable {
40
+ this.notebookTypes.push(notebookType);
41
+ return Disposable.create(() => {
42
+ this.notebookTypes.splice(this.notebookTypes.indexOf(notebookType), 1);
43
+ });
44
+ }
45
+
46
+ canHandle(uri: URI, options?: NotebookWidgetOpenerOptions): MaybePromise<number> {
47
+ const defaultHandler = getDefaultHandler(uri, this.preferenceService);
48
+ if (options?.notebookType) {
49
+ return this.canHandleType(uri, this.notebookTypes.find(type => type.type === options.notebookType), defaultHandler);
50
+ }
51
+ return Math.max(...this.notebookTypes.map(type => this.canHandleType(uri, type), defaultHandler));
52
+ }
53
+
54
+ canHandleType(uri: URI, notebookType?: NotebookTypeDescriptor, defaultHandler?: string): number {
55
+ if (notebookType?.selector && this.matches(notebookType.selector, uri)) {
56
+ return notebookType.type === defaultHandler ? defaultHandlerPriority : this.calculatePriority(notebookType);
57
+ } else {
58
+ return 0;
59
+ }
60
+ }
61
+
62
+ protected calculatePriority(notebookType: NotebookTypeDescriptor | undefined): number {
63
+ if (!notebookType) {
64
+ return 0;
65
+ }
66
+ return notebookType.priority === 'option' ? 100 : 200;
67
+ }
68
+
69
+ protected findHighestPriorityType(uri: URI): NotebookTypeDescriptor | undefined {
70
+ const matchingTypes = this.notebookTypes
71
+ .filter(notebookType => notebookType.selector && this.matches(notebookType.selector, uri))
72
+ .map(notebookType => ({ descriptor: notebookType, priority: this.calculatePriority(notebookType) }));
73
+
74
+ if (matchingTypes.length === 0) {
75
+ return undefined;
76
+ }
77
+ let type = matchingTypes[0];
78
+ for (let i = 1; i < matchingTypes.length; i++) {
79
+ const notebookType = matchingTypes[i];
80
+ if (notebookType.priority > type.priority) {
81
+ type = notebookType;
82
+ }
83
+ }
84
+ return type.descriptor;
85
+ }
86
+
87
+ // Override for better options typing
88
+ override open(uri: URI, options?: NotebookWidgetOpenerOptions): Promise<NotebookEditorWidget> {
89
+ return super.open(uri, options);
90
+ }
91
+
92
+ protected override createWidgetOptions(uri: URI, options?: NotebookWidgetOpenerOptions): NotebookEditorWidgetOptions {
93
+ const widgetOptions = super.createWidgetOptions(uri, options);
94
+ if (options?.notebookType) {
95
+ return {
96
+ notebookType: options.notebookType,
97
+ ...widgetOptions
98
+ };
99
+ }
100
+ const defaultHandler = getDefaultHandler(uri, this.preferenceService);
101
+ const notebookType = this.notebookTypes.find(type => type.type === defaultHandler)
102
+ || this.findHighestPriorityType(uri);
103
+ if (!notebookType) {
104
+ throw new Error('No notebook types registered for uri: ' + uri.toString());
105
+ }
106
+ return {
107
+ notebookType: notebookType.type,
108
+ ...widgetOptions
109
+ };
110
+ }
111
+
112
+ protected matches(selectors: readonly NotebookFileSelector[], resource: URI): boolean {
113
+ return selectors.some(selector => this.selectorMatches(selector, resource));
114
+ }
115
+
116
+ protected selectorMatches(selector: NotebookFileSelector, resource: URI): boolean {
117
+ return !!selector.filenamePattern
118
+ && match(selector.filenamePattern, resource.path.name + resource.path.ext);
119
+ }
120
+ }